@sema-agent/server 1.323.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (565) hide show
  1. package/dist/approval-hmac.d.ts +40 -0
  2. package/dist/approval-hmac.js +67 -0
  3. package/dist/approval.d.ts +31 -0
  4. package/dist/approval.js +72 -4
  5. package/dist/audit.d.ts +26 -0
  6. package/dist/audit.js +40 -1
  7. package/dist/auth-bridge.d.ts +10 -0
  8. package/dist/auth-bridge.js +47 -4
  9. package/dist/auth-keys.d.ts +19 -0
  10. package/dist/auth-keys.js +13 -0
  11. package/dist/bake-runner/main.d.ts +5 -0
  12. package/dist/bake-runner/main.js +43 -4
  13. package/dist/bake-runner/protocol.d.ts +57 -0
  14. package/dist/bake-runner/protocol.js +58 -3
  15. package/dist/bake-runner/runner.d.ts +54 -0
  16. package/dist/bake-runner/runner.js +87 -5
  17. package/dist/bench/l8/artifact.d.ts +63 -0
  18. package/dist/bench/l8/artifact.js +61 -2
  19. package/dist/bench/l8/escape.d.ts +36 -0
  20. package/dist/bench/l8/escape.js +25 -0
  21. package/dist/bench/l8/index.d.ts +14 -0
  22. package/dist/bench/l8/index.js +14 -0
  23. package/dist/bench/l8/probes.d.ts +74 -0
  24. package/dist/bench/l8/probes.js +60 -0
  25. package/dist/bench/l8/run-probes.d.ts +43 -0
  26. package/dist/bench/l8/run-probes.js +45 -2
  27. package/dist/bench/s1/arms.d.ts +126 -0
  28. package/dist/bench/s1/arms.js +188 -13
  29. package/dist/bench/s1/live-deps.d.ts +66 -0
  30. package/dist/bench/s1/live-deps.js +249 -11
  31. package/dist/bench/s1/oracle.d.ts +49 -0
  32. package/dist/bench/s1/oracle.js +36 -1
  33. package/dist/bench/s1/repair-oracle-adapter.d.ts +33 -0
  34. package/dist/bench/s1/repair-oracle-adapter.js +30 -0
  35. package/dist/bench/s1/reviewer.d.ts +38 -0
  36. package/dist/bench/s1/reviewer.js +34 -0
  37. package/dist/bench/s1/row.d.ts +77 -0
  38. package/dist/bench/s1/row.js +62 -0
  39. package/dist/bench/s1/run-firm.d.ts +47 -0
  40. package/dist/bench/s1/run-firm.js +70 -4
  41. package/dist/bench/s1/runner-ctx.d.ts +71 -0
  42. package/dist/bench/s1/runner-ctx.js +36 -0
  43. package/dist/bench/s1/tasks.d.ts +108 -0
  44. package/dist/bench/s1/tasks.js +115 -0
  45. package/dist/boot/budget-tracing.d.ts +48 -0
  46. package/dist/boot/budget-tracing.js +86 -0
  47. package/dist/boot/config-center.d.ts +62 -0
  48. package/dist/boot/config-center.js +995 -0
  49. package/dist/boot/coordinators.d.ts +33 -0
  50. package/dist/boot/coordinators.js +97 -0
  51. package/dist/boot/execution-env.d.ts +26 -0
  52. package/dist/boot/execution-env.js +370 -0
  53. package/dist/boot/leader.d.ts +27 -0
  54. package/dist/boot/leader.js +81 -0
  55. package/dist/boot/reapers.d.ts +53 -0
  56. package/dist/boot/reapers.js +252 -0
  57. package/dist/boot/resolve-spec.d.ts +70 -0
  58. package/dist/boot/resolve-spec.js +1072 -0
  59. package/dist/boot/runner-deps.d.ts +101 -0
  60. package/dist/boot/runner-deps.js +343 -0
  61. package/dist/boot/runtime-caps.d.ts +21 -0
  62. package/dist/boot/runtime-caps.js +62 -0
  63. package/dist/boot/session-faces.d.ts +57 -0
  64. package/dist/boot/session-faces.js +157 -0
  65. package/dist/boot/shutdown.d.ts +50 -0
  66. package/dist/boot/shutdown.js +129 -0
  67. package/dist/boot/stores.d.ts +32 -0
  68. package/dist/boot/stores.js +361 -0
  69. package/dist/boot/workflow-orchestration.d.ts +46 -0
  70. package/dist/boot/workflow-orchestration.js +150 -0
  71. package/dist/boot-reclaim.d.ts +19 -0
  72. package/dist/boot-reclaim.js +20 -0
  73. package/dist/brain.d.ts +25 -0
  74. package/dist/brain.js +61 -1
  75. package/dist/budget.d.ts +66 -0
  76. package/dist/budget.js +128 -4
  77. package/dist/capabilities/builtin-tools.d.ts +3 -0
  78. package/dist/capabilities/builtin-tools.js +3 -0
  79. package/dist/capabilities/center-plugins.d.ts +17 -1
  80. package/dist/capabilities/center-plugins.js +45 -4
  81. package/dist/capabilities/center-prompts.d.ts +46 -0
  82. package/dist/capabilities/center-prompts.js +57 -3
  83. package/dist/capabilities/code-review-council.d.ts +28 -0
  84. package/dist/capabilities/code-review-council.js +40 -7
  85. package/dist/capabilities/collab-wire.d.ts +2 -0
  86. package/dist/capabilities/collab-workflows.d.ts +7 -0
  87. package/dist/capabilities/collab-workflows.js +44 -1
  88. package/dist/capabilities/oa-tools.d.ts +6 -0
  89. package/dist/capabilities/oa-tools.js +10 -0
  90. package/dist/capabilities/prompt.d.ts +14 -0
  91. package/dist/capabilities/prompt.js +14 -0
  92. package/dist/capabilities/prompts/code-review.d.ts +14 -0
  93. package/dist/capabilities/prompts/code-review.js +14 -0
  94. package/dist/capabilities/prompts/identity.d.ts +6 -0
  95. package/dist/capabilities/prompts/identity.js +6 -0
  96. package/dist/capabilities/prompts/team.d.ts +4 -0
  97. package/dist/capabilities/prompts/team.js +4 -0
  98. package/dist/capabilities/repo-tools.d.ts +11 -0
  99. package/dist/capabilities/repo-tools.js +8 -0
  100. package/dist/capabilities/sandbox-file-send.d.ts +95 -0
  101. package/dist/capabilities/sandbox-file-send.js +91 -3
  102. package/dist/capabilities/scenarios.d.ts +130 -0
  103. package/dist/capabilities/scenarios.js +180 -7
  104. package/dist/capabilities/select-environment-tool.d.ts +7 -0
  105. package/dist/capabilities/select-environment-tool.js +30 -0
  106. package/dist/capabilities/send-user-file-tool.d.ts +33 -0
  107. package/dist/capabilities/send-user-file-tool.js +65 -1
  108. package/dist/capabilities/skills.d.ts +29 -0
  109. package/dist/capabilities/skills.js +13 -2
  110. package/dist/capabilities/team.d.ts +22 -0
  111. package/dist/capabilities/team.js +22 -2
  112. package/dist/capabilities/tool-defer.d.ts +26 -0
  113. package/dist/capabilities/tool-defer.js +3 -0
  114. package/dist/config-center/apply-effective.d.ts +65 -0
  115. package/dist/config-center/apply-effective.js +204 -12
  116. package/dist/config-center/http-client.d.ts +34 -0
  117. package/dist/config-center/http-client.js +68 -0
  118. package/dist/config-center/restart-signal.d.ts +22 -0
  119. package/dist/config-center/restart-signal.js +39 -0
  120. package/dist/config-center/skills-mcp.d.ts +20 -1
  121. package/dist/config-center/skills-mcp.js +42 -7
  122. package/dist/config-center/types.d.ts +92 -1
  123. package/dist/config-lkg.d.ts +12 -0
  124. package/dist/config-lkg.js +41 -0
  125. package/dist/config-provider.d.ts +78 -0
  126. package/dist/config-provider.js +165 -2
  127. package/dist/config-types.d.ts +585 -1
  128. package/dist/config.d.ts +78 -2
  129. package/dist/config.js +874 -301
  130. package/dist/degenerate-instrument.d.ts +38 -0
  131. package/dist/degenerate-instrument.js +55 -3
  132. package/dist/elicitation.d.ts +39 -0
  133. package/dist/elicitation.js +87 -3
  134. package/dist/env-facts.d.ts +61 -0
  135. package/dist/env-facts.js +73 -7
  136. package/dist/fleet/fleet-bus.d.ts +185 -0
  137. package/dist/fleet/fleet-bus.js +333 -27
  138. package/dist/fleet/subagent-tail-bus.d.ts +11 -0
  139. package/dist/fleet/subagent-tail-bus.js +33 -2
  140. package/dist/fleet-client.d.ts +38 -0
  141. package/dist/fleet-client.js +44 -9
  142. package/dist/fleet-lease.d.ts +46 -0
  143. package/dist/fleet-lease.js +73 -5
  144. package/dist/hooks/branch-transcript.d.ts +8 -0
  145. package/dist/hooks/branch-transcript.js +33 -0
  146. package/dist/hooks/cc-stop-prompt.d.ts +42 -0
  147. package/dist/hooks/cc-stop-prompt.js +43 -1
  148. package/dist/hooks/hook-llm.d.ts +15 -0
  149. package/dist/hooks/hook-llm.js +47 -0
  150. package/dist/hooks/hook-runner.d.ts +89 -0
  151. package/dist/hooks/hook-runner.js +327 -18
  152. package/dist/http/idempotency.d.ts +31 -0
  153. package/dist/http/idempotency.js +34 -0
  154. package/dist/http/principal-gate.d.ts +17 -0
  155. package/dist/http/principal-gate.js +35 -3
  156. package/dist/http/route-ctx.d.ts +36 -0
  157. package/dist/http/routes/approvals-assistant.d.ts +25 -0
  158. package/dist/http/routes/approvals-assistant.js +253 -23
  159. package/dist/http/routes/attachments.js +22 -4
  160. package/dist/http/routes/capabilities.d.ts +7 -0
  161. package/dist/http/routes/capabilities.js +202 -1
  162. package/dist/http/routes/fleet.d.ts +6 -0
  163. package/dist/http/routes/fleet.js +94 -5
  164. package/dist/http/routes/images.d.ts +17 -0
  165. package/dist/http/routes/images.js +222 -14
  166. package/dist/http/routes/leader.d.ts +7 -0
  167. package/dist/http/routes/leader.js +10 -0
  168. package/dist/http/routes/memory-policy.d.ts +6 -0
  169. package/dist/http/routes/memory-policy.js +38 -6
  170. package/dist/http/routes/notify-wake.d.ts +10 -0
  171. package/dist/http/routes/notify-wake.js +19 -3
  172. package/dist/http/routes/observability.d.ts +6 -0
  173. package/dist/http/routes/observability.js +19 -2
  174. package/dist/http/routes/runs.d.ts +15 -0
  175. package/dist/http/routes/runs.js +464 -41
  176. package/dist/http/routes/session-sync.d.ts +15 -0
  177. package/dist/http/routes/session-sync.js +229 -19
  178. package/dist/http/routes/sessions-list.d.ts +6 -0
  179. package/dist/http/routes/sessions-list.js +35 -4
  180. package/dist/http/routes/sessions.d.ts +14 -0
  181. package/dist/http/routes/sessions.js +176 -31
  182. package/dist/http/routes/side-query.d.ts +8 -0
  183. package/dist/http/routes/side-query.js +26 -1
  184. package/dist/http/routes/tasks.d.ts +18 -0
  185. package/dist/http/routes/tasks.js +501 -38
  186. package/dist/http/routes/trace-usage.d.ts +10 -0
  187. package/dist/http/routes/trace-usage.js +66 -14
  188. package/dist/http/routes/workflows.d.ts +12 -0
  189. package/dist/http/routes/workflows.js +180 -19
  190. package/dist/http/run-meta.d.ts +11 -0
  191. package/dist/http/run-meta.js +6 -0
  192. package/dist/http/send.d.ts +19 -0
  193. package/dist/http/send.js +11 -0
  194. package/dist/http/server.d.ts +255 -0
  195. package/dist/http/server.js +921 -75
  196. package/dist/http/sse-log.d.ts +15 -0
  197. package/dist/http/sse-log.js +16 -0
  198. package/dist/http/tar.d.ts +9 -0
  199. package/dist/http/tar.js +21 -5
  200. package/dist/http/wire-gate.d.ts +9 -0
  201. package/dist/http/wire-gate.js +9 -0
  202. package/dist/http/wire-types.d.ts +187 -0
  203. package/dist/http/workspace-content.d.ts +8 -0
  204. package/dist/http/workspace-content.js +10 -0
  205. package/dist/images/bake-validate.d.ts +63 -0
  206. package/dist/images/bake-validate.js +71 -1
  207. package/dist/images/manifest.d.ts +19 -0
  208. package/dist/images/manifest.js +6 -1
  209. package/dist/index.d.ts +1 -5
  210. package/dist/index.js +10 -5
  211. package/dist/key-resolver.d.ts +23 -0
  212. package/dist/key-resolver.js +27 -2
  213. package/dist/leader/diffout.d.ts +23 -0
  214. package/dist/leader/diffout.js +8 -1
  215. package/dist/leader/diffup.d.ts +32 -0
  216. package/dist/leader/diffup.js +43 -0
  217. package/dist/leader/endpoint.d.ts +20 -0
  218. package/dist/leader/endpoint.js +25 -2
  219. package/dist/leader/fanout.d.ts +60 -0
  220. package/dist/leader/fanout.js +29 -3
  221. package/dist/leader/grader-env-factory.d.ts +74 -0
  222. package/dist/leader/grader-env-factory.js +62 -3
  223. package/dist/leader/leader.d.ts +97 -0
  224. package/dist/leader/leader.js +151 -4
  225. package/dist/leader/merge.d.ts +94 -0
  226. package/dist/leader/merge.js +112 -9
  227. package/dist/leader/planner.d.ts +52 -0
  228. package/dist/leader/planner.js +47 -3
  229. package/dist/leader/repair-oracle.d.ts +61 -0
  230. package/dist/leader/repair-oracle.js +59 -1
  231. package/dist/leader/repair-wire.d.ts +78 -0
  232. package/dist/leader/repair-wire.js +79 -2
  233. package/dist/leader/wire.d.ts +79 -0
  234. package/dist/leader/wire.js +255 -8
  235. package/dist/lsp/e2b-bridge.d.ts +16 -0
  236. package/dist/lsp/e2b-bridge.js +32 -4
  237. package/dist/lsp/e2b-manager.d.ts +10 -0
  238. package/dist/lsp/e2b-manager.js +18 -2
  239. package/dist/lsp/lsp-frames.d.ts +12 -0
  240. package/dist/lsp/lsp-frames.js +12 -0
  241. package/dist/lsp/manager.d.ts +12 -0
  242. package/dist/lsp/manager.js +35 -2
  243. package/dist/lsp/types.d.ts +10 -0
  244. package/dist/lsp/ws-transport.d.ts +12 -0
  245. package/dist/lsp/ws-transport.js +53 -5
  246. package/dist/lsp-evict.d.ts +14 -0
  247. package/dist/lsp-evict.js +15 -1
  248. package/dist/main.js +530 -2129
  249. package/dist/memory-export.d.ts +1 -0
  250. package/dist/memory-export.js +4 -0
  251. package/dist/memory-scope.d.ts +49 -0
  252. package/dist/memory-scope.js +87 -4
  253. package/dist/memory-sync-client.d.ts +24 -0
  254. package/dist/memory-sync-client.js +41 -2
  255. package/dist/memory-sync.d.ts +23 -0
  256. package/dist/memory-sync.js +70 -1
  257. package/dist/model-select.d.ts +39 -0
  258. package/dist/model-select.js +42 -1
  259. package/dist/observability/cost-quota.d.ts +20 -0
  260. package/dist/observability/cost-quota.js +4 -0
  261. package/dist/observability/cost-taxonomy.d.ts +45 -0
  262. package/dist/observability/cost-taxonomy.js +34 -0
  263. package/dist/observability/logger.d.ts +1 -0
  264. package/dist/observability/logger.js +6 -0
  265. package/dist/observability/metrics.d.ts +13 -0
  266. package/dist/observability/metrics.js +63 -0
  267. package/dist/observability/otel-exporter.d.ts +9 -0
  268. package/dist/observability/otel-exporter.js +11 -3
  269. package/dist/observability/principal-context.d.ts +9 -0
  270. package/dist/observability/principal-context.js +9 -0
  271. package/dist/observability/prompt-manifest.d.ts +37 -0
  272. package/dist/observability/prompt-manifest.js +35 -1
  273. package/dist/observability/rate-limit.d.ts +10 -0
  274. package/dist/observability/rate-limit.js +1 -0
  275. package/dist/observability/tool-trace.d.ts +24 -0
  276. package/dist/observability/tool-trace.js +41 -1
  277. package/dist/orchestration/hardened-vm-runner.d.ts +107 -0
  278. package/dist/orchestration/hardened-vm-runner.js +119 -4
  279. package/dist/orchestration/hardened-vm-worker-runner.d.ts +14 -0
  280. package/dist/orchestration/hardened-vm-worker-runner.js +26 -1
  281. package/dist/orchestration/hardened-vm-worker.js +27 -0
  282. package/dist/orchestration/subagent-steer.d.ts +44 -0
  283. package/dist/orchestration/subagent-steer.js +45 -1
  284. package/dist/orchestration/workflow-agent-steer.d.ts +54 -0
  285. package/dist/orchestration/workflow-agent-steer.js +80 -1
  286. package/dist/orchestration/workflow-completion-inbox.d.ts +189 -2
  287. package/dist/orchestration/workflow-completion-inbox.js +283 -32
  288. package/dist/orchestration/workflow-notify-journal.d.ts +132 -1
  289. package/dist/orchestration/workflow-notify-journal.js +187 -13
  290. package/dist/parked-decide.d.ts +61 -0
  291. package/dist/parked-decide.js +58 -1
  292. package/dist/per-task-image.d.ts +54 -0
  293. package/dist/per-task-image.js +41 -0
  294. package/dist/plan-cache-probe.d.ts +35 -0
  295. package/dist/plan-cache-probe.js +18 -3
  296. package/dist/plugins/approval-exemption-store.d.ts +7 -0
  297. package/dist/plugins/approval-exemption-store.js +28 -2
  298. package/dist/plugins/approval-store-sql.d.ts +64 -0
  299. package/dist/plugins/approval-store-sql.js +32 -0
  300. package/dist/plugins/background-agent-store-sql.d.ts +55 -0
  301. package/dist/plugins/background-agent-store-sql.js +91 -4
  302. package/dist/plugins/background-shell-support.d.ts +98 -0
  303. package/dist/plugins/background-shell-support.js +117 -13
  304. package/dist/plugins/blob-backend.d.ts +104 -0
  305. package/dist/plugins/blob-backend.js +163 -6
  306. package/dist/plugins/breaker-state-sql.d.ts +65 -1
  307. package/dist/plugins/breaker-state-sql.js +46 -8
  308. package/dist/plugins/caching-session-store.d.ts +42 -0
  309. package/dist/plugins/caching-session-store.js +63 -3
  310. package/dist/plugins/checkpoint-store-sql.d.ts +179 -0
  311. package/dist/plugins/checkpoint-store-sql.js +239 -11
  312. package/dist/plugins/file-outcome-sink.d.ts +4 -0
  313. package/dist/plugins/file-outcome-sink.js +9 -0
  314. package/dist/plugins/file-resume-anchor-store.d.ts +20 -0
  315. package/dist/plugins/file-resume-anchor-store.js +43 -4
  316. package/dist/plugins/file-run-store.d.ts +90 -0
  317. package/dist/plugins/file-run-store.js +145 -13
  318. package/dist/plugins/file-snapshot-store-sql.d.ts +133 -1
  319. package/dist/plugins/file-snapshot-store-sql.js +178 -10
  320. package/dist/plugins/file-workflow-journal-store.d.ts +10 -0
  321. package/dist/plugins/file-workflow-journal-store.js +10 -0
  322. package/dist/plugins/fork-routing-session-store.d.ts +47 -0
  323. package/dist/plugins/fork-routing-session-store.js +51 -3
  324. package/dist/plugins/host-platform.d.ts +69 -0
  325. package/dist/plugins/host-platform.js +81 -2
  326. package/dist/plugins/image-bake-store-sql.d.ts +136 -1
  327. package/dist/plugins/image-bake-store-sql.js +241 -7
  328. package/dist/plugins/image-index-sql.d.ts +46 -0
  329. package/dist/plugins/image-index-sql.js +113 -4
  330. package/dist/plugins/k8s-bg-scripts.d.ts +34 -0
  331. package/dist/plugins/k8s-bg-scripts.js +88 -4
  332. package/dist/plugins/k8s-exec-protocol.d.ts +33 -0
  333. package/dist/plugins/k8s-exec-protocol.js +41 -0
  334. package/dist/plugins/local-checkpoint-store.d.ts +40 -0
  335. package/dist/plugins/local-checkpoint-store.js +86 -7
  336. package/dist/plugins/local-session-store.d.ts +157 -0
  337. package/dist/plugins/local-session-store.js +289 -34
  338. package/dist/plugins/local-task-attachment-store.js +14 -2
  339. package/dist/plugins/mailbox-store-sql.d.ts +38 -0
  340. package/dist/plugins/mailbox-store-sql.js +39 -6
  341. package/dist/plugins/memory-engine-pg.d.ts +30 -0
  342. package/dist/plugins/memory-engine-pg.js +122 -4
  343. package/dist/plugins/memory-engine-tidb.d.ts +26 -0
  344. package/dist/plugins/memory-engine-tidb.js +115 -5
  345. package/dist/plugins/memory-engine-vector-util.d.ts +5 -0
  346. package/dist/plugins/memory-engine-vector-util.js +5 -0
  347. package/dist/plugins/memory-resume-anchor-store.d.ts +8 -0
  348. package/dist/plugins/memory-resume-anchor-store.js +17 -0
  349. package/dist/plugins/memory-run-store.d.ts +63 -0
  350. package/dist/plugins/memory-run-store.js +73 -8
  351. package/dist/plugins/memory-session-policy-store.d.ts +17 -0
  352. package/dist/plugins/memory-session-policy-store.js +17 -0
  353. package/dist/plugins/memory-sync-store-pg.d.ts +42 -0
  354. package/dist/plugins/memory-sync-store-pg.js +45 -2
  355. package/dist/plugins/memory-sync-store-tidb.d.ts +9 -0
  356. package/dist/plugins/memory-sync-store-tidb.js +31 -1
  357. package/dist/plugins/outcome-ledger-sql.d.ts +63 -0
  358. package/dist/plugins/outcome-ledger-sql.js +97 -3
  359. package/dist/plugins/pg-approval-store.d.ts +7 -0
  360. package/dist/plugins/pg-approval-store.js +7 -0
  361. package/dist/plugins/pg-breaker-state.d.ts +6 -0
  362. package/dist/plugins/pg-breaker-state.js +6 -0
  363. package/dist/plugins/pg-checkpoint-store.d.ts +8 -0
  364. package/dist/plugins/pg-checkpoint-store.js +8 -0
  365. package/dist/plugins/pg-cost-quota.d.ts +17 -0
  366. package/dist/plugins/pg-cost-quota.js +6 -0
  367. package/dist/plugins/pg-file-snapshot-store.d.ts +6 -0
  368. package/dist/plugins/pg-file-snapshot-store.js +6 -0
  369. package/dist/plugins/pg-image-bake.d.ts +9 -0
  370. package/dist/plugins/pg-image-bake.js +9 -0
  371. package/dist/plugins/pg-image-index.d.ts +9 -0
  372. package/dist/plugins/pg-image-index.js +9 -0
  373. package/dist/plugins/pg-outcome-ledger.d.ts +9 -0
  374. package/dist/plugins/pg-outcome-ledger.js +9 -0
  375. package/dist/plugins/pg-pool.d.ts +50 -0
  376. package/dist/plugins/pg-pool.js +78 -0
  377. package/dist/plugins/pg-query.d.ts +11 -0
  378. package/dist/plugins/pg-rate-limiter.d.ts +23 -0
  379. package/dist/plugins/pg-rate-limiter.js +12 -2
  380. package/dist/plugins/pg-resume-anchor-store.d.ts +5 -0
  381. package/dist/plugins/pg-resume-anchor-store.js +5 -0
  382. package/dist/plugins/pg-run-store.d.ts +7 -0
  383. package/dist/plugins/pg-run-store.js +7 -0
  384. package/dist/plugins/pg-safe-json.d.ts +13 -0
  385. package/dist/plugins/pg-safe-json.js +40 -4
  386. package/dist/plugins/pg-session-policy-store.d.ts +5 -0
  387. package/dist/plugins/pg-session-policy-store.js +5 -0
  388. package/dist/plugins/pg-session-storage.d.ts +72 -0
  389. package/dist/plugins/pg-session-storage.js +152 -20
  390. package/dist/plugins/pg-session-store.d.ts +10 -0
  391. package/dist/plugins/pg-session-store.js +10 -0
  392. package/dist/plugins/pg-tool-result-store.d.ts +7 -0
  393. package/dist/plugins/pg-tool-result-store.js +7 -0
  394. package/dist/plugins/pg-workflow-journal-store.d.ts +7 -0
  395. package/dist/plugins/pg-workflow-journal-store.js +7 -0
  396. package/dist/plugins/pg-workflow-run-store.d.ts +7 -0
  397. package/dist/plugins/pg-workflow-run-store.js +7 -0
  398. package/dist/plugins/posix-shell-fs.d.ts +3 -0
  399. package/dist/plugins/posix-shell-fs.js +31 -1
  400. package/dist/plugins/remote-env-adb.d.ts +25 -0
  401. package/dist/plugins/remote-env-adb.js +95 -12
  402. package/dist/plugins/remote-env-e2b.d.ts +146 -0
  403. package/dist/plugins/remote-env-e2b.js +371 -40
  404. package/dist/plugins/remote-env-file-error.d.ts +34 -0
  405. package/dist/plugins/remote-env-file-error.js +37 -0
  406. package/dist/plugins/remote-env-host.d.ts +151 -0
  407. package/dist/plugins/remote-env-host.js +468 -70
  408. package/dist/plugins/remote-env-k8s.d.ts +135 -0
  409. package/dist/plugins/remote-env-k8s.js +318 -32
  410. package/dist/plugins/remote-env-local-docker.d.ts +65 -0
  411. package/dist/plugins/remote-env-local-docker.js +149 -24
  412. package/dist/plugins/remote-env-ssh.d.ts +35 -0
  413. package/dist/plugins/remote-env-ssh.js +117 -20
  414. package/dist/plugins/remote-scratchpad.d.ts +38 -0
  415. package/dist/plugins/remote-scratchpad.js +32 -2
  416. package/dist/plugins/remote-shell.d.ts +22 -0
  417. package/dist/plugins/remote-shell.js +27 -1
  418. package/dist/plugins/resume-anchor-store-sql.d.ts +28 -0
  419. package/dist/plugins/resume-anchor-store-sql.js +11 -0
  420. package/dist/plugins/roster-store-sql.d.ts +27 -0
  421. package/dist/plugins/roster-store-sql.js +54 -0
  422. package/dist/plugins/run-store-sql.d.ts +194 -0
  423. package/dist/plugins/run-store-sql.js +210 -9
  424. package/dist/plugins/s3-presign.d.ts +20 -0
  425. package/dist/plugins/s3-presign.js +49 -2
  426. package/dist/plugins/scheduler-support.d.ts +12 -0
  427. package/dist/plugins/scheduler-support.js +75 -3
  428. package/dist/plugins/send-file-ledger.d.ts +15 -0
  429. package/dist/plugins/send-file-ledger.js +53 -4
  430. package/dist/plugins/send-user-file.d.ts +77 -0
  431. package/dist/plugins/send-user-file.js +92 -4
  432. package/dist/plugins/session-policy-store-sql.d.ts +15 -0
  433. package/dist/plugins/session-policy-store-sql.js +75 -3
  434. package/dist/plugins/session-store.d.ts +45 -0
  435. package/dist/plugins/session-store.js +51 -0
  436. package/dist/plugins/sql-driver.d.ts +77 -0
  437. package/dist/plugins/sql-driver.js +4 -0
  438. package/dist/plugins/sql-escape.d.ts +8 -0
  439. package/dist/plugins/sql-escape.js +8 -0
  440. package/dist/plugins/sql-row-helpers.d.ts +25 -0
  441. package/dist/plugins/sql-row-helpers.js +25 -0
  442. package/dist/plugins/store-backend.d.ts +103 -0
  443. package/dist/plugins/store-backend.js +120 -27
  444. package/dist/plugins/store-contracts.d.ts +62 -0
  445. package/dist/plugins/store-contracts.js +3 -0
  446. package/dist/plugins/task-attachment-store.d.ts +60 -0
  447. package/dist/plugins/task-attachment-store.js +49 -3
  448. package/dist/plugins/task-list-store-sql.d.ts +25 -0
  449. package/dist/plugins/task-list-store-sql.js +21 -0
  450. package/dist/plugins/tidb-approval-store.d.ts +6 -0
  451. package/dist/plugins/tidb-approval-store.js +6 -0
  452. package/dist/plugins/tidb-breaker-state.d.ts +5 -0
  453. package/dist/plugins/tidb-breaker-state.js +5 -0
  454. package/dist/plugins/tidb-checkpoint-store.d.ts +7 -0
  455. package/dist/plugins/tidb-checkpoint-store.js +7 -0
  456. package/dist/plugins/tidb-cost-quota.d.ts +6 -0
  457. package/dist/plugins/tidb-cost-quota.js +1 -0
  458. package/dist/plugins/tidb-file-snapshot-store.d.ts +6 -0
  459. package/dist/plugins/tidb-file-snapshot-store.js +6 -0
  460. package/dist/plugins/tidb-image-bake.d.ts +8 -0
  461. package/dist/plugins/tidb-image-bake.js +8 -0
  462. package/dist/plugins/tidb-image-index.d.ts +8 -0
  463. package/dist/plugins/tidb-image-index.js +8 -0
  464. package/dist/plugins/tidb-outcome-ledger.d.ts +10 -0
  465. package/dist/plugins/tidb-outcome-ledger.js +10 -0
  466. package/dist/plugins/tidb-pool.d.ts +56 -0
  467. package/dist/plugins/tidb-pool.js +181 -1
  468. package/dist/plugins/tidb-rate-limiter.d.ts +11 -0
  469. package/dist/plugins/tidb-rate-limiter.js +5 -2
  470. package/dist/plugins/tidb-resume-anchor-store.d.ts +5 -0
  471. package/dist/plugins/tidb-resume-anchor-store.js +5 -0
  472. package/dist/plugins/tidb-run-store.d.ts +7 -0
  473. package/dist/plugins/tidb-run-store.js +7 -0
  474. package/dist/plugins/tidb-session-policy-store.d.ts +5 -0
  475. package/dist/plugins/tidb-session-policy-store.js +5 -0
  476. package/dist/plugins/tidb-session-storage.d.ts +43 -0
  477. package/dist/plugins/tidb-session-storage.js +62 -3
  478. package/dist/plugins/tidb-session-store.d.ts +142 -0
  479. package/dist/plugins/tidb-session-store.js +264 -16
  480. package/dist/plugins/tidb-tool-result-store.d.ts +5 -0
  481. package/dist/plugins/tidb-tool-result-store.js +7 -0
  482. package/dist/plugins/tidb-workflow-journal-store.d.ts +7 -0
  483. package/dist/plugins/tidb-workflow-journal-store.js +7 -0
  484. package/dist/plugins/tidb-workflow-run-store.d.ts +8 -0
  485. package/dist/plugins/tidb-workflow-run-store.js +8 -0
  486. package/dist/plugins/tool-result-store-sql.d.ts +58 -0
  487. package/dist/plugins/tool-result-store-sql.js +38 -2
  488. package/dist/plugins/web-search.d.ts +35 -0
  489. package/dist/plugins/web-search.js +45 -9
  490. package/dist/plugins/workflow-journal-limits.d.ts +10 -0
  491. package/dist/plugins/workflow-journal-limits.js +10 -0
  492. package/dist/plugins/workflow-journal-store-sql.d.ts +78 -0
  493. package/dist/plugins/workflow-journal-store-sql.js +58 -2
  494. package/dist/plugins/workflow-run-store-sql.d.ts +84 -0
  495. package/dist/plugins/workflow-run-store-sql.js +84 -6
  496. package/dist/plugins/worktree-isolation.d.ts +45 -0
  497. package/dist/plugins/worktree-isolation.js +105 -6
  498. package/dist/plugins/write-behind-counter.d.ts +56 -1
  499. package/dist/plugins/write-behind-counter.js +53 -14
  500. package/dist/principal-jwt.d.ts +24 -0
  501. package/dist/principal-jwt.js +60 -5
  502. package/dist/project-memory.d.ts +22 -0
  503. package/dist/project-memory.js +144 -15
  504. package/dist/prompts-domain-validate.d.ts +28 -0
  505. package/dist/prompts-domain-validate.js +42 -1
  506. package/dist/question.d.ts +33 -0
  507. package/dist/question.js +69 -2
  508. package/dist/resource-suspend.d.ts +21 -0
  509. package/dist/resource-suspend.js +16 -0
  510. package/dist/router/route-orchestration.d.ts +78 -0
  511. package/dist/router/route-orchestration.js +77 -0
  512. package/dist/run-local.d.ts +32 -0
  513. package/dist/run-local.js +172 -8
  514. package/dist/runs.d.ts +189 -4
  515. package/dist/runs.js +465 -24
  516. package/dist/runtime-caps-resolver.d.ts +106 -0
  517. package/dist/runtime-caps-resolver.js +89 -4
  518. package/dist/runtime-governance.d.ts +84 -0
  519. package/dist/runtime-governance.js +127 -1
  520. package/dist/sandbox-pkg-source.d.ts +23 -0
  521. package/dist/sandbox-pkg-source.js +37 -0
  522. package/dist/sealed-key.d.ts +54 -0
  523. package/dist/sealed-key.js +68 -3
  524. package/dist/security.d.ts +108 -0
  525. package/dist/security.js +145 -6
  526. package/dist/sema-registry.d.ts +21 -0
  527. package/dist/sema-registry.js +21 -0
  528. package/dist/session-leaf-bus.d.ts +31 -0
  529. package/dist/session-leaf-bus.js +32 -0
  530. package/dist/session-sync-content.d.ts +46 -0
  531. package/dist/session-sync-content.js +47 -1
  532. package/dist/session-sync-kernel.d.ts +89 -0
  533. package/dist/session-sync-kernel.js +48 -3
  534. package/dist/session-sync.d.ts +125 -0
  535. package/dist/session-sync.js +181 -8
  536. package/dist/session-titler.d.ts +26 -0
  537. package/dist/session-titler.js +41 -7
  538. package/dist/session-watch.d.ts +53 -1
  539. package/dist/session-watch.js +73 -9
  540. package/dist/sighup-idle.d.ts +30 -0
  541. package/dist/sighup-idle.js +12 -1
  542. package/dist/spec-fields.d.ts +91 -3
  543. package/dist/spec-fields.js +116 -4
  544. package/dist/task-cwd.d.ts +50 -0
  545. package/dist/task-cwd.js +68 -1
  546. package/dist/task-mcp.d.ts +47 -0
  547. package/dist/task-mcp.js +29 -0
  548. package/dist/task-settings.d.ts +175 -0
  549. package/dist/task-settings.js +226 -11
  550. package/dist/task-workflow.d.ts +67 -0
  551. package/dist/task-workflow.js +75 -8
  552. package/dist/tool-approval.d.ts +91 -0
  553. package/dist/tool-approval.js +215 -0
  554. package/dist/trace/artifacts.d.ts +9 -0
  555. package/dist/trace/artifacts.js +30 -5
  556. package/dist/trace/core-keyset-guard.d.ts +18 -0
  557. package/dist/trace/ledger-sink.d.ts +43 -0
  558. package/dist/trace/ledger-sink.js +64 -5
  559. package/dist/trace/project.d.ts +133 -0
  560. package/dist/trace/project.js +189 -2
  561. package/dist/trace/redact.d.ts +19 -0
  562. package/dist/trace/redact.js +66 -9
  563. package/dist/usage-analytics.d.ts +26 -0
  564. package/dist/usage-analytics.js +26 -3
  565. package/package.json +1 -1
