@sema-agent/server 1.323.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (539) hide show
  1. package/dist/approval-hmac.d.ts +40 -0
  2. package/dist/approval-hmac.js +67 -0
  3. package/dist/approval.d.ts +31 -0
  4. package/dist/approval.js +72 -4
  5. package/dist/audit.d.ts +26 -0
  6. package/dist/audit.js +40 -1
  7. package/dist/auth-bridge.d.ts +10 -0
  8. package/dist/auth-bridge.js +47 -4
  9. package/dist/auth-keys.d.ts +19 -0
  10. package/dist/auth-keys.js +13 -0
  11. package/dist/bake-runner/main.d.ts +5 -0
  12. package/dist/bake-runner/main.js +43 -4
  13. package/dist/bake-runner/protocol.d.ts +57 -0
  14. package/dist/bake-runner/protocol.js +58 -3
  15. package/dist/bake-runner/runner.d.ts +54 -0
  16. package/dist/bake-runner/runner.js +87 -5
  17. package/dist/bench/l8/artifact.d.ts +63 -0
  18. package/dist/bench/l8/artifact.js +61 -2
  19. package/dist/bench/l8/escape.d.ts +36 -0
  20. package/dist/bench/l8/escape.js +25 -0
  21. package/dist/bench/l8/index.d.ts +14 -0
  22. package/dist/bench/l8/index.js +14 -0
  23. package/dist/bench/l8/probes.d.ts +74 -0
  24. package/dist/bench/l8/probes.js +60 -0
  25. package/dist/bench/l8/run-probes.d.ts +43 -0
  26. package/dist/bench/l8/run-probes.js +45 -2
  27. package/dist/bench/s1/arms.d.ts +126 -0
  28. package/dist/bench/s1/arms.js +188 -13
  29. package/dist/bench/s1/live-deps.d.ts +66 -0
  30. package/dist/bench/s1/live-deps.js +249 -11
  31. package/dist/bench/s1/oracle.d.ts +49 -0
  32. package/dist/bench/s1/oracle.js +36 -1
  33. package/dist/bench/s1/repair-oracle-adapter.d.ts +33 -0
  34. package/dist/bench/s1/repair-oracle-adapter.js +30 -0
  35. package/dist/bench/s1/reviewer.d.ts +38 -0
  36. package/dist/bench/s1/reviewer.js +34 -0
  37. package/dist/bench/s1/row.d.ts +77 -0
  38. package/dist/bench/s1/row.js +62 -0
  39. package/dist/bench/s1/run-firm.d.ts +47 -0
  40. package/dist/bench/s1/run-firm.js +70 -4
  41. package/dist/bench/s1/runner-ctx.d.ts +71 -0
  42. package/dist/bench/s1/runner-ctx.js +36 -0
  43. package/dist/bench/s1/tasks.d.ts +108 -0
  44. package/dist/bench/s1/tasks.js +115 -0
  45. package/dist/boot-reclaim.d.ts +19 -0
  46. package/dist/boot-reclaim.js +20 -0
  47. package/dist/brain.d.ts +25 -0
  48. package/dist/brain.js +61 -1
  49. package/dist/budget.d.ts +66 -0
  50. package/dist/budget.js +128 -4
  51. package/dist/capabilities/builtin-tools.d.ts +3 -0
  52. package/dist/capabilities/builtin-tools.js +3 -0
  53. package/dist/capabilities/center-plugins.d.ts +17 -1
  54. package/dist/capabilities/center-plugins.js +45 -4
  55. package/dist/capabilities/center-prompts.d.ts +46 -0
  56. package/dist/capabilities/center-prompts.js +57 -3
  57. package/dist/capabilities/code-review-council.d.ts +28 -0
  58. package/dist/capabilities/code-review-council.js +40 -7
  59. package/dist/capabilities/collab-wire.d.ts +2 -0
  60. package/dist/capabilities/collab-workflows.d.ts +7 -0
  61. package/dist/capabilities/collab-workflows.js +44 -1
  62. package/dist/capabilities/oa-tools.d.ts +6 -0
  63. package/dist/capabilities/oa-tools.js +10 -0
  64. package/dist/capabilities/prompt.d.ts +14 -0
  65. package/dist/capabilities/prompt.js +14 -0
  66. package/dist/capabilities/prompts/code-review.d.ts +14 -0
  67. package/dist/capabilities/prompts/code-review.js +14 -0
  68. package/dist/capabilities/prompts/identity.d.ts +6 -0
  69. package/dist/capabilities/prompts/identity.js +6 -0
  70. package/dist/capabilities/prompts/team.d.ts +4 -0
  71. package/dist/capabilities/prompts/team.js +4 -0
  72. package/dist/capabilities/repo-tools.d.ts +11 -0
  73. package/dist/capabilities/repo-tools.js +8 -0
  74. package/dist/capabilities/sandbox-file-send.d.ts +95 -0
  75. package/dist/capabilities/sandbox-file-send.js +91 -3
  76. package/dist/capabilities/scenarios.d.ts +130 -0
  77. package/dist/capabilities/scenarios.js +180 -7
  78. package/dist/capabilities/select-environment-tool.d.ts +7 -0
  79. package/dist/capabilities/select-environment-tool.js +30 -0
  80. package/dist/capabilities/send-user-file-tool.d.ts +33 -0
  81. package/dist/capabilities/send-user-file-tool.js +65 -1
  82. package/dist/capabilities/skills.d.ts +29 -0
  83. package/dist/capabilities/skills.js +13 -2
  84. package/dist/capabilities/team.d.ts +22 -0
  85. package/dist/capabilities/team.js +22 -2
  86. package/dist/capabilities/tool-defer.d.ts +26 -0
  87. package/dist/capabilities/tool-defer.js +3 -0
  88. package/dist/config-center/apply-effective.d.ts +65 -0
  89. package/dist/config-center/apply-effective.js +204 -12
  90. package/dist/config-center/http-client.d.ts +34 -0
  91. package/dist/config-center/http-client.js +68 -0
  92. package/dist/config-center/restart-signal.d.ts +22 -0
  93. package/dist/config-center/restart-signal.js +39 -0
  94. package/dist/config-center/skills-mcp.d.ts +20 -1
  95. package/dist/config-center/skills-mcp.js +42 -7
  96. package/dist/config-center/types.d.ts +92 -1
  97. package/dist/config-lkg.d.ts +12 -0
  98. package/dist/config-lkg.js +41 -0
  99. package/dist/config-provider.d.ts +78 -0
  100. package/dist/config-provider.js +165 -2
  101. package/dist/config-types.d.ts +546 -0
  102. package/dist/config.d.ts +64 -0
  103. package/dist/config.js +455 -60
  104. package/dist/degenerate-instrument.d.ts +38 -0
  105. package/dist/degenerate-instrument.js +55 -3
  106. package/dist/elicitation.d.ts +39 -0
  107. package/dist/elicitation.js +87 -3
  108. package/dist/env-facts.d.ts +61 -0
  109. package/dist/env-facts.js +73 -7
  110. package/dist/fleet/fleet-bus.d.ts +185 -0
  111. package/dist/fleet/fleet-bus.js +333 -27
  112. package/dist/fleet/subagent-tail-bus.d.ts +11 -0
  113. package/dist/fleet/subagent-tail-bus.js +33 -2
  114. package/dist/fleet-client.d.ts +38 -0
  115. package/dist/fleet-client.js +44 -9
  116. package/dist/fleet-lease.d.ts +46 -0
  117. package/dist/fleet-lease.js +73 -5
  118. package/dist/hooks/branch-transcript.d.ts +8 -0
  119. package/dist/hooks/branch-transcript.js +33 -0
  120. package/dist/hooks/cc-stop-prompt.d.ts +42 -0
  121. package/dist/hooks/cc-stop-prompt.js +43 -1
  122. package/dist/hooks/hook-llm.d.ts +15 -0
  123. package/dist/hooks/hook-llm.js +47 -0
  124. package/dist/hooks/hook-runner.d.ts +89 -0
  125. package/dist/hooks/hook-runner.js +327 -18
  126. package/dist/http/idempotency.d.ts +31 -0
  127. package/dist/http/idempotency.js +34 -0
  128. package/dist/http/principal-gate.d.ts +17 -0
  129. package/dist/http/principal-gate.js +35 -3
  130. package/dist/http/route-ctx.d.ts +36 -0
  131. package/dist/http/routes/approvals-assistant.d.ts +25 -0
  132. package/dist/http/routes/approvals-assistant.js +253 -23
  133. package/dist/http/routes/attachments.js +22 -4
  134. package/dist/http/routes/capabilities.d.ts +7 -0
  135. package/dist/http/routes/capabilities.js +202 -1
  136. package/dist/http/routes/fleet.d.ts +6 -0
  137. package/dist/http/routes/fleet.js +94 -5
  138. package/dist/http/routes/images.d.ts +17 -0
  139. package/dist/http/routes/images.js +222 -14
  140. package/dist/http/routes/leader.d.ts +7 -0
  141. package/dist/http/routes/leader.js +10 -0
  142. package/dist/http/routes/memory-policy.d.ts +6 -0
  143. package/dist/http/routes/memory-policy.js +38 -6
  144. package/dist/http/routes/notify-wake.d.ts +10 -0
  145. package/dist/http/routes/notify-wake.js +19 -3
  146. package/dist/http/routes/observability.d.ts +6 -0
  147. package/dist/http/routes/observability.js +19 -2
  148. package/dist/http/routes/runs.d.ts +15 -0
  149. package/dist/http/routes/runs.js +464 -41
  150. package/dist/http/routes/session-sync.d.ts +15 -0
  151. package/dist/http/routes/session-sync.js +229 -19
  152. package/dist/http/routes/sessions-list.d.ts +6 -0
  153. package/dist/http/routes/sessions-list.js +35 -4
  154. package/dist/http/routes/sessions.d.ts +14 -0
  155. package/dist/http/routes/sessions.js +176 -31
  156. package/dist/http/routes/side-query.d.ts +8 -0
  157. package/dist/http/routes/side-query.js +26 -1
  158. package/dist/http/routes/tasks.d.ts +18 -0
  159. package/dist/http/routes/tasks.js +501 -38
  160. package/dist/http/routes/trace-usage.d.ts +10 -0
  161. package/dist/http/routes/trace-usage.js +66 -14
  162. package/dist/http/routes/workflows.d.ts +12 -0
  163. package/dist/http/routes/workflows.js +180 -19
  164. package/dist/http/run-meta.d.ts +11 -0
  165. package/dist/http/run-meta.js +6 -0
  166. package/dist/http/send.d.ts +19 -0
  167. package/dist/http/send.js +11 -0
  168. package/dist/http/server.d.ts +255 -0
  169. package/dist/http/server.js +921 -75
  170. package/dist/http/sse-log.d.ts +15 -0
  171. package/dist/http/sse-log.js +16 -0
  172. package/dist/http/tar.d.ts +9 -0
  173. package/dist/http/tar.js +21 -5
  174. package/dist/http/wire-gate.d.ts +9 -0
  175. package/dist/http/wire-gate.js +9 -0
  176. package/dist/http/wire-types.d.ts +187 -0
  177. package/dist/http/workspace-content.d.ts +8 -0
  178. package/dist/http/workspace-content.js +10 -0
  179. package/dist/images/bake-validate.d.ts +63 -0
  180. package/dist/images/bake-validate.js +71 -1
  181. package/dist/images/manifest.d.ts +19 -0
  182. package/dist/images/manifest.js +6 -1
  183. package/dist/index.d.ts +1 -5
  184. package/dist/index.js +10 -5
  185. package/dist/key-resolver.d.ts +23 -0
  186. package/dist/key-resolver.js +27 -2
  187. package/dist/leader/diffout.d.ts +23 -0
  188. package/dist/leader/diffout.js +8 -1
  189. package/dist/leader/diffup.d.ts +32 -0
  190. package/dist/leader/diffup.js +43 -0
  191. package/dist/leader/endpoint.d.ts +20 -0
  192. package/dist/leader/endpoint.js +25 -2
  193. package/dist/leader/fanout.d.ts +60 -0
  194. package/dist/leader/fanout.js +29 -3
  195. package/dist/leader/grader-env-factory.d.ts +74 -0
  196. package/dist/leader/grader-env-factory.js +62 -3
  197. package/dist/leader/leader.d.ts +97 -0
  198. package/dist/leader/leader.js +151 -4
  199. package/dist/leader/merge.d.ts +94 -0
  200. package/dist/leader/merge.js +112 -9
  201. package/dist/leader/planner.d.ts +52 -0
  202. package/dist/leader/planner.js +47 -3
  203. package/dist/leader/repair-oracle.d.ts +61 -0
  204. package/dist/leader/repair-oracle.js +59 -1
  205. package/dist/leader/repair-wire.d.ts +78 -0
  206. package/dist/leader/repair-wire.js +79 -2
  207. package/dist/leader/wire.d.ts +79 -0
  208. package/dist/leader/wire.js +255 -8
  209. package/dist/lsp/e2b-bridge.d.ts +16 -0
  210. package/dist/lsp/e2b-bridge.js +32 -4
  211. package/dist/lsp/e2b-manager.d.ts +10 -0
  212. package/dist/lsp/e2b-manager.js +18 -2
  213. package/dist/lsp/lsp-frames.d.ts +12 -0
  214. package/dist/lsp/lsp-frames.js +12 -0
  215. package/dist/lsp/manager.d.ts +12 -0
  216. package/dist/lsp/manager.js +35 -2
  217. package/dist/lsp/types.d.ts +10 -0
  218. package/dist/lsp/ws-transport.d.ts +12 -0
  219. package/dist/lsp/ws-transport.js +53 -5
  220. package/dist/lsp-evict.d.ts +14 -0
  221. package/dist/lsp-evict.js +15 -1
  222. package/dist/main.js +2132 -96
  223. package/dist/memory-export.d.ts +1 -0
  224. package/dist/memory-export.js +4 -0
  225. package/dist/memory-scope.d.ts +49 -0
  226. package/dist/memory-scope.js +87 -4
  227. package/dist/memory-sync-client.d.ts +24 -0
  228. package/dist/memory-sync-client.js +41 -2
  229. package/dist/memory-sync.d.ts +23 -0
  230. package/dist/memory-sync.js +70 -1
  231. package/dist/model-select.d.ts +39 -0
  232. package/dist/model-select.js +42 -1
  233. package/dist/observability/cost-quota.d.ts +20 -0
  234. package/dist/observability/cost-quota.js +4 -0
  235. package/dist/observability/cost-taxonomy.d.ts +45 -0
  236. package/dist/observability/cost-taxonomy.js +34 -0
  237. package/dist/observability/logger.d.ts +1 -0
  238. package/dist/observability/logger.js +6 -0
  239. package/dist/observability/metrics.d.ts +13 -0
  240. package/dist/observability/metrics.js +63 -0
  241. package/dist/observability/otel-exporter.d.ts +9 -0
  242. package/dist/observability/otel-exporter.js +11 -3
  243. package/dist/observability/principal-context.d.ts +9 -0
  244. package/dist/observability/principal-context.js +9 -0
  245. package/dist/observability/prompt-manifest.d.ts +37 -0
  246. package/dist/observability/prompt-manifest.js +35 -1
  247. package/dist/observability/rate-limit.d.ts +10 -0
  248. package/dist/observability/rate-limit.js +1 -0
  249. package/dist/observability/tool-trace.d.ts +24 -0
  250. package/dist/observability/tool-trace.js +41 -1
  251. package/dist/orchestration/hardened-vm-runner.d.ts +107 -0
  252. package/dist/orchestration/hardened-vm-runner.js +119 -4
  253. package/dist/orchestration/hardened-vm-worker-runner.d.ts +14 -0
  254. package/dist/orchestration/hardened-vm-worker-runner.js +26 -1
  255. package/dist/orchestration/hardened-vm-worker.js +27 -0
  256. package/dist/orchestration/subagent-steer.d.ts +44 -0
  257. package/dist/orchestration/subagent-steer.js +45 -1
  258. package/dist/orchestration/workflow-agent-steer.d.ts +54 -0
  259. package/dist/orchestration/workflow-agent-steer.js +80 -1
  260. package/dist/orchestration/workflow-completion-inbox.d.ts +189 -2
  261. package/dist/orchestration/workflow-completion-inbox.js +283 -32
  262. package/dist/orchestration/workflow-notify-journal.d.ts +132 -1
  263. package/dist/orchestration/workflow-notify-journal.js +187 -13
  264. package/dist/parked-decide.d.ts +61 -0
  265. package/dist/parked-decide.js +58 -1
  266. package/dist/per-task-image.d.ts +54 -0
  267. package/dist/per-task-image.js +41 -0
  268. package/dist/plan-cache-probe.d.ts +35 -0
  269. package/dist/plan-cache-probe.js +18 -3
  270. package/dist/plugins/approval-exemption-store.d.ts +7 -0
  271. package/dist/plugins/approval-exemption-store.js +28 -2
  272. package/dist/plugins/approval-store-sql.d.ts +64 -0
  273. package/dist/plugins/approval-store-sql.js +32 -0
  274. package/dist/plugins/background-agent-store-sql.d.ts +55 -0
  275. package/dist/plugins/background-agent-store-sql.js +91 -4
  276. package/dist/plugins/background-shell-support.d.ts +98 -0
  277. package/dist/plugins/background-shell-support.js +117 -13
  278. package/dist/plugins/blob-backend.d.ts +104 -0
  279. package/dist/plugins/blob-backend.js +163 -6
  280. package/dist/plugins/breaker-state-sql.d.ts +65 -1
  281. package/dist/plugins/breaker-state-sql.js +46 -8
  282. package/dist/plugins/caching-session-store.d.ts +42 -0
  283. package/dist/plugins/caching-session-store.js +63 -3
  284. package/dist/plugins/checkpoint-store-sql.d.ts +179 -0
  285. package/dist/plugins/checkpoint-store-sql.js +239 -11
  286. package/dist/plugins/file-outcome-sink.d.ts +4 -0
  287. package/dist/plugins/file-outcome-sink.js +9 -0
  288. package/dist/plugins/file-resume-anchor-store.d.ts +20 -0
  289. package/dist/plugins/file-resume-anchor-store.js +43 -4
  290. package/dist/plugins/file-run-store.d.ts +90 -0
  291. package/dist/plugins/file-run-store.js +145 -13
  292. package/dist/plugins/file-snapshot-store-sql.d.ts +133 -1
  293. package/dist/plugins/file-snapshot-store-sql.js +178 -10
  294. package/dist/plugins/file-workflow-journal-store.d.ts +10 -0
  295. package/dist/plugins/file-workflow-journal-store.js +10 -0
  296. package/dist/plugins/fork-routing-session-store.d.ts +47 -0
  297. package/dist/plugins/fork-routing-session-store.js +51 -3
  298. package/dist/plugins/host-platform.d.ts +69 -0
  299. package/dist/plugins/host-platform.js +81 -2
  300. package/dist/plugins/image-bake-store-sql.d.ts +136 -1
  301. package/dist/plugins/image-bake-store-sql.js +241 -7
  302. package/dist/plugins/image-index-sql.d.ts +46 -0
  303. package/dist/plugins/image-index-sql.js +113 -4
  304. package/dist/plugins/k8s-bg-scripts.d.ts +34 -0
  305. package/dist/plugins/k8s-bg-scripts.js +88 -4
  306. package/dist/plugins/k8s-exec-protocol.d.ts +33 -0
  307. package/dist/plugins/k8s-exec-protocol.js +41 -0
  308. package/dist/plugins/local-checkpoint-store.d.ts +40 -0
  309. package/dist/plugins/local-checkpoint-store.js +86 -7
  310. package/dist/plugins/local-session-store.d.ts +157 -0
  311. package/dist/plugins/local-session-store.js +289 -34
  312. package/dist/plugins/local-task-attachment-store.js +14 -2
  313. package/dist/plugins/mailbox-store-sql.d.ts +38 -0
  314. package/dist/plugins/mailbox-store-sql.js +39 -6
  315. package/dist/plugins/memory-engine-pg.d.ts +30 -0
  316. package/dist/plugins/memory-engine-pg.js +122 -4
  317. package/dist/plugins/memory-engine-tidb.d.ts +26 -0
  318. package/dist/plugins/memory-engine-tidb.js +115 -5
  319. package/dist/plugins/memory-engine-vector-util.d.ts +5 -0
  320. package/dist/plugins/memory-engine-vector-util.js +5 -0
  321. package/dist/plugins/memory-resume-anchor-store.d.ts +8 -0
  322. package/dist/plugins/memory-resume-anchor-store.js +17 -0
  323. package/dist/plugins/memory-run-store.d.ts +63 -0
  324. package/dist/plugins/memory-run-store.js +73 -8
  325. package/dist/plugins/memory-session-policy-store.d.ts +17 -0
  326. package/dist/plugins/memory-session-policy-store.js +17 -0
  327. package/dist/plugins/memory-sync-store-pg.d.ts +42 -0
  328. package/dist/plugins/memory-sync-store-pg.js +45 -2
  329. package/dist/plugins/memory-sync-store-tidb.d.ts +9 -0
  330. package/dist/plugins/memory-sync-store-tidb.js +31 -1
  331. package/dist/plugins/outcome-ledger-sql.d.ts +63 -0
  332. package/dist/plugins/outcome-ledger-sql.js +97 -3
  333. package/dist/plugins/pg-approval-store.d.ts +7 -0
  334. package/dist/plugins/pg-approval-store.js +7 -0
  335. package/dist/plugins/pg-breaker-state.d.ts +6 -0
  336. package/dist/plugins/pg-breaker-state.js +6 -0
  337. package/dist/plugins/pg-checkpoint-store.d.ts +8 -0
  338. package/dist/plugins/pg-checkpoint-store.js +8 -0
  339. package/dist/plugins/pg-cost-quota.d.ts +17 -0
  340. package/dist/plugins/pg-cost-quota.js +6 -0
  341. package/dist/plugins/pg-file-snapshot-store.d.ts +6 -0
  342. package/dist/plugins/pg-file-snapshot-store.js +6 -0
  343. package/dist/plugins/pg-image-bake.d.ts +9 -0
  344. package/dist/plugins/pg-image-bake.js +9 -0
  345. package/dist/plugins/pg-image-index.d.ts +9 -0
  346. package/dist/plugins/pg-image-index.js +9 -0
  347. package/dist/plugins/pg-outcome-ledger.d.ts +9 -0
  348. package/dist/plugins/pg-outcome-ledger.js +9 -0
  349. package/dist/plugins/pg-pool.d.ts +50 -0
  350. package/dist/plugins/pg-pool.js +78 -0
  351. package/dist/plugins/pg-query.d.ts +11 -0
  352. package/dist/plugins/pg-rate-limiter.d.ts +23 -0
  353. package/dist/plugins/pg-rate-limiter.js +12 -2
  354. package/dist/plugins/pg-resume-anchor-store.d.ts +5 -0
  355. package/dist/plugins/pg-resume-anchor-store.js +5 -0
  356. package/dist/plugins/pg-run-store.d.ts +7 -0
  357. package/dist/plugins/pg-run-store.js +7 -0
  358. package/dist/plugins/pg-safe-json.d.ts +13 -0
  359. package/dist/plugins/pg-safe-json.js +40 -4
  360. package/dist/plugins/pg-session-policy-store.d.ts +5 -0
  361. package/dist/plugins/pg-session-policy-store.js +5 -0
  362. package/dist/plugins/pg-session-storage.d.ts +72 -0
  363. package/dist/plugins/pg-session-storage.js +152 -20
  364. package/dist/plugins/pg-session-store.d.ts +10 -0
  365. package/dist/plugins/pg-session-store.js +10 -0
  366. package/dist/plugins/pg-tool-result-store.d.ts +7 -0
  367. package/dist/plugins/pg-tool-result-store.js +7 -0
  368. package/dist/plugins/pg-workflow-journal-store.d.ts +7 -0
  369. package/dist/plugins/pg-workflow-journal-store.js +7 -0
  370. package/dist/plugins/pg-workflow-run-store.d.ts +7 -0
  371. package/dist/plugins/pg-workflow-run-store.js +7 -0
  372. package/dist/plugins/posix-shell-fs.d.ts +3 -0
  373. package/dist/plugins/posix-shell-fs.js +31 -1
  374. package/dist/plugins/remote-env-adb.d.ts +25 -0
  375. package/dist/plugins/remote-env-adb.js +95 -12
  376. package/dist/plugins/remote-env-e2b.d.ts +146 -0
  377. package/dist/plugins/remote-env-e2b.js +371 -40
  378. package/dist/plugins/remote-env-file-error.d.ts +34 -0
  379. package/dist/plugins/remote-env-file-error.js +37 -0
  380. package/dist/plugins/remote-env-host.d.ts +151 -0
  381. package/dist/plugins/remote-env-host.js +468 -70
  382. package/dist/plugins/remote-env-k8s.d.ts +135 -0
  383. package/dist/plugins/remote-env-k8s.js +318 -32
  384. package/dist/plugins/remote-env-local-docker.d.ts +65 -0
  385. package/dist/plugins/remote-env-local-docker.js +149 -24
  386. package/dist/plugins/remote-env-ssh.d.ts +35 -0
  387. package/dist/plugins/remote-env-ssh.js +117 -20
  388. package/dist/plugins/remote-scratchpad.d.ts +38 -0
  389. package/dist/plugins/remote-scratchpad.js +32 -2
  390. package/dist/plugins/remote-shell.d.ts +22 -0
  391. package/dist/plugins/remote-shell.js +27 -1
  392. package/dist/plugins/resume-anchor-store-sql.d.ts +28 -0
  393. package/dist/plugins/resume-anchor-store-sql.js +11 -0
  394. package/dist/plugins/roster-store-sql.d.ts +27 -0
  395. package/dist/plugins/roster-store-sql.js +54 -0
  396. package/dist/plugins/run-store-sql.d.ts +194 -0
  397. package/dist/plugins/run-store-sql.js +210 -9
  398. package/dist/plugins/s3-presign.d.ts +20 -0
  399. package/dist/plugins/s3-presign.js +49 -2
  400. package/dist/plugins/scheduler-support.d.ts +12 -0
  401. package/dist/plugins/scheduler-support.js +75 -3
  402. package/dist/plugins/send-file-ledger.d.ts +15 -0
  403. package/dist/plugins/send-file-ledger.js +53 -4
  404. package/dist/plugins/send-user-file.d.ts +77 -0
  405. package/dist/plugins/send-user-file.js +92 -4
  406. package/dist/plugins/session-policy-store-sql.d.ts +15 -0
  407. package/dist/plugins/session-policy-store-sql.js +75 -3
  408. package/dist/plugins/session-store.d.ts +45 -0
  409. package/dist/plugins/session-store.js +51 -0
  410. package/dist/plugins/sql-driver.d.ts +77 -0
  411. package/dist/plugins/sql-driver.js +4 -0
  412. package/dist/plugins/sql-escape.d.ts +8 -0
  413. package/dist/plugins/sql-escape.js +8 -0
  414. package/dist/plugins/sql-row-helpers.d.ts +25 -0
  415. package/dist/plugins/sql-row-helpers.js +25 -0
  416. package/dist/plugins/store-backend.d.ts +103 -0
  417. package/dist/plugins/store-backend.js +120 -27
  418. package/dist/plugins/store-contracts.d.ts +62 -0
  419. package/dist/plugins/store-contracts.js +3 -0
  420. package/dist/plugins/task-attachment-store.d.ts +60 -0
  421. package/dist/plugins/task-attachment-store.js +49 -3
  422. package/dist/plugins/task-list-store-sql.d.ts +25 -0
  423. package/dist/plugins/task-list-store-sql.js +21 -0
  424. package/dist/plugins/tidb-approval-store.d.ts +6 -0
  425. package/dist/plugins/tidb-approval-store.js +6 -0
  426. package/dist/plugins/tidb-breaker-state.d.ts +5 -0
  427. package/dist/plugins/tidb-breaker-state.js +5 -0
  428. package/dist/plugins/tidb-checkpoint-store.d.ts +7 -0
  429. package/dist/plugins/tidb-checkpoint-store.js +7 -0
  430. package/dist/plugins/tidb-cost-quota.d.ts +6 -0
  431. package/dist/plugins/tidb-cost-quota.js +1 -0
  432. package/dist/plugins/tidb-file-snapshot-store.d.ts +6 -0
  433. package/dist/plugins/tidb-file-snapshot-store.js +6 -0
  434. package/dist/plugins/tidb-image-bake.d.ts +8 -0
  435. package/dist/plugins/tidb-image-bake.js +8 -0
  436. package/dist/plugins/tidb-image-index.d.ts +8 -0
  437. package/dist/plugins/tidb-image-index.js +8 -0
  438. package/dist/plugins/tidb-outcome-ledger.d.ts +10 -0
  439. package/dist/plugins/tidb-outcome-ledger.js +10 -0
  440. package/dist/plugins/tidb-pool.d.ts +56 -0
  441. package/dist/plugins/tidb-pool.js +181 -1
  442. package/dist/plugins/tidb-rate-limiter.d.ts +11 -0
  443. package/dist/plugins/tidb-rate-limiter.js +5 -2
  444. package/dist/plugins/tidb-resume-anchor-store.d.ts +5 -0
  445. package/dist/plugins/tidb-resume-anchor-store.js +5 -0
  446. package/dist/plugins/tidb-run-store.d.ts +7 -0
  447. package/dist/plugins/tidb-run-store.js +7 -0
  448. package/dist/plugins/tidb-session-policy-store.d.ts +5 -0
  449. package/dist/plugins/tidb-session-policy-store.js +5 -0
  450. package/dist/plugins/tidb-session-storage.d.ts +43 -0
  451. package/dist/plugins/tidb-session-storage.js +62 -3
  452. package/dist/plugins/tidb-session-store.d.ts +142 -0
  453. package/dist/plugins/tidb-session-store.js +264 -16
  454. package/dist/plugins/tidb-tool-result-store.d.ts +5 -0
  455. package/dist/plugins/tidb-tool-result-store.js +7 -0
  456. package/dist/plugins/tidb-workflow-journal-store.d.ts +7 -0
  457. package/dist/plugins/tidb-workflow-journal-store.js +7 -0
  458. package/dist/plugins/tidb-workflow-run-store.d.ts +8 -0
  459. package/dist/plugins/tidb-workflow-run-store.js +8 -0
  460. package/dist/plugins/tool-result-store-sql.d.ts +58 -0
  461. package/dist/plugins/tool-result-store-sql.js +38 -2
  462. package/dist/plugins/web-search.d.ts +35 -0
  463. package/dist/plugins/web-search.js +45 -9
  464. package/dist/plugins/workflow-journal-limits.d.ts +10 -0
  465. package/dist/plugins/workflow-journal-limits.js +10 -0
  466. package/dist/plugins/workflow-journal-store-sql.d.ts +78 -0
  467. package/dist/plugins/workflow-journal-store-sql.js +58 -2
  468. package/dist/plugins/workflow-run-store-sql.d.ts +84 -0
  469. package/dist/plugins/workflow-run-store-sql.js +84 -6
  470. package/dist/plugins/worktree-isolation.d.ts +45 -0
  471. package/dist/plugins/worktree-isolation.js +105 -6
  472. package/dist/plugins/write-behind-counter.d.ts +56 -1
  473. package/dist/plugins/write-behind-counter.js +53 -14
  474. package/dist/principal-jwt.d.ts +24 -0
  475. package/dist/principal-jwt.js +60 -5
  476. package/dist/project-memory.d.ts +22 -0
  477. package/dist/project-memory.js +144 -15
  478. package/dist/prompts-domain-validate.d.ts +28 -0
  479. package/dist/prompts-domain-validate.js +42 -1
  480. package/dist/question.d.ts +33 -0
  481. package/dist/question.js +69 -2
  482. package/dist/resource-suspend.d.ts +21 -0
  483. package/dist/resource-suspend.js +16 -0
  484. package/dist/router/route-orchestration.d.ts +78 -0
  485. package/dist/router/route-orchestration.js +77 -0
  486. package/dist/run-local.d.ts +32 -0
  487. package/dist/run-local.js +172 -8
  488. package/dist/runs.d.ts +189 -4
  489. package/dist/runs.js +465 -24
  490. package/dist/runtime-caps-resolver.d.ts +106 -0
  491. package/dist/runtime-caps-resolver.js +89 -4
  492. package/dist/runtime-governance.d.ts +84 -0
  493. package/dist/runtime-governance.js +127 -1
  494. package/dist/sandbox-pkg-source.d.ts +23 -0
  495. package/dist/sandbox-pkg-source.js +37 -0
  496. package/dist/sealed-key.d.ts +54 -0
  497. package/dist/sealed-key.js +68 -3
  498. package/dist/security.d.ts +108 -0
  499. package/dist/security.js +145 -6
  500. package/dist/sema-registry.d.ts +21 -0
  501. package/dist/sema-registry.js +21 -0
  502. package/dist/session-leaf-bus.d.ts +31 -0
  503. package/dist/session-leaf-bus.js +32 -0
  504. package/dist/session-sync-content.d.ts +46 -0
  505. package/dist/session-sync-content.js +47 -1
  506. package/dist/session-sync-kernel.d.ts +89 -0
  507. package/dist/session-sync-kernel.js +48 -3
  508. package/dist/session-sync.d.ts +125 -0
  509. package/dist/session-sync.js +181 -8
  510. package/dist/session-titler.d.ts +26 -0
  511. package/dist/session-titler.js +41 -7
  512. package/dist/session-watch.d.ts +53 -1
  513. package/dist/session-watch.js +73 -9
  514. package/dist/sighup-idle.d.ts +30 -0
  515. package/dist/sighup-idle.js +12 -1
  516. package/dist/spec-fields.d.ts +91 -3
  517. package/dist/spec-fields.js +116 -4
  518. package/dist/task-cwd.d.ts +50 -0
  519. package/dist/task-cwd.js +68 -1
  520. package/dist/task-mcp.d.ts +47 -0
  521. package/dist/task-mcp.js +29 -0
  522. package/dist/task-settings.d.ts +175 -0
  523. package/dist/task-settings.js +226 -11
  524. package/dist/task-workflow.d.ts +67 -0
  525. package/dist/task-workflow.js +75 -8
  526. package/dist/tool-approval.d.ts +91 -0
  527. package/dist/tool-approval.js +215 -0
  528. package/dist/trace/artifacts.d.ts +9 -0
  529. package/dist/trace/artifacts.js +30 -5
  530. package/dist/trace/core-keyset-guard.d.ts +18 -0
  531. package/dist/trace/ledger-sink.d.ts +43 -0
  532. package/dist/trace/ledger-sink.js +64 -5
  533. package/dist/trace/project.d.ts +133 -0
  534. package/dist/trace/project.js +189 -2
  535. package/dist/trace/redact.d.ts +19 -0
  536. package/dist/trace/redact.js +66 -9
  537. package/dist/usage-analytics.d.ts +26 -0
  538. package/dist/usage-analytics.js +26 -3
  539. package/package.json +1 -1
