@sema-agent/server 1.322.0 → 2.0.0

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 (539) 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-reclaim.d.ts +19 -0
  46. package/dist/boot-reclaim.js +20 -0
  47. package/dist/brain.d.ts +25 -0
  48. package/dist/brain.js +61 -1
  49. package/dist/budget.d.ts +66 -0
  50. package/dist/budget.js +128 -4
  51. package/dist/capabilities/builtin-tools.d.ts +3 -0
  52. package/dist/capabilities/builtin-tools.js +3 -0
  53. package/dist/capabilities/center-plugins.d.ts +17 -1
  54. package/dist/capabilities/center-plugins.js +45 -4
  55. package/dist/capabilities/center-prompts.d.ts +46 -0
  56. package/dist/capabilities/center-prompts.js +57 -3
  57. package/dist/capabilities/code-review-council.d.ts +28 -0
  58. package/dist/capabilities/code-review-council.js +40 -7
  59. package/dist/capabilities/collab-wire.d.ts +2 -0
  60. package/dist/capabilities/collab-workflows.d.ts +7 -0
  61. package/dist/capabilities/collab-workflows.js +44 -1
  62. package/dist/capabilities/oa-tools.d.ts +6 -0
  63. package/dist/capabilities/oa-tools.js +10 -0
  64. package/dist/capabilities/prompt.d.ts +14 -0
  65. package/dist/capabilities/prompt.js +14 -0
  66. package/dist/capabilities/prompts/code-review.d.ts +14 -0
  67. package/dist/capabilities/prompts/code-review.js +14 -0
  68. package/dist/capabilities/prompts/identity.d.ts +6 -0
  69. package/dist/capabilities/prompts/identity.js +6 -0
  70. package/dist/capabilities/prompts/team.d.ts +4 -0
  71. package/dist/capabilities/prompts/team.js +4 -0
  72. package/dist/capabilities/repo-tools.d.ts +11 -0
  73. package/dist/capabilities/repo-tools.js +8 -0
  74. package/dist/capabilities/sandbox-file-send.d.ts +95 -0
  75. package/dist/capabilities/sandbox-file-send.js +91 -3
  76. package/dist/capabilities/scenarios.d.ts +130 -0
  77. package/dist/capabilities/scenarios.js +180 -7
  78. package/dist/capabilities/select-environment-tool.d.ts +7 -0
  79. package/dist/capabilities/select-environment-tool.js +30 -0
  80. package/dist/capabilities/send-user-file-tool.d.ts +33 -0
  81. package/dist/capabilities/send-user-file-tool.js +65 -1
  82. package/dist/capabilities/skills.d.ts +29 -0
  83. package/dist/capabilities/skills.js +13 -2
  84. package/dist/capabilities/team.d.ts +22 -0
  85. package/dist/capabilities/team.js +22 -2
  86. package/dist/capabilities/tool-defer.d.ts +26 -0
  87. package/dist/capabilities/tool-defer.js +3 -0
  88. package/dist/config-center/apply-effective.d.ts +65 -0
  89. package/dist/config-center/apply-effective.js +204 -12
  90. package/dist/config-center/http-client.d.ts +34 -0
  91. package/dist/config-center/http-client.js +68 -0
  92. package/dist/config-center/restart-signal.d.ts +22 -0
  93. package/dist/config-center/restart-signal.js +39 -0
  94. package/dist/config-center/skills-mcp.d.ts +20 -1
  95. package/dist/config-center/skills-mcp.js +42 -7
  96. package/dist/config-center/types.d.ts +92 -1
  97. package/dist/config-lkg.d.ts +12 -0
  98. package/dist/config-lkg.js +41 -0
  99. package/dist/config-provider.d.ts +78 -0
  100. package/dist/config-provider.js +165 -2
  101. package/dist/config-types.d.ts +546 -0
  102. package/dist/config.d.ts +64 -0
  103. package/dist/config.js +455 -60
  104. package/dist/degenerate-instrument.d.ts +38 -0
  105. package/dist/degenerate-instrument.js +55 -3
  106. package/dist/elicitation.d.ts +39 -0
  107. package/dist/elicitation.js +87 -3
  108. package/dist/env-facts.d.ts +61 -0
  109. package/dist/env-facts.js +73 -7
  110. package/dist/fleet/fleet-bus.d.ts +185 -0
  111. package/dist/fleet/fleet-bus.js +333 -27
  112. package/dist/fleet/subagent-tail-bus.d.ts +11 -0
  113. package/dist/fleet/subagent-tail-bus.js +33 -2
  114. package/dist/fleet-client.d.ts +38 -0
  115. package/dist/fleet-client.js +44 -9
  116. package/dist/fleet-lease.d.ts +46 -0
  117. package/dist/fleet-lease.js +73 -5
  118. package/dist/hooks/branch-transcript.d.ts +8 -0
  119. package/dist/hooks/branch-transcript.js +33 -0
  120. package/dist/hooks/cc-stop-prompt.d.ts +42 -0
  121. package/dist/hooks/cc-stop-prompt.js +43 -1
  122. package/dist/hooks/hook-llm.d.ts +15 -0
  123. package/dist/hooks/hook-llm.js +47 -0
  124. package/dist/hooks/hook-runner.d.ts +89 -0
  125. package/dist/hooks/hook-runner.js +327 -18
  126. package/dist/http/idempotency.d.ts +31 -0
  127. package/dist/http/idempotency.js +34 -0
  128. package/dist/http/principal-gate.d.ts +17 -0
  129. package/dist/http/principal-gate.js +35 -3
  130. package/dist/http/route-ctx.d.ts +36 -0
  131. package/dist/http/routes/approvals-assistant.d.ts +25 -0
  132. package/dist/http/routes/approvals-assistant.js +253 -23
  133. package/dist/http/routes/attachments.js +22 -4
  134. package/dist/http/routes/capabilities.d.ts +7 -0
  135. package/dist/http/routes/capabilities.js +202 -1
  136. package/dist/http/routes/fleet.d.ts +6 -0
  137. package/dist/http/routes/fleet.js +94 -5
  138. package/dist/http/routes/images.d.ts +17 -0
  139. package/dist/http/routes/images.js +222 -14
  140. package/dist/http/routes/leader.d.ts +7 -0
  141. package/dist/http/routes/leader.js +10 -0
  142. package/dist/http/routes/memory-policy.d.ts +6 -0
  143. package/dist/http/routes/memory-policy.js +38 -6
  144. package/dist/http/routes/notify-wake.d.ts +10 -0
  145. package/dist/http/routes/notify-wake.js +19 -3
  146. package/dist/http/routes/observability.d.ts +6 -0
  147. package/dist/http/routes/observability.js +19 -2
  148. package/dist/http/routes/runs.d.ts +15 -0
  149. package/dist/http/routes/runs.js +464 -41
  150. package/dist/http/routes/session-sync.d.ts +15 -0
  151. package/dist/http/routes/session-sync.js +229 -19
  152. package/dist/http/routes/sessions-list.d.ts +6 -0
  153. package/dist/http/routes/sessions-list.js +35 -4
  154. package/dist/http/routes/sessions.d.ts +14 -0
  155. package/dist/http/routes/sessions.js +176 -31
  156. package/dist/http/routes/side-query.d.ts +8 -0
  157. package/dist/http/routes/side-query.js +26 -1
  158. package/dist/http/routes/tasks.d.ts +18 -0
  159. package/dist/http/routes/tasks.js +501 -38
  160. package/dist/http/routes/trace-usage.d.ts +10 -0
  161. package/dist/http/routes/trace-usage.js +66 -14
  162. package/dist/http/routes/workflows.d.ts +12 -0
  163. package/dist/http/routes/workflows.js +180 -19
  164. package/dist/http/run-meta.d.ts +11 -0
  165. package/dist/http/run-meta.js +6 -0
  166. package/dist/http/send.d.ts +19 -0
  167. package/dist/http/send.js +11 -0
  168. package/dist/http/server.d.ts +255 -0
  169. package/dist/http/server.js +921 -75
  170. package/dist/http/sse-log.d.ts +15 -0
  171. package/dist/http/sse-log.js +16 -0
  172. package/dist/http/tar.d.ts +9 -0
  173. package/dist/http/tar.js +21 -5
  174. package/dist/http/wire-gate.d.ts +9 -0
  175. package/dist/http/wire-gate.js +9 -0
  176. package/dist/http/wire-types.d.ts +187 -0
  177. package/dist/http/workspace-content.d.ts +8 -0
  178. package/dist/http/workspace-content.js +10 -0
  179. package/dist/images/bake-validate.d.ts +63 -0
  180. package/dist/images/bake-validate.js +71 -1
  181. package/dist/images/manifest.d.ts +19 -0
  182. package/dist/images/manifest.js +6 -1
  183. package/dist/index.d.ts +1 -5
  184. package/dist/index.js +10 -5
  185. package/dist/key-resolver.d.ts +23 -0
  186. package/dist/key-resolver.js +27 -2
  187. package/dist/leader/diffout.d.ts +23 -0
  188. package/dist/leader/diffout.js +8 -1
  189. package/dist/leader/diffup.d.ts +32 -0
  190. package/dist/leader/diffup.js +43 -0
  191. package/dist/leader/endpoint.d.ts +20 -0
  192. package/dist/leader/endpoint.js +25 -2
  193. package/dist/leader/fanout.d.ts +60 -0
  194. package/dist/leader/fanout.js +29 -3
  195. package/dist/leader/grader-env-factory.d.ts +74 -0
  196. package/dist/leader/grader-env-factory.js +62 -3
  197. package/dist/leader/leader.d.ts +97 -0
  198. package/dist/leader/leader.js +151 -4
  199. package/dist/leader/merge.d.ts +94 -0
  200. package/dist/leader/merge.js +112 -9
  201. package/dist/leader/planner.d.ts +52 -0
  202. package/dist/leader/planner.js +47 -3
  203. package/dist/leader/repair-oracle.d.ts +61 -0
  204. package/dist/leader/repair-oracle.js +59 -1
  205. package/dist/leader/repair-wire.d.ts +78 -0
  206. package/dist/leader/repair-wire.js +79 -2
  207. package/dist/leader/wire.d.ts +79 -0
  208. package/dist/leader/wire.js +255 -8
  209. package/dist/lsp/e2b-bridge.d.ts +16 -0
  210. package/dist/lsp/e2b-bridge.js +32 -4
  211. package/dist/lsp/e2b-manager.d.ts +10 -0
  212. package/dist/lsp/e2b-manager.js +18 -2
  213. package/dist/lsp/lsp-frames.d.ts +12 -0
  214. package/dist/lsp/lsp-frames.js +12 -0
  215. package/dist/lsp/manager.d.ts +12 -0
  216. package/dist/lsp/manager.js +35 -2
  217. package/dist/lsp/types.d.ts +10 -0
  218. package/dist/lsp/ws-transport.d.ts +12 -0
  219. package/dist/lsp/ws-transport.js +53 -5
  220. package/dist/lsp-evict.d.ts +14 -0
  221. package/dist/lsp-evict.js +15 -1
  222. package/dist/main.js +2132 -96
  223. package/dist/memory-export.d.ts +1 -0
  224. package/dist/memory-export.js +4 -0
  225. package/dist/memory-scope.d.ts +49 -0
  226. package/dist/memory-scope.js +87 -4
  227. package/dist/memory-sync-client.d.ts +24 -0
  228. package/dist/memory-sync-client.js +41 -2
  229. package/dist/memory-sync.d.ts +23 -0
  230. package/dist/memory-sync.js +70 -1
  231. package/dist/model-select.d.ts +39 -0
  232. package/dist/model-select.js +42 -1
  233. package/dist/observability/cost-quota.d.ts +20 -0
  234. package/dist/observability/cost-quota.js +4 -0
  235. package/dist/observability/cost-taxonomy.d.ts +45 -0
  236. package/dist/observability/cost-taxonomy.js +34 -0
  237. package/dist/observability/logger.d.ts +1 -0
  238. package/dist/observability/logger.js +6 -0
  239. package/dist/observability/metrics.d.ts +13 -0
  240. package/dist/observability/metrics.js +63 -0
  241. package/dist/observability/otel-exporter.d.ts +9 -0
  242. package/dist/observability/otel-exporter.js +11 -3
  243. package/dist/observability/principal-context.d.ts +9 -0
  244. package/dist/observability/principal-context.js +9 -0
  245. package/dist/observability/prompt-manifest.d.ts +37 -0
  246. package/dist/observability/prompt-manifest.js +35 -1
  247. package/dist/observability/rate-limit.d.ts +10 -0
  248. package/dist/observability/rate-limit.js +1 -0
  249. package/dist/observability/tool-trace.d.ts +24 -0
  250. package/dist/observability/tool-trace.js +41 -1
  251. package/dist/orchestration/hardened-vm-runner.d.ts +107 -0
  252. package/dist/orchestration/hardened-vm-runner.js +119 -4
  253. package/dist/orchestration/hardened-vm-worker-runner.d.ts +14 -0
  254. package/dist/orchestration/hardened-vm-worker-runner.js +26 -1
  255. package/dist/orchestration/hardened-vm-worker.js +27 -0
  256. package/dist/orchestration/subagent-steer.d.ts +44 -0
  257. package/dist/orchestration/subagent-steer.js +45 -1
  258. package/dist/orchestration/workflow-agent-steer.d.ts +54 -0
  259. package/dist/orchestration/workflow-agent-steer.js +80 -1
  260. package/dist/orchestration/workflow-completion-inbox.d.ts +189 -2
  261. package/dist/orchestration/workflow-completion-inbox.js +283 -32
  262. package/dist/orchestration/workflow-notify-journal.d.ts +132 -1
  263. package/dist/orchestration/workflow-notify-journal.js +187 -13
  264. package/dist/parked-decide.d.ts +61 -0
  265. package/dist/parked-decide.js +58 -1
  266. package/dist/per-task-image.d.ts +54 -0
  267. package/dist/per-task-image.js +41 -0
  268. package/dist/plan-cache-probe.d.ts +35 -0
  269. package/dist/plan-cache-probe.js +18 -3
  270. package/dist/plugins/approval-exemption-store.d.ts +7 -0
  271. package/dist/plugins/approval-exemption-store.js +28 -2
  272. package/dist/plugins/approval-store-sql.d.ts +64 -0
  273. package/dist/plugins/approval-store-sql.js +32 -0
  274. package/dist/plugins/background-agent-store-sql.d.ts +55 -0
  275. package/dist/plugins/background-agent-store-sql.js +91 -4
  276. package/dist/plugins/background-shell-support.d.ts +98 -0
  277. package/dist/plugins/background-shell-support.js +117 -13
  278. package/dist/plugins/blob-backend.d.ts +104 -0
  279. package/dist/plugins/blob-backend.js +163 -6
  280. package/dist/plugins/breaker-state-sql.d.ts +65 -1
  281. package/dist/plugins/breaker-state-sql.js +46 -8
  282. package/dist/plugins/caching-session-store.d.ts +42 -0
  283. package/dist/plugins/caching-session-store.js +63 -3
  284. package/dist/plugins/checkpoint-store-sql.d.ts +179 -0
  285. package/dist/plugins/checkpoint-store-sql.js +239 -11
  286. package/dist/plugins/file-outcome-sink.d.ts +4 -0
  287. package/dist/plugins/file-outcome-sink.js +9 -0
  288. package/dist/plugins/file-resume-anchor-store.d.ts +20 -0
  289. package/dist/plugins/file-resume-anchor-store.js +43 -4
  290. package/dist/plugins/file-run-store.d.ts +90 -0
  291. package/dist/plugins/file-run-store.js +145 -13
  292. package/dist/plugins/file-snapshot-store-sql.d.ts +133 -1
  293. package/dist/plugins/file-snapshot-store-sql.js +178 -10
  294. package/dist/plugins/file-workflow-journal-store.d.ts +10 -0
  295. package/dist/plugins/file-workflow-journal-store.js +10 -0
  296. package/dist/plugins/fork-routing-session-store.d.ts +47 -0
  297. package/dist/plugins/fork-routing-session-store.js +51 -3
  298. package/dist/plugins/host-platform.d.ts +69 -0
  299. package/dist/plugins/host-platform.js +81 -2
  300. package/dist/plugins/image-bake-store-sql.d.ts +136 -1
  301. package/dist/plugins/image-bake-store-sql.js +241 -7
  302. package/dist/plugins/image-index-sql.d.ts +46 -0
  303. package/dist/plugins/image-index-sql.js +113 -4
  304. package/dist/plugins/k8s-bg-scripts.d.ts +34 -0
  305. package/dist/plugins/k8s-bg-scripts.js +88 -4
  306. package/dist/plugins/k8s-exec-protocol.d.ts +33 -0
  307. package/dist/plugins/k8s-exec-protocol.js +41 -0
  308. package/dist/plugins/local-checkpoint-store.d.ts +40 -0
  309. package/dist/plugins/local-checkpoint-store.js +86 -7
  310. package/dist/plugins/local-session-store.d.ts +157 -0
  311. package/dist/plugins/local-session-store.js +289 -34
  312. package/dist/plugins/local-task-attachment-store.js +14 -2
  313. package/dist/plugins/mailbox-store-sql.d.ts +38 -0
  314. package/dist/plugins/mailbox-store-sql.js +39 -6
  315. package/dist/plugins/memory-engine-pg.d.ts +30 -0
  316. package/dist/plugins/memory-engine-pg.js +122 -4
  317. package/dist/plugins/memory-engine-tidb.d.ts +26 -0
  318. package/dist/plugins/memory-engine-tidb.js +115 -5
  319. package/dist/plugins/memory-engine-vector-util.d.ts +5 -0
  320. package/dist/plugins/memory-engine-vector-util.js +5 -0
  321. package/dist/plugins/memory-resume-anchor-store.d.ts +8 -0
  322. package/dist/plugins/memory-resume-anchor-store.js +17 -0
  323. package/dist/plugins/memory-run-store.d.ts +63 -0
  324. package/dist/plugins/memory-run-store.js +73 -8
  325. package/dist/plugins/memory-session-policy-store.d.ts +17 -0
  326. package/dist/plugins/memory-session-policy-store.js +17 -0
  327. package/dist/plugins/memory-sync-store-pg.d.ts +42 -0
  328. package/dist/plugins/memory-sync-store-pg.js +45 -2
  329. package/dist/plugins/memory-sync-store-tidb.d.ts +9 -0
  330. package/dist/plugins/memory-sync-store-tidb.js +31 -1
  331. package/dist/plugins/outcome-ledger-sql.d.ts +63 -0
  332. package/dist/plugins/outcome-ledger-sql.js +97 -3
  333. package/dist/plugins/pg-approval-store.d.ts +7 -0
  334. package/dist/plugins/pg-approval-store.js +7 -0
  335. package/dist/plugins/pg-breaker-state.d.ts +6 -0
  336. package/dist/plugins/pg-breaker-state.js +6 -0
  337. package/dist/plugins/pg-checkpoint-store.d.ts +8 -0
  338. package/dist/plugins/pg-checkpoint-store.js +8 -0
  339. package/dist/plugins/pg-cost-quota.d.ts +17 -0
  340. package/dist/plugins/pg-cost-quota.js +6 -0
  341. package/dist/plugins/pg-file-snapshot-store.d.ts +6 -0
  342. package/dist/plugins/pg-file-snapshot-store.js +6 -0
  343. package/dist/plugins/pg-image-bake.d.ts +9 -0
  344. package/dist/plugins/pg-image-bake.js +9 -0
  345. package/dist/plugins/pg-image-index.d.ts +9 -0
  346. package/dist/plugins/pg-image-index.js +9 -0
  347. package/dist/plugins/pg-outcome-ledger.d.ts +9 -0
  348. package/dist/plugins/pg-outcome-ledger.js +9 -0
  349. package/dist/plugins/pg-pool.d.ts +50 -0
  350. package/dist/plugins/pg-pool.js +78 -0
  351. package/dist/plugins/pg-query.d.ts +11 -0
  352. package/dist/plugins/pg-rate-limiter.d.ts +23 -0
  353. package/dist/plugins/pg-rate-limiter.js +12 -2
  354. package/dist/plugins/pg-resume-anchor-store.d.ts +5 -0
  355. package/dist/plugins/pg-resume-anchor-store.js +5 -0
  356. package/dist/plugins/pg-run-store.d.ts +7 -0
  357. package/dist/plugins/pg-run-store.js +7 -0
  358. package/dist/plugins/pg-safe-json.d.ts +13 -0
  359. package/dist/plugins/pg-safe-json.js +40 -4
  360. package/dist/plugins/pg-session-policy-store.d.ts +5 -0
  361. package/dist/plugins/pg-session-policy-store.js +5 -0
  362. package/dist/plugins/pg-session-storage.d.ts +72 -0
  363. package/dist/plugins/pg-session-storage.js +152 -20
  364. package/dist/plugins/pg-session-store.d.ts +10 -0
  365. package/dist/plugins/pg-session-store.js +10 -0
  366. package/dist/plugins/pg-tool-result-store.d.ts +7 -0
  367. package/dist/plugins/pg-tool-result-store.js +7 -0
  368. package/dist/plugins/pg-workflow-journal-store.d.ts +7 -0
  369. package/dist/plugins/pg-workflow-journal-store.js +7 -0
  370. package/dist/plugins/pg-workflow-run-store.d.ts +7 -0
  371. package/dist/plugins/pg-workflow-run-store.js +7 -0
  372. package/dist/plugins/posix-shell-fs.d.ts +3 -0
  373. package/dist/plugins/posix-shell-fs.js +31 -1
  374. package/dist/plugins/remote-env-adb.d.ts +25 -0
  375. package/dist/plugins/remote-env-adb.js +95 -12
  376. package/dist/plugins/remote-env-e2b.d.ts +146 -0
  377. package/dist/plugins/remote-env-e2b.js +371 -40
  378. package/dist/plugins/remote-env-file-error.d.ts +34 -0
  379. package/dist/plugins/remote-env-file-error.js +37 -0
  380. package/dist/plugins/remote-env-host.d.ts +151 -0
  381. package/dist/plugins/remote-env-host.js +468 -70
  382. package/dist/plugins/remote-env-k8s.d.ts +135 -0
  383. package/dist/plugins/remote-env-k8s.js +318 -32
  384. package/dist/plugins/remote-env-local-docker.d.ts +65 -0
  385. package/dist/plugins/remote-env-local-docker.js +149 -24
  386. package/dist/plugins/remote-env-ssh.d.ts +35 -0
  387. package/dist/plugins/remote-env-ssh.js +117 -20
  388. package/dist/plugins/remote-scratchpad.d.ts +38 -0
  389. package/dist/plugins/remote-scratchpad.js +32 -2
  390. package/dist/plugins/remote-shell.d.ts +22 -0
  391. package/dist/plugins/remote-shell.js +27 -1
  392. package/dist/plugins/resume-anchor-store-sql.d.ts +28 -0
  393. package/dist/plugins/resume-anchor-store-sql.js +11 -0
  394. package/dist/plugins/roster-store-sql.d.ts +27 -0
  395. package/dist/plugins/roster-store-sql.js +54 -0
  396. package/dist/plugins/run-store-sql.d.ts +194 -0
  397. package/dist/plugins/run-store-sql.js +210 -9
  398. package/dist/plugins/s3-presign.d.ts +20 -0
  399. package/dist/plugins/s3-presign.js +49 -2
  400. package/dist/plugins/scheduler-support.d.ts +12 -0
  401. package/dist/plugins/scheduler-support.js +75 -3
  402. package/dist/plugins/send-file-ledger.d.ts +15 -0
  403. package/dist/plugins/send-file-ledger.js +53 -4
  404. package/dist/plugins/send-user-file.d.ts +77 -0
  405. package/dist/plugins/send-user-file.js +92 -4
  406. package/dist/plugins/session-policy-store-sql.d.ts +15 -0
  407. package/dist/plugins/session-policy-store-sql.js +75 -3
  408. package/dist/plugins/session-store.d.ts +45 -0
  409. package/dist/plugins/session-store.js +51 -0
  410. package/dist/plugins/sql-driver.d.ts +77 -0
  411. package/dist/plugins/sql-driver.js +4 -0
  412. package/dist/plugins/sql-escape.d.ts +8 -0
  413. package/dist/plugins/sql-escape.js +8 -0
  414. package/dist/plugins/sql-row-helpers.d.ts +25 -0
  415. package/dist/plugins/sql-row-helpers.js +25 -0
  416. package/dist/plugins/store-backend.d.ts +103 -0
  417. package/dist/plugins/store-backend.js +120 -27
  418. package/dist/plugins/store-contracts.d.ts +62 -0
  419. package/dist/plugins/store-contracts.js +3 -0
  420. package/dist/plugins/task-attachment-store.d.ts +60 -0
  421. package/dist/plugins/task-attachment-store.js +49 -3
  422. package/dist/plugins/task-list-store-sql.d.ts +25 -0
  423. package/dist/plugins/task-list-store-sql.js +21 -0
  424. package/dist/plugins/tidb-approval-store.d.ts +6 -0
  425. package/dist/plugins/tidb-approval-store.js +6 -0
  426. package/dist/plugins/tidb-breaker-state.d.ts +5 -0
  427. package/dist/plugins/tidb-breaker-state.js +5 -0
  428. package/dist/plugins/tidb-checkpoint-store.d.ts +7 -0
  429. package/dist/plugins/tidb-checkpoint-store.js +7 -0
  430. package/dist/plugins/tidb-cost-quota.d.ts +6 -0
  431. package/dist/plugins/tidb-cost-quota.js +1 -0
  432. package/dist/plugins/tidb-file-snapshot-store.d.ts +6 -0
  433. package/dist/plugins/tidb-file-snapshot-store.js +6 -0
  434. package/dist/plugins/tidb-image-bake.d.ts +8 -0
  435. package/dist/plugins/tidb-image-bake.js +8 -0
  436. package/dist/plugins/tidb-image-index.d.ts +8 -0
  437. package/dist/plugins/tidb-image-index.js +8 -0
  438. package/dist/plugins/tidb-outcome-ledger.d.ts +10 -0
  439. package/dist/plugins/tidb-outcome-ledger.js +10 -0
  440. package/dist/plugins/tidb-pool.d.ts +56 -0
  441. package/dist/plugins/tidb-pool.js +181 -1
  442. package/dist/plugins/tidb-rate-limiter.d.ts +11 -0
  443. package/dist/plugins/tidb-rate-limiter.js +5 -2
  444. package/dist/plugins/tidb-resume-anchor-store.d.ts +5 -0
  445. package/dist/plugins/tidb-resume-anchor-store.js +5 -0
  446. package/dist/plugins/tidb-run-store.d.ts +7 -0
  447. package/dist/plugins/tidb-run-store.js +7 -0
  448. package/dist/plugins/tidb-session-policy-store.d.ts +5 -0
  449. package/dist/plugins/tidb-session-policy-store.js +5 -0
  450. package/dist/plugins/tidb-session-storage.d.ts +43 -0
  451. package/dist/plugins/tidb-session-storage.js +62 -3
  452. package/dist/plugins/tidb-session-store.d.ts +142 -0
  453. package/dist/plugins/tidb-session-store.js +264 -16
  454. package/dist/plugins/tidb-tool-result-store.d.ts +5 -0
  455. package/dist/plugins/tidb-tool-result-store.js +7 -0
  456. package/dist/plugins/tidb-workflow-journal-store.d.ts +7 -0
  457. package/dist/plugins/tidb-workflow-journal-store.js +7 -0
  458. package/dist/plugins/tidb-workflow-run-store.d.ts +8 -0
  459. package/dist/plugins/tidb-workflow-run-store.js +8 -0
  460. package/dist/plugins/tool-result-store-sql.d.ts +58 -0
  461. package/dist/plugins/tool-result-store-sql.js +38 -2
  462. package/dist/plugins/web-search.d.ts +35 -0
  463. package/dist/plugins/web-search.js +45 -9
  464. package/dist/plugins/workflow-journal-limits.d.ts +10 -0
  465. package/dist/plugins/workflow-journal-limits.js +10 -0
  466. package/dist/plugins/workflow-journal-store-sql.d.ts +78 -0
  467. package/dist/plugins/workflow-journal-store-sql.js +59 -3
  468. package/dist/plugins/workflow-run-store-sql.d.ts +84 -0
  469. package/dist/plugins/workflow-run-store-sql.js +84 -6
  470. package/dist/plugins/worktree-isolation.d.ts +45 -0
  471. package/dist/plugins/worktree-isolation.js +105 -6
  472. package/dist/plugins/write-behind-counter.d.ts +56 -1
  473. package/dist/plugins/write-behind-counter.js +53 -14
  474. package/dist/principal-jwt.d.ts +24 -0
  475. package/dist/principal-jwt.js +60 -5
  476. package/dist/project-memory.d.ts +22 -0
  477. package/dist/project-memory.js +144 -15
  478. package/dist/prompts-domain-validate.d.ts +28 -0
  479. package/dist/prompts-domain-validate.js +42 -1
  480. package/dist/question.d.ts +33 -0
  481. package/dist/question.js +69 -2
  482. package/dist/resource-suspend.d.ts +21 -0
  483. package/dist/resource-suspend.js +16 -0
  484. package/dist/router/route-orchestration.d.ts +78 -0
  485. package/dist/router/route-orchestration.js +77 -0
  486. package/dist/run-local.d.ts +32 -0
  487. package/dist/run-local.js +172 -8
  488. package/dist/runs.d.ts +189 -4
  489. package/dist/runs.js +465 -24
  490. package/dist/runtime-caps-resolver.d.ts +106 -0
  491. package/dist/runtime-caps-resolver.js +89 -4
  492. package/dist/runtime-governance.d.ts +84 -0
  493. package/dist/runtime-governance.js +127 -1
  494. package/dist/sandbox-pkg-source.d.ts +23 -0
  495. package/dist/sandbox-pkg-source.js +37 -0
  496. package/dist/sealed-key.d.ts +54 -0
  497. package/dist/sealed-key.js +68 -3
  498. package/dist/security.d.ts +108 -0
  499. package/dist/security.js +145 -6
  500. package/dist/sema-registry.d.ts +21 -0
  501. package/dist/sema-registry.js +21 -0
  502. package/dist/session-leaf-bus.d.ts +31 -0
  503. package/dist/session-leaf-bus.js +32 -0
  504. package/dist/session-sync-content.d.ts +46 -0
  505. package/dist/session-sync-content.js +47 -1
  506. package/dist/session-sync-kernel.d.ts +89 -0
  507. package/dist/session-sync-kernel.js +48 -3
  508. package/dist/session-sync.d.ts +125 -0
  509. package/dist/session-sync.js +181 -8
  510. package/dist/session-titler.d.ts +26 -0
  511. package/dist/session-titler.js +41 -7
  512. package/dist/session-watch.d.ts +53 -1
  513. package/dist/session-watch.js +73 -9
  514. package/dist/sighup-idle.d.ts +30 -0
  515. package/dist/sighup-idle.js +12 -1
  516. package/dist/spec-fields.d.ts +91 -3
  517. package/dist/spec-fields.js +116 -4
  518. package/dist/task-cwd.d.ts +50 -0
  519. package/dist/task-cwd.js +68 -1
  520. package/dist/task-mcp.d.ts +47 -0
  521. package/dist/task-mcp.js +29 -0
  522. package/dist/task-settings.d.ts +175 -0
  523. package/dist/task-settings.js +226 -11
  524. package/dist/task-workflow.d.ts +67 -0
  525. package/dist/task-workflow.js +75 -8
  526. package/dist/tool-approval.d.ts +91 -0
  527. package/dist/tool-approval.js +215 -0
  528. package/dist/trace/artifacts.d.ts +9 -0
  529. package/dist/trace/artifacts.js +30 -5
  530. package/dist/trace/core-keyset-guard.d.ts +18 -0
  531. package/dist/trace/ledger-sink.d.ts +43 -0
  532. package/dist/trace/ledger-sink.js +64 -5
  533. package/dist/trace/project.d.ts +133 -0
  534. package/dist/trace/project.js +189 -2
  535. package/dist/trace/redact.d.ts +19 -0
  536. package/dist/trace/redact.js +66 -9
  537. package/dist/usage-analytics.d.ts +26 -0
  538. package/dist/usage-analytics.js +26 -3
  539. package/package.json +1 -1
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Code-review council copy (bundle-data layer). Pure data — placeholders are `{name}`-style,
3
+ * filled by the consumer (code-review-council.ts fillPrompt). Guardrail rationale lives with the
4
+ * consumer's comments; this file is ONLY the words.
5
+ */
6
+ /** The deployment-owned lens roster. Order = priority (security/correctness first = the bug-finders);
7
+ * the caller dials COUNT only (pickLenses), never a named subset. */
1
8
  export const REVIEW_LENSES = [
2
9
  { name: "security", brief: "authz/ownership checks, input validation, injection (SQL/command/path), secrets, unsafe deserialization, SSRF, trust boundaries" },
3
10
  { name: "correctness", brief: "edge cases, off-by-one, race conditions, resource leaks, missing/incorrect error paths, unhandled rejections" },
@@ -6,6 +13,8 @@ export const REVIEW_LENSES = [
6
13
  { name: "tests", brief: "are the risky paths covered? do tests assert behavior (not implementation)? missing edge-case tests" },
7
14
  { name: "readability", brief: "naming, dead code, duplication, misleading comments, structure — these are [DESIGN], never [BUG]" },
8
15
  ];
16
+ /** Guardrails 2-5: evidence grounding (a CONFIDENCE signal, not a delete), requirement anchoring,
17
+ * bucketing, severity×confidence. */
9
18
  export const GROUNDING = [
10
19
  "RULES:",
11
20
  "1. EVIDENCE drives CONFIDENCE (it does NOT delete a finding): cite an exact `path:line` and, whenever you can, **paste the verbatim code snippet** you are flagging. A finding WITH a pasted snippet may carry full confidence/severity; a finding with only a line reference is still allowed but MUST be tagged `[unverified: line-ref only]` and capped at minor severity / low confidence (never a blocker).",
@@ -13,17 +22,21 @@ export const GROUNDING = [
13
22
  "3. BUCKET: label each finding [BUG] (provably wrong against the code), [DESIGN] (subjective preference), or [QUESTION]. A design preference is NEVER a [BUG].",
14
23
  "4. RATE each: severity (blocker/major/minor) AND confidence (high/med/low).",
15
24
  ].join("\n");
25
+ /** L1 lens reviewer system prompt. Placeholders: {name} {brief} {grounding}. */
16
26
  export const LENS_SYSTEM_TPL = "You are a {name} code reviewer. Stay strictly in your lane: {brief}.\n" +
17
27
  "Read only the files you need — repo_tree to map, then repo_read_file (just-in-time).\n\n{grounding}\n\n" +
18
28
  'List findings in your lens only. If you find nothing solid, say "no findings".';
29
+ /** L2 peer-debate persona (guardrails 5,6). Placeholders: {name} {brief}. */
19
30
  export const DEBATE_MEMBER_TPL = "You are the {name} reviewer on a review panel ({brief}). Cross-examine the findings in " +
20
31
  "the shared transcript: CORROBORATE or REBUT others' claims in your area (raising/lowering their " +
21
32
  "confidence), and DEFEND or WITHDRAW your own if rebutted.\n" +
22
33
  "You MAY call repo_read_file to VERIFY ONE specific DISPUTED finding (quote the exact path:line) — do " +
23
34
  "NOT re-review the whole repo. A finding with no path:line + code quote is invalid. Be concise.";
35
+ /** L2 debate topic body. Placeholders: {objective} {grounding} {findings}. */
24
36
  export const DEBATE_TOPIC_TPL = "Cross-examine these specialist code-review findings for: {objective}\n\n{grounding}\n" +
25
37
  "5. CONFIDENCE: peer corroboration raises it; an unrebutted rebuttal lowers it; drop findings that " +
26
38
  "collapse under scrutiny.\n\nFindings to debate:\n\n{findings}";
39
+ /** Guardrails 4,7: arbitration is not summary — no new findings, ground/dedup/bucket/rank only. */
27
40
  export const ARBITER_SYSTEM = "You are the NEUTRAL ARBITER of a code-review council. You are given findings from independent " +
28
41
  "specialist reviewers. You do NOT add new findings and do NOT re-review. Your only job:\n" +
29
42
  "- TIER by grounding, do NOT silently drop real findings: a finding that PASTES the code keeps its " +
@@ -35,5 +48,6 @@ export const ARBITER_SYSTEM = "You are the NEUTRAL ARBITER of a code-review coun
35
48
  "Output the final review: a 2-3 line summary, then findings grouped by bucket then severity, each as " +
36
49
  "`path:line` — the problem — a concrete fix. Never invent files or symbols. If a whole lens reported " +
37
50
  "nothing groundable, say so rather than inventing.";
51
+ /** No-arbiter fallback header ({findings} appended by the consumer). */
38
52
  export const ARBITER_FALLBACK_HEADER = "[council 仲裁无输出——以下是未经仲裁的各 lens 原始发现]\n\n";
39
53
  //# sourceMappingURL=code-review.js.map
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Sema identity — the branded role layer for the `default` scenario (bundle-data layer; wording
3
+ * history: neutralized — no baked model/vendor/protocol facts, because the brain
4
+ * stack has both OpenAI-compatible AND Anthropic-compatible legs and any baked substrate claim is the same
5
+ * class of lie the neutralization removed. The anti-"I am Claude" design is kept.)
6
+ */
1
7
  export declare const SEMA_IDENTITY: string;
2
8
  //# sourceMappingURL=identity.d.ts.map
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Sema identity — the branded role layer for the `default` scenario (bundle-data layer; wording
3
+ * history: neutralized — no baked model/vendor/protocol facts, because the brain
4
+ * stack has both OpenAI-compatible AND Anthropic-compatible legs and any baked substrate claim is the same
5
+ * class of lie the neutralization removed. The anti-"I am Claude" design is kept.)
6
+ */
1
7
  export const SEMA_IDENTITY = "You are Sema, an AI agent built by the Sema team. You act through tools to get real work done.\n" +
2
8
  "You run on a large language model chosen and configured by your operator — you are NOT Claude, NOT " +
3
9
  "GPT, and NOT made by Anthropic or OpenAI. If asked who you are or which model you are, answer honestly " +
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Built-in team personas (bundle-data layer) — GENERIC personas only; the business prompt is
3
+ * appended at call time by the consumer (team.ts), never baked in here.
4
+ */
1
5
  export declare const TEAM_PERSONAS: {
2
6
  readonly analyst: "You analyze the task: lay out the key considerations, options, and trade-offs. Be concrete.";
3
7
  readonly critic: "You challenge the analysis: surface gaps, wrong assumptions, risks, and stronger alternatives.";
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Built-in team personas (bundle-data layer) — GENERIC personas only; the business prompt is
3
+ * appended at call time by the consumer (team.ts), never baked in here.
4
+ */
1
5
  export const TEAM_PERSONAS = {
2
6
  analyst: "You analyze the task: lay out the key considerations, options, and trade-offs. Be concrete.",
3
7
  critic: "You challenge the analysis: surface gaps, wrong assumptions, risks, and stronger alternatives.",
@@ -1,9 +1,19 @@
1
1
  import type { ToolSpec } from "@sema-agent/core";
2
+ /**
3
+ * Read-only repository tools backed by a Git host (Gitea) HTTP API — NOT a clone/shell on the runner.
4
+ *
5
+ * The agent reads a repo just-in-time (tree → read file → PR diff) through scoped function tools; the
6
+ * read token lives only in this server-side client (never in the model/sandbox), and tools are bound
7
+ * to exactly the repo the task was given. This is the lightweight path for code review (read + reason);
8
+ * running tests/linters would need a sandboxed ExecutionEnv (a deliberate future extension, not here).
9
+ */
2
10
  export interface RepoCoords {
3
11
  owner: string;
4
12
  repo: string;
5
13
  }
14
+ /** Parse `owner/name` or a repo URL (e.g. http://host:9999/AI-Only/sema-server.git). */
6
15
  export declare function parseRepo(input: string): RepoCoords;
16
+ /** Thin read-only Gitea API client. Built once at startup; bound to a repo per task. */
7
17
  export declare class GiteaClient {
8
18
  private readonly baseUrl;
9
19
  private readonly token?;
@@ -15,5 +25,6 @@ export declare class GiteaClient {
15
25
  readFile(coords: RepoCoords, path: string, ref: string): Promise<string>;
16
26
  pullDiff(coords: RepoCoords, index: number): Promise<string>;
17
27
  }
28
+ /** Build the read-only repo tool set bound to one repo (cheap per-task closure; the client is shared). */
18
29
  export declare function repoToolsFor(client: GiteaClient, coords: RepoCoords): ToolSpec[];
19
30
  //# sourceMappingURL=repo-tools.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { Type } from "typebox";
2
+ /** Parse `owner/name` or a repo URL (e.g. http://host:9999/AI-Only/sema-server.git). */
2
3
  export function parseRepo(input) {
3
4
  const s = input.trim().replace(/\.git$/, "");
4
5
  const m = /^[a-z]+:\/\/[^/]+\/(.+)$/i.exec(s);
@@ -10,7 +11,9 @@ export function parseRepo(input) {
10
11
  }
11
12
  const MAX_FILE_BYTES = 96 * 1024;
12
13
  const MAX_TREE_ENTRIES = 2000;
14
+ /** Bound each Git-host call so a slow/hung host can't pin a review lens to its whole deadline. */
13
15
  const REQUEST_TIMEOUT_MS = 15_000;
16
+ /** Thin read-only Gitea API client. Built once at startup; bound to a repo per task. */
14
17
  export class GiteaClient {
15
18
  baseUrl;
16
19
  token;
@@ -43,6 +46,10 @@ export class GiteaClient {
43
46
  }
44
47
  async readFile(coords, path, ref) {
45
48
  const { owner, repo } = coords;
49
+ // `encodeURIComponent` does NOT escape "." — so a `..` segment survives the per-segment encode and the
50
+ // WHATWG URL parser collapses it when `fetch` builds the request, letting a crafted `path` climb out of
51
+ // `/repos/<owner>/<repo>/contents/` to any endpoint the read token can reach (cross-repo / admin). The
52
+ // tools are contractually bound to exactly one repo (see header), so reject traversal before it hits fetch.
46
53
  const segments = path.split("/").filter(Boolean);
47
54
  if (segments.some((s) => s === "..")) {
48
55
  throw new Error(`invalid path "${path}" (".." segments are not allowed)`);
@@ -62,6 +69,7 @@ export class GiteaClient {
62
69
  return text.length > MAX_FILE_BYTES * 4 ? text.slice(0, MAX_FILE_BYTES * 4) + "\n…[diff truncated]" : text;
63
70
  }
64
71
  }
72
+ /** Build the read-only repo tool set bound to one repo (cheap per-task closure; the client is shared). */
65
73
  export function repoToolsFor(client, coords) {
66
74
  const ref = (r) => (r ? Promise.resolve(r) : client.defaultBranch(coords));
67
75
  return [
@@ -1,24 +1,119 @@
1
+ /**
2
+ * SendUserFile v2 — the sandbox-lane file source (clay ruling 2026-07-14: Plan B direct upload).
3
+ *
4
+ * The tool cannot reach the task's sandbox through core (ToolExecuteContext carries no env handle — core
5
+ * keeps the per-task ExecutionEnv private to its prepare-task closure). But the server BUILDS the
6
+ * `executionEnvFactory` core calls, and the factory context carries `taskId` — so we wrap OUR OWN factory
7
+ * (same posture as withWorktreeIsolation) and keep a replica-local taskId → env registry, unregistering
8
+ * when core destroys the env. No core change, no parallel abstraction — pure deployment glue on a seam
9
+ * the deployment already owns.
10
+ *
11
+ * The send itself is the anti-relay shape ([747]; k8s workspace-snapshot posture): the server presigns a
12
+ * single-object PUT (120s, method-bound, STAGING key — 修3), the SANDBOX `curl -T`s the file straight to S3 — bytes never
13
+ * relay through the server, S3 credentials never enter the sandbox. Tenant isolation = the sandbox can
14
+ * only read its own filesystem, which is exactly the tenant's task workspace; that is why this lane is
15
+ * multi-tenant-safe while the host lane never is (host-lane multi-tenant is permanently closed).
16
+ *
17
+ * ssh lane (backfill 2026-07-14): the SAME send chain works over the ssh adapter unchanged — its exec
18
+ * face is contract-identical (Result{stdout,stderr,exitCode}, stderr split, `options.timeout` in SECONDS
19
+ * ×1000, remote-env-ssh.ts) and the peer is assumed LINUX (`stat -c %s` = GNU/busybox; the fleet is all
20
+ * Linux — a macOS peer's `stat -f %z` dialect would fail LOUD at the exit-code/stat-parse guards, never
21
+ * silently). But the TENANT judgment INVERTS: an ssh peer is ONE persistent real machine shared by every
22
+ * task (sshExecutionEnvFactory ignores ctx — same host + same mountPath for all tasks; destroy() only
23
+ * disconnects, files persist; capabilities.isolation:false). "Scoped read = tenant boundary" does NOT
24
+ * hold there, so the ssh lane is SINGLE-USER ONLY (same gate as host) — see `sandboxSendLaneEnabled`.
25
+ *
26
+ * The presigned PUT URL is a capability secret: it never enters model context (the tool returns delivery
27
+ * metadata only) and is REDACTED from every error surfaced from here (curl stderr may echo the URL).
28
+ *
29
+ * RESIDUAL CLOSED (修3, 三路复审 2026-07-15; was the accepted dual-review residual of 2026-07-14): the URL
30
+ * still rides the exec command line (readable via /proc inside the sandbox), but it is now a capability on
31
+ * a STAGING key only — the server promotes staging→final with its own creds (CopyObject), deletes staging,
32
+ * and size-verifies the FINAL object, whose write URL never existed outside the server. A /proc reader can
33
+ * no longer rewrite the delivered object after verification or skew the ledgered size (see
34
+ * PreparedDirectUpload in send-user-file.ts for the full promotion contract).
35
+ */
1
36
  import type { ExecutionEnv, ExecutionEnvFactory } from "@sema-agent/core";
2
37
  import type { IssuedFileLink, PreparedDirectUpload } from "../plugins/send-user-file.js";
38
+ /** Leak backstop (codex review HIGH): core skips destroy on suspend/review paths and a crash may skip it
39
+ * entirely — the suspendVM wrap covers the common case, this bound covers the rest. Far above any real
40
+ * per-replica concurrency. 修6: at the cap the registry REFUSES the new registration instead of FIFO-evicting
41
+ * the oldest entry — every entry here is live-until-destroy/suspend by construction, so there is no
42
+ * "terminal/stale" liveness verdict to evict on, and silently breaking an EXISTING live task's send face to
43
+ * admit a new one inverts the harm (the old FIFO victim's SendUserFile would report "no sandbox attached"
44
+ * while its env kept executing). The refused task gets a TYPED capacity error at send time instead. */
3
45
  export declare const TASK_ENV_REGISTRY_MAX = 512;
46
+ /** Replica-local taskId → live ExecutionEnv(s). Registered by the factory wrap, dropped on destroy/suspend.
47
+ *
48
+ * 修5 (concurrent-generation guard): deployments WITHOUT a run-store single-active-session claim can race
49
+ * two legs of one session through the factory concurrently — previously the second registration silently
50
+ * OVERWROTE the first, so leg A's later SendUserFile resolved to leg B's env (wrong-generation read/upload).
51
+ * The registry now keeps EVERY live env per key and `get()` fail-louds on ambiguity: neither leg can silently
52
+ * read the other's sandbox, and the moment one generation is destroyed/suspended the survivor resolves again.
53
+ * (Rejecting the second factory call outright was considered and discarded: a stale never-destroyed entry —
54
+ * crash/no-destroy path — would then brick every future leg of that task, and the factory seam must not fail
55
+ * env creation for a send-face bookkeeping conflict. Deployments WITH the single-active-session claim
56
+ * serialize legs upstream and never see this state.) */
4
57
  export declare class TaskEnvRegistry {
5
58
  private readonly map;
59
+ /** 修6: taskIds whose registration was refused at the cap — lets get() report the TRUE reason (typed
60
+ * capacity error, not a misleading "no sandbox attached"). Bounded by the same cap (marker-only). */
6
61
  private readonly refusedAtCapacity;
7
62
  private liveCount;
63
+ /** Resolve the ONE live env for a task. Throws typed errors on the two governed failure states:
64
+ * ambiguity (修5 — concurrent generations both live) and capacity refusal (修6). Returns undefined when
65
+ * the task simply has no registered env (caller reports "no sandbox attached"). */
8
66
  get(taskId: string | undefined): ExecutionEnv | undefined;
67
+ /** Wrap the deployment's own factory: register each minted env under the task's CANONICAL id — core hands
68
+ * the factory the raw `spec.taskId` but gives tools `hostTaskId = spec.taskId ?? sessionId` (prepare-task
69
+ * 262/320/428; the sync `/v1/tasks` leg deliberately sets no spec.taskId), so the registry key MUST apply
70
+ * the same fallback or every sync-leg lookup misses (codex review HIGH). Unregister when core calls
71
+ * destroy() (identity guard: only the env's OWN entry is dropped — a replacement env for a reused key must
72
+ * not be evicted by the old one's late destroy). core SKIPS destroy on durable suspend/review (runtask
73
+ * keeps the env for the snapshot) — wrap suspendVM the same way so a suspended task doesn't pin its env
74
+ * here forever; the bounded-size backstop covers any remaining no-destroy crash path. */
9
75
  wrapFactory(factory: ExecutionEnvFactory): ExecutionEnvFactory;
10
76
  }
77
+ /**
78
+ * Which REMOTE_EXEC lanes may register the sandbox-send TaskEnvRegistry (and thus mount the sandbox-lane
79
+ * SendUserFile source), under which tenancy gate. The judgment per lane (2026-07-14 ssh backfill review):
80
+ *
81
+ * - e2b / k8s: one task = one disposable sandbox; the sandbox filesystem IS the tenant's task workspace,
82
+ * so a sandbox-scoped read is tenant-scoped by construction → open to any tenant.
83
+ * - ssh: the peer is ONE persistent real machine SHARED across tasks (factory ignores ctx: every task
84
+ * gets the same host+mountPath; destroy=disconnect only, files persist). Tenant A's task can read the
85
+ * residue of tenant B's task → the isolation premise FAILS. Multi-tenant here would be an
86
+ * arbitrary-host-path-read → public-URL exfil face, so the lane opens ONLY single-user
87
+ * (`requirePrincipal !== true`), the exact gate the host lane uses. NOT a lane to "fix later with a
88
+ * per-task workspace": tasks legitimately operate outside any workspace on a real host (design/61 —
89
+ * batch deployment), so per-task dirs would not restore the boundary anyway.
90
+ * - adb / local-docker / host / unset: no registry (host+unset use the local-fs source in main.ts;
91
+ * adb/local-docker remain a follow-on).
92
+ */
11
93
  export declare function sandboxSendLaneEnabled(provider: string | undefined, requirePrincipal: boolean): boolean;
94
+ /** Single-quote a path for POSIX sh (the only metacharacter inside '' is ' itself). */
12
95
  export declare function shq(s: string): string;
96
+ /** Strip the capability URL (and any SigV4 signature) from text before it reaches an error/log — including
97
+ * the percent-encoded forms an adapter may echo (the k8s exec transport carries the command in a request
98
+ * URI, so an error can quote the URL re-encoded; codex review MED). */
13
99
  export declare function redactPutUrl(text: string, url: string): string;
14
100
  export interface SandboxFileSendDeps {
15
101
  registry: TaskEnvRegistry;
102
+ /** `scope` = the caller's VERIFIED principal (ToolExecuteContext.principal) — keys the hashed scope segment
103
+ * in the object key + rides back on IssuedFileLink.scope for the ledger. Absent on single-user lanes. */
16
104
  prepare: (filename: string | undefined, scope?: string) => PreparedDirectUpload;
17
105
  maxBytes: number;
18
106
  }
107
+ /** The live object `createSandboxFileSend` produces — a bare callable (deps captured in closure), mirroring
108
+ * the sibling `SendUserFileIssuer` role (send-user-file.ts) one level down: this is the sandbox-lane half. */
19
109
  export type SandboxFileSend = (path: string, ctx: {
20
110
  taskId?: string;
21
111
  principal?: string;
22
112
  }) => Promise<IssuedFileLink>;
113
+ /**
114
+ * The sandbox-lane `send` seam for the SendUserFile tool: in-sandbox stat (existence + regular file +
115
+ * size cap, BEFORE any signing) → presign PUT → in-sandbox `curl -T` → finalize the user-facing link.
116
+ * Throws typed Errors (redacted) — the tool reports them per file.
117
+ */
23
118
  export declare function createSandboxFileSend(deps: SandboxFileSendDeps): SandboxFileSend;
24
119
  //# sourceMappingURL=sandbox-file-send.d.ts.map
@@ -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
  }