@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
@@ -1,9 +1,47 @@
1
1
  import { untrustedEgressForHuman } from "@sema-agent/core";
2
+ /**
3
+ * SVC-5 (design/97 CORE-5 #6) — the SERVICE-side transport + redaction trust-gate for
4
+ * STEERING a still-running workflow agent (`ctx.agentStream`). Two concerns live here so the steer-in path
5
+ * cannot reopen the hole in scattered places:
6
+ * 1. A process-local REGISTRY of the live {@link WorkflowAgentHandle}s on THIS replica — the only steerable
7
+ * surface (`handle.steer` is an in-memory bridge to the running `TaskStream`, replica-local like
8
+ * `steerableRuns` / `preemptableRuns`). Keyed by `runId label` (a label is unique within a run —
9
+ * core mints `agent-N` when the caller omits one, so the pair addresses exactly one running agent).
10
+ * 2. The steer-in REDACTION gate ({@link redactSteerIn}) — a human's / leader's steer content is UNTRUSTED
11
+ * EVEN THOUGH it carries operator authority on the wire: it must not smuggle host internals to the worker
12
+ * (a leaked baseUrl/token/path in a copy-pasted steer) nor pose as authority to it. We apply core's
13
+ * `untrustedEgressForHuman` (redact host leaks + size-bound + fence) BEFORE the content reaches
14
+ * `handle.steer`, which fences AGAIN inside its trusted marker framing — defense in depth, two independent
15
+ * owners of the boundary.
16
+ *
17
+ * 🔴 HANDLE-VISIBILITY SEAM (the SVC-5 design blocker, reported to clay/core). Core returns a
18
+ * {@link WorkflowAgentHandle} ONLY from `WorkflowRunContext.agentStream`, and — by a deliberate security
19
+ * invariant (workflow-script-runner.d.ts) — the host `WorkflowRunContext` STRUCTURALLY
20
+ * never enters the script runner: the LLM-authored workflow runs against the flat, sterile
21
+ * `WorkflowPrimitives` record, which carries `agent` but NOT `agentStream`. The service launches workflows
22
+ * EXCLUSIVELY through core's `run_workflow` tool → `WorkflowScriptRunner` → `WorkflowPrimitives`, so no code in
23
+ * the service process ever holds a handle to register. This module is therefore the COMPLETE, REAL transport
24
+ * (registry + redaction + auth contract) the service WOULD register into the instant core exposes the handle to
25
+ * the deployment — e.g. a `RunWorkflowToolDeps.onAgentStream(handle)` lifecycle callback, or a steerable-handle
26
+ * sink on the run_workflow tool. Until then the HTTP route correctly returns `steering.not_running` (the
27
+ * registry is genuinely empty — an honest seam, never a silent drop or a fake-live). It is NOT a stopgap: the
28
+ * registry/redaction/auth are production-real and what the populated path uses unchanged.
29
+ */
30
+ /** The composite key NUL-joining `runId` + `label` (a label is unique within a workflow run). NUL can't appear
31
+ * in either part, so the join is unambiguous. */
2
32
  function handleKey(runId, label) {
3
33
  return `${runId}\u0000${label}`;
4
34
  }