@@ -1,2 +1,10 @@
1
+ /**
2
+ * Thin re-export shim (design/158 A12 扇出): the TiDB `WorkflowRunStore`/`WorkflowCompletionInbox`/
3
+ * `WorkflowNotifyJournalStore` twins now live collapsed with their PG dialect siblings in the
4
+ * single-file dual-dialect `workflow-run-store-sql.ts`. Class names, ctor arity, and the exported
5
+ * `MAX_RUN_BLOB_BYTES` / `slimOversizeRun` / `InboxWarn` surface stay EXACTLY as they were — every
6
+ * consumer (store-backend.ts, the DB-integration + slim-oversize-run suites) imports from THIS path
7
+ * unchanged.
8
+ */
1
9
  export { MAX_RUN_BLOB_BYTES, slimOversizeRun, TiDBWorkflowRunStore, TiDBWorkflowCompletionInbox, TiDBWorkflowNotifyJournalStore, } from "./workflow-run-store-sql.js";
2
10
  //# sourceMappingURL=tidb-workflow-run-store.js.map
@@ -1,24 +1,82 @@
1
+ /**
2
+ * Durable backing store for offloaded large tool results (core 1.47 offload / 1.49 durable contract) —
3
+ * SINGLE-FILE DUAL-DIALECT (design/158 A12 定型半场). ONE implementation, TWO dialects; the historical
4
+ * `TiDBToolResultStore` / `PgToolResultStore` class names survive as thin ctor subclasses so every consumer
5
+ * (store-backend.ts, the fake-pool unit suites, the real-DB integration suites) is untouched.
6
+ *
7
+ * Mirrors core's reference `TiDbToolResultStore` adapter. Without this, the Runner defaults to a
8
+ * task-scoped in-memory store: an async run that wakes on ANOTHER replica can't `read_tool_result` an
9
+ * offloaded result (the ref misses → the model is told it's unavailable; the preview still stands, so it
10
+ * degrades, never crashes). A durable store survives wake/resume across the stateless fleet.
11
+ *
12
+ * core namespaces the ref as `tr_<sessionId>_<toolCallId>` (1.49) → globally unique → usable directly as
13
+ * the PRIMARY KEY (no composite key needed). `put` is write-once (idempotent on replay/retry: a retry is
14
+ * a NEW toolCallId → new ref, so a given ref never changes content). Retention is anchored to a run's
15
+ * RECOVERABLE window via TTL (`reapOlderThan`): a resumable run may re-fetch an old ref after wake, but a
16
+ * completed run only needs the preview for audit/replay — so a TTL comfortably exceeding the run lifetime
17
+ * bounds storage without losing recoverable full-text.
18
+ *
19
+ * ── Dialect deltas, kept EXPLICIT ────────────────────────────────────────────────────────────────────
20
+ * - `?` placeholders vs `$n`
21
+ * - write-once insert = `INSERT IGNORE` vs `INSERT ... ON CONFLICT (ref) DO NOTHING`
22
+ * - affectedRows vs rowCount (via SqlDriver)
23
+ * - `SUBSTRING(content, ?, ?)` (1-indexed, comma form) vs the ANSI `SUBSTRING(content FROM $n::int FOR
24
+ * $m::int)` positional form WITH explicit `::int` casts — node-pg binds bare params as text, and
25
+ * `SUBSTRING(s FROM <text>)` is the POSIX-REGEX overload (it would treat $1 as a pattern); the cast
26
+ * forces the positional integer overload. `CHAR_LENGTH` is ANSI and shared.
27
+ * - content column: TiDB LONGTEXT vs PG TEXT (PG has no LONGTEXT; TEXT is unbounded), DATETIME(3) vs
28
+ * TIMESTAMPTZ(3) — schema only (TiDB DDL in tidb-pool.ts; PG DDL self-contained below, exported for the
29
+ * integration test + pg-pool.ts's central apply).
30
+ * - `put`'s UTF-16 sanitize is a GENUINE algorithm divergence, not just SQL text — see the dialect branch
31
+ * inline for why.
32
+ * - ESCAPE-clause literal: TiDB spells `ESCAPE '\\\\'` (declares the backslash escape char explicitly —
33
+ * under `sql_mode=NO_BACKSLASH_ESCAPES` `\` is NOT the LIKE escape char by default, so leaving it
34
+ * implicit would silently stop escaping and let a crafted sessionId's `_`/`%` over-match OTHER
35
+ * sessions' rows); PG spells `ESCAPE '\'` (its default escape char already, kept for lock-step intent
36
+ * with the TiDB twin rather than out of necessity).
37
+ */
1
38
  import type { ToolResultStore, ToolResultSlice } from "@sema-agent/core";
