@cortex-agent/server 2026.7.30 → 2026.8.3-2

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 (353) hide show
  1. package/README.md +1 -1
  2. package/defaults/CORTEX.md +1 -0
  3. package/defaults/config/CORTEX.md +2 -1
  4. package/defaults/config/hooks/13-status-md-guard.json +11 -0
  5. package/defaults/config/hooks/CORTEX.md +1 -0
  6. package/defaults/config/mcp-config-empty.json +3 -0
  7. package/defaults/config/thread-templates/agents/benchmark-coder.json +22 -0
  8. package/defaults/config/thread-templates/agents/benchmark-reviewer.json +22 -0
  9. package/defaults/config/thread-templates/agents/coder-reviewer.json +4 -9
  10. package/defaults/config/thread-templates/agents/coder.json +4 -14
  11. package/defaults/config/thread-templates/templates/benchmark-coder-review.json +37 -0
  12. package/defaults/config/thread-templates/templates/coder-review.json +3 -27
  13. package/defaults/context/projects/CORTEX.md +1 -1
  14. package/defaults/data/schedules.json +12 -0
  15. package/defaults/hooks/CORTEX.md +1 -0
  16. package/defaults/hooks/new-session-hook.mjs +2 -2
  17. package/defaults/hooks/status-md-guard.mjs +193 -0
  18. package/defaults/plugins/cortex-coder/.claude-plugin/plugin.json +1 -1
  19. package/defaults/plugins/cortex-coder/skills/develop/SKILL.md +28 -2
  20. package/defaults/plugins/cortex-common/.claude-plugin/plugin.json +1 -1
  21. package/defaults/plugins/cortex-common/skills/compound/SKILL.md +1 -1
  22. package/defaults/plugins/cortex-common/skills/compound-simple/SKILL.md +4 -2
  23. package/defaults/plugins/cortex-common/skills/postmortem/SKILL.md +1 -1
  24. package/defaults/plugins/cortex-stage-gate/.claude-plugin/plugin.json +1 -1
  25. package/defaults/plugins/cortex-stage-gate/skills/director-method/SKILL.md +1 -1
  26. package/defaults/plugins/cortex-stage-gate/skills/need-approval/SKILL.md +1 -0
  27. package/defaults/plugins/cortex-stage-gate/skills/reorient/SKILL.md +2 -2
  28. package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +11 -8
  29. package/defaults/plugins/cortex-system/skills/feedback/SKILL.md +1 -1
  30. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +13 -16
  31. package/defaults/prompts/directives/coder-reviewer.md +24 -20
  32. package/defaults/prompts/directives/coder.md +4 -5
  33. package/defaults/prompts/directives/director.md +4 -10
  34. package/defaults/prompts/directives/manager.md +9 -10
  35. package/defaults/prompts/systemPrompts/worker.md +2 -2
  36. package/defaults/rules/cortex-md.md +31 -0
  37. package/defaults/rules/experiment-format.md +8 -1
  38. package/defaults/rules/issues-md.md +10 -9
  39. package/defaults/rules/meta-conventions.md +5 -4
  40. package/defaults/rules/mission-md.md +2 -1
  41. package/defaults/rules/status-md.md +39 -21
  42. package/dist/agent-adapter/bg-wait.d.ts +10 -12
  43. package/dist/agent-adapter/bg-wait.js +209 -129
  44. package/dist/agent-adapter/claude/adapter-tui.d.ts +3 -1
  45. package/dist/agent-adapter/claude/adapter-tui.js +8 -5
  46. package/dist/agent-adapter/claude/adapter.d.ts +43 -14
  47. package/dist/agent-adapter/claude/adapter.js +276 -161
  48. package/dist/agent-adapter/claude/defaults.d.ts +2 -0
  49. package/dist/agent-adapter/claude/defaults.js +5 -5
  50. package/dist/agent-adapter/claude/event-parser.d.ts +3 -8
  51. package/dist/agent-adapter/claude/event-parser.js +28 -31
  52. package/dist/agent-adapter/claude/hooks-builder.js +4 -3
  53. package/dist/agent-adapter/claude/jsonl-tail.js +54 -35
  54. package/dist/agent-adapter/claude/spawn-args.d.ts +15 -12
  55. package/dist/agent-adapter/claude/spawn-args.js +44 -38
  56. package/dist/agent-adapter/claude/tmux-control.d.ts +4 -17
  57. package/dist/agent-adapter/claude/tmux-control.js +39 -32
  58. package/dist/agent-adapter/event-tee.d.ts +19 -0
  59. package/dist/agent-adapter/event-tee.js +145 -0
  60. package/dist/agent-adapter/index.d.ts +1 -0
  61. package/dist/agent-adapter/index.js +7 -3
  62. package/dist/agent-adapter/normalize/event-types.d.ts +17 -9
  63. package/dist/agent-adapter/normalize/event-types.js +4 -4
  64. package/dist/agent-adapter/pi/adapter.d.ts +16 -4
  65. package/dist/agent-adapter/pi/adapter.js +69 -36
  66. package/dist/agent-adapter/pi/discovery.d.ts +19 -3
  67. package/dist/agent-adapter/pi/discovery.js +81 -43
  68. package/dist/agent-adapter/pi/event-parser.js +4 -2
  69. package/dist/agent-adapter/pi/spawn-args.d.ts +2 -4
  70. package/dist/agent-adapter/pi/spawn-args.js +6 -5
  71. package/dist/agent-adapter/types.d.ts +43 -2
  72. package/dist/agent-adapter/types.js +8 -4
  73. package/dist/core/atomic-write.d.ts +6 -1
  74. package/dist/core/atomic-write.js +183 -7
  75. package/dist/core/cli-utils.d.ts +15 -2
  76. package/dist/core/cli-utils.js +46 -41
  77. package/dist/core/config-generator.d.ts +4 -0
  78. package/dist/core/config-generator.js +34 -21
  79. package/dist/core/json-repository.d.ts +4 -0
  80. package/dist/core/json-repository.js +6 -3
  81. package/dist/core/locales/en.d.ts +94 -0
  82. package/dist/core/locales/slices/commands.d.ts +76 -0
  83. package/dist/core/locales/slices/commands.js +155 -1
  84. package/dist/core/locales/slices/status.d.ts +18 -0
  85. package/dist/core/locales/slices/status.js +43 -2
  86. package/dist/core/log.d.ts +5 -0
  87. package/dist/core/log.js +25 -23
  88. package/dist/core/pi-session-filename.d.ts +2 -0
  89. package/dist/core/pi-session-filename.js +18 -0
  90. package/dist/core/resume-reminder.d.ts +5 -0
  91. package/dist/core/resume-reminder.js +18 -0
  92. package/dist/core/runtime-env.d.ts +1 -0
  93. package/dist/core/runtime-env.js +15 -0
  94. package/dist/core/settings-migration.d.ts +5 -0
  95. package/dist/core/settings-migration.js +128 -0
  96. package/dist/core/settings-spec.d.ts +174 -0
  97. package/dist/core/settings-spec.js +150 -0
  98. package/dist/core/settings.d.ts +10 -0
  99. package/dist/core/settings.js +235 -0
  100. package/dist/core/task-parser.d.ts +11 -1
  101. package/dist/core/task-parser.js +34 -3
  102. package/dist/core/types/agent-types.d.ts +19 -0
  103. package/dist/core/types/agent-types.js +1 -1
  104. package/dist/core/types/thread-types.d.ts +48 -3
  105. package/dist/core/types/thread-types.js +2 -2
  106. package/dist/core/utils.d.ts +21 -1
  107. package/dist/core/utils.js +37 -1
  108. package/dist/domain/agent-run/access-probe-cli.d.ts +7 -0
  109. package/dist/domain/agent-run/access-probe-cli.js +139 -0
  110. package/dist/domain/agent-run/access-probe-policy.d.ts +61 -0
  111. package/dist/domain/agent-run/access-probe-policy.js +614 -0
  112. package/dist/domain/agent-run/access-probe.d.ts +21 -0
  113. package/dist/domain/agent-run/access-probe.js +194 -0
  114. package/dist/domain/agent-run/agent-run-cli.d.ts +19 -0
  115. package/dist/domain/agent-run/agent-run-cli.js +171 -0
  116. package/dist/domain/agent-run/atif.d.ts +54 -0
  117. package/dist/domain/agent-run/atif.js +211 -0
  118. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +32 -0
  119. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +616 -0
  120. package/dist/domain/agent-run/benchmark-thread-identity.d.ts +34 -0
  121. package/dist/domain/agent-run/benchmark-thread-identity.js +106 -0
  122. package/dist/domain/agent-run/identity.d.ts +62 -0
  123. package/dist/domain/agent-run/identity.js +118 -0
  124. package/dist/domain/agent-run/journal.d.ts +51 -0
  125. package/dist/domain/agent-run/journal.js +259 -0
  126. package/dist/domain/agent-run/manifest-contract.d.ts +44 -0
  127. package/dist/domain/agent-run/manifest-contract.js +134 -0
  128. package/dist/domain/agent-run/manifest.d.ts +51 -0
  129. package/dist/domain/agent-run/manifest.js +801 -0
  130. package/dist/domain/agent-run/pinned-node-process.d.ts +35 -0
  131. package/dist/domain/agent-run/pinned-node-process.js +206 -0
  132. package/dist/domain/agent-run/role-surface.d.ts +4 -0
  133. package/dist/domain/agent-run/role-surface.js +99 -0
  134. package/dist/domain/agent-run/run-config.d.ts +22 -0
  135. package/dist/domain/agent-run/run-config.js +135 -0
  136. package/dist/domain/agent-run/runner.d.ts +7 -0
  137. package/dist/domain/agent-run/runner.js +518 -0
  138. package/dist/domain/agent-run/supervisor.d.ts +78 -0
  139. package/dist/domain/agent-run/supervisor.js +425 -0
  140. package/dist/domain/agent-run/trajectory-merge-cli.d.ts +11 -0
  141. package/dist/domain/agent-run/trajectory-merge-cli.js +111 -0
  142. package/dist/domain/agent-run/trajectory-merge.d.ts +39 -0
  143. package/dist/domain/agent-run/trajectory-merge.js +505 -0
  144. package/dist/domain/agents/config.d.ts +10 -0
  145. package/dist/domain/agents/config.js +149 -44
  146. package/dist/domain/agents/facade.d.ts +42 -7
  147. package/dist/domain/agents/facade.js +174 -170
  148. package/dist/domain/agents/provider-run-lifecycle.d.ts +18 -0
  149. package/dist/domain/agents/provider-run-lifecycle.js +60 -0
  150. package/dist/domain/auth/auth-events.d.ts +18 -0
  151. package/dist/domain/auth/auth-events.js +38 -0
  152. package/dist/domain/auth/auth-format.d.ts +2 -0
  153. package/dist/domain/auth/auth-format.js +58 -0
  154. package/dist/domain/auth/auth-status.d.ts +61 -0
  155. package/dist/domain/auth/auth-status.js +304 -0
  156. package/dist/domain/auth/auth-watch.d.ts +16 -0
  157. package/dist/domain/auth/auth-watch.js +125 -0
  158. package/dist/domain/auth/cc-login.d.ts +7 -0
  159. package/dist/domain/auth/cc-login.js +16 -0
  160. package/dist/domain/auth/cc-subscription.d.ts +38 -0
  161. package/dist/domain/auth/cc-subscription.js +204 -0
  162. package/dist/domain/auth/index.d.ts +12 -0
  163. package/dist/domain/auth/index.js +16 -0
  164. package/dist/domain/auth/login-flow.d.ts +120 -0
  165. package/dist/domain/auth/login-flow.js +253 -0
  166. package/dist/domain/auth/login-service.d.ts +32 -0
  167. package/dist/domain/auth/login-service.js +97 -0
  168. package/dist/domain/auth/logout.d.ts +32 -0
  169. package/dist/domain/auth/logout.js +123 -0
  170. package/dist/domain/auth/pi-login.d.ts +36 -0
  171. package/dist/domain/auth/pi-login.js +72 -0
  172. package/dist/domain/auth/pi-oauth.d.ts +36 -0
  173. package/dist/domain/auth/pi-oauth.js +84 -0
  174. package/dist/domain/auth/pi-runtime.d.ts +72 -0
  175. package/dist/domain/auth/pi-runtime.js +86 -0
  176. package/dist/domain/mcp/benchmark-thread-server.d.ts +1 -0
  177. package/dist/domain/mcp/benchmark-thread-server.js +26 -0
  178. package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +23 -0
  179. package/dist/domain/mcp/tools/benchmark-thread-run.js +146 -0
  180. package/dist/domain/memory/user-context.js +6 -8
  181. package/dist/domain/monitor/disk-monitor.js +47 -16
  182. package/dist/domain/projects/project-store.js +23 -6
  183. package/dist/domain/remote/client-hot-reload.d.ts +9 -1
  184. package/dist/domain/remote/client-hot-reload.js +60 -12
  185. package/dist/domain/remote/client-manager.js +12 -6
  186. package/dist/domain/scheduling/jobs/auth-expiry-scan.d.ts +14 -0
  187. package/dist/domain/scheduling/jobs/auth-expiry-scan.js +86 -0
  188. package/dist/domain/scheduling/jobs/task-dispatch.js +36 -40
  189. package/dist/domain/scheduling/runner.d.ts +2 -0
  190. package/dist/domain/scheduling/runner.js +7 -4
  191. package/dist/domain/sessions/session-backup.d.ts +14 -20
  192. package/dist/domain/sessions/session-backup.js +57 -68
  193. package/dist/domain/system/doctor.d.ts +4 -0
  194. package/dist/domain/system/doctor.js +113 -28
  195. package/dist/domain/system/install-cli.js +8 -3
  196. package/dist/domain/system/server-update-check.js +7 -5
  197. package/dist/domain/system/system-notice.d.ts +3 -1
  198. package/dist/domain/system/system-notice.js +6 -11
  199. package/dist/domain/tasks/archiver.d.ts +1 -0
  200. package/dist/domain/tasks/archiver.js +13 -7
  201. package/dist/domain/tasks/claim-recovery.d.ts +3 -3
  202. package/dist/domain/tasks/claim-recovery.js +12 -8
  203. package/dist/domain/tasks/dispatch-utils.d.ts +15 -14
  204. package/dist/domain/tasks/dispatch-utils.js +22 -18
  205. package/dist/domain/tasks/dispatcher.d.ts +1 -0
  206. package/dist/domain/tasks/dispatcher.js +9 -5
  207. package/dist/domain/tasks/mutator.d.ts +21 -11
  208. package/dist/domain/tasks/mutator.js +30 -24
  209. package/dist/domain/tasks/pending-tracker.d.ts +5 -2
  210. package/dist/domain/tasks/pending-tracker.js +11 -5
  211. package/dist/domain/tasks/system/cortex-run.d.ts +2 -1
  212. package/dist/domain/tasks/system/cortex-run.js +24 -4
  213. package/dist/domain/tasks/system/task-cli.d.ts +1 -0
  214. package/dist/domain/tasks/system/task-cli.js +72 -22
  215. package/dist/domain/tasks/system/task-completion.d.ts +19 -2
  216. package/dist/domain/tasks/system/task-completion.js +31 -17
  217. package/dist/domain/tasks/system/task-file-input.d.ts +10 -0
  218. package/dist/domain/tasks/system/task-file-input.js +57 -0
  219. package/dist/domain/tasks/system/task-id-utils.d.ts +9 -9
  220. package/dist/domain/tasks/system/task-id-utils.js +13 -4
  221. package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -2
  222. package/dist/domain/tasks/system/task-lifecycle-edit.js +200 -6
  223. package/dist/domain/tasks/system/task-lock.js +19 -5
  224. package/dist/domain/tasks/system/task-mutations.d.ts +22 -12
  225. package/dist/domain/tasks/system/task-mutations.js +28 -4
  226. package/dist/domain/tasks/system/task-process.js +10 -8
  227. package/dist/domain/tasks/system/task-state.d.ts +65 -11
  228. package/dist/domain/tasks/system/task-state.js +86 -13
  229. package/dist/domain/threads/local-runtime-deps.d.ts +32 -0
  230. package/dist/domain/threads/local-runtime-deps.js +91 -0
  231. package/dist/domain/threads/local-runtime-scope.d.ts +6 -0
  232. package/dist/domain/threads/local-runtime-scope.js +12 -0
  233. package/dist/domain/threads/pending-user-inputs.d.ts +3 -0
  234. package/dist/domain/threads/pending-user-inputs.js +37 -0
  235. package/dist/domain/threads/prompt-builder.d.ts +12 -1
  236. package/dist/domain/threads/prompt-builder.js +73 -26
  237. package/dist/domain/threads/runner.d.ts +15 -3
  238. package/dist/domain/threads/runner.js +261 -105
  239. package/dist/domain/threads/state-machine.d.ts +1 -1
  240. package/dist/domain/threads/state-machine.js +17 -8
  241. package/dist/domain/ui-service/app-router.d.ts +86 -6
  242. package/dist/domain/ui-service/app-router.js +171 -133
  243. package/dist/domain/ui-service/input-schemas.d.ts +132 -10
  244. package/dist/domain/ui-service/input-schemas.js +59 -5
  245. package/dist/domain/ui-service/mutate/approvals.d.ts +2 -1
  246. package/dist/domain/ui-service/mutate/approvals.js +2 -1
  247. package/dist/domain/ui-service/mutate/auth.d.ts +6 -0
  248. package/dist/domain/ui-service/mutate/auth.js +83 -0
  249. package/dist/domain/ui-service/mutate/config.js +11 -10
  250. package/dist/domain/ui-service/query/approvals.js +3 -0
  251. package/dist/domain/ui-service/query/auth.d.ts +6 -0
  252. package/dist/domain/ui-service/query/auth.js +12 -0
  253. package/dist/domain/ui-service/query/config.d.ts +5 -5
  254. package/dist/domain/ui-service/query/config.js +27 -17
  255. package/dist/domain/ui-service/query/tasks.d.ts +1 -1
  256. package/dist/domain/ui-service/query/tasks.js +69 -30
  257. package/dist/domain/ui-service/query/threads.js +3 -3
  258. package/dist/domain/ui-service/types.d.ts +67 -8
  259. package/dist/domain/ui-service/types.js +2 -2
  260. package/dist/domain/ui-service/ui-service.js +16 -2
  261. package/dist/entry/admin-channel-hot-reload.d.ts +4 -0
  262. package/dist/entry/admin-channel-hot-reload.js +22 -0
  263. package/dist/entry/app.js +38 -38
  264. package/dist/entry/auth-cli.d.ts +10 -0
  265. package/dist/entry/auth-cli.js +52 -0
  266. package/dist/entry/cli-help.d.ts +5 -0
  267. package/dist/entry/cli-help.js +130 -0
  268. package/dist/entry/cli.d.ts +5 -5
  269. package/dist/entry/cli.js +174 -248
  270. package/dist/entry/daemon.d.ts +11 -0
  271. package/dist/entry/daemon.js +204 -103
  272. package/dist/entry/draft-attachments.d.ts +8 -0
  273. package/dist/entry/draft-attachments.js +83 -0
  274. package/dist/entry/feishu-login.d.ts +2 -6
  275. package/dist/entry/feishu-login.js +16 -21
  276. package/dist/entry/init.js +6 -4
  277. package/dist/entry/start-ui-http.d.ts +2 -8
  278. package/dist/entry/start-ui-http.js +7 -34
  279. package/dist/events/event-logger.js +11 -13
  280. package/dist/events/event-types.d.ts +19 -1
  281. package/dist/events/event-types.js +3 -3
  282. package/dist/events/index.d.ts +1 -1
  283. package/dist/events/index.js +3 -3
  284. package/dist/hooks/new-session-hook.mjs +2 -2
  285. package/dist/hooks/status-md-guard.mjs +193 -0
  286. package/dist/orchestration/agent-file-send.js +44 -14
  287. package/dist/orchestration/agent-runner.d.ts +7 -3
  288. package/dist/orchestration/agent-runner.js +65 -41
  289. package/dist/orchestration/conversation-runner.d.ts +5 -1
  290. package/dist/orchestration/conversation-runner.js +16 -7
  291. package/dist/orchestration/lifecycle.d.ts +23 -1
  292. package/dist/orchestration/lifecycle.js +103 -40
  293. package/dist/orchestration/mid-turn-inject.d.ts +2 -0
  294. package/dist/orchestration/mid-turn-inject.js +29 -13
  295. package/dist/orchestration/resume-dispatcher.d.ts +3 -5
  296. package/dist/orchestration/resume-dispatcher.js +9 -17
  297. package/dist/orchestration/routing/commands/index.d.ts +4 -1
  298. package/dist/orchestration/routing/commands/index.js +83 -61
  299. package/dist/orchestration/routing/commands/login-notice.d.ts +21 -0
  300. package/dist/orchestration/routing/commands/login-notice.js +97 -0
  301. package/dist/orchestration/routing/commands/login.d.ts +12 -0
  302. package/dist/orchestration/routing/commands/login.js +555 -0
  303. package/dist/orchestration/routing/commands/status.js +45 -59
  304. package/dist/orchestration/routing/edit-handler.d.ts +5 -0
  305. package/dist/orchestration/routing/edit-handler.js +127 -73
  306. package/dist/orchestration/routing/webhook.js +5 -4
  307. package/dist/orchestration/session-rewind.d.ts +5 -1
  308. package/dist/orchestration/session-rewind.js +106 -62
  309. package/dist/orchestration/session-send.d.ts +2 -0
  310. package/dist/orchestration/session-send.js +5 -6
  311. package/dist/orchestration/status-helpers.d.ts +1 -2
  312. package/dist/orchestration/status-helpers.js +7 -10
  313. package/dist/orchestration/thread-callback.d.ts +19 -11
  314. package/dist/orchestration/thread-callback.js +132 -61
  315. package/dist/orchestration/thread-executor.js +37 -27
  316. package/dist/orchestration/turn-mutation-lock.d.ts +3 -0
  317. package/dist/orchestration/turn-mutation-lock.js +36 -0
  318. package/dist/orchestration/turn-notify.d.ts +2 -5
  319. package/dist/orchestration/turn-notify.js +9 -21
  320. package/dist/platform/adapter.d.ts +1 -0
  321. package/dist/platform/adapter.js +2 -2
  322. package/dist/platform/adapters/composite-adapter.d.ts +2 -0
  323. package/dist/platform/adapters/composite-adapter.js +13 -3
  324. package/dist/platform/adapters/feishu.d.ts +2 -4
  325. package/dist/platform/adapters/feishu.js +38 -59
  326. package/dist/platform/adapters/index.d.ts +1 -1
  327. package/dist/platform/adapters/index.js +13 -12
  328. package/dist/platform/adapters/slack.d.ts +1 -1
  329. package/dist/platform/adapters/slack.js +12 -35
  330. package/dist/platform/index.d.ts +2 -1
  331. package/dist/platform/index.js +3 -3
  332. package/dist/platform/testing.d.ts +1 -0
  333. package/dist/platform/testing.js +13 -4
  334. package/dist/platform/tool-trace.js +6 -11
  335. package/dist/platform/ui-http/ui-http-server.d.ts +1 -1
  336. package/dist/platform/ui-http/ui-http-server.js +6 -18
  337. package/dist/store/execution-repo.d.ts +17 -1
  338. package/dist/store/execution-repo.js +55 -4
  339. package/dist/store/prompt-migration-replacements.d.ts +4 -0
  340. package/dist/store/prompt-migration-replacements.js +149 -0
  341. package/dist/store/thread-repo.d.ts +15 -4
  342. package/dist/store/thread-repo.js +61 -24
  343. package/dist/store/version-migrations.js +36 -1
  344. package/native/cortex-supervisor/dist/build-manifest.json +22 -0
  345. package/native/cortex-supervisor/dist/cortex-supervisor +0 -0
  346. package/package.json +5 -2
  347. package/web/dist/assets/index-XqBCYtkw.js +139 -0
  348. package/web/dist/assets/index-zpf3OSKC.css +1 -0
  349. package/web/dist/index.html +2 -2
  350. package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.d.ts +0 -1
  351. package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.js +0 -78
  352. package/web/dist/assets/index-B19jLgji.js +0 -138
  353. package/web/dist/assets/index-BuFyPyRW.css +0 -1