35
+ /** A process-local registry of the steerable workflow-agent handles live on THIS replica. Mirrors the
36
+ * `steerableRuns` / `preemptableRuns` pattern (a live in-memory handle is replica-local — a cross-replica steer
37
+ * is a structured 409, never a silent drop). Stores a LIST per (runId,label): core does not enforce label
38
+ * uniqueness, so a duplicate-label collision must NOT silently last-writer-wins (that would steer the WRONG
39
+ * agent + strand the sibling) — {@link resolve} reports the count so the route can 409-on-ambiguous instead. */
5
40
  export class WorkflowAgentRegistry {
6
41
  handles = new Map();
42
+ /** Register a handle when its `agentStream` starts on this replica. Returns an unregister thunk to call when
43
+ * the agent settles (keeps the map from leaking). APPENDS (does not overwrite) so a duplicate-label sibling is
44
+ * also tracked → {@link resolve} sees count>1 and the route refuses rather than steering an arbitrary one. */
7
45
  register(handle) {
8
46
  const key = handleKey(handle.runId, handle.label);
9
47
  const list = this.handles.get(key);
@@ -15,18 +53,22 @@ export class WorkflowAgentRegistry {
15
53
  const cur = this.handles.get(key);
16
54
  if (!cur)
17
55
  return;
18
- const i = cur.indexOf(handle);
56
+ const i = cur.indexOf(handle); // remove THIS handle only — a sibling's unregister must not evict it
19
57
  if (i >= 0)
20
58
  cur.splice(i, 1);
21
59
  if (cur.length === 0)
22
60
  this.handles.delete(key);
23
61
  };
24
62
  }
63
+ /** Resolve `runId`+`label` to its UNIQUE live handle on this replica. count=0 → not here (terminal /
64
+ * cross-replica); count=1 → `handle` set; count>1 → ambiguous (`handle` undefined → the route 409s rather
65
+ * than steering an arbitrary one of the colliding same-label agents). */
25
66
  resolve(runId, label) {
26
67
  const list = this.handles.get(handleKey(runId, label));
27
68
  const count = list ? list.length : 0;
28
69
  return count === 1 ? { handle: list[0], count } : { count };
29
70
  }
71
+ /** Total live handles (test/observability). */
30
72
  get size() {
31
73
  let n = 0;
32
74
  for (const list of this.handles.values())
@@ -34,8 +76,45 @@ export class WorkflowAgentRegistry {
34
76
  return n;
35
77
  }
36
78
  }
79
+ /** Max steer-in length fed to a worker (chars). A steer is a short redirection, not a payload; core's
80
+ * `untrustedEgressForHuman` bounds + truncates beyond this.
81
+ *
82
+ * ⚠️ 纠正(2026-07-26,core 1.414 + 亲测):这里原本写的是「truncates with an **honest marker**」,现在只有
83
+ * 一半成立 —— 实测(`test/svc5-steer-live.test.ts` 里已钉):
84
+ * · **「被截断过」仍有信号**:超界时正文段尾出现 `…`(未超界时不出现)⇒ 消费方能判断"这不是全文";
85
+ * · **「截了多少」不再披露**:`[+N chars]` 在**所有**档位都没有了(实测 +1 / +10 / +100 / +5000 / +50000
86
+ * 全部无披露,输出长度恒 4103)。所以一个超出 5 万字符的输入与只超 1 个字符的输入,**外观完全相同**。
87
+ * ⚠️ core [1707]⑤ 的措辞是「**刚过界**的输入现在是裸 `…` 结尾」,而实测是**全档位**都没有披露 —— 范围比
88
+ * 它描述的宽。已带实测数据上黑板问 core 这是否是有意的(可能只是描述省略,也可能是它没注意到)。
89
+ * 在得到答复前**不改行为**:core 的截断器是它那侧的安全件,server 不该自己在外面补一层"+N chars"去顶
90
+ * ——那会变成两处各说一套。 */
37
91
  export const STEER_IN_MAX_CHARS = 4_000;
92
+ /**
93
+ * **入参**上限(与 {@link STEER_IN_MAX_CHARS} 是两件事:那个限的是**输出**,这个限的是**请求带进来的**)。
94
+ *
95
+ * ── 为什么需要它 ───────────────────────────────────────────────────────────────────────────────
96
+ * 脱敏门是**同步**函数,烧的是**事件循环** ⇒ 一次大 steer 卡住的是**整个副本**,不只是那个请求。
97
+ * 此前这里没有上限:`body.content` 只校验类型与非空,而 JSON 请求体上限是 8 MiB。
98
+ *
99
+ * ── 数是怎么定的(实测,不是拍的)────────────────────────────────────────────────────────────────
100
+ * core 1.421.0 起该函数对输入是**线性**的(此前对「最长不间断词字符段」二次,已修)。
101
+ * 本机实测最坏形状(纯词字符段):64 KiB ≈ 17ms ⇒ **256 KiB ≈ 68ms**、8 MiB ≈ 2.2s。
102
+ * ⇒ 取 **256 KiB**:最坏一拍 ~70ms(可接受的事件循环占用),而它是输出上限的 **64 倍** ——
103
+ * 任何正当的粘贴都装得下,而超出部分**本来就会被丢弃**(只保留 4000 字符 + 一个"丢了多少"的披露)。
104
+ *
105
+ * ── 为什么是**拒**而不是**服务端先截** ──────────────────────────────────────────────────────────
106
+ * 先截会让 core 的 `[+N chars]` 披露**低报**(N 会变成相对截断后输入的),
107
+ * 而"诚实标记不得低报"是本仓另一条钉守着的性质。**为一个已经不紧迫的成本去改一条正确性性质,不划算。**
108
+ * ⇒ 拒 + 在错误里说清上限,调用方自己决定发什么。
109
+ */
38
110
  export const STEER_IN_MAX_REQUEST_CHARS = 256 * 1024;
111
+ /**
112
+ * The steer-in REDACTION gate (SVC-5 信任门). Treat the human/leader steer content as UNTRUSTED before it
113
+ * reaches the worker: redact host-internal leaks (URLs / tokens / named secrets / absolute paths), size-bound,
114
+ * and FENCE it so it can't pose as authority / forge a `</system-reminder>`. `label` tags the fenced block for
115
+ * the worker's reader. This is the service's half of the depth — `handle.steer` fences again inside its trusted
116
+ * marker framing.
117
+ */
39
118
  export function redactSteerIn(content, label) {
40
119
  return untrustedEgressForHuman(content, { label, max: STEER_IN_MAX_CHARS });
41
120
  }
@@ -1,59 +1,173 @@
1
+ /** One pending completion, scoped to the session that must be told about it. `summary` is ALREADY
2
+ * redacted + length-bounded by core's notifier seam (see {@link WorkflowCompletionPayload}). */
1
3
  export interface WorkflowCompletionInboxEntry {
2
4
  sessionId: string;
5
+ /** The originating run's owner (verified principal), or null in the single-user turnkey posture. Gates
6
+ * emission at drain time (defence-in-depth over the sessionId→owner binding a delete/reclaim can rotate). */
3
7
  owner: string | null;
4
8
  runId: string;
5
9
  status: "completed" | "failed";
6
10
  summary: string;
7
11
  enqueuedAt: number;
12
+ /** The frame family this entry drains as. Absent (every pre-1.109 row) = the original
13
+ * `workflow_complete`. `task_notification` = a background subagent/bash completion observed while the
14
+ * originating leg was IDLE (core's in-process injection had no harness to steer — the durable half
15
+ * is the deployment's job). `runId` then holds the core task_id (disjoint id spaces). */
8
16
  kind?: "workflow_complete" | "task_notification";
17
+ /** The task_notification extras (JSON: {task_type, toolUseId?, result?, output_file?}) — bounded +
18
+ * redacted AT ENQUEUE (the store carries only egress-safe bytes). Absent on workflow_complete entries. */
9
19
  payload?: string;
10
20
  }
21
+ /** Session-keyed queue of finished-workflow completions awaiting a push to the originating session.
22
+ * Two-phase delivery (1.80, closes the 1.77-review "drained-but-append-failed" at-most-once window): `pending`
23
+ * READS without removing; the consumer removes each entry via `ack` only AFTER its frame durably landed (or it
24
+ * decided a deliberate drop, e.g. an owner mismatch). A crash/failed write between pending and ack re-delivers
25
+ * on the next leg (at-least-once; the shell dedups by runId). Two legs racing the same session may double-emit —
26
+ * same at-least-once contract, same dedup. */
11
27
  export interface WorkflowCompletionInbox {
28
+ /** Record a completion for `entry.sessionId`. Idempotent on `runId` within a session (a re-delivered
29
+ * at-least-once notify replaces, never duplicates). Dropped (with a warn) when the session was PURGED within
30
+ * the fence window — a late completion racing a session delete must not resurrect as a live ledger entry
31
+ * (1.78-review purge-vs-enqueue hygiene). */
12
32
  enqueue(entry: WorkflowCompletionInboxEntry): Promise<void>;
33
+ /** READ every pending completion for `sessionId` (oldest-first) WITHOUT removing — phase 1 of delivery. */
13
34
  pending(sessionId: string): Promise<WorkflowCompletionInboxEntry[]>;
35
+ /** Remove ONE delivered (or deliberately dropped) completion — phase 2. Idempotent on an unknown runId. */
14
36
  ack(sessionId: string, runId: string): Promise<void>;
37
+ /** Drop every pending completion for `sessionId` without emitting (called on session delete) + arm the
38
+ * enqueue fence for {@link PURGE_FENCE_MS}. `purgedOwner` (the deleted session's owner) scopes the fence:
39
+ * a completion enqueued for a DIFFERENT owner — a new tenant who legitimately re-claimed the sessionId
40
+ * within the window (sessionIds are caller-chosen; reuse is a supported flow) — is NOT fenced (review:
41
+ * the ownerless fence silently starved the new claimant's push). Omitted `purgedOwner` = conservative
42
+ * fence-all (an ownerless caller can't distinguish). */
15
43
  purge(sessionId: string, purgedOwner?: string | null): Promise<void>;
44
+ /** The originating session OBSERVED this run's terminal state through a model-facing poll
45
+ * (core 1.232 `WorkflowCompletionNotifier.ackServed` fires this), so the push would be
46
+ * a pure duplicate ("poll-then-also-notify" double delivery: the model burns turns dismissing a completion
47
+ * it already summarized). Drops the pending entry (a deliberate ack) AND arms a {@link SERVED_FENCE_MS}
48
+ * enqueue fence for this (session, runId) so a LATE-arriving notify (the notifier races the poll) is
49
+ * dropped too. Fence is in-memory only — a crash between poll and notify re-delivers (at-least-once; the
50
+ * shell's own runId dedup + the model tolerate it), mirroring the purge fence's restart posture. */
16
51
  markTerminalServed(sessionId: string, runId: string): Promise<void>;
17
52
  }
53
+ /** Cap on retained pending completions per session (drop-oldest beyond it). A session with more than this many
54
+ * undelivered workflow completions is pathological; the poll floor still covers the dropped ones. */
18
55
  export declare const MAX_PENDING_PER_SESSION = 100;
56
+ /** Compact the File ledger (rewrite from live state) once this many records have been appended since the last
57
+ * compaction — bounds on-disk size + boot replay cost for a long-lived process with high workflow churn. */
19
58
  export declare const COMPACT_EVERY = 512;
59
+ /** How long after a `purge` an `enqueue` for the same session is refused (the purge-vs-enqueue fence): a
60
+ * workflow completion landing AFTER its session was deleted must not resurrect as a live entry the next
61
+ * claimant of that sessionId would see. In-memory only (a restart forgets the fence — the cross-restart race
62
+ * window is negligible and the drain-side owner gate still stands as the real tenancy boundary). */
20
63
  export declare const PURGE_FENCE_MS: number;
64
+ /** How long after {@link WorkflowCompletionInbox.markTerminalServed} an `enqueue` for the SAME (session,
65
+ * runId) is refused — covers the notify path lagging the model's poll (the notify gate is async +
66
+ * at-least-once, so the completion can land in the inbox AFTER the poll already told the model). Long enough
67
+ * to swallow any realistic notify lag incl. a boot-recovery re-fire racing a fresh poll; per-runId scoped, so
68
+ * it can never starve a DIFFERENT workflow's push. In-memory only (see {@link PURGE_FENCE_MS} rationale). */
21
69
  export declare const SERVED_FENCE_MS: number;
70
+ /** design/144 §4 server 折叠键:`JSON([域, taskId, RAW status])[#seq]`。域=external 帧独立 lane(task_id 是
71
+ * 调用方自由串,不分域可预占内部帧键把真实子代 settle 帧吞掉)/其余内部帧统一 "task" 域。
72
+ *
73
+ * 三路复审修1(MED):status 保留 RAW,不再归一 completed/failed —— 归一让同 id 无 seq 的两条 external
74
+ * 通知(先 `event` 后 `cancelled`)折叠成同一把 `…:failed` 键,inbox map 里第二条 REPLACE 第一条,drain
75
+ * 只吐一条(entry 的存储 status 列仍归一,那是账本的双终态列,不动;RAW status 本就随 payload extras
76
+ * 透传)。这与 {@link taskNotificationStreamKey} 的 RAW 语义对齐(stream 侧早已保 RAW)。
77
+ *
78
+ * 编码=防碰撞元组:域/taskId/status 走 JSON 数组(调用方自由串伪造不了分隔符);`#seq` 尾折在 JSON 之外
79
+ * ——JSON 段恒以 `"]` 结尾,`#digits` 尾无歧义,于是 {@link foldKeyFamily} 的剥尾语义 AND SQL 双生子
80
+ * (tidb/pg-workflow-run-store 的 `regexp_replace(run_id, '#[0-9]+$', '')` 家族比对)原样成立——把 seq 折进
81
+ * JSON 元组会让 SQL 侧家族 ack/fence 永 miss(那是另一批的真库改动面,本修有意不碰)。
82
+ * seq 折入=逐停机周期各自成键(1.283 起 background_agent 四腿 notify 铸 cycleSeq);无 seq=单周期旧键
83
+ * (bash/monitor terminal/retain 降级,诚实语义)。serve-fence 侧必须用同一函数(或其家族前缀)构造,
84
+ * 否则键形漂移=fence 永 miss(server.ts fleet 腿的 `taskNotificationFoldKey({task_id, status})` 无 seq 形
85
+ * 即家族前缀,两侧同为 RAW status,依旧咬合)。 */
22
86
  export declare function taskNotificationFoldKey(n: {
23
87
  task_type?: string;
24
88
  task_id: string;
25
89
  status: string;
26
90
  seq?: number;
27
91
  }): string;
92
+ /** design/144 stream 侧去重键(core [784]④a + codex 1.189 前双审 F2)= `域:taskId:status[#seq]`。
93
+ * 与 {@link taskNotificationFoldKey} 同族,域二分也一致(codex F2 HIGH:external 通知的 task_id 是
94
+ * POST /v1/sessions/:id/notify 调用方自由串——同一条腿上,drain 出的 external 帧可与内部任务帧同形
95
+ * `task_id:status:seq` 撞键互吞,per-leg 键集并不豁免这个面,旧注释「没有跨调用方预占面」判错);
96
+ * 仍与 fold key 有意不同的一点:status 保留 RAW(killed/cancelled/event 不归一 failed)——归一会让同
97
+ * task 的 Monitor event 批与 failed 终态在一条腿上互吞;wire 去重要的是逐帧身份,不是 inbox 的双终态列。
98
+ * `seq` 折入 = 停→唤→停的第二周期同 status 帧各自成键(core 1.283 起 background_agent 四腿 notify 铸
99
+ * cycleSeq;缺 seq 时旧键曾把二周期 completed 帧在 observer 臂反向吞掉——core [784]④a);无 seq 的帧
100
+ * (bash/monitor terminal/retain 降级)保持单周期旧键=同键第二帧吞,诚实语义。task_type 缺席(旧 core
101
+ * 内部帧)归 "task" 域——external 帧的 task_type 三来源齐备(notify 端点 core 铸 / inbox entry extras 存
102
+ * / drain 帧 spread 复原),不会漏域。observer 臂 / stream 臂 / turn-open drain 登记三处必须用本函数
103
+ * 构键且都传 task_type,键形漂移=去重永 miss。 */
28
104
  export declare function taskNotificationStreamKey(n: {
29
105
  task_type?: string;
30
106
  task_id: string;
31
107
  status: string;
32
108
  seq?: number;
33
109
  }): string;
110
+ /** Per-leg notified-key ledger cap (codex 1.189 前双审 F3):一条超长腿(海量互异 bg 通知)不许把键集
111
+ * 撑到无界——超出删最老插入(Map 迭代序=插入序)。远高于任何真实 per-leg 通知量;被逐键的老通知
112
+ * 最坏情形=同键晚到帧多写一次(at-least-once,shell 按键 dedup 兜底),绝不吞新帧。 */
34
113
  export declare const NOTIFIED_KEYS_MAX = 4096;
114
+ /**
115
+ * Per-leg delivered-notification ledger(codex 1.189 前双审 F1 HIGH 的修位)。
116
+ * 键 = {@link taskNotificationStreamKey};值 = 「认领这把键的那次写是否真落盘」的 promise(true=成功)。
117
+ * 为什么是 Map<string, Promise<boolean>> 而不是 Set:bg/resume 腿的 observer 臂是 fire-and-forget append
118
+ * (`void append(...)`)——旧 Set 下 append 失败(SQL blip)时键已被占而盘上无帧,core pend-drain 把同
119
+ * payload 重放到 stream 臂时被键吞 = 通知永丢。现在 stream 臂对已见键 `await` 认领方的真实结果,false 则
120
+ * 照写并把键值升为 true。sync 腿的写是同步 res.write(无异步失败窗口)、drain 臂的写被
121
+ * emitPendingWorkflowCompletions await(失败→不 ack→下腿重投)——两者登记 resolved(true) 即可;三腿统一
122
+ * 用本 Map 形状,让三对臂保持逐行孪生。
123
+ */
35
124
  export declare class NotifiedKeys {
36
125
  private readonly byKey;
126
+ /** The pending/settled outcome of the write that claimed `key`, or undefined when unclaimed. */
37
127
  get(key: string): Promise<boolean> | undefined;
128
+ /** Claim (or update) `key` with the outcome of its write. Bounded: past {@link NOTIFIED_KEYS_MAX} the
129
+ * oldest-inserted key is dropped (F3; an update keeps the original insertion slot — good enough for a
130
+ * pathology cap). */
38
131
  set(key: string, written: Promise<boolean>): void;
39
132
  }
133
+ /** 家族前缀 = 折叠键只剥 `#seq` 分量(仅当尾是纯数字才剥)。新元组键的 JSON 段恒以 `"]` 结尾、taskId/
134
+ * status 里天然的 # 被 JSON 引号包住,`#digits` 尾无歧义=必是 seq;旧格式遗留行(`域:task:status#seq`)
135
+ * 与 workflow_complete 的裸 runId 键同一语义原样兼容。 */
40
136
  export declare function foldKeyFamily(runId: string): string;
137
+ /** In-memory inbox — the parity oracle + the ephemeral opt-out (WORKFLOW_RUN_STORE=memory). No persistence:
138
+ * a restart forgets undelivered completions (the poll floor covers them). */
41
139
  export declare class InMemoryWorkflowCompletionInbox implements WorkflowCompletionInbox {
42
140
  protected readonly onWarn?: ((msg: string, meta: Record<string, unknown>) => void) | undefined;
43
141
  protected readonly bySession: Map<string, Map<string, WorkflowCompletionInboxEntry>>;
142
+ /** sessionId → {at, owner}: purge stamps; enqueues within {@link PURGE_FENCE_MS} for the SAME owner are
143
+ * refused. Swept on BOTH enqueue and purge (a purge-heavy, enqueue-quiet process must not accumulate
144
+ * stamps unboundedly — review). */
44
145
  private readonly purgedAt;
146
+ /** servedKey(sessionId, runId) → stamp: terminal-poll-served fences; an enqueue for the pair within
147
+ * {@link SERVED_FENCE_MS} is refused (the poll already told the model). Swept alongside the purge fence. */
45
148
  private readonly servedAt;
46
149
  constructor(onWarn?: ((msg: string, meta: Record<string, unknown>) => void) | undefined);
47
150
  private sweepFence;
151
+ /** True (and warns) when `entry`'s session was purged within the fence window AND the fence applies to its
152
+ * owner: same owner as the purged session (a late completion of the DELETED session) — or an owner-less
153
+ * fence (caller couldn't say), conservative. A DIFFERENT owner = a new legitimate claimant of a reused
154
+ * sessionId → not fenced (their push must not be starved; the drain-side owner gate stays the real
155
+ * tenancy boundary either way). */
48
156
  protected purgeFenced(entry: WorkflowCompletionInboxEntry): boolean;
157
+ /** Fence FIRST (an enqueue racing the poll is refused even mid-call), then drop any already-pending
158
+ * entry via `ack` — the durable subclass inherits this and gets a durable ack for free. */
49
159
  markTerminalServed(sessionId: string, runId: string): Promise<void>;
50
160
  protected stampPurge(sessionId: string, owner: string | null | undefined): void;
161
+ /** Fold one entry into the map. `warn` is false during ledger replay (a historical overflow must not re-log
162
+ * on every boot) and true on a live enqueue. */
51
163
  protected applyEnqueue(entry: WorkflowCompletionInboxEntry, warn: boolean): void;
52
164
  enqueue(entry: WorkflowCompletionInboxEntry): Promise<void>;
53
165
  pending(sessionId: string): Promise<WorkflowCompletionInboxEntry[]>;
54
166
  ack(sessionId: string, runId: string): Promise<void>;
55
167
  purge(sessionId: string, purgedOwner?: string | null): Promise<void>;
56
168
  }
169
+ /** File-backed crash-safe inbox (the durable default — a background workflow's completion survives a replica
170
+ * restart, the prerequisite for pushing it to a session that reconnects after the crash). */
57
171
  export declare class FileWorkflowCompletionInbox extends InMemoryWorkflowCompletionInbox {
58
172
  private readonly fsyncEnabled;
59
173
  private readonly dir;
@@ -63,20 +177,60 @@ export declare class FileWorkflowCompletionInbox extends InMemoryWorkflowComplet
63
177
  constructor(root: string, onWarn?: (msg: string, meta: Record<string, unknown>) => void, fsyncEnabled?: boolean);
64
178
  private replay;
65
179
  private commit;
180
+ /** Compact iff we've appended enough since the last one. MUST be called AFTER the in-memory mutation the
181
+ * triggering commit records — compact() rewrites from `bySession`, so a compact fired BEFORE the caller
182
+ * applied its enqueue/delete would rewrite a stale snapshot and lose that record. */
66
183
  private maybeCompact;
184
+ /** Rewrite the ledger from the authoritative in-memory state — one `enqueue` record per LIVE pending entry —
185
+ * dropping every accumulated drain-tombstone + evicted/drained line. Atomic (temp + rename) so a crash
186
+ * mid-compact leaves the old ledger intact. */
67
187
  private compact;
68
188
  enqueue(entry: WorkflowCompletionInboxEntry): Promise<void>;
69
189
  ack(sessionId: string, runId: string): Promise<void>;
70
190
  purge(sessionId: string, purgedOwner?: string | null): Promise<void>;
191
+ /** Close the ledger fd (shutdown). */
71
192
  close(): void;
72
193
  }
194
+ /**
195
+ * P1 ①② delivery half, TWO-PHASE since 1.80: read the session's pending completions, emit
196
+ * one `workflow_complete` out-of-band frame per entry, and `ack` (remove) each entry only AFTER its emit
197
+ * SUCCEEDED — a failed frame write (dead socket / durable-append error) leaves the entry pending, so the next
198
+ * leg re-delivers instead of silently eating it (the 1.77-review "drained-but-append-failed" window, closed).
199
+ * Called at STREAM-OPEN of EVERY run leg (the sync `POST /v1/runs` SSE leg emits a live frame; the bg + resume
200
+ * legs append a durable `workflow_complete` event their tailing client replays). Best-effort throughout (the
201
+ * deterministic `WorkflowStatus` poll is the floor); at-least-once — the shell dedups by runId (two legs racing
202
+ * the same session may double-emit; same contract).
203
+ *
204
+ * 🔒 Tenancy (defence-in-depth over the authorizer's sessionId→owner gate): only entries whose stamped
205
+ * `owner` matches `callerPrincipal` are EMITTED — a session deleted-then-reclaimed by a different tenant
206
+ * (which rotates the sessionId→owner binding) can't surface the prior owner's completions. `owner: null`
207
+ * (single-user turnkey) has no tenancy boundary → always emitted. A non-matching entry is a DELIBERATE drop —
208
+ * acked (the session is gone/reclaimed for its original owner; the poll floor is their fallback), so it never
209
+ * wedges the queue.
210
+ */
73
211
  export declare function emitPendingWorkflowCompletions(inbox: WorkflowCompletionInbox | undefined, sessionId: string | undefined, callerPrincipal: string | null, emit: (frame: {
74
212
  type: string;
75
- }) => void | Promise<void>, diag?: {
213
+ }) => void | Promise<void>,
214
+ /** Emit-TARGET diagnostics — WHICH leg drained (route) onto WHAT kind of connection
215
+ * (live SSE write vs durable event-log append), plus the enqueue→emit lag, so a "workflow completed but the
216
+ * shell only saw it on the next manual turn" report can be pinned to the leg that finally carried the frame
217
+ * (the push is stream-open-driven by design — a session with NO open leg has no push path until its next
218
+ * leg; the lag makes that visible instead of a mystery). Info-level, one line per delivered frame. */
219
+ diag?: {
76
220
  route: string;
77
221
  connection: string;
78
222
  log(msg: string, meta?: Record<string, unknown>): void;
79
223
  }): Promise<void>;