2
39
  import type { Pool as MySqlPool } from "mysql2/promise";
3
40
  import type { Pool as PgPool, PoolClient as PgPoolClient } from "pg";
4
41
  import { type SqlDriver } from "./sql-driver.js";
42
+ /** PG schema for the tool_result table — the PG translation of tidb-pool.ts's tool_result DDL
43
+ * (LONGTEXT→TEXT, DATETIME(3)→TIMESTAMPTZ(3), inline KEY→separate CREATE INDEX). Disjoint from other stores'
44
+ * tables, so a self-contained ensureSchema is safe (central pg-pool aggregation is done separately). */
5
45
  export declare const PG_TOOL_RESULT_SCHEMA: string[];
46
+ /** Idempotent schema apply for the tool_result table (for the integration test to call). */
6
47
  export declare function ensureSchema(pool: PgPool | PgPoolClient): Promise<void>;
48
+ /** Dual-dialect durable ToolResultStore. See the file header for the dialect-delta ledger. */
7
49
  export declare class SqlToolResultStore implements ToolResultStore {
8
50
  protected readonly db: SqlDriver;
9
51
  constructor(db: SqlDriver);
52
+ /** Pick the dialect's SQL text. Both statements stay written out at the call site ON PURPOSE. */
10
53
  private q;
11
54
  put(ref: string, content: string): Promise<void>;
12
55
  get(ref: string, opts?: {
13
56
  offset?: number;
14
57
  limit?: number;
15
58
  }): Promise<ToolResultSlice | undefined>;
59
+ /** TTL reap: delete results older than `cutoffMs`. Returns rows removed. */
16
60
  reapOlderThan(cutoffMs: number): Promise<number>;
61
+ /**
62
+ * E21 (§0.5 session delete) — purge offloaded tool results for one session. core namespaces every ref as
63
+ * `tr_<sessionId>_<toolCallId>`, so a `LIKE 'tr_<sessionId>_%'` prefix match catches them all. The sessionId
64
+ * is LIKE-escaped (`\`, `%`, `_`) so a crafted id can never widen the match across tenants. Returns rows removed.
65
+ *
66
+ * 🔴 NO SQL owner guard (adversarial-review MEDIUM, deliberate): tool_result is keyed ONLY by `ref` — there is
67
+ * no `session_id` (or `owner`) column to guard on, and the ref is not a session_meta foreign key, so an
68
+ * owner sub-select would be an awkward ref-correlated EXISTS. This purge stays ROUTE-guarded (the DELETE route
69
+ * owner-matches the session via `ownerOf` before calling, and the owner-guarded run-ledger delete runs first in
70
+ * the same coordinator) — belt-and-suspenders only, not an exploitable leak. The LIKE-escape below is the
71
+ * data-layer protection that matters (a crafted id can't widen the prefix across tenants).
72
+ */
17
73
  deleteBySession(sessionId: string): Promise<number>;
18
74
  }