@@ -1,4 +1,35 @@
1
1
  import type { ApprovalHmacKey } from "./auth-keys.js";
2
+ /**
3
+ * The canonical message an approval MAC signs — a fixed-order, JSON-escaped tuple so no field value (an id, a
4
+ * hash, a free-text note) can ambiguate the boundary with the next (same discipline as the approvals-stream diff
5
+ * key). 🔴 Bound to CLIENT-VISIBLE values only: `sessionId` (in the /decide URL) + `boundCallId`/`boundInputHash`
6
+ * (surfaced by listPending) + `reason` (the caller's own body). It must NOT include the checkpointToken — that is
7
+ * the unexposed resume credential the client can never see (it resumes by sessionId), so a checkpointToken-bound
8
+ * message would be uncomputable by the signer.
9
+ *
10
+ * ── `reason` 入签(三方裁 (a):cli [1797] / core [1801]§四 / server;clay「干净切」令 [1802])─────────────
11
+ * `reason` 是随决定落账的自由文本(审计面的一部分)。它此前**在信封之外** ⇒ 能改线上字节的一方(反代 /
12
+ * 被劫持的客户端 —— 正是 HMAC 要防的威胁模型)可以在操作员批准同一个动作的那次决定里,把落账理由换成
13
+ * 别的:动作没变,**审计记录变了**。三方裁定纳入签名载荷,不留 `reasonUnsigned` 宽限代际(未上生产)。
14
+ *
15
+ * ── 🔴 字节构造规则(权威定义;跨仓签名器照此实现,docs/ASSISTANT-WIRE-CONTRACT.md §6.2 同源)──────────
16
+ * 被 HMAC 的是下面这个字符串的 **UTF-8 字节**:
17
+ * 1. **恒 5 元素、定序**的紧凑 JSON 数组(元素间**无空格**):
18
+ * `[sessionId, boundCallId|null, boundInputHash|null, decision, reason|null]`
19
+ * —— 恒定长度是刻意的:签名器里少一个"有 reason 才追加"的条件分支,就少一类跨实现漂移。
20
+ * 2. 缺席 ⇒ `null`;**`""`(空串)是与 `null` 不同的被签值**(否则"把理由抹成空"不改变 MAC)。
21
+ * 3. 字符串转义 = RFC 8259 最小集:`"`→`\"`、`\`→`\\`、U+0000–U+001F → `\n`/`\t`/`\uXXXX`。
22
+ * 4. **非 ASCII 原样输出 UTF-8,不转 `\uXXXX`**。⚠️ Python 的 `json.dumps` 缺省 `ensure_ascii=True` 会踩
23
+ * —— 必须 `json.dumps(t, ensure_ascii=False, separators=(",", ":"))`。
24
+ * 5. **`<` `>` `&` 不转义**。⚠️ Go 的 `json.Marshal` 缺省 HTML 转义会踩 —— 必须
25
+ * `enc := json.NewEncoder(w); enc.SetEscapeHTML(false)`(并去掉它追加的换行)。
26
+ * 6. 孤代理项按 ES2019 well-formed 语义转成 `\udXXX`(JS 原生行为,其它语言按同规则)。
27
+ * 7. MAC = HMAC-SHA256(上述字节),**小写十六进制**上 wire。
28
+ * 逐字节黄金向量(含中文/引号/换行/制表/`<`/`&`/emoji)钉在 `test/approval-hmac.test.ts`,签名器对拍用。
29
+ *
30
+ * 之所以到今天才把规则写死:此前四个字段全是**受限字母表**(uuid / 调用 id / 十六进制 / 枚举),转义怎么
31
+ * 写都一样、规则不写也测不出来;`reason` 是第一个进入签名载荷的自由文本,转义从"无所谓"变成"承重"。
32
+ */
2
33
  export declare function approvalHmacMessage(env: {
3
34
  sessionId: string;
4
35
  boundCallId?: string | null;
@@ -6,7 +37,16 @@ export declare function approvalHmacMessage(env: {
6
37
  decision: string;
7
38
  reason?: string | null;
8
39
  }): string;
40
+ /** 签名载荷里 `reason` 的字符上限。**拒**而不是截 —— 截断在这条路径上**结构上不可行**:服务端截过的字节
41
+ * 与签名方签的字节必然不同,MAC 恒不匹配,"截断"只会把一个可诊断的 413 变成一个费解的 401。
42
+ * 取 4096 与本仓既有的人写文本上限同档(`MAX_ELICIT_MESSAGE_CHARS` / `MAX_AGENT_TEXT_CHARS`)。 */
9
43
  export declare const MAX_APPROVAL_REASON_CHARS = 4096;
44
+ /**
45
+ * design/80 D-G: verify the INTEGRITY of an approval-decision envelope. Returns true iff `mac` (hex) equals
46
+ * HMAC-SHA256(canonical-envelope) under ANY key in the set — the `kid`-hinted key first, then the rest (so a MAC
47
+ * signed with a key being rotated out still verifies during the overlap). `timingSafeEqual` avoids a timing
48
+ * oracle. An empty key-set ⇒ false (caller decides whether absence = skip-because-inactive or fail-closed).
49
+ */
10
50
  export declare function verifyApprovalHmac(env: {
11
51
  sessionId: string;
12
52
  boundCallId?: string | null;
@@ -1,8 +1,75 @@
1
+ /**
2
+ * design/80 D-G: approval-envelope HMAC (INTEGRITY, not identity). Split out of `security.ts` (design/158
3
+ * A13, internal-lossless — the facade re-exports every symbol below unchanged; verifyDirectDoorProof in
4
+ * ./principal-jwt.ts imports {@link verifyApprovalHmac} from here for the combined proof).
5
+ *
6
+ * ✅ WIRED into the resolve path (was "🔴 SCAFFOLD — NOT YET WIRED" — that claim went STALE; a 2026-07-25 doc-rot
7
+ * sweep traced the real call chain: {@link verifyApprovalHmac} ← `verifyDirectDoorProof` ← the live decide
8
+ * routes at `http/server.ts:4796` and `:4907`). So "not wired" was wrong; "not turned on" is right, and turning it
9
+ * on is a DEPLOYMENT + KEY-PROVISIONING task (sema-registry mints/rotates the set), not a coding task.
10
+ *
11
+ * FULL activation chain (an independent 2026-07-25 cross-check caught the first draft of this note naming only the
12
+ * leaf conditions — record it completely so a deployment engineer isn't surprised): the crypto branch lives ONLY
13
+ * under the durable-checkpoint /decide path, whose route block is gated on `deps.checkpointStore`
14
+ * (`http/server.ts:4517`), which needs `backend?.checkpoint && config.durableApproval` (`main.ts:1902`). That is NOT
15
+ * an extra thing to remember, because `directDoorActive` ALREADY requires `DURABLE_APPROVAL=true` by construction
16
+ * (`config.ts:1264` — and see the 🔴 note above it: without it, checkpointStore is undefined, this branch is
17
+ * skipped, and the LEGACY trusted-header /decide becomes live = a full crypto bypass). So `directDoorActive` really
18
+ * is the single load-bearing switch — it just transitively implies the durable store, rather than being independent
19
+ * of it. A half-configured door refuses to boot (`config.ts:1266`+), so "looks on, verifies nothing" is impossible.
20
+ * This is the crypto FOUNDATION for D-G (the direct-connect approval door): it proves the decision envelope
21
+ * `{checkpointToken, boundCallId, boundInputHash, decision}` was not tampered in transit. It is INTEGRITY, NOT
22
+ * identity — `isOperator(principal)` stays the identity gate (a valid MAC says "the bytes are intact", never
23
+ * "this is the operator").
24
+ * The KEY-SET shape here is PROVISIONAL — sema-registry owns the final secret format; only parseApprovalHmacKeys
25
+ * changes if it differs. Replay protection is the checkpointToken's SINGLE-USE nature (a replayed MAC names an
26
+ * already-resolved token → the resolve CAS fails already_resolved), so no separate replay cache is needed.
27
+ */
1
28
  import { createHmac, timingSafeEqual } from "node:crypto";
29
+ /**
30
+ * The canonical message an approval MAC signs — a fixed-order, JSON-escaped tuple so no field value (an id, a
31
+ * hash, a free-text note) can ambiguate the boundary with the next (same discipline as the approvals-stream diff
32
+ * key). 🔴 Bound to CLIENT-VISIBLE values only: `sessionId` (in the /decide URL) + `boundCallId`/`boundInputHash`
33
+ * (surfaced by listPending) + `reason` (the caller's own body). It must NOT include the checkpointToken — that is
34
+ * the unexposed resume credential the client can never see (it resumes by sessionId), so a checkpointToken-bound
35
+ * message would be uncomputable by the signer.
36
+ *
37
+ * ── `reason` 入签(三方裁 (a):cli [1797] / core [1801]§四 / server;clay「干净切」令 [1802])─────────────
38
+ * `reason` 是随决定落账的自由文本(审计面的一部分)。它此前**在信封之外** ⇒ 能改线上字节的一方(反代 /
39
+ * 被劫持的客户端 —— 正是 HMAC 要防的威胁模型)可以在操作员批准同一个动作的那次决定里,把落账理由换成
40
+ * 别的:动作没变,**审计记录变了**。三方裁定纳入签名载荷,不留 `reasonUnsigned` 宽限代际(未上生产)。
41
+ *
42
+ * ── 🔴 字节构造规则(权威定义;跨仓签名器照此实现,docs/ASSISTANT-WIRE-CONTRACT.md §6.2 同源)──────────
43
+ * 被 HMAC 的是下面这个字符串的 **UTF-8 字节**:
44
+ * 1. **恒 5 元素、定序**的紧凑 JSON 数组(元素间**无空格**):
45
+ * `[sessionId, boundCallId|null, boundInputHash|null, decision, reason|null]`
46
+ * —— 恒定长度是刻意的:签名器里少一个"有 reason 才追加"的条件分支,就少一类跨实现漂移。
47
+ * 2. 缺席 ⇒ `null`;**`""`(空串)是与 `null` 不同的被签值**(否则"把理由抹成空"不改变 MAC)。
48
+ * 3. 字符串转义 = RFC 8259 最小集:`"`→`\"`、`\`→`\\`、U+0000–U+001F → `\n`/`\t`/`\uXXXX`。
49
+ * 4. **非 ASCII 原样输出 UTF-8,不转 `\uXXXX`**。⚠️ Python 的 `json.dumps` 缺省 `ensure_ascii=True` 会踩
50
+ * —— 必须 `json.dumps(t, ensure_ascii=False, separators=(",", ":"))`。
51
+ * 5. **`<` `>` `&` 不转义**。⚠️ Go 的 `json.Marshal` 缺省 HTML 转义会踩 —— 必须
52
+ * `enc := json.NewEncoder(w); enc.SetEscapeHTML(false)`(并去掉它追加的换行)。
53
+ * 6. 孤代理项按 ES2019 well-formed 语义转成 `\udXXX`(JS 原生行为,其它语言按同规则)。
54
+ * 7. MAC = HMAC-SHA256(上述字节),**小写十六进制**上 wire。
55
+ * 逐字节黄金向量(含中文/引号/换行/制表/`<`/`&`/emoji)钉在 `test/approval-hmac.test.ts`,签名器对拍用。
56
+ *
57
+ * 之所以到今天才把规则写死:此前四个字段全是**受限字母表**(uuid / 调用 id / 十六进制 / 枚举),转义怎么
58
+ * 写都一样、规则不写也测不出来;`reason` 是第一个进入签名载荷的自由文本,转义从"无所谓"变成"承重"。
59
+ */
2
60
  export function approvalHmacMessage(env) {
3
61
  return JSON.stringify([env.sessionId, env.boundCallId ?? null, env.boundInputHash ?? null, env.decision, env.reason ?? null]);
4
62
  }
63
+ /** 签名载荷里 `reason` 的字符上限。**拒**而不是截 —— 截断在这条路径上**结构上不可行**:服务端截过的字节
64
+ * 与签名方签的字节必然不同,MAC 恒不匹配,"截断"只会把一个可诊断的 413 变成一个费解的 401。
65
+ * 取 4096 与本仓既有的人写文本上限同档(`MAX_ELICIT_MESSAGE_CHARS` / `MAX_AGENT_TEXT_CHARS`)。 */
5
66
  export const MAX_APPROVAL_REASON_CHARS = 4_096;
67
+ /**
68
+ * design/80 D-G: verify the INTEGRITY of an approval-decision envelope. Returns true iff `mac` (hex) equals
69
+ * HMAC-SHA256(canonical-envelope) under ANY key in the set — the `kid`-hinted key first, then the rest (so a MAC
70
+ * signed with a key being rotated out still verifies during the overlap). `timingSafeEqual` avoids a timing
71
+ * oracle. An empty key-set ⇒ false (caller decides whether absence = skip-because-inactive or fail-closed).
72
+ */
6
73
  export function verifyApprovalHmac(env, mac, kid, keys) {
7
74
  if (keys.length === 0)
8
75
  return false;
@@ -1,27 +1,58 @@
1
+ /**
2
+ * OA human-in-the-loop approval gate (F4) — a `ToolPolicy` that holds a gated tool call until an
3
+ * operator approves/denies, with the pending state in TiDB so the decision can arrive on any instance.
4
+ *
5
+ * Built on core's `createApprovalPolicy` (which routes requireApproval/deny and races the wait against
6
+ * the task's AbortSignal). Our `approve` records a pending row and polls it for a decision; it also
7
+ * honors the signal directly (marks the request expired and releases) so a never-answered approval is
8
+ * dropped at the task deadline instead of holding the worker — design/06 F4 self-protection.
9
+ */
1
10
  import { type ToolPolicy } from "@sema-agent/core";
2
11
  import type { ApprovalStore } from "./plugins/store-backend.js";
12
+ /**
13
+ * Durable approval policy (core 1.67 / design/45): returns three-state **`ask`** for gated tools instead of
14
+ * polling. With `TaskSpec.durableApproval` set + a `checkpointStore` on the Runner, core turns that `ask` into
15
+ * a **suspend** (persists a checkpoint, ends `status:"suspended"`) — no held connection, resumable on any
16
+ * replica. (Contrast {@link createOaApprovalPolicy}, which holds the call open by polling a TiDB row.)
17
+ */
3
18
  export declare function createDurableAskPolicy(opts: {
4
19
  requireApproval: string[];
5
20
  deny?: string[];
6
21
  autoBudget?: number;
7
22
  neverAuto?: string[];
23
+ /** Per-session approval-exemption probe ("本会话不再询问"): consulted ONLY for require-listed
24
+ * tools, AFTER deny/neverAuto (both always win) and BEFORE the budget path. Canonical-space toolName.
25
+ * A rejected promise is treated as NOT exempt (fail-closed → ask) at the call site below. */
8
26
  exempt?: (canonicalToolName: string) => Promise<boolean>;
27
+ /** Audit hook — fired when an exemption short-circuits the ask (the `approval_exempted` log line). */
9
28
  onExempted?: (canonicalToolName: string, rawToolName: string) => void;
10
29
  }): ToolPolicy;
11
30
  export interface OaApprovalOptions {
12
31
  store: ApprovalStore;
32
+ /** Tool names that require an operator decision before they run. */
13
33
  requireApproval: string[];
34
+ /** Safety tools that must ALWAYS reach a human — checked BEFORE the exemption probe (workflow audit
35
+ * 2026-07-13: the OA leg consumed exemptions without the neverAuto guard, so a grant made in durable mode
36
+ * could silently auto-approve a NEVER_AUTO tool after an ops switch back to the poll gate). */
14
37
  neverAuto?: string[];
38
+ /** Session exemption probe — same contract as createDurableAskPolicy.exempt (fail-closed). */
15
39
  exempt?: (sessionId: string, canonicalToolName: string) => Promise<boolean>;
40
+ /** Audit hook for an exemption short-circuit. */
16
41
  onExempted?: (sessionId: string, canonicalToolName: string) => void;
42
+ /** Per-run context captured for the approval row (operator UI shows session/tool/args). */
17
43
  context: () => {
18
44
  taskId?: string | null;
19
45
  sessionId?: string | null;
20
46
  owner?: string | null;
21
47
  };
48
+ /** Always-denied tools. */
22
49
  deny?: string[];
50
+ /** Poll interval for the decision. Default 1500ms. */
23
51
  pollMs?: number;
24
52
  }
25
53
  export declare function createOaApprovalPolicy(opts: OaApprovalOptions): ToolPolicy;
54
+ /** Poll the approval row until decided, or release (deny) when the task aborts. Exported for unit tests.
55
+ * `scope` is the run's tenant identity (owner-sourced) — carried on every read/decide so a run only ever
56
+ * observes/aborts its OWN pending row (single-DB fleet read guard; defense-in-depth). */
26
57
  export declare function waitForDecision(store: ApprovalStore, id: string, scope: string | null, signal: AbortSignal | undefined, pollMs: number): Promise<boolean>;
27
58
  //# sourceMappingURL=approval.d.ts.map
package/dist/approval.js CHANGED
@@ -1,30 +1,68 @@
1
+ /**
2
+ * OA human-in-the-loop approval gate (F4) — a `ToolPolicy` that holds a gated tool call until an
3
+ * operator approves/denies, with the pending state in TiDB so the decision can arrive on any instance.
4
+ *
5
+ * Built on core's `createApprovalPolicy` (which routes requireApproval/deny and races the wait against
6
+ * the task's AbortSignal). Our `approve` records a pending row and polls it for a decision; it also
7
+ * honors the signal directly (marks the request expired and releases) so a never-answered approval is
8
+ * dropped at the task deadline instead of holding the worker — design/06 F4 self-protection.
9
+ */
1
10
  import { createApprovalPolicy, canonicalToolName, uuidv7 } from "@sema-agent/core";
11
+ /**
12
+ * Durable approval policy (core 1.67 / design/45): returns three-state **`ask`** for gated tools instead of
13
+ * polling. With `TaskSpec.durableApproval` set + a `checkpointStore` on the Runner, core turns that `ask` into
14
+ * a **suspend** (persists a checkpoint, ends `status:"suspended"`) — no held connection, resumable on any
15
+ * replica. (Contrast {@link createOaApprovalPolicy}, which holds the call open by polling a TiDB row.)
16
+ */
2
17
  export function createDurableAskPolicy(opts) {
18
+ // 🔒 CANONICAL-space matching (mirrors core 1.202 `createAllowDenyPolicy` + the design/116 S8 discipline):
19
+ // configured names AND the live request name both normalize via `canonicalToolName`, so an operator rule written
20
+ // against a legacy alias ("Task"/"KillShell"/"MultiEdit") keeps gating after a core CC-parity rename, and a
21
+ // durable-resume replay carrying a pre-rename `req.toolName` can't slip a rule written in the new names. A raw
22
+ // compare here is the same silent fail-open class the 1.202 rename exposed in main.ts's read-only strip.
3
23
  const require = new Set(opts.requireApproval.map(canonicalToolName));
4
24
  const deny = new Set((opts.deny ?? []).map(canonicalToolName));
5
25
  const neverAuto = new Set((opts.neverAuto ?? []).map(canonicalToolName));
6
26
  const budget = Math.max(0, Math.floor(opts.autoBudget ?? 0));
27
+ // design/80 D-E (upgrade-budget): a per-run-leg counter of NORMAL gated calls auto-approved so far. The policy
28
+ // is rebuilt per resolveSpec call (= per submit AND per resume — server.ts), so this closure is per-leg —
29
+ // adequate for a runaway-loop circuit-breaker (the loop lives within one leg; a suspend only fires on an
30
+ // over-budget / never-auto ask, which escalates to a human anyway). A durable per-run budget is a refinement.
7
31
  let autoApproved = 0;
8
32
  return {
9
33
  check: (req) => {
10
- const toolName = canonicalToolName(req.toolName);
34
+ const toolName = canonicalToolName(req.toolName); // canonical-space lookup; messages keep the raw name for the operator
11
35
  if (deny.has(toolName))
12
36
  return { action: "deny", message: `tool "${req.toolName}" is denied by policy` };
37
+ // inv#2: a never-auto (irreversible / safety) tool ALWAYS asks a human — UNCONDITIONALLY, even if it was not
38
+ // also listed in requireApproval. An operator marking a tool "never auto-approve" means "always human"; it
39
+ // must never fall through to a bare allow (the footgun: neverAuto ⊄ requireApproval). Checked BEFORE the
40
+ // budget so a safety tool is never auto-approved. The enforcement is THIS deterministic policy `ask` — NOT a
41
+ // decisionReason (core 1.102 council proved decisionReason both misses policy-ask asks AND is forgeable, so
42
+ // the safety axis is sourced only from tool marks / core's persisted CheckpointGate.safetyAxis, never here).
13
43
  if (neverAuto.has(toolName))
14
44
  return { action: "ask", message: `human approval required to run "${req.toolName}"` };
15
45
  if (require.has(toolName)) {
46
+ // Invariant alignment (workflow audit 2026-07-13): the DURABLE-resource-exhausted escalation is a
47
+ // SAFETY-axis ask (like neverAuto), so it outranks an exemption. In practice core already fail-fasts
48
+ // an exhausted leg before any tool call (runtask budget gate) — this is defense-in-depth ordering,
49
+ // zero behavior change on the live path, and it makes "耗尽恒问人" structural rather than incidental.
16
50
  const remEarly = req.budget?.resourceRemainingMicroUsd;
17
51
  if (remEarly !== undefined && remEarly <= 0) {
18
52
  return { action: "ask", message: `durable resource budget exhausted — human approval required to run "${req.toolName}"` };
19
53
  }
54
+ // Session exemption — an APPROVAL MEMORY, not a policy loosen: deny/neverAuto already won
55
+ // above; this only skips the HUMAN ask for a require-listed tool the operator said "remember" on. The
56
+ // probe is fail-closed (store error ⇒ not exempt ⇒ the normal ask path). AskUserQuestion is excluded
57
+ // for the same reason as the budget below (owned by the durable-question policy; its ask must stand).
20
58
  if (opts.exempt && toolName !== "AskUserQuestion") {
21
59
  return (async () => {
22
60
  let exempted = false;
23
61
  try {
24
- exempted = (await opts.exempt(toolName)) === true;
62
+ exempted = (await opts.exempt(toolName)) === true; // strict: a truthy non-boolean must not auto-approve
25
63
  }
26
64
  catch {
27
- exempted = false;
65
+ exempted = false; // fail-closed: a store hiccup must never auto-approve
28
66
  }
29
67
  if (exempted) {
30
68
  opts.onExempted?.(toolName, req.toolName);
@@ -38,11 +76,27 @@ export function createDurableAskPolicy(opts) {
38
76
  return { action: "allow" };
39
77
  },
40
78
  };
79
+ /** The pre-existing require-branch tail (durable resource cap → per-leg count budget → ask), factored so the
80
+ * async exemption probe and the sync path share ONE implementation (no drift). */
41
81
  function decideRequired(req, toolName) {
82
+ // a NORMAL gated tool AUTO-APPROVES while under the per-leg budget (the AI proceeds, no human); once the
83
+ // budget is exhausted the rest escalate to a human (the circuit-breaker trips). budget 0 ⇒ always ask.
84
+ // 🔴 EXCLUDE AskUserQuestion: it is owned by the durable-question policy (it ALWAYS asks), and
85
+ // combinePolicies (deny>ask>allow) makes that ask outrank our allow anyway — so counting it would
86
+ // silently shrink the real auto-approve budget for genuine NORMAL tools (adversarial finding). It falls
87
+ // through to ask here, consuming no budget.
88
+ // design/80 D-E-core (b, Framing 3): self-limit against the DURABLE resource ledger. If the run's durable
89
+ // resource budget is EXHAUSTED, escalate to a human REGARDLESS of the per-leg count budget. `req.budget`
90
+ // (core 1.103, built per-leg from the frozen-total resourceLedger) survives suspend/resume and CANNOT be
91
+ // re-granted (frozen-total, prior-wins) — so this is the durable cap that closes the per-leg re-grant below.
92
+ // 🔴 `resourceRemainingMicroUsd` is NEVER falsy-tested: 0 = exhausted (escalate), undefined = no ceiling.
42
93
  const rem = req.budget?.resourceRemainingMicroUsd;
43
94
  if (rem !== undefined && rem <= 0) {
44
95
  return { action: "ask", message: `durable resource budget exhausted — human approval required to run "${req.toolName}"` };
45
96
  }
97
+ // The per-leg COUNT budget remains a circuit-breaker (looser than configured across a deny-resume, but
98
+ // BOUNDED by core's suspendLoopCap, and inv#2 holds — a safety tool returned ask above). The durable
99
+ // resource cap above is the exact-per-run limiter the per-leg counter could not be (finding#1).
46
100
  if (toolName !== "AskUserQuestion" && budget > 0 && autoApproved < budget) {
47
101
  autoApproved++;
48
102
  return { action: "allow" };
@@ -58,12 +112,16 @@ export function createOaApprovalPolicy(opts) {
58
112
  deny: opts.deny,
59
113
  approve: async (req, signal) => {
60
114
  const ctx = opts.context();
115
+ // Session exemption — core already routed deny (deny wins before approve is ever called);
116
+ // a remembered (sessionId, toolName) auto-approves without a pending row. Fail-closed on a store error.
117
+ // neverAuto ALWAYS wins the exemption (same ordering lock as the durable policy — the OA leg previously
118
+ // lacked this guard, workflow audit 2026-07-13).
61
119
  if (opts.exempt && ctx.sessionId) {
62
120
  const toolName = canonicalToolName(req.toolName);
63
121
  if (toolName !== "AskUserQuestion" && !neverAuto.has(toolName)) {
64
122
  let exempted = false;
65
123
  try {
66
- exempted = (await opts.exempt(ctx.sessionId, toolName)) === true;
124
+ exempted = (await opts.exempt(ctx.sessionId, toolName)) === true; // strict boolean, same as the durable twin
67
125
  }
68
126
  catch {
69
127
  exempted = false;
@@ -75,13 +133,19 @@ export function createOaApprovalPolicy(opts) {
75
133
  }
76
134
  }
77
135
  const id = uuidv7();
136
+ // scope = the run's tenant identity, owner-sourced (single-DB fleet read guard; defense-in-depth). The
137
+ // poll/abort paths below carry the SAME scope so this run only ever reads/aborts its own pending row.
78
138
  const scope = ctx.owner ?? null;
79
139
  await opts.store.createPending(id, scope, { ...ctx, toolName: req.toolName, args: req.args });
80
140
  return waitForDecision(opts.store, id, scope, signal, pollMs);
81
141
  },
82
142
  });
83
143
  }
144
+ /** Consecutive poll errors tolerated before giving up (a persistent outage still fail-closes to deny). */
84
145
  const MAX_POLL_ERRORS = 5;
146
+ /** Poll the approval row until decided, or release (deny) when the task aborts. Exported for unit tests.
147
+ * `scope` is the run's tenant identity (owner-sourced) — carried on every read/decide so a run only ever
148
+ * observes/aborts its OWN pending row (single-DB fleet read guard; defense-in-depth). */
85
149
  export async function waitForDecision(store, id, scope, signal, pollMs) {
86
150
  let consecutiveErrors = 0;
87
151
  for (;;) {
@@ -95,6 +159,10 @@ export async function waitForDecision(store, id, scope, signal, pollMs) {
95
159
  consecutiveErrors = 0;
96
160
  }
97
161
  catch (e) {
162
+ // A single transient TiDB blip must NOT throw out of the poll loop — core fail-closes a thrown
163
+ // approval policy to DENY, so one hiccup would deny an already-approved high-risk call after the
164
+ // operator clicked approve. Tolerate a few consecutive errors (keep polling); only give up (re-throw →
165
+ // deny) on a persistent outage.
98
166
  if (++consecutiveErrors >= MAX_POLL_ERRORS)
99
167
  throw e;
100
168
  await sleepAbortable(pollMs, signal);
package/dist/audit.d.ts CHANGED
@@ -1,15 +1,26 @@
1
1
  import type { Pool } from "mysql2/promise";
2
2
  import type { Pool as PgPool } from "pg";
3
+ /**
4
+ * Audit view of a session = its **current context** (the live messages + the last compaction's
5
+ * summary), i.e. the floor-bounded window — never the full raw transcript. This matches the
6
+ * deployment decision that audit/回溯 needs "current + summary" (design/08); the full `session_event`
7
+ * log remains available as a separate cold-forensic query if ever needed.
8
+ */
3
9
  export interface SessionAudit {
4
10
  sessionId: string;
5
11
  createdAt: string;
12
+ /** The bounded-window floor (last compaction's firstKeptEntryId), or null if never compacted. */
6
13
  floorEntryId: string | null;
7
14
  thinkingLevel: string;
8
15
  model: {
9
16
  provider: string;
10
17
  modelId: string;
11
18
  } | null;
19
+ /** Current model context: prior messages with older history collapsed into a summary message. */
12
20
  messages: unknown[];
21
+ /** [1023]① web 观测切片 B: the session's prompt-epoch pin, core contract verbatim (core 1.304
22
+ * `session.getPromptEpoch()` — first-class `prompt_epoch` entry, compaction restatement, RB-14 anchor
23
+ * all inside core). Additive; a pre-epoch session omits the key entirely (undefined). */
13
24
  promptEpoch?: {
14
25
  epoch: number;
15
26
  artifactDigest: string;
@@ -18,9 +29,19 @@ export interface SessionAudit {
18
29
  activatedBy: "session_start" | "compaction" | "legacy_migration";
19
30
  };
20
31
  }
32
+ /** Build the audit view from the durable log. Returns undefined if the session does not exist. */
21
33
  export declare function buildSessionAudit(pool: Pool, sessionId: string): Promise<SessionAudit | undefined>;
34
+ /** The PG twin — same view over PgSessionStorage.wake. Until this, the
35
+ * audit face was TiDB-only and a PG/local deployment 404'd the whole web session area. local = follow-on
36
+ * (its storage seam has no wake-equivalent yet — may turn out to be a core gap). */
22
37
  export declare function buildSessionAuditPg(pool: PgPool, sessionId: string): Promise<SessionAudit | undefined>;
38
+ /** The LOCAL (File) leg — web session area on DB_BACKEND=local.
39
+ * 实现姿势:`FileSessionRepo.exportEntries`(纯读、torn-tail 恢复、missing→not_found)→
40
+ * `boundedTail`(纯函数切 floor)→ InMemorySessionStorage → 同一 auditFromStorage 内核。零写面、
41
+ * 零新 seam;createdAt 从 repo.list() 的 metadata 取(File 形态 meta 与 entries 分储)。 */
23
42
  export declare function buildSessionAuditLocal(root: string, sessionId: string): Promise<SessionAudit | undefined>;
43
+ /** Window `messages` — `tail=N` (last N) or `before=<offset>&limit=N` ([max(0,before-N), before)).
44
+ * Returns the window + its {offset,total} so the web can page upward. */
24
45
  export declare function windowMessages(messages: unknown[], opts: {
25
46
  tail?: number;
26
47
  before?: number;
@@ -32,5 +53,10 @@ export declare function windowMessages(messages: unknown[], opts: {
32
53
  total: number;
33
54
  };
34
55
  };
56
+ /** Cap oversized STRING bodies inside a message (top-level `content` string, or `text`/`content`
57
+ * string fields of content parts — the shapes core emits; anything else passes through untouched). A capped
58
+ * message gains `truncated: true` (message level — the web renders an expand affordance and refetches that
59
+ * one message at full size). Pure/copy-on-write: uncapped messages keep their original reference.
60
+ * [1075]①:超预算时引擎注入块(INJECTED_BLOCK_RE 闭集)优先整段让位,用户正文最后截。 */
35
61
  export declare function truncateMessageBlobs(messages: unknown[], capBytes: number): unknown[];
36
62
  //# sourceMappingURL=audit.d.ts.map
package/dist/audit.js CHANGED
@@ -1,12 +1,23 @@
1
+ // 🔴 core 1.403 迁移(2026-07-25):`Session` 从 runtime class 降级成纯 interface,可构造的 storage-backed
2
+ // class 改名 `StoredSession`(core CHANGELOG 1.403.0:"the constructable storage-backed class formerly
3
+ // exported as `Session` is now `StoredSession`")——这里是 runtime 构造用法,照 core 给的迁移指南改。
1
4
  import { StoredSession, FileSessionRepo, InMemorySessionStorage, boundedTail } from "@sema-agent/core";
2
5
  import { TiDBSessionStorage } from "./plugins/tidb-session-storage.js";
3
6
  import { PgSessionStorage } from "./plugins/pg-session-storage.js";
7
+ /** Build the audit view from the durable log. Returns undefined if the session does not exist. */
4
8
  export async function buildSessionAudit(pool, sessionId) {
5
9
  return auditFromStorage(await TiDBSessionStorage.wake(pool, sessionId), sessionId);
6
10
  }
11
+ /** The PG twin — same view over PgSessionStorage.wake. Until this, the
12
+ * audit face was TiDB-only and a PG/local deployment 404'd the whole web session area. local = follow-on
13
+ * (its storage seam has no wake-equivalent yet — may turn out to be a core gap). */
7
14
  export async function buildSessionAuditPg(pool, sessionId) {
8
15
  return auditFromStorage(await PgSessionStorage.wake(pool, sessionId), sessionId);
9
16
  }
17
+ /** The LOCAL (File) leg — web session area on DB_BACKEND=local.
18
+ * 实现姿势:`FileSessionRepo.exportEntries`(纯读、torn-tail 恢复、missing→not_found)→
19
+ * `boundedTail`(纯函数切 floor)→ InMemorySessionStorage → 同一 auditFromStorage 内核。零写面、
20
+ * 零新 seam;createdAt 从 repo.list() 的 metadata 取(File 形态 meta 与 entries 分储)。 */
10
21
  export async function buildSessionAuditLocal(root, sessionId) {
11
22
  const repo = new FileSessionRepo(root);
12
23
  let entries;
@@ -21,14 +32,19 @@ export async function buildSessionAuditLocal(root, sessionId) {
21
32
  const meta = (await repo.list()).find((m) => m.id === sessionId);
22
33
  const { tail, floorEntryId } = boundedTail(entries);
23
34
  const storage = new InMemorySessionStorage({ entries: tail, floorEntryId, ...(meta ? { metadata: meta } : {}) });
24
- return auditFromStorage(storage, sessionId);
35
+ return auditFromStorage(storage, sessionId); // BaseSessionStorage 本有 getFloorId(构造喂了 floorEntryId)
25
36
  }
37
+ /** The dialect-neutral kernel: both wake() twins land on core's StoredSession over a BaseSessionStorage. */
26
38
  async function auditFromStorage(storage, sessionId) {
27
39
  if (!storage)
28
40
  return undefined;
29
41
  const session = new StoredSession(storage);
30
42
  const meta = await session.getMetadata();
31
43
  const ctx = await session.buildContext();
44
+ // [1023]①: the typed prompt_epoch entry is NOT an LLM message, so it never appears in buildContext()'s
45
+ // messages — attach it as its own additive field. One kernel call covers all three dialect twins.
46
+ // (On the Local leg the bounded tail may pre-date the root pin; core resolves through the kept
47
+ // compaction's restatement — a truly pre-epoch session stays undefined → key omitted.)
32
48
  const promptEpoch = await session.getPromptEpoch();
33
49
  return {
34
50
  sessionId,
@@ -40,6 +56,18 @@ async function auditFromStorage(storage, sessionId) {
40
56
  ...(promptEpoch ? { promptEpoch } : {}),
41
57
  };
42
58
  }
59
+ // ── web 会话区性能 PRD 的两条 additive 缝 ────────────────────────────────────────────────────
60
+ //
61
+ // The audit view's `messages` used to be ALL-OR-NOTHING: a 1000-entry session shipped its whole current
62
+ // context on open (first-paint transfer + parse both scale with history). Two PURE post-processing helpers
63
+ // give the route the additive knobs (hard requirement: parameterless requests stay byte-identical):
64
+ // windowMessages — tail/before+limit windowing over the messages array (offset-based; offsets are stable
65
+ // within one floor generation — the response's floorEntryId is the generation tag, a compaction changes
66
+ // it and the web refetches);
67
+ // truncateMessageBlobs — cap oversized string bodies (tool outputs are the whale) to a preview + a
68
+ // `truncated:true` marker; the web expands one message on demand via the single-message face.
69
+ /** Window `messages` — `tail=N` (last N) or `before=<offset>&limit=N` ([max(0,before-N), before)).
70
+ * Returns the window + its {offset,total} so the web can page upward. */
43
71
  export function windowMessages(messages, opts) {
44
72
  const total = messages.length;
45
73
  if (opts.before !== undefined) {
@@ -52,7 +80,12 @@ export function windowMessages(messages, opts) {
52
80
  const offset = Math.max(0, total - tail);
53
81
  return { messages: messages.slice(offset), window: { offset, total } };
54
82
  }
83
+ /** 引擎注入块的闭集标签([1075]①,web [1069] 同款拆法):user wire 消息里每轮前置的
84
+ * <system-reminder>/<task-notification> 原文段。裁剪时这些段**优先整段丢弃**——blobCap 预算留给
85
+ * 用户真正说的话(clay 报障现场:注入块排在人话前把 4096 字节吃光,`[truncated …]` 后正文整段消失)。 */
55
86
  const INJECTED_BLOCK_RE = /<(system-reminder|task-notification)>[\s\S]*?<\/\1>\s*/g;
87
+ /** blobCap 下先剥注入块再量预算:剥后若已在预算内=保住全部人话(加 `injectedDropped:true` 注记);
88
+ * 仍超才截人话本身。剥离只在「原文本超预算」时发生——预算内的消息原样(含注入块)零变化,旧行为不动。 */
56
89
  function capWithInjectionAwareness(s, capBytes) {
57
90
  const total = Buffer.byteLength(s, "utf8");
58
91
  if (total <= capBytes)
@@ -62,8 +95,14 @@ function capWithInjectionAwareness(s, capBytes) {
62
95
  if (droppedAny && Buffer.byteLength(stripped, "utf8") <= capBytes) {
63
96
  return { text: `${stripped}…[${total - Buffer.byteLength(stripped, "utf8")} bytes of injected context omitted]`, dropped: true };
64
97
  }
98
+ // 剥后仍超(或无注入块):截 stripped——人话最后动,且从头保留(注入块已让位)。
65
99
  return { text: `${stripped.slice(0, capBytes)}…[truncated ${total} bytes total]`, dropped: droppedAny };
66
100
  }
101
+ /** Cap oversized STRING bodies inside a message (top-level `content` string, or `text`/`content`
102
+ * string fields of content parts — the shapes core emits; anything else passes through untouched). A capped
103
+ * message gains `truncated: true` (message level — the web renders an expand affordance and refetches that
104
+ * one message at full size). Pure/copy-on-write: uncapped messages keep their original reference.
105
+ * [1075]①:超预算时引擎注入块(INJECTED_BLOCK_RE 闭集)优先整段让位,用户正文最后截。 */
67
106
  export function truncateMessageBlobs(messages, capBytes) {
68
107
  const capStr = (s) => capWithInjectionAwareness(s, capBytes)?.text;
69
108
  return messages.map((m) => {
@@ -4,15 +4,20 @@ import type { Metrics } from "./observability/metrics.js";
4
4
  export type { VerifiedIdentity } from "@sema-agent/registry-core/api/auth-bridge";
5
5
  export { looksLikeJwt } from "@sema-agent/registry-core/api/auth-bridge";
6
6
  export interface RegistryJwtVerifierOptions {
7
+ /** R4 — 期望 iss(registry 的 SSO_ISSUER;默认=SEMA_REGISTRY_URL,双侧去尾斜杠比较)。 */
7
8
  issuer: string;
9
+ /** R2 — JWKS 绝对 URL(默认=issuer + REGISTRY_JWKS_PATH)。 */
8
10
  jwksUrl?: string;
11
+ /** R7 — 设了则 aud 必须包含它;不设=忽略 aud。 */
9
12
  audience?: string;
10
13
  clockSkewSec?: number;
11
14
  jwksRefreshMinIntervalSec?: number;
12
15
  offlineGraceSec?: number;
16
+ /** 常规(非 kid-miss)缓存刷新周期——过期后下一次 verify 顺路重拉(成功前旧键继续用,R8 语义)。 */
13
17
  jwksTtlSec?: number;
14
18
  logger?: Logger;
15
19
  metrics?: Pick<Metrics, "inc" | "observe">;
20
+ /** 测试注入。 */
16
21
  fetchImpl?: typeof fetch;
17
22
  nowMs?: () => number;
18
23
  }
@@ -23,8 +28,13 @@ export type VerifyOutcome = {
23
28
  ok: false;
24
29
  error: AuthBridgeErrorCode;
25
30
  };
31
+ /** The live object `createRegistryJwtVerifier` produces — a single `verify` entry point over the process-level JWKS cache. */
26
32
  export interface RegistryJwtVerifier {
27
33
  verify: (bearer: string) => Promise<VerifyOutcome>;
28
34
  }
35
+ /**
36
+ * registry-JWT verifier(单例,进程级 JWKS 缓存)。`verify(bearer)` 全程不 throw——一切异常折为
37
+ * AUTH_BRIDGE_ERROR_CODES(HTTP 面由调用方恒答 generic 401,码只进日志/metrics,R9)。
38
+ */
29
39
  export declare function createRegistryJwtVerifier(opts: RegistryJwtVerifierOptions): RegistryJwtVerifier;
30
40
  //# sourceMappingURL=auth-bridge.d.ts.map