@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
@@ -8,29 +8,101 @@ import { createTeamTool, teamCoordinatorPrompt, getTeam, teamNames } from "./tea
8
8
  import { oaTools, oaPrompt } from "./oa-tools.js";
9
9
  import { createWebSearchBackend, webSearchConfigFromSettings } from "../plugins/web-search.js";
10
10
  import { skillsForScenario } from "./skills.js";
11
- export { SEMA_IDENTITY } from "./prompts/identity.js";
11
+ /**
12
+ * Sema product identity, prepended to the core default base for the `default` scenario when
13
+ * {@link ScenarioDeps.brandIdentity} is on. Honest about the substrate (the engine runs whichever model
14
+ * the operator configured — not Claude/Anthropic), so the agent never inherits the model's training-time
15
+ * "I am Claude" hallucination.
16
+ *
17
+ * Live-caught incident (a Qwen3.5 deployment self-described as "running on a DeepSeek model"):
18
+ * NOTHING substrate-specific may be hardcoded here — onboard is multi-provider (Qwen/GLM/Kimi/self-hosted
19
+ * vLLM…), so a baked maker name makes every non-DeepSeek deployment misstate its own substrate. Same for
20
+ * the gateway protocol (the brain stack serves Anthropic-compatible routes too — routing brain +
21
+ * createAnthropicBrain — so "OpenAI-compatible gateway" would be the same class of lie). Neutral wording
22
+ * (zero core-seam need; interpolating the model id would need a `StablePromptContext.model`
23
+ * seam and reads poorly for ugly preset ids). The anti-"I am Claude" design is kept — only the baked
24
+ * substrate facts are removed.
25
+ */
26
+ export { SEMA_IDENTITY } from "./prompts/identity.js"; // copy moved to the bundle-data layer
12
27
  import { SEMA_IDENTITY } from "./prompts/identity.js";
28
+ /**
29
+ * Prompt provider for the branded `default` scenario: SEMA_IDENTITY on top of the ROLE base — the
30
+ * task's own `body.systemPrompt`, or core's {@link DEFAULT_SYSTEM_PROMPT} when none. Core 1.243
31
+ * (提示词主权批) appends the constitution structurally AFTER this role layer (harness
32
+ * safety blocks + modes + memory guidance + the prefix-cache-safe `<user_memory>` tail), so identity
33
+ * cannot displace the safety blocks. The pre-1.243 form (identity + `defaultPromptProvider.stableSystem`,
34
+ * i.e. an ALREADY-assembled prompt) would now trip the migration guard (anchor-detect → pass-through +
35
+ * `onError(phase:"prompt-constitution")`) — this role-only form is the guard-free contract.
36
+ */
13
37
  export function semaIdentityProvider() {
38
+ // Lens-4 endgame (core 1.310, [1006]②/[1012]): the typed stableBlocks branch now carries core's OWN
39
+ // pass-through guard (M9-family anchor detection on identity declarations → provider-assembled,
40
+ // un-doubled) — the 0c3352f server-side fallback routing for the already-assembled input face is
41
+ // retired; the real-composer parity matrix keeps that face pinned byte-equal against the pre-M14 form.
14
42
  return {
43
+ // M14 (core 1.303, 板 [968]): the branded head is a TYPED block — the stable id "sema/identity" gives
44
+ // it a manifest section identity + digest (the G-1 observability gap; IDENTITY-DIGEST-MIGRATION.md
45
+ // route B, this hook is its carrier). identity-slot semantics: the block REPLACES core/role.base at
46
+ // the head position, so it must carry the FULL role layer (identity + role base) — byte-identical to
47
+ // the previous stableSystem string. Finer identity/role digest separation is the catalog-section
48
+ // endgame, not this hook's job.
15
49
  stableBlocks: (ctx) => [
16
50
  { id: "sema/identity", slot: "identity", text: `${SEMA_IDENTITY}\n\n${ctx.userSystemPrompt ?? DEFAULT_SYSTEM_PROMPT}` },
17
51
  ],
18
52
  };
19
53
  }
54
+ /**
55
+ * `code` 场景的提示词提供者([849] 造,[891] clay 裁定改名 autonomous→code):role 基底 = core
56
+ * {@link CODE_SYSTEM_PROMPT}(core 1.298 [891] 改名批正名,旧名 FULL_BODY_SYSTEM_PROMPT=恒等
57
+ * 别名过渡窗;CODE_AGENT persona + AUTONOMY_SELF_AUDIT + ANTI_VERBOSITY +
58
+ * TOOL_PARAM_JSON;[891] 血缘定论 = CC 生产编码提示词的蒸馏去牌版,底本随 CC 版本对表 cc-anchors,
59
+ * 非自研)——与 bench 的请求组装完全同源,引用 core 常量随版本走,绝不复制字符串(tb bench 实测:
60
+ * 产品默认请求与同引擎 bench 态的差距根因就在这三件 persona/自检/终验)。品牌层与
61
+ * {@link semaIdentityProvider} 同构:brandIdentity 开时 SEMA_IDENTITY 叠在 role 基底之上;任务自带
62
+ * systemPrompt 按同一优先序赢过基底(role 合成规则与 default 场景一致)。宪法由 core 1.243 在 role
63
+ * 层之后结构化追加——此处只产 role-only 形态(guard-free 契约,同 semaIdentityProvider 注释)。
64
+ * 无 systemPrompt 且无品牌时原样返回 core 常量(测试以引用比对锁 bench 同源,不做字符串快照)。
65
+ */
20
66
  export function codePromptProvider(brand) {
67
+ // [1158]/[1161]/[1162] b 案(clay 拍):provider 供给的字节 core 永不改写(provenance 卫,1.329),
68
+ // 所以 known-constant narrowing 够不着 provider 手里的 CODE_SYSTEM_PROMPT——simple 形的「裸底」
69
+ // 由 server 自己按 ctx.promptProfile 选 core 常量(CODE_AGENT_PROMPT=core 1.329 narrowing 的同一
70
+ // 目标常量,引用不复制,[891] 同源铁律)。classic 全链字节等价旧形;行为九段随 pack 走(平形
71
+ // stableSystem/stableBlocks 都不排段;server 从未用 replaceAll)。
21
72
  const roleBase = (ctx) => ctx.userSystemPrompt ?? (ctx.promptProfile === "classic" ? CODE_SYSTEM_PROMPT : CODE_AGENT_PROMPT);
73
+ // Unbranded: plain role layer via the string hook — core keeps its own core/role.base section identity,
74
+ // and the reference-equality bench-parity tests keep comparing the exact core constant.
22
75
  if (!brand) {
23
76
  return { stableSystem: (ctx) => roleBase(ctx) };
24
77
  }
78
+ // Branded: same M14 typed form as semaIdentityProvider (identity slot = role-layer replacement with the
79
+ // brand line on top; the base under the brand follows the SAME profile fork — the brand overlay is the
80
+ // legal divergence ([1134] 宪法二类), the base stays core-owned bytes).
25
81
  return {
26
82
  stableBlocks: (ctx) => [
27
83
  { id: "sema/identity", slot: "identity", text: `${SEMA_IDENTITY}\n\n${roleBase(ctx)}` },
28
84
  ],
29
85
  };
30
86
  }