75
+ /** MySQL-protocol (TiDB) binding — historical class name + ctor shape preserved. */
19
76
  export declare class TiDBToolResultStore extends SqlToolResultStore {
20
77
  constructor(pool: MySqlPool);
21
78
  }
79
+ /** PostgreSQL binding — historical class name + ctor shape preserved. */
22
80
  export declare class PgToolResultStore extends SqlToolResultStore {
23
81
  constructor(pool: PgPool);
24
82
  }
@@ -1,6 +1,9 @@
1
1
  import { escapeLike } from "./sql-escape.js";
2
2
  import { pgSanitizeText } from "./pg-safe-json.js";
3
3
  import { mysqlDriver, pgDriver } from "./sql-driver.js";
4
+ /** PG schema for the tool_result table — the PG translation of tidb-pool.ts's tool_result DDL
5
+ * (LONGTEXT→TEXT, DATETIME(3)→TIMESTAMPTZ(3), inline KEY→separate CREATE INDEX). Disjoint from other stores'
6
+ * tables, so a self-contained ensureSchema is safe (central pg-pool aggregation is done separately). */
4
7
  export const PG_TOOL_RESULT_SCHEMA = [
5
8
  `CREATE TABLE IF NOT EXISTS tool_result (
6
9
  ref VARCHAR(190) NOT NULL,
@@ -10,57 +13,90 @@ export const PG_TOOL_RESULT_SCHEMA = [
10
13
  )`,
11
14
  `CREATE INDEX IF NOT EXISTS idx_tool_result_created ON tool_result (created_at)`,
12
15
  ];
