@sema-agent/server 1.323.0 → 2.0.1

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 (565) hide show
  1. package/dist/approval-hmac.d.ts +40 -0
  2. package/dist/approval-hmac.js +67 -0
  3. package/dist/approval.d.ts +31 -0
  4. package/dist/approval.js +72 -4
  5. package/dist/audit.d.ts +26 -0
  6. package/dist/audit.js +40 -1
  7. package/dist/auth-bridge.d.ts +10 -0
  8. package/dist/auth-bridge.js +47 -4
  9. package/dist/auth-keys.d.ts +19 -0
  10. package/dist/auth-keys.js +13 -0
  11. package/dist/bake-runner/main.d.ts +5 -0
  12. package/dist/bake-runner/main.js +43 -4
  13. package/dist/bake-runner/protocol.d.ts +57 -0
  14. package/dist/bake-runner/protocol.js +58 -3
  15. package/dist/bake-runner/runner.d.ts +54 -0
  16. package/dist/bake-runner/runner.js +87 -5
  17. package/dist/bench/l8/artifact.d.ts +63 -0
  18. package/dist/bench/l8/artifact.js +61 -2
  19. package/dist/bench/l8/escape.d.ts +36 -0
  20. package/dist/bench/l8/escape.js +25 -0
  21. package/dist/bench/l8/index.d.ts +14 -0
  22. package/dist/bench/l8/index.js +14 -0
  23. package/dist/bench/l8/probes.d.ts +74 -0
  24. package/dist/bench/l8/probes.js +60 -0
  25. package/dist/bench/l8/run-probes.d.ts +43 -0
  26. package/dist/bench/l8/run-probes.js +45 -2
  27. package/dist/bench/s1/arms.d.ts +126 -0
  28. package/dist/bench/s1/arms.js +188 -13
  29. package/dist/bench/s1/live-deps.d.ts +66 -0
  30. package/dist/bench/s1/live-deps.js +249 -11
  31. package/dist/bench/s1/oracle.d.ts +49 -0
  32. package/dist/bench/s1/oracle.js +36 -1
  33. package/dist/bench/s1/repair-oracle-adapter.d.ts +33 -0
  34. package/dist/bench/s1/repair-oracle-adapter.js +30 -0
  35. package/dist/bench/s1/reviewer.d.ts +38 -0
  36. package/dist/bench/s1/reviewer.js +34 -0
  37. package/dist/bench/s1/row.d.ts +77 -0
  38. package/dist/bench/s1/row.js +62 -0
  39. package/dist/bench/s1/run-firm.d.ts +47 -0
  40. package/dist/bench/s1/run-firm.js +70 -4
  41. package/dist/bench/s1/runner-ctx.d.ts +71 -0
  42. package/dist/bench/s1/runner-ctx.js +36 -0
  43. package/dist/bench/s1/tasks.d.ts +108 -0
  44. package/dist/bench/s1/tasks.js +115 -0
  45. package/dist/boot/budget-tracing.d.ts +48 -0
  46. package/dist/boot/budget-tracing.js +86 -0
  47. package/dist/boot/config-center.d.ts +62 -0
  48. package/dist/boot/config-center.js +995 -0
  49. package/dist/boot/coordinators.d.ts +33 -0
  50. package/dist/boot/coordinators.js +97 -0
  51. package/dist/boot/execution-env.d.ts +26 -0
  52. package/dist/boot/execution-env.js +370 -0
  53. package/dist/boot/leader.d.ts +27 -0
  54. package/dist/boot/leader.js +81 -0
  55. package/dist/boot/reapers.d.ts +53 -0
  56. package/dist/boot/reapers.js +252 -0
  57. package/dist/boot/resolve-spec.d.ts +70 -0
  58. package/dist/boot/resolve-spec.js +1072 -0
  59. package/dist/boot/runner-deps.d.ts +101 -0
  60. package/dist/boot/runner-deps.js +343 -0
  61. package/dist/boot/runtime-caps.d.ts +21 -0
  62. package/dist/boot/runtime-caps.js +62 -0
  63. package/dist/boot/session-faces.d.ts +57 -0
  64. package/dist/boot/session-faces.js +157 -0
  65. package/dist/boot/shutdown.d.ts +50 -0
  66. package/dist/boot/shutdown.js +129 -0
  67. package/dist/boot/stores.d.ts +32 -0
  68. package/dist/boot/stores.js +361 -0
  69. package/dist/boot/workflow-orchestration.d.ts +46 -0
  70. package/dist/boot/workflow-orchestration.js +150 -0
  71. package/dist/boot-reclaim.d.ts +19 -0
  72. package/dist/boot-reclaim.js +20 -0
  73. package/dist/brain.d.ts +25 -0
  74. package/dist/brain.js +61 -1
  75. package/dist/budget.d.ts +66 -0
  76. package/dist/budget.js +128 -4
  77. package/dist/capabilities/builtin-tools.d.ts +3 -0
  78. package/dist/capabilities/builtin-tools.js +3 -0
  79. package/dist/capabilities/center-plugins.d.ts +17 -1
  80. package/dist/capabilities/center-plugins.js +45 -4
  81. package/dist/capabilities/center-prompts.d.ts +46 -0
  82. package/dist/capabilities/center-prompts.js +57 -3
  83. package/dist/capabilities/code-review-council.d.ts +28 -0
  84. package/dist/capabilities/code-review-council.js +40 -7
  85. package/dist/capabilities/collab-wire.d.ts +2 -0
  86. package/dist/capabilities/collab-workflows.d.ts +7 -0
  87. package/dist/capabilities/collab-workflows.js +44 -1
  88. package/dist/capabilities/oa-tools.d.ts +6 -0
  89. package/dist/capabilities/oa-tools.js +10 -0
  90. package/dist/capabilities/prompt.d.ts +14 -0
  91. package/dist/capabilities/prompt.js +14 -0
  92. package/dist/capabilities/prompts/code-review.d.ts +14 -0
  93. package/dist/capabilities/prompts/code-review.js +14 -0
  94. package/dist/capabilities/prompts/identity.d.ts +6 -0
  95. package/dist/capabilities/prompts/identity.js +6 -0
  96. package/dist/capabilities/prompts/team.d.ts +4 -0
  97. package/dist/capabilities/prompts/team.js +4 -0
  98. package/dist/capabilities/repo-tools.d.ts +11 -0
  99. package/dist/capabilities/repo-tools.js +8 -0
  100. package/dist/capabilities/sandbox-file-send.d.ts +95 -0
  101. package/dist/capabilities/sandbox-file-send.js +91 -3
  102. package/dist/capabilities/scenarios.d.ts +130 -0
  103. package/dist/capabilities/scenarios.js +180 -7
  104. package/dist/capabilities/select-environment-tool.d.ts +7 -0
  105. package/dist/capabilities/select-environment-tool.js +30 -0
  106. package/dist/capabilities/send-user-file-tool.d.ts +33 -0
  107. package/dist/capabilities/send-user-file-tool.js +65 -1
  108. package/dist/capabilities/skills.d.ts +29 -0
  109. package/dist/capabilities/skills.js +13 -2
  110. package/dist/capabilities/team.d.ts +22 -0
  111. package/dist/capabilities/team.js +22 -2
  112. package/dist/capabilities/tool-defer.d.ts +26 -0
  113. package/dist/capabilities/tool-defer.js +3 -0
  114. package/dist/config-center/apply-effective.d.ts +65 -0
  115. package/dist/config-center/apply-effective.js +204 -12
  116. package/dist/config-center/http-client.d.ts +34 -0
  117. package/dist/config-center/http-client.js +68 -0
  118. package/dist/config-center/restart-signal.d.ts +22 -0
  119. package/dist/config-center/restart-signal.js +39 -0
  120. package/dist/config-center/skills-mcp.d.ts +20 -1
  121. package/dist/config-center/skills-mcp.js +42 -7
  122. package/dist/config-center/types.d.ts +92 -1
  123. package/dist/config-lkg.d.ts +12 -0
  124. package/dist/config-lkg.js +41 -0
  125. package/dist/config-provider.d.ts +78 -0
  126. package/dist/config-provider.js +165 -2
  127. package/dist/config-types.d.ts +585 -1
  128. package/dist/config.d.ts +78 -2
  129. package/dist/config.js +874 -301
  130. package/dist/degenerate-instrument.d.ts +38 -0
  131. package/dist/degenerate-instrument.js +55 -3
  132. package/dist/elicitation.d.ts +39 -0
  133. package/dist/elicitation.js +87 -3
  134. package/dist/env-facts.d.ts +61 -0
  135. package/dist/env-facts.js +73 -7
  136. package/dist/fleet/fleet-bus.d.ts +185 -0
  137. package/dist/fleet/fleet-bus.js +333 -27
  138. package/dist/fleet/subagent-tail-bus.d.ts +11 -0
  139. package/dist/fleet/subagent-tail-bus.js +33 -2
  140. package/dist/fleet-client.d.ts +38 -0
  141. package/dist/fleet-client.js +44 -9
  142. package/dist/fleet-lease.d.ts +46 -0
  143. package/dist/fleet-lease.js +73 -5
  144. package/dist/hooks/branch-transcript.d.ts +8 -0
  145. package/dist/hooks/branch-transcript.js +33 -0
  146. package/dist/hooks/cc-stop-prompt.d.ts +42 -0
  147. package/dist/hooks/cc-stop-prompt.js +43 -1
  148. package/dist/hooks/hook-llm.d.ts +15 -0
  149. package/dist/hooks/hook-llm.js +47 -0
  150. package/dist/hooks/hook-runner.d.ts +89 -0
  151. package/dist/hooks/hook-runner.js +327 -18
  152. package/dist/http/idempotency.d.ts +31 -0
  153. package/dist/http/idempotency.js +34 -0
  154. package/dist/http/principal-gate.d.ts +17 -0
  155. package/dist/http/principal-gate.js +35 -3
  156. package/dist/http/route-ctx.d.ts +36 -0
  157. package/dist/http/routes/approvals-assistant.d.ts +25 -0
  158. package/dist/http/routes/approvals-assistant.js +253 -23
  159. package/dist/http/routes/attachments.js +22 -4
  160. package/dist/http/routes/capabilities.d.ts +7 -0
  161. package/dist/http/routes/capabilities.js +202 -1
  162. package/dist/http/routes/fleet.d.ts +6 -0
  163. package/dist/http/routes/fleet.js +94 -5
  164. package/dist/http/routes/images.d.ts +17 -0
  165. package/dist/http/routes/images.js +222 -14
  166. package/dist/http/routes/leader.d.ts +7 -0
  167. package/dist/http/routes/leader.js +10 -0
  168. package/dist/http/routes/memory-policy.d.ts +6 -0
  169. package/dist/http/routes/memory-policy.js +38 -6
  170. package/dist/http/routes/notify-wake.d.ts +10 -0
  171. package/dist/http/routes/notify-wake.js +19 -3
  172. package/dist/http/routes/observability.d.ts +6 -0
  173. package/dist/http/routes/observability.js +19 -2
  174. package/dist/http/routes/runs.d.ts +15 -0
  175. package/dist/http/routes/runs.js +464 -41
  176. package/dist/http/routes/session-sync.d.ts +15 -0
  177. package/dist/http/routes/session-sync.js +229 -19
  178. package/dist/http/routes/sessions-list.d.ts +6 -0
  179. package/dist/http/routes/sessions-list.js +35 -4
  180. package/dist/http/routes/sessions.d.ts +14 -0
  181. package/dist/http/routes/sessions.js +176 -31
  182. package/dist/http/routes/side-query.d.ts +8 -0
  183. package/dist/http/routes/side-query.js +26 -1
  184. package/dist/http/routes/tasks.d.ts +18 -0
  185. package/dist/http/routes/tasks.js +501 -38
  186. package/dist/http/routes/trace-usage.d.ts +10 -0
  187. package/dist/http/routes/trace-usage.js +66 -14
  188. package/dist/http/routes/workflows.d.ts +12 -0
  189. package/dist/http/routes/workflows.js +180 -19
  190. package/dist/http/run-meta.d.ts +11 -0
  191. package/dist/http/run-meta.js +6 -0
  192. package/dist/http/send.d.ts +19 -0
  193. package/dist/http/send.js +11 -0
  194. package/dist/http/server.d.ts +255 -0
  195. package/dist/http/server.js +921 -75
  196. package/dist/http/sse-log.d.ts +15 -0
  197. package/dist/http/sse-log.js +16 -0
  198. package/dist/http/tar.d.ts +9 -0
  199. package/dist/http/tar.js +21 -5
  200. package/dist/http/wire-gate.d.ts +9 -0
  201. package/dist/http/wire-gate.js +9 -0
  202. package/dist/http/wire-types.d.ts +187 -0
  203. package/dist/http/workspace-content.d.ts +8 -0
  204. package/dist/http/workspace-content.js +10 -0
  205. package/dist/images/bake-validate.d.ts +63 -0
  206. package/dist/images/bake-validate.js +71 -1
  207. package/dist/images/manifest.d.ts +19 -0
  208. package/dist/images/manifest.js +6 -1
  209. package/dist/index.d.ts +1 -5
  210. package/dist/index.js +10 -5
  211. package/dist/key-resolver.d.ts +23 -0
  212. package/dist/key-resolver.js +27 -2
  213. package/dist/leader/diffout.d.ts +23 -0
  214. package/dist/leader/diffout.js +8 -1
  215. package/dist/leader/diffup.d.ts +32 -0
  216. package/dist/leader/diffup.js +43 -0
  217. package/dist/leader/endpoint.d.ts +20 -0
  218. package/dist/leader/endpoint.js +25 -2
  219. package/dist/leader/fanout.d.ts +60 -0
  220. package/dist/leader/fanout.js +29 -3
  221. package/dist/leader/grader-env-factory.d.ts +74 -0
  222. package/dist/leader/grader-env-factory.js +62 -3
  223. package/dist/leader/leader.d.ts +97 -0
  224. package/dist/leader/leader.js +151 -4
  225. package/dist/leader/merge.d.ts +94 -0
  226. package/dist/leader/merge.js +112 -9
  227. package/dist/leader/planner.d.ts +52 -0
  228. package/dist/leader/planner.js +47 -3
  229. package/dist/leader/repair-oracle.d.ts +61 -0
  230. package/dist/leader/repair-oracle.js +59 -1
  231. package/dist/leader/repair-wire.d.ts +78 -0
  232. package/dist/leader/repair-wire.js +79 -2
  233. package/dist/leader/wire.d.ts +79 -0
  234. package/dist/leader/wire.js +255 -8
  235. package/dist/lsp/e2b-bridge.d.ts +16 -0
  236. package/dist/lsp/e2b-bridge.js +32 -4
  237. package/dist/lsp/e2b-manager.d.ts +10 -0
  238. package/dist/lsp/e2b-manager.js +18 -2
  239. package/dist/lsp/lsp-frames.d.ts +12 -0
  240. package/dist/lsp/lsp-frames.js +12 -0
  241. package/dist/lsp/manager.d.ts +12 -0
  242. package/dist/lsp/manager.js +35 -2
  243. package/dist/lsp/types.d.ts +10 -0
  244. package/dist/lsp/ws-transport.d.ts +12 -0
  245. package/dist/lsp/ws-transport.js +53 -5
  246. package/dist/lsp-evict.d.ts +14 -0
  247. package/dist/lsp-evict.js +15 -1
  248. package/dist/main.js +530 -2129
  249. package/dist/memory-export.d.ts +1 -0
  250. package/dist/memory-export.js +4 -0
  251. package/dist/memory-scope.d.ts +49 -0
  252. package/dist/memory-scope.js +87 -4
  253. package/dist/memory-sync-client.d.ts +24 -0
  254. package/dist/memory-sync-client.js +41 -2
  255. package/dist/memory-sync.d.ts +23 -0
  256. package/dist/memory-sync.js +70 -1
  257. package/dist/model-select.d.ts +39 -0
  258. package/dist/model-select.js +42 -1
  259. package/dist/observability/cost-quota.d.ts +20 -0
  260. package/dist/observability/cost-quota.js +4 -0
  261. package/dist/observability/cost-taxonomy.d.ts +45 -0
  262. package/dist/observability/cost-taxonomy.js +34 -0
  263. package/dist/observability/logger.d.ts +1 -0
  264. package/dist/observability/logger.js +6 -0
  265. package/dist/observability/metrics.d.ts +13 -0
  266. package/dist/observability/metrics.js +63 -0
  267. package/dist/observability/otel-exporter.d.ts +9 -0
  268. package/dist/observability/otel-exporter.js +11 -3
  269. package/dist/observability/principal-context.d.ts +9 -0
  270. package/dist/observability/principal-context.js +9 -0
  271. package/dist/observability/prompt-manifest.d.ts +37 -0
  272. package/dist/observability/prompt-manifest.js +35 -1
  273. package/dist/observability/rate-limit.d.ts +10 -0
  274. package/dist/observability/rate-limit.js +1 -0
  275. package/dist/observability/tool-trace.d.ts +24 -0
  276. package/dist/observability/tool-trace.js +41 -1
  277. package/dist/orchestration/hardened-vm-runner.d.ts +107 -0
  278. package/dist/orchestration/hardened-vm-runner.js +119 -4
  279. package/dist/orchestration/hardened-vm-worker-runner.d.ts +14 -0
  280. package/dist/orchestration/hardened-vm-worker-runner.js +26 -1
  281. package/dist/orchestration/hardened-vm-worker.js +27 -0
  282. package/dist/orchestration/subagent-steer.d.ts +44 -0
  283. package/dist/orchestration/subagent-steer.js +45 -1
  284. package/dist/orchestration/workflow-agent-steer.d.ts +54 -0
  285. package/dist/orchestration/workflow-agent-steer.js +80 -1
  286. package/dist/orchestration/workflow-completion-inbox.d.ts +189 -2
  287. package/dist/orchestration/workflow-completion-inbox.js +283 -32
  288. package/dist/orchestration/workflow-notify-journal.d.ts +132 -1
  289. package/dist/orchestration/workflow-notify-journal.js +187 -13
  290. package/dist/parked-decide.d.ts +61 -0
  291. package/dist/parked-decide.js +58 -1
  292. package/dist/per-task-image.d.ts +54 -0
  293. package/dist/per-task-image.js +41 -0
  294. package/dist/plan-cache-probe.d.ts +35 -0
  295. package/dist/plan-cache-probe.js +18 -3
  296. package/dist/plugins/approval-exemption-store.d.ts +7 -0
  297. package/dist/plugins/approval-exemption-store.js +28 -2
  298. package/dist/plugins/approval-store-sql.d.ts +64 -0
  299. package/dist/plugins/approval-store-sql.js +32 -0
  300. package/dist/plugins/background-agent-store-sql.d.ts +55 -0
  301. package/dist/plugins/background-agent-store-sql.js +91 -4
  302. package/dist/plugins/background-shell-support.d.ts +98 -0
  303. package/dist/plugins/background-shell-support.js +117 -13
  304. package/dist/plugins/blob-backend.d.ts +104 -0
  305. package/dist/plugins/blob-backend.js +163 -6
  306. package/dist/plugins/breaker-state-sql.d.ts +65 -1
  307. package/dist/plugins/breaker-state-sql.js +46 -8
  308. package/dist/plugins/caching-session-store.d.ts +42 -0
  309. package/dist/plugins/caching-session-store.js +63 -3
  310. package/dist/plugins/checkpoint-store-sql.d.ts +179 -0
  311. package/dist/plugins/checkpoint-store-sql.js +239 -11
  312. package/dist/plugins/file-outcome-sink.d.ts +4 -0
  313. package/dist/plugins/file-outcome-sink.js +9 -0
  314. package/dist/plugins/file-resume-anchor-store.d.ts +20 -0
  315. package/dist/plugins/file-resume-anchor-store.js +43 -4
  316. package/dist/plugins/file-run-store.d.ts +90 -0
  317. package/dist/plugins/file-run-store.js +145 -13
  318. package/dist/plugins/file-snapshot-store-sql.d.ts +133 -1
  319. package/dist/plugins/file-snapshot-store-sql.js +178 -10
  320. package/dist/plugins/file-workflow-journal-store.d.ts +10 -0
  321. package/dist/plugins/file-workflow-journal-store.js +10 -0
  322. package/dist/plugins/fork-routing-session-store.d.ts +47 -0
  323. package/dist/plugins/fork-routing-session-store.js +51 -3
  324. package/dist/plugins/host-platform.d.ts +69 -0
  325. package/dist/plugins/host-platform.js +81 -2
  326. package/dist/plugins/image-bake-store-sql.d.ts +136 -1
  327. package/dist/plugins/image-bake-store-sql.js +241 -7
  328. package/dist/plugins/image-index-sql.d.ts +46 -0
  329. package/dist/plugins/image-index-sql.js +113 -4
  330. package/dist/plugins/k8s-bg-scripts.d.ts +34 -0
  331. package/dist/plugins/k8s-bg-scripts.js +88 -4
  332. package/dist/plugins/k8s-exec-protocol.d.ts +33 -0
  333. package/dist/plugins/k8s-exec-protocol.js +41 -0
  334. package/dist/plugins/local-checkpoint-store.d.ts +40 -0
  335. package/dist/plugins/local-checkpoint-store.js +86 -7
  336. package/dist/plugins/local-session-store.d.ts +157 -0
  337. package/dist/plugins/local-session-store.js +289 -34
  338. package/dist/plugins/local-task-attachment-store.js +14 -2
  339. package/dist/plugins/mailbox-store-sql.d.ts +38 -0
  340. package/dist/plugins/mailbox-store-sql.js +39 -6
  341. package/dist/plugins/memory-engine-pg.d.ts +30 -0
  342. package/dist/plugins/memory-engine-pg.js +122 -4
  343. package/dist/plugins/memory-engine-tidb.d.ts +26 -0
  344. package/dist/plugins/memory-engine-tidb.js +115 -5
  345. package/dist/plugins/memory-engine-vector-util.d.ts +5 -0
  346. package/dist/plugins/memory-engine-vector-util.js +5 -0
  347. package/dist/plugins/memory-resume-anchor-store.d.ts +8 -0
  348. package/dist/plugins/memory-resume-anchor-store.js +17 -0
  349. package/dist/plugins/memory-run-store.d.ts +63 -0
  350. package/dist/plugins/memory-run-store.js +73 -8
  351. package/dist/plugins/memory-session-policy-store.d.ts +17 -0
  352. package/dist/plugins/memory-session-policy-store.js +17 -0
  353. package/dist/plugins/memory-sync-store-pg.d.ts +42 -0
  354. package/dist/plugins/memory-sync-store-pg.js +45 -2
  355. package/dist/plugins/memory-sync-store-tidb.d.ts +9 -0
  356. package/dist/plugins/memory-sync-store-tidb.js +31 -1
  357. package/dist/plugins/outcome-ledger-sql.d.ts +63 -0
  358. package/dist/plugins/outcome-ledger-sql.js +97 -3
  359. package/dist/plugins/pg-approval-store.d.ts +7 -0
  360. package/dist/plugins/pg-approval-store.js +7 -0
  361. package/dist/plugins/pg-breaker-state.d.ts +6 -0
  362. package/dist/plugins/pg-breaker-state.js +6 -0
  363. package/dist/plugins/pg-checkpoint-store.d.ts +8 -0
  364. package/dist/plugins/pg-checkpoint-store.js +8 -0
  365. package/dist/plugins/pg-cost-quota.d.ts +17 -0
  366. package/dist/plugins/pg-cost-quota.js +6 -0
  367. package/dist/plugins/pg-file-snapshot-store.d.ts +6 -0
  368. package/dist/plugins/pg-file-snapshot-store.js +6 -0
  369. package/dist/plugins/pg-image-bake.d.ts +9 -0
  370. package/dist/plugins/pg-image-bake.js +9 -0
  371. package/dist/plugins/pg-image-index.d.ts +9 -0
  372. package/dist/plugins/pg-image-index.js +9 -0
  373. package/dist/plugins/pg-outcome-ledger.d.ts +9 -0
  374. package/dist/plugins/pg-outcome-ledger.js +9 -0
  375. package/dist/plugins/pg-pool.d.ts +50 -0
  376. package/dist/plugins/pg-pool.js +78 -0
  377. package/dist/plugins/pg-query.d.ts +11 -0
  378. package/dist/plugins/pg-rate-limiter.d.ts +23 -0
  379. package/dist/plugins/pg-rate-limiter.js +12 -2
  380. package/dist/plugins/pg-resume-anchor-store.d.ts +5 -0
  381. package/dist/plugins/pg-resume-anchor-store.js +5 -0
  382. package/dist/plugins/pg-run-store.d.ts +7 -0
  383. package/dist/plugins/pg-run-store.js +7 -0
  384. package/dist/plugins/pg-safe-json.d.ts +13 -0
  385. package/dist/plugins/pg-safe-json.js +40 -4
  386. package/dist/plugins/pg-session-policy-store.d.ts +5 -0
  387. package/dist/plugins/pg-session-policy-store.js +5 -0
  388. package/dist/plugins/pg-session-storage.d.ts +72 -0
  389. package/dist/plugins/pg-session-storage.js +152 -20
  390. package/dist/plugins/pg-session-store.d.ts +10 -0
  391. package/dist/plugins/pg-session-store.js +10 -0
  392. package/dist/plugins/pg-tool-result-store.d.ts +7 -0
  393. package/dist/plugins/pg-tool-result-store.js +7 -0
  394. package/dist/plugins/pg-workflow-journal-store.d.ts +7 -0
  395. package/dist/plugins/pg-workflow-journal-store.js +7 -0
  396. package/dist/plugins/pg-workflow-run-store.d.ts +7 -0
  397. package/dist/plugins/pg-workflow-run-store.js +7 -0
  398. package/dist/plugins/posix-shell-fs.d.ts +3 -0
  399. package/dist/plugins/posix-shell-fs.js +31 -1
  400. package/dist/plugins/remote-env-adb.d.ts +25 -0
  401. package/dist/plugins/remote-env-adb.js +95 -12
  402. package/dist/plugins/remote-env-e2b.d.ts +146 -0
  403. package/dist/plugins/remote-env-e2b.js +371 -40
  404. package/dist/plugins/remote-env-file-error.d.ts +34 -0
  405. package/dist/plugins/remote-env-file-error.js +37 -0
  406. package/dist/plugins/remote-env-host.d.ts +151 -0
  407. package/dist/plugins/remote-env-host.js +468 -70
  408. package/dist/plugins/remote-env-k8s.d.ts +135 -0
  409. package/dist/plugins/remote-env-k8s.js +318 -32
  410. package/dist/plugins/remote-env-local-docker.d.ts +65 -0
  411. package/dist/plugins/remote-env-local-docker.js +149 -24
  412. package/dist/plugins/remote-env-ssh.d.ts +35 -0
  413. package/dist/plugins/remote-env-ssh.js +117 -20
  414. package/dist/plugins/remote-scratchpad.d.ts +38 -0
  415. package/dist/plugins/remote-scratchpad.js +32 -2
  416. package/dist/plugins/remote-shell.d.ts +22 -0
  417. package/dist/plugins/remote-shell.js +27 -1
  418. package/dist/plugins/resume-anchor-store-sql.d.ts +28 -0
  419. package/dist/plugins/resume-anchor-store-sql.js +11 -0
  420. package/dist/plugins/roster-store-sql.d.ts +27 -0
  421. package/dist/plugins/roster-store-sql.js +54 -0
  422. package/dist/plugins/run-store-sql.d.ts +194 -0
  423. package/dist/plugins/run-store-sql.js +210 -9
  424. package/dist/plugins/s3-presign.d.ts +20 -0
  425. package/dist/plugins/s3-presign.js +49 -2
  426. package/dist/plugins/scheduler-support.d.ts +12 -0
  427. package/dist/plugins/scheduler-support.js +75 -3
  428. package/dist/plugins/send-file-ledger.d.ts +15 -0
  429. package/dist/plugins/send-file-ledger.js +53 -4
  430. package/dist/plugins/send-user-file.d.ts +77 -0
  431. package/dist/plugins/send-user-file.js +92 -4
  432. package/dist/plugins/session-policy-store-sql.d.ts +15 -0
  433. package/dist/plugins/session-policy-store-sql.js +75 -3
  434. package/dist/plugins/session-store.d.ts +45 -0
  435. package/dist/plugins/session-store.js +51 -0
  436. package/dist/plugins/sql-driver.d.ts +77 -0
  437. package/dist/plugins/sql-driver.js +4 -0
  438. package/dist/plugins/sql-escape.d.ts +8 -0
  439. package/dist/plugins/sql-escape.js +8 -0
  440. package/dist/plugins/sql-row-helpers.d.ts +25 -0
  441. package/dist/plugins/sql-row-helpers.js +25 -0
  442. package/dist/plugins/store-backend.d.ts +103 -0
  443. package/dist/plugins/store-backend.js +120 -27
  444. package/dist/plugins/store-contracts.d.ts +62 -0
  445. package/dist/plugins/store-contracts.js +3 -0
  446. package/dist/plugins/task-attachment-store.d.ts +60 -0
  447. package/dist/plugins/task-attachment-store.js +49 -3
  448. package/dist/plugins/task-list-store-sql.d.ts +25 -0
  449. package/dist/plugins/task-list-store-sql.js +21 -0
  450. package/dist/plugins/tidb-approval-store.d.ts +6 -0
  451. package/dist/plugins/tidb-approval-store.js +6 -0
  452. package/dist/plugins/tidb-breaker-state.d.ts +5 -0
  453. package/dist/plugins/tidb-breaker-state.js +5 -0
  454. package/dist/plugins/tidb-checkpoint-store.d.ts +7 -0
  455. package/dist/plugins/tidb-checkpoint-store.js +7 -0
  456. package/dist/plugins/tidb-cost-quota.d.ts +6 -0
  457. package/dist/plugins/tidb-cost-quota.js +1 -0
  458. package/dist/plugins/tidb-file-snapshot-store.d.ts +6 -0
  459. package/dist/plugins/tidb-file-snapshot-store.js +6 -0
  460. package/dist/plugins/tidb-image-bake.d.ts +8 -0
  461. package/dist/plugins/tidb-image-bake.js +8 -0
  462. package/dist/plugins/tidb-image-index.d.ts +8 -0
  463. package/dist/plugins/tidb-image-index.js +8 -0
  464. package/dist/plugins/tidb-outcome-ledger.d.ts +10 -0
  465. package/dist/plugins/tidb-outcome-ledger.js +10 -0
  466. package/dist/plugins/tidb-pool.d.ts +56 -0
  467. package/dist/plugins/tidb-pool.js +181 -1
  468. package/dist/plugins/tidb-rate-limiter.d.ts +11 -0
  469. package/dist/plugins/tidb-rate-limiter.js +5 -2
  470. package/dist/plugins/tidb-resume-anchor-store.d.ts +5 -0
  471. package/dist/plugins/tidb-resume-anchor-store.js +5 -0
  472. package/dist/plugins/tidb-run-store.d.ts +7 -0
  473. package/dist/plugins/tidb-run-store.js +7 -0
  474. package/dist/plugins/tidb-session-policy-store.d.ts +5 -0
  475. package/dist/plugins/tidb-session-policy-store.js +5 -0
  476. package/dist/plugins/tidb-session-storage.d.ts +43 -0
  477. package/dist/plugins/tidb-session-storage.js +62 -3
  478. package/dist/plugins/tidb-session-store.d.ts +142 -0
  479. package/dist/plugins/tidb-session-store.js +264 -16
  480. package/dist/plugins/tidb-tool-result-store.d.ts +5 -0
  481. package/dist/plugins/tidb-tool-result-store.js +7 -0
  482. package/dist/plugins/tidb-workflow-journal-store.d.ts +7 -0
  483. package/dist/plugins/tidb-workflow-journal-store.js +7 -0
  484. package/dist/plugins/tidb-workflow-run-store.d.ts +8 -0
  485. package/dist/plugins/tidb-workflow-run-store.js +8 -0
  486. package/dist/plugins/tool-result-store-sql.d.ts +58 -0
  487. package/dist/plugins/tool-result-store-sql.js +38 -2
  488. package/dist/plugins/web-search.d.ts +35 -0
  489. package/dist/plugins/web-search.js +45 -9
  490. package/dist/plugins/workflow-journal-limits.d.ts +10 -0
  491. package/dist/plugins/workflow-journal-limits.js +10 -0
  492. package/dist/plugins/workflow-journal-store-sql.d.ts +78 -0
  493. package/dist/plugins/workflow-journal-store-sql.js +58 -2
  494. package/dist/plugins/workflow-run-store-sql.d.ts +84 -0
  495. package/dist/plugins/workflow-run-store-sql.js +84 -6
  496. package/dist/plugins/worktree-isolation.d.ts +45 -0
  497. package/dist/plugins/worktree-isolation.js +105 -6
  498. package/dist/plugins/write-behind-counter.d.ts +56 -1
  499. package/dist/plugins/write-behind-counter.js +53 -14
  500. package/dist/principal-jwt.d.ts +24 -0
  501. package/dist/principal-jwt.js +60 -5
  502. package/dist/project-memory.d.ts +22 -0
  503. package/dist/project-memory.js +144 -15
  504. package/dist/prompts-domain-validate.d.ts +28 -0
  505. package/dist/prompts-domain-validate.js +42 -1
  506. package/dist/question.d.ts +33 -0
  507. package/dist/question.js +69 -2
  508. package/dist/resource-suspend.d.ts +21 -0
  509. package/dist/resource-suspend.js +16 -0
  510. package/dist/router/route-orchestration.d.ts +78 -0
  511. package/dist/router/route-orchestration.js +77 -0
  512. package/dist/run-local.d.ts +32 -0
  513. package/dist/run-local.js +172 -8
  514. package/dist/runs.d.ts +189 -4
  515. package/dist/runs.js +465 -24
  516. package/dist/runtime-caps-resolver.d.ts +106 -0
  517. package/dist/runtime-caps-resolver.js +89 -4
  518. package/dist/runtime-governance.d.ts +84 -0
  519. package/dist/runtime-governance.js +127 -1
  520. package/dist/sandbox-pkg-source.d.ts +23 -0
  521. package/dist/sandbox-pkg-source.js +37 -0
  522. package/dist/sealed-key.d.ts +54 -0
  523. package/dist/sealed-key.js +68 -3
  524. package/dist/security.d.ts +108 -0
  525. package/dist/security.js +145 -6
  526. package/dist/sema-registry.d.ts +21 -0
  527. package/dist/sema-registry.js +21 -0
  528. package/dist/session-leaf-bus.d.ts +31 -0
  529. package/dist/session-leaf-bus.js +32 -0
  530. package/dist/session-sync-content.d.ts +46 -0
  531. package/dist/session-sync-content.js +47 -1
  532. package/dist/session-sync-kernel.d.ts +89 -0
  533. package/dist/session-sync-kernel.js +48 -3
  534. package/dist/session-sync.d.ts +125 -0
  535. package/dist/session-sync.js +181 -8
  536. package/dist/session-titler.d.ts +26 -0
  537. package/dist/session-titler.js +41 -7
  538. package/dist/session-watch.d.ts +53 -1
  539. package/dist/session-watch.js +73 -9
  540. package/dist/sighup-idle.d.ts +30 -0
  541. package/dist/sighup-idle.js +12 -1
  542. package/dist/spec-fields.d.ts +91 -3
  543. package/dist/spec-fields.js +116 -4
  544. package/dist/task-cwd.d.ts +50 -0
  545. package/dist/task-cwd.js +68 -1
  546. package/dist/task-mcp.d.ts +47 -0
  547. package/dist/task-mcp.js +29 -0
  548. package/dist/task-settings.d.ts +175 -0
  549. package/dist/task-settings.js +226 -11
  550. package/dist/task-workflow.d.ts +67 -0
  551. package/dist/task-workflow.js +75 -8
  552. package/dist/tool-approval.d.ts +91 -0
  553. package/dist/tool-approval.js +215 -0
  554. package/dist/trace/artifacts.d.ts +9 -0
  555. package/dist/trace/artifacts.js +30 -5
  556. package/dist/trace/core-keyset-guard.d.ts +18 -0
  557. package/dist/trace/ledger-sink.d.ts +43 -0
  558. package/dist/trace/ledger-sink.js +64 -5
  559. package/dist/trace/project.d.ts +133 -0
  560. package/dist/trace/project.js +189 -2
  561. package/dist/trace/redact.d.ts +19 -0
  562. package/dist/trace/redact.js +66 -9
  563. package/dist/usage-analytics.d.ts +26 -0
  564. package/dist/usage-analytics.js +26 -3
  565. package/package.json +1 -1
