@sema-agent/server 7.37.0 → 7.38.0-rc.1

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 (82) hide show
  1. package/USAGE.md +2 -1
  2. package/dist/adoption/plan.js +16 -0
  3. package/dist/boot/budget-tracing.d.ts +1 -1
  4. package/dist/boot/budget-tracing.js +12 -5
  5. package/dist/boot/config-center.d.ts +27 -2
  6. package/dist/boot/config-center.js +148 -15
  7. package/dist/boot/limit-sync.d.ts +32 -0
  8. package/dist/boot/limit-sync.js +35 -0
  9. package/dist/boot/reapers.d.ts +68 -0
  10. package/dist/boot/reapers.js +63 -4
  11. package/dist/boot/resolve-spec.js +2 -0
  12. package/dist/boot/runner-deps.d.ts +1 -1
  13. package/dist/boot/runner-deps.js +4 -0
  14. package/dist/boot/stores.js +13 -0
  15. package/dist/config-center/apply-effective.d.ts +38 -3
  16. package/dist/config-center/apply-effective.js +75 -5
  17. package/dist/config-center/apply-ledger.d.ts +67 -0
  18. package/dist/config-center/apply-ledger.js +83 -0
  19. package/dist/config-center/facade.d.ts +1 -1
  20. package/dist/config-center/hot-keys-registry.d.ts +62 -0
  21. package/dist/config-center/hot-keys-registry.js +54 -0
  22. package/dist/config-center/http-client.js +12 -2
  23. package/dist/config-center/restart-signal.js +5 -2
  24. package/dist/config-center/stage-limits.d.ts +59 -0
  25. package/dist/config-center/stage-limits.js +188 -0
  26. package/dist/config-center/types.d.ts +60 -0
  27. package/dist/config-invariants.d.ts +65 -0
  28. package/dist/config-invariants.js +139 -0
  29. package/dist/config-provider.js +11 -0
  30. package/dist/config-types.d.ts +10 -1
  31. package/dist/config.d.ts +11 -0
  32. package/dist/config.js +37 -5
  33. package/dist/http/routes/admin-config-refresh.d.ts +20 -0
  34. package/dist/http/routes/admin-config-refresh.js +43 -0
  35. package/dist/http/routes/diagnostics.js +4 -0
  36. package/dist/http/server.d.ts +8 -0
  37. package/dist/http/server.js +23 -0
  38. package/dist/main.js +49 -6
  39. package/dist/memory-sync.js +50 -1
  40. package/dist/observability/cost-quota.d.ts +23 -3
  41. package/dist/observability/cost-quota.js +27 -4
  42. package/dist/observability/fail-open.d.ts +8 -0
  43. package/dist/observability/fail-open.js +8 -0
  44. package/dist/observability/rate-limit.d.ts +11 -1
  45. package/dist/observability/rate-limit.js +8 -2
  46. package/dist/plan-cache-probe.d.ts +5 -7
  47. package/dist/plan-cache-probe.js +27 -5
  48. package/dist/plugins/caching-session-store.d.ts +20 -4
  49. package/dist/plugins/caching-session-store.js +43 -2
  50. package/dist/plugins/fork-routing-session-store.d.ts +26 -4
  51. package/dist/plugins/fork-routing-session-store.js +134 -9
  52. package/dist/plugins/memory-engine-pg.d.ts +1 -0
  53. package/dist/plugins/memory-engine-pg.js +34 -4
  54. package/dist/plugins/memory-engine-tidb.d.ts +1 -0
  55. package/dist/plugins/memory-engine-tidb.js +17 -2
  56. package/dist/plugins/memory-origin-law.d.ts +69 -0
  57. package/dist/plugins/memory-origin-law.js +118 -1
  58. package/dist/plugins/pg-cost-quota.d.ts +7 -2
  59. package/dist/plugins/pg-cost-quota.js +25 -2
  60. package/dist/plugins/pg-rate-limiter.d.ts +7 -2
  61. package/dist/plugins/pg-rate-limiter.js +20 -2
  62. package/dist/plugins/pg-session-storage.d.ts +30 -7
  63. package/dist/plugins/pg-session-storage.js +145 -23
  64. package/dist/plugins/retention-store-sql.js +10 -1
  65. package/dist/plugins/session-placement.d.ts +113 -0
  66. package/dist/plugins/session-placement.js +153 -0
  67. package/dist/plugins/session-store.js +7 -1
  68. package/dist/plugins/tidb-cost-quota.d.ts +7 -2
  69. package/dist/plugins/tidb-cost-quota.js +26 -2
  70. package/dist/plugins/tidb-pool.js +15 -1
  71. package/dist/plugins/tidb-rate-limiter.d.ts +9 -2
  72. package/dist/plugins/tidb-rate-limiter.js +22 -2
  73. package/dist/plugins/tidb-session-storage.js +10 -2
  74. package/dist/plugins/tidb-session-store.d.ts +55 -7
  75. package/dist/plugins/tidb-session-store.js +174 -24
  76. package/dist/plugins/write-behind-counter.d.ts +17 -2
  77. package/dist/plugins/write-behind-counter.js +19 -1
  78. package/dist/runs.d.ts +3 -1
  79. package/dist/runs.js +5 -2
  80. package/dist/trace/engine-notice-wire.d.ts +1 -1
  81. package/dist/trace/engine-notice-wire.js +24 -6
  82. package/package.json +3 -3