16
+ /** Idempotent schema apply for the tool_result table (for the integration test to call). */
13
17
  export async function ensureSchema(pool) {
14
18
  for (const stmt of PG_TOOL_RESULT_SCHEMA)
15
19
  await pool.query(stmt);
16
20
  }
21
+ /** Dual-dialect durable ToolResultStore. See the file header for the dialect-delta ledger. */
17
22
  export class SqlToolResultStore {
18
23
  db;
19
24
  constructor(db) {
20
25
  this.db = db;
21
26
  }
27
+ /** Pick the dialect's SQL text. Both statements stay written out at the call site ON PURPOSE. */
22
28
  q(tidb, pg) {
23
29
  return this.db.dialect === "tidb" ? tidb : pg;
24
30
  }
25
31
  async put(ref, content) {
32
+ // Sanitize invalid UTF-16 (lone/half surrogates — a JS string CAN hold them, e.g. a binary-ish tool
33
+ // output) to U+FFFD so the column accepts the FULL value via a Buffer utf8 round-trip (valid content is
34
+ // unchanged). Shared by both dialects.
26
35
  let safe = Buffer.from(content, "utf8").toString("utf8");
36
+ // 🔴 Genuine algorithm divergence (not just SQL text): TiDB's `INSERT IGNORE` downgrades an invalid-byte
37
+ // rejection to a warning + SILENT TRUNCATION (the utf8 round-trip above is enough — TiDB never sees a NUL
38
+ // complaint). PG's `ON CONFLICT DO NOTHING` does NOT paper over an encoding error — it errors — and node-pg's
39
+ // TEXT columns additionally reject a bare NUL (u0000) that a lone-surrogate round-trip alone does NOT strip
40
+ // (codex H4). `pgSanitizeText` double-scans (NUL + lone surrogate → U+FFFD) so PG never sees either. Never
41
+ // "unify" onto one engine's sanitize: TiDB doesn't need the NUL scan, and skipping it on PG reintroduces 22P05.
27
42
  if (this.db.dialect === "pg")
28
43
  safe = pgSanitizeText(safe);
44
+ // write-once / keep-first: a replay re-puts the SAME ref+content → IGNORE / DO NOTHING keeps the original row.
29
45
  await this.db.query(this.q("INSERT IGNORE INTO tool_result (ref, content, created_at) VALUES (?,?,?)", "INSERT INTO tool_result (ref, content, created_at) VALUES ($1,$2,$3) ON CONFLICT (ref) DO NOTHING"), [ref, safe, new Date()]);
30
46
  }
31
47
  async get(ref, opts = {}) {
32
48
  const offset = Math.max(0, Math.floor(opts.offset ?? 0));
33
49
  const hasLimit = opts.limit !== undefined && Number.isFinite(opts.limit);
34
50
  const limit = hasLimit ? Math.max(0, Math.floor(opts.limit)) : 0;
51
+ // One round-trip: SUBSTRING is 1-indexed (offset+1); CHAR_LENGTH gives the full (character) length for the
52
+ // slice header. With no limit, return the remainder from `offset`.
35
53
  const sql = hasLimit
36
54
  ? this.q("SELECT SUBSTRING(content, ?, ?) AS slice, CHAR_LENGTH(content) AS total FROM tool_result WHERE ref = ?", "SELECT SUBSTRING(content FROM $1::int FOR $2::int) AS slice, CHAR_LENGTH(content) AS total FROM tool_result WHERE ref = $3")
37
55
  : this.q("SELECT SUBSTRING(content, ?) AS slice, CHAR_LENGTH(content) AS total FROM tool_result WHERE ref = ?", "SELECT SUBSTRING(content FROM $1::int) AS slice, CHAR_LENGTH(content) AS total FROM tool_result WHERE ref = $2");
38
56
  const params = hasLimit ? [offset + 1, limit, ref] : [offset + 1, ref];
39
57
  const { rows } = await this.db.query(sql, params);
40
58
  if (rows.length === 0)
41
- return undefined;
59
+ return undefined; // unknown ref (e.g. reaped) → core reports "no longer available"
42
60
  return { content: String(rows[0].slice ?? ""), offset, totalChars: Number(rows[0].total) };
43
61
  }
62
+ /** TTL reap: delete results older than `cutoffMs`. Returns rows removed. */
44
63
  async reapOlderThan(cutoffMs) {
45
64
  try {
46
65
  const { affected } = await this.db.query(this.q("DELETE FROM tool_result WHERE created_at < ?", "DELETE FROM tool_result WHERE created_at < $1"), [new Date(cutoffMs)]);
47
66
  return affected;
48
67
  }
49
68
  catch {
50
- return 0;
69
+ return 0; // best-effort reaper — never throw into the loop
51
70
  }
52
71
  }
72
+ /**
73
+ * E21 (§0.5 session delete) — purge offloaded tool results for one session. core namespaces every ref as
74
+ * `tr_<sessionId>_<toolCallId>`, so a `LIKE 'tr_<sessionId>_%'` prefix match catches them all. The sessionId
75
+ * is LIKE-escaped (`\`, `%`, `_`) so a crafted id can never widen the match across tenants. Returns rows removed.
76
+ *
77
+ * 🔴 NO SQL owner guard (adversarial-review MEDIUM, deliberate): tool_result is keyed ONLY by `ref` — there is
78
+ * no `session_id` (or `owner`) column to guard on, and the ref is not a session_meta foreign key, so an
79
+ * owner sub-select would be an awkward ref-correlated EXISTS. This purge stays ROUTE-guarded (the DELETE route
80
+ * owner-matches the session via `ownerOf` before calling, and the owner-guarded run-ledger delete runs first in
81
+ * the same coordinator) — belt-and-suspenders only, not an exploitable leak. The LIKE-escape below is the
82
+ * data-layer protection that matters (a crafted id can't widen the prefix across tenants).
83
+ */
53
84
  async deleteBySession(sessionId) {
85
+ // Escape the WHOLE literal prefix `tr_<sessionId>_` (incl. both literal underscores) so the only LIKE wildcard
86
+ // is the trailing `%` — a `_` left un-escaped is a single-char wildcard that could over-match across tenants.
54
87
  const prefix = `${escapeLike(`tr_${sessionId}_`)}%`;
88
+ // Explicit `ESCAPE` clause — see the file-header dialect-delta note for why each dialect spells it as it does.
55
89
  const { affected } = await this.db.query(this.q("DELETE FROM tool_result WHERE ref LIKE ? ESCAPE '\\\\'", "DELETE FROM tool_result WHERE ref LIKE $1 ESCAPE '\\'"), [prefix]);
56
90
  return affected;
57
91
  }
58
92
  }
