@sema-agent/server 7.52.0 → 7.53.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 (328) hide show
  1. package/USAGE.md +22 -5
  2. package/dist/adoption/plan.d.ts +3 -3
  3. package/dist/adoption/quiesce.d.ts +1 -1
  4. package/dist/adoption/sql.d.ts +2 -2
  5. package/dist/adoption/wire.d.ts +1 -1
  6. package/dist/approval-ask-machine.d.ts +2 -2
  7. package/dist/approval-card.d.ts +18 -18
  8. package/dist/approval-deny-reasons.d.ts +1 -1
  9. package/dist/approval-hmac.d.ts +2 -2
  10. package/dist/approval-reconciler.d.ts +14 -14
  11. package/dist/approval.d.ts +2 -2
  12. package/dist/audit.d.ts +4 -4
  13. package/dist/auth-keys.d.ts +6 -6
  14. package/dist/bench/l8/artifact.d.ts +6 -1
  15. package/dist/bench/l8/artifact.js +2 -27
  16. package/dist/bench/l8/escape.d.ts +3 -3
  17. package/dist/bench/l8/index.d.ts +1 -1
  18. package/dist/bench/s1/arms.d.ts +3 -3
  19. package/dist/bench/s1/oracle.d.ts +2 -2
  20. package/dist/bench/s1/reviewer.d.ts +1 -1
  21. package/dist/bench/s1/row.d.ts +5 -5
  22. package/dist/bench/s1/runner-ctx.d.ts +3 -3
  23. package/dist/boot/config-center.d.ts +14 -7
  24. package/dist/boot/config-center.js +2 -0
  25. package/dist/boot/coordinators.d.ts +4 -4
  26. package/dist/boot/crash-last.d.ts +1 -1
  27. package/dist/boot/device-lane.d.ts +3 -3
  28. package/dist/boot/device-lane.js +2 -0
  29. package/dist/boot/engine-lease.d.ts +4 -4
  30. package/dist/boot/governance-seams.d.ts +5 -5
  31. package/dist/boot/leader.d.ts +5 -5
  32. package/dist/boot/limit-sync.d.ts +1 -1
  33. package/dist/boot/memory-boundary.d.ts +5 -5
  34. package/dist/boot/memory-consolidation.d.ts +8 -2
  35. package/dist/boot/memory-consolidation.js +1 -0
  36. package/dist/boot/org-memory.d.ts +5 -5
  37. package/dist/boot/parked-revive-gate.d.ts +6 -6
  38. package/dist/boot/permission-rules-audit.d.ts +2 -2
  39. package/dist/boot/reapers.d.ts +8 -8
  40. package/dist/boot/resolve-spec.d.ts +4 -4
  41. package/dist/boot/retention-lane.d.ts +1 -1
  42. package/dist/boot/runner-deps.d.ts +33 -27
  43. package/dist/boot/runner-deps.js +2 -1
  44. package/dist/boot/runtime-caps.d.ts +4 -4
  45. package/dist/boot/session-faces.d.ts +1 -1
  46. package/dist/boot/shutdown.d.ts +10 -10
  47. package/dist/boot/side-query-lane.d.ts +14 -14
  48. package/dist/boot/stores.js +5 -0
  49. package/dist/boot/task-list-lane.d.ts +3 -3
  50. package/dist/boot/webfetch-summarize-lane.d.ts +9 -9
  51. package/dist/boot/workflow-orchestration.d.ts +1 -1
  52. package/dist/bounded-session-map.d.ts +1 -1
  53. package/dist/brain.d.ts +3 -3
  54. package/dist/budget.d.ts +3 -3
  55. package/dist/canonical-json.d.ts +53 -0
  56. package/dist/canonical-json.js +48 -0
  57. package/dist/capabilities/center-prompts.d.ts +13 -13
  58. package/dist/capabilities/collab-workflows.d.ts +1 -1
  59. package/dist/capabilities/hands-lane.d.ts +4 -4
  60. package/dist/capabilities/memory-notice.d.ts +4 -4
  61. package/dist/capabilities/prompt.d.ts +2 -2
  62. package/dist/capabilities/sandbox-file-send.d.ts +2 -2
  63. package/dist/capabilities/scenarios.d.ts +16 -16
  64. package/dist/capabilities/skills.d.ts +1 -1
  65. package/dist/capabilities/team.d.ts +3 -3
  66. package/dist/capabilities/tool-defer.d.ts +6 -6
  67. package/dist/config-catalog.d.ts +139 -0
  68. package/dist/config-catalog.js +556 -0
  69. package/dist/config-center/apply-effective.d.ts +20 -7
  70. package/dist/config-center/apply-effective.js +45 -0
  71. package/dist/config-center/apply-ledger.d.ts +6 -6
  72. package/dist/config-center/facade.d.ts +3 -2
  73. package/dist/config-center/hot-keys-registry.d.ts +2 -2
  74. package/dist/config-center/http-client.d.ts +5 -5
  75. package/dist/config-center/mcp-revocation.d.ts +6 -4
  76. package/dist/config-center/mcp-revocation.js +2 -12
  77. package/dist/config-center/restart-signal.d.ts +11 -1
  78. package/dist/config-center/restart-signal.js +1 -1
  79. package/dist/config-center/skills-mcp.d.ts +2 -2
  80. package/dist/config-center/stage-limits.d.ts +3 -3
  81. package/dist/config-center/types.d.ts +23 -19
  82. package/dist/config-invariants.d.ts +1 -1
  83. package/dist/config-provider.d.ts +2 -2
  84. package/dist/config-types.d.ts +157 -134
  85. package/dist/config.d.ts +32 -24
  86. package/dist/config.js +48 -6
  87. package/dist/degenerate-instrument.d.ts +1 -1
  88. package/dist/deployment-governance.d.ts +13 -13
  89. package/dist/device-store.d.ts +2 -2
  90. package/dist/device-ws-hub.d.ts +6 -4
  91. package/dist/device-ws-hub.js +9 -3
  92. package/dist/device-ws-protocol.d.ts +3 -3
  93. package/dist/digest-form.d.ts +1 -1
  94. package/dist/elicitation.d.ts +1 -1
  95. package/dist/env-facts.d.ts +7 -7
  96. package/dist/execution-lane-caps.d.ts +5 -5
  97. package/dist/fleet/fleet-bus.d.ts +56 -53
  98. package/dist/fleet/fleet-reconciler.d.ts +2 -2
  99. package/dist/fleet/fleet-terminal-window.d.ts +1 -1
  100. package/dist/fleet/subagent-tail-bus.d.ts +3 -3
  101. package/dist/fleet-client.d.ts +3 -3
  102. package/dist/fleet-lease.d.ts +1 -1
  103. package/dist/hooks/branch-transcript.d.ts +2 -2
  104. package/dist/hooks/cc-agent-hook-prompt.d.ts +2 -2
  105. package/dist/hooks/cc-stop-prompt.d.ts +2 -2
  106. package/dist/hooks/hook-llm.d.ts +1 -1
  107. package/dist/hooks/hook-runner.d.ts +12 -5
  108. package/dist/http/active-run-conflict.d.ts +31 -33
  109. package/dist/http/active-run-conflict.js +4 -2
  110. package/dist/http/route-ctx.d.ts +23 -21
  111. package/dist/http/routes/a2a-serve.d.ts +2 -2
  112. package/dist/http/routes/admin-config-refresh.d.ts +1 -1
  113. package/dist/http/routes/admin-drain.d.ts +4 -4
  114. package/dist/http/routes/admin-memory-optout.d.ts +5 -5
  115. package/dist/http/routes/adoption.d.ts +1 -1
  116. package/dist/http/routes/agents-roster.d.ts +1 -1
  117. package/dist/http/routes/approvals-assistant.d.ts +6 -6
  118. package/dist/http/routes/approvals-assistant.js +4 -1
  119. package/dist/http/routes/capabilities.d.ts +1 -1
  120. package/dist/http/routes/capabilities.js +1 -0
  121. package/dist/http/routes/config-catalog.d.ts +28 -0
  122. package/dist/http/routes/config-catalog.js +42 -0
  123. package/dist/http/routes/diagnostics.d.ts +2 -2
  124. package/dist/http/routes/fleet.d.ts +1 -1
  125. package/dist/http/routes/images.d.ts +1 -1
  126. package/dist/http/routes/leader.d.ts +1 -1
  127. package/dist/http/routes/memory-bundle.d.ts +4 -4
  128. package/dist/http/routes/memory-bundle.js +2 -3
  129. package/dist/http/routes/memory-compliance.d.ts +7 -7
  130. package/dist/http/routes/memory-consolidation.d.ts +1 -1
  131. package/dist/http/routes/memory-origin.d.ts +9 -9
  132. package/dist/http/routes/memory-policy.d.ts +3 -3
  133. package/dist/http/routes/notify-wake.d.ts +1 -1
  134. package/dist/http/routes/observability.d.ts +1 -1
  135. package/dist/http/routes/retention-ops.d.ts +1 -1
  136. package/dist/http/routes/rules.d.ts +3 -3
  137. package/dist/http/routes/run-memory-capture.d.ts +1 -1
  138. package/dist/http/routes/runs.d.ts +3 -3
  139. package/dist/http/routes/runs.js +12 -17
  140. package/dist/http/routes/session-sync.d.ts +2 -2
  141. package/dist/http/routes/sessions-list.d.ts +1 -1
  142. package/dist/http/routes/sessions.d.ts +9 -1
  143. package/dist/http/routes/sessions.js +61 -1
  144. package/dist/http/routes/shared-memory.d.ts +1 -1
  145. package/dist/http/routes/side-query.d.ts +1 -1
  146. package/dist/http/routes/tasks.d.ts +1 -1
  147. package/dist/http/routes/trace-usage.d.ts +1 -1
  148. package/dist/http/routes/workflows.d.ts +1 -1
  149. package/dist/http/run-meta.d.ts +1 -1
  150. package/dist/http/send.d.ts +6 -6
  151. package/dist/http/server.d.ts +84 -67
  152. package/dist/http/server.js +25 -12
  153. package/dist/http/sse-lifecycle.d.ts +1 -1
  154. package/dist/http/sse-log.d.ts +6 -6
  155. package/dist/http/verify-rounds.d.ts +3 -3
  156. package/dist/http/wire-gate.d.ts +2 -2
  157. package/dist/http/wire-types.d.ts +38 -38
  158. package/dist/key-resolver.d.ts +1 -1
  159. package/dist/leader/diffout.d.ts +2 -2
  160. package/dist/leader/diffup.d.ts +1 -1
  161. package/dist/leader/endpoint.d.ts +1 -1
  162. package/dist/leader/fanout.d.ts +6 -6
  163. package/dist/leader/grader-env-factory.d.ts +1 -1
  164. package/dist/leader/leader.d.ts +12 -12
  165. package/dist/leader/merge.d.ts +3 -3
  166. package/dist/leader/planner.d.ts +5 -5
  167. package/dist/leader/repair-oracle.d.ts +1 -1
  168. package/dist/leader/wire.d.ts +9 -9
  169. package/dist/lsp/manager.d.ts +2 -2
  170. package/dist/lsp/types.d.ts +1 -1
  171. package/dist/lsp/ws-transport.d.ts +2 -2
  172. package/dist/main.js +13 -2
  173. package/dist/mcp-content-origin.d.ts +1 -1
  174. package/dist/memory-bundle-engine.d.ts +5 -3
  175. package/dist/memory-bundle-engine.js +2 -2
  176. package/dist/memory-operator-faces.d.ts +41 -11
  177. package/dist/memory-operator-faces.js +12 -0
  178. package/dist/memory-origin-fence.d.ts +20 -35
  179. package/dist/memory-origin-fence.js +41 -1
  180. package/dist/memory-posture.d.ts +6 -6
  181. package/dist/memory-scope.d.ts +7 -7
  182. package/dist/model-select.d.ts +5 -5
  183. package/dist/observability/cost-quota.d.ts +6 -6
  184. package/dist/observability/cost-taxonomy.d.ts +2 -2
  185. package/dist/observability/fail-open.d.ts +1 -5
  186. package/dist/observability/fail-open.js +0 -4
  187. package/dist/observability/metrics.d.ts +1 -1
  188. package/dist/observability/prompt-manifest.d.ts +8 -8
  189. package/dist/observability/rate-limit.d.ts +2 -2
  190. package/dist/observability/secret-env-scrub.d.ts +1 -1
  191. package/dist/observability/tool-trace.d.ts +1 -1
  192. package/dist/orchestration/hardened-vm-runner.d.ts +6 -6
  193. package/dist/orchestration/hardened-vm-worker-runner.d.ts +1 -1
  194. package/dist/orchestration/subagent-steer.d.ts +3 -3
  195. package/dist/orchestration/workflow-agent-steer.d.ts +1 -1
  196. package/dist/orchestration/workflow-completion-inbox.d.ts +6 -6
  197. package/dist/orchestration/workflow-notify-journal.d.ts +6 -6
  198. package/dist/parent-watch.d.ts +1 -1
  199. package/dist/parked-decide.d.ts +11 -11
  200. package/dist/plan-cache-probe.d.ts +1 -1
  201. package/dist/plugins/adoption-log-sql.d.ts +4 -4
  202. package/dist/plugins/approval-ask-store-memory.d.ts +1 -1
  203. package/dist/plugins/approval-ask-store-memory.js +12 -0
  204. package/dist/plugins/approval-ask-store-sql.d.ts +39 -17
  205. package/dist/plugins/approval-ask-store-sql.js +23 -6
  206. package/dist/plugins/approval-payload-fingerprint.d.ts +23 -0
  207. package/dist/plugins/approval-payload-fingerprint.js +23 -0
  208. package/dist/plugins/background-agent-store-sql.d.ts +8 -8
  209. package/dist/plugins/background-shell-support.d.ts +12 -12
  210. package/dist/plugins/blob-backend.d.ts +3 -3
  211. package/dist/plugins/breaker-state-sql.d.ts +3 -3
  212. package/dist/plugins/caching-session-store.d.ts +6 -6
  213. package/dist/plugins/checkpoint-store-sql.d.ts +162 -66
  214. package/dist/plugins/checkpoint-store-sql.js +76 -33
  215. package/dist/plugins/device-store-sql.d.ts +4 -3
  216. package/dist/plugins/e2b-orphan-reclaim.d.ts +3 -3
  217. package/dist/plugins/file-history-store-sql.d.ts +9 -8
  218. package/dist/plugins/file-run-store.d.ts +27 -27
  219. package/dist/plugins/fork-routing-session-store.d.ts +9 -9
  220. package/dist/plugins/image-bake-store-sql.d.ts +1 -1
  221. package/dist/plugins/image-index-sql.d.ts +2 -2
  222. package/dist/plugins/k8s-bg-scripts.d.ts +1 -1
  223. package/dist/plugins/k8s-exec-protocol.d.ts +1 -1
  224. package/dist/plugins/leader-run-store-sql.d.ts +1 -1
  225. package/dist/plugins/local-checkpoint-store.d.ts +26 -17
  226. package/dist/plugins/local-checkpoint-store.js +21 -11
  227. package/dist/plugins/local-session-store.d.ts +5 -5
  228. package/dist/plugins/mailbox-store-sql.d.ts +6 -6
  229. package/dist/plugins/memory-embedder-fingerprint.d.ts +2 -2
  230. package/dist/plugins/memory-engine-pg.d.ts +1 -1
  231. package/dist/plugins/memory-engine-tidb.d.ts +1 -1
  232. package/dist/plugins/memory-key-guards.d.ts +3 -3
  233. package/dist/plugins/memory-optout-grant-store-sql.d.ts +10 -10
  234. package/dist/plugins/memory-origin-law.d.ts +13 -13
  235. package/dist/plugins/memory-run-store.d.ts +12 -12
  236. package/dist/plugins/outcome-ledger-sql.d.ts +3 -3
  237. package/dist/plugins/permission-rule-store-file.d.ts +3 -3
  238. package/dist/plugins/permission-rule-store-sql.d.ts +38 -33
  239. package/dist/plugins/permission-rule-store-sql.js +7 -12
  240. package/dist/plugins/pg-cost-quota.d.ts +2 -2
  241. package/dist/plugins/pg-pool.js +5 -0
  242. package/dist/plugins/pg-query.d.ts +1 -1
  243. package/dist/plugins/pg-rate-limiter.d.ts +2 -2
  244. package/dist/plugins/pg-session-storage.d.ts +9 -9
  245. package/dist/plugins/remote-env-adb.d.ts +1 -1
  246. package/dist/plugins/remote-env-device.d.ts +2 -2
  247. package/dist/plugins/remote-env-e2b.d.ts +11 -11
  248. package/dist/plugins/remote-env-file-error.d.ts +2 -2
  249. package/dist/plugins/remote-env-host.d.ts +10 -10
  250. package/dist/plugins/remote-env-k8s.d.ts +7 -7
  251. package/dist/plugins/remote-env-local-docker.d.ts +1 -1
  252. package/dist/plugins/remote-env-ssh.d.ts +9 -9
  253. package/dist/plugins/remote-scratchpad.d.ts +1 -1
  254. package/dist/plugins/resume-anchor-store-sql.d.ts +1 -1
  255. package/dist/plugins/retention-lane-store-sql.d.ts +2 -2
  256. package/dist/plugins/retention-store-sql.d.ts +11 -11
  257. package/dist/plugins/roster-store-sql.d.ts +5 -5
  258. package/dist/plugins/run-store-sql.d.ts +12 -12
  259. package/dist/plugins/scheduler-support.d.ts +1 -1
  260. package/dist/plugins/send-user-file.d.ts +1 -1
  261. package/dist/plugins/session-capture-record-store-sql.d.ts +99 -0
  262. package/dist/plugins/session-capture-record-store-sql.js +110 -0
  263. package/dist/plugins/session-placement.d.ts +1 -1
  264. package/dist/plugins/session-policy-store-sql.d.ts +2 -2
  265. package/dist/plugins/session-store.d.ts +3 -3
  266. package/dist/plugins/shared-memory-store-sql.d.ts +5 -5
  267. package/dist/plugins/sql-driver.d.ts +7 -7
  268. package/dist/plugins/sql-errors.d.ts +2 -2
  269. package/dist/plugins/sql-escape.d.ts +1 -1
  270. package/dist/plugins/sql-row-helpers.d.ts +1 -1
  271. package/dist/plugins/store-backend.d.ts +32 -19
  272. package/dist/plugins/store-backend.js +4 -0
  273. package/dist/plugins/store-contracts.d.ts +9 -9
  274. package/dist/plugins/task-list-store-sql.d.ts +3 -3
  275. package/dist/plugins/tidb-cost-quota.d.ts +3 -3
  276. package/dist/plugins/tidb-pool.js +9 -0
  277. package/dist/plugins/tidb-rate-limiter.d.ts +2 -2
  278. package/dist/plugins/tidb-session-storage.d.ts +2 -2
  279. package/dist/plugins/tidb-session-store.d.ts +11 -11
  280. package/dist/plugins/tool-result-store-sql.d.ts +8 -8
  281. package/dist/plugins/usage-window-store-sql.d.ts +3 -3
  282. package/dist/plugins/web-search.d.ts +7 -7
  283. package/dist/plugins/workflow-journal-store-sql.d.ts +6 -6
  284. package/dist/plugins/workflow-run-store-sql.d.ts +1 -1
  285. package/dist/plugins/write-behind-counter.d.ts +6 -6
  286. package/dist/principal-jwt.d.ts +2 -2
  287. package/dist/project-memory.d.ts +1 -1
  288. package/dist/prompts-domain-validate.d.ts +8 -8
  289. package/dist/question.d.ts +3 -3
  290. package/dist/resource-suspend.d.ts +4 -4
  291. package/dist/resource-window.d.ts +3 -3
  292. package/dist/router/route-orchestration.d.ts +1 -1
  293. package/dist/rules-consent.d.ts +48 -40
  294. package/dist/run-local.d.ts +5 -5
  295. package/dist/run-local.js +28 -4
  296. package/dist/runs.d.ts +19 -19
  297. package/dist/runtime-caps-resolver.d.ts +6 -6
  298. package/dist/runtime-governance.d.ts +7 -7
  299. package/dist/security.d.ts +13 -13
  300. package/dist/session-leaf-bus.d.ts +1 -1
  301. package/dist/session-sync-content.d.ts +4 -4
  302. package/dist/session-sync-kernel.d.ts +2 -2
  303. package/dist/session-sync.d.ts +13 -13
  304. package/dist/session-titler.d.ts +1 -1
  305. package/dist/session-watch.d.ts +3 -3
  306. package/dist/shared-memory-scope-authorizer.d.ts +4 -4
  307. package/dist/sighup-idle.d.ts +1 -1
  308. package/dist/spec-fields.d.ts +20 -20
  309. package/dist/ssh-host-key.d.ts +5 -5
  310. package/dist/store-live-probe.d.ts +2 -2
  311. package/dist/task-cwd.d.ts +11 -11
  312. package/dist/task-mcp.d.ts +5 -5
  313. package/dist/task-settings.d.ts +35 -35
  314. package/dist/task-workflow.d.ts +3 -3
  315. package/dist/text-bidi.d.ts +1 -1
  316. package/dist/tool-approval.d.ts +171 -160
  317. package/dist/tool-approval.js +33 -28
  318. package/dist/trace/core-keyset-guard.d.ts +21 -7
  319. package/dist/trace/engine-notice-wire.d.ts +6 -6
  320. package/dist/trace/injection-tier.d.ts +2 -2
  321. package/dist/trace/ledger-events.d.ts +3 -3
  322. package/dist/trace/ledger-sink.d.ts +7 -7
  323. package/dist/trace/project.d.ts +35 -30
  324. package/dist/trace/project.js +9 -0
  325. package/dist/turn-activity.d.ts +4 -4
  326. package/dist/usage-analytics.d.ts +1 -1
  327. package/dist/wall-clock-jump-guard.d.ts +3 -3
  328. package/package.json +6 -6
