@sema-agent/server 7.145.0 → 7.147.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 (526) hide show
  1. package/MIGRATION.md +876 -0
  2. package/README.md +1 -1
  3. package/README.zh-CN.md +1 -1
  4. package/USAGE.md +374 -99
  5. package/deploy/facts/CHANGES.json +25 -0
  6. package/deploy/facts/README.md +57 -0
  7. package/deploy/facts/lanes.json +61 -0
  8. package/deploy/facts/lanes.schema.json +57 -0
  9. package/deploy/facts/sandbox-rbac.json +113 -0
  10. package/deploy/facts/sandbox-rbac.schema.json +74 -0
  11. package/deploy/facts/sealed-key.json +9 -0
  12. package/deploy/facts/sealed-key.schema.json +52 -0
  13. package/deploy/sema-up/README.md +2 -2
  14. package/deploy/sema-up/chart/templates/_helpers.tpl +41 -0
  15. package/deploy/sema-up/chart/templates/sandbox-rbac.yaml +47 -7
  16. package/deploy/sema-up/chart/templates/server-v4pro.yaml +9 -4
  17. package/deploy/sema-up/chart/templates/server.yaml +9 -4
  18. package/deploy/sema-up/chart/values.yaml +8 -1
  19. package/deploy/sema-up/cluster-up.sh +2 -1
  20. package/deploy/sema-up/lib/flagshape.sh +4 -0
  21. package/deploy/sema-up/lib/lanes.json +2 -5
  22. package/deploy/sema-up/sema-up.sh +12 -9
  23. package/deploy/sema-up/stack/compose.yaml +5 -4
  24. package/deploy/sema-up/stack/sema-stack-cluster.yaml +34 -17
  25. package/dist/adoption/import-limits.d.ts +6 -0
  26. package/dist/adoption/import-limits.js +7 -0
  27. package/dist/adoption/import.d.ts +62 -0
  28. package/dist/adoption/import.js +107 -0
  29. package/dist/adoption/wire.d.ts +52 -0
  30. package/dist/adoption/wire.js +9 -0
  31. package/dist/approval-ask-machine.d.ts +2 -2
  32. package/dist/approval-card.d.ts +7 -16
  33. package/dist/approval-card.js +0 -4
  34. package/dist/approval-gate-currency.d.ts +1 -1
  35. package/dist/approval-gate-currency.js +1 -1
  36. package/dist/approval-reconciler.d.ts +1 -1
  37. package/dist/approval.d.ts +3 -3
  38. package/dist/audit.js +2 -2
  39. package/dist/bench/s1/live-deps.js +3 -1
  40. package/dist/boot/crash-last.js +2 -1
  41. package/dist/boot/deployment-mods.d.ts +11 -1
  42. package/dist/boot/deployment-mods.js +15 -2
  43. package/dist/boot/device-lane.js +7 -5
  44. package/dist/boot/engine-lease.d.ts +195 -22
  45. package/dist/boot/engine-lease.js +146 -20
  46. package/dist/boot/execution-env.d.ts +5 -0
  47. package/dist/boot/execution-env.js +57 -33
  48. package/dist/boot/execution-lane.d.ts +37 -9
  49. package/dist/boot/execution-lane.js +74 -20
  50. package/dist/boot/exit-boundary.d.ts +50 -0
  51. package/dist/boot/exit-boundary.js +32 -0
  52. package/dist/boot/exit-last.d.ts +20 -4
  53. package/dist/boot/exit-last.js +23 -5
  54. package/dist/boot/governance-seams.d.ts +2 -2
  55. package/dist/boot/governance-seams.js +1 -0
  56. package/dist/boot/leader.js +1 -1
  57. package/dist/boot/memory-boundary.d.ts +11 -11
  58. package/dist/boot/memory-boundary.js +3 -3
  59. package/dist/boot/memory-consolidation.d.ts +42 -41
  60. package/dist/boot/memory-consolidation.js +26 -28
  61. package/dist/boot/org-memory.js +3 -2
  62. package/dist/boot/parked-revive-gate.d.ts +1 -1
  63. package/dist/boot/parked-revive-gate.js +1 -1
  64. package/dist/boot/reapers.d.ts +12 -4
  65. package/dist/boot/reapers.js +40 -16
  66. package/dist/boot/resolve-spec.d.ts +2 -0
  67. package/dist/boot/resolve-spec.js +126 -123
  68. package/dist/boot/retention-lane.d.ts +4 -42
  69. package/dist/boot/runner-deps.js +1 -1
  70. package/dist/boot/session-faces.d.ts +1 -0
  71. package/dist/boot/session-faces.js +11 -3
  72. package/dist/boot/shutdown.js +27 -9
  73. package/dist/boot/stage-01-config.d.ts +1 -1
  74. package/dist/boot/stage-01-config.js +7 -3
  75. package/dist/boot/stage-02-web-admin-pull.d.ts +1 -1
  76. package/dist/boot/stage-02-web-admin-pull.js +10 -8
  77. package/dist/boot/stage-03-store-backend.d.ts +2 -1
  78. package/dist/boot/stage-03-store-backend.js +2 -2
  79. package/dist/boot/stage-04-stores.d.ts +2 -1
  80. package/dist/boot/stage-05-execution-env.d.ts +4 -1
  81. package/dist/boot/stage-05-execution-env.js +6 -6
  82. package/dist/boot/stage-06-runners.d.ts +5 -2
  83. package/dist/boot/stage-06-runners.js +12 -13
  84. package/dist/boot/stage-07-capability-layer.d.ts +5 -2
  85. package/dist/boot/stage-07-capability-layer.js +7 -7
  86. package/dist/boot/stage-08-reapers.d.ts +5 -2
  87. package/dist/boot/stage-08-reapers.js +3 -3
  88. package/dist/boot/stage-09-leader.d.ts +6 -2
  89. package/dist/boot/stage-10-http-server.d.ts +6 -2
  90. package/dist/boot/stage-10-http-server.js +5 -3
  91. package/dist/boot/stores.d.ts +10 -0
  92. package/dist/boot/stores.js +53 -26
  93. package/dist/boot/web-admin.js +3 -3
  94. package/dist/boot/workflow-orchestration.d.ts +1 -1
  95. package/dist/boot/workflow-orchestration.js +2 -1
  96. package/dist/capabilities/center-plugins.d.ts +2 -0
  97. package/dist/capabilities/center-plugins.js +6 -2
  98. package/dist/capabilities/composite-members.d.ts +4 -1
  99. package/dist/capabilities/composite-members.js +4 -1
  100. package/dist/capabilities/execution-lane.d.ts +7 -7
  101. package/dist/capabilities/execution-lane.js +2 -2
  102. package/dist/capabilities/hands-lane.d.ts +1 -1
  103. package/dist/capabilities/scenarios.d.ts +34 -20
  104. package/dist/capabilities/scenarios.js +13 -9
  105. package/dist/capabilities/settings-contract.d.ts +29 -0
  106. package/dist/capabilities/settings-contract.js +14 -0
  107. package/dist/capabilities/skills.d.ts +5 -5
  108. package/dist/capability-facts.d.ts +56 -1
  109. package/dist/capability-facts.js +59 -8
  110. package/dist/center-credential-renewer.js +3 -2
  111. package/dist/checkpoint-ctx-seal-m28.d.ts +1 -1
  112. package/dist/config-catalog.js +19 -9
  113. package/dist/config-invariants.d.ts +18 -3
  114. package/dist/config-invariants.js +36 -19
  115. package/dist/config-lkg.d.ts +1 -1
  116. package/dist/config-lkg.js +5 -6
  117. package/dist/config-provider.d.ts +2 -2
  118. package/dist/config-provider.js +2 -0
  119. package/dist/config-types.d.ts +228 -185
  120. package/dist/config.d.ts +74 -6
  121. package/dist/config.js +146 -64
  122. package/dist/degenerate-instrument.js +1 -1
  123. package/dist/deleted-session-ids.d.ts +19 -0
  124. package/dist/deleted-session-ids.js +26 -0
  125. package/dist/deploy-facts.d.ts +155 -0
  126. package/dist/deploy-facts.js +95 -0
  127. package/dist/deployment-shape.d.ts +21 -12
  128. package/dist/deployment-shape.js +24 -6
  129. package/dist/device-ws-hub.d.ts +48 -3
  130. package/dist/device-ws-hub.js +48 -2
  131. package/dist/env-facts.d.ts +7 -5
  132. package/dist/env-facts.js +10 -6
  133. package/dist/error-code-family.d.ts +35 -0
  134. package/dist/error-code-family.js +26 -0
  135. package/dist/execution-config-root.d.ts +5 -5
  136. package/dist/execution-config-root.js +5 -5
  137. package/dist/execution-env-purpose.d.ts +14 -0
  138. package/dist/execution-env-purpose.js +29 -0
  139. package/dist/execution-lane-caps.d.ts +49 -86
  140. package/dist/execution-lane-caps.js +52 -62
  141. package/dist/execution-placement.d.ts +18 -2
  142. package/dist/execution-placement.js +19 -0
  143. package/dist/file-history-disclosure.d.ts +2 -2
  144. package/dist/fleet/drain-entry.d.ts +46 -3
  145. package/dist/fleet/drain-entry.js +6 -0
  146. package/dist/fleet/fleet-bus.d.ts +2 -1
  147. package/dist/fleet/serving-lease.js +3 -4
  148. package/dist/history-anchor.d.ts +22 -0
  149. package/dist/history-anchor.js +14 -0
  150. package/dist/hooks/branch-transcript.d.ts +1 -1
  151. package/dist/hooks/branch-transcript.js +1 -0
  152. package/dist/hooks/classic-stations.d.ts +25 -8
  153. package/dist/hooks/classic-stations.js +29 -3
  154. package/dist/hooks/command-spawn.d.ts +1 -4
  155. package/dist/hooks/command-spawn.js +0 -11
  156. package/dist/hooks/hook-runner.d.ts +85 -24
  157. package/dist/hooks/hook-runner.js +326 -109
  158. package/dist/hooks/hook-source.d.ts +14 -2
  159. package/dist/hooks/hook-source.js +8 -0
  160. package/dist/http/active-run-conflict.d.ts +1 -1
  161. package/dist/http/active-run-conflict.js +1 -1
  162. package/dist/http/admission.js +11 -1
  163. package/dist/http/approval-sweeps.d.ts +2 -5
  164. package/dist/http/approval-sweeps.js +3 -2
  165. package/dist/http/checkpoint-ctx.d.ts +76 -71
  166. package/dist/http/checkpoint-ctx.js +40 -40
  167. package/dist/http/claim-latency.d.ts +10 -0
  168. package/dist/http/claim-latency.js +12 -0
  169. package/dist/http/dispatch.js +19 -3
  170. package/dist/http/durable-run-leg.d.ts +5 -0
  171. package/dist/http/durable-run-leg.js +3 -1
  172. package/dist/http/execution-context.d.ts +7 -1
  173. package/dist/http/execution-context.js +13 -0
  174. package/dist/http/health-self-report.d.ts +6 -2
  175. package/dist/http/health-self-report.js +3 -2
  176. package/dist/http/memory-compliance-failure-reply.d.ts +2 -2
  177. package/dist/http/memory-compliance-failure-reply.js +5 -15
  178. package/dist/http/memory-control-plane-corrupt-reply.d.ts +25 -0
  179. package/dist/http/memory-control-plane-corrupt-reply.js +19 -0
  180. package/dist/http/memory-store-refusal-reply.d.ts +3 -3
  181. package/dist/http/memory-store-refusal-reply.js +3 -0
  182. package/dist/http/owner-access.d.ts +11 -0
  183. package/dist/http/owner-access.js +7 -4
  184. package/dist/http/principal-gate.d.ts +28 -16
  185. package/dist/http/principal-gate.js +10 -19
  186. package/dist/http/request-guards.d.ts +2 -2
  187. package/dist/http/request-guards.js +5 -5
  188. package/dist/http/resume-legs.d.ts +29 -10
  189. package/dist/http/resume-legs.js +94 -56
  190. package/dist/http/rewind-files-reply.d.ts +34 -0
  191. package/dist/http/rewind-files-reply.js +36 -0
  192. package/dist/http/route-ctx.d.ts +43 -26
  193. package/dist/http/route-table.js +4 -0
  194. package/dist/http/routes/adoption.d.ts +11 -0
  195. package/dist/http/routes/adoption.js +80 -6
  196. package/dist/http/routes/agents-roster.js +1 -0
  197. package/dist/http/routes/approvals-assistant.js +7 -26
  198. package/dist/http/routes/background.js +1 -0
  199. package/dist/http/routes/capabilities.js +12 -3
  200. package/dist/http/routes/devices.js +1 -1
  201. package/dist/http/routes/diagnostics.d.ts +9 -14
  202. package/dist/http/routes/diagnostics.js +10 -20
  203. package/dist/http/routes/engine.d.ts +31 -0
  204. package/dist/http/routes/engine.js +81 -0
  205. package/dist/http/routes/memory-bundle.js +3 -0
  206. package/dist/http/routes/memory-consolidation.js +3 -5
  207. package/dist/http/routes/memory-origin.d.ts +2 -2
  208. package/dist/http/routes/memory-origin.js +2 -4
  209. package/dist/http/routes/memory-policy.js +5 -1
  210. package/dist/http/routes/notify-wake.js +2 -1
  211. package/dist/http/routes/observability.js +3 -6
  212. package/dist/http/routes/projects.d.ts +70 -0
  213. package/dist/http/routes/projects.js +86 -0
  214. package/dist/http/routes/rules.js +30 -2
  215. package/dist/http/routes/runs.js +15 -11
  216. package/dist/http/routes/session-sync.js +39 -35
  217. package/dist/http/routes/sessions-list.d.ts +1 -1
  218. package/dist/http/routes/sessions.d.ts +7 -1
  219. package/dist/http/routes/sessions.js +108 -2
  220. package/dist/http/routes/tasks.js +32 -8
  221. package/dist/http/routes/trace-usage.js +1 -1
  222. package/dist/http/run-concurrency-cap.d.ts +86 -0
  223. package/dist/http/run-concurrency-cap.js +54 -0
  224. package/dist/http/server.d.ts +31 -14
  225. package/dist/http/server.js +29 -3
  226. package/dist/http/stored-body-replay.d.ts +12 -7
  227. package/dist/http/stored-body-replay.js +28 -5
  228. package/dist/http/wire-types.d.ts +27 -13
  229. package/dist/index.d.ts +2 -2
  230. package/dist/index.js +1 -1
  231. package/dist/instruction-source-notice.d.ts +1 -1
  232. package/dist/json-body-limit.d.ts +8 -0
  233. package/dist/json-body-limit.js +2 -0
  234. package/dist/leader/diffout.d.ts +1 -1
  235. package/dist/local-data-root.d.ts +2 -2
  236. package/dist/memory-embedder-reembed.d.ts +38 -0
  237. package/dist/memory-embedder-reembed.js +20 -0
  238. package/dist/memory-incident-sink.d.ts +0 -28
  239. package/dist/memory-incident-sink.js +5 -0
  240. package/dist/memory-operator-faces.d.ts +9 -4
  241. package/dist/memory-scope-stores.d.ts +9 -7
  242. package/dist/memory-scope-stores.js +3 -14
  243. package/dist/memory-scope.d.ts +38 -2
  244. package/dist/memory-scope.js +33 -2
  245. package/dist/memory-store-refusal.d.ts +17 -4
  246. package/dist/memory-store-refusal.js +1 -1
  247. package/dist/memory-sync-client.d.ts +2 -0
  248. package/dist/memory-sync-client.js +13 -11
  249. package/dist/memory-sync.js +1 -1
  250. package/dist/model-compat.d.ts +35 -21
  251. package/dist/model-compat.js +49 -21
  252. package/dist/model-entry-refusal.d.ts +11 -1
  253. package/dist/model-entry-refusal.js +7 -0
  254. package/dist/namespaced-rule-name.d.ts +18 -1
  255. package/dist/namespaced-rule-name.js +12 -0
  256. package/dist/net-address.d.ts +53 -0
  257. package/dist/net-address.js +111 -0
  258. package/dist/observability/fail-open.d.ts +29 -17
  259. package/dist/observability/fail-open.js +29 -17
  260. package/dist/observability/metrics.d.ts +2 -0
  261. package/dist/observability/metrics.js +2 -0
  262. package/dist/observability/secret-env-scrub.d.ts +30 -4
  263. package/dist/observability/secret-env-scrub.js +15 -3
  264. package/dist/orchestration/workflow-agent-session-index.d.ts +7 -12
  265. package/dist/orchestration/workflow-agent-session-index.js +1 -6
  266. package/dist/orchestration/workflow-completion-inbox.d.ts +26 -6
  267. package/dist/orchestration/workflow-completion-inbox.js +63 -45
  268. package/dist/orchestration/workflow-notify-journal.js +2 -3
  269. package/dist/org-delivery-gate.js +1 -1
  270. package/dist/org-memory-admission.d.ts +5 -2
  271. package/dist/org-memory-admission.js +25 -10
  272. package/dist/parked-decide.d.ts +33 -26
  273. package/dist/parked-decide.js +36 -44
  274. package/dist/peer-directory.d.ts +6 -12
  275. package/dist/peer-directory.js +5 -1
  276. package/dist/plugins/approval-ask-store-file.d.ts +10 -2
  277. package/dist/plugins/approval-ask-store-file.js +37 -4
  278. package/dist/plugins/approval-ask-store-memory.d.ts +5 -3
  279. package/dist/plugins/approval-ask-store-memory.js +11 -2
  280. package/dist/plugins/approval-ask-store-sql.d.ts +3 -0
  281. package/dist/plugins/approval-ask-store-sql.js +3 -1
  282. package/dist/plugins/blob-backend.d.ts +38 -195
  283. package/dist/plugins/blob-backend.js +33 -229
  284. package/dist/plugins/caching-session-store.d.ts +12 -5
  285. package/dist/plugins/caching-session-store.js +3 -0
  286. package/dist/plugins/checkpoint-index-columns.d.ts +1 -1
  287. package/dist/plugins/checkpoint-index-columns.js +3 -2
  288. package/dist/plugins/checkpoint-store-face.d.ts +426 -0
  289. package/dist/plugins/checkpoint-store-face.js +152 -0
  290. package/dist/plugins/device-store-sql.d.ts +2 -2
  291. package/dist/plugins/device-store-sql.js +5 -10
  292. package/dist/plugins/execution-lane-rename-m40.d.ts +20 -0
  293. package/dist/plugins/execution-lane-rename-m40.js +10 -0
  294. package/dist/plugins/execution-placement-sql.d.ts +63 -88
  295. package/dist/plugins/execution-placement-sql.js +94 -54
  296. package/dist/plugins/file-run-store.d.ts +26 -18
  297. package/dist/plugins/file-run-store.js +64 -75
  298. package/dist/plugins/fork-routing-session-store.d.ts +6 -2
  299. package/dist/plugins/fork-routing-session-store.js +2 -2
  300. package/dist/plugins/imported-layer-root-retirement.d.ts +22 -11
  301. package/dist/plugins/imported-layer-root-retirement.js +4 -8
  302. package/dist/plugins/inbox-payload-column.d.ts +14 -0
  303. package/dist/plugins/inbox-payload-column.js +13 -0
  304. package/dist/plugins/local-checkpoint-store.d.ts +7 -2
  305. package/dist/plugins/local-checkpoint-store.js +13 -8
  306. package/dist/plugins/local-data-dir-modes-m39.d.ts +48 -0
  307. package/dist/plugins/local-data-dir-modes-m39.js +182 -0
  308. package/dist/plugins/local-engine-high-water.d.ts +11 -0
  309. package/dist/plugins/local-engine-high-water.js +59 -0
  310. package/dist/plugins/local-session-store.d.ts +119 -30
  311. package/dist/plugins/local-session-store.js +156 -53
  312. package/dist/plugins/local-task-attachment-store.d.ts +2 -0
  313. package/dist/plugins/local-task-attachment-store.js +10 -11
  314. package/dist/plugins/memory-embedder-fingerprint.d.ts +33 -10
  315. package/dist/plugins/memory-embedder-fingerprint.js +52 -12
  316. package/dist/plugins/memory-embedder.d.ts +1 -1
  317. package/dist/plugins/memory-embedder.js +2 -2
  318. package/dist/plugins/memory-engine-pg.d.ts +30 -6
  319. package/dist/plugins/memory-engine-pg.js +96 -214
  320. package/dist/plugins/memory-engine-sql-apply.d.ts +130 -0
  321. package/dist/plugins/memory-engine-sql-apply.js +358 -0
  322. package/dist/plugins/memory-engine-tidb.d.ts +38 -9
  323. package/dist/plugins/memory-engine-tidb.js +99 -230
  324. package/dist/plugins/memory-key-guards.d.ts +1 -1
  325. package/dist/plugins/memory-origin-law.d.ts +3 -3
  326. package/dist/plugins/one-time-migrations.d.ts +169 -83
  327. package/dist/plugins/one-time-migrations.js +295 -235
  328. package/dist/plugins/owner-only-file-mode.d.ts +29 -0
  329. package/dist/plugins/owner-only-file-mode.js +141 -0
  330. package/dist/plugins/permission-rule-store-file.d.ts +17 -3
  331. package/dist/plugins/permission-rule-store-file.js +20 -1
  332. package/dist/plugins/pg-pool.d.ts +2 -1
  333. package/dist/plugins/pg-pool.js +12 -5
  334. package/dist/plugins/release-version.d.ts +20 -0
  335. package/dist/plugins/release-version.js +28 -0
  336. package/dist/plugins/remote-env-adb.d.ts +20 -4
  337. package/dist/plugins/remote-env-adb.js +39 -11
  338. package/dist/plugins/remote-env-e2b.d.ts +12 -3
  339. package/dist/plugins/remote-env-e2b.js +6 -4
  340. package/dist/plugins/remote-env-host.d.ts +9 -1
  341. package/dist/plugins/remote-env-host.js +6 -5
  342. package/dist/plugins/remote-env-k8s.d.ts +5 -2
  343. package/dist/plugins/remote-env-k8s.js +15 -4
  344. package/dist/plugins/remote-env-local-docker.d.ts +4 -1
  345. package/dist/plugins/remote-env-local-docker.js +3 -3
  346. package/dist/plugins/remote-env-ssh.d.ts +8 -2
  347. package/dist/plugins/remote-env-ssh.js +26 -24
  348. package/dist/plugins/remote-shell.d.ts +59 -30
  349. package/dist/plugins/remote-shell.js +175 -62
  350. package/dist/plugins/retention-declaration.d.ts +37 -0
  351. package/dist/plugins/retention-declaration.js +9 -0
  352. package/dist/plugins/retention-deployment.d.ts +126 -0
  353. package/dist/plugins/retention-deployment.js +88 -0
  354. package/dist/plugins/retention-lane-store-sql.d.ts +74 -4
  355. package/dist/plugins/retention-lane-store-sql.js +103 -1
  356. package/dist/plugins/retention-sql.d.ts +29 -0
  357. package/dist/plugins/retention-sql.js +8 -0
  358. package/dist/plugins/run-store-sql.js +2 -2
  359. package/dist/plugins/schema-consistency.d.ts +0 -6
  360. package/dist/plugins/schema-consistency.js +1 -2
  361. package/dist/plugins/schema-ensure-legs.d.ts +1 -1
  362. package/dist/plugins/schema-ensure-legs.js +13 -3
  363. package/dist/plugins/session-ext-table.d.ts +74 -0
  364. package/dist/plugins/session-ext-table.js +121 -0
  365. package/dist/plugins/session-fork.d.ts +31 -9
  366. package/dist/plugins/session-fork.js +3 -2
  367. package/dist/plugins/session-placement.d.ts +4 -2
  368. package/dist/plugins/session-row-sql.d.ts +8 -7
  369. package/dist/plugins/session-row-sql.js +15 -7
  370. package/dist/plugins/session-store-sql.d.ts +131 -0
  371. package/dist/plugins/session-store-sql.js +298 -0
  372. package/dist/plugins/session-workspace-cell.d.ts +2 -2
  373. package/dist/plugins/session-workspace-cell.js +2 -2
  374. package/dist/plugins/shared-memory-store-sql.d.ts +10 -0
  375. package/dist/plugins/shared-memory-store-sql.js +13 -13
  376. package/dist/plugins/snapshot-bucket-presence.js +1 -1
  377. package/dist/plugins/sql-driver.d.ts +23 -7
  378. package/dist/plugins/sql-driver.js +41 -8
  379. package/dist/plugins/sql-errors.d.ts +5 -2
  380. package/dist/plugins/sql-errors.js +4 -0
  381. package/dist/plugins/sql-json-column.d.ts +5 -1
  382. package/dist/plugins/store-backend.d.ts +46 -16
  383. package/dist/plugins/store-backend.js +192 -69
  384. package/dist/plugins/store-contracts.d.ts +10 -13
  385. package/dist/plugins/store-contracts.js +1 -9
  386. package/dist/plugins/store-sweep.d.ts +63 -0
  387. package/dist/plugins/store-sweep.js +48 -0
  388. package/dist/plugins/task-attachment-store.d.ts +6 -8
  389. package/dist/plugins/task-attachment-store.js +15 -10
  390. package/dist/plugins/task-list-store-sql.d.ts +1 -1
  391. package/dist/plugins/text-column-capacity.d.ts +21 -0
  392. package/dist/plugins/text-column-capacity.js +5 -0
  393. package/dist/plugins/tidb-pool.d.ts +3 -2
  394. package/dist/plugins/tidb-pool.js +20 -32
  395. package/dist/plugins/user-input-ledger-sql.d.ts +1 -1
  396. package/dist/prompt-screen.d.ts +6 -9
  397. package/dist/prompt-screen.js +2 -5
  398. package/dist/read-face-posture.d.ts +6 -6
  399. package/dist/read-face-posture.js +2 -2
  400. package/dist/request-value-closure.d.ts +5 -5
  401. package/dist/request-value-closure.js +1 -1
  402. package/dist/rules-consent.d.ts +48 -27
  403. package/dist/rules-consent.js +147 -23
  404. package/dist/run-cancel-context.d.ts +4 -1
  405. package/dist/run-cancel-context.js +2 -1
  406. package/dist/run-local.js +17 -13
  407. package/dist/runs.d.ts +48 -30
  408. package/dist/runs.js +27 -17
  409. package/dist/runtime-caps-resolver.d.ts +15 -8
  410. package/dist/runtime-caps-resolver.js +14 -10
  411. package/dist/sandbox-egress-policy.js +6 -11
  412. package/dist/sandbox-rbac-rules.d.ts +88 -0
  413. package/dist/sandbox-rbac-rules.js +80 -0
  414. package/dist/sealed-key-layout.d.ts +16 -0
  415. package/dist/sealed-key-layout.js +3 -0
  416. package/dist/sealed-key.js +8 -6
  417. package/dist/security.d.ts +43 -9
  418. package/dist/security.js +9 -2
  419. package/dist/sema-config-dir.js +2 -2
  420. package/dist/server-secret-env.d.ts +2 -0
  421. package/dist/service-version.d.ts +2 -1
  422. package/dist/service-version.js +2 -2
  423. package/dist/session-error-wire.d.ts +1 -1
  424. package/dist/session-incarnation.d.ts +8 -5
  425. package/dist/session-notify-door.d.ts +5 -3
  426. package/dist/session-resident-background.d.ts +110 -0
  427. package/dist/session-resident-background.js +88 -0
  428. package/dist/session-row.d.ts +1 -1
  429. package/dist/session-sync-kernel.d.ts +53 -14
  430. package/dist/session-sync-kernel.js +70 -1
  431. package/dist/session-sync.d.ts +5 -3
  432. package/dist/session-workspace.d.ts +12 -2
  433. package/dist/session-workspace.js +6 -0
  434. package/dist/sighup-idle.d.ts +9 -7
  435. package/dist/sighup-idle.js +4 -5
  436. package/dist/spec-fields.d.ts +16 -0
  437. package/dist/spec-fields.js +7 -0
  438. package/dist/store-posture.d.ts +2 -1
  439. package/dist/stored-request-env-credentials-m38.d.ts +3 -0
  440. package/dist/stored-request-env-credentials-m38.js +8 -0
  441. package/dist/stored-request-hooks-m20.d.ts +3 -2
  442. package/dist/stored-request-hooks-m20.js +19 -14
  443. package/dist/stored-request-prompt-profile-m30.d.ts +1 -1
  444. package/dist/stores-sql/blob-index-sql.d.ts +148 -0
  445. package/dist/stores-sql/blob-index-sql.js +154 -0
  446. package/dist/{plugins → stores-sql}/checkpoint-store-sql.d.ts +14 -428
  447. package/dist/{plugins → stores-sql}/checkpoint-store-sql.js +43 -220
  448. package/dist/{plugins → stores-sql}/file-history-store-sql.d.ts +23 -11
  449. package/dist/{plugins → stores-sql}/file-history-store-sql.js +23 -18
  450. package/dist/{plugins → stores-sql}/mailbox-store-sql.d.ts +2 -2
  451. package/dist/{plugins → stores-sql}/mailbox-store-sql.js +4 -4
  452. package/dist/{plugins → stores-sql}/pg-session-storage.d.ts +27 -67
  453. package/dist/{plugins → stores-sql}/pg-session-storage.js +82 -207
  454. package/dist/{plugins → stores-sql}/retention-store-sql.d.ts +123 -217
  455. package/dist/{plugins → stores-sql}/retention-store-sql.js +66 -190
  456. package/dist/{plugins → stores-sql}/roster-store-sql.d.ts +2 -2
  457. package/dist/{plugins → stores-sql}/roster-store-sql.js +1 -1
  458. package/dist/{plugins → stores-sql}/session-event-payload.d.ts +1 -1
  459. package/dist/{plugins → stores-sql}/session-event-payload.js +1 -1
  460. package/dist/stores-sql/session-policy-store-sql.d.ts +1 -1
  461. package/dist/stores-sql/session-write-hooks.d.ts +59 -0
  462. package/dist/stores-sql/session-write-hooks.js +2 -0
  463. package/dist/{plugins → stores-sql}/tidb-session-storage.d.ts +10 -11
  464. package/dist/{plugins → stores-sql}/tidb-session-storage.js +10 -21
  465. package/dist/{plugins → stores-sql}/tidb-session-store.d.ts +35 -112
  466. package/dist/{plugins → stores-sql}/tidb-session-store.js +73 -169
  467. package/dist/{plugins → stores-sql}/tool-result-store-sql.d.ts +3 -3
  468. package/dist/{plugins → stores-sql}/tool-result-store-sql.js +6 -6
  469. package/dist/stores-sql/windowed-session-storage.d.ts +56 -0
  470. package/dist/stores-sql/windowed-session-storage.js +61 -0
  471. package/dist/{plugins → stores-sql}/workflow-journal-store-sql.d.ts +7 -12
  472. package/dist/{plugins → stores-sql}/workflow-journal-store-sql.js +3 -8
  473. package/dist/task-a2a.d.ts +7 -1
  474. package/dist/task-a2a.js +15 -14
  475. package/dist/task-cwd.d.ts +11 -3
  476. package/dist/task-cwd.js +17 -1
  477. package/dist/task-mcp.d.ts +10 -2
  478. package/dist/task-mcp.js +13 -16
  479. package/dist/task-settings.d.ts +68 -8
  480. package/dist/task-settings.js +63 -6
  481. package/dist/tool-approval.d.ts +23 -10
  482. package/dist/tool-approval.js +10 -6
  483. package/dist/trace/core-keyset-guard.d.ts +17 -10
  484. package/dist/trace/engine-notice-wire.d.ts +1 -1
  485. package/dist/trace/engine-notice-wire.js +4 -0
  486. package/dist/trace/exit-seat.d.ts +29 -1
  487. package/dist/trace/exit-seat.js +4 -0
  488. package/dist/trace/project.d.ts +33 -16
  489. package/dist/trace/project.js +21 -9
  490. package/dist/trace/redact.d.ts +13 -2
  491. package/dist/trace/redact.js +347 -78
  492. package/dist/trace/self-minted-wire.d.ts +587 -16
  493. package/dist/trace/self-minted-wire.js +215 -9
  494. package/dist/trace/sema-provenance.d.ts +45 -41
  495. package/dist/trace/sema-provenance.js +81 -10
  496. package/dist/trace/task-notification-facets.d.ts +70 -2
  497. package/dist/trace/task-notification-facets.js +71 -1
  498. package/dist/trace/wire-projection-faces.d.ts +39 -3
  499. package/dist/trace/wire-projection-faces.js +27 -2
  500. package/dist/unread-request-members.d.ts +66 -0
  501. package/dist/unread-request-members.js +41 -0
  502. package/dist/usage-analytics.d.ts +4 -0
  503. package/dist/user-input-ledger.d.ts +2 -2
  504. package/dist/web-admin-client/apply-effective.js +22 -26
  505. package/dist/web-admin-client/candidate-gate.d.ts +35 -3
  506. package/dist/web-admin-client/candidate-gate.js +53 -5
  507. package/dist/web-admin-client/center-request.d.ts +4 -1
  508. package/dist/web-admin-client/center-request.js +2 -1
  509. package/dist/web-admin-client/effective-keys.js +0 -1
  510. package/dist/web-admin-client/facade.d.ts +1 -1
  511. package/dist/web-admin-client/http-client.d.ts +1 -0
  512. package/dist/web-admin-client/http-client.js +17 -9
  513. package/dist/web-admin-client/restart-signal.js +5 -2
  514. package/dist/web-admin-client/skills-mcp.d.ts +20 -6
  515. package/dist/web-admin-client/skills-mcp.js +26 -21
  516. package/dist/web-admin-client/types.d.ts +34 -49
  517. package/docs/DEVICE-EXECUTOR-PROTOCOL.md +2 -2
  518. package/package.json +22 -13
  519. package/scripts/drain-check-local.mjs +8 -55
  520. package/scripts/drain-check.mysql.sql +3 -40
  521. package/scripts/drain-check.pg.sql +3 -40
  522. package/skills/update-config.md +1 -1
  523. package/wire-changes/server@7.146.0.json +3221 -0
  524. package/wire-changes/server@7.147.0.json +813 -0
  525. package/dist/approval-batch-census.d.ts +0 -27
  526. package/dist/approval-batch-census.js +0 -27
