@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
@@ -12,18 +12,40 @@
12
12
  * (`RunRegistry` / `RouteHelpers` / `RouteLegs` / `ReturnType<typeof createRequestGuards>`),不手抄签名 ⇒ 不会漂。
13
13
  */
14
14
  import type { IncomingMessage } from "node:http";
15
- import { CheckpointError, type QuestionAnswer, type CheckpointToken } from "@sema-agent/core";
15
+ import { CheckpointError, type QuestionAnswer, type CheckpointToken, type PendingSteerInput } from "@sema-agent/core";
16
16
  import type { DecideBinding, DecidedAction } from "./wire-types.js";
17
17
  import type { CheckpointStoreFull } from "../plugins/store-backend.js";
18
18
  import type { HostDecision } from "../host-decision.js";
19
19
  import { type GateSighting } from "../approval-gate-currency.js";
20
20
  import { type PlanApprovePermissionModeAfter } from "../task-settings.js";
21
- import type { RouteCtxBase, DriveResumeArgs, PreparedPlanReview, ResumeLegOutcome, WorkflowDecisionDelivery } from "./route-ctx.js";
21
+ import type { RouteCtxBase, DriveResumeArgs, PreparedPlanReview, RememberSessionRequest, ResumeCheckpointOutcome, ResumeLegOutcome, WorkflowDecisionDelivery } from "./route-ctx.js";
22
22
  import type { RunRegistry, RouteHelpers, RouteLegs } from "./route-ctx.js";
23
23
  import type { createRequestGuards } from "./request-guards.js";
24
24
  import type { FlatServiceDeps } from "./server.js";
25
25
  import { type ResumeRefusalAnswer } from "./checkpoint-ctx.js";
26
26
  import { type ResumeRestatement } from "./resume-restatement.js";
