@tekmidian/pai 0.66.6 → 0.66.8

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 (139) hide show
  1. package/dist/{aibroker-client-WCZi_tn-.mjs → aibroker-client-BfnVwGZl.mjs} +3 -3
  2. package/dist/{aibroker-client-WCZi_tn-.mjs.map → aibroker-client-BfnVwGZl.mjs.map} +1 -1
  3. package/dist/{aibroker-client-Ck3p3k_-.mjs → aibroker-client-C-O3Fflh.mjs} +1 -1
  4. package/dist/{auto-route-BnizyALK.mjs → auto-route-D8TBDNqb.mjs} +3 -3
  5. package/dist/{auto-route-BnizyALK.mjs.map → auto-route-D8TBDNqb.mjs.map} +1 -1
  6. package/dist/auto-route-DCxTKz19.mjs +7 -0
  7. package/dist/{chain-2_uoiEdD.mjs → chain-BL4khGgy.mjs} +4 -3
  8. package/dist/{chain-2_uoiEdD.mjs.map → chain-BL4khGgy.mjs.map} +1 -1
  9. package/dist/cli/index.mjs +20 -16
  10. package/dist/cli/index.mjs.map +1 -1
  11. package/dist/cli/program.mjs +19 -15
  12. package/dist/{config-Ddc4DIPk.mjs → config-DjZELvoA.mjs} +12 -3
  13. package/dist/config-DjZELvoA.mjs.map +1 -0
  14. package/dist/{run-env-CQRnxNht.mjs → config-Dpe2JlbY.mjs} +5 -114
  15. package/dist/config-Dpe2JlbY.mjs.map +1 -0
  16. package/dist/{config-CnsDMETf.mjs → config-yomayAwe.mjs} +1 -1
  17. package/dist/{context-handover-cache-SFkWucuT.mjs → context-handover-cache-DFqxNh-H.mjs} +27 -13
  18. package/dist/context-handover-cache-DFqxNh-H.mjs.map +1 -0
  19. package/dist/daemon/index.mjs +20 -15
  20. package/dist/daemon/index.mjs.map +1 -1
  21. package/dist/{daemon-vLtT3yaI.mjs → daemon-CsR1S_Qr.mjs} +762 -24
  22. package/dist/daemon-CsR1S_Qr.mjs.map +1 -0
  23. package/dist/daemon-WrncnGua.mjs +23 -0
  24. package/dist/daemon-mcp/index.mjs +15 -12
  25. package/dist/daemon-mcp/index.mjs.map +1 -1
  26. package/dist/embedding-gate-DqbKvn56.mjs +378 -0
  27. package/dist/embedding-gate-DqbKvn56.mjs.map +1 -0
  28. package/dist/embedding-gate-SJMCPwxG.mjs +5 -0
  29. package/dist/{embeddings-DMVzpvRZ.mjs → embeddings-BUjZMD9F.mjs} +16 -2
  30. package/dist/{embeddings-DMVzpvRZ.mjs.map → embeddings-BUjZMD9F.mjs.map} +1 -1
  31. package/dist/embeddings-DrJ-ewfi.mjs +3 -0
  32. package/dist/{env-DiolswKQ.mjs → env-CPCNHz3i.mjs} +1 -1
  33. package/dist/{env-DiolswKQ.mjs.map → env-CPCNHz3i.mjs.map} +1 -1
  34. package/dist/factory-DjtXElOI.mjs +9 -0
  35. package/dist/{factory-CXFHwvcv.mjs → factory-yElzJc6f.mjs} +31 -9
  36. package/dist/factory-yElzJc6f.mjs.map +1 -0
  37. package/dist/{fallback-DNzd3jJc.mjs → fallback-2yWDDYiT.mjs} +5 -4
  38. package/dist/{fallback-DNzd3jJc.mjs.map → fallback-2yWDDYiT.mjs.map} +1 -1
  39. package/dist/{helpers-CZsi_49C.mjs → helpers-B9LHRJ8R.mjs} +1 -1
  40. package/dist/{helpers-CZsi_49C.mjs.map → helpers-B9LHRJ8R.mjs.map} +1 -1
  41. package/dist/hooks/block-sleep-poll.mjs +7 -2
  42. package/dist/hooks/block-sleep-poll.mjs.map +3 -3
  43. package/dist/hooks/context-compression-hook.mjs +2 -0
  44. package/dist/hooks/context-compression-hook.mjs.map +2 -2
  45. package/dist/hooks/load-core-context.mjs +5 -5
  46. package/dist/hooks/load-core-context.mjs.map +2 -2
  47. package/dist/hooks/load-project-context.mjs +2 -0
  48. package/dist/hooks/load-project-context.mjs.map +2 -2
  49. package/dist/hooks/post-compact-inject.mjs +2 -0
  50. package/dist/hooks/post-compact-inject.mjs.map +2 -2
  51. package/dist/hooks/route-agents-to-worker.mjs +2 -0
  52. package/dist/hooks/route-agents-to-worker.mjs.map +2 -2
  53. package/dist/hooks/security-validator.mjs +2 -0
  54. package/dist/hooks/security-validator.mjs.map +2 -2
  55. package/dist/hooks/whisper-rules.mjs +2 -0
  56. package/dist/hooks/whisper-rules.mjs.map +2 -2
  57. package/dist/hooks/worker-guard.mjs +82 -5
  58. package/dist/hooks/worker-guard.mjs.map +4 -4
  59. package/dist/hooks/worker-proxy.mjs +2 -0
  60. package/dist/hooks/worker-proxy.mjs.map +2 -2
  61. package/dist/hooks/worker-status-line.mjs +7 -2
  62. package/dist/hooks/worker-status-line.mjs.map +3 -3
  63. package/dist/hooks/worker-supervision.mjs +2 -0
  64. package/dist/hooks/worker-supervision.mjs.map +2 -2
  65. package/dist/index.d.mts.map +1 -1
  66. package/dist/index.mjs +7 -4
  67. package/dist/{ipc-client-DkxRay-o.mjs → ipc-client-DVZ_EGnu.mjs} +2 -2
  68. package/dist/{ipc-client-DkxRay-o.mjs.map → ipc-client-DVZ_EGnu.mjs.map} +1 -1
  69. package/dist/main-resolver-DjQsexge.mjs +8 -0
  70. package/dist/{main-resolver-SfGGg1DB.mjs → main-resolver-Dxvn4Mv8.mjs} +7 -6
  71. package/dist/{main-resolver-SfGGg1DB.mjs.map → main-resolver-Dxvn4Mv8.mjs.map} +1 -1
  72. package/dist/{pai-marker-DXVpFsYz.mjs → pai-marker-1B7iC7oq.mjs} +121 -3
  73. package/dist/pai-marker-1B7iC7oq.mjs.map +1 -0
  74. package/dist/{planner-C-gzg7ye.mjs → planner-CspP59ya.mjs} +13 -10
  75. package/dist/{planner-C-gzg7ye.mjs.map → planner-CspP59ya.mjs.map} +1 -1
  76. package/dist/{postgres-BxmyQHoA.mjs → postgres-CCAGq1qp.mjs} +86 -5
  77. package/dist/postgres-CCAGq1qp.mjs.map +1 -0
  78. package/dist/postgres-CzkEPfAm.mjs +7 -0
  79. package/dist/{program-CfG1T_ko.mjs → program-cWqZI0_L.mjs} +231 -125
  80. package/dist/program-cWqZI0_L.mjs.map +1 -0
  81. package/dist/{query-feedback-BPdapXKd.mjs → query-feedback-GPeVGvIa.mjs} +2 -2
  82. package/dist/{query-feedback-BPdapXKd.mjs.map → query-feedback-GPeVGvIa.mjs.map} +1 -1
  83. package/dist/{reranker-3lnggwgq.mjs → reranker-BTiOia8Y.mjs} +1 -1
  84. package/dist/{reranker-3lnggwgq.mjs.map → reranker-BTiOia8Y.mjs.map} +1 -1
  85. package/dist/{reranker-CZ2mP4cf.mjs → reranker-YwDT2n5e.mjs} +1 -1
  86. package/dist/{router-BaTbc9VX.mjs → router-Bk_ySIZT.mjs} +2 -2
  87. package/dist/{router-BaTbc9VX.mjs.map → router-Bk_ySIZT.mjs.map} +1 -1
  88. package/dist/router-DyiZNI6o.mjs +3 -0
  89. package/dist/{run-ChlIbDJ0.mjs → run-BZNdpUGQ.mjs} +226 -1797
  90. package/dist/run-BZNdpUGQ.mjs.map +1 -0
  91. package/dist/run-env-Cd0Son-Y.mjs +115 -0
  92. package/dist/run-env-Cd0Son-Y.mjs.map +1 -0
  93. package/dist/{pai-home-UncxWxlX.mjs → runtime-paths-DkZoxofH.mjs} +50 -2
  94. package/dist/runtime-paths-DkZoxofH.mjs.map +1 -0
  95. package/dist/{search-CNAGTiJP.mjs → search-cPDj-9fO.mjs} +2 -2
  96. package/dist/{search-CNAGTiJP.mjs.map → search-cPDj-9fO.mjs.map} +1 -1
  97. package/dist/{sources-CM2g-CLT.mjs → sources-CvvzNZad.mjs} +1 -1
  98. package/dist/{sources-CM2g-CLT.mjs.map → sources-CvvzNZad.mjs.map} +1 -1
  99. package/dist/{stop-words-DtxaTWU_.mjs → stop-words-LtkS-Pej.mjs} +1 -1
  100. package/dist/{stop-words-DtxaTWU_.mjs.map → stop-words-LtkS-Pej.mjs.map} +1 -1
  101. package/dist/worktree-CwMRTa0H.mjs +1578 -0
  102. package/dist/worktree-CwMRTa0H.mjs.map +1 -0
  103. package/dist/{zettelkasten-BRIaHzFm.mjs → zettelkasten-DSIe6wpF.mjs} +6 -5
  104. package/dist/zettelkasten-DSIe6wpF.mjs.map +1 -0
  105. package/dist/{zettelkasten-G0-ZTybr.mjs → zettelkasten-DtkAvA18.mjs} +5 -3
  106. package/docker/docker-compose.yml +4 -0
  107. package/docs/commands/README.md +6 -0
  108. package/docs/commands/memory.md +52 -0
  109. package/docs/commands/worker.md +22 -0
  110. package/docs/install-linux.md +1 -0
  111. package/docs/memory.md +69 -0
  112. package/package.json +1 -1
  113. package/src/hooks/ts/lib/sleep-poll-gate.test.ts +2 -2
  114. package/src/hooks/ts/lib/sleep-poll-gate.ts +4 -4
  115. package/src/hooks/ts/lib/worker-guard-longwait.test.ts +48 -0
  116. package/src/hooks/ts/lib/worker-guard.ts +50 -6
  117. package/src/hooks/ts/pre-tool-use/block-sleep-poll.test.ts +1 -1
  118. package/src/hooks/ts/session-start/load-core-context.ts +11 -8
  119. package/src/hooks/ts/session-start/session-start-worker-guard.test.ts +34 -2
  120. package/dist/auto-route-D6fW1Q8z.mjs +0 -3
  121. package/dist/config-Ddc4DIPk.mjs.map +0 -1
  122. package/dist/context-handover-cache-SFkWucuT.mjs.map +0 -1
  123. package/dist/daemon-BHQoEjt0.mjs +0 -18
  124. package/dist/daemon-vLtT3yaI.mjs.map +0 -1
  125. package/dist/embeddings-D0WOQpYR.mjs +0 -3
  126. package/dist/factory-CXFHwvcv.mjs.map +0 -1
  127. package/dist/factory-CnKsU6zX.mjs +0 -8
  128. package/dist/main-resolver-DrHtx8iW.mjs +0 -7
  129. package/dist/pai-home-UncxWxlX.mjs.map +0 -1
  130. package/dist/pai-marker-DXVpFsYz.mjs.map +0 -1
  131. package/dist/postgres-B2BEBT-J.mjs +0 -5
  132. package/dist/postgres-BxmyQHoA.mjs.map +0 -1
  133. package/dist/program-CfG1T_ko.mjs.map +0 -1
  134. package/dist/router-BK-hFeQ6.mjs +0 -3
  135. package/dist/run-ChlIbDJ0.mjs.map +0 -1
  136. package/dist/run-env-CQRnxNht.mjs.map +0 -1
  137. package/dist/runtime-paths-Bw3Jk8qJ.mjs +0 -52
  138. package/dist/runtime-paths-Bw3Jk8qJ.mjs.map +0 -1
  139. package/dist/zettelkasten-BRIaHzFm.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-DjZELvoA.mjs","names":[],"sources":["../src/notifications/types.ts","../src/tasks/types.ts","../src/config/json-store.ts","../src/config/yaml-store.ts","../src/config/main-config.ts","../src/daemon/config.ts"],"sourcesContent":["/**\n * types.ts — Unified Notification Framework type definitions\n *\n * Defines the channel registry, event routing, and configuration schema\n * for PAI's notification subsystem.\n */\n\n// ---------------------------------------------------------------------------\n// Channel identifiers\n// ---------------------------------------------------------------------------\n\nexport type ChannelId = \"ntfy\" | \"whatsapp\" | \"macos\" | \"voice\" | \"cli\";\n\n// ---------------------------------------------------------------------------\n// Notification event types\n// ---------------------------------------------------------------------------\n\n/**\n * The semantic type of a notification event.\n * Used to route events to the appropriate channels.\n */\nexport type NotificationEvent =\n | \"error\"\n | \"progress\"\n | \"completion\"\n | \"info\"\n | \"debug\";\n\n// ---------------------------------------------------------------------------\n// Notification mode\n// ---------------------------------------------------------------------------\n\n/**\n * The current notification mode.\n *\n * - \"auto\" — Use the per-event routing table (default)\n * - \"voice\" — All events go to voice (WhatsApp TTS)\n * - \"whatsapp\" — All events go to WhatsApp text\n * - \"ntfy\" — All events go to ntfy.sh\n * - \"macos\" — All events go to macOS notifications\n * - \"cli\" — All events go to CLI stdout only\n * - \"off\" — Suppress all notifications\n */\nexport type NotificationMode =\n | \"auto\"\n | \"voice\"\n | \"whatsapp\"\n | \"ntfy\"\n | \"macos\"\n | \"cli\"\n | \"off\";\n\n// ---------------------------------------------------------------------------\n// Per-channel configuration\n// ---------------------------------------------------------------------------\n\nexport interface NtfyChannelConfig {\n enabled: boolean;\n /** ntfy.sh topic URL, e.g. \"https://ntfy.sh/my-topic\" */\n url?: string;\n /** ntfy priority: min | low | default | high | urgent */\n priority?: \"min\" | \"low\" | \"default\" | \"high\" | \"urgent\";\n}\n\nexport interface WhatsAppChannelConfig {\n enabled: boolean;\n /** Optional recipient (phone, JID, or contact name). Omit for self-chat. */\n recipient?: string;\n}\n\nexport interface MacOsChannelConfig {\n enabled: boolean;\n}\n\nexport interface VoiceChannelConfig {\n enabled: boolean;\n /** Kokoro voice name, e.g. \"bm_george\", \"af_bella\". Default: \"bm_george\" */\n voiceName?: string;\n}\n\nexport interface CliChannelConfig {\n enabled: boolean;\n}\n\nexport interface ChannelConfigs {\n ntfy: NtfyChannelConfig;\n whatsapp: WhatsAppChannelConfig;\n macos: MacOsChannelConfig;\n voice: VoiceChannelConfig;\n cli: CliChannelConfig;\n}\n\n// ---------------------------------------------------------------------------\n// Routing table\n// ---------------------------------------------------------------------------\n\n/**\n * Maps each event type to the ordered list of channels that should receive it.\n * Only channels that are enabled in `channels` and present in this list are used.\n */\nexport type RoutingTable = {\n [K in NotificationEvent]: ChannelId[];\n};\n\nexport const DEFAULT_ROUTING: RoutingTable = {\n error: [\"whatsapp\", \"macos\", \"ntfy\", \"cli\"],\n completion: [\"whatsapp\", \"macos\", \"ntfy\", \"cli\"],\n info: [\"cli\"],\n progress: [\"cli\"],\n debug: [],\n};\n\n// ---------------------------------------------------------------------------\n// Top-level notification config (embedded in PaiDaemonConfig)\n// ---------------------------------------------------------------------------\n\nexport interface NotificationConfig {\n /** Current routing mode. Default: \"auto\" */\n mode: NotificationMode;\n /** Per-channel configuration */\n channels: ChannelConfigs;\n /** Event → channel routing (used in \"auto\" mode) */\n routing: RoutingTable;\n}\n\nexport const DEFAULT_CHANNELS: ChannelConfigs = {\n ntfy: {\n enabled: false,\n url: undefined,\n priority: \"default\",\n },\n whatsapp: {\n enabled: true,\n recipient: undefined,\n },\n macos: {\n enabled: true,\n },\n voice: {\n enabled: false,\n voiceName: \"bm_george\",\n },\n cli: {\n enabled: true,\n },\n};\n\nexport const DEFAULT_NOTIFICATION_CONFIG: NotificationConfig = {\n mode: \"auto\",\n channels: DEFAULT_CHANNELS,\n routing: DEFAULT_ROUTING,\n};\n\n// ---------------------------------------------------------------------------\n// Notification payload\n// ---------------------------------------------------------------------------\n\nexport interface NotificationPayload {\n /** Semantic event type — used for routing */\n event: NotificationEvent;\n /** The notification message body */\n message: string;\n /** Optional title (used by macOS, ntfy) */\n title?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Provider interface\n// ---------------------------------------------------------------------------\n\nexport interface NotificationProvider {\n readonly channelId: ChannelId;\n /**\n * Send a notification.\n * Returns true on success, false on failure (failure is non-fatal).\n */\n send(payload: NotificationPayload, config: NotificationConfig): Promise<boolean>;\n}\n\n// ---------------------------------------------------------------------------\n// Send result\n// ---------------------------------------------------------------------------\n\nexport interface SendResult {\n channelsAttempted: ChannelId[];\n channelsSucceeded: ChannelId[];\n channelsFailed: ChannelId[];\n mode: NotificationMode;\n}\n","/**\n * types.ts — Task Bus type definitions\n *\n * Defines the provider registry, ownership resolution, and configuration schema\n * for PAI's cross-session task subsystem.\n *\n * The task bus routes work between PAI sessions through an external tracker.\n * A session files a task; a routine reads it later and dispatches it to the\n * session that owns it — spawning one if none is running.\n *\n * See docs/task-bus.md for the architecture and its constraints.\n */\n\n// ---------------------------------------------------------------------------\n// Provider identifiers\n// ---------------------------------------------------------------------------\n\nexport type ProviderId = \"todoist\";\n\n// ---------------------------------------------------------------------------\n// Ownership\n// ---------------------------------------------------------------------------\n\n/**\n * Prefix marking a tracker label as a PAI ownership assertion.\n * A task labelled `pai:acme-api` is owned by the `acme-api` project.\n */\nexport const OWNER_LABEL_PREFIX = \"pai:\";\n\n/**\n * How a task's owner was determined. Recorded so the routine can explain\n * itself, and so a mis-resolution is diagnosable rather than silent.\n *\n * - \"label\" — an explicit `pai:<project>` label (authoritative)\n * - \"container\" — the enclosing sub-project name matched a PAI alias (fallback)\n * - \"none\" — unresolved; the task stays in the findings inbox\n */\nexport type OwnerSource = \"label\" | \"container\" | \"none\";\n\nexport interface TaskOwner {\n /** Resolved PAI project short name, e.g. \"acme-api\". Null when UNROUTED. */\n project: string | null;\n /** Absolute path to the project root. Null when UNROUTED. */\n rootPath: string | null;\n source: OwnerSource;\n /**\n * The raw string that resolution was attempted against, kept for diagnostics\n * when `source` is \"none\" — e.g. a \"Reading List 📚\" container matches no\n * PAI project, which is expected rather than a fault.\n */\n rawHint?: string;\n}\n\n/** An unresolved owner. UNROUTED is a normal state, not an error. */\nexport const UNROUTED: TaskOwner = {\n project: null,\n rootPath: null,\n source: \"none\",\n};\n\n// ---------------------------------------------------------------------------\n// Tasks\n// ---------------------------------------------------------------------------\n\nexport type TaskPriority = \"p1\" | \"p2\" | \"p3\" | \"p4\";\n\nexport interface Task {\n /** Provider-native task ID. Opaque; never parsed. */\n id: string;\n title: string;\n /**\n * Full procedure AND reasoning — enough that the task is actionable months\n * later, or by the user alone, without re-deriving anything. Enforced at\n * filing time rather than left to discipline.\n */\n body: string;\n owner: TaskOwner;\n /** ISO 8601 date or datetime. Null when the task has no due date. */\n due: string | null;\n /**\n * The tracker's own recurrence text, e.g. \"every day at 08:00\". Null for a\n * one-off.\n *\n * Kept verbatim rather than parsed into a rule because it is also the only\n * way to write a recurrence back: Todoist re-parses this string, and it is\n * what lets a due date be restored without destroying the recurrence.\n */\n recurrence?: string | null;\n priority: TaskPriority;\n labels: string[];\n /**\n * Stable reference to the artifact this task is about. Prefer a `hook://`\n * URL over a filesystem path — it survives renames and moves, and opens in\n * DEVONthink To Go on iOS.\n */\n sourceUrl?: string;\n /** True for organizational headers that cannot be completed. */\n isHeader?: boolean;\n}\n\n/** A task being filed. `owner` is a project short name, resolved on write. */\nexport interface NewTask {\n title: string;\n body: string;\n owner?: string | null;\n due?: string;\n priority?: TaskPriority;\n labels?: string[];\n sourceUrl?: string;\n /**\n * Sub-project to file into, created if absent.\n *\n * The convention is one sub-project per PAI project under the bus root. It\n * previously existed only in the shape of the data, so every session had to\n * re-derive it — and a session that inferred cautiously filed flat instead,\n * which is exactly the pile the convention prevents.\n */\n into?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Provider interface\n// ---------------------------------------------------------------------------\n\nexport interface ListOptions {\n /** Only tasks due on or before this ISO date. Omit for all open tasks. */\n dueBefore?: string;\n /** Restrict to one resolved owner. Omit for every owner. */\n owner?: string;\n /** Include tasks that resolved to UNROUTED. Default: true. */\n includeUnrouted?: boolean;\n limit?: number;\n}\n\nexport interface TaskProvider {\n readonly providerId: ProviderId;\n\n /**\n * False when no credential is configured. The bus degrades to a no-op\n * rather than failing — a user without a tracker still gets working PAI.\n */\n isConfigured(): boolean;\n\n listOpen(opts: ListOptions): Promise<Task[]>;\n add(task: NewTask): Promise<Task>;\n complete(id: string): Promise<void>;\n\n /**\n * Rewrite a task's due date through the tracker's natural-language field.\n *\n * Optional, and deliberately expressed as a string rather than a date: a\n * recurring task's schedule and its next occurrence are the same field, so\n * moving the date without the rule silently downgrades a routine to a one-off.\n * A provider that cannot express both at once should not offer this.\n */\n setDue?(id: string, dueString: string): Promise<void>;\n\n /**\n * Sub-projects under the bus root — the set of addresses a task can be filed\n * against, one per session.\n *\n * Optional because it is not universal: a tracker may address work by tag or\n * list rather than by nested project, and forcing a nesting concept onto one\n * that has none would mean faking it. A provider without these simply does\n * not offer session-scoped inboxes, and callers say so rather than failing.\n */\n listSubProjects?(): Promise<Array<{ id: string; name: string }>>;\n findOrCreateSubProject?(name: string): Promise<{ id: string; created: boolean }>;\n\n /**\n * The comment thread on a task, oldest first.\n *\n * Optional because not every tracker has threaded comments. Where it exists,\n * the thread is usually where the reasoning lives — the question, the answer,\n * the correction — and completing the task takes it out of view. That is what\n * the archive exists to keep.\n */\n listComments?(taskId: string): Promise<Array<{ id: string; content: string; postedAt?: string }>>;\n\n /**\n * One task by id, whether open or completed.\n *\n * Needed because archiving runs at or after completion, and a completed task\n * is gone from `listOpen` — which is exactly the moment its discussion stops\n * being visible and most needs keeping.\n */\n getTask?(id: string): Promise<Task | null>;\n}\n\n// ---------------------------------------------------------------------------\n// Configuration\n// ---------------------------------------------------------------------------\n\nexport interface TodoistProviderConfig {\n enabled: boolean;\n /**\n * API token. Resolution order is apiKey → TODOIST_API_KEY env → unconfigured.\n *\n * Never read this from another tool's config file. PAI ships as a product;\n * scraping ~/.claude.json for a key belonging to the Todoist MCP is not\n * acceptable even though the key is sitting there.\n */\n apiKey?: string;\n /**\n * Tracker project ID that roots the bus (the \"Claude 🤖\" project).\n *\n * Stored as an ID, never a name. Todoist's project search silently returns\n * zero results for names containing emoji — resolving by name would report\n * \"no tasks\" instead of failing, which is the exact class of silent failure\n * this subsystem exists to surface.\n */\n rootProjectId?: string;\n /** Section ID for the findings inbox. Tasks land here when UNROUTED. */\n findingsSectionId?: string;\n}\n\nexport interface TaskConfig {\n /** Master switch. When false the bus is inert. */\n enabled: boolean;\n providers: {\n todoist: TodoistProviderConfig;\n };\n /**\n * Dispatch work to the owning session automatically, spawning one if absent.\n * Requires AIBroker. When false — or when AIBroker is unavailable — PAI\n * reports which project owns each task and leaves acting to the user.\n */\n autoDispatch: boolean;\n\n /**\n * Seconds AIBroker may spend on a single dispatch, spawn included.\n *\n * Passed down to the transport so both sides share one deadline. Raise it on\n * a loaded machine where sessions are slow to start accepting input.\n */\n dispatchTimeoutSecs?: number;\n\n /**\n * Project a task goes to when it carries the bare `pai` marker and its\n * location says nothing — an Inbox capture, typically.\n *\n * This is the one thing a task's location cannot express: \"an AI should take\n * this, and I do not know which one yet\". Everything else is answered by the\n * project the task sits in.\n *\n * Unset means such a task stays UNROUTED, which is a legitimate choice: it\n * then surfaces in the findings inbox for triage rather than being guessed at.\n */\n defaultOwner?: string;\n}\n\nexport const DEFAULT_TASK_CONFIG: TaskConfig = {\n enabled: false,\n providers: {\n todoist: {\n enabled: false,\n },\n },\n autoDispatch: false,\n};\n\n// ---------------------------------------------------------------------------\n// Dispatch results\n// ---------------------------------------------------------------------------\n\n/**\n * What happened to one task during a dispatch run.\n *\n * - \"delivered\" — sent to an already-running session, and confirmed submitted\n * - \"queued\" — typed into a live session that was mid-turn, so submission\n * could not be confirmed inside the window. This is delivery:\n * Claude Code holds typed input until the current turn ends.\n * Never retried — the text is already in the input box, so a\n * second attempt is a second copy, not a retry. One trigger\n * arrived three times on 2026-08-01 for exactly that reason.\n * - \"spawned\" — none running; one was launched, came up, and received it\n * - \"unrouted\" — no owner resolved; left in the findings inbox\n * - \"unlaunchable\" — an owner resolved but no PAI alias exists to launch it\n * - \"unreachable\" — a session was launched but never became ready to accept input\n * - \"skipped\" — autoDispatch is off, or no transport; reported only\n *\n * `unlaunchable` and `unreachable` are distinct because the fixes differ:\n * the first is a setup gap (register an alias), the second is a runtime\n * failure (find out why the session did not come up). Collapsing them would\n * send users looking in the wrong place.\n *\n * None of these are errors. A task that could not be delivered is a routing\n * result to report, not an exception to throw.\n */\nexport type DispatchOutcome =\n | \"delivered\"\n | \"queued\"\n | \"spawned\"\n | \"unrouted\"\n | \"unlaunchable\"\n | \"unreachable\"\n | \"skipped\";\n\nexport interface DispatchResult {\n task: Task;\n outcome: DispatchOutcome;\n /** Session the task reached, when it reached one. */\n session?: string;\n /** Why the task did not reach a session. Present on failure outcomes. */\n reason?: string;\n}\n","/**\n * json-store.ts — read/write JSON config files without destroying them\n *\n * The failure this exists to prevent:\n *\n * try { return JSON.parse(read(path)); } catch { return {}; }\n * ... later ...\n * write(path, JSON.stringify(ourData));\n *\n * An unreadable file becomes an empty object, and the next write makes that\n * permanent. Silently, exit code 0. This shape appeared three times in this\n * repo against three different files, and twice in AIBroker.\n *\n * The distinction that matters is between *missing* and *unreadable*:\n *\n * missing — legitimate first run. Start fresh; writing is safe.\n * unreadable — the file exists and we could not parse it. Those bytes are\n * the only copy of something. Never overwrite them.\n *\n * Collapsing the second into the first is the bug.\n *\n * NOT everything deserves this guard. For a transient buffer — an undelivered\n * message queue, a cache — starting fresh IS the correct recovery, and\n * refusing to write would disable the feature permanently. Use `writeJsonAtomic`\n * alone there: it still prevents a crash from truncating a good file, without\n * blocking recovery. Reserve `readJsonStrict` for data a user cannot rebuild.\n */\n\nimport {\n existsSync,\n readFileSync,\n writeFileSync,\n copyFileSync,\n renameSync,\n unlinkSync,\n mkdirSync,\n chmodSync,\n} from \"node:fs\";\nimport { dirname } from \"node:path\";\n\n/**\n * Read a JSON file, distinguishing \"absent\" from \"damaged\".\n *\n * @param path file to read\n * @param label how to name it to the user, e.g. \"~/.claude.json\"\n * @throws if the file exists but cannot be read or parsed\n */\nexport function readJsonStrict(path: string, label = path): Record<string, unknown> {\n if (!existsSync(path)) return {};\n\n let raw: string;\n try {\n raw = readFileSync(path, \"utf8\");\n } catch (e) {\n throw new Error(\n `Could not read ${label}: ${e instanceof Error ? e.message : String(e)}\\n` +\n `Refusing to continue — writing now would replace its contents with ours alone.`\n );\n }\n\n try {\n return JSON.parse(raw) as Record<string, unknown>;\n } catch (e) {\n throw new Error(\n `${label} exists but is not valid JSON: ${e instanceof Error ? e.message : String(e)}\\n` +\n `Refusing to continue — overwriting it would destroy whatever it holds.\\n` +\n `Repair the file, or move it aside and re-run this command.`\n );\n }\n}\n\n/**\n * Leaf values that mean \"type word\", not data.\n *\n * A config whose top-level keys map to bare type words is a serialized schema,\n * not a configuration — the exact shape found over the live config on\n * 2026-09-18 (399 bytes: `socketPath: string`, `indexIntervalSecs: int`, …).\n * No real config carries three of these at its top level; a dump carries\n * nothing else.\n */\nconst SCHEMA_TYPE_WORDS = new Set([\n \"string\", \"int\", \"integer\", \"number\", \"bool\", \"boolean\",\n \"float\", \"double\", \"object\", \"array\", \"any\", \"unknown\",\n]);\n\nfunction schemaDumpHits(data: Record<string, unknown>): number {\n let hits = 0;\n for (const v of Object.values(data)) {\n if (typeof v === \"string\" && SCHEMA_TYPE_WORDS.has(v.trim())) hits += 1;\n }\n return hits;\n}\n\n/**\n * Write JSON without risking the existing file.\n *\n * Keeps a `.bak-pai` copy of the previous contents, then writes to a temp file\n * and renames. Rename is atomic within a filesystem, so a crash mid-write\n * leaves the original intact rather than truncated — which is how these files\n * become corrupt in the first place.\n */\nexport function writeJsonAtomic(\n path: string,\n data: Record<string, unknown>,\n opts: { backup?: boolean; label?: string } = {}\n): void {\n const { backup = true, label = path } = opts;\n if (schemaDumpHits(data) >= 3) {\n throw new Error(\n `${label}: refusing to write — the object looks like a type schema, not values ` +\n `(several top-level keys map to bare type words). That is the corruption ` +\n `signature of 2026-09-18: the caller serialized the schema instead of the ` +\n `config. Nothing was written.`\n );\n }\n const serialized = JSON.stringify(data, null, 2) + \"\\n\";\n\n const dir = dirname(path);\n if (!existsSync(dir)) mkdirSync(dir, { recursive: true });\n\n if (backup && existsSync(path)) {\n try {\n copyFileSync(path, `${path}.bak-pai`);\n chmodSync(`${path}.bak-pai`, 0o600);\n } catch (e) {\n throw new Error(\n `Could not back up ${label}: ${e instanceof Error ? e.message : String(e)}\\n` +\n `Refusing to write without a backup.`\n );\n }\n }\n\n const tmp = `${path}.tmp-pai-${process.pid}`;\n try {\n writeFileSync(tmp, serialized, { encoding: \"utf8\", mode: 0o600 });\n renameSync(tmp, path);\n chmodSync(path, 0o600);\n } catch (e) {\n try { if (existsSync(tmp)) unlinkSync(tmp); } catch { /* best effort */ }\n throw new Error(\n `Failed to write ${label}: ${e instanceof Error ? e.message : String(e)}\\n` +\n `The original is unchanged.`\n );\n }\n}\n","/**\n * yaml-store.ts — generic, comment-preserving YAML file helpers shared by\n * every PAI config file that has a YAML form (config.yaml, voices.yaml;\n * workers.yaml keeps its own writer in workers-config.ts because it needs\n * provider-specific key-quoting, but its atomic-write tail is this module's\n * writeYamlFileAtomic).\n */\n\nimport {\n existsSync,\n readFileSync,\n writeFileSync,\n copyFileSync,\n renameSync,\n unlinkSync,\n mkdirSync,\n chmodSync,\n} from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { Document, YAMLMap, parseDocument, type Node, type Pair, type Scalar } from \"yaml\";\n\nexport class YamlStoreError extends Error {}\n\n/**\n * Validate `text` parses as YAML, back up any existing file to `.bak-pai`,\n * then write via temp file + rename (atomic within a filesystem) at mode\n * 0600 — every PAI-owned YAML file can carry secrets, key or no key.\n */\nexport function writeYamlFileAtomic(path: string, text: string, opts: { label?: string } = {}): void {\n const label = opts.label ?? path;\n const parsed = parseDocument(text);\n if (parsed.errors.length) {\n throw new YamlStoreError(`refusing to write ${label}: ${parsed.errors[0].message} (previous file left unchanged)`);\n }\n\n const dir = dirname(path);\n if (!existsSync(dir)) mkdirSync(dir, { recursive: true });\n if (existsSync(path)) {\n try {\n copyFileSync(path, `${path}.bak-pai`);\n } catch (e) {\n throw new YamlStoreError(\n `Could not back up ${label}: ${e instanceof Error ? e.message : String(e)}\\nRefusing to write without a backup.`\n );\n }\n }\n const tmp = `${path}.tmp-pai-${process.pid}`;\n try {\n writeFileSync(tmp, text, { encoding: \"utf8\", mode: 0o600 });\n renameSync(tmp, path);\n chmodSync(path, 0o600);\n } catch (e) {\n try {\n if (existsSync(tmp)) unlinkSync(tmp);\n } catch {\n /* best effort */\n }\n throw new YamlStoreError(`Failed to write ${label}: ${e instanceof Error ? e.message : String(e)}`);\n }\n}\n\n/** Deep-equal for plain JSON-shaped values (objects/arrays/scalars). */\nexport function deepEqualJson(a: unknown, b: unknown): boolean {\n return JSON.stringify(a) === JSON.stringify(b);\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/**\n * Apply the diff between `before` and `after` (arbitrary nested plain JSON\n * objects) onto a YAML Document, touching only the leaves/keys that actually\n * changed — this is what lets hand-written comments elsewhere in the file\n * survive a `set`/`unset`. Arrays and non-object values are replaced\n * wholesale when they differ; only plain objects are diffed key by key.\n */\nexport function syncPlainObjectIntoYamlDoc(\n doc: Document,\n before: unknown,\n after: unknown,\n path: (string | number)[] = []\n): void {\n if (isPlainObject(after) && isPlainObject(before)) {\n for (const key of Object.keys(after)) {\n syncPlainObjectIntoYamlDoc(doc, before[key], after[key], [...path, key]);\n }\n for (const key of Object.keys(before)) {\n if (!(key in after)) doc.deleteIn([...path, key]);\n }\n return;\n }\n if (after === undefined) {\n if (before !== undefined) doc.deleteIn(path);\n return;\n }\n if (!deepEqualJson(before, after)) {\n doc.setIn(path, after);\n }\n}\n\n/**\n * Attach a `# text` comment directly above the key at `path` inside a YAML\n * Document — used for the annotated section headers `pai config yaml`\n * writes. No-op if the path does not resolve to a mapping entry (e.g. the\n * key was omitted from the document).\n */\nexport function setYamlKeyComment(doc: Document, path: (string | number)[], text: string): void {\n const parentPath = path.slice(0, -1);\n const lastKey = path[path.length - 1];\n const parent = parentPath.length ? doc.getIn(parentPath, true) : doc.contents;\n if (!(parent instanceof YAMLMap)) return;\n const pair = (parent.items as Pair[]).find((p) => (p.key as Scalar)?.value === lastKey);\n if (pair) {\n (pair.key as Node & { commentBefore?: string }).commentBefore = ` ${text}`;\n }\n}\n","/**\n * main-config.ts — the dual-format (config.yaml / config.json) engine behind\n * the main PAI config file. Deliberately has NO dependency on\n * src/daemon/config.ts (which owns path resolution, PaiDaemonConfig and\n * DEFAULTS) so that module can import this one for loadConfig() without a\n * cycle; every path this module touches is passed in explicitly.\n *\n * Precedence, same shape as workers.yaml/workers/config.ts: config.yaml wins\n * when it exists, config.json otherwise. `pai config yaml` (see\n * src/cli/commands/config.ts) performs the one-time JSON→YAML conversion;\n * every writer that goes through readMainConfigRaw/writeMainConfigRaw (see\n * src/daemon/config.ts) keeps working unmodified either way.\n */\n\nimport { existsSync, readFileSync, renameSync, chmodSync } from \"node:fs\";\nimport { dirname, join, basename } from \"node:path\";\nimport { Document, parseDocument } from \"yaml\";\nimport { readJsonStrict, writeJsonAtomic } from \"./json-store.js\";\nimport { writeYamlFileAtomic, syncPlainObjectIntoYamlDoc, deepEqualJson, setYamlKeyComment } from \"./yaml-store.js\";\n\nexport class MainConfigError extends Error {}\n\n/** The config.yaml sibling of a given config.json path (same directory). */\nexport function yamlSiblingPath(jsonPath: string): string {\n return join(dirname(jsonPath), \"config.yaml\");\n}\n\n/** The path a user should be pointed at: config.yaml when it exists (same\n * precedence as readDualFormatConfigRaw), else config.json. */\nexport function resolvedMainConfigPath(jsonPath: string, yamlPath: string = yamlSiblingPath(jsonPath)): string {\n return existsSync(yamlPath) ? yamlPath : jsonPath;\n}\n\n/**\n * Read the raw main config: config.yaml if it exists, else config.json\n * (readJsonStrict — missing is `{}`, damaged throws), matching\n * readWorkersSection's precedence for workers.yaml/JSON.\n */\nexport function readDualFormatConfigRaw(jsonPath: string, yamlPath: string = yamlSiblingPath(jsonPath)): Record<string, unknown> {\n if (existsSync(yamlPath)) {\n let text: string;\n try {\n text = readFileSync(yamlPath, \"utf8\");\n } catch (e) {\n throw new MainConfigError(`Could not read ${yamlPath}: ${e instanceof Error ? e.message : String(e)}`);\n }\n const doc = parseDocument(text);\n if (doc.errors.length) {\n throw new MainConfigError(`${yamlPath}: ${doc.errors[0].message}`);\n }\n const parsed = doc.toJS();\n if (parsed === null || parsed === undefined) return {};\n if (typeof parsed !== \"object\" || Array.isArray(parsed)) {\n throw new MainConfigError(`${yamlPath}: top level must be a mapping`);\n }\n return parsed as Record<string, unknown>;\n }\n return readJsonStrict(jsonPath, jsonPath);\n}\n\n/**\n * Write the raw main config back: comment-preserving diff-sync into\n * config.yaml when it exists, else plain writeJsonAtomic to config.json —\n * this is the one seam every writer of the main config (CLI commands,\n * identity, notifications, setup, workers) routes through, so a config.yaml\n * on disk is honored no matter which of them made the change.\n */\nexport function writeDualFormatConfigRaw(\n jsonPath: string,\n raw: Record<string, unknown>,\n yamlPath: string = yamlSiblingPath(jsonPath)\n): void {\n if (existsSync(yamlPath)) {\n let text: string;\n try {\n text = readFileSync(yamlPath, \"utf8\");\n } catch (e) {\n throw new MainConfigError(`Could not read ${yamlPath}: ${e instanceof Error ? e.message : String(e)}`);\n }\n const doc = parseDocument(text);\n if (doc.errors.length) {\n throw new MainConfigError(`${yamlPath}: ${doc.errors[0].message}`);\n }\n const before = (doc.toJS() ?? {}) as Record<string, unknown>;\n syncPlainObjectIntoYamlDoc(doc, before, raw);\n try {\n writeYamlFileAtomic(yamlPath, String(doc), { label: yamlPath });\n } catch (e) {\n throw new MainConfigError(e instanceof Error ? e.message : String(e));\n }\n return;\n }\n writeJsonAtomic(jsonPath, raw, { label: jsonPath });\n}\n\n// ---------------------------------------------------------------------------\n// JSON → YAML migration (\"pai config yaml\")\n// ---------------------------------------------------------------------------\n\n/**\n * Short annotation for every top-level PaiDaemonConfig field, shown as a `#`\n * comment above the field in the generated config.yaml. Mirrors (and must be\n * kept in sync with) the doc comments on PaiDaemonConfig in\n * src/daemon/config.ts — kept as a separate short-form table rather than\n * parsed from the TS source at runtime.\n */\nexport const MAIN_CONFIG_SECTION_COMMENTS: Record<string, string> = {\n socketPath: \"Unix Domain Socket path for daemon IPC.\",\n indexIntervalSecs: \"How often the daemon re-indexes changed files, in seconds.\",\n embedIntervalSecs: \"How often the daemon runs the embedding pass, in seconds.\",\n embedOnStartup:\n \"Run an embed pass 60s after daemon start. Off by default: with a large backlog it makes every restart a CPU storm.\",\n passPriority: 'Priority of scheduled index/embed passes: \"background\" (default; low-priority child process) or \"normal\" (in-process).',\n maintenanceHour: \"Local hour (0-23) to anchor the recurring index/embed cycle to, so maintenance runs in a fixed window.\",\n storageBackend: 'Storage backend: \"sqlite\" (default) or \"postgres\".',\n postgres: 'PostgreSQL connection settings, used when storageBackend is \"postgres\".',\n embeddingModel: \"Embedding model name, used for semantic/hybrid search.\",\n embedding:\n 'Embedding backend: backend (\"transformers-cpu-q8\" or \"ollama-f16\"), model, ollama.baseUrl. Switching needs `pai memory reembed`.',\n logLevel: \"Daemon log level: debug, info, warn, or error.\",\n vaultPath: \"Obsidian vault root path for zettelkasten indexing, if any.\",\n vaultProjectId: \"Registry project_id used for vault chunks in memory_chunks. Default: auto-detected.\",\n notifications: \"Notification subsystem configuration.\",\n search: \"Search defaults, applied when an MCP tool or CLI call doesn't specify one.\",\n tasks: \"Task bus — optional external tracker for cross-session work.\",\n identity:\n 'Who \"me\" is — addresses that count as the user\\'s own. Empty by default and never guessed: nothing is self-addressed until this is set.',\n workers:\n \"Non-provider worker settings (pane, routing, tree, cache keepalive, fallback). Providers/classes/mcp_sets live in workers.yaml, not here.\",\n};\n\n/** Keys whose leading-underscore string value is a JSON stand-in for a\n * comment (e.g. `\"_comment\": \"...\"`, `\"_deliverToNote\": \"...\"`). Stripped\n * from the generated YAML and re-attached as a real `#` comment above the\n * nearest remaining sibling key in the same object. */\nfunction isCommentKey(key: string): boolean {\n return key.startsWith(\"_\");\n}\n\ninterface CollectedComment {\n path: (string | number)[];\n text: string;\n}\n\n/** Recursively strip `_`-prefixed comment keys out of a plain JSON value,\n * returning the cleaned value plus where each stripped comment belongs. */\nfunction stripUnderscoreComments(value: unknown, path: (string | number)[] = []): { cleaned: unknown; comments: CollectedComment[] } {\n if (Array.isArray(value)) {\n const comments: CollectedComment[] = [];\n const cleaned = value.map((v, i) => {\n const r = stripUnderscoreComments(v, [...path, i]);\n comments.push(...r.comments);\n return r.cleaned;\n });\n return { cleaned, comments };\n }\n if (typeof value === \"object\" && value !== null) {\n const obj = value as Record<string, unknown>;\n const cleaned: Record<string, unknown> = {};\n const comments: CollectedComment[] = [];\n const localComments: string[] = [];\n for (const [k, v] of Object.entries(obj)) {\n if (isCommentKey(k)) {\n if (typeof v === \"string\" && v.trim()) localComments.push(v.trim());\n continue;\n }\n const r = stripUnderscoreComments(v, [...path, k]);\n cleaned[k] = r.cleaned;\n comments.push(...r.comments);\n }\n // Attach every local comment above the first remaining key in this\n // object (in source order) — good enough for the JSON-workaround shape\n // this exists to convert (a `_comment` sibling explaining the object).\n const firstKey = Object.keys(cleaned)[0];\n if (localComments.length && firstKey !== undefined) {\n comments.unshift({ path: [...path, firstKey], text: localComments.join(\" \") });\n }\n return { cleaned, comments };\n }\n return { cleaned: value, comments: [] };\n}\n\nexport interface MainConfigMigrateResult {\n yamlPath: string;\n yamlText: string;\n /** Path the pre-migration JSON was renamed to; null on a dry run. */\n backupPath: string | null;\n dryRun: boolean;\n}\n\n/**\n * `pai config yaml`: convert config.json to config.yaml. Strips `_`-prefixed\n * JSON-comment-workaround keys into real `#` comments, adds a short\n * annotation above every top-level section (MAIN_CONFIG_SECTION_COMMENTS),\n * verifies the generated YAML re-parses to the exact same data before\n * writing anything, then renames the JSON aside to\n * `config.json.migrated-<YYYY-MM-DD>` (never deleted). Refuses when\n * config.yaml already exists unless `force`. `dryRun` computes and returns\n * the would-be YAML text without touching either file.\n */\nexport function migrateMainConfigToYaml(\n jsonPath: string,\n opts: { dryRun?: boolean; force?: boolean; yamlPath?: string; sectionComments?: Record<string, string> } = {}\n): MainConfigMigrateResult {\n const yamlPath = opts.yamlPath ?? yamlSiblingPath(jsonPath);\n if (existsSync(yamlPath) && !opts.force) {\n throw new MainConfigError(`${yamlPath} already exists — edit it directly, or pass --force to regenerate it from ${jsonPath}`);\n }\n if (!existsSync(jsonPath)) {\n throw new MainConfigError(`${jsonPath} does not exist — nothing to migrate`);\n }\n\n const raw = readJsonStrict(jsonPath, jsonPath);\n const { cleaned, comments } = stripUnderscoreComments(raw);\n const cleanedObj = cleaned as Record<string, unknown>;\n\n const doc = new Document(cleanedObj);\n const sectionComments = opts.sectionComments ?? MAIN_CONFIG_SECTION_COMMENTS;\n for (const [key, text] of Object.entries(sectionComments)) {\n if (key in cleanedObj) setYamlKeyComment(doc, [key], text);\n }\n for (const c of comments) {\n setYamlKeyComment(doc, c.path, c.text);\n }\n const yamlText = String(doc);\n\n // Round-trip check: the generated YAML must re-parse to exactly the data\n // it was built from before anything is written or renamed.\n const reparsed = parseDocument(yamlText).toJS();\n if (!deepEqualJson(reparsed, cleanedObj)) {\n throw new MainConfigError(\n `${yamlPath}: generated YAML does not re-parse to the same data as ${jsonPath} — aborting, nothing written`\n );\n }\n\n if (opts.dryRun) {\n return { yamlPath, yamlText, backupPath: null, dryRun: true };\n }\n\n writeYamlFileAtomic(yamlPath, yamlText, { label: yamlPath });\n\n const stamp = new Date().toISOString().slice(0, 10);\n const backupPath = join(dirname(jsonPath), `${basename(jsonPath)}.migrated-${stamp}`);\n renameSync(jsonPath, backupPath);\n chmodSync(backupPath, 0o600);\n\n return { yamlPath, yamlText, backupPath, dryRun: false };\n}\n","/**\n * config.ts — Configuration loader for PAI Daemon\n *\n * Loads config from ~/.claude/pai/config.json (the pre-2026-09-19 location\n * was ~/.config/pai/config.json, briefly ~/.claude/pai.json in between —\n * see paiConfigFilePath/migrateConfigFile).\n * Deep-merges with defaults so partial configs work fine.\n * Expands ~ in path values at runtime.\n */\n\nimport { existsSync, mkdirSync, writeFileSync, chmodSync, readdirSync } from \"node:fs\";\nimport { homedir, userInfo } from \"node:os\";\nimport { join, dirname, basename } from \"node:path\";\nimport type { NotificationConfig } from \"../notifications/types.js\";\nimport { DEFAULT_NOTIFICATION_CONFIG } from \"../notifications/types.js\";\nimport type { TaskConfig } from \"../tasks/types.js\";\nimport { DEFAULT_TASK_CONFIG } from \"../tasks/types.js\";\nimport { paiSocketPath } from \"../runtime-paths.js\";\nimport {\n paiHomePath,\n resolvePaiFile,\n migratePaiFile,\n PaiFileMigrationError,\n type MigrateFileResult,\n} from \"../config/pai-home.js\";\nimport {\n yamlSiblingPath,\n readDualFormatConfigRaw,\n writeDualFormatConfigRaw,\n MainConfigError,\n} from \"../config/main-config.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface SearchConfig {\n /** Default search mode: 'keyword', 'semantic', or 'hybrid'. Default: 'keyword'. */\n mode: \"keyword\" | \"semantic\" | \"hybrid\";\n /** Enable cross-encoder reranking by default. Default: true. */\n rerank: boolean;\n /** Recency boost half-life in days. 0 = off. Default: 90. */\n recencyBoostDays: number;\n /** Default max results. Default: 10. */\n defaultLimit: number;\n /** Default snippet length for MCP results. Default: 200. */\n snippetLength: number;\n}\n\nexport interface PostgresConfig {\n /** Connection string — if set, overrides individual host/port/etc. fields */\n connectionString?: string;\n /** Postgres host (default: \"localhost\") */\n host?: string;\n /** Postgres port (default: 5432) */\n port?: number;\n /** Postgres database name (default: \"pai\") */\n database?: string;\n /** Postgres user (default: \"pai\") */\n user?: string;\n /** Postgres password (default: \"pai\") */\n password?: string;\n /** Maximum pool connections (default: 5) */\n maxConnections?: number;\n /** Connection timeout in ms (default: 5000) */\n connectionTimeoutMs?: number;\n}\n\n/**\n * Idle-triggered prompt-cache keepalive for interactive Claude Code sessions\n * (see docs/cache-keepalive.md, \"Interactive sessions\"). Distinct from\n * `workers.cacheKeepaliveSecs` (src/workers/config.ts), which re-arms a\n * *worker provider's* cache via trivial worker spawns on a fixed timer: this\n * beats a live interactive session only when it has actually gone idle long\n * enough to risk its 1h ephemeral cache expiring, and only within working\n * hours — a fixed timer would beat while the user is active (no-op, wasted\n * quota) or overnight (never pays back before the next real prompt anyway).\n */\nexport interface SessionsCacheKeepaliveConfig {\n /** Off by default — arming it is the operator's explicit call. */\n enabled: boolean;\n /** Beat a session once it has been idle at least this long. Must be < the\n * provider's cache TTL (60 for the 1h ephemeral cache) or the beat is too\n * late to matter. */\n idleMinutes: number;\n /** Cap on consecutive beats per idle stretch; resets when the user prompts\n * the session again for real (not with the keepalive word itself). */\n maxBeats: number;\n /** Local time window \"HH:MM-HH:MM\" outside which no beats are sent. */\n activeHours: string;\n /** Skip sessions whose context is too small to be worth a beat. */\n minContextTokens: number;\n /** The exact word typed into the session; kept to one word so the\n * UserPromptSubmit hook can recognise it and answer minimally. */\n prompt: string;\n}\n\nexport interface SessionsConfig {\n cacheKeepalive: SessionsCacheKeepaliveConfig;\n}\n\nexport interface EmbeddingConfig {\n /** Backend id: \"transformers-cpu-q8\" (default, in-process) or \"ollama-f16\". */\n backend: string;\n /** Model name for the backend. Ollama: the model name on the server\n * (default \"arctic-embed-m-v1.5-f16\"). Unset for transformers-cpu-q8,\n * which uses embeddingModel. */\n model?: string;\n ollama: { baseUrl: string };\n}\n\nexport interface DashboardConfig {\n /** Serve the read-only status dashboard. Default: true. */\n enabled: boolean;\n /** TCP port. Default: 8770 (8765-8768 are taken by other local services). */\n port: number;\n /** Bind address. Default \"127.0.0.1\"; add the tailnet IP to reach it from a phone. */\n bind: string;\n}\n\nexport interface PaiDaemonConfig {\n /** Unix Domain Socket path for IPC */\n socketPath: string;\n\n /** Index schedule interval in seconds (default: 300 = 5 minutes) */\n indexIntervalSecs: number;\n\n /** Embedding schedule interval in seconds (default: 600 = 10 minutes) */\n embedIntervalSecs: number;\n /** Run an embed pass 60s after daemon start. Off by default: with a large\n * backlog it makes every restart a CPU storm, and it ignores the interval. */\n embedOnStartup: boolean;\n\n /** Local hour (0-23) to anchor the recurring index/embed cycle to. When unset,\n * the cycle is anchored to daemon start, so a daytime restart pins every\n * later pass to daytime too — a 24h interval does not by itself mean \"at\n * night\". Set this to run maintenance in a fixed window regardless of when\n * the machine last booted. */\n maintenanceHour?: number;\n\n /** Priority of the scheduled index/embed passes. \"background\" (default) runs\n * them in a child under `taskpolicy -b nice -n 19` (macOS) or\n * `nice -n 19 ionice -c3` (Linux); the daemon itself, which serves MCP,\n * keeps normal priority. \"normal\" runs them in-process. */\n passPriority: \"background\" | \"normal\";\n\n /** Storage backend: \"sqlite\" (default) or \"postgres\" */\n storageBackend: \"sqlite\" | \"postgres\";\n\n /** PostgreSQL connection config (used when storageBackend = \"postgres\") */\n postgres?: PostgresConfig;\n\n /** Embedding model name (used for semantic/hybrid search) */\n embeddingModel: string;\n\n /** Embedding backend selection (see src/memory/backends/). */\n embedding: EmbeddingConfig;\n\n /** Log level */\n logLevel: \"debug\" | \"info\" | \"warn\" | \"error\";\n\n /** Obsidian vault root path for zettelkasten indexing. If set, vault indexing runs alongside project indexing. */\n vaultPath?: string;\n\n /** Registry project_id to use for vault chunks in memory_chunks. Default: auto-detected. */\n vaultProjectId?: number;\n\n /** Notification subsystem configuration */\n notifications: NotificationConfig;\n\n /** Search defaults — applied when MCP tool or CLI doesn't specify a value */\n search: SearchConfig;\n\n /** Task bus — optional external tracker for cross-session work */\n tasks: TaskConfig;\n\n /** Who \"me\" is — addresses that count as the user's own. */\n identity: IdentityConfig;\n\n /** Interactive-session settings (currently just the cache keepalive). */\n sessions: SessionsConfig;\n\n /** Read-only memory status dashboard (src/daemon/dashboard.ts). */\n dashboard: DashboardConfig;\n}\n\n/**\n * The user's own identity, for anything that delivers back to them.\n *\n * This exists so \"my own address\" is a fact the system can check rather than\n * something a model infers from context. An assistant deciding on the spot\n * whether an address looks like the user's is exactly the judgement that should\n * not be re-made per message.\n *\n * Empty by default and never guessed at install time: an empty `selfEmails`\n * means nothing is self-addressed, so anything reading this fails closed.\n */\nexport interface IdentityConfig {\n /**\n * Where digests and \"mail me X\" requests are delivered.\n *\n * Must be a mailbox separate from the account doing the sending. Gmail files\n * a message sent from an account to itself — or to one of its own domain\n * aliases — under Sent only, and it never reaches the inbox. The send reports\n * success, so this fails silently and looks exactly like delivery. Observed\n * 2026-08-01: owner@example.ch → owner@example.de, sent fine, invisible.\n *\n * Where a separate mailbox is not available, deliver by writing the message\n * and adding the INBOX label to it rather than relying on the send path.\n */\n deliverTo?: string;\n\n /**\n * Every address that counts as the user's own.\n *\n * Used as an allowlist by anything that may act without review — outbound\n * mail being the case that motivated it. Membership is the whole test: an\n * address that is not listed is not the user's, however similar it looks.\n * Plus-aliases and domain aliases must be listed explicitly rather than\n * pattern-matched, because the patterns that would match them also match\n * addresses belonging to other people.\n */\n selfEmails: string[];\n\n /** The account used to send on the user's behalf, when one is configured. */\n sendingAccount?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Per-user Postgres isolation\n// ---------------------------------------------------------------------------\n\n/** Derive a per-user Postgres database name: pai_<username> */\nfunction perUserDbName(): string {\n const username = userInfo().username;\n // Sanitize: only allow alphanumeric and underscore for Postgres identifiers\n const safe = username.replace(/[^a-zA-Z0-9_]/g, \"_\").toLowerCase();\n return `pai_${safe}`;\n}\n\n/** Derive the per-user connection string */\nfunction perUserConnectionString(): string {\n const db = perUserDbName();\n return `postgresql://pai:pai@localhost:5432/${db}`;\n}\n\n// ---------------------------------------------------------------------------\n// Defaults\n// ---------------------------------------------------------------------------\n\n/**\n * idleMinutes=50 sits under the 60-minute ephemeral-1h TTL with margin for\n * scheduler jitter; maxBeats=6 (~5h of coverage at one beat per idle stretch)\n * and activeHours 08:00-22:00 keep an unattended overnight machine from\n * beating all night for a session nobody will return to before the cache\n * would have expired anyway.\n */\nexport const DEFAULT_SESSIONS_CACHE_KEEPALIVE: SessionsCacheKeepaliveConfig = {\n enabled: false,\n idleMinutes: 50,\n maxBeats: 6,\n activeHours: \"08:00-22:00\",\n minContextTokens: 20_000,\n prompt: \"keepalive\",\n};\n\nexport const DEFAULTS: PaiDaemonConfig = {\n socketPath: paiSocketPath(),\n indexIntervalSecs: 300,\n embedIntervalSecs: 600,\n embedOnStartup: false,\n passPriority: \"background\",\n storageBackend: \"sqlite\",\n postgres: {\n connectionString: perUserConnectionString(),\n maxConnections: 5,\n connectionTimeoutMs: 5000,\n },\n embeddingModel: \"Snowflake/snowflake-arctic-embed-m-v1.5\",\n embedding: { backend: \"transformers-cpu-q8\", ollama: { baseUrl: \"http://127.0.0.1:11434\" } },\n logLevel: \"info\",\n notifications: DEFAULT_NOTIFICATION_CONFIG,\n tasks: DEFAULT_TASK_CONFIG,\n // Deliberately empty. An install must not guess who the user is: a wrong\n // guess here is an address that can be mailed without review.\n identity: { selfEmails: [] },\n sessions: { cacheKeepalive: { ...DEFAULT_SESSIONS_CACHE_KEEPALIVE } },\n dashboard: { enabled: true, port: 8770, bind: \"127.0.0.1\" },\n search: {\n mode: \"keyword\",\n rerank: true,\n recencyBoostDays: 90,\n defaultLimit: 10,\n snippetLength: 200,\n },\n};\n\n/** Config template — generated at runtime so the DB name is per-user */\nfunction configTemplate(): string {\n return `{\n \"socketPath\": \"/tmp/pai.sock\",\n \"indexIntervalSecs\": 300,\n \"embedIntervalSecs\": 600,\n \"storageBackend\": \"sqlite\",\n \"postgres\": {\n \"connectionString\": \"${perUserConnectionString()}\",\n \"maxConnections\": 5,\n \"connectionTimeoutMs\": 5000\n },\n \"embeddingModel\": \"Snowflake/snowflake-arctic-embed-m-v1.5\",\n \"logLevel\": \"info\",\n \"vaultPath\": \"\",\n \"vaultProjectId\": 0,\n \"search\": {\n \"mode\": \"keyword\",\n \"rerank\": true,\n \"recencyBoostDays\": 90,\n \"defaultLimit\": 10,\n \"snippetLength\": 200\n }\n}\n`;\n}\n\n// ---------------------------------------------------------------------------\n// Path helpers\n// ---------------------------------------------------------------------------\n\n/** Expand a leading ~ to the real home directory */\nexport function expandHome(p: string): string {\n if (p === \"~\" || p.startsWith(\"~/\") || p.startsWith(\"~\\\\\")) {\n return join(homedir(), p.slice(1));\n }\n return p;\n}\n\n/** Canonical location since 2026-09-19: under the PAI_HOME namespace dir,\n * so nothing PAI writes can collide with a file Claude Code itself owns. */\nconst NEW_CONFIG_FILE = paiHomePath(\"config.json\");\n\n/** Briefly the canonical location between 2026-09-19's two migrations —\n * read during the transition, never written to again. */\nconst OLD_CONFIG_FILE = join(homedir(), \".claude\", \"pai.json\");\n\n/** Where the config lived before 2026-09-19 — read during the transition,\n * never written to once NEW_CONFIG_FILE exists (see `pai config migrate`). */\nconst LEGACY_CONFIG_FILE = join(homedir(), \".config\", \"pai\", \"config.json\");\n\n/**\n * The path any read/write of the PAI config actually uses: PAI_CONFIG_FILE\n * (tests, power users) first, else the new PAI_HOME location if it exists,\n * else the most recent old location that is actually on disk (printing a\n * one-time notice), else the new location (the target a first write creates).\n */\nexport function paiConfigFilePath(): string {\n const override = process.env.PAI_CONFIG_FILE;\n if (override) return override;\n return resolvePaiFile(NEW_CONFIG_FILE, [OLD_CONFIG_FILE, LEGACY_CONFIG_FILE], \"pai config migrate\");\n}\n\nexport const CONFIG_FILE = paiConfigFilePath();\nexport const CONFIG_DIR = dirname(CONFIG_FILE);\n\n/** config.yaml — the canonical main config once `pai config yaml` has run,\n * read/written by readMainConfigRaw/writeMainConfigRaw instead of\n * CONFIG_FILE whenever it exists (see src/config/main-config.ts). */\nexport function paiConfigYamlFilePath(): string {\n return yamlSiblingPath(CONFIG_FILE);\n}\n\n/**\n * Read the raw main config object exactly as every non-typed writer\n * (identity, notifications, obsidian, setup, workers, memory settings) needs\n * it: config.yaml when it exists, else CONFIG_FILE. `path` overrides the\n * JSON location (tests, or workers/config.ts's parametrized CONFIG_FILE) —\n * its YAML sibling (same dir, `config.yaml`) is what gets preferred.\n */\nexport function readMainConfigRaw(path: string = CONFIG_FILE): Record<string, unknown> {\n try {\n return readDualFormatConfigRaw(path);\n } catch (e) {\n throw e instanceof MainConfigError ? new Error(e.message) : e;\n }\n}\n\n/**\n * Write the raw main config object back through the same seam: a\n * comment-preserving sync into config.yaml when it exists, else a plain\n * writeJsonAtomic to `path`. Every writer of the main config must call this\n * instead of touching CONFIG_FILE directly, so a config.yaml on disk is\n * honored no matter which of them made the change.\n */\nexport function writeMainConfigRaw(raw: Record<string, unknown>, path: string = CONFIG_FILE): void {\n try {\n writeDualFormatConfigRaw(path, raw);\n } catch (e) {\n throw e instanceof MainConfigError ? new Error(e.message) : e;\n }\n}\n\nexport const ConfigMigrationError = PaiFileMigrationError;\nexport type ConfigMigrateResult = MigrateFileResult;\n\n/**\n * `pai config migrate`: move config.json (from ~/.claude/pai.json or\n * ~/.config/pai/config.json, whichever is found) to ~/.claude/pai/config.json\n * byte-for-byte, verify the copy, then rename the old file aside as\n * config.json.migrated-<YYYYMMDD> (never deleted).\n */\nexport function migrateConfigFile(opts: { dryRun?: boolean } = {}): ConfigMigrateResult {\n const result = migratePaiFile(NEW_CONFIG_FILE, [OLD_CONFIG_FILE, LEGACY_CONFIG_FILE], opts);\n if (!result.dryRun && result.fromPath) {\n // config.json can hold secrets (e.g. the Postgres password) — lock down\n // both the new location and the `.migrated-<stamp>` copy left behind.\n if (existsSync(result.toPath)) chmodSync(result.toPath, 0o600);\n const oldDir = dirname(result.fromPath);\n const oldName = basename(result.fromPath);\n for (const entry of readdirSync(oldDir)) {\n if (entry.startsWith(`${oldName}.migrated-`)) chmodSync(join(oldDir, entry), 0o600);\n }\n }\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Deep merge (handles nested objects, not arrays)\n// ---------------------------------------------------------------------------\n\nfunction deepMerge<T extends object>(\n target: T,\n source: Record<string, unknown>\n): T {\n const result = { ...target };\n for (const key of Object.keys(source)) {\n const srcVal = source[key];\n if (srcVal === undefined || srcVal === null) continue;\n const tgtVal = (target as Record<string, unknown>)[key];\n if (\n typeof srcVal === \"object\" &&\n !Array.isArray(srcVal) &&\n typeof tgtVal === \"object\" &&\n tgtVal !== null &&\n !Array.isArray(tgtVal)\n ) {\n (result as Record<string, unknown>)[key] = deepMerge(\n tgtVal as object,\n srcVal as Record<string, unknown>\n );\n } else {\n (result as Record<string, unknown>)[key] = srcVal;\n }\n }\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Config loader\n// ---------------------------------------------------------------------------\n\n/**\n * Load configuration: config.yaml (see paiConfigYamlFilePath) if it exists,\n * else CONFIG_FILE (see paiConfigFilePath), else defaults. Returns defaults\n * deep-merged with any values found in the file.\n */\nexport function loadConfig(): PaiDaemonConfig {\n if (!existsSync(CONFIG_FILE) && !existsSync(paiConfigYamlFilePath())) {\n return { ...DEFAULTS };\n }\n\n let parsed: Record<string, unknown>;\n try {\n parsed = readMainConfigRaw();\n } catch (e) {\n process.stderr.write(\n `[pai-daemon] Could not read config: ${e instanceof Error ? e.message : String(e)}\\n`\n );\n return { ...DEFAULTS };\n }\n\n // Compat: config.json may use \"obsidianVaultPath\" (legacy key) instead of \"vaultPath\".\n // Map it across so the daemon picks it up correctly.\n if (parsed.obsidianVaultPath && !parsed.vaultPath) {\n parsed.vaultPath = parsed.obsidianVaultPath;\n process.stderr.write(\n `[pai-daemon] Config: mapped obsidianVaultPath → vaultPath (${parsed.vaultPath})\\n`\n );\n }\n\n return deepMerge(DEFAULTS, parsed);\n}\n\n/**\n * Ensure CONFIG_DIR exists and write a default config template to CONFIG_FILE\n * if none exists yet. Call this only from the `serve` command.\n */\nexport function ensureConfigDir(): void {\n if (!existsSync(CONFIG_DIR)) {\n mkdirSync(CONFIG_DIR, { recursive: true });\n process.stderr.write(\n `[pai-daemon] Created config directory: ${CONFIG_DIR}\\n`\n );\n }\n\n if (!existsSync(CONFIG_FILE) && !existsSync(paiConfigYamlFilePath())) {\n try {\n writeFileSync(CONFIG_FILE, configTemplate(), \"utf-8\");\n process.stderr.write(\n `[pai-daemon] Wrote default config to: ${CONFIG_FILE}\\n`\n );\n } catch (e) {\n process.stderr.write(\n `[pai-daemon] Could not write default config: ${e}\\n`\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAwGA,MAAa,kBAAgC;CAC3C,OAAY;EAAC;EAAY;EAAS;EAAQ;EAAM;CAChD,YAAY;EAAC;EAAY;EAAS;EAAQ;EAAM;CAChD,MAAY,CAAC,MAAM;CACnB,UAAY,CAAC,MAAM;CACnB,OAAY,EAAE;CACf;AAeD,MAAa,mBAAmC;CAC9C,MAAM;EACJ,SAAS;EACT,KAAK;EACL,UAAU;EACX;CACD,UAAU;EACR,SAAS;EACT,WAAW;EACZ;CACD,OAAO,EACL,SAAS,MACV;CACD,OAAO;EACL,SAAS;EACT,WAAW;EACZ;CACD,KAAK,EACH,SAAS,MACV;CACF;AAED,MAAa,8BAAkD;CAC7D,MAAM;CACN,UAAU;CACV,SAAS;CACV;;;;;;;;AC5HD,MAAa,qBAAqB;;AA2BlC,MAAa,WAAsB;CACjC,SAAS;CACT,UAAU;CACV,QAAQ;CACT;AAiMD,MAAa,sBAAkC;CAC7C,SAAS;CACT,WAAW,EACT,SAAS,EACP,SAAS,OACV,EACF;CACD,cAAc;CACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpND,SAAgB,eAAe,MAAc,QAAQ,MAA+B;AAClF,KAAI,CAAC,WAAW,KAAK,CAAE,QAAO,EAAE;CAEhC,IAAI;AACJ,KAAI;AACF,QAAM,aAAa,MAAM,OAAO;UACzB,GAAG;AACV,QAAM,IAAI,MACR,kBAAkB,MAAM,IAAI,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,CAAC,kFAExE;;AAGH,KAAI;AACF,SAAO,KAAK,MAAM,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AG,UAAU;CAGxB,IAAI;AACJ,KAAI;AACF,WAAS,mBAAmB;UACrB,GAAG;AACV,UAAQ,OAAO,MACb,uCAAuC,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,CAAC,IACnF;AACD,SAAO,EAAE,GAAG,UAAU;;AAKxB,KAAI,OAAO,qBAAqB,CAAC,OAAO,WAAW;AACjD,SAAO,YAAY,OAAO;AAC1B,UAAQ,OAAO,MACb,8DAA8D,OAAO,UAAU,KAChF;;AAGH,QAAO,UAAU,UAAU,OAAO;;;;;;AAOpC,SAAgB,kBAAwB;AACtC,KAAI,CAAC,WAAW,WAAW,EAAE;AAC3B,YAAU,YAAY,EAAE,WAAW,MAAM,CAAC;AAC1C,UAAQ,OAAO,MACb,0CAA0C,WAAW,IACtD;;AAGH,KAAI,CAAC,WAAW,YAAY,IAAI,CAAC,WAAW,uBAAuB,CAAC,CAClE,KAAI;AACF,gBAAc,aAAa,gBAAgB,EAAE,QAAQ;AACrD,UAAQ,OAAO,MACb,yCAAyC,YAAY,IACtD;UACM,GAAG;AACV,UAAQ,OAAO,MACb,gDAAgD,EAAE,IACnD"}