@@ -1,23 +1,18 @@
1
1
  import { parkedApprovalCard } from "../approval-content-kind.js";
2
2
  import { createHash } from "node:crypto";
3
- import { CHECKPOINT_FACET_SQL, CHECKPOINT_SWEEP_ORDER_SQL, CheckpointIndexRefusedError, judgeCheckpointIndexCells } from "./checkpoint-index-columns.js";
4
- import { CheckpointError, isGateKind, MAX_RULE_TEXT_CHARS, validatePendingSteer, appendPendingSteer, winnerFromOutcome, summarizeCheckpoint, checkpointRevOf, judgeCheckpointRow, CONTRACT_KIT_ENGINE_VERSION, ExecutionOutcomeConflictError, executionRecordDisposition, executionVerdict, } from "@sema-agent/core";
5
- import { redactDeep, redactSecrets } from "../trace/redact.js";
6
- import { MAX_RULE_OFFERS, MAX_RULE_OFFER_BATCH_MEMBERS, countKindlessBatchOffers, parkRowFacts, readRuleOfferList, skillCardFacts } from "../approval-card.js";
7
- import { assertJsonColumnWritable, createObjectColumnReader, decodeJsonColumn, decodeNullableJsonColumn, foldJsonColumn, isJsonColumnBodyProblem, jsonColumnText, jsonColumnTextExpr, jsonColumnTextSha256, readJsonArrayColumn, readJsonColumnTextSha256, readJsonObjectColumn, readNonNullJsonValueColumn, } from "./sql-json-column.js";
3
+ import { CHECKPOINT_FACET_SQL, CHECKPOINT_SWEEP_ORDER_SQL, CheckpointIndexRefusedError, judgeCheckpointIndexCells } from "../plugins/checkpoint-index-columns.js";
4
+ import { CheckpointError, validatePendingSteer, appendPendingSteer, winnerFromOutcome, summarizeCheckpoint, checkpointRevOf, judgeCheckpointRow, CONTRACT_KIT_ENGINE_VERSION, ExecutionOutcomeConflictError, executionRecordDisposition, executionVerdict, } from "@sema-agent/core";
5
+ import { parkRowFacts, skillCardFacts } from "../approval-card.js";
6
+ import { assertJsonColumnWritable, createObjectColumnReader, decodeJsonColumn, decodeNullableJsonColumn, foldJsonColumn, isJsonColumnBodyProblem, jsonColumnText, jsonColumnTextSha256, readJsonArrayColumn, readJsonColumnTextSha256, readNonNullJsonValueColumn, StoreCorruptError, } from "../plugins/sql-json-column.js";
8
7
  import { recordFailOpen } from "../observability/fail-open.js";
