@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,7 +1,27 @@
1
1
  import { hasDestroy } from "@sema-agent/core";
2
+ /** Leak backstop (codex review HIGH): core skips destroy on suspend/review paths and a crash may skip it
3
+ * entirely — the suspendVM wrap covers the common case, this bound covers the rest. Far above any real
4
+ * per-replica concurrency. 修6: at the cap the registry REFUSES the new registration instead of FIFO-evicting
5
+ * the oldest entry — every entry here is live-until-destroy/suspend by construction, so there is no
6
+ * "terminal/stale" liveness verdict to evict on, and silently breaking an EXISTING live task's send face to
7
+ * admit a new one inverts the harm (the old FIFO victim's SendUserFile would report "no sandbox attached"
8
+ * while its env kept executing). The refused task gets a TYPED capacity error at send time instead. */
2
9
  export const TASK_ENV_REGISTRY_MAX = 512;
10
+ /** Replica-local taskId → live ExecutionEnv(s). Registered by the factory wrap, dropped on destroy/suspend.
11
+ *
12
+ * 修5 (concurrent-generation guard): deployments WITHOUT a run-store single-active-session claim can race
13
+ * two legs of one session through the factory concurrently — previously the second registration silently
14
+ * OVERWROTE the first, so leg A's later SendUserFile resolved to leg B's env (wrong-generation read/upload).
15
+ * The registry now keeps EVERY live env per key and `get()` fail-louds on ambiguity: neither leg can silently
16
+ * read the other's sandbox, and the moment one generation is destroyed/suspended the survivor resolves again.
17
+ * (Rejecting the second factory call outright was considered and discarded: a stale never-destroyed entry —
18
+ * crash/no-destroy path — would then brick every future leg of that task, and the factory seam must not fail
19
+ * env creation for a send-face bookkeeping conflict. Deployments WITH the single-active-session claim
20
+ * serialize legs upstream and never see this state.) */
3
21
  export class TaskEnvRegistry {
4
22
  map = new Map();
23
+ /** 修6: taskIds whose registration was refused at the cap — lets get() report the TRUE reason (typed
24
+ * capacity error, not a misleading "no sandbox attached"). Bounded by the same cap (marker-only). */
5
25
  refusedAtCapacity = new Set();
6
26
  liveCount() {
7
27
  let n = 0;
@@ -9,6 +29,9 @@ export class TaskEnvRegistry {
9
29
  n += envs.length;
10
30
  return n;
11
31
  }
32
+ /** Resolve the ONE live env for a task. Throws typed errors on the two governed failure states:
33
+ * ambiguity (修5 — concurrent generations both live) and capacity refusal (修6). Returns undefined when
34
+ * the task simply has no registered env (caller reports "no sandbox attached"). */
12
35
  get(taskId) {
13
36
  if (taskId === undefined)
14
37
  return undefined;
@@ -23,14 +46,26 @@ export class TaskEnvRegistry {
23
46
  }
24
47
  return undefined;
25
48
  }
49
+ /** Wrap the deployment's own factory: register each minted env under the task's CANONICAL id — core hands
50
+ * the factory the raw `spec.taskId` but gives tools `hostTaskId = spec.taskId ?? sessionId` (prepare-task
51
+ * 262/320/428; the sync `/v1/tasks` leg deliberately sets no spec.taskId), so the registry key MUST apply
52
+ * the same fallback or every sync-leg lookup misses (codex review HIGH). Unregister when core calls
53
+ * destroy() (identity guard: only the env's OWN entry is dropped — a replacement env for a reused key must
54
+ * not be evicted by the old one's late destroy). core SKIPS destroy on durable suspend/review (runtask
55
+ * keeps the env for the snapshot) — wrap suspendVM the same way so a suspended task doesn't pin its env
56
+ * here forever; the bounded-size backstop covers any remaining no-destroy crash path. */
26
57
  wrapFactory(factory) {
27
58
  return async (ctx) => {
28
59
  const env = await factory(ctx);
29
60
  const taskId = ctx.taskId ?? ctx.sessionId;
30
61
  if (hasDestroy(env)) {
31
62
  const existing = this.map.get(taskId);
63
+ // 修6: refuse NEW keys at the cap (never evict a live entry — see TASK_ENV_REGISTRY_MAX). A same-key
64
+ // additional registration is always admitted even at the cap: the 修5 ambiguity guard is a correctness
65
+ // fence and must not be dodgeable by arriving while the registry is full.
32
66
  if (existing === undefined && this.liveCount() >= TASK_ENV_REGISTRY_MAX) {
33
67
  if (this.refusedAtCapacity.size >= TASK_ENV_REGISTRY_MAX) {
68
+ // marker set is itself bounded; beyond it the task degrades to the plain "no sandbox attached" report
34
69
  const oldestMarker = this.refusedAtCapacity.values().next().value;
35
70
  if (oldestMarker !== undefined)
36
71
  this.refusedAtCapacity.delete(oldestMarker);
@@ -42,8 +77,10 @@ export class TaskEnvRegistry {
42
77
  clearMarker();
43
78
  return origDestroy();
44
79
  };
45
- return env;
80
+ return env; // env itself is untouched — only the send face is refused (typed error at get())
46
81
  }
82
+ // 修5: append, never overwrite — a live sibling under the same key makes get() fail loud instead of
83
+ // silently handing one leg the other leg's sandbox.
47
84
  if (existing === undefined)
48
85
  this.map.set(taskId, [env]);
49
86
  else
@@ -52,7 +89,7 @@ export class TaskEnvRegistry {
52
89
  const envs = this.map.get(taskId);
53
90
  if (envs === undefined)
54
91
  return;
55
- const i = envs.indexOf(env);
92
+ const i = envs.indexOf(env); // identity guard: drop only THIS env's entry
56
93
  if (i >= 0)
57
94
  envs.splice(i, 1);
58
95
  if (envs.length === 0)
@@ -69,7 +106,7 @@ export class TaskEnvRegistry {
69
106
  suspendable.suspendVM = async (...args) => {
70
107
  const r = await origSuspend(...args);
71
108
  if (r.ok)
72
- evict();
109
+ evict(); // suspended env is dormant — the resume leg registers a fresh one
73
110
  return r;
74
111
  };
75
112
  }
@@ -78,6 +115,22 @@ export class TaskEnvRegistry {
78
115
  };
79
116
  }
80
117
  }
118
+ /**
119
+ * Which REMOTE_EXEC lanes may register the sandbox-send TaskEnvRegistry (and thus mount the sandbox-lane
120
+ * SendUserFile source), under which tenancy gate. The judgment per lane (2026-07-14 ssh backfill review):
121
+ *
122
+ * - e2b / k8s: one task = one disposable sandbox; the sandbox filesystem IS the tenant's task workspace,
123
+ * so a sandbox-scoped read is tenant-scoped by construction → open to any tenant.
124
+ * - ssh: the peer is ONE persistent real machine SHARED across tasks (factory ignores ctx: every task
125
+ * gets the same host+mountPath; destroy=disconnect only, files persist). Tenant A's task can read the
126
+ * residue of tenant B's task → the isolation premise FAILS. Multi-tenant here would be an
127
+ * arbitrary-host-path-read → public-URL exfil face, so the lane opens ONLY single-user
128
+ * (`requirePrincipal !== true`), the exact gate the host lane uses. NOT a lane to "fix later with a
129
+ * per-task workspace": tasks legitimately operate outside any workspace on a real host (design/61 —
130
+ * batch deployment), so per-task dirs would not restore the boundary anyway.
131
+ * - adb / local-docker / host / unset: no registry (host+unset use the local-fs source in main.ts;
132
+ * adb/local-docker remain a follow-on).
133
+ */
81
134
  export function sandboxSendLaneEnabled(provider, requirePrincipal) {
82
135
  if (provider === "e2b" || provider === "k8s")
83
136
  return true;
@@ -85,9 +138,13 @@ export function sandboxSendLaneEnabled(provider, requirePrincipal) {
85
138
  return requirePrincipal !== true;
86
139
  return false;
87
140
  }
141
+ /** Single-quote a path for POSIX sh (the only metacharacter inside '' is ' itself). */
88
142
  export function shq(s) {
89
143
  return `'${s.replace(/'/g, `'\\''`)}'`;
90
144
  }
145
+ /** Strip the capability URL (and any SigV4 signature) from text before it reaches an error/log — including
146
+ * the percent-encoded forms an adapter may echo (the k8s exec transport carries the command in a request
147
+ * URI, so an error can quote the URL re-encoded; codex review MED). */
91
148
  export function redactPutUrl(text, url) {
92
149
  return text
93
150
  .split(url)
@@ -95,25 +152,45 @@ export function redactPutUrl(text, url) {
95
152
  .split(encodeURIComponent(url))
96
153
  .join("<presigned-put-url>")
97
154
  .replace(/X-Amz-Signature(=|%3D)[0-9a-f]+/gi, "X-Amz-Signature=<redacted>")
155
+ // A PARTIAL URL (adapter truncation/line-wrap) can survive the exact-match passes above — the SigV4
156
+ // Credential query param carries the ACCESS KEY ID, scrub it independently (defense in depth).
98
157
  .replace(/X-Amz-Credential(=|%3D)[^&\s"']+/gi, "X-Amz-Credential=<redacted>");
99
158
  }
159
+ /**
160
+ * The sandbox-lane `send` seam for the SendUserFile tool: in-sandbox stat (existence + regular file +
161
+ * size cap, BEFORE any signing) → presign PUT → in-sandbox `curl -T` → finalize the user-facing link.
162
+ * Throws typed Errors (redacted) — the tool reports them per file.
163
+ */
100
164
  export function createSandboxFileSend(deps) {
101
165
  return async (path, ctx) => {
102
166
  const env = deps.registry.get(ctx.taskId);
103
167
  if (!env) {
104
168
  throw new Error("no sandbox is attached to this task yet — SendUserFile reads from the task sandbox; retry after the environment has started");
105
169
  }
170
+ // The path is model-controlled and rides a shell line: shq() covers every POSIX metacharacter, but
171
+ // control chars (NUL truncates argv in some transports; \n splits lines in naive adapters) buy nothing
172
+ // legitimate — reject outright rather than trust each adapter's quoting edge.
106
173
  if (/[\u0000-\u001f\u007f]/.test(path))
107
174
  throw new Error("file path contains control characters — not a valid sandbox path");
108
175
  if (path.length > 4096)
109
176
  throw new Error("file path exceeds 4096 characters — not a valid sandbox path");
177
+ // `curl -T -` means STDIN by convention — a relative path starting with '-' must ride as ./-name so all
178
+ // three sites (test operand / stat / curl) name the same real file.
110
179
  const q = shq(path.startsWith("-") ? `./${path}` : path);
180
+ // stat first: fail before minting any capability URL. `test -f` = regular file only (no dirs/devices);
181
+ // `stat -c %s` = GNU/busybox size (sandbox images are Linux; the ssh lane assumes a LINUX peer — the
182
+ // whole fleet is — a macOS peer would exit non-zero here and fail loud, see the module header).
183
+ // ExecutionEnv.exec timeout is SECONDS (e2b, k8s AND ssh adapters all multiply by 1000 — codex
184
+ // review MED caught ms here; ssh reading = remote-env-ssh.ts `options.timeout * 1000`).
111
185
  const stat = await env.exec(`test -f ${q} && stat -c %s -- ${q}`, { timeout: 30 });
112
186
  if (!stat.ok)
113
187
  throw new Error(`sandbox stat failed: ${stat.error.message}`);
114
188
  if (stat.value.exitCode !== 0) {
115
189
  throw new Error(`file not found in the sandbox (or not a regular file): ${path} — ls first; absolute paths are safest`);
116
190
  }
191
+ // Advisory pre-check only (the authoritative size accounting is server-side verifySize below — the
192
+ // sandbox owns its filesystem, so nothing it reports is binding): still worth failing early and cheap.
193
+ // Strict digit match, not bare parseInt — a digit-prefixed garbled line must fail loud, not truncate.
117
194
  const statOut = stat.value.stdout.trim();
118
195
  if (!/^\d+$/.test(statOut))
119
196
  throw new Error(`sandbox stat returned an unparsable size for ${path}: ${statOut}`);
@@ -123,7 +200,15 @@ export function createSandboxFileSend(deps) {
123
200
  }
124
201
  const filename = path.split(/[/\\]/).pop();
125
202
  const prepared = deps.prepare(filename, ctx.principal);
203
+ // Everything from here can echo the capability URL (adapter throws included, not just Result errors —
204
+ // codex review MED) — one redacting fence around the whole upload phase.
126
205
  try {
206
+ // -f: HTTP >= 400 → exit 22 (no silent half-uploads). NO -s: the progress meter on stderr feeds the
207
+ // e2b/k8s adapters' ~120s zero-output liveness watchdog — a silent multi-minute upload would be killed
208
+ // as a hang (the k8s snapshot lane solves this with livenessMs:0; a chatty meter is the seam-free way).
209
+ // The ssh adapter has NO idle-output watchdog on exec() (total-timeout bound only) — the meter is
210
+ // harmless noise there, so one shared command shape serves all three lanes.
211
+ // stderr may echo the URL → the redact fence below covers every throw out of this block.
127
212
  const up = await env.exec(`curl -f -T ${q} ${shq(prepared.putUrl)}`, { timeout: 300 });
128
213
  if (!up.ok)
129
214
  throw new Error(`sandbox upload failed: ${up.error.message}`);
@@ -133,6 +218,9 @@ export function createSandboxFileSend(deps) {
133
218
  throw new Error("sandbox upload failed: curl is not available in this sandbox image");
134
219
  throw new Error(`sandbox upload failed (curl exit ${up.value.exitCode})${detail.length > 0 ? `: ${detail}` : ""}`);
135
220
  }
221
+ // Server-side accounting is authoritative (codex review HIGH: stat→curl is an exploitable TOCTOU —
222
+ // swap/grow the file between the two and the cap is bypassed with a stale size on the card): HEAD the
223
+ // real object; over-cap ⇒ deleted inside verifySize; the card carries the verified size.
136
224
  const verifiedSize = await prepared.verifySize(deps.maxBytes);
137
225
  return prepared.finalize(verifiedSize);
138
226
  }
@@ -3,6 +3,12 @@ import type { Metrics } from "../observability/metrics.js";
3
3
  import type { Logger } from "../observability/logger.js";
4
4
  import { GiteaClient } from "./repo-tools.js";
5
5
  import { type LoadedSkill } from "./skills.js";
6
+ /**
7
+ * Scenario routing — a deployment serves many scenarios from one image. Each request's `scenario`
8
+ * selects a pre-wired capability bundle: tools (incl. subagent roster) + a whole-harness prompt +
9
+ * skills. Heavy bits (HTTP clients, skill files) are startup singletons; per task we only bind
10
+ * coordinates and build cheap closures, so there is no per-request "assembly" cost.
11
+ */
6
12
  export interface ScenarioRequest {
7
13
  scenario?: string;
8
14
  repo?: string;
@@ -12,22 +18,37 @@ export interface ScenarioBundle {
12
18
  tools: ToolSpec[];
13
19
  skills: SkillSpec[];
14
20
  promptProvider?: PromptProvider;
21
+ /** [849] 场景解释层定死的终验开关(core TaskSpec.finalVerification):bench 实测产品默认请求与
22
+ * bench 态差距三件之一。只有 `autonomous` 置 true;spec 组装处与 caller 显式声明取 OR(场景只会
23
+ * 多加一轮收官验证,绝不收窄 caller 意图),壳/caller 不感知。 */
15
24
  finalVerification?: true;
16
25
  }
17
26
  export type Scenario = (req: ScenarioRequest, principal?: string) => ScenarioBundle;
18
27
  export interface ScenarioDeps {
19
28
  runner: Runner;
29
+ /** In-memory runner for ephemeral sub-tasks (council lenses/arbiter) — keeps them out of TiDB. */
20
30
  subRunner: Runner;
21
31
  model: string;
22
32
  skills: LoadedSkill[];
23
33
  repoClient?: GiteaClient;
34
+ /** Multi-tenant deployment (REQUIRE_PRINCIPAL). Gates the full-body `WebFetch` tool out of the
35
+ * default roster — core says a multi-tenant deployment MUST allowlist hosts (an injected/malicious tenant model
36
+ * could exfil via an arbitrary public URL; the SSRF floor only blocks internal). Single-user TOC keeps WebFetch. */
24
37
  requirePrincipal?: boolean;
38
+ /** Deployment-injected WebSearch backend (Brave/Tavily/SearXNG via `WEB_SEARCH_PROVIDER`). When set,
39
+ * `assembleCodeTools` mounts the WebSearch tool; absent ⇒ not assembled (core ships no search backend). */
25
40
  webSearch?: WebSearchConfig;
41
+ /** [1900]/[1904] WebFetch 摘要器(core `makeWebFetchSummarizer(brain, summarize 角色模型)` 的产物,
42
+ * main.ts 构造一次注入)。在场 ⇒ 装配实参携 `webFetch.summarize`——带 prompt 的 WebFetch 走 cheap
43
+ * 模型摘要而非整页灌上下文([1870] L1 的 ~660× 放大就是这缝);缺席 ⇒ `webFetch` 键不铸(修前
44
+ * 字节形,core 落「summarization unavailable」诚实兜底)。 */
26
45
  webFetchSummarize?: (content: string, prompt: string, signal?: AbortSignal) => Promise<string>;
27
46
  metrics?: Metrics;
28
47
  logger?: Logger;
48
+ /** OA backend coordinates for the `oa` scenario (read /api/v1, write /api/assets). */
29
49
  oaApiBaseUrl?: string;
30
50
  oaServiceToken?: string;
51
+ /** 可选:`oa` 场景注入"开 Gitea issue"工具(OA AI 请求#5);repo/token/labels 固定,模型只填 title/body。 */
31
52
  oaIssue?: {
32
53
  baseUrl: string;
33
54
  owner: string;
@@ -35,29 +56,113 @@ export interface ScenarioDeps {
35
56
  token: string;
36
57
  defaultLabels?: number[];
37
58
  };
59
+ /**
60
+ * When true, the `default` scenario carries the Sema product identity (see {@link semaIdentityProvider}).
61
+ * Set by the local/TOC deployment (CONFIG_PROVIDER=local / run-local) so the local engine answers "who
62
+ * are you" as Sema instead of the model's hallucinated identity. Business scenarios (oa/team/code-review)
63
+ * keep their own prompts; cloud (CONFIG_PROVIDER≠local) leaves the default scenario neutral unless turned
64
+ * on, so integrators that inject their own persona are unaffected.
65
+ */
38
66
  brandIdentity?: boolean;
67
+ /**
68
+ * core 1.287 `SubagentToolOptions.extraTools` seam wire-through — per-SPAWN dynamic tool injection into the
69
+ * delegated (Agent-tool) child roster. Deployment-injected per-task tools (today: SendUserFile — its instance is
70
+ * execute-time late-bound via ctx.taskId → TaskEnvRegistry, so ONE spec serves every spawn) cannot ride the
71
+ * ASSEMBLY-time static `subagent.tools` pool; this factory is evaluated by core at each spawn and its product is
72
+ * merged into the pool, then goes through core's `resolveToolSubset` whitelist like any other tool (agent-def
73
+ * allowTools/denyTools still govern — no extra gate needed on our side). Absent ⇒ no dynamic injection (children
74
+ * see exactly the static full-body roster, the pre-1.287 behavior).
75
+ */
39
76
  subagentExtraTools?: (ctx: SubagentSpawnContext) => ToolSpec[];
77
+ /**
78
+ * core 1.364 durable background agents(design/151 S1,[1503] 提货单②写半场):后台子代 `a*` 行的
79
+ * durable 执行记录 store。**必须与 `RunnerDeps.backgroundAgentStore` 同实例**(读写双点配对,engine
80
+ * 无法核对——半接=静默死特性,RB-37①)。绝不在这里另起实例。absent ⇒ pre-151 行为(settle 后
81
+ * eager release,读面纯 live)。
82
+ */
40
83
  backgroundAgentStore?: BackgroundAgentStore;
84
+ /**
85
+ * core 1.382(design/153 二拍B 件1+件2,parked 状态机)[1561] 提货单①②:「同车必接」的一对——core
86
+ * `parkEligible` 门要求 checkpointStore 与 ensureChildSessionDurable **全在场**才成立,任一缺席 = 净是
87
+ * pre-153 行为(子代 SAFETY ask 照旧 deny+continue,零回归)。
88
+ * - `checkpointStore` 必须与 `RunnerDeps.checkpointStore`(主 runner 的 per-task spec 面)**同实例**
89
+ * ——子代 suspend 在那里铸 token,异实例 = park 全静默失效(core JSDoc 钉过症状,组装区注释同步)。
90
+ * - `ensureChildSessionDurable` = park 提交前的 capability 挂点(core 签名 `(sessionId) => Promise<void>`)
91
+ * ——resolve = 该子代 session 已从任意进程可读,reject/缺席 = veto(子代按 pre-153 settle failed,
92
+ * checkpoint 被 expire)。**本车保守实现**:只在子代 session 已经真正路由到宿主 durable 会话店
93
+ * **且真有内容**(`getLeafId() !== null`——排除 F-7 同族的空壳 claim-create 行,那种行 acquire
94
+ * 命中但零内容,是`register()`对任意自报 sessionId 的副作用,不是真正 durable 的会话)时 resolve
95
+ * (=fork 续聊的常见形),其余一律 reject——不做「主动迁移私店会话进 durable 店」这一步
96
+ * (ForkRoutingSessionStore 的路由表是私有状态,无迁移 API;主动迁移是更大的活,candidate 留给
97
+ * 后续按需再做)。
98
+ */
41
99
  checkpointStore?: CheckpointStore;
42
100
  ensureChildSessionDurable?: (sessionId: string) => Promise<void>;
43
101
  }
102
+ /**
103
+ * Sema product identity, prepended to the core default base for the `default` scenario when
104
+ * {@link ScenarioDeps.brandIdentity} is on. Honest about the substrate (the engine runs whichever model
105
+ * the operator configured — not Claude/Anthropic), so the agent never inherits the model's training-time
106
+ * "I am Claude" hallucination.
107
+ *
108
+ * Live-caught incident (a Qwen3.5 deployment self-described as "running on a DeepSeek model"):
109
+ * NOTHING substrate-specific may be hardcoded here — onboard is multi-provider (Qwen/GLM/Kimi/self-hosted
110
+ * vLLM…), so a baked maker name makes every non-DeepSeek deployment misstate its own substrate. Same for
111
+ * the gateway protocol (the brain stack serves Anthropic-compatible routes too — routing brain +
112
+ * createAnthropicBrain — so "OpenAI-compatible gateway" would be the same class of lie). Neutral wording
113
+ * (zero core-seam need; interpolating the model id would need a `StablePromptContext.model`
114
+ * seam and reads poorly for ugly preset ids). The anti-"I am Claude" design is kept — only the baked
115
+ * substrate facts are removed.
116
+ */
44
117
  export { SEMA_IDENTITY } from "./prompts/identity.js";
118
+ /**
119
+ * Prompt provider for the branded `default` scenario: SEMA_IDENTITY on top of the ROLE base — the
120
+ * task's own `body.systemPrompt`, or core's {@link DEFAULT_SYSTEM_PROMPT} when none. Core 1.243
121
+ * (提示词主权批) appends the constitution structurally AFTER this role layer (harness
122
+ * safety blocks + modes + memory guidance + the prefix-cache-safe `<user_memory>` tail), so identity
123
+ * cannot displace the safety blocks. The pre-1.243 form (identity + `defaultPromptProvider.stableSystem`,
124
+ * i.e. an ALREADY-assembled prompt) would now trip the migration guard (anchor-detect → pass-through +
125
+ * `onError(phase:"prompt-constitution")`) — this role-only form is the guard-free contract.
126
+ */
45
127
  export declare function semaIdentityProvider(): PromptProvider;
128
+ /**
129
+ * `code` 场景的提示词提供者([849] 造,[891] clay 裁定改名 autonomous→code):role 基底 = core
130
+ * {@link CODE_SYSTEM_PROMPT}(core 1.298 [891] 改名批正名,旧名 FULL_BODY_SYSTEM_PROMPT=恒等
131
+ * 别名过渡窗;CODE_AGENT persona + AUTONOMY_SELF_AUDIT + ANTI_VERBOSITY +
132
+ * TOOL_PARAM_JSON;[891] 血缘定论 = CC 生产编码提示词的蒸馏去牌版,底本随 CC 版本对表 cc-anchors,
133
+ * 非自研)——与 bench 的请求组装完全同源,引用 core 常量随版本走,绝不复制字符串(tb bench 实测:
134
+ * 产品默认请求与同引擎 bench 态的差距根因就在这三件 persona/自检/终验)。品牌层与
135
+ * {@link semaIdentityProvider} 同构:brandIdentity 开时 SEMA_IDENTITY 叠在 role 基底之上;任务自带
136
+ * systemPrompt 按同一优先序赢过基底(role 合成规则与 default 场景一致)。宪法由 core 1.243 在 role
137
+ * 层之后结构化追加——此处只产 role-only 形态(guard-free 契约,同 semaIdentityProvider 注释)。
138
+ * 无 systemPrompt 且无品牌时原样返回 core 常量(测试以引用比对锁 bench 同源,不做字符串快照)。
139
+ */
46
140
  export declare function codePromptProvider(brand: boolean): PromptProvider;
141
+ /** @deprecated [891] 改名 code——一版过渡期保留旧符号(与场景名 alias 同窗退役)。 */
47
142
  export declare const autonomousPromptProvider: typeof codePromptProvider;
48
143
  export declare function buildScenarios(deps: ScenarioDeps): Record<string, Scenario>;
144
+ /** Resolve the scenario for a request (falls back to `default`). */
49
145
  export declare function selectScenario(scenarios: Record<string, Scenario>, name: string | undefined): Scenario;
146
+ /** web 渲染契约(定稿形状;knobs 现在没有=整字段省略)。 */
50
147
  export interface ScenarioDetail {
51
148
  name: string;
149
+ /** selectScenario 实际用哪份定义(center 同名 shadow 时="center")——与 centerScenarios overlay 同判定源。 */
52
150
  source: "builtin" | "center";
151
+ /** 是否存在同名内建定义(被 shadow 时仍 true,web 画锁徽章+shadow 标注)。 */
53
152
  builtin: boolean;
54
153
  summary: string;
55
154
  toolset: string;
56
155
  tools: string[];
156
+ /** 内建=概览(不外泄提示词资产全文);center 条目=prompt 原文(本就 ≤4KB 明文在配置域)。 */
57
157
  promptSummary: string;
58
158
  enabled: boolean;
59
159
  }
160
+ /** 内建六场景详情。default/autonomous/team 工厂对良性请求无副作用可真调(拿真实工具名单);code-review/scan/oa 是
161
+ * fail-loud 语义(缺 GIT_API/OA 配置/principal 即 throw)→ 探针失败落静态表兜底(表↔工厂一致性由测试锁:
162
+ * 测试喂 fake deps 真调工厂对账工具名)。enabled 对内建恒 true(约定②)。 */
60
163
  export declare function builtinScenarioDetails(scenarios: Record<string, Scenario>, deps: Pick<ScenarioDeps, "brandIdentity">): Record<string, ScenarioDetail>;
164
+ /** center 条目详情(有效性判定与 centerScenarios 完全同款:无效条目既不进 overlay 也不进详情——
165
+ * 保证约定①「详情显示的来源=运行实际用的定义」永不错位)。 */
61
166
  export declare function centerScenarioDetails(specs: CenterScenarioSpec[] | undefined, builtinNames: string[]): Record<string, ScenarioDetail>;
62
167
  export interface CenterScenarioSpec {
63
168
  name: string;
@@ -66,14 +171,39 @@ export interface CenterScenarioSpec {
66
171
  enabled?: boolean;
67
172
  }
68
173
  export declare const SCENARIO_NAME_RE: RegExp;
174
+ /**
175
+ * Build the center-declared scenario overlay. Invalid specs are SKIPPED with a warning (never fail
176
+ * boot — same posture as skills/teams); valid ones become scenarios keyed by name, ready to be merged
177
+ * OVER the built-ins (center wins). Returns the overlay plus which built-in names it shadows.
178
+ */
69
179
  export declare function centerScenarios(deps: ScenarioDeps, specs: CenterScenarioSpec[] | undefined, builtinNames: string[], logger?: Logger): {
70
180
  overlay: Record<string, Scenario>;
71
181
  shadows: string[];
72
182
  };
183
+ /**
184
+ * Personalization seam: merge the caller's own skills AFTER the scenario's, with
185
+ * SCENARIO-WINS on a name clash — the security baseline (scenario/center skills) can never be shadowed
186
+ * by user content. Duplicate names within the user list keep the first. Clashes are logged for audit
187
+ * (silent drops would make "my skill didn't fire" undebuggable). Input is already shape/size-validated
188
+ * by the HTTP layer (validateUserSkills); this stays pure merge policy.
189
+ */
73
190
  export declare function mergeUserSkills(scenarioSkills: SkillSpec[] | undefined, userSkills: SkillSpec[] | undefined, logger?: Logger): SkillSpec[] | undefined;
191
+ /** center caps view 的解析结果两键(形状钉死)。`scenario` null = 三层皆未配。 */
74
192
  export interface ScenarioRuling {
75
193
  scenario: string | null;
194
+ /** 纯场景名集合(principal/组名不上 wire);空 = 该 principal 无任何指派 = 无治理。 */
76
195
  allowlist: string[];
77
196
  }
197
+ /**
198
+ * resolveSpec 的执法入口(指派为默认、body.scenario 可换但限 allowlist)。返回本请求的
199
+ * 生效场景名(未做 unknown→default 回退——那是 resolveSpec 既有职责,保持单点)。
200
+ *
201
+ * - body.scenario 显式给出:allowlist 非空且集外 ⇒ typed 拒绝(400 `scenario_not_allowed`,附 allowlist
202
+ * ——机器码归 wire、人话归壳/web);集内 ⇒ 用户主动切换赢。allowlist 为空(无 ruling / 该 principal
203
+ * 三层皆无指派 / caps 面故障)⇒ 无治理约束,现状放行(与「null 落兜底链」同一语义:分配面未覆盖 =
204
+ * 不收紧,恒不比没有治理时更宽;caps 故障不把用户锁死在 default——场景切换不是权限放大面,fail-open
205
+ * 到现状,与 workflows 面的 fail-closed 是刻意的 posture 差异,见 runtime-caps-resolver)。
206
+ * - body.scenario 未给:ruling 胜者 ⇒ 指派为默认;无胜者 ⇒ defaultScenario 现状链。
207
+ */
78
208
  export declare function gateScenarioRequest(ruling: ScenarioRuling | undefined, bodyScenario: unknown, defaultScenario: string): string;
79
209
  //# sourceMappingURL=scenarios.d.ts.map