@@ -1,8 +1,8 @@
1
- import { _ as writeYamlFileAtomic, d as readMainConfigRaw, f as writeMainConfigRaw, g as YamlStoreError, n as CONFIG_FILE, v as readJsonStrict, y as writeJsonAtomic } from "./config-Ddc4DIPk.mjs";
2
- import { a as paiHomePath, o as resolvePaiFile, r as migratePaiFile } from "./pai-home-UncxWxlX.mjs";
1
+ import { _ as writeYamlFileAtomic, d as readMainConfigRaw, f as writeMainConfigRaw, g as YamlStoreError, n as CONFIG_FILE, v as readJsonStrict, y as writeJsonAtomic } from "./config-DjZELvoA.mjs";
2
+ import { c as migratePaiFile, d as resolvePaiFile, u as paiHomePath } from "./runtime-paths-DkZoxofH.mjs";
3
3
  import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { homedir } from "node:os";
5
- import { delimiter, dirname, join } from "node:path";
5
+ import { dirname, join } from "node:path";
6
6
  import { Document, Scalar, parseDocument } from "yaml";
7
7
 
8
8
  //#region src/utils/model-window.ts
@@ -1352,114 +1352,5 @@ function keysDir() {
1352
1352
  }
1353
1353
 
1354
1354
  //#endregion