package/dist/entry/cli.js CHANGED
@@ -1,79 +1,31 @@
1
1
  #!/usr/bin/env node
2
- // input: process argv, child_process, net, @core/paths, @core/cli-utils, ./init, @domain/tasks/system/task-cli, @domain/system/install-cli
3
- // output: CLI dispatcher: cortex {init,start,daemon,task,config,install,setup-gateway,tui}
4
- // pos: Bin entry point (`cortex`). Dispatches to:
5
- // init [--home <path>] — interactive init (async, runInit)
6
- // start — fork app.js
7
- // daemon — fork daemon.js
8
- // daemon stop — stop running daemon gracefully (SIGTERM)
9
- // daemon status — check daemon + child status (PID, uptime)
10
- // daemon restart — graceful: signal daemon to drain and respawn app.js
11
- // daemon restart --hard — hard: send SIGTERM directly to app.js (daemon recovers)
12
- // daemon restart --force— force: send SIGKILL immediately to app.js
13
- // daemon restart-self — stop daemon, then re-fork daemon.js
14
- // task <subcommand> — delegate to task-cli
15
- // install latest — install latest Cortex from npm
16
- // config — show resolved paths
17
- // tui [options] — start Terminal UI client (forks dist/tui/index.js)
18
- // Packaged as dist/entry/cli.js, registered in package.json bin.
19
- // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
2
+ // input: process argv, child processes, CLI handler modules
3
+ // output: cortex CLI dispatch and process exit status
4
+ // pos: Top-level cortex command dispatcher
5
+ // >>> If I am updated, update my header and folder CORTEX.md <<<
20
6
  import { fork } from 'child_process';
