/**
 * Workforce SQLite schema.
 *
 * Unified workers+jobs+claims tables. Coexists with synapse/architects tables
 * (no DROP, no rename). Migration copies live data on first init.
 */
import type { WorkforceDb } from '../types.js';
export declare const WORKFORCE_SCHEMA = "\nCREATE TABLE IF NOT EXISTS workforce_workers (\n  id               TEXT PRIMARY KEY,\n  name             TEXT NOT NULL UNIQUE,\n  role             TEXT,\n  client           TEXT NOT NULL DEFAULT 'unknown',\n  status           TEXT NOT NULL DEFAULT 'idle'\n    CHECK(status IN ('idle','active','stale','retired')),\n  budget_cap_usd   REAL NOT NULL DEFAULT 10.0,\n  spent_usd        REAL NOT NULL DEFAULT 0.0,\n  score            REAL NOT NULL DEFAULT 0.0,\n  last_heartbeat   INTEGER NOT NULL DEFAULT 0,\n  created_at       INTEGER NOT NULL DEFAULT (strftime('%s','now')*1000)\n);\n\nCREATE TABLE IF NOT EXISTS workforce_jobs (\n  id               TEXT PRIMARY KEY,\n  title            TEXT NOT NULL,\n  tier             TEXT NOT NULL DEFAULT 'tactical'\n    CHECK(tier IN ('strategy','tactical')),\n  status           TEXT NOT NULL DEFAULT 'ready'\n    CHECK(status IN ('backlog','ready','claimed','wip','blocked','review','done','failed','cancelled')),\n  priority         INTEGER NOT NULL DEFAULT 5,\n  worker_id        TEXT,\n  parent_id        TEXT,\n  depends_on       TEXT NOT NULL DEFAULT '[]',\n  budget_cap_usd   REAL,\n  tokens_used      INTEGER NOT NULL DEFAULT 0,\n  payload          TEXT NOT NULL DEFAULT '{}',\n  client           TEXT NOT NULL DEFAULT 'unknown',\n  claimed_at       INTEGER,\n  completed_at     INTEGER,\n  created_at       INTEGER NOT NULL DEFAULT (strftime('%s','now')*1000)\n);\n\nCREATE TABLE IF NOT EXISTS workforce_claims (\n  id               TEXT PRIMARY KEY,\n  job_id           TEXT NOT NULL REFERENCES workforce_jobs(id) ON DELETE CASCADE,\n  worker_id        TEXT NOT NULL,\n  acquired_at      INTEGER NOT NULL DEFAULT (strftime('%s','now')*1000),\n  released_at      INTEGER,\n  lease_ms         INTEGER NOT NULL DEFAULT 300000,\n  expires_at       INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_wf_jobs_status       ON workforce_jobs(status, priority);\nCREATE INDEX IF NOT EXISTS idx_wf_jobs_worker        ON workforce_jobs(worker_id, status);\nCREATE INDEX IF NOT EXISTS idx_wf_jobs_parent        ON workforce_jobs(parent_id);\nCREATE INDEX IF NOT EXISTS idx_wf_workers_status     ON workforce_workers(status, last_heartbeat);\nCREATE INDEX IF NOT EXISTS idx_wf_claims_job         ON workforce_claims(job_id, released_at);\nCREATE INDEX IF NOT EXISTS idx_wf_claims_expiry      ON workforce_claims(job_id, expires_at, released_at);\n\nCREATE VIEW IF NOT EXISTS vw_kanban AS\n  SELECT\n    status AS lane,\n    id, title, worker_id, priority, tokens_used,\n    budget_cap_usd, client, created_at, claimed_at\n  FROM workforce_jobs\n  WHERE\n    -- Active lanes: always show\n    status NOT IN ('done', 'failed', 'cancelled')\n    OR\n    -- Terminal lanes: only show last 7 days to prevent unbounded growth\n    completed_at > (strftime('%s','now') - 7*86400) * 1000\n  ORDER BY\n    CASE status\n      WHEN 'backlog'   THEN 1\n      WHEN 'ready'     THEN 2\n      WHEN 'claimed'   THEN 3\n      WHEN 'wip'       THEN 4\n      WHEN 'blocked'   THEN 5\n      WHEN 'review'    THEN 6\n      WHEN 'done'      THEN 7\n      WHEN 'failed'    THEN 8\n      WHEN 'cancelled' THEN 9\n      ELSE 10\n    END,\n    priority,\n    created_at;\n\nCREATE VIEW IF NOT EXISTS vw_worker_load AS\n  SELECT\n    w.id, w.name, w.role, w.status, w.client,\n    COUNT(j.id)        AS active_jobs,\n    COALESCE(SUM(j.tokens_used), 0) AS total_tokens,\n    w.spent_usd,\n    w.budget_cap_usd,\n    w.last_heartbeat\n  FROM workforce_workers w\n  LEFT JOIN workforce_jobs j\n    ON j.worker_id = w.id AND j.status IN ('claimed','wip','review')\n  GROUP BY w.id;\n";
export declare function initWorkforceSchema(db: WorkforceDb): void;