@@ -1,5 +1,5 @@
1
1
  /**
2
- * #154 件二+件三 —— **装配自证**域:启动期静态自检(拒启判据)与 operator 诊断读面
2
+ * [ref] 件二+件三 —— **装配自证**域:启动期静态自检(拒启判据)与 operator 诊断读面
3
3
  * (`GET /v1/diagnostics/wiring`)。
4
4
  *
5
5
  * 🔴 两件为什么同住一个模块:它们回答的是同一个问题(「这台 worker 到底接了什么线」),只是一个在 boot
@@ -81,7 +81,7 @@ export declare function assertStaticWiringConsistent(facts: StaticWiringFacts, l
81
81
  warn: (msg: string, meta?: Record<string, unknown>) => void;
82
82
  } | undefined): StaticWiringAudit;
83
83
  /**
84
- * [3399]③ clay 裁 (b)(2026-08-12,core [3648]④ + cli [3649]① 双背书):**零凭证 turnkey 形**的
84
+ * [ref]③ clay 裁 (b)(2026-08-12,core [ref]④ + cli [ref]① 双背书):**零凭证 turnkey 形**的
85
85
  * loopback 来源门判据(单一属主,端点与测试同吃)。
86
86
  *
87
87
  * 只在「operator 名单空 ∧ 非多租户 ∧ 全局 service-credential 门也不在场(没配 SERVICE_AUTH_TOKEN /
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— MF-Fleet 实时舰队流。
2
+ * [ref] A9 域模块 —— MF-Fleet 实时舰队流。
3
3
  *
4
4
  * 路由:`GET /v1/fleet/stream`(SSE PUSH:连上先快照,之后每条 per-row delta)。跑在服务凭据门**之前**
5
5
  * (按 principal 自门,与 workflow 只读路由同列)。本域零可变状态。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— sandbox-image-pool 控制面(IMAGE-API-DESIGN.md)。
2
+ * [ref] A9 域模块 —— sandbox-image-pool 控制面(IMAGE-API-DESIGN.md)。
3
3
  *
4
4
  * 路由:P2 bake 作业面 `/v1/images/bakes*`(提交/列表/详情/事件 SSE/取消/claim/ingest)与 P1 镜像索引
5
5
  * `/v1/images*`(digests/profile/select)。**bakes 段必须排在 images 段之前**——P1 的单段 profile 正则会把
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— v2 leader 端点(design/50)。
2
+ * [ref] A9 域模块 —— v2 leader 端点([ref])。
3
3
  *
4
4
  * 路由:`POST /v1/leader`(异步,形同 `/v1/runs`)· `GET /v1/leader/:id`。整域由 `deps.leaderEndpoint`
5
5
  * 的存在与否开关;身份层与 `/v1/runs` 同款(BL-4:此前整条路跳过 authorize/requirePrincipal 且不记 owner,
@@ -1,6 +1,6 @@
1
1
  /**
2
- * #264 v2-c —— **治理携出 bundle 的 operator 面**(core 5.40.0 `MemoryEngine.exportMemoryScopes` /
3
- * `importMemoryBundle`,design/178 v2-c;判据帖 [4315] G1/G2/G3)。
2
+ * [ref] v2-c —— **治理携出 bundle 的 operator 面**(core 5.40.0 `MemoryEngine.exportMemoryScopes` /
3
+ * `importMemoryBundle`,[ref] v2-c;判据帖 [ref] G1/G2/G3)。
4
4
  *
5
5
  * · `POST /v1/memory/export` —— 请求 `{scopes: string[]}`,回**治理完备包**(bundle 原样);
6
6
  * · `POST /v1/memory/import` —— 请求 `{bundle}`,回 `MemoryImportReport` 的白名单投影。
@@ -37,12 +37,12 @@
37
37
  * SQL 孪生补齐两面是上游/本仓 store 层的独立工单(消费台账 debt 行)。
38
38
  *
39
39
  * ── 验型的分权:server 验**形**,core 验**义** ─────────────────────────────────────────────────
40
- * 本层只用 zod 校 JSON **结构**(宪法 [2704]:边界必 schema、禁裸 as-cast)。scopes 的「非空/去重/
40
+ * 本层只用 zod 校 JSON **结构**(宪法 [ref]:边界必 schema、禁裸 as-cast)。scopes 的「非空/去重/
41
41
  * 元素非空」与 bundle 的整包判决(section hash 键集、逐条目 rev 重算、批内唯一性、scope 授权信封)
42
42
  * **全部**归 core —— 在本层抄一遍等于第二真源:core 收紧一格我方不会跟着动,而两边都"绿"。
43
43
  * 于是 `{scopes:["a","a"]}` 这种**形对义错**的请求会走到引擎并带回 `config.memory_export_request`。
44
44
  *
45
- * ── 披露的传导([4352] 权威句;打分帖 [4351] 扣点① 的 server 半场)────────────────────────────
45
+ * ── 披露的传导([ref] 权威句;打分帖 [ref] 扣点① 的 server 半场)────────────────────────────
46
46
  * bundle 体里的 `doc: string[]` 是**铸包方的治理披露**(自由串字面的租户隔离界限等),core 铸包时恒
47
47
  * 写入。本面把它**原样透传**:不剥离、不复述、不另铸 `disclosure` 键。理由是单一属主 —— 复述会随
48
48
  * core 版本漂移,而转发即真话。端点文档(openapi 段 + docs/ASSISTANT-WIRE-CONTRACT.md)负责告诉消费方
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { sendJson, sendError } from "../send.js";
3
- import { buildOriginFence, readOriginAware } from "../../memory-origin-fence.js";
3
+ import { buildOriginFencedBundle, readOriginAware } from "../../memory-origin-fence.js";
4
4
  import { gatedPrincipal, explicitOperatorOk } from "../principal-gate.js";
5
5
  export const MEMORY_BUNDLE_EXPORT_PATH = "/v1/memory/export";
6
6
  export const MEMORY_BUNDLE_IMPORT_PATH = "/v1/memory/import";
@@ -94,8 +94,7 @@ async function handleMemoryBundleBody(req, res, url, ctx, miss) {
94
94
  }
95
95
  try {
96
96
  const bundle = await engineExport(parsed.data.scopes);
97
- const fence = buildOriginFence(bundle.entries, readOriginAware(new URL(req.url ?? "", "http://x").searchParams));
98
- sendJson(res, 200, fence.withheldOriginTagged !== undefined ? { ...bundle, entries: fence.entries, withheldOriginTagged: fence.withheldOriginTagged } : bundle);
97
+ sendJson(res, 200, buildOriginFencedBundle(bundle, readOriginAware(new URL(req.url ?? "", "http://x").searchParams)));
99
98
  }
100
99
  catch (err) {
101
100
  if (!sentClassifiedFailure(res, ctx, "export", err))
@@ -1,13 +1,13 @@
1
1
  /**
2
- * design/316 件③ —— **出处 / 抹除合规面的 operator 两口**(core 5.57.0 `MemoryEngine.provenanceOf` /
3
- * `eraseMemoryEntries`,design/178 v2-a / v2-b)。
2
+ * [ref] 件③ —— **出处 / 抹除合规面的 operator 两口**(core 5.57.0 `MemoryEngine.provenanceOf` /
3
+ * `eraseMemoryEntries`,[ref] v2-a / v2-b)。
4
4
  *
5
5
  * · `GET /v1/memory/entries/:entryId/provenance` —— 回 `EntryProvenanceAccount` 原样;
6
6
  * · `POST /v1/memory/erase` —— 请求 `{requestId, select, allowUnevidenced?}`,回
7
7
  * `MemoryErasureAttestation` 原样。
8
8
  *
9
9
  * ── 为什么是 operator-only ─────────────────────────────────────────────────────────────────────
10
- * 与 #264 的 bundle 两口同族(memory-bundle.ts 的同名段):
10
+ * 与 [ref] 的 bundle 两口同族(memory-bundle.ts 的同名段):
11
11
  * · erase 是**治理写面**,而且是本族里爆炸半径最大的一口 —— 整 scope / 整会话删除是**合法**选择子,
12
12
  * 而 core 的大规模删除熔丝对它**显式不适用**(engine.d.ts:684 逐字:那道熔丝守的是「文件在 harvest
13
13
  * 时悄悄不见了」的事故形,一次显式授权的抹除靠在收执里逐 id 列举来自证);
@@ -63,7 +63,7 @@
63
63
  * 一次**人的**授权表态(「我接受没有证据的删除」),中间层替他勾上就是替他签字。
64
64
  *
65
65
  * ── 验型的分权:server 验**形**,core 验**义**(同 memory-bundle.ts)────────────────────────────
66
- * 本层只用 zod 校 JSON **结构**(宪法 [2704]:边界必 schema、禁裸 as-cast)。三选一选择子的判决
66
+ * 本层只用 zod 校 JSON **结构**(宪法 [ref]:边界必 schema、禁裸 as-cast)。三选一选择子的判决
67
67
  * (恰好一个 ids/scope/sessionId、ids 非空去重、allowUnevidenced 是布尔…)**全部**归 core 的
68
68
  * `erasureRequestInvalid` —— 在本层抄一遍等于第二真源。于是 `{ids:[…], scope:…}` 这种**形对义错**的请求
69
69
  * 会走到引擎并带回 `config.memory_erasure_request`。
@@ -72,10 +72,10 @@
72
72
  * memory-bundle 同族,申明在 test/billable-route-declaration.test.ts)。
73
73
  *
74
74
  * ── 改写门(`isCredentialGatedRewrite`):**两口都进** ──────────────────────────────────────────
75
- * 该门自 #277 起的判据是「持久改写 **或** 授权唯一输入是 principal 头、且**没有属主门兜底**的治理面」:
75
+ * 该门自 [ref] 起的判据是「持久改写 **或** 授权唯一输入是 principal 头、且**没有属主门兜底**的治理面」:
76
76
  * · `POST /v1/memory/erase` 落在**前**一项上,而且是最深的一种:它把条目从本店**删掉**。自造一个在册
77
77
  * operator 头即可对任一租户执行一次不可撤销的删除 —— 无凭证部署上缺的正是「上游会验这个头」这个前提。
78
- * · `GET …/:entryId/provenance` 落在**后**一项上。🔴 这一条**推翻了 design/316 §3 的原始裁定**
78
+ * · `GET …/:entryId/provenance` 落在**后**一项上。🔴 这一条**推翻了 [ref] §3 的原始裁定**
79
79
  * (稿子把它豁免在门外,理由是「爆炸半径=一条」);codex 交叉复审 [high] 指出该理由站不住,亲验后采信:
80
80
  * ⑴ 稿子援引来类比的两条豁免读(`GET /v1/adoption/:id` / `GET /v1/rules`)在门外的**真正**原因是
81
81
  * 它们各有**属主门**兜底,不是「读得少」;本口的授权判据就只有 `explicitOperatorOk`,过了就直接答;
@@ -85,7 +85,7 @@
85
85
  * 先例逐字同源:`POST /v1/memory/export` 当初也「按原措辞本不该进」,同一条论证把它收了进来
86
86
  * ——「把它留在门外只为守住一句措辞,是把措辞看得比它要保护的东西更重」。
87
87
  * 🔴 判据里**刻意不写**「本口 side-effect-free」:那不是这道门的判据。该门拦的是「授权的唯一输入是
88
- * 一个可自造的头」这件事 —— 用「没有副作用」当豁免理由,正是 #277 那次把 `POST /v1/memory/export`
88
+ * 一个可自造的头」这件事 —— 用「没有副作用」当豁免理由,正是 [ref] 那次把 `POST /v1/memory/export`
89
89
  * (纯读、跨租户全库)漏在门外的那句话。
90
90
  * ⚠️ 代价与补偿如实成文:无凭证部署上两口都答 503 `auth.service_token_required`。补偿是**既有旋钮、
91
91
  * 零新增** —— 配 `SERVICE_AUTH_TOKEN`(正路),或本地开发显式 `ALLOW_UNAUTHED_WRITES=true`
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/378 D2/D3(316 车C)—— 记忆 **consolidation 阀门**的 operator 两口:
2
+ * [ref] D2/D3(316 车C)—— 记忆 **consolidation 阀门**的 operator 两口:
3
3
  *
4
4
  * · `POST /v1/admin/memory/consolidation/run` —— 跑(或**续跑**)一轮,同步回一份收执**摘要投影**;
5
5
  * · `GET /v1/admin/memory/consolidation` —— D3 状态投影(阀门、座位、scope 表、上一轮的账)。
@@ -1,13 +1,13 @@
1
1
  /**
2
- * design/316 件② —— **外源标记人面的 operator 三口**(core 5.59.0 `MemoryEngine.listExternalOriginEntries` /
3
- * `listOriginClearances` / `clearEntryOrigin`,design/336 §13-4①②)。
2
+ * [ref] 件② —— **外源标记人面的 operator 三口**(core 5.59.0 `MemoryEngine.listExternalOriginEntries` /
3
+ * `listOriginClearances` / `clearEntryOrigin`,[ref] §13-4①②)。
4
4
  *
5
5
  * · `GET /v1/memory/origin/external?scopes=a,b` —— 点名 scope 里每一条带外源标记的条目 + 出处账;
6
6
  * · `GET /v1/memory/origin/clearances` —— 清标审计账(**白名单投影**,见下);
7
7
  * · `POST /v1/memory/origin/entries/:entryId/clear` `{requestId, reason}` —— 审计化的 UN-MARK 阀门。
8
8
  *
9
9
  * ── 为什么是 operator-only ─────────────────────────────────────────────────────────────────────
10
- * 与件③(memory-compliance.ts)、#264 的 bundle 两口同族:
10
+ * 与件③(memory-compliance.ts)、[ref] 的 bundle 两口同族:
11
11
  * · 前两口是**跨租户治理读**:一次调用取回任意 scope 的条目 + 每条的完整出处账(贡献会话 id、污染
12
12
  * 理由、托管链事件),按定义超出任何单个 principal 的自助边界;
13
13
  * · clear 是**治理写面**,而且是记忆域里语义最重的一次表态 —— 它把「这条记忆来自外部、用前先核」
@@ -26,7 +26,7 @@
26
26
  * compliance 两族刻意不同字,因为要查的旋钮不是同一个(那两族自己的头注就吃过复用文案的亏)。
27
27
  *
28
28
  * ── `scopes` 为什么必须由调用方给(F-13 的诚实形)──────────────────────────────────────────────
29
- * 🔴 本仓**今天没有任何 scope 枚举读面**。core 5.59.0 长出了 `listMemoryScopes`(#437③:File 腿在场、
29
+ * 🔴 本仓**今天没有任何 scope 枚举读面**。core 5.59.0 长出了 `listMemoryScopes`([ref]③:File 腿在场、
30
30
  * SQL 腿是 core 候升件,且带「backend 是否支持枚举」判别位——不支持**永不读作零**),但本仓尚未接线。
31
31
  * 于是 v1 的形是:scope 名**显式提供**,缺参 400 并**指路来源**。
32
32
  * 为什么不给一个默认名单(比如「本部署配过的那些」):污染审计的价值全在**发现链闭合**,而不完备是
@@ -45,23 +45,23 @@
45
45
  * = `entryText`,逐字写理由):core 加一个键 ⇒ TS2344 ⇒ 由人处置,而不是悄悄上 wire 或悄悄漏掉。
46
46
  * 🔴 白名单是**深**的,不是只做一层(codex 交叉复审 [high] 抓的第一版病):嵌套的 `origin` 也逐键投影
47
47
  * —— 一层白名单 + 一个整只透传的嵌套对象,等于给这条排除留了一个旁路,全文见 {@link buildOriginWire}。
48
- * 🔴 **剥了不等于不说**:投影补一个 `custodyBytes`(托管字节数)。这是 #196 absence-reports-not-silent-green
48
+ * 🔴 **剥了不等于不说**:投影补一个 `custodyBytes`(托管字节数)。这是 [ref] absence-reports-not-silent-green
49
49
  * 在本口的落法 —— operator 判「这个 pending 行还揣着一条记忆吗」只需要这一位;悄悄把整个托管概念从
50
50
  * 审计面上抹掉,会让一个**必须由人处置**的崩溃恢复席看上去不存在。
51
51
  *
52
- * ── 拒因族:**闭集逐码 switch**(#123 码族)────────────────────────────────────────────────────
53
- * 见 {@link sentClearCode} 的头注(逐码状态与理由、以及 core 真形与 design/316 稿面的**一处偏差**)。
52
+ * ── 拒因族:**闭集逐码 switch**([ref] 码族)────────────────────────────────────────────────────
53
+ * 见 {@link sentClearCode} 的头注(逐码状态与理由、以及 core 真形与 [ref] 稿面的**一处偏差**)。
54
54
  *
55
55
  * 计费/lane:三口都是**部署级治理动作**,零模型工作 ⇒ `billable=false`(与 adoption / retention-ops /
56
56
  * memory-bundle / memory-compliance 同族,申明在 test/billable-route-declaration.test.ts)。
57
57
  *
58
58
  * ── 改写门(`isCredentialGatedRewrite`):**三口全进** ──────────────────────────────────────────
59
- * 该门自 #277 起的判据是「持久改写 **或** 授权唯一输入是 principal 头的跨租户治理读」:
59
+ * 该门自 [ref] 起的判据是「持久改写 **或** 授权唯一输入是 principal 头的跨租户治理读」:
60
60
  * · `POST …/clear` 落在**前**一项:它把一条条目的外源披露**永久摘掉**(墓碑 + 同 id 重录),自造一个
61
61
  * 在册 operator 头即可让任意租户的一条外来记忆看上去是本店自产的 —— 而记忆是模型每次挂载都读的面;
62
62
  * · `GET …/external` 落在**后**一项,而且是这一族里爆炸半径最大的读:一次调用取回**任意 scope**的
63
63
  * 条目 + 每条的完整出处账(贡献会话 id、污染理由、仓内 ingest 路径与内容哈希、托管链事件)。判据与
64
- * `POST /v1/memory/export`(#277 收进门的那条纯读)逐字同构:它没有属主门兜底,operator 头过了就直接答。
64
+ * `POST /v1/memory/export`([ref] 收进门的那条纯读)逐字同构:它没有属主门兜底,operator 头过了就直接答。
65
65
  * · `GET …/clearances` —— 🔴 **本车第一版把它留在门外,codex 交叉复审 [high] 推翻,亲验后采信**。
66
66
  * 那一版的理由是「投影后不含条目正文,爆炸半径差一个量级」,而这个理由**用错了基准**:本门的判据
67
67
  * 从来不是「含不含正文」,而是「授权的**唯一**输入是 principal 头」∧「没有属主门兜底」。按那条判据,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— memory 导出/同步 + 只读策略面。
2
+ * [ref] A9 域模块 —— memory 导出/同步 + 只读策略面。
3
3
  *
4
4
  * 路由:`GET /v1/memory/export`、`POST /v1/memory/sync/:scope`、`GET /v1/policy`。
5
5
  * owner 门 = 「本人 user scope / 显式 operator / `org:` 键的目录成员」(见 {@link gateMemoryScope}),
@@ -8,9 +8,9 @@
8
8
  import type { IncomingMessage, ServerResponse } from "node:http";
9
9
  import type { RouteCtx } from "../route-ctx.js";
10
10
  /**
11
- * #271 件3(#275 A2 车立的欠账,[4163] 我方认领)—— `GET /v1/memory/export` 的 keyset 分页上限。
11
+ * [ref] 件3([ref] A2 车立的欠账,[ref] 我方认领)—— `GET /v1/memory/export` 的 keyset 分页上限。
12
12
  *
13
- * 在此之前本面是**整盘导出**:一个几千条目的盘就是一个几 MB 的响应体,壳侧(sema-web 只读页)
13
+ * 在此之前本面是**整盘导出**:一个几千条目的盘就是一个几 MB 的响应体,壳侧(sema-web-admin 只读页)
14
14
  * 无从分次要 —— 那是它真实撞到的天花板。分页是 **additive** 的:`?limit=` 缺席 ⇒ 旧契约逐字不变
15
15
  * (全量数组、响应键一个不多),所以现行消费端零破坏;要分页的调用方自己带 `limit` 进来。
16
16
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— 会话外事件注入 / 唤醒(design/144 §2 §3)。
2
+ * [ref] A9 域模块 —— 会话外事件注入 / 唤醒([ref] §2 §3)。
3
3
  *
4
4
  * 路由:`POST /v1/sessions/:id/notify`(external-notification-bridge 的 HTTP 入站门:live 走 core
5
5
  * `TaskStream.notify()`,idle 走 inbox park,下次开流 drain)、`POST /v1/sessions/:id/wake`(对 task_done
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— 观测只读面。
2
+ * [ref] A9 域模块 —— 观测只读面。
3
3
  *
4
4
  * 路由:`GET /v1/outcomes`(operator-only 机械信号聚合)、`GET /v1/usage`(per-principal 累计花费读面,
5
5
  * 与 quotaExceeded 门同键、只读不消费)。本域零可变状态。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * #270 车2 —— **托管留存的 operator 治理面**(设计稿 `docs/DESIGN-270-retention-lane.md` §5/§6)。
2
+ * [ref] 车2 —— **托管留存的 operator 治理面**(设计稿 `docs/DESIGN-270-retention-lane.md` §5/§6)。
3
3
  *
4
4
  * · `PUT /v1/ops/retention/holds/:domain` —— 放置 legal hold;
5
5
  * · `DELETE /v1/ops/retention/holds/:domain` —— 解除;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * #154 车二 + #203 §2 —— **规则车道的 wire 面**(design/179 §7 的导入半场 + design/203 的撤销半场)。
2
+ * [ref] 车二 + [ref] §2 —— **规则车道的 wire 面**([ref] §7 的导入半场 + [ref] 的撤销半场)。
3
3
  *
4
4
  * POST /v1/rules/cc-import/prepare → 预览 + 一张**一次性、principal 绑定、有期、载荷绑定**的票
5
5
  * POST /v1/rules/cc-import/redeem → 原子消费票 → confirm → 批量兑付进店
@@ -11,7 +11,7 @@
11
11
  * 因此**导入两口**只认已验明的 principal,连 `explicitOperatorOk` 的旁路都不给:一个 operator 想给
12
12
  * 自己导规则,用他自己的 principal 走同一条路即可(那时他就是租户)。
13
13
  *
14
- * 🔴 **撤销面两口多一条 operator 超范围域,而这不是上面那句话的例外,是它的对偶**(design/203 §2 设计题
14
+ * 🔴 **撤销面两口多一条 operator 超范围域,而这不是上面那句话的例外,是它的对偶**([ref] §2 设计题
15
15
  * 一裁定):`?principal=` / body 里的 `principal` 让 operator 读**或收回**任一租户的规则。方向决定授权:
16
16
  * 收回是**收紧**(core 的 `removePersistedRule` 头注逐字:「a host may narrow on a user's behalf, it may
17
17
  * not widen」),而多租户管理员能回收权限正是撤销面的本义。读那一半同样只开给 operator ——
@@ -29,7 +29,7 @@ import type { IncomingMessage, ServerResponse } from "node:http";
29
29
  import type { RouteCtx } from "../route-ctx.js";
30
30
  export declare const RULES_CC_IMPORT_PREPARE_PATH = "/v1/rules/cc-import/prepare";
31
31
  export declare const RULES_CC_IMPORT_REDEEM_PATH = "/v1/rules/cc-import/redeem";
32
- /** #265 A7:File 规则直通票口两条(与 cc-import 两口并列,票语义分家见 `rules-consent.ts` 的 A7 段)。 */
32
+ /** [ref] A7:File 规则直通票口两条(与 cc-import 两口并列,票语义分家见 `rules-consent.ts` 的 A7 段)。 */
33
33
  export declare const RULES_LOCAL_IMPORT_PREPARE_PATH = "/v1/rules/local-import/prepare";