9
8
  import { durableRowIdentity, withoutCheckpointToken } from "../checkpoint-identity.js";
10
- import { mysqlDriver, pgDriver, dialectProtocolJsonEncoder } from "./sql-driver.js";
11
- import { isDupKeyError, isMissingColumnError, rowTooLargeOrSelf, StoreRowTooLargeError } from "./sql-errors.js";
12
- import { describeProbedTableDrift } from "./schema-drift-sentence.js";
13
- import { MANAGED_RETENTION, UNMANAGED_RETENTION } from "./retention-store-sql.js";
14
- import { approvalPayloadFingerprint } from "./approval-payload-fingerprint.js";
9
+ import { mysqlDriver, pgDriver, dialectProtocolJsonEncoder } from "../plugins/sql-driver.js";
10
+ import { isDupKeyError, isMissingColumnError, rowTooLargeOrSelf, StoreRowTooLargeError } from "../plugins/sql-errors.js";
11
+ import { describeProbedTableDrift } from "../plugins/schema-drift-sentence.js";
12
+ import { MANAGED_RETENTION, UNMANAGED_RETENTION } from "../plugins/retention-declaration.js";
13
+ import { approvalPayloadFingerprint } from "../plugins/approval-payload-fingerprint.js";
14
+ import { approvalDecisionOfWinner, boundedRuleOffers, boundedToolInput, candidateIdentityOf, DECIDED_REPLAY_SCAN_CAP, queueRowGateKind, TERMINAL_BACKSTOP_MS, TERMINAL_GRACE_MS, UnreadableCheckpointRowError, } from "../plugins/checkpoint-store-face.js";
15
15
  const CTX_REWRITE_PAGE = 500;