93
+ /** MySQL-protocol (TiDB) binding — historical class name + ctor shape preserved. */
59
94
  export class TiDBToolResultStore extends SqlToolResultStore {
60
95
  constructor(pool) {
61
96
  super(mysqlDriver(pool));
62
97
  }
63
98
  }
99
+ /** PostgreSQL binding — historical class name + ctor shape preserved. */
64
100
  export class PgToolResultStore extends SqlToolResultStore {
65
101
  constructor(pool) {
66
102
  super(pgDriver(pool));
@@ -1,10 +1,31 @@
1
+ /**
2
+ * design/102 (K-8 CC full-body) — the WebSearch BACKEND (BRAIN / model-service leg) that core leaves
3
+ * deployment-injected (`WebSearchConfig.search`; core ships NONE, the same boundary as the model gateway). Wiring a
4
+ * backend here is what makes `assembleFullBodyTools({ webSearch })` actually mount the WebSearch tool.
5
+ *
6
+ * Multi-provider, picked by `WEB_SEARCH_PROVIDER`:
7
+ * - `brave` — Brave Web Search API (GET, `X-Subscription-Token` header)
8
+ * - `tavily` — Tavily Search API (POST, `Authorization: Bearer`, native include/exclude_domains)
9
+ * - `searxng` — a self-hosted SearXNG instance (GET `?format=json`, no auth)
10
+ *
11
+ * Each returns `{ title, url, snippet }[]`; core does the rest — it `delimitUntrusted`-fences the (UNTRUSTED) results
12
+ * and re-enforces the `allowed_domains`/`blocked_domains` FLOOR on them, so honoring `opts` here is an optimization,
13
+ * not a correctness requirement (a backend MAY ignore it). The API key comes from deployment env — it never enters
14
+ * the model prompt or the tool args. `effect:"read"` (idempotent) is core's concern; this is just the transport.
15
+ */
16
+ /** Search providers this backend speaks. Absent `WEB_SEARCH_PROVIDER` ⇒ no backend ⇒ WebSearch is not assembled. */
1
17
  export type WebSearchProvider = "brave" | "tavily" | "searxng";
2
18
  export interface WebSearchBackendConfig {
3
19
  readonly provider: WebSearchProvider;
20
+ /** API key (brave/tavily). From `WEB_SEARCH_API_KEY` — never reaches the model. */
4
21
  readonly apiKey?: string;
22
+ /** SearXNG instance base URL (REQUIRED for searxng); for brave/tavily an optional base-URL override (proxy/test). */
5
23
  readonly endpoint?: string;
24
+ /** Max results returned to the model (clamped 1..20; default 10). */
6
25
  readonly maxResults?: number;
26
+ /** Per-search wall-clock (ms, default 10000). */
7
27
  readonly timeoutMs?: number;
28
+ /** Injectable for tests. */
8
29
  readonly fetchImpl?: typeof fetch;
9
30
  }
10
31
  export interface WebSearchResult {
@@ -16,13 +37,27 @@ export interface WebSearchOpts {
16
37
  allowedDomains?: string[];
17
38
  blockedDomains?: string[];
18
39
  }
40
+ /** The shape core's `WebSearchConfig.search` expects (back-compatible 2- or 3-arg). */
19
41
  export type WebSearchFn = (query: string, signal?: AbortSignal, opts?: WebSearchOpts) => Promise<WebSearchResult[]>;
42
+ /** The live object `createWebSearchBackend` produces — a `search` fn (provider + API key captured in the closure) + the effective result cap. */
20
43
  export interface WebSearchBackend {
21
44
  search: WebSearchFn;
22
45
  maxResults: number;
23
46
  }
24
47
  export declare function setWebSearchBadPayloadObserver(fn: ((provider: string) => void) | undefined): void;
48
+ /**
49
+ * Build the `WebSearchConfig` (a `search` fn + `maxResults`) for `assembleFullBodyTools({ webSearch })`. The API key
50
+ * stays captured in this closure — it is never surfaced to the model or the tool args.
51
+ */
25
52
  export declare function createWebSearchBackend(cfg: WebSearchBackendConfig): WebSearchBackend;
53
+ /** Parse the deployment env into a backend config; `undefined` when no provider is set (⇒ WebSearch not assembled). */
26
54
  export declare function webSearchConfigFromEnv(env?: NodeJS.ProcessEnv): WebSearchBackendConfig | undefined;
55
+ /**
56
+ * Parse an UNTRUSTED per-request `body.settings.webSearch` (the user's shell settings — `{provider, apiKey?, endpoint?,
57
+ * maxResults?}`) into a backend config. Returns `undefined` for a missing/invalid provider — NEVER throws, so a bad
58
+ * per-request config falls back to the deployment-env backend rather than failing the task. 🔒 The CALLER gates this to
59
+ * the single-user host lane (a per-request `endpoint`/`apiKey` is a capability config; on multi-tenant a tenant could
60
+ * point `searxng` at an internal URL = SSRF, so multi-tenant uses ONLY the deployment-env backend — design/107 axis).
61
+ */
27
62
  export declare function webSearchConfigFromSettings(raw: unknown): WebSearchBackendConfig | undefined;
28
63
  //# sourceMappingURL=web-search.d.ts.map
@@ -1,7 +1,23 @@
1
+ /**
2
+ * design/102 (K-8 CC full-body) — the WebSearch BACKEND (BRAIN / model-service leg) that core leaves
3
+ * deployment-injected (`WebSearchConfig.search`; core ships NONE, the same boundary as the model gateway). Wiring a
4
+ * backend here is what makes `assembleFullBodyTools({ webSearch })` actually mount the WebSearch tool.
5
+ *
6
+ * Multi-provider, picked by `WEB_SEARCH_PROVIDER`:
7
+ * - `brave` — Brave Web Search API (GET, `X-Subscription-Token` header)
8
+ * - `tavily` — Tavily Search API (POST, `Authorization: Bearer`, native include/exclude_domains)
9
+ * - `searxng` — a self-hosted SearXNG instance (GET `?format=json`, no auth)
10
+ *
11
+ * Each returns `{ title, url, snippet }[]`; core does the rest — it `delimitUntrusted`-fences the (UNTRUSTED) results
12
+ * and re-enforces the `allowed_domains`/`blocked_domains` FLOOR on them, so honoring `opts` here is an optimization,
13
+ * not a correctness requirement (a backend MAY ignore it). The API key comes from deployment env — it never enters
14
+ * the model prompt or the tool args. `effect:"read"` (idempotent) is core's concern; this is just the transport.
15
+ */
1
16
  const DEFAULT_MAX_RESULTS = 10;
2
17
  const DEFAULT_TIMEOUT_MS = 10_000;
3
18
  const BRAVE_BASE = "https://api.search.brave.com/res/v1/web/search";
4
19
  const TAVILY_BASE = "https://api.tavily.com/search";
20
+ /** Combine the caller's AbortSignal with a per-search timeout into one signal; `done()` clears the timer + listener. */
5
21
  function withTimeout(signal, ms) {
6
22
  const ctrl = new AbortController();
7
23
  const onAbort = () => ctrl.abort();
@@ -18,6 +34,13 @@ function withTimeout(signal, ms) {
18
34
  async function errorText(res) {
19
35
  return (await res.text().catch(() => "")).slice(0, 200);
20
36
  }
37
+ /**
38
+ * Normalize an UNTRUSTED provider results payload: guard a non-array (a misconfigured proxy / buggy self-hosted
39
+ * SearXNG could return a non-list or null elements), skip null/non-object rows, coerce every field to a string, drop
40
+ * url-less rows, cap to max. `pick` maps each provider's row to the common shape (Brave→description, others→content).
41
+ */
42
+ /** LOW (SILENT-FALLBACK P1): a provider returning a non-array `results` used to silently become zero results
43
+ * for the model. main.ts wires this to web_search_bad_payload_total{provider} + a warn. */
21
44
  let onBadPayload;
22
45
  export function setWebSearchBadPayloadObserver(fn) {
23
46
  onBadPayload = fn;
@@ -28,18 +51,18 @@ function normalize(raw, pick, max, provider) {
28
51
  try {
29
52
  onBadPayload?.(provider);
30
53
  }
31
- catch { }
54
+ catch { /* observability never breaks search */ }
32
55
  }
33
- return [];
34
- }
56
+ return []; // absent field (undefined/null) = legitimately empty; a PRESENT non-array = malformed payload
57
+ } // 🔴 review LOW: a non-array `results` must not throw a raw TypeError upstream
35
58
  const out = [];
36
59
  for (const row of raw) {
37
60
  if (!row || typeof row !== "object")
38
- continue;
61
+ continue; // a null / non-object element is not a result
39
62
  const f = pick(row);
40
63
  const url = typeof f.url === "string" ? f.url : "";
41
64
  if (!url)
42
- continue;
65
+ continue; // no URL ⇒ useless to the model (and to core's domain re-enforcement)
43
66
  out.push({ title: typeof f.title === "string" ? f.title : "", url, snippet: typeof f.snippet === "string" ? f.snippet : "" });
44
67
  if (out.length >= max)
45
68
  break;
@@ -51,7 +74,8 @@ async function braveSearch(fetchImpl, cfg, query, max, signal) {
51
74
  throw new Error("WEB_SEARCH_API_KEY is required for the brave provider");
52
75
  const url = new URL(cfg.endpoint || BRAVE_BASE);
53
76
  url.searchParams.set("q", query);
54
- url.searchParams.set("count", String(Math.min(20, max)));
77
+ url.searchParams.set("count", String(Math.min(20, max))); // Brave caps count at 20
78
+ // Brave has no native include/exclude_domains param — core re-enforces the domain floor on the results.
55
79
  const res = await fetchImpl(url, { headers: { Accept: "application/json", "X-Subscription-Token": cfg.apiKey }, signal });
56
80
  if (!res.ok)
57
81
  throw new Error(`brave search failed (${res.status}): ${await errorText(res)}`);
@@ -63,7 +87,7 @@ async function tavilySearch(fetchImpl, cfg, query, max, signal, opts) {
63
87
  throw new Error("WEB_SEARCH_API_KEY is required for the tavily provider");
64
88
  const body = { query, max_results: Math.min(20, max) };
65
89
  if (opts?.allowedDomains?.length)
66
- body.include_domains = opts.allowedDomains.slice(0, 300);
90
+ body.include_domains = opts.allowedDomains.slice(0, 300); // Tavily native domain filter
67
91
  if (opts?.blockedDomains?.length)
68
92
  body.exclude_domains = opts.blockedDomains.slice(0, 150);
69
93
  const res = await fetchImpl(cfg.endpoint || TAVILY_BASE, {
@@ -80,15 +104,19 @@ async function tavilySearch(fetchImpl, cfg, query, max, signal, opts) {
80
104
  async function searxngSearch(fetchImpl, cfg, query, max, signal) {
81
105
  if (!cfg.endpoint)
82
106
  throw new Error("WEB_SEARCH_ENDPOINT (the SearXNG instance URL) is required for the searxng provider");
83
- const url = new URL("/search", cfg.endpoint);
107
+ const url = new URL("/search", cfg.endpoint); // endpoint is the deployment-configured instance base (trusted, not model-controlled)
84
108
  url.searchParams.set("q", query);
85
109
  url.searchParams.set("format", "json");
86
- const res = await fetchImpl(url, { headers: { Accept: "application/json" }, signal });
110
+ const res = await fetchImpl(url, { headers: { Accept: "application/json" }, signal }); // SearXNG needs no auth
87
111
  if (!res.ok)
88
112
  throw new Error(`searxng search failed (${res.status}): ${await errorText(res)}`);
89
113
  const data = (await res.json());
90
114
  return normalize(data.results, (r) => ({ title: r.title, url: r.url, snippet: r.content }), max, "searxng");
91
115
  }
116
+ /**
117
+ * Build the `WebSearchConfig` (a `search` fn + `maxResults`) for `assembleFullBodyTools({ webSearch })`. The API key
118
+ * stays captured in this closure — it is never surfaced to the model or the tool args.
119
+ */
92
120
  export function createWebSearchBackend(cfg) {
93
121
  const fetchImpl = cfg.fetchImpl ?? fetch;
94
122
  const maxResults = Math.max(1, Math.min(20, cfg.maxResults ?? DEFAULT_MAX_RESULTS));
@@ -111,6 +139,7 @@ export function createWebSearchBackend(cfg) {
111
139
  };
112
140
  return { search, maxResults };
113
141
  }
142
+ /** Parse the deployment env into a backend config; `undefined` when no provider is set (⇒ WebSearch not assembled). */
114
143
  export function webSearchConfigFromEnv(env = process.env) {
115
144
  const provider = env.WEB_SEARCH_PROVIDER?.trim().toLowerCase();
116
145
  if (provider !== "brave" && provider !== "tavily" && provider !== "searxng")
@@ -125,6 +154,13 @@ export function webSearchConfigFromEnv(env = process.env) {
125
154
  ...(Number.isFinite(timeoutRaw) && timeoutRaw > 0 ? { timeoutMs: Math.floor(timeoutRaw) } : {}),
126
155
  };
127
156
  }
157
+ /**
158
+ * Parse an UNTRUSTED per-request `body.settings.webSearch` (the user's shell settings — `{provider, apiKey?, endpoint?,
159
+ * maxResults?}`) into a backend config. Returns `undefined` for a missing/invalid provider — NEVER throws, so a bad
160
+ * per-request config falls back to the deployment-env backend rather than failing the task. 🔒 The CALLER gates this to
161
+ * the single-user host lane (a per-request `endpoint`/`apiKey` is a capability config; on multi-tenant a tenant could
162
+ * point `searxng` at an internal URL = SSRF, so multi-tenant uses ONLY the deployment-env backend — design/107 axis).
163
+ */
128
164
  export function webSearchConfigFromSettings(raw) {
129
165
  if (!raw || typeof raw !== "object")
130
166
  return undefined;
@@ -1,2 +1,12 @@
1
+ /**
2
+ * SVC-2 — the shared size bound for a journaled workflow-agent result, so all THREE backends (tidb/pg SQL
3
+ * twins here + core's FileWorkflowJournalStore) DEGRADE IDENTICALLY on an oversize TaskResult: skip-journal
4
+ * (a no-op, never insert/throw) — the agent's ordinal is simply not cached and a resume re-runs that one
5
+ * agent live. Rationale (TiDB ~6 MiB txn-entry-size-limit vs PG/file no such limit) documented at the source.
6
+ *
7
+ * Now a RE-EXPORT of core's copy: the constant + helper moved to core with the FileWorkflowJournalStore
8
+ * adoption (core 1.223.0 — core inlined them into its store file and exports both).
9
+ * The SQL twins import from here unchanged; one source of truth for the byte-match contract.
10
+ */
1
11
  export { MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult } from "@sema-agent/core";
2
12
  //# sourceMappingURL=workflow-journal-limits.d.ts.map
@@ -1,2 +1,12 @@
1
+ /**
2
+ * SVC-2 — the shared size bound for a journaled workflow-agent result, so all THREE backends (tidb/pg SQL
3
+ * twins here + core's FileWorkflowJournalStore) DEGRADE IDENTICALLY on an oversize TaskResult: skip-journal
4
+ * (a no-op, never insert/throw) — the agent's ordinal is simply not cached and a resume re-runs that one
5
+ * agent live. Rationale (TiDB ~6 MiB txn-entry-size-limit vs PG/file no such limit) documented at the source.
6
+ *
7
+ * Now a RE-EXPORT of core's copy: the constant + helper moved to core with the FileWorkflowJournalStore
8
+ * adoption (core 1.223.0 — core inlined them into its store file and exports both).
9
+ * The SQL twins import from here unchanged; one source of truth for the byte-match contract.
10
+ */
1
11
  export { MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult } from "@sema-agent/core";
2
12
  //# sourceMappingURL=workflow-journal-limits.js.map
@@ -1,7 +1,50 @@
1
+ /**
2
+ * Durable {@link WorkflowJournalStore} (SVC-2, core CORE-7) — SINGLE-FILE DUAL-DIALECT (design/158 A12
3
+ * 定型半场). ONE implementation, TWO dialects; the historical `TiDBWorkflowJournalStore` / `PgWorkflowJournalStore`
4
+ * class names survive as thin ctor subclasses so every consumer (store-backend.ts, the extreme/integration/
5
+ * resume-fork-probe suites) is untouched.
6
+ *
7
+ * This is the cross-replica resume journal for an LLM-authored workflow. core ships
8
+ * {@link import("@sema-agent/core").InMemoryWorkflowJournalStore} (single-replica, lost on crash); this is the
9
+ * byte-match durable twin so a workflow survives a replica crash and RESUMES (replay the longest unchanged
10
+ * PREFIX of recorded `ctx.agent` results, run only the first changed/new call + everything after it live). The
11
+ * journal is LOAD-BEARING (unlike the best-effort {@link import("./tidb-run-store.js")} observation layer):
12
+ * append/load failures MUST throw — a silently-dropped entry would silently re-run already-done work.
13
+ *
14
+ * Schema = `workflow_journal (run_id, ordinal) PK` (DDL in tidb-pool.ts / pg-pool.ts ensureSchema). `ordinal`
15
+ * is the positional index a callKey was minted at, derived with core's {@link callKeyOrdinal} (NEVER
16
+ * hand-parsed — a malformed key falls back to ordinal 0 there, matching the InMemory store). `result` holds
17
+ * `JSON.stringify(entry.result)` (a TaskResult is plain serializable data). The PK makes append IDEMPOTENT per
18
+ * (run_id, ordinal): a second append for the same ordinal OVERWRITES (last-write-wins) — a resumed run
19
+ * re-appends its replayed prefix verbatim, so this is the exact InMemory `byOrdinal.set(ordinal, …)` semantics,
20
+ * not a duplicate row.
21
+ *
22
+ * ── Dialect deltas, kept EXPLICIT ────────────────────────────────────────────────────────────────────
23
+ * - `?` placeholders vs `$n`
24
+ * - `ON DUPLICATE KEY UPDATE … VALUES(col)` vs `ON CONFLICT (run_id, ordinal) DO UPDATE SET … EXCLUDED.col`
25
+ * - `LENGTH(result)` (TiDB — byte length) vs `OCTET_LENGTH(result)` (PG — `LENGTH(text)` is CHARACTER count;
26
+ * a multi-byte UTF-8 payload would silently slip past the byte-budget cap on PG with plain `LENGTH`, so
27
+ * the twin uses the byte-counting function instead — codex R3, real dual-DB-suite-confirmed) in `loadPage`'s
28
+ * size-gate CASE.
29
+ * - `loadPage`'s bind-param ORDER: TiDB's `?`s appear in query-text order (maxResultBytes first, inside the
30
+ * CASE, ahead of runId/scope), so its params array is `[maxResultBytes, runId, scope, limit, offset]`; PG's
31
+ * `$n` are POSITIONAL (not text-order), so its array is `[runId, scope, maxResultBytes, limit, offset]`
32
+ * (`$3` inside the CASE refers to the third element regardless of where `$3` sits in the text). Same
33
+ * placeholder-arity-fallout class the sql-driver.ts header calls out for null-safe compares.
34
+ * - affectedRows vs rowCount (via SqlDriver's normalized `affected`).
35
+ * - schema ownership: TiDB DDL in tidb-pool.ts, PG DDL in pg-pool.ts (neither store creates tables).
36
+ */
1
37
  import type { Pool as MySqlPool } from "mysql2/promise";
2
38
  import type { Pool as PgPool } from "pg";
3
39
  import { type WorkflowJournalEntry, type WorkflowJournalStore } from "@sema-agent/core";
4
40
  import { type SqlDriver } from "./sql-driver.js";
41
+ /** Dual-dialect durable WorkflowJournalStore. See the file header for the dialect-delta ledger. */
42
+ /** RB-242 租约旋钮。TTL 只是**崩溃兜底**(engine 终态 finally 显式释放;[1981]/[1984] 两层分工:
43
+ * engine 崩了没释放 ⇒ 陈旧 claim 可被接管)。
44
+ * 🔴 缺省 1h,与 core file 参考实现同值([1984] :284)——**租约无心跳**(claimed_at 在授予时刻定格,
45
+ * 运行期间不刷新),所以 TTL 必须盖过最长合法 run 时长:取小了(我初版 15min)会在一次 >TTL 的活跑
46
+ * 中把 claim 判陈旧、放另一副本进来接管——恰是本缝要防的双跑。要更短的接管等待,先给 engine 半场
47
+ * 加心跳刷新,再谈调小。 */
5
48
  export interface SqlWorkflowJournalStoreOptions {
6
49
  resumeClaimTtlMs?: number;
7
50
  }
@@ -9,10 +52,26 @@ export declare class SqlWorkflowJournalStore implements WorkflowJournalStore {
9
52
  private readonly db;
10
53
  private readonly resumeClaimTtlMs;
11
54
  constructor(db: SqlDriver, opts?: SqlWorkflowJournalStoreOptions);
55
+ /** Pick the dialect's SQL text. Both statements stay written out at the call site ON PURPOSE. */
12
56
  private q;
57
+ /** Record one agent's result. Idempotent per (run_id, ordinal): the PK upsert OVERWRITES (last-write-wins), so a
58
+ * resumed run re-appending its replayed prefix verbatim leaves no duplicate. callKeyOrdinal is the SOLE ordinal
59
+ * source (core's parser — a malformed key collapses to 0, matching InMemory). Throws on a REAL failure
60
+ * (LOAD-BEARING), EXCEPT an oversize result is skip-journaled (see below) rather than throwing the workflow dead. */
13
61
  append(runId: string, scope: string, entry: WorkflowJournalEntry): Promise<void>;
62
+ /** Entries for `runId` IF its recorded scope === `scope`, ASCENDING by ordinal; otherwise EMPTY. CORE-9 audit
63
+ * BLOCKER: scope in the WHERE (twin of WorkflowRunStore) — the LLM controls `resumeFromRunId`, so a cross-scope
64
+ * runId resolves to an empty journal (resume safely diverges to live, never discloses another tenant's results).
65
+ * Each row's `result` is the persisted JSON.stringify(TaskResult) → JSON.parse back. Throws on failure (LOAD-BEARING). */
14
66
  load(runId: string, scope: string): Promise<WorkflowJournalEntry[]>;
67
+ /** [1412] locator 云形(core 1.353 WorkflowJournalStore.locator additive):SQL 店的 journal 坐标=
68
+ * [1402] HTTP 读面路由(file 店返 jsonl 路径=CC 本地形;此处返云形,core 铸 diagnostics 教句时单源引用)。 */
15
69
  locator(runId: string, _scope: string): string;
70
+ /** codex R1-H2:分页投影读——LIMIT/OFFSET 界行数,字节门界单行字节(超限行不取 result 全文,只回字节数;
71
+ * 读面标 truncated)。ORDER BY ordinal 与 load 同轴。
72
+ * 🔴 param ORDER differs by dialect (see file header): TiDB's `?`s bind in text order (maxResultBytes first,
73
+ * inside the CASE); PG's `$n` are positional, so its array keeps runId/scope first. Never unify — a swap
74
+ * silently mis-binds the OTHER dialect's placeholders. */
16
75
  loadPage(runId: string, scope: string, opts: {
17
76
  offset: number;
18
77
  limit: number;
@@ -22,7 +81,18 @@ export declare class SqlWorkflowJournalStore implements WorkflowJournalStore {
22
81
  resultJson: string | null;
23
82
  resultBytes: number;
24
83
  }>>;
84
+ /** GC — purge ALL journal entries for a run (the run reaper calls this once the run is terminal + retained). Scoped
85
+ * by run_id alone; idempotent (affected-row count). Mirrors the resume-anchor store's deleteBySession. */
25
86
  deleteByRun(runId: string): Promise<number>;
87
+ /** RB-242 / WF2([1981] core 拍板 a 形,签名逐字)—— cross-replica resume admission lease。
88
+ *
89
+ * 语义(bake-store `idem_key UNIQUE` 先例):PK (source_run_id, scope) 上的原子赢或观察。四步,每步
90
+ * 单语句原子,并发交叉在任一步都收敛到「恰一个持有者」:
91
+ * ① 抢空位:INSERT..DO NOTHING / ON DUP KEY 无操作 —— affected=1 即赢;
92
+ * ② 同持有者幂等重入(engine 重试同一 resume):按 (键, new_run_id) 守卫的 claimed_at 刷新;
93
+ * ③ TTL 崩溃兜底接管:claimed_at < now-ttl 守卫下的原子改持有者(engine 终态会显式释放,
94
+ * 走到这步=上一持有 engine 崩了没释放;两层分工见 SqlWorkflowJournalStoreOptions 注);
95
+ * ④ 都没赢 ⇒ 读在位者返 {granted:false, holder}(holder 进 engine 的拒绝文案供归因)。 */
26
96
  resumeClaim(input: {
27
97
  sourceRunId: string;
28
98
  newRunId: string;
@@ -31,16 +101,24 @@ export declare class SqlWorkflowJournalStore implements WorkflowJournalStore {
31
101
  granted: boolean;
32
102
  holder?: string;
33
103
  }>;
104
+ /** 只有 holder 能释放(new_run_id 守卫)—— engine 在 newRunId 终态/放弃时调;非 holder 调用=no-op。 */
34
105
  releaseResumeClaim(input: {
35
106
  sourceRunId: string;
36
107
  newRunId: string;
37
108
  scope: string;
38
109
  }): Promise<void>;
110
+ /** GC — time-based sweep: purge journal entries older than `maxAgeMs` (created_at < now - maxAgeMs). The
111
+ * per-run deleteByRun has no production caller (a run-store reap gives no per-run hook), so this bounded sweep
112
+ * — wired into the service reaper — is what keeps the heaviest table (TaskResult-bearing) from growing without
113
+ * bound. A resume of a journal older than the retention window simply re-runs live (resume is an optimization).
114
+ * Idempotent; returns the rows purged. */
39
115
  reapExpired(now: number, maxAgeMs: number): Promise<number>;
40
116
  }
117
+ /** MySQL-protocol (TiDB) binding — historical class name + ctor shape preserved. */
41
118
  export declare class TiDBWorkflowJournalStore extends SqlWorkflowJournalStore {
42
119
  constructor(pool: MySqlPool, opts?: SqlWorkflowJournalStoreOptions);
43
120
  }
121
+ /** PostgreSQL binding — historical class name + ctor shape preserved. */
44
122
  export declare class PgWorkflowJournalStore extends SqlWorkflowJournalStore {
45
123
  constructor(pool: PgPool, opts?: SqlWorkflowJournalStoreOptions);
46
124
  }