package/dist/runs.d.ts CHANGED
@@ -277,6 +277,8 @@ approval?: {
277
277
  windowMarginMs: number;
278
278
  }): Promise<void>;
279
279
  /** How often a running instance refreshes its run's updated_at (liveness, independent of events).
280
- * Must stay strictly below `runStaleSec` (asserted at startup) or the reaper would race live runs. */
280
+ * Must stay strictly below `runStaleSec` (asserted at startup AND on every hot config candidate) or the
281
+ * reaper would race live runs. #322:数值的单源是 `config-invariants.ts`(那条不变量的属主),两个消费面
282
+ * ——心跳环与 run-stale 判据——因此不可能各读各的。 */
281
283
  export declare const HEARTBEAT_MS = 30000;
282
284
  //# sourceMappingURL=runs.d.ts.map
package/dist/runs.js CHANGED
@@ -10,6 +10,7 @@ import { fleetRunResiduals, isFleetAgentTerminalNotification } from "./fleet/fle
10
10
  import { defaultSubagentTailBus, projectTailFrame } from "./fleet/subagent-tail-bus.js";
11
11
  import { emitPendingWorkflowCompletions, taskNotificationInboxEntry, taskNotificationStreamKey, NotifiedKeys } from "./orchestration/workflow-completion-inbox.js";
12
12
  import { recordFailOpen } from "./observability/fail-open.js"; // #310:通告 durable 写失败的留痕口
13
+ import { LIVENESS_HEARTBEAT_MS } from "./config-invariants.js"; // #322:心跳周期的单源 = 它服务的那条不变量
13
14
  /**
14
15
  * stoppedBy (core 1.252): a service cancel is a USER stop — mark the run's still-running background
15
16
  * children BEFORE core's teardown reaps them (bare abort = attribution falls back to "system"; core's own
@@ -1012,6 +1013,8 @@ approval) {
1012
1013
  }
1013
1014
  }
1014
1015
  /** How often a running instance refreshes its run's updated_at (liveness, independent of events).
1015
- * Must stay strictly below `runStaleSec` (asserted at startup) or the reaper would race live runs. */
1016
- export const HEARTBEAT_MS = 30_000;
1016
+ * Must stay strictly below `runStaleSec` (asserted at startup AND on every hot config candidate) or the
1017
+ * reaper would race live runs. #322:数值的单源是 `config-invariants.ts`(那条不变量的属主),两个消费面
1018
+ * ——心跳环与 run-stale 判据——因此不可能各读各的。 */
1019
+ export const HEARTBEAT_MS = LIVENESS_HEARTBEAT_MS;
1017
1020
  //# sourceMappingURL=runs.js.map
@@ -4,7 +4,7 @@
4
4
  * 三码同族:都是「这条 session 的记忆姿态」的披露,resume 之后仍然相关 ⇒ 也进 durable 账本
5
5
  * (cli 断连补看走既有 events 重放腿,[4634](ii))。
6
6
  */
7
- export declare const ENGINE_NOTICE_WIRE_CODES: readonly ["memory.session_polluted", "memory.harvest_quarantined", "memory.delegation_static_mark_waived"];
7
+ export declare const ENGINE_NOTICE_WIRE_CODES: readonly ["memory.session_polluted", "memory.harvest_quarantined", "memory.delegation_static_mark_waived", "memory.hold_opened", "memory.hold_released", "memory.hold_disposed"];
8
8
  export type EngineNoticeWireCode = (typeof ENGINE_NOTICE_WIRE_CODES)[number];
9
9
  /** 白名单谓词(单点):路由与门都读这一个,不许第二处手抄码串。 */
10
10
  export declare function isEngineNoticeWireCode(code: string): code is EngineNoticeWireCode;
@@ -18,12 +18,17 @@
18
18
  * **不投**(fail-closed 方向 = 宁缺席不串台;猜一个"当前活跃会话"就是串台的定义)。日志终点仍逐字
19
19
  * 保留 ⇒ 运维观察面零回退,事实一条不丢。
20
20
  *