21
7
  import * as path from 'path';
22
8
  import * as net from 'net';
23
9
  import { fileURLToPath } from 'url';
24
10
  import { existsSync, readdirSync, mkdirSync, writeFileSync, utimesSync, readFileSync, unlinkSync } from 'fs';
25
11
  import { INSTALL_ROOT, DATA_DIR, STORE_DIR, isMainModule } from '../core/utils.js';
26
- import { formatHelp } from '../core/cli-utils.js';
27
12
  import { createLogger } from '../core/log.js';
28
- import { runCli as taskRunCli } from '../domain/tasks/system/task-cli.js';
29
- import { runCli as installRunCli, getInstallHelp } from '../domain/system/install-cli.js';
30
13
  import { getResolvedPaths, formatConfigOutput, runInit, } from './init.js';
31
14
  import { cmdFeishu } from './feishu-login.js';
32
15
  import { cmdDoctor, getDoctorHelp } from './doctor-cli.js';
33
16
  import { discoverEndpoints, writeMergedGatewayYaml, validateProfilesAgainstGateway, dryRunGatewayYaml } from '../core/gateway-generator.js';
34
17
  import { generateProfiles, writeProfilesJson } from '../core/profile-generator.js';
35
18
  import { CORTEX_VERSION } from '../core/version.js';