package/dist/run-local.js CHANGED
@@ -1,4 +1,26 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * `run-local` — a ONE-SHOT local CLI for the agent engine.
4
+ *
5
+ * Boots the SAME runtime as `src/main.ts` (createBrain + Runner + the scenario/skills capability layer +
6
+ * the host execution env) IN-PROCESS, runs ONE task from the CLI objective to completion, prints the
7
+ * TaskResult, and exits. There is NO long-running HTTP server and NO submission auth gate — this is the
8
+ * whole point: it removes two friction points (the SERVICE_AUTH_TOKEN 503 on submit and the
9
+ * manual server lifecycle). The user fills `~/.ai-agent/.env` + `config.d/` (the LOCAL config source) and
10
+ * just runs `run-local "<objective>"`.
11
+ *
12
+ * Posture: LOCAL config mode (CONFIG_PROVIDER=local) → createConfigProvider → LocalConfigProvider →
13
+ * applyEffective (config.d/.env drives models/roles/mcp), and the `host` exec lane (run on THIS machine,
14
+ * no container) — identical building blocks to the server path so behavior matches (no drift). It reuses
15
+ * main.ts's helpers verbatim; the only thing it skips is the server-only surface (createHttpServer, listen,
16
+ * auth/rateLimit/quota/run-store/leader/durable-checkpoint/reapers).
17
+ *
18
+ * Usage: run-local "<objective>" [--root <dir>] [--json] [--scenario <name>]
19
+ *
20
+ * `main()` is a thin wrapper over the testable {@link runLocal}, which takes argv + injectable
21
+ * deps (a mock Brain, a captured logger/printer, and an `exit` shim) so the assembly + one-shot flow can be
22
+ * exercised deterministically with no real LLM / network / keys.
23
+ */
2
24
  import { homedir } from "node:os";
