@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
@@ -4,9 +4,19 @@ import { NotifiedKeys, taskNotificationStreamKey } from "../orchestration/workfl
4
4
  export function createLedgerSink(opts) {
5
5
  const keys = opts.notifiedKeys ?? new NotifiedKeys();
6
6
  let seq = 0;
7
+ // [1.211 codex H2] 单写串行链:seq 的「分配」在链步内发生 ⇒ 分配序 == durable 提交序。没有它,
8
+ // onForwardEvent 的 fire-and-forget 写与主循环的 awaited 写交错时,高 seq 可先落盘对 events tail 可见,
9
+ // 迟到的低 seq 在读方游标(afterSeq)前进后被永久遗漏。链上一步失败不断链(catch → undefined),
10
+ // 调用方拿到的是自己那步的真实结果(await 者照常收到 reject)。
7
11
  let chain = Promise.resolve();
8
12
  let text = "";
9
13
  let reasoning = "";
14
+ // E18 resume-at: the turn's FIRST text_delta eventId = the message's stable per-message resume handle,
15
+ // stamped on the durable `text` event (ONE handle per message even when a mid-turn tool_start flushes the
16
+ // text early). Latched on the first DEFINED eventId of the turn (`??=` — a later part after a tool must not
17
+ // re-latch), cleared at turn_end — the exact `TurnAnchorCapture.firstTextEventId` semantics. (The bg leg's
18
+ // anchor tracks the same value for its own anchor-put; both latches see the same events in the same order,
19
+ // so the stamps agree byte-for-byte — the anchor's extra `turnHadTool` state never feeds the stamp.)
10
20
  let textEventId;
11
21
  const append = (type, data) => {
12
22
  const step = chain.then(() => opts.appendEvent(++seq, type, data));
@@ -14,12 +24,14 @@ export function createLedgerSink(opts) {
14
24
  return step;
15
25
  };
16
26
  const flush = async () => {
27
+ // Thinking precedes content within a turn → flush a buffered reasoning block FIRST (redacted).
17
28
  if (reasoning) {
18
29
  await append("reasoning", { text: redactSecrets(reasoning) });
19
30
  reasoning = "";
20
31
  }
21
32
  if (text) {
22
- await append("text", { text, ...(textEventId ? { eventId: textEventId } : {}) });
33
+ // E18: stamp the turn's first-text eventId as the per-message resume handle (additive; tolerate-absent).
34
+ await append("text", { text, ...(textEventId ? { eventId: textEventId } : {}) }); // persist first; clear only on success so a failed write doesn't drop it
23
35
  text = "";
24
36
  }
25
37
  };
@@ -32,45 +44,85 @@ export function createLedgerSink(opts) {
32
44
  break;
33
45
  }
34
46
  case "reasoning_delta":
47
+ // Persist the agent's thinking for the trace UI (core [R57]: reasoning IS on the live stream but NOT in
48
+ // the metadata Tracer — capturing it is the service's call). Gated by TRACE_THINKING; redacted on flush.
35
49
  if (opts.persistThinking)
36
50
  reasoning += ev.delta;
37
51
  break;
38
52
  case "tool_start":
39
53
  await flush();
54
+ // E1+E2 (shell-host contract): redacted args + identity via the shared whitelist builder — identical
55
+ // persisted shape across every leg.
40
56
  await append("tool_start", toolStartEventData(ev));
41
57
  break;
42
58
  case "tool_end":
43
59
  await flush();
60
+ // E1: redacted model-facing output (+truncated, core size-bound) + E2 identity, via the shared builder.
44
61
  await append("tool_end", toolEndEventData(ev));
45
62
  break;
46
63
  case "status":
64
+ // S4 (SILENT-FALLBACK P0-a): persist the brain-layer liveness observation. core marks the live frame
65
+ // EPHEMERAL (it never replays it) — this durable row is OUR observation record so async/replay readers
66
+ // can attribute a stalled turn. flush() first (review MED-2): a reconnect can fire MID-TEXT — without
67
+ // the flush the already-streamed text lands AFTER this row and the durable timeline inverts.
68
+ // design/158 B2: durable row type aligned to the live frame name ("status", not "brain_status") — the
69
+ // two legs were emitting the SAME logical event under two different `type` strings, and the SDK's
70
+ // public `AgentEvent` union only declared "status" (a durable-leg reader saw a frame outside its own
71
+ // public type). 写新读旧:这里只管写新;**存量行救不了**(任何旧部署的账本里都躺着 `brain_status`
72
+ // 行),所以重放边界配了一次性归一 —— `normalizeRunEventType`(trace/project.ts),唯一调用点是
73
+ // task_run SSE 的 `formatEvent`(routes/runs.ts)。两半缺一不可:只改写入侧的话,存量行重放时
74
+ // 仍会漏出公开联合之外的名字。无 migration、无回填(读边界归一比改历史行便宜且不可逆风险为零)。
47
75
  await flush();
48
76
  await append("status", brainStatusEventData(ev));
49
77
  break;
50
78
  case "context_usage":
79
+ // core 1.414 一等分支(server [1669]⑥ 要的上下文用量面)。每个压缩边界上报一次 ⇒ 一次任务多条,
80
+ // 消费方取最后一条为当前值。两条口径见 `contextUsageEventData` 旁注(别把 windowTokens 当模型上下文)。
51
81
  await flush();
52
82
  await append("context_usage", contextUsageEventData(ev));
53
83
  break;
54
84
  case "compacted":
55
85
  await flush();
86
+ // MF-18 (1.149) trigger/tokensBefore + core 1.219 attachedFiles/preserved_segment via the SHARED
87
+ // whitelist builder — the shell renders CC's post-compact `Read {path}` cards + the divider from these.
56
88
  await append("compacted", compactedEventData(ev));
57
89
  break;
58
90
  case "diagnostics":
91
+ // core 1.220 (design/121): NEW LSP diagnostics at a turn boundary — the shell's render source for CC's
92
+ // "Found N new diagnostic issues" row. §E1: language-server output is UNTRUSTED RAW → builder redacts.
59
93
  await flush();
60
94
  await append("diagnostics", diagnosticsEventData(ev));
61
95
  break;
62
96
  case "steering_injected":
97
+ // [1550]/[1552]: core's mid-run system-reminder injection (todo/file-change/date-roll/skills-delta/…) —
98
+ // the shell's render source for CC's steering-attachment row. §E1: preview is UNTRUSTED free text →
99
+ // builder redacts. Host/self-session only — NOT mirrored into onForwardEvent (a delegated child's own
100
+ // reminders are its internal bookkeeping, not host-relevant progress like tool_start/task_progress).
63
101
  await flush();
64
102
  await append("steering_injected", steeringInjectedEventData(ev));
65
103
  break;
66
104
  case "workspace_changed":
105
+ // [1559]二 core 裁定:design/99 §E13 旧臂,L1 门扩臂时首次撞见。durable 记账与其余内容型臂
106
+ // 同处置(轨迹回放时「何时 cd 到了哪」是合法历史事实,「不当持久态渲染」是 LIVE 消费端纪律,
107
+ // 不是不许落账)——共享白名单构造器 + §E1 redact。
67
108
  await flush();
68
109
  await append("workspace_changed", workspaceChangedEventData(ev));
69
110
  break;
70
111
  case "task_progress":
112
+ // core breakpoint⑤: a subagent's live progress tick → an INLINE "subagent working" card for the tailing
113
+ // client (S2-a). Shared whitelist+redact builder (+ E2 identity for the exact concurrent-tick binding).
71
114
  await append("task_progress", taskProgressEventData(ev));
72
115
  break;
73
116
  case "task_notification": {
117
+ // core 1.202 (design/115 P2): a background task finished while this harness was live — persist the
118
+ // display projection so a tailing client renders it (summary/result are UNTRUSTED free text → shared
119
+ // builder redacts). core [784]④a+④b: seq-folded shared key + skip keys this leg already delivered
120
+ // (start-of-leg inbox drain or observer arm) — core's pend-drain replays a double-parked idle arrival
121
+ // as a stream event; appending it again doubles the frame in the durable tail. codex F1: a key claimed
122
+ // by a fire-and-forget arm may have FAILED to land — await the claim's outcome; false ⇒ write anyway
123
+ // (this stream replay is the notification's last copy on this leg) and promote the key with THIS
124
+ // write's outcome. The claim promise is registered before the awaited append so a concurrent observer
125
+ // callback can't double-claim mid-write.
74
126
  await flush();
75
127
  const tn = ev.notification;
76
128
  const tnKey = tn?.task_id ? taskNotificationStreamKey({ task_type: tn.task_type, task_id: tn.task_id, status: String(tn.status), seq: tn.seq }) : undefined;
@@ -78,21 +130,26 @@ export function createLedgerSink(opts) {
78
130
  if (tnPrior === undefined || !(await tnPrior)) {
79
131
  const write = append("task_notification", taskNotificationEventData(ev));
80
132
  if (tnKey !== undefined)
81
- keys.set(tnKey, write.then(() => true, () => false));
133
+ keys.set(tnKey, write.then(() => true, () => false)); // the stream delivered this key
82
134
  await write;
83
135
  }
84
136
  break;
85
137
  }
86
138
  case "turn_end": {
87
139
  await flush();
140
+ // core 1.76 (service [41]/core [R59]): per-turn usage rides turn_end.usage — persist it for TraceTurn.tokens.
88
141
  const usage = ev.usage;
89
- await append("turn_end", turnEndEventData(ev));
90
- textEventId = undefined;
142
+ await append("turn_end", turnEndEventData(ev)); // 白名单 builder(此前手写 {usage},剥掉了 stopReason/usageMissing)
143
+ textEventId = undefined; // next turn latches its own first-text handle (TurnAnchorCapture parity)
91
144
  break;
92
145
  }
146
+ // `done` / `message_committed` / unknown: deliberate no-ops — see the interface doc.
93
147
  }
94
148
  };
95
149
  const onForwardEvent = (e) => {
150
+ // 1.78 (review HIGH) + C1 (core 1.219, spec.forwardSubagentEvents): a delegated child's lifecycle rides the
151
+ // forward sink (each stamped parentToolCallId — the shell nests them under the delegation card). Same
152
+ // shared builders as the top stream; fire-and-forget (`++seq` is sync → unique seqs vs the awaited loop).
96
153
  const t = e.type;
97
154
  if (t === "task_progress") {
98
155
  void append("task_progress", taskProgressEventData(e)).catch(() => undefined);
@@ -104,7 +161,9 @@ export function createLedgerSink(opts) {
104
161
  void append("tool_end", toolEndEventData(e)).catch(() => undefined);
105
162
  }
106
163
  };
107
- const appendParked = (kind, result) => append(kind, { gate: result?.checkpointGate ?? null });
164
+ const appendParked = (kind, result) =>
165
+ // Never the capability checkpointToken — only the non-secret gate (search [18] Q1b).
166
+ append(kind, { gate: result?.checkpointGate ?? null });
108
167
  const appendDone = (result) => append("done", { result });
109
168
  const onDone = async (result) => {
110
169
  await flush();
@@ -1,19 +1,47 @@
1
+ /**
2
+ * Task Trace projection (S1): the durable run event log → sema-registry's `TraceTurn[]` contract.
3
+ *
4
+ * The event log (src/runs.ts) is a flat per-task seq stream: reasoning / text / tool_start / tool_end /
5
+ * turn_end / compacted / done / suspended / failed. sema-registry renders an ORDERED `blocks[]` transcript
6
+ * (CC-style thinking↔tool interleave), grouped into turns. This is pure presentation/projection = the
7
+ * SERVICE layer (core [R57] adversarial: do NOT push this shape into core — different consumer, different shape).
8
+ *
9
+ * Per core [R57] corrections: there is no `suspended` event (suspend = the run row's status); per-turn tokens ride
10
+ * on `turn_end.usage` (core additive). As of core 1.121.0 (design/99 §E1) `tool_end` ALSO carries the model-facing
11
+ * `output` (+ `truncated`) — redacted + size-bounded at append (runs.ts) and read straight off the event here (the
12
+ * old session-join `toolOutput` hook is gone, there's a real source now); `eventId`/`parentToolCallId` (§E2) ride
13
+ * each content event, additive / tolerate-absent.
14
+ */
1
15
  import type { TaskResult } from "@sema-agent/core";
2
16
  import type { RunEvent, RunRecord } from "../plugins/store-contracts.js";
3
17
  import type { ModelUsageDelta, ModelUsageTracker, PromptManifestRecord } from "../budget.js";
4
18
  type AppendFn = (type: string, data: unknown) => Promise<void>;
5
19
  type GetEventsFn = (taskId: string, afterSeq: number) => Promise<RunEvent[]>;
20
+ /** E8 (shell-host): drain the per-task model-usage accumulator into an append-only `model_usage` DELTA event.
21
+ * Shared by BOTH durable-write legs (runInBackground + the resume leg) so the persisted shape never drifts; the
22
+ * append-only deltas make a suspended/resumed run's total resume-safe (each leg appends its own, the echo sums). */
6
23
  export declare function appendModelUsageDelta(append: AppendFn, modelUsage: ModelUsageTracker | undefined, taskId: string): Promise<void>;
24
+ /** [998]② drain the pending prompt-manifest records (whitelisted at RECORD time, budget.ts — ids/digests/
25
+ * counts only, no prompt bodies by core's manifest contract) into durable `prompt_assembled` events, one per
26
+ * prepare IN EMISSION ORDER (a cascade/verify leg re-prepares under one taskId — every rung's manifest
27
+ * persists; release-review finding). Shared by both durable-write legs; a no-op when nothing is pending
28
+ * (one Map.get), so callers fire it liberally. */
7
29
  export declare function appendPromptManifest(append: AppendFn, tracker: {
8
30
  drain(taskId: string): PromptManifestRecord[] | undefined;
9
31
  drainConfig?(taskId: string): Array<Record<string, unknown>> | undefined;
10
32
  } | undefined, taskId: string): Promise<void>;
33
+ /** E8: at a TERMINAL done — flush the final delta, then SUM all `model_usage` events (every process leg) into the
34
+ * result's `stats.modelUsage` echo. Returns the result unchanged when no usage was tracked (shell soft-degrades). */
11
35
  export declare function attachModelUsage<T extends TaskResult>(result: T, ctx: {
12
36
  append: AppendFn;
13
37
  getEvents: GetEventsFn;
14
38
  modelUsage: ModelUsageTracker | undefined;
15
39
  taskId: string;
16
40
  }): Promise<T>;
41
+ /** E8 (shell-host contract): SUM the per-turn `model_usage` delta events in a run's durable event log into the
42
+ * cumulative per-model total for `TaskStats.modelUsage`. The tracer drains deltas at each turn boundary
43
+ * (append-only) → this is resume-safe: it sums across ALL process legs of a suspended/resumed run. Returns
44
+ * undefined when the run logged no model usage (→ the shell soft-degrades to aggregate cost only). */
17
45
  export declare function aggregateModelUsage(events: RunEvent[]): Record<string, ModelUsageDelta> | undefined;
18
46
  export type TraceBlock = {
19
47
  type: "thinking";
@@ -48,6 +76,10 @@ export type TraceBlock = {
48
76
  sections?: unknown;
49
77
  tools?: unknown;
50
78
  };
79
+ /** The durable `tool_start` event payload, shared by BOTH append sites (runInBackground + the resume leg) so the
80
+ * persisted shape never drifts: redacted args (UNTRUSTED) + E2 identity. `label`([1543]§三族B:durable 腿
81
+ * 此前剥掉——同一 run live 观看有展示名、replay/resume 退化成 wire 名):core 展示名 verbatim(tail 面
82
+ * 1.251 复审同裁,两腿同处理)。 */
51
83
  export declare function toolStartEventData(ev: {
52
84
  toolCallId: string;
53
85
  toolName: string;
@@ -56,6 +88,15 @@ export declare function toolStartEventData(ev: {
56
88
  eventId?: string;
57
89
  parentToolCallId?: string;
58
90
  }): Record<string, unknown>;
91
+ /** The durable `tool_end` payload (shared by both append sites). E1: the model-facing `output` is UNTRUSTED RAW
92
+ * from core (file/shell/API bodies) — core only SIZE-bounds it (`truncated`), REDACTION is ours (same contract as
93
+ * `tool_start.args`); never re-fed to a model. E2: identity. Absent `output` ⇒ the tool produced no content body.
94
+ * core 1.203: `structured` = the tool's CC-shaped `details` card (edit/create/bash/… — core
95
+ * allowlists the card `type` and size-caps the whole card, omit-whole on overflow, so a subagent's child-TaskResult
96
+ * can never appear here) — SAME UNTRUSTED RAW contract as `output` (a card carries `originalFile`/stdout bodies),
97
+ * so it gets the same deep redaction before it is persisted or echoed. `label`(core 展示名,同 tool_start 的
98
+ * label 待遇 verbatim)白名单排查(2026-07-24)补齐进函数本体——此前外包给调用点各自手动拼接,7 处只有
99
+ * 3 处记得拼,resume leg + ledger-sink 落盘两处漏了,持久化记录本身缺 label 一写盘就永久追不回来。 */
59
100
  export declare function toolEndEventData(ev: {
60
101
  toolCallId: string;
61
102
  toolName: string;
@@ -68,6 +109,12 @@ export declare function toolEndEventData(ev: {
68
109
  eventId?: string;
69
110
  parentToolCallId?: string;
70
111
  }): Record<string, unknown>;
112
+ /** The `task_progress` payload (a subagent's live progress tick) — EXPLICIT WHITELIST shared by all
113
+ * three legs (bg runs.ts + resume append + the sync live SSE frame): taskId/parent linkage/token rollup verbatim,
114
+ * `name` UNTRUSTED (core sanitizes for rendering, does NOT secret-redact — a taskName can be secret-shaped) →
115
+ * `redactSecrets`. Never the delegated objective/args. E2 identity rides (eventId/
116
+ * parentToolCallId are core-mint uuidv7 identifiers, not content — consumers bind concurrent subagent ticks
117
+ * exactly by them; the 1.72 whitelist dropped them, leaving a FIFO heuristic). */
71
118
  export declare function taskProgressEventData(ev: {
72
119
  taskId: string;
73
120
  parentTaskId?: string;
@@ -80,6 +127,18 @@ export declare function taskProgressEventData(ev: {
80
127
  workflowRunId?: string;
81
128
  workflowAgentLabel?: string;
82
129
  }): Record<string, unknown>;
130
+ /** The `task_notification` payload (core 1.202 design/115 P2: a background task finished — this event is the
131
+ * LEDGER/display projection of the OBSERVED terminal state, emitted the moment core observes it. It does NOT
132
+ * attest that the `<task-notification>` XML has entered the model context: core's steer targets the NEXT TURN
133
+ * BOUNDARY (design/116 §7 — turn 在飞时不注入), so the frame can precede actual injection by minutes ([1818]
134
+ * clay live: 3m54s; the previous wording here — "core already injected in-process" — was the same wrong
135
+ * assumption that broke the shell's dedup). `injected: false` says exactly that on the wire: a consumer must
136
+ * NOT treat this frame as an echo of model-context injection. EXPLICIT WHITELIST (never `{...ev}` — the 1.72 task_progress lesson: a
137
+ * future core field must not ride raw): ids/status/usage verbatim; `summary`/`result`/`output_file` are UNTRUSTED
138
+ * free text (core bounds+sanitizes for XML, does NOT secret-redact) → `redactSecrets` at OUR wire boundary. Shared
139
+ * by all three legs (bg runs.ts + resume append + the sync live SSE frame) so the shape never drifts. Takes the
140
+ * EVENT (not just the payload) so the E2 identity fields core stamps on it (eventId/parentToolCallId) ride the
141
+ * frame like every other content event (review round 2: the payload-only version silently dropped them). */
83
142
  export declare function taskNotificationEventData(ev: {
84
143
  notification: {
85
144
  task_id: string;
@@ -113,6 +172,18 @@ export declare function taskNotificationEventData(ev: {
113
172
  eventId?: string;
114
173
  parentToolCallId?: string;
115
174
  }): Record<string, unknown>;
175
+ /** The `compacted` payload — EXPLICIT WHITELIST shared by all three legs (bg runs.ts + resume append + the sync
176
+ * live SSE frame; the 1.72 task_progress lesson: never `{...ev}`). trigger/tokensBefore (MF-18) verbatim;
177
+ * `preserved_segment.firstKeptEntryId` verbatim (a core-mint entryId, the shell's compaction-divider anchor);
178
+ * core 1.219 `attachedFiles` (attachWorkingFiles default-ON — the shell renders CC's post-compact `Read {path}`
179
+ * cards from it): `path` is the engine's own working-file path (env-derived, not free text) but still crosses our
180
+ * wire → `redactSecrets` (a project path can embed a secret-shaped dir name); chars/truncated are numeric/bool
181
+ * verbatim. Absent fields stay absent (feature off / nothing attached / no kept-tail floor). */
182
+ /** The `diagnostics` payload (core 1.220 design/121 — NEW LSP diagnostics drained at a turn boundary; the model
183
+ * already got the `<new-diagnostics>` context message in-process, this frame is the shell's render source).
184
+ * EXPLICIT WHITELIST shared by all three legs. UNTRUSTED RAW (§E1: language-server output over workspace files —
185
+ * a diagnostic message can quote file content, a secret-shaped uri/source is possible) → `redactSecrets` on the
186
+ * string fields; severity/range/code numbers verbatim. E2 identity rides. */
116
187
  export declare function diagnosticsEventData(ev: {
117
188
  files: Array<{
118
189
  uri: string;
@@ -128,17 +199,32 @@ export declare function diagnosticsEventData(ev: {
128
199
  eventId?: string;
129
200
  parentToolCallId?: string;
130
201
  }): Record<string, unknown>;
202
+ /** The `steering_injected` payload([1550]/[1552] 裁定透传;core `TaskEvent` 联合臂 `type: "steering_injected"`,
203
+ * shell 渲染源 = CC 的系统提醒条:core 在 turn 之间给模型注入一条系统提示[todo 提醒/文件变化/日期跨天/
204
+ * 技能列表变化…]时随手抛的展示投影,一附件一帧)。EXPLICIT WHITELIST(source=封闭枚举 verbatim;
205
+ * preview=注入文本的展示摘录,UNTRUSTED[core 未做秘密脱敏]→ `redactSecrets`)。共享三腿(sync 实时 SSE +
206
+ * bg/resume 落账,ledger-sink 同门)。 */
131
207
  export declare function steeringInjectedEventData(ev: {
132
208
  source: string;
133
209
  preview: string;
134
210
  eventId?: string;
135
211
  parentToolCallId?: string;
136
212
  }): Record<string, unknown>;
213
+ /** The `workspace_changed` payload([1559]二 core 裁定:design/99 §E13 旧臂,L1 门本车首次撞见——非新增,
214
+ * 是本门扩 TaskEvent 臂集时第一次显式处置。语义 = bash `cd`/EnterWorktree 移动任务逻辑 cwd 后,在移动
215
+ * 它的工具结算后发一帧,给 shell/宿主 UI 一个路径提示行。cwd 与已展示的工具 args 同信任级[UNTRUSTED,
216
+ * RAW 逻辑路径,symlink 不解析]→ `redactSecrets` + 长度 bound[300,与 brainStatusEventData.detail 同
217
+ * 惯例]。core 只在真变化时才发(不播初始 cwd);渲染面(cli)不得当持久态——跨 suspend/resume 重置为
218
+ * 根,这是消费端纪律,服务端只如实转发单帧不做状态缓存。 */
137
219
  export declare function workspaceChangedEventData(ev: {
138
220
  cwd: string;
139
221
  eventId?: string;
140
222
  parentToolCallId?: string;
141
223
  }): Record<string, unknown>;
224
+ /** S4 (SILENT-FALLBACK P0-a): the durable `brain_status` observation row, shared by the bg + resume append
225
+ * sites. core marks the live `status` frame EPHEMERAL (never replayed by core on resume) — this row is the
226
+ * SERVICE's own observation record (why a turn stalled: rate_limited/retrying/reconnecting/circuit_open),
227
+ * not a core event replay. Whitelist: the closed phase union + neutral bounded detail (redacted) + retryInSec. */
142
228
  export declare function brainStatusEventData(ev: {
143
229
  phase: string;
144
230
  detail?: string;
@@ -172,6 +258,7 @@ export declare function compactedEventData(ev: {
172
258
  };
173
259
  }): Record<string, unknown>;
174
260
  export interface TraceTurn {
261
+ /** per-task seq = the turn's terminating event seq (so history-up-to-H splices with stream seq>H). */
175
262
  seq: number;
176
263
  ts: string;
177
264
  role: "system" | "user" | "assistant" | "tool";
@@ -183,21 +270,47 @@ export interface TraceTurn {
183
270
  cacheWrite?: number;
184
271
  };
185
272
  }
273
+ /**
274
+ * `context_usage` 的白名单投影(core 1.414 新增一等 `TaskEvent` 分支;server [1669]⑥ 点名要的上下文用量面)。
275
+ *
276
+ * 🔴 两条 core 明确交代的口径,必须原样传下去、不要在服务端"聪明地"重算:
277
+ * · `usedTokens > compactAtTokens` **就是引擎自己喂 `shouldCompact` 的谓词** —— 消费方直接用,别重新推导阈值。
278
+ * · `windowTokens` 是 **autocompact 窗**,**不是**「模型上下文大小」(模型声明 `autoCompactTokens` 时物理请求
279
+ * 窗更大)。渲染成"模型上下文"会给用户一个错的分母。
280
+ * ⚠️ 它在**每个压缩边界**上报(不只压缩真发生时),所以一次任务里会有多条 —— 消费方按最后一条取当前值。
281
+ * ⚠️ 它**没有**挂在 `turn_end.usage` 上(core 解释:边界检查跑在 turn_end 之后、对 flush 后的消息集,
282
+ * 挂那儿会是"另一次更早的测量顶着同一个名字")。去 turn_end 找是找不到的。
283
+ * 三个字段都是引擎派生的有限数标量 ⇒ 走 finite 门(与 compacted 的 1.289 标量同姿势),非有限即缺席。
284
+ */
186
285
  export declare function contextUsageEventData(ev: {
187
286
  usedTokens?: unknown;
188
287
  windowTokens?: unknown;
189
288
  compactAtTokens?: unknown;
190
289
  }): Record<string, unknown>;
290
+ /**
291
+ * `turn_end` 的白名单投影 —— 🔴 2026-07-25 补:`turn_end` 此前是**唯一没有 builder 的内容臂**,两条持久化点
292
+ * (ledger-sink 与 resume 腿)各自手写 `{ usage }`,于是 core 的另两个字段被静默剥掉:
293
+ * · `stopReason` —— **这一轮为什么停**(max_tokens / stop_sequence / …);
294
+ * · `usageMissing: true` —— **用量不可信**的诚实标记。缺了它,"没有 usage"会被读成"用量是 0",
295
+ * 而不是"未知";这正是那种"回放后看起来一切正常"的丢失。
296
+ * 两者**在 live 腿看得见、durable 腿回放后永久消失** —— 与 [1622] 的 `label`、[1611] 的 workflowRunId 同一族
297
+ * (白名单没跟上 core 新增字段)。补 builder 的同时也就把它纳入了 `wire-whitelist-exhaustiveness` 的编译期差集门。
298
+ */
191
299
  export declare function turnEndEventData(ev: {
192
300
  usage?: unknown;
193
301
  usageMissing?: true;
194
302
  stopReason?: string;
195
303
  }): Record<string, unknown>;
304
+ /** Map core's `turn_end.usage` (1.76 / core [R59]: inputTokens/outputTokens/cacheReadTokens/cacheWriteTokens/
305
+ * costMicroUsd) → the contract's `TraceTurn.tokens {in,out,cacheRead?,cacheWrite?}`. Absent/empty → undefined. */
196
306
  export declare function toContractTokens(usage: unknown): TraceTurn["tokens"] | undefined;
197
307
  export interface ProjectOpts {
308
+ /** Prepend the user turn (the objective is not in the event log; the endpoint supplies it). */
198
309
  objective?: string;
199
310
  }
311
+ /** Project a per-task event slice (seq-ascending) into ordered `TraceTurn[]`. Pure + total (never throws). */
200
312
  export declare function projectEvents(events: RunEvent[], opts?: ProjectOpts): TraceTurn[];
313
+ /** Structured `lastStep` (contract 2.1) from the latest event — UI maps an icon, never free text. */
201
314
  export declare function lastStep(latestEventType: string | undefined, status: string): {
202
315
  type: "thinking" | "tool-call" | "responding" | "idle";
203
316
  label?: string;
@@ -206,9 +319,13 @@ export interface TaskSummary {
206
319
  id: string;
207
320
  status: string;
208
321
  scenario?: string;
322
+ /** Work-view correlation id (optional) — lets the client group a list into logical tasks. */
209
323
  jobId?: string;
324
+ /** Credential-derived submitting system (oa/cc-mcp/portal…) — per-door attribution. */
210
325
  source?: string;
326
+ /** Redacted first ~120 chars of the objective — the "what is this task" glance. */
211
327
  objectivePreview?: string;
328
+ /** The run's owner principal — the operator/boss view needs "whose task". */
212
329
  owner?: string;
213
330
  startedAt: string;
214
331
  endedAt?: string;
@@ -220,8 +337,24 @@ export interface TaskSummary {
220
337
  label?: string;
221
338
  };
222
339
  }
340
+ /** A run record → the cheap list summary (contract 2.1). Token/cost/turns come from the terminal result.stats;
341
+ * scenario isn't denormalized on the run row (omitted — a later push-index/column refinement). */
223
342
  export declare function taskSummary(run: RunRecord, latestEventType?: string): TaskSummary;
343
+ /** design/158 B2(lens4 N8)—— 重放边界的**读旧**归一:把历史账本里的 `brain_status` 行改叫 `status`。
344
+ *
345
+ * 同一条「大脑存活性」观测曾在两条腿上叫两个名字:live 腿(`POST /v1/tasks/stream`)发 `type:"status"`,
346
+ * durable 腿的账本行落 `brain_status`,而 SDK 的公开 `AgentEvent` 联合**只有** `status` —— 于是走
347
+ * `GET /v1/runs/:id/events` 的消费端会收到一个公开联合之外的帧(穷举式 closed-oneOf 消费者当场抛)。
348
+ *
349
+ * 写入侧已经改叫 `status`(ledger-sink.ts 与 resume 腿的 append 两处),但**存量行救不了**:任何
350
+ * <1.317 的部署账本里都躺着 `brain_status` 行,重放它们仍会漏出旧名。所以「写新」必须配一个「读旧」——
351
+ * 这个函数就是那个读边界,唯一调用点是 task_run SSE 的 `formatEvent`(routes/runs.ts)。
352
+ *
353
+ * 🔴 刻意**只**认这一个键,不做成映射表:帧名归一是历史包袱的一次性偿还,不是一条可以长胖的兼容层。
354
+ * 再有第二个名字对不齐,应当在源头修,而不是往这里加一行。 */
224
355
  export declare function normalizeRunEventType(type: string): string;
356
+ /** Map one durable event → a sema-registry SSE trace event (contract 2.3). null = not a client event. The
357
+ * durable log is block-grained, so each block ships as one "delta" the client appends (stream mode = "delta"). */
225
358
  export declare function mapTraceEvent(type: string, seq: number, data: Record<string, unknown>): {
226
359
  event: string;
227
360
  data: Record<string, unknown>;