@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
@@ -0,0 +1,54 @@
1
+ import { gatedPrincipal } from "./principal-gate.js";
2
+ import { refusalBody } from "./refusal-body.js";
3
+ import { sendError } from "./send.js";
4
+ export function liveRunIdsOf(inflightRuns, steerableRuns) {
5
+ return new Set([...inflightRuns.keys(), ...steerableRuns.keys()]);
6
+ }
7
+ export const RUN_CONCURRENCY_CAP_REASON = "run_concurrency_cap";
8
+ export const RATE_EXCEEDED_REASONS = [RUN_CONCURRENCY_CAP_REASON];
9
+ export const RUN_CONCURRENCY_RETRY_AFTER_SEC = 5;
10
+ const UNTRACKED_SLOT = { release: () => undefined };
11
+ export function runConcurrencyRefusalOf() {
12
+ return {
13
+ status: 429,
14
+ body: refusalBody({
15
+ errorCode: "limit.rate_exceeded",
16
+ message: "too many runs are in flight on this server right now — nothing was started; retry after the Retry-After interval",
17
+ facts: { reason: RUN_CONCURRENCY_CAP_REASON, retryAfterSec: RUN_CONCURRENCY_RETRY_AFTER_SEC },
18
+ }),
19
+ retryAfterSec: RUN_CONCURRENCY_RETRY_AFTER_SEC,
20
+ };
21
+ }
22
+ export function createRunConcurrencyGate(ctx) {
23
+ const { deps, inflightRuns, steerableRuns } = ctx;
24
+ const seats = new Set();
25
+ function admitRun(req, res) {
26
+ const { runMaxConcurrent: globalCap, runMaxConcurrentPerPrincipal: ownCap } = deps.config;
27
+ if (globalCap === 0 && ownCap === 0)
28
+ return UNTRACKED_SLOT;
29
+ const owner = gatedPrincipal(req, deps.config);
30
+ const live = liveRunIdsOf(inflightRuns, steerableRuns);
31
+ const inFlight = live.size + seats.size;
32
+ let scope;
33
+ if (globalCap > 0 && inFlight >= globalCap)
34
+ scope = "global";
35
+ else if (ownCap > 0 && owner !== undefined) {
36
+ const holders = [...[...live].map((id) => inflightRuns.get(id)?.owner), ...[...seats].map((seat) => seat.owner)];
37
+ if (holders.filter((o) => o === owner).length >= ownCap)
38
+ scope = "principal";
39
+ }
40
+ if (scope !== undefined) {
41
+ deps.logger?.info?.("run_concurrency_cap_refused", { scope, inFlight, cap: scope === "global" ? globalCap : ownCap, hasPrincipal: owner !== undefined });
42
+ const refusal = runConcurrencyRefusalOf();
43
+ const { error, errorCode, ...extra } = refusal.body;
44
+ res.setHeader("retry-after", String(refusal.retryAfterSec));
45
+ sendError(res, refusal.status, errorCode, error, extra);
46
+ return undefined;
47
+ }
48
+ const seat = { owner };
49
+ seats.add(seat);
50
+ return { release: () => void seats.delete(seat) };
51
+ }
52
+ return { admitRun };
53
+ }
54
+ //# sourceMappingURL=run-concurrency-cap.js.map
@@ -2,7 +2,7 @@ import http from "node:http";
2
2
  import type { MemoryComplianceFaces, MemoryOriginFaces, SessionMemoryStatusFace } from "../memory-operator-faces.js";
3
3
  import type { SideQueryAccounting } from "../budget.js";
4
4
  import type { IncomingMessage } from "node:http";
5
- import { type Runner, type RunnerDeps, type TaskSpec, type TaskResult, type WorkflowRunStore, type MemoryEntry, type MemoryExportBundle, type MemoryImportReport, type ConsolidationRunReceipt, type ConsolidationDriverRunRow, type SideQuerySpec, type SideQueryResult, type Brain, type EngineNotice } from "@sema-agent/core";
5
+ import { type Runner, type RunnerDeps, type TaskSpec, type TaskResult, type WorkflowRunStore, type MemoryEntry, type MemoryExportBundle, type MemoryImportReport, type SideQuerySpec, type SideQueryResult, type Brain, type EngineNotice } from "@sema-agent/core";
6
6
  import type { TaskRequestBody } from "./wire-types.js";
7
7
  import type { ServiceConfig } from "../config-types.js";
8
8
  import { type SessionMirrorRuling } from "../web-admin-client/facade.js";
@@ -21,6 +21,7 @@ import type { SubagentSteerRegistry } from "../orchestration/subagent-steer.js";
21
21
  import { type WorkflowCompletionInbox } from "../orchestration/workflow-completion-inbox.js";
22
22
  import type { FleetLeaseManager } from "../fleet-lease.js";
23
23
  import { type FleetEventBus } from "../fleet/fleet-bus.js";
24
+ import type { SessionResidentCounts } from "../session-resident-background.js";
24
25
  import type { ElicitationCoordinator } from "../elicitation.js";
25
26
  import type { QuestionCoordinator } from "../question.js";
26
27
  import { type ParkedAskRedeem, type ToolApprovalCoordinator } from "../tool-approval.js";
@@ -31,7 +32,7 @@ import type { Metrics } from "../observability/metrics.js";
31
32
  import { type RateGate } from "../observability/rate-limit.js";
32
33
  import type { QuotaTracker } from "../observability/cost-quota.js";
33
34
  import type { ModelUsageTracker, PromptManifestTracker } from "../budget.js";
34
- import type { ConsolidationSeatLabel, ConsolidationValve } from "../boot/memory-consolidation.js";
35
+ import type { ConsolidationValve, MemoryConsolidationFaces } from "../boot/memory-consolidation.js";
35
36
  import { streamApprovals, checkQuestionAnswer } from "./routes/approvals-assistant.js";
36
37
  export { streamApprovals, checkQuestionAnswer };
37
38
  import { cascadeConfig } from "./run-meta.js";
@@ -100,7 +101,9 @@ export interface ServiceCoreDeps {
100
101
  /**
101
102
  * Map an inbound request body + resolved auth to a TaskSpec. The SERVICE/deployment owns model
102
103
  * + tools + mcp here (callers only supply content). `auth` carries the principal-derived memory scope —
103
- * prefer it over anything in the body.
104
+ * prefer it over anything in the body. The root session is not read from `auth` either: the resolver's one reading of
105
+ * "which session is this leg on" is `opts.execution.root` (`auth.sessionId` is the authorizer's hand-off to the server's
106
+ * execution-context resolver, not a second reading for the resolver).
104
107
  * The root session is NOT the resolver's to write: the return type carries no `sessionId`
105
108
  * (`ResolvedTaskSpec`); the server stamps the root the authorizer resolved onto every spec it executes
106
109
  * (`http/execution-context.ts` `stampSpecRoot`). A resolver that needs the root reads `opts.execution.root`.
@@ -155,7 +158,8 @@ export interface ServiceCoreDeps {
155
158
  * `principalCaps`、同一份部署缺省):凡回答「此主体在此场景能看见哪些 MCP 服务器 / A2A 对端」的口 —— `GET /v1/capabilities/mcp` 的状态面、
156
159
  * `GET /v1/sessions/:id/mcp` 与 `…/a2a` 两张会话面板 —— 的场景名都由它给,**点名与缺席都问**:点名 ⇒ 判在册 / allowlist,
157
160
  * 拒体(400 `scenario_unknown` 附在册词表 / 400 `scenario_not_allowed` 附 allowlist)与任务提交腿逐字同;缺席 ⇒ 指派链(中心 ruling 胜者,
158
- * 否则部署缺省),与这位主体 run 时同一读法(指派悬空 ⇒ 503 `state.scenario_assignment_unknown`,同提交腿)。
161
+ * 否则部署缺省),与这位主体 run 时同一读法(指派悬空 ⇒ 503 `state.scenario_assignment_unknown`,同提交腿)。中心配了却答不出这位主体的裁定 ⇒
162
+ * 点名与缺席同答 503 `state.scenario_assignment_unavailable`(同提交腿)。
159
163
  * 读面上这只门走**只读腿**(`createScenarioGate(…, "peek")`):问中心裁定时 center 抖动的那一拍,不替这个主体的真提交留下 fail-closed 降级项
160
164
  * (提交腿自己是 `"enforce"`)。
161
165
  * 🔴 **必填**:读口的场景名只有这一个来源,没有「缺接缝 ⇒ 读部署缺省 / 点名 404」这类第二种读法 —— 漏接是**编译错**(嵌入方自己装配时,工厂与它的型从包根导出:
@@ -581,15 +585,9 @@ export interface ServiceSeamDeps {
581
585
  * **启动期**就被拒了(`boot/memory-consolidation.ts`),那些机器根本起不来。⇒ 缺席形是 **404 族**
582
586
  * (整域不挂),刻意**不是** 501:501 说「换部署形态」,这里的动作是「把旋钮打开」。全文见
583
587
  * `routes/memory-consolidation.ts` 头注。
584
- * 🔴 `seat` 的词表单一真源 = `boot/memory-consolidation.ts` 的 {@link ConsolidationSeatLabel}
585
- * (type-only import,tsc 擦除、非装载边)——在这里再写一遍字面量联合就是第二份会漂的词表。 */
586
- memoryConsolidation?: {
587
- readonly seat: ConsolidationSeatLabel;
588
- readonly model: string;
589
- readonly scopes: readonly string[];
590
- run(scope: string): Promise<ConsolidationRunReceipt>;
591
- lastRun(scope: string): ConsolidationDriverRunRow | undefined;
592
- };
588
+ * 🔴 形的单一真源 = `boot/memory-consolidation.ts` 的 {@link MemoryConsolidationFaces}(type-only import,tsc 擦除、非装载边)——
589
+ * 在这里再写一遍成员表就是第二份会漂的形(core 7.63.0 把 `lastRun` 改成异步时这里的手抄形正好漂了一次)。 */
590
+ memoryConsolidation?: MemoryConsolidationFaces;
593
591
  /** [ref] §3.1 / [ref] §1.3([ref] S-2):per-principal memory-capture opt-out 授权表的管理面
594
592
  * (`/v1/admin/memory-optout` 四口,operator-only)—— `backend.memoryOptOutGrant()` 的同一只(与
595
593
  * `RuntimeCaps.allowMemoryOptOut` 的 resolver 腿读同一张表,零缓存直读 ⇒ 写后下一次 prepare 即生效)。
@@ -723,13 +721,24 @@ export interface ServiceDeploymentDeps {
723
721
  * composition root 装起来的夹具)⇒ 两键都缺席,两面与没有声明的部署逐字节同。
724
722
  */
725
723
  deploymentModPackages?: number;
724
+ /**
725
+ * 会话 → 调用方登记的工作目录(提交体 `cwd` 的唯一写口 `setSessionCwd` 写的那一张进程内表,`boot/execution-env.ts` `createSessionScopedRegistries`)。
726
+ * **只读**,读者只有 run 外回退口(`POST /v1/sessions/:id/rewind-files`):host 工厂按 `effectiveHostWorkspace(本表.get(会话), ctx)` 定根(`execution-env.ts`
727
+ * host 臂),口在交引擎之前用**同一只函数、同一份入参**问「工厂这一次会不会落到一只用完即删的临时目录」—— 会 ⇒ 拒,不让台账说恢复了而项目没动。
728
+ * 缺席(夹具 / 嵌入方没接)⇒ 读作「没有登记」⇒ host 车道上口拒(fail-closed)。
729
+ */
730
+ perSessionCwd?: ReadonlyMap<string, string>;
726
731
  /**
727
732
  * Graceful drain — shared mutable state between main.ts (flips `draining` on SIGTERM) and this server:
728
733
  * • while `draining`, NEW model-running submissions (the billable submit paths) get 503 + Retry-After, so an
729
734
  * orchestrator/shell retries against the replacement instance; read paths + in-flight verbs (steer/cancel/
730
735
  * respond/subagent) stay open so the runs we are waiting on can still finish/interact.
731
736
  * • `inflight` is ASSIGNED BY createServer (a live union of this replica's in-flight legs: durable bg/resume
732
- * `inflightRuns` + live sync/resume streams `steerableRuns`) — main.ts polls it to know when drain is done.
737
+ * `inflightRuns` + live sync/resume streams `steerableRuns`, the leader leg, the background sub-agents that outlived the leg
738
+ * that spawned them, and the session-resident background shells/monitors — `inflightBreakdown` is the same read split into its
739
+ * four terms) — an observable fact (`/health.inflight`).
740
+ * `blockingInflight` (also ASSIGNED BY createServer) is the SAME breakdown function minus the session-resident shell term: "is there still
741
+ * work that must be waited out" — the drain wait main.ts polls after SIGTERM, the orphan/lease windows and the SIGHUP idle window read THAT.
733
742
  * • /health carries `draining:true` + `version` (build self-description); draining is a readiness reason
734
743
  * (`http/readiness.ts`) ⇒ `/readyz` 503 + `/health` `ready:false` (the k8s readiness 摘流信号).
735
744
  * • [ref]:`attachedStreams` 同样 ASSIGNED BY createServer —— 本副本当前打开着的 SSE 流条数
@@ -740,6 +749,14 @@ export interface ServiceDeploymentDeps {
740
749
  * 硬停起点各调一次。
741
750
  */
742
751
  drainState?: import("../fleet/drain-entry.js").DrainState;
752
+ /**
753
+ * 会话驻留后台行的读口:本进程活过起它的腿、仍在跑的**后台子代理**与**后台 shell / monitor**,一次走查交出两项(`session-resident-background.ts` 的
754
+ * `countSessionResidentBackground` 在 composition root 绑上围栏表;法与边界见该文件头)。`createHttpServer` 把两项并进**唯一的分项函数** `inflightBreakdown`:
755
+ * `backgroundAgents` 进阻断集 `drainState.blockingInflight`(排空 / 孤儿窗与附着租约自退 / SIGHUP 空闲窗判停读它)与总数,`sessionResident` 只进总数 `drainState.inflight`。
756
+ * 读口**不许抛**:判停路径每拍读它,排空首读在期限计时器装上之前 —— 一抛就永不硬停(组合根那只按会话收住读失败、计 1 并报出)。
757
+ * 缺席(嵌入方 / 夹具)= 两项恒 0,两个读数逐字同 7.145.x。
758
+ */
759
+ sessionResidentBackground?: () => SessionResidentCounts;
743
760
  /** 编排器片 2 件 3:服务租约此刻的读数(`fleet/serving-lease.ts` 的客户端交出;引擎信号铸点与计费准入判同读)。缺席 = 没装租约客户端
744
761
  * (非 fleet 成员 / 没接中心 / 测试夹具)⇒ `none`(与没有租约的引擎逐字同)。 */
745
762
  servingLease?: () => import("../fleet/engine-signal.js").ServingLeaseView;
@@ -9,6 +9,7 @@ import {} from "../memory-sync.js";
9
9
  import {} from "../orchestration/workflow-agent-steer.js";
10
10
  import {} from "../orchestration/workflow-completion-inbox.js";
11
11
  import {} from "../fleet/fleet-bus.js";
12
+ import { blockingInflightOf, inflightTotal } from "../fleet/drain-entry.js";
12
13
  import {} from "../tool-approval.js";
13
14
  import {} from "../observability/rate-limit.js";
14
15
  import { IdempotencyCache } from "./idempotency.js";
@@ -20,10 +21,12 @@ import { coarseStatusForState, errorCodeForExit } from "./routes/images.js";
20
21
  export { coarseStatusForState, errorCodeForExit };
21
22
  import { sendError, sendHttpError, sendOpenFaceFault, logRequestError } from "./send.js";
22
23
  import { createRequestGuards } from "./request-guards.js";
24
+ import { createRunConcurrencyGate, liveRunIdsOf } from "./run-concurrency-cap.js";
23
25
  import { sqlEngineSeatIssue } from "../sql-engine-posture.js";
24
26
  import { parkDecisionStoreRefusal } from "../orchestration/workflow-park-decision.js";
25
27
  import { CHECKPOINT_CTX_SEALING_REQUIRED } from "./checkpoint-ctx.js";
26
28
  import { PARKED_REVIVE_EXECUTION_SEAT_REQUIRED } from "../parked-decide.js";
29
+ import { operatorDeclarationRefusal } from "../config-invariants.js";
27
30
  import { retiredServiceDepsRefusal } from "./retired-service-deps.js";
28
31
  import { createAdmission, MAX_SKILL_CONTENT_CHARS, MAX_SYSTEM_PROMPT_CHARS, MAX_OUTPUT_SCHEMA_CHARS, validateUserSkills } from "./admission.js";
29
32
  import { createResumeLegs } from "./resume-legs.js";
@@ -74,6 +77,12 @@ export function createHttpServer(rawDeps) {
74
77
  if (retired !== undefined)
75
78
  throw new Error(retired);
76
79
  }
80
+ {
81
+ const operatorDeclarationFailure = operatorDeclarationRefusal(deps.config);
82
+ if (operatorDeclarationFailure !== undefined) {
83
+ throw new Error(operatorDeclarationFailure);
84
+ }
85
+ }
77
86
  {
78
87
  const issue = sqlEngineSeatIssue(deps.backend, deps.sqlEngine);
79
88
  if (issue !== undefined) {
@@ -104,16 +113,32 @@ export function createHttpServer(rawDeps) {
104
113
  const steerableRuns = new Map();
105
114
  const wakeParkMints = new Map();
106
115
  const counters = { uncountedBillableInflight: 0, admittedInflight: 0 };
107
- if (deps.drainState)
108
- deps.drainState.inflight = () => new Set([...inflightRuns.keys(), ...steerableRuns.keys()]).size + counters.uncountedBillableInflight + counters.admittedInflight + (deps.leaderEndpoint?.inflight?.() ?? 0);
116
+ const inflightBreakdown = () => {
117
+ const resident = deps.sessionResidentBackground?.() ?? { backgroundAgents: 0, sessionResident: 0 };
118
+ return {
119
+ http: liveRunIdsOf(inflightRuns, steerableRuns).size + counters.uncountedBillableInflight + counters.admittedInflight,
120
+ leader: deps.leaderEndpoint?.inflight?.() ?? 0,
121
+ backgroundAgents: resident.backgroundAgents,
122
+ sessionResident: resident.sessionResident,
123
+ };
124
+ };
125
+ if (deps.drainState) {
126
+ deps.drainState.inflightBreakdown = inflightBreakdown;
127
+ deps.drainState.inflight = () => inflightTotal(inflightBreakdown());
128
+ deps.drainState.blockingInflight = () => blockingInflightOf(inflightBreakdown());
129
+ }
109
130
  let lastBillableActivityAt = performance.now();
131
+ let firstBillableActivityAt = null;
110
132
  const noteActivity = (url) => {
111
133
  if (isProbePath(url))
112
134
  return;
113
135
  lastBillableActivityAt = performance.now();
136
+ firstBillableActivityAt ??= lastBillableActivityAt;
114
137
  };
115
138
  if (deps.drainState)
116
139
  deps.drainState.lastActivityAt = () => lastBillableActivityAt;
140
+ if (deps.drainState)
141
+ deps.drainState.firstActivityAt = () => firstBillableActivityAt;
117
142
  if (deps.drainState)
118
143
  deps.drainState.yieldInflight = () => preemptableRuns.yieldAll();
119
144
  if (deps.hookWakeBus) {
@@ -155,7 +180,8 @@ export function createHttpServer(rawDeps) {
155
180
  }
156
181
  const { quotaExceeded, ownerCostQuotaDenied, ownerFleetLeaseDenied, ownerLeaseDenied, ownerQuotaDenied, leaseDenied, usageWindowDenialFor, usageWindowDenied, rateLimited, safeDecode, runOwnerOk, sessionOwnerOk, runSessionAcceptOk, readJson, readRawBody } = createRequestGuards({ deps });
157
182
  const { prepareSpec } = createAdmission({ deps, readJson, runnerFor });
158
- const { routeCtxBase, resumeCheckpoint, driveResumeIntoRunLog, driveResumeLeg, mayDiscloseRowError, resumePreempted, startFreshHostTurn, resumeWake, sessionNotifyDoor } = createResumeLegs({ 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 });
183
+ const { admitRun } = createRunConcurrencyGate({ deps, inflightRuns, steerableRuns });
184
+ const { routeCtxBase, resumeCheckpoint, driveResumeIntoRunLog, driveResumeLeg, mayDiscloseRowError, resumePreempted, startFreshHostTurn, resumeWake, sessionNotifyDoor } = createResumeLegs({ 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 });
159
185
  const { denyExpiredApprovals, redeemParkedAsk } = createApprovalSweeps({ deps, resumeCheckpoint, mayDiscloseRowError });
160
186
  const { handle } = createDispatch({ deps, noteActivity, routeCtxBase, counters });
161
187
  const server = http.createServer((req, res) => {
@@ -1,19 +1,21 @@
1
1
  /**
2
- * 「这条停驻行的持久化体在本版上能否重放」—— **唯一**判据(四问一只;五个问点同调:续跑驱动段 `resume-legs.ts` `resolveResumeSpecOrBlocked`、
2
+ * 「这条停驻行的持久化体在本版上能否重放」—— **唯一**判据(四问一只,外加 `settings.env` 凭据一臂;五个问点同调:续跑驱动段 `resume-legs.ts` `resolveResumeSpecOrBlocked`、
3
3
  * plan_review 的 prepare 段、SLA 拒扫腿的跳过臂 `approval-sweeps.ts`、终态 run 的 steer 铸唤醒卡之前 `routes/runs.ts`;`resolveSpec` 本身留作提交腿的拒点)。
4
4
  * 四问的规则、记号、拒句与删除条件的属主 = `http/checkpoint-ctx.ts` 顶注;答复 = 那里的 `storedBodyReplayAnswer`。
5
5
  *
6
- * 为什么判据住在这里而不是 `checkpoint-ctx.ts`:第三问要读体的**生效模式词**(`task-settings.ts` `storedBodyPermissionMode`,请求设置的解析层)与本部署此刻的
6
+ * 为什么判据住在这里而不是 `checkpoint-ctx.ts`:模式词问要读体的**生效模式词**(`task-settings.ts` `storedBodyPermissionMode`,请求设置的解析层)与本部署此刻的
7
7
  * **入口地板**(`runtime-governance.ts` `autonomyModeFloor`)—— 这两只属主带着配置层的包外依赖;`checkpoint-ctx.ts` 被随包的本地排空脚本经编译产物 import,
8
- * 它的闭包只许 node 内建 / 引擎包根(`test/drain-check-local.test.ts` 的闭包门)。判据只有这一只,前两问的谓词照旧住在各自属主里。
8
+ * 它的闭包只许 node 内建 / 引擎包根(`test/drain-check-local.test.ts` 的闭包门)。判据只有这一只,allow 读法问、工具名清单问与退役请求键问的谓词照旧住在各自属主里。
9
9
  */
10
10
  import type { PermissionMode } from "@sema-agent/core";
11
11
  import { type Autonomy } from "../runtime-governance.js";
12
12
  import { type ExecutionConfigRootDeployment } from "../execution-config-root.js";
13
+ import { type UnreadMembersDeployment } from "../unread-request-members.js";
14
+ import { type ModelApiKeyEnvTable } from "../server-secret-env.js";
13
15
  import { type StoredBodyReplayRefusal } from "./checkpoint-ctx.js";
14
16
  import type { CheckpointCtx } from "./route-ctx.js";
15
17
  /**
16
- * 第三问:本行体里的模式词能否按当前读法重放。不能 ⇔ 本部署此刻有入口地板 ∧ 行上没有当前的模式词读法记号 ∧ 体的生效词进这块地板会变
18
+ * 模式词问:本行体里的模式词能否按当前读法重放。不能 ⇔ 本部署此刻有入口地板 ∧ 行上没有当前的模式词读法记号 ∧ 体的生效词进这块地板会变
17
19
  * (`runtime-governance.ts` `entryPermissionMode`,与提交入口的盖章同一只函数;判的是「词变不变」而不是 `clamped` —— 体无词的旧行进地板取地板本身,
18
20
  * 那也是变)⇒ 返回拒因的两个事实(体的词、地板);能 ⇒ `undefined`。
19
21
  */
@@ -22,13 +24,16 @@ export declare function permissionModeReadingUnstated(ctx: CheckpointCtx, floor:
22
24
  floor: PermissionMode;
23
25
  } | undefined;
24
26
  /**
25
- * 预判读的部署配置:`autonomy`(第三问的模式词地板)、执行车道的 home 两位(`~/` 形规则那一问)与配置根的几位(user 设置层 `/` 规则那一问)。`ServiceConfig` 结构上满足,四个问点传 `deps.config` 整份。
27
+ * 预判读的部署配置:`autonomy`(模式词问的模式词地板)、执行车道的 home 两位(`~/` 形规则那一问)、配置根的几位(user 设置层 `/` 规则那一问)与「请求成员读不出」那一问的
28
+ * 租户轴 / 两只注入闸的否决位。`ServiceConfig` 结构上满足,四个问点传 `deps.config` 整份。
26
29
  */
27
- export type StoredReplayDeployment = ExecutionConfigRootDeployment & {
30
+ export type StoredReplayDeployment = ExecutionConfigRootDeployment & UnreadMembersDeployment & {
28
31
  readonly autonomy?: Autonomy | undefined;
32
+ /** 生效配置模型条目 name → `apiKeyEnv`(`settings.env` 凭据判据的名单一臂;缺席 = 没有模型条目,与 `serverCredentialValueSources` 的缺省同读)。 */
33
+ readonly modelApiKeyEnv?: ModelApiKeyEnvTable | undefined;
29
34
  };
30
35
  /**
31
- * 四问一只判据:不能重放 ⇒ 返回拒的那条规则;能 ⇒ `undefined`。顺序:allow 读法记号 → 请求设置里的条目表(**与拒点同序**:桶门〔形 / 空串 / 超帽〕→ 工具名清单读成空〔**只问限制方向**:放行方向的存量条目读成空,续跑照旧、只留一行运维 warn〕→ deny / ask 的名字层 + 规则文法)→ 模式词读法记号 → 体里的退役请求键(几问同中时答先中的那一问 ——
36
+ * 四问一只判据:不能重放 ⇒ 返回拒的那条规则;能 ⇒ `undefined`。顺序:allow 读法(体里带非空 `allow` 而写者版本证不出 ≥ 7.117.0;常设,按写者版本)→ 请求设置里的条目表(**与拒点同序**:桶门〔形 / 空串 / 超帽〕→ 工具名清单读成空〔**只问限制方向**:放行方向的存量条目读成空,续跑照旧、只留一行运维 warn〕→ 请求成员读不出〔hooks / env / MCP transport / A2A headers …,判据 `unread-request-members.ts`〕→ deny / ask 的名字层 + 规则文法)→ 模式词读法记号 → 体里的退役请求键(几问同中时答先中的那一问 ——
32
37
  * 任一问中都不重放,句子只需一句)。`deployment` = 本部署**此刻**的 `config`(活 config:热改即生效):`autonomy` 的地板由它的唯一属主算,`~/` 形规则的 home 由 `executionLaneHomeDir` 算,问点都不自己算。
33
38
  */
34
39
  export declare function storedBodyReplayRefusal(ctx: CheckpointCtx, deployment: StoredReplayDeployment): StoredBodyReplayRefusal | undefined;
@@ -1,4 +1,4 @@
1
- import { REQUEST_SETTINGS_REFUSAL_PREFIX, SETTINGS_PERMISSION_BUCKETS, SETTINGS_RULE_REFUSAL_CODE, neverAutoNamesRefusal, rulePolicyBucketsRefusal, settingsPermissionBucketIssue, storedBodyPermissionMode } from "../task-settings.js";
1
+ import { REQUEST_SETTINGS_REFUSAL_PREFIX, SETTINGS_PERMISSION_BUCKETS, SETTINGS_RULE_REFUSAL_CODE, neverAutoNamesRefusal, readSettingsEnv, rulePolicyBucketsRefusal, settingsEnvCredentialIssue, settingsPermissionBucketIssue, storedBodyPermissionMode } from "../task-settings.js";
2
2
  import { readTightenOnlySeats, tightenOnlySeatField, tightenOnlySeatIssue } from "../tighten-only-seats.js";
3
3
  import { entryProblemsFacts } from "../entry-problems.js";
4
4
  import { autonomyModeFloor, entryPermissionMode } from "../runtime-governance.js";
@@ -6,7 +6,11 @@ import { inertToolListEntryOf, replayInertEntry } from "../rule-entry-list.js";
6
6
  import { executionLaneHomeDir } from "../execution-lane-caps.js";
7
7
  import { executionConfigRootOf } from "../execution-config-root.js";
8
8
  import { migrationWindowEnd } from "../plugins/one-time-migrations.js";
9
- import { allowListReadingEraOf, allowListReadingUnstated, permissionModeReadingStated, retiredRequestKeyOf } from "./checkpoint-ctx.js";
9
+ import { storedEnvCredentialsDropM38 } from "../stored-request-env-credentials-m38.js";
10
+ import { storedToolAxesRereadM19 } from "../stored-request-tool-axes-m19.js";
11
+ import { MAX_NAMED_MEMBERS, unreadRequestMembers, unreadRequestMembersRefusal } from "../unread-request-members.js";
12
+ import { serverCredentialValueSources } from "../server-secret-env.js";
13
+ import { allowListWriterUnproven, permissionModeReadingStated, retiredRequestKeyOf } from "./checkpoint-ctx.js";
10
14
  export function permissionModeReadingUnstated(ctx, floor) {
11
15
  if (floor === undefined || permissionModeReadingStated(ctx))
12
16
  return undefined;
@@ -57,11 +61,30 @@ function storedRulePolicyRefusal(body, deployment) {
57
61
  const neverAutoRefused = neverAutoNamesRefusal(neverAuto);
58
62
  return neverAutoRefused === undefined ? undefined : replayInertEntry(tightenOnlySeatField("neverAuto"), "deny", SETTINGS_RULE_REFUSAL_CODE, `${REQUEST_SETTINGS_REFUSAL_PREFIX}${neverAutoRefused.message}`, { ...entryProblemsFacts(neverAutoRefused.problems) });
59
63
  }
64
+ function storedEnvCredentialRefusal(body, deployment) {
65
+ const issue = settingsEnvCredentialIssue(readSettingsEnv(body?.settings).reaching, serverCredentialValueSources(deployment.modelApiKeyEnv));
66
+ if (issue === null || storedEnvCredentialsDropM38(new Date().toISOString().slice(0, 10)))
67
+ return undefined;
68
+ return { errorCode: "request.env_credential_refused", message: issue.message, facts: { ...issue.fields } };
69
+ }
60
70
  export function storedBodyReplayRefusal(ctx, deployment) {
61
71
  const writer = ctx.writerVersion !== undefined ? { writerVersion: ctx.writerVersion } : {};
62
- if (allowListReadingUnstated(ctx))
63
- return { kind: "allow_list_reading", era: allowListReadingEraOf(ctx), ...writer };
64
- const entry = storedPermissionBucketRefusal(ctx.body) ?? storedTightenOnlySeatRefusal(ctx.body) ?? inertToolListEntryOf(ctx.body, ["deny"]) ?? storedRulePolicyRefusal(ctx.body, deployment);
72
+ if (allowListWriterUnproven(ctx))
73
+ return { kind: "allow_list_reading", ...writer };
74
+ const early = storedPermissionBucketRefusal(ctx.body) ?? storedTightenOnlySeatRefusal(ctx.body);
75
+ if (early !== undefined)
76
+ return { kind: "inert_tool_list", entry: early };
77
+ const envCredential = storedEnvCredentialRefusal(ctx.body, deployment);
78
+ if (envCredential !== undefined)
79
+ return { kind: "settings_env_credential", refusal: envCredential };
80
+ const inert = inertToolListEntryOf(ctx.body, ["deny"]);
81
+ if (inert !== undefined)
82
+ return { kind: "inert_tool_list", entry: inert };
83
+ const today = new Date().toISOString().slice(0, 10);
84
+ const unread = unreadRequestMembers({ settings: ctx.body.settings, mcpServers: ctx.body.mcpServers, a2aPeers: ctx.body.a2aPeers }, deployment, { replay: true, today, storedToolAxes: storedToolAxesRereadM19(today) });
85
+ if (unread.length > 0)
86
+ return { kind: "unread_members", refusal: unreadRequestMembersRefusal(unread), members: unread.slice(0, MAX_NAMED_MEMBERS), memberCount: unread.length };
87
+ const entry = storedRulePolicyRefusal(ctx.body, deployment);
65
88
  if (entry !== undefined)
66
89
  return { kind: "inert_tool_list", entry };
67
90
  const mode = permissionModeReadingUnstated(ctx, autonomyModeFloor(deployment.autonomy));
@@ -46,7 +46,8 @@ export interface TaskRequestBody {
46
46
  * `scenario_unknown`, a known-but-not-allowed one a typed 400 `scenario_not_allowed`; absent ⇒ the ruling's
47
47
  * assigned scenario, else `DEFAULT_SCENARIO` (consumed at `boot/resolve-spec.ts` via `gateScenarioRequest`). A name
48
48
  * on that default chain this deployment does not have is NEVER folded to `default`: an assigned one is a typed 503
49
- * `state.scenario_assignment_unknown`, a dangling `DEFAULT_SCENARIO` refuses to boot.
49
+ * `state.scenario_assignment_unknown`, a dangling `DEFAULT_SCENARIO` refuses to boot. On a center-wired deployment whose
50
+ * center cannot answer for this principal, named or absent alike is a typed 503 `state.scenario_assignment_unavailable`.
50
51
  * ⚠️ scenario-SPECIFIC keys (`repo`/`lenses`/`rounds`, read through `ScenarioRequest`'s index signature) are
51
52
  * deliberately NOT declared here — they belong to one scenario each, not to the shared submit surface. */
52
53
  scenario?: string;
@@ -172,9 +173,14 @@ export interface TaskRequestBody {
172
173
  * `outputSchema` (core ignores it there). */
173
174
  outputRetries?: number;
174
175
  /** Within-task compaction tuning (core [ref] `TaskSpec.compaction`). ⚠️ ONLY `clampTolerance` is a caller
175
- * knob — the rest of core's compaction object is an OPERATOR axis and is deliberately not on the wire, so this
176
- * type is narrower than core's field on purpose. `boot/resolve-spec.ts` accepts a finite number in [0,1] and
177
- * omits the whole `compaction` key otherwise. Pairs with `compactionModel` (which gear compacts). */
176
+ * knob HERE — the rest of core's compaction object is an OPERATOR axis and is deliberately not on the wire, so this
177
+ * type is narrower than core's field on purpose. `spec-fields.ts` `compactionSpecFragment` accepts a finite number
178
+ * in [0,1] and omits the whole `compaction` key otherwise. Pairs with `compactionModel` (which gear compacts).
179
+ * The other caller-owned member of core's `compaction`, the automatic-compaction seat `autoCompact`, rides the CC
180
+ * settings key `settings.autoCompactEnabled` (boolean; 7.146.0, capability bit `taskSettings.autoCompactEnabled`) —
181
+ * ONE seat per fact: it is deliberately NOT repeated here (`compaction.autoCompact` in the body is not read). Both
182
+ * members are minted into the one `TaskSpec.compaction` object by the same mapper. The manual seat `manualCompact`
183
+ * (the pass `POST /v1/runs/:id/compact` asks for) is not caller-writable: it takes the deployment's / engine's default. */
178
184
  compaction?: {
179
185
  clampTolerance?: number;
180
186
  };
@@ -184,10 +190,12 @@ export interface TaskRequestBody {
184
190
  * 400 (fail-loud, never silently dropped — the body.model silent-drop bug class). Absent ⇒ core uses the resolved
185
191
  * role's default thinking. NEVER `budgetTokens`/`fast_mode` (provider-neutral by omission). */
186
192
  reasoningEffort?: string;
187
- /** Resume-at (shell-host contract E18): the E2 message `eventId` to rewind the conversation to — core branches the
188
- * session at that prior message before running the new objective ("rewind to this message, ask differently").
189
- * The service resolves eventId→the persisted SessionTreeEntry.id (the anchor map) in resolveSpec; an unknown
190
- * eventId is a 4xx (never silently dropped). Requires a session. Absent ⇒ continue from the current leaf. */
193
+ /** Resume-at (shell-host contract E18): the history-anchor handle of the prior message to rewind the conversation to
194
+ * (a message's E2 `eventId`, or a prompt's `taskId` — the anchor map holds both) — core branches the session at
195
+ * that message before running the new objective ("rewind to this message, ask differently"). The service resolves
196
+ * handle → the persisted SessionTreeEntry.id through the ONE anchor reader (`history-anchor.ts`) in resolveSpec; an
197
+ * unknown handle is a 404 `resume_at.unknown_event` (never silently dropped). Requires a session. Absent ⇒ continue
198
+ * from the current leaf. */
191
199
  resumeAt?: string;
192
200
  /** [ref] rewind exclusive mode (core 1.292 `TaskSpec.resumeAtMode`): qualifies the `resumeAt` target. `"at"`
193
201
  * (default when absent — zero regression) keeps the target message in the branched context; `"before"` branches at
@@ -219,12 +227,18 @@ export interface TaskRequestBody {
219
227
  * either way. Requires a FileHistoryStore. */
220
228
  restoreFiles?: boolean;
221
229
  /** DV-15: opt-in tolerance for a PARTIAL file restore (default = loud terminal failure carrying the per-file
222
- * ledger; `true` = keep going and disclose the same ledger on the result's rewindNotes). */
230
+ * ledger; `true` = keep going and disclose the same ledger on the result's rewindNotes). A RUN-seat policy only
231
+ * ("may the agent keep working on a mixed tree"): the out-of-run `POST /v1/sessions/:id/rewind-files` has no such
232
+ * key — the engine's out-of-run rewind has no partial policy and that route answers the ledger as it stands. */
223
233
  acceptPartialRestore?: boolean;
224
234
  /** R8 code-only rewind (CC "Restore code" mode): converge the TRACKED set to the history boundary at a prior
225
- * USER message WITHOUT forking the conversation (the session leaf is untouched — only the files move). The
226
- * value is the same handle as `resumeAt` (the prompt's taskId); the service resolves it → the entry id. Honored ONLY
227
- * when `resumeAt` is ABSENT (the two modes are mutually exclusive). Requires the anchor map + a FileHistoryStore. */
235
+ * USER message WITHOUT forking the conversation (the session leaf is untouched — only the files move). The value is
236
+ * a history-anchor handle, NOT a SessionTreeEntry.id: the prompt's `taskId` (`messages[].taskId` on the session view;
237
+ * the same handle space `resumeAt` reads) — the service resolves it → the entry id through the one anchor reader
238
+ * (unknown ⇒ 404 `rewind_files_to.unknown_event`). Honored ONLY when `resumeAt` is ABSENT (the two modes are mutually
239
+ * exclusive). Requires the anchor map + a FileHistoryStore + the session store's head read (capability
240
+ * `rewindFilesTo`). Its out-of-run twin — no run, no model call — is `POST /v1/sessions/:id/rewind-files` with the same
241
+ * handle in `to` (capability `sessionRewindFiles`). */
228
242
  rewindFilesTo?: string;
229
243
  /** [ref](core 7.31.0 [ref] `TaskSpec.fileHistory`)—— 请求级的**文件历史关断词**,唯一词 `"disabled"`(core 的拼法,
230
244
  * 与 `checkpointStore` 同;没有 `"enabled"` —— 缺席就是「部署说了算」的唯一形,声明只能单向收紧)。`"disabled"` ⇒
@@ -452,7 +466,7 @@ export interface TaskRequestBody {
452
466
  * · `"scrub"` —— 缺省清洗(剥凭据形变量),**任何车道、任何部署**都受理(它就是缺省;7.106.0 合并复审 X7)。
453
467
  * **缺席 = 缺省清洗**:不带键的请求把本会话的绑定清掉(不继承上一条请求的声明 —— 这一位是「本条请求要什么」,
454
468
  * 粘到下一条上就是替一个没说话的请求放宽)。名单形(`string[]`)**不上 wire**(那是嵌入方构造执行环境的选项)。
455
- * 🔒 **只有 host 车道有消费点**:别的车道(e2b / k8s / local-docker / ssh / adb / device / in-process)带 `"all"` ⇒
469
+ * 🔒 **只有 host 车道有消费点**:别的车道(e2b / k8s / local-docker / ssh / adb / device / none)带 `"all"` ⇒
456
470
  * 400 `request.field_invalid`(`reason: lane_not_host`)「applies to the host lane only」,不静默忽略、不映射到别的车道的 env 名单;`"scrub"` 在那些车道上照受理(无消费点,无害)。
457
471
  * Rides the persisted body onto resume legs:重放照射程与车道重判(部署由单用户改托管后 revive ⇒ 同一只拒,
458
472
  * resume-legs 折成 `409 resume_blocked_by_policy`)。
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export { loadConfig, type ServiceConfig } from "./config.js";
2
- export { composeExecutionLane, assertExecutionLaneInvariants, type ExecutionLaneComposeCtx } from "./boot/execution-lane.js";
2
+ export { composeExecutionLane, assertExecutionLaneInvariants, HTTP_SERVICE_LANE_ENTRY, type ExecutionLaneComposeCtx, type ExecutionLaneEntry } from "./boot/execution-lane.js";
3
3
  export { createBrain } from "./brain.js";
4
4
  export { createSessionStore } from "./plugins/session-store.js";
5
5
  export { createStoreBackend, type StoreBackend, type SessionCaptureRecordSource } from "./plugins/store-backend.js";
6
6
  export { RetiredSchemaPresentError } from "./plugins/schema-consistency.js";
7
- export { LocalDataRootSchemaMismatchError, type LocalSidecarMismatch } from "./plugins/local-session-store.js";
7
+ export { LocalDataRootSchemaMismatchError, type LocalDataRootMismatch } from "./plugins/local-session-store.js";
8
8
  export { CachingSessionStore, type CachingOptions } from "./plugins/caching-session-store.js";
9
9
  export type { RunRecord, RunEvent } from "./plugins/store-contracts.js";
10
10
  export { runInBackground } from "./runs.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { loadConfig } from "./config.js";
2
- export { composeExecutionLane, assertExecutionLaneInvariants } from "./boot/execution-lane.js";
2
+ export { composeExecutionLane, assertExecutionLaneInvariants, HTTP_SERVICE_LANE_ENTRY } from "./boot/execution-lane.js";
3
3
  export { createBrain } from "./brain.js";
4
4
  export { createSessionStore } from "./plugins/session-store.js";
5
5
  export { createStoreBackend } from "./plugins/store-backend.js";
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * ## 基线 = 会话的服务端元数据
12
12
  * 基线是「同一 session 上一次 run 选中的链成员相对路径」(不是指纹:指纹密钥每进程随机,跨进程不可比)。它住在会话店的
13
- * 服务端元数据面 —— SQL 两孪生是 `session_meta.instruction_source` 一列,local 文件店是一只 sidecar —— 所以重启 /
13
+ * 服务端元数据面 —— SQL 两孪生是 `session_ext.instruction_source` 一列,local 文件店是一只 sidecar —— 所以重启 /
14
14
  * 跨副本都读得到、随会话删除一起消失,且不进模型上下文、不进 wire 会话面。不接这张面的店(core 的内存 dev 店、
15
15
  * `run-local` 的 core 文件店)⇒ 席缺席 ⇒ 一帧不发(诚实缺席:那两形的会话本来就活不过进程,或没有会话流可投)。
16
16
  *
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 一切 JSON 请求体的字节上限 —— `readJson` 边读边计,越过即 413 `request.payload_too_large`(一条一直都在的门,`http/request-guards.ts`)。
3
+ *
4
+ * 住叶子(零依赖)而不是守门族里:依它定帽的面要读同一个数 —— 收编批量导入的「每个会话信封最多多少字节」只有落在它之下才可达
5
+ * (一个越过它的信封根本进不了门,把旋钮设到那里就是一只永远够不着的帽),配置的上帽从这里算(`adoption/import-limits.ts`)。
6
+ */
7
+ export declare const MAX_JSON_BODY_BYTES: number;
8
+ //# sourceMappingURL=json-body-limit.d.ts.map
@@ -0,0 +1,2 @@
1
+ export const MAX_JSON_BODY_BYTES = 8 * 1024 * 1024;
2
+ //# sourceMappingURL=json-body-limit.js.map
@@ -45,7 +45,7 @@ export type PullDiffResult = {
45
45
  * 而它**本就已经** `import { safeRev } from "./diffout.js"` —— 依赖边在,共享零成本。两份手抄的后果不是
46
46
  * 「多写一行」,是**单边改值后上行/pull 两腿对同一个 diff 的过/拒判定分家**:同一份补丁在一条腿上过、
47
47
  * 另一条腿上被截断,而两处都「按自己的常量」正确工作,没有任何一处会报错。
48
- * (同族先例:`checkpoint-store-sql.ts` 的 `export const TERMINAL_GRACE_MS`。)
48
+ * (同族先例:`checkpoint-store-face.ts` 的 `export const TERMINAL_GRACE_MS`。)
49
49
  */
50
50
  export declare const DEFAULT_MAX_DIFF_BYTES: number;
51
51
  export declare function safeRev(rev: string): boolean;
@@ -7,8 +7,8 @@
7
7
  * `scripts/drain-check-local.mjs`(经 `dist/local-data-root.js` 取同一只函数,缺省数据根不再自抄一份链:抄本只对了一半,
8
8
  * 设了 `AGENT_DATA_DIR` 的部署不带参数跑脚本会读到另一个目录并报「干净」)。纯叶、零反向依赖 ⇒ 脚本引它不会把整个服务装载起来。
9
9
  *
10
- * ⚠️ 与**配置根**(`configLocalRoot`:`CONFIG_LOCAL_DIR` → `AGENT_DATA_DIR` → `~/.ai-agent`,不吃 `LOCAL_DATA_ROOT`)不是同一条链 —— 两根分家的那一形由
11
- * boot 期的 `local_roots_split` 告警说出来,本函数不改那条解析。
10
+ * ⚠️ 与**配置根**(`configLocalRoot`:`CONFIG_LOCAL_DIR` → `AGENT_DATA_DIR` → `~/.ai-agent`,不吃 `LOCAL_DATA_ROOT`)不是同一条链 —— 两根一声不响分家的那一形
11
+ * (没给 `CONFIG_LOCAL_DIR`)由 boot 期的 `local_roots_split` 告警说出来,本函数不改那条解析。
12
12
  */
13
13
  export declare function resolveLocalDataRoot(env: Readonly<Record<string, string | undefined>>, home: string): string;
14
14
  //# sourceMappingURL=local-data-root.d.ts.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `memory-embedder-reembed.ts` —— 「清列重嵌」**确认口令**的单一属主:`MEMORY_EMBEDDER_REEMBED=<model>/<dimensions>`。
3
+ *
4
+ * ## 律(一句)
5
+ *
6
+ * embedder 指纹门(`plugins/memory-embedder-fingerprint.ts`)从不凭自己的判断清列:记下的身份与配置的身份对不上
7
+ * (changed / unattributed / unreadable 三态)⇒ 拒启;唯一出路是运维显式确认「把向量列清掉、按**这个**身份重嵌」——
8
+ * 口令的值就是**配置的那个身份**。口令绑定身份,所以它天然是一次性的:清完并记下这个身份之后,下一次起服判「相等」,
9
+ * 口令不再有东西可确认;之后再换一次模型,留着的旧口令对不上新配置 ⇒ 起服拒(不会替下一次换模型静默清列)。
10
+ *
11
+ * ## 为什么是一只顶层叶模块
12
+ *
13
+ * 两个消费方在不同层:`config.ts` 在 boot 期解析并判口令(拼错 / 对不上配置 ⇒ 拒启),指纹门在拒句里**写出**这条口令。
14
+ * config 层不得值引 plugins 层;口令的读写形只有一份,两层各按需引 —— 这是本文件存在的全部理由。零依赖。
15
+ *
16
+ * 句子里写给运维**照抄**的那条赋值只有一个写者 {@link formatReembedAssignment}:值按 POSIX 单引号包起(模型名可以含空格 / `$` / 引号,
17
+ * 不包就粘不进 shell);引号只是 shell 的写法,shell 读完赋给 env 的值仍是 `<model>/<dimensions>` 本身(config 读的就是它)。
18
+ */
19
+ /** 口令那一键的名字(config 读它、门的拒句写它)。 */
20
+ export declare const MEMORY_EMBEDDER_REEMBED_ENV = "MEMORY_EMBEDDER_REEMBED";
21
+ /** 口令所确认的身份形(与指纹门的 `EmbedderIdentity` 同形;本叶不引 zod)。 */
22
+ export interface EmbedderIdentityToken {
23
+ readonly model: string;
24
+ readonly dimensions: number;
25
+ }
26
+ /** 身份 → 口令值:`<model>/<dimensions>`。模型名自身可以含 `/`(`BAAI/bge-m3`)—— 维度恒在**最后一个** `/` 之后。 */
27
+ export declare function formatEmbedderIdentityToken(identity: EmbedderIdentityToken): string;
28
+ /**
29
+ * 运维照抄的那条赋值:`MEMORY_EMBEDDER_REEMBED='<model>/<dimensions>'`。POSIX 单引号:值内唯一的元字符是 `'` 本身,写成 `'\''`
30
+ * (关引号、转义一个 `'`、再开引号)。拒句与 config 的出路句都经这里写,不各拼一份。
31
+ */
32
+ export declare function formatReembedAssignment(identity: EmbedderIdentityToken): string;
33
+ /**
34
+ * 口令值 → 身份;形不对 ⇒ `undefined`(调用方拒启并给出期望形,不猜)。判据:最后一个 `/` 之前非空(模型名),
35
+ * 之后是十进制正整数(无前导零、无符号、无空白)。`true` / `1` / `yes` 这类「开关形」一律不是口令。
36
+ */
37
+ export declare function parseEmbedderIdentityToken(raw: string): EmbedderIdentityToken | undefined;
38
+ //# sourceMappingURL=memory-embedder-reembed.d.ts.map
@@ -0,0 +1,20 @@
1
+ export const MEMORY_EMBEDDER_REEMBED_ENV = "MEMORY_EMBEDDER_REEMBED";
2
+ export function formatEmbedderIdentityToken(identity) {
3
+ return `${identity.model}/${identity.dimensions}`;
4
+ }
5
+ export function formatReembedAssignment(identity) {
6
+ return `${MEMORY_EMBEDDER_REEMBED_ENV}='${formatEmbedderIdentityToken(identity).replace(/'/g, "'\\''")}'`;
7
+ }
8
+ export function parseEmbedderIdentityToken(raw) {
9
+ const cut = raw.lastIndexOf("/");
10
+ if (cut <= 0)
11
+ return undefined;
12
+ const digits = raw.slice(cut + 1);
13
+ if (!/^[1-9][0-9]*$/.test(digits))
14
+ return undefined;
15
+ const dimensions = Number(digits);
16
+ if (!Number.isSafeInteger(dimensions))
17
+ return undefined;
18
+ return { model: raw.slice(0, cut), dimensions };
19
+ }
20
+ //# sourceMappingURL=memory-embedder-reembed.js.map
@@ -1,31 +1,3 @@
1
- /**
2
- * 记忆引擎 **incident 席**在本仓的唯一落点形。
3
- *
4
- * ## 为什么要一只共用工厂(而不是每个宿主各写一行 `logger.warn`)
5
- * core 的记忆引擎有**两条**到宿主的披露路:
6
- * · **mount 路**——`MemoryEngine` 自己的 `onIncident`,由 core 的 Runner 在 `prepare-memory` 里桥到
7
- * `RunnerDeps.onError(err, { phase: "memory", sessionId })`(亲读 `dist/core/runner/prepare-memory.js`
8
- * 的 `const onEngineIncident = (err) => deps.onError?.(err, { phase: "memory", sessionId })`);
9
- * · **无锁公开面路**——`FileMemoryEngineBackend` 的**构造期** `onIncident`,是那条腿上唯一的披露口
10
- * (`adoptLayoutLocked` 取 `onIncident ?? this.onIncident`)。
11
- * 同一条事实(例如一次性的目录布局搬家)会按调用路径落到其中**一条**,而本仓有**两个宿主**
12
- * (HTTP 服务的 `boot/runner-deps.ts` 与 `run-local.ts`)各自持有 `onError` 座。四个落点各写一行 =
13
- * 四份会各自漂移的形;实际已经漂过一次:服务腿把整族印成 `memory_consolidation_failed`(只有一支是
14
- * consolidation),run-local 腿把整族印成 `engine_error` 并用 `String(err)` 抹掉 `err.code`。
15
- *
16
- * ## 形(一处定义,四处引用)
17
- * `memory_engine_incident` + `{ sessionId?, code?, detail }`,并计 `memory_engine_incident_total{code?}`。
18
- * 🔴 `code` 是**结构化字段**而不是被折进散文:它是运维唯一能按名告警的那一位,而这一族里最要紧的几条
19
- * (一次性布局搬家、无主根内容、控制面写失败)一辈子只发生一次 —— 折平就等于没说。
20
- * 码的读法与 `boot/runner-deps.ts` 的 `onError` 汇点其余七条行**同一只**(`terminal.ts` 的 `codeFieldOf`:不抛的读口 + 码判官 `isCodeToken`):是码才带;
21
- * 无码(core 里有大量不带 `.code` 的记忆相 Error)、不是串 / 空串、非 `Error` 抛出物、读取时抛、或带的不是码(超长 / 含空白 / 凭据形 —— 引擎错上的 `code` 是别人写的串)⇒ 行里**没有** `code` 键、
22
- * 计数**没有** `code` 标签:不编码,也不写 `null` / `"none"` 之类的占位。
23
- *
24
- * ⚠️ 与三只 **operator 面**引擎座(`memory_compliance_incident` / `memory_origin_incident` /
25
- * `memory_consolidation_incident`)**事件名刻意不合并**:那三条的事件名回答「哪一张操作面」,是三个产品面的
26
- * 分辨位;本工厂回答「引擎事故席」,是同一件事的四个落点。合并会丢掉前者的分辨位。三座有自己的工厂
27
- * {@link createOperatorFaceIncidentSink}(事件名由装配处点名),`code` 位与本工厂读同一只 `codeFieldOf`。
28
- */
29
1
  import type { Logger } from "./observability/logger.js";
30
2
  import type { Metrics } from "./observability/metrics.js";
31
3
  /** 落点依赖。`metrics` 可缺席(run-local 的 backend 构造期座就没有计数面的消费者)。 */
@@ -1,3 +1,5 @@
1
+ import { recordFailOpen } from "./observability/fail-open.js";
2
+ import { isStoreFormRefusalCode } from "./memory-store-refusal.js";
1
3
  import { redactIncarnations } from "./session-incarnation.js";
2
4
  import { codeFieldOf } from "./terminal.js";
3
5
  import { seatText } from "./trace/exit-seat.js";
@@ -10,6 +12,9 @@ export function createMemoryEngineIncidentSink(deps) {
10
12
  detail: redactIncarnations(String(err)),
11
13
  });
12
14
  deps.metrics?.inc("memory_engine_incident_total", { ...codeField });
15
+ const { code } = codeField;
16
+ if (isStoreFormRefusalCode(code))
17
+ recordFailOpen("server.memory.store-form-refused-step-skipped", `code=${code}`);
13
18
  };
14
19
  }
15
20
  export function createOperatorFaceIncidentSink(deps, event) {