3
25
  import { join } from "node:path";
4
26
  import { realpathSync } from "node:fs";
@@ -24,6 +46,7 @@ import { buildPricing } from "./budget.js";
24
46
  import { createKeyResolver } from "./key-resolver.js";
25
47
  import { createLogger } from "./observability/logger.js";
26
48
  import { createMetrics } from "./observability/metrics.js";
49
+ /** Parse argv (everything AFTER `node run-local.js`). Throws a clear Error on a missing objective. */
27
50
  export function parseArgs(argv) {
28
51
  let objective;
29
52
  let root;
@@ -34,6 +57,11 @@ export function parseArgs(argv) {
34
57
  let json = false;
35
58
  const valueFlag = (i, name) => {
36
59
  const v = argv[i];
60
+ // 空串/纯空白 = **没给参数**,不是"用户就想要空"(core [1689] 第 3 条同款:`??` 兜不住 `""`)。
61
+ // 收下它会让空串变成**隔离键**:`--session ""` → `args.session ?? uuidv7()` 得到 `""`,所有这类调用
62
+ // 复用同一个空 id「会话」;`--user ""` → `args.user ?? "local"` 得到 `""`,长期记忆落进匿名桶而不是
63
+ // 文档写的默认身份,且「传空串」与「不传」成为两个不同的桶。在解析器这一层拒才对 —— 这个函数存在的
64
+ // 意义本就是「这个 flag 需要一个参数」。
37
65
  if (v === undefined || v.trim() === "" || v.startsWith("--"))
38
66
  throw new UsageError(`${name} needs an argument`);
39
67
  return v;
@@ -59,7 +87,7 @@ export function parseArgs(argv) {
59
87
  throw new UsageError(`unknown flag: ${a}`);
60
88
  }
61
89
  else if (objective === undefined) {
62
- objective = a;
90
+ objective = a; // first positional = the objective
63
91
  }
64
92
  else {
65
93
  throw new UsageError(`unexpected extra argument: ${a} (quote the objective as one argument)`);
@@ -70,15 +98,35 @@ export function parseArgs(argv) {
70
98
  }
71
99
  return { objective, root, json, ...(scenario ? { scenario } : {}), ...(session ? { session } : {}), ...(workspace ? { workspace } : {}), ...(user ? { user } : {}) };
72
100
  }
101
+ /** A bad-usage error → print to stderr + exit 2 (distinct from a task failure exit 1). */
73
102
  export class UsageError extends Error {
74
103
  }
104
+ /**
105
+ * The model GATEWAY pre-flight (mirrors the doctor message): the engine cannot run a real
106
+ * task without (a) a gateway base URL that ends in `/v1` and (b) the gateway/model API key resolvable from
107
+ * env. We surface a "you still need to set: …" list rather than letting the first brain call crash with a
108
+ * cryptic auth/connect error. Returns a list of missing items (empty = OK).
109
+ *
110
+ * NOTE: with an injected mock `brain` the gateway is irrelevant (no real call is made), so the caller skips
111
+ * this check in that case — the check is about a REAL run, not the assembly.
112
+ */
75
113
  export function missingGatewayRequirements(config) {
76
114
  const missing = [];
115
+ // (a) base URL: loadConfig always has a default, but a real local user must point it at THEIR gateway and
116
+ // it must carry the OpenAI-compatible `/v1` suffix (the brain appends `/chat/completions`).
77
117
  if (!config.gatewayBaseUrl || !/\/v1\/?$/.test(config.gatewayBaseUrl)) {
78
118
  missing.push("MODEL_GATEWAY_BASEURL (the OpenAI-compatible gateway URL, must end in /v1)");
79
119
  }
120
+ // (b) the key: either the single gateway key (MODEL_API_KEY) OR — when the catalog pins a per-model
121
+ // apiKeyEnv (sema-registry / config.d) — that named env var must be present. A model without its own
122
+ // apiKeyEnv falls back to the gateway key, so the gateway key is the floor.
80
123
  const perModelEnvs = Object.values(config.modelApiKeyEnv ?? {});
81
124
  const haveGatewayKey = !!config.gatewayApiKey;
125
+ // The gateway key is the FLOOR: per-model keys only WAIVE it when EVERY catalog model the resolver may be
126
+ // asked about carries (and has set) its own apiKeyEnv. A model with no per-model key falls back to the
127
+ // gateway key, so a MIXED catalog (some models keyed, some not) with the gateway key unset would crash on
128
+ // the unkeyed model's first brain call. We dedupe via the model objects' `.name` so the synthetic `default`
129
+ // / model-id ALIAS entries of config.models (which mirror an existing per-name model) are not over-counted.
82
130
  const catalogModelNames = new Set(Object.values(config.models ?? {}).map((m) => m.name));
83
131
  const allModelsHaveOwnKey = catalogModelNames.size > 0 &&
84
132
  [...catalogModelNames].every((n) => {
@@ -97,6 +145,11 @@ export function missingGatewayRequirements(config) {
97
145
  }
98
146
  return missing;
99
147
  }
148
+ /**
149
+ * Boot the engine in LOCAL mode, run ONE task to completion, print the result. Returns the process exit
150
+ * code (0 = completed, 1 = the task did not complete / a fatal error, 2 = bad usage / unmet env). Pure of
151
+ * `process.exit` so a test can assert the code; `main()` applies it.
152
+ */
100
153
  export async function runLocal(argv, deps = {}) {
101
154
  const print = deps.print ?? ((l) => console.log(l));
102
155
  const printErr = deps.printErr ?? ((l) => console.error(l));
@@ -111,17 +164,39 @@ export async function runLocal(argv, deps = {}) {
111
164
  }
112
165
  throw err;
113
166
  }
167
+ // FORCE local posture: a one-shot CLI is a single-machine run. Set the knob BEFORE loadConfig so
168
+ // (1) createConfigProvider selects the LocalConfigProvider and (2) config.ts defaults the `host` exec lane
169
+ // (the TOC first-run default for CONFIG_PROVIDER=local with no explicit REMOTE_EXEC). Honor an operator who
170
+ // already set it to something else (don't override an explicit choice) — but never leave it remote-by-default.
114
171
  if (!process.env.CONFIG_PROVIDER)
115
172
  process.env.CONFIG_PROVIDER = "local";
173
+ // FORCE the durable backends OFF: a one-shot, single-machine CLI has nothing durable to persist
174
+ // and deliberately does NOT assemble the server-only StoreBackend. A shared .env that carries
175
+ // SESSION_BACKEND=tidb would otherwise make loadConfig() (needsTidb → TIDB_HOST) or createSessionStore()
176
+ // throw a cryptic error before the run even starts. Unlike CONFIG_PROVIDER/REMOTE_EXEC (where an explicit
177
+ // operator choice can be HONORED), a DB session store cannot work here at all, so we FORCE — never honor —
178
+ // this knob to in-memory so the CLI just works regardless of the shared config. Long-term memory needs no
179
+ // forcing: the design/138 memory ENGINE is file-based and default-ON here (single-user; MEMORY_ENGINE=off
180
+ // and MEMORY_ENGINE_DIR pass through loadConfig as-is).
116
181
  process.env.SESSION_BACKEND = "memory";
182
+ // 🔴 REQUIRE_PRINCIPAL is the same shared-config footgun class: run-local IS the single
183
+ // user at their own terminal — there is no untrusted caller to gate — but a server .env carrying
184
+ // REQUIRE_PRINCIPAL=true would flip `memoryEngineBackendFor`/`memoryScopeFor` into the multi-tenant
185
+ // memory-dark branch (plus the host-power gates), silently killing the CLI's long-term memory. FORCE it off.
117
186
  process.env.REQUIRE_PRINCIPAL = "false";
187
+ // --root wins, then the standard local roots (mirrors main.ts's local-root resolution).
118
188
  const root = args.root ?? process.env.CONFIG_LOCAL_DIR ?? process.env.AGENT_DATA_DIR ?? join(homedir(), ".ai-agent");
119
189
  if (args.root)
120
- process.env.CONFIG_LOCAL_DIR = args.root;
190
+ process.env.CONFIG_LOCAL_DIR = args.root; // so loadConfig's local-dir + the provider agree
121
191
  const config = loadConfig();
122
192
  const logger = deps.logger ?? createLogger(config.logLevel);
123
193
  const metrics = createMetrics();
194
+ // F10 (codex audit): run-local used to drop the pre-logger config diagnostics on the floor (S20 soft-knob
195
+ // warnings + [792]④ boot notices) — main.ts drained them, this entrypoint didn't. Shared helper, no drift.
124
196
  logConfigDiagnostics(logger);
197
+ // ── Config source (DUAL-MODE §4): resolve the effective config from the LOCAL FileConfigStore and apply it
198
+ // OVER the env defaults (config.d/.env drives models/roles). Unreachable/empty → keep the env-derived
199
+ // config (the local root may not exist yet — "fill .env and run" still works off env). ──
125
200
  const configProvider = createConfigProvider({
126
201
  provider: config.configProvider ?? "local",
127
202
  ...(config.configLocalDir ? { localDir: config.configLocalDir } : { localDir: root }),
@@ -130,10 +205,14 @@ export async function runLocal(argv, deps = {}) {
130
205
  try {
131
206
  const r = await configProvider.fetchEffective(undefined);
132
207
  if (r) {
208
+ // [898] tolerant read(registry-core 0.10.12):catalog 域坏文件不再连坐整包回落 env——坏域按 default
209
+ // 落+这里 per-domain warn 点名(文件路径在 error 文案里),好域照常生效。gate 域坏仍走下面整包 catch。
133
210
  for (const de of r.domainErrors ?? [])
134
211
  logger.warn("config_domain_invalid", { domain: de.domain, error: de.error, note: "domain fell to schema defaults; other domains applied normally" });
135
212
  effective = r.effective;
136
213
  applyEffective(config, r.effective, logger);
214
+ // MCP servers (config.d/mcp.json or center) — applied here (NOT inside applyEffective, which only
215
+ // covers models/roles/gates/teams) so run-local matches the server path (main.ts:446). Restart-to-apply.
137
216
  if (effective?.mcp)
138
217
  config.mcpServers = resolveMcpServers(effective.mcp, logger);
139
218
  logger.info("config_loaded", { source: configProvider.kind, version: r.effective.version });
@@ -142,6 +221,10 @@ export async function runLocal(argv, deps = {}) {
142
221
  catch (err) {
143
222
  logger.warn("config_source_unreachable_using_env", { source: configProvider.kind, err: String(err) });
144
223
  }
224
+ // ── remoteExec (DUAL-MODE §5): in local mode, honor the SHARED config.d/remote-exec.json via the registry
225
+ // loader (the SAME file the client's `agent-cli config` writes). MISSING → keep config.ts's host default;
226
+ // PRESENT host → it wins (workdir→workspaceBase); corrupt → fail-closed. Mirrors main.ts's block; the
227
+ // isolated lanes (e2b/k8s/ssh/adb) stay env-sourced (a one-shot CLI is the host lane by design). ──
145
228
  try {
146
229
  const fileRx = await loadRemoteExec(root);
147
230
  if (fileRx?.provider === "host") {
@@ -161,6 +244,8 @@ export async function runLocal(argv, deps = {}) {
161
244
  printErr(`config.d/remote-exec.json is invalid: ${String(err)}`);
162
245
  return 2;
163
246
  }
247
+ // ── Pre-flight: with a REAL brain, validate the gateway + key and print the doctor-style guidance instead
248
+ // of crashing on the first brain call. With an injected mock brain, no real call happens → skip. ──
164
249
  if (!deps.brain) {
165
250
  const missing = missingGatewayRequirements(config);
166
251
  if (missing.length > 0) {
@@ -171,8 +256,12 @@ export async function runLocal(argv, deps = {}) {
171
256
  return 2;
172
257
  }
173
258
  }
259
+ // ── Minimal runtime assembly (the SAME building blocks as main.ts, server-only bits omitted). ──
174
260
  const brain = deps.brain ?? createBrain(config, deps.fetchImpl ? { fetchImpl: deps.fetchImpl } : {});
175
261
  const pricing = buildPricing(config.models);
262
+ // Persistent LOCAL stores (TOC): core's file-backed StorageBackend under the data root → session + long-term
263
+ // memory + checkpoints SURVIVE across invocations (no DB). flock'd single-instance per data dir; a second
264
+ // concurrent instance throws in the constructor — surface a clear message instead of a stack.
176
265
  let fileBackend;
177
266
  try {
178
267
  fileBackend = new FileStorageBackend({ root });
@@ -184,17 +273,36 @@ export async function runLocal(argv, deps = {}) {
184
273
  }
185
274
  const sessionStore = fileBackend.sessionStore;
186
275
  const keyResolver = createKeyResolver(config.modelApiKeyEnv);
276
+ // Host exec lane: run on THIS machine, in a FIXED workspace (CC-like) — the cwd by default (or --workspace /
277
+ // a config.d workdir). The agent's file edits PERSIST there + are user-visible; the dir is the user's OWN and
278
+ // is NEVER deleted (workspaceDir mode). One env per task; the Runner owns its lifetime.
187
279
  const hostRx = config.remoteExec?.provider === "host" ? config.remoteExec : undefined;
188
280
  const workspaceDir = args.workspace ?? hostRx?.workspaceBase ?? process.cwd();
189
281
  const executionEnvFactory = hostRx
190
282
  ? hostExecutionEnvFactory({
191
283
  workspaceDir,
284
+ // systematic-audit (uniformity with main.ts:442 + the worktree-lane gates): gate background-shell by tenancy.
285
+ // run-local is a single-user CLI (no untrusted caller) so requirePrincipal is ~always false → ON; passing the
286
+ // gate keeps the policy uniform if a shared .env ever sets REQUIRE_PRINCIPAL, never relying on the `?? true`.
192
287
  backgroundShell: config.requirePrincipal !== true,
193
288
  ...(hostRx.commandTimeoutMs != null ? { commandTimeoutMs: hostRx.commandTimeoutMs } : {}),
194
289
  })
195
290
  : undefined;
291
+ // TOC local LSP (core 1.190): run-local IS the pure-local host lane, so mount core's `NodeLspManager` (local
292
+ // child_process language servers over stdio, CC `services/lsp` parity) on the host lane. Default ON (degrades
293
+ // gracefully to grep/read if a server binary is absent); `LSP_HOST_ENABLED=false` opts out (design/158 B4 split
294
+ // this lane off `LSP_ENABLED`, which still works as a back-compat opt-out). `requirePrincipal !== true`
295
+ // keeps it uniform with main.ts (a no-op here — run-local is single-user — but never relies on that). Both runners.
196
296
  const lspManager = hostRx && config.lspHostEnabled && config.requirePrincipal !== true ? new NodeLspManager({ log: (event, fields) => logger.info(event, fields) }) : undefined;
297
+ // Long-term memory (design/138 S1): run-local IS the single-user lane, so the file-based memory ENGINE is
298
+ // default-ON (MEMORY_ENGINE=off opts out). The data root doubles as the engine config-root fallback so a
299
+ // run-local and the local HTTP service on one box share ONE memory home (MEMORY_ENGINE_DIR overrides).
197
300
  const memoryEngine = memoryEngineBackendFor(config, root);
301
+ // 142-S2.5-W1: TOC 同步 client 腿——run-local 是 file memory 形态本尊(loadConfig 已拒
302
+ // DB backend 上的 MEMORY_SYNC_*)。run-local 没接 onMemoryHarvestReport 钩子(一次性 CLI:harvest 只在
303
+ // 任务收尾发生一次,fire-and-forget 轮会被进程退出腰斩),按设计的后备姿势:boot fire-and-forget 一轮
304
+ // (拉中心增量,失败 warn 不阻断;进程退出腰斩也安全——cursor 保留纪律下轮重收敛)+ 任务结束后 await
305
+ // 一轮(推本次 harvest 的新记忆;syncOnce 串行链自动排在 boot 轮之后)。
198
306
  let memorySync;
199
307
  if (config.memorySync && memoryEngine) {
200
308
  memorySync = createMemorySyncRunner({
@@ -210,7 +318,12 @@ export async function runLocal(argv, deps = {}) {
210
318
  else if (config.memorySync) {
211
319
  logger.warn("memory_sync_configured_but_memory_dark", { note: "MEMORY_SYNC_URL is set but the file memory engine is dark (MEMORY_ENGINE=off / remote exec lane) — no sync rounds will run" });
212
320
  }
321
+ // codex-2 F3([985]e run-local 半场):config.d/prompts.json 的 catalog 轴在这条 lane 也要真消费——
322
+ // 判形(与 server 同一候选门)→ CenterPromptSource(File 形,<root>/prompt-epoch 自管)→ 两 Runner 的
323
+ // promptSource。坏形/apply 失败=warn + 内置照跑(单进程本地形,无 refresh 重试拍;下次启动再试)。
213
324
  const promptEpochDir = join(root, "prompt-epoch");
325
+ // codex-7:守护工厂与 main.ts 同姿势——File 店构造同步 mkdir,坏 prompt-epoch 路径不得把可选特性
326
+ // 变成 run-local 启动致命(Memory 兜底=candidate 不跨启动持久;内置照跑)。
214
327
  const promptSource = (() => {
215
328
  try {
216
329
  return new CenterPromptSource({
@@ -225,7 +338,7 @@ export async function runLocal(argv, deps = {}) {
225
338
  }
226
339
  })();
227
340
  try {
228
- await promptSource.restore();
341
+ await promptSource.restore(); // run-local IS the owning local provider — the on-disk candidate is authoritative
229
342
  const promptsRaw = effective?.prompts;
230
343
  if (promptsRaw !== undefined) {
231
344
  const pv = validatePromptsDomain(promptsRaw);
@@ -235,6 +348,8 @@ export async function runLocal(argv, deps = {}) {
235
348
  logger.warn("center_prompts_invalid", { phase: "run-local", error: pv.error, note: "malformed prompts face — built-ins serve" });
236
349
  }
237
350
  else {
351
+ // no prompts face on this boot: a persisted candidate whose file was removed must not survive (same
352
+ // cleared semantics as the server lane) — applyCatalogToSource's current() probe handles the owed disable.
238
353
  await applyCatalogToSource(promptSource, undefined, undefined, logger, "run-local");
239
354
  }
240
355
  }
@@ -247,35 +362,57 @@ export async function runLocal(argv, deps = {}) {
247
362
  roles: config.roles,
248
363
  pricing,
249
364
  promptSource,
365
+ // [931]① clay 拍:run-local=Sema 品牌本地形态,commit 尾注接 Sema 署名(core 1.300 缺省已翻转不署)。
250
366
  hands: { commitCoAuthor: "Sema <noreply@vivi-ai.com>" },
251
367
  sessionStore,
252
368
  ...(memoryEngine ? { memoryBackend: memoryEngine.backend, memoryEngineDir: memoryEngine.root } : {}),
253
369
  checkpointStore: fileBackend.checkpointStore,
370
+ // core 1.219 (dogfood: "ReadToolResult(ref) 恒空"): durable tool-result refs on the TOC CLI
371
+ // lane too — offloaded full text survives a process restart (one file per ref under the data root).
254
372
  toolResultStore: fileBackend.toolResultStore,
255
373
  ...(executionEnvFactory ? { executionEnvFactory } : {}),
256
374
  ...(lspManager ? { lspManager } : {}),
375
+ // design/113 C4: run-local IS the single-user host lane (cwd = --workspace ?? process.cwd()) — the CLI path where
376
+ // CLAUDE.md project-awareness most belongs. Wire it unless explicitly disabled.
257
377
  ...(config.projectMemoryEnabled
258
378
  ? { loadProjectMemory: makeLoadProjectMemory({ logger }), probeInstructionSources: makeProbeInstructionSources() }
259
379
  : {}),
260
380
  });
381
+ // Sub-task runner (council lenses/team) — mirrors main.ts's subRunner, INCLUDING executionEnvFactory so a delegated
382
+ // child gets hands (Bash/Read/Edit) on the host lane. Without it the child's handsEnabled is false — the exact
383
+ // "subagent couldn't run pwd" defect fixed at main.ts:799; this is its run-local twin, caught by the systematic audit.
384
+ // [1367]① fork server half(main.ts subRunner 同款):ForkRoutingSessionStore——fork/resume 形
385
+ // (requireExisting)→ host 文件店优先(core 1.350 hostSessionFork 在宿主店 fork,拆店=响亮
386
+ // resume.session_not_found),普通子任务 → 私有 TTL 店(throwaway 姿势保留)。
261
387
  const subRunner = new Runner({ brain, models: config.models, roles: config.roles, pricing, promptSource, sessionStore: new ForkRoutingSessionStore(sessionStore, new TtlSessionStore({ defaultTtlDays: 1 / 24 })), ...(executionEnvFactory ? { executionEnvFactory } : {}), ...(lspManager ? { lspManager } : {}) });
388
+ // Capability layer (loadSkills + buildScenarios + selectScenario) — assembled exactly like main.ts.
262
389
  const skills = loadSkills(config.skillsDir);
263
390
  const repoClient = config.gitApiBaseUrl ? new GiteaClient(config.gitApiBaseUrl, config.gitApiToken) : undefined;
391
+ // systematic-audit: wire the env-configured WebSearch backend (WEB_SEARCH_PROVIDER) exactly like main.ts, so the
392
+ // default scenario's WebSearch tool is assembled on the CLI path too (it was silently never built before).
264
393
  const webSearchCfg = webSearchConfigFromEnv();
265
394
  const webSearch = webSearchCfg ? createWebSearchBackend(webSearchCfg) : undefined;
266
395
  const scenarioDeps = {
267
396
  runner, subRunner, model: "default", skills, repoClient, metrics, logger,
268
397
  oaApiBaseUrl: config.oaApiBaseUrl, oaServiceToken: config.oaServiceToken, oaIssue: config.oaIssue,
269
398
  ...(webSearch ? { webSearch } : {}),
270
- brandIdentity: true,
399
+ brandIdentity: true, // run-local is always a local/TOC deployment → brand the default scenario as Sema.
271
400
  };
272
401
  const scenarios = buildScenarios(scenarioDeps);
402
+ // Center-/config.d-declared scenarios (composition-as-config): overlay over the built-ins, center wins —
403
+ // mirrors main.ts:453-457 so a config.d/scenarios.json scenario resolves identically in run-local (no drift).
273
404
  if (effective?.scenarios) {
274
405
  const { overlay } = centerScenarios(scenarioDeps, effective.scenarios.scenarios, Object.keys(scenarios), logger);
275
406
  Object.assign(scenarios, overlay);
276
407
  }
408
+ // ── Build the TaskSpec the way the /v1/tasks sync handler's resolveSpec does (minus server-only fields:
409
+ // no auth/principal/durable/approval/budget-cap-from-body). Fresh sessionId; @-model mention honored. ──
277
410
  const requested = args.scenario ?? config.defaultScenario;
278
411
  const scenarioName = scenarios[requested] ? requested : "default";
412
+ // A scenario may THROW HttpError synchronously when a prerequisite is unmet (e.g. `scan` needs
413
+ // GIT_API_BASEURL + a repo; `oa` needs OA_* + an authenticated principal — neither of which a one-shot CLI
414
+ // supplies). The server catches this in resolveSpec/prepareSpec and returns a clean 4xx; here we mirror that
415
+ // with the doctor-style UX (message to stderr + exit 2) instead of letting it bubble to the fatal exit-1 path.
279
416
  let cap;
280
417
  try {
281
418
  cap = selectScenario(scenarios, scenarioName)({ scenario: scenarioName, objective: args.objective });
@@ -285,34 +422,48 @@ export async function runLocal(argv, deps = {}) {
285
422
  printErr(`cannot run scenario "${scenarioName}": ${err.message}`);
286
423
  if (scenarioName === "scan")
287
424
  printErr("(the `scan` scenario needs a git API base URL and a repo — run-local cannot supply a repo; use the default scenario)");
288
- void lspManager?.dispose();
425
+ void lspManager?.dispose(); // symmetry (harmless no-op here — servers spawn lazily during runTask, not yet)
289
426
  await fileBackend.dispose();
290
427
  return 2;
291
428
  }
292
429
  throw err;
293
430
  }
294
431
  const mention = parseModelMention(args.objective, Object.keys(config.models));
432
+ // --session REUSES a session (durable multi-turn across invocations, via the file session store); absent →
433
+ // a fresh uuidv7 (still persisted). --user is the stable memory/identity scope so long-term memory
434
+ // accumulates per user (default "local" = the single TOC user). The file stores acquire/append lazily.
295
435
  const sessionId = args.session ?? uuidv7();
296
436
  const scope = args.user ?? "local";
437
+ // Timeout policy mirrors the server (taskWallClockSec): run-local IS the pure single-user
438
+ // TOC lane → NO wall clock by default (core's wedge safety-net still applies); explicit TASK_TIMEOUT_SEC
439
+ // wins with its raise-only floor (team 1500s — a multi-agent coordinator legitimately exceeds 600s).
440
+ // [854]④ 不落此腿:per-request body.limits 是 HTTP body 车道(resolveTaskLimits,main.ts resolveSpec);
441
+ // run-local 无 body,配速仍走 env(要 CLI flag 时另开件,别在这里半做)。
297
442
  const taskTimeoutSec = Math.max(0, Math.floor(Number(process.env.TASK_TIMEOUT_SEC ?? "0")) || 0);
298
443
  const timeoutSec = taskWallClockSec(taskTimeoutSec, false, scenarioName === "team");
299
444
  const mcp = mcpForScenario(config.mcpServers, scenarioName);
300
445
  const spec = {
301
446
  objective: mention.cleanedText || args.objective,
302
447
  sessionId,
448
+ // design/129: run-local IS the pure TOC lane → session-scoped background children
449
+ // (CC Backgrounded semantics; parity with the server's single-user posture).
303
450
  backgroundScope: "session",
304
- principal: scope,
451
+ principal: scope, // stable local memory/identity scope (single-user TOC; --user overrides)
452
+ // design/138 S1: enable the memory engine for this run (spec.memory is core's per-task activation half of
453
+ // the deps.memoryBackend switch). Scope = the --user identity (default "local", the single TOC user).
305
454
  ...(memoryEngine ? { memory: memorySpecForRequest(scope, undefined) } : {}),
306
455
  model: mention.model ?? "default",
307
456
  getApiKeyAndHeaders: keyResolver,
308
457
  tools: cap.tools,
309
458
  skills: cap.skills,
310
459
  ...(cap.promptProvider ? { promptProvider: cap.promptProvider } : {}),
460
+ // [849] 场景层定死的终验(autonomous 场景)——与 main.ts resolveSpec 同语义,CLI 路径不漂移。
311
461
  ...(cap.finalVerification === true ? { finalVerification: true } : {}),
312
462
  ...(mcp ? { mcp } : {}),
313
463
  ...(timeoutSec !== undefined ? { limits: { timeoutSec } } : {}),
314
464
  };
315
465
  logger.info("run_local_start", { scenario: scenarioName, model: spec.model, sessionId, exec: config.remoteExec?.provider ?? "in-process" });
466
+ // ── Run ONE task to completion (the sync /v1/tasks path: plain runTask, no verify/cascade). ──
316
467
  let result;
317
468
  let exitCode = 0;
318
469
  try {
@@ -320,12 +471,14 @@ export async function runLocal(argv, deps = {}) {
320
471
  }
321
472
  catch (err) {
322
473
  printErr(`task crashed: ${err instanceof Error ? err.message : String(err)}`);
474
+ // Clean shutdown even on a crash.
323
475
  runner.sessions.dispose();
324
476
  subRunner.sessions.dispose();
325
- void lspManager?.dispose();
477
+ void lspManager?.dispose(); // Kill local child-process language servers so a re-run doesn't orphan them
326
478
  await fileBackend.dispose();
327
479
  return 1;
328
480
  }
481
+ // ── Output: --json → the full TaskResult; else the final assistant text (or salvaged/blocked/error info). ──
329
482
  if (args.json) {
330
483
  print(JSON.stringify(result, null, 2));
331
484
  }
@@ -333,6 +486,7 @@ export async function runLocal(argv, deps = {}) {
333
486
  print(result.result);
334
487
  }
335
488
  else {
489
+ // Non-completed: surface the most useful text we have, then a one-line status footer to stderr.
336
490
  const salvage = result.result || result.salvagedOutput || result.blockedReason || "";
337
491
  if (salvage)
338
492
  print(salvage);
@@ -340,6 +494,9 @@ export async function runLocal(argv, deps = {}) {
340
494
  }
341
495
  if (result.status !== "completed")
342
496
  exitCode = 1;
497
+ // 142-S2.5-W1: 任务结束后 await 一轮同步(推本次 harvest 的新记忆到中心;串行链自动排在 boot 轮
498
+ // 之后,绝不并发互踩)。await 保证轮次在进程退出前完成(fire-and-forget 会被 exit 腰斩);失败只
499
+ // warn——同步是增益面,绝不改变任务本身的退出码。输出已打印完,这里的等待不挡用户看结果。
343
500
  if (memorySync) {
344
501
  try {
345
502
  await memorySync.syncOnce("post-task");
@@ -348,16 +505,23 @@ export async function runLocal(argv, deps = {}) {
348
505
  logger.warn("memory_sync_failed", { reason: "post-task", err: String(err) });
349
506
  }
350
507
  }
508
+ // ── Clean shutdown: dispose the warm sessions; the host env workspace is rm -rf'd by the Runner on task
509
+ // end (executionEnvFactory env → destroy()). No server/pool/reaper to tear down (none were created). ──
351
510
  runner.sessions.dispose();
352
511
  subRunner.sessions.dispose();
353
- void lspManager?.dispose();
512
+ void lspManager?.dispose(); // SAME as the crash path — kill local child-process language servers on the
513
+ // SUCCESS path too. `runLocal` is exported/reusable (tests/embeddings call it directly, no process.exit), so
514
+ // without this a completed LSP-touching run orphans a fresh set of stdio servers; the leak is per-invocation.
354
515
  await fileBackend.dispose();
355
516
  return exitCode;
356
517
  }
518
+ /** Process entrypoint: run, print, exit with the resolved code. */
357
519
  async function main() {
358
520
  const code = await runLocal(process.argv.slice(2));
359
521
  process.exit(code);
360
522
  }
523
+ // Only auto-run when invoked as a script (not when imported by the test). Compare REALPATH-resolved paths
524
+ // so symlinked roots (/tmp→/private/tmp) and the tsx loader's file URL still match the entrypoint argv[1].
361
525
  function isMainModule() {
362
526
  const entry = process.argv[1];
363
527
  if (!entry)