19
+ import { getAuthStatus } from '../domain/auth/auth-status.js';
20
+ import { runAuthCli } from './auth-cli.js';
21
+ import { getCliHelp, getInitHelp, getSetupGatewayHelp, getTuiHelp, } from './cli-help.js';
22
+ export { getAuthHelp, getCliHelp, getInitHelp, getSetupGatewayHelp, getTuiHelp } from './cli-help.js';
36
23
  // ─── Paths ──────────────────────────────────────────────────────
37
24
  const log = createLogger('cli');
38
25
  const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
39
26
  const APP_JS = path.join(MODULE_DIR, 'app.js');
40
27
  const DAEMON_JS = path.join(MODULE_DIR, 'daemon.js');
41
28
  const TUI_JS = path.join(MODULE_DIR, '..', 'tui', 'index.js');
42
- // ─── Help ───────────────────────────────────────────────────────
43
- export function getInitHelp() {
44
- return [
45
- 'Initialize Cortex data directory',
46
- '',
47
- 'Usage: cortex init [--home <path>] [--gateway-config-dir <path>]',
48
- '',
49
- 'Creates the CORTEX_HOME directory structure, prompts for backends,',
50
- 'interaction platform (Slack / Feishu), gateway usage, and system service.',
51
- 'Generates .env with platform tokens, copies default configs, and',
52
- 'auto-generates mcp-config.json and mode.json.',
53
- '',
54
- 'Options:',
55
- ' --home <path> Set CORTEX_HOME (default: $CORTEX_HOME or ~/.cortex/)',
56
- ' --gateway-config-dir <path> Gateway config output directory (default: ~/.aistatus/)',
57
- ' --force Overwrite existing configs (.env, budget.json, mode.json, etc.)',
58
- ' --help, -h Show this help',
59
- ].join('\n');
60
- }
61
- export function getSetupGatewayHelp() {
62
- return [
63
- 'Auto-detect Claude Code / PI configurations and generate gateway.yaml + profiles.json',
64
- '',
65
- 'Usage: cortex setup-gateway [--dry-run] [--output-dir <path>]',
66
- '',
67
- 'Discovers backend endpoints from local Claude Code and PI configs, then',
68
- 'writes ~/.aistatus/gateway.yaml (with backup) and $CORTEX_HOME/config/profiles.json.',
69
- 'Without flags, this command writes files in place.',
70
- '',
71
- 'Options:',
72
- ' --dry-run Print the generated gateway.yaml to stdout without writing anything',
73
- ' --output-dir <path> Write gateway.yaml and profiles.json under <path> instead of the defaults',
74
- ' --help, -h Show this help',
75
- ].join('\n');
76
- }
77
29
  /** Parse arguments for the `cortex tui` subcommand. */