16
- const KINDLESS_SCAN_PAGE = 200;
17
- export { approvalPayloadFingerprint } from "./approval-payload-fingerprint.js";
18
- const MAX_TOOL_INPUT_CHARS = 8192;
19
- export const TERMINAL_BACKSTOP_MS = Math.max(60_000, (Number.isFinite(Number(process.env.APPROVAL_TERMINAL_BACKSTOP_MS)) ? Number(process.env.APPROVAL_TERMINAL_BACKSTOP_MS) : 0) || 30 * 86_400_000);
20
- export const TERMINAL_GRACE_MS = 3_600_000;
21
16
  export function tokenFingerprint(token) {
22
17
  return "sha256:" + createHash("sha256").update(token).digest("hex").slice(0, 12);
23
18
  }
@@ -50,21 +45,6 @@ class StoredRowProjectionMemo {
50
45
  }
51
46
  const STORED_ROW_READ_BATCH = 100;
52
47
  const CHECKPOINT_SHA256_AS = "checkpoint_sha256";
53
- const GATE_KIND_IS_LIVE_RUN_PARK = {
54
- human: true,
55
- irreversible_ask: true,
56
- resource_limit: true,
57
- needs_review: true,
58
- plan_review: true,
59
- task_done: false,
60
- };
61
- export const LIVE_RUN_GATE_KINDS = Object.keys(GATE_KIND_IS_LIVE_RUN_PARK).filter((k) => GATE_KIND_IS_LIVE_RUN_PARK[k]);
62
- export const TERMINAL_PARK_GATE_KINDS = Object.keys(GATE_KIND_IS_LIVE_RUN_PARK).filter((k) => !GATE_KIND_IS_LIVE_RUN_PARK[k]);
63
- export function pendingRowPrecedes(a, b, pick) {
64
- if (pick === "oldest")
65
- return a.createdAt < b.createdAt || (a.createdAt === b.createdAt && a.token < b.token);
66
- return a.createdAt > b.createdAt || (a.createdAt === b.createdAt && a.token > b.token);
67
- }
68
48
  export const CHECKPOINT_ADDED_COLUMNS = [
69
49
  {
70
50
  column: "has_bidi_controls",
@@ -99,53 +79,6 @@ export async function assertCheckpointColumnSchema(query, dialect) {
99
79
  }
100
80
  }
101
81
  }
102
- const MAX_RULE_OFFER_SCAN = 32;
103
- function preboundBatchMembers(item) {
104
- if (typeof item !== "object" || item === null)
105
- return item;
106
- const candidate = item;
107
- if (candidate.kind !== "batch" || !Array.isArray(candidate.rules) || candidate.rules.length <= MAX_RULE_OFFER_BATCH_MEMBERS)
108
- return item;
109
- return { ...candidate, rules: candidate.rules.slice(0, MAX_RULE_OFFER_BATCH_MEMBERS) };
110
- }
111
- export function boundedReaderInput(raw) {
112
- return Array.isArray(raw) ? raw.slice(0, MAX_RULE_OFFER_SCAN).map(preboundBatchMembers) : raw;
113
- }
114
- export function boundedRuleOffers(raw, opts = {}) {
115
- const observe = opts.countRedactions ?? true;
116
- const scrub = (text) => redactSecrets(text, { observe }).slice(0, MAX_RULE_TEXT_CHARS);
117
- const read = readRuleOfferList(boundedReaderInput(raw));
118
- const out = [];
119
- for (const { offer } of read) {
120
- if (out.length >= MAX_RULE_OFFERS)
121
- break;
122
- switch (offer.kind) {
123
- case "single":
124
- out.push({ kind: "single", rule: scrub(offer.rule), match: offer.match, command: scrub(offer.command) });
125
- break;
126
- case "batch":
127
- out.push({
128
- kind: "batch",
129
- rules: offer.rules.slice(0, MAX_RULE_OFFER_BATCH_MEMBERS).map((r) => {
130
- switch (r.kind) {
131
- case "command":
132
- return { kind: "command", rule: scrub(r.rule), match: r.match, command: scrub(r.command), segment: scrub(r.segment) };
133
- case "directoryRead":
134
- return { kind: "directoryRead", rule: scrub(r.rule), directory: scrub(r.directory), segment: scrub(r.segment) };
135
- default:
136
- throw new Error(`unknown rule-offer batch member kind: ${JSON.stringify(r)}`);
137
- }
138
- }),
139
- uncoveredSegments: offer.uncoveredSegments,
140
- ...(offer.uncoveredDetail !== undefined ? { uncoveredDetail: offer.uncoveredDetail.map((d) => ({ segment: scrub(d.segment), reason: d.reason })) } : {}),
141
- });
142
- break;
143
- default:
144
- throw new Error(`unknown rule-offer kind: ${JSON.stringify(offer)}`);
145
- }
146
- }
147
- return out.length > 0 ? out : undefined;
148
- }
149
82
  const readCheckpointBlobBody = createObjectColumnReader();
150
83
  const readResumeOutcomeBody = createObjectColumnReader();
151
84
  const readGateOutcomeBody = createObjectColumnReader();
@@ -156,6 +89,19 @@ function decodeCheckpointColumn(cell, where) {
156
89
  function verdictOfUnreadableBody(cell) {
157
90
  return judgeCheckpointRow(cell);
158
91
  }
92
+ const UNREADABLE_SUMMARY_MEMBERS = new Set(["token", "rowVerdict", "sessionId", "scope", "gateKind", "createdAt", "deadline"]);
93
+ function isUnreadableSummaryForm(summary) {
94
+ const names = UNREADABLE_SUMMARY_MEMBERS;
95
+ return summary.rowVerdict.kind !== "ok" && Object.keys(summary).every((member) => names.has(member));
96
+ }
97
+ function readCheckpointBodyOrRefuse(cell, where) {
98
+ try {
99
+ return refusing("a checkpoint nobody can resume", () => decodeCheckpointColumn(cell, where));
100
+ }
101
+ catch (e) {
102
+ throw e instanceof StoreCorruptError ? new UnreadableCheckpointRowError(e, verdictOfUnreadableBody(cell)) : e;
103
+ }
104
+ }
159
105
  function decodeOutcomeColumn(cell, where) {
160
106
  return decodeNullableJsonColumn(cell, readResumeOutcomeBody, `checkpoint.outcome ${where}`);
161
107
  }
@@ -228,80 +174,7 @@ function readCheckpointIdCell(cell) {
228
174
  return null;
229
175
  }
230
176
  }
231
- export function queueRowGateKind(kind) {
232
- if (isGateKind(kind))
233
- return kind;
234
- recordFailOpen("server.approvals.queue-row-gate-kind-missing", `gate_kind=${kind === null || kind === undefined ? "NULL" : redactSecrets(String(kind)).slice(0, 40)}`);
235
- return undefined;
236
- }
237
177
  const readPendingActionMemberBody = createObjectColumnReader();
238
- export function boundedToolInput(args) {
239
- if (args === undefined)
240
- return null;
241
- const redacted = redactDeep(args);
242
- const json = JSON.stringify(redacted);
243
- if (json === undefined)
244
- return null;
245
- if (json.length > MAX_TOOL_INPUT_CHARS)
246
- return { truncated: true, bytes: json.length };
247
- return redacted;
248
- }
249
- export const DECIDED_REPLAY_SCAN_CAP = 8;
250
- export function approvalDecisionOfWinner(winner, boundCallId) {
251
- if (winner === undefined)
252
- return null;
253
- if (winner.boundCallId !== boundCallId)
254
- return null;
255
- switch (winner.decision) {
256
- case "allow":
257
- return "approve";
258
- case "deny":
259
- return "deny";
260
- case "approve":
261
- case "reject":
262
- case "edit":
263
- return null;
264
- default: {
265
- const unhandled = winner.decision;
266
- void unhandled;
267
- return null;
268
- }
269
- }
270
- }
271
- function pendingActionToolCallId(body) {
272
- if (typeof body !== "object" || body === null)
273
- return { readable: false };
274
- if ("sourceTaskId" in body)
275
- return { readable: false };
276
- const rawSource = "sourceSessionId" in body ? body.sourceSessionId : null;
277
- if (rawSource !== null && rawSource !== undefined && typeof rawSource !== "string")
278
- return { readable: false };
279
- const sourceSessionId = typeof rawSource === "string" ? rawSource : null;
280
- if (!("pendingAction" in body))
281
- return { readable: true, toolCallId: null, boundInputHash: null, kind: null, sourceSessionId };
282
- const pa = body.pendingAction;
283
- if (typeof pa !== "object" || pa === null)
284
- return { readable: false };
285
- const kind = "kind" in pa ? pa.kind : null;
286
- if (kind !== null && typeof kind !== "string")
287
- return { readable: false };
288
- if (!("toolCallId" in pa))
289
- return { readable: true, toolCallId: null, boundInputHash: null, kind, sourceSessionId };
290
- const id = pa.toolCallId;
291
- if (typeof id !== "string")
292
- return { readable: false };
293
- if (kind !== "tool_approval")
294
- return { readable: false };
295
- const bih = "boundInputHash" in pa ? pa.boundInputHash : null;
296
- if (bih !== null && typeof bih !== "string")
297
- return { readable: false };
298
- return { readable: true, toolCallId: id, boundInputHash: bih, kind, sourceSessionId };
299
- }
300
- export function candidateIdentityOf(cp) {
301
- if (judgeCheckpointRow(cp).kind === "lacking")
302
- return { readable: false };
303
- return pendingActionToolCallId(cp);
304
- }
305
178
  function candidateIdentityOfColumn(cell, where) {
306
179
  let cp;
307
180
  try {
@@ -314,39 +187,23 @@ function candidateIdentityOfColumn(cell, where) {
314
187
  }
315
188
  return candidateIdentityOf(cp);
316
189
  }
317
- function readActorAssertion(v) {
318
- if (typeof v !== "object" || v === null)
319
- return undefined;
320
- const id = "id" in v ? v.id : undefined;
321
- const hostAsserted = "hostAsserted" in v ? v.hostAsserted : undefined;
322
- if (typeof id !== "string" || typeof hostAsserted !== "boolean")
323
- return undefined;
324
- const issuer = "issuer" in v ? v.issuer : undefined;
325
- return { id, hostAsserted, ...(typeof issuer === "string" ? { issuer } : {}) };
326
- }
327
190
  function readQueueEntry(v) {
328
191
  if (typeof v !== "object" || v === null)
329
192
  return undefined;
330
- const text = "text" in v ? v.text : undefined;
331
- const trusted = "trusted" in v ? v.trusted : undefined;
332
193
  const seq = "seq" in v ? v.seq : undefined;
333
- const inputId = "inputId" in v ? v.inputId : undefined;
334
- if (typeof text !== "string" || typeof trusted !== "boolean")
335
- return undefined;
336
194
  if (typeof seq !== "number" || !Number.isFinite(seq))
337
195
  return undefined;
338
- if (typeof inputId !== "string" || inputId === "")
196
+ if (!("inputId" in v) || v.inputId === undefined)
339
197
  return undefined;
340
- const priority = "priority" in v ? v.priority : undefined;
341
- const actor = readActorAssertion("actor" in v ? v.actor : undefined);
342
- return {
343
- text,
344
- trusted,
345
- seq,
346
- inputId,
347
- ...(actor !== undefined ? { actor } : {}),
348
- ...(priority === "now" || priority === "next" || priority === "later" ? { priority } : {}),
349
- };
198
+ const carried = Object.fromEntries(Object.entries(v).filter(([key]) => key !== "seq"));
199
+ try {
200
+ return { ...validatePendingSteer(carried), seq };
201
+ }
202
+ catch (e) {
203
+ if (e instanceof CheckpointError && e.code === "steering.invalid_content")
204
+ return undefined;
205
+ throw e;
206
+ }
350
207
  }
351
208
  export function readPendingSteerQueueColumn(queueRaw) {
352
209
  let lossy = false;
@@ -374,7 +231,6 @@ export function readPendingSteerQueueColumn(queueRaw) {
374
231
  }
375
232
  const STEER_CAS_ATTEMPTS = 8;
376
233
  const EXECUTION_RECORD_CAS_ATTEMPTS = 8;
377
- export const CTX_CLAIM_REWRITES = ["written", "claim_released", "context_absent"];
378
234
  export class SqlCheckpointStore {
379
235
  db;
380
236
  logger;
@@ -477,7 +333,7 @@ export class SqlCheckpointStore {
477
333
  const r = rows[0];
478
334
  if (!r)
479
335
  return null;
480
- const cp = refusing("a checkpoint nobody can resume", () => decodeCheckpointColumn(r.checkpoint, `for token ${tokenFingerprint(token)}`));
336
+ const cp = readCheckpointBodyOrRefuse(r.checkpoint, `for token ${tokenFingerprint(token)}`);
481
337
  cp.status = r.status;
482
338
  const outcomeRaw = refusing("a decision record nobody can read", () => decodeOutcomeColumn(r.outcome, `for token ${tokenFingerprint(token)}`));
483
339
  if (outcomeRaw)
@@ -679,13 +535,21 @@ export class SqlCheckpointStore {
679
535
  return { rowVerdict: verdictOfUnreadableBody(r.checkpoint) };
680
536
  }
681
537
  let summary;
538
+ const disclosed = [];
682
539
  try {
683
- summary = summarizeCheckpoint(cp, discloseFor?.(cp), memo?.rowVerdict);
540
+ summary = summarizeCheckpoint(cp, (sentence) => disclosed.push(sentence), memo?.rowVerdict);
684
541
  }
685
542
  catch {
686
543
  recordFailOpen("server.approvals.park-row-blob-unreadable");
687
544
  return { rowVerdict: judgeCheckpointRow(cp) };
688
545
  }
546
+ if (isUnreadableSummaryForm(summary)) {
547
+ recordFailOpen("server.approvals.park-row-blob-unreadable");
548
+ return { rowVerdict: summary.rowVerdict };
549
+ }
550
+ const seat = discloseFor?.(cp);
551
+ for (const sentence of disclosed)
552
+ seat?.(sentence);
689
553
  if (memo === undefined)
690
554
  this.storedRowMemo.set(sha256, { rowVerdict: summary.rowVerdict, skillCardFacts: skillCardFacts(summary) });
691
555
  return { rowVerdict: summary.rowVerdict, summary };
@@ -894,47 +758,6 @@ export class SqlCheckpointStore {
894
758
  }
895
759
  return out;
896
760
  }
897
- async scanKindlessBatchRows() {
898
- const out = [];
899
- let unreadableCells = 0;
900
- const tolerant = (read) => {
901
- try {
902
- return read();
903
- }
904
- catch (e) {
905
- if (!isJsonColumnBodyProblem(e))
906
- throw e;
907
- unreadableCells += 1;
908
- return undefined;
909
- }
910
- };
911
- const prefilter = (d) => `(rule_suggestions IS NOT NULL OR ${jsonColumnTextExpr(d, "checkpoint", PARK_ROW_PENDING_ACTION.key)} LIKE '%"batch"%')`;
912
- let after = "";
913
- for (;;) {
914
- const { rows } = await this.db.query(this.q(`SELECT token, ${jsonColumnText("mysql", "rule_suggestions")}, ${jsonColumnText("mysql", "checkpoint", PARK_ROW_PENDING_ACTION)} FROM checkpoint WHERE token > ? AND ${prefilter("mysql")} ORDER BY token LIMIT ${KINDLESS_SCAN_PAGE}`, `SELECT token, ${jsonColumnText("pg", "rule_suggestions")}, ${jsonColumnText("pg", "checkpoint", PARK_ROW_PENDING_ACTION)} FROM checkpoint WHERE token > $1 AND ${prefilter("pg")} ORDER BY token LIMIT ${KINDLESS_SCAN_PAGE}`), [after]);
915
- for (const row of rows) {
916
- const token = String(row.token);
917
- after = token;
918
- const carriers = [];
919
- const column = tolerant(() => decodeNullableJsonColumn(row.rule_suggestions, readJsonArrayColumn, "checkpoint.rule_suggestions (kind-less batch census)"));
920
- if (countKindlessBatchOffers(boundedReaderInput(column)) > 0)
921
- carriers.push("rule_suggestions");
922
- const pendingAction = tolerant(() => decodeNullableJsonColumn(row[PARK_ROW_PENDING_ACTION.as], readJsonObjectColumn, "checkpoint.checkpoint pendingAction member (kind-less batch census)"));
923
- if (typeof pendingAction === "object" && pendingAction !== null) {
924
- const blobOffers = Reflect.get(pendingAction, "ruleOffers");
925
- if (blobOffers !== undefined && !Array.isArray(blobOffers))
926
- unreadableCells += 1;
927
- else if (countKindlessBatchOffers(blobOffers) > 0)
928
- carriers.push("pendingAction.ruleOffers");
929
- }
930
- if (carriers.length > 0)
931
- out.push({ ref: tokenFingerprint(token), carriers });
932
- }
933
- if (rows.length < KINDLESS_SCAN_PAGE)
934
- break;
935
- }
936
- return { rows: out, unreadableCells };
937
- }
938
761
  async reapCtx(cutoff) {
939
762
  const res = await this.db.query(this.q("DELETE FROM checkpoint_ctx WHERE updated_at_ms < ? " +
940
763
  "AND session_id NOT IN (SELECT session_id FROM checkpoint WHERE status='pending') " +
@@ -1,10 +1,11 @@
1
1
  import type { Pool as MySqlPool } from "mysql2/promise";
2
2
  import type { Pool as PgPool } from "pg";
3
3
  import { type FileHistoryRetentionPolicy, type ExecutionEnv, type FileHistoryStore, type FileHistoryResult, type FileHistoryTrackResult, type FileHistoryRestoreResult, type FileHistoryExport, type FileHistoryExportResult } from "@sema-agent/core";
4
- import { type BlobBackend } from "./blob-backend.js";
5
- import type { ServiceBlobExchange } from "./store-backend.js";
6
- import { type SqlDriver, type SqlDialect } from "./sql-driver.js";
7
- /** The file-history blob domain's SQL table (BlobBackend `table`/MinIO index binding + the A7 assert). */
4
+ import type { BlobBackend } from "../plugins/blob-backend.js";
5
+ import { SqlBlobIndex } from "./blob-index-sql.js";
6
+ import type { ServiceBlobExchange } from "../plugins/store-backend.js";
7
+ import { type SqlDriver, type SqlDialect } from "../plugins/sql-driver.js";
8
+ /** The file-history blob domain's SQL table (this store's blob index + the A7 assert). */
8
9
  export declare const FILE_HISTORY_BLOB_TABLE = "file_history_blob";
9
10
  /** MinIO object-key prefix for this domain (snapshot epoch used "blobs/"; a separate prefix keeps the
10
11
  * two domains' objects disjoint so neither sweep can see the other's keys). */
@@ -17,18 +18,29 @@ export declare const FILE_HISTORY_BLOB_KEY_PREFIX = "file-history/";
17
18
  */
18
19
  export interface SqlFileHistoryStoreOptions {
19
20
  retention?: FileHistoryRetentionPolicy;
21
+ /** Where the blob bytes go — the shape of the engine package's `fileHistory.blobs`: absent ⇒ in this store's own
22
+ * `file_history_blob` rows (SQL, capped per blob); a byte port ⇒ the port holds them and the rows keep bytes NULL. */
23
+ blobs?: BlobBackend;
24
+ /** The operator's explicit per-blob cap for SQL-kept bytes (`SNAPSHOT_BLOB_SQL_MAX_BYTES`); absent ⇒ derived from the walls of
25
+ * the connection that writes. Not read with a byte port. */
26
+ blobSqlMaxBytes?: number;
27
+ /** Where a stale connection's replacement on an SQL-kept blob write is logged. */
28
+ log?: {
29
+ warn(msg: string, meta?: Record<string, unknown>): void;
30
+ };
20
31
  }
21
32
  /** Dual-dialect durable FileHistoryStore. See the file header for posture + dialect-delta ledger. */
22
33
  export declare class SqlFileHistoryStore implements FileHistoryStore {
23
34
  protected readonly db: SqlDriver;
24
- /** RAW native pool — handed to blob-backend.ts (outside the SqlDriver seam, dialect-switches on
35
+ /** RAW native pool — handed to the blob index (`blob-index-sql.ts`, outside the SqlDriver seam, dialect-switches on
25
36
  * its own string). Not used for this class's own statements (those go through `db`). */
26
37
  protected readonly pool: MySqlPool | PgPool;
27
38
  /** The blob exchange (core's `FileHistoryStore.blobExchange` group, see {@link ServiceBlobExchange}): how another machine's bytes
28
39
  * come in ahead of an `importHistory`, go out to a puller, and are asked about. Its presence IS the capability — read through
29
40
  * `blobExchangeOf` (`session-sync.ts`), which defers to core's judge; there is no second word for it on this class. */
30
41
  readonly blobExchange: ServiceBlobExchange;
31
- protected readonly blobs: BlobBackend;
42
+ /** This store's blob index (the `file_history_blob` rows; the byte port, when given, behind it). */
43
+ protected readonly blobs: SqlBlobIndex;
32
44
  /** §10 S-6 in-process lease state (design v1 D2: NOT persisted). Keys = `${scope}\x00${entryId}`. */
33
45
  private readonly spentAttempts;
34
46
  private readonly activeAttempts;
@@ -36,9 +48,9 @@ export declare class SqlFileHistoryStore implements FileHistoryStore {
36
48
  * 由 core 的 `resolveFileHistoryRetention` 在构造期裁定 —— 与两只内置后端同一道门、同一句拒绝。 */
37
49
  private readonly boundaryKeep;
38
50
  constructor(db: SqlDriver,
39
- /** RAW native pool — handed to blob-backend.ts (outside the SqlDriver seam, dialect-switches on
51
+ /** RAW native pool — handed to the blob index (`blob-index-sql.ts`, outside the SqlDriver seam, dialect-switches on
40
52
  * its own string). Not used for this class's own statements (those go through `db`). */
41
- pool: MySqlPool | PgPool, blobBackend?: BlobBackend, opts?: SqlFileHistoryStoreOptions);
53
+ pool: MySqlPool | PgPool, opts?: SqlFileHistoryStoreOptions);
42
54
  /** Pick the dialect's SQL text. Both statements stay written out at the call site ON PURPOSE. */
43
55
  private q;
44
56
  private bool;
@@ -174,18 +186,18 @@ export declare class SqlFileHistoryStore implements FileHistoryStore {
174
186
  /**
175
187
  * Fetch + content-address verify EVERY blob the envelope references from the source, one at a time (memory bounded by one blob) —— 首推与同图重推共用的**唯一**取值校验;
176
188
  * 任何一枚取不出 / 核不过 ⇒ 整信封典型拒,什么都不发布。`onVerified` = 校验过的这一枚拿来做什么:首推传「续租式 upsert」(delete-in-use 租约 —— 发布前的孤儿清扫不许收走
177
- * 这次导入正要引用的字节);同图重推不传 —— 已发布的图的版本行本身就是引用,租约无事可护,而回写会把每只对象重传一遍(MinIO 的 `putBlob` 是整体 PUT)。
189
+ * 这次导入正要引用的字节);同图重推不传 —— 已发布的图的版本行本身就是引用,租约无事可护,而回写会把每只对象重传一遍(对象存储字节口的 `put` 是整体 PUT)。
178
190
  */
179
191
  private verifySourceBlobs;
180
192
  importHistory(scope: string, data: FileHistoryExport, srcGetBlob: (hash: string) => Promise<Uint8Array | undefined>): Promise<FileHistoryResult>;
181
193
  }
182
194
  /** MySQL-protocol (TiDB) binding. */
183
195
  export declare class TiDBFileHistoryStore extends SqlFileHistoryStore {
184
- constructor(pool: MySqlPool, blobBackend?: BlobBackend, opts?: SqlFileHistoryStoreOptions);
196
+ constructor(pool: MySqlPool, opts?: SqlFileHistoryStoreOptions);
185
197
  }
186
198
  /** PostgreSQL binding. */
187
199
  export declare class PgFileHistoryStore extends SqlFileHistoryStore {
188
- constructor(pool: PgPool, blobBackend?: BlobBackend, opts?: SqlFileHistoryStoreOptions);
200
+ constructor(pool: PgPool, opts?: SqlFileHistoryStoreOptions);
189
201
  }
190
202
  /**
191
203
  * [ref] D1② — A7-recipe upgrade precondition assert (**refuse to start**, never a warn; the form and
@@ -1,9 +1,9 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { captureFileBackupViaEnv, applyFileRestoreViaEnv, fileHistoryModeProvenDifferent, worldStillMatchesMint, annulProofFailure, boundaryPublishVerdict, fileHistoryDescribeTrackKey, fileHistoryTrackKeyOf, fileHistoryResolveTrackKey, fileHistoryExportDigest, validateFileHistoryExport, resolveFileHistoryRetention, fileHistoryBoundariesToKeep, } from "@sema-agent/core";
3
- import { BlobTooLargeError, SqlBlobBackend } from "./blob-backend.js";
4
- import { mysqlDriver, pgDriver } from "./sql-driver.js";
5
- import { isMissingColumnError, retryOnDeadlock } from "./sql-errors.js";
6
- import { describeProbedTableDrift } from "./schema-drift-sentence.js";
3
+ import { BlobTooLargeError, SqlBlobIndex } from "./blob-index-sql.js";
4
+ import { mysqlDriver, pgDriver } from "../plugins/sql-driver.js";
5
+ import { isMissingColumnError, retryOnDeadlock } from "../plugins/sql-errors.js";
6
+ import { describeProbedTableDrift } from "../plugins/schema-drift-sentence.js";
7
7
  import { recordFailOpen } from "../observability/fail-open.js";
8
8
  import { foldCaughtFailure } from "../file-history-disclosure.js";
9
9
  export const FILE_HISTORY_BLOB_TABLE = "file_history_blob";
@@ -28,17 +28,22 @@ export class SqlFileHistoryStore {
28
28
  pool;
29
29
  blobExchange = {
30
30
  put: (hash, bytes) => this.putExchangedBlob(hash, bytes),
31
- get: (hash) => this.blobs.getBlob(hash),
32
- has: (hashes) => this.blobs.hasBlobs([...hashes]),
31
+ get: (hash) => this.blobs.get(hash),
32
+ has: (hashes) => this.blobs.has([...hashes]),
33
33
  };
34
34
  blobs;
35
35
  spentAttempts = new Set();
36
36
  activeAttempts = new Set();
37
37
  boundaryKeep;
38
- constructor(db, pool, blobBackend, opts) {
38
+ constructor(db, pool, opts) {
39
39
  this.db = db;
40
40
  this.pool = pool;
41
- this.blobs = blobBackend ?? new SqlBlobBackend(this.db.dialect, this.pool, undefined, FILE_HISTORY_BLOB_TABLE);
41
+ this.blobs = new SqlBlobIndex(this.db.dialect, this.pool, {
42
+ table: FILE_HISTORY_BLOB_TABLE,
43
+ ...(opts?.blobs !== undefined ? { bytes: opts.blobs } : {}),
44
+ ...(opts?.blobSqlMaxBytes !== undefined ? { maxBytes: opts.blobSqlMaxBytes } : {}),
45
+ ...(opts?.log !== undefined ? { log: opts.log } : {}),
46
+ });
42
47
  this.boundaryKeep = resolveFileHistoryRetention(this.db.dialect === "mysql" ? "TiDBFileHistoryStore" : "PgFileHistoryStore", opts?.retention);
43
48
  }
44
49
  q(mysql, pg) {
@@ -95,7 +100,7 @@ export class SqlFileHistoryStore {
95
100
  const baseAvailable = cap.state !== "unreadable";
96
101
  let v1;
97
102
  if (cap.state === "file") {
98
- await this.blobs.putBlob(cap.hash, cap.bytes);
103
+ await this.blobs.put(cap.hash, cap.bytes);
99
104
  v1 = { blobHash: cap.hash, ...(cap.mode !== undefined ? { mode: cap.mode } : {}), ...(cap.parentIdent !== undefined ? { parentIdent: cap.parentIdent } : {}) };
100
105
  }
101
106
  else if (cap.state === "absent") {
@@ -344,7 +349,7 @@ export class SqlFileHistoryStore {
344
349
  staged.set(t.keyHash, { kind: "unchanged", version: last.version });
345
350
  continue;
346
351
  }
347
- await this.blobs.putBlob(cap.hash, cap.bytes);
352
+ await this.blobs.put(cap.hash, cap.bytes);
348
353
  staged.set(t.keyHash, { kind: "changed", blobHash: cap.hash, ...(cap.mode !== undefined ? { mode: cap.mode } : {}), ...(cap.parentIdent !== undefined ? { parentIdent: cap.parentIdent } : {}) });
349
354
  }
350
355
  const verdict = boundaryPublishVerdict({ aborted: signal?.aborted === true });
@@ -471,7 +476,7 @@ export class SqlFileHistoryStore {
471
476
  if (rec.blobHash === null)
472
477
  target = { absent: true };
473
478
  else {
474
- const bytes = await this.blobs.getBlob(rec.blobHash);
479
+ const bytes = await this.blobs.get(rec.blobHash);
475
480
  if (bytes === undefined) {
476
481
  ledger.failed.push({ path: t.trackKey, reason: `blob ${rec.blobHash} missing (store integrity)` });
477
482
  continue;
@@ -594,14 +599,14 @@ export class SqlFileHistoryStore {
594
599
  const orphans = rows.map((r) => String(r.blob_hash));
595
600
  if (orphans.length === 0)
596
601
  return 0;
597
- return this.blobs.deleteBlobs(orphans);
602
+ return this.blobs.sweep(orphans);
598
603
  }
599
604
  async putExchangedBlob(hash, bytes) {
600
605
  if (sha256hex(bytes) !== hash) {
601
606
  return { ok: false, error: { code: "adopt_failed", message: `blob ${hash}: the bytes do not hash to this address — nothing stored`, permanence: "terminal" } };
602
607
  }
603
608
  try {
604
- await this.blobs.putBlob(hash, bytes);
609
+ await this.blobs.put(hash, bytes);
605
610
  return { ok: true };
606
611
  }
607
612
  catch (err) {
@@ -760,7 +765,7 @@ export class SqlFileHistoryStore {
760
765
  if (existing !== null && !sameGraph) {
761
766
  return { ok: false, error: { code: "conflict", message: `importHistory target "${scope}" already holds a DIFFERENT history — a first import requires an empty target and a retry is legal only for the identical envelope (atomic visibility prevents half-graphs; this law prevents publishing the wrong complete graph over locally-grown history)` } };
762
767
  }
763
- const verified = await this.verifySourceBlobs(data, srcGetBlob, sameGraph ? undefined : (hash, bytes) => this.blobs.putBlob(hash, bytes));
768
+ const verified = await this.verifySourceBlobs(data, srcGetBlob, sameGraph ? undefined : (hash, bytes) => this.blobs.put(hash, bytes));
764
769
  if (!verified.ok)
765
770
  return verified;
766
771
  if (sameGraph)
@@ -813,13 +818,13 @@ export class SqlFileHistoryStore {
813
818
  }
814
819
  }
815
820
  export class TiDBFileHistoryStore extends SqlFileHistoryStore {
816
- constructor(pool, blobBackend, opts) {
817
- super(mysqlDriver(pool), pool, blobBackend, opts);
821
+ constructor(pool, opts) {
822
+ super(mysqlDriver(pool), pool, opts);
818
823
  }
819
824
  }
820
825
  export class PgFileHistoryStore extends SqlFileHistoryStore {
821
- constructor(pool, blobBackend, opts) {
822
- super(pgDriver(pool), pool, blobBackend, opts);
826
+ constructor(pool, opts) {
827
+ super(pgDriver(pool), pool, opts);
823
828
  }
824
829
  }
825
830
  export async function assertFileHistorySchema(query, dialect) {
@@ -1,8 +1,8 @@
1
1
  import type { Pool as MySqlPool } from "mysql2/promise";
2
2
  import type { Pool as PgPool } from "pg";
3
3
  import type { MailboxAckResult, MailboxAppendMessage, MailboxDecision, MailboxDecisionOutcome, MailboxLease, MailboxRecipientTombstone, MailboxStore } from "@sema-agent/core";
4
- import { type IndexSpec } from "./ensure-index.js";
5
- import type { SqlDialect } from "./sql-driver.js";
4
+ import { type IndexSpec } from "../plugins/ensure-index.js";
5
+ import type { SqlDialect } from "../plugins/sql-driver.js";
6
6
  export declare const MAILBOX_TABLE = "mailbox";
7
7
  export declare const MAILBOX_MSG_TABLE = "mailbox_message";
8
8
  /** [ref] 收件人墓碑表(预删除态的**唯一**真源;形与理由见 `mailbox-recipient-lifecycle.ts` 模块头)。
@@ -1,10 +1,10 @@
1
1
  import { isUtf8 } from "node:buffer";
2
2
  import { MAILBOX_CONSUMED_ID_WINDOW, MAILBOX_INVALID_PEER_META_CODE, MAILBOX_RECORD_ID_MAX_CHARS, MAILBOX_REPLAY_FACETS, MAILBOX_TOMBSTONED_RECIPIENT_CODE, MailboxStoreError, assertMailboxDecisionMove, judgeMailboxAppendById, mailboxReplayDigests, readMailboxAppend, readMailboxPeerMeta, readStoredMailboxDecision } from "@sema-agent/core";
3
- import { pgHasUnstorable, pgSanitizeText, PgUnstorableError } from "./pg-safe-json.js";
3
+ import { pgHasUnstorable, pgSanitizeText, PgUnstorableError } from "../plugins/pg-safe-json.js";
4
4
  import { isWellFormedUnicode } from "../principal-jwt.js";
5
- import { ensureIndexes } from "./ensure-index.js";
6
- import { escapeLike } from "./sql-escape.js";
7
- import { SqlJsonColumnError, decodeJsonColumn, decodeNullableJsonColumn, foldJsonColumn, isJsonColumnBodyProblem, jsonColumnText, readStringArrayColumn } from "./sql-json-column.js";
5
+ import { ensureIndexes } from "../plugins/ensure-index.js";
6
+ import { escapeLike } from "../plugins/sql-escape.js";
7
+ import { SqlJsonColumnError, decodeJsonColumn, decodeNullableJsonColumn, foldJsonColumn, isJsonColumnBodyProblem, jsonColumnText, readStringArrayColumn } from "../plugins/sql-json-column.js";
8
8
  export const MAILBOX_TABLE = "mailbox";
9
9
  export const MAILBOX_MSG_TABLE = "mailbox_message";
10
10
  export const MAILBOX_TOMBSTONE_TABLE = "mailbox_tombstone";