34
34
  export declare const RULES_LOCAL_IMPORT_REDEEM_PATH = "/v1/rules/local-import/redeem";
35
35
  /** 撤销面两口共用的字面路径(GET 列举 / DELETE 撤销)。 */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/383 §2.1 / §3.4 S-8①(server S-49;[5596] 认领)—— **中途翻转 verb** 的 wire 面:
2
+ * [ref] §2.1 / §3.4 S-8①(server [ref];[ref] 认领)—— **中途翻转 verb** 的 wire 面:
3
3
  *
4
4
  * `POST /v1/runs/:id/memory/capture-optout` body `{ reason?: string }`
5
5
  * → 200 `{ taskId, sessionId, outcome: "created" | "existed" }`
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— 异步 run 面与它的全部动词。
2
+ * [ref] A9 域模块 —— 异步 run 面与它的全部动词。
3
3
  *
4
4
  * 路由:`POST /v1/runs`(异步提交)· `GET /v1/runs/:id[/events]`(轮询 / 可恢复 SSE)· 运行期动词
5
5
  * `cancel` / `steer` / `compact` / `detach` · 子代理面 `subagents/:target/{steer,resume,output,stream}` ·
@@ -22,8 +22,8 @@ export declare const RUN_DETACH_RE: RegExp;
22
22
  export declare const RUN_COMPACT_RE: RegExp;
23
23
  export declare const RUN_INTERRUPT_RE: RegExp;
24
24
  /** PAIR-REVIEW F-10:runs 面 404 文案统一富形——a\* 形 id(background-agent registry 句柄,`a`+hex 短形)
25
- * 是「结构性不在 run 店」的常客([1347]⑤ 记档裁量:不改路由,只给引导)。识别句法形即补引导;
26
- * 非 a\* 形保通用富文案(cancel 腿 [888]① 同款)。 */
25
+ * 是「结构性不在 run 店」的常客([ref]⑤ 记档裁量:不改路由,只给引导)。识别句法形即补引导;
26
+ * 非 a\* 形保通用富文案(cancel 腿 [ref]① 同款)。 */
27
27
  export declare const ELICIT_RESPOND_RE: RegExp;
28
28
  export declare const QUESTION_RESPOND_RE: RegExp;
29
29
  export declare const TOOL_APPROVAL_RESPOND_RE: RegExp;
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { uuidv7, mintCheckpointToken, CheckpointError, validatePendingSteer } from "@sema-agent/core";
3
3
  import { isTerminalRunStatus, isParkedRunStatus } from "../../plugins/store-contracts.js";
4
+ import { LIVE_RUN_GATE_KINDS, TERMINAL_PARK_GATE_KINDS } from "../../plugins/checkpoint-store-sql.js";
4
5
  import { redactSecrets } from "../../trace/redact.js";
5
6
  import { HttpError, verifiedPrincipal, isUuidV7, encodeCheckpointScope } from "../../security.js";
6
7
  import { runInBackground } from "../../runs.js";
@@ -286,7 +287,7 @@ async function handleRunsBody(req, res, url, ctx, miss) {
286
287
  const cs = deps.checkpointStore;
287
288
  let note = "cancelled while suspended (pending approval settled)";
288
289
  if (cs) {
289
- const token = await cs.findPendingTokenBySession(run.sessionId);
290
+ const token = await cs.findPendingTokenBySession(run.sessionId, undefined, { gateKinds: LIVE_RUN_GATE_KINDS });
290
291
  if (token) {
291
292
  const cp = await cs.get(token);
292
293
  const won = cp ? await cs.expire(token, cp.scope) : false;
@@ -459,10 +460,11 @@ async function handleRunsBody(req, res, url, ctx, miss) {
459
460
  const cs = deps.checkpointStore;
460
461
  if (!cs)
461
462
  return "no-store";
462
- const scope = await cs.peekPendingScope(run.sessionId);
463
+ const parkBinding = { gateKinds: LIVE_RUN_GATE_KINDS };
464
+ const scope = await cs.peekPendingScope(run.sessionId, parkBinding);
463
465
  if (scope === null || scope === undefined)
464
466
  return "no-checkpoint";
465
- const token = await cs.findPendingTokenBySession(run.sessionId, scope);
467
+ const token = await cs.findPendingTokenBySession(run.sessionId, scope, parkBinding);
466
468
  if (!token)
467
469
  return "no-checkpoint";
468
470
  try {
@@ -627,7 +629,7 @@ async function handleRunsBody(req, res, url, ctx, miss) {
627
629
  mintResult.noResumeCtx = true;
628
630
  return;
629
631
  }
630
- const winner = await cs.findPendingTokenBySession(run.sessionId).catch(() => null);
632
+ const winner = await cs.findPendingTokenBySession(run.sessionId, undefined, { gateKinds: TERMINAL_PARK_GATE_KINDS, pick: "oldest" }).catch(() => null);
631
633
  if (winner !== null && winner !== wakeToken) {
632
634
  await cs.expire(wakeToken, cpScope).catch(() => undefined);
633
635
  await parkOnce(winner, cpScope);
@@ -1347,11 +1349,8 @@ async function handleRunVerbsBody(req, res, url, ctx, miss) {
1347
1349
  return true;
1348
1350
  if (deps.toolApproval?.editedDecisionInFlight(row.askId) === true)
1349
1351
  return true;
1350
- const settled = deps.toolApproval?.notifyExternalDecision(row.askId, row.decision === "approve");
1352
+ const settled = deps.toolApproval?.notifyExternalDecision(row.askId, row.decision === "approve", row.updatedInput);
1351
1353
  observedSettled.set(row.askId, settled?.settled ?? 0);
1352
- if (row.decision === "approve" && (settled?.settled ?? 0) > 0) {
1353
- recordFailOpen("server.hitl.row-derived-approve-drops-updated-input", "runs:sync-live-from-decided-row");
1354
- }
1355
1354
  return true;
1356
1355
  };
1357
1356
  const decisionNoteEcho = (row) => (row.decisionNote === null ? {} : { decisionNote: row.decisionNote });
@@ -1431,11 +1430,6 @@ async function handleRunVerbsBody(req, res, url, ctx, miss) {
1431
1430
  sendTerminal(row0);
1432
1431
  return;
1433
1432
  }
1434
- if (body.decision === "approve" && hasUpdatedInput && (deps.toolApproval?.liveConsumerCount(askId) ?? 0) === 0) {
1435
- deps.logger?.warn?.("ask_decision_edit_undeliverable", { taskId, askId });
1436
- sendError(res, 409, "conflict.ask_edit_undeliverable", "this decision carries an edited input but no live approval waiter for this ask exists on THIS replica — the edit cannot be bound to the decision (the durable ask row has no field for it), so committing would run the ORIGINAL input instead. Nothing was decided: re-send without updatedInput to approve the original as-is, or send the decision to the replica holding this ask (the live POST /v1/tool-approvals/:approvalId/respond leg is always same-replica)");
1437
- return;
1438
- }
1439
1433
  let outcome;
1440
1434
  const releaseEditMark = body.decision === "approve" && hasUpdatedInput ? deps.toolApproval?.markEditedDecisionInFlight(askId) : undefined;
1441
1435
  try {
@@ -1444,6 +1438,7 @@ async function handleRunVerbsBody(req, res, url, ctx, miss) {
1444
1438
  decisionActor: actor,
1445
1439
  decisionNote: body.note ?? null,
1446
1440
  idempotencyKey: body.idempotencyKey ?? null,
1441
+ ...(body.decision === "approve" && hasUpdatedInput ? { updatedInput: body.updatedInput } : {}),
1447
1442
  });
1448
1443
  }
1449
1444
  catch (err) {
@@ -1464,7 +1459,7 @@ async function handleRunVerbsBody(req, res, url, ctx, miss) {
1464
1459
  confirmed.decision === body.decision &&
1465
1460
  confirmed.idempotencyKey === body.idempotencyKey &&
1466
1461
  !confirmed.provisional) {
1467
- const settledNow = deps.toolApproval.notifyExternalDecision(askId, confirmed.decision === "approve", body.updatedInput).settled;
1462
+ const settledNow = deps.toolApproval.notifyExternalDecision(askId, confirmed.decision === "approve", confirmed.updatedInput).settled;
1468
1463
  deps.logger?.warn?.("ask_decision_edit_settled_after_ambiguous_commit", { taskId, askId, settled: settledNow });
1469
1464
  }
1470
1465
  }
@@ -1503,12 +1498,12 @@ async function handleRunVerbsBody(req, res, url, ctx, miss) {
1503
1498
  return;
1504
1499
  if (outcome.row.decision !== body.decision) {
1505
1500
  deps.logger?.error?.("ask_decision_row_diverged", { taskId, askId, requested: body.decision, stored: outcome.row.decision });
1506
- deps.toolApproval?.notifyExternalDecision(outcome.row.askId, outcome.row.decision === "approve");
1501
+ deps.toolApproval?.notifyExternalDecision(outcome.row.askId, outcome.row.decision === "approve", outcome.row.updatedInput);
1507
1502
  sendError(res, 500, "internal.error", "the ask row was rewritten between commit and read-back — the decision that stands is not the one this request submitted; re-read the ask before acting on it");
1508
1503
  return;
1509
1504
  }
1510
- const settled = deps.toolApproval?.notifyExternalDecision(outcome.row.askId, outcome.row.decision === "approve", hasUpdatedInput ? body.updatedInput : undefined).settled ?? 0;
1511
- const forwarded = outcome.row.decision === "approve" && hasUpdatedInput && settled > 0;
1505
+ const settled = deps.toolApproval?.notifyExternalDecision(outcome.row.askId, outcome.row.decision === "approve", outcome.row.updatedInput).settled ?? 0;
1506
+ const forwarded = outcome.row.decision === "approve" && outcome.row.updatedInput !== undefined && settled > 0;
1512
1507
  sendJson(res, 200, {
1513
1508
  askId: outcome.row.askId,
1514
1509
  taskId: outcome.row.taskId,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— 2c session-sync 面(sema-internal server/docs/DESIGN-session-sync.md §15 + §5–§10)。
2
+ * [ref] A9 域模块 —— 2c session-sync 面(sema-internal server/docs/DESIGN-session-sync.md §15 + §5–§10)。
3
3
  *
4
4
  * 路由:`/v1/sessions/:id/sync/{manifest,entries,import,plan,blobs,snapshots/:k/blobs/:b,import/:staging/entries}`。
5
5
  * 每条都像 fork/delete 一样 owner-gated;无持久 session store 时 501(能力面与路由解析同真值)。
@@ -17,7 +17,7 @@ export type PendingStaging = {
17
17
  owner: string | null;
18
18
  resolution?: "overwrite-dst";
19
19
  operatorOk: boolean;
20
- /** S-15: the session's file-history envelope (or null — no history travelled). Replaces the E19 per-key manifests. */
20
+ /** [ref]: the session's file-history envelope (or null — no history travelled). Replaces the E19 per-key manifests. */
21
21
  fileHistory: FileHistoryExport | null;
22
22
  policy: SessionRulesRecord[];
23
23
  anchors: Array<{
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— 会话列表 / 发件链接列表。
2
+ * [ref] A9 域模块 —— 会话列表 / 发件链接列表。
3
3
  *
4
4
  * 路由:`GET /v1/sessions`(CC /resume picker,keyset 分页)、`GET /v1/sendfile-links`。
5
5
  * owner-scope 与 trace 列表同一权威模型(system/traceToken=fleet-wide,principal=钉住本人)。本域零可变状态。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— 单会话面。
2
+ * [ref] A9 域模块 —— 单会话面。
3
3
  *
4
4
  * 路由:`/v1/sessions/:id` 的 init / settings / mcp / head / events(SSE)/ fork / DELETE / policy / workspace,
5
5
  * 外加同段的 `deps.sessionAudit` 只读审计面。
@@ -12,6 +12,7 @@
12
12
  * `sse.sseConnections` / `sse.sseOwnerLookups`——`let` 无法跨模块共享自增。判据/时机/配对释放逐字未动。
13
13
  */
14
14
  import type { IncomingMessage, ServerResponse } from "node:http";
15
+ import { type SessionMemoryStatus } from "@sema-agent/core";
15
16
  import type { RouteCtx } from "../route-ctx.js";
16
17
  /** 单域独占状态。每个 server 实例一份——模块级会把连接坑/缓存跨实例串味。 */
17
18
  export interface SessionsLocal {
@@ -36,6 +37,13 @@ export interface SessionsLocal {
36
37
  degraded?: boolean;
37
38
  }>;
38
39
  }>;
40
+ /** [ref]①:memory-status 读面的短 TTL single-flight 缓存(理由见 `MEMORY_STATUS_TTL_MS` 注)。
41
+ * 键 = sessionId **裸键**(答案与调用方无关 —— 属主门在缓存读**之前**跑,外人到不了这张表;
42
+ * mcp/a2a 按 (scenario, principal) 分键是因为它们的面按人裁,这张面不按人裁,分键只会白扩表)。 */
43
+ memoryStatusCache: Map<string, {
44
+ at: number;
45
+ status: Promise<SessionMemoryStatus>;
46
+ }>;
39
47
  }
40
48
  export declare function createSessionsLocal(): SessionsLocal;
41
49
  export declare function handleSessions(req: IncomingMessage, res: ServerResponse, url: string, ctx: RouteCtx): Promise<boolean>;
@@ -10,6 +10,7 @@ const MCP_STATUS_TTL_MS = 5_000;
10
10
  const MCP_MATERIALIZE_TIMEOUT_MS = 10_000;
11
11
  const A2A_STATUS_TTL_MS = 5_000;
12
12
  const A2A_MATERIALIZE_TIMEOUT_MS = 10_000;
13
+ const MEMORY_STATUS_TTL_MS = 5_000;
13
14
  const A2A_PANEL_MAX_TOOL_NAMES = 200;
14
15
  export function createSessionsLocal() {
15
16
  return {
@@ -17,6 +18,7 @@ export function createSessionsLocal() {
17
18
  sseOwnerLookups: 0,
18
19
  mcpStatusCache: new Map(),
19
20
  a2aStatusCache: new Map(),
21
+ memoryStatusCache: new Map(),
20
22
  };
21
23
  }
22
24
  export async function handleSessions(req, res, url, ctx) {
@@ -430,7 +432,7 @@ async function handleSessionsBody(req, res, url, ctx, miss) {
430
432
  sendError(res, 404, "not_found.session", "session not found");
431
433
  return;
432
434
  }
433
- if (!runOwnerOk(req, res, audit.owner))
435
+ if (!runOwnerOk(req, res, audit.owner, "session"))
434
436
  return;
435
437
  const faces = deps.memoryCompliance;
436
438
  if (faces === undefined) {
@@ -469,6 +471,64 @@ async function handleSessionsBody(req, res, url, ctx, miss) {
469
471
  return;
470
472
  }
471
473
  }
474
+ {
475
+ const msm = req.method === "GET" ? /^\/v1\/sessions\/([^/]+)\/memory-status$/.exec(url) : null;
476
+ if (msm) {
477
+ const sessionId = safeDecode(msm[1]);
478
+ if (sessionId === null) {
479
+ sendError(res, 400, "request.path_malformed", "session id segment is not valid percent-encoding");
480
+ return;
481
+ }
482
+ if (deps.config.requirePrincipal && !gatedPrincipal(req, deps.config)) {
483
+ sendError(res, 401, "auth.principal_required", `missing principal header '${deps.config.principalHeader}'`);
484
+ return;
485
+ }
486
+ if (!deps.sessionAudit) {
487
+ sendError(res, 501, "capability.memory_engine_required", "session memory status is not available on this deployment — it requires a wired memory engine (MEMORY_ENGINE=on) whose backend owns the engine control plane (controlPlaneRoot); the file memory backend does, the pg/tidb memory backends do not (their control plane would land on a replica's local disk)");
488
+ return;
489
+ }
490
+ const audit = await deps.sessionAudit(sessionId);
491
+ if (!audit) {
492
+ sendError(res, 404, "not_found.session", "session not found");
493
+ return;
494
+ }
495
+ if (!runOwnerOk(req, res, audit.owner, "session"))
496
+ return;
497
+ const face = deps.sessionMemoryStatus;
498
+ if (face === undefined) {
499
+ sendError(res, 501, "capability.memory_engine_required", "session memory status is not available on this deployment — it requires a wired memory engine (MEMORY_ENGINE=on) whose backend owns the engine control plane (controlPlaneRoot); the file memory backend does, the pg/tidb memory backends do not (their control plane would land on a replica's local disk)");
500
+ return;
501
+ }
502
+ try {
503
+ const { memoryStatusCache } = ctx.local.sessions;
504
+ let entry = memoryStatusCache.get(sessionId);
505
+ if (!entry || Date.now() - entry.at > MEMORY_STATUS_TTL_MS) {
506
+ if (memoryStatusCache.size > 1024)
507
+ memoryStatusCache.clear();
508
+ const status = face.status(sessionId);
509
+ const fresh = { at: Date.now(), status };
510
+ memoryStatusCache.set(sessionId, fresh);
511
+ status.catch(() => { if (memoryStatusCache.get(sessionId) === fresh)
512
+ memoryStatusCache.delete(sessionId); });
513
+ entry = fresh;
514
+ }
515
+ const s = await entry.status;
516
+ sendJson(res, 200, {
517
+ sessionId,
518
+ ...(s.captureOptedOut !== undefined ? { captureOptedOut: s.captureOptedOut } : {}),
519
+ ...(s.committedCount !== undefined ? { committedCount: s.committedCount } : {}),
520
+ ...(s.foldedCount !== undefined ? { foldedCount: s.foldedCount } : {}),
521
+ ...(s.optOutSource !== undefined ? { optOutSource: s.optOutSource } : {}),
522
+ ...(s.lastCaptureAt !== undefined ? { lastCaptureAt: s.lastCaptureAt } : {}),
523
+ });
524
+ }
525
+ catch (err) {
526
+ deps.logger?.warn?.("session_memory_status_failed", { sessionId, err: String(err) });
527
+ sendError(res, 500, "internal.error", "session memory status read failed");
528
+ }
529
+ return;
530
+ }
531
+ }
472
532
  if (deps.sessionAudit && req.method === "GET") {
473
533
  const sm = /^\/v1\/sessions\/([^/]+)$/.exec(url);
474
534
  if (sm) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/177 —— 共享记忆库(org 盘)的**只读 HTTP 面**。
2
+ * [ref] —— 共享记忆库(org 盘)的**只读 HTTP 面**。
3
3
  *
4
4
  * 路由:`GET /v1/shared-memory/stores`、`GET /v1/shared-memory/stores/:store/documents`、
5
5
  * `GET /v1/shared-memory/stores/:store/document?path=`。本域零可变状态。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— sideQuery 一次性问答面([1469],core 1.361)。
2
+ * [ref] A9 域模块 —— sideQuery 一次性问答面([ref],core 1.361)。
3
3
  *
4
4
  * 路由:`POST /v1/side-query` —— 无 session / 无工具执行 / 无 policy gate / 无引擎侧记账 / 无流式的
5
5
  * 一次性 brain 路由问答(v1 刻意面 = core 规格 side-query.d.ts)。cli 壳侧十几个 utility(标题/摘要/
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— 同步提交面 `POST /v1/tasks` / `POST /v1/tasks/stream`(+ design/158 B3 三腿具名化)。
2
+ * [ref] A9 域模块 —— 同步提交面 `POST /v1/tasks` / `POST /v1/tasks/stream`(+ [ref] B3 三腿具名化)。
3
3
  *
4
4
  * 一条路由两条腿:`/v1/tasks/stream` = SSE 活流(单次尝试,verify/cascade 在此 400);`/v1/tasks` = 同步等结果
5
5
  * (verify / cascade / plain 三选一)。两腿共享同一个 Idempotency-Key 包装:先 `peek` 重放(含 IN-FLIGHT 的
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— Task Trace 只读面 + 用量统计面。
2
+ * [ref] A9 域模块 —— Task Trace 只读面 + 用量统计面。
3
3
  *
4
4
  * 路由:`GET /v1/tasks/source-summary`(跨租户 door 汇总,ops-only)、`GET /v1/tasks[/:id/{turns,stream,artifacts}]`
5
5
  * (S1 Task Trace API)、`GET /v1/usage/{summary,series,breakdown}`(web P4 / registry AnalyticsSource)。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 域模块 —— S8 自编排 workflow 面(design/97/98)。
2
+ * [ref] A9 域模块 —— S8 自编排 workflow 面([ref]/98)。
3
3
  *
4
4
  * 路由:`GET /v1/workflows`(列表)· `GET /v1/workflows/:id[/journal]`(详情)· `GET /v1/workflows/:id/stream`
5
5
  * (在进程内 live SSE)· `POST /v1/workflows/:id/agents/:label/steer`(SVC-5:给 workflow 里某个仍在跑的
@@ -1,5 +1,5 @@
1
1
  /**
2
- * design/158 A9 装配缝的一片小叶子 —— 提交路径共用的两个纯函数(run 行元数据 + cascade 配置)。
2
+ * [ref] A9 装配缝的一片小叶子 —— 提交路径共用的两个纯函数(run 行元数据 + cascade 配置)。
3
3
  *
4
4
  * 为什么单独成文件:`runMeta` 被 tasks 与 runs **两个**域模块调用,`cascadeConfig` 同理(还被测试直接引)。
5
5
  * 挂在任一域模块上都会造出 routes/* 互相值 import 的第二条边;它们又是纯函数(只依赖入参 + redact 叶子),