@sema-agent/server 1.323.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 +58 -2
  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,15 +1,36 @@
1
+ /**
2
+ * Request-body → TaskSpec field normalizers (shell-host contract). Kept out of main.ts (which auto-runs the service
3
+ * on import) so they are unit-testable in isolation. Each is DEFENSIVE: a RESUME re-runs resolveSpec from the stored
4
+ * body WITHOUT the HTTP-layer 400 validation, so a malformed value must fall back to a safe default, never throw.
5
+ */
1
6
  import { isThinkingLevel } from "@sema-agent/core";
2
7
  import { taskWallClockSec } from "./task-workflow.js";
8
+ /**
9
+ * E12 — normalize `body.suggestNextPrompts` → `TaskSpec.suggestNextPrompts`. `true` = on with core defaults
10
+ * (count 3, cheap role); an object tunes `count` (clamped 1..10) / `role` (a free string — core validates it against
11
+ * `ModelRole`, an unknown role falls back to the task model). `false` / absent / non-object / garbage ⇒ undefined (off).
12
+ */
3
13
  export function normalizeSuggestNextPrompts(v) {
4
14
  if (v === true)
5
15
  return true;
6
16
  if (v == null || typeof v !== "object" || Array.isArray(v))
7
- return undefined;
17
+ return undefined; // false / absent / non-object / array ⇒ off
8
18
  const o = v;
19
+ // DROP a non-finite or <1 count (treat as absent → core's default), matching the HTTP layer which 400s count<1 — so
20
+ // submit-reject and resume-normalize never diverge into an unintended count. Clamp a large count down to 10.
9
21
  const count = typeof o.count === "number" && Number.isFinite(o.count) && o.count >= 1 ? Math.min(10, Math.floor(o.count)) : undefined;
10
22
  const role = typeof o.role === "string" && o.role ? o.role : undefined;
11
23
  return { ...(count !== undefined ? { count } : {}), ...(role ? { role } : {}) };
12
24
  }
25
+ /**
26
+ * design/131 (core 1.246) — normalize `body.resilience` → `TaskSpec.resilience`. INTENT flags only:
27
+ * `allowDegrade:false` / `allowFailover:false` let a bench/eval or critical task say "fail rather than fall back".
28
+ * `bypassBreaker` is OPERATOR-FACING (不给 wire 用户直开 — it punches through a shared circuit breaker,
29
+ * which exists to protect the provider): honored only when the request principal is an explicit operator; silently
30
+ * dropped otherwise (not a 4xx — resume re-runs this without HTTP validation, and a stripped intent flag degrades
31
+ * to today's behavior, core's own "all absent = byte-compat" posture). Only literal booleans pass; all-empty ⇒
32
+ * undefined (never an empty object — keeps the spec byte-identical for non-users).
33
+ */
13
34
  export function normalizeResilience(v, operator) {
14
35
  if (v == null || typeof v !== "object" || Array.isArray(v))
15
36
  return undefined;
@@ -21,9 +42,20 @@ export function normalizeResilience(v, operator) {
21
42
  };
22
43
  return Object.keys(out).length > 0 ? out : undefined;
23
44
  }