87
+ /** @deprecated [891] 改名 code——一版过渡期保留旧符号(与场景名 alias 同窗退役)。 */
31
88
  export const autonomousPromptProvider = codePromptProvider;
32
89
  export function buildScenarios(deps) {
90
+ // The default scenario filters skills by "default" — NOT by req.scenario (which may be an unknown name
91
+ // that fell back here): the bundle must be a coherent "default" set, matching how main.ts resolves an
92
+ // unknown scenario to "default" for tools/prompt/mcp too (council finding — else default-tagged drop).
93
+ // 抽成具名工厂:`autonomous` 直接复用它取 bundle(工具/技能面与 default 恒等由构造保证,不靠两处
94
+ // 各写一份 assembleCodeTools 参数再祈祷不漂移)。
33
95
  const defaultScenario = (req) => {
96
+ // gap-audit rank-1 BLOCKER: the default agent is the CC agent loop — it MUST have the
97
+ // full-body roster, not just nowTool. core's `assembleCodeTools` (1.161) ships TodoWrite (planning) +
98
+ // the subagent/Task delegation tool (runs on the sub-runner, child ⊆ parent — no escalation) + WebFetch.
99
+ // 🔒 WebFetch is GATED OUT on a multi-tenant deployment (REQUIRE_PRINCIPAL): allowHosts is unset = all PUBLIC,
100
+ // and core says a multi-tenant deployment MUST allowlist (an injected tenant model could exfil via an
101
+ // arbitrary public URL — the SSRF floor only blocks INTERNAL). Single-user TOC keeps it (the user's own box).
102
+ // WebSearch backend resolution: a per-request `body.settings.webSearch` (the user's shell settings) WINS, but
103
+ // ONLY on the single-user host lane (a per-request endpoint/key is a capability config — on multi-tenant a tenant
104
+ // could SSRF via a `searxng` URL pointed at an internal host, so multi-tenant uses ONLY the deployment-env
105
+ // `deps.webSearch`; design/107 axis, mirrors settings.env). Absent both ⇒ WebSearch not assembled (core ships none).
34
106
  const reqWebSearch = deps.requirePrincipal !== true
35
107
  ? webSearchConfigFromSettings(req?.settings?.webSearch)
36
108
  : undefined;
@@ -39,9 +111,29 @@ export function buildScenarios(deps) {
39
111
  tools: [
40
112
  nowTool(),
41
113
  ...assembleCodeTools({
114
+ // [1900]/[1904]:WebFetch 摘要缝——键在场才铸(负控=修前字节形)。
42
115
  ...(deps.webFetchSummarize ? { webFetch: { summarize: deps.webFetchSummarize } } : {}),
116
+ // CC 201 parity: CC 201 makes the two planning families MUTUALLY
117
+ // EXCLUSIVE — with TodoV2 (the Task trio) enabled, TodoWriteTool.isEnabled returns false and the
118
+ // interactive model sees ONE family (TodoWrite survives only as an SDK/non-interactive compat slot).
119
+ // Both-on was the CC 198 posture (live-caught cost: the model wastes a turn comparing the two tools
120
+ // and juggles duplicate state). taskList:true below ⇒ TodoWrite OFF.
43
121
  todoWrite: false,
122
+ // core 1.215 (design/119): the structured task-list family (TaskCreate/TaskGet/TaskUpdate/TaskList —
123
+ // stable ids, status transitions, dependencies); core defaults it OFF, the full-body deployment opts
124
+ // in. Under CC 201 this family is the ONLY planning leg (see todoWrite above).
44
125
  taskList: true,
126
+ // core 1.206 (design/115 P3): `background` exposes CC's `run_in_background` on the Agent tool — the
127
+ // child runs async under an `a*` task id (TaskOutput/TaskStop; ONE "later" completion notification;
128
+ // parent teardown aborts orphans). Same trust envelope as the sync path (child ⊆ parent roster, same
129
+ // rights) — only the scheduling is async, so no posture gate. owner/scope: core 1.365 BREAKING 升必填,
130
+ // 但 core 仍 ctx-first(subagent.js `ctx.taskId ?? bg.owner` / `ctx.principal ?? bg.scope`)——引擎链
131
+ // 每 spawn 恒带 ctx.taskId,这里的值是类型要求的兜底:scope="default" 与引擎链 `principal ?? "default"`
132
+ // 同词([1509] 单租户拼法);owner 哨兵在 ctx.taskId 缺席的病态窗把行锚到无人可匹配的键(fail-closed
133
+ // 方向,default-deny 谓词下不可读,绝不放大)。
134
+ // core 1.364 agentStore = durable 写半场,与 RunnerDeps.backgroundAgentStore 同实例(deps 注入)。
135
+ // core 1.382 checkpointStore/ensureChildSessionDurable = design/153 parked 状态机的「同车必接」
136
+ // 一对([1561] 提货单①②,ScenarioDeps 字段注释详述);两者任一缺席 = 净是 pre-153 行为。
45
137
  subagent: {
46
138
  runner: deps.subRunner,
47
139
  background: {
@@ -52,7 +144,11 @@ export function buildScenarios(deps) {
52
144
  ...(deps.checkpointStore ? { checkpointStore: deps.checkpointStore } : {}),
53
145
  ...(deps.ensureChildSessionDurable ? { ensureChildSessionDurable: deps.ensureChildSessionDurable } : {}),
54
146
  },
147
+ // core 1.287 extraTools seam ([795]/[802]③): per-spawn dynamic tool injection (SendUserFile
148
+ // reaches the delegated-child roster; product still goes through resolveToolSubset).
55
149
  ...(deps.subagentExtraTools ? { extraTools: deps.subagentExtraTools } : {}),
150
+ // 历史复审轴B #3(1.254):extraTools 工厂 throw 的错误 sink——core 契约「absent ⇒ dropped after
151
+ // the generic disclosure」= 部署日志零痕迹,只剩模型面固定 note。接 warn 让故障可观测。
56
152
  ...(deps.subagentExtraTools && deps.logger
57
153
  ? { onExtraToolsError: (err, info) => deps.logger?.warn?.("subagent_extra_tools_error", { ...info, err: err instanceof Error ? err.message : String(err) }) }
58
154
  : {}),
@@ -61,21 +157,41 @@ export function buildScenarios(deps) {
61
157
  }).filter((t) => t.name !== "WebFetch" || deps.requirePrincipal !== true),
62
158
  ],
63
159
  skills: skillsForScenario(deps.skills, "default"),
160
+ // Local/TOC deployment brands the neutral default scenario as Sema (so the local engine answers "who
161
+ // are you" as Sema, not the model's hallucinated identity). Cloud leaves it neutral unless opted in.
64
162
  ...(deps.brandIdentity ? { promptProvider: semaIdentityProvider() } : {}),
65
163
  };
66
164
  };
67
165
  return {
68
166
  default: defaultScenario,
167
+ // [849]→[891] code(原名 autonomous,clay 裁定改名+persona×终验解耦):与 default 完全同 roster
168
+ // (full-body 工具面 + default 技能面原样复用,连 WebFetch 多租户闸/WebSearch 装配都跟着 default
169
+ // 工厂走),只换一轴——role 基底 = core CODE_SYSTEM_PROMPT(CC 编码 persona 蒸馏版,见
170
+ // codePromptProvider)。**不再定死 finalVerification**([891] 解耦:终验是无人值守运行模式旋钮,
171
+ // caller 显式声明,交互态不多烧终验轮)。这是 [891] 起的出厂缺省场景(config DEFAULT_SCENARIO
172
+ // 缺省 "code")——编码产品出厂态对标 CC 出厂态;通用域中性 persona 的 default 保留为显式可选。
173
+ // 刻意走内建、不走 center overlay:overlay 已无 prompt 通道([1053] ScenarioEntry.prompt 直删,场景级提示词=center prompts binding)。
69
174
  code: (req, principal) => ({
70
175
  ...defaultScenario(req, principal),
71
176
  promptProvider: codePromptProvider(deps.brandIdentity === true),
72
177
  }),
178
+ // [891] 兼容 alias(一版过渡,deprecation warn 在 main.ts 解析处):旧语义逐字保留 —— code persona
179
+ // + finalVerification 场景层定死 true(存量 TB harness/部署传 "autonomous" 的行为一根毛不变;
180
+ // 新调用方要终验请显式传 body.finalVerification)。
73
181
  autonomous: (req, principal) => ({
74
182
  ...defaultScenario(req, principal),
75
183
  promptProvider: codePromptProvider(deps.brandIdentity === true),
76
184
  finalVerification: true,
77
185
  }),
78
186
  "code-review": (req) => codeReview(deps, req),
187
+ // Neutral repo-readonly scenario (OA ask): the SAME clone-free read-only repo tools as code-review
188
+ // (repo_tree / repo_read_file / repo_pull_diff over GIT_API_TOKEN) with NO promptProvider — the
189
+ // objective and the center-distributed skills own the output contract. The reviewer framing was
190
+ // never a security control (the boundary is the token's scope + the read-only tool set); it only
191
+ // fought skill-driven outputs (live: oa-repo-scan loaded but the lead still wrote a review).
192
+ // Deliberately NOT the alternative "let a scenario-targeted skill override promptProvider": that
193
+ // would let runtime-distributed content rewrite the deployment-pinned system prompt and break the
194
+ // stablePrompt STABLE→VARIABLE prefix-cache discipline (design/12/17).
79
195
  scan: (req) => {
80
196
  if (!deps.repoClient)
81
197
  throw new HttpError(501, "scan scenario needs GIT_API_BASEURL configured");
@@ -90,8 +206,11 @@ export function buildScenarios(deps) {
90
206
  oa: (req, principal) => {
91
207
  if (!deps.oaApiBaseUrl || !deps.oaServiceToken)
92
208
  throw new HttpError(501, "oa scenario needs OA_API_BASEURL + OA_SERVICE_TOKEN configured");
209
+ // OA enforces the END USER's RBAC from the forwarded principal — without one, every OA call would
210
+ // run unattributed. Refuse rather than silently send a null principal.
93
211
  if (!principal)
94
212
  throw new HttpError(401, "oa scenario requires an authenticated principal (set REQUIRE_PRINCIPAL + x-agent-principal)");
213
+ // 写权限的"开 issue"工具仅当配置了 OA_ISSUE_* 时注入;token/repo 固定,模型只填 title/body。
95
214
  const issueTool = deps.oaIssue
96
215
  ? [createGiteaIssueTool({ ...deps.oaIssue, name: "open_gitea_issue", description: "把用户的 bug/需求开成 Gitea issue 报给老板。只填 title(简洁)/body(现象、影响、复现/建议)。仓库与标签由部署固定。" })]
97
216
  : [];
@@ -101,9 +220,13 @@ export function buildScenarios(deps) {
101
220
  promptProvider: oaPrompt,
102
221
  };
103
222
  },
223
+ // Multi-agent team: pick a template, the consumer (OA) injects business context, we run it.
224
+ // Templates resolve from the live registry (`getTeam`) = BUILTIN_TEAMS overridden/extended by the
225
+ // sema registry at runtime (applyEffective → registerTeams), so a team is config-driven; built-ins
226
+ // are the fallback when the center supplies none.
104
227
  team: (req) => {
105
228
  const name = typeof req.team === "string" ? req.team : "default";
106
- const template = getTeam(name);
229
+ const template = getTeam(name); // built-ins, overridden/extended by the sema registry at runtime
107
230
  if (!template) {
108
231
  throw new HttpError(404, `unknown team "${name}" (available: ${teamNames().join(", ")})`);
109
232
  }
@@ -117,16 +240,20 @@ export function buildScenarios(deps) {
117
240
  },
118
241
  };
119
242
  }
243
+ /** Resolve the scenario for a request (falls back to `default`). */
120
244
  export function selectScenario(scenarios, name) {
121
245
  return (name && scenarios[name]) || scenarios.default;
122
246
  }
247
+ /** 内建六场景详情。default/autonomous/team 工厂对良性请求无副作用可真调(拿真实工具名单);code-review/scan/oa 是
248
+ * fail-loud 语义(缺 GIT_API/OA 配置/principal 即 throw)→ 探针失败落静态表兜底(表↔工厂一致性由测试锁:
249
+ * 测试喂 fake deps 真调工厂对账工具名)。enabled 对内建恒 true(约定②)。 */
123
250
  export function builtinScenarioDetails(scenarios, deps) {
124
251
  const probe = (name, req, principal, fallback) => {
125
252
  try {
126
253
  return (scenarios[name]?.(req, principal)?.tools ?? []).map((t) => t.name);
127
254
  }
128
255
  catch {
129
- return fallback;
256
+ return fallback; // 工厂 fail-loud(部署未配该场景的后端)→ 静态名单(web 仍能展示工具面选项)
130
257
  }
131
258
  };
132
259
  const REPO_TOOLS = ["repo_tree", "repo_read_file", "repo_pull_diff", "Now"];
@@ -145,6 +272,8 @@ export function builtinScenarioDetails(scenarios, deps) {
145
272
  team: mk("team", "多智能体团队圆桌(模板成员+synthesizer,模板可由 registry 配置)", "team", probe("team", {}, undefined, ["run_team"]), "团队协调者提示词(圆桌纪律+合成流程)"),
146
273
  };
147
274
  }
275
+ /** center 条目详情(有效性判定与 centerScenarios 完全同款:无效条目既不进 overlay 也不进详情——
276
+ * 保证约定①「详情显示的来源=运行实际用的定义」永不错位)。 */
148
277
  export function centerScenarioDetails(specs, builtinNames) {
149
278
  const out = {};
150
279
  for (const spec of specs ?? []) {
@@ -158,9 +287,11 @@ export function centerScenarioDetails(specs, builtinNames) {
158
287
  name: spec.name,
159
288
  source: "center",
160
289
  builtin: builtinNames.includes(spec.name),
161
- summary: "",
290
+ summary: "", // center spec 无 notes 字段(回落空串;registry 侧加 notes 后在此透传)
162
291
  toolset: spec.toolset,
163
292
  tools: spec.toolset === "repo-readonly" ? ["repo_tree", "repo_read_file", "repo_pull_diff", "Now"] : ["Now"],
293
+ // [1053] ScenarioEntry.prompt 已删(scenario 级提示词=center prompts binding 单入口)——center 条目
294
+ // 恒空串;字段本身保留(builtin 条目仍有真值,wire 形不变)。
164
295
  promptSummary: "",
165
296
  enabled: true,
166
297
  };
@@ -182,6 +313,12 @@ const TOOLSETS = {
182
313
  },
183
314
  };
184
315
  export const SCENARIO_NAME_RE = /^[a-z][a-z0-9-]{1,31}$/;
316
+ // ([1053] registry-core 0.10.15:SCENARIO_PROMPT_MAX 随 ScenarioEntry.prompt 一并退役)
317
+ /**
318
+ * Build the center-declared scenario overlay. Invalid specs are SKIPPED with a warning (never fail
319
+ * boot — same posture as skills/teams); valid ones become scenarios keyed by name, ready to be merged
320
+ * OVER the built-ins (center wins). Returns the overlay plus which built-in names it shadows.
321
+ */
185
322
  export function centerScenarios(deps, specs, builtinNames, logger) {
186
323
  const overlay = {};
187
324
  const shadows = [];
@@ -197,6 +334,9 @@ export function centerScenarios(deps, specs, builtinNames, logger) {
197
334
  logger?.warn("sema_registry_scenario_invalid", { name: spec.name, reason: `unknown toolset "${String(spec.toolset)}" (have: ${Object.keys(TOOLSETS).join(", ")})` });
198
335
  continue;
199
336
  }
337
+ // [1053] registry-core 0.10.15:ScenarioEntry.prompt 直删(clay 亲裁)——center 场景的提示词通道收敛为
338
+ // center prompts binding(scenario 维,[1050]①a/[1051]③a);overlay 只组装工具面+技能面,提示词由投影腿
339
+ // (effective 声明数组→core stableBlocks,[1054]③ 已认领)在 binding 落地后统一承载。
200
340
  const name = spec.name;
201
341
  overlay[name] = (req) => ({
202
342
  tools: toolset.build(deps, req),
@@ -217,15 +357,25 @@ function codeReview(deps, req) {
217
357
  const repoTools = repoToolsFor(deps.repoClient, coords);
218
358
  const skills = skillsForScenario(deps.skills, "code-review");
219
359
  const objective = typeof req.objective === "string" ? req.objective : "Review this repository.";
360
+ // Tiering: `council: true` runs the multi-lens council (L1 parallel lenses + L3 arbiter) — for
361
+ // high-value/whole-repo review (~15× tokens). Default = the lead reviews the in-scope files DIRECTLY
362
+ // (cheap, reliable, finishes fast). A live run showed the model self-orchestrates unreliably, so for
363
+ // review (a KNOWN decomposition) the subagent fan-out is CODE-driven here, not left to the model
364
+ // (deterministic + cheaper + cacheable; see design/35). For OPEN-ENDED tasks where the decomposition
365
+ // isn't known, core's `createSubagentTool` (model-driven self-delegation, with maxDepth / isolated
366
+ // context / compressed-report guardrails) is the right tool — wire it in a dedicated scenario then.
220
367
  if (req.council === true) {
221
- const rounds = clampRounds(req.rounds);
368
+ const rounds = clampRounds(req.rounds); // finite-guarded (NaN/±Inf → undefined → council default 1)
222
369
  return {
223
370
  tools: [
224
371
  createCouncilTool(deps.subRunner, repoTools, objective, {
225
372
  metrics: deps.metrics,
226
373
  logger: deps.logger,
227
- debate: req.debate === true,
374
+ debate: req.debate === true, // L1+L2+L3 (peer debate) vs L1+L3
375
+ // OA cost/coverage dial: an optional structured lens COUNT (clamped to [1,6] + NaN-guarded in pickLenses;
376
+ // absent = all 6 → zero regression). Per-request, no restart — orthogonal to the lens MODEL (startup env).
228
377
  ...(typeof req.lenses === "number" ? { lensCount: req.lenses } : {}),
378
+ // Caller-settable debate rounds (finite, clamped [1,3]; absent/NaN = default 1). Only when debate=true.
229
379
  ...(rounds !== undefined ? { rounds } : {}),
230
380
  }),
231
381
  ],
@@ -237,12 +387,24 @@ function codeReview(deps, req) {
237
387
  }
238
388
  const reviewBody = "Produce ONE prioritized review: a short summary, then findings grouped by severity " +
239
389
  "(blocker / major / minor), each with `path:line`, the problem, and a concrete fix. Cite real code — never invent files or symbols.";
390
+ // Each provider supplies ONLY its stable base; `stablePrompt` enforces STABLE→VARIABLE ordering
391
+ // (base, then userSystemPrompt, then per-user memoryBlock) so the prefix-cache discipline can't be
392
+ // got wrong by hand (design/12, design/17).
393
+ /** Default: the lead reads the in-scope files and reviews them directly. */
240
394
  const directReviewerPrompt = stablePrompt("You are a senior code reviewer. Call repo_tree to map the repository, then repo_read_file to read " +
241
395
  "the files in scope, then review them yourself. " +
242
396
  reviewBody);
397
+ /** Council mode: the lead just runs the (code-driven) council tool and returns its result verbatim. */
243
398
  const coordinatorPrompt = stablePrompt("You coordinate a code-review council. Call `run_council` exactly once (no arguments). When it " +
244
399
  "returns the arbitrated review, output that review as your final answer VERBATIM — do not " +
245
400
  "summarize, shorten, or rewrite it.");
401
+ /**
402
+ * Personalization seam: merge the caller's own skills AFTER the scenario's, with
403
+ * SCENARIO-WINS on a name clash — the security baseline (scenario/center skills) can never be shadowed
404
+ * by user content. Duplicate names within the user list keep the first. Clashes are logged for audit
405
+ * (silent drops would make "my skill didn't fire" undebuggable). Input is already shape/size-validated
406
+ * by the HTTP layer (validateUserSkills); this stays pure merge policy.
407
+ */
246
408
  export function mergeUserSkills(scenarioSkills, userSkills, logger) {
247
409
  if (!userSkills || userSkills.length === 0)
248
410
  return scenarioSkills;
@@ -254,13 +416,24 @@ export function mergeUserSkills(scenarioSkills, userSkills, logger) {
254
416
  dropped.push(s.name);
255
417
  continue;
256
418
  }
257
- reserved.add(s.name);
419
+ reserved.add(s.name); // also dedupes within the user list itself (first wins)
258
420
  out.push(s);
259
421
  }
260
422
  if (dropped.length > 0)
261
423
  logger?.warn("user_skills_dropped", { reason: "name reserved by scenario (or duplicate)", names: dropped });
262
424
  return out;
263
425
  }
426
+ /**
427
+ * resolveSpec 的执法入口(指派为默认、body.scenario 可换但限 allowlist)。返回本请求的
428
+ * 生效场景名(未做 unknown→default 回退——那是 resolveSpec 既有职责,保持单点)。
429
+ *
430
+ * - body.scenario 显式给出:allowlist 非空且集外 ⇒ typed 拒绝(400 `scenario_not_allowed`,附 allowlist
431
+ * ——机器码归 wire、人话归壳/web);集内 ⇒ 用户主动切换赢。allowlist 为空(无 ruling / 该 principal
432
+ * 三层皆无指派 / caps 面故障)⇒ 无治理约束,现状放行(与「null 落兜底链」同一语义:分配面未覆盖 =
433
+ * 不收紧,恒不比没有治理时更宽;caps 故障不把用户锁死在 default——场景切换不是权限放大面,fail-open
434
+ * 到现状,与 workflows 面的 fail-closed 是刻意的 posture 差异,见 runtime-caps-resolver)。
435
+ * - body.scenario 未给:ruling 胜者 ⇒ 指派为默认;无胜者 ⇒ defaultScenario 现状链。
436
+ */
264
437
  export function gateScenarioRequest(ruling, bodyScenario, defaultScenario) {
265
438
  if (typeof bodyScenario === "string") {
266
439
  const allowed = ruling?.allowlist ?? [];
@@ -1,12 +1,17 @@
1
1
  import type { ToolSpec } from "@sema-agent/core";
2
2
  import { type SandboxImageResolver } from "../per-task-image.js";
3
3
  import type { ImageViewer, ImageIndexEntry, ImageListFilter } from "../plugins/store-contracts.js";
4
+ /** The catalog slice the tool needs: fail-closed resolution + the viewer-scoped published listing. */
4
5
  export interface EnvironmentCatalog extends SandboxImageResolver {
5
6
  list(filter: ImageListFilter): Promise<{
6
7
  entries: ImageIndexEntry[];
7
8
  nextCursor: string | null;
8
9
  }>;
9
10
  }
11
+ /** Session-keyed selected PROFILE (intent). Mirrors PerTaskImageRegistry's bounded-eviction shape, but holds
12
+ * the profile string so every subsequent task re-resolves fail-closed (re-admit discipline). In-memory —
13
+ * honest v1 boundary: a worker restart drops the selection (the model can re-select; nothing fails closed
14
+ * the wrong way, the session just falls back to the worker default image). */
10
15
  export declare class SessionEnvironmentSelection {
11
16
  private readonly maxEntries;
12
17
  private readonly map;
@@ -17,6 +22,8 @@ export declare class SessionEnvironmentSelection {
17
22
  export declare function selectEnvironmentTool(deps: {
18
23
  catalog: EnvironmentCatalog;
19
24
  selection: SessionEnvironmentSelection;
25
+ /** Trusted viewer scope derived from the AUTH channel at spec-prep (never from tool args/ctx besides the
26
+ * read-only ctx.principal the Runner threads) — built per-execute so operator/tenant scoping stays live. */
20
27
  viewerFor: (principal: string | undefined) => ImageViewer;
21
28
  }): ToolSpec;
22
29
  //# sourceMappingURL=select-environment-tool.d.ts.map
@@ -1,5 +1,31 @@
1
+ /**
2
+ * RFC A2 (docs/design/ENV-SELECT-AND-REGION-SOURCE.md) — the model-facing `SelectEnvironment` tool.
3
+ * A 切片先行;挂载路线 = RFC 判定②(a):deployment 经 `spec.tools` 注入(同 lsp/
4
+ * 自定义工具),core 收编等真用起来再谈。
5
+ *
6
+ * Backend = the EXISTING trusted admission chain, nothing new:
7
+ * - discovery: `ImageIndex.list({latestOnly, status:'published', viewer})` — the SAME per-principal
8
+ * visibility the `/v1/images/select` catalog applies (SQL-baked, never caller enumeration).
9
+ * - selection: `resolveSandboxImageRef` (fail-closed profile→digest re-admission).
10
+ * - binding: a session-keyed PROFILE (intent — never a digest) the next task's resolveSpec re-resolves
11
+ * FAIL-CLOSED, exactly like a body-supplied `sandboxImageProfile`. Storing the profile (not the ref)
12
+ * keeps the re-admit discipline intact: every task re-resolves LIVE, a stale digest can never ride a
13
+ * session binding past admission.
14
+ *
15
+ * Boundary contract (verbatim in the tool's model-facing note): a binding change takes
16
+ * effect ONLY at a task boundary; any child (including design/129 session-scoped background children)
17
+ * inherits the binding at its spawn moment and never drifts mid-flight. This tool therefore only writes
18
+ * the session-profile store — the RUNNING task's sandbox is untouched.
19
+ *
20
+ * 409-style self-correction: a failed selection returns `missing` + the viewer-visible catalog
21
+ * (tenant-neutral profile names only — the list enters model context).
22
+ */
1
23
  import { Type } from "typebox";
2
24
  import { resolveSandboxImageRef } from "../per-task-image.js";
25
+ /** Session-keyed selected PROFILE (intent). Mirrors PerTaskImageRegistry's bounded-eviction shape, but holds
26
+ * the profile string so every subsequent task re-resolves fail-closed (re-admit discipline). In-memory —
27
+ * honest v1 boundary: a worker restart drops the selection (the model can re-select; nothing fails closed
28
+ * the wrong way, the session just falls back to the worker default image). */
3
29
  export class SessionEnvironmentSelection {
4
30
  maxEntries;
5
31
  map = new Map();
@@ -24,6 +50,7 @@ const capList = (caps) => Object.entries(caps ?? {})
24
50
  .map(([k]) => k);
25
51
  async function availableProfiles(catalog, viewer) {
26
52
  const { entries } = await catalog.list({ ...viewer, status: "published", latestOnly: true, limit: 100 });
53
+ // tenant-neutral: profile name + boolean capability keys only (this list enters model context).
27
54
  return entries.map((e) => ({ profile: e.profile, capabilities: capList(e.capabilities) }));
28
55
  }
29
56
  export function selectEnvironmentTool(deps) {
@@ -35,6 +62,7 @@ export function selectEnvironmentTool(deps) {
35
62
  "The change takes effect for the NEXT task/subagent — the current sandbox is not swapped mid-run; " +
36
63
  "running work keeps the environment it started with, and artifacts hand over via the workspace/git. " +
37
64
  "Use this instead of hand-installing SDK-level toolchains (Android SDK, JVM, browsers, …).",
65
+ // set-to-value on a session-keyed map: repeat-safe with the same args.
38
66
  effect: "idempotent",
39
67
  parameters: Type.Object({
40
68
  profile: Type.Optional(Type.String({ description: "Target image profile name (from the available list). Omit to discover." })),
@@ -59,6 +87,7 @@ export function selectEnvironmentTool(deps) {
59
87
  index: deps.catalog,
60
88
  });
61
89
  if (!resolved.ok) {
90
+ // self-correction payload: the error + the viewer's own catalog. Model retries with a valid one.
62
91
  const available = await availableProfiles(deps.catalog, viewer);
63
92
  return {
64
93
  content: JSON.stringify({ error: resolved.message, ...(caps.length > 0 ? { missing: caps } : {}), available }),
@@ -66,6 +95,7 @@ export function selectEnvironmentTool(deps) {
66
95
  };
67
96
  }
68
97
  if (!sessionId) {
98
+ // outside a Runner session there is nothing to bind to — honest failure, not a silent success.
69
99
  return { content: JSON.stringify({ error: "no session to bind the environment selection to" }), details: { mode: "select-failed" } };
70
100
  }
71
101
  deps.selection.set(sessionId, a.profile);
@@ -1,10 +1,12 @@
1
1
  import type { SubagentSpawnContext, ToolSpec } from "@sema-agent/core";
2
2
  import type { IssuedFileLink } from "../plugins/send-user-file.js";
3
+ /** The frame the web/shell renders as a file card. Rides the durable events tail (replayable). */
3
4
  export interface FileLinkFrame {
4
5
  type: "file_link";
5
6
  url: string;
6
7
  filename: string;
7
8
  size: number;
9
+ /** 0 = permanent (public track). */
8
10
  ttlSec: number;
9
11
  status: "normal" | "proactive";
10
12
  caption?: string;
@@ -14,15 +16,25 @@ export interface SendUserFileRunContext {
14
16
  taskId: string;
15
17
  emit: (frame: FileLinkFrame) => Promise<void>;
16
18
  }
19
+ /** Per-run ALS carrier (QuestionCoordinator pattern): run legs wrap their body via runWithContext; the tool
20
+ * recovers the ambient emit at execute time. No pending state, no respond face — emission is one-way. */
17
21
  export declare class SendUserFileEmitter {
18
22
  private readonly als;
19
23
  runWithContext<T>(ctx: SendUserFileRunContext, fn: () => Promise<T>): Promise<T>;
24
+ /** Emit into the ambient run's events tail. Returns false when no run context is ambient (a leg not wrapped —
25
+ * the caller reports "sent but not surfaced live" honestly rather than pretending). */
20
26
  emit(frame: FileLinkFrame): Promise<boolean>;
21
27
  }
28
+ /** Per-call caps (bounded model-facing surface; the issuer has its own ttl/name guards). */
22
29
  export declare const SEND_USER_FILE_MAX_FILES = 10;
23
30
  export declare const SEND_USER_FILE_MAX_BYTES: number;
24
31
  export declare const SEND_USER_FILE_MAX_CAPTION = 500;
25
32
  export declare function sendUserFileTool(deps: {
33
+ /** Lane-scoped send: read/stat the file where the lane lives, upload, mint the user-facing link.
34
+ * Enforces the size cap itself (host: fs stat; sandbox: in-sandbox stat BEFORE presigning). Throws
35
+ * typed Errors (not-found / too-large / no-sandbox) — surfaced verbatim per file in the tool result.
36
+ * `principal` = core's VERIFIED ToolExecuteContext.principal — the multi-tenant SCOPE the issuer keys the
37
+ * hashed key segment on and the ledger records (absent on single-user lanes → the "_" sentinel). */
26
38
  send: (path: string, ctx: {
27
39
  taskId?: string;
28
40
  sessionId?: string;
@@ -31,8 +43,29 @@ export declare function sendUserFileTool(deps: {
31
43
  emitter: SendUserFileEmitter;
32
44
  }): ToolSpec;
33
45
  export declare const SEND_USER_FILE_TOOL_NAME = "SendUserFile";
46
+ /**
47
+ * Build the `SubagentToolOptions.extraTools` factory that injects SendUserFile into delegated-child rosters —
48
+ * WITH the two gates the bare `() => [spec]` wiring lacked:
49
+ *
50
+ * F1 (HIGH, codex): the subRunner carries NO tool policy and core's child spec does not inherit the parent's
51
+ * `toolPolicy`, so an extraTools-injected SendUserFile BYPASSED the deployment approval gate (evidence: with
52
+ * `APPROVAL_DENY=SendUserFile` the top-level call is denied but a delegated child could still call it). Until
53
+ * core lands a child-policy propagation seam, the CONSERVATIVE server-side stopgap is a deployment-policy
54
+ * PRE-CHECK: if the deployment's approval face gates SendUserFile at all (deny OR ask — approvalDeny /
55
+ * approvalRequire / approvalNeverAuto, matched in canonical space exactly like src/approval.ts), the factory
56
+ * injects NOTHING. deny obviously must not reach children; ask-gated is ALSO withheld because the child leg has
57
+ * no policy to route the ask (injecting would silently auto-allow — the exact bypass). The gate is read LIVE per
58
+ * spawn (a getter, not a boot snapshot) so center/env hot-applied governance is honored, mirroring how the
59
+ * per-request approval baseline reads live config. A deployment with no gate intent is unchanged.
60
+ *
61
+ * F2 (MED, codex): read-only builtin agents (Explore/Plan) must NOT get SendUserFile — a read-only agent that
62
+ * can read sensitive files AND mint public links off them breaks the read-only posture (their denyTools sets
63
+ * predate this tool, so core's resolveToolSubset would let it through). `ctx.agentType` carries the spawned
64
+ * definition's name (core subagent.js); membership in core's builtin catalog ⇒ inject nothing for that spawn.
65
+ */
34
66
  export declare function subagentSendUserFileExtraTools(deps: {
35
67
  spec: ToolSpec;
68
+ /** LIVE deployment approval face (config.approvalDeny/approvalRequire/approvalNeverAuto) — evaluated per spawn. */
36
69
  approvalGate: () => {
37
70
  deny?: string[];
38
71
  require?: string[];
@@ -1,11 +1,39 @@
1
+ /**
2
+ * SendUserFile — the tool face (slice 2 of the dual-track public-link lane; the issuer core is
3
+ * src/plugins/send-user-file.ts, shipped in 1.186.0).
4
+ *
5
+ * TOOL CONTRACT = the real CC-web schema (operator-provided verbatim, 2026-07-14 — CC-parity discipline):
6
+ * files: string[] (required — paths, absolute or relative to the task cwd; ONE file still rides an array)
7
+ * status: "normal" | "proactive" (required — proactive = pushed while the user is away; normal = replying)
8
+ * caption?: string (one-line context, e.g. "the failing line is 42")
9
+ * display?: "render" | "attach" (render = inline in the side panel; attach = download card; omitted = by type)
10
+ * Returns DELIVERY metadata only — never the file content, and (deliberately) not the URL either: the link is
11
+ * a capability secret for the USER's pane; echoing it into model context invites mis-transcription + leakage.
12
+ *
13
+ * Delivery = a `file_link` frame on the run's durable events tail (same posture as `question`/`suggestions`:
14
+ * the shell/web renders it; it is NEVER re-fed to a model). Emission recovers the per-run emit sink via
15
+ * AsyncLocalStorage, the exact QuestionCoordinator/ElicitationCoordinator pattern — sub-tasks inherit the
16
+ * top-level run's frame.
17
+ *
18
+ * File source: the injected `send` seam — one path string in, an issued link out. Two lane shapes (v2,
19
+ * clay ruling 2026-07-14): HOST lane reads the local disk and uploads server-side (single-user only —
20
+ * host-lane multi-tenant is permanently closed); SANDBOX lanes (e2b/k8s) stat + `curl -T` INSIDE the
21
+ * sandbox against a server-presigned single-object PUT (bytes never relay through the server, creds never
22
+ * enter the sandbox; the sandbox's own filesystem IS the tenant boundary, so any tenant may use it).
23
+ * Lanes without a wired send face simply don't get the tool (honest seam, no fake-live).
24
+ */
1
25
  import { AsyncLocalStorage } from "node:async_hooks";
2
26
  import { Type } from "typebox";
3
27
  import { builtinAgentDefinitions, canonicalToolName } from "@sema-agent/core";
28
+ /** Per-run ALS carrier (QuestionCoordinator pattern): run legs wrap their body via runWithContext; the tool
29
+ * recovers the ambient emit at execute time. No pending state, no respond face — emission is one-way. */
4
30
  export class SendUserFileEmitter {
5
31
  als = new AsyncLocalStorage();
6
32
  runWithContext(ctx, fn) {
7
33
  return this.als.run(ctx, fn);
8
34
  }
35
+ /** Emit into the ambient run's events tail. Returns false when no run context is ambient (a leg not wrapped —
36
+ * the caller reports "sent but not surfaced live" honestly rather than pretending). */
9
37
  async emit(frame) {
10
38
  const ctx = this.als.getStore();
11
39
  if (!ctx)
@@ -14,8 +42,9 @@ export class SendUserFileEmitter {
14
42
  return true;
15
43
  }
16
44
  }
45
+ /** Per-call caps (bounded model-facing surface; the issuer has its own ttl/name guards). */
17
46
  export const SEND_USER_FILE_MAX_FILES = 10;
18
- export const SEND_USER_FILE_MAX_BYTES = 100 * 1024 * 1024;
47
+ export const SEND_USER_FILE_MAX_BYTES = 100 * 1024 * 1024; // 100 MiB per file — issuer PUT is a single upload
19
48
  export const SEND_USER_FILE_MAX_CAPTION = 500;
20
49
  export function sendUserFileTool(deps) {
21
50
  return {
@@ -59,6 +88,7 @@ export function sendUserFileTool(deps) {
59
88
  const sendCtx = {
60
89
  ...(ctx.taskId !== undefined ? { taskId: ctx.taskId } : {}),
61
90
  ...(ctx.sessionId !== undefined ? { sessionId: ctx.sessionId } : {}),
91
+ // scope passthrough (multi-tenant governance): core's VERIFIED principal — never a model-supplied value.
62
92
  ...(ctx.principal !== undefined ? { principal: ctx.principal } : {}),
63
93
  };
64
94
  for (const path of a.files) {
@@ -77,10 +107,17 @@ export function sendUserFileTool(deps) {
77
107
  sent.push({ filename: link.filename, size: link.size, surfacedLive });
78
108
  }
79
109
  catch (e) {
110
+ // 修4 defense-in-depth: per-file errors are spliced VERBATIM into the model-visible result below —
111
+ // the send chain already redacts its own capability URLs (redactPutUrl) and the ledger throws
112
+ // coordinate-free incident codes, but any URL that still survives an unforeseen path (adapter echo,
113
+ // store error body) must not reach model context, where the public endpoint transparency in
114
+ // capabilities would make it a reconstructable permanent link. Scrub generically; the useful typed
115
+ // errors (not-found / cap / no-sandbox) carry no URLs and pass through untouched.
80
116
  const raw = e instanceof Error ? e.message : String(e);
81
117
  failed.push({ file: path, error: raw.replace(/https?:\/\/\S+/gi, "<url>") });
82
118
  }
83
119
  }
120
+ // Delivery metadata ONLY (CC contract) — no URL, no content, into model context.
84
121
  const summary = `sent ${sent.length}/${a.files.length} file(s)` +
85
122
  (failed.length > 0 ? `; FAILED: ${failed.map((f) => `${f.file} (${f.error})`).join("; ")}` : "");
86
123
  return {
@@ -91,13 +128,40 @@ export function sendUserFileTool(deps) {
91
128
  },
92
129
  };
93
130
  }
131
+ // ── subagent extraTools gate(codex F1/F2,core 1.287 seam 的 server 半场守门)────────────────────────
94
132
  export const SEND_USER_FILE_TOOL_NAME = "SendUserFile";
133
+ /** core's read-only builtin agents (Explore/Plan) — derived from core's OWN builtinAgentDefinitions so the set
134
+ * cannot drift when core adds/renames a read-only builtin. Every entry of that catalog is a read-only agent by
135
+ * contract (their systemPrompts forbid ALL writes and their denyTools strip the write tools). */
95
136
  const READONLY_BUILTIN_AGENT_TYPES = new Set(builtinAgentDefinitions().map((d) => d.name));
137
+ /**
138
+ * Build the `SubagentToolOptions.extraTools` factory that injects SendUserFile into delegated-child rosters —
139
+ * WITH the two gates the bare `() => [spec]` wiring lacked:
140
+ *
141
+ * F1 (HIGH, codex): the subRunner carries NO tool policy and core's child spec does not inherit the parent's
142
+ * `toolPolicy`, so an extraTools-injected SendUserFile BYPASSED the deployment approval gate (evidence: with
143
+ * `APPROVAL_DENY=SendUserFile` the top-level call is denied but a delegated child could still call it). Until
144
+ * core lands a child-policy propagation seam, the CONSERVATIVE server-side stopgap is a deployment-policy
145
+ * PRE-CHECK: if the deployment's approval face gates SendUserFile at all (deny OR ask — approvalDeny /
146
+ * approvalRequire / approvalNeverAuto, matched in canonical space exactly like src/approval.ts), the factory
147
+ * injects NOTHING. deny obviously must not reach children; ask-gated is ALSO withheld because the child leg has
148
+ * no policy to route the ask (injecting would silently auto-allow — the exact bypass). The gate is read LIVE per
149
+ * spawn (a getter, not a boot snapshot) so center/env hot-applied governance is honored, mirroring how the
150
+ * per-request approval baseline reads live config. A deployment with no gate intent is unchanged.
151
+ *
152
+ * F2 (MED, codex): read-only builtin agents (Explore/Plan) must NOT get SendUserFile — a read-only agent that
153
+ * can read sensitive files AND mint public links off them breaks the read-only posture (their denyTools sets
154
+ * predate this tool, so core's resolveToolSubset would let it through). `ctx.agentType` carries the spawned
155
+ * definition's name (core subagent.js); membership in core's builtin catalog ⇒ inject nothing for that spawn.
156
+ */
96
157
  export function subagentSendUserFileExtraTools(deps) {
97
158
  const canonical = canonicalToolName(SEND_USER_FILE_TOOL_NAME);
98
159
  return (ctx) => {
160
+ // F2: read-only builtin child (Explore/Plan) — never inject.
99
161
  if (ctx.agentType !== undefined && READONLY_BUILTIN_AGENT_TYPES.has(ctx.agentType))
100
162
  return [];
163
+ // F1: deployment policy gates SendUserFile (deny/ask) — withhold from ALL children (fail-closed stopgap
164
+ // until core propagates the parent toolPolicy into child specs). Canonical-space match (S8 discipline).
101
165
  const gate = deps.approvalGate();
102
166
  const gated = [...(gate.deny ?? []), ...(gate.require ?? []), ...(gate.neverAuto ?? [])].some((t) => canonicalToolName(t) === canonical);
103
167
  return gated ? [] : [deps.spec];