@sema-agent/server 3.23.0 → 3.24.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.
- package/dist/boot/config-center.js +9 -2
- package/dist/config-center/apply-effective.d.ts +4 -18
- package/dist/config-center/apply-effective.js +140 -47
- package/dist/config-center/http-client.d.ts +9 -2
- package/dist/config-center/http-client.js +20 -2
- package/dist/config-provider.js +8 -2
- package/package.json +2 -2
|
@@ -780,7 +780,11 @@ export async function createConfigCenterRuntime(ctx) {
|
|
|
780
780
|
// expanded admission gate while core throws "Unknown model ref" until restart. Hot-apply is safe
|
|
781
781
|
// only when BOTH generations are tier-less.
|
|
782
782
|
const planeDeferred = (runnerTierFrozen || planeHasActiveTiers(r.effective)) && modelPlaneChanged(appliedPlaneEff, r.effective);
|
|
783
|
-
applyEffective(config, r.effective, logger, { teamsOnly: true, sealedKeys, ...(planeDeferred ? { deferModelPlane: true } : {}) });
|
|
783
|
+
const committed = applyEffective(config, r.effective, logger, { teamsOnly: true, sealedKeys, ...(planeDeferred ? { deferModelPlane: true } : {}) });
|
|
784
|
+
// [2283]③:CAS 拒绝(更旧世代)⇒ 本拍整体跳过——prompts 采用/pricing/keyResolver/restart
|
|
785
|
+
// 对账/etag 推进/LKG 落盘都不得从旁路半应用同一个被拒世代(拒绝 warn 已在 applyEffective 留痕)。
|
|
786
|
+
if (!committed)
|
|
787
|
+
return;
|
|
784
788
|
if (planeDeferred) {
|
|
785
789
|
logger.warn("models_tiers_plane_deferred", { version: r.effective.version, note: "tier-frozen Runner: the changed model plane (models/roles/tiers/default) is NOT hot-applied — admission stays on the Runner's generation; restart applies the new plane (models-tiers restart signal rides /health)" });
|
|
786
790
|
}
|
|
@@ -954,7 +958,10 @@ export async function createConfigCenterRuntime(ctx) {
|
|
|
954
958
|
// this late arrival — if it froze a tier-expanded copy, the arriving center plane must not hot-apply
|
|
955
959
|
// (admission/Runner split). Tier-less env boot (the common deferred-boot shape) keeps true hot-apply.
|
|
956
960
|
const planeDeferredLate = (runnerTierFrozen || planeHasActiveTiers(r.effective)) && modelPlaneChanged(appliedPlaneEff, r.effective);
|
|
957
|
-
applyEffective(config, r.effective, logger, { teamsOnly: true, sealedKeys, ...(planeDeferredLate ? { deferModelPlane: true } : {}) });
|
|
961
|
+
const committedLate = applyEffective(config, r.effective, logger, { teamsOnly: true, sealedKeys, ...(planeDeferredLate ? { deferModelPlane: true } : {}) });
|
|
962
|
+
// [2283]③(refresh 腿同款):CAS 拒绝 ⇒ 迟到 boot 拍整体跳过,旁路消费与 etag/LKG 都不动。
|
|
963
|
+
if (!committedLate)
|
|
964
|
+
return;
|
|
958
965
|
if (planeDeferredLate)
|
|
959
966
|
logger.warn("models_tiers_plane_deferred", { version: r.effective.version, note: "tier-frozen Runner (env tiers): the late-boot center model plane is NOT hot-applied — restart applies it" });
|
|
960
967
|
else {
|
|
@@ -8,11 +8,14 @@ import type { EffectiveConfig } from "./types.js";
|
|
|
8
8
|
* `this.deps.models/roles/pricing` LIVE per-task and `/v1/models` reads `config.models` — both share the
|
|
9
9
|
* reference captured at boot, so mutating it (vs reassigning) updates both with no split, no Runner rebuild. */
|
|
10
10
|
export declare function mutateInPlace<V>(target: Record<string, V>, source: Record<string, V>): void;
|
|
11
|
+
/** 返回值=是否 COMMIT(false 仅在 [2283]③ 世代序 CAS 拒绝时)。caller 收到 false 必须把**同一世代的
|
|
12
|
+
* 旁路消费**(prompts 采用/pricing/keyResolver/etag 推进/LKG 落盘)一并跳过——否则 applyEffective 拒了
|
|
13
|
+
* 主面、旁路却半应用同一个被拒世代,混合世代从侧门回来。首次 apply(live 未登记)恒 true。 */
|
|
11
14
|
export declare function applyEffective(config: ServiceConfig, eff: EffectiveConfig, logger?: Logger, opts?: {
|
|
12
15
|
teamsOnly?: boolean;
|
|
13
16
|
sealedKeys?: SealedKeyOpener;
|
|
14
17
|
deferModelPlane?: boolean;
|
|
15
|
-
}):
|
|
18
|
+
}): boolean;
|
|
16
19
|
/**
|
|
17
20
|
* Apply the center `runtime` governance/limit gates OVER the env-derived config (mutates `config`).
|
|
18
21
|
*
|
|
@@ -42,23 +45,6 @@ export type RuntimeGateKey = (typeof RUNTIME_GATE_KEYS)[number];
|
|
|
42
45
|
* divides by it; center's `.positive()` already enforces, belt-and-suspenders here). */
|
|
43
46
|
export declare function runtimeGatePresent(rt: NonNullable<EffectiveConfig["runtime"]>, key: RuntimeGateKey): boolean;
|
|
44
47
|
export declare function applyRuntimeGates(config: ServiceConfig, rt: EffectiveConfig["runtime"], logger?: Logger): void;
|
|
45
|
-
/**
|
|
46
|
-
* Apply the runtime governance "second baton" (center §10): `autonomy` + `commandPolicy`. UNLIKE the 6 gates in
|
|
47
|
-
* {@link applyRuntimeGates}, these are per-request HOT (read live in main.ts `resolveSpec` via
|
|
48
|
-
* `applyRuntimeGovernance`), so they apply on BOTH boot and refresh (NOT via RUNTIME_GATE_KEYS / restart-to-apply).
|
|
49
|
-
*
|
|
50
|
-
* 🔴 NON-STICKY (differs from the restart-to-apply gates on purpose — adversarial-review HIGH): a hot field that
|
|
51
|
-
* center STOPS publishing must REVERT to the env baseline, not keep the last center value. The restart-to-apply
|
|
52
|
-
* gates can be sticky because a refresh never touches them (the running middleware holds boot values until a
|
|
53
|
-
* restart re-reads env+center); a HOT field has no such reset, so "absent ⇒ keep" would silently freeze a stale
|
|
54
|
-
* center override (e.g. center published `auto`, then un-published it — the gate would stay OFF forever). So we
|
|
55
|
-
* recompute every call as `present ? center : envBaseline`. The env baseline = `AUTONOMY` (re-derived, env is
|
|
56
|
-
* immutable at runtime) for autonomy; `undefined` (no env scalar source) for commandPolicy.
|
|
57
|
-
*
|
|
58
|
-
* 🔴 commandPolicy is VALIDATED here (adversarial-review HIGH): an invalid command (glob/path/operator — which
|
|
59
|
-
* core's EXACT-name matcher would silently never match → a hole) is rejected FAIL-LOUD and the prior good policy
|
|
60
|
-
* is KEPT (a broken publish never half-applies a silently-weakened gate).
|
|
61
|
-
*/
|
|
62
48
|
export declare function applyRuntimeHot(config: ServiceConfig, rt: EffectiveConfig["runtime"], logger?: Logger): void;
|
|
63
49
|
/**
|
|
64
50
|
* [865]① 显式默认解析——applyEffective 与 dry-run(logEffectiveDiff.wouldDefaultModel)共用的单源。优先级
|
|
@@ -78,7 +78,74 @@ export function mutateInPlace(target, source) {
|
|
|
78
78
|
delete target[k];
|
|
79
79
|
Object.assign(target, source);
|
|
80
80
|
}
|
|
81
|
+
/** 每个 config 对象上一次 COMMIT 的世代号([2283]③ CAS 的 live 端)。WeakMap——config 回收即回收;
|
|
82
|
+
* version 0(未发布/本地一次性 lane)不参与登记。 */
|
|
83
|
+
const appliedGeneration = new WeakMap();
|
|
84
|
+
/** 返回值=是否 COMMIT(false 仅在 [2283]③ 世代序 CAS 拒绝时)。caller 收到 false 必须把**同一世代的
|
|
85
|
+
* 旁路消费**(prompts 采用/pricing/keyResolver/etag 推进/LKG 落盘)一并跳过——否则 applyEffective 拒了
|
|
86
|
+
* 主面、旁路却半应用同一个被拒世代,混合世代从侧门回来。首次 apply(live 未登记)恒 true。 */
|
|
81
87
|
export function applyEffective(config, eff, logger, opts = {}) {
|
|
88
|
+
const staged = stageEffective(config, eff, logger, opts);
|
|
89
|
+
const live = appliedGeneration.get(config);
|
|
90
|
+
if (staged.version > 0 && live !== undefined && staged.version < live) {
|
|
91
|
+
// [2283]③:两次拉取的 staging 并发/乱序完成时,慢的旧世代不得整体覆盖快的新世代——每次都是
|
|
92
|
+
// 「整世代」,但方向反了。拒绝必须留痕(C6);caller 的 etag 纪律本就只在 apply 成功后推进,
|
|
93
|
+
// 下一拍拉到的自然是更新的世代。等版本重放(etag 未推进的幂等重放)照常放行。
|
|
94
|
+
logger?.warn("sema_registry_stale_generation_refused", { staged: staged.version, live, note: "an older staged generation must not overwrite a newer committed one — refused whole; next poll replays" });
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
commitStaged(config, staged);
|
|
98
|
+
// ── post-commit notifications(全部世代描述性通知在最后一笔赋值之后,[2283]②)──
|
|
99
|
+
if (staged.modelPlane)
|
|
100
|
+
logger?.info("sema_registry_models", staged.modelPlane.infoLine);
|
|
101
|
+
if (staged.gatesInfo)
|
|
102
|
+
logger?.info("sema_registry_runtime", staged.gatesInfo);
|
|
103
|
+
if (Object.keys(staged.hot.infoLine).length > 0)
|
|
104
|
+
logger?.info("sema_registry_runtime_hot", staged.hot.infoLine);
|
|
105
|
+
for (const n of staged.teamsPlane?.notices ?? []) {
|
|
106
|
+
if (n.level === "warn")
|
|
107
|
+
logger?.warn(n.msg, n.fields);
|
|
108
|
+
else
|
|
109
|
+
logger?.info(n.msg, n.fields);
|
|
110
|
+
}
|
|
111
|
+
if (Object.keys(staged.projects).length > 0)
|
|
112
|
+
logger?.info("sema_registry_projects", { projects: Object.keys(staged.projects) });
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
/** COMMIT 段:纯赋值,零 await/零回调/零发射(源码钉守着——[2283]①②)。mutateInPlace/整对象重赋值/
|
|
116
|
+
* registry 表整体换装(registerTeams/registerCollabWorkflows 皆为过滤+swap 的赋值形,无回调面)。 */
|
|
117
|
+
function commitStaged(config, staged) {
|
|
118
|
+
const mp = staged.modelPlane;
|
|
119
|
+
if (mp) {
|
|
120
|
+
config.modelApiKeyEnv = mp.modelApiKeyEnv; // reassign ok — keyResolver is rebuilt from it on refresh (main.ts)
|
|
121
|
+
config.modelApiKeys = mp.modelApiKeys; // plaintext values — memory-only; poison markers ride the same map
|
|
122
|
+
mutateInPlace(config.modelQuotaWeights, mp.quotaWeights);
|
|
123
|
+
mutateInPlace(config.models, mp.models); // IN PLACE: keep the ref the Runner + /v1/models share (hot-apply)
|
|
124
|
+
config.model = config.models.default;
|
|
125
|
+
if (Object.keys(mp.roles).length > 0)
|
|
126
|
+
mutateInPlace(config.roles, mp.roles); // IN PLACE: Runner reads this.deps.roles live
|
|
127
|
+
mutateInPlace(config.tiers, mp.activeTiers);
|
|
128
|
+
}
|
|
129
|
+
if (staged.gateAssignments) {
|
|
130
|
+
for (const [k, v] of staged.gateAssignments)
|
|
131
|
+
config[k] = v;
|
|
132
|
+
}
|
|
133
|
+
if (staged.hot.setAutonomy)
|
|
134
|
+
config.autonomy = staged.hot.autonomyNext;
|
|
135
|
+
if (staged.hot.setCommandPolicy)
|
|
136
|
+
config.commandPolicy = staged.hot.commandPolicyNext;
|
|
137
|
+
const tp = staged.teamsPlane;
|
|
138
|
+
if (tp) {
|
|
139
|
+
registerTeams(tp.teams);
|
|
140
|
+
registerCollabWorkflows(tp.workflows);
|
|
141
|
+
}
|
|
142
|
+
mutateInPlace(config.projects, staged.projects); // IN PLACE: keep the ref per-request consumers captured at boot
|
|
143
|
+
if (staged.version > 0)
|
|
144
|
+
appliedGeneration.set(config, staged.version);
|
|
145
|
+
}
|
|
146
|
+
/** STAGE 段:一切计算/校验/解封/投影(可抛;抛=候选整体拒绝,活配置零触碰)。内容判定性 warn/error
|
|
147
|
+
* (描述 eff 真伪,与是否 commit 无关)在此发;世代描述性 info 只装载荷,post-commit 发。 */
|
|
148
|
+
function stageEffective(config, eff, logger, opts) {
|
|
82
149
|
// version 0 / empty effective = the config-center has nothing for us yet — typically CONFIG_PUBLISH_MODE
|
|
83
150
|
// is ON but nothing has been published. We do NOT wipe: models/roles fall back to env (the enabled>0
|
|
84
151
|
// guard below), teams to BUILTIN_TEAMS (registerTeams resets to built-ins). Warn once at boot so the
|
|
@@ -96,6 +163,7 @@ export function applyEffective(config, eff, logger, opts = {}) {
|
|
|
96
163
|
// split, no Runner rebuild, no core change. Caller (main.ts refresh) additionally refreshes `pricing` (same
|
|
97
164
|
// ref) + rebuilds `keyResolver`. (Was startup-only when reassignment split the Runner's ref from config.)
|
|
98
165
|
const enabled = (eff.models?.models ?? []).filter((m) => m.enabled !== false);
|
|
166
|
+
let modelPlane;
|
|
99
167
|
// codex R10: `deferModelPlane` skips the WHOLE model plane (models/roles/tiers + per-model keys) — main.ts
|
|
100
168
|
// sets it when the Runner is tier-frozen (private expanded copy) and the plane changed: hot-applying would
|
|
101
169
|
// split admission (/v1/models, catalog gates) from the Runner's frozen generation, letting a same-key retarget
|
|
@@ -189,11 +257,6 @@ export function applyEffective(config, eff, logger, opts = {}) {
|
|
|
189
257
|
logger?.warn("sema_registry_model_no_brain", { model: m.name, provider: m.provider, hint: "set ANTHROPIC_API_KEY in this service's env, else it mis-routes to the gateway brain" });
|
|
190
258
|
}
|
|
191
259
|
}
|
|
192
|
-
config.modelApiKeyEnv = modelApiKeyEnv; // reassign ok — keyResolver is rebuilt from it on refresh (main.ts)
|
|
193
|
-
// same rebuild contract; plaintext values — memory-only, never logged. Poison markers ride the same
|
|
194
|
-
// map (they ARE per-model key state: "configured but broken"); the cast bridges config.ts's
|
|
195
|
-
// plaintext-only field type until it is widened to Record<string, string | SealedKeyPoison>.
|
|
196
|
-
config.modelApiKeys = modelApiKeys; // 类型已放真(string | SealedKeyPoison),桥接 cast 退役
|
|
197
260
|
// weight-at-burn 源:quotaWeight 按 name+id 双键索引(tracer 的 brain.call e.model=模型 id,
|
|
198
261
|
// 目录键=name——双键免猜);非法值(≤0/NaN)按缺省 1 丢弃。IN PLACE 与 models 同批 hot-apply。
|
|
199
262
|
const quotaWeights = {};
|
|
@@ -205,7 +268,6 @@ export function applyEffective(config, eff, logger, opts = {}) {
|
|
|
205
268
|
quotaWeights[m.id] = qw;
|
|
206
269
|
}
|
|
207
270
|
}
|
|
208
|
-
mutateInPlace(config.modelQuotaWeights, quotaWeights);
|
|
209
271
|
const roles = {};
|
|
210
272
|
for (const [role, tgt] of Object.entries(eff.models.roles ?? {})) {
|
|
211
273
|
if ("model" in tgt)
|
|
@@ -225,15 +287,16 @@ export function applyEffective(config, eff, logger, opts = {}) {
|
|
|
225
287
|
// 静默翻转,default 必须消费 wire 里已有的显式意图。解析单源 = resolveDefaultModelName(dry-run 的
|
|
226
288
|
// wouldDefaultModel 共用同一只,报数与真 apply 永不撕裂——codex M2)。
|
|
227
289
|
const picked = resolveDefaultModelName(eff, (n) => models[n] !== undefined, enabled[0].name, (source, name) => logger?.warn("sema_registry_default_dangling", { source, name, hint: "explicit default names a model that is not in the enabled catalog — falling to the next source" }));
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
290
|
+
models.default = models[picked.name];
|
|
291
|
+
modelPlane = {
|
|
292
|
+
models,
|
|
293
|
+
modelApiKeyEnv,
|
|
294
|
+
modelApiKeys,
|
|
295
|
+
quotaWeights,
|
|
296
|
+
roles,
|
|
297
|
+
activeTiers,
|
|
298
|
+
infoLine: { count: enabled.length, default: models.default.id, defaultSource: picked.source, roles: Object.keys(roles), tiers: Object.keys(activeTiers), sealedKeys: Object.values(modelApiKeys).filter((v) => typeof v === "string").length, sealedPoisoned: Object.values(modelApiKeys).filter((v) => typeof v !== "string").length },
|
|
299
|
+
};
|
|
237
300
|
}
|
|
238
301
|
// Runtime governance/limit gates (phase-2): STARTUP only (restart-to-apply) — the live RateLimiter / CostQuota
|
|
239
302
|
// / approval gate are built from `config` AFTER this in main.ts, so mutating it here before they're constructed
|
|
@@ -241,18 +304,18 @@ export function applyEffective(config, eff, logger, opts = {}) {
|
|
|
241
304
|
// governance 切新位:治理三件优先读 governance 域(真值),runtime 旧位(双写镜像)fallback——
|
|
242
305
|
// 双写期两处逐键相等语义不变;center 撤双写后 governance 即唯一来源。限额残余(rateLimit/cost 五件)仍在 runtime。
|
|
243
306
|
const gatesView = eff.governance ? { ...eff.runtime, ...eff.governance } : eff.runtime;
|
|
244
|
-
|
|
245
|
-
applyRuntimeGates(config, gatesView, logger);
|
|
307
|
+
const gates = opts.teamsOnly ? undefined : stageRuntimeGates(gatesView);
|
|
246
308
|
// Runtime governance "second baton" (center §10): autonomy + commandPolicy are per-request HOT (read live in
|
|
247
309
|
// resolveSpec), NOT baked into boot middleware → apply on BOTH boot and refresh (outside the teamsOnly guard) so
|
|
248
310
|
// they hot-reload. No restart-to-apply signal (they take effect on the next task without a restart).
|
|
249
|
-
|
|
311
|
+
const hot = stageRuntimeHot(config, gatesView, logger);
|
|
250
312
|
// Teams → registry (hot-reloadable; center overrides/extends the built-ins).
|
|
251
313
|
// codex R11: teams + collab workflows carry MODEL REFERENCES (member.model / workflow model args) — when the
|
|
252
314
|
// model plane is deferred (tier-frozen Runner, see the deferModelPlane guard above) these faces must defer
|
|
253
315
|
// WITH it, or a candidate that atomically adds/retargets a model AND updates a team/workflow to reference it
|
|
254
316
|
// publishes a mixed generation: the new template goes live while config.models/the Runner stay old (a new ref
|
|
255
317
|
// fails as unknown; a same-name retarget silently executes stale). One catalog generation = one visibility.
|
|
318
|
+
let teamsPlane;
|
|
256
319
|
if (opts.deferModelPlane !== true) {
|
|
257
320
|
const teams = {};
|
|
258
321
|
for (const t of (eff.teams?.teams ?? []).filter((t) => t.enabled !== false)) {
|
|
@@ -265,22 +328,22 @@ export function applyEffective(config, eff, logger, opts = {}) {
|
|
|
265
328
|
synthesizer: t.synthesizer ? { role: t.synthesizer.role, modelRole: t.synthesizer.modelRole, systemPrompt: t.synthesizer.systemPrompt } : undefined,
|
|
266
329
|
};
|
|
267
330
|
}
|
|
268
|
-
registerTeams(teams);
|
|
269
|
-
if (Object.keys(teams).length > 0)
|
|
270
|
-
logger?.info("sema_registry_teams", { teams: Object.keys(teams) });
|
|
271
331
|
// collab → named-workflow projection(切片 1.5,design/140 统一解;切片① 的
|
|
272
332
|
// TeamTemplate 投影已整体替换——纪律「别留双路径降级」)。可投影子集翻译成命名 workflow 注册条目
|
|
273
333
|
// (执行体=core 内置 team-discussion 脚本,center 模板=defaultArgs 合并链第二级;键=collab id,shell
|
|
274
334
|
// `/team`/LLM 经 Workflow({name}) 调用);子集外整条跳过+结构化上报,绝不静默降级。HOT:boot+refresh
|
|
275
|
-
// 双腿整表替换(非粘——center 停发即空表,内置 workflow 不受影响)。
|
|
335
|
+
// 双腿整表替换(非粘——center 停发即空表,内置 workflow 不受影响)。register* 在 commit 段成对换装。
|
|
276
336
|
const projected = projectCollabToWorkflows(eff.collab?.templates);
|
|
277
|
-
|
|
337
|
+
const notices = [];
|
|
338
|
+
if (Object.keys(teams).length > 0)
|
|
339
|
+
notices.push({ level: "info", msg: "sema_registry_teams", fields: { teams: Object.keys(teams) } });
|
|
278
340
|
if (Object.keys(projected.workflows).length > 0)
|
|
279
|
-
|
|
341
|
+
notices.push({ level: "info", msg: "sema_registry_collab_workflows", fields: { workflows: Object.keys(projected.workflows) } });
|
|
280
342
|
if (projected.skipped.length > 0)
|
|
281
|
-
|
|
343
|
+
notices.push({ level: "warn", msg: "sema_registry_collab_skipped", fields: { skipped: projected.skipped } });
|
|
282
344
|
if (projected.notes.length > 0)
|
|
283
|
-
|
|
345
|
+
notices.push({ level: "info", msg: "sema_registry_collab_notes", fields: { notes: projected.notes } });
|
|
346
|
+
teamsPlane = { teams, workflows: projected.workflows, notices };
|
|
284
347
|
}
|
|
285
348
|
// 142-S4 projects 域(registry-core 0.10.0):center 项目登记簿 → config.projects(键=
|
|
286
349
|
// projectId)。消费是 per-request 查表(memoryScope 派生 + defaultScopes 种子,security.ts/main.ts),
|
|
@@ -304,9 +367,14 @@ export function applyEffective(config, eff, logger, opts = {}) {
|
|
|
304
367
|
...(Array.isArray(r.defaultScopes) ? { defaultScopes: r.defaultScopes.filter((x) => typeof x === "string") } : {}),
|
|
305
368
|
};
|
|
306
369
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
370
|
+
return {
|
|
371
|
+
version: typeof eff.version === "number" && Number.isFinite(eff.version) ? eff.version : 0,
|
|
372
|
+
...(modelPlane !== undefined ? { modelPlane } : {}),
|
|
373
|
+
...(gates !== undefined ? { gateAssignments: gates.assignments, ...(gates.info !== undefined ? { gatesInfo: gates.info } : {}) } : {}),
|
|
374
|
+
hot,
|
|
375
|
+
...(teamsPlane !== undefined ? { teamsPlane } : {}),
|
|
376
|
+
projects,
|
|
377
|
+
};
|
|
310
378
|
}
|
|
311
379
|
/**
|
|
312
380
|
* Apply the center `runtime` governance/limit gates OVER the env-derived config (mutates `config`).
|
|
@@ -342,18 +410,28 @@ export function runtimeGatePresent(rt, key) {
|
|
|
342
410
|
return typeof v === "number" && v > 0;
|
|
343
411
|
return typeof v === "number";
|
|
344
412
|
}
|
|
345
|
-
|
|
413
|
+
/** [2283] stage 半场:六闸的赋值清单(纯计算,零变异)。commit 段照单赋值,通知载荷 post-commit 发。 */
|
|
414
|
+
function stageRuntimeGates(rt) {
|
|
346
415
|
if (!rt)
|
|
347
|
-
return;
|
|
416
|
+
return { assignments: [] };
|
|
417
|
+
const assignments = [];
|
|
348
418
|
const applied = {};
|
|
349
419
|
for (const key of RUNTIME_GATE_KEYS) {
|
|
350
420
|
if (!runtimeGatePresent(rt, key))
|
|
351
421
|
continue; // undefined / sentinel → keep env
|
|
352
|
-
|
|
422
|
+
assignments.push([key, rt[key]]); // present (incl. explicit 0/[]) → override
|
|
353
423
|
applied[key] = rt[key];
|
|
354
424
|
}
|
|
355
|
-
|
|
356
|
-
|
|
425
|
+
return { assignments, ...(Object.keys(applied).length > 0 ? { info: applied } : {}) };
|
|
426
|
+
}
|
|
427
|
+
export function applyRuntimeGates(config, rt, logger) {
|
|
428
|
+
// 独立调用面的兼容壳(测试/外部):stage → 就地赋值 → 通知。applyEffective 不走这里——它把
|
|
429
|
+
// assignments 并进自己的 commit 段以保住整世代原子性([2283]②)。
|
|
430
|
+
const s = stageRuntimeGates(rt);
|
|
431
|
+
for (const [k, v] of s.assignments)
|
|
432
|
+
config[k] = v;
|
|
433
|
+
if (s.info)
|
|
434
|
+
logger?.info("sema_registry_runtime", s.info);
|
|
357
435
|
}
|
|
358
436
|
/**
|
|
359
437
|
* Apply the runtime governance "second baton" (center §10): `autonomy` + `commandPolicy`. UNLIKE the 6 gates in
|
|
@@ -372,34 +450,49 @@ export function applyRuntimeGates(config, rt, logger) {
|
|
|
372
450
|
* core's EXACT-name matcher would silently never match → a hole) is rejected FAIL-LOUD and the prior good policy
|
|
373
451
|
* is KEPT (a broken publish never half-applies a silently-weakened gate).
|
|
374
452
|
*/
|
|
375
|
-
|
|
376
|
-
|
|
453
|
+
/** [2283] stage 半场:hot 二件的赋值决定(计算+校验;`sema_registry_commandpolicy_invalid` 是内容判定,
|
|
454
|
+
* stage 期发——它描述 eff 的真伪,与是否 commit 无关)。对比基准=stage 时刻的 config 现值:stage 与
|
|
455
|
+
* commit 同一同步 tick,期间无人能改 config(单线程),对比不失效。 */
|
|
456
|
+
function stageRuntimeHot(config, rt, logger) {
|
|
457
|
+
const infoLine = {};
|
|
377
458
|
// autonomy: present ⇒ center value; absent ⇒ revert to the env baseline (never a stale center override).
|
|
378
459
|
const envAutonomy = parseAutonomy(process.env.AUTONOMY);
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
460
|
+
const autonomyNext = rt?.autonomy !== undefined ? rt.autonomy : envAutonomy;
|
|
461
|
+
const setAutonomy = config.autonomy !== autonomyNext;
|
|
462
|
+
if (setAutonomy)
|
|
463
|
+
infoLine.autonomy = autonomyNext ?? "(env-baseline)";
|
|
384
464
|
// commandPolicy: present+valid ⇒ apply; present+invalid ⇒ fail-loud + keep prior; absent ⇒ revert to baseline
|
|
385
465
|
// (undefined — no env scalar source for structured command rules). Only re-set + log on an ACTUAL change
|
|
386
466
|
// (deep-equal compare) — refresh runs every ~60s and the policy is usually unchanged; logging every tick = noise.
|
|
467
|
+
let setCommandPolicy = false;
|
|
468
|
+
let commandPolicyNext;
|
|
387
469
|
if (rt?.commandPolicy !== undefined) {
|
|
388
470
|
const errors = validateCommandRules(rt.commandPolicy);
|
|
389
471
|
if (errors.length > 0) {
|
|
390
472
|
logger?.error("sema_registry_commandpolicy_invalid", { errors, kept: config.commandPolicy?.length ?? 0 });
|
|
391
473
|
}
|
|
392
474
|
else if (JSON.stringify(config.commandPolicy) !== JSON.stringify(rt.commandPolicy)) {
|
|
393
|
-
|
|
394
|
-
|
|
475
|
+
setCommandPolicy = true;
|
|
476
|
+
commandPolicyNext = rt.commandPolicy;
|
|
477
|
+
infoLine.commandPolicy = rt.commandPolicy.length; // log the COUNT, not the rules (avoid leaking on every refresh)
|
|
395
478
|
}
|
|
396
479
|
}
|
|
397
480
|
else if (config.commandPolicy !== undefined) {
|
|
398
|
-
|
|
399
|
-
|
|
481
|
+
setCommandPolicy = true;
|
|
482
|
+
commandPolicyNext = undefined; // center stopped managing → revert to baseline (no env source)
|
|
483
|
+
infoLine.commandPolicy = "(env-baseline)";
|
|
400
484
|
}
|
|
401
|
-
|
|
402
|
-
|
|
485
|
+
return { setAutonomy, autonomyNext, setCommandPolicy, commandPolicyNext, infoLine };
|
|
486
|
+
}
|
|
487
|
+
export function applyRuntimeHot(config, rt, logger) {
|
|
488
|
+
// 独立调用面的兼容壳(测试/外部)——applyEffective 不走这里(同 applyRuntimeGates 的注)。
|
|
489
|
+
const s = stageRuntimeHot(config, rt, logger);
|
|
490
|
+
if (s.setAutonomy)
|
|
491
|
+
config.autonomy = s.autonomyNext;
|
|
492
|
+
if (s.setCommandPolicy)
|
|
493
|
+
config.commandPolicy = s.commandPolicyNext;
|
|
494
|
+
if (Object.keys(s.infoLine).length > 0)
|
|
495
|
+
logger?.info("sema_registry_runtime_hot", s.infoLine);
|
|
403
496
|
}
|
|
404
497
|
/** [865]①/H3:activeTierGroup 档绑定当默认时的档梯,与 core 单一语义源逐字对齐(core roles.js:
|
|
405
498
|
* `ROLE_TIER_DEFAULTS.default = "pro"` + `resolveTier` 从本档位置**只向低档**扫 DEFAULT_TIER_ORDER
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EntitlementRuntimeCaps } from "@sema-agent/registry-core";
|
|
2
2
|
import type { ScenarioRuling } from "../capabilities/scenarios.js";
|
|
3
3
|
import type { EffectiveConfig, ExecutionRuling } from "./types.js";
|
|
4
|
-
/** GET the effective config (Bearer + ETag). null = 304 (unchanged). Throws on transport/HTTP error
|
|
4
|
+
/** GET the effective config (Bearer + ETag). null = 304 (unchanged). Throws on transport/HTTP error, and on a
|
|
5
|
+
* payload that is not an effective config at all(非对象 / version 非有限数 / gate 域坏形——[2281] 裁B)。
|
|
6
|
+
* `domainErrors`:坏 catalog 域(schema default 已落)逐域单列——与本地腿 `FetchEffectiveResult` 同键同义,
|
|
7
|
+
* boot/refresh 的候选门直接消费。 */
|
|
5
8
|
export declare function fetchEffective(baseUrl: string, token: string, etag: string | undefined, fetchImpl?: typeof fetch, worker?: string): Promise<{
|
|
6
9
|
effective: EffectiveConfig;
|
|
7
10
|
etag?: string;
|
|
11
|
+
domainErrors?: Array<{
|
|
12
|
+
domain: string;
|
|
13
|
+
error: string;
|
|
14
|
+
}>;
|
|
8
15
|
} | null>;
|
|
9
16
|
/**
|
|
10
17
|
* design/99 §K (core 1.157 `RunnerDeps.runtimeCapsResolver`) — GET the PER-PRINCIPAL runtime
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* facade re-exports every symbol below unchanged).
|
|
6
6
|
*/
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
|
-
|
|
8
|
+
import { readEffectiveWire } from "@sema-agent/registry-core";
|
|
9
|
+
/** GET the effective config (Bearer + ETag). null = 304 (unchanged). Throws on transport/HTTP error, and on a
|
|
10
|
+
* payload that is not an effective config at all(非对象 / version 非有限数 / gate 域坏形——[2281] 裁B)。
|
|
11
|
+
* `domainErrors`:坏 catalog 域(schema default 已落)逐域单列——与本地腿 `FetchEffectiveResult` 同键同义,
|
|
12
|
+
* boot/refresh 的候选门直接消费。 */
|
|
9
13
|
export async function fetchEffective(baseUrl, token, etag, fetchImpl = fetch, worker) {
|
|
10
14
|
// Defensive scheme guard: Node's fetch supports file:// — a mis-set
|
|
11
15
|
// SEMA_REGISTRY_URL must not turn into a local-file read. Reject anything but http(s).
|
|
@@ -23,7 +27,21 @@ export async function fetchEffective(baseUrl, token, etag, fetchImpl = fetch, wo
|
|
|
23
27
|
return null;
|
|
24
28
|
if (!res.ok)
|
|
25
29
|
throw new Error(`config-center HTTP ${res.status}`);
|
|
26
|
-
|
|
30
|
+
// [2281] 裁B(§M1):wire 载荷在**这个消费端边界**过 registry-core `readEffectiveWire`(0.12.0)真校验,
|
|
31
|
+
// 不再裸断言——「两个契约共用一个拼写不是一个被检查的契约」。判据与本地腿同源(parseDomain +
|
|
32
|
+
// DOMAIN_READ_FALLBACK):catalog 域坏形 → 该域 schema default + 下面折进 domainErrors(候选门在
|
|
33
|
+
// refresh 拒候选、boot 逐域 warn);gate 域坏形/垃圾载荷 → throw(caller 整包 catch 回落 env/LKG)。
|
|
34
|
+
// 未知顶层键 verbatim 透传(open-world:新 center 新域、legacy teams 键都不丢)。grandfather 类
|
|
35
|
+
// 警告(值已被收编接受)不算 error,不进 domainErrors——与本地店同口径。
|
|
36
|
+
const warnings = [];
|
|
37
|
+
const wire = readEffectiveWire(await res.json(), (w) => warnings.push(w));
|
|
38
|
+
const domainErrors = warnings
|
|
39
|
+
.filter((w) => w.kind === "domain-defaulted")
|
|
40
|
+
.map((w) => ({ domain: w.domain, error: (w.error instanceof Error ? w.error.message : String(w.error)).slice(0, 600) }));
|
|
41
|
+
// 经真校验后的 wire 值到 service 拼写副本的换装:两型同一契约面(EffectiveWire 是 service 型的同源超集,
|
|
42
|
+
// service 型只声明自己消费的域且全 optional)——此断言的前提正是上面那次校验,不再是裸信任。
|
|
43
|
+
const effective = wire;
|
|
44
|
+
return { effective, etag: res.headers.get("etag") ?? undefined, ...(domainErrors.length > 0 ? { domainErrors } : {}) };
|
|
27
45
|
}
|
|
28
46
|
/**
|
|
29
47
|
* design/99 §K (core 1.157 `RunnerDeps.runtimeCapsResolver`) — GET the PER-PRINCIPAL runtime
|
package/dist/config-provider.js
CHANGED
|
@@ -91,10 +91,16 @@ export class RemoteConfigProvider {
|
|
|
91
91
|
this.cc = cc;
|
|
92
92
|
this.deps = deps;
|
|
93
93
|
}
|
|
94
|
-
fetchEffective(etag) {
|
|
94
|
+
async fetchEffective(etag) {
|
|
95
95
|
const fn = this.deps.fetchEffective ?? remoteFetchEffective;
|
|
96
96
|
// 5th arg = worker scope; transport (fetchImpl) stays the config-center's default.
|
|
97
|
-
|
|
97
|
+
const r = await fn(this.cc.baseUrl, this.cc.token, etag, undefined, this.cc.worker);
|
|
98
|
+
if (r === null || r.domainErrors === undefined)
|
|
99
|
+
return r;
|
|
100
|
+
// [2281] 裁B:远程腿从此也产 domainErrors(http-client 消费端校验)。与本地腿同一条产出边界纪律:
|
|
101
|
+
// error 文本先过 redactConfigError(zod 错误会回声违规值——operand 指纹化,防受控值经
|
|
102
|
+
// config_candidate_rejected/config_domain_invalid 进结构化日志流)。
|
|
103
|
+
return { ...r, domainErrors: r.domainErrors.map((de) => ({ domain: de.domain, error: redactConfigError(de.error) })) };
|
|
98
104
|
}
|
|
99
105
|
async fetchSkillContent(contentHash) {
|
|
100
106
|
const fn = this.deps.fetchSkillContent ?? remoteFetchSkillContent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sema-agent/server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.24.0",
|
|
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",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@sema-agent/core": "^2.13.0",
|
|
58
|
-
"@sema-agent/registry-core": "^0.
|
|
58
|
+
"@sema-agent/registry-core": "^0.12.0",
|
|
59
59
|
"e2b": "^2.28.0",
|
|
60
60
|
"libsodium-wrappers": "^0.8.4",
|
|
61
61
|
"mysql2": "^3.22.4",
|