45
+ /**
46
+ * design/133 (core 1.251) — normalize `body.attachments` → `TaskSpec.attachments`. Core's contract is
47
+ * literal-true unions ("关闭=删 key,勿传 false"): only `true` (or, for changedFiles, an object with a sane
48
+ * `maxFiles`) survives; `false`/garbage per key is DROPPED, not forwarded. maxFiles clamped 1..100 (core caps its
49
+ * own stat cost at 20 by default; the clamp only guards against a resume replaying a wild persisted value).
50
+ * All-empty ⇒ undefined. NB resume audit: our persisted body is the FULL request JSON and resolveSpec
51
+ * is the single translation point, so consuming the field here IS the whitelist inclusion — nothing else to add.
52
+ */
24
53
  export function normalizeAttachments(v) {
25
54
  if (v == null || typeof v !== "object" || Array.isArray(v))
26
55
  return undefined;
56
+ // 历史复审轴B #1(1.254):白名单曾落后 core 五键——尤其 agentListing/skillsListing 是 core DEFAULT-ON
57
+ // (explicit false 才关),旧名单静默丢 false = wire 上唯一无法表达关闭的面(调用方 200 以为生效)。
58
+ // 两键按 boolean 透传(含 false);budgetUsd/mcpInstructions literal-true 同族;todoReminderMode 枚举。
27
59
  const o = v;
28
60
  let changedFiles;
29
61
  if (o.changedFiles === true)
@@ -37,6 +69,8 @@ export function normalizeAttachments(v) {
37
69
  ...(o.todoReminder === true ? { todoReminder: true } : {}),
38
70
  ...(changedFiles !== undefined ? { changedFiles } : {}),
39
71
  ...(o.planModeReminder === true ? { planModeReminder: true } : {}),
72
+ // core 1.253 G1: post-compaction background-task recap + deferred-tools boundary notice —
73
+ // same literal-true contract as the rest of the family (both are one-shot/opt-in on the core side).
40
74
  ...(o.backgroundTasks === true ? { backgroundTasks: true } : {}),
41
75
  ...(o.toolsDelta === true ? { toolsDelta: true } : {}),
42
76
  ...(o.todoReminderMode === "baseline" || o.todoReminderMode === "off" ? { todoReminderMode: o.todoReminderMode } : {}),
@@ -47,18 +81,30 @@ export function normalizeAttachments(v) {
47
81
  };
48
82
  return Object.keys(out).length > 0 ? out : undefined;
49
83
  }
84
+ /**
85
+ * [833] rewind exclusive mode (core 1.292) — normalize `body.resumeAtMode` → `TaskSpec.resumeAtMode`. DEFENSIVE
86
+ * (the resume path re-runs resolveSpec WITHOUT the HTTP 400 gate): only the two enum values survive, and only when
87
+ * the resume-at handle actually RESOLVED (core ignores the field without `resumeAt`; keep the spec tight instead of
88
+ * shipping a dangling qualifier). Absent/garbage ⇒ undefined = core default "at" (zero regression).
89
+ */
50
90
  export function normalizeResumeAtMode(v, resumeAtResolved) {
51
91
  if (!resumeAtResolved)
52
92
  return undefined;
53
93
  return v === "at" || v === "before" ? v : undefined;
54
94
  }
95
+ // ─── [876] per-task subagents(core 1.295 `TaskSpec.agents`)──────────────────────────────────────────────
96
+ /** [876] 防御上限:一份请求最多带多少个 agent 定义。core 侧无上限;这里封一个防御值 —— 每个定义都进
97
+ * 系统提示(whenToUse/skills/systemPrompt 全是 prompt 载荷),不设界就是 per-turn token 成本洞(与
98
+ * MAX_USER_SKILLS 同轴)。32 足够覆盖 CC 式 `.claude/agents/` 全家桶还有余量。 */
55
99
  export const MAX_TASK_AGENTS = 32;
100
+ // [876] 每字段防御上限(cross-review 抓获:无上限的 prompt 载荷字段=32 条帽封不住的 per-turn token 成本洞,
101
+ // maxTurns 无顶=运行成本洞)。skill 三上限与 server.ts validateUserSkills 同值(64/1024/1MiB,engine 同一载荷面)。
56
102
  const MAX_AGENT_NAME_CHARS = 64;
57
- const MAX_AGENT_TEXT_CHARS = 4_096;
103
+ const MAX_AGENT_TEXT_CHARS = 4_096; // whenToUse/whenToUseLean/observer/observerMessage
58
104
  const MAX_AGENT_SYSTEM_PROMPT_CHARS = 65_536;
59
- const MAX_AGENT_TOOLS = 64;
105
+ const MAX_AGENT_TOOLS = 64; // allowTools/denyTools entries
60
106
  const MAX_AGENT_TOOL_NAME_CHARS = 128;
61
- const MAX_AGENT_SKILLS = 10;
107
+ const MAX_AGENT_SKILLS = 10; // 与 MAX_USER_SKILLS 同轴
62
108
  const MAX_AGENT_SKILL_CONTENT_CHARS = 1_048_576;
63
109
  const MAX_AGENT_MAX_TURNS = 1_000;
64
110
  const boundedString = (max) => (v) => typeof v === "string" && v.length <= max;
@@ -66,6 +112,9 @@ const toolList = (v) => Array.isArray(v) &&
66
112
  v.length <= MAX_AGENT_TOOLS &&
67
113
  v.every((x) => typeof x === "string" && x.length > 0 && x.length <= MAX_AGENT_TOOL_NAME_CHARS);
68
114
  const plainObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
115
+ /** SkillSpec 闭合白名单(core dist/core/types.d.ts:169:name/description/content 必填 + manifest?/files?)。
116
+ * files 条目必须 {path, content} 双 string —— core synthetic-tools 直接迭代 `f.path`,一个 null 条目就是
117
+ * 运行期 crash(cross-review 抓获);未知键整条拒(与 agent 键同姿势)。 */
69
118
  const skillOk = (s) => {
70
119
  if (!plainObject(s))
71
120
  return false;
@@ -79,6 +128,8 @@ const skillOk = (s) => {
79
128
  return false;
80
129
  if (typeof s.content !== "string" || s.content.length === 0 || s.content.length > MAX_AGENT_SKILL_CONTENT_CHARS)
81
130
  return false;
131
+ // SkillManifest 闭合(core types.d.ts:163:allowTools+lineageId 必填)—— 空对象/畸形 allowTools 会晚失败
132
+ // 在 core 激活技能时 `manifest.allowTools.map(...)`(round-2 cross-review)。
82
133
  if (s.manifest !== undefined) {
83
134
  const m = s.manifest;
84
135
  if (!plainObject(m))
@@ -108,6 +159,8 @@ const skillOk = (s) => {
108
159
  }
109
160
  return true;
110
161
  };
162
+ /** MemorySpecInput 闭合白名单(core dist/core/memory.d.ts:92 亲读)。core 的 normalizeMemorySpec 会直接
163
+ * 迭代 `scopes` —— 非数组形状(如 {scopes:{length:1}})在服务门不拦就是 core 运行期异常(cross-review 抓获)。 */
111
164
  const memoryOk = (v) => {
112
165
  if (!plainObject(v))
113
166
  return false;
@@ -127,6 +180,12 @@ const memoryOk = (v) => {
127
180
  return false;
128
181
  return true;
129
182
  };
183
+ /** [876] AgentDefinition 白名单字段表(core 1.295 dist/core/types.d.ts:113 亲读)+ 每字段的形状谓词。
184
+ * ⚠️ `permissionMode` 有意不纳(core 拍,独立批)—— body 里出现按未知键拒,见 taskAgentIssue。
185
+ * `model` 收「已解析真名 string 或带非空 string `id` 的 Model 对象」—— server 不做词表翻译(壳侧已解析,
186
+ * [879]④ 契约);core 对对象形 Model 原样信任不校验(dist/core/roles.js 亲读),空对象 `{}` 会晚失败在
187
+ * 引擎深处,所以最低限 `id` 在门上验。保留名(如与委派工具同名)不在这里镜像 —— core prepare 侧
188
+ * fail-loud `config.agent.reserved_name`(镜像 core 私有清单=漂移风险)。 */
130
189
  const TASK_AGENT_FIELD_SHAPES = {
131
190
  name: {
132
191
  desc: `a non-empty string of at most ${MAX_AGENT_NAME_CHARS} characters`,
@@ -157,6 +216,12 @@ const TASK_AGENT_FIELD_SHAPES = {
157
216
  observer: { desc: `a string of at most ${MAX_AGENT_TEXT_CHARS} characters`, ok: boundedString(MAX_AGENT_TEXT_CHARS) },
158
217
  observerMessage: { desc: `a string of at most ${MAX_AGENT_TEXT_CHARS} characters`, ok: boundedString(MAX_AGENT_TEXT_CHARS) },
159
218
  };
219
+ /** [876] 单条 agent 定义的形状裁决:null=合法;否则一句可 400 的英文错误(不带索引,调用方自己加)。
220
+ * 白名单外键 fail-loud —— 与 resilience/limits 的「容忍未知键」相反:agents 是能力定义,静默丢字段 =
221
+ * 定义被悄悄削(一个丢掉的 isolation 就是放宽),比 400 更危险,故整条拒。⚠️ 已知残账(core 半场):
222
+ * core 只对 allowTools 未知项 fail-loud,denyTools 未知项(如 typo)静默失效 —— 已上板请 core 镜像。
223
+ * ⚠️ 键判断必须 Object.hasOwn:`in` 走原型链,JSON 里的 "toString"/"constructor"/"__proto__" 键会被
224
+ * 误判为白名单字段,随后 SHAPES[k].ok 不是函数 ⇒ TypeError(fresh 500 / resume 砖;cross-review 复现)。 */
160
225
  export function taskAgentIssue(item) {
161
226
  if (item === null || typeof item !== "object" || Array.isArray(item))
162
227
  return "each agent must be an object";
@@ -178,6 +243,9 @@ export function taskAgentIssue(item) {
178
243
  }
179
244
  return null;
180
245
  }
246
+ /** [876] HTTP 门(fresh submit,server.ts prepareSpec):body.agents 在场必须是非空数组、每条过
247
+ * {@link taskAgentIssue}、name 数组内唯一、条数 ≤ {@link MAX_TASK_AGENTS}。返回 400 错误串或 null。
248
+ * RESUME 重放不过这道门 —— {@link taskAgentsFromBody} defensive(按条 DROP+warn,不砖 resume)。 */
181
249
  export function validateTaskAgents(v) {
182
250
  if (!Array.isArray(v) || v.length === 0)
183
251
  return "agents must be a non-empty array of agent definitions";
@@ -195,6 +263,14 @@ export function validateTaskAgents(v) {
195
263
  }
196
264
  return null;
197
265
  }
266
+ /** [876] body.agents → `TaskSpec.agents`(resolveSpec 的唯一装配点;main.ts 只 spread)。两层门:
267
+ * - 🔒 TOB 租户门:多租户(requirePrincipal===true)暂不放行 —— [876] 原文「TOB 面按租户 caps 门」,
268
+ * 当前没有 per-tenant caps 面可挂,先 fail-closed 关多租(warn `task_agents_ignored`,capabilities
269
+ * 的 `taskAgents` 同步 advertise false);单机/单用户直通(caller 是自己 worker 的 super-admin,
270
+ * 与 mcpInjection/hooks 同一姿势)。
271
+ * - defensive 归一化(RESUME 重放持久化 body 不过 HTTP 400 门):非法项按条 DROP + warn
272
+ * `task_agent_dropped`(绝不 throw 砖 resume);重名后到者 DROP;超上限截断。幸存字段按白名单拷贝
273
+ * (不透传未知键 —— 非法项已整条 drop,这里只是让持久化 body 的杂键不上 spec)。全空 ⇒ undefined。 */
198
274
  export function taskAgentsFromBody(raw, requirePrincipal, warn) {
199
275
  if (raw === undefined)
200
276
  return undefined;
@@ -233,10 +309,19 @@ export function taskAgentsFromBody(raw, requirePrincipal, warn) {
233
309
  }
234
310
  return out.length > 0 ? out : undefined;
235
311
  }
312
+ /** [876] main.ts resolveSpec 的 agents 装配片段(可 import 真 fold,[1.211 codex L]:此前 main.ts 用内联
313
+ * 闭包,测试只能 SOURCE PIN 文本+重写同构表达式——文本锚可被「移出 resolveSpec 但保留同文」静默骗过;
314
+ * 现在行为测试直接调这个真出口,main.ts 只剩一次调用点可锚)。语义=taskAgentsFromBody 的条件 spread:
315
+ * 有幸存 agents 才挂键(absent/全 drop ⇒ 空对象,spec byte-compat)。 */
236
316
  export function taskAgentsSpecFragment(raw, requirePrincipal, warn) {
237
317
  const agents = taskAgentsFromBody(raw, requirePrincipal, warn);
238
318
  return agents ? { agents } : {};
239
319
  }
320
+ /** [854]② — body.retainBackgroundProcesses → `TaskSpec.retainBackgroundProcesses`。core 语义(1.295
321
+ * runtask/task-registry dist 亲读):`=== true` 时任务收尾不主动收割 session 后台进程 —— host lane 上是
322
+ * 资源驻留授予,与 backgroundShell 同款单用户闸:多租户 warn 忽略(`task_retain_bg_ignored`,capability
323
+ * 同步 advertise false)。只 literal `true` 上 spec(false=core 缺省,不挂键保持 byte-compat);非 boolean
324
+ * 由 HTTP 门 400,resume 重放这里 defensive DROP(不 throw)。 */
240
325
  export function retainBackgroundProcessesFromBody(raw, requirePrincipal, warn) {
241
326
  if (raw !== true)
242
327
  return undefined;
@@ -246,15 +331,31 @@ export function retainBackgroundProcessesFromBody(raw, requirePrincipal, warn) {
246
331
  }
247
332
  return true;
248
333
  }
334
+ /** [1052]② — body.{excludeTools,deferTools} → `TaskSpec.{excludeTools,deferTools}`(core 1.314 工具面
335
+ * 控制批)。语义:excludeTools=roster 真卸载(schema 字节不上 wire,manifest 如实收窄);deferTools=
336
+ * design/36 延迟披露(占位上 wire,ToolSearch 激活 materialize)。两位 tighten-only(core 继承不变量:
337
+ * union 进全部子 spawn 路径),per-run 工具面收窄无跨租户面 ⇒ 无租户门(interactiveTools 同姿势)。
338
+ * DEFENSIVE(resume 重放不过 HTTP 400 门):非数组 ⇒ undefined;项非非空字符串 ⇒ 逐项 DROP;空数组 ⇒
339
+ * undefined(不挂键=core 缺省,byte-compat)。HTTP 门另有 fail-loud 400(提交面邻居姿势)。 */
249
340
  export function toolNameListFromBody(raw) {
250
341
  if (!Array.isArray(raw))
251
342
  return undefined;
252
343
  const names = raw.filter((v) => typeof v === "string" && v.length > 0);
253
344
  return names.length > 0 ? names : undefined;
254
345
  }
346
+ /** [1144]/[1146] — body.promptProfile → `TaskSpec.promptProfile`(core 1.328 R2 主件,CC LT(model_id)
347
+ * 同构双形轴)。语义:纯呈现轴不碰策略(simple=CC 212 短形面缺省;classic=长形面,可按任务/模型试分)
348
+ * ⇒ 无租户门(deferTools 同姿势);全委托树继承由 core 管。缺省不挂键(引擎缺省 simple,byte-compat)。
349
+ * DEFENSIVE(resume 重放不过 HTTP 400 门):非法值 ⇒ undefined;提交面另有 fail-loud 400(邻居姿势)。 */
255
350
  export function promptProfileFromBody(raw) {
256
351
  return raw === "simple" || raw === "classic" ? raw : undefined;
257
352
  }
353
+ /**
354
+ * [854]④ — normalize `body.limits` → 请求方配速意图 {timeoutSec?, maxOutputTokens?, maxTurns?}。DEFENSIVE
355
+ * (resume 重放持久化 body 不过 HTTP 400 门):仅正的有限数字存活(floor 取整),0/负/垃圾按键 DROP —— core 侧
356
+ * `timeoutSec > 0` 才生效(0=不设墙,会绕过运营方封顶)、maxTurns/maxOutputTokens 的 0 无意义。每键各自被
357
+ * 运营方上限旋钮 clamp(Math.min;旋钮缺省不设=不封顶)。全空 ⇒ undefined。
358
+ */
258
359
  export function normalizeLimits(v, caps) {
259
360
  if (v == null || typeof v !== "object" || Array.isArray(v))
260
361
  return undefined;
@@ -269,12 +370,23 @@ export function normalizeLimits(v, caps) {
269
370
  ...(() => { const n = pick(o.timeoutSec, caps.timeoutSec); return n !== undefined ? { timeoutSec: n } : {}; })(),
270
371
  ...(() => { const n = pick(o.maxOutputTokens, caps.maxOutputTokens); return n !== undefined ? { maxOutputTokens: n } : {}; })(),
271
372
  ...(() => { const n = pick(o.maxTurns, caps.maxTurns); return n !== undefined ? { maxTurns: n } : {}; })(),
373
+ // 历史复审轴B #4(1.254):deadline 族三个 **opt-out**(design/128/130,timeoutSec 在场即默认 ON;
374
+ // server 恒注 tenancy 墙钟 ⇒ 此前恒开且 wire 无法关)。只认 literal false(纯关闭旋钮,零扩权面)。
272
375
  ...(o.deadlineNudge === false ? { deadlineNudge: false } : {}),
273
376
  ...(o.callCapByDeadline === false ? { callCapByDeadline: false } : {}),
274
377
  ...(o.gracefulFinalize === false ? { gracefulFinalize: false } : {}),
275
378
  };
276
379
  return Object.keys(out).length > 0 ? out : undefined;
277
380
  }
381
+ /**
382
+ * [854]④ — body.limits 与 env 墙钟的合成规则(resolveSpec 的唯一 limits 装配点;run-local 无 body 车道不经此):
383
+ * - `timeoutSec`:body 给了就用 body(caller 明确配速;已在 normalizeLimits 里被 TASK_TIMEOUT_MAX_SEC 封顶)。
384
+ * body 缺席保持既有姿势 = tenancy 墙钟 + env `TASK_TIMEOUT_SEC` 只抬不降(taskWallClockSec 内 Math.max,
385
+ * 误配低值不能砍 council 预算)。注意两条纪律不叠加:「只抬不降」是 env 对内建缺省墙的规则,body 是
386
+ * caller 的显式意图,直接生效(可低于 env 墙 —— 交互短任务要更紧的配速正是本件诉求)。
387
+ * - `maxOutputTokens` / `maxTurns`:直透传(各自可选 env 上限已 clamp)。
388
+ * 全空 ⇒ undefined(spec 不挂 limits 键,byte-compat)。
389
+ */
278
390
  export function resolveTaskLimits(bodyLimits, caps, envTimeoutSec, requirePrincipal, big) {
279
391
  const requested = normalizeLimits(bodyLimits, caps);
280
392
  const timeoutSec = requested?.timeoutSec ?? taskWallClockSec(envTimeoutSec, requirePrincipal, big);
@@ -1,21 +1,71 @@
1
+ /** Cap on a cwd path length (defensive — a row/path label bound; a real path is far shorter). */
1
2
  export declare const MAX_CWD_CHARS = 4096;
3
+ /** Is this a structurally-valid absolute host path? Rejects: non-strings, relative paths (TOC review #12 — a
4
+ * relative cwd would resolve against the SERVICE process cwd, not the user's project = silent wrong-dir), empty,
5
+ * over-long, and NUL-byte injection. NOT an existence check (the env surfaces a missing dir at first tool use).
6
+ * Defense-in-depth (double-review LOW): `path.isAbsolute` is SYNTACTIC — `/a/../../etc` is "absolute" yet contains
7
+ * `..` traversal that the host env would `path.resolve` away. Single-user host lane = the caller's own machine (no
8
+ * cross-tenant escape), but we reject any path with a `..` segment so the honored cwd is the literal path sent. */
2
9
  export declare function isValidCwd(cwd: unknown): cwd is string;
10
+ /**
11
+ * The deployment-level gate: does THIS deployment honor a caller-supplied `cwd`? TRUE only for the single-user
12
+ * `host` lane (see module header). All cloud/container lanes + any multi-tenant deployment → FALSE (cwd ignored).
13
+ */
3
14
  export declare function cwdHonored(config: {
4
15
  remoteExec?: {
5
16
  provider?: string;
6
17
  };
7
18
  requirePrincipal?: boolean;
8
19
  }): boolean;
20
+ /**
21
+ * [851]P3a — the OTHER host-semantics lane: provider UNSET = the in-process single-user lane. It has NO shell
22
+ * hands (core prepare-task: no factory/executionEnv ⇒ StubExecutionEnv), so the perSession cwd/env registries
23
+ * have no consumer there — but PROCESS-level consumers (hooks commands, the C4 projectContext local read) still
24
+ * see the engine's own `process.cwd()`/`process.env`. When the shell spawned the engine in the caller's own
25
+ * dir/env, a caller override is often ALREADY satisfied by that process state, and a per-task "ignored" warn
26
+ * contradicts it (飞轮双平台观测). Signal-truth split: satisfied ⇒ debug, real mismatch ⇒ warn. True per-session
27
+ * honoring remains `REMOTE_EXEC=host`. Multi-tenant excluded for the same reason as {@link cwdHonored}.
28
+ */
9
29
  export declare function inProcessSingleUserLane(config: {
10
30
  remoteExec?: {
11
31
  provider?: string;
12
32
  };
13
33
  requirePrincipal?: boolean;
14
34
  }): boolean;
35
+ /** Is a requested cwd ALREADY the engine process's working dir? realpath BOTH sides (macOS `/tmp` →
36
+ * `/private/tmp`-class symlinks); either side failing to resolve ⇒ treated as a mismatch (warn — never a
37
+ * false downgrade). `realpath`/`cwd` are parameters for testability; production passes `fs.realpathSync`. */
15
38
  export declare function satisfiedByProcessCwd(requested: string, realpath: (p: string) => string, cwd?: () => string): boolean;
39
+ /** How many requested shellEnv entries the engine process env does NOT already carry (value-exact compare).
40
+ * 0 ⇒ satisfied by the inherited process state (debug, not "ignored"). Callers must log only this COUNT —
41
+ * never env values (secret-class), and not key names either (a name can itself carry sensitive semantics). */
16
42
  export declare function shellEnvMismatchCount(requested: Record<string, string>, procEnv: Record<string, string | undefined>): number;
43
+ /** Cap on the number of `--add-dir` entries a caller may attach (bounds a pathological allowlist blast). */
17
44
  export declare const MAX_ADDITIONAL_DIRS = 64;
45
+ /**
46
+ * design/119 (CC `--add-dir` parity): validate an untrusted `body.additionalDirectories` — extra host dirs the
47
+ * FILE tools may access beyond the containment root (core canonicalizes each into its allowlist + lists them in the
48
+ * `# Environment` block). Gated identically to {@link cwdHonored}: these are the caller's OWN-machine paths, so they
49
+ * only make sense — and are only safe — on the single-user host lane (on a cloud/container lane a file-tool root is
50
+ * the sandbox fs, and a multi-tenant lane must never let one caller widen containment onto operator/other-tenant
51
+ * host paths). Each element gets the SAME structural check as `cwd` (absolute, no `..` traversal, no NUL, capped);
52
+ * malformed entries are dropped (never throw), the count is bounded, and duplicates collapse. Returns undefined when
53
+ * nothing valid remains (so the spec field stays absent rather than an empty array). NOT an existence check.
54
+ */
18
55
  export declare function parseAdditionalDirectories(raw: unknown): string[] | undefined;
56
+ /**
57
+ * core 1.219 `ExecutionEnvFactoryContext.parentCwd` (dogfood: sub-agents landed in an EMPTY
58
+ * sandbox — "当前工作目录为空"): resolve the HOST lane's effective workspace for a task. Precedence:
59
+ * 1. the session's explicitly-registered `cwd` (the caller's own launch dir, the cwd seam) — an explicit
60
+ * per-session choice always wins;
61
+ * 2. the TRUSTED `ctx.parentCwd` (core threads the PARENT task's working root via `RunInternals` when this
62
+ * task is a delegated child — never a TaskSpec field), UNLESS the child asked for `isolation:"worktree"`
63
+ * (core contract: worktree wins — an isolated fan-out child must not share the parent's mutable dir);
64
+ * 3. undefined → the factory's ephemeral per-task dir (top-level task with no registered cwd).
65
+ * CC parity: a Task sub-agent inherits the main session's cwd. Trust: `parentCwd` comes from core's trusted
66
+ * run-internals channel (same posture as `isolation`), so no tenancy gate is needed here — but the HOST lane
67
+ * itself is single-user by deployment shape, and container lanes (k8s/e2b/local-docker) never consult this.
68
+ */
19
69
  export declare function effectiveHostWorkspace(sessionCwd: string | undefined, ctx: {
20
70
  isolation?: string;
21
71
  parentCwd?: string;
package/dist/task-cwd.js CHANGED
@@ -1,5 +1,29 @@
1
+ /**
2
+ * TOC cwd seam — project the TOC client's launch directory (`TaskRequest.cwd`, SDK 0.0.36) onto the agent's
3
+ * HOST execution-env workspace, so `sema` run from a project dir operates on THAT project (CC-parity), instead of
4
+ * the persistent local engine's (default port 47362) fixed/ephemeral workspace (TOC adversarial review CRITICAL: the HTTP path conveyed NO
5
+ * project context — the agent always landed in an empty temp dir).
6
+ *
7
+ * 🔒 SECURITY (workflow): `cwd` is a HOST PATH supplied by the caller. Honoring it is a sandbox/
8
+ * filesystem-root choice, so it is gated HARD:
9
+ * - ONLY the `host` execution lane (run-on-this-machine, no container) reads it — every OTHER lane (k8s / e2b /
10
+ * ssh / adb / local-docker) has its own factory that NEVER consults the cwd registry, so cwd is ignored there
11
+ * by construction (a tenant can't point a shared/cloud worker at an arbitrary host path).
12
+ * - AND only a SINGLE-USER deployment (`requirePrincipal === false`) — a multi-tenant host lane must NOT let one
13
+ * caller's cwd steer the agent into another tenant's / the operator's files (cross-tenant host-path access).
14
+ * Same trust boundary as the deferred per-task `env` (TaskSpec deliberately has no per-task env for untrusted
15
+ * callers). When the gate is closed, a sent `cwd` is IGNORED (not honored) — advertised via capabilities so the
16
+ * shell never pretends it took effect.
17
+ */
1
18
  import path from "node:path";
19
+ /** Cap on a cwd path length (defensive — a row/path label bound; a real path is far shorter). */
2
20
  export const MAX_CWD_CHARS = 4_096;
21
+ /** Is this a structurally-valid absolute host path? Rejects: non-strings, relative paths (TOC review #12 — a
22
+ * relative cwd would resolve against the SERVICE process cwd, not the user's project = silent wrong-dir), empty,
23
+ * over-long, and NUL-byte injection. NOT an existence check (the env surfaces a missing dir at first tool use).
24
+ * Defense-in-depth (double-review LOW): `path.isAbsolute` is SYNTACTIC — `/a/../../etc` is "absolute" yet contains
25
+ * `..` traversal that the host env would `path.resolve` away. Single-user host lane = the caller's own machine (no
26
+ * cross-tenant escape), but we reject any path with a `..` segment so the honored cwd is the literal path sent. */
3
27
  export function isValidCwd(cwd) {
4
28
  return (typeof cwd === "string" &&
5
29
  cwd.length > 0 &&
@@ -8,12 +32,28 @@ export function isValidCwd(cwd) {
8
32
  path.isAbsolute(cwd) &&
9
33
  !cwd.split(/[/\\]/).includes(".."));
10
34
  }
35
+ /**
36
+ * The deployment-level gate: does THIS deployment honor a caller-supplied `cwd`? TRUE only for the single-user
37
+ * `host` lane (see module header). All cloud/container lanes + any multi-tenant deployment → FALSE (cwd ignored).
38
+ */
11
39
  export function cwdHonored(config) {
12
40
  return config.remoteExec?.provider === "host" && config.requirePrincipal !== true;
13
41
  }
42
+ /**
43
+ * [851]P3a — the OTHER host-semantics lane: provider UNSET = the in-process single-user lane. It has NO shell
44
+ * hands (core prepare-task: no factory/executionEnv ⇒ StubExecutionEnv), so the perSession cwd/env registries
45
+ * have no consumer there — but PROCESS-level consumers (hooks commands, the C4 projectContext local read) still
46
+ * see the engine's own `process.cwd()`/`process.env`. When the shell spawned the engine in the caller's own
47
+ * dir/env, a caller override is often ALREADY satisfied by that process state, and a per-task "ignored" warn
48
+ * contradicts it (飞轮双平台观测). Signal-truth split: satisfied ⇒ debug, real mismatch ⇒ warn. True per-session
49
+ * honoring remains `REMOTE_EXEC=host`. Multi-tenant excluded for the same reason as {@link cwdHonored}.
50
+ */
14
51
  export function inProcessSingleUserLane(config) {
15
52
  return config.remoteExec === undefined && config.requirePrincipal !== true;
16
53
  }
54
+ /** Is a requested cwd ALREADY the engine process's working dir? realpath BOTH sides (macOS `/tmp` →
55
+ * `/private/tmp`-class symlinks); either side failing to resolve ⇒ treated as a mismatch (warn — never a
56
+ * false downgrade). `realpath`/`cwd` are parameters for testability; production passes `fs.realpathSync`. */
17
57
  export function satisfiedByProcessCwd(requested, realpath, cwd = process.cwd) {
18
58
  try {
19
59
  return realpath(requested) === realpath(cwd());
@@ -22,10 +62,24 @@ export function satisfiedByProcessCwd(requested, realpath, cwd = process.cwd) {
22
62
  return false;
23
63
  }
24
64
  }
65
+ /** How many requested shellEnv entries the engine process env does NOT already carry (value-exact compare).
66
+ * 0 ⇒ satisfied by the inherited process state (debug, not "ignored"). Callers must log only this COUNT —
67
+ * never env values (secret-class), and not key names either (a name can itself carry sensitive semantics). */
25
68
  export function shellEnvMismatchCount(requested, procEnv) {
26
69
  return Object.keys(requested).filter((k) => procEnv[k] !== requested[k]).length;
27
70
  }
71
+ /** Cap on the number of `--add-dir` entries a caller may attach (bounds a pathological allowlist blast). */
28
72
  export const MAX_ADDITIONAL_DIRS = 64;
73
+ /**
74
+ * design/119 (CC `--add-dir` parity): validate an untrusted `body.additionalDirectories` — extra host dirs the
75
+ * FILE tools may access beyond the containment root (core canonicalizes each into its allowlist + lists them in the
76
+ * `# Environment` block). Gated identically to {@link cwdHonored}: these are the caller's OWN-machine paths, so they
77
+ * only make sense — and are only safe — on the single-user host lane (on a cloud/container lane a file-tool root is
78
+ * the sandbox fs, and a multi-tenant lane must never let one caller widen containment onto operator/other-tenant
79
+ * host paths). Each element gets the SAME structural check as `cwd` (absolute, no `..` traversal, no NUL, capped);
80
+ * malformed entries are dropped (never throw), the count is bounded, and duplicates collapse. Returns undefined when
81
+ * nothing valid remains (so the spec field stays absent rather than an empty array). NOT an existence check.
82
+ */
29
83
  export function parseAdditionalDirectories(raw) {
30
84
  if (!Array.isArray(raw))
31
85
  return undefined;
@@ -35,12 +89,25 @@ export function parseAdditionalDirectories(raw) {
35
89
  if (out.length >= MAX_ADDITIONAL_DIRS)
36
90
  break;
37
91
  if (!isValidCwd(entry) || seen.has(entry))
38
- continue;
92
+ continue; // reuse the cwd structural gate; collapse dups
39
93
  seen.add(entry);
40
94
  out.push(entry);
41
95
  }
42
96
  return out.length > 0 ? out : undefined;
43
97
  }
98
+ /**
99
+ * core 1.219 `ExecutionEnvFactoryContext.parentCwd` (dogfood: sub-agents landed in an EMPTY
100
+ * sandbox — "当前工作目录为空"): resolve the HOST lane's effective workspace for a task. Precedence:
101
+ * 1. the session's explicitly-registered `cwd` (the caller's own launch dir, the cwd seam) — an explicit
102
+ * per-session choice always wins;
103
+ * 2. the TRUSTED `ctx.parentCwd` (core threads the PARENT task's working root via `RunInternals` when this
104
+ * task is a delegated child — never a TaskSpec field), UNLESS the child asked for `isolation:"worktree"`
105
+ * (core contract: worktree wins — an isolated fan-out child must not share the parent's mutable dir);
106
+ * 3. undefined → the factory's ephemeral per-task dir (top-level task with no registered cwd).
107
+ * CC parity: a Task sub-agent inherits the main session's cwd. Trust: `parentCwd` comes from core's trusted
108
+ * run-internals channel (same posture as `isolation`), so no tenancy gate is needed here — but the HOST lane
109
+ * itself is single-user by deployment shape, and container lanes (k8s/e2b/local-docker) never consult this.
110
+ */
44
111
  export function effectiveHostWorkspace(sessionCwd, ctx) {
45
112
  return sessionCwd ?? (ctx.isolation !== "worktree" ? ctx.parentCwd : undefined);
46
113
  }
@@ -1,13 +1,60 @@
1
+ /**
2
+ * [TOC MCP seam, R3] — project the TOC client's local
3
+ * `.mcp.json` (`TaskRequest.mcpServers`) into the engine, so a `sema` run honors the user's own MCP servers
4
+ * (CC-parity "配置即用" local-first), instead of ONLY the center-config MCP. Mirrors the `cwd` seam (task-cwd.ts).
5
+ *
6
+ * 🔒 SECURITY — per-request MCP is the constitutional "untrusted-client tool injection" red line, because an MCP
7
+ * server is a TOOL SOURCE and an stdio transport is **arbitrary command execution**. The decisive fact (verified):
8
+ * core materializes stdio MCP with `StdioClientTransport`, which spawns the command as a child of **the WORKER
9
+ * (core's process), NOT the execution env** — so an stdio MCP runs on the worker host REGARDLESS of the exec lane
10
+ * (host/e2b/docker). Therefore the trust boundary is NOT "the host execution lane" (that's where the agent's TOOL
11
+ * CALLS run, irrelevant to MCP) — it is **"is the worker single-user, i.e. is the requester the super-admin?"** =
12
+ * `requirePrincipal !== true`. core's ruling (R3): the SERVICE is core's caller-trust-root; body→`TaskSpec.mcp` is a
13
+ * trust decision the service makes, never a passthrough.
14
+ * - SINGLE-USER deployment (`requirePrincipal===false`): the requester IS the super-admin of their own worker, so
15
+ * their `.mcp.json` is authoritative — exactly what CC does on the user's machine. This holds across EVERY
16
+ * execution lane (host / E2B / k8s / local-docker), so a TOC user who switches execution local↔cloud keeps their
17
+ * MCP honored seamlessly (TOC↔cloud is a spectrum, not a wall — clay 2026-06-29: TOB = single-user + people-mgmt).
18
+ * The caller being the trust root, `toolAxes` (authoritative effect overrides) + `elicitation` are their own choices.
19
+ * - MULTI-TENANT deployment (`requirePrincipal===true`): a tenant must NOT make the SHARED worker run an arbitrary
20
+ * command (RCE) or connect to a body-chosen URL (SSRF). Gate CLOSED → body MCP ignored; the fleet gets MCP only
21
+ * through center config refs. Per-principal http-remote injection (a center `allowMcpInjection` entitlement via
22
+ * `runtimeCapsResolver`) is a DEFERRED v2.
23
+ * When the gate is closed, a sent `mcpServers` is IGNORED (advertised via `capabilities.mcpInjection`).
24
+ */
1
25
  import type { McpServerSpec } from "@sema-agent/core";
26
+ /** Bound on caller-supplied servers (anti-DoS; a real local `.mcp.json` has a handful). */
2
27
  export declare const MAX_REQUEST_MCP_SERVERS = 32;
28
+ /**
29
+ * Does THIS deployment honor caller-supplied per-request MCP servers? TRUE for a SINGLE-USER deployment
30
+ * (`requirePrincipal !== true`) — the requester is the super-admin of their own worker, so their `.mcp.json` is
31
+ * authoritative (CC-parity), on ANY execution lane (the stdio command runs on the worker, not the exec env, so the
32
+ * lane is irrelevant — see module header). FALSE on a multi-tenant deployment (a tenant can't make the shared worker
33
+ * run an arbitrary command / connect to an arbitrary URL).
34
+ */
3
35
  export declare function mcpInjectionHonored(config: {
4
36
  requirePrincipal?: boolean;
5
37
  }): boolean;
38
+ /**
39
+ * Shape-check the raw `body.mcpServers`. `null` → a non-array (caller error; the route may 400). Otherwise the
40
+ * valid subset + the names of dropped (malformed/over-cap) entries.
41
+ */
6
42
  export declare function validateRequestMcp(raw: unknown): {
7
43
  ok: McpServerSpec[];
8
44
  dropped: string[];
9
45
  } | null;
46
+ /**
47
+ * Merge GATED per-request MCP servers OVER the deployment baseline (center/config). The baseline WINS on a name
48
+ * clash — a caller can ADD servers but can never SHADOW a configured one (the security baseline is authoritative,
49
+ * same posture as `mergeUserSkills`). Returns the baseline unchanged when there is nothing to add.
50
+ */
10
51
  export declare function mergeRequestMcp(baseline: McpServerSpec[] | undefined, gated: McpServerSpec[]): McpServerSpec[] | undefined;
52
+ /**
53
+ * The single entry point the spec-builder calls: compute the effective `TaskSpec.mcp` = deployment baseline + the
54
+ * caller's gated per-request servers. Off the honored lane (or with no caller servers) returns the baseline
55
+ * unchanged. Logs an `mcp_injection_ignored` when a caller SENT servers a closed gate dropped (so the shell never
56
+ * silently believes its `.mcp.json` took effect — it also reads `capabilities.mcpInjection`).
57
+ */
11
58
  export declare function resolveRequestMcp(baseline: McpServerSpec[] | undefined, bodyMcp: unknown, config: {
12
59
  remoteExec?: {
13
60
  provider?: string;
package/dist/task-mcp.js CHANGED
@@ -1,10 +1,19 @@
1
+ /** Bound on caller-supplied servers (anti-DoS; a real local `.mcp.json` has a handful). */
1
2
  export const MAX_REQUEST_MCP_SERVERS = 32;
3
+ /**
4
+ * Does THIS deployment honor caller-supplied per-request MCP servers? TRUE for a SINGLE-USER deployment
5
+ * (`requirePrincipal !== true`) — the requester is the super-admin of their own worker, so their `.mcp.json` is
6
+ * authoritative (CC-parity), on ANY execution lane (the stdio command runs on the worker, not the exec env, so the
7
+ * lane is irrelevant — see module header). FALSE on a multi-tenant deployment (a tenant can't make the shared worker
8
+ * run an arbitrary command / connect to an arbitrary URL).
9
+ */
2
10
  export function mcpInjectionHonored(config) {
3
11
  return config.requirePrincipal !== true;
4
12
  }
5
13
  function isStringRecord(v) {
6
14
  return !!v && typeof v === "object" && !Array.isArray(v) && Object.values(v).every((x) => typeof x === "string");
7
15
  }
16
+ /** Validate + normalize ONE caller entry to a core `McpServerSpec`, or null if malformed (dropped, not fatal). */
8
17
  function normalizeServer(e) {
9
18
  if (!e || typeof e !== "object")
10
19
  return null;
@@ -27,6 +36,7 @@ function normalizeServer(e) {
27
36
  };
28
37
  }
29
38
  else if (tr.kind === "http") {
39
+ // http(s) only — never file://, never a bare host (a syntactic guard; cloud http injection is still gated off-lane).
30
40
  if (typeof tr.url !== "string" || !/^https?:\/\//i.test(tr.url))
31
41
  return null;
32
42
  transport = {
@@ -42,14 +52,18 @@ function normalizeServer(e) {
42
52
  const spec = { name: o.name, transport };
43
53
  if (Array.isArray(o.allowTools) && o.allowTools.every((a) => typeof a === "string"))
44
54
  spec.allowTools = o.allowTools;
55
+ // caller-trust-root (host-lane single-user): the user's own effect/elicitation choices are kept (CC-parity).
45
56
  if (typeof o.elicitation === "boolean")
46
57
  spec.elicitation = o.elicitation;
47
58
  if (o.toolAxes && typeof o.toolAxes === "object" && !Array.isArray(o.toolAxes)) {
59
+ // 轴B #6(1.254):裸 cast 换 per-key 形状校验——单用户 caller-trust-root 姿势不变(值语义仍由 caller
60
+ // 定),只挡畸形值直达 core(非对象条目/未知枚举字段值静默剔除,诚实收窄不 400)。
48
61
  const axes = {};
49
62
  for (const [tool, ax] of Object.entries(o.toolAxes)) {
50
63
  if (!ax || typeof ax !== "object" || Array.isArray(ax))
51
64
  continue;
52
65
  const a = ax;
66
+ // 真域对齐 core types(自查纠偏:egress 是 boolean、irreversibility 是 "always"|"never")
53
67
  const entry = {
54
68
  ...(a.effect === "read" || a.effect === "write" || a.effect === "idempotent" ? { effect: a.effect } : {}),
55
69
  ...(typeof a.egress === "boolean" ? { egress: a.egress } : {}),
@@ -63,6 +77,10 @@ function normalizeServer(e) {
63
77
  }
64
78
  return spec;
65
79
  }
80
+ /**
81
+ * Shape-check the raw `body.mcpServers`. `null` → a non-array (caller error; the route may 400). Otherwise the
82
+ * valid subset + the names of dropped (malformed/over-cap) entries.
83
+ */
66
84
  export function validateRequestMcp(raw) {
67
85
  if (raw === undefined || raw === null)
68
86
  return { ok: [], dropped: [] };
@@ -81,6 +99,11 @@ export function validateRequestMcp(raw) {
81
99
  dropped.push(`(+${raw.length - MAX_REQUEST_MCP_SERVERS} over cap of ${MAX_REQUEST_MCP_SERVERS})`);
82
100
  return { ok, dropped };
83
101
  }
102
+ /**
103
+ * Merge GATED per-request MCP servers OVER the deployment baseline (center/config). The baseline WINS on a name
104
+ * clash — a caller can ADD servers but can never SHADOW a configured one (the security baseline is authoritative,
105
+ * same posture as `mergeUserSkills`). Returns the baseline unchanged when there is nothing to add.
106
+ */
84
107
  export function mergeRequestMcp(baseline, gated) {
85
108
  if (gated.length === 0)
86
109
  return baseline;
@@ -88,6 +111,12 @@ export function mergeRequestMcp(baseline, gated) {
88
111
  const add = gated.filter((s) => !taken.has(s.name));
89
112
  return add.length === 0 ? baseline : [...(baseline ?? []), ...add];
90
113
  }
114
+ /**
115
+ * The single entry point the spec-builder calls: compute the effective `TaskSpec.mcp` = deployment baseline + the
116
+ * caller's gated per-request servers. Off the honored lane (or with no caller servers) returns the baseline
117
+ * unchanged. Logs an `mcp_injection_ignored` when a caller SENT servers a closed gate dropped (so the shell never
118
+ * silently believes its `.mcp.json` took effect — it also reads `capabilities.mcpInjection`).
119
+ */
91
120
  export function resolveRequestMcp(baseline, bodyMcp, config, logger) {
92
121
  if (bodyMcp === undefined || bodyMcp === null)
93
122
  return baseline;