224
+ /**
225
+ * The durable half is the deployment's job: map a core `TaskNotificationPayload`
226
+ * (background subagent / background bash completion) onto an inbox entry, for the IDLE gap — core's in-process
227
+ * injection covers a LIVE harness; a completion that lands after the leg ended had NO durable path (idle no-show,
228
+ * lost across restart). Bounded + redacted HERE (the store carries only egress-safe bytes; summary/result are
229
+ * UNTRUSTED free text). `status` collapses onto the inbox's completed|failed column; the ORIGINAL status rides
230
+ * the payload extras and overrides on drain (killed/cancelled reach the shell verbatim). Workflow-type
231
+ * notifications are the CALLER's job to filter (they have their own durable chain — double-enqueueing here would
232
+ * re-open the poll-served double-push).
233
+ */
80
234
  export declare function taskNotificationInboxEntry(sessionId: string, owner: string | null, n: {
81
235
  task_id: string;
82
236
  task_type: string;
@@ -99,8 +253,34 @@ export declare function taskNotificationInboxEntry(sessionId: string, owner: str
99
253
  edits: number;
100
254
  }>;
101
255
  resumable?: boolean;
256
+ /** core 1.353([1412]):诊断槽(journal 坐标+教句,引擎值单源)——park 透传,drain 帧原样带。 */
102
257
  diagnostics?: string;
103
- }, enqueuedAt: number, parentTaskId?: string): WorkflowCompletionInboxEntry;
258
+ }, enqueuedAt: number,
259
+ /** lead-b (dual-ID audit): the PARENT run's durable taskId (the uuid the shell's footer rows
260
+ * key on) — rides the drained frame so a consumer can bind the a*-keyed child notification to its uuid-keyed
261
+ * parent row without a side lookup. */
262
+ parentTaskId?: string): WorkflowCompletionInboxEntry;
263
+ /**
264
+ * Resolve WHERE a workflow completion routes (core 1.208): the SESSION comes straight off
265
+ * `originatingSessionId` (the Runner closes over it at RunWorkflow mount — lookup-free). The OWNER comes from,
266
+ * in order:
267
+ * 1. the originating RUN ROW's owner (`getRun(sourceTaskId)`, 1.75) — immutable, stamped at submit. Only the
268
+ * BG leg has a run-row `sourceTaskId` though: the sync + resume legs deliberately leave `spec.taskId` unset
269
+ * (subagent nesting), so core derives `sourceTaskId = sessionId` and this lookup MISSES for them (review
270
+ * review, 1.78) — which under the old rule silently killed the multi-tenant push for every sync-leg workflow;
271
+ * 2. the payload's `principal` — core threads `spec.principal`, which in THIS service is ALWAYS the VERIFIED
272
+ * identity (the 1.55 F-fix invariant, main.ts: gated door = BFF-verified header, direct door = JWT `sub`,
273
+ * never the spoofable header; core 1.187 hardened the `TaskSpec.principal` contract to exactly this).
274
+ * Captured at SPAWN time → immutable, no delete-then-reclaim window. This is also the same value core's own
275
+ * workflow scope guard (`canAccessWorkflowRun`) keys off;
276
+ * 3. neither → single-user stamps `owner: null` (no tenancy boundary); multi-tenant (`requirePrincipal`)
277
+ * returns undefined = DROP fail-closed (an unverifiable owner must not ride the reclaim gate; the
278
+ * `WorkflowStatus` poll floor covers). Returns undefined when there is no route at all.
279
+ * The `getRun` lookup also carries the session FALLBACK for a crash-RECOVERY notify payload that lacks
280
+ * `originatingSessionId` — since core 1.210 the durable `WorkflowRun` records it and the recovery
281
+ * re-derivation threads it through (workflow-notify-journal), so this fallback covers only pre-1.210 rows
282
+ * (or a writer that omitted it), not the recovery path wholesale.
283
+ */
104
284
  export declare function resolveCompletionRoute(p: {
105
285
  originatingSessionId?: string;
106
286
  sourceTaskId?: string;
@@ -112,6 +292,13 @@ export declare function resolveCompletionRoute(p: {
112
292
  sessionId: string;
113
293
  owner: string | null;
114
294
  } | undefined>;
295
+ /**
296
+ * core 1.232 — resolve WHICH session's inbox entry a poll-served ack targets: the payload's
297
+ * `originatingSessionId` directly (core threads it on `ackServed`), else the originating run row via
298
+ * `sourceTaskId` (mirrors {@link resolveCompletionRoute}'s session half — same fallback, same reason:
299
+ * older runs may predate the lookup-free field). Returns undefined when there is no attribution — the
300
+ * entry stays pending (at-least-once; the shell's own dedup covers a rare duplicate).
301
+ */
115
302
  export declare function resolveServedSession(p: {
116
303
  originatingSessionId?: string;
117
304
  sourceTaskId?: string;