@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,31 @@
1
+ /**
2
+ * `POST /v1/engine/handover` · `POST /v1/engine/attach` —— 附着租约的交接车道([ref] v3,「Move to background and exit」)。
3
+ *
4
+ * 一只门的两扇口:交接口置交接位(壳随后自己退出、不 SIGTERM 引擎;后台 shell 在跑时引擎不退),attach 口清位(下一只壳收回)。车道、窗、
5
+ * 工作谓词全在租约腿(`boot/engine-lease.ts`);本域只读写**交接门**(`drainState.engineHandover`,收尾链装配时进盒子)。
6
+ * · 门序:身份(多租户形的主体门,与运维口同一只铸点)→ 能力事实 `engineHandover`(与 `capabilities.engine.handover` 同读;不可用 ⇒ 501
7
+ * `capability.engine_handover_unavailable`,按 why 两句)→ 验型(体坏 ⇒ 400,零状态变化)→ 写门。billable=false,**不吃排空 503**
8
+ * (排空一开始租约腿在它的下一拍收摊,能力事实随即答 501;那一拍之内的交接 / attach 无害 —— 引擎已在退)。
9
+ * · 交接体只收 `{ reason: "background_exit" }`(闭集);attach 体只收空对象或空体(字面 `null` 与空体同读 —— 共用读体器的全服务律)。
10
+ * 非对象体 ⇒ 400 `request.invalid_json`(`not_object`)。
11
+ * · 能力事实读两次、是同一只函数:读体之前读一次(决定 501 先于 400),验完体、写门之前**无 await** 再读一次 —— 读体途中腿停了(停机开始)
12
+ * 就答 501,不拿读体之前的旧事实去写一只已不在观察的门(codex r1 [medium])。
13
+ * · 两口幂等:再次交接回同一个 `since`;不在交接车道时 attach 照回此刻车道(`handedOverForMs` 缺席)。
14
+ */
15
+ import type { IncomingMessage, ServerResponse } from "node:http";
16
+ import type { RouteCtx, RouteMatch, RouteIdsOf } from "../route-ctx.js";
17
+ export declare const ENGINE_HANDOVER_PATH = "/v1/engine/handover";
18
+ export declare const ENGINE_ATTACH_PATH = "/v1/engine/attach";
19
+ export declare function handleEngine(req: IncomingMessage, res: ServerResponse, match: RouteMatch<EngineRouteId>, ctx: RouteCtx): Promise<void>;
20
+ export declare const ENGINE_ROUTES: readonly [{
21
+ readonly id: "engine-handover";
22
+ readonly path: "/v1/engine/handover";
23
+ readonly methods: readonly ["POST"];
24
+ }, {
25
+ readonly id: "engine-attach";
26
+ readonly path: "/v1/engine/attach";
27
+ readonly methods: readonly ["POST"];
28
+ }];
29
+ type EngineRouteId = RouteIdsOf<typeof ENGINE_ROUTES>;
30
+ export {};
31
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1,81 @@
1
+ import { sendJson, sendError, sendHttpError, invalidJsonError } from "../send.js";
2
+ import { gatedPrincipal, sendPrincipalRefusal } from "../principal-gate.js";
3
+ import * as facts from "../../capability-facts.js";
4
+ import { HANDOVER_REASONS } from "../../boot/engine-lease.js";
5
+ import { assertNever } from "../route-ctx.js";
6
+ export const ENGINE_HANDOVER_PATH = "/v1/engine/handover";
7
+ export const ENGINE_ATTACH_PATH = "/v1/engine/attach";
8
+ const HANDOVER_REASONS_SPELLED = HANDOVER_REASONS.map((r) => `"${r}"`).join(", ");
9
+ const ATTACH_BODY_MESSAGE = "the attach request takes no fields (send {} or an empty body) — nothing was changed";
10
+ function isPlainObject(v) {
11
+ return typeof v === "object" && v !== null && !Array.isArray(v);
12
+ }
13
+ function readHandoverReason(body) {
14
+ const keys = Object.keys(body);
15
+ if (keys.length !== 1 || keys[0] !== "reason")
16
+ return undefined;
17
+ const reason = body.reason;
18
+ return HANDOVER_REASONS.find((r) => r === reason);
19
+ }
20
+ function sendHandoverUnavailable(res, why) {
21
+ switch (why) {
22
+ case "engine_handover_lane_absent":
23
+ sendError(res, 501, "capability.engine_handover_unavailable", "handover is not available on this engine: its attachment lease is not armed (neither ENGINE_AUTO_EXIT nor SEMA_PARENT_PID), or the deployment is multi-tenant (REQUIRE_PRINCIPAL=true) — GET /v1/capabilities reports engine.handover=false; exit and stop tasks instead");
24
+ return;
25
+ case "engine_lease_stopped":
26
+ sendError(res, 501, "capability.engine_handover_unavailable", "this engine is shutting down: its attachment lease has stopped observing, so there is nothing to hand over or attach to");
27
+ return;
28
+ default:
29
+ return assertNever(why);
30
+ }
31
+ }
32
+ export async function handleEngine(req, res, match, ctx) {
33
+ const { deps } = ctx;
34
+ if (deps.config.requirePrincipal && gatedPrincipal(req, deps.config) === undefined) {
35
+ sendPrincipalRefusal(res, req, deps.config);
36
+ return;
37
+ }
38
+ const before = facts.engineHandover(deps);
39
+ if (!before.available) {
40
+ sendHandoverUnavailable(res, before.why);
41
+ return;
42
+ }
43
+ const body = await ctx.helpers.readJson(req);
44
+ if (!isPlainObject(body)) {
45
+ sendHttpError(res, invalidJsonError("not_object"));
46
+ return;
47
+ }
48
+ let write;
49
+ switch (match.decl.id) {
50
+ case "engine-handover": {
51
+ const reason = readHandoverReason(body);
52
+ if (reason === undefined) {
53
+ sendError(res, 400, "request.field_invalid", `the handover request must be exactly { reason } with reason one of ${HANDOVER_REASONS_SPELLED} — nothing was changed`);
54
+ return;
55
+ }
56
+ write = (door) => door.enter(reason);
57
+ break;
58
+ }
59
+ case "engine-attach": {
60
+ if (Object.keys(body).length > 0) {
61
+ sendError(res, 400, "request.field_invalid", ATTACH_BODY_MESSAGE);
62
+ return;
63
+ }
64
+ write = (door) => door.attach();
65
+ break;
66
+ }
67
+ default:
68
+ return assertNever(match.decl.id);
69
+ }
70
+ const now = facts.engineHandover(deps);
71
+ if (!now.available) {
72
+ sendHandoverUnavailable(res, now.why);
73
+ return;
74
+ }
75
+ sendJson(res, 200, write(now.door));
76
+ }
77
+ export const ENGINE_ROUTES = [
78
+ { id: "engine-handover", path: ENGINE_HANDOVER_PATH, methods: ["POST"] },
79
+ { id: "engine-attach", path: ENGINE_ATTACH_PATH, methods: ["POST"] },
80
+ ];
81
+ //# sourceMappingURL=engine.js.map
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { sendJson, sendError } from "../send.js";
3
3
  import { sentMemoryStoreRefusal } from "../memory-store-refusal-reply.js";
4
+ import { sentControlPlaneCorrupt } from "../memory-control-plane-corrupt-reply.js";
4
5
  import { buildOriginFencedBundle, readOriginAware } from "../../memory-origin-fence.js";
5
6
  import { gatedPrincipal, explicitOperatorOk, sendOperatorPrincipalsRequired, sendPrincipalRefusal } from "../principal-gate.js";
6
7
  import { assertNever } from "../route-ctx.js";
@@ -42,6 +43,8 @@ function sentClassifiedFailure(res, ctx, face, err) {
42
43
  return true;
43
44
  if (sentMemoryStoreRefusal(res, err, ctx.deps.logger))
44
45
  return true;
46
+ if (sentControlPlaneCorrupt(res, err, { kind: "operator" }))
47
+ return true;
45
48
  ctx.deps.logger?.warn?.(`memory_bundle_${face}_failed`, { err: String(err) });
46
49
  return false;
47
50
  }
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
- import { ControlPlaneCorruptError } from "@sema-agent/core";
3
2
  import { sendJson, sendError } from "../send.js";
4
3
  import { sentMemoryLayerRefusal } from "../memory-layer-reply.js";
4
+ import { sentControlPlaneCorrupt } from "../memory-control-plane-corrupt-reply.js";
5
5
  import { gatedPrincipal, explicitOperatorOk, sendPrincipalRefusal, sendOperatorPrincipalsRequired } from "../principal-gate.js";
6
6
  import { assertNever } from "../route-ctx.js";
7
7
  import * as facts from "../../capability-facts.js";
@@ -104,7 +104,7 @@ export async function handleMemoryConsolidation(req, res, match, ctx) {
104
104
  const scope = "scope" in decided ? decided.scope : undefined;
105
105
  let row;
106
106
  try {
107
- row = scope !== undefined ? faces.lastRun(scope) : undefined;
107
+ row = scope !== undefined ? await faces.lastRun(scope) : undefined;
108
108
  }
109
109
  catch (err) {
110
110
  if (sentMemoryLayerRefusal(res, err, { kind: "operator" }))
@@ -160,10 +160,8 @@ export async function handleMemoryConsolidation(req, res, match, ctx) {
160
160
  sendError(res, 409, "memory.consolidation_refused", `memory consolidation refused (${coreCode}): ${err instanceof Error ? err.message : String(err)}`);
161
161
  return;
162
162
  }
163
- if (err instanceof ControlPlaneCorruptError) {
164
- sendError(res, 500, "internal.memory_control_plane_corrupt", err.message);
163
+ if (sentControlPlaneCorrupt(res, err, { kind: "operator" }))
165
164
  return;
166
- }
167
165
  ctx.deps.logger?.warn?.("memory_consolidation_run_failed", { scope: decided.scope, err: String(err) });
168
166
  sendError(res, 500, "internal.error", "memory consolidation run failed");
169
167
  }
@@ -78,7 +78,7 @@
78
78
  * 分层:本模块不值 import `server.ts`(那条边闭合运行时装载环),只 `import type`。
79
79
  */
80
80
  import type { IncomingMessage, ServerResponse } from "node:http";
81
- import { type OriginClearanceRow } from "@sema-agent/core";
81
+ import type { OriginClearanceRow } from "@sema-agent/core";
82
82
  import type { RouteCtx, RouteMatch, RouteIdsOf } from "../route-ctx.js";
83
83
  export declare const MEMORY_ORIGIN_EXTERNAL_PATH = "/v1/memory/origin/external";
84
84
  export declare const MEMORY_ORIGIN_CLEARANCES_PATH = "/v1/memory/origin/clearances";
@@ -105,7 +105,7 @@ export declare function buildClearanceRowWire(r: OriginClearanceRow): {
105
105
  requestId: string;
106
106
  reason: string;
107
107
  at: number;
108
- status: "done" | "failed" | "pending";
108
+ status: "done" | "pending" | "failed";
109
109
  originUnknownKeys?: string[] | undefined;
110
110
  clearanceId: string;
111
111
  entryId: string;
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
- import { ControlPlaneCorruptError } from "@sema-agent/core";
3
2
  import { sendJson, sendError } from "../send.js";
4
3
  import { sentMemoryStoreRefusal } from "../memory-store-refusal-reply.js";
4
+ import { sentControlPlaneCorrupt } from "../memory-control-plane-corrupt-reply.js";
5
5
  import { buildOriginFence, readOriginAware } from "../../memory-origin-fence.js";
6
6
  import { readLayerSeat, sentMemoryLayerRefusal } from "../memory-layer-reply.js";
7
7
  import { gatedPrincipal, explicitOperatorOk, sendOperatorPrincipalsRequired, sendPrincipalRefusal } from "../principal-gate.js";
@@ -59,10 +59,8 @@ function sentClassifiedFailure(res, ctx, face, err) {
59
59
  }
60
60
  if (face !== "clearances" && sentMemoryStoreRefusal(res, err, ctx.deps.logger))
61
61
  return true;
62
- if (err instanceof ControlPlaneCorruptError) {
63
- sendError(res, 500, "internal.memory_control_plane_corrupt", err.message);
62
+ if (sentControlPlaneCorrupt(res, err, { kind: "operator" }))
64
63
  return true;
65
- }
66
64
  ctx.deps.logger?.warn?.(`memory_origin_${face}_failed`, { err: String(err) });
67
65
  return false;
68
66
  }
@@ -1,4 +1,4 @@
1
- import { formatUserScope } from "@sema-agent/core";
1
+ import { formatUserScope, isReplicableScope } from "@sema-agent/core";
2
2
  import { parseMemorySyncRequest } from "../../memory-sync.js";
3
3
  import { memorySyncIdentityRule } from "../../memory-sync-identity.js";
4
4
  import * as facts from "../../capability-facts.js";
@@ -160,6 +160,10 @@ export async function handleMemoryPolicy(req, res, match, ctx) {
160
160
  sendError(res, 400, "memory_sync_invalid_scope", "missing :scope");
161
161
  return;
162
162
  }
163
+ if (!isReplicableScope(scope)) {
164
+ sendError(res, 400, "memory_sync_invalid_scope", "a userlocal: memory layer never leaves the store it is written in — it is not synced");
165
+ return;
166
+ }
163
167
  if (sendScopeGateRefusal(res, await gateMemoryScope(deps, principal, scope, "write")))
164
168
  return;
165
169
  const body = await readJson(req);
@@ -119,7 +119,8 @@ export async function handleNotifyWake(req, res, match, ctx) {
119
119
  return;
120
120
  }
121
121
  const restatement = readResumeRestatement(wakeBody);
122
- const out = await resumeWake(wakeSession, wakeBody.message, principal, req, true, undefined, undefined, restatement);
122
+ const message = typeof wakeBody.message === "string" ? { text: wakeBody.message, trusted: false } : undefined;
123
+ const out = await resumeWake(wakeSession, message, principal, req, true, undefined, undefined, restatement);
123
124
  sendResumeOutcome(res, out, deps.logger);
124
125
  return;
125
126
  }
@@ -12,12 +12,9 @@ export async function handleObservability(req, res, match, ctx) {
12
12
  sendOperatorPrincipalsRequired(res);
13
13
  return;
14
14
  }
15
- if (deps.config.requirePrincipal) {
16
- const principal = gatedPrincipal(req, deps.config);
17
- if (!explicitOperatorOk(principal, deps.config)) {
18
- sendError(res, 403, "auth.operator_only", "outcomes view is operator-only on a multi-tenant worker");
19
- return;
20
- }
15
+ if (!explicitOperatorOk(gatedPrincipal(req, deps.config), deps.config)) {
16
+ sendError(res, 403, "auth.operator_only", "the outcomes view is operator-only");
17
+ return;
21
18
  }
22
19
  if (!fact.available) {
23
20
  switch (fact.why) {
@@ -0,0 +1,70 @@
1
+ /**
2
+ * 项目登记簿的**读面** —— `GET /v1/projects`、`GET /v1/projects/:id`。
3
+ *
4
+ * ## 律(三句)
5
+ * · **一个项目 = settings-schema 的一只 `ProjectRegistration`**:形与判官只在 settings-schema;本仓把判过的登记原样放在 `config.projects` 一张表里
6
+ * (`web-admin-client/apply-effective.ts` 的 stage 是唯一写者),本面只读那一张。行 = `{ id, …登记的原键原名 }` —— 不铸 `name` / `repos` /
7
+ * `createdAt` 之类的别名(端侧要别的叫法自己投影),逐键处置在 {@link PROJECT_ROW_DISPOSITIONS} 一张表里(settings-schema 给登记加键 ⇒ 这里 tsc 红,
8
+ * 先表态再上 wire)。
9
+ * · **登记簿只由配置中心下发**:settings-schema 的本地读取集不收 `projects` 域 ⇒ 没有中心腿在应用配置的部署上没有登记簿 —— 两口 501
10
+ * `capability.unavailable`,能力位 `capabilities.projects`(布尔)读同一只事实(`capability-facts.ts` 的 `projectRegistry`)答 `false`;
11
+ * 有登记簿时答 `true`。本面不开写动词(写到哪里由另一张设计定;写面到货时另立一位,本位不改义)。
12
+ * · **可见性 fail-closed**:身份判在登记簿在场判**之前**(否则「这台有没有登记簿」先于 401 泄出去);fleet 调用方(`fleetViewOf` 读档)看全部;
13
+ * 带验过主体的调用方只看 `registeredBy` 恰是自己的登记;看不见的与不存在的同码同句(404 `not_found.project`,不给存在性预言机)。
14
+ *
15
+ * 归档:`archivedAt` 在场 = 已归档。列表缺省不列,`?archived=true` 只列已归档的,`?archived=false` 与缺省同;单项读不论归档与否都答(会话行引用它)。
16
+ */
17
+ import type { IncomingMessage, ServerResponse } from "node:http";
18
+ import type { ProjectRegistration } from "@sema-agent/settings-schema";
19
+ import type { RouteCtx, RouteMatch, RouteIdsOf } from "../route-ctx.js";
20
+ /** 404 的唯一句(不存在与看不见同句)。 */
21
+ export declare const PROJECT_NOT_FOUND_MESSAGE = "no such project";
22
+ /** 投影根:这只登记的 id(登记簿的键 —— 不是登记的成员)。 */
23
+ interface ProjectRowRoot {
24
+ readonly id: string;
25
+ }
26
+ /**
27
+ * 项目行的**逐键处置**(表序 = 出口序)。登记的每个键原样出门;`contextItems` 逐条按成员处置(闭集三形,成员同为 `kind` / `value`)。
28
+ * `id` 是本面铸的唯一键:登记簿的键,行上要有它才能回指 `GET /v1/projects/:id` 与提交体 `projectId`。
29
+ */
30
+ export declare const PROJECT_ROW_DISPOSITIONS: {
31
+ readonly id: {
32
+ readonly mint: (_reg: ProjectRegistration, root: ProjectRowRoot) => string;
33
+ };
34
+ readonly displayName: "forward";
35
+ readonly goal: "forward";
36
+ readonly contextItems: {
37
+ readonly nested: {
38
+ readonly kind: "forward";
39
+ readonly value: "forward";
40
+ };
41
+ readonly rows: "each";
42
+ };
43
+ readonly gitRemotes: "forward";
44
+ readonly defaultScopes: "forward";
45
+ readonly notes: "forward";
46
+ readonly icon: "forward";
47
+ readonly color: "forward";
48
+ readonly registeredBy: "forward";
49
+ readonly registeredAt: "forward";
50
+ readonly archivedAt: "forward";
51
+ };
52
+ /** 项目行的键全集(处置表的键 = wire 上可能出现的每一个键;自铸登记表 `trace/self-minted-wire.ts` 的 `projectRowKey` 按它 `satisfies`)。 */
53
+ export type ProjectRowKey = keyof typeof PROJECT_ROW_DISPOSITIONS;
54
+ /** 一只登记 → wire 行(唯一投影)。 */
55
+ export declare function projectRowOf(id: string, registration: ProjectRegistration): Record<string, unknown>;
56
+ export declare function handleProjects(req: IncomingMessage, res: ServerResponse, match: RouteMatch<ProjectsRouteId>, ctx: RouteCtx): Promise<void>;
57
+ export declare const PROJECTS_ROUTES: readonly [{
58
+ readonly id: "projects-list";
59
+ readonly path: "/v1/projects";
60
+ readonly methods: readonly ["GET"];
61
+ }, {
62
+ readonly id: "project-get";
63
+ readonly pattern: RegExp;
64
+ readonly label: "/v1/projects/:id";
65
+ readonly methods: readonly ["GET"];
66
+ }];
67
+ /** 本域可分派行的 `id` 闭集。 */
68
+ export type ProjectsRouteId = RouteIdsOf<typeof PROJECTS_ROUTES>;
69
+ export {};
70
+ //# sourceMappingURL=projects.d.ts.map
@@ -0,0 +1,86 @@
1
+ import { PROJECT_ID_REGEX } from "@sema-agent/core";
2
+ import { sendJson, sendError } from "../send.js";
3
+ import { fleetViewOf, sendUnauthorized } from "../principal-gate.js";
4
+ import { assertNever } from "../route-ctx.js";
5
+ import * as facts from "../../capability-facts.js";
6
+ import { projectByTable } from "../../trace/projection-table.js";
7
+ export const PROJECT_NOT_FOUND_MESSAGE = "no such project";
8
+ export const PROJECT_ROW_DISPOSITIONS = {
9
+ id: { mint: (_reg, root) => root.id },
10
+ displayName: "forward",
11
+ goal: "forward",
12
+ contextItems: { nested: { kind: "forward", value: "forward" }, rows: "each" },
13
+ gitRemotes: "forward",
14
+ defaultScopes: "forward",
15
+ notes: "forward",
16
+ icon: "forward",
17
+ color: "forward",
18
+ registeredBy: "forward",
19
+ registeredAt: "forward",
20
+ archivedAt: "forward",
21
+ };
22
+ export function projectRowOf(id, registration) {
23
+ return projectByTable("project", PROJECT_ROW_DISPOSITIONS, registration, { id });
24
+ }
25
+ function readArchivedQuery(raw) {
26
+ switch (raw) {
27
+ case null:
28
+ case "false":
29
+ return false;
30
+ case "true":
31
+ return true;
32
+ default:
33
+ return "invalid";
34
+ }
35
+ }
36
+ export async function handleProjects(req, res, match, ctx) {
37
+ const { deps } = ctx;
38
+ const { safeDecode } = ctx.helpers;
39
+ const { fleetWide, gateOwner } = fleetViewOf(req, deps, "read");
40
+ if (!fleetWide && gateOwner === null) {
41
+ sendUnauthorized(res, "identity");
42
+ return;
43
+ }
44
+ const registry = facts.projectRegistry(deps);
45
+ if (!registry.available) {
46
+ sendError(res, 501, "capability.unavailable", "the project registry is not available on this deployment: projects are published only by the configuration center, and no center configuration is applied here");
47
+ return;
48
+ }
49
+ const visible = (registration) => fleetWide || registration.registeredBy === gateOwner;
50
+ switch (match.decl.id) {
51
+ case "projects-list": {
52
+ const archived = readArchivedQuery(new URLSearchParams(match.search).get("archived"));
53
+ if (archived === "invalid") {
54
+ sendError(res, 400, "request.query_invalid", "archived must be `true` or `false`");
55
+ return;
56
+ }
57
+ const projects = Object.entries(registry.registry)
58
+ .filter(([, registration]) => visible(registration) && (registration.archivedAt !== undefined) === archived)
59
+ .map(([id, registration]) => projectRowOf(id, registration));
60
+ sendJson(res, 200, { projects });
61
+ return;
62
+ }
63
+ case "project-get": {
64
+ const raw = safeDecode(match.params.projectId);
65
+ if (raw === null || !PROJECT_ID_REGEX.test(raw)) {
66
+ sendError(res, 400, "request.id_invalid", "invalid project id (must be a canonical uuid)");
67
+ return;
68
+ }
69
+ const id = raw.toLowerCase();
70
+ const registration = Object.hasOwn(registry.registry, id) ? registry.registry[id] : undefined;
71
+ if (registration === undefined || !visible(registration)) {
72
+ sendError(res, 404, "not_found.project", PROJECT_NOT_FOUND_MESSAGE);
73
+ return;
74
+ }
75
+ sendJson(res, 200, projectRowOf(id, registration));
76
+ return;
77
+ }
78
+ default:
79
+ return assertNever(match.decl.id);
80
+ }
81
+ }
82
+ export const PROJECTS_ROUTES = [
83
+ { id: "projects-list", path: "/v1/projects", methods: ["GET"] },
84
+ { id: "project-get", pattern: /^\/v1\/projects\/(?<projectId>[^/]+)$/, label: "/v1/projects/:id", methods: ["GET"] },
85
+ ];
86
+ //# sourceMappingURL=projects.js.map
@@ -142,6 +142,10 @@ export async function handleRules(req, res, match, ctx) {
142
142
  logger.info("local rule import tightening write failed", { detail: prepared.detail, committed: prepared.committed });
143
143
  sendRuleWriteFailure(res, "import-tightening", prepared.committed);
144
144
  return;
145
+ case "record-store-refused":
146
+ logger.info("local rule import record store refused", { detail: prepared.detail, committed: prepared.committed });
147
+ sendRuleWriteFailure(res, "import-record", prepared.committed);
148
+ return;
145
149
  default: {
146
150
  const unknown = prepared;
147
151
  throw new Error(`unknown local import refusal: ${JSON.stringify(unknown)}`);
@@ -189,8 +193,19 @@ export async function handleRules(req, res, match, ctx) {
189
193
  }
190
194
  const prepared = await lane.prepareImport(principal, parsed.data.layers);
191
195
  if (!prepared.ok) {
192
- sendError(res, 413, "request.payload_too_large", "too many allow entries across the submitted settings layers");
193
- return;
196
+ switch (prepared.reason) {
197
+ case "too-many-candidates":
198
+ sendError(res, 413, "request.payload_too_large", "too many allow entries across the submitted settings layers");
199
+ return;
200
+ case "record-store-refused":
201
+ logger.info("rule import record store refused", { detail: prepared.detail, committed: prepared.committed });
202
+ sendRuleWriteFailure(res, "import-record", prepared.committed);
203
+ return;
204
+ default: {
205
+ const unknown = prepared;
206
+ throw new Error(`unknown rule import refusal: ${JSON.stringify(unknown)}`);
207
+ }
208
+ }
194
209
  }
195
210
  sendJson(res, 200, { preview: prepared.preview, ...(prepared.ticket !== undefined ? { ticket: prepared.ticket, expiresAtMs: prepared.expiresAtMs } : {}) });
196
211
  return;
@@ -306,6 +321,19 @@ function sendRuleWriteFailure(res, verb, committed) {
306
321
  throw new Error(`unknown rule-write committed word: ${JSON.stringify(unknownWord)}`);
307
322
  }
308
323
  }
324
+ case "import-record":
325
+ switch (committed) {
326
+ case "no":
327
+ sendError(res, 503, "state.rule_write_failed", "the import's approval record could not be created (no ticket was issued and no allow rule was written; deny / ask rows of a local batch may already be in force) — send the same request again", { committed });
328
+ return;
329
+ case "unknown":
330
+ sendError(res, 503, "state.rule_write_failed", "the import's approval record may or may not have been created (no ticket was issued and no allow rule was written; deny / ask rows of a local batch may already be in force) — send the same request again", { committed });
331
+ return;
332
+ default: {
333
+ const unknownWord = committed;
334
+ throw new Error(`unknown rule-import committed word: ${JSON.stringify(unknownWord)}`);
335
+ }
336
+ }
309
337
  case "revoke":
310
338
  switch (committed) {
311
339
  case "no":
@@ -4,7 +4,7 @@ import { z } from "zod";
4
4
  import { uuidv7, mintCheckpointToken, CheckpointError, policyCannotAnswer, validatePendingSteer, TASK_OUTPUT_REPLAY_KINDS, isSystemInjectionPriority } from "@sema-agent/core";
5
5
  import { isTerminalRunStatus, isParkedRunStatus, runProvenElsewhere } from "../../plugins/store-contracts.js";
6
6
  import { askOwnerAdmits, askRowCarriesOwner } from "../../plugins/approval-ask-store-sql.js";
7
- import { LIVE_RUN_GATE_KINDS, TERMINAL_PARK_GATE_KINDS } from "../../plugins/checkpoint-store-sql.js";
7
+ import { LIVE_RUN_GATE_KINDS, TERMINAL_PARK_GATE_KINDS } from "../../plugins/checkpoint-store-face.js";
8
8
  import { redactSecrets } from "../../trace/redact.js";
9
9
  import { isUuidV7, encodeCheckpointScope } from "../../security.js";
10
10
  import { redactSteerIn, STEER_IN_MAX_CHARS, STEER_IN_MAX_REQUEST_CHARS } from "../../orchestration/workflow-agent-steer.js";
@@ -440,10 +440,10 @@ export async function handleRuns(req, res, match, ctx) {
440
440
  const priority = body.priority;
441
441
  const steerIdemRaw = headerStr(req.headers["idempotency-key"]);
442
442
  const messageId = steerIdemRaw ? `idem-${idemKeyOf(steerIdemRaw, idemCallerOf(req, ctx), "run").slice(0, 32)}` : uuidv7();
443
- const trusted = explicitOperatorOk(principal, deps.config);
443
+ const operator = explicitOperatorOk(principal, deps.config);
444
444
  const steerInput = () => ({
445
445
  text,
446
- trusted,
446
+ trusted: false,
447
447
  inputId: messageId,
448
448
  ...(priority !== undefined ? { priority } : {}),
449
449
  });
@@ -462,7 +462,7 @@ export async function handleRuns(req, res, match, ctx) {
462
462
  sendError(res, 404, "not_found.run", runNotFoundMessage(taskId));
463
463
  return;
464
464
  }
465
- if (!trusted && !runOwnerOk(req, res, run.owner))
465
+ if (!operator && !runOwnerOk(req, res, run.owner))
466
466
  return;
467
467
  if (!runSessionAcceptOk(req, res, run, "run.steer"))
468
468
  return;
@@ -505,7 +505,7 @@ export async function handleRuns(req, res, match, ctx) {
505
505
  if (acceptance === "refused")
506
506
  return;
507
507
  try {
508
- await relayAcceptedInput(deps, acceptance, () => live.steer(text, { trusted, inputId: messageId, ...(priority !== undefined ? { priority } : {}) }));
508
+ await relayAcceptedInput(deps, acceptance, () => live.steer(text, { trusted: false, inputId: messageId, ...(priority !== undefined ? { priority } : {}) }));
509
509
  sendJson(res, 200, { taskId, status: "running", delivery: "applied", messageId, ...(priority ? { priority } : {}) });
510
510
  return;
511
511
  }
@@ -765,10 +765,10 @@ export async function handleRuns(req, res, match, ctx) {
765
765
  const interruptIdemRaw = headerStr(req.headers["idempotency-key"]);
766
766
  const interruptInputId = interruptIdemRaw ? `idem-${idemKeyOf(interruptIdemRaw, idemCallerOf(req, ctx), "run").slice(0, 32)}` : uuidv7();
767
767
  const interruptMessageId = interruptInputId;
768
- const trusted = explicitOperatorOk(principal, deps.config);
768
+ const operator = explicitOperatorOk(principal, deps.config);
769
769
  if (!interruptBare) {
770
770
  try {
771
- validatePendingSteer({ text, trusted, inputId: interruptInputId });
771
+ validatePendingSteer({ text, trusted: false, inputId: interruptInputId });
772
772
  }
773
773
  catch (e) {
774
774
  if (e instanceof CheckpointError && e.code === "steering.invalid_content") {
@@ -783,7 +783,7 @@ export async function handleRuns(req, res, match, ctx) {
783
783
  sendError(res, 404, "not_found.run", runNotFoundMessage(taskId));
784
784
  return;
785
785
  }
786
- if (!trusted && !runOwnerOk(req, res, run.owner))
786
+ if (!operator && !runOwnerOk(req, res, run.owner))
787
787
  return;
788
788
  if (!runSessionAcceptOk(req, res, run, "run.interrupt"))
789
789
  return;
@@ -838,7 +838,7 @@ export async function handleRuns(req, res, match, ctx) {
838
838
  if (acceptance === "refused")
839
839
  return;
840
840
  try {
841
- await relayAcceptedInput(deps, acceptance, () => liveStream.steer(text, { trusted, priority: "now", ...(interruptInputId !== undefined ? { inputId: interruptInputId } : {}) }));
841
+ await relayAcceptedInput(deps, acceptance, () => liveStream.steer(text, { trusted: false, priority: "now", ...(interruptInputId !== undefined ? { inputId: interruptInputId } : {}) }));
842
842
  }
843
843
  catch (e) {
844
844
  const code = e.code;
@@ -1578,7 +1578,7 @@ export async function handleRunVerbs(req, res, match, ctx) {
1578
1578
  export async function createDurableRun(req, res, ctx, prepared, idem) {
1579
1579
  const { deps } = ctx;
1580
1580
  const { idemCache } = ctx.registry;
1581
- const { leaseDenied, usageWindowDenied } = ctx.helpers;
1581
+ const { leaseDenied, usageWindowDenied, admitRun } = ctx.helpers;
1582
1582
  const source = ctx.req.source;
1583
1583
  const runs = facts.durableRuns(deps);
1584
1584
  if (!runs.available) {
@@ -1600,6 +1600,9 @@ export async function createDurableRun(req, res, ctx, prepared, idem) {
1600
1600
  }
1601
1601
  if ((await leaseDenied(req, res)) || (await usageWindowDenied(req, res)))
1602
1602
  return null;
1603
+ const runSlot = admitRun(req, res);
1604
+ if (runSlot === undefined)
1605
+ return null;
1603
1606
  return await idemCache.run(idem !== undefined ? inflightKeyOf(idem, "durable", clientTaskId) : undefined, async () => {
1604
1607
  const out = await mintAndDriveDurableRun({ deps, registry: ctx.registry, helpers: ctx.helpers, local: ctx.local, legs: ctx.legs }, runStore, {
1605
1608
  prepared,
@@ -1609,9 +1612,10 @@ export async function createDurableRun(req, res, ctx, prepared, idem) {
1609
1612
  elicitOwner: submitter ?? null,
1610
1613
  source,
1611
1614
  identity: runIdentityOf(req, deps.config, prepared.auth?.principal ?? null),
1615
+ runSlot,
1612
1616
  });
1613
1617
  return out.existing ? await replayOfExistingRun(out.existing, caller, "durable", deps, runStore) : out;
1614
- });
1618
+ }).finally(() => runSlot.release());
1615
1619
  }
1616
1620
  function clientTaskIdOf(body) {
1617
1621
  const raw = typeof body === "object" && body !== null ? body.taskId : undefined;