@sema-agent/server 7.134.0 → 7.136.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 (550) hide show
  1. package/MIGRATION.md +197 -1
  2. package/USAGE.md +147 -42
  3. package/deploy/sema-up/README.md +1 -1
  4. package/deploy/sema-up/chart/templates/NOTES.txt +1 -1
  5. package/deploy/sema-up/chart/values.yaml +1 -1
  6. package/dist/adoption/plan.d.ts +1 -1
  7. package/dist/approval-ask-audit-store.d.ts +24 -24
  8. package/dist/approval-ask-machine.d.ts +2 -2
  9. package/dist/approval-card.d.ts +122 -154
  10. package/dist/approval-card.js +50 -51
  11. package/dist/approval-content-kind.d.ts +23 -5
  12. package/dist/approval-content-kind.js +8 -1
  13. package/dist/approval-deny-reasons.d.ts +1 -1
  14. package/dist/approval-gate-currency.d.ts +22 -3
  15. package/dist/approval-gate-currency.js +44 -18
  16. package/dist/approval-hmac.d.ts +7 -7
  17. package/dist/approval-policy-settlement.d.ts +2 -2
  18. package/dist/approval-reconciler.d.ts +3 -3
  19. package/dist/approval.d.ts +8 -8
  20. package/dist/approval.js +4 -2
  21. package/dist/auth-bridge.d.ts +35 -6
  22. package/dist/auth-bridge.js +20 -3
  23. package/dist/auto-mode-face.d.ts +4 -4
  24. package/dist/background-session-reap.d.ts +2 -2
  25. package/dist/bake-runner/main.d.ts +2 -2
  26. package/dist/bake-runner/runner.d.ts +4 -4
  27. package/dist/bench/s1/live-deps.d.ts +1 -1
  28. package/dist/bench/s1/run-firm.d.ts +1 -1
  29. package/dist/boot/budget-tracing.d.ts +1 -2
  30. package/dist/boot/budget-tracing.js +2 -2
  31. package/dist/boot/coordinators.d.ts +2 -2
  32. package/dist/boot/coordinators.js +2 -2
  33. package/dist/boot/deferred-sandbox-path-env.d.ts +0 -6
  34. package/dist/boot/deferred-sandbox-path-env.js +0 -5
  35. package/dist/boot/engine-lease.d.ts +5 -5
  36. package/dist/boot/execution-env.d.ts +16 -15
  37. package/dist/boot/execution-env.js +19 -21
  38. package/dist/boot/fatal-exit.d.ts +2 -2
  39. package/dist/boot/late-binds.d.ts +1 -1
  40. package/dist/boot/leader.d.ts +1 -1
  41. package/dist/boot/memory-boundary.d.ts +2 -2
  42. package/dist/boot/memory-consolidation.d.ts +15 -15
  43. package/dist/boot/org-memory.js +1 -1
  44. package/dist/boot/parked-revive-gate.d.ts +3 -3
  45. package/dist/boot/parked-revive-gate.js +3 -2
  46. package/dist/boot/reapers.d.ts +4 -4
  47. package/dist/boot/resolve-spec.d.ts +1 -1
  48. package/dist/boot/resolve-spec.js +36 -29
  49. package/dist/boot/runner-deps.d.ts +11 -11
  50. package/dist/boot/runner-deps.js +7 -4
  51. package/dist/boot/session-faces.d.ts +3 -3
  52. package/dist/boot/session-faces.js +11 -30
  53. package/dist/boot/shutdown.d.ts +5 -5
  54. package/dist/boot/side-query-lane.d.ts +2 -2
  55. package/dist/boot/stage-04-stores.d.ts +1 -1
  56. package/dist/boot/stage-05-execution-env.d.ts +1 -1
  57. package/dist/boot/stage-05-execution-env.js +4 -4
  58. package/dist/boot/stage-06-runners.d.ts +1 -1
  59. package/dist/boot/stage-06-runners.js +0 -2
  60. package/dist/boot/stage-07-capability-layer.d.ts +1 -1
  61. package/dist/boot/stage-08-reapers.d.ts +1 -1
  62. package/dist/boot/stage-09-leader.d.ts +1 -1
  63. package/dist/boot/stage-10-http-server.d.ts +1 -1
  64. package/dist/boot/stores.js +4 -4
  65. package/dist/boot/web-admin.d.ts +17 -17
  66. package/dist/boot/web-admin.js +15 -27
  67. package/dist/boot/workflow-orchestration.js +2 -9
  68. package/dist/brain.d.ts +11 -11
  69. package/dist/brain.js +12 -3
  70. package/dist/budget.d.ts +7 -7
  71. package/dist/budget.js +4 -0
  72. package/dist/capabilities/approvals-push.d.ts +4 -4
  73. package/dist/capabilities/builtin-tools.d.ts +5 -5
  74. package/dist/capabilities/center-plugins.d.ts +5 -5
  75. package/dist/capabilities/center-plugins.js +1 -1
  76. package/dist/capabilities/center-prompts.d.ts +1 -1
  77. package/dist/capabilities/center-wiring.d.ts +1 -1
  78. package/dist/capabilities/composite-members.d.ts +1 -1
  79. package/dist/capabilities/execution-lane.d.ts +5 -5
  80. package/dist/capabilities/execution-lane.js +2 -2
  81. package/dist/capabilities/hands-lane.d.ts +5 -5
  82. package/dist/capabilities/mcp-probe.d.ts +11 -7
  83. package/dist/capabilities/sandbox-file-send.d.ts +1 -18
  84. package/dist/capabilities/sandbox-file-send.js +0 -7
  85. package/dist/capabilities/scenarios.d.ts +28 -10
  86. package/dist/capabilities/scenarios.js +15 -5
  87. package/dist/capabilities/send-user-file-tool.d.ts +1 -1
  88. package/dist/capabilities/skills.d.ts +31 -12
  89. package/dist/capabilities/skills.js +23 -17
  90. package/dist/capabilities/tool-defer.d.ts +1 -1
  91. package/dist/capability-facts.d.ts +29 -32
  92. package/dist/capability-facts.js +17 -21
  93. package/dist/center-config-tier.d.ts +1 -1
  94. package/dist/center-credential.d.ts +22 -8
  95. package/dist/center-credential.js +18 -3
  96. package/dist/checkpoint-identity.d.ts +5 -0
  97. package/dist/checkpoint-identity.js +14 -0
  98. package/dist/config-catalog.d.ts +12 -12
  99. package/dist/config-catalog.js +12 -10
  100. package/dist/config-d-migration.js +1 -1
  101. package/dist/config-invariants.d.ts +5 -5
  102. package/dist/config-invariants.js +11 -2
  103. package/dist/config-lkg.d.ts +1 -39
  104. package/dist/config-lkg.js +1 -83
  105. package/dist/config-provider.d.ts +13 -13
  106. package/dist/config-provider.js +2 -1
  107. package/dist/config-types.d.ts +95 -87
  108. package/dist/config.d.ts +26 -24
  109. package/dist/config.js +38 -18
  110. package/dist/cross-session-settings.d.ts +1 -1
  111. package/dist/delegated-session-owner.d.ts +16 -13
  112. package/dist/delegated-session-owner.js +9 -10
  113. package/dist/deployment-governance.d.ts +16 -16
  114. package/dist/deployment-shape.d.ts +127 -0
  115. package/dist/deployment-shape.js +72 -0
  116. package/dist/device-store.d.ts +1 -1
  117. package/dist/device-ws-hub.d.ts +1 -1
  118. package/dist/egress-redirect.d.ts +1 -1
  119. package/dist/elicitation.d.ts +8 -7
  120. package/dist/elicitation.js +9 -8
  121. package/dist/entry-mode-clamp-notice.d.ts +2 -2
  122. package/dist/env-facts.d.ts +10 -9
  123. package/dist/env-facts.js +1 -1
  124. package/dist/env-name-allowlist-knobs.d.ts +5 -5
  125. package/dist/exec-bounds.d.ts +2 -2
  126. package/dist/execution-lane-caps.d.ts +31 -43
  127. package/dist/execution-lane-caps.js +0 -13
  128. package/dist/file-history-capture.d.ts +9 -9
  129. package/dist/file-history-disclosure.d.ts +25 -11
  130. package/dist/file-history-disclosure.js +25 -14
  131. package/dist/fleet/drain-entry.d.ts +2 -2
  132. package/dist/fleet/fleet-bus.d.ts +22 -14
  133. package/dist/fleet/fleet-bus.js +5 -5
  134. package/dist/fleet/fleet-reconciler.d.ts +9 -9
  135. package/dist/fleet/subagent-tail-bus.d.ts +4 -4
  136. package/dist/fleet-client.d.ts +45 -14
  137. package/dist/fleet-client.js +24 -4
  138. package/dist/fleet-lease.d.ts +23 -19
  139. package/dist/fleet-lease.js +31 -23
  140. package/dist/governance-http-status.d.ts +2 -2
  141. package/dist/hooks/hook-llm.d.ts +7 -7
  142. package/dist/hooks/hook-llm.js +14 -8
  143. package/dist/hooks/hook-runner.d.ts +58 -31
  144. package/dist/hooks/hook-runner.js +37 -19
  145. package/dist/host-decision.d.ts +5 -5
  146. package/dist/host-lsp-manager.d.ts +5 -5
  147. package/dist/hosted-posture.d.ts +23 -13
  148. package/dist/hosted-posture.js +4 -9
  149. package/dist/http/admission.d.ts +2 -2
  150. package/dist/http/admission.js +20 -5
  151. package/dist/http/approval-sweeps.d.ts +1 -1
  152. package/dist/http/approval-sweeps.js +2 -1
  153. package/dist/http/checkpoint-ctx.d.ts +62 -17
  154. package/dist/http/checkpoint-ctx.js +78 -35
  155. package/dist/http/dispatch.d.ts +3 -3
  156. package/dist/http/dispatch.js +9 -9
  157. package/dist/http/durable-run-leg.js +4 -3
  158. package/dist/http/idempotency.d.ts +2 -2
  159. package/dist/http/mcp-dial-deadline.d.ts +7 -5
  160. package/dist/http/memory-compliance-failure-reply.d.ts +4 -4
  161. package/dist/http/owner-access.d.ts +4 -6
  162. package/dist/http/owner-access.js +1 -1
  163. package/dist/http/principal-gate.d.ts +7 -7
  164. package/dist/http/principal-gate.js +3 -2
  165. package/dist/http/readiness.d.ts +1 -1
  166. package/dist/http/request-guards.d.ts +4 -4
  167. package/dist/http/request-guards.js +2 -1
  168. package/dist/http/resume-ctx-read.d.ts +9 -23
  169. package/dist/http/resume-ctx-read.js +2 -3
  170. package/dist/http/resume-legs.d.ts +3 -3
  171. package/dist/http/resume-legs.js +11 -8
  172. package/dist/http/route-ctx.d.ts +29 -29
  173. package/dist/http/route-table.d.ts +9 -9
  174. package/dist/http/routes/agents-roster.d.ts +1 -1
  175. package/dist/http/routes/approvals-assistant.d.ts +5 -7
  176. package/dist/http/routes/approvals-assistant.js +101 -26
  177. package/dist/http/routes/background.d.ts +3 -3
  178. package/dist/http/routes/background.js +2 -2
  179. package/dist/http/routes/capabilities.d.ts +1 -1
  180. package/dist/http/routes/capabilities.js +16 -8
  181. package/dist/http/routes/config-catalog.d.ts +1 -1
  182. package/dist/http/routes/devices.d.ts +1 -1
  183. package/dist/http/routes/diagnostics.d.ts +3 -3
  184. package/dist/http/routes/fleet.d.ts +1 -1
  185. package/dist/http/routes/fleet.js +2 -1
  186. package/dist/http/routes/mcp-reconnect.d.ts +4 -4
  187. package/dist/http/routes/mcp-reconnect.js +3 -3
  188. package/dist/http/routes/memory-consolidation.d.ts +1 -1
  189. package/dist/http/routes/notify-wake.d.ts +1 -1
  190. package/dist/http/routes/notify-wake.js +2 -2
  191. package/dist/http/routes/rules.d.ts +1 -1
  192. package/dist/http/routes/runs.js +23 -11
  193. package/dist/http/routes/session-sync.d.ts +1 -1
  194. package/dist/http/routes/session-sync.js +97 -46
  195. package/dist/http/routes/sessions-list.js +1 -1
  196. package/dist/http/routes/sessions.js +43 -53
  197. package/dist/http/routes/tasks.d.ts +1 -1
  198. package/dist/http/routes/trace-usage.d.ts +1 -1
  199. package/dist/http/routes/workflows.d.ts +3 -0
  200. package/dist/http/routes/workflows.js +31 -28
  201. package/dist/http/send.d.ts +5 -5
  202. package/dist/http/server.d.ts +34 -34
  203. package/dist/http/session-inherit-env.d.ts +3 -3
  204. package/dist/http/sse-lifecycle.d.ts +1 -1
  205. package/dist/http/sse-log.d.ts +2 -2
  206. package/dist/http/submit-ctx.js +1 -1
  207. package/dist/http/sync-submit-body.d.ts +1 -1
  208. package/dist/http/verify-rounds.d.ts +1 -1
  209. package/dist/http/wire-types.d.ts +33 -24
  210. package/dist/index.d.ts +1 -0
  211. package/dist/index.js +1 -0
  212. package/dist/instruction-source-notice.d.ts +2 -2
  213. package/dist/key-resolver.d.ts +3 -3
  214. package/dist/lane-home-probe.d.ts +1 -1
  215. package/dist/leader/diffout.d.ts +1 -1
  216. package/dist/leader/diffup.d.ts +2 -2
  217. package/dist/leader/endpoint.d.ts +1 -1
  218. package/dist/leader/fanout.d.ts +1 -1
  219. package/dist/leader/leader.d.ts +4 -4
  220. package/dist/leader/merge.d.ts +3 -3
  221. package/dist/leader/repair-wire.d.ts +1 -1
  222. package/dist/leader/wire.d.ts +6 -6
  223. package/dist/list-entry-display.d.ts +1 -1
  224. package/dist/lsp-evict.d.ts +1 -1
  225. package/dist/mcp-assertion-header.d.ts +1 -1
  226. package/dist/memory-layer-legacy-lock.d.ts +1 -1
  227. package/dist/memory-operator-faces.d.ts +1 -1
  228. package/dist/memory-posture.js +4 -2
  229. package/dist/memory-project-layer.d.ts +1 -1
  230. package/dist/memory-scope.d.ts +19 -19
  231. package/dist/memory-store-refusal.d.ts +4 -4
  232. package/dist/model-entry-headers.d.ts +2 -2
  233. package/dist/model-entry-refusal.d.ts +17 -17
  234. package/dist/model-provider.d.ts +10 -10
  235. package/dist/model-reach-scope.d.ts +1 -1
  236. package/dist/model-route-endpoint.d.ts +6 -6
  237. package/dist/model-route-gap.d.ts +49 -4
  238. package/dist/model-route-gap.js +34 -1
  239. package/dist/model-route-url.d.ts +5 -5
  240. package/dist/model-select.d.ts +15 -6
  241. package/dist/model-select.js +5 -0
  242. package/dist/model-unreachable-notice.d.ts +3 -3
  243. package/dist/namespaced-rule-name.d.ts +15 -5
  244. package/dist/namespaced-rule-name.js +3 -2
  245. package/dist/object-store-buckets.d.ts +13 -0
  246. package/dist/object-store-buckets.js +3 -0
  247. package/dist/observability/corrupt-read-seat.d.ts +9 -9
  248. package/dist/observability/cost-taxonomy.d.ts +1 -1
  249. package/dist/observability/err-text.d.ts +1 -1
  250. package/dist/observability/fail-open.d.ts +17 -13
  251. package/dist/observability/fail-open.js +17 -13
  252. package/dist/observability/metrics.d.ts +3 -3
  253. package/dist/observability/metrics.js +1 -1
  254. package/dist/observability/principal-context.d.ts +4 -1
  255. package/dist/observability/principal-context.js +6 -1
  256. package/dist/observability/run-terminal.d.ts +36 -36
  257. package/dist/observability/secret-env-scrub.d.ts +3 -3
  258. package/dist/observability/tool-trace.d.ts +1 -1
  259. package/dist/operator-ask.d.ts +4 -4
  260. package/dist/orchestration/workflow-agent-session-index.d.ts +3 -3
  261. package/dist/orchestration/workflow-completion-inbox.d.ts +20 -5
  262. package/dist/orchestration/workflow-completion-inbox.js +29 -7
  263. package/dist/orchestration/workflow-notify-journal.d.ts +43 -19
  264. package/dist/orchestration/workflow-notify-journal.js +17 -0
  265. package/dist/outbound-dispatcher.d.ts +4 -4
  266. package/dist/parent-watch.d.ts +4 -4
  267. package/dist/parked-decide.d.ts +20 -18
  268. package/dist/parked-decide.js +31 -11
  269. package/dist/parked-revive-surface.d.ts +7 -7
  270. package/dist/parked-revive-surface.js +2 -3
  271. package/dist/peer-directory.d.ts +5 -4
  272. package/dist/peer-directory.js +6 -6
  273. package/dist/permission-rule-list.d.ts +10 -1
  274. package/dist/permission-rule-list.js +7 -5
  275. package/dist/permission-rule-vocab.d.ts +2 -2
  276. package/dist/plugins/adoption-log-sql.d.ts +1 -1
  277. package/dist/plugins/approval-ask-store-file.d.ts +8 -1
  278. package/dist/plugins/approval-ask-store-file.js +6 -3
  279. package/dist/plugins/approval-ask-store-memory.d.ts +11 -7
  280. package/dist/plugins/approval-ask-store-memory.js +11 -7
  281. package/dist/plugins/approval-ask-store-sql.d.ts +42 -15
  282. package/dist/plugins/approval-ask-store-sql.js +21 -5
  283. package/dist/plugins/approval-exemption-store.d.ts +3 -3
  284. package/dist/plugins/approval-nonce-store.d.ts +3 -3
  285. package/dist/plugins/background-agent-store-sql.d.ts +1 -1
  286. package/dist/plugins/background-shell-support.d.ts +2 -2
  287. package/dist/plugins/blob-backend.d.ts +1 -1
  288. package/dist/plugins/blob-backend.js +2 -1
  289. package/dist/plugins/caching-session-store.d.ts +23 -32
  290. package/dist/plugins/caching-session-store.js +5 -17
  291. package/dist/plugins/checkpoint-index-columns.d.ts +130 -0
  292. package/dist/plugins/checkpoint-index-columns.js +90 -0
  293. package/dist/plugins/checkpoint-store-sql.d.ts +71 -69
  294. package/dist/plugins/checkpoint-store-sql.js +109 -127
  295. package/dist/plugins/device-store-sql.d.ts +7 -6
  296. package/dist/plugins/e2b-orphan-reclaim.d.ts +1 -1
  297. package/dist/plugins/ensure-schema-lock-policy.d.ts +1 -1
  298. package/dist/plugins/file-history-store-sql.d.ts +15 -7
  299. package/dist/plugins/file-history-store-sql.js +55 -36
  300. package/dist/plugins/file-run-store.d.ts +8 -8
  301. package/dist/plugins/fork-routing-session-store.d.ts +2 -2
  302. package/dist/plugins/fork-routing-session-store.js +1 -1
  303. package/dist/plugins/host-platform.d.ts +10 -10
  304. package/dist/plugins/image-bake-store-sql.d.ts +1 -1
  305. package/dist/plugins/image-index-sql.d.ts +1 -1
  306. package/dist/plugins/leader-run-store-sql.d.ts +1 -1
  307. package/dist/plugins/local-checkpoint-store.d.ts +10 -10
  308. package/dist/plugins/local-checkpoint-store.js +7 -7
  309. package/dist/plugins/local-session-store.d.ts +34 -38
  310. package/dist/plugins/local-session-store.js +20 -39
  311. package/dist/plugins/local-session-window.d.ts +1 -1
  312. package/dist/plugins/mailbox-store-sql.d.ts +2 -2
  313. package/dist/plugins/memory-engine-pg.d.ts +1 -1
  314. package/dist/plugins/memory-run-store.d.ts +4 -4
  315. package/dist/plugins/memory-sync-store-pg.d.ts +3 -3
  316. package/dist/plugins/one-time-migrations.d.ts +73 -54
  317. package/dist/plugins/one-time-migrations.js +131 -134
  318. package/dist/plugins/outcome-ledger-sql.d.ts +1 -1
  319. package/dist/plugins/park-commit-watch.d.ts +3 -3
  320. package/dist/plugins/permission-rule-store-file.d.ts +5 -5
  321. package/dist/plugins/permission-rule-store-file.js +12 -19
  322. package/dist/plugins/permission-rule-store-sql.d.ts +38 -4
  323. package/dist/plugins/permission-rule-store-sql.js +67 -24
  324. package/dist/plugins/pg-cost-quota.d.ts +1 -1
  325. package/dist/plugins/pg-pool.d.ts +2 -2
  326. package/dist/plugins/pg-pool.js +5 -2
  327. package/dist/plugins/pg-rate-limiter.d.ts +1 -1
  328. package/dist/plugins/pg-session-storage.d.ts +8 -20
  329. package/dist/plugins/pg-session-storage.js +14 -27
  330. package/dist/plugins/remote-env-adb.d.ts +10 -10
  331. package/dist/plugins/remote-env-device.d.ts +10 -9
  332. package/dist/plugins/remote-env-device.js +6 -2
  333. package/dist/plugins/remote-env-e2b.d.ts +3 -3
  334. package/dist/plugins/remote-env-host.d.ts +16 -16
  335. package/dist/plugins/remote-env-k8s.d.ts +26 -13
  336. package/dist/plugins/remote-env-k8s.js +24 -7
  337. package/dist/plugins/remote-env-local-docker.d.ts +2 -2
  338. package/dist/plugins/remote-env-ssh.d.ts +4 -4
  339. package/dist/plugins/remote-scratchpad.d.ts +2 -3
  340. package/dist/plugins/remote-scratchpad.js +0 -4
  341. package/dist/plugins/remote-shell.d.ts +6 -6
  342. package/dist/plugins/retention-lane-store-sql.d.ts +4 -4
  343. package/dist/plugins/retention-store-sql.d.ts +4 -4
  344. package/dist/plugins/roster-store-sql.d.ts +1 -1
  345. package/dist/plugins/run-store-sql.d.ts +8 -8
  346. package/dist/plugins/s3-answer.d.ts +15 -0
  347. package/dist/plugins/s3-answer.js +5 -0
  348. package/dist/plugins/schema-consistency.d.ts +2 -2
  349. package/dist/plugins/schema-ensure-legs.d.ts +3 -3
  350. package/dist/plugins/schema-indexes.d.ts +1 -1
  351. package/dist/plugins/schema-live-columns.d.ts +1 -1
  352. package/dist/plugins/session-event-payload.d.ts +4 -4
  353. package/dist/plugins/session-fork.d.ts +34 -0
  354. package/dist/plugins/session-fork.js +29 -0
  355. package/dist/plugins/session-ownership.js +1 -1
  356. package/dist/plugins/session-placement.d.ts +1 -1
  357. package/dist/plugins/session-policy-store-sql.d.ts +12 -12
  358. package/dist/plugins/session-store.d.ts +2 -2
  359. package/dist/plugins/session-store.js +2 -2
  360. package/dist/plugins/shared-memory-store-sql.d.ts +2 -2
  361. package/dist/plugins/snapshot-bucket-presence.d.ts +39 -4
  362. package/dist/plugins/snapshot-bucket-presence.js +35 -7
  363. package/dist/plugins/sql-driver.d.ts +8 -8
  364. package/dist/plugins/sql-errors.d.ts +40 -1
  365. package/dist/plugins/sql-errors.js +49 -1
  366. package/dist/plugins/sql-json-column.d.ts +21 -21
  367. package/dist/plugins/sql-row-helpers.d.ts +2 -2
  368. package/dist/plugins/store-backend.d.ts +17 -16
  369. package/dist/plugins/store-backend.js +3 -3
  370. package/dist/plugins/store-contracts.d.ts +21 -21
  371. package/dist/plugins/store-fault.d.ts +4 -0
  372. package/dist/plugins/store-fault.js +8 -0
  373. package/dist/plugins/task-attachment-store.d.ts +2 -2
  374. package/dist/plugins/task-list-store-sql.d.ts +1 -1
  375. package/dist/plugins/tidb-pool.d.ts +2 -2
  376. package/dist/plugins/tidb-pool.js +10 -3
  377. package/dist/plugins/tidb-session-store.d.ts +16 -26
  378. package/dist/plugins/tidb-session-store.js +15 -27
  379. package/dist/plugins/tool-result-store-sql.d.ts +1 -1
  380. package/dist/plugins/usage-window-store-sql.d.ts +3 -3
  381. package/dist/plugins/user-input-ledger-file.d.ts +1 -1
  382. package/dist/plugins/user-input-ledger-sql.d.ts +3 -3
  383. package/dist/plugins/web-search.d.ts +19 -5
  384. package/dist/plugins/web-search.js +20 -5
  385. package/dist/{orchestration/workflow-journal-entry.d.ts → plugins/workflow-journal-payload.d.ts} +23 -32
  386. package/dist/plugins/workflow-journal-payload.js +32 -0
  387. package/dist/plugins/workflow-journal-store-sql.d.ts +28 -14
  388. package/dist/plugins/workflow-journal-store-sql.js +34 -15
  389. package/dist/plugins/workflow-run-store-sql.d.ts +4 -4
  390. package/dist/posture-source.d.ts +11 -11
  391. package/dist/principal-jwt.d.ts +6 -6
  392. package/dist/project-identity.d.ts +3 -3
  393. package/dist/project-memory.d.ts +4 -4
  394. package/dist/read-face-posture.d.ts +7 -7
  395. package/dist/request-declaration-refusal.d.ts +94 -0
  396. package/dist/request-declaration-refusal.js +78 -0
  397. package/dist/request-image-urls.d.ts +6 -0
  398. package/dist/request-image-urls.js +27 -0
  399. package/dist/request-key-closure.d.ts +6 -1
  400. package/dist/request-key-closure.js +5 -2
  401. package/dist/request-value-closure.d.ts +15 -8
  402. package/dist/request-value-closure.js +2 -0
  403. package/dist/router/route-orchestration.d.ts +11 -16
  404. package/dist/router/route-orchestration.js +2 -12
  405. package/dist/rule-entry-list.d.ts +8 -7
  406. package/dist/rule-entry-list.js +2 -9
  407. package/dist/rules-consent.d.ts +6 -6
  408. package/dist/rules-consent.js +2 -0
  409. package/dist/run-cancel-context.d.ts +5 -5
  410. package/dist/run-local.d.ts +10 -10
  411. package/dist/runs.d.ts +13 -11
  412. package/dist/runs.js +15 -1
  413. package/dist/runtime-caps-resolver.d.ts +6 -6
  414. package/dist/runtime-caps-resolver.js +1 -1
  415. package/dist/runtime-governance.d.ts +9 -9
  416. package/dist/sandbox-pkg-source.d.ts +17 -12
  417. package/dist/sandbox-pkg-source.js +14 -9
  418. package/dist/sealed-key.d.ts +22 -3
  419. package/dist/sealed-key.js +47 -4
  420. package/dist/security.d.ts +23 -26
  421. package/dist/security.js +12 -9
  422. package/dist/server-secret-env.d.ts +10 -10
  423. package/dist/session-children-retire.d.ts +1 -1
  424. package/dist/session-error-wire.d.ts +7 -7
  425. package/dist/session-incarnation.d.ts +65 -37
  426. package/dist/session-incarnation.js +30 -12
  427. package/dist/session-policy-wire.d.ts +27 -5
  428. package/dist/session-policy-wire.js +15 -1
  429. package/dist/session-records-skipped-notice.d.ts +1 -1
  430. package/dist/session-row.d.ts +3 -17
  431. package/dist/session-row.js +4 -0
  432. package/dist/session-sync-kernel.d.ts +4 -4
  433. package/dist/session-sync.d.ts +61 -6
  434. package/dist/session-sync.js +55 -10
  435. package/dist/session-titler.d.ts +7 -6
  436. package/dist/session-titler.js +8 -13
  437. package/dist/session-watch.d.ts +3 -3
  438. package/dist/session-watch.js +4 -4
  439. package/dist/sighup-idle.d.ts +2 -2
  440. package/dist/spec-fields.d.ts +4 -4
  441. package/dist/sql-engine-posture.d.ts +3 -3
  442. package/dist/store-posture.d.ts +2 -2
  443. package/dist/stored-request-tool-axes-m19.d.ts +1 -1
  444. package/dist/task-a2a.d.ts +52 -79
  445. package/dist/task-a2a.js +224 -62
  446. package/dist/task-cwd.d.ts +7 -88
  447. package/dist/task-cwd.js +2 -15
  448. package/dist/task-mcp.d.ts +13 -17
  449. package/dist/task-mcp.js +29 -49
  450. package/dist/task-settings.d.ts +30 -18
  451. package/dist/task-settings.js +33 -3
  452. package/dist/task-workflow.d.ts +0 -24
  453. package/dist/task-workflow.js +2 -1
  454. package/dist/terminal.d.ts +5 -5
  455. package/dist/tighten-only-seats.d.ts +7 -6
  456. package/dist/tighten-only-seats.js +1 -1
  457. package/dist/tool-approval.d.ts +166 -207
  458. package/dist/tool-approval.js +61 -61
  459. package/dist/tool-rule-names.d.ts +2 -2
  460. package/dist/trace/core-keyset-guard.d.ts +13 -8
  461. package/dist/trace/engine-notice-wire.d.ts +5 -5
  462. package/dist/trace/engine-notice-wire.js +1 -0
  463. package/dist/trace/exit-seat.d.ts +31 -4
  464. package/dist/trace/exit-seat.js +69 -67
  465. package/dist/trace/ledger-events.d.ts +3 -3
  466. package/dist/trace/ledger-sink.d.ts +1 -1
  467. package/dist/trace/model-segment.d.ts +3 -3
  468. package/dist/trace/project.d.ts +47 -45
  469. package/dist/trace/project.js +33 -1
  470. package/dist/trace/redact.d.ts +61 -31
  471. package/dist/trace/redact.js +394 -153
  472. package/dist/trace/self-minted-wire.d.ts +302 -14
  473. package/dist/trace/self-minted-wire.js +87 -0
  474. package/dist/trace/sema-provenance.d.ts +1 -1
  475. package/dist/trace/task-notification-facets.d.ts +4 -4
  476. package/dist/trace/wire-projection-faces.d.ts +3 -3
  477. package/dist/trace/wire-projection-faces.js +1 -1
  478. package/dist/unattended-permission-mode.d.ts +5 -5
  479. package/dist/url-credential-refusal.d.ts +52 -0
  480. package/dist/url-credential-refusal.js +14 -0
  481. package/dist/url-refusal.d.ts +16 -3
  482. package/dist/url-refusal.js +15 -2
  483. package/dist/usage-analytics.d.ts +2 -2
  484. package/dist/user-input-ledger.d.ts +23 -23
  485. package/dist/web-admin-client/apply-effective.d.ts +5 -5
  486. package/dist/web-admin-client/apply-effective.js +2 -1
  487. package/dist/web-admin-client/apply-ledger.d.ts +2 -2
  488. package/dist/web-admin-client/center-request.d.ts +2 -2
  489. package/dist/web-admin-client/facade.d.ts +5 -5
  490. package/dist/web-admin-client/facade.js +1 -1
  491. package/dist/web-admin-client/hot-keys-registry.d.ts +2 -2
  492. package/dist/web-admin-client/http-client.d.ts +4 -4
  493. package/dist/web-admin-client/mcp-revocation.d.ts +1 -1
  494. package/dist/web-admin-client/pull-state.d.ts +1 -1
  495. package/dist/web-admin-client/read-face.d.ts +2 -2
  496. package/dist/web-admin-client/read-warnings.d.ts +5 -5
  497. package/dist/web-admin-client/restart-signal.d.ts +6 -6
  498. package/dist/web-admin-client/skills-mcp.d.ts +28 -3
  499. package/dist/web-admin-client/skills-mcp.js +29 -1
  500. package/dist/web-admin-client/types.d.ts +16 -9
  501. package/dist/workspace-space.d.ts +32 -3
  502. package/dist/workspace-space.js +26 -0
  503. package/dist/write-protection.d.ts +2 -2
  504. package/package.json +5 -3
  505. package/scripts/drain-check-local.mjs +4 -2
  506. package/scripts/drain-check.mysql.sql +6 -2
  507. package/scripts/drain-check.pg.sql +6 -2
  508. package/skills/loop.md +1 -1
  509. package/skills/schedule.md +1 -1
  510. package/wire-changes/server@7.104.0.json +134 -0
  511. package/wire-changes/server@7.105.0.json +53 -0
  512. package/wire-changes/server@7.106.0.json +475 -0
  513. package/wire-changes/server@7.107.0.json +64 -0
  514. package/wire-changes/server@7.108.0.json +153 -0
  515. package/wire-changes/server@7.109.0.json +46 -0
  516. package/wire-changes/server@7.110.0.json +90 -0
  517. package/wire-changes/server@7.111.0.json +86 -0
  518. package/wire-changes/server@7.112.0.json +60 -0
  519. package/wire-changes/server@7.113.0.json +26 -0
  520. package/wire-changes/server@7.114.0.json +26 -0
  521. package/wire-changes/server@7.115.0.json +97 -0
  522. package/wire-changes/server@7.116.0.json +218 -0
  523. package/wire-changes/server@7.116.1.json +26 -0
  524. package/wire-changes/server@7.117.0.json +65 -0
  525. package/wire-changes/server@7.118.0.json +129 -0
  526. package/wire-changes/server@7.119.0.json +65 -0
  527. package/wire-changes/server@7.120.0.json +89 -0
  528. package/wire-changes/server@7.121.0.json +219 -0
  529. package/wire-changes/server@7.122.0.json +54 -0
  530. package/wire-changes/server@7.123.0.json +26 -0
  531. package/wire-changes/server@7.124.0.json +336 -0
  532. package/wire-changes/server@7.124.1.json +26 -0
  533. package/wire-changes/server@7.125.0.json +111 -0
  534. package/wire-changes/server@7.126.0.json +285 -0
  535. package/wire-changes/server@7.127.0.json +77 -0
  536. package/wire-changes/server@7.127.1.json +26 -0
  537. package/wire-changes/server@7.127.2.json +53 -0
  538. package/wire-changes/server@7.128.0.json +26 -0
  539. package/wire-changes/server@7.129.0.json +106 -0
  540. package/wire-changes/server@7.129.1.json +26 -0
  541. package/wire-changes/server@7.130.0.json +26 -0
  542. package/wire-changes/server@7.131.0.json +118 -0
  543. package/wire-changes/server@7.132.0.json +226 -0
  544. package/wire-changes/server@7.133.0.json +1155 -0
  545. package/wire-changes/server@7.134.0.json +107 -0
  546. package/wire-changes/server@7.135.0.json +174 -0
  547. package/wire-changes/server@7.136.0.json +448 -0
  548. package/dist/http/run-declared-families.d.ts +0 -16
  549. package/dist/http/run-declared-families.js +0 -12
  550. package/dist/orchestration/workflow-journal-entry.js +0 -27
@@ -33,9 +33,9 @@
33
33
  * 「**静默满一个对账周期**」(本腿订阅总线自记每行的最后帧时刻):还在出帧 = 活着的证据。
34
34
  * durable 行**在场**的那三格没有这个歧义(`getRun` 命中 = 它就是一条 run 行),故照矩阵即时处置。
35
35
  *
36
- * ## 子代行(§1;🔴 S-751 起改为「活性由属主说了算」)
36
+ * ## 子代行(§1;🔴 [ref] 起改为「活性由属主说了算」)
37
37
  * 子代行**不读 durable run 店**(它不是 run 行)。它的活性属主有两只,都在本仓可读 —— 读它们**不是**越界重判,
38
- * 是问属主(S-751 之前此处写「bg 子代的 durable 真源在 core 侧 registry,server 不越界重判」,于是判据里只剩
38
+ * 是问属主([ref] 之前此处写「bg 子代的 durable 真源在 core 侧 registry,server 不越界重判」,于是判据里只剩
39
39
  * 「静默」这一条,而 registry 的读半场 `RunnerDeps.backgroundAgentStore` 一直就在本仓):
40
40
  * ① core bg registry(`BackgroundAgentStore` 行 `status` 非终态 = `running` / `parked`);
41
41
  * ② 本副本审批面的待决卡(子代发起、没人答的 ask —— 子代卡在那儿,当然不出帧)。
@@ -49,7 +49,7 @@
49
49
  * 只做同款「durable 终局投影」([ref] 的 snapshot pull 腿 + reapers 的 workflow recover 腿已在场),
50
50
  * **不加新判据**:活行恒不动,没有陈述级退场这一形。
51
51
  *
52
- * ## 🔴 S-450:候补窗的升级**由事实驱动**,周期臂降为兜底
52
+ * ## 🔴 [ref]:候补窗的升级**由事实驱动**,周期臂降为兜底
53
53
  * 陈述级退场(`orphanExit`)恒不造终态、行进候补窗;把它升级成真终局此前**只**发生在下一个对账周期的
54
54
  * ① 臂 ⇒ 成对终帧最晚 {@link FLEET_RECONCILE_INTERVAL_MS} + 预算抖动才到面板,而消费方
55
55
  * (`@sema-agent/client-core` 的面板投影)对「行缺席」按 30s 结算 —— 两侧各自正确,合成的是「面板先结算
@@ -118,7 +118,7 @@ export interface FleetReconcileRunPort {
118
118
  export interface FleetReconcileWorkflowPort {
119
119
  get(id: string): Promise<WorkflowRun | null | undefined>;
120
120
  }
121
- /** S-751:core bg registry 账(`BackgroundAgentStore`)的只读窄口 —— 与 {@link FleetReconcileRunPort} 同一条
121
+ /** [ref]:core bg registry 账(`BackgroundAgentStore`)的只读窄口 —— 与 {@link FleetReconcileRunPort} 同一条
122
122
  * 单写者纪律(接口上没有写方法)。生产 = `RunnerDeps.backgroundAgentStore` **同实例**(结构上就是它的 `get`
123
123
  * 一面);`null` = 账上没有这一行。 */
124
124
  export interface FleetReconcileAgentPort {
@@ -133,7 +133,7 @@ export interface FleetReconcilerDeps {
133
133
  */
134
134
  isLiveOnThisReplica: (taskId: string) => boolean;
135
135
  /**
136
- * S-450 测试缝:「run 行 CAS 赢了翻终局」的订阅口。**生产恒缺席** —— 缺席时本腿自己去
136
+ * [ref] 测试缝:「run 行 CAS 赢了翻终局」的订阅口。**生产恒缺席** —— 缺席时本腿自己去
137
137
  * `observability/run-terminal.ts` 的**唯一铸点**登记(那口是进程级的自由函数,与 `recordFailOpen`
138
138
  * 同姿势:真正的铸点在没有任何句柄的深处)。给它一个注入形只是为了让用例能在一台假铸点上跑。
139
139
  *
@@ -143,10 +143,10 @@ export interface FleetReconcilerDeps {
143
143
  subscribeRunTerminal?: (fn: (rec: RunTerminalRecord) => void) => () => void;
144
144
  runs?: FleetReconcileRunPort;
145
145
  workflows?: FleetReconcileWorkflowPort | WorkflowRunStore;
146
- /** S-751:子代活性的属主①(bg registry 账)。缺席 = 没有 bg 店的部署(纯内存 dev),这一问问不了。 */
146
+ /** [ref]:子代活性的属主①(bg registry 账)。缺席 = 没有 bg 店的部署(纯内存 dev),这一问问不了。 */
147
147
  agents?: FleetReconcileAgentPort;
148
148
  /**
149
- * S-751:子代活性的属主②:这只子代此刻有没有**待决**审批卡。只问是非(与 {@link isLiveOnThisReplica} 同姿势,
149
+ * [ref]:子代活性的属主②:这只子代此刻有没有**待决**审批卡。只问是非(与 {@link isLiveOnThisReplica} 同姿势,
150
150
  * 不搬 Map)。入参是 ask 发起者域(子代自己的 core session id,= 卡上的 `originTaskId`),**不是**行 id ——
151
151
  * 行 id → 该域的换算只在 `FleetEventBus.childOwnerKeys`。生产 = `ToolApprovalCoordinator.hasLivePendingFrom`。
152
152
  */
@@ -171,9 +171,9 @@ export interface FleetReconcileTally {
171
171
  retired: number;
172
172
  /** 陈述级退场的行数(顶层 + 孤儿子行)。 */
173
173
  orphaned: number;
174
- /** 父本周期刚离场、自己又判成孤儿而陈述级退场的子行数(S-751 前 = 随父无条件同扫的数)。 */
174
+ /** 父本周期刚离场、自己又判成孤儿而陈述级退场的子行数([ref] 前 = 随父无条件同扫的数)。 */
175
175
  childrenSwept: number;
176
- /** S-751:静默满一周期、无父可循(或 run 账不认识),但属主作保而**留行**的子行数。 */
176
+ /** [ref]:静默满一周期、无父可循(或 run 账不认识),但属主作保而**留行**的子行数。 */
177
177
  childrenKeptAlive: number;
178
178
  /** durable 终局 ⇒ 投影退休的 workflow 行数。 */
179
179
  workflowsRetired: number;
@@ -8,7 +8,7 @@ export type SubagentTailFrame = Record<string, unknown> & {
8
8
  };
9
9
  /** core forward 事件 → wire 投影(sync 主流五分支同源;不认识的帧类型=null 不发——tail 面只承诺
10
10
  * content 六类,新 core 帧类型先经这里显式收编再出 wire)。
11
- * ⚠️ **本函数是无状态逐帧投影**:`reasoning_end`(S-310 的推理权威段)不在这里 —— 它要按句柄攒段,
11
+ * ⚠️ **本函数是无状态逐帧投影**:`reasoning_end`([ref] 的推理权威段)不在这里 —— 它要按句柄攒段,
12
12
  * 住在 {@link SubagentTailBus.onForwardFrame}(publish 侧是唯一知道句柄的地方)。 */
13
13
  export declare function projectTailFrame(e: Record<string, unknown> & {
14
14
  type?: string;
@@ -53,7 +53,7 @@ export declare class SubagentTailBus {
53
53
  */
54
54
  private readonly modeByHandle;
55
55
  /**
56
- * 句柄 → 该句柄这条 tail 流上**在攒的推理段**(S-310)。
56
+ * 句柄 → 该句柄这条 tail 流上**在攒的推理段**([ref])。
57
57
  *
58
58
  * 键必须是句柄,理由与 {@link modeByHandle} 同源再加一条硬的:两个并发子代的 `reasoning_delta` 在
59
59
  * **同一个** forward sink 上交错到达,一只累积器会把两份思考拼成一段、再盖上其中一个的身份键。
@@ -67,10 +67,10 @@ export declare class SubagentTailBus {
67
67
  * 否则晚开的 tail 永远读不到供给形)。同值重复写是 no-op(热路径只付一次 Map.get)。 */
68
68
  noteHandleContentMode(bgAgentId: string, mode: TailContentMode): void;
69
69
  /**
70
- * 🔴 **三条 run 腿的 forward 回调唯一入口**(S-310 收口)——登记供给形 → 段界收段 → 逐帧投影 → publish。
70
+ * 🔴 **三条 run 腿的 forward 回调唯一入口**([ref] 收口)——登记供给形 → 段界收段 → 逐帧投影 → publish。
71
71
  *
72
72
  * 此前这四步以**同一段六行代码**抄在三条腿上(sync 流腿、verify-resume 腿、resume-stream 腿),
73
- * 差别为零;S-310 要给 tail 面补 `reasoning_end` 时,那就是第四、第五、第六份拷贝。收成一扇门之后
73
+ * 差别为零;[ref] 要给 tail 面补 `reasoning_end` 时,那就是第四、第五、第六份拷贝。收成一扇门之后
74
74
  * 腿上只剩「句柄在不在」这一句判断,三腿不可能再分家(`test/subagent-tail-stream.test.ts` G18-G20)。
75
75
  *
76
76
  * 顺序即语义:权威段**先于**触发它的结构帧上 wire(消费端「整段替换已攒 delta」的替换点不与卡片交错),
@@ -1,21 +1,21 @@
1
1
  /**
2
2
  * Fleet worker-side wiring(announce/heartbeat + usage 批报;契约 = registry-core 0.1.48+
3
3
  * `/fleet`,center 端点 = web-admin `/api/fleet/*`)。设计要点:
4
- * - **可选分层(D3),两条环各自有门(S-866 ④)**:客户端在中心车道配齐时启动(`centerLaneConfigured` —— baseUrl + 声明了
4
+ * - **可选分层(D3),两条环各自有门([ref] ④)**:客户端在中心车道配齐时启动(`centerLaneConfigured` —— baseUrl + 声明了
5
5
  * 凭证 + worker,与租约管理器、用量累加器**同一只**谓词);**用量环**只要这三件;**公告环**(announce / 心跳 / 注销)另要
6
6
  * 配置席 `fleetAdvertiseAddress`(env `FLEET_ADVERTISE_ADDRESS`,`loadConfig` 解析一次;可达性是运维的话,不自猜:k8s pod IP /
7
7
  * docker alias / 127.0.0.1:port 只有部署环境自己知道)。不配中心的部署零行为变化;配了中心而不公告的引擎只报用量、不注册(7.105.0 及以前它连用量都不报)。
8
8
  * - **announce=注册=心跳同形状幂等 upsert**:boot 后(listen 之后)POST 一次 + 每 heartbeatMs 续。
9
- * `ready` / `draining` 两字段由引擎信号铸点的同一次读铸(S-740:`ready` = `http/readiness.ts` `readinessOf` 的判,
9
+ * `ready` / `draining` 两字段由引擎信号铸点的同一次读铸([ref]:`ready` = `http/readiness.ts` `readinessOf` 的判,
10
10
  * 与 `/health.ready`、`GET /readyz`、计费提交门同源;= roster 已落 ∧ ¬draining),`draining` = 排空事实在场(与嵌套
11
11
  * `engineSignal.draining` 同一个字段,`fleet/engine-signal.ts` 规则 5)。修前 `ready = !isDraining()`,不含 roster ⇒ roster 未落时
12
12
  * 心跳说「就绪」而计费提交在 503。
13
13
  * - **`engineSignal`(7.123.0)**:引擎态整只(契约 `EngineSignal`),与扁平键同一次读数;契约包 10.x 的心跳形没有它的座位(10.x 中心
14
14
  * 默认 strip 解析丢掉它、照收心跳);扁平布尔 `draining` settings-schema 12.0.0 删、本引擎 7.124.0+ 删发。
15
- * - **`restart?`(S-741)**:在场 ⇔ 本副本必须重启才能应用配置 —— 取自 `/health.restart` **同一只**取值口(装配层接
15
+ * - **`restart?`([ref])**:在场 ⇔ 本副本必须重启才能应用配置 —— 取自 `/health.restart` **同一只**取值口(装配层接
16
16
  * `deployment.restartState`,web-admin 的 `restartState()`),同一个对象,形 = settings-schema `RestartSignal`;
17
17
  * 缺席即键缺席(中心按行整体替换,不合并 —— 一条不带它的心跳就是「不再需要」)。
18
- * - **`modelRefusals?`(S-768)**:在场 ⇔ 本副本对最近一次被判的中心候选目录有可报的拒(逐条名 → 码 / 模型面组拒码)—— 取自
18
+ * - **`modelRefusals?`([ref])**:在场 ⇔ 本副本对最近一次被判的中心候选目录有可报的拒(逐条名 → 码 / 模型面组拒码)—— 取自
19
19
  * `/health.modelRefusals` **同一只**取值口(装配层接 `deployment.modelRefusalsState`),同一个对象,形 = settings-schema
20
20
  * `ModelRefusalsSignal`;缺席即键缺席(同 `restart`)。
21
21
  * - **自报状态翻转即刻再 announce**(第一时间自摘流 / 自挂流 / 报重启 / 报拒因,比任何观测都快):draining 翻转由收尾链直调
@@ -25,11 +25,15 @@
25
25
  * 累计,每窗口(默认 60s,半开 [windowStartMs, windowEndMs))POST /api/fleet/usage。幂等键
26
26
  * (worker,instanceId,windowStartMs) 重发安全;**发送失败 → merge 回累计器**,并入下一窗(失败窗从未入账,
27
27
  * 向前合并不会双计 —— 只延迟,不丢量)。
28
+ * - **用量按中心凭证身份分箱([ref])**:累计器一个身份一只({@link createFleetUsageBins},分箱规则 = `createIdentityBins` 一只),
29
+ * tracer 记进记账身份那一箱(执行开始时钉下的身份;执行外 = 此刻身份);用量环只报此刻身份那一箱、经钉在它身份上的凭证发 —— 文件形凭证进程内换人后,上一个人窗里的用量
30
+ * 不在下一个人的凭证下上报(不记到别人头上);它留在原箱,那个身份回来时照常报出去,收尾时还压着就响亮一行。
28
31
  * - 全部 fire-and-forget + swallow-guarded:fleet 面是运维旁路,绝不影响任务面;网络错误只 warn 一次/连败类。
29
32
  */
30
33
  import { UsageReport, type CapabilityReading, type WebAdminCapabilities, type ModelRefusalsSignal } from "@sema-agent/settings-schema/fleet";
31
34
  import { type EngineSignalFacts } from "./fleet/engine-signal.js";
32
35
  import { type CenterEndpoint } from "./web-admin-client/center-request.js";
36
+ import { type CenterCredentialSource } from "./center-credential.js";
33
37
  /** Bound on distinct principal×model keys per window — a runaway/multi-tenant burst collapses into
34
38
  * `__other__` instead of growing unbounded (same posture as budget.ts cardinalityGuard). */
35
39
  export declare const FLEET_USAGE_KEY_CAP = 1024;
@@ -71,28 +75,55 @@ export declare class FleetUsageAccumulator {
71
75
  mergeBack(entries: UsageReport["entries"]): void;
72
76
  get size(): number;
73
77
  }
78
+ /** [ref] —— 一个中心凭证身份的用量箱:这个身份窗里的累计格,与钉在这个身份上的凭证(用量环只经它报这一箱)。 */
79
+ export interface FleetUsageBin {
80
+ readonly usage: FleetUsageAccumulator;
81
+ readonly credential: CenterCredentialSource;
82
+ }
83
+ /**
84
+ * [ref] —— **按中心凭证身份分箱的用量账**(活对象 ⇒ `create*`)。tracer / side-query 记账写 {@link record}(此刻身份那一箱);
85
+ * 用量环读 {@link current}(此刻身份那一箱 + 钉住的凭证)。分箱规则只有 `createIdentityBins` 一只(与租约管理器、per-principal caps 同规则)。
86
+ */
87
+ export interface FleetUsageBins {
88
+ /** 记进**记账身份**那一箱(执行里 = 执行开始时钉下的身份;执行外 = 此刻身份)。 */
89
+ record(principal: string | undefined, model: string, taskId: string, d: {
90
+ inputTokens: number;
91
+ outputTokens: number;
92
+ costMicroUsd?: number;
93
+ weightedTokens?: number;
94
+ quotaWeightAtUse?: number;
95
+ }): void;
96
+ /** 把这次执行的记账身份钉在此刻(tracer 在 `task.start` 调;规则属 `center-credential.ts` `pinAccountingIdentity`)。 */
97
+ pinExecution(): void;
98
+ /** 此刻身份那一箱(用量环上报读它)。 */
99
+ current(): FleetUsageBin;
100
+ /** **全部**箱里还压着的条目数(收尾那一行 warn 用:最后一窗之后还压着的,进程退出即丢 —— 别的身份的、身份未知的、或最后一窗没报成的,同一待遇)。 */
101
+ held(): number;
102
+ }
103
+ export declare function createFleetUsageBins(credential: CenterCredentialSource): FleetUsageBins;
74
104
  export interface FleetClientOpts {
75
- /** S-651:凭证是**来源**(每条公告 / 用量 / 注销请求各取一次值),不是启动期烧进 header 的字符串。 */
105
+ /** [ref]:凭证是**来源**(每条公告 / 用量 / 注销请求各取一次值),不是启动期烧进 header 的字符串。 */
76
106
  center: CenterEndpoint & {
77
107
  worker: string;
78
108
  };
79
109
  instanceId: string;
80
110
  /** Reachable base URL of THIS instance — the operator's explicit declaration (`FLEET_ADVERTISE_ADDRESS`).
81
- * S-866 ④:**缺席 = 公告环不装**(不注册、不心跳、不注销;`announceNow` 是空操作),用量环照装。 */
111
+ * [ref] ④:**缺席 = 公告环不装**(不注册、不心跳、不注销;`announceNow` 是空操作),用量环照装。 */
82
112
  advertiseAddress?: string | undefined;
83
113
  version: string;
84
114
  /** 编排器片 2 件 1:引擎信号的**一只铸点**(装配层接 `mintEngineSignal(deployment)` —— `/health` 与 `/readyz` 读的同一只、同一个 deps 组)。
85
115
  * 每条公告现铸**一次**,嵌套 `engineSignal` 与扁平 `ready` / `draining` / `restart` / 代际与租约三键都取自这一次(不会撕裂成 `ready:true` +
86
- * `draining:true`,也不会出现心跳与 `/health` 各算一份重启或租约)。修前是 `readiness` + `restart` 两只取值口(S-740 / S-741),合进这一只。 */
116
+ * `draining:true`,也不会出现心跳与 `/health` 各算一份重启或租约)。修前是 `readiness` + `restart` 两只取值口([ref] / [ref]),合进这一只。 */
87
117
  signal: () => EngineSignalFacts;
88
- /** S-768:模型拒因信号(装配层接 `/health` 同一只取值口 `deployment.modelRefusalsState`)。每条公告现读一次;`undefined` ⇒ 公告不带
118
+ /** [ref]:模型拒因信号(装配层接 `/health` 同一只取值口 `deployment.modelRefusalsState`)。每条公告现读一次;`undefined` ⇒ 公告不带
89
119
  * `modelRefusals` 键。必填:与 `restart` 同 —— 心跳面没有「不知道有没有拒」这一形(老引擎不发这个键,中心按 `version` 判「不可知」)。 */
90
120
  modelRefusals: () => ModelRefusalsSignal | undefined;
91
121
  /** 编排器片 2:每一次**能力读数**交出去一次(装配层接服务租约客户端的 `noteCenterCapabilities`)。规则见 {@link capabilityReadingOf}:
92
122
  * 只有 `declared`(交出宣告的位)与 `undeclared`(交 `undefined` = 老中心没宣告)是读数;`unreadable`(体读不出 / 不是对象 /
93
123
  * `capabilities` 键在场而形坏)不是读数 ⇒ 不调,上一次读数与它的钟原样。失败的公告同样不调(没听到 ≠ 没有)。 */
94
124
  onCenterCapabilities?: (caps: WebAdminCapabilities | undefined) => void;
95
- usage?: FleetUsageAccumulator;
125
+ /** [ref]:按凭证身份分箱的用量账(缺席 = 用量环不装)。 */
126
+ usage?: FleetUsageBins;
96
127
  heartbeatMs?: number;
97
128
  usageWindowMs?: number;
98
129
  logger?: {
@@ -104,7 +135,7 @@ export interface FleetClientOpts {
104
135
  }
105
136
  export interface FleetClient {
106
137
  /** Immediate out-of-cycle announce — call when a self-reported input flips (draining: self-remove from routing FIRST;
107
- * roster landed: become routable without waiting a heartbeat; restart signal changed: S-741). */
138
+ * roster landed: become routable without waiting a heartbeat; restart signal changed: [ref]). */
108
139
  announceNow: () => Promise<void>;
109
140
  /**
110
141
  * **路由面**停:停心跳、等在飞公告排空、best-effort DELETE 注销(各请求有界;从不抛)。之后的 `announceNow` 是空操作。
@@ -113,7 +144,7 @@ export interface FleetClient {
113
144
  stopRouting: () => Promise<void>;
114
145
  /**
115
146
  * **记账面**停:停用量窗定时器、上报最后一个(可能不满的)用量窗(有界;从不抛;空窗不发)。与路由面无关(不公告的引擎也报用量)。
116
- * 收尾链排在**排空等待之后**调(S-929 F12:宽限窗里跑完的腿记下的用量必须进这一窗)。
147
+ * 收尾链排在**排空等待之后**调([ref] F12:宽限窗里跑完的腿记下的用量必须进这一窗)。
117
148
  */
118
149
  flushFinalUsage: () => Promise<void>;
119
150
  }
@@ -134,13 +165,13 @@ export type AnnounceReplyReading = Exclude<CapabilityReading, {
134
165
  };
135
166
  /**
136
167
  * Start the worker-side fleet loops. Caller has already gated on the center lane (startFleetClientFromConfig below).
137
- * The announce loop runs iff `advertiseAddress` is present; the usage loop iff `usage` is present (S-866 ④: the two
168
+ * The announce loop runs iff `advertiseAddress` is present; the usage loop iff `usage` is present ([ref] ④: the two
138
169
  * loops no longer share one gate).
139
170
  */
140
171
  export declare function startFleetClient(opts: FleetClientOpts): FleetClient;
141
172
  /**
142
- * Config gate (D3 可选分层;S-866 ④ 两条环各自有门): start when the center lane is configured —
143
- * {@link centerLaneConfigured}(baseUrl + a DECLARED credential + worker — S-651: declared, not "currently readable": a token
173
+ * Config gate (D3 可选分层;[ref] ④ 两条环各自有门): start when the center lane is configured —
174
+ * {@link centerLaneConfigured}(baseUrl + a DECLARED credential + worker — [ref]: declared, not "currently readable": a token
144
175
  * file that is unreadable right now still starts the client, every request re-reads it), the SAME predicate the lease
145
176
  * manager and the usage accumulator use. The usage loop needs nothing more; the announce loop additionally needs the
146
177
  * operator's explicit reachable address — the config seat `fleetAdvertiseAddress` (env `FLEET_ADVERTISE_ADDRESS`, parsed once by
@@ -2,6 +2,7 @@ import { InstanceAnnouncement, UsageReport, DEFAULT_HEARTBEAT_MS, readCapability
2
2
  import { ENGINE_SIGNAL_KEY, buildEngineSignal, fleetMembershipKeys, heartbeatReadinessKeys } from "./fleet/engine-signal.js";
3
3
  import { centerFetch, centerLaneConfigured } from "./web-admin-client/center-request.js";
4
4
  import { recordFailOpen } from "./observability/fail-open.js";
5
+ import { createIdentityBins, pinAccountingIdentity } from "./center-credential.js";
5
6
  import { WEB_ADMIN_ENV } from "@sema-agent/settings-schema";
6
7
  export const FLEET_USAGE_KEY_CAP = 1024;
7
8
  export const FLEET_CLIENT_FETCH_TIMEOUT_MS = 5000;
@@ -67,6 +68,20 @@ export class FleetUsageAccumulator {
67
68
  return this.cells.size;
68
69
  }
69
70
  }
71
+ export function createFleetUsageBins(credential) {
72
+ const made = [];
73
+ const bins = createIdentityBins(credential, (pinned) => {
74
+ const bin = { usage: new FleetUsageAccumulator(), credential: pinned };
75
+ made.push(bin);
76
+ return bin;
77
+ });
78
+ return {
79
+ record: (principal, model, taskId, d) => bins.accounting().usage.record(principal, model, taskId, d),
80
+ pinExecution: () => pinAccountingIdentity(credential),
81
+ current: bins.now,
82
+ held: () => made.reduce((n, b) => n + b.usage.size, 0),
83
+ };
84
+ }
70
85
  async function rejectionSnippet(res) {
71
86
  try {
72
87
  const text = (await res.text()).slice(0, 200).trim();
@@ -90,7 +105,7 @@ export function startFleetClient(opts) {
90
105
  const f = opts.fetchImpl ?? fetch;
91
106
  const heartbeatMs = opts.heartbeatMs ?? DEFAULT_HEARTBEAT_MS;
92
107
  const usageWindowMs = opts.usageWindowMs ?? 60_000;
93
- const send = (route, method, json) => centerFetch(opts.center, { kind: route }, { method, json, timeoutMs: FLEET_CLIENT_FETCH_TIMEOUT_MS, fetchImpl: f });
108
+ const send = (route, method, json, center = opts.center) => centerFetch(center, { kind: route }, { method, json, timeoutMs: FLEET_CLIENT_FETCH_TIMEOUT_MS, fetchImpl: f });
94
109
  let stopped = false;
95
110
  let failStreak = 0;
96
111
  let unreadableStreak = 0;
@@ -177,20 +192,21 @@ export function startFleetClient(opts) {
177
192
  const flushUsage = async () => {
178
193
  if (!opts.usage)
179
194
  return;
195
+ const bin = opts.usage.current();
180
196
  const windowEndMs = Date.now();
181
- const entries = opts.usage.drain();
197
+ const entries = bin.usage.drain();
182
198
  const start = windowStartMs;
183
199
  windowStartMs = windowEndMs;
184
200
  if (entries.length === 0)
185
201
  return;
186
202
  const report = { worker: opts.center.worker, instanceId: opts.instanceId, windowStartMs: start, windowEndMs, entries };
187
203
  try {
188
- const { res } = await send("fleet-usage", "POST", { reports: [report] });
204
+ const { res } = await send("fleet-usage", "POST", { reports: [report] }, { ...opts.center, credential: bin.credential });
189
205
  if (!res.ok)
190
206
  throw new Error(`usage ${res.status}${await rejectionSnippet(res)}`);
191
207
  }
192
208
  catch (err) {
193
- opts.usage.mergeBack(entries);
209
+ bin.usage.mergeBack(entries);
194
210
  opts.logger?.warn("fleet_usage_report_failed", { error: err instanceof Error ? err.message : String(err), entries: entries.length });
195
211
  }
196
212
  };
@@ -227,6 +243,10 @@ export function startFleetClient(opts) {
227
243
  if (uw)
228
244
  clearInterval(uw);
229
245
  await flushUsage();
246
+ const held = opts.usage?.held() ?? 0;
247
+ if (held > 0) {
248
+ opts.logger?.warn("fleet_usage_unreported_identity", { entries: held, note: "usage still held at exit is dropped: it accrued under another center credential identity (never reported under the current one — it would be billed to the wrong account), under an unknown identity (credential unreadable), or its final report failed" });
249
+ }
230
250
  };
231
251
  return { announceNow, stopRouting, flushFinalUsage };
232
252
  }
@@ -3,20 +3,20 @@ import { type CenterEndpoint } from "./web-admin-client/center-request.js";
3
3
  export declare const NOT_LEASE_TTL_MS: number;
4
4
  /** center 判 budget exhausted 后,多久内的重复提交直接拒绝而不再打 center(防 per-request 打爆)。 */
5
5
  export declare const EXHAUSTED_RETRY_MS: number;
6
- /** principal 状态表上界(镜像 FLEET_USAGE_KEY_CAP 的姿势):超界丢最旧 —— 被丢的 principal 下次 admit
6
+ /** principal 状态表上界(**每个身份箱各一份**;镜像 FLEET_USAGE_KEY_CAP 的姿势):超界丢最旧 —— 被丢的 principal 下次 admit
7
7
  * 重新协商,一次多余 RTT,无正确性影响。 */
8
8
  export declare const LEASE_PRINCIPAL_CAP = 4096;
9
9
  /** 复审 O1:lease 协商 RTT 的硬上限——leaseDenied 在提交热路径同步 await 它,一个 accept-but-hang 的
10
10
  * center 必须迅速塌成连接级失败臂而不是拖垮提交。取 2.5s(远小于任何续租余量,略紧于 registry 的 8s)。 */
11
11
  export declare const LEASE_FETCH_TIMEOUT_MS = 2500;
12
- /** S-866 ③:`closed` 姿态下连接级失败给调用方的重试窗(秒)。**固定短窗** —— 不猜中心何时恢复;503 可重试,下一次提交就是
12
+ /** [ref] ③:`closed` 姿态下连接级失败给调用方的重试窗(秒)。**固定短窗** —— 不猜中心何时恢复;503 可重试,下一次提交就是
13
13
  * 下一次谈判(失败臂不缓存,中心一恢复即恢复)。 */
14
14
  export declare const LEASE_UNAVAILABLE_RETRY_SEC = 5;
15
- /** S-866 ③:租约连接级失败的两种姿态(= caps `centerWiring.failMode` 的词表;生效值由 `createFleetLeaseFromEnv` 从
15
+ /** [ref] ③:租约连接级失败的两种姿态(= caps `centerWiring.failMode` 的词表;生效值由 `createFleetLeaseFromEnv` 从
16
16
  * `FLEET_LEASE_FAIL_CLOSED` 定)。加一种 = 下面按姿态穷举的 `Record` 当场编译红。 */
17
17
  export declare const LEASE_FAIL_MODES: readonly ["open", "closed"];
18
18
  export type LeaseFailMode = (typeof LEASE_FAIL_MODES)[number];
19
- /** S-866 ③:`lease_unavailable` 的两个成因(503 体 `reason` 的词表,与 caps `leaseHealth` 的两个失败词同名)。 */
19
+ /** [ref] ③:`lease_unavailable` 的两个成因(503 体 `reason` 的词表,与 caps `leaseHealth` 的两个失败词同名)。 */
20
20
  export declare const LEASE_UNAVAILABLE_CAUSES: readonly ["auth-rejected", "unreachable"];
21
21
  export type LeaseUnavailableCause = (typeof LEASE_UNAVAILABLE_CAUSES)[number];
22
22
  /** E4 定稿的 409 结构化字段(center verbatim → 我方 429 body verbatim 透传;人话归壳/web)。 */
@@ -45,7 +45,7 @@ export type LeaseRefusalAdmission = Extract<LeaseAdmission, {
45
45
  ok: false;
46
46
  }>;
47
47
  /**
48
- * S-866 ② —— **最近一次谈判怎么收尾的**(`issueOrRenew` 收尾写;新状态,本管理器只此一枚)。闭集:
48
+ * [ref] ② —— **最近一次谈判怎么收尾的**(`issueOrRenew` 收尾写;新状态,本管理器只此一枚)。闭集:
49
49
  * · `none` —— 本进程还没谈判过;
50
50
  * · `ok` —— 中心给了合法答复(200 租约 / 409 not-lease / 409 耗尽 —— 耗尽也是「中心在判」);
51
51
  * · `auth-error` —— 中心 401 / 403 / 400,或这一次读凭证失败(请求根本没发);
@@ -54,10 +54,10 @@ export type LeaseRefusalAdmission = Extract<LeaseAdmission, {
54
54
  */
55
55
  export declare const LEASE_ADMIT_OUTCOMES: readonly ["none", "ok", "auth-error", "unavailable"];
56
56
  export type LeaseAdmitOutcome = (typeof LEASE_ADMIT_OUTCOMES)[number];
57
- /** S-866 ② caps `centerWiring.leaseHealth` 的词表。 */
57
+ /** [ref] ② caps `centerWiring.leaseHealth` 的词表。 */
58
58
  export declare const LEASE_HEALTH_WORDS: readonly ["ok", "auth-rejected", "unreachable", "unobserved"];
59
59
  export type LeaseHealth = (typeof LEASE_HEALTH_WORDS)[number];
60
- /** S-866 ② caps `centerWiring.caller.lease` 的词表(F-1 裁定:过期 / 耗尽而未续成 ⇒ `unobserved`)。 */
60
+ /** [ref] ② caps `centerWiring.caller.lease` 的词表(F-1 裁定:过期 / 耗尽而未续成 ⇒ `unobserved`)。 */
61
61
  export declare const CALLER_LEASE_WORDS: readonly ["enforced", "not-enforced", "exhausted", "unobserved"];
62
62
  export type CallerLease = (typeof CALLER_LEASE_WORDS)[number];
63
63
  /** `snapshot()` 的产物(纯数据):调用方这一刻的租约读数 + 管理器最近一次谈判的健康位。`retryAfterSec` 只随 `exhausted`。 */
@@ -69,11 +69,11 @@ export interface LeaseSnapshot {
69
69
  };
70
70
  }
71
71
  export interface FleetLeaseOpts {
72
- /** S-651:凭证是**来源**(每次协商取一次值),不是构造期烧进 header 的字符串。 */
72
+ /** [ref]:凭证是**来源**(每次协商取一次值),不是构造期烧进 header 的字符串。 */
73
73
  center: CenterEndpoint & {
74
74
  worker: string;
75
75
  };
76
- /** S-866 ③:连接级失败臂的姿态。**必填** —— 安全轴上没有「不知道该放还是该拒」这一形(缺省在配置层按部署姿态派生,不在这里猜)。 */
76
+ /** [ref] ③:连接级失败臂的姿态。**必填** —— 安全轴上没有「不知道该放还是该拒」这一形(缺省在配置层按部署姿态派生,不在这里猜)。 */
77
77
  failMode: LeaseFailMode;
78
78
  fetchImpl?: typeof fetch;
79
79
  logger?: {
@@ -87,16 +87,18 @@ export interface FleetLeaseOpts {
87
87
  }
88
88
  export declare class FleetLeaseManager {
89
89
  private readonly opts;
90
- private readonly state;
91
- private readonly inflight;
90
+ /** 记账身份的那一箱(惰建;分箱规则只有 `createIdentityBins` 一只,取箱口 `accounting`)。 */
91
+ private readonly binNow;
92
92
  private readonly f;
93
93
  private readonly now;
94
94
  private failStreak;
95
- /** S-866 ②:最近一次谈判的收尾({@link LeaseAdmitOutcome})。只在 `issueOrRenewInner` 的各收尾点写。 */
95
+ /** [ref] ②:最近一次谈判的收尾({@link LeaseAdmitOutcome})。只在 `issueOrRenewInner` 的各收尾点写。 */
96
96
  private lastAdmit;
97
- /** S-866 ③ 生效姿态(caps `centerWiring.failMode` 读的就是它 —— 与执行的那一只同源)。 */
97
+ /** [ref] ③ 生效姿态(caps `centerWiring.failMode` 读的就是它 —— 与执行的那一只同源)。 */
98
98
  readonly failMode: LeaseFailMode;
99
99
  constructor(opts: FleetLeaseOpts);
100
+ /** [ref]:把这次执行的记账身份钉在此刻(tracer 在执行的第一帧 `task.start` 调;规则属 `center-credential.ts` `pinAccountingIdentity`)。 */
101
+ pinExecution(): void;
100
102
  /**
101
103
  * Admission check for one billed submission. Fast path is synchronous-shaped (live lease / fresh negative
102
104
  * cache → no await beyond the microtask); only first-touch / expiry / exhaustion pays a center RTT.
@@ -117,8 +119,9 @@ export declare class FleetLeaseManager {
117
119
  costMicroUsd?: number;
118
120
  }): void;
119
121
  /**
120
- * S-866 ② —— 调用方这一刻的租约读数(caps `centerWiring.caller` / `leaseHealth` 的唯一来源;7.105.0 的 `peek()` 退役:它只回 kind、
122
+ * [ref] ② —— 调用方这一刻的租约读数(caps `centerWiring.caller` / `leaseHealth` 的唯一来源;7.105.0 的 `peek()` 退役:它只回 kind、
121
123
  * 不看 `until`,过期条目照回原 kind)。**纯读**:不打中心、不写状态、不动 LRU 序(`Map.get` 不改插入序)—— caps 路由自己不 admit。
124
+ * 读的是**此刻凭证身份**那一箱([ref];取箱要读一次凭证,首次见到的身份惰建一只空箱 —— 空箱不是状态)。
122
125
  * 规则表(设计稿 v1.1 §2②,逐行钉在 `test/fleet-lease.test.ts`):
123
126
  * · principal 缺席 / 无条目(含被 LRU 逐出)⇒ `unobserved`;
124
127
  * · `not-lease` 且 `now < until` ⇒ `not-enforced`;到期 ⇒ `unobserved`;
@@ -128,20 +131,21 @@ export declare class FleetLeaseManager {
128
131
  * `leaseHealth` 按 `lastAdmit`({@link LEASE_HEALTH_BY_OUTCOME})。
129
132
  */
130
133
  snapshot(principal: string | undefined, now: number): LeaseSnapshot;
131
- /** 🔴 复审 O2(Opus)的鉴权失败臂,S-651 起两个入口共用(中心 401/403/400;凭证文件不可读):运维配置事故,
134
+ /** 🔴 复审 O2(Opus)的鉴权失败臂,[ref] 起两个入口共用(中心 401/403/400;凭证文件不可读):运维配置事故,
132
135
  * 不是可用性事件。**每次**都 warn + 专用计数,且**不缓存**(配置一修好下一次谈判即恢复)。放不放行归姿态
133
- * ({@link connectionFailure},S-866 ③):open = 照旧放行(凭证抖一下不许把单用户锁在门外);closed = 拒。 */
136
+ * ({@link connectionFailure},[ref] ③):open = 照旧放行(凭证抖一下不许把单用户锁在门外);closed = 拒。 */
134
137
  private authFailure;
135
- /** S-866 ③:两条连接级失败臂的**唯一**收尾 —— 按姿态穷举(加一种姿态 = 编译红)。 */
138
+ /** [ref] ③:两条连接级失败臂的**唯一**收尾 —— 按姿态穷举(加一种姿态 = 编译红)。 */
136
139
  private connectionFailure;
137
140
  private set;
141
+ /** 单飞在箱内:同一身份同一 principal 的并发谈判共用一条;换了人的谈判各发各的([ref])。 */
138
142
  private issueOrRenew;
139
143
  private issueOrRenewInner;
140
144
  }
141
145
  /**
142
- * Env/config gate:中心车道配齐({@link centerLaneConfigured} —— 与 fleet 用量环 / 用量累加器**同一只**谓词,S-866 ④)即启;
146
+ * Env/config gate:中心车道配齐({@link centerLaneConfigured} —— 与 fleet 用量环 / 用量累加器**同一只**谓词,[ref] ④)即启;
143
147
  * 不需要 FLEET_ADVERTISE_ADDRESS(它是出站消费面,不是入站可达性声明)。缺任一件 → undefined,非 fleet 部署零行为变化。
144
- * S-651:按**声明**装、不按内容装 —— `SEMA_WEB_ADMIN_TOKEN_FILE`(`WEB_ADMIN_ENV.tokenFile`)在场而
148
+ * [ref]:按**声明**装、不按内容装 —— `SEMA_WEB_ADMIN_TOKEN_FILE`(`WEB_ADMIN_ENV.tokenFile`)在场而
145
149
  * 文件此刻不可读,管理器照样装上(每次协商取值,失败走响亮的鉴权失败臂;文件恢复即恢复)。
146
150
  */
147
151
  export declare function createFleetLeaseFromEnv(cfg: {
@@ -1,5 +1,5 @@
1
1
  import { QuotaLease, leaseExhausted, shouldRenewLease } from "@sema-agent/settings-schema/fleet";
2
- import { CenterCredentialUnavailableError } from "./center-credential.js";
2
+ import { CenterCredentialUnavailableError, createIdentityBins, pinAccountingIdentity } from "./center-credential.js";
3
3
  import { centerFetch, centerLaneConfigured } from "./web-admin-client/center-request.js";
4
4
  export const NOT_LEASE_TTL_MS = 10 * 60 * 1000;
5
5
  export const EXHAUSTED_RETRY_MS = 30 * 1000;
@@ -23,8 +23,7 @@ const LEASE_HEALTH_BY_OUTCOME = {
23
23
  };
24
24
  export class FleetLeaseManager {
25
25
  opts;
26
- state = new Map();
27
- inflight = new Map();
26
+ binNow;
28
27
  f;
29
28
  now;
30
29
  failStreak = 0;
@@ -35,10 +34,19 @@ export class FleetLeaseManager {
35
34
  this.f = opts.fetchImpl ?? fetch;
36
35
  this.now = opts.now ?? Date.now;
37
36
  this.failMode = opts.failMode;
37
+ this.binNow = createIdentityBins(opts.center.credential, (pinned) => ({
38
+ state: new Map(),
39
+ inflight: new Map(),
40
+ center: { ...opts.center, credential: pinned },
41
+ })).accounting;
42
+ }
43
+ pinExecution() {
44
+ pinAccountingIdentity(this.opts.center.credential);
38
45
  }
39
46
  async admit(principal) {
47
+ const bin = this.binNow();
40
48
  const now = this.now();
41
- const st = this.state.get(principal);
49
+ const st = bin.state.get(principal);
42
50
  if (st?.kind === "not-lease" && now < st.until)
43
51
  return { ok: true };
44
52
  if (st?.kind === "exhausted" && now < st.until) {
@@ -46,15 +54,15 @@ export class FleetLeaseManager {
46
54
  }
47
55
  if (st?.kind === "lease" && !leaseExhausted(st.lease, now)) {
48
56
  if (shouldRenewLease(st.lease, now))
49
- void this.issueOrRenew(principal).catch(() => undefined);
57
+ void this.issueOrRenew(bin, principal).catch(() => undefined);
50
58
  return { ok: true };
51
59
  }
52
- return this.issueOrRenew(principal);
60
+ return this.issueOrRenew(bin, principal);
53
61
  }
54
62
  recordSpend(principal, d) {
55
63
  if (!principal)
56
64
  return;
57
- const st = this.state.get(principal);
65
+ const st = this.binNow().state.get(principal);
58
66
  if (st?.kind !== "lease")
59
67
  return;
60
68
  st.lease.consumed.weightedTokens += d.weightedTokens ?? 0;
@@ -62,7 +70,7 @@ export class FleetLeaseManager {
62
70
  }
63
71
  snapshot(principal, now) {
64
72
  const leaseHealth = LEASE_HEALTH_BY_OUTCOME[this.lastAdmit];
65
- const st = principal === undefined ? undefined : this.state.get(principal);
73
+ const st = principal === undefined ? undefined : this.binNow().state.get(principal);
66
74
  if (st === undefined)
67
75
  return { leaseHealth, caller: { lease: "unobserved" } };
68
76
  switch (st.kind) {
@@ -97,25 +105,25 @@ export class FleetLeaseManager {
97
105
  }
98
106
  }
99
107
  }
100
- set(principal, st) {
101
- if (!this.state.has(principal) && this.state.size >= LEASE_PRINCIPAL_CAP) {
102
- const oldest = this.state.keys().next().value;
103
- this.state.delete(oldest);
108
+ set(bin, principal, st) {
109
+ if (!bin.state.has(principal) && bin.state.size >= LEASE_PRINCIPAL_CAP) {
110
+ const oldest = bin.state.keys().next().value;
111
+ bin.state.delete(oldest);
104
112
  }
105
- this.state.delete(principal);
106
- this.state.set(principal, st);
113
+ bin.state.delete(principal);
114
+ bin.state.set(principal, st);
107
115
  }
108
- issueOrRenew(principal) {
109
- const existing = this.inflight.get(principal);
116
+ issueOrRenew(bin, principal) {
117
+ const existing = bin.inflight.get(principal);
110
118
  if (existing)
111
119
  return existing;
112
- const p = this.issueOrRenewInner(principal).finally(() => this.inflight.delete(principal));
113
- this.inflight.set(principal, p);
120
+ const p = this.issueOrRenewInner(bin, principal).finally(() => bin.inflight.delete(principal));
121
+ bin.inflight.set(principal, p);
114
122
  return p;
115
123
  }
116
- async issueOrRenewInner(principal) {
124
+ async issueOrRenewInner(bin, principal) {
117
125
  try {
118
- const { res } = await centerFetch(this.opts.center, { kind: "fleet-leases" }, {
126
+ const { res } = await centerFetch(bin.center, { kind: "fleet-leases" }, {
119
127
  method: "POST",
120
128
  json: { principal, worker: this.opts.center.worker },
121
129
  timeoutMs: LEASE_FETCH_TIMEOUT_MS,
@@ -124,7 +132,7 @@ export class FleetLeaseManager {
124
132
  if (res.status === 200) {
125
133
  const body = (await res.json());
126
134
  const lease = QuotaLease.parse(body.lease);
127
- this.set(principal, { kind: "lease", lease });
135
+ this.set(bin, principal, { kind: "lease", lease });
128
136
  if (this.failStreak > 0)
129
137
  this.opts.logger?.info?.("fleet_lease_recovered", { after: this.failStreak });
130
138
  this.failStreak = 0;
@@ -145,11 +153,11 @@ export class FleetLeaseManager {
145
153
  ...(body.pool !== undefined ? { pool: body.pool } : {}),
146
154
  };
147
155
  const hasDetail = Object.keys(detail).length > 0;
148
- this.set(principal, { kind: "exhausted", until, ...(hasDetail ? { detail } : {}) });
156
+ this.set(bin, principal, { kind: "exhausted", until, ...(hasDetail ? { detail } : {}) });
149
157
  this.opts.metrics?.inc("fleet_lease_exhausted_total");
150
158
  return { ok: false, reason: "budget_exhausted", retryAfterSec: Math.ceil(EXHAUSTED_RETRY_MS / 1000), ...(hasDetail ? { detail } : {}) };
151
159
  }
152
- this.set(principal, { kind: "not-lease", until: this.now() + NOT_LEASE_TTL_MS });
160
+ this.set(bin, principal, { kind: "not-lease", until: this.now() + NOT_LEASE_TTL_MS });
153
161
  return { ok: true };
154
162
  }
155
163
  if (res.status === 401 || res.status === 403 || res.status === 400) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * S-189 —— core `GOVERNANCE_CODES` **闭集**在本分诊面上的逐码处置表。
2
+ * [ref] —— core `GOVERNANCE_CODES` **闭集**在本分诊面上的逐码处置表。
3
3
  *
4
4
  * 为什么单独一张表而不是继续往下面的 if 链里加行:`failureCodeOf` 是**开集**(顶注写死「消费点一律带
5
5
  * default 臂,禁按穷举写」),而开集里嵌着 core 这一个**闭集注册表**。闭集的成员共享两个性质——同一条
@@ -11,7 +11,7 @@
11
11
  * 值 `null` = **有意**不在本腿分诊(理由逐条写在行上),与「忘了写」在类型上不同形 —— 这是本表存在的
12
12
  * 全部意义:让「没表态」不可能静默发生。开集那一半(下面的 if 链 + `resume_at.` 前缀臂 + default)不动。
13
13
  *
14
- * 逐码预期的**行为面**镜像在 `test/resume-anchor.test.ts` 的 S-189 段(同型同义、刻意不共用这张表:
14
+ * 逐码预期的**行为面**镜像在 `test/resume-anchor.test.ts` 的 [ref] 段(同型同义、刻意不共用这张表:
15
15
  * 测试喂码进函数看状态码,不读本表,否则表写错了两边一起错还全绿)。
16
16
  */
17
17
  export declare const GOVERNANCE_HTTP_STATUS: {
@@ -5,23 +5,23 @@ import type { HookLlmCall, HookLlmFailureCode } from "./hook-runner.js";
5
5
  * hookLlm(prompt 条目/session titler 的模型载体)= 直连一次非流式 completion,从 main.ts 抽出成可注入
6
6
  * 单元(fetchImpl/keyResolver 可假),因为这条 wire 在每个默认部署上都活(titler),必须可单测。
7
7
  *
8
- * api 形分派(2026-07-15,黑板 [ref]③b 真缺陷修;**选线依据 S-1630 起改为引擎主路由同一只判词**,见下):被选模型按所落的 brain 腿分家 ——
8
+ * api 形分派(2026-07-15,黑板 [ref]③b 真缺陷修;**选线依据 [ref] 起改为引擎主路由同一只判词**,见下):被选模型按所落的 brain 腿分家 ——
9
9
  * - `openai-completions` ⇒ POST {base}/chat/completions(现状,字节不变);
10
10
  * - `anthropic-messages` ⇒ POST {base}/v1/messages(x-api-key / Authorization: Bearer + anthropic-version
11
11
  * 头,messages 数组,回包取 content[].text)。此前 hookLlm 只会说 openai 形且缺省 baseUrl 恒落
12
- * `config.gatewayBaseUrl`(当年它有一个本机 8000 端口的出厂缺省,S-623 已删)——anthropic 单路由部署(主模型
12
+ * `config.gatewayBaseUrl`(当年它有一个本机 8000 端口的出厂缺省,[ref] 已删)——anthropic 单路由部署(主模型
13
13
  * provider=anthropic 走 ANTHROPIC_BASE_URL,没配 MODEL_GATEWAY_BASEURL)下 titler 每会话打死
14
14
  * localhost:8000 ⇒ `session_title_failed: TypeError: fetch failed`;即使端点活着,anthropic-messages
15
15
  * 模型也不能用 /chat/completions 形调。
16
16
  *
17
- * 🔴 **选线 = 引擎主路由同一只判词**(S-1630):「这只模型走 openai-completions 还是 anthropic-messages」不是本面的事,
17
+ * 🔴 **选线 = 引擎主路由同一只判词**([ref]):「这只模型走 openai-completions 还是 anthropic-messages」不是本面的事,
18
18
  * 是引擎主路由的事 —— `brain.ts` 按 `model.provider` 在「anthropic 路由(仅当 ANTHROPIC 凭据把它装上)/ 网关栈」之间选,
19
19
  * 路由没装时整台机器只有网关这一只 brain,**连 `provider:"anthropic"` 的模型也落网关**(判词 `brainLaneFor` = 引擎 `brainLaneOf` 对装上的路由表的答案,
20
20
  * 端点判官 / 降级腿 / 启动摘要读的是同一只)。本面此前自己按 `provider === "anthropic"` / `api === "anthropic-messages"`
21
21
  * 字面判线 ⇒ 在 `MODEL_PROVIDER=anthropic` 而只配了网关的部署上,主请求去网关、标题与 hooks 的 llm 面却要找一条没装的
22
22
  * anthropic 路由,整条拒发(零请求,只落 fail-open 标签)。现在本面只问那一只判词,不留第二个读法 —— 含 `api` 词:
23
23
  * 引擎不按 `api` 选线(core 的 `createRoutingBrain` 缺省按 `provider` 键),settings-schema 的 `ModelEntry` 又强制两个词同真同假。
24
- * (S-1630 的 (a) 路已兑现:core 7.53.0 #1842 根导出了那只判官 `brainLaneOf(model, routes)` —— `createRoutingBrain` 对每个请求问的就是它;
24
+ * ([ref] 的 (a) 路已兑现:core 7.53.0 [ref] 根导出了那只判官 `brainLaneOf(model, routes)` —— `createRoutingBrain` 对每个请求问的就是它;
25
25
  * 本仓自写的合取 `dispatchBrainLane` 随之退役,本调用点与另三处一并改问它。)
26
26
  */
27
27
  export type HookModelPick = {
@@ -31,14 +31,14 @@ export type HookModelPick = {
31
31
  baseUrl: string;
32
32
  api: "openai-completions" | "anthropic-messages";
33
33
  }
34
- /** 选不出来的那一臂自带失败码(S-1635):两个载体(prompt 直连 / agent 子代理)共用这一只选模闸,同一只判词同一个码。 */
34
+ /** 选不出来的那一臂自带失败码([ref]):两个载体(prompt 直连 / agent 子代理)共用这一只选模闸,同一只判词同一个码。 */
35
35
  | {
36
36
  ok: false;
37
37
  error: string;
38
38
  code: Extract<HookLlmFailureCode, "model_unresolved">;
39
39
  };
40
40
  /**
41
- * 🔴 **hook 失败展示文本的唯一铸点**(S-494;`build*` = 返回纯数据的一只纯函数)。
41
+ * 🔴 **hook 失败展示文本的唯一铸点**([ref];`build*` = 返回纯数据的一只纯函数)。
42
42
  *
43
43
  * 病(codex 对 7.88.1/7.88.2 的补审抓出,存量泄漏,本车红先复现):这一族失败文本是**拼**出来的 ——
44
44
  * 料有四种:core 的路由拒绝文案(`routeRefusalText` 的 `fixHint` 逐字带 `config.baseUrl` 的值)、
@@ -59,7 +59,7 @@ export type HookModelPick = {
59
59
  * 🚧 **已知射程边界(登记,另车修在源头)**:自由文本律对**非规范拼法**的 URL
60
60
  * (`https:alice:pw@h/v1` 省了 `//`、authority 里夹 tab)认不出结构 ⇒ 那两形若出现在料里(目录下发的
61
61
  * `models[].baseUrl` 今天原样存,`apply-effective.ts` 只校验 `protocol`)仍会原样。修在源头 =
62
- * 目录 baseUrl 落库前归一成 `new URL(raw).href`(S-483 收车档未闭环项),不是在这里再加一把尺。
62
+ * 目录 baseUrl 落库前归一成 `new URL(raw).href`([ref] 收车档未闭环项),不是在这里再加一把尺。
63
63
  */
64
64
  export declare function buildHookFailureText(raw: string): string;
65
65
  /** The live object `createHookLlm` produces — model-pick resolution + the direct completion call, both capturing the hot-refreshed keyResolver/fetchImpl in closure. */