78
30
  export function parseTuiArgs(args) {
79
31
  const opts = { resume: false };
@@ -104,22 +56,6 @@ export function tuiPortListening(port) {
104
56
  sock.on('error', () => resolve(false));
105
57
  });
106
58
  }
107
- export function getTuiHelp() {
108
- return [
109
- 'Start the Cortex TUI (terminal UI) client',
110
- '',
111
- 'Usage: cortex tui [options]',
112
- '',
113
- 'Connects to a running Cortex daemon via WebSocket and opens',
114
- 'a terminal-based chat interface.',
115
- '',
116
- 'Options:',
117
- ' --resume Open the resume-session picker on connect',
118
- ' --project <id> Start a fresh session in the named project',
119
- ' --port <n> Override TUI port (default: 3003, or CORTEX_TUI_PORT)',
120
- ' --help, -h Show this help',
121
- ].join('\n');
122
- }
123
59
  /** Execute the `cortex tui` subcommand: check daemon liveness, fork Ink client. */
124
60
  export async function cmdTui(args) {
125
61
  const opts = parseTuiArgs(args);
@@ -147,49 +83,6 @@ export async function cmdTui(args) {
147
83
  child.on('exit', code => process.exit(code ?? 0));
148
84
  await new Promise(() => { }); // keep alive until child exits
149
85
  }
150
- export function getCliHelp() {
151
- return formatHelp({
152
- name: 'cortex',
153
- description: 'Cortex CLI — server management and initialization',
154
- usage: 'cortex <command> [options]',
155
- commands: [
156
- { name: 'init', description: 'Initialize CORTEX_HOME directory with configs and API keys' },
157
- { name: 'start', description: 'Start the Cortex server (node dist/entry/app.js)' },
158
- { name: 'daemon', description: 'Start daemon mode with file watching and auto-restart' },
159
- { name: 'daemon stop', description: 'Stop the running daemon gracefully (SIGTERM)' },
160
- { name: 'daemon status', description: 'Check daemon + child status (PID, uptime)' },
161
- { name: 'daemon restart', description: 'Graceful restart — signal daemon to drain and respawn app.js' },
162
- { name: 'daemon restart --hard', description: 'Hard restart — send SIGTERM directly to app.js (daemon auto-recovers)' },
163
- { name: 'daemon restart --force', description: 'Force restart — send SIGKILL immediately to app.js' },
164
- { name: 'daemon restart-self', description: 'Stop and restart the daemon process itself' },
165
- { name: 'restart', description: 'Legacy alias for daemon restart (touches $STORE_DIR/.restart)' },
166
- { name: 'task', description: 'Task system CLI (delegate to cortex-task)' },
167
- { name: 'install latest', description: 'Install the latest version of Cortex from npm' },
168
- { name: 'config', description: 'Show resolved paths and initialization status' },
169
- { name: 'doctor', description: 'Health-check the install (runtime, login, platform, gateway); --fix to repair' },
170
- { name: 'feishu', description: 'Manage Feishu user-identity login (login / status / logout)' },
171
- { name: 'setup-gateway', description: 'Auto-detect Claude/PI configs and generate gateway.yaml + profiles.json' },
172
- { name: 'tui', description: 'Start the Terminal UI (TUI) client for local interaction' },
173
- ],
174
- options: [
175
- { flag: '--help, -h', description: 'Show this help' },
176
- ],
177
- examples: [
178
- { description: 'Interactive init', command: 'cortex init' },
179
- { description: 'Init to custom directory', command: 'cortex init --home /tmp/my-cortex' },
180
- { description: 'Show resolved paths', command: 'cortex config' },
181
- { description: 'Health-check the install', command: 'cortex doctor' },
182
- { description: 'Diagnose and auto-repair', command: 'cortex doctor --fix' },
183
- { description: 'Re-generate gateway config', command: 'cortex setup-gateway' },
184
- { description: 'Start the server', command: 'cortex start' },
185
- { description: 'Stop the daemon', command: 'cortex daemon stop' },
186
- { description: 'Check daemon status', command: 'cortex daemon status' },
187
- { description: 'Graceful restart', command: 'cortex daemon restart' },
188
- { description: 'Hard restart app.js', command: 'cortex daemon restart --hard' },
189
- { description: 'Restart daemon itself', command: 'cortex daemon restart-self' },
190
- ],
191
- });
192
- }
193
86
  // ─── Daemon stop ──────────────────────────────────────────────────
194
87
  async function stopDaemonInternal() {
195
88
  const pidFile = path.join(STORE_DIR, 'daemon.pid');
@@ -528,143 +421,166 @@ export function getConfigOutput() {
528
421
  };
529
422
  return formatConfigOutput(paths, status);
530
423
  }
531
- // ─── runCli (synchronous/async commands) ────────────────────────
532
- export async function runCli(argv) {
424
+ function optionValue(args, flag) {
425
+ const index = args.indexOf(flag);
426
+ return index !== -1 && args[index + 1] ? args[index + 1] : undefined;
427
+ }
428
+ async function runInitCli(args) {
429
+ if (args.includes('--help') || args.includes('-h')) {
430
+ return { exitCode: 0, stdout: getInitHelp(), stderr: '' };
431
+ }
432
+ const homeDir = optionValue(args, '--home');
433
+ const gatewayConfigDir = optionValue(args, '--gateway-config-dir');
434
+ try {
435
+ await runInit({ homeDir, gatewayConfigDir, force: args.includes('--force') });
436
+ return { exitCode: 0, stdout: '', stderr: '' };
437
+ }
438
+ catch (error) {
439
+ return { exitCode: 1, stdout: '', stderr: error.message || String(error) };
440
+ }
441
+ }
442
+ function runDoctorCli(args) {
443
+ if (args.includes('--help') || args.includes('-h')) {
444
+ return { exitCode: 0, stdout: getDoctorHelp(), stderr: '' };
445
+ }
446
+ return cmdDoctor(args);
447
+ }
448
+ function touchRestartTrigger(trigger) {
449
+ mkdirSync(STORE_DIR, { recursive: true });
450
+ if (!existsSync(trigger)) {
451
+ writeFileSync(trigger, '');
452
+ return;
453
+ }
454
+ const now = new Date();
455
+ utimesSync(trigger, now, now);
456
+ }
457
+ function runRestartCli() {
458
+ const trigger = path.join(STORE_DIR, '.restart');
459
+ try {
460
+ touchRestartTrigger(trigger);
461
+ const stdout = `Restart trigger touched: ${trigger}\nIf a daemon is running it will drain and respawn app.js.\n`;
462
+ return { exitCode: 0, stdout, stderr: '' };
463
+ }
464
+ catch (error) {
465
+ return { exitCode: 1, stdout: '', stderr: `Could not write ${trigger}: ${error.message || String(error)}` };
466
+ }
467
+ }
468
+ function appendDroppedWarnings(lines, result) {
469
+ if (result.droppedFromDiscovery.length === 0)
470
+ return;
471
+ const list = result.droppedFromDiscovery.map(item => `${item.mode}/${item.endpoint}`).join(', ');
472
+ lines.push(`WARNING: preserved ${result.droppedFromDiscovery.length} existing gateway mode(s) not reported by discovery: ${list}`);
473
+ lines.push(' (if these should auto-detect, check `pi /login` / `pi --list-models`)');
474
+ }
475
+ function appendProfileIssues(lines, issues) {
476
+ if (issues.length === 0)
477
+ return;
478
+ lines.push(`WARNING: ${issues.length} profile(s) reference an unconfigured gateway mode (would fail with "Unknown mode"):`);
479
+ for (const issue of issues)
480
+ lines.push(` - ${issue.profile}: ${issue.reason}`);
481
+ }
482
+ function gatewayOutput(endpoints, outputDir, gatewayPath, profilesPath, mergeResult) {
483
+ const profiles = generateProfiles(endpoints);
484
+ const profileNames = Object.keys(profiles.profiles).join(', ');
485
+ const lines = [
486
+ outputDir ? `[TEST MODE] Output directory: ${outputDir}` : '',
487
+ `Gateway config: ${gatewayPath}`,
488
+ `Profiles: ${profilesPath}`,
489
+ `Discovered ${endpoints.length} endpoint modes`,
490
+ `Generated profiles: ${profileNames} (default: ${profiles.defaultProfile})`,
491
+ ];
492
+ appendDroppedWarnings(lines, mergeResult);
493
+ appendProfileIssues(lines, validateProfilesAgainstGateway(mergeResult.endpoints, outputDir));
494
+ return lines.filter(Boolean).join('\n');
495
+ }
496
+ function writeGatewayConfiguration(outputDir) {
497
+ const endpoints = discoverEndpoints();
498
+ if (endpoints.length === 0) {
499
+ return { exitCode: 0, stdout: 'No backends discovered. Log into Claude Code and/or PI first.\n', stderr: '' };
500
+ }
501
+ const { path: gatewayPath, result } = writeMergedGatewayYaml(endpoints, outputDir);
502
+ const profilesPath = writeProfilesJson(endpoints, outputDir);
503
+ return {
504
+ exitCode: 0,
505
+ stdout: gatewayOutput(endpoints, outputDir, gatewayPath, profilesPath, result),
506
+ stderr: '',
507
+ };
508
+ }
509
+ function runSetupGatewayCli(args) {
510
+ if (args.includes('--help') || args.includes('-h')) {
511
+ return { exitCode: 0, stdout: getSetupGatewayHelp(), stderr: '' };
512
+ }
513
+ try {
514
+ if (args.includes('--dry-run')) {
515
+ return { exitCode: 0, stdout: dryRunGatewayYaml(), stderr: '' };
516
+ }
517
+ return writeGatewayConfiguration(optionValue(args, '--output-dir'));
518
+ }
519
+ catch (error) {
520
+ return { exitCode: 1, stdout: '', stderr: error.message || String(error) };
521
+ }
522
+ }
523
+ async function runTaskCli(args) {
524
+ const { runCli: taskRunCli } = await import('../domain/tasks/system/task-cli.js');
525
+ return taskRunCli(args.length > 0 ? args : ['list']);
526
+ }
527
+ async function runInstallCli(args) {
528
+ const { runCli: installRunCli, getInstallHelp } = await import('../domain/system/install-cli.js');
529
+ if (args.includes('--help') || args.includes('-h')) {
530
+ return { exitCode: 0, stdout: getInstallHelp(), stderr: '' };
531
+ }
532
+ return installRunCli(args);
533
+ }
534
+ function runDaemonRestart(args) {
535
+ if (args[1] === '--hard')
536
+ return daemonRestartHardInternal(false);
537
+ if (args[1] === '--force')
538
+ return daemonRestartHardInternal(true);
539
+ return daemonRestartInternal();
540
+ }
541
+ function runDaemonAction(args) {
542
+ if (args[0] === 'stop')
543
+ return stopDaemonInternal();
544
+ if (args[0] === 'status')
545
+ return getDaemonStatusInternal();
546
+ if (args[0] === 'restart')
547
+ return runDaemonRestart(args);
548
+ return null;
549
+ }
550
+ async function runDaemonCli(args) {
551
+ const action = runDaemonAction(args);
552
+ if (action)
553
+ return action;
554
+ if (args.includes('--help') || args.includes('-h')) {
555
+ return { exitCode: 0, stdout: getCliHelp(), stderr: '' };
556
+ }
557
+ if (args.includes('--version') || args.includes('-V')) {
558
+ return { exitCode: 0, stdout: `${CORTEX_VERSION}\n`, stderr: '' };
559
+ }
560
+ return { exitCode: 0, stdout: '', stderr: `'daemon' must be run from the main entry point, not imported.\nUse: node dist/entry/cli.js daemon` };
561
+ }
562
+ const CLI_HANDLERS = {
563
+ init: (args) => runInitCli(args),
564
+ config: () => ({ exitCode: 0, stdout: getConfigOutput(), stderr: '' }),
565
+ auth: (args, deps) => runAuthCli(args, deps.getAuthStatus ?? getAuthStatus),
566
+ doctor: (args) => runDoctorCli(args),
567
+ feishu: (args) => cmdFeishu(args),
568
+ restart: () => runRestartCli(),
569
+ 'setup-gateway': (args) => runSetupGatewayCli(args),
570
+ task: (args) => runTaskCli(args),
571
+ install: (args) => runInstallCli(args),
572
+ start: () => ({ exitCode: 0, stdout: '', stderr: `'start' must be run from the main entry point, not imported.\nUse: node dist/entry/cli.js start` }),
573
+ daemon: (args) => runDaemonCli(args),
574
+ };
575
+ export async function runCli(argv, deps = {}) {
533
576
  if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
534
577
  return { exitCode: 0, stdout: getCliHelp(), stderr: '' };
535
578
  }
536
- const cmd = argv[0];
537
- const rest = argv.slice(1);
538
- switch (cmd) {
539
- case 'init': {
540
- if (rest.includes('--help') || rest.includes('-h')) {
541
- return { exitCode: 0, stdout: getInitHelp(), stderr: '' };
542
- }
543
- const homeIndex = rest.indexOf('--home');
544
- const homeDir = homeIndex !== -1 && rest[homeIndex + 1] ? rest[homeIndex + 1] : undefined;
545
- const gatewayIndex = rest.indexOf('--gateway-config-dir');
546
- const gatewayConfigDir = gatewayIndex !== -1 && rest[gatewayIndex + 1] ? rest[gatewayIndex + 1] : undefined;
547
- const force = rest.includes('--force');
548
- try {
549
- await runInit({ homeDir, force, gatewayConfigDir });
550
- return { exitCode: 0, stdout: '', stderr: '' };
551
- }
552
- catch (err) {
553
- return { exitCode: 1, stdout: '', stderr: err.message || String(err) };
554
- }
555
- }
556
- case 'config':
557
- return { exitCode: 0, stdout: getConfigOutput(), stderr: '' };
558
- case 'doctor': {
559
- if (rest.includes('--help') || rest.includes('-h')) {
560
- return { exitCode: 0, stdout: getDoctorHelp(), stderr: '' };
561
- }
562
- return cmdDoctor(rest);
563
- }
564
- case 'feishu':
565
- return cmdFeishu(rest);
566
- case 'restart': {
567
- const trigger = path.join(STORE_DIR, '.restart');
568
- try {
569
- mkdirSync(STORE_DIR, { recursive: true });
570
- if (existsSync(trigger)) {
571
- const now = new Date();
572
- utimesSync(trigger, now, now);
573
- }
574
- else {
575
- writeFileSync(trigger, '');
576
- }
577
- return { exitCode: 0, stdout: `Restart trigger touched: ${trigger}\nIf a daemon is running it will drain and respawn app.js.\n`, stderr: '' };
578
- }
579
- catch (err) {
580
- return { exitCode: 1, stdout: '', stderr: `Could not write ${trigger}: ${err.message || String(err)}` };
581
- }
582
- }
583
- case 'setup-gateway': {
584
- if (rest.includes('--help') || rest.includes('-h')) {
585
- return { exitCode: 0, stdout: getSetupGatewayHelp(), stderr: '' };
586
- }
587
- const dryRun = rest.includes('--dry-run');
588
- const outDirIndex = rest.indexOf('--output-dir');
589
- const outputDir = outDirIndex !== -1 && rest[outDirIndex + 1] ? rest[outDirIndex + 1] : undefined;
590
- try {
591
- if (dryRun) {
592
- const yaml = dryRunGatewayYaml();
593
- return { exitCode: 0, stdout: yaml, stderr: '' };
594
- }
595
- const endpoints = discoverEndpoints();
596
- if (endpoints.length === 0) {
597
- return { exitCode: 0, stdout: 'No backends discovered. Log into Claude Code and/or PI first.\n', stderr: '' };
598
- }
599
- const { path: gatewayPath, result: mergeResult } = writeMergedGatewayYaml(endpoints, outputDir);
600
- const profilesPath = writeProfilesJson(endpoints, outputDir);
601
- const profiles = generateProfiles(endpoints);
602
- const profileNames = Object.keys(profiles.profiles).join(', ');
603
- const issues = validateProfilesAgainstGateway(mergeResult.endpoints, outputDir);
604
- const stdoutLines = [
605
- outputDir ? `[TEST MODE] Output directory: ${outputDir}` : '',
606
- `Gateway config: ${gatewayPath}`,
607
- `Profiles: ${profilesPath}`,
608
- `Discovered ${endpoints.length} endpoint modes`,
609
- `Generated profiles: ${profileNames} (default: ${profiles.defaultProfile})`,
610
- ];
611
- if (mergeResult.droppedFromDiscovery.length > 0) {
612
- const list = mergeResult.droppedFromDiscovery.map(p => `${p.mode}/${p.endpoint}`).join(', ');
613
- stdoutLines.push(`WARNING: preserved ${mergeResult.droppedFromDiscovery.length} existing gateway mode(s) not reported by discovery: ${list}`);
614
- stdoutLines.push(' (if these should auto-detect, check `pi /login` / `pi --list-models`)');
615
- }
616
- if (issues.length > 0) {
617
- stdoutLines.push(`WARNING: ${issues.length} profile(s) reference an unconfigured gateway mode (would fail with "Unknown mode"):`);
618
- for (const i of issues)
619
- stdoutLines.push(` - ${i.profile}: ${i.reason}`);
620
- }
621
- return {
622
- exitCode: 0,
623
- stdout: stdoutLines.filter(Boolean).join('\n'),
624
- stderr: '',
625
- };
626
- }
627
- catch (err) {
628
- return { exitCode: 1, stdout: '', stderr: err.message || String(err) };
629
- }
630
- }
631
- case 'task': {
632
- const result = taskRunCli(rest.length > 0 ? rest : ['list']);
633
- return result;
634
- }
635
- case 'install': {
636
- if (rest.includes('--help') || rest.includes('-h')) {
637
- return { exitCode: 0, stdout: getInstallHelp(), stderr: '' };
638
- }
639
- return installRunCli(rest);
640
- }
641
- case 'start':
642
- return { exitCode: 0, stdout: '', stderr: `'start' must be run from the main entry point, not imported.\nUse: node dist/entry/cli.js start` };
643
- case 'daemon': {
644
- if (rest[0] === 'stop') {
645
- return stopDaemonInternal();
646
- }
647
- if (rest[0] === 'status') {
648
- return getDaemonStatusInternal();
649
- }
650
- if (rest[0] === 'restart') {
651
- if (rest[1] === '--hard')
652
- return daemonRestartHardInternal(false);
653
- if (rest[1] === '--force')
654
- return daemonRestartHardInternal(true);
655
- return daemonRestartInternal();
656
- }
657
- if (rest.includes('--help') || rest.includes('-h')) {
658
- return { exitCode: 0, stdout: getCliHelp(), stderr: '' };
659
- }
660
- if (rest.includes('--version') || rest.includes('-V')) {
661
- return { exitCode: 0, stdout: `${CORTEX_VERSION}\n`, stderr: '' };
662
- }
663
- return { exitCode: 0, stdout: '', stderr: `'daemon' must be run from the main entry point, not imported.\nUse: node dist/entry/cli.js daemon` };
664
- }
665
- default:
666
- return { exitCode: 1, stdout: '', stderr: `Unknown command: '${cmd}'. Use --help to see available commands.` };
579
+ const handler = CLI_HANDLERS[argv[0]];
580
+ if (!handler) {
581
+ return { exitCode: 1, stdout: '', stderr: `Unknown command: '${argv[0]}'. Use --help to see available commands.` };
667
582
  }
583
+ return handler(argv.slice(1), deps);
668
584
  }
669
585
  // ─── Main entry point (bin invocation) ─────────────────────────
670
586
  function main() {
@@ -675,6 +591,16 @@ function main() {
675
591
  }
676
592
  const cmd = args[0];
677
593
  const rest = args.slice(1);
594
+ if (cmd === 'agent-run') {
595
+ void import('../domain/agent-run/agent-run-cli.js')
596
+ .then(({ runAgentRunCli }) => runAgentRunCli(rest))
597
+ .then(code => { process.exitCode = code; })
598
+ .catch((error) => {
599
+ process.stderr.write(`${error?.message ?? String(error)}\n`);
600
+ process.exitCode = 1;
601
+ });
602
+ return;
603
+ }
678
604
  // Handle --help / -h for subcommands
679
605
  if (rest.includes('--help') || rest.includes('-h')) {
680
606
  if (cmd === 'daemon') {
@@ -1,3 +1,4 @@
1
+ import { type FSWatcher } from 'fs';
1
2
  declare function buildChildProcessConfig(restartReason?: string | null): {
2
3
  cwd: string;
3
4
  stdio: ("pipe" | "ignore" | "ipc")[];
@@ -6,6 +7,16 @@ declare function buildChildProcessConfig(restartReason?: string | null): {
6
7
  [key: string]: string;
7
8
  };
8
9
  };
10
+ export interface WatchMonitor {
11
+ close(): void;
12
+ }
13
+ export interface ResilientWatchOptions {
14
+ label: string;
15
+ startWatching: () => FSWatcher[];
16
+ poll?: () => void;
17
+ warn?: (message: string) => void;
18
+ }
19
+ export declare function createResilientWatchMonitor(options: ResilientWatchOptions): WatchMonitor;
9
20
  export interface RebuildStep {
10
21
  /** Short stable name used in logs and in the abort notice. */
11
22
  label: string;