1355
- //#region src/workers/run-env.ts
1356
- /**
1357
- * run-env.ts — the provider environment every Claude Code spawn must run with.
1358
- *
1359
- * Extracted from run.ts so daemon-side background spawns (session summaries,
1360
- * context handovers, KG extraction) go through the exact same env the worker
1361
- * runner uses, instead of importing the whole runner into the daemon.
1362
- */
1363
- /**
1364
- * Session-identity variables the SPAWNING session leaves in the environment.
1365
- * Inherited, they make a headless child attach to the spawner's messaging
1366
- * socket instead of standing on its own — and a worktree-mode child then
1367
- * starts with its core tools (Bash/Read/…) deferred out of its reach, left
1368
- * with nothing but the tool-registry search (2026-09-18). The child is its
1369
- * own session, so none of these may cross the spawn boundary.
1370
- */
1371
- const SESSION_IDENTITY_VARS = [
1372
- "CLAUDE_CODE_MESSAGING_SOCKET",
1373
- "CLAUDE_CODE_MESSAGING_TOKEN",
1374
- "CLAUDE_CODE_SESSION_ID",
1375
- "CLAUDE_CODE_CHILD_SESSION",
1376
- "CLAUDE_PID",
1377
- "CLAUDECODE"
1378
- ];
1379
- /**
1380
- * Harness settings the spawner's environment carries that a headless worker
1381
- * must not keep. ENABLE_TOOL_SEARCH reaches every pai process through the
1382
- * user settings' env block, so a pai spawned from inside a Claude session
1383
- * passes it on to worker children; inherited, the headless child starts with
1384
- * every core tool deferred out of reach — only ToolSearch remains callable,
1385
- * granted tools included (2026-09-18, verified by stripping exactly this one
1386
- * var). Interactive runs set it deliberately below.
1387
- */
1388
- const HEADLESS_STRIP_VARS = ["ENABLE_TOOL_SEARCH"];
1389
- /**
1390
- * Provider-specific env vars a native-Anthropic run must never carry — not
1391
- * set by this function, and stripped even when a parent shell exported them
1392
- * (e.g. this worker was itself spawned from a GLM-configured environment).
1393
- */
1394
- const NATIVE_STRIP_VARS = [
1395
- "ANTHROPIC_BASE_URL",
1396
- "ANTHROPIC_AUTH_TOKEN",
1397
- "ANTHROPIC_DEFAULT_HAIKU_MODEL",
1398
- "ANTHROPIC_DEFAULT_SONNET_MODEL",
1399
- "ANTHROPIC_DEFAULT_OPUS_MODEL"
1400
- ];
1401
- /** Environment for a run through `provider`. Caller's env minus the Anthropic key. */
1402
- function buildRunEnv(provider, headless, proxyUrl) {
1403
- const env = { ...process.env };
1404
- delete env.ANTHROPIC_API_KEY;
1405
- if (headless) {
1406
- for (const k of SESSION_IDENTITY_VARS) delete env[k];
1407
- for (const k of HEADLESS_STRIP_VARS) delete env[k];
1408
- }
1409
- if (provider.native) {
1410
- for (const k of NATIVE_STRIP_VARS) delete env[k];
1411
- env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
1412
- if (headless) env.PAI_WORKER = "1";
1413
- else env.ENABLE_TOOL_SEARCH = "true";
1414
- return env;
1415
- }
1416
- let token = "local";
1417
- if (proxyUrl) env.ANTHROPIC_BASE_URL = proxyUrl;
1418
- else {
1419
- const resolved = resolveProviderKey(provider);
1420
- if (resolved) token = resolved;
1421
- env.ANTHROPIC_BASE_URL = provider.baseUrl;
1422
- }
1423
- env.ANTHROPIC_AUTH_TOKEN = token;
1424
- env.ANTHROPIC_DEFAULT_HAIKU_MODEL = resolveModelCapability(provider, "fast");
1425
- env.ANTHROPIC_DEFAULT_SONNET_MODEL = provider.models.default;
1426
- env.ANTHROPIC_DEFAULT_OPUS_MODEL = provider.models.default;
1427
- for (const [k, v] of Object.entries(provider.env)) env[k] = v;
1428
- env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
1429
- if (headless) env.PAI_WORKER = "1";
1430
- else env.ENABLE_TOOL_SEARCH = "true";
1431
- return env;
1432
- }
1433
- /** First-party route a native run is pinned to when caveman is off. */
1434
- const ANTHROPIC_FIRST_PARTY_URL = "https://api.anthropic.com";
1435
- /**
1436
- * The argv head every Claude Code spawn starts from, for an env built by
1437
- * buildRunEnv. The user settings' env block outranks the process env
1438
- * (measured 2026-09-22: an unreachable ANTHROPIC_BASE_URL in the process env
1439
- * was ignored while settings.json carried a caveman proxy route, and a glm
1440
- * worker's bearer token ended at Anthropic with a 401), so a route set in
1441
- * `env` is not enough once a machine-wide proxy is installed — it is pinned
1442
- * again with `--settings`, which outranks user settings. A native run goes
1443
- * through `caveman claude` when workers.caveman is on and the CLI is on
1444
- * PATH; off, it is pinned to api.anthropic.com so a global route cannot
1445
- * pull it in either.
1446
- */
1447
- function claudeCommand(env, caveman) {
1448
- const route = env.ANTHROPIC_BASE_URL;
1449
- if (!route && caveman) {
1450
- if (onPath("caveman", env)) return ["caveman", "claude"];
1451
- process.stderr.write("pai: workers.caveman is on but `caveman` is not on PATH; running claude directly\n");
1452
- }
1453
- return [
1454
- "claude",
1455
- "--settings",
1456
- JSON.stringify({ env: { ANTHROPIC_BASE_URL: route || ANTHROPIC_FIRST_PARTY_URL } })
1457
- ];
1458
- }
1459
- function onPath(bin, env) {
1460
- return (env.PATH ?? "").split(delimiter).some((d) => d && existsSync(join(d, bin)));
1461
- }
1462
-
1463
- //#endregion
1464
- export { resolveProviderKey as A, DEFAULT_CONTEXT_WINDOW as B, maskKey as C, readWorkersSection as D, providerKeyPath as E, needsWorkersYamlRelocation as F, stripModelVariant as H, parseWorkersYamlDocument as I, relocateWorkersYaml as L, initWorkersYaml as M, inlineWorkersYamlKeys as N, resolveCapability as O, migrateWorkersToYaml as P, workersYamlLegacyNotice as R, keysDir as S, providerCostTier as T, contextWindowFromModelId as V, classModelCapability as _, DEFAULT_CACHE_KEEPALIVE_SECS as a, getProviderOrNative as b, DEFAULT_PANE as c, MODEL_CAPABILITIES as d, NATIVE_ANTHROPIC_MODELS as f, assertProviderRunnable as g, WorkersConfigError as h, CAPABILITY_NAME_RE as i, writeWorkersSection as j, resolveModelCapability as k, DEFAULT_ROUTING as l, WORKER_CLASSES as m, claudeCommand as n, DEFAULT_LOG_DIR as o, PROVIDER_TAGS as p, ANTHROPIC_NATIVE as r, DEFAULT_MAX_MINUTES as s, buildRunEnv as t, DEFAULT_TREE as u, defaultWorkersConfig as v, nativeAnthropicProvider as w, isModelCapability as x, expandHome as y, workersYamlPath as z };
1465
- //# sourceMappingURL=run-env-CQRnxNht.mjs.map
1355
+ export { initWorkersYaml as A, stripModelVariant as B, providerCostTier as C, resolveModelCapability as D, resolveCapability as E, relocateWorkersYaml as F, workersYamlLegacyNotice as I, workersYamlPath as L, migrateWorkersToYaml as M, needsWorkersYamlRelocation as N, resolveProviderKey as O, parseWorkersYamlDocument as P, DEFAULT_CONTEXT_WINDOW as R, nativeAnthropicProvider as S, readWorkersSection as T, expandHome as _, DEFAULT_MAX_MINUTES as a, keysDir as b, DEFAULT_TREE as c, PROVIDER_TAGS as d, WORKER_CLASSES as f, defaultWorkersConfig as g, classModelCapability as h, DEFAULT_LOG_DIR as i, inlineWorkersYamlKeys as j, writeWorkersSection as k, MODEL_CAPABILITIES as l, assertProviderRunnable as m, CAPABILITY_NAME_RE as n, DEFAULT_PANE as o, WorkersConfigError as p, DEFAULT_CACHE_KEEPALIVE_SECS as r, DEFAULT_ROUTING as s, ANTHROPIC_NATIVE as t, NATIVE_ANTHROPIC_MODELS as u, getProviderOrNative as v, providerKeyPath as w, maskKey as x, isModelCapability as y, contextWindowFromModelId as z };
1356
+ //# sourceMappingURL=config-Dpe2JlbY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-Dpe2JlbY.mjs","names":[],"sources":["../src/utils/model-window.ts","../src/workers/workers-config.ts","../src/workers/config.ts"],"sourcesContent":["/**\n * model-window.ts — facts derivable from a bare model id.\n *\n * Shared by the worker stack (provider registry) and the session hooks\n * (context-fill). Zero imports on purpose: this leaf is bundled into hooks\n * (scripts/build-hooks.mjs) and must never drag config or path machinery\n * into a hook process.\n */\n\n/** Last-resort window when nothing on hand reports one and the model id\n * carries no window information. */\nexport const DEFAULT_CONTEXT_WINDOW = 200_000;\n\n/** Strip a bracketed variant suffix: \"glm-5.3[1m]\" → \"glm-5.3\". The suffix\n * selects a variant of the same base model (a context-window tier, a\n * quantization), so the prefix is the id's family. */\nexport function stripModelVariant(model: string): string {\n const stripped = model.replace(/\\[[^\\]]*\\]\\s*$/, \"\").trim();\n return stripped || model;\n}\n\n/**\n * The context window a model id itself declares, or null when the id carries\n * no window information. Only the bracketed variant suffix is read\n * (\"[1m]\" → 1,000,000); a bare id says nothing and stays null so callers can\n * fall back to whatever they measured themselves.\n */\nexport function contextWindowFromModelId(model: string | null | undefined): number | null {\n if (typeof model !== \"string\" || model === \"\") return null;\n const m = /\\[(\\d+)m\\]$/i.exec(model.trim());\n if (!m) return null;\n const millions = Number(m[1]);\n if (!Number.isFinite(millions) || millions < 1) return null;\n return millions * 1_000_000;\n}\n","/**\n * workers-config.ts — workers.yaml: providers, model roles, class routing,\n * mcp_sets.\n *\n * config.ts's readWorkersSection/writeWorkersSection are the only callers —\n * every other module keeps talking to the WorkersConfig shape from config.ts\n * and never touches this file. That is deliberate: adding a provider used to\n * mean editing JSON inside an unrelated config blob; this module makes\n * providers/classes/mcp_sets/active a single human-editable file, documented\n * in docs/workers-config.md, while everything downstream is unchanged.\n *\n * Writes go through the `yaml` package's Document API and only touch the\n * entries that actually changed, so hand-written comments elsewhere in the\n * file — including a comment directly above an untouched provider — survive\n * byte-for-byte across `add`, `use`, `disable`, and every other mutation.\n */\n\nimport { existsSync, readFileSync, writeFileSync, chmodSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { Document, Scalar, parseDocument, type Node } from \"yaml\";\nimport { readJsonStrict, writeJsonAtomic } from \"../config/json-store.js\";\nimport { writeYamlFileAtomic, YamlStoreError } from \"../config/yaml-store.js\";\nimport { paiHomePath, resolvePaiFile, migratePaiFile, type MigrateFileResult } from \"../config/pai-home.js\";\nimport {\n ANTHROPIC_NATIVE,\n NATIVE_ANTHROPIC_MODELS,\n WorkersConfigError,\n expandHome,\n isModelCapability,\n parseCapabilitiesValue,\n parseClassesValue,\n parseMcpSetsValue,\n parseModelsBlock,\n parseProvider,\n parseWorkersConfig,\n type ClassTarget,\n type WorkerProvider,\n} from \"./config.js\";\n\nexport const WORKERS_YAML_FILENAME = \"workers.yaml\";\n\n/**\n * Where workers.yaml lives since 2026-09-19: under the PAI_HOME namespace\n * dir (~/.claude/pai by default) — this file is per-user state that can\n * carry API keys and must never be committed, same as the rest of PAI_HOME.\n */\nfunction defaultWorkersYamlPath(): string {\n return paiHomePath(WORKERS_YAML_FILENAME);\n}\n\n/** Briefly the canonical location between 2026-09-19's two migrations —\n * read during the transition, never written to again. */\nfunction oldWorkersYamlPath(): string {\n return join(homedir(), \".claude\", WORKERS_YAML_FILENAME);\n}\n\n/** Where workers.yaml lived before 2026-09-19 — read during the transition,\n * never written to (see `pai worker config migrate`). */\nfunction legacyWorkersYamlPath(): string {\n return join(homedir(), \".config\", \"pai\", WORKERS_YAML_FILENAME);\n}\n\n/**\n * The path any read/write of workers.yaml actually uses: PAI_WORKERS_YAML\n * (tests, power users) first, else the new PAI_HOME location if it exists,\n * else the most recent old location that is actually on disk (printing a\n * one-time notice), else the new location (the target a first write creates).\n */\nexport function workersYamlPath(): string {\n const override = process.env.PAI_WORKERS_YAML;\n if (override) return override;\n return resolvePaiFile(\n defaultWorkersYamlPath(),\n [oldWorkersYamlPath(), legacyWorkersYamlPath()],\n \"pai worker config migrate\"\n );\n}\n\n/** Where a fresh write (init, migrate, relocate's destination) always\n * targets — the new location, or PAI_WORKERS_YAML for test isolation.\n * Never an old path: nothing is ever written there again. */\nfunction writeTargetWorkersYamlPath(): string {\n return process.env.PAI_WORKERS_YAML ?? defaultWorkersYamlPath();\n}\n\n/**\n * One-line notice for `pai worker config check` and `pai worker providers`\n * when workers.yaml is still sitting at an old location. Null once it has\n * moved (or PAI_WORKERS_YAML is set — that always wins, nothing to migrate).\n */\nexport function workersYamlLegacyNotice(): string | null {\n if (process.env.PAI_WORKERS_YAML) return null;\n if (existsSync(defaultWorkersYamlPath())) return null;\n const found = [oldWorkersYamlPath(), legacyWorkersYamlPath()].find((p) => existsSync(p));\n if (!found) return null;\n return `workers.yaml is still at the old location (${found}) — run \\`pai worker config migrate\\` to move it to ${defaultWorkersYamlPath()}`;\n}\n\nexport interface WorkersYamlData {\n active: string | null;\n providers: Record<string, WorkerProvider>;\n classes: Record<string, ClassTarget>;\n capabilities: Record<string, string[]>;\n mcpSets: Record<string, string[]>;\n nativeModels: WorkerProvider[\"models\"];\n}\n\n// ---------------------------------------------------------------------------\n// Friendly (on-disk) provider shape ↔ internal WorkerProvider\n// ---------------------------------------------------------------------------\n\n/** snake_case on-disk keys → the camelCase raw shape parseProvider expects. */\nfunction yamlProviderToRaw(y: Record<string, unknown>): Record<string, unknown> {\n const raw: Record<string, unknown> = {};\n if (y.enabled !== undefined) raw.enabled = y.enabled;\n if (y.url !== undefined) raw.baseUrl = y.url;\n if (y.key_file !== undefined) raw.keyFile = y.key_file;\n if (y.key !== undefined) raw.key = y.key;\n if (y.tier !== undefined) raw.costTier = y.tier;\n if (y.models !== undefined) raw.models = y.models;\n if (y.protocol !== undefined) raw.protocol = y.protocol;\n if (y.engine !== undefined) raw.engine = y.engine;\n if (y.upstream_url !== undefined) raw.upstreamUrl = y.upstream_url;\n if (y.env !== undefined) raw.env = y.env;\n if (y.note !== undefined) raw.note = y.note;\n if (y.quota_probe !== undefined) raw.quotaProbe = y.quota_probe;\n if (y.quota_skip_at !== undefined) raw.quotaSkipAt = y.quota_skip_at;\n if (y.context_window !== undefined) raw.contextWindow = y.context_window;\n if (y.tags !== undefined) raw.tags = y.tags;\n if (y.usage !== undefined) raw.usage = y.usage;\n if (y.model_tiers !== undefined) raw.modelTiers = y.model_tiers;\n return raw;\n}\n\n/** Internal WorkerProvider → the friendly on-disk plain object for writing. */\nfunction providerToYamlPlain(p: WorkerProvider): Record<string, unknown> {\n const y: Record<string, unknown> = {};\n if (!p.enabled) y.enabled = false;\n if (p.baseUrl) y.url = p.baseUrl;\n if (p.keyFile) y.key_file = p.keyFile;\n if (p.key) y.key = p.key;\n if (p.costTier !== undefined) y.tier = p.costTier;\n y.models = { ...p.models };\n if (p.protocol && p.protocol !== \"anthropic\") y.protocol = p.protocol;\n if (p.engine && p.engine !== \"claude\") y.engine = p.engine;\n if (p.upstreamUrl) y.upstream_url = p.upstreamUrl;\n if (p.env && Object.keys(p.env).length) y.env = { ...p.env };\n if (p.note) y.note = p.note;\n if (p.quotaProbe) y.quota_probe = p.quotaProbe;\n if (p.quotaSkipAt !== undefined) y.quota_skip_at = p.quotaSkipAt;\n if (p.contextWindow !== undefined) y.context_window = p.contextWindow;\n if (p.tags?.length) y.tags = [...p.tags];\n if (p.usage) y.usage = p.usage;\n if (p.modelTiers) y.model_tiers = { ...p.modelTiers };\n return y;\n}\n\n/** The builtin `anthropic` block only ever carries `builtin: true` + `models`. */\nfunction parseBuiltinAnthropic(raw: unknown, pathPrefix: string): WorkerProvider[\"models\"] {\n if (typeof raw !== \"object\" || raw === null || Array.isArray(raw)) {\n throw new WorkersConfigError(`${pathPrefix}: must be an object`);\n }\n const p = raw as Record<string, unknown>;\n if (p.builtin !== true) {\n throw new WorkersConfigError(\n `${pathPrefix}: \"${ANTHROPIC_NATIVE}\" is reserved for the built-in Claude Code login — ` +\n `set \"builtin: true\" (optionally with a \"models\" override) or rename this provider`\n );\n }\n const disallowed = [\"url\", \"key_file\", \"key\", \"engine\", \"protocol\", \"upstream_url\"].filter(\n (k) => p[k] !== undefined\n );\n if (disallowed.length) {\n throw new WorkersConfigError(\n `${pathPrefix}: a builtin provider cannot set ${disallowed.join(\", \")} — it runs on Claude Code's own login`\n );\n }\n if (p.models === undefined) return { ...NATIVE_ANTHROPIC_MODELS };\n return { ...NATIVE_ANTHROPIC_MODELS, ...parseModelsBlock(`${pathPrefix}.models`, p.models) };\n}\n\n// ---------------------------------------------------------------------------\n// Line-numbered errors\n// ---------------------------------------------------------------------------\n\nfunction lineOf(doc: Document, path: (string | number)[]): number | null {\n try {\n const node = doc.getIn(path, true) as Node | undefined;\n const range = node && typeof node === \"object\" && \"range\" in node ? node.range : undefined;\n if (!range) return null;\n const text = String(doc);\n return text.slice(0, range[0]).split(\"\\n\").length;\n } catch {\n return null;\n }\n}\n\nfunction withLine(doc: Document, path: (string | number)[], yamlPath: string, e: unknown): never {\n const msg = e instanceof Error ? e.message : String(e);\n const line = lineOf(doc, path);\n throw new WorkersConfigError(line ? `${yamlPath}:${line}: ${msg}` : `${yamlPath}: ${msg}`);\n}\n\n// ---------------------------------------------------------------------------\n// Load + validate\n// ---------------------------------------------------------------------------\n\n/**\n * Parse and fully validate a workers.yaml Document. Throws WorkersConfigError\n * naming `<path>:<line>` for anything wrong — an unknown provider referenced\n * by a class is a load error here, not a spawn-time surprise.\n */\nexport function parseWorkersYamlDocument(doc: Document, yamlPath: string): WorkersYamlData {\n const root = doc.toJS() ?? {};\n if (typeof root !== \"object\" || Array.isArray(root)) {\n throw new WorkersConfigError(`${yamlPath}: top level must be a mapping`);\n }\n const r = root as Record<string, unknown>;\n\n const providers: Record<string, WorkerProvider> = {};\n let nativeModels: WorkerProvider[\"models\"] = { ...NATIVE_ANTHROPIC_MODELS };\n const providersRaw = r.providers;\n if (providersRaw !== undefined) {\n if (typeof providersRaw !== \"object\" || providersRaw === null || Array.isArray(providersRaw)) {\n withLine(doc, [\"providers\"], yamlPath, new WorkersConfigError(\"providers: must be a mapping of name → provider\"));\n }\n for (const [name, raw] of Object.entries(providersRaw as Record<string, unknown>)) {\n try {\n if (name === ANTHROPIC_NATIVE) {\n nativeModels = parseBuiltinAnthropic(raw, `providers.${name}`);\n } else {\n providers[name] = parseProvider(name, yamlProviderToRaw(raw as Record<string, unknown>));\n }\n } catch (e) {\n withLine(doc, [\"providers\", name], yamlPath, e);\n }\n }\n }\n\n let classes: Record<string, ClassTarget> = {};\n if (r.classes !== undefined) {\n try {\n classes = parseClassesValue(r.classes, \"classes\");\n } catch (e) {\n withLine(doc, [\"classes\"], yamlPath, e);\n }\n // Cross-validate: every class must name a known provider (or \"anthropic\")\n // and, if it names a role, a capability that provider actually declares.\n // Unlike the JSON path (where a provider can be removed out from under a\n // class and the error surfaces at spawn time), workers.yaml catches this\n // at load time.\n for (const [cls, target] of Object.entries(classes)) {\n const provider = typeof target === \"string\" ? target.split(\"/\")[0] : target.provider;\n const alias = typeof target === \"string\" ? target.split(\"/\")[1] : undefined;\n if (provider !== undefined) {\n const native = provider === ANTHROPIC_NATIVE;\n if (!native && !providers[provider]) {\n withLine(\n doc,\n [\"classes\", cls],\n yamlPath,\n new WorkersConfigError(\n `classes.${cls}: no provider named \"${provider}\" (configured: ${Object.keys(providers).join(\", \") || \"(none)\"})`\n )\n );\n }\n if (alias !== undefined) {\n if (!isModelCapability(alias)) {\n withLine(\n doc,\n [\"classes\", cls],\n yamlPath,\n new WorkersConfigError(\n `classes.${cls}: \"${alias}\" is not a valid capability name (must match ^[a-z][a-z0-9-]*$)`\n )\n );\n } else if (!native && providers[provider] && alias !== \"default\" && !providers[provider].models[alias]) {\n // the native provider has no configurable model slots — any\n // alias resolves through resolveModelCapability's own fallback\n withLine(\n doc,\n [\"classes\", cls],\n yamlPath,\n new WorkersConfigError(`classes.${cls}: provider \"${provider}\" has no \"${alias}\" model configured`)\n );\n }\n }\n }\n }\n }\n\n let capabilities: Record<string, string[]> = {};\n if (r.capabilities !== undefined) {\n try {\n capabilities = parseCapabilitiesValue(r.capabilities, \"capabilities\");\n } catch (e) {\n withLine(doc, [\"capabilities\"], yamlPath, e);\n }\n }\n\n let mcpSets: Record<string, string[]> = {};\n if (r.mcp_sets !== undefined) {\n try {\n mcpSets = parseMcpSetsValue(r.mcp_sets, \"mcp_sets\");\n } catch (e) {\n withLine(doc, [\"mcp_sets\"], yamlPath, e);\n }\n } else {\n mcpSets = parseMcpSetsValue(undefined, \"mcp_sets\");\n }\n\n const active = r.active === undefined || r.active === null ? null : String(r.active);\n if (active !== null && active !== ANTHROPIC_NATIVE && active !== \"auto\" && !providers[active]) {\n withLine(\n doc,\n [\"active\"],\n yamlPath,\n new WorkersConfigError(\n `active: no provider named \"${active}\" (configured: ${Object.keys(providers).join(\", \") || \"(none)\"})`\n )\n );\n }\n\n return { active, providers, classes, capabilities, mcpSets, nativeModels };\n}\n\n/** Read + parse workers.yaml. Returns null if the file does not exist. */\nexport function readWorkersYaml(yamlPath: string): { doc: Document; data: WorkersYamlData } | null {\n if (!existsSync(yamlPath)) return null;\n let text: string;\n try {\n text = readFileSync(yamlPath, \"utf8\");\n } catch (e) {\n throw new WorkersConfigError(\n `Could not read ${yamlPath}: ${e instanceof Error ? e.message : String(e)}`\n );\n }\n const doc = parseDocument(text);\n if (doc.errors.length) {\n throw new WorkersConfigError(`${yamlPath}: ${doc.errors[0].message}`);\n }\n const data = parseWorkersYamlDocument(doc, yamlPath);\n return { doc, data };\n}\n\n// ---------------------------------------------------------------------------\n// Write (diff-based, comment-preserving)\n// ---------------------------------------------------------------------------\n\nfunction shallowEqual(a: unknown, b: unknown): boolean {\n return JSON.stringify(a) === JSON.stringify(b);\n}\n\n/**\n * A `key:` value as an explicit double-quoted YAML scalar. A key is an\n * opaque token, not YAML-authored text — plain-scalar auto-styling could\n * read one back as a number or boolean (an all-digit token, \"true\", \"no\", …)\n * if it were ever left unquoted, so every write forces the quoted form\n * regardless of what the plain style would otherwise pick.\n */\nfunction quotedKeyNode(value: string): Scalar {\n const s = new Scalar(value);\n s.type = Scalar.QUOTE_DOUBLE;\n return s;\n}\n\n/**\n * Apply the changes between `before` and `after` onto `doc`, touching only\n * the providers/classes/mcp_sets/active entries that actually differ. This is\n * what makes comment preservation possible: an untouched provider's node\n * (and any comment above it) is never revisited.\n */\nfunction syncWorkersYamlDocument(doc: Document, before: WorkersYamlData, after: WorkersYamlData): void {\n // providers: add/update changed, remove gone (never touch the builtin anthropic block)\n for (const [name, p] of Object.entries(after.providers)) {\n const beforeP = before.providers[name];\n const changed = !beforeP || !shallowEqual(providerToYamlPlain(beforeP), providerToYamlPlain(p));\n if (changed) {\n // a fresh (or wholesale-replaced) provider entry is set in one shot as\n // a plain object — the yaml lib only turns it into real Map/Scalar\n // nodes lazily at stringify time, so a follow-up setIn/deleteIn into\n // the same not-yet-a-collection value would fail. Embedding the `key`\n // as an actual Scalar node here rides along: stringify leaves already-\n // Node values alone (see stringifyPair.js), quoting only that field.\n const y: Record<string, unknown> = providerToYamlPlain(p);\n if (typeof y.key === \"string\") y.key = quotedKeyNode(y.key);\n doc.setIn([\"providers\", name], y);\n }\n }\n for (const name of Object.keys(before.providers)) {\n if (!(name in after.providers)) doc.deleteIn([\"providers\", name]);\n }\n\n // builtin anthropic models: only the capabilities that changed; the entry\n // is created (with `builtin: true`) when the file has none yet\n if (!shallowEqual(before.nativeModels, after.nativeModels)) {\n if (!doc.hasIn([\"providers\", ANTHROPIC_NATIVE])) {\n doc.setIn([\"providers\", ANTHROPIC_NATIVE], { builtin: true, models: { ...after.nativeModels } });\n } else {\n for (const [cap, id] of Object.entries(after.nativeModels)) {\n if (before.nativeModels[cap] !== id) doc.setIn([\"providers\", ANTHROPIC_NATIVE, \"models\", cap], id);\n }\n }\n }\n\n // classes: same add/update/remove diff\n for (const [cls, target] of Object.entries(after.classes)) {\n if (!shallowEqual(before.classes[cls], target)) {\n doc.setIn([\"classes\", cls], target);\n }\n }\n for (const cls of Object.keys(before.classes)) {\n if (!(cls in after.classes)) doc.deleteIn([\"classes\", cls]);\n }\n\n // capabilities: same add/update/remove diff\n for (const [cap, prefs] of Object.entries(after.capabilities)) {\n if (!shallowEqual(before.capabilities[cap], prefs)) {\n doc.setIn([\"capabilities\", cap], [...prefs]);\n }\n }\n for (const cap of Object.keys(before.capabilities)) {\n if (!(cap in after.capabilities)) doc.deleteIn([\"capabilities\", cap]);\n }\n\n // mcp_sets: same add/update/remove diff\n for (const [set, servers] of Object.entries(after.mcpSets)) {\n if (!shallowEqual(before.mcpSets[set], servers)) {\n doc.setIn([\"mcp_sets\", set], [...servers]);\n }\n }\n for (const set of Object.keys(before.mcpSets)) {\n if (!(set in after.mcpSets)) doc.deleteIn([\"mcp_sets\", set]);\n }\n\n // active\n if (before.active !== after.active) {\n if (after.active === null) doc.deleteIn([\"active\"]);\n else doc.setIn([\"active\"], after.active);\n }\n}\n\n/**\n * Write `after` into workers.yaml, preserving comments on everything that did\n * not change. Re-reads the file fresh (so the diff is against what is really\n * on disk, not a stale in-memory copy) and re-validates the result before\n * committing; on failure the previous bytes are left untouched.\n */\nexport function writeWorkersYaml(yamlPath: string, after: WorkersYamlData): void {\n const existing = readWorkersYaml(yamlPath);\n const doc = existing ? existing.doc : new Document({});\n const before: WorkersYamlData = existing\n ? existing.data\n : {\n active: null,\n providers: {},\n classes: {},\n capabilities: {},\n mcpSets: {},\n nativeModels: { ...NATIVE_ANTHROPIC_MODELS },\n };\n syncWorkersYamlDocument(doc, before, after);\n writeWorkersYamlText(yamlPath, String(doc));\n}\n\n/** Atomic write with a .bak-pai backup and a re-validate-or-restore guard.\n * The file-I/O tail (backup, temp write at 0600, rename, chmod) is shared\n * with every other PAI YAML file via writeYamlFileAtomic; only the\n * workers.yaml-specific validation (parseWorkersYamlDocument) lives here. */\nexport function writeWorkersYamlText(yamlPath: string, text: string): void {\n // Validate before committing anything to disk.\n const probe = parseDocument(text);\n if (probe.errors.length) {\n throw new WorkersConfigError(`refusing to write ${yamlPath}: ${probe.errors[0].message} (previous file left unchanged)`);\n }\n try {\n parseWorkersYamlDocument(probe, yamlPath);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new WorkersConfigError(`refusing to write ${yamlPath}: ${msg} (previous file left unchanged)`);\n }\n\n try {\n writeYamlFileAtomic(yamlPath, text, { label: yamlPath });\n } catch (e) {\n throw new WorkersConfigError(e instanceof YamlStoreError ? e.message : String(e instanceof Error ? e.message : e));\n }\n}\n\n// ---------------------------------------------------------------------------\n// Starter template, init, migrate\n// ---------------------------------------------------------------------------\n\n/** The exact commented starter shipped as examples/workers.yaml and by `init`. */\nexport function starterWorkersYamlText(): string {\n return `# PAI worker configuration.\n# Providers PAI can run workers on, the model each role uses, and which\n# provider every --class goes to. Edit by hand; \\`pai worker providers\\` shows\n# the effective result. Comments are preserved when PAI writes this file.\n#\n# Per-user state, kept 0600: this file can hold API keys (\\`key:\\`, below).\n# Never commit it or share it. \\`key_file: <path>\\` keeps a secret in its own\n# 0600 file instead, if you'd rather not put it here.\n\nactive: anthropic # provider for \\`pai worker run\\` without --provider or --class\n\nproviders:\n anthropic:\n builtin: true # Claude Code's own login: no url, no key file\n models:\n default: ${NATIVE_ANTHROPIC_MODELS.default}\n fast: ${NATIVE_ANTHROPIC_MODELS.fast}\n glm:\n url: https://api.z.ai/api/anthropic\n key: \"<your-api-key>\" # or key_file: <path to a 0600 file>\n tier: 3\n models:\n default: glm-5.3[1m]\n fast: glm-5.3-flash\n image: example-paint\n kimi:\n url: https://api.kimi.ai/coding/\n key: \"<your-api-key>\" # or key_file: <path to a 0600 file>\n tier: 3\n models:\n default: k3[1m]\n fast: kimi-for-coding[1m]\n\n# An \\`engine: image\\` provider does not spawn Claude — \\`pai worker run\n# --capability image\\` POSTs straight to its OpenAI-compatible images API and\n# writes the PNG it gets back. Uncomment and point it at a real provider\n# (still nested under providers:, above) to enable \\`--capability image\\`:\n# pictures:\n# engine: image\n# url: https://api.example.com/v1\n# key: \"<your-api-key>\"\n# models:\n# default: example-image-model\n# image: example-image-model\n\n# A class names a provider, or provider/role to pick a non-default model.\n# Workers exist to parallelise and to save cost: the default is Sonnet,\n# Haiku for the mechanical classes, and nothing here inherits the\n# orchestrating session's model.\nclasses:\n implement: anthropic\n draft: anthropic\n research: anthropic\n complex: anthropic\n plan: anthropic\n review: anthropic\n spotcheck: anthropic/fast\n simple: anthropic/fast\n image: glm/image\n\n# Cross-provider capability preference: which provider serves a --capability\n# request, in order, when more than one declares it. Unlisted capabilities\n# fall back to the active provider, then any provider that declares them.\n# capabilities:\n# image: [pictures, glm]\n# fast: [anthropic]\n\nmcp_sets:\n desktop: [clickr]\n`;\n}\n\n/**\n * Build a workers.yaml document from real (migrated) data, keeping the same\n * header/section comments as the starter. Used by `pai worker config\n * migrate` — `init` writes the literal starter instead, since it has no data\n * to carry over.\n */\nexport function buildWorkersYamlText(data: WorkersYamlData): string {\n const lines: string[] = [];\n lines.push(\"# PAI worker configuration.\");\n lines.push(\"# Providers PAI can run workers on, the model each role uses, and which\");\n lines.push(\"# provider every --class goes to. Edit by hand; `pai worker providers` shows\");\n lines.push(\"# the effective result. Comments are preserved when PAI writes this file.\");\n lines.push(\"\");\n lines.push(\n `active: ${data.active ?? \"null\"}` +\n \" # provider for `pai worker run` without --provider or --class\"\n );\n lines.push(\"\");\n lines.push(\"providers:\");\n lines.push(\" anthropic:\");\n lines.push(\" builtin: true # Claude Code's own login: no url, no key file\");\n lines.push(\" models:\");\n lines.push(` default: ${data.nativeModels.default}`);\n if (data.nativeModels.fast) lines.push(` fast: ${data.nativeModels.fast}`);\n if (data.nativeModels.image) lines.push(` image: ${data.nativeModels.image}`);\n for (const [name, p] of Object.entries(data.providers)) {\n const y = providerToYamlPlain(p);\n lines.push(` ${name}:`);\n for (const [k, v] of Object.entries(y)) {\n if (k === \"models\") continue;\n // a key is an opaque token, not YAML-authored text — always quoted so\n // it never round-trips as a number or boolean (see quotedKeyNode).\n lines.push(k === \"key\" ? ` key: ${JSON.stringify(String(v))}` : ` ${k}: ${yamlScalar(v)}`);\n }\n lines.push(\" models:\");\n for (const [k, v] of Object.entries(p.models)) lines.push(` ${k}: ${yamlScalar(v)}`);\n }\n lines.push(\"\");\n lines.push(\"# A class names a provider, or provider/role to pick a non-default model.\");\n lines.push(\"# Workers exist to parallelise and to save cost: the default is Sonnet,\");\n lines.push(\"# Haiku for the mechanical classes, and nothing here inherits the\");\n lines.push(\"# orchestrating session's model.\");\n const classEntries = Object.entries(data.classes);\n lines.push(classEntries.length ? \"classes:\" : \"classes: {}\");\n for (const [cls, target] of classEntries) {\n lines.push(` ${cls}: ${typeof target === \"string\" ? target : yamlScalar(target)}`);\n }\n lines.push(\"\");\n const capEntries = Object.entries(data.capabilities);\n if (capEntries.length) {\n lines.push(\"capabilities:\");\n for (const [cap, prefs] of capEntries) lines.push(` ${cap}: [${prefs.join(\", \")}]`);\n lines.push(\"\");\n }\n const mcpEntries = Object.entries(data.mcpSets);\n lines.push(mcpEntries.length ? \"mcp_sets:\" : \"mcp_sets: {}\");\n for (const [set, servers] of mcpEntries) {\n lines.push(` ${set}: [${servers.join(\", \")}]`);\n }\n lines.push(\"\");\n return lines.join(\"\\n\");\n}\n\n/** Minimal scalar formatter for buildWorkersYamlText's flat key: value lines. */\nfunction yamlScalar(v: unknown): string {\n if (typeof v === \"string\") {\n // quote only when the plain form would be ambiguous YAML\n return /^[\\w./~\\[\\]-]+$/.test(v) ? v : JSON.stringify(v);\n }\n if (Array.isArray(v)) return `[${v.map(yamlScalar).join(\", \")}]`;\n if (v && typeof v === \"object\") return JSON.stringify(v);\n return String(v);\n}\n\n// ---------------------------------------------------------------------------\n// Migration from the JSON `workers` section\n// ---------------------------------------------------------------------------\n\nexport interface MigrateResult {\n yamlPath: string;\n yamlText: string;\n /** Path the pre-migration JSON `workers` section was backed up to; null on a dry run. */\n backupPath: string | null;\n dryRun: boolean;\n}\n\n/**\n * `pai worker config migrate`: reads the JSON `workers` section, writes\n * workers.yaml with the starter's comments, backs the JSON section up to\n * `workers.json.migrated-<date>` next to it, and strips providers/classes\n * (and the legacy `roles`)/mcpSets/active from the JSON. Idempotent: refuses\n * when workers.yaml already exists unless `force`. `dryRun` computes and\n * returns the would-be YAML text without touching either file.\n */\nexport function migrateWorkersToYaml(\n jsonPath: string,\n opts: { force?: boolean; dryRun?: boolean } = {}\n): MigrateResult {\n const existing = workersYamlPath();\n if (existsSync(existing) && !opts.force) {\n throw new WorkersConfigError(\n `${existing} already exists — refusing to overwrite without --force`\n );\n }\n const yamlPath = writeTargetWorkersYamlPath();\n const raw = readJsonStrict(jsonPath, jsonPath);\n const workers = parseWorkersConfig(raw.workers);\n const data: WorkersYamlData = {\n active: workers.active,\n providers: workers.providers,\n classes: workers.classes,\n capabilities: workers.capabilities,\n mcpSets: workers.mcpSets,\n nativeModels: workers.nativeModels,\n };\n const yamlText = buildWorkersYamlText(data);\n\n if (opts.dryRun) {\n return { yamlPath, yamlText, backupPath: null, dryRun: true };\n }\n\n writeWorkersYamlText(yamlPath, yamlText);\n\n const stamp = new Date().toISOString().slice(0, 10);\n const backupPath = join(dirname(jsonPath), `workers.json.migrated-${stamp}`);\n writeFileSync(backupPath, JSON.stringify(raw.workers ?? {}, null, 2) + \"\\n\", \"utf8\");\n\n const priorWorkers = (raw.workers as Record<string, unknown>) ?? {};\n const { providers: _p, classes: _c, roles: _r, mcpSets: _m, active: _a, ...rest } = priorWorkers;\n raw.workers = rest;\n writeJsonAtomic(jsonPath, raw, { label: jsonPath });\n\n return { yamlPath, yamlText, backupPath, dryRun: false };\n}\n\n/**\n * `pai worker config init`: write the literal commented starter (no data to\n * carry over — that is what `migrate` is for). Refuses if workers.yaml\n * already exists.\n */\nexport function initWorkersYaml(): string {\n const existing = workersYamlPath();\n if (existsSync(existing)) {\n throw new WorkersConfigError(\n `${existing} already exists — edit it directly, or run \\`pai worker config migrate --force\\` to regenerate it from the JSON config`\n );\n }\n const yamlPath = writeTargetWorkersYamlPath();\n writeWorkersYamlText(yamlPath, starterWorkersYamlText());\n return yamlPath;\n}\n\n// ---------------------------------------------------------------------------\n// Relocating from an old location\n// ---------------------------------------------------------------------------\n\nexport type RelocateResult = MigrateFileResult;\n\n/** True when an old-location workers.yaml exists and nothing is at the new one yet. */\nexport function needsWorkersYamlRelocation(): boolean {\n return (\n !process.env.PAI_WORKERS_YAML &&\n !existsSync(defaultWorkersYamlPath()) &&\n [oldWorkersYamlPath(), legacyWorkersYamlPath()].some((p) => existsSync(p))\n );\n}\n\n/**\n * `pai worker config migrate` when workers.yaml is still at an old location\n * (~/.claude/workers.yaml or, older still, ~/.config/pai/workers.yaml): a\n * byte-for-byte copy to the new path (comments, keys, everything — this only\n * changes where the file lives), verified, then the old file is renamed\n * aside as workers.yaml.migrated-<YYYYMMDD> (never deleted). No JSON\n * involved, and no secrets are read or transformed beyond copying bytes.\n */\nexport function relocateWorkersYaml(opts: { force?: boolean; dryRun?: boolean } = {}): RelocateResult {\n const toPath = writeTargetWorkersYamlPath();\n const result = migratePaiFile(toPath, [oldWorkersYamlPath(), legacyWorkersYamlPath()], opts);\n if (!result.dryRun && result.fromPath) chmodSync(toPath, 0o600);\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Inlining key_file contents as `key:`\n// ---------------------------------------------------------------------------\n\nexport interface InlineKeysResult {\n yamlPath: string;\n inlined: { provider: string; keyFilePath: string }[];\n dryRun: boolean;\n}\n\n/**\n * `pai worker config inline-keys`: for every provider with a `key_file` and\n * no `key`, read the file, write its trimmed contents as a quoted `key:`,\n * and remove `key_file`. The key file itself is left on disk — this only\n * changes what workers.yaml reads from, never deletes a credential the\n * operator might still want. `dryRun` computes the plan (provider names and\n * key file paths only — never the key values) without writing anything.\n */\nexport function inlineWorkersYamlKeys(opts: { dryRun?: boolean } = {}): InlineKeysResult {\n const yamlPath = workersYamlPath();\n const existing = readWorkersYaml(yamlPath);\n if (!existing) {\n throw new WorkersConfigError(`${yamlPath} does not exist — run \\`pai worker config init\\` first`);\n }\n const { doc, data } = existing;\n const inlined: { provider: string; keyFilePath: string }[] = [];\n for (const [name, p] of Object.entries(data.providers)) {\n if (p.key || !p.keyFile) continue;\n const keyPath = expandHome(p.keyFile);\n let content: string;\n try {\n content = readFileSync(keyPath, \"utf8\");\n } catch (e) {\n throw new WorkersConfigError(\n `providers.${name}.key_file: could not read ${keyPath}: ${e instanceof Error ? e.message : String(e)}`\n );\n }\n const token = content.trim();\n if (!token) throw new WorkersConfigError(`providers.${name}.key_file: ${keyPath} is empty`);\n inlined.push({ provider: name, keyFilePath: p.keyFile });\n if (!opts.dryRun) {\n doc.setIn([\"providers\", name, \"key\"], quotedKeyNode(token));\n doc.deleteIn([\"providers\", name, \"key_file\"]);\n }\n }\n if (!opts.dryRun && inlined.length) {\n writeWorkersYamlText(yamlPath, String(doc));\n }\n return { yamlPath, inlined, dryRun: !!opts.dryRun };\n}\n","/**\n * config.ts — the `workers` section of the PAI config file (CONFIG_FILE,\n * see src/daemon/config.ts's paiConfigFilePath — ~/.claude/pai/config.yaml\n * today, config.json until `pai config yaml` runs).\n *\n * Everything that knows about worker providers reads this module: the CLI\n * (`pai worker …`), the MCP tools (worker_*), and the Agent-routing hook.\n * Keep it free of commander/MCP imports so all three layers stay thin over it.\n *\n * Keys are never stored here — only paths to 0600 files. A provider without a\n * keyFile is a local server and gets the placeholder token \"local\".\n *\n * `protocol: \"openai\"` providers run through the PAI proxy (src/workers/proxy):\n * `upstreamUrl` is their Chat Completions base, and `run` points\n * ANTHROPIC_BASE_URL at the local proxy with the provider name in the path.\n * `engine: \"codex\"` providers run through the Codex CLI instead of Claude\n * Code.\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { CONFIG_FILE, readMainConfigRaw, writeMainConfigRaw } from \"../daemon/config.js\";\nimport { paiHomePath } from \"../config/pai-home.js\";\nimport { contextWindowFromModelId, DEFAULT_CONTEXT_WINDOW } from \"../utils/model-window.js\";\nimport { readWorkersYaml, workersYamlPath, writeWorkersYaml, type WorkersYamlData } from \"./workers-config.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * Wire protocol a provider speaks: \"anthropic\" natively, \"openai\" through the\n * PAI proxy (which translates the Anthropic Messages API to Chat Completions).\n */\nexport type WorkerProtocol = \"anthropic\" | \"openai\";\n\n/**\n * Runner executable behind a provider: Claude Code, the Codex CLI, or the\n * \"image\" engine (src/workers/engines/image.ts — an OpenAI-compatible\n * images API, not a claude/codex spawn).\n */\nexport type WorkerEngine = \"claude\" | \"codex\" | \"image\";\n\n/** One quota window the statusline renders for a provider (e.g. \"5h\", \"7d\"). */\nexport interface UsageWindow {\n /** Window label shown in the statusline, e.g. \"5h\". */\n name: string;\n /** jq expression against the usage response yielding a percent 0–100. */\n percent: string;\n /** jq expression against the usage response yielding the reset time. */\n resetAt?: string;\n /** How resetAt is interpreted: epoch ms (default), epoch s, or ISO string. */\n resetUnit?: \"ms\" | \"s\" | \"iso\";\n}\n\n/**\n * How the statusline fetches and renders a provider's plan quota. The block\n * names a JSON GET endpoint plus per-window jq expressions, so a new provider\n * is config, not code in statusline-command.sh.\n */\nexport interface ProviderUsage {\n /** GET endpoint returning the usage JSON. */\n url: string;\n /**\n * Auth header template, default \"Authorization: Bearer\"; the key from\n * keyFile is appended after a space. A value without a space (e.g.\n * \"x-api-key\") is sent as \"<authHeader>: <key>\".\n */\n authHeader?: string;\n /** Display label for the usage segments, default = provider name. */\n label?: string;\n windows: UsageWindow[];\n /** Statusline cache TTL in seconds, default 60. */\n ttlSeconds?: number;\n}\n\nexport interface WorkerProvider {\n enabled: boolean;\n /** Wire protocol the baseUrl speaks. */\n protocol: WorkerProtocol;\n /** Anthropic-compatible Messages API base. */\n baseUrl: string;\n /** 0600 file holding the auth token; null for local servers (\"local\"). */\n keyFile: string | null;\n /**\n * The auth token itself, inline in workers.yaml. Wins over keyFile when\n * both are set (`pai worker config check` notices this). Keeping the key\n * out of a separate file is the operator's explicit call — the file this\n * lives in must be 0600 (writeWorkersYamlText enforces that) and is never\n * committed. See resolveProviderKey for the one place this is read.\n */\n key?: string;\n /** Model id per capability; see MODEL_CAPABILITIES. Only default is required. */\n models: { default: string } & Partial<Record<ModelCapability, string>>;\n /**\n * Model id → tier alias, overriding the built-in mapping (models.fast →\n * haiku tier, models.default → sonnet tier). Lets a provider pin an extra\n * model id to a tier, e.g. a heavyweight default to the opus tier.\n */\n modelTiers?: Record<string, ModelTier>;\n /** Extra environment variables for runs through this provider (string values). */\n env: Record<string, string>;\n note?: string;\n /**\n * OpenAI Chat Completions base (e.g. \"https://api.openai.com/v1\"). Required\n * for protocol \"openai\"; read by the PAI proxy, never by the runner.\n */\n upstreamUrl?: string;\n /** Runner for this provider; \"codex\" goes through the Codex CLI. */\n engine?: WorkerEngine;\n /** Optional shell command printing 0–100 (percent of quota used). */\n quotaProbe?: string;\n /** Auto-routing skips the provider at or above this percentage. Default 95. */\n quotaSkipAt?: number;\n /**\n * Context window of the provider's model, for the context meter. No\n * default: the meter only shows a window the init event announced (or\n * this explicit value, for engines without one, e.g. codex).\n */\n contextWindow?: number;\n /** Cost tier 1 (cheapest) … 5 (most expensive); classes cap it via maxCostTier. */\n costTier?: number;\n /** Capability tags; classes filter auto-routing via requireTags. */\n tags?: ProviderTag[];\n /** Statusline plan-quota block; see ProviderUsage. Absent = \"usage n/a\". */\n usage?: ProviderUsage;\n /**\n * True only for the synthetic built-in \"anthropic\" provider (see\n * ANTHROPIC_NATIVE): plain Claude Code, on its own OAuth/Max-plan login —\n * no baseUrl, no key file, no config entry. Never set by parseProvider.\n */\n native?: boolean;\n}\n\n/**\n * Reserved provider name for plain Anthropic: Claude Code's own OAuth/Max-plan\n * login, no base URL override and no API key. It never needs (or accepts) a\n * `providers.anthropic` config entry — resolveTarget/mustExist synthesize it\n * on demand via `nativeAnthropicProvider()`.\n */\nexport const ANTHROPIC_NATIVE = \"anthropic\";\n\n/**\n * Models the built-in provider runs on. This is the only place a model id is\n * named for it: run.ts resolves the class capability against this table like\n * it does for any configured provider and passes `--model` explicitly.\n *\n * Workers exist to parallelise and to save cost, so they must never inherit\n * the orchestrator's model. A bare headless `claude` takes the interactive\n * session default, and one probe came up on the most expensive tier because\n * the chat session had been switched to it. Sonnet is the working tier;\n * haiku serves the fast classes (spotcheck, simple). These are the Claude\n * Code CLI's own tier aliases, not pinned ids: the CLI resolves each to its\n * newest model on every run, so the tier tracks a release without a code\n * change here (adoptInitModel in run.ts swaps the alias for the init event's\n * resolved id once the run announces one).\n */\nexport const NATIVE_ANTHROPIC_MODELS: WorkerProvider[\"models\"] = {\n default: \"sonnet\",\n fast: \"haiku\",\n};\n\n/**\n * The synthetic provider object for ANTHROPIC_NATIVE. `baseUrl` is empty and\n * there is no key file, so buildRunEnv strips every provider env override;\n * the models come from NATIVE_ANTHROPIC_MODELS so a run always names its\n * model on the command line.\n */\nexport function nativeAnthropicProvider(\n models: WorkerProvider[\"models\"] = NATIVE_ANTHROPIC_MODELS\n): WorkerProvider {\n return {\n enabled: true,\n protocol: \"anthropic\",\n baseUrl: \"\",\n keyFile: null,\n models: { ...models },\n env: {},\n native: true,\n };\n}\n\n/**\n * Provider by name, synthesizing ANTHROPIC_NATIVE when it is asked for. Reads\n * `config.nativeModels` (workers.yaml's documented `providers.anthropic.models`\n * override, if any) so a config that pins a different default/fast id for the\n * built-in provider is honored everywhere a provider is resolved.\n */\nexport function getProviderOrNative(\n config: { providers: Record<string, WorkerProvider>; nativeModels?: WorkerProvider[\"models\"] },\n name: string\n): WorkerProvider | undefined {\n if (name === ANTHROPIC_NATIVE) return nativeAnthropicProvider(config.nativeModels);\n return config.providers[name];\n}\n\nexport interface WorkersPaneConfig {\n enabled: boolean;\n /** Font size (points) of the follow-pane profile's font. */\n fontSize: number;\n /** Seconds a pane lingers after its worker goes quiet. */\n autoExitSecs: number;\n}\n\nexport interface WorkersRoutingConfig {\n /** Provider names in preference order; first usable one wins. */\n order: string[];\n /** Minutes a provider sits in cooldown after a quota/rate failure. */\n cooldownMinutes: number;\n /** Reroute a failed-before-first-tool run to the next provider. */\n retryOnQuota: boolean;\n}\n\n/** Sub-worker caps: how deep the worker tree may grow, how wide per parent. */\nexport interface WorkersTreeConfig {\n /** Maximum nesting depth of sub-workers (top-level = 0). */\n maxDepth: number;\n /** Maximum concurrently running children per parent. */\n maxChildren: number;\n}\n\n/** Cost/quality tier of a provider's model, 1 (cheapest) … 5 (most expensive). */\nexport type CostTier = 1 | 2 | 3 | 4 | 5;\n\n/** The tier aliases the CLI and daemon tables understand — class proxies, not\n * Anthropic model names: any provider's model maps onto one of these. */\nexport type ModelTier = \"haiku\" | \"sonnet\" | \"opus\";\n\nconst MODEL_TIERS: readonly ModelTier[] = [\"haiku\", \"sonnet\", \"opus\"];\n\nexport const DEFAULT_COST_TIER = 3;\n\n/** Tags a provider may carry; classes filter auto-routing on them. */\nexport const PROVIDER_TAGS = [\n \"code\",\n \"vision\",\n \"image-gen\",\n \"long-context\",\n \"fast\",\n \"reasoning\",\n] as const;\n\nexport type ProviderTag = (typeof PROVIDER_TAGS)[number];\n\n/** The standard task classes; `workers.classes` maps each to a target. */\nexport const WORKER_CLASSES = [\n \"draft\",\n \"plan\",\n \"implement\",\n \"review\",\n \"research\",\n \"spotcheck\",\n \"simple\",\n \"complex\",\n \"image\",\n] as const;\n\nexport type WorkerClassName = (typeof WORKER_CLASSES)[number];\n\n/**\n * The well-known model capabilities — documented, and what the starter\n * workers.yaml and `pai worker model`'s listing show by name. The set is\n * open, though: a provider's `models` block may carry any capability name\n * matching CAPABILITY_NAME_RE (see isModelCapability), e.g. \"vision\" or\n * \"longcontext\" for a provider that serves them. \"default\" is the required\n * catch-all; the others name what a model is *for* — \"fast\" the cheap tier\n * (spotcheck, haiku-tier spawns), \"image\" the image class/capability.\n * Everything resolves through resolveModelCapability, falling back to\n * default; cross-provider preference for a capability is `capabilities:` in\n * workers.yaml (see resolveCapability).\n */\nexport const MODEL_CAPABILITIES = [\"default\", \"fast\", \"image\"] as const;\n\nexport type ModelCapability = string;\n\nexport const CAPABILITY_NAME_RE = /^[a-z][a-z0-9-]*$/;\n\n/** Is this string a syntactically valid capability name (open set)? */\nexport function isModelCapability(v: string): v is ModelCapability {\n return CAPABILITY_NAME_RE.test(v);\n}\n\n/**\n * Which model capability a class runs on when its target names no alias: the\n * image class uses the image model, the cheap classes (spotcheck, simple) the\n * fast model, every other class the provider default. A provider without a\n * fast model falls back to its default (resolveModelCapability).\n */\nconst CLASS_MODEL_CAPABILITY: Record<WorkerClassName, ModelCapability> = {\n draft: \"default\",\n plan: \"default\",\n implement: \"default\",\n review: \"default\",\n research: \"default\",\n spotcheck: \"fast\",\n simple: \"fast\",\n complex: \"default\",\n image: \"image\",\n};\n\n/** Capability for a run's class (default when unset or not a standard class). */\nexport function classModelCapability(className?: string): ModelCapability {\n return (className && CLASS_MODEL_CAPABILITY[className as WorkerClassName]) || \"default\";\n}\n\n/**\n * A class target: \"<provider>\", \"<provider>/<modelAlias>\", or an object. The\n * object either pins a `provider` (plus optional `mcp` allowlist) or only\n * constrains auto-routing (`maxCostTier`, `requireTags`, per-class `order`).\n */\nexport type ClassTarget =\n | string\n | {\n provider?: string;\n mcp?: string[];\n /** Auto-routing may only use providers at or below this cost tier. */\n maxCostTier?: number;\n /** Auto-routing may only use providers carrying all these tags. */\n requireTags?: string[];\n /** Provider order for this class; defaults to routing.order. */\n order?: string[];\n };\n\n/**\n * State of the machine-wide Claude Code fallback (`pai worker fallback on`):\n * every new Claude Code process runs on `provider` until `fallback off`.\n * `saved` holds what ~/.claude/settings.json carried before the switch so\n * `off` can restore it exactly.\n */\nexport interface WorkersFallback {\n /** Provider every new Claude Code process is pointed at. */\n provider: string;\n /**\n * settings.json before the switch. `env` records the previous value of\n * every env key fallback touched (null = the key was absent), `model` the\n * previous top-level model pin (null = none), `envExisted` whether an env\n * block existed at all.\n */\n saved: {\n env: Record<string, string | null>;\n model: string | null;\n envExisted: boolean;\n };\n /** ISO stamp of the switch (shown by `fallback status`). */\n on: string;\n}\n\nexport interface WorkersConfig {\n enabled: boolean;\n /** Provider name, or \"auto\" for routing.order resolution. */\n active: string | null;\n providers: Record<string, WorkerProvider>;\n /** Class → target; see ClassTarget. (Reads the legacy `roles` key.) */\n classes: Record<string, ClassTarget>;\n /** MCP set name → server names; `--mcp <set>` and class `mcp` expand these. */\n mcpSets: Record<string, string[]>;\n /**\n * Capability → provider names in preference order (workers.yaml\n * `capabilities:`), e.g. `{ image: [\"pictures\", \"glm\"] }`. Cross-provider,\n * unlike a provider's own `models` table: this is what lets `--capability\n * image` find the one provider configured to serve it. See resolveCapability.\n */\n capabilities: Record<string, string[]>;\n pane: WorkersPaneConfig;\n logDir: string;\n routing: WorkersRoutingConfig;\n /** Sub-worker caps (workers.tree). */\n tree: WorkersTreeConfig;\n /**\n * Daemon cache-keepalive cadence in seconds: how often a trivial\n * single-turn heartbeat worker re-arms the provider prompt cache\n * (src/workers/keepalive.ts). 0 = off.\n */\n cacheKeepaliveSecs: number;\n /** Default time limit of every run in minutes (workers.defaultMaxMinutes); 0 = none. */\n defaultMaxMinutes: number;\n /** Runs strip browser tools unless --browser is passed (workers.noBrowserByDefault). */\n noBrowserByDefault: boolean;\n /**\n * Run native-Anthropic workers through `caveman claude` (workers.caveman).\n * Off pins them to api.anthropic.com even when the user settings route\n * every claude through a proxy; see claudeCommand in run-env.ts.\n */\n caveman: boolean;\n /** Machine-wide Claude Code fallback; null = off. */\n fallback: WorkersFallback | null;\n /**\n * Model ids for the built-in `anthropic` provider, when workers.yaml\n * documents an override under `providers.anthropic.models`. Defaults to\n * NATIVE_ANTHROPIC_MODELS.\n */\n nativeModels: WorkerProvider[\"models\"];\n}\n\n// ---------------------------------------------------------------------------\n// Defaults\n// ---------------------------------------------------------------------------\n\nexport const DEFAULT_LOG_DIR = \"~/.claude/logs/workers\";\n\nexport const DEFAULT_PANE: WorkersPaneConfig = {\n enabled: true,\n fontSize: 13,\n autoExitSecs: 60,\n};\n\nexport const DEFAULT_ROUTING: WorkersRoutingConfig = {\n order: [],\n cooldownMinutes: 30,\n retryOnQuota: true,\n};\n\nexport const DEFAULT_TREE: WorkersTreeConfig = {\n maxDepth: 2,\n maxChildren: 4,\n};\n\n/**\n * Cache-keepalive cadence when the config names none. Measured 2026-09-18\n * (pair probes through the real worker spawn path, numbers in\n * docs/cache-keepalive.md): the implicit provider cache only serves a fresh\n * worker warm within roughly the first minute (positive back-to-back, gone\n * at 2 min), and it covers only ~2.6k of the ~18k-token prefix. Holding it\n * needs a beat every <2 min — a continuous bill for a small saving — so the\n * default is OFF and arming it is the operator's explicit call (set e.g.\n * \"cacheKeepaliveSecs\": 60).\n */\nexport const DEFAULT_CACHE_KEEPALIVE_SECS = 0;\nexport const DEFAULT_MAX_MINUTES = 60;\n\n/**\n * The default MCP sets every config starts from. `desktop` names the clickr\n * server so `--mcp desktop` hands a worker the machine controls (read-only\n * tools always; actuating ones after the operator hands the controls over,\n * see `pai worker controls`). A user's mcpSets section is merged over this,\n * so `desktop: []` removes the set deliberately.\n */\nexport const DEFAULT_MCP_SETS: Record<string, string[]> = {\n desktop: [\"clickr\"],\n};\n\nexport function defaultWorkersConfig(): WorkersConfig {\n return {\n enabled: false,\n active: null,\n providers: {},\n classes: {},\n mcpSets: { ...DEFAULT_MCP_SETS },\n capabilities: {},\n pane: { ...DEFAULT_PANE },\n logDir: DEFAULT_LOG_DIR,\n routing: { ...DEFAULT_ROUTING, order: [] },\n tree: { ...DEFAULT_TREE },\n cacheKeepaliveSecs: DEFAULT_CACHE_KEEPALIVE_SECS,\n defaultMaxMinutes: DEFAULT_MAX_MINUTES,\n noBrowserByDefault: false,\n caveman: false,\n fallback: null,\n nativeModels: { ...NATIVE_ANTHROPIC_MODELS },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Validation\n// ---------------------------------------------------------------------------\n\nexport class WorkersConfigError extends Error {}\n\nfunction bad(path: string, why: string): never {\n throw new WorkersConfigError(`workers${path}: ${why}`);\n}\n\nfunction str(v: unknown): string {\n return typeof v === \"string\" ? v : \"\";\n}\n\n/**\n * Parse a `models` block (capability → model id, \"default\" required). Shared\n * by parseProvider and the YAML loader's builtin-anthropic override, which\n * has no other provider fields to validate.\n */\nexport function parseModelsBlock(pathPrefix: string, modelsRaw: unknown): WorkerProvider[\"models\"] {\n const raw = modelsRaw === undefined ? {} : modelsRaw;\n if (typeof raw !== \"object\" || raw === null) bad(pathPrefix, \"must be an object\");\n const m = raw as Record<string, unknown>;\n const defaultModel = str(m.default);\n if (!defaultModel) bad(`${pathPrefix}.default`, \"is required\");\n const models: WorkerProvider[\"models\"] = { default: defaultModel };\n for (const key of Object.keys(m)) {\n if (key === \"default\") continue;\n if (!isModelCapability(key)) {\n bad(\n `${pathPrefix}.${key}`,\n `\"${key}\" is not a valid capability name (must match ^[a-z][a-z0-9-]*$; well-known: ${MODEL_CAPABILITIES.join(\", \")}, but any name in that shape is accepted)`\n );\n }\n const id = str(m[key]);\n if (!id) bad(`${pathPrefix}.${key}`, \"must be a non-empty model id\");\n models[key] = id;\n }\n return models;\n}\n\n/** Parse and validate one provider entry (shared by JSON and YAML loading). */\nexport function parseProvider(name: string, raw: unknown): WorkerProvider {\n if (name === ANTHROPIC_NATIVE) {\n bad(\n `.providers.${name}`,\n `\"${ANTHROPIC_NATIVE}\" is reserved for plain Anthropic (Claude Code's own OAuth/Max-plan login) and cannot be configured here — remove this entry; use --provider ${ANTHROPIC_NATIVE} or \"pai worker providers use ${ANTHROPIC_NATIVE}\" instead`\n );\n }\n if (typeof raw !== \"object\" || raw === null) bad(`.providers.${name}`, \"must be an object\");\n const p = raw as Record<string, unknown>;\n\n const protocol = p.protocol === undefined ? \"anthropic\" : str(p.protocol);\n if (protocol !== \"anthropic\" && protocol !== \"openai\") {\n bad(`.providers.${name}.protocol`, `\"${str(p.protocol)}\" is neither \"anthropic\" nor \"openai\"`);\n }\n const engine = p.engine === undefined ? \"claude\" : str(p.engine);\n if (engine !== \"claude\" && engine !== \"codex\" && engine !== \"image\") {\n bad(`.providers.${name}.engine`, `\"${str(p.engine)}\" is none of \"claude\", \"codex\", \"image\"`);\n }\n\n const baseUrl = str(p.baseUrl);\n // openai providers reach the model through the PAI proxy; their baseUrl is\n // the proxy URL, filled in by the runner — only anthropic needs one here.\n if (!baseUrl && protocol !== \"openai\") bad(`.providers.${name}.baseUrl`, \"is required\");\n\n const keyFile =\n p.keyFile === undefined || p.keyFile === null || str(p.keyFile) === \"\"\n ? null\n : str(p.keyFile);\n const key = str(p.key) || undefined;\n\n const models = parseModelsBlock(`.providers.${name}.models`, p.models);\n\n let modelTiers: Record<string, ModelTier> | undefined;\n if (p.modelTiers !== undefined) {\n if (typeof p.modelTiers !== \"object\" || p.modelTiers === null || Array.isArray(p.modelTiers)) {\n bad(`.providers.${name}.modelTiers`, \"must be an object of model id → haiku | sonnet | opus\");\n }\n modelTiers = {};\n for (const [id, tier] of Object.entries(p.modelTiers as Record<string, unknown>)) {\n if (typeof tier !== \"string\" || !MODEL_TIERS.includes(tier as ModelTier)) {\n bad(\n `.providers.${name}.modelTiers.${id}`,\n `must be \"haiku\", \"sonnet\" or \"opus\" (got ${JSON.stringify(tier)})`\n );\n }\n modelTiers[id] = tier as ModelTier;\n }\n }\n\n const env: Record<string, string> = {};\n if (p.env !== undefined) {\n if (typeof p.env !== \"object\" || p.env === null || Array.isArray(p.env)) {\n bad(`.providers.${name}.env`, \"must be an object of string values\");\n }\n for (const [k, v] of Object.entries(p.env as Record<string, unknown>)) {\n if (typeof v !== \"string\") bad(`.providers.${name}.env.${k}`, \"must be a string\");\n env[k] = v;\n }\n }\n\n const quotaSkipAt = p.quotaSkipAt === undefined ? undefined : p.quotaSkipAt;\n if (quotaSkipAt !== undefined) {\n if (typeof quotaSkipAt !== \"number\" || quotaSkipAt < 0 || quotaSkipAt > 100) {\n bad(`.providers.${name}.quotaSkipAt`, \"must be a number between 0 and 100\");\n }\n }\n\n const contextWindow = p.contextWindow === undefined ? undefined : p.contextWindow;\n if (contextWindow !== undefined) {\n if (typeof contextWindow !== \"number\" || contextWindow <= 0) {\n bad(`.providers.${name}.contextWindow`, \"must be a positive number of tokens\");\n }\n }\n\n const upstreamUrl = str(p.upstreamUrl);\n if (protocol === \"openai\" && !upstreamUrl) {\n bad(`.providers.${name}.upstreamUrl`, `is required for protocol \"openai\" (the Chat Completions base, e.g. \"https://api.openai.com/v1\")`);\n }\n\n const costTier = p.costTier === undefined ? undefined : p.costTier;\n if (costTier !== undefined) {\n if (typeof costTier !== \"number\" || !Number.isInteger(costTier) || costTier < 1 || costTier > 5) {\n bad(`.providers.${name}.costTier`, \"must be an integer 1 (cheapest) … 5 (most expensive)\");\n }\n }\n\n let tags: ProviderTag[] | undefined;\n if (p.tags !== undefined) {\n if (!Array.isArray(p.tags) || p.tags.some((x) => typeof x !== \"string\")) {\n bad(`.providers.${name}.tags`, `must be an array of tags from: ${PROVIDER_TAGS.join(\", \")}`);\n }\n for (const t of p.tags as string[]) {\n if (!(PROVIDER_TAGS as readonly string[]).includes(t)) {\n bad(`.providers.${name}.tags`, `\"${t}\" is not a tag (from: ${PROVIDER_TAGS.join(\", \")})`);\n }\n }\n tags = p.tags as ProviderTag[];\n }\n\n let usage: ProviderUsage | undefined;\n if (p.usage !== undefined) {\n if (typeof p.usage !== \"object\" || p.usage === null || Array.isArray(p.usage)) {\n bad(`.providers.${name}.usage`, \"must be an object\");\n }\n const u = p.usage as Record<string, unknown>;\n const usageUrl = str(u.url);\n if (!usageUrl) bad(`.providers.${name}.usage.url`, \"is required\");\n if (!Array.isArray(u.windows) || u.windows.length === 0) {\n bad(`.providers.${name}.usage.windows`, \"must be a non-empty array\");\n }\n const windows: UsageWindow[] = [];\n for (const [i, wRaw] of (u.windows as unknown[]).entries()) {\n const wpath = `.providers.${name}.usage.windows[${i}]`;\n if (typeof wRaw !== \"object\" || wRaw === null || Array.isArray(wRaw)) {\n bad(wpath, \"must be an object\");\n }\n const w = wRaw as Record<string, unknown>;\n const wname = str(w.name);\n if (!wname) bad(`${wpath}.name`, \"is required\");\n const percent = str(w.percent);\n if (!percent) bad(`${wpath}.percent`, \"is required (a jq expression yielding 0–100)\");\n const resetUnit = w.resetUnit === undefined ? undefined : str(w.resetUnit);\n if (resetUnit !== undefined && resetUnit !== \"ms\" && resetUnit !== \"s\" && resetUnit !== \"iso\") {\n bad(`${wpath}.resetUnit`, `must be \"ms\", \"s\" or \"iso\"`);\n }\n windows.push({\n name: wname,\n percent,\n ...(str(w.resetAt) ? { resetAt: str(w.resetAt) } : {}),\n ...(resetUnit ? { resetUnit } : {}),\n });\n }\n const ttlSeconds = u.ttlSeconds === undefined ? undefined : u.ttlSeconds;\n if (ttlSeconds !== undefined && (typeof ttlSeconds !== \"number\" || ttlSeconds <= 0)) {\n bad(`.providers.${name}.usage.ttlSeconds`, \"must be a positive number of seconds\");\n }\n usage = {\n url: usageUrl,\n ...(str(u.authHeader) ? { authHeader: str(u.authHeader) } : {}),\n ...(str(u.label) ? { label: str(u.label) } : {}),\n windows,\n ...(ttlSeconds !== undefined ? { ttlSeconds } : {}),\n };\n }\n\n return {\n enabled: p.enabled === undefined ? true : p.enabled === true,\n protocol,\n baseUrl,\n keyFile,\n ...(key ? { key } : {}),\n models,\n ...(modelTiers ? { modelTiers } : {}),\n env,\n ...(str(p.note) ? { note: str(p.note) } : {}),\n ...(upstreamUrl ? { upstreamUrl } : {}),\n ...(engine !== \"claude\" ? { engine } : {}),\n ...(str(p.quotaProbe) ? { quotaProbe: str(p.quotaProbe) } : {}),\n ...(quotaSkipAt !== undefined ? { quotaSkipAt } : {}),\n ...(contextWindow !== undefined ? { contextWindow } : {}),\n ...(costTier !== undefined ? { costTier } : {}),\n ...(tags ? { tags } : {}),\n ...(usage ? { usage } : {}),\n };\n}\n\n/**\n * Parse a `classes` (or legacy `roles`) value shared by JSON and YAML\n * loading. `badPathPrefix` names the field in error messages, e.g. \".classes\".\n */\nexport function parseClassesValue(\n classesRaw: unknown,\n badPathPrefix: string\n): Record<string, ClassTarget> {\n const classes: Record<string, ClassTarget> = {};\n if (classesRaw === undefined) return classes;\n if (typeof classesRaw !== \"object\" || classesRaw === null || Array.isArray(classesRaw)) {\n bad(badPathPrefix, \"must be an object of class → provider[/alias] or {provider, mcp, maxCostTier, requireTags, order}\");\n }\n for (const [cls, target] of Object.entries(classesRaw as Record<string, unknown>)) {\n if (typeof target === \"object\" && target !== null && !Array.isArray(target)) {\n const o = target as Record<string, unknown>;\n const provider = str(o.provider);\n if (o.provider !== undefined && (!provider || provider.includes(\" \"))) {\n bad(`${badPathPrefix}.${cls}.provider`, `invalid provider \"${provider}\"`);\n }\n let mcp: string[] | undefined;\n if (o.mcp !== undefined) {\n if (!Array.isArray(o.mcp) || o.mcp.some((x) => typeof x !== \"string\")) {\n bad(`${badPathPrefix}.${cls}.mcp`, \"must be an array of MCP server or set names\");\n }\n mcp = o.mcp as string[];\n }\n let maxCostTier: number | undefined;\n if (o.maxCostTier !== undefined) {\n if (\n typeof o.maxCostTier !== \"number\" ||\n !Number.isInteger(o.maxCostTier) ||\n o.maxCostTier < 1 ||\n o.maxCostTier > 5\n ) {\n bad(`${badPathPrefix}.${cls}.maxCostTier`, \"must be an integer 1 … 5\");\n }\n maxCostTier = o.maxCostTier;\n }\n let requireTags: string[] | undefined;\n if (o.requireTags !== undefined) {\n if (!Array.isArray(o.requireTags) || o.requireTags.some((x) => typeof x !== \"string\")) {\n bad(`${badPathPrefix}.${cls}.requireTags`, `must be an array of tags from: ${PROVIDER_TAGS.join(\", \")}`);\n }\n for (const t of o.requireTags as string[]) {\n if (!(PROVIDER_TAGS as readonly string[]).includes(t)) {\n bad(`${badPathPrefix}.${cls}.requireTags`, `\"${t}\" is not a tag (from: ${PROVIDER_TAGS.join(\", \")})`);\n }\n }\n requireTags = o.requireTags as string[];\n }\n let order: string[] | undefined;\n if (o.order !== undefined) {\n if (!Array.isArray(o.order) || o.order.some((x) => typeof x !== \"string\")) {\n bad(`${badPathPrefix}.${cls}.order`, \"must be an array of provider names\");\n }\n order = o.order as string[];\n }\n const obj: ClassTarget = {\n ...(provider ? { provider } : {}),\n ...(mcp ? { mcp } : {}),\n ...(maxCostTier !== undefined ? { maxCostTier } : {}),\n ...(requireTags ? { requireTags } : {}),\n ...(order ? { order } : {}),\n };\n classes[cls] = Object.keys(obj).length ? obj : {};\n } else {\n const t = str(target);\n if (!t || t.includes(\" \")) bad(`${badPathPrefix}.${cls}`, `invalid target \"${t}\"`);\n classes[cls] = t;\n }\n }\n return classes;\n}\n\n/**\n * Parse an `mcpSets` (or `mcp_sets`) value shared by JSON and YAML loading.\n * Always merged over DEFAULT_MCP_SETS, so an omitted `desktop` key keeps the\n * built-in clickr set (see DEFAULT_MCP_SETS).\n */\nexport function parseMcpSetsValue(raw: unknown, badPathPrefix: string): Record<string, string[]> {\n const mcpSets: Record<string, string[]> = { ...DEFAULT_MCP_SETS };\n if (raw === undefined) return mcpSets;\n if (typeof raw !== \"object\" || raw === null || Array.isArray(raw)) {\n bad(badPathPrefix, \"must be an object of set name → [server names]\");\n }\n for (const [setName, servers] of Object.entries(raw as Record<string, unknown>)) {\n if (!Array.isArray(servers) || servers.some((x) => typeof x !== \"string\")) {\n bad(`${badPathPrefix}.${setName}`, \"must be an array of MCP server names\");\n }\n mcpSets[setName] = servers as string[];\n }\n return mcpSets;\n}\n\n/**\n * Parse a `capabilities` value shared by JSON and YAML loading: capability\n * name (open set, see isModelCapability) → provider names in preference\n * order. Provider names are not cross-checked here — a name that stops\n * existing is simply skipped by resolveCapability at resolve time, the same\n * way routing.order tolerates a removed provider.\n */\nexport function parseCapabilitiesValue(raw: unknown, badPathPrefix: string): Record<string, string[]> {\n const capabilities: Record<string, string[]> = {};\n if (raw === undefined) return capabilities;\n if (typeof raw !== \"object\" || raw === null || Array.isArray(raw)) {\n bad(badPathPrefix, \"must be an object of capability name → [provider names]\");\n }\n for (const [name, order] of Object.entries(raw as Record<string, unknown>)) {\n if (!isModelCapability(name)) {\n bad(`${badPathPrefix}.${name}`, `\"${name}\" is not a valid capability name (must match ^[a-z][a-z0-9-]*$)`);\n }\n if (!Array.isArray(order) || order.length === 0 || order.some((x) => typeof x !== \"string\" || !x)) {\n bad(`${badPathPrefix}.${name}`, \"must be a non-empty array of provider names\");\n }\n capabilities[name] = order as string[];\n }\n return capabilities;\n}\n\n/**\n * Parse and validate a raw `workers` value. Missing section → defaults.\n * Unknown-but-typed garbage → WorkersConfigError naming the offending field.\n */\nexport function parseWorkersConfig(raw: unknown): WorkersConfig {\n const d = defaultWorkersConfig();\n if (raw === undefined || raw === null) return d;\n if (typeof raw !== \"object\" || Array.isArray(raw)) {\n bad(\"\", \"section must be an object\");\n }\n const w = raw as Record<string, unknown>;\n\n const providers: Record<string, WorkerProvider> = {};\n if (w.providers !== undefined) {\n if (typeof w.providers !== \"object\" || w.providers === null || Array.isArray(w.providers)) {\n bad(\".providers\", \"must be an object keyed by provider name\");\n }\n for (const [name, p] of Object.entries(w.providers)) {\n providers[name] = parseProvider(name, p);\n }\n }\n\n // classes is canonical; a config that still carries the pre-classes `roles`\n // key is migrated by reading it here — the next write stores only `classes`.\n const classesRaw = w.classes !== undefined ? w.classes : w.roles;\n const classes = parseClassesValue(classesRaw, w.classes !== undefined ? \".classes\" : \".roles\");\n\n const mcpSets = parseMcpSetsValue(w.mcpSets, \".mcpSets\");\n const capabilities = parseCapabilitiesValue(w.capabilities, \".capabilities\");\n\n let pane = { ...DEFAULT_PANE };\n if (w.pane !== undefined) {\n if (typeof w.pane !== \"object\" || w.pane === null) bad(\".pane\", \"must be an object\");\n const pc = w.pane as Record<string, unknown>;\n if (pc.enabled !== undefined && typeof pc.enabled !== \"boolean\") bad(\".pane.enabled\", \"must be boolean\");\n if (pc.fontSize !== undefined && (typeof pc.fontSize !== \"number\" || pc.fontSize <= 0)) {\n bad(\".pane.fontSize\", \"must be a positive number of points\");\n }\n if (pc.autoExitSecs !== undefined && typeof pc.autoExitSecs !== \"number\") {\n bad(\".pane.autoExitSecs\", \"must be a number\");\n }\n // legacy fontScale (a relative scale, superseded by fontSize) is tolerated and ignored\n pane = {\n enabled: pc.enabled === undefined ? DEFAULT_PANE.enabled : pc.enabled === true,\n fontSize: pc.fontSize === undefined ? DEFAULT_PANE.fontSize : pc.fontSize,\n autoExitSecs: pc.autoExitSecs === undefined ? DEFAULT_PANE.autoExitSecs : pc.autoExitSecs,\n };\n }\n\n let routing = { ...DEFAULT_ROUTING, order: [] as string[] };\n if (w.routing !== undefined) {\n if (typeof w.routing !== \"object\" || w.routing === null) bad(\".routing\", \"must be an object\");\n const r = w.routing as Record<string, unknown>;\n if (r.order !== undefined) {\n if (!Array.isArray(r.order) || r.order.some((x) => typeof x !== \"string\")) {\n bad(\".routing.order\", \"must be an array of provider names\");\n }\n routing.order = r.order as string[];\n }\n if (r.cooldownMinutes !== undefined && typeof r.cooldownMinutes !== \"number\") {\n bad(\".routing.cooldownMinutes\", \"must be a number\");\n }\n if (r.retryOnQuota !== undefined && typeof r.retryOnQuota !== \"boolean\") {\n bad(\".routing.retryOnQuota\", \"must be boolean\");\n }\n routing = {\n order: routing.order,\n cooldownMinutes: r.cooldownMinutes === undefined ? DEFAULT_ROUTING.cooldownMinutes : r.cooldownMinutes,\n retryOnQuota: r.retryOnQuota === undefined ? DEFAULT_ROUTING.retryOnQuota : r.retryOnQuota === true,\n };\n }\n\n let tree = { ...DEFAULT_TREE };\n if (w.tree !== undefined) {\n if (typeof w.tree !== \"object\" || w.tree === null || Array.isArray(w.tree)) {\n bad(\".tree\", \"must be an object\");\n }\n const t = w.tree as Record<string, unknown>;\n if (t.maxDepth !== undefined) {\n if (typeof t.maxDepth !== \"number\" || !Number.isInteger(t.maxDepth) || t.maxDepth < 0) {\n bad(\".tree.maxDepth\", \"must be a non-negative integer\");\n }\n }\n if (t.maxChildren !== undefined) {\n if (typeof t.maxChildren !== \"number\" || !Number.isInteger(t.maxChildren) || t.maxChildren < 1) {\n bad(\".tree.maxChildren\", \"must be a positive integer\");\n }\n }\n tree = {\n maxDepth: t.maxDepth === undefined ? DEFAULT_TREE.maxDepth : t.maxDepth,\n maxChildren: t.maxChildren === undefined ? DEFAULT_TREE.maxChildren : t.maxChildren,\n };\n }\n\n let cacheKeepaliveSecs = DEFAULT_CACHE_KEEPALIVE_SECS;\n if (w.cacheKeepaliveSecs !== undefined) {\n if (\n typeof w.cacheKeepaliveSecs !== \"number\" ||\n !Number.isInteger(w.cacheKeepaliveSecs) ||\n w.cacheKeepaliveSecs < 0\n ) {\n bad(\".cacheKeepaliveSecs\", \"must be a non-negative integer (seconds, 0 = off)\");\n }\n cacheKeepaliveSecs = w.cacheKeepaliveSecs;\n }\n\n let defaultMaxMinutes = DEFAULT_MAX_MINUTES;\n if (w.defaultMaxMinutes !== undefined) {\n if (typeof w.defaultMaxMinutes !== \"number\" || !Number.isInteger(w.defaultMaxMinutes) || w.defaultMaxMinutes < 0) {\n bad(\".defaultMaxMinutes\", \"must be a non-negative integer (minutes, 0 = no limit)\");\n }\n defaultMaxMinutes = w.defaultMaxMinutes;\n }\n if (w.noBrowserByDefault !== undefined && typeof w.noBrowserByDefault !== \"boolean\") {\n bad(\".noBrowserByDefault\", \"must be true or false\");\n }\n const noBrowserByDefault = w.noBrowserByDefault === true;\n\n if (w.caveman !== undefined && typeof w.caveman !== \"boolean\") {\n bad(\".caveman\", \"must be true or false\");\n }\n const caveman = w.caveman === true;\n\n const active = w.active === undefined || w.active === null ? null : str(w.active);\n if (active !== null && active !== \"auto\" && !(active in providers)) {\n // Tolerated at parse time (a provider may have been removed while active\n // still names it) but every consumer resolves it to a clear error.\n }\n\n let fallback: WorkersFallback | null = null;\n if (w.fallback !== undefined && w.fallback !== null) {\n if (typeof w.fallback !== \"object\" || Array.isArray(w.fallback)) {\n bad(\".fallback\", \"must be an object (written by `pai worker fallback on`)\");\n }\n const f = w.fallback as Record<string, unknown>;\n const provider = str(f.provider);\n if (!provider) bad(\".fallback.provider\", \"is required\");\n const savedRaw = f.saved;\n if (typeof savedRaw !== \"object\" || savedRaw === null || Array.isArray(savedRaw)) {\n bad(\".fallback.saved\", \"must be an object\");\n }\n const s = savedRaw as Record<string, unknown>;\n if (typeof s.env !== \"object\" || s.env === null || Array.isArray(s.env)) {\n bad(\".fallback.saved.env\", \"must be an object of env key → previous value or null\");\n }\n const env: Record<string, string | null> = {};\n for (const [k, v] of Object.entries(s.env as Record<string, unknown>)) {\n env[k] = v === null || typeof v === \"string\" ? (v as string | null) : null;\n }\n if (s.model !== null && s.model !== undefined && typeof s.model !== \"string\") {\n bad(\".fallback.saved.model\", \"must be a string or null\");\n }\n fallback = {\n provider,\n saved: {\n env,\n model: typeof s.model === \"string\" ? s.model : null,\n envExisted: s.envExisted === true,\n },\n on: str(f.on) || new Date(0).toISOString(),\n };\n }\n\n return {\n enabled: w.enabled === undefined ? d.enabled : w.enabled === true,\n active,\n providers,\n classes,\n mcpSets,\n capabilities,\n pane,\n logDir: str(w.logDir) || d.logDir,\n routing,\n tree,\n cacheKeepaliveSecs,\n defaultMaxMinutes,\n noBrowserByDefault,\n caveman,\n fallback,\n nativeModels: { ...NATIVE_ANTHROPIC_MODELS },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Read / write\n// ---------------------------------------------------------------------------\n\nfunction workersYamlDataOf(workers: WorkersConfig): WorkersYamlData {\n return {\n active: workers.active,\n providers: workers.providers,\n classes: workers.classes,\n mcpSets: workers.mcpSets,\n capabilities: workers.capabilities,\n nativeModels: workers.nativeModels,\n };\n}\n\n/**\n * Read the whole config file and return (raw, workers) — the raw record so\n * callers can rewrite it preserving every other section, the parsed+validated\n * workers section. Unreadable config throws, missing is fine. `path`\n * overrides the config location (tests, CLAUDE_SETTINGS_PATH-style dry runs);\n * default CONFIG_FILE (see paiConfigFilePath). Reads via readMainConfigRaw,\n * so a config.yaml next to `path` is preferred over JSON, same as every\n * other main-config reader.\n *\n * Providers, classes, mcpSets and active load from workers.yaml (next to\n * `path`) when it exists; otherwise they fall back to the JSON `workers`\n * section, and then to built-in defaults — nothing breaks before migration\n * (`pai worker config migrate`). Everything else (pane, routing, tree,\n * cacheKeepaliveSecs, fallback, enabled, logDir) always comes from the main\n * config (JSON or YAML).\n */\nexport function readWorkersSection(path: string = CONFIG_FILE): {\n raw: Record<string, unknown>;\n workers: WorkersConfig;\n} {\n const raw = readMainConfigRaw(path);\n const workers = parseWorkersConfig(raw.workers);\n const yaml = readWorkersYaml(workersYamlPath());\n if (yaml) {\n workers.active = yaml.data.active;\n workers.providers = yaml.data.providers;\n workers.classes = yaml.data.classes;\n workers.mcpSets = yaml.data.mcpSets;\n workers.capabilities = yaml.data.capabilities;\n workers.nativeModels = yaml.data.nativeModels;\n }\n return { raw, workers };\n}\n\n/**\n * Write the workers section back, atomically. When workers.yaml exists, its\n * providers/classes/mcpSets/active are synced there (comment-preserving,\n * only the entries that changed are touched) and stripped from the JSON\n * `workers` section; everything else still writes to JSON as before.\n */\nexport function writeWorkersSection(\n raw: Record<string, unknown>,\n workers: WorkersConfig,\n path: string = CONFIG_FILE\n): void {\n const yamlPath = workersYamlPath();\n const usingYaml = existsSync(yamlPath);\n if (usingYaml) {\n writeWorkersYaml(yamlPath, workersYamlDataOf(workers));\n }\n const jsonWorkers = usingYaml\n ? {\n enabled: workers.enabled,\n pane: workers.pane,\n logDir: workers.logDir,\n routing: workers.routing,\n tree: workers.tree,\n cacheKeepaliveSecs: workers.cacheKeepaliveSecs,\n defaultMaxMinutes: workers.defaultMaxMinutes,\n noBrowserByDefault: workers.noBrowserByDefault,\n caveman: workers.caveman,\n ...(workers.fallback ? { fallback: workers.fallback } : {}),\n }\n : workers.fallback\n ? workers\n : { ...workers, fallback: undefined };\n raw.workers = jsonWorkers;\n writeMainConfigRaw(raw, path);\n}\n\n/** Expand a leading ~ (config values are written with `~` to stay portable). */\nexport function expandHome(p: string): string {\n if (p === \"~\" || p.startsWith(\"~/\")) return join(homedir(), p.slice(1));\n return p;\n}\n\n// ---------------------------------------------------------------------------\n// Runnability checks (proxy / codex providers included)\n// ---------------------------------------------------------------------------\n\nexport function assertProviderRunnable(name: string, p: WorkerProvider): void {\n if (p.protocol === \"openai\" && !p.upstreamUrl) {\n throw new WorkersConfigError(\n `provider \"${name}\" uses protocol \"openai\" but has no upstreamUrl — ` +\n `set its Chat Completions base (e.g. \"https://api.openai.com/v1\") ` +\n `so the PAI proxy knows where to translate to.`\n );\n }\n}\n\n/** Where a provider's key file lives, or null. Shared by run + test + add. */\nexport function providerKeyPath(p: WorkerProvider): string | null {\n return p.keyFile ? expandHome(p.keyFile) : null;\n}\n\n/**\n * The provider's auth token: inline `key` wins when set, else `key_file`\n * read and trimmed, else null (native/local providers use the \"local\"\n * placeholder). The one place a provider's key value is resolved — every\n * spawn path (buildRunEnv, the codex runner, the openai proxy, the\n * machine-wide fallback) reads through this instead of its own\n * readFileSync, so inline keys work everywhere a key file already did.\n */\nexport function resolveProviderKey(p: WorkerProvider): string | null {\n if (p.key) return p.key;\n const keyPath = providerKeyPath(p);\n if (!keyPath) return null;\n let content: string;\n try {\n content = readFileSync(keyPath, \"utf8\");\n } catch {\n throw new WorkersConfigError(`key file not readable: ${keyPath}`);\n }\n const token = content.trim();\n if (!token) throw new WorkersConfigError(`key file is empty: ${keyPath}`);\n return token;\n}\n\n/** `key: ****` + last 4 chars — never the full value. Used everywhere a\n * provider's key would otherwise be echoed (`providers`, `config check`). */\nexport function maskKey(key: string): string {\n return `****${key.slice(-4)}`;\n}\n\nexport { DEFAULT_CONTEXT_WINDOW } from \"../utils/model-window.js\";\n\n/** Cost tier of a provider for class filtering (unset = 3, the middle). */\nexport function providerCostTier(p: WorkerProvider): number {\n return p.costTier ?? DEFAULT_COST_TIER;\n}\n\n/**\n * The model id for a capability: the provider's preference for it, else its\n * default model — the one resolution rule every consumer (image class, fast\n * tier spawns, env pins) goes through.\n */\nexport function resolveModelCapability(p: WorkerProvider, capability: ModelCapability): string {\n return p.models[capability] ?? p.models.default;\n}\n\n/** Runner behind a provider, defaulting to the Claude Code harness. */\nfunction providerEngine(p: WorkerProvider): WorkerEngine {\n return p.engine ?? \"claude\";\n}\n\n/** Does this provider name a model for the capability (\"default\" always counts)? */\nfunction providerDeclaresCapability(p: WorkerProvider, capability: string): boolean {\n return capability === \"default\" || p.models[capability] !== undefined;\n}\n\n/** A provider usable for this capability: declares it, enabled, and passes assertProviderRunnable. */\nfunction providerUsableForCapability(p: WorkerProvider | undefined, capability: string): p is WorkerProvider {\n if (!p || !p.enabled || !providerDeclaresCapability(p, capability)) return false;\n try {\n assertProviderRunnable(\"\", p);\n return true;\n } catch {\n return false;\n }\n}\n\nexport interface ResolvedCapability {\n /** Provider name the capability resolved to (\"anthropic\" for the built-in). */\n provider: string;\n model: string;\n engine: WorkerEngine;\n /**\n * True when nothing declared this capability anywhere and the result is\n * just the active provider's default model — a caller should treat this as\n * \"no real image/vision/… provider is configured\", not a genuine match.\n */\n fellBack: boolean;\n}\n\n/**\n * Cross-provider capability resolution (`workers.yaml`'s `capabilities:`\n * map): which provider+model serves a named capability (e.g. \"image\"),\n * independent of any one provider's own `models` table.\n *\n * Resolution order:\n * 1. `capabilities.<name>` (explicit preference list) — first provider\n * that declares the capability, is enabled, and passes\n * assertProviderRunnable.\n * 2. No preference list: the active provider, if it declares the\n * capability.\n * 3. Still nothing: any enabled provider that declares the capability\n * (stable order — provider names sorted, \"anthropic\" included).\n * 4. Nothing anywhere: the active provider's default model, `fellBack: true`.\n */\nexport function resolveCapability(\n workers: Pick<WorkersConfig, \"providers\" | \"active\" | \"capabilities\" | \"nativeModels\">,\n capability: string\n): ResolvedCapability {\n const order = workers.capabilities[capability];\n if (order?.length) {\n for (const name of order) {\n const p = getProviderOrNative(workers, name);\n if (providerUsableForCapability(p, capability)) {\n return { provider: name, model: resolveModelCapability(p, capability), engine: providerEngine(p), fellBack: false };\n }\n }\n throw new WorkersConfigError(\n `no configured provider for capability \"${capability}\" is usable right now ` +\n `(checked, in order: ${order.join(\", \")}) — set one with: pai worker capability ${capability} <provider>`\n );\n }\n\n const activeName = workers.active && workers.active !== \"auto\" ? workers.active : null;\n if (activeName) {\n const p = getProviderOrNative(workers, activeName);\n if (providerUsableForCapability(p, capability)) {\n return { provider: activeName, model: resolveModelCapability(p, capability), engine: providerEngine(p), fellBack: false };\n }\n }\n\n const candidates: Record<string, WorkerProvider> = {\n [ANTHROPIC_NATIVE]: nativeAnthropicProvider(workers.nativeModels),\n ...workers.providers,\n };\n for (const name of Object.keys(candidates).sort()) {\n const p = candidates[name];\n if (providerUsableForCapability(p, capability)) {\n return { provider: name, model: resolveModelCapability(p, capability), engine: providerEngine(p), fellBack: false };\n }\n }\n\n const fallbackName = activeName ?? ANTHROPIC_NATIVE;\n const fallback = getProviderOrNative(workers, fallbackName) ?? nativeAnthropicProvider(workers.nativeModels);\n return {\n provider: fallbackName,\n model: fallback.models.default,\n engine: providerEngine(fallback),\n fellBack: true,\n };\n}\n\n/**\n * Context window used by the meter when the run reports none: an explicit\n * `contextWindow` first, then whatever the default model's id declares\n * (\"[1m]\" → 1,000,000), then the last-resort default.\n */\nexport function providerContextWindow(p: WorkerProvider): number {\n return (\n p.contextWindow ??\n contextWindowFromModelId(p.models.default) ??\n DEFAULT_CONTEXT_WINDOW\n );\n}\n\n/** Directory under which inline keys (MCP `key` field) are stored, 0600. */\nexport function keysDir(): string {\n return paiHomePath(\"keys\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAWA,MAAa,yBAAyB;;;;AAKtC,SAAgB,kBAAkB,OAAuB;AAEvD,QADiB,MAAM,QAAQ,kBAAkB,GAAG,CAAC,MAAM,IACxC;;;;;;;;AASrB,SAAgB,yBAAyB,OAAiD;AACxF,KAAI,OAAO,UAAU,YAAY,UAAU,GAAI,QAAO;CACtD,MAAM,IAAI,eAAe,KAAK,MAAM,MAAM,CAAC;AAC3C,KAAI,CAAC,EAAG,QAAO;CACf,MAAM,WAAW,OAAO,EAAE,GAAG;AAC7B,KAAI,CAAC,OAAO,SAAS,SAAS,IAAI,WAAW,EAAG,QAAO;AACvD,QAAO,WAAW;;;;;;;;;;;;;;;;;;;;;ACOpB,MAAa,wBAAwB;;;;;;AAOrC,SAAS,yBAAiC;AACxC,QAAO,YAAY,sBAAsB;;;;AAK3C,SAAS,qBAA6B;AACpC,QAAO,KAAK,SAAS,EAAE,WAAW,sBAAsB;;;;AAK1D,SAAS,wBAAgC;AACvC,QAAO,KAAK,SAAS,EAAE,WAAW,OAAO,sBAAsB;;;;;;;;AASjE,SAAgB,kBAA0B;CACxC,MAAM,WAAW,QAAQ,IAAI;AAC7B,KAAI,SAAU,QAAO;AACrB,QAAO,eACL,wBAAwB,EACxB,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,EAC/C,4BACD;;;;;AAMH,SAAS,6BAAqC;AAC5C,QAAO,QAAQ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AAkB;AAChC,QAAO,YAAY,OAAO"}
@@ -1,3 +1,3 @@
1
- import { a as ensureConfigDir, c as migrateConfigFile, d as readMainConfigRaw, f as writeMainConfigRaw, i as DEFAULT_SESSIONS_CACHE_KEEPALIVE, l as paiConfigFilePath, n as CONFIG_FILE, o as expandHome, r as DEFAULTS, s as loadConfig, t as CONFIG_DIR, u as paiConfigYamlFilePath } from "./config-Ddc4DIPk.mjs";
1
+ import { a as ensureConfigDir, c as migrateConfigFile, d as readMainConfigRaw, f as writeMainConfigRaw, i as DEFAULT_SESSIONS_CACHE_KEEPALIVE, l as paiConfigFilePath, n as CONFIG_FILE, o as expandHome, r as DEFAULTS, s as loadConfig, t as CONFIG_DIR, u as paiConfigYamlFilePath } from "./config-DjZELvoA.mjs";
2
2
 
3
3
  export { ensureConfigDir, loadConfig };