@sema-agent/server 7.131.0 → 7.133.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 (509) hide show
  1. package/MIGRATION.md +575 -0
  2. package/README.md +12 -9
  3. package/README.zh-CN.md +9 -6
  4. package/USAGE.md +326 -98
  5. package/deploy/sema-up/README.md +19 -1
  6. package/deploy/sema-up/chart/templates/server-v4pro.yaml +5 -2
  7. package/deploy/sema-up/chart/templates/server.yaml +5 -2
  8. package/deploy/sema-up/stack/compose.yaml +3 -0
  9. package/deploy/sema-up/stack/sema-stack-cluster.yaml +4 -2
  10. package/dist/adoption/plan.d.ts +3 -2
  11. package/dist/adoption/plan.js +7 -5
  12. package/dist/adoption/runner.js +3 -10
  13. package/dist/adoption/sql.d.ts +3 -2
  14. package/dist/adoption/sql.js +3 -5
  15. package/dist/adoption/wire.d.ts +4 -1
  16. package/dist/adoption/wire.js +1 -0
  17. package/dist/approval-ask-audit-store.d.ts +31 -13
  18. package/dist/approval-ask-audit-store.js +272 -74
  19. package/dist/approval-ask-machine.d.ts +15 -0
  20. package/dist/approval-ask-machine.js +6 -0
  21. package/dist/approval-ask-retention.d.ts +136 -0
  22. package/dist/approval-ask-retention.js +102 -0
  23. package/dist/approval-card.d.ts +82 -20
  24. package/dist/approval-card.js +46 -16
  25. package/dist/approval-deny-reasons.d.ts +1 -1
  26. package/dist/approval.d.ts +9 -0
  27. package/dist/approval.js +24 -3
  28. package/dist/audit.d.ts +33 -19
  29. package/dist/audit.js +12 -16
  30. package/dist/auth-bridge.d.ts +4 -0
  31. package/dist/auth-bridge.js +10 -11
  32. package/dist/bake-runner/main.js +3 -2
  33. package/dist/boot/deferred-sandbox-path-env.js +1 -1
  34. package/dist/boot/deployment-mods.d.ts +31 -0
  35. package/dist/boot/deployment-mods.js +26 -0
  36. package/dist/boot/execution-env.d.ts +1 -1
  37. package/dist/boot/execution-env.js +27 -12
  38. package/dist/boot/execution-lane.js +11 -0
  39. package/dist/boot/leader.js +2 -0
  40. package/dist/boot/memory-boundary.d.ts +2 -2
  41. package/dist/boot/memory-boundary.js +2 -2
  42. package/dist/boot/memory-consolidation.d.ts +5 -4
  43. package/dist/boot/memory-consolidation.js +7 -6
  44. package/dist/boot/org-delivery.d.ts +28 -0
  45. package/dist/boot/org-delivery.js +20 -0
  46. package/dist/boot/read-deny-anchor-audit.d.ts +17 -0
  47. package/dist/boot/read-deny-anchor-audit.js +36 -0
  48. package/dist/boot/reapers.d.ts +3 -0
  49. package/dist/boot/reapers.js +21 -1
  50. package/dist/boot/resolve-spec.d.ts +4 -5
  51. package/dist/boot/resolve-spec.js +74 -123
  52. package/dist/boot/runner-deps.d.ts +19 -8
  53. package/dist/boot/runner-deps.js +15 -2
  54. package/dist/boot/session-faces.d.ts +2 -7
  55. package/dist/boot/session-faces.js +4 -2
  56. package/dist/boot/stage-02-web-admin-pull.js +4 -1
  57. package/dist/boot/stage-03-store-backend.d.ts +1 -1
  58. package/dist/boot/stage-03-store-backend.js +2 -2
  59. package/dist/boot/stage-04-stores.d.ts +1 -1
  60. package/dist/boot/stage-05-execution-env.d.ts +4 -4
  61. package/dist/boot/stage-05-execution-env.js +7 -10
  62. package/dist/boot/stage-06-runners.d.ts +4 -2
  63. package/dist/boot/stage-06-runners.js +11 -7
  64. package/dist/boot/stage-07-capability-layer.d.ts +4 -2
  65. package/dist/boot/stage-07-capability-layer.js +27 -6
  66. package/dist/boot/stage-08-reapers.d.ts +4 -2
  67. package/dist/boot/stage-08-reapers.js +2 -2
  68. package/dist/boot/stage-09-leader.d.ts +6 -9
  69. package/dist/boot/stage-10-http-server.d.ts +6 -9
  70. package/dist/boot/stage-10-http-server.js +7 -9
  71. package/dist/boot/stores.d.ts +1 -1
  72. package/dist/boot/stores.js +7 -8
  73. package/dist/boot/web-admin.d.ts +4 -3
  74. package/dist/boot/web-admin.js +186 -98
  75. package/dist/boot/workflow-orchestration.d.ts +2 -0
  76. package/dist/boot/workflow-orchestration.js +2 -1
  77. package/dist/brain.js +25 -25
  78. package/dist/breaker-key.d.ts +6 -0
  79. package/dist/breaker-key.js +29 -0
  80. package/dist/budget.js +5 -4
  81. package/dist/caller-text-echo.d.ts +23 -0
  82. package/dist/caller-text-echo.js +21 -0
  83. package/dist/capabilities/brand-identity.d.ts +26 -0
  84. package/dist/capabilities/brand-identity.js +27 -0
  85. package/dist/capabilities/center-plugins.d.ts +7 -0
  86. package/dist/capabilities/center-plugins.js +1 -1
  87. package/dist/capabilities/center-prompts.d.ts +32 -59
  88. package/dist/capabilities/center-prompts.js +18 -32
  89. package/dist/capabilities/composite-members.d.ts +1 -1
  90. package/dist/capabilities/composite-members.js +1 -1
  91. package/dist/capabilities/engine-capabilities.js +2 -1
  92. package/dist/capabilities/execution-lane.js +2 -2
  93. package/dist/capabilities/hands-lane.d.ts +30 -6
  94. package/dist/capabilities/hands-lane.js +11 -1
  95. package/dist/capabilities/mcp-probe.d.ts +48 -3
  96. package/dist/capabilities/mcp-probe.js +47 -135
  97. package/dist/capabilities/scenarios.d.ts +95 -45
  98. package/dist/capabilities/scenarios.js +53 -38
  99. package/dist/capabilities/skills.d.ts +19 -4
  100. package/dist/capabilities/skills.js +30 -10
  101. package/dist/capability-facts.d.ts +34 -4
  102. package/dist/capability-facts.js +28 -2
  103. package/dist/center-config-tier.d.ts +69 -0
  104. package/dist/center-config-tier.js +42 -0
  105. package/dist/checkpoint-identity.d.ts +16 -0
  106. package/dist/checkpoint-identity.js +19 -0
  107. package/dist/config-catalog.d.ts +17 -10
  108. package/dist/config-catalog.js +47 -32
  109. package/dist/config-d-migration.d.ts +3 -1
  110. package/dist/config-d-migration.js +2 -2
  111. package/dist/config-dir-trust.d.ts +114 -0
  112. package/dist/config-dir-trust.js +388 -0
  113. package/dist/config-invariants.d.ts +18 -5
  114. package/dist/config-invariants.js +35 -3
  115. package/dist/config-lkg.d.ts +9 -9
  116. package/dist/config-lkg.js +20 -4
  117. package/dist/config-provider.d.ts +9 -2
  118. package/dist/config-provider.js +18 -6
  119. package/dist/config-types.d.ts +75 -20
  120. package/dist/config-types.js +8 -0
  121. package/dist/config.d.ts +13 -0
  122. package/dist/config.js +137 -62
  123. package/dist/delegated-session-owner.d.ts +185 -0
  124. package/dist/delegated-session-owner.js +119 -0
  125. package/dist/device-protocol.d.ts +5 -3
  126. package/dist/device-protocol.js +1 -1
  127. package/dist/device-ws-hub.js +21 -2
  128. package/dist/device-ws-protocol.d.ts +70 -6
  129. package/dist/device-ws-protocol.js +50 -22
  130. package/dist/elicitation.js +3 -2
  131. package/dist/entry-problems.d.ts +34 -0
  132. package/dist/entry-problems.js +14 -0
  133. package/dist/env-name-allowlist-knobs.d.ts +12 -2
  134. package/dist/env-name-allowlist-knobs.js +5 -4
  135. package/dist/exec-bounds.d.ts +15 -3
  136. package/dist/exec-bounds.js +4 -0
  137. package/dist/execution-lane-caps.d.ts +56 -10
  138. package/dist/execution-lane-caps.js +50 -0
  139. package/dist/field-conflict.d.ts +43 -0
  140. package/dist/field-conflict.js +20 -0
  141. package/dist/fleet/fleet-bus.d.ts +80 -6
  142. package/dist/fleet/fleet-bus.js +41 -9
  143. package/dist/hooks/classic-stations.d.ts +91 -0
  144. package/dist/hooks/classic-stations.js +27 -0
  145. package/dist/hooks/command-spawn.d.ts +57 -0
  146. package/dist/hooks/command-spawn.js +139 -0
  147. package/dist/hooks/hook-llm.d.ts +8 -5
  148. package/dist/hooks/hook-llm.js +79 -36
  149. package/dist/hooks/hook-runner.d.ts +349 -95
  150. package/dist/hooks/hook-runner.js +855 -568
  151. package/dist/hooks/hook-source.d.ts +44 -0
  152. package/dist/hooks/hook-source.js +40 -0
  153. package/dist/http/active-run-conflict.d.ts +5 -13
  154. package/dist/http/active-run-conflict.js +17 -27
  155. package/dist/http/admission.d.ts +8 -2
  156. package/dist/http/admission.js +188 -101
  157. package/dist/http/approval-sweeps.js +99 -21
  158. package/dist/http/caller-trust.d.ts +77 -0
  159. package/dist/http/caller-trust.js +143 -0
  160. package/dist/http/checkpoint-ctx.d.ts +41 -24
  161. package/dist/http/checkpoint-ctx.js +23 -16
  162. package/dist/http/claimed-run.d.ts +14 -0
  163. package/dist/http/claimed-run.js +15 -0
  164. package/dist/http/device-placement.d.ts +2 -4
  165. package/dist/http/device-placement.js +7 -11
  166. package/dist/http/dispatch.d.ts +0 -4
  167. package/dist/http/dispatch.js +15 -13
  168. package/dist/http/durable-run-leg.d.ts +6 -33
  169. package/dist/http/durable-run-leg.js +36 -10
  170. package/dist/http/health-self-report.d.ts +7 -5
  171. package/dist/http/health-self-report.js +4 -18
  172. package/dist/http/owner-access.d.ts +56 -0
  173. package/dist/http/owner-access.js +42 -0
  174. package/dist/http/principal-gate.d.ts +70 -28
  175. package/dist/http/principal-gate.js +61 -15
  176. package/dist/http/readiness.d.ts +11 -5
  177. package/dist/http/readiness.js +10 -3
  178. package/dist/http/refusal-body.d.ts +21 -0
  179. package/dist/http/refusal-body.js +4 -0
  180. package/dist/http/request-guards.d.ts +43 -23
  181. package/dist/http/request-guards.js +53 -17
  182. package/dist/http/resume-ctx-read.d.ts +2 -5
  183. package/dist/http/resume-ctx-read.js +7 -4
  184. package/dist/http/resume-legs.d.ts +28 -4
  185. package/dist/http/resume-legs.js +169 -91
  186. package/dist/http/retired-service-deps.d.ts +43 -0
  187. package/dist/http/retired-service-deps.js +18 -0
  188. package/dist/http/route-ctx.d.ts +44 -28
  189. package/dist/http/route-ctx.js +4 -0
  190. package/dist/http/route-table.js +2 -0
  191. package/dist/http/routes/a2a-serve.js +3 -4
  192. package/dist/http/routes/admin-config-refresh.js +1 -1
  193. package/dist/http/routes/admin-drain.js +1 -1
  194. package/dist/http/routes/admin-memory-optout.js +5 -1
  195. package/dist/http/routes/adoption.js +2 -9
  196. package/dist/http/routes/approvals-assistant.js +49 -48
  197. package/dist/http/routes/background.js +3 -2
  198. package/dist/http/routes/capabilities.js +21 -5
  199. package/dist/http/routes/config-catalog.d.ts +3 -3
  200. package/dist/http/routes/config-catalog.js +1 -1
  201. package/dist/http/routes/devices.js +3 -17
  202. package/dist/http/routes/diagnostics.js +6 -2
  203. package/dist/http/routes/images.js +6 -7
  204. package/dist/http/routes/leader.js +1 -8
  205. package/dist/http/routes/mcp-reconnect.d.ts +1 -1
  206. package/dist/http/routes/mcp-reconnect.js +3 -2
  207. package/dist/http/routes/memory-bundle.js +1 -1
  208. package/dist/http/routes/memory-compliance.js +1 -1
  209. package/dist/http/routes/memory-consolidation.js +1 -1
  210. package/dist/http/routes/memory-origin.js +1 -1
  211. package/dist/http/routes/memory-policy.d.ts +1 -1
  212. package/dist/http/routes/memory-policy.js +3 -2
  213. package/dist/http/routes/notify-wake.js +8 -21
  214. package/dist/http/routes/observability.js +2 -2
  215. package/dist/http/routes/principal-inbox.d.ts +39 -0
  216. package/dist/http/routes/principal-inbox.js +76 -0
  217. package/dist/http/routes/retention-ops.js +2 -9
  218. package/dist/http/routes/rules.js +5 -18
  219. package/dist/http/routes/runs.d.ts +5 -0
  220. package/dist/http/routes/runs.js +34 -107
  221. package/dist/http/routes/session-sync.js +15 -26
  222. package/dist/http/routes/sessions.js +30 -40
  223. package/dist/http/routes/shared-memory.js +2 -13
  224. package/dist/http/routes/side-query.js +8 -7
  225. package/dist/http/routes/tasks.js +67 -21
  226. package/dist/http/routes/workflows.d.ts +351 -0
  227. package/dist/http/routes/workflows.js +153 -119
  228. package/dist/http/send.d.ts +33 -10
  229. package/dist/http/send.js +21 -4
  230. package/dist/http/server.d.ts +27 -18
  231. package/dist/http/server.js +34 -6
  232. package/dist/http/stored-body-replay.js +17 -4
  233. package/dist/http/submit-ctx.d.ts +25 -0
  234. package/dist/http/submit-ctx.js +40 -0
  235. package/dist/http/submit-replay.d.ts +4 -3
  236. package/dist/http/submit-replay.js +5 -4
  237. package/dist/http/wire-types.d.ts +11 -8
  238. package/dist/index.d.ts +2 -2
  239. package/dist/index.js +1 -2
  240. package/dist/lane-home-probe.d.ts +112 -0
  241. package/dist/lane-home-probe.js +101 -0
  242. package/dist/leader/endpoint.d.ts +4 -1
  243. package/dist/leader/endpoint.js +11 -10
  244. package/dist/limit-refusal.d.ts +59 -0
  245. package/dist/limit-refusal.js +15 -0
  246. package/dist/main.js +1 -1
  247. package/dist/mcp-assertion-header.d.ts +32 -19
  248. package/dist/mcp-assertion-header.js +10 -9
  249. package/dist/mcp-tool-faces.d.ts +5 -0
  250. package/dist/mcp-tool-faces.js +6 -4
  251. package/dist/memory-project-layer.d.ts +37 -0
  252. package/dist/memory-project-layer.js +46 -0
  253. package/dist/memory-scope.d.ts +24 -17
  254. package/dist/memory-scope.js +24 -8
  255. package/dist/memory-sync-client.d.ts +27 -13
  256. package/dist/memory-sync-client.js +107 -18
  257. package/dist/model-entry-refusal.d.ts +9 -1
  258. package/dist/model-entry-refusal.js +6 -1
  259. package/dist/model-plane-face.d.ts +51 -0
  260. package/dist/model-plane-face.js +24 -0
  261. package/dist/model-provider.d.ts +44 -12
  262. package/dist/model-provider.js +21 -2
  263. package/dist/model-route-endpoint.d.ts +9 -12
  264. package/dist/model-route-endpoint.js +8 -11
  265. package/dist/model-route-env.d.ts +22 -0
  266. package/dist/model-route-env.js +2 -0
  267. package/dist/model-route-gap.d.ts +60 -30
  268. package/dist/model-route-gap.js +21 -15
  269. package/dist/observability/corrupt-read-seat.d.ts +7 -0
  270. package/dist/observability/corrupt-read-seat.js +9 -0
  271. package/dist/observability/cost-taxonomy.d.ts +7 -7
  272. package/dist/observability/err-text.d.ts +6 -0
  273. package/dist/observability/err-text.js +18 -4
  274. package/dist/observability/fail-open.d.ts +76 -14
  275. package/dist/observability/fail-open.js +76 -14
  276. package/dist/observability/metrics.js +4 -1
  277. package/dist/observability/prompt-manifest.d.ts +33 -82
  278. package/dist/observability/prompt-manifest.js +122 -17
  279. package/dist/observability/run-terminal.js +14 -6
  280. package/dist/observability/secret-env-scrub.d.ts +13 -1
  281. package/dist/observability/secret-env-scrub.js +13 -1
  282. package/dist/observability/tool-trace.d.ts +16 -21
  283. package/dist/observability/tool-trace.js +58 -49
  284. package/dist/operator-ask.d.ts +10 -0
  285. package/dist/operator-ask.js +3 -0
  286. package/dist/orchestration/workflow-agent-session-index.d.ts +12 -12
  287. package/dist/orchestration/workflow-agent-session-index.js +9 -13
  288. package/dist/orchestration/workflow-completion-inbox.d.ts +42 -15
  289. package/dist/orchestration/workflow-completion-inbox.js +13 -0
  290. package/dist/orchestration/workflow-notify-journal.d.ts +13 -32
  291. package/dist/orchestration/workflow-notify-journal.js +27 -34
  292. package/dist/orchestration/workflow-park-decision.d.ts +89 -0
  293. package/dist/orchestration/workflow-park-decision.js +118 -0
  294. package/dist/org-delivery-gate.d.ts +81 -0
  295. package/dist/org-delivery-gate.js +59 -0
  296. package/dist/panel-tool-names.d.ts +23 -0
  297. package/dist/panel-tool-names.js +8 -0
  298. package/dist/parked-decide.d.ts +39 -6
  299. package/dist/parked-decide.js +98 -51
  300. package/dist/parked-revive-surface.d.ts +9 -2
  301. package/dist/parked-revive-surface.js +11 -8
  302. package/dist/per-task-image.d.ts +7 -1
  303. package/dist/per-task-image.js +3 -3
  304. package/dist/permission-rule-list.d.ts +1 -1
  305. package/dist/permission-rule-list.js +2 -2
  306. package/dist/plain-string-record.d.ts +25 -0
  307. package/dist/plain-string-record.js +32 -0
  308. package/dist/plugins/approval-ask-store-file.d.ts +16 -1
  309. package/dist/plugins/approval-ask-store-file.js +21 -0
  310. package/dist/plugins/approval-ask-store-memory.d.ts +18 -1
  311. package/dist/plugins/approval-ask-store-memory.js +34 -2
  312. package/dist/plugins/approval-ask-store-sql.d.ts +25 -0
  313. package/dist/plugins/approval-ask-store-sql.js +37 -1
  314. package/dist/plugins/blob-backend.d.ts +83 -15
  315. package/dist/plugins/blob-backend.js +68 -15
  316. package/dist/plugins/breaker-state-sql.d.ts +2 -2
  317. package/dist/plugins/breaker-state-sql.js +4 -4
  318. package/dist/plugins/caching-session-store.d.ts +3 -0
  319. package/dist/plugins/caching-session-store.js +3 -0
  320. package/dist/plugins/checkpoint-store-sql.d.ts +28 -4
  321. package/dist/plugins/checkpoint-store-sql.js +59 -28
  322. package/dist/plugins/file-history-store-sql.d.ts +5 -2
  323. package/dist/plugins/file-history-store-sql.js +3 -1
  324. package/dist/plugins/file-run-store.d.ts +5 -13
  325. package/dist/plugins/file-run-store.js +9 -0
  326. package/dist/plugins/fork-routing-session-store.d.ts +9 -1
  327. package/dist/plugins/fork-routing-session-store.js +12 -1
  328. package/dist/plugins/host-platform.d.ts +2 -0
  329. package/dist/plugins/host-platform.js +2 -1
  330. package/dist/plugins/k8s-bg-scripts.d.ts +11 -0
  331. package/dist/plugins/k8s-bg-scripts.js +22 -0
  332. package/dist/plugins/local-checkpoint-store.d.ts +2 -0
  333. package/dist/plugins/local-checkpoint-store.js +11 -3
  334. package/dist/plugins/local-session-store.d.ts +1 -1
  335. package/dist/plugins/local-session-store.js +1 -1
  336. package/dist/plugins/local-session-window.d.ts +39 -0
  337. package/dist/plugins/local-session-window.js +54 -0
  338. package/dist/plugins/mailbox-recipient-lifecycle.d.ts +3 -2
  339. package/dist/plugins/mailbox-store-sql.d.ts +30 -48
  340. package/dist/plugins/mailbox-store-sql.js +77 -52
  341. package/dist/plugins/memory-embedder-fingerprint.js +2 -1
  342. package/dist/plugins/memory-run-store.d.ts +5 -13
  343. package/dist/plugins/memory-run-store.js +8 -0
  344. package/dist/plugins/one-time-migrations.d.ts +245 -93
  345. package/dist/plugins/one-time-migrations.js +668 -207
  346. package/dist/plugins/org-delivery-quota-store.d.ts +123 -0
  347. package/dist/plugins/org-delivery-quota-store.js +228 -0
  348. package/dist/plugins/permission-rule-store-sql.d.ts +13 -7
  349. package/dist/plugins/permission-rule-store-sql.js +4 -18
  350. package/dist/plugins/pg-pool.js +39 -7
  351. package/dist/plugins/pg-session-storage.d.ts +20 -8
  352. package/dist/plugins/pg-session-storage.js +34 -21
  353. package/dist/plugins/remote-env-adb.d.ts +12 -12
  354. package/dist/plugins/remote-env-adb.js +21 -6
  355. package/dist/plugins/remote-env-device.js +3 -0
  356. package/dist/plugins/remote-env-e2b.d.ts +1 -1
  357. package/dist/plugins/remote-env-e2b.js +21 -9
  358. package/dist/plugins/remote-env-host.d.ts +9 -9
  359. package/dist/plugins/remote-env-host.js +10 -32
  360. package/dist/plugins/remote-env-k8s.d.ts +103 -38
  361. package/dist/plugins/remote-env-k8s.js +288 -95
  362. package/dist/plugins/remote-env-local-docker.d.ts +27 -13
  363. package/dist/plugins/remote-env-local-docker.js +82 -11
  364. package/dist/plugins/remote-env-ssh.d.ts +21 -12
  365. package/dist/plugins/remote-env-ssh.js +117 -5
  366. package/dist/plugins/remote-shell.d.ts +0 -1
  367. package/dist/plugins/remote-shell.js +1 -2
  368. package/dist/plugins/retention-store-sql.js +6 -2
  369. package/dist/plugins/run-store-sql.d.ts +16 -14
  370. package/dist/plugins/run-store-sql.js +22 -2
  371. package/dist/plugins/schema-consistency.d.ts +54 -0
  372. package/dist/plugins/schema-consistency.js +52 -0
  373. package/dist/plugins/schema-indexes.js +2 -0
  374. package/dist/plugins/send-user-file.js +2 -2
  375. package/dist/plugins/session-epoch-anchor.d.ts +39 -0
  376. package/dist/plugins/session-epoch-anchor.js +22 -0
  377. package/dist/plugins/session-store.d.ts +18 -8
  378. package/dist/plugins/session-store.js +15 -4
  379. package/dist/plugins/shared-memory-store-sql.d.ts +9 -3
  380. package/dist/plugins/shared-memory-store-sql.js +5 -16
  381. package/dist/plugins/sql-driver.d.ts +205 -1
  382. package/dist/plugins/sql-driver.js +325 -13
  383. package/dist/plugins/sql-errors.d.ts +64 -0
  384. package/dist/plugins/sql-errors.js +57 -0
  385. package/dist/plugins/store-backend.d.ts +36 -1
  386. package/dist/plugins/store-backend.js +42 -15
  387. package/dist/plugins/store-contracts.d.ts +42 -0
  388. package/dist/plugins/store-contracts.js +1 -0
  389. package/dist/plugins/tidb-pool.d.ts +6 -1
  390. package/dist/plugins/tidb-pool.js +44 -10
  391. package/dist/plugins/tidb-session-storage.d.ts +8 -11
  392. package/dist/plugins/tidb-session-storage.js +6 -16
  393. package/dist/plugins/tidb-session-store.d.ts +24 -4
  394. package/dist/plugins/tidb-session-store.js +29 -5
  395. package/dist/plugins/workflow-journal-store-sql.d.ts +73 -19
  396. package/dist/plugins/workflow-journal-store-sql.js +19 -6
  397. package/dist/plugins/workflow-run-store-sql.d.ts +30 -8
  398. package/dist/plugins/workflow-run-store-sql.js +50 -9
  399. package/dist/posture-source.d.ts +18 -10
  400. package/dist/posture-source.js +4 -1
  401. package/dist/project-identity.d.ts +45 -6
  402. package/dist/project-identity.js +162 -8
  403. package/dist/project-layer-key.d.ts +28 -0
  404. package/dist/project-layer-key.js +29 -0
  405. package/dist/prompts-domain-validate.d.ts +17 -61
  406. package/dist/prompts-domain-validate.js +9 -119
  407. package/dist/question.js +3 -2
  408. package/dist/read-deny-entry.d.ts +25 -0
  409. package/dist/read-deny-entry.js +12 -0
  410. package/dist/read-face-posture.d.ts +37 -11
  411. package/dist/read-face-posture.js +32 -3
  412. package/dist/request-key-closure.d.ts +9 -2
  413. package/dist/request-key-closure.js +11 -5
  414. package/dist/request-value-closure.d.ts +5 -0
  415. package/dist/request-value-closure.js +11 -3
  416. package/dist/rule-entry-list.d.ts +38 -11
  417. package/dist/rule-entry-list.js +106 -30
  418. package/dist/rules-consent.js +3 -4
  419. package/dist/run-acceptance.d.ts +19 -3
  420. package/dist/run-acceptance.js +13 -1
  421. package/dist/run-local.js +54 -24
  422. package/dist/runs.d.ts +15 -8
  423. package/dist/runs.js +35 -1
  424. package/dist/runtime-caps-resolver.d.ts +16 -6
  425. package/dist/runtime-caps-resolver.js +18 -5
  426. package/dist/sandbox-pkg-source.d.ts +19 -1
  427. package/dist/sandbox-pkg-source.js +29 -7
  428. package/dist/security.d.ts +87 -9
  429. package/dist/security.js +52 -9
  430. package/dist/server-secret-env.d.ts +44 -18
  431. package/dist/server-secret-env.js +49 -8
  432. package/dist/session-error-wire.d.ts +19 -2
  433. package/dist/session-error-wire.js +5 -1
  434. package/dist/session-incarnation.d.ts +15 -5
  435. package/dist/session-incarnation.js +16 -9
  436. package/dist/session-titled-frame.d.ts +33 -0
  437. package/dist/session-titled-frame.js +4 -0
  438. package/dist/session-titler.d.ts +9 -1
  439. package/dist/session-titler.js +27 -6
  440. package/dist/spec-fields.d.ts +28 -16
  441. package/dist/spec-fields.js +66 -54
  442. package/dist/sql-engine-posture.d.ts +31 -4
  443. package/dist/sql-engine-posture.js +36 -1
  444. package/dist/stored-request-tool-axes-m19.d.ts +19 -4
  445. package/dist/stored-request-tool-axes-m19.js +30 -2
  446. package/dist/task-a2a.d.ts +9 -1
  447. package/dist/task-a2a.js +73 -47
  448. package/dist/task-cwd.d.ts +1 -1
  449. package/dist/task-mcp.d.ts +46 -58
  450. package/dist/task-mcp.js +82 -107
  451. package/dist/task-settings.d.ts +95 -108
  452. package/dist/task-settings.js +77 -98
  453. package/dist/text-bidi.d.ts +1 -48
  454. package/dist/text-bidi.js +3 -5
  455. package/dist/tighten-only-seats.d.ts +150 -0
  456. package/dist/tighten-only-seats.js +196 -0
  457. package/dist/tool-approval.d.ts +304 -88
  458. package/dist/tool-approval.js +623 -239
  459. package/dist/trace/core-keyset-guard.d.ts +122 -20
  460. package/dist/trace/engine-notice-wire.d.ts +11 -3
  461. package/dist/trace/engine-notice-wire.js +8 -1
  462. package/dist/trace/exit-seat.d.ts +28 -0
  463. package/dist/trace/exit-seat.js +76 -0
  464. package/dist/trace/ledger-events.d.ts +6 -3
  465. package/dist/trace/ledger-sink.js +4 -1
  466. package/dist/trace/model-segment.js +1 -1
  467. package/dist/trace/project.d.ts +98 -17
  468. package/dist/trace/project.js +98 -50
  469. package/dist/trace/projection-table.d.ts +100 -0
  470. package/dist/trace/projection-table.js +130 -0
  471. package/dist/trace/redact.d.ts +54 -0
  472. package/dist/trace/redact.js +778 -152
  473. package/dist/trace/self-minted-wire.d.ts +345 -1
  474. package/dist/trace/self-minted-wire.js +117 -1
  475. package/dist/trace/wire-projection-faces.d.ts +377 -3
  476. package/dist/trace/wire-projection-faces.js +164 -1
  477. package/dist/url-refusal.js +2 -0
  478. package/dist/web-admin-client/apply-effective.d.ts +12 -0
  479. package/dist/web-admin-client/apply-effective.js +56 -5
  480. package/dist/web-admin-client/candidate-gate.d.ts +6 -6
  481. package/dist/web-admin-client/candidate-gate.js +3 -3
  482. package/dist/web-admin-client/facade.d.ts +1 -1
  483. package/dist/web-admin-client/facade.js +1 -1
  484. package/dist/web-admin-client/http-client.js +0 -6
  485. package/dist/web-admin-client/read-face.js +5 -9
  486. package/dist/web-admin-client/read-warnings.d.ts +13 -0
  487. package/dist/web-admin-client/read-warnings.js +10 -0
  488. package/dist/web-admin-client/skills-mcp.d.ts +3 -0
  489. package/dist/web-admin-client/skills-mcp.js +11 -9
  490. package/dist/web-admin-client/types.d.ts +2 -3
  491. package/dist/workspace-cache.d.ts +35 -0
  492. package/dist/workspace-cache.js +36 -0
  493. package/dist/workspace-space.d.ts +3 -2
  494. package/dist/workspace-space.js +2 -0
  495. package/docs/DEVICE-EXECUTOR-PROTOCOL.md +65 -10
  496. package/package.json +8 -4
  497. package/scripts/drain-check-local.mjs +34 -1
  498. package/scripts/drain-check.mysql.sql +30 -2
  499. package/scripts/drain-check.pg.sql +29 -2
  500. package/dist/capabilities/memory-notice.d.ts +0 -138
  501. package/dist/capabilities/memory-notice.js +0 -64
  502. package/dist/capabilities/prompt.d.ts +0 -17
  503. package/dist/capabilities/prompt.js +0 -6
  504. package/dist/mcp-content-origin.d.ts +0 -34
  505. package/dist/mcp-content-origin.js +0 -10
  506. package/dist/tool-axis-words.d.ts +0 -27
  507. package/dist/tool-axis-words.js +0 -9
  508. package/dist/wire-name-bound.d.ts +0 -14
  509. package/dist/wire-name-bound.js +0 -13
@@ -269,6 +269,21 @@ export class SqlRunStore {
269
269
  const { affected } = await this.db.query(this.q("UPDATE task_run SET status = 'running', cancel_requested = 0, preempt_requested = 0, result = NULL, instance_id = ?, updated_at = ? WHERE task_id = ? AND status IN ('suspended','needs_review')", "UPDATE task_run SET status = 'running', cancel_requested = 0, preempt_requested = 0, result = NULL, instance_id = $1, updated_at = $2 WHERE task_id = $3 AND status IN ('suspended','needs_review')"), [instanceId, new Date(), taskId]);
270
270
  return affected === 1;
271
271
  }
272
+ async whileHoldingClaim(sessionId, taskId, write) {
273
+ let fenced = { held: false };
274
+ await this.tx(async (conn) => {
275
+ const run = await conn.query(this.q("SELECT task_id FROM task_run WHERE task_id = ? AND status = 'running' FOR UPDATE", "SELECT task_id FROM task_run WHERE task_id = $1 AND status = 'running' FOR UPDATE"), [taskId]);
276
+ if (run.rows.length === 0)
277
+ return;
278
+ const claim = await conn.query(this.q("SELECT task_id FROM task_active WHERE session_id = ? FOR UPDATE", "SELECT task_id FROM task_active WHERE session_id = $1 FOR UPDATE"), [sessionId]);
279
+ const holder = claim.rows[0];
280
+ if (holder === undefined || String(holder.task_id) !== taskId)
281
+ return;
282
+ await conn.query(this.q("UPDATE task_run SET updated_at = ? WHERE task_id = ?", "UPDATE task_run SET updated_at = $1 WHERE task_id = $2"), [new Date(), taskId]);
283
+ fenced = { held: true, value: await write(conn) };
284
+ });
285
+ return fenced;
286
+ }
272
287
  async getActiveTaskId(sessionId) {
273
288
  const { rows } = await this.db.query(this.q("SELECT task_id FROM task_active WHERE session_id = ?", "SELECT task_id FROM task_active WHERE session_id = $1"), [sessionId]);
274
289
  return rows[0] ? String(rows[0].task_id) : undefined;
@@ -335,7 +350,10 @@ export class SqlRunStore {
335
350
  where.push("source = ?");
336
351
  params.push(opts.source);
337
352
  }
338
- if (opts.owner !== undefined) {
353
+ if (opts.owner === null) {
354
+ where.push("owner IS NULL");
355
+ }
356
+ else if (opts.owner !== undefined) {
339
357
  where.push("owner = ?");
340
358
  params.push(opts.owner);
341
359
  }
@@ -362,7 +380,9 @@ export class SqlRunStore {
362
380
  where.push(`job_id = ${p(opts.jobId)}`);
363
381
  if (opts.source !== undefined)
364
382
  where.push(`source = ${p(opts.source)}`);
365
- if (opts.owner !== undefined)
383
+ if (opts.owner === null)
384
+ where.push("owner IS NULL");
385
+ else if (opts.owner !== undefined)
366
386
  where.push(`owner = ${p(opts.owner)}`);
367
387
  if (opts.cursor) {
368
388
  const a = p(new Date(opts.cursor.createdAt));
@@ -30,9 +30,29 @@
30
30
  * information_schema 查询抛错、或整库一行都读不出来 ⇒ **拒启**。探针的语义是「我证明了库等于代码」,
31
31
  * 证不出来时放行等于把一条保护性断言静默降级成祝福([ref]:保护型缺席必须 fail-closed)。
32
32
  * `recordFailOpen` 在这条腿上**不适用** —— 它是 F 类(装饰/缓存)的登记口,不是 P 类保护臂的逃生门。
33
+ *
34
+ * ── 第二道对账:跳版升级的库带着**退役** schema(先于建表)──────────────────────────────────────
35
+ * 一次性迁移 M1–M3(7.74.0–7.125.x)删掉了整树快照索引表 `snapshot_manifest` 与单座 steering 列 `checkpoint.pending_steer`,并把账本 / 已决行里
36
+ * 旧拼法 `unresolvable` 改写成 `ancestor_marked`;三条窗关后已删码。从没在带那三条的版本上起过服的库(跳版升级)两件退役 schema 至少一件仍在 ⇒
37
+ * 旧拼法的改写同样没跑过 ⇒ {@link assertRetiredSchemaAbsent} 响亮拒启({@link RetiredSchemaPresentError},同一个拒启码 `config.schema_mismatch`),
38
+ * 点名在场的坐标与出路(先在 7.125.x 起服一次让那三条跑完,再升)。**旧拼法不另扫**:那是一条对账本 `task_event` 的无索引整表扫(全站最大的表,
39
+ * PG 池级 `statement_timeout` 会把它切成拒启、每次起服重演);两件 schema 的在场就是「这只库没经过带迁移的版本」的判据(7.74.0 之前的每一版 DDL
40
+ * 都建它们,7.74.0 起都不再建;能写下旧拼法的 7.64.0–7.71.0 恒带两者)。
41
+ * 这一道**没有窗**(跳版升级的库永远可能出现),所以它住在起服对账一族而不在一次性迁移文件里 —— 那个文件里每一条都有窗,最后一条删掉时整个文件
42
+ * 一起删、零例外。判据读本族**唯一**的列册读者 {@link readLiveColumns}(PG 读查询真正会解析到的关系,与第一道同一读法),不另造表 / 列在场探针。
43
+ * **先于一切 DDL**:唯一的读处是探针口 {@link assertRetiredSchemaAbsentOnPool},唯一的调用点是 `store-backend.ts` 里 SQL 两后端的 `ensureSchema()` 包装
44
+ * (探针先于它的第一条 CREATE)—— 一次会拒的起服不许先在库里建出几十张本版新表(`task_run` 还带着新列),否则拒句里「没动过库」就是假话,
45
+ * 按拒句指路去 7.125.x 起服的人会撞上「库比 7.125.x 新」的第二道拒。嵌入方走公开序列 `createStoreBackend()` → `ensureSchema()` → `runOneTimeMigrations()`
46
+ * 即得到这一问,零动作。
47
+ * 残余(如实):运维在第一次起带迁移的版本之前就把两件退役 schema 都手工删掉的库,残留的旧拼法由门记录的读腿接住 —— 7.129.0 起(core 7.51.0 #1731)
48
+ * 那只读腿按 core 的档案读法读,`unresolvable` 是 core 退役词注册表里的词 ⇒ 记录原词原样读回、不改写(`trace/project.ts` `screenedGate`);local 文件车道
49
+ * 没有表与列,没有这一问 —— 引擎 File 店里已决 checkpoint 的记录按契约物理不可变,本仓没有合法缝改写它们,同由那条读腿接住。
33
50
  */
51
+ import type { Pool as MysqlPool } from "mysql2/promise";
52
+ import type { Pool as PgPool } from "pg";
34
53
  import { type SchemaDialect } from "./schema-ensure-legs.js";
35
54
  import { type SchemaProbeRead } from "./schema-live-columns.js";
55
+ import { StoreBootRefusalError } from "./store-contracts.js";
36
56
  /** 一列:名字 + 它在 `CREATE TABLE` 里的**原样定义文本**(生成 ADD COLUMN 指路用,不另手写)。 */
37
57
  export interface ParsedColumn {
38
58
  readonly name: string;
@@ -73,4 +93,38 @@ export declare function describeSchemaMismatch(dialect: SchemaDialect, mismatche
73
93
  * 失败方向见文件头注:读抛 / 整库零行 ⇒ 拒。
74
94
  */
75
95
  export declare function assertSchemaMatchesCode(read: SchemaProbeRead, dialect: SchemaDialect): Promise<void>;
96
+ /**
97
+ * 跳版升级的库的拒启:退役 schema(快照索引表 / 单座列)任一仍在。**具名类型**:锚类型不锚文案(日志消费端与测试按 `code` / 类型分派);
98
+ * 码取列册对账同一个 `config.schema_mismatch`,运维面一个拒启码一个读法。拒句点名在场的坐标、说明第三条(旧拼法改写)同样没跑过、给出路。
99
+ * 继承 {@link StoreBootRefusalError}:这是一句**确定**的拒启表态(再等也等不来另一个答案)—— `ensureSchema()` 里它不被 SQL 开库的等待窗重试、不被改写成「库打不开」的拒句。
100
+ */
101
+ export declare class RetiredSchemaPresentError extends StoreBootRefusalError {
102
+ readonly found: readonly string[];
103
+ /** 机读码(与列册对账的拒启同一个)。 */
104
+ readonly code = "config.schema_mismatch";
105
+ constructor(found: readonly string[]);
106
+ }
107
+ /**
108
+ * 退役 schema 的判据(纯读,**唯一一只**;规则见文件头「第二道对账」一节):经列册读者 {@link readLiveColumns} 读一次库里的列集,
109
+ * 快照索引表 / 单座列任一在场 ⇒ 抛 {@link RetiredSchemaPresentError}。新库(建表之前一列都没有)⇒ 不在场、过。读抛 ⇒ 原样上抛(拒启;不是确定的拒启表态,
110
+ * 开库等待窗照常重试 —— 与修前两条目录探针抛出时同一个去向)。
111
+ */
112
+ export declare function assertRetiredSchemaAbsent(read: SchemaProbeRead, dialect: SchemaDialect): Promise<void>;
113
+ /** 探针口的池参数:方言与它的池一起走(判别联合 ⇒ 不靠调用方断言「这个池是哪种」)。 */
114
+ export type RetiredSchemaProbeTarget = {
115
+ readonly dialect: "tidb";
116
+ readonly pool: MysqlPool;
117
+ } | {
118
+ readonly dialect: "pg";
119
+ readonly pool: PgPool;
120
+ };
121
+ /**
122
+ * **探针口**(退役 schema 唯一的读处):库一连上、**任何 DDL 之前**在一条借来的连接上读一遍,在场 ⇒ 抛 {@link RetiredSchemaPresentError}。本仓唯一调用点 =
123
+ * `store-backend.ts` 的 `withRetiredSchemaProbe`(SQL 两后端的 `ensureSchema()` 自身:探针先于建表的先后只写在那一处)。**不在包根上**:
124
+ * 嵌入方经公开序列的 `ensureSchema()` 得到这一问,不需要自己排序列。
125
+ *
126
+ * 不取 `ensureSchema` 那把 advisory 锁:本口纯读(列册读),不改任何东西,与别的副本正在跑的建表 / 迁移互不相干 —— 退役 schema 只会被 7.125.x 的迁移删去、
127
+ * 不会被谁凭空建回。用完即还连接,拒启时连接也已归还。
128
+ */
129
+ export declare function assertRetiredSchemaAbsentOnPool(target: RetiredSchemaProbeTarget): Promise<void>;
76
130
  //# sourceMappingURL=schema-consistency.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import { recordEnsureStatements } from "./schema-ensure-legs.js";
2
2
  import { readLiveColumns } from "./schema-live-columns.js";
3
+ import { StoreBootRefusalError } from "./store-contracts.js";
3
4
  const QUOTES = new Set(["'", '"', "`"]);
4
5
  function stripLineComments(sql) {
5
6
  let out = "";
@@ -159,4 +160,55 @@ export async function assertSchemaMatchesCode(read, dialect) {
159
160
  if (mismatches.length > 0)
160
161
  throw new Error(describeSchemaMismatch(dialect, mismatches));
161
162
  }
163
+ const RETIRED_SNAPSHOT_TABLE = "snapshot_manifest";
164
+ const RETIRED_STEER_SEAT = { table: "checkpoint", column: "pending_steer" };
165
+ export class RetiredSchemaPresentError extends StoreBootRefusalError {
166
+ found;
167
+ code = SCHEMA_MISMATCH_ERROR_CODE;
168
+ constructor(found) {
169
+ super(`${SCHEMA_MISMATCH_ERROR_CODE}: this database still carries schema that the one-time migrations of server 7.74.0–7.125.x retired — refusing to start. ` +
170
+ `Found: ${found.join("; ")}. ` +
171
+ `Both come from builds that predate those migrations, so this database never booted a build that still carried them — which also means the third one never ran: ` +
172
+ `ask-origin gates stored under the retired spelling \`unresolvable\` (in task_event.data and in checkpoint.execution_outcome) were not rewritten to \`ancestor_marked\`. ` +
173
+ `This build carries none of the three and will not guess. ` +
174
+ `Way out: start a server 7.125.x build once against this database and let its one-time migrations finish (it drops the table and the column and rewrites the spelling; ` +
175
+ `while the column still holds a steering instruction that can be delivered it refuses and names the rows and its own ways out), then upgrade to this build. ` +
176
+ `On PostgreSQL this check reads the relation an unqualified name resolves to along search_path, while the 7.125.x migrations look only at current_schema(): ` +
177
+ `if the table or the checkpoint table carrying the column lives in a schema later on search_path, run the 7.125.x build with that schema first on its search_path ` +
178
+ `(for example ALTER ROLE <role> SET search_path = <that schema>, <the rest>), then restore the search_path and start this build. ` +
179
+ `The check behind this refusal is read-only and runs before this build creates any table or rewrites anything: it changed nothing in the database.`);
180
+ this.found = found;
181
+ this.name = "RetiredSchemaPresentError";
182
+ }
183
+ }
184
+ export async function assertRetiredSchemaAbsent(read, dialect) {
185
+ const live = await readLiveColumns(read, dialect);
186
+ const found = [];
187
+ if (live.has(RETIRED_SNAPSHOT_TABLE))
188
+ found.push(`table ${RETIRED_SNAPSHOT_TABLE} (the retired whole-tree snapshot index)`);
189
+ if (live.get(RETIRED_STEER_SEAT.table)?.has(RETIRED_STEER_SEAT.column) === true) {
190
+ found.push(`column ${RETIRED_STEER_SEAT.table}.${RETIRED_STEER_SEAT.column} (the retired single-seat steering column)`);
191
+ }
192
+ if (found.length > 0)
193
+ throw new RetiredSchemaPresentError(found);
194
+ }
195
+ export async function assertRetiredSchemaAbsentOnPool(target) {
196
+ if (target.dialect === "tidb") {
197
+ const conn = await target.pool.getConnection();
198
+ try {
199
+ await assertRetiredSchemaAbsent(async (sql) => (await conn.query(sql))[0], "mysql");
200
+ }
201
+ finally {
202
+ conn.release();
203
+ }
204
+ return;
205
+ }
206
+ const client = await target.pool.connect();
207
+ try {
208
+ await assertRetiredSchemaAbsent(async (sql) => (await client.query(sql)).rows, "pg");
209
+ }
210
+ finally {
211
+ client.release();
212
+ }
213
+ }
162
214
  //# sourceMappingURL=schema-consistency.js.map
@@ -21,6 +21,8 @@ export const CENTRAL_SCHEMA_INDEXES = [
21
21
  { table: "workflow_run", name: "idx_wfrun_scope_created", columns: ["scope", "created_at_ms"] },
22
22
  { table: "workflow_run", name: "idx_wfrun_scope_status", columns: ["scope", "status"] },
23
23
  { table: "workflow_agent_session", name: "idx_wfagentsess_run", columns: ["run_id"] },
24
+ { table: "workflow_park_decision", name: "idx_wfparkdec_host", columns: ["host_session_id"] },
25
+ { table: "workflow_park_decision", name: "idx_wfparkdec_run", columns: ["run_id"] },
24
26
  { table: "workflow_completion_inbox", name: "idx_wfinbox_session_seq", columns: ["session_id", "seq"] },
25
27
  { table: "workflow_inbox_fence", name: "idx_wffence_until", columns: ["until_ms"] },
26
28
  { table: "workflow_notify_journal", name: "idx_wfnotify_acked", columns: ["acked"] },
@@ -1,6 +1,6 @@
1
1
  import { createHmac } from "node:crypto";
2
2
  import { uuidv7 } from "@sema-agent/core";
3
- import { CONTROL_AND_BIDI_STRIP_RE } from "../text-bidi.js";
3
+ import { stripControlAndBidi } from "@sema-agent/settings-schema";
4
4
  import { presignS3CopyUrl, presignS3Url } from "./s3-presign.js";
5
5
  import { OBJECT_STORE_IO_TIMEOUT_MS } from "./blob-backend.js";
6
6
  export const PRESIGN_MAX_TTL_SEC = 604_800;
@@ -11,7 +11,7 @@ export function scopeSegment(secretKey, scope) {
11
11
  }
12
12
  export function sanitizeSendFileName(name) {
13
13
  const base = (name ?? "").split(/[/\\]/).pop() ?? "";
14
- let clean = base.replace(CONTROL_AND_BIDI_STRIP_RE, "").replace(/^\.+/, "").trim();
14
+ let clean = stripControlAndBidi(base).replace(/^\.+/, "").trim();
15
15
  if (clean.length > 128) {
16
16
  const dot = clean.lastIndexOf(".");
17
17
  const ext = dot > 0 && clean.length - dot <= 16 ? clean.slice(dot) : "";
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The prompt-epoch anchor below a bounded window's floor — `SessionStorage.getEpochAnchor()` for every session storage that
3
+ * loads a window instead of the whole tree: the two SQL session backends (`tidb-session-storage.ts` / `pg-session-storage.ts`,
4
+ * the run's wake and the session view alike) and the local leg's session view (`local-session-window.ts`). One reading, three
5
+ * dialects: each storage hands in only its own page and reads its own rows.
6
+ *
7
+ * ## The rule: the store carries the record, the engine reads it
8
+ * A bounded wake loads `[floor .. leaf]`; when the loaded branch holds no epoch carrier (a rewind cut inside the kept
9
+ * tail, or compactions written before the engine restated the epoch), the engine's `Session.getPromptEpoch()` asks the
10
+ * storage for the nearest carrier BELOW the floor and reads it itself. The storage returns that record **as stored**:
11
+ * · a `prompt_epoch` entry ⇒ the whole entry (the engine's branch walk reads the whole entry too);
12
+ * · a compaction whose `details.promptEpoch` is present ⇒ that restatement;
13
+ * · a compaction without a restatement carries nothing ⇒ the scan pages past it, to exhaustion (a session that lived
14
+ * across the release that introduced epochs can hold any number of them between the floor and its pin).
15
+ * The storage never judges the record's shape. The engine answers a current-shape record as a pin and a retired-shape
16
+ * record by name (`legacy`, with whether it pinned a center artifact) — a storage that normalized the record first would
17
+ * turn a session pinned under a retired shape into one with no pin, and the engine would then skip the center source's
18
+ * handling of that pin. A record that is neither is the engine's to read as well (it reads as no record).
19
+ *
20
+ * `floorSeq <= 0` (a full load: the walk already reaches the root) or no carrier below the floor ⇒ `undefined`
21
+ * (a session that predates epochs).
22
+ *
23
+ * What "below the floor, newest first" walks is the storage's: the SQL twins page their `session_event` rows by `seq` (their
24
+ * window is cut by `seq` too); the local window pages the branch path it was cut from.
25
+ */
26
+ import type { SessionTreeEntry } from "@sema-agent/core";
27
+ /** One row of a scan: its position (`seq`, the keyset cursor). What else the row holds is the storage's — it reads the entry
28
+ * out of the row itself ({@link scanEpochAnchor}'s `entryOf`), so a row is read only when the scan reaches it. */
29
+ export interface EpochAnchorRow {
30
+ readonly seq: string | number;
31
+ }
32
+ /**
33
+ * Page the rows `seq < beforeSeq` that may carry an epoch record, newest first (an empty page = no older row). A page may hold
34
+ * other rows too — they carry nothing and the scan passes them.
35
+ */
36
+ export type EpochAnchorPage<R extends EpochAnchorRow> = (beforeSeq: number) => Promise<readonly R[]>;
37
+ /** The nearest epoch carrier below `floorSeq`, as stored; see the file header. */
38
+ export declare function scanEpochAnchor<R extends EpochAnchorRow>(floorSeq: number, page: EpochAnchorPage<R>, entryOf: (row: R) => SessionTreeEntry): Promise<unknown>;
39
+ //# sourceMappingURL=session-epoch-anchor.d.ts.map
@@ -0,0 +1,22 @@
1
+ export async function scanEpochAnchor(floorSeq, page, entryOf) {
2
+ if (floorSeq <= 0)
3
+ return undefined;
4
+ let cursor = floorSeq;
5
+ for (;;) {
6
+ const rows = await page(cursor);
7
+ if (rows.length === 0)
8
+ return undefined;
9
+ for (const row of rows) {
10
+ const entry = entryOf(row);
11
+ if (entry.type === "prompt_epoch")
12
+ return entry;
13
+ if (entry.type === "compaction") {
14
+ const details = entry.details;
15
+ if (typeof details === "object" && details !== null && "promptEpoch" in details && details.promptEpoch !== undefined)
16
+ return details.promptEpoch;
17
+ }
18
+ }
19
+ cursor = Number(rows[rows.length - 1].seq);
20
+ }
21
+ }
22
+ //# sourceMappingURL=session-epoch-anchor.js.map
@@ -1,6 +1,8 @@
1
1
  import { type SessionStore } from "@sema-agent/core";
2
2
  import type { ServiceConfig } from "../config-types.js";
3
3
  import type { StoreBackend } from "./store-backend.js";
4
+ import { type DelegationRootWitness, type DelegationTree, type OrphanOwnerLog } from "../delegated-session-owner.js";
5
+ import type { OwnerAwareSessionStore } from "../security.js";
4
6
  /**
5
7
  * Session-store plugin seam.
6
8
  *
@@ -43,15 +45,23 @@ export declare function ensureSessionDurable(hostStore: SessionStore, sessionId:
43
45
  * [ref] 主动晋升版 ensureChildSessionDurable(cli TiDB 真机撞获:1.263 的只查不迁形在拆店生产形下
44
46
  * 恒否决 park——bg 子会话住 subRunner 私有 TTL 店、从不在 host 店,core 收 veto 即 expire checkpoint
45
47
  * (14ms~2s)+ settle failed,赎回窗口不存在):
46
- * 1. 快路:已在 host 店且有真内容 → 直接通过(幂等/重入)。
48
+ * 0. 属主(S-1770,`delegated-session-owner.ts`):按委派继承律判一次(唯一判据 `judgeDelegatedOwner`)—— 来源集 = 见证的根这一只(调用方交出的委派树根 + 调用方判断那一刻
49
+ * 读到的根行住客:请求腿 = 本请求经鉴权解析的会话与受理时那一读,`/decide` 赎回腿 = 行上的 `rootSessionId` 与 claim 前后两读的那一位;core 的挂点签名只给子代 id,
50
+ * 场景层把见证绑进闭包交下来)。此刻根行在而住客不是见证的那一位(删了、同 id 被重新登记)⇒ **拒**(`assertRootStillWitnessed`:不按新住客晋升 / 认领);
51
+ * 缺席(行上没有根)或根行此刻不在 ⇒ 孤行哨兵。
52
+ * 1. 快路:已在 host 店且有真内容 → 通过,**前提是那一行的属主按律定得下来**(`settleDelegatedOwner`:记着别的委派树 ⇒ 抛;记着这一棵 ⇒ 按它记录的根、父再判一次
53
+ * (与 M23 同读数),无主 ⇒ 认领(CAS 子行,写判断时的读数)、没落下 ⇒ 抛(只有记录委派树的 SQL 店;local 店的行不记委派树 ⇒ 不认领);此刻属主不是律给的那一只 ⇒ 那是别人的同 id 会话,
54
+ * 不是这只子代的转录 ⇒ 抛 = 停驻否决;与晋升建行前那一道同一只函数)。
47
55
  * 2. 晋升:routing.promoteToHost 把子会话整树从私店拷进 host 店(拷贝→私店 forget→路由记 host,
48
- * 三步见 ForkRoutingSessionStore.promoteToHost)。
49
- * 3. 复验:同一把 `ensureSessionDurable` 严检(leaf 非空)——晋升产物必须达到与既有校验完全相同的
50
- * durable 标准,任何一步失败=如实 reject=veto=pre-153 行为(不放大)。
56
+ * 三步见 ForkRoutingSessionStore.promoteToHost),宿主行在建行那一笔里带第 0 步的属主;写的是哨兵 ⇒ 写落下之后一行 warn。
57
+ * 3. 复验:同一把 `ensureSessionDurable` 严检(leaf 非空)+ 同一只属主定夺 —— 晋升产物必须达到与快路完全相同的
58
+ * 标准,任何一步失败=如实 reject=veto=pre-153 行为(不放大)。
59
+ * 宿主店必须读得出属主(`delegatedOwnerHostOf`:`ownerOf` + `sessionFaceOf`;记录委派树的店另交 `placementOf` + `claimOwnerless`,两只同在或同缺;生产的 SQL / local 店与缓存包装层都满足),
60
+ * 否则响亮拒。
51
61
  * 调用方纪律与 {@link ensureSessionDurable} 同款:hostStore 必须是 release 非破坏性的真 durable 店
52
- * (main.ts 的 `config.sessionBackend === "tidb"` 门不变)。
62
+ * (stage-07 的 `config.sessionBackend === "tidb"` 门不变 —— 该词在 local 后端上同样归一成 `tidb`,所以本腿在 local 宿主店上也跑)。
53
63
  */
54
- export declare function ensureChildSessionDurableWithPromotion(hostStore: SessionStore, routing: {
55
- promoteToHost(sessionId: string): Promise<void>;
56
- }, sessionId: string): Promise<void>;
64
+ export declare function ensureChildSessionDurableWithPromotion(hostStore: OwnerAwareSessionStore, routing: {
65
+ promoteToHost(sessionId: string, owner: string | null, tree: DelegationTree): Promise<void>;
66
+ }, sessionId: string, root: DelegationRootWitness | undefined, log: OrphanOwnerLog): Promise<void>;
57
67
  //# sourceMappingURL=session-store.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import { TtlSessionStore } from "@sema-agent/core";
2
2
  import { CachingSessionStore } from "./caching-session-store.js";
3
+ import { assertRootStillWitnessed, delegatedOwnerHostOf, readDelegatedOwner, reportWrittenOwner, settleDelegatedOwner, sourceFacesVia, } from "../delegated-session-owner.js";
3
4
  export function createSessionStore(config, backend, metrics) {
4
5
  if (config.sessionBackend === "tidb") {
5
6
  if (!backend)
@@ -22,14 +23,24 @@ export async function ensureSessionDurable(hostStore, sessionId) {
22
23
  await hostStore.forget?.(acquired.sessionId);
23
24
  }
24
25
  }
25
- export async function ensureChildSessionDurableWithPromotion(hostStore, routing, sessionId) {
26
+ export async function ensureChildSessionDurableWithPromotion(hostStore, routing, sessionId, root, log) {
27
+ const host = delegatedOwnerHostOf(hostStore);
28
+ if (host === undefined) {
29
+ throw new Error(`session "${sessionId}" cannot be parked: the host session store cannot read a session's owner (ownerOf / sessionFaceOf), or records delegation trees without being able to claim under them (placementOf / claimOwnerless), so the delegated transcript's owner cannot be derived or checked`);
30
+ }
31
+ const judged = await readDelegatedOwner(sessionId, root === undefined ? {} : { rootSessionId: root.sessionId }, sourceFacesVia(host.sessionFaceOf));
32
+ assertRootStillWitnessed(sessionId, root, judged);
33
+ let promoted = false;
26
34
  try {
27
35
  await ensureSessionDurable(hostStore, sessionId);
28
- return;
29
36
  }
30
37
  catch {
38
+ await routing.promoteToHost(sessionId, judged.inherited.owner, judged.tree);
39
+ await ensureSessionDurable(hostStore, sessionId);
40
+ promoted = true;
31
41
  }
32
- await routing.promoteToHost(sessionId);
33
- await ensureSessionDurable(hostStore, sessionId);
42
+ const settled = await settleDelegatedOwner(host, sessionId, judged.inherited.owner, judged.tree);
43
+ if (promoted || settled.claimed)
44
+ reportWrittenOwner(log, "promotion", sessionId, settled.judged ?? judged);
34
45
  }
35
46
  //# sourceMappingURL=session-store.js.map
@@ -125,12 +125,18 @@ export interface SqlSharedMemoryStoreOptions {
125
125
  * hope (core puts no cap on the provider's window, so the provider must state its own). */
126
126
  maxListLimit?: number;
127
127
  }
128
+ /**
129
+ * WRITE-side store-id admission. The rule is core's own judge ({@link isSharedMemoryStoreId}): a row failing it would be dropped
130
+ * from every listing — an id the model cannot echo back is worse than an absent one — so we refuse to store it in the first place.
131
+ * This module keeps no copy of the pattern (nor of the `__` ban): the protocol table's namespace separator is core's to spell.
132
+ */
128
133
  export declare function assertStoreId(storeId: string): void;
129
134
  export declare function assertScopeKey(scopeKey: string): void;
130
135
  /**
131
- * WRITE-side document-path admission. Deliberately at least as strict as core's READ-side listing gate
132
- * (`isListablePath`): a row core would silently drop is refused here where an operator can see it. The
133
- * ONE rule that is stricter on purpose is the non-BMP refusal — see the header's ORDERING section.
136
+ * WRITE-side document-path admission: core's own judge ({@link isSharedMemoryDocumentPath} — the SAME predicate core's listing
137
+ * gate applies, so a row core would silently drop is refused here where an operator can see it), plus the two rules that are
138
+ * stricter on purpose and are this store's own: the column width, and the non-BMP refusal — see the header's ORDERING section.
139
+ * This module keeps no copy of core's rule (forbidden characters, segment shape, suffix table).
134
140
  */
135
141
  export declare function assertDocumentPath(path: string): void;
136
142
  /**
@@ -1,20 +1,17 @@
1
- import { SHARED_MEMORY_READ_CAP_BYTES, SharedMemoryStoreError, } from "@sema-agent/core";
1
+ import { isSharedMemoryDocumentPath, isSharedMemoryStoreId, SHARED_MEMORY_READ_CAP_BYTES, SharedMemoryStoreError, } from "@sema-agent/core";
2
2
  import { mysqlDriver, pgDriver } from "./sql-driver.js";
3
3
  import { isDupKeyError } from "./sql-errors.js";
4
4
  const isDupKey = isDupKeyError;
5
5
  export const SHARED_MEMORY_SCOPE_TABLE = "shared_memory_scope";
6
6
  export const SHARED_MEMORY_STORE_TABLE = "shared_memory_store";
7
7
  export const SHARED_MEMORY_ENTRY_TABLE = "shared_memory_entry";
8
- const STORE_ID_RE = /^[A-Za-z0-9_.-]{1,64}$/;
9
8
  const ORG_SCOPE_RE = /^org:\S{1,185}$/;
10
- const FORBIDDEN_PATH_CHARS = /[\p{Cc}\p{Cf}\p{Co}\p{Cn}\p{Default_Ignorable_Code_Point}\u2028\u2029\\]/u;
11
- const DOCUMENT_SUFFIXES = [".md", ".txt", ".json", ".jsonl"];
12
9
  const PATH_MAX_CHARS = 512;
13
10
  const DESCRIPTION_MAX_CHARS = 512;
14
11
  const DEFAULT_MAX_LIST_LIMIT = 500;
15
12
  export function assertStoreId(storeId) {
16
- if (!STORE_ID_RE.test(storeId) || storeId.includes("__")) {
17
- throw new Error(`shared-memory store id ${JSON.stringify(storeId)} is not usable: it must match /^[A-Za-z0-9_.-]{1,64}$/ and must not contain "__"`);
13
+ if (!isSharedMemoryStoreId(storeId)) {
14
+ throw new Error(`shared-memory store id ${JSON.stringify(storeId)} is not usable: core's shared-memory store-id rule refuses it`);
18
15
  }
19
16
  }
20
17
  export function assertScopeKey(scopeKey) {
@@ -26,18 +23,10 @@ export function assertDocumentPath(path) {
26
23
  const refuse = (why) => {
27
24
  throw new Error(`shared-memory document path ${JSON.stringify(path)} is not usable: ${why}`);
28
25
  };
29
- if (!path.startsWith("/"))
30
- refuse("it must be absolute (leading \"/\")");
31
26
  if (path.length > PATH_MAX_CHARS)
32
27
  refuse(`it is ${path.length} UTF-16 units, over the ${PATH_MAX_CHARS} the column stores`);
33
- if (FORBIDDEN_PATH_CHARS.test(path))
34
- refuse("it carries a control/format/private-use character or a backslash");
35
- const segments = path.slice(1).split("/");
36
- if (!segments.every((s) => s !== "" && !s.startsWith(".")))
37
- refuse("every folder segment must be non-empty and must not start with \".\"");
38
- const last = segments.at(-1);
39
- if (last === undefined || !DOCUMENT_SUFFIXES.some((s) => last.endsWith(s)))
40
- refuse(`the filename must end in ${DOCUMENT_SUFFIXES.join(", ")}`);
28
+ if (!isSharedMemoryDocumentPath(path))
29
+ refuse("core's shared-memory document-path rule refuses it");
41
30
  for (const ch of path) {
42
31
  if (ch.codePointAt(0) > 0xffff)
43
32
  refuse("it carries a supplementary-plane character, which would make SQL ordering and core's UTF-16 cursor ordering disagree");