@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
@@ -2,13 +2,13 @@ import { redactErrorMessage, redactLedgerEventData, sealRunRowResult } from "../
2
2
  import { outwardPlane } from "../terminal.js";
3
3
  import { projectUsageStats, USAGE_SCAN_LIMIT } from "../usage-analytics.js";
4
4
  import { join } from "node:path";
5
- import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
5
+ import { existsSync, readFileSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
6
6
  import { randomBytes } from "node:crypto";
7
7
  import { AppendLog, atomicWriteFile, ensureDir, isProcessLive, processFingerprint, sanitizePathComponent, sanitizeScope, writeThenLink } from "@sema-agent/core";
8
8
  import { recordFailOpen } from "../observability/fail-open.js";
9
9
  import { replayJsonlSkipping } from "../observability/corrupt-read-seat.js";
10
10
  import { joinFromStore, splitForStore } from "./wiring-section-codec.js";
11
- import { RUN_HOLDER_DEATH_CODES, RUN_ORPHANED_ERROR, RUN_STALLED_ERROR, StoreBootRefusalError, buildRunOrphanedError, readLegacyHolderDeathCode, isTerminalRunStatus, settledLegObservationOf } from "./store-contracts.js";
11
+ import { RUN_HOLDER_DEATH_CODES, RUN_ORPHANED_ERROR, RUN_STALLED_ERROR, StoreBootRefusalError, buildRunOrphanedError, isTerminalRunStatus, settledLegObservationOf } from "./store-contracts.js";
12
12
  import { notifyRunTerminal } from "../observability/run-terminal.js";
13
13
  import { readRunIdentityCells, runIdentityCells } from "../identity-source.js";
14
14
  import { createInProcessSpaceCommitTable, fenceSpaceCommitAtTerminal, SPACE_COMMIT_RECORD_SCHEMA } from "../workspace-space-commit.js";
@@ -58,6 +58,9 @@ const PARK_ORPHAN_SETTLE_MS = 30_000;
58
58
  export class RunStoreStrictHydrateError extends StoreBootRefusalError {
59
59
  name = "RunStoreStrictHydrateError";
60
60
  }
61
+ export function fileRunStoreDirsFor(root) {
62
+ return { runs: join(root, "runs"), active: join(root, "runs", "active"), tmp: join(root, "tmp"), spaceCommits: join(root, "space-commits") };
63
+ }
61
64
  export class FileRunStore {
62
65
  runsDir;
63
66
  activeDir;
@@ -81,15 +84,16 @@ export class FileRunStore {
81
84
  constructor(root, opts) {
82
85
  this.logger = opts;
83
86
  this.strictHydrate = opts?.strictHydrate === true;
84
- this.runsDir = join(root, "runs");
85
- this.activeDir = join(root, "runs", "active");
86
- this.tmpDir = join(root, "tmp");
87
+ const dirs = fileRunStoreDirsFor(root);
88
+ this.runsDir = dirs.runs;
89
+ this.activeDir = dirs.active;
90
+ this.tmpDir = dirs.tmp;
87
91
  this.blobsDir = join(root, "run-blobs");
88
- this.spaceCommitsDir = join(root, "space-commits");
92
+ this.spaceCommitsDir = dirs.spaceCommits;
89
93
  this.spaceCommits = createInProcessSpaceCommitTable({
90
94
  load: (spaceKey) => this.loadSpaceCommit(spaceKey),
91
95
  save: (record) => {
92
- mkdirSync(this.spaceCommitsDir, { recursive: true });
96
+ ensureDir(this.spaceCommitsDir);
93
97
  atomicWriteFile(this.tmpDir, this.spaceCommitPath(record.spaceKey), `${JSON.stringify(record)}\n`);
94
98
  },
95
99
  remove: (spaceKey) => rmSync(this.spaceCommitPath(spaceKey), { force: true }),
@@ -353,17 +357,21 @@ export class FileRunStore {
353
357
  }
354
358
  }
355
359
  writeRunFile(r) {
356
- mkdirSync(this.runDir(r.taskId), { recursive: true });
360
+ ensureDir(this.runDir(r.taskId));
357
361
  atomicWriteFile(this.tmpDir, this.runJsonPath(r.taskId), `${JSON.stringify(this.toDisk(r))}\n`);
358
362
  }
359
- persist(r) {
360
- this.writeRunFile(r);
361
- this.runs.set(r.taskId, r);
363
+ persist(draft) {
364
+ this.writeRunFile(draft);
365
+ const live = this.runs.get(draft.taskId);
366
+ if (live === undefined)
367
+ this.runs.set(draft.taskId, draft);
368
+ else
369
+ Object.assign(live, draft);
362
370
  }
363
371
  eventLogFor(taskId) {
364
372
  let log = this.eventLogs.get(taskId);
365
373
  if (!log) {
366
- mkdirSync(this.runDir(taskId), { recursive: true });
374
+ ensureDir(this.runDir(taskId));
367
375
  log = new AppendLog(this.eventsPath(taskId));
368
376
  this.eventLogs.set(taskId, log);
369
377
  }
@@ -434,15 +442,13 @@ export class FileRunStore {
434
442
  const r = this.runs.get(taskId);
435
443
  if (!r || r.objectivePreview !== null)
436
444
  return;
437
- this.writeRunFile({ ...r, objectivePreview: preview });
438
- r.objectivePreview = preview;
445
+ this.persist({ ...r, objectivePreview: preview });
439
446
  }
440
447
  async requestCancel(taskId, owner) {
441
448
  const r = this.runs.get(taskId);
442
449
  if (!r || !ownerEq(r.owner, owner) || r.status !== "running")
443
450
  return false;
444
- r.cancelRequested = true;
445
- this.persist(r);
451
+ this.persist({ ...r, cancelRequested: true });
446
452
  return true;
447
453
  }
448
454
  async isCancelRequested(taskId, owner) {
@@ -453,8 +459,7 @@ export class FileRunStore {
453
459
  const r = this.runs.get(taskId);
454
460
  if (!r || !ownerEq(r.owner, owner) || r.status !== "running")
455
461
  return false;
456
- r.preemptRequested = true;
457
- this.persist(r);
462
+ this.persist({ ...r, preemptRequested: true });
458
463
  return true;
459
464
  }
460
465
  async isPreemptRequested(taskId, owner) {
@@ -463,10 +468,8 @@ export class FileRunStore {
463
468
  }
464
469
  async heartbeat(taskId, owner) {
465
470
  const r = this.runs.get(taskId);
466
- if (r && ownerEq(r.owner, owner) && r.status === "running") {
467
- r.updatedAt = new Date();
468
- this.persist(r);
469
- }
471
+ if (r && ownerEq(r.owner, owner) && r.status === "running")
472
+ this.persist({ ...r, updatedAt: new Date() });
470
473
  }
471
474
  async appendEvent(taskId, seq, type, data) {
472
475
  data = redactLedgerEventData(type, data);
@@ -569,12 +572,8 @@ export class FileRunStore {
569
572
  }
570
573
  let pending;
571
574
  if (r.status === "running" || r.status === "suspended" || r.status === "needs_review") {
572
- r.status = status;
573
- r.result = result;
574
- r.error = error;
575
- r.errorCode = result === null ? null : (outwardPlane(result.terminal).errorCode ?? null);
576
- r.updatedAt = new Date();
577
- this.persist(r);
575
+ const errorCode = result === null ? null : (outwardPlane(result.terminal).errorCode ?? null);
576
+ this.persist({ ...r, status, result, error, errorCode, updatedAt: new Date() });
578
577
  pending = {
579
578
  runId: taskId,
580
579
  sessionId: r.sessionId,
@@ -582,7 +581,7 @@ export class FileRunStore {
582
581
  status,
583
582
  resultTaskId: result?.taskId,
584
583
  model: result?.model,
585
- errorCode: r.errorCode ?? undefined,
584
+ errorCode: errorCode ?? undefined,
586
585
  errorMessage: (result === null ? undefined : outwardPlane(result.terminal).errorMessage) ?? error ?? undefined,
587
586
  elapsedMs: Math.max(0, Date.now() - r.createdAt.getTime()),
588
587
  };
@@ -597,33 +596,29 @@ export class FileRunStore {
597
596
  const sealed = sealRunRowResult(result);
598
597
  const r = this.runs.get(taskId);
599
598
  if (r && (r.status === "running" || r.status === "suspended")) {
600
- r.status = "suspended";
601
- r.result = sealed;
602
- r.updatedAt = new Date();
603
- this.persist(r);
599
+ this.persist({ ...r, status: "suspended", result: sealed, updatedAt: new Date() });
604
600
  }
605
601
  }
606
602
  async setNeedsReview(taskId, result) {
607
603
  const sealed = sealRunRowResult(result);
608
604
  const r = this.runs.get(taskId);
609
605
  if (r && (r.status === "running" || r.status === "needs_review")) {
610
- r.status = "needs_review";
611
- r.result = sealed;
612
- r.updatedAt = new Date();
613
- this.persist(r);
606
+ this.persist({ ...r, status: "needs_review", result: sealed, updatedAt: new Date() });
614
607
  }
615
608
  }
616
609
  async markResuming(taskId, instanceId) {
617
610
  const r = this.runs.get(taskId);
618
611
  if (!r || (r.status !== "suspended" && r.status !== "needs_review"))
619
612
  return false;
620
- r.status = "running";
621
- r.result = null;
622
- r.instanceId = instanceId;
623
- r.cancelRequested = false;
624
- r.preemptRequested = false;
625
- r.updatedAt = new Date();
626
- this.persist(r);
613
+ this.persist({
614
+ ...r,
615
+ status: "running",
616
+ result: null,
617
+ instanceId,
618
+ cancelRequested: false,
619
+ preemptRequested: false,
620
+ updatedAt: new Date(),
621
+ });
627
622
  return true;
628
623
  }
629
624
  async getActiveTaskId(sessionId) {
@@ -633,8 +628,7 @@ export class FileRunStore {
633
628
  const r = this.runs.get(taskId);
634
629
  if (this.active.get(sessionId) !== taskId || r === undefined || r.status !== "running")
635
630
  return false;
636
- r.updatedAt = new Date();
637
- this.persist(r);
631
+ this.persist({ ...r, updatedAt: new Date() });
638
632
  write({ instanceId: r.instanceId });
639
633
  return true;
640
634
  }
@@ -806,12 +800,14 @@ export class FileRunStore {
806
800
  let reaped = 0;
807
801
  for (const r of this.runs.values()) {
808
802
  if (r.status === "running" && pred(r)) {
809
- r.status = "failed";
810
- r.result = null;
811
- r.error = reason;
812
- r.errorCode = code;
813
- r.updatedAt = new Date();
814
- this.persist(r);
803
+ this.persist({
804
+ ...r,
805
+ status: "failed",
806
+ result: null,
807
+ error: reason,
808
+ errorCode: code,
809
+ updatedAt: new Date(),
810
+ });
815
811
  reaped += 1;
816
812
  }
817
813
  }
@@ -829,12 +825,14 @@ export class FileRunStore {
829
825
  orphans.push(r);
830
826
  }
831
827
  for (const r of orphans) {
832
- r.status = "failed";
833
- r.result = null;
834
- r.error = RUN_ORPHANED_ERROR;
835
- r.errorCode = RUN_HOLDER_DEATH_CODES.orphaned;
836
- r.updatedAt = new Date();
837
- this.persist(r);
828
+ this.persist({
829
+ ...r,
830
+ status: "failed",
831
+ result: null,
832
+ error: RUN_ORPHANED_ERROR,
833
+ errorCode: RUN_HOLDER_DEATH_CODES.orphaned,
834
+ updatedAt: new Date(),
835
+ });
838
836
  }
839
837
  this.sweepClaims();
840
838
  return orphans.length;
@@ -843,12 +841,14 @@ export class FileRunStore {
843
841
  this.checkpointProbe = probe;
844
842
  }
845
843
  failExpiredPark(r) {
846
- r.status = "failed";
847
- r.result = null;
848
- r.error = "approval expired before decision";
849
- r.errorCode = "approval.expired";
850
- r.updatedAt = new Date();
851
- this.persist(r);
844
+ this.persist({
845
+ ...r,
846
+ status: "failed",
847
+ result: null,
848
+ error: "approval expired before decision",
849
+ errorCode: "approval.expired",
850
+ updatedAt: new Date(),
851
+ });
852
852
  }
853
853
  async reapSuspended(olderThanMs) {
854
854
  const probe = this.checkpointProbe;
@@ -1107,17 +1107,6 @@ export class FileRunStore {
1107
1107
  }
1108
1108
  }
1109
1109
  }
1110
- migrateLegacyHolderDeathCodes() {
1111
- let migrated = 0;
1112
- for (const r of this.runs.values()) {
1113
- const code = readLegacyHolderDeathCode(r);
1114
- if (code === null || r.errorCode === code)
1115
- continue;
1116
- this.persist({ ...r, errorCode: code });
1117
- migrated += 1;
1118
- }
1119
- return migrated;
1120
- }
1121
1110
  sessionIdsWithRuns() {
1122
1111
  return new Set([...this.runs.values()].map((r) => r.sessionId));
1123
1112
  }
@@ -34,7 +34,7 @@
34
34
  */
35
35
  import { type SessionStore, type AcquiredSession, type SessionHead, type SessionStoreSummary, type SessionPlacement, type PlacedSessionRow } from "@sema-agent/core";
36
36
  import type { ExecutionPlacementSeat } from "../execution-placement.js";
37
- import type { ForkToFn } from "./session-fork.js";
37
+ import type { ForkPlacement, ForkToFn } from "./session-fork.js";
38
38
  /** acquire 选项形(core 5.48 SessionStore 契约):[ref] placement=受信 spawner 的分区建会话声明。 */
39
39
  type AcquireOpts = {
40
40
  requireExisting?: boolean;
@@ -86,7 +86,11 @@ export declare class ForkRoutingSessionStore implements SessionStore {
86
86
  unpin(sessionId: string): void | Promise<void>;
87
87
  noteTaskRun(sessionId: string, taskId: string, runId?: string): void | Promise<void>;
88
88
  list(): Promise<SessionStoreSummary[]>;
89
- fork(sourceId: string, owner?: string | null): Promise<string | null>;
89
+ /** `opts.placement`(后台 fork 子代的转录进委派分区)原样交给做这次 fork 的那只店 —— 落不落由那只店的声明判(host 声明了分区就落;瞬态店不声明 ⇒ 忽略),
90
+ * 本类不判第二次(声明面从 host 逐字转发,引擎据它决定交不交元组)。 */
91
+ fork(sourceId: string, owner?: string | null, opts?: {
92
+ placement?: ForkPlacement;
93
+ }): Promise<string | null>;
90
94
  get size(): number;
91
95
  dispose(): void | Promise<void>;
92
96
  }
@@ -191,10 +191,10 @@ export class ForkRoutingSessionStore {
191
191
  list() {
192
192
  return this.transient.list?.() ?? Promise.resolve([]);
193
193
  }
194
- async fork(sourceId, owner) {
194
+ async fork(sourceId, owner, opts) {
195
195
  const routed = this.route.get(sourceId);
196
196
  const tryFork = async (store, where) => {
197
- const forked = (await store.fork?.(sourceId, owner)) ?? null;
197
+ const forked = (await store.fork?.(sourceId, owner, opts)) ?? null;
198
198
  if (forked !== null) {
199
199
  this.remember(sourceId, where);
200
200
  this.remember(forked, where);
@@ -16,9 +16,12 @@
16
16
  * 一律问**店**:它能叫出名字的每一只桶,判据在桶里判(不在桶外按「谁可能有」预筛)。
17
17
  * · SQL:规则表里的每一只桶(`listRuleBucketOwners`,按 `owner_key` 分页)。不从审批记录推 —— 收编把规则桶整桶改键到新身份、审批史留在旧身份名下,
18
18
  * 从记录推出的属主集在收编之后漏掉新桶。
19
- * · File:引擎的 File 分区后端**没有**列桶口(桶文件按属主名的单向摘要命名),本步能叫出名字的只有本店导入记录点名过的属主
20
- * (`FileRuleApprovalRecordStore.importRecordOwners`;`imported-cc` 只由导入记录派生,记录是只增日志)。**已知缺口(如实)**:引擎的本地数据根收编
21
- * 把一只桶改名到一个没有任何导入记录点名的身份之后,那只桶本步叫不出、不读 —— 等引擎给 File 分区后端一个列桶口再收。
19
+ * · File:引擎 File 分区后端的列桶口一次答(`FileDurableRulePartitionProvider.listBucketOwners({ knownOwners })`):目录自己叫得出名字的属主(本机属主那只桶、
20
+ * 收编标记点名的身份 —— 收编把桶改名到一个没有任何导入记录点名的身份之后,那只桶照样被叫出来、被读),加上本店导入记录点名过的身份里桶文件在场的那些
21
+ * (`knownOwners` = `FileRuleApprovalRecordStore.importRecordOwners` 的身份名;`imported-cc` 只由导入记录派生,记录是只增日志;桶名由引擎的那一只摘要算,本仓不算)。
22
+ * **两者都叫不出属主的桶**(桶文件按属主名的单向摘要命名)本步读不到 —— 引擎在同一次答里给出它们的个数(`unnamedBuckets`),本步原样记进报告
23
+ * (`importedLayerRootBucketsUnnamed`),非零每次起服 warn 一行;它不是「空」,是本步的普查缺了这么多只。
24
+ * 一种店一个来源、一次答 ⇒ 属主不重(引擎:同名给两次、或收编标记也点了它,是一个属主;SQL:按 `owner_key` 分页,键唯一)。
22
25
  *
23
26
  * ## 写在哪里(一处)
24
27
  * 墓碑经**这只桶自己的写面**落(`writerOf(partition).apply({ kind: "tighten-delete" })`,引擎的写面契约)—— SQL 两孪生走 `SqlDurableRulePartition` 的那只
@@ -30,10 +33,11 @@
30
33
  * 列桶 / 解析桶 / 读桶 / 取点 / 写面**抛** ⇒ 原样抛:起服拒,收据账里已提交的墓碑随拒因交出(与本段其余各步同一条路)。例外两条,都由店的判官按抛出物的**类**判(不按文案):
31
34
  * 取点时店说这只桶**在写它的那一步里没了**(`source.isVanishedBucket`:另一只副本删桶恰落在这一窗)⇒ 无可退役、点名跳过 `vanished`(桶都没了,它什么都不放行);
32
35
  * 另一条是解析桶(属主 → 分区)或读桶时**店的唯一判官整桶拒**了
33
- * 这只桶(解析与读同一条律、同一只判官;`source.isWholeBucketRefusal`:确定性判决,引擎读侧对它同样整桶拒、它什么都不放行;SQL = 读腿真往外交的那两类 —— 判官四道的拒与某只 JSON 列的体读不出)
34
- * ⇒ 点名跳过 `bucket_unreadable`,接着读下一只桶(一只读不出的桶不挡别的桶,也不挡起服);一次读失败(连接 / 超时)
35
- * 证明不了以后也读不出,所以它**不**归这一类 —— 跳过它就是让那几行在读恢复之后照旧放行。File 店没有这种判决证据(引擎的 File 分区对损坏与 I/O 失败抛同一种错,
36
- * 解析时读收编标记也是:一次 EIO 与一份坏标记同一种错)⇒ 那一侧解析 / 读桶抛一律起服拒。另两种店**答了**却做不了的(没有写面或写面拒 / 并发争不过)⇒ 点名跳过,下一次起服再试,其间那几行照旧放行,每次起服都点名。
36
+ * 这只桶(解析与读同一条律、同一只判官;`source.isWholeBucketRefusal`:确定性判决,引擎读侧对它同样整桶拒、它什么都不放行;SQL = 读腿真往外交的那两类 —— 判官四道的拒与某只 JSON 列的体读不出;
37
+ * File = 引擎 File 分区的拒码 `permission_rules.bucket_damaged`〔同一份字节每次读都同样拒〕)
38
+ * ⇒ 点名跳过 `bucket_unreadable`,接着读下一只桶(一只读不出的桶不挡别的桶,也不挡起服);一次读失败(连接 / 超时;File 的拒码 `permission_rules.bucket_unreadable`,
39
+ * 带系统错名 `errno`)证明不了以后也读不出,所以它**不**归这一类 —— 跳过它就是让那几行在读恢复之后照旧放行。File 解析时读收编标记的拒(标记自己的拒,不带桶拒码)同样不归这一类 ⇒ 起服拒。
40
+ * 另两种店**答了**却做不了的(没有写面或写面拒 / 并发争不过)⇒ 点名跳过,下一次起服再试,其间那几行照旧放行,每次起服都点名。
37
41
  */
38
42
  import { type DurableRulePartitionProvider, type PersistedRule, type RuleAdd, type RuleOwner } from "@sema-agent/core";
39
43
  /** 一只被退役的导入 add 所在的行(一行一条读数)。**不带规则正文**(与 M11 同一条纪律:规则正文不出店)—— 桶键 + 工具名足够让运维去列举面对上它。 */
@@ -61,14 +65,21 @@ export interface ImportedLayerRootBucketSkipped {
61
65
  * 原句由店自己的披露口说,File 店的 `permission_rule_store_disclosure`、SQL 店的整桶拒句);写面拒的是闭集词,原样带。 */
62
66
  readonly why: string;
63
67
  }
64
- /** 本步记进收据账的两格(`OneTimeMigrationReport` 的两只键,随提交追加)。 */
68
+ /** 本步记进收据账的三格(`OneTimeMigrationReport` 的三只键;前两格随提交追加,第三格在列桶那一刻落定)。 */
65
69
  export interface ImportedLayerRootReadings {
66
70
  importedLayerRootAllowsRetired: ImportedLayerRootAllowRetired[];
67
71
  importedLayerRootBucketsSkipped: ImportedLayerRootBucketSkipped[];
72
+ /** 店在场却叫不出属主、本步因此没读的桶数(见头注「读哪些桶」;SQL 恒 0)。 */
73
+ importedLayerRootBucketsUnnamed: number;
68
74
  }
69
- /** 一种店交给本步的三样东西:它能叫出名字的桶的属主(见头注「读哪些桶」)、它的 durable 分区后端(读桶、写墓碑)、它的整桶拒判别(见头注「失败方向」)。 */
75
+ /** 一种店的桶普查(一次答):叫得出名字的属主,与在场却叫不出名字的桶数。 */
76
+ export interface RuleBucketCensus {
77
+ readonly owners: readonly RuleOwner[];
78
+ readonly unnamedBuckets: number;
79
+ }
80
+ /** 一种店交给本步的三样东西:它的桶普查(见头注「读哪些桶」)、它的 durable 分区后端(读桶、写墓碑)、它的整桶拒判别(见头注「失败方向」)。 */
70
81
  export interface ImportedLayerRootRetirementSource {
71
- candidateOwners(): Promise<readonly RuleOwner[]>;
82
+ candidateOwners(): Promise<RuleBucketCensus>;
72
83
  readonly durable: DurableRulePartitionProvider;
73
84
  /** 这只读桶抛出物是不是店的唯一判官的**确定性**整桶拒(真 ⇒ 点名跳过、读下一只桶;假 ⇒ 原样抛、起服拒)。判的是读面**真往外交的**抛出物的类,不按文案。 */
74
85
  isWholeBucketRefusal(e: unknown): boolean;
@@ -77,6 +88,6 @@ export interface ImportedLayerRootRetirementSource {
77
88
  }
78
89
  /** 判据(引擎 §5.14 那一句,逐字):这一行里该退役的 add;不选 ⇒ 空。 */
79
90
  export declare function importedLayerRootAddsOf(row: PersistedRule): readonly RuleAdd[];
80
- /** 跑一遍:读记录点名的每只桶(按桶键去重),退役判据选中的 add。读数随每次提交记进 `into`。 */
91
+ /** 跑一遍:读店叫得出名字的每只桶(`candidateOwners()` 一次答,见头注「读哪些桶」),退役判据选中的 add;叫不出名字的桶数记进 `into`。读数随每次提交记进 `into`。 */
81
92
  export declare function retireImportedLayerRootAllows(source: ImportedLayerRootRetirementSource, into: ImportedLayerRootReadings): Promise<void>;
82
93
  //# sourceMappingURL=imported-layer-root-retirement.d.ts.map
@@ -7,14 +7,10 @@ export function importedLayerRootAddsOf(row) {
7
7
  return row.adds.filter((a) => a.origin === "imported-cc");
8
8
  }
9
9
  export async function retireImportedLayerRootAllows(source, into) {
10
- const seen = new Set();
11
- for (const owner of await source.candidateOwners()) {
12
- const ownerKey = buildRuleOwnerKey(owner);
13
- if (seen.has(ownerKey))
14
- continue;
15
- seen.add(ownerKey);
16
- await retireInBucket(source, owner, ownerKey, into);
17
- }
10
+ const census = await source.candidateOwners();
11
+ into.importedLayerRootBucketsUnnamed = census.unnamedBuckets;
12
+ for (const owner of census.owners)
13
+ await retireInBucket(source, owner, buildRuleOwnerKey(owner), into);
18
14
  }
19
15
  async function retireInBucket(source, owner, ownerKey, into) {
20
16
  const durable = source.durable;
@@ -0,0 +1,14 @@
1
+ /** 两方言的列类型词(键表对 {@link SqlDialect} 闭合:加一种方言 ⇒ 编译红)。 */
2
+ export declare const INBOX_PAYLOAD_COLUMN_TYPE: {
3
+ readonly mysql: "TEXT";
4
+ readonly pg: "TEXT";
5
+ };
6
+ /** 列定义(两方言 DDL 内插;存量库缺列由起服列册对账拒启,拒句里的 ALTER 由建表语句生成)。 */
7
+ export declare const INBOX_PAYLOAD_COLUMN: {
8
+ readonly name: "payload";
9
+ readonly mysql: "payload TEXT NULL";
10
+ readonly pg: "payload TEXT COLLATE \"C\"";
11
+ };
12
+ /** 收件条目 `payload` 的字节预算(UTF-8 字节,量最终 JSON)= 各方言 `payload` 列容量的最小值。 */
13
+ export declare const INBOX_PAYLOAD_MAX_BYTES: number;
14
+ //# sourceMappingURL=inbox-payload-column.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { TEXT_COLUMN_TYPE_MAX_BYTES } from "./text-column-capacity.js";
2
+ export const INBOX_PAYLOAD_COLUMN_TYPE = { mysql: "TEXT", pg: "TEXT" };
3
+ export const INBOX_PAYLOAD_COLUMN = {
4
+ name: "payload",
5
+ mysql: `payload ${INBOX_PAYLOAD_COLUMN_TYPE.mysql} NULL`,
6
+ pg: `payload ${INBOX_PAYLOAD_COLUMN_TYPE.pg} COLLATE "C"`,
7
+ };
8
+ const INBOX_PAYLOAD_COLUMN_MAX_BYTES = {
9
+ mysql: TEXT_COLUMN_TYPE_MAX_BYTES.mysql[INBOX_PAYLOAD_COLUMN_TYPE.mysql],
10
+ pg: TEXT_COLUMN_TYPE_MAX_BYTES.pg[INBOX_PAYLOAD_COLUMN_TYPE.pg],
11
+ };
12
+ export const INBOX_PAYLOAD_MAX_BYTES = Math.min(...Object.values(INBOX_PAYLOAD_COLUMN_MAX_BYTES));
13
+ //# sourceMappingURL=inbox-payload-column.js.map
@@ -1,5 +1,5 @@
1
1
  import { type Checkpoint, type CheckpointSummary, type CheckpointToken, type PendingSteerInput, type ReopenReason, type ResolveExpectation, type ExecutionOutcomeRecordWord, type GateOutcome, type ResumeOutcome, type StoreDurability, type StoreFidelity } from "@sema-agent/core";
2
- import { type CheckpointAskCandidate, type CtxClaimRewrite, type CtxRowRewrite, type CtxRowsRewrite, type DecidedApprovalRecord, type PendingCheckpoint, type PendingRowBinding } from "./checkpoint-store-sql.js";
2
+ import { type CheckpointAskCandidate, type CtxClaimRewrite, type CtxRowRewrite, type CtxRowsRewrite, type DecidedApprovalRecord, type PendingCheckpoint, type PendingRowBinding } from "./checkpoint-store-face.js";
3
3
  import { type FencedRun, type InProcessClaimFence } from "./store-contracts.js";
4
4
  import type { SealedCheckpointCtx } from "../http/checkpoint-ctx.js";
5
5
  export interface LocalCheckpointStoreOptions {
@@ -11,6 +11,11 @@ export interface LocalCheckpointStoreOptions {
11
11
  /** ctx 改写的认领栅栏({@link LocalCheckpointStore.rewriteCtxWhileClaimed}):同一数据根上的文件 run 店(进程内栅栏形)。缺席 ⇒ 那一口响亮抛(装配缺陷)。 */
12
12
  claims?: InProcessClaimFence;
13
13
  }
14
+ /** checkpoint 店在数据根下自己铸的目录(构造器与一次性迁移 M39 的名册同读这一只)。 */
15
+ export declare function localCheckpointStoreDirsFor(root: string): {
16
+ readonly ctx: string;
17
+ readonly tmp: string;
18
+ };
14
19
  export declare class LocalCheckpointStore {
15
20
  /** [ref] 车1:托管留存声明 —— **诚实的 none**(与 local session 店同一条判据:本店的行没有按期删除的腿;
16
21
  * 留存三方法只实现在 SQL 聚合店上)。locked policy + 本店 ⇒ core 的门拒启,那是契约的正确行为。 */
@@ -221,7 +226,7 @@ export declare class LocalCheckpointStore {
221
226
  */
222
227
  rewriteCtxWhileClaimed(sessionId: string, taskId: string, ctx: SealedCheckpointCtx, legHolds: (run: FencedRun) => boolean): Promise<CtxClaimRewrite>;
223
228
  /**
224
- * 🔴 **一次性迁移的 ctx 行改写店腿**(local 孪生;`checkpoint-store-sql.ts` `CheckpointCtxRowsRewriter`,判词与 SQL 孪生 `rewriteCtxRows` 逐条同):
229
+ * 🔴 **一次性迁移的 ctx 行改写店腿**(local 孪生;`checkpoint-store-face.ts` `CheckpointCtxRowsRewriter`,判词与 SQL 孪生 `rewriteCtxRows` 逐条同):
225
230
  * 逐档读(信封经读腿**同一只**判形 —— 读不出 ⇒ 计数、跳过、**不删**),`rewrite` 交回新体 ⇒ 信封原样(`sessionId` / `updatedAt` 不动:收割按 `updatedAt` 判)
226
231
  * 只换 `ctx`,经写腿同一只形闸、同一只原子写落回原档。封签绑的是信封里的 `sessionId`(与 `getCtx` 认行的那一格同一个)。
227
232
  * 数据根独占 + 起服在任何读写者之前跑 ⇒ 本车道没有并发写者,不需要 CAS;没有一行装不下这回事(`tooLarge` 恒 0)。
@@ -3,13 +3,14 @@ import { denySweepOwns, parkedApprovalCard } from "../approval-content-kind.js";
3
3
  import { parkRowFacts, skillCardFacts } from "../approval-card.js";
4
4
  import { durableRowIdentity } from "../checkpoint-identity.js";
5
5
  import { createHash } from "node:crypto";
6
- import { existsSync, readFileSync, readdirSync, unlinkSync, mkdirSync } from "node:fs";
6
+ import { existsSync, readFileSync, readdirSync, unlinkSync } from "node:fs";
7
7
  import { join } from "node:path";
8
- import { CHECKPOINT_LIST_LIMITS, FileCheckpointStore, atomicWriteFile, executionVerdict, sanitizePathComponent, } from "@sema-agent/core";
9
- import { approvalDecisionOfWinner, approvalPayloadFingerprint, boundedRuleOffers, boundedToolInput, candidateIdentityOf, pendingRowPrecedes, queueRowGateKind, TERMINAL_BACKSTOP_MS, TERMINAL_GRACE_MS } from "./checkpoint-store-sql.js";
8
+ import { CHECKPOINT_LIST_LIMITS, FileCheckpointStore, atomicWriteFile, ensureDir, executionVerdict, sanitizePathComponent, } from "@sema-agent/core";
9
+ import { approvalPayloadFingerprint } from "./approval-payload-fingerprint.js";
10
+ import { approvalDecisionOfWinner, boundedRuleOffers, boundedToolInput, candidateIdentityOf, pendingRowPrecedes, queueRowGateKind, TERMINAL_BACKSTOP_MS, TERMINAL_GRACE_MS } from "./checkpoint-store-face.js";
10
11
  import { quarantineUnreadableSidecar } from "./local-sidecar-quarantine.js";
11
12
  import { createZodColumnReader, decodeJsonColumn, foldJsonColumn, readStringArrayColumn } from "./sql-json-column.js";
12
- import { UNMANAGED_RETENTION } from "./retention-store-sql.js";
13
+ import { UNMANAGED_RETENTION } from "./retention-declaration.js";
13
14
  import { assertJsonColumnWritable, createObjectColumnReader } from "./sql-json-column.js";
14
15
  import { FENCE_LANDED } from "./store-contracts.js";
15
16
  function terminalAtOf(cp) {
@@ -46,6 +47,9 @@ function refusingCtx(sessionId, read) {
46
47
  throw foldJsonColumn(e, (m) => `LocalCheckpointStore: ${m} — refusing rather than serve a resume context nobody can read (session ${JSON.stringify(sessionId)})`);
47
48
  }
48
49
  }
50
+ export function localCheckpointStoreDirsFor(root) {
51
+ return { ctx: join(root, "checkpoint-ctx"), tmp: join(root, ".tmp") };
52
+ }
49
53
  export class LocalCheckpointStore {
50
54
  retention = UNMANAGED_RETENTION;
51
55
  durability = "durable";
@@ -64,10 +68,11 @@ export class LocalCheckpointStore {
64
68
  this.opts = opts;
65
69
  this.scopesPath = join(root, "checkpoint-scopes.json");
66
70
  this.sessionTokensPath = join(root, "checkpoint-session-tokens.json");
67
- this.ctxDir = join(root, "checkpoint-ctx");
68
- this.tmpDir = join(root, ".tmp");
69
- mkdirSync(this.ctxDir, { recursive: true });
70
- mkdirSync(this.tmpDir, { recursive: true });
71
+ const dirs = localCheckpointStoreDirsFor(root);
72
+ this.ctxDir = dirs.ctx;
73
+ this.tmpDir = dirs.tmp;
74
+ ensureDir(this.ctxDir);
75
+ ensureDir(this.tmpDir);
71
76
  if (existsSync(this.scopesPath)) {
72
77
  try {
73
78
  for (const s of decodeJsonColumn(readFileSync(this.scopesPath, "utf8"), readScopeRegistry, "checkpoint-scopes.json (the local scope registry)"))
@@ -0,0 +1,48 @@
1
+ /** 披露码:路径(含数据根自身、名册目录的子项)经符号链接 —— 不跟,这一条不走(「不在根内」一类,不按链接指向哪里特判)。 */
2
+ export declare const SYMLINK_IN_PATH = "SYMLINK_IN_PATH";
3
+ /**
4
+ * 本迁移看的两只根:数据根(`LocalBackend` 持锁的那一只物理路径 —— core `resolveDataRoot` 的 `physicalPathOf` 拼写 = 店构造时拿到的值;身份核拿它当「根内」的唯一判据,
5
+ * 不是物理拼写的值 ⇒ 每一只目录都过不了核、逐个进披露行)与记忆引擎根(boot 的 `memoryEngineRootFor` 推导,同步游标在它下面;
6
+ * 调用方先把它换成与数据根同一种拼写 —— 见 `LocalBackend` 的 `dataDirLayout`)。名册包含关系按字面判:引擎根经数据根之外的别名拼写 ⇒ 当作在数据根之外(不进名册)。
7
+ */
8
+ export interface DataDirLayout {
9
+ readonly dataRoot: string;
10
+ readonly memoryEngineRoot: string;
11
+ }
12
+ /**
13
+ * 布局只在这里铸一次(`LocalBackend` 取锁之后调):数据根 = 持锁的物理路径(配置里的拼写若经链接,事后改指也不影响);
14
+ * 记忆引擎根落在配置拼写的数据根之下 ⇒ 换成物理拼写(同一只目录只认一种拼写),否则原样(在数据根之外,名册不收)。
15
+ */
16
+ export declare function buildDataDirLayout(a: {
17
+ readonly configuredRoot: string;
18
+ readonly physicalRoot: string;
19
+ readonly memoryEngineRoot: string;
20
+ }): DataDirLayout;
21
+ export interface DataDirModeRefusal {
22
+ /** 相对数据根的路径。 */
23
+ readonly path: string;
24
+ /** 错误码(`EPERM` / `EACCES` / `ESTALE` / …)或 {@link SYMLINK_IN_PATH};没有码的错误记 `UNKNOWN`。 */
25
+ readonly code: string;
26
+ }
27
+ export interface DataDirModeReading {
28
+ /** 本次收紧成 0o700 的目录(相对数据根)。 */
29
+ readonly tightened: readonly string[];
30
+ /** 本次没能收紧 / 没能看见 / 没有走的目录。 */
31
+ readonly refused: readonly DataDirModeRefusal[];
32
+ }
33
+ /** 两只日志座:成功提示与失败披露各一(失败那只由调用方接**不可缺席**的口)。 */
34
+ export interface DataDirModeSinks {
35
+ readonly tightened: (msg: string, meta: Record<string, unknown>) => void;
36
+ readonly refused: (msg: string, meta: Record<string, unknown>) => void;
37
+ }
38
+ /** 测试座:收紧动作(默认对过了身份核的 fd `fchmod`)与平台(默认 `IS_WIN32`)。 */
39
+ export interface DataDirModeSeats {
40
+ readonly fchmod?: (fd: number, mode: number, rel: string) => void;
41
+ readonly win32?: boolean;
42
+ }
43
+ /**
44
+ * 把数据根下名册里的 0755 店目录一次收紧成 0o700。起服时调(`LocalBackend.runOneTimeMigrations`,任何读者之前);数据根独占 ⇒ 没有滚动升级窗,不需要读侧半场。
45
+ * 失败不抛(见头注);读数也由两只日志座打出。
46
+ */
47
+ export declare function tightenLocalDataDirModes(layout: DataDirLayout, sinks: DataDirModeSinks, seats?: DataDirModeSeats): DataDirModeReading;
48
+ //# sourceMappingURL=local-data-dir-modes-m39.d.ts.map