@tekmidian/pai 0.65.2 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/{chain-CT3SI-3z.mjs → chain-D4PuQ2c-.mjs} +4 -4
  2. package/dist/{chain-CT3SI-3z.mjs.map → chain-D4PuQ2c-.mjs.map} +1 -1
  3. package/dist/cli/index.mjs +9 -9
  4. package/dist/cli/program.mjs +9 -9
  5. package/dist/{context-handover-cache-CRSFdkNi.mjs → context-handover-cache-pkHzmL3c.mjs} +3 -3
  6. package/dist/{context-handover-cache-CRSFdkNi.mjs.map → context-handover-cache-pkHzmL3c.mjs.map} +1 -1
  7. package/dist/daemon/index.mjs +7 -7
  8. package/dist/{daemon-SaPnmoyg.mjs → daemon-BEoVgVfJ.mjs} +9 -9
  9. package/dist/{daemon-SaPnmoyg.mjs.map → daemon-BEoVgVfJ.mjs.map} +1 -1
  10. package/dist/{daemon-DoTVK9z6.mjs → daemon-DPAYU9hp.mjs} +7 -7
  11. package/dist/daemon-mcp/index.mjs +6 -6
  12. package/dist/daemon-mcp/index.mjs.map +1 -1
  13. package/dist/{fallback-vHjFZP0Y.mjs → fallback-B5svk75f.mjs} +15 -7
  14. package/dist/fallback-B5svk75f.mjs.map +1 -0
  15. package/dist/hooks/block-sleep-poll.mjs.map +2 -2
  16. package/dist/hooks/load-project-context.mjs +16 -0
  17. package/dist/hooks/load-project-context.mjs.map +2 -2
  18. package/dist/hooks/route-agents-to-worker.mjs +16 -0
  19. package/dist/hooks/route-agents-to-worker.mjs.map +2 -2
  20. package/dist/hooks/security-validator.mjs +16 -0
  21. package/dist/hooks/security-validator.mjs.map +2 -2
  22. package/dist/hooks/worker-guard.mjs +10 -0
  23. package/dist/hooks/worker-guard.mjs.map +3 -3
  24. package/dist/hooks/worker-proxy.mjs +16 -0
  25. package/dist/hooks/worker-proxy.mjs.map +2 -2
  26. package/dist/hooks/worker-status-line.mjs +16 -0
  27. package/dist/hooks/worker-status-line.mjs.map +2 -2
  28. package/dist/hooks/worker-supervision.mjs +16 -0
  29. package/dist/hooks/worker-supervision.mjs.map +2 -2
  30. package/dist/{main-resolver-VSM5ytnA.mjs → main-resolver-BKz_OuEh.mjs} +2 -2
  31. package/dist/{main-resolver-CKNGux1B.mjs → main-resolver-DPPwHNtn.mjs} +2 -2
  32. package/dist/{main-resolver-CKNGux1B.mjs.map → main-resolver-DPPwHNtn.mjs.map} +1 -1
  33. package/dist/{planner-Dzs9-8AS.mjs → planner-EJPZnnif.mjs} +5 -5
  34. package/dist/{planner-Dzs9-8AS.mjs.map → planner-EJPZnnif.mjs.map} +1 -1
  35. package/dist/{program-DK0mRRlf.mjs → program-DSETzrWg.mjs} +56 -16
  36. package/dist/{program-DK0mRRlf.mjs.map → program-DSETzrWg.mjs.map} +1 -1
  37. package/dist/{run-DMaCpvMW.mjs → run-Z4akoa8G.mjs} +325 -23
  38. package/dist/run-Z4akoa8G.mjs.map +1 -0
  39. package/dist/{run-env-BHWnXqle.mjs → run-env-DRcp7A8K.mjs} +16 -2
  40. package/dist/run-env-DRcp7A8K.mjs.map +1 -0
  41. package/dist/{server-DlL1QI2k.mjs → server-DgmAHyFK.mjs} +2 -2
  42. package/dist/{server-DlL1QI2k.mjs.map → server-DgmAHyFK.mjs.map} +1 -1
  43. package/dist/{session-keepalive-DVZ9-7qg.mjs → session-keepalive-BDhytXEo.mjs} +4 -4
  44. package/dist/{session-keepalive-DVZ9-7qg.mjs.map → session-keepalive-BDhytXEo.mjs.map} +1 -1
  45. package/dist/{work-queue-worker-DZiEMvBQ.mjs → work-queue-worker-4tLa5gpQ.mjs} +2 -2
  46. package/dist/{work-queue-worker-DZiEMvBQ.mjs.map → work-queue-worker-4tLa5gpQ.mjs.map} +1 -1
  47. package/dist/{work-queue-worker-D7GHuj2I.mjs → work-queue-worker-rFZvTO3p.mjs} +4 -4
  48. package/docs/commands/README.md +1 -0
  49. package/docs/commands/worker.md +30 -0
  50. package/package.json +1 -1
  51. package/src/hooks/ts/lib/worker-guard.ts +4 -0
  52. package/dist/fallback-vHjFZP0Y.mjs.map +0 -1
  53. package/dist/run-DMaCpvMW.mjs.map +0 -1
  54. package/dist/run-env-BHWnXqle.mjs.map +0 -1
@@ -1,6 +1,6 @@
1
- import { E as readWorkersSection } from "./run-env-BHWnXqle.mjs";
2
- import { V as newWorkerId, Y as shortText, k as appendLedger, n as runWorker } from "./run-DMaCpvMW.mjs";
3
- import { h as ledgerPath, v as workersLogDir } from "./server-DlL1QI2k.mjs";
1
+ import { D as readWorkersSection } from "./run-env-DRcp7A8K.mjs";
2
+ import { U as newWorkerId, Z as shortText, j as appendLedger, n as runWorker } from "./run-Z4akoa8G.mjs";
3
+ import { h as ledgerPath, v as workersLogDir } from "./server-DgmAHyFK.mjs";
4
4
  import { existsSync, mkdirSync, readFileSync } from "node:fs";
5
5
  import { join } from "node:path";
6
6
 
@@ -162,4 +162,4 @@ async function runChain(opts, deps = {}) {
162
162
 
163
163
  //#endregion
164
164
  export { swapPromptArg as n, runChain as t };
165
- //# sourceMappingURL=chain-CT3SI-3z.mjs.map
165
+ //# sourceMappingURL=chain-D4PuQ2c-.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"chain-CT3SI-3z.mjs","names":[],"sources":["../src/workers/chain.ts"],"sourcesContent":["/**\n * chain.ts — draft-then-implement chains: `--chain draft,implement[,review]`.\n *\n * The chain runs each stage as its own worker (own id, own pane, `parent` set\n * to the chain id), so `ps` shows the chain as a tree and every stage can be\n * followed, replayed and said to like any other worker:\n *\n * - draft turns the operator's brief into a full spec file under\n * <logDir>/specs/<chain id>.md (goal, constraints, files likely\n * touched, acceptance checks, verification commands);\n * - any other stage (implement, plan, …) runs with that spec as its prompt\n * and the original brief attached;\n * - review reads the spec and the working-tree diff and produces the\n * structured report.\n *\n * A stage that fails (or a draft that produces no spec file) stops the chain;\n * the caller then writes the spec itself and re-runs without the draft stage.\n */\n\nimport { existsSync, mkdirSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { readWorkersSection } from \"./config.js\";\nimport { appendLedger } from \"./ledger.js\";\nimport { ledgerPath, workersLogDir } from \"./paths.js\";\nimport { newWorkerId } from \"./status.js\";\nimport { shortText } from \"./args.js\";\nimport { runWorker, type RunOptions } from \"./run.js\";\n\n/** Where a chain's spec file lives: <logDir>/specs/<chain id>.md. */\nexport function specPathFor(logDir: string, chainId: string): string {\n return join(logDir, \"specs\", `${chainId}.md`);\n}\n\n/**\n * Replace the caller's -p value with `prompt`, dropping every existing\n * -p/--print pair first (two -p flags on one claude command line are an error,\n * so the chain must never leave the brief in place when swapping prompts).\n */\nexport function swapPromptArg(claudeArgs: string[], prompt: string): string[] {\n const out: string[] = [];\n for (let i = 0; i < claudeArgs.length; i++) {\n const a = claudeArgs[i];\n if (a === \"-p\" || a === \"--print\") {\n if (i + 1 < claudeArgs.length && !claudeArgs[i + 1].startsWith(\"-\")) i += 1;\n continue;\n }\n out.push(a);\n }\n out.push(\"-p\", prompt);\n return out;\n}\n\nexport function draftPrompt(brief: string, specPath: string): string {\n return [\n \"You are the DRAFT stage of a worker chain. Turn the operator's brief below into a full implementation spec and write it to\",\n specPath,\n \"with the Write tool.\",\n \"\",\n \"Use exactly these five sections as Markdown headings:\",\n \"# Goal\",\n \"# Constraints\",\n \"# Files likely touched\",\n \"# Acceptance checks\",\n \"# Verification commands\",\n \"\",\n \"Read the repository first (Glob/Grep/Read) so the spec names real files and real commands. Do not implement anything.\",\n \"\",\n \"## Operator brief\",\n \"\",\n brief,\n ].join(\"\\n\");\n}\n\nexport function implementPrompt(brief: string, specPath: string | null, spec: string | null): string {\n const head = spec\n ? [\n \"You are the IMPLEMENT stage of a worker chain. The draft stage wrote the spec below (also at \" +\n specPath +\n \"). Implement it exactly, then run the spec's verification commands before finishing.\",\n \"\",\n \"## Spec\",\n \"\",\n spec,\n ]\n : [\"Implement the operator's brief below.\"];\n return [...head, \"\", \"## Operator brief\", \"\", brief].join(\"\\n\");\n}\n\nexport function reviewPrompt(brief: string, specPath: string | null, spec: string | null): string {\n const specPart = spec\n ? [\n \"\",\n \"## Spec (also at \" + specPath + \")\",\n \"\",\n spec,\n ]\n : [];\n return [\n \"You are the REVIEW stage of a worker chain. The implement stage just ran. Read the repository's diff (run `git diff` and `git status`; use `git diff --stat` for the overview) and check it against the spec's acceptance checks and verification commands — run the checks when they are cheap. Do not fix anything you find; report it.\",\n ...specPart,\n \"\",\n \"## Operator brief\",\n \"\",\n brief,\n ].join(\"\\n\");\n}\n\nexport interface ChainOptions {\n /** Class names, run in order: e.g. [\"draft\", \"implement\", \"review\"]. */\n stages: string[];\n /** Overrides the class of every stage when given (--class with --chain). */\n className?: string;\n providerFlag?: string;\n modelFlag?: string;\n label?: string;\n noPane?: boolean;\n mcpFlag?: string;\n /** --spec value, resolved for display/recording (\"-\" for stdin). */\n specPath?: string;\n /** The operator's brief — the -p value of the run. */\n brief: string;\n /** The caller's claude args (allowedTools etc.); the -p value is swapped. */\n claudeArgs: string[];\n cwd?: string;\n /** Internal: notified with the chain id once it exists (worker_run uses it). */\n onChainStart?: (chainId: string) => void;\n /** Internal: suppress result printing (the MCP shim's stdout is the RPC channel). */\n quiet?: boolean;\n}\n\nexport interface ChainDeps {\n /** Stage runner; tests inject a mock, production uses runWorker. */\n runStage?: (opts: RunOptions) => Promise<number>;\n /** logDir override for tests; default: the configured workers logDir. */\n logDir?: string;\n}\n\n/** Run a chain of stages; returns the exit code of the first failed stage, 0 when all pass. */\nexport async function runChain(opts: ChainOptions, deps: ChainDeps = {}): Promise<number> {\n const stages = opts.stages.map((s) => s.trim()).filter(Boolean);\n if (!stages.length) throw new Error(\"--chain needs at least one class, e.g. --chain draft,implement\");\n const runStage = deps.runStage ?? runWorker;\n const logDir = deps.logDir ?? workersLogDir(readWorkersSection().workers);\n const chainId = newWorkerId();\n const specPath = specPathFor(logDir, chainId);\n mkdirSync(join(logDir, \"specs\"), { recursive: true }); // the draft stage writes into it\n const baseLabel = opts.label ?? shortText(opts.brief, 40);\n\n appendLedger(ledgerPath(logDir), \"WORKER-CHAIN\", {\n chain: chainId,\n stages: stages.join(\",\"),\n label: baseLabel,\n });\n opts.onChainStart?.(chainId);\n\n let spec: string | null = null;\n for (let i = 0; i < stages.length; i++) {\n const stage = stages[i];\n if (stage === \"draft\") {\n spec = null; // a chain may legally start over; the draft rewrites it\n } else if (spec === null && existsSync(specPath)) {\n spec = readFileSync(specPath, \"utf8\");\n }\n const prompt =\n stage === \"draft\"\n ? draftPrompt(opts.brief, specPath)\n : stage === \"review\"\n ? reviewPrompt(opts.brief, spec ? specPath : null, spec)\n : implementPrompt(opts.brief, spec ? specPath : null, spec);\n process.stderr.write(\n `chain ${chainId}: stage ${i + 1}/${stages.length} ${stage} (spec: ${specPath})\\n`\n );\n const rc = await runStage({\n className: opts.className ?? stage,\n providerFlag: opts.providerFlag,\n modelFlag: opts.modelFlag,\n label: `${baseLabel} · ${stage}`,\n noPane: opts.noPane,\n mcpFlag: opts.mcpFlag,\n specPath: opts.specPath,\n claudeArgs: swapPromptArg(opts.claudeArgs, prompt),\n cwd: opts.cwd,\n parent: chainId,\n stage,\n quiet: opts.quiet,\n });\n if (stage === \"draft\") {\n if (!existsSync(specPath)) {\n process.stderr.write(\n `chain ${chainId}: draft stage produced no spec at ${specPath} — stopping. ` +\n `Write the spec yourself and re-run without the draft stage.\\n`\n );\n appendLedger(ledgerPath(logDir), \"WORKER-CHAIN-END\", {\n chain: chainId,\n rc: rc !== 0 ? rc : 1,\n failed: \"draft\",\n });\n return rc !== 0 ? rc : 1;\n }\n spec = readFileSync(specPath, \"utf8\");\n }\n if (rc !== 0) {\n appendLedger(ledgerPath(logDir), \"WORKER-CHAIN-END\", {\n chain: chainId,\n rc,\n failed: stage,\n });\n return rc;\n }\n }\n appendLedger(ledgerPath(logDir), \"WORKER-CHAIN-END\", { chain: chainId, rc: 0 });\n return 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6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,CAAC;AACF,WAAO,OAAO,IAAI,KAAK;;AAEzB,UAAO,aAAa,UAAU,OAAO;;AAEvC,MAAI,OAAO,GAAG;AACZ,gBAAa,WAAW,OAAO,EAAE,oBAAoB;IACnD,OAAO;IACP;IACA,QAAQ;IACT,CAAC;AACF,UAAO;;;AAGX,cAAa,WAAW,OAAO,EAAE,oBAAoB;EAAE,OAAO;EAAS,IAAI;EAAG,CAAC;AAC/E,QAAO"}
1
+ {"version":3,"file":"chain-D4PuQ2c-.mjs","names":[],"sources":["../src/workers/chain.ts"],"sourcesContent":["/**\n * chain.ts — draft-then-implement chains: `--chain draft,implement[,review]`.\n *\n * The chain runs each stage as its own worker (own id, own pane, `parent` set\n * to the chain id), so `ps` shows the chain as a tree and every stage can be\n * followed, replayed and said to like any other worker:\n *\n * - draft turns the operator's brief into a full spec file under\n * <logDir>/specs/<chain id>.md (goal, constraints, files likely\n * touched, acceptance checks, verification commands);\n * - any other stage (implement, plan, …) runs with that spec as its prompt\n * and the original brief attached;\n * - review reads the spec and the working-tree diff and produces the\n * structured report.\n *\n * A stage that fails (or a draft that produces no spec file) stops the chain;\n * the caller then writes the spec itself and re-runs without the draft stage.\n */\n\nimport { existsSync, mkdirSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { readWorkersSection } from \"./config.js\";\nimport { appendLedger } from \"./ledger.js\";\nimport { ledgerPath, workersLogDir } from \"./paths.js\";\nimport { newWorkerId } from \"./status.js\";\nimport { shortText } from \"./args.js\";\nimport { runWorker, type RunOptions } from \"./run.js\";\n\n/** Where a chain's spec file lives: <logDir>/specs/<chain id>.md. */\nexport function specPathFor(logDir: string, chainId: string): string {\n return join(logDir, \"specs\", `${chainId}.md`);\n}\n\n/**\n * Replace the caller's -p value with `prompt`, dropping every existing\n * -p/--print pair first (two -p flags on one claude command line are an error,\n * so the chain must never leave the brief in place when swapping prompts).\n */\nexport function swapPromptArg(claudeArgs: string[], prompt: string): string[] {\n const out: string[] = [];\n for (let i = 0; i < claudeArgs.length; i++) {\n const a = claudeArgs[i];\n if (a === \"-p\" || a === \"--print\") {\n if (i + 1 < claudeArgs.length && !claudeArgs[i + 1].startsWith(\"-\")) i += 1;\n continue;\n }\n out.push(a);\n }\n out.push(\"-p\", prompt);\n return out;\n}\n\nexport function draftPrompt(brief: string, specPath: string): string {\n return [\n \"You are the DRAFT stage of a worker chain. Turn the operator's brief below into a full implementation spec and write it to\",\n specPath,\n \"with the Write tool.\",\n \"\",\n \"Use exactly these five sections as Markdown headings:\",\n \"# Goal\",\n \"# Constraints\",\n \"# Files likely touched\",\n \"# Acceptance checks\",\n \"# Verification commands\",\n \"\",\n \"Read the repository first (Glob/Grep/Read) so the spec names real files and real commands. Do not implement anything.\",\n \"\",\n \"## Operator brief\",\n \"\",\n brief,\n ].join(\"\\n\");\n}\n\nexport function implementPrompt(brief: string, specPath: string | null, spec: string | null): string {\n const head = spec\n ? [\n \"You are the IMPLEMENT stage of a worker chain. The draft stage wrote the spec below (also at \" +\n specPath +\n \"). Implement it exactly, then run the spec's verification commands before finishing.\",\n \"\",\n \"## Spec\",\n \"\",\n spec,\n ]\n : [\"Implement the operator's brief below.\"];\n return [...head, \"\", \"## Operator brief\", \"\", brief].join(\"\\n\");\n}\n\nexport function reviewPrompt(brief: string, specPath: string | null, spec: string | null): string {\n const specPart = spec\n ? [\n \"\",\n \"## Spec (also at \" + specPath + \")\",\n \"\",\n spec,\n ]\n : [];\n return [\n \"You are the REVIEW stage of a worker chain. The implement stage just ran. Read the repository's diff (run `git diff` and `git status`; use `git diff --stat` for the overview) and check it against the spec's acceptance checks and verification commands — run the checks when they are cheap. Do not fix anything you find; report it.\",\n ...specPart,\n \"\",\n \"## Operator brief\",\n \"\",\n brief,\n ].join(\"\\n\");\n}\n\nexport interface ChainOptions {\n /** Class names, run in order: e.g. [\"draft\", \"implement\", \"review\"]. */\n stages: string[];\n /** Overrides the class of every stage when given (--class with --chain). */\n className?: string;\n providerFlag?: string;\n modelFlag?: string;\n label?: string;\n noPane?: boolean;\n mcpFlag?: string;\n /** --spec value, resolved for display/recording (\"-\" for stdin). */\n specPath?: string;\n /** The operator's brief — the -p value of the run. */\n brief: string;\n /** The caller's claude args (allowedTools etc.); the -p value is swapped. */\n claudeArgs: string[];\n cwd?: string;\n /** Internal: notified with the chain id once it exists (worker_run uses it). */\n onChainStart?: (chainId: string) => void;\n /** Internal: suppress result printing (the MCP shim's stdout is the RPC channel). */\n quiet?: boolean;\n}\n\nexport interface ChainDeps {\n /** Stage runner; tests inject a mock, production uses runWorker. */\n runStage?: (opts: RunOptions) => Promise<number>;\n /** logDir override for tests; default: the configured workers logDir. */\n logDir?: string;\n}\n\n/** Run a chain of stages; returns the exit code of the first failed stage, 0 when all pass. */\nexport async function runChain(opts: ChainOptions, deps: ChainDeps = {}): Promise<number> {\n const stages = opts.stages.map((s) => s.trim()).filter(Boolean);\n if (!stages.length) throw new Error(\"--chain needs at least one class, e.g. --chain draft,implement\");\n const runStage = deps.runStage ?? runWorker;\n const logDir = deps.logDir ?? workersLogDir(readWorkersSection().workers);\n const chainId = newWorkerId();\n const specPath = specPathFor(logDir, chainId);\n mkdirSync(join(logDir, \"specs\"), { recursive: true }); // the draft stage writes into it\n const baseLabel = opts.label ?? shortText(opts.brief, 40);\n\n appendLedger(ledgerPath(logDir), \"WORKER-CHAIN\", {\n chain: chainId,\n stages: stages.join(\",\"),\n label: baseLabel,\n });\n opts.onChainStart?.(chainId);\n\n let spec: string | null = null;\n for (let i = 0; i < stages.length; i++) {\n const stage = stages[i];\n if (stage === \"draft\") {\n spec = null; // a chain may legally start over; the draft rewrites it\n } else if (spec === null && existsSync(specPath)) {\n spec = readFileSync(specPath, \"utf8\");\n }\n const prompt =\n stage === \"draft\"\n ? draftPrompt(opts.brief, specPath)\n : stage === \"review\"\n ? reviewPrompt(opts.brief, spec ? specPath : null, spec)\n : implementPrompt(opts.brief, spec ? specPath : null, spec);\n process.stderr.write(\n `chain ${chainId}: stage ${i + 1}/${stages.length} ${stage} (spec: ${specPath})\\n`\n );\n const rc = await runStage({\n className: opts.className ?? stage,\n providerFlag: opts.providerFlag,\n modelFlag: opts.modelFlag,\n label: `${baseLabel} · ${stage}`,\n noPane: opts.noPane,\n mcpFlag: opts.mcpFlag,\n specPath: opts.specPath,\n claudeArgs: swapPromptArg(opts.claudeArgs, prompt),\n cwd: opts.cwd,\n parent: chainId,\n stage,\n quiet: opts.quiet,\n });\n if (stage === \"draft\") {\n if (!existsSync(specPath)) {\n process.stderr.write(\n `chain ${chainId}: draft stage produced no spec at ${specPath} — stopping. ` +\n `Write the spec yourself and re-run without the draft stage.\\n`\n );\n appendLedger(ledgerPath(logDir), \"WORKER-CHAIN-END\", {\n chain: chainId,\n rc: rc !== 0 ? rc : 1,\n failed: \"draft\",\n });\n return rc !== 0 ? rc : 1;\n }\n spec = readFileSync(specPath, \"utf8\");\n }\n if (rc !== 0) {\n appendLedger(ledgerPath(logDir), \"WORKER-CHAIN-END\", {\n chain: chainId,\n rc,\n failed: stage,\n });\n return rc;\n }\n }\n appendLedger(ledgerPath(logDir), \"WORKER-CHAIN-END\", { chain: chainId, rc: 0 });\n return 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,YAAY,QAAgB,SAAyB;AACnE,QAAO,KAAK,QAAQ,SAAS,GAAG,QAAQ,KAAK;;;;;;;AAQ/C,SAAgB,cAAc,YAAsB,QAA0B;CAC5E,MAAM,MAAgB,EAAE;AACxB,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;EAC1C,MAAM,IAAI,WAAW;AACrB,MAAI,MAAM,QAAQ,MAAM,WAAW;AACjC,OAAI,IAAI,IAAI,WAAW,UAAU,CAAC,WAAW,IAAI,GAAG,WAAW,IAAI,CAAE,MAAK;AAC1E;;AAEF,MAAI,KAAK,EAAE;;AAEb,KAAI,KAAK,MAAM,OAAO;AACtB,QAAO;;AAGT,SAAgB,YAAY,OAAe,UAA0B;AACnE,QAAO;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O;EAEvC,MAAM,SACJ,UAAU,UACN,YAAY,KAAK,OAAO,SAAS,GACjC,UAAU,WACR,aAAa,KAAK,OAAO,OAAO,WAAW,MAAM,KAAK,GACtD,gBAAgB,KAAK,OAAO,OAAO,WAAW,MAAM,KAAK;AACjE,UAAQ,OAAO,MACb,SAAS,QAAQ,UAAU,IAAI,EAAE,GAAG,OAAO,OAAO,GAAG,MAAM,UAAU,SAAS,KAC/E;EACD,MAAM,KAAK,MAAM,SAAS;GACxB,WAAW,KAAK,aAAa;GAC7B,cAAc,KAAK;GACnB,WAAW,KAAK;GAChB,OAAO,GAAG,UAAU,KAAK;GACzB,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,UAAU,KAAK;GACf,YAAY,cAAc,KAAK,YAAY,OAAO;GAClD,KAAK,KAAK;GACV,QAAQ;GACR;GACA,OAAO,KAAK;GACb,CAAC;AACF,MAAI,UAAU,SAAS;AACrB,OAAI,CAAC,WAAW,SAAS,EAAE;AACzB,YAAQ,OAAO,MACb,SAAS,QAAQ,oCAAoC,SAAS,4EAE/D;AACD,iBAAa,WAAW,OAAO,EAAE,oBAAoB;KACnD,OAAO;KACP,IAAI,OAAO,IAAI,KAAK;KACpB,QAAQ;KACT,CAAC;AACF,WAAO,OAAO,IAAI,KAAK;;AAEzB,UAAO,aAAa,UAAU,OAAO;;AAEvC,MAAI,OAAO,GAAG;AACZ,gBAAa,WAAW,OAAO,EAAE,oBAAoB;IACnD,OAAO;IACP;IACA,QAAQ;IACT,CAAC;AACF,UAAO;;;AAGX,cAAa,WAAW,OAAO,EAAE,oBAAoB;EAAE,OAAO;EAAS,IAAI;EAAG,CAAC;AAC/E,QAAO"}
@@ -3,24 +3,24 @@ import { i as err } from "../utils-C9HsYDpO.mjs";
3
3
  import "../migrate-BD7D8EEh.mjs";
4
4
  import "../helpers-BRCJg0G3.mjs";
5
5
  import "../factory-CNpPQQ-5.mjs";
6
- import { n as drainStdio, t as buildProgram } from "../program-DK0mRRlf.mjs";
6
+ import { n as drainStdio, t as buildProgram } from "../program-DSETzrWg.mjs";
7
7
  import "../wakeup-D8n33hYV.mjs";
8
- import "../context-handover-cache-CRSFdkNi.mjs";
8
+ import "../context-handover-cache-pkHzmL3c.mjs";
9
9
  import "../config-BbLFD7Uf.mjs";
10
- import "../run-env-BHWnXqle.mjs";
11
- import "../run-DMaCpvMW.mjs";
10
+ import "../run-env-DRcp7A8K.mjs";
11
+ import "../run-Z4akoa8G.mjs";
12
12
  import "../federation-db-BTyoufBh.mjs";
13
13
  import "../registry-db-C7voqML9.mjs";
14
14
  import "../async-C2Bm_Lal.mjs";
15
15
  import "../indexer-backend-isSLg6yE.mjs";
16
16
  import "../ipc-client-D16Xw6Uo.mjs";
17
- import "../fallback-vHjFZP0Y.mjs";
18
- import "../main-resolver-CKNGux1B.mjs";
19
- import "../server-DlL1QI2k.mjs";
17
+ import "../fallback-B5svk75f.mjs";
18
+ import "../main-resolver-DPPwHNtn.mjs";
19
+ import "../server-DgmAHyFK.mjs";
20
20
  import "../state-HyjqTihC.mjs";
21
21
  import "../aibroker-client-C5Fw7DNz.mjs";
22
- import "../session-keepalive-DVZ9-7qg.mjs";
23
- import "../chain-CT3SI-3z.mjs";
22
+ import "../session-keepalive-BDhytXEo.mjs";
23
+ import "../chain-D4PuQ2c-.mjs";
24
24
  import { t as dropItermBundleId } from "../env-JNEIrQWg.mjs";
25
25
  import { CommanderError } from "commander";
26
26
 
@@ -2,23 +2,23 @@ import "../utils-C9HsYDpO.mjs";
2
2
  import "../migrate-BD7D8EEh.mjs";
3
3
  import "../helpers-BRCJg0G3.mjs";
4
4
  import "../factory-CNpPQQ-5.mjs";
5
- import { t as buildProgram } from "../program-DK0mRRlf.mjs";
5
+ import { t as buildProgram } from "../program-DSETzrWg.mjs";
6
6
  import "../wakeup-D8n33hYV.mjs";
7
- import "../context-handover-cache-CRSFdkNi.mjs";
7
+ import "../context-handover-cache-pkHzmL3c.mjs";
8
8
  import "../config-BbLFD7Uf.mjs";
9
- import "../run-env-BHWnXqle.mjs";
10
- import "../run-DMaCpvMW.mjs";
9
+ import "../run-env-DRcp7A8K.mjs";
10
+ import "../run-Z4akoa8G.mjs";
11
11
  import "../federation-db-BTyoufBh.mjs";
12
12
  import "../registry-db-C7voqML9.mjs";
13
13
  import "../async-C2Bm_Lal.mjs";
14
14
  import "../indexer-backend-isSLg6yE.mjs";
15
15
  import "../ipc-client-D16Xw6Uo.mjs";
16
- import "../fallback-vHjFZP0Y.mjs";
17
- import "../main-resolver-CKNGux1B.mjs";
18
- import "../server-DlL1QI2k.mjs";
16
+ import "../fallback-B5svk75f.mjs";
17
+ import "../main-resolver-DPPwHNtn.mjs";
18
+ import "../server-DgmAHyFK.mjs";
19
19
  import "../state-HyjqTihC.mjs";
20
20
  import "../aibroker-client-C5Fw7DNz.mjs";
21
- import "../session-keepalive-DVZ9-7qg.mjs";
22
- import "../chain-CT3SI-3z.mjs";
21
+ import "../session-keepalive-BDhytXEo.mjs";
22
+ import "../chain-D4PuQ2c-.mjs";
23
23
 
24
24
  export { buildProgram };
@@ -3,8 +3,8 @@ import { a as slugify, i as parseSessionFilename, n as decodeEncodedDir, t as bu
3
3
  import { n as ensurePaiMarker, t as discoverPaiMarkers } from "./pai-marker-D1MMswkz.mjs";
4
4
  import { i as getRegistryBackend } from "./factory-CNpPQQ-5.mjs";
5
5
  import { a as paiHomePath, o as resolvePaiFile, r as migratePaiFile } from "./pai-home-Cm9rcJgX.mjs";
6
- import { E as readWorkersSection, O as resolveModelCapability, _ as defaultWorkersConfig, t as buildRunEnv } from "./run-env-BHWnXqle.mjs";
7
- import { d as resolveTarget, n as ensureProxyRunning, p as ensureNoMcpConfig, t as DEFAULT_PROXY_PORT, v as workersLogDir } from "./server-DlL1QI2k.mjs";
6
+ import { D as readWorkersSection, k as resolveModelCapability, t as buildRunEnv, v as defaultWorkersConfig } from "./run-env-DRcp7A8K.mjs";
7
+ import { d as resolveTarget, n as ensureProxyRunning, p as ensureNoMcpConfig, t as DEFAULT_PROXY_PORT, v as workersLogDir } from "./server-DgmAHyFK.mjs";
8
8
  import { k as storageBackend, n as daemonConfig } from "./state-HyjqTihC.mjs";
9
9
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
10
10
  import { homedir, tmpdir } from "node:os";
@@ -3204,4 +3204,4 @@ function writeContextHandoverCache(cache) {
3204
3204
 
3205
3205
  //#endregion
3206
3206
  export { archiveSessionFilesToSessionsDir as A, claudeProjectsDir as B, findLatestNote as C, appendCheckpoint as D, addWorkToSessionNote as E, performScan as F, scanTranscriptFolders as H, resolveHome as I, saveScanConfig as L, cmdScan as M, loadScanConfig as N, finalizeSessionNote as O, migrateScanConfig as P, upsertProject as R, applyContinue as S, readBodyFile as T, transcriptFiles as U, findMovedProjects as V, spawnSummarizer as _, enqueue as a, updateTodoContinue as b, loadQueue as c, migrateWorkQueue as d, contentToText as f, migrateSummaryCooldowns as g, handleSessionSummary as h, dequeue as i, findNotesDir$1 as j, getCurrentNotePath as k, markCompleted as l, getGitContext as m, writeContextHandoverCache as n, getStats as o, findLatestJsonl as p, cleanup as r, hasPendingOrProcessingOfType as s, readContextHandoverCache as t, markFailed as u, extractAndStoreTriples$1 as v, findNotesDir as w, appendCheckpointToNote as x, sessionIdFromTranscript as y, upsertSession as z };
3207
- //# sourceMappingURL=context-handover-cache-CRSFdkNi.mjs.map
3207
+ //# sourceMappingURL=context-handover-cache-pkHzmL3c.mjs.map