21
- * ## 白名单的演化机制(设计稿 ④)
22
- * 本表是**过渡形**。core [4631] 已认领 `NOTICE_AUDIENCE` **码级注册表**(code → "user"|"operator",
23
- * 闭集映射,随 5.46 / 最迟 5.47)+ `EngineNotice.sessionId` 顶层可选。到货后本表**退役为消费该表**,
24
- * 不在本仓自造第二份「哪类码该上 wire」的判定语义。
25
- * 🔴 在此之前的固定动作:**每一次 core 提货批**,LEDGER 对表 core `EngineNotice` 码册的新增码,
26
- * 三选一登记(入册 / 明拒 + 理由 / 申裁),登记在 `docs/CORE-CONSUMPTION-LEDGER.md` 的该批行里。
21
+ * ## 白名单的演化机制(设计稿 ④)—— **注册表已到货(core 5.47/5.48)**
22
+ * core [4631] 认领的 `NOTICE_AUDIENCE` **码级注册表**(code → "user"|"operator";缺席读 `"operator"`,
23
+ * 保守默认)已随 5.47/5.48 到货,`EngineNotice.sessionId` 顶层键亦然。#292 提货批的处置是
24
+ * **消费它当上界,而不是当场把本表整只退役**:
25
+ * · 本表是**投递可行性**的判定(有没有 sessionId 归属键、core 侧的去重单位是不是 sink),
26
+ * `NOTICE_AUDIENCE` 是**受众**的判定(这条码是给谁看的)——两者是合取,不是同一件事;
27
+ * · 于是机器门(`test/engine-notice-wire.test.ts` ⑥)现在**双向**咬:白名单里出现一个 core 判
28
+ * `"operator"` 的码 ⇒ 红(本仓不许自造第二份受众语义);core 判 `"user"` 的码没入册也没明拒 ⇒ 红。
29
+ * · 真正的整表退役条件 = 上游把「归属键在不在」也纳入注册表(那时本表退化成一次查表),届时删。
30
+ * 🔴 固定动作不变:**每一次 core 提货批**对表 core `EngineNotice` 码册的新增码,三选一登记
31
+ * (入册 / 明拒 + 理由 / 申裁),并在 `docs/core-consumption/LEDGER.json` 的该批行里留痕。
27
32
  * 漏对表的后果不是报错而是**静默缺席**:新码永远不上 wire,消费端(cli)无从知道该码存在。
28
33
  */
29
34
  import { redactSecrets } from "./redact.js";
@@ -44,6 +49,19 @@ export const ENGINE_NOTICE_WIRE_CODES = [
44
49
  /** design/324 #324①:`memoryDelegationEvidence:"attested-only"` 下,一次静态面本会打的污染标记被豁免。
45
50
  * core 去重单位 = **prepared leg**。`detail: { reason, subagentType?, sessionId? }` */
46
51
  "memory.delegation_static_mark_waived",
52
+ /** design/336 §4/§6.3(core 5.47/5.48 到货,#292 提货批对表入册):**instruction-hold 生命周期**三码。
53
+ * 同族三条都是「这条 session 的记忆此刻处在什么姿态」的披露,与既有三码同一条判据:
54
+ * · core `NOTICE_AUDIENCE` 明列 **"user"**(到货的码级注册表,见本文件顶注的演化机制);
55
+ * · 铸点在 `memoryHoldNotices(report, sessionId)`,`detail.sessionId` 随 harvest 报告一起给 ⇒ 投得出去;
56
+ * · core 去重单位 = **harvest**(检查点收与终局收是两件事),不是 sink ⇒ 上 per-session 流不翻面。
57
+ * `detail: { count, paths, sessionId? }`(paths 已 neutralize + 截 20 条)。 */
58
+ "memory.hold_opened",
59
+ /** 同族:被扣住的 instruction 条目在写者会话干净结算(或宿主阀门放行)后重走全套门并提交。
60
+ * `detail: { count, paths, sessionId? }` */
61
+ "memory.hold_released",
62
+ /** 同族:被扣住的条目移交控制面隔离区。`detail: { count, disposed: [{ path, terminal }], sessionId? }`
63
+ * —— 🔴 `terminal:"expired"` 是**超时不是定罪**(core 铸文逐字如此),消费端不得渲染成裁决语气。 */
64
+ "memory.hold_disposed",
47
65
  ];
48
66
  const WIRE_CODES = new Set(ENGINE_NOTICE_WIRE_CODES);
49
67
  /** 白名单谓词(单点):路由与门都读这一个,不许第二处手抄码串。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sema-agent/server",
3
- "version": "7.37.0",
3
+ "version": "7.38.0-rc.1",
4
4
  "description": "Sema Server — the server/API implementation layer for Sema, wiring core, registry, model providers, and cloud agent execution. Built on @sema-agent/core.",
5
5
  "type": "module",
6
6
  "license": "BUSL-1.1",
@@ -54,8 +54,8 @@
54
54
  "build:binary:run-local:darwin-arm64": "bun build --compile --target=bun-darwin-arm64 src/run-local.ts --outfile dist/run-local-darwin-arm64"
55
55
  },
56
56
  "dependencies": {
57
- "@sema-agent/core": "^5.46.0",
58
- "@sema-agent/registry-core": "^0.18.0",
57
+ "@sema-agent/core": "^5.49.0",
58
+ "@sema-agent/registry-core": "^0.19.0",
59
59
  "e2b": "^2.28.0",
60
60
  "libsodium-wrappers": "^0.8.4",
61
61
  "mysql2": "^3.22.4",