27
+ /**
28
+ * 🔴 **resume / 决断腿上一次 `CheckpointError` 拒的处置 —— 一张表:core 的码闭集 → 处置词**(唯一读口 {@link resumeRefusalDisposition};
29
+ * 7.113.0 提货车 UP ⑤ 起穷举,此前是 catch 臂里一串 `e.code === … ||` 手列)。
30
+ *
31
+ * doctrine(只写这一次):处置词说的是**这张卡与这条 run 行此刻的处境**,不是「重试会不会成」——
32
+ * · `retriable` —— PRE-CAS 拒:**卡仍 pending ⇒ run 行重新 park**(`suspended` / `needs_review`),wire 体自述 `retriable:true`
33
+ * (契约附录 A.1 注的定义:「卡仍 pending,不是『重试会成功』」)。出路(改那一格 / 重取坐标 / 回到写它的那一版引擎 / 换对 worker / 取消)
34
+ * 由码、`field`、`writerVersion` / `readerVersion` 与报文说,**不由 `retriable` 说**;
35
+ * · `terminal` —— 卡已消费 / 已不在 / 本腿读不懂 ⇒ 驱行终局,wire 体不带 `retriable`;
36
+ * · `cancelled` —— 取消 ⇒ 取消终局。
37
+ * 行的落点与 wire 的 `retriable` 读**同一次**求值(catch 臂一处),所以同一处境只有一个答案。决断口 409 的成因({@link decisionRefusalCauseOf})只决定码名、
38
+ * 不另答处置:决断类三词都出自 `checkpoint.invalid_outcome`,落点读本表那一行。「停驻行的格式比本引擎新」只有 core 一个来源(`checkpoint.unsupported_version`
39
+ * + `version_newer` ⇒ `retriable`);续跑上下文的写者版本只让那一码的 409 体多带 `writerVersion` / `readerVersion` 两件事实,不参与判处置。
40
+ * 同码多铸点、可恢复性不同的码再按它自己的判别位闭集分(`"by_reason"` → {@link WORKER_SWAP_REDEEMABLE})。
41
+ * 表是 `Record<CheckpointError["code"], …>` ⇒ core 加一个码而本表没跟 = **tsc 红**(手列串的病:新码不在串里 ⇒ 静默落终局 —— core 7.39.0 的
42
+ * `checkpoint.config_refused` 提货当拍就是这样把一张 pending 卡孤儿化的,钉 `test/durable-resume-http.test.ts` [ref] 两格)。
43
+ *
44
+ * 驱终局为什么危险(原 catch 臂注,D-1 / core 1.101):PRE-CAS 拒时卡仍 pending,驱终局会释放 task_active 并孤儿化那张卡(下一次 /decide → 404);
45
+ * re-park 让改正后的重试能再认领。驱终局只给「卡已消费或已不在」的码,免得留一条僵尸 `running` 行让 reapStale 误标并攥着会话锁 ~runStaleSec。
46
+ */
47
+ export type CheckpointErrorDispositionWord = "cancelled" | "retriable" | "terminal" | "by_reason";
48
+ export declare const CHECKPOINT_ERROR_DISPOSITION: Readonly<Record<CheckpointError["code"], CheckpointErrorDispositionWord>>;
27
49
  /**
28
50
  * 🔴 **一次 `CheckpointError` 拒的处置 —— 唯一读口**:{@link CHECKPOINT_ERROR_DISPOSITION} 的读法(doctrine 在那张表头)。resume 腿的 catch 臂只调它一次,
29
51
  * 行的落点与 wire 的 `retriable` 都读这一个结果。纯函数,钉直接调。运行期遇到表外的码(装树 core 比本二进制多一个码的版本偏斜 —— 型面上拼不出来)
@@ -53,13 +75,10 @@ export declare function createResumeLegs(ctx: {
53
75
  runnerFor: FlatServiceDeps["runnerFor"];
54
76
  } & RunRegistry & RouteHelpers & Pick<RouteLegs, "prepareSpec" | "finalizeTaskResult"> & Pick<ReturnType<typeof createRequestGuards>, "ownerCostQuotaDenied" | "ownerFleetLeaseDenied" | "usageWindowDenialFor">): {
55
77
  routeCtxBase: RouteCtxBase;
56
- resumeCheckpoint: (sessionId: string, decision: "approve" | "deny", reason: string | undefined, hostDecision: HostDecision, req: IncomingMessage | undefined, answer: QuestionAnswer | undefined, binding: DecideBinding, onResumeCommitted?: (grant: {
57
- overrideSessionId?: string;
58
- rememberableToolName: string | null;
59
- }) => Promise<void>, acceptEarly?: boolean, decider?: {
78
+ resumeCheckpoint: (sessionId: string, decision: "approve" | "deny", reason: string | undefined, hostDecision: HostDecision, req: IncomingMessage | undefined, answer: QuestionAnswer | undefined, binding: DecideBinding, remember?: RememberSessionRequest, acceptEarly?: boolean, decider?: {
60
79
  principal?: string;
61
80
  explicitOperator: boolean;
62
- }, restatement?: ResumeRestatement) => Promise<ResumeLegOutcome>;
81
+ }, restatement?: ResumeRestatement) => Promise<ResumeCheckpointOutcome>;
63
82
  driveResumeIntoRunLog: (args: DriveResumeArgs) => Promise<ResumeLegOutcome>;
64
83
  driveResumeLeg: (args: DriveResumeArgs, onAccepted?: (receipt: {
65
84
  status: number;
@@ -74,14 +93,14 @@ export declare function createResumeLegs(ctx: {
74
93
  explicitOperator: boolean;
75
94
  }, restatement?: ResumeRestatement) => Promise<ResumeLegOutcome>;
76
95
  startFreshHostTurn: (sessionId: string, objective: string, principal: string | undefined, req: IncomingMessage, workflowDecision: WorkflowDecisionDelivery, runId: string, restatement?: ResumeRestatement) => Promise<ResumeLegOutcome>;
77
- resumeWake: (sessionId: string, message: string | undefined, caller: string | undefined, req: IncomingMessage | undefined, acceptEarly?: boolean, workflowDecision?: WorkflowDecisionDelivery, ownerLeaseAdmittedFor?: string, restatement?: ResumeRestatement) => Promise<ResumeLegOutcome>;
96
+ resumeWake: (sessionId: string, message: PendingSteerInput | undefined, caller: string | undefined, req: IncomingMessage | undefined, acceptEarly?: boolean, workflowDecision?: WorkflowDecisionDelivery, ownerLeaseAdmittedFor?: string, restatement?: ResumeRestatement) => Promise<ResumeLegOutcome>;
78
97
  preparePlanReview: (sessionId: string, log?: {
79
98
  taskId?: string;
80
99
  principalPresent?: boolean;
81
100
  }, decider?: {
82
101
  principal?: string;
83
102
  explicitOperator: boolean;
84
- }, sighting?: GateSighting) => Promise<{
103
+ }, sighting?: GateSighting, restatement?: ResumeRestatement) => Promise<{
85
104
  readonly ok: false;
86
105
  readonly answer: {
87
106
  status: number;
@@ -91,7 +110,7 @@ export declare function createResumeLegs(ctx: {
91
110
  readonly ok: true;
92
111
  readonly prepared: PreparedPlanReview;
93
112
  }>;
94
- drivePlanReview: (prepared: PreparedPlanReview, decision: "approve" | "edit" | "reject", editedPlan: string | undefined, reason: string | undefined, hostDecision: HostDecision, req: IncomingMessage | undefined, acceptEarly?: boolean, permissionModeAfter?: PlanApprovePermissionModeAfter, restatement?: ResumeRestatement) => Promise<ResumeLegOutcome>;
113
+ drivePlanReview: (prepared: PreparedPlanReview, decision: "approve" | "edit" | "reject", editedPlan: string | undefined, reason: string | undefined, hostDecision: HostDecision, req: IncomingMessage | undefined, acceptEarly?: boolean, permissionModeAfter?: PlanApprovePermissionModeAfter) => Promise<ResumeLegOutcome>;
95
114
  sessionNotifyDoor: import("../session-notify-door.js").SessionNotifyDoor;
96
115
  };
97
116
  //# sourceMappingURL=resume-legs.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { redactErrorMessage, redactHead } from "../observability/run-terminal.js";
2
2
  import { createHash } from "node:crypto";
3
- import { uuidv7, resumeWithVerification, CheckpointError, defaultTaskRegistry, taskNotificationDedupKey, validatePendingSteer, GLOBAL_USAGE_KEY } from "@sema-agent/core";
3
+ import { uuidv7, resumeWithVerification, CheckpointError, judgeCheckpointRow, defaultTaskRegistry, taskNotificationDedupKey, validatePendingSteer, GLOBAL_USAGE_KEY } from "@sema-agent/core";
4
4
  import { decideParkedAgent, denyWorkflowParkForked, denyWorkflowParksUnreadable, findParkOrigin, heldWorkflowParkDecisions, planWorkflowParkedDecide } from "../parked-decide.js";
5
5
  import { parkDecisionFingerprint } from "../orchestration/workflow-park-decision.js";
6
6
  import { headReadOf } from "../session-incarnation.js";
@@ -22,12 +22,12 @@ import { approverFacingArgs, createApprovalCardEmitter, declaredApprovalFrameFam
22
22
  import { buildCheckpointAnchorHash } from "../approval-ask-audit-store.js";
23
23
  import { APPROVAL_ENDING_CAUSES } from "../approval-deny-reasons.js";
24
24
  import { serviceVersion } from "../service-version.js";
25
- import { TERMINAL_PARK_GATE_KINDS } from "../plugins/checkpoint-store-sql.js";
25
+ import { TERMINAL_PARK_GATE_KINDS, UnreadableCheckpointRowError } from "../plugins/checkpoint-store-face.js";
26
26
  import { withPrincipal } from "../observability/principal-context.js";
27
27
  import { withModelReachScope } from "../model-reach-scope.js";
28
28
  import { legFactsOf } from "../leg-facts.js";
29
29
  import { createInstructionSelectionLeg } from "../instruction-selection.js";
30
- import { modelTextEventData, appendParkRow, turnEndEventData, contextUsageEventData, toolStartEventData, toolEndEventData, taskProgressEventData, taskStartedEventData, taskNotificationEventData, compactedEventData, diagnosticsEventData, brainStatusEventData, steeringInjectedEventData, compactionOutcomeEventData, compactionStartedEventData, workspaceChangedEventData, wiringManifestEventData, toolRosterDeltaEventData, toolDisclosureEventData, humanInputEventData, appendModelUsageDelta, appendPromptManifest, attachModelUsage } from "../trace/project.js";
30
+ import { modelTextEventData, appendParkRow, turnEndEventData, contextUsageEventData, toolStartEventData, toolEndEventData, taskProgressEventData, taskStartedEventData, taskNotificationEventData, compactedEventData, diagnosticsEventData, brainStatusEventData, steeringInjectedEventData, compactionOutcomeEventData, compactionStartedEventData, workspaceChangedEventData, wiringManifestEventData, toolRosterDeltaEventData, toolDisclosureEventData, humanInputEventData, appendModelUsageDelta, attachModelUsage, createPromptManifestSeat } from "../trace/project.js";
31
31
  import { redactSecrets } from "../trace/redact.js";
32
32
  import { buildRunObjectivePreview } from "../user-authored-text.js";
33
33
  import { createForwardAppendFailedNote, createLedgerSink, createSerialLedgerAppend } from "../trace/ledger-sink.js";
@@ -49,13 +49,14 @@ import { createCapabilitiesLocal } from "./routes/capabilities.js";
49
49
  import { gatedPrincipal, explicitOperatorOk, runIdentityOf } from "./principal-gate.js";
50
50
  import { buildActiveRunConflict, resumeEntryForGate } from "./active-run-conflict.js";
51
51
  import { commitExecutionContext, isRootSessionGoneError, resolveExecutionContext, rootSessionAbsentAnswer, stampSpecRoot } from "./execution-context.js";
52
+ import { timeClaim } from "./claim-latency.js";
52
53
  import { commitSessionInheritEnv } from "./session-inherit-env.js";
53
54
  import { ASK_USER_QUESTION_TOOL_NAME, isApprovalGateKind, isEngineQuestionRow } from "../approval-content-kind.js";
54
55
  import { deploymentListAsks } from "../approval.js";
55
56
  import { isParkLedgerEventType } from "../trace/ledger-events.js";
56
57
  import { readResumeCtx, resumeCtxCorruptAnswer, resumeCtxUnsealableAnswer } from "./resume-ctx-read.js";
57
58
  import { objectiveWithheldIn } from "./submit-ctx.js";
58
- import { buildCheckpointVersionKeys, resumeBlockedByPolicyAnswer, resumeRefusalWithCard, sealCheckpointCtx, storedBodyReplayAnswer, storedBodyReplayLogFields, withPermissionModeRewritten } from "./checkpoint-ctx.js";
59
+ import { buildCheckpointVersionKeys, resumeAssemblyRefusalAnswer, resumeRefusalWithCard, sealCheckpointCtx, storedBodyReplayAnswer, storedBodyReplayLogFields, withPermissionModeRewritten } from "./checkpoint-ctx.js";
59
60
  import { refusalBody, resumeRefusalFacts } from "./refusal-body.js";
60
61
  import { storedBodyReplayRefusal } from "./stored-body-replay.js";
61
62
  import { restateResumeCtx } from "./resume-restatement.js";
@@ -103,7 +104,7 @@ const WORKER_SWAP_REDEEMABLE = {
103
104
  function checkpointRowRedeemableElsewhere(reason) {
104
105
  return reason !== undefined && WORKER_SWAP_REDEEMABLE[reason] === true;
105
106
  }
106
- const CHECKPOINT_ERROR_DISPOSITION = {
107
+ export const CHECKPOINT_ERROR_DISPOSITION = {
107
108
  "checkpoint.resume_aborted": "cancelled",
108
109
  "checkpoint.invalid_outcome": "retriable",
109
110
  "checkpoint.reopen_revote": "retriable",
@@ -184,13 +185,13 @@ const WIRE_CODE_OF_DECISION_REFUSAL = {
184
185
  [APPROVAL_ENDING_CAUSES.ANSWER_INVALID]: "resume_outcome_invalid",
185
186
  [APPROVAL_ENDING_CAUSES.OUTCOME_CELL_INVALID]: "resume_outcome_invalid",
186
187
  };
187
- const UNCLASSIFIED_INVALID_OUTCOME_CODE = WIRE_CODE_OF_DECISION_REFUSAL[APPROVAL_ENDING_CAUSES.BINDING_CHANGED];
188
188
  function decisionRefusalCauseOf(e, gate) {
189
- if (gate !== "policy_ask")
190
- return APPROVAL_ENDING_CAUSES.OUTCOME_CELL_INVALID;
189
+ if (e.detail?.reason !== undefined)
190
+ return undefined;
191
191
  const field = e.detail?.field;
192
- const role = field !== undefined && Object.hasOwn(CHECKPOINT_ERROR_FIELD_ROLE, field) ? CHECKPOINT_ERROR_FIELD_ROLE[field] : undefined;
193
- return role === undefined ? undefined : FIELD_ROLE_CAUSE[role];
192
+ if (field !== undefined)
193
+ return Object.hasOwn(CHECKPOINT_ERROR_FIELD_ROLE, field) ? FIELD_ROLE_CAUSE[CHECKPOINT_ERROR_FIELD_ROLE[field]] : undefined;
194
+ return gate === "policy_ask" ? undefined : APPROVAL_ENDING_CAUSES.OUTCOME_CELL_INVALID;
194
195
  }
195
196
  function notResumableAnswer() {
196
197
  return { status: 409, body: refusalBody({ errorCode: "conflict.not_resumable", message: "run is not in a resumable (suspended) state (already resumed, decided, or expired)" }) };
@@ -208,6 +209,13 @@ function approvalStaleAnswer(facts) {
208
209
  }),
209
210
  };
210
211
  }
212
+ function rowRefusalAnswer(verdict, diagnostic, ctx) {
213
+ const refusal = new CheckpointError(verdict.code, diagnostic === undefined ? verdict.sentence : `${verdict.sentence} Diagnostic: ${diagnostic}`, verdict.reason === undefined ? undefined : { reason: verdict.reason });
214
+ return checkpointRefusalAnswer(refusal, { gate: "policy_ask", retriable: resumeRefusalDisposition(refusal) === "retriable", versionKeys: refusalVersionKeys(refusal, ctx) });
215
+ }
216
+ function refusalVersionKeys(e, ctx) {
217
+ return e.code === "checkpoint.unsupported_version" ? buildCheckpointVersionKeys(ctx.writerVersion, serviceVersion()) : {};
218
+ }
211
219
  function acceptableFormFacts(detail) {
212
220
  const rewritten = detail !== null && typeof detail === "object" ? detail.editRewritten : undefined;
213
221
  if (rewritten === null || typeof rewritten !== "object" || !Object.hasOwn(rewritten, "acceptableForm"))
@@ -222,7 +230,7 @@ export function checkpointRefusalAnswer(e, at) {
222
230
  status: e.code === "checkpoint.not_found" ? 404 : 409,
223
231
  body: refusalBody({
224
232
  message: e.message,
225
- errorCode: e.code === "checkpoint.invalid_outcome" ? (refusalCause !== undefined ? WIRE_CODE_OF_DECISION_REFUSAL[refusalCause] : UNCLASSIFIED_INVALID_OUTCOME_CODE) : e.code,
233
+ errorCode: refusalCause === undefined ? e.code : WIRE_CODE_OF_DECISION_REFUSAL[refusalCause],
226
234
  facts: {
227
235
  ...(at.taskId !== undefined ? { taskId: at.taskId } : {}),
228
236
  ...resumeRefusalFacts(detail),
@@ -241,11 +249,36 @@ export function decidedActionOf(binding) {
241
249
  return missingKeys.length === 0 ? { action: { boundCallId: boundCallId, boundInputHash: boundInputHash } } : { missingKeys };
242
250
  }
243
251
  export function createResumeLegs(ctx) {
244
- const { deps, runnerFor, idemCache, inflightRuns, preemptableRuns, steerableRuns, wakeParkMints, counters, readJson, readRawBody, rateLimited, quotaExceeded, ownerQuotaDenied, leaseDenied, ownerLeaseDenied, usageWindowDenied, safeDecode, runOwnerOk, sessionOwnerOk, runSessionAcceptOk, prepareSpec, finalizeTaskResult, ownerCostQuotaDenied, ownerFleetLeaseDenied, usageWindowDenialFor } = ctx;
252
+ const { deps, runnerFor, idemCache, inflightRuns, preemptableRuns, steerableRuns, wakeParkMints, counters, readJson, readRawBody, rateLimited, quotaExceeded, ownerQuotaDenied, leaseDenied, ownerLeaseDenied, usageWindowDenied, admitRun, safeDecode, runOwnerOk, sessionOwnerOk, runSessionAcceptOk, prepareSpec, finalizeTaskResult, ownerCostQuotaDenied, ownerFleetLeaseDenied, usageWindowDenialFor } = ctx;
245
253
  const ctxOpening = (sessionId) => ({ sessionId, opener: deps.checkpointCtxSealing });
246
254
  const resumeFleetScope = (req, auth) => req ? (gatedPrincipal(req, deps.config) ?? "default") : (auth.principal ?? "default");
247
- async function resumeCheckpoint(sessionId, decision, reason, hostDecision, req, answer, binding, onResumeCommitted, acceptEarly, decider, restatement) {
255
+ function createRememberIntent(sessionId, remember) {
256
+ let pending;
257
+ return {
258
+ laneCannotRecord: remember.laneCannotRecord,
259
+ record: async (grant) => {
260
+ if (grant.rememberableToolName !== null)
261
+ pending = { sessionId: grant.overrideSessionId ?? sessionId, toolName: grant.rememberableToolName };
262
+ },
263
+ settle: async (committed) => {
264
+ const store = deps.approvalExemptionStore;
265
+ if (!committed || pending === undefined || store === undefined)
266
+ return false;
267
+ try {
268
+ await store.grant(pending.sessionId, pending.toolName, remember.grantedBy);
269
+ deps.logger?.info?.("approval_exemption_granted", { sessionId: pending.sessionId, toolName: pending.toolName, grantedBy: remember.grantedBy });
270
+ return true;
271
+ }
272
+ catch (e) {
273
+ deps.logger?.warn?.("approval_exemption_grant_failed", { sessionId: pending.sessionId, toolName: pending.toolName, error: String(e).slice(0, 200) });
274
+ return false;
275
+ }
276
+ },
277
+ };
278
+ }
279
+ async function resumeCheckpoint(sessionId, decision, reason, hostDecision, req, answer, binding, remember, acceptEarly, decider, restatement) {
248
280
  const cs = deps.checkpointStore;
281
+ const intent = remember !== undefined ? createRememberIntent(sessionId, remember) : undefined;
249
282
  const token = await currentApprovalGateToken(cs, sessionId);
250
283
  if (binding.checkpointToken && !sightsCurrentGate({ face: "checkpointToken", value: binding.checkpointToken }, token ? { checkpointToken: token } : null)) {
251
284
  let seenUnreadable = false;
@@ -293,6 +326,7 @@ export function createResumeLegs(ctx) {
293
326
  const ctxPromise = cs.getCtx(sessionId);
294
327
  void ctxPromise.catch(() => { });
295
328
  const noApproval = { status: 404, body: refusalBody({ errorCode: "not_found.approval", message: "approval not found" }) };
329
+ const rowOwnRefusal = async (verdict, diagnostic) => rowRefusalAnswer(verdict, diagnostic, verdict.code === "checkpoint.unsupported_version" ? ((await ctxPromise.catch(() => null)) ?? {}) : {});
296
330
  let cp;
297
331
  try {
298
332
  cp = await cpPromise;
@@ -303,7 +337,9 @@ export function createResumeLegs(ctx) {
303
337
  deps.logger?.warn?.("approval_decide_unreadable_row_withheld", { sessionId, note: "row unreadable and the caller's ownership of THAT token is unproven — folded into the uniform 404" });
304
338
  return noApproval;
305
339
  }
306
- return { status: 409, body: refusalBody({ errorCode: "conflict.checkpoint_unreadable", message: e instanceof Error ? e.message : String(e) }) };
340
+ if (e instanceof UnreadableCheckpointRowError && e.rowVerdict.kind !== "ok")
341
+ return rowOwnRefusal(e.rowVerdict, errorText(e));
342
+ return { status: 409, body: refusalBody({ errorCode: "conflict.checkpoint_unreadable", message: errorText(e) }) };
307
343
  }
308
344
  if (!cp) {
309
345
  if (!(await mayDiscloseRowError(cs, token, decider)))
@@ -319,20 +355,20 @@ export function createResumeLegs(ctx) {
319
355
  }
320
356
  const decideGateKind = cp.gate?.kind;
321
357
  if (!isApprovalGateKind(decideGateKind)) {
322
- const activeForPath = decideGateKind
323
- ? await deps.runStore?.getActiveTaskId(sessionId).catch(() => undefined)
324
- : undefined;
325
- const gnPath = decideGateKind && activeForPath
326
- ? resumeEntryForGate(decideGateKind, { sessionId, taskId: activeForPath })
327
- : null;
358
+ const verdict = judgeCheckpointRow(cp);
359
+ if (verdict.kind !== "ok")
360
+ return rowOwnRefusal(verdict);
361
+ if (typeof decideGateKind !== "string" || decideGateKind === "") {
362
+ return { status: 409, body: refusalBody({ errorCode: "gate_not_tool_approval", message: "task is suspended on a gate whose kind this engine cannot read, so it cannot say which endpoint resolves it" }) };
363
+ }
364
+ const activeForPath = await deps.runStore?.getActiveTaskId(sessionId).catch(() => undefined);
365
+ const gnPath = activeForPath ? resumeEntryForGate(decideGateKind, { sessionId, taskId: activeForPath }) : null;
328
366
  return {
329
367
  status: 409,
330
368
  body: refusalBody({
331
369
  errorCode: "gate_not_tool_approval",
332
- message: `task is suspended on a '${decideGateKind ?? "unknown"}' gate, not a tool approval — a plan_review gate is resolved via POST /v1/assistant/tasks/:id/plan_review, a resource_limit suspension via POST /v1/assistant/tasks/:id/resume`,
333
- facts: {
334
- ...(decideGateKind ? { pendingGate: { kind: decideGateKind, ...(gnPath ? { decidePath: gnPath } : {}) } } : {}),
335
- },
370
+ message: `task is suspended on a '${decideGateKind}' gate, not a tool approval — a plan_review gate is resolved via POST /v1/assistant/tasks/:id/plan_review, a resource_limit suspension via POST /v1/assistant/tasks/:id/resume`,
371
+ facts: { pendingGate: { kind: decideGateKind, ...(gnPath ? { decidePath: gnPath } : {}) } },
336
372
  }),
337
373
  };
338
374
  }
@@ -370,8 +406,8 @@ export function createResumeLegs(ctx) {
370
406
  standingAnswerDurablyRecordable(parkRowStandingAnswerFacts(paForGrant, cp.gate, deps.config, deploymentListAsks(deps.config, { toolName: paForGrant.toolName })))
371
407
  ? paForGrant.toolName
372
408
  : null;
373
- const boundGrant = onResumeCommitted
374
- ? (overrideSessionId) => onResumeCommitted({ ...(overrideSessionId !== undefined ? { overrideSessionId } : {}), rememberableToolName: rememberableTool })
409
+ const boundGrant = intent
410
+ ? (overrideSessionId) => intent.record({ ...(overrideSessionId !== undefined ? { overrideSessionId } : {}), rememberableToolName: rememberableTool })
375
411
  : undefined;
376
412
  const lateSettleSink = deps.approvalLateSettle;
377
413
  const lateSettleAnchor = lateSettleSink !== undefined && req !== undefined && token
@@ -381,8 +417,8 @@ export function createResumeLegs(ctx) {
381
417
  checkpointTokenHash: buildCheckpointAnchorHash(token),
382
418
  }
383
419
  : undefined;
384
- const noteLateSettleIfAccepted = (out) => {
385
- if (lateSettleSink === undefined || lateSettleAnchor === undefined || !decisionCommittedOf(out))
420
+ const noteLateSettleIfAccepted = (committed) => {
421
+ if (!committed || lateSettleSink === undefined || lateSettleAnchor === undefined)
386
422
  return;
387
423
  try {
388
424
  lateSettleSink.recordLateSettle({ ...lateSettleAnchor, outcome: decision === "approve" ? "allowed" : "denied", decidedBy: hostDecision.decidedBy, ...(hostDecision.approver !== undefined ? { approver: hostDecision.approver } : {}), settledAtMs: Date.now() });
@@ -391,6 +427,11 @@ export function createResumeLegs(ctx) {
391
427
  recordFailOpen("server.approval-ask-audit.append-failed", `kind=late_settle err=${e instanceof Error ? e.message : String(e)}`);
392
428
  }
393
429
  };
430
+ const landAfterCommit = async (out) => {
431
+ const committed = decisionCommittedOf(out);
432
+ noteLateSettleIfAccepted(committed);
433
+ return intent === undefined ? out : { ...out, rememberApplied: await intent.settle(committed) };
434
+ };
394
435
  const parkedForkQuotaDenial = req !== undefined ? ownerCostQuotaDenied(decodeCheckpointScope(cp.scope)) : undefined;
395
436
  if (parkedForkQuotaDenial)
396
437
  return parkedForkQuotaDenial;
@@ -416,7 +457,7 @@ export function createResumeLegs(ctx) {
416
457
  binding: { ...(({ checkpointToken: _staleGuardOnly, ...rest }) => rest)(binding), ...action },
417
458
  ...(answer !== undefined ? { answer } : {}),
418
459
  ...(restatement !== undefined ? { restatement } : {}),
419
- ...(boundGrant ? { grantRemember: (rootSessionId) => boundGrant(rootSessionId) } : {}),
460
+ ...(boundGrant && intent ? { remember: { anchor: (rootSessionId) => boundGrant(rootSessionId), laneCannotRecord: intent.laneCannotRecord } } : {}),
420
461
  };
421
462
  if (origin?.kind === "background" && parkedAgentStore !== undefined && parkedSurface !== undefined) {
422
463
  const parked = await withPrincipal(decodeCheckpointScope(cp.scope), () => decideParkedAgent({
@@ -437,7 +478,7 @@ export function createResumeLegs(ctx) {
437
478
  if (isRootSessionGoneError(e))
438
479
  return { ok: false, gone: true };
439
480
  if (e instanceof HttpError)
440
- return { ok: false, gone: false, answer: resumeRefusalWithCard(resumeBlockedByPolicyAnswer(httpErrorRefusal(e)), true) };
481
+ return { ok: false, gone: false, answer: resumeRefusalWithCard(resumeAssemblyRefusalAnswer(e.status, httpErrorRefusal(e)), true) };
441
482
  throw e;
442
483
  }
443
484
  const occupant = ctx.occupant;
@@ -451,8 +492,7 @@ export function createResumeLegs(ctx) {
451
492
  ...(deps.logger ? { warn: parkWarn } : {}),
452
493
  }, { ...parkedReq, selectedGate: captureSelectedGate() }, { handle: origin.handle, row: origin.row }));
453
494
  void ctxPromise.catch(() => { });
454
- noteLateSettleIfAccepted(parked);
455
- return parked;
495
+ return await landAfterCommit(parked);
456
496
  }
457
497
  if (origin?.kind === "workflow_parks_unreadable") {
458
498
  void ctxPromise.catch(() => { });
@@ -503,7 +543,7 @@ export function createResumeLegs(ctx) {
503
543
  const admittedPayer = decodeCheckpointScope(cp.scope);
504
544
  const out = hostToken
505
545
  ? await resumeWake(plan.hostSessionId, plan.message, decider?.principal, req, acceptEarly, delivery, admittedPayer, restatement)
506
- : await startFreshHostTurn(plan.hostSessionId, plan.message, admittedPayer, req, delivery, plan.runId, restatement);
546
+ : await startFreshHostTurn(plan.hostSessionId, plan.message.text, admittedPayer, req, delivery, plan.runId, restatement);
507
547
  if (recordFailure !== undefined)
508
548
  throw recordFailure.err;
509
549
  if (acceptedTaskIdOf(out) === undefined)
@@ -548,8 +588,7 @@ export function createResumeLegs(ctx) {
548
588
  };
549
589
  const verifyRounds = verifyRoundsFromBody(ctx.body);
550
590
  const driven = await driveResumeIntoRunLog({ peerLease: resolved.peerLease, execution: resolved.execution, runner: resolved.runner, legFacts: resolved.legFacts, token, sessionId: cp.sessionId, principal: auth.principal, fleetScope: resumeFleetScope(req, auth), taskConfig, resumeObjective, outcome, commitment: { kind: "gate_resolved", ...captureSelectedGate() }, verifyRounds, resumeCtx: { sessionId, ctx }, ...(engineNotices.length > 0 ? { engineNotices } : {}), ...(boundGrant ? { onResumeCommitted: boundGrant } : {}), ...(acceptEarly === true ? { acceptEarly: true } : {}), ...(req !== undefined ? { callerInitiated: true } : {}), ...(ownerLeaseAdmittedHere ? { ownerLeaseAdmitted: true } : {}) });
551
- noteLateSettleIfAccepted(driven);
552
- return driven;
591
+ return await landAfterCommit(driven);
553
592
  }
554
593
  finally {
555
594
  resolved.peerLease.release();
@@ -588,7 +627,7 @@ export function createResumeLegs(ctx) {
588
627
  catch (e) {
589
628
  lease.release();
590
629
  if (e instanceof HttpError) {
591
- return { ok: false, answer: resumeRefusalWithCard(resumeBlockedByPolicyAnswer(httpErrorRefusal(e)), true) };
630
+ return { ok: false, answer: resumeRefusalWithCard(resumeAssemblyRefusalAnswer(e.status, httpErrorRefusal(e)), true) };
592
631
  }
593
632
  throw e;
594
633
  }
@@ -652,11 +691,11 @@ export function createResumeLegs(ctx) {
652
691
  }
653
692
  if (!taskId && args.mintFreshRun && deps.runStore) {
654
693
  const freshId = uuidv7();
655
- const created = await deps.runStore.createRun(freshId, sessionId, principal ?? null, deps.instanceId ?? "default", {
694
+ const created = await timeClaim(deps.metrics, "run_claim", deps.runStore.createRun(freshId, sessionId, principal ?? null, deps.instanceId ?? "default", {
656
695
  source: args.mintFreshRun.source,
657
696
  identity: args.mintFreshRun.identity,
658
697
  objectivePreview: heldObjective === undefined ? null : buildRunObjectivePreview(heldObjective),
659
- });
698
+ }));
660
699
  if (created.existing) {
661
700
  throw new Error(`wake fresh run: createRun observed an existing row for the freshly minted taskId ${freshId} (no idempotency key was sent) — refusing to treat it as a busy session`);
662
701
  }
@@ -742,12 +781,12 @@ export function createResumeLegs(ctx) {
742
781
  return { reopened: pending, leg };
743
782
  };
744
783
  let resumeHeartbeat;
745
- let resumeManifestLease = 0;
784
+ let resumeManifestSeat;
746
785
  let resumeStreamRef;
747
786
  let resumeLegLive = false;
748
787
  const subagentHandleEvictions = [];
749
788
  let claimedRow = false;
750
- const cancelCtrl = createRunAbort();
789
+ const cancelCtrl = createRunAbort(principal ?? null);
751
790
  let cancelLedgerAppend;
752
791
  const preemptCtrl = new AbortController();
753
792
  if (taskId && deps.runStore) {
@@ -778,7 +817,7 @@ export function createResumeLegs(ctx) {
778
817
  }, HEARTBEAT_MS);
779
818
  resumeHeartbeat.unref?.();
780
819
  deps.modelUsage?.register(taskId);
781
- resumeManifestLease = deps.promptManifests?.register(taskId) ?? 0;
820
+ resumeManifestSeat = createPromptManifestSeat(deps.promptManifests, taskId);
782
821
  }
783
822
  if (args.workflowDecision !== undefined && taskId === undefined) {
784
823
  throw new Error("workflow decision delivery: no run row was claimed for the delivering leg — refusing to start a delivery whose decision could not be recorded against it");
@@ -890,7 +929,7 @@ export function createResumeLegs(ctx) {
890
929
  const rs2 = deps.runStore;
891
930
  try {
892
931
  const ap = vAppend;
893
- await appendPromptManifest(ap, deps.promptManifests, taskId);
932
+ await resumeManifestSeat?.drain(ap);
894
933
  if (reSuspended || vrReopened) {
895
934
  const vrParkCallId = reSuspended ? await parkToolCallId(vr, deps.checkpointStore) : undefined;
896
935
  await appendParkRow(ap, { modelUsage: deps.modelUsage, taskId }, reParkEvent ?? reparkStatus, { terminal: vrPaused, ...(vrParkCallId !== undefined ? { toolCallId: vrParkCallId } : {}) }, vrReopened ? (failureCodeOf(vr.terminal) ?? null) : undefined);
@@ -938,7 +977,7 @@ export function createResumeLegs(ctx) {
938
977
  ? async (eventId) => { const leaf = (await headOf(sessionId))?.leafId; if (leaf)
939
978
  await deps.resumeAnchorStore.put(sessionId, eventId, leaf, anchorOwner); }
940
979
  : undefined;
941
- const captureUserMessageAnchor = deps.resumeAnchorStore && taskId
980
+ const captureUserMessageAnchor = deps.resumeAnchorStore && taskId && freshRunClaimed
942
981
  ? async (entryId) => { await deps.resumeAnchorStore.put(sessionId, taskId, entryId, anchorOwner); }
943
982
  : undefined;
944
983
  const anchor = new TurnAnchorCapture(captureTurnAnchor, "resume", captureUserMessageAnchor);
@@ -1039,7 +1078,7 @@ export function createResumeLegs(ctx) {
1039
1078
  fleetPub?.onEvent(ev);
1040
1079
  await deps.userInputLedger?.observeLegEvent(stream, ev);
1041
1080
  await resumeWorkspace.observe(ev);
1042
- await appendPromptManifest(append, deps.promptManifests, taskId);
1081
+ await resumeManifestSeat?.drain(append);
1043
1082
  switch (ev.type) {
1044
1083
  case "text_delta":
1045
1084
  block += ev.delta;
@@ -1247,7 +1286,7 @@ export function createResumeLegs(ctx) {
1247
1286
  settleFleet("failed");
1248
1287
  }
1249
1288
  }
1250
- return checkpointRefusalAnswer(e, { gate: outcome.gate, retriable, ...(taskId !== undefined ? { taskId } : {}), versionKeys: e.code === "checkpoint.unsupported_version" ? buildCheckpointVersionKeys(resumeCtx.ctx.writerVersion, serviceVersion()) : {} });
1289
+ return checkpointRefusalAnswer(e, { gate: outcome.gate, retriable, ...(taskId !== undefined ? { taskId } : {}), versionKeys: refusalVersionKeys(e, resumeCtx.ctx) });
1251
1290
  }
1252
1291
  const thrownCause = cancelCtrl.cause();
1253
1292
  if (thrownCause !== undefined) {
@@ -1281,7 +1320,7 @@ export function createResumeLegs(ctx) {
1281
1320
  for (const evict of subagentHandleEvictions)
1282
1321
  evict();
1283
1322
  deps.modelUsage?.clear(taskId);
1284
- deps.promptManifests?.clear(taskId, resumeManifestLease);
1323
+ resumeManifestSeat?.release();
1285
1324
  }
1286
1325
  if (resumeHeartbeat)
1287
1326
  clearInterval(resumeHeartbeat);
@@ -1488,10 +1527,9 @@ export function createResumeLegs(ctx) {
1488
1527
  if (gateKind !== "task_done") {
1489
1528
  return { status: 409, body: refusalBody({ errorCode: "wake.gate_pending", message: `cannot wake: this session is waiting on a pending gate decision (gate "${gateKind ?? "unknown"}") — resolve it through its own decide entry` }) };
1490
1529
  }
1491
- const trusted = operator;
1492
1530
  if (message !== undefined) {
1493
1531
  try {
1494
- validatePendingSteer({ text: message, trusted });
1532
+ validatePendingSteer(message);
1495
1533
  }
1496
1534
  catch (e) {
1497
1535
  if (e instanceof CheckpointError && e.code === "steering.invalid_content") {
@@ -1526,7 +1564,7 @@ export function createResumeLegs(ctx) {
1526
1564
  fleetScope: resumeFleetScope(req, auth),
1527
1565
  taskConfig,
1528
1566
  resumeObjective,
1529
- outcome: { gate: "wake", ...(message !== undefined ? { message: { text: message, trusted } } : {}) },
1567
+ outcome: { gate: "wake", ...(message !== undefined ? { message } : {}) },
1530
1568
  commitment: { kind: "delivered" },
1531
1569
  verifyRounds: undefined,
1532
1570
  resumeCtx: { sessionId, ctx },
@@ -1542,7 +1580,7 @@ export function createResumeLegs(ctx) {
1542
1580
  resolved.peerLease.release();
1543
1581
  }
1544
1582
  }
1545
- async function preparePlanReview(sessionId, log, decider, sighting) {
1583
+ async function preparePlanReview(sessionId, log, decider, sighting, restatement) {
1546
1584
  const cs = deps.checkpointStore;
1547
1585
  const refuse = (answer) => ({ ok: false, answer });
1548
1586
  const log404 = (r) => deps.logger?.info?.("decide_404", {
@@ -1614,14 +1652,14 @@ export function createResumeLegs(ctx) {
1614
1652
  return refuse(resumeCtxUnsealableAnswer(ctxRead));
1615
1653
  if (ctxRead.kind === "absent")
1616
1654
  return refuse({ status: 409, body: refusalBody({ errorCode: "conflict.resume_context_unavailable", message: "resume context missing — cannot rebuild task config" }) });
1617
- const replay = storedBodyReplayRefusal(ctxRead.ctx, deps.config);
1655
+ const ctx = restateResumeCtx(ctxRead.ctx, restatement);
1656
+ const replay = storedBodyReplayRefusal(ctx, deps.config);
1618
1657
  if (replay !== undefined)
1619
1658
  return refuse(refuseStoredBodyReplay(sessionId, replay));
1620
- return { ok: true, prepared: { sessionId, token, cp, ctx: ctxRead.ctx } };
1659
+ return { ok: true, prepared: { sessionId, token, cp, ctx } };
1621
1660
  }
1622
- async function drivePlanReview(prepared, decision, editedPlan, reason, hostDecision, req, acceptEarly, permissionModeAfter, restatement) {
1623
- const { sessionId, token, cp } = prepared;
1624
- const ctx = restateResumeCtx(prepared.ctx, restatement);
1661
+ async function drivePlanReview(prepared, decision, editedPlan, reason, hostDecision, req, acceptEarly, permissionModeAfter) {
1662
+ const { sessionId, token, cp, ctx } = prepared;
1625
1663
  if ((await deps.checkpointStore.findPendingTokenBySession(sessionId, undefined, { gateKinds: ["plan_review"] })) !== token)
1626
1664
  return notResumableAnswer();
1627
1665
  const auth = { sessionId: cp.sessionId, principal: decodeCheckpointScope(cp.scope), memoryScope: ctx.memoryScope };
@@ -1662,7 +1700,7 @@ export function createResumeLegs(ctx) {
1662
1700
  const routeCtxBase = {
1663
1701
  deps,
1664
1702
  registry: { idemCache, inflightRuns, preemptableRuns, steerableRuns, wakeParkMints, counters },
1665
- helpers: { readJson, readRawBody, rateLimited, quotaExceeded, ownerQuotaDenied, leaseDenied, ownerLeaseDenied, usageWindowDenied, safeDecode, runOwnerOk, sessionOwnerOk, runSessionAcceptOk },
1703
+ helpers: { readJson, readRawBody, rateLimited, quotaExceeded, ownerQuotaDenied, leaseDenied, ownerLeaseDenied, usageWindowDenied, admitRun, safeDecode, runOwnerOk, sessionOwnerOk, runSessionAcceptOk },
1666
1704
  local: { images: createImagesLocal(deps), sessions: createSessionsLocal(), sessionSync: createSessionSyncLocal(), capabilities: createCapabilitiesLocal() },
1667
1705
  legs: { prepareSpec, finalizeTaskResult, resumeCheckpoint, driveResumeIntoRunLog, resumePreempted, resumeWake, preparePlanReview, drivePlanReview, sessionNotify: sessionNotifyDoor },
1668
1706
  };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * run 外回退口 `POST /v1/sessions/:id/rewind-files` 的 200 体 —— 引擎 `Runner.rewindFiles` 的结果(`RewindFilesResult`)**原形**,文本叶经出口座出门。
3
+ *
4
+ * 规则一句:形照引擎(`dryRun:true` ⇒ `{ preview }`,`null` 仍是 `null`;`dryRun:false` ⇒ `{ restore }` 台账,空数组仍是空数组),每一片自由文本叶只经
5
+ * {@link seatText} 的一行 —— 被跟踪文件的路径(台账 `filesChanged` / `identicalSkipped` / `refused[].path` / `failed[].path`、预览 `filesChanged`;源头是模型交的
6
+ * 路径参数)走 `rewind-ledger-path`(不设界:截过的路径就不是那个文件了);拒因 / 故障句(`refused[].reason` / `failed[].reason` / `error.message`)走
7
+ * `rewind-ledger-reason`;闭集词 / 计数逐字。台账上的店故障(core `FileHistoryError`)按本仓错误体的唯一机读键律出门:引擎的 `code` 成员在 wire 上叫
8
+ * `errorCode`(值逐字),`message` 经座,`permanence` 逐字 —— 本仓的 wire 上没有叫 `code` 的错误键。两张叶表与故障的三键按 core 型的键穷举 ——
9
+ * core 给台账 / 统计 / 故障加一格而这里不表态 ⇒ tsc 红;表外的运行期键不出门(按表取键,不展开原对象)。唯一调用方 = `http/routes/sessions.ts` 的 `session-rewind-files` 臂。
10
+ */
11
+ import type { FileHistoryDiffStats, FileHistoryError, FileHistoryRestoreResult, RewindFilesResult } from "@sema-agent/core";
12
+ /** 台账上的店故障在 wire 上的形:码键 = `errorCode`(本仓错误体的唯一机读键),其余两键同引擎。 */
13
+ export interface RewindLedgerError {
14
+ readonly errorCode: FileHistoryError["code"];
15
+ readonly message: string;
16
+ readonly permanence?: FileHistoryError["permanence"];
17
+ }
18
+ /** 台账在 wire 上的形 = 引擎台账,`error` 换成 {@link RewindLedgerError}。 */
19
+ export type RewindLedgerReply = Omit<FileHistoryRestoreResult, "error"> & {
20
+ readonly error?: RewindLedgerError;
21
+ };
22
+ /** 200 体在 wire 上的形(引擎 `RewindFilesResult`,台账的 `error` 按 {@link RewindLedgerError})。 */
23
+ export type RewindFilesReply = {
24
+ readonly dryRun: true;
25
+ readonly preview: FileHistoryDiffStats | null;
26
+ } | {
27
+ readonly dryRun: false;
28
+ readonly restore: RewindLedgerReply & {
29
+ readonly outcome: "complete" | "partial";
30
+ };
31
+ };
32
+ /** 200 体(纯数据)。 */
33
+ export declare function buildRewindFilesReply(result: RewindFilesResult): RewindFilesReply;
34
+ //# sourceMappingURL=rewind-files-reply.d.ts.map
@@ -0,0 +1,36 @@
1
+ import { seatText } from "../trace/exit-seat.js";
2
+ function applyLeafTable(obj, table) {
3
+ const out = {};
4
+ for (const key of Object.keys(table)) {
5
+ const v = obj[key];
6
+ if (v !== undefined && v !== null)
7
+ out[key] = table[key](v);
8
+ }
9
+ return out;
10
+ }
11
+ const pathLeaf = (p) => seatText("rewind-ledger-path", p);
12
+ const reasonLeaf = (t) => seatText("rewind-ledger-reason", t);
13
+ function ledgerErrorOf(e) {
14
+ return { errorCode: e.code, message: reasonLeaf(e.message), ...(e.permanence !== undefined ? { permanence: e.permanence } : {}) };
15
+ }
16
+ const RESTORE_LEDGER_LEAVES = {
17
+ outcome: (v) => v,
18
+ filesChanged: (v) => v.map(pathLeaf),
19
+ identicalSkipped: (v) => v.map(pathLeaf),
20
+ refused: (v) => v.map((f) => ({ path: pathLeaf(f.path), reason: reasonLeaf(f.reason), class: f.class })),
21
+ failed: (v) => v.map((f) => ({ path: pathLeaf(f.path), reason: reasonLeaf(f.reason) })),
22
+ modeNotPreserved: (v) => v,
23
+ };
24
+ const DIFF_STATS_LEAVES = {
25
+ filesChanged: (v) => v.map(pathLeaf),
26
+ insertions: (v) => v,
27
+ deletions: (v) => v,
28
+ };
29
+ export function buildRewindFilesReply(result) {
30
+ if (result.dryRun)
31
+ return { dryRun: true, preview: result.preview === null ? null : applyLeafTable(result.preview, DIFF_STATS_LEAVES) };
32
+ const { error, ...ledger } = result.restore;
33
+ const projected = applyLeafTable(ledger, RESTORE_LEDGER_LEAVES);
34
+ return { dryRun: false, restore: { ...projected, outcome: result.restore.outcome, ...(error !== undefined ? { error: ledgerErrorOf(error) } : {}) } };
35
+ }
36
+ //# sourceMappingURL=rewind-files-reply.js.map