@sema-agent/server 7.131.0 → 7.132.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/MIGRATION.md +309 -0
- package/README.md +5 -1
- package/README.zh-CN.md +3 -1
- package/USAGE.md +163 -54
- package/dist/approval-card.d.ts +3 -1
- package/dist/approval-card.js +2 -3
- package/dist/audit.d.ts +7 -10
- package/dist/auth-bridge.d.ts +4 -0
- package/dist/auth-bridge.js +10 -11
- package/dist/boot/deployment-mods.d.ts +31 -0
- package/dist/boot/deployment-mods.js +26 -0
- package/dist/boot/execution-env.d.ts +1 -1
- package/dist/boot/execution-env.js +19 -6
- package/dist/boot/memory-boundary.d.ts +2 -2
- package/dist/boot/read-deny-anchor-audit.d.ts +17 -0
- package/dist/boot/read-deny-anchor-audit.js +36 -0
- package/dist/boot/resolve-spec.d.ts +1 -5
- package/dist/boot/resolve-spec.js +19 -47
- package/dist/boot/runner-deps.d.ts +19 -8
- package/dist/boot/runner-deps.js +14 -2
- package/dist/boot/session-faces.d.ts +1 -7
- package/dist/boot/stage-03-store-backend.d.ts +1 -1
- package/dist/boot/stage-03-store-backend.js +2 -2
- package/dist/boot/stage-04-stores.d.ts +1 -1
- package/dist/boot/stage-05-execution-env.d.ts +4 -4
- package/dist/boot/stage-05-execution-env.js +7 -10
- package/dist/boot/stage-06-runners.d.ts +2 -2
- package/dist/boot/stage-06-runners.js +5 -4
- package/dist/boot/stage-07-capability-layer.d.ts +2 -2
- package/dist/boot/stage-07-capability-layer.js +3 -3
- package/dist/boot/stage-08-reapers.d.ts +2 -2
- package/dist/boot/stage-09-leader.d.ts +3 -9
- package/dist/boot/stage-10-http-server.d.ts +3 -9
- package/dist/boot/stage-10-http-server.js +6 -7
- package/dist/boot/stores.d.ts +1 -1
- package/dist/boot/stores.js +5 -6
- package/dist/boot/web-admin.d.ts +0 -3
- package/dist/boot/web-admin.js +35 -35
- package/dist/brain.js +17 -22
- package/dist/budget.js +5 -4
- package/dist/caller-text-echo.d.ts +20 -0
- package/dist/caller-text-echo.js +24 -0
- package/dist/capabilities/brand-identity.d.ts +26 -0
- package/dist/capabilities/brand-identity.js +27 -0
- package/dist/capabilities/center-plugins.js +1 -1
- package/dist/capabilities/center-prompts.d.ts +32 -59
- package/dist/capabilities/center-prompts.js +18 -32
- package/dist/capabilities/engine-capabilities.js +2 -1
- package/dist/capabilities/hands-lane.d.ts +9 -6
- package/dist/capabilities/hands-lane.js +1 -1
- package/dist/capabilities/mcp-probe.d.ts +14 -1
- package/dist/capabilities/mcp-probe.js +22 -133
- package/dist/capabilities/scenarios.d.ts +34 -40
- package/dist/capabilities/scenarios.js +16 -33
- package/dist/capabilities/skills.d.ts +19 -4
- package/dist/capabilities/skills.js +30 -10
- package/dist/config-catalog.js +6 -6
- package/dist/config-lkg.d.ts +9 -9
- package/dist/config-lkg.js +20 -4
- package/dist/config-provider.d.ts +3 -1
- package/dist/config-provider.js +12 -4
- package/dist/config-types.d.ts +7 -9
- package/dist/config.js +17 -4
- package/dist/device-ws-protocol.d.ts +1 -1
- package/dist/device-ws-protocol.js +1 -0
- package/dist/env-name-allowlist-knobs.d.ts +12 -2
- package/dist/env-name-allowlist-knobs.js +5 -4
- package/dist/exec-bounds.d.ts +15 -3
- package/dist/exec-bounds.js +4 -0
- package/dist/execution-lane-caps.d.ts +9 -2
- package/dist/execution-lane-caps.js +11 -0
- package/dist/hooks/classic-stations.d.ts +86 -0
- package/dist/hooks/classic-stations.js +27 -0
- package/dist/hooks/hook-llm.d.ts +8 -5
- package/dist/hooks/hook-llm.js +78 -35
- package/dist/hooks/hook-runner.d.ts +232 -80
- package/dist/hooks/hook-runner.js +218 -312
- package/dist/http/admission.d.ts +8 -2
- package/dist/http/admission.js +101 -57
- package/dist/http/approval-sweeps.js +57 -16
- package/dist/http/checkpoint-ctx.d.ts +25 -8
- package/dist/http/checkpoint-ctx.js +11 -7
- package/dist/http/claimed-run.d.ts +13 -0
- package/dist/http/claimed-run.js +15 -0
- package/dist/http/device-placement.js +5 -10
- package/dist/http/dispatch.d.ts +0 -4
- package/dist/http/dispatch.js +5 -9
- package/dist/http/durable-run-leg.d.ts +2 -1
- package/dist/http/durable-run-leg.js +5 -3
- package/dist/http/health-self-report.d.ts +7 -5
- package/dist/http/health-self-report.js +4 -18
- package/dist/http/principal-gate.d.ts +23 -6
- package/dist/http/principal-gate.js +24 -5
- package/dist/http/refusal-body.d.ts +21 -0
- package/dist/http/refusal-body.js +4 -0
- package/dist/http/request-guards.d.ts +27 -0
- package/dist/http/request-guards.js +24 -3
- package/dist/http/resume-legs.d.ts +25 -0
- package/dist/http/resume-legs.js +43 -22
- package/dist/http/routes/capabilities.js +1 -1
- package/dist/http/routes/diagnostics.js +1 -1
- package/dist/http/routes/rules.js +2 -2
- package/dist/http/routes/runs.js +7 -7
- package/dist/http/routes/session-sync.js +4 -2
- package/dist/http/routes/sessions.js +1 -1
- package/dist/http/routes/shared-memory.js +2 -13
- package/dist/http/routes/side-query.js +2 -3
- package/dist/http/routes/tasks.js +19 -9
- package/dist/http/send.d.ts +9 -7
- package/dist/http/send.js +7 -2
- package/dist/http/server.d.ts +21 -11
- package/dist/http/server.js +28 -2
- package/dist/http/submit-ctx.d.ts +25 -0
- package/dist/http/submit-ctx.js +39 -0
- package/dist/http/wire-types.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lane-home-probe.d.ts +43 -0
- package/dist/lane-home-probe.js +35 -0
- package/dist/limit-refusal.d.ts +47 -0
- package/dist/limit-refusal.js +12 -0
- package/dist/main.js +1 -1
- package/dist/mcp-assertion-header.d.ts +1 -9
- package/dist/mcp-assertion-header.js +0 -6
- package/dist/mcp-tool-faces.d.ts +5 -0
- package/dist/mcp-tool-faces.js +5 -1
- package/dist/memory-scope.d.ts +1 -1
- package/dist/model-provider.d.ts +39 -12
- package/dist/model-provider.js +19 -2
- package/dist/model-route-endpoint.d.ts +1 -1
- package/dist/model-route-endpoint.js +5 -5
- package/dist/observability/cost-taxonomy.d.ts +7 -7
- package/dist/observability/fail-open.d.ts +42 -6
- package/dist/observability/fail-open.js +42 -6
- package/dist/observability/metrics.js +3 -1
- package/dist/observability/prompt-manifest.d.ts +47 -82
- package/dist/observability/prompt-manifest.js +119 -17
- package/dist/observability/run-terminal.js +14 -6
- package/dist/observability/secret-env-scrub.d.ts +13 -1
- package/dist/observability/secret-env-scrub.js +13 -1
- package/dist/observability/tool-trace.d.ts +16 -21
- package/dist/observability/tool-trace.js +51 -42
- package/dist/per-task-image.d.ts +7 -1
- package/dist/per-task-image.js +3 -3
- package/dist/plain-string-record.d.ts +25 -0
- package/dist/plain-string-record.js +32 -0
- package/dist/plugins/blob-backend.d.ts +68 -13
- package/dist/plugins/blob-backend.js +53 -10
- package/dist/plugins/checkpoint-store-sql.d.ts +14 -4
- package/dist/plugins/checkpoint-store-sql.js +39 -26
- package/dist/plugins/k8s-bg-scripts.d.ts +11 -0
- package/dist/plugins/k8s-bg-scripts.js +22 -0
- package/dist/plugins/local-checkpoint-store.js +5 -2
- package/dist/plugins/local-session-store.js +1 -1
- package/dist/plugins/one-time-migrations.d.ts +137 -90
- package/dist/plugins/one-time-migrations.js +356 -207
- package/dist/plugins/permission-rule-store-sql.d.ts +13 -7
- package/dist/plugins/permission-rule-store-sql.js +4 -18
- package/dist/plugins/pg-session-storage.d.ts +4 -5
- package/dist/plugins/pg-session-storage.js +7 -17
- package/dist/plugins/remote-env-adb.d.ts +6 -0
- package/dist/plugins/remote-env-adb.js +9 -4
- package/dist/plugins/remote-env-device.js +3 -0
- package/dist/plugins/remote-env-e2b.d.ts +1 -1
- package/dist/plugins/remote-env-e2b.js +21 -9
- package/dist/plugins/remote-env-host.d.ts +9 -9
- package/dist/plugins/remote-env-host.js +10 -32
- package/dist/plugins/remote-env-k8s.d.ts +95 -26
- package/dist/plugins/remote-env-k8s.js +265 -90
- package/dist/plugins/remote-env-local-docker.d.ts +20 -1
- package/dist/plugins/remote-env-local-docker.js +77 -9
- package/dist/plugins/remote-env-ssh.d.ts +15 -0
- package/dist/plugins/remote-env-ssh.js +109 -3
- package/dist/plugins/remote-shell.d.ts +0 -1
- package/dist/plugins/remote-shell.js +1 -2
- package/dist/plugins/retention-store-sql.js +6 -2
- package/dist/plugins/schema-consistency.d.ts +54 -0
- package/dist/plugins/schema-consistency.js +52 -0
- package/dist/plugins/session-epoch-anchor.d.ts +13 -0
- package/dist/plugins/session-epoch-anchor.js +23 -0
- package/dist/plugins/shared-memory-store-sql.d.ts +9 -3
- package/dist/plugins/shared-memory-store-sql.js +5 -16
- package/dist/plugins/sql-driver.d.ts +141 -0
- package/dist/plugins/sql-driver.js +115 -1
- package/dist/plugins/sql-errors.d.ts +41 -0
- package/dist/plugins/sql-errors.js +36 -0
- package/dist/plugins/store-backend.js +2 -1
- package/dist/plugins/tidb-session-storage.d.ts +7 -11
- package/dist/plugins/tidb-session-storage.js +6 -16
- package/dist/plugins/tidb-session-store.js +1 -1
- package/dist/prompts-domain-validate.d.ts +17 -61
- package/dist/prompts-domain-validate.js +9 -119
- package/dist/request-key-closure.d.ts +2 -2
- package/dist/request-key-closure.js +2 -4
- package/dist/rule-entry-list.d.ts +12 -9
- package/dist/rule-entry-list.js +37 -21
- package/dist/run-local.js +19 -19
- package/dist/runs.d.ts +6 -0
- package/dist/runs.js +16 -0
- package/dist/server-secret-env.d.ts +44 -18
- package/dist/server-secret-env.js +49 -8
- package/dist/session-incarnation.d.ts +15 -5
- package/dist/session-incarnation.js +16 -9
- package/dist/session-titler.js +12 -2
- package/dist/spec-fields.d.ts +28 -16
- package/dist/spec-fields.js +46 -53
- package/dist/sql-engine-posture.d.ts +29 -4
- package/dist/sql-engine-posture.js +36 -1
- package/dist/stored-request-tool-axes-m19.d.ts +19 -4
- package/dist/stored-request-tool-axes-m19.js +30 -2
- package/dist/task-a2a.d.ts +9 -1
- package/dist/task-a2a.js +73 -47
- package/dist/task-mcp.d.ts +46 -58
- package/dist/task-mcp.js +99 -65
- package/dist/task-settings.d.ts +7 -21
- package/dist/task-settings.js +7 -36
- package/dist/text-bidi.d.ts +3 -46
- package/dist/text-bidi.js +3 -3
- package/dist/tool-approval.d.ts +1 -1
- package/dist/trace/core-keyset-guard.d.ts +24 -4
- package/dist/trace/engine-notice-wire.d.ts +11 -3
- package/dist/trace/engine-notice-wire.js +8 -1
- package/dist/trace/ledger-events.d.ts +3 -1
- package/dist/trace/ledger-sink.js +4 -1
- package/dist/trace/model-segment.js +1 -1
- package/dist/trace/project.d.ts +19 -6
- package/dist/trace/project.js +57 -22
- package/dist/trace/wire-projection-faces.d.ts +79 -1
- package/dist/trace/wire-projection-faces.js +22 -0
- package/dist/web-admin-client/candidate-gate.d.ts +6 -6
- package/dist/web-admin-client/candidate-gate.js +3 -3
- package/dist/web-admin-client/http-client.js +0 -6
- package/dist/web-admin-client/read-warnings.d.ts +13 -0
- package/dist/web-admin-client/read-warnings.js +10 -0
- package/dist/web-admin-client/skills-mcp.d.ts +3 -0
- package/dist/web-admin-client/skills-mcp.js +9 -6
- package/dist/web-admin-client/types.d.ts +2 -3
- package/dist/workspace-cache.d.ts +35 -0
- package/dist/workspace-cache.js +36 -0
- package/dist/workspace-space.d.ts +3 -2
- package/dist/workspace-space.js +2 -0
- package/docs/DEVICE-EXECUTOR-PROTOCOL.md +8 -1
- package/package.json +4 -4
- package/scripts/drain-check-local.mjs +34 -1
- package/scripts/drain-check.mysql.sql +30 -2
- package/scripts/drain-check.pg.sql +29 -2
- package/dist/capabilities/memory-notice.d.ts +0 -138
- package/dist/capabilities/memory-notice.js +0 -64
- package/dist/capabilities/prompt.d.ts +0 -17
- package/dist/capabilities/prompt.js +0 -6
- package/dist/mcp-content-origin.d.ts +0 -34
- package/dist/mcp-content-origin.js +0 -10
- package/dist/tool-axis-words.d.ts +0 -27
- package/dist/tool-axis-words.js +0 -9
- package/dist/wire-name-bound.d.ts +0 -14
- package/dist/wire-name-bound.js +0 -13
package/dist/boot/web-admin.js
CHANGED
|
@@ -8,8 +8,7 @@ import { buildModelRefusalsSignal } from "../model-entry-refusal.js";
|
|
|
8
8
|
import { CenterPromptSource, FilePromptArtifactStore, FilePromptSourceStateStore, MemoryPromptArtifactStore, MemoryPromptSourceStateStore, } from "@sema-agent/core";
|
|
9
9
|
import { buildPricing } from "../budget.js";
|
|
10
10
|
import { applyCenterPlugins } from "../capabilities/center-plugins.js";
|
|
11
|
-
import {
|
|
12
|
-
import { CORE_ENGINE_VERSION } from "../prompts-domain-validate.js";
|
|
11
|
+
import { applyCenterArtifact, centerSourceOnError, withPromptArtifactBackfill } from "../capabilities/center-prompts.js";
|
|
13
12
|
import { centerScenarios, centerScenarioDetails } from "../capabilities/scenarios.js";
|
|
14
13
|
import { isRosterGateArmed } from "../config.js";
|
|
15
14
|
import { defaultLkgPath, defaultSkillCacheDir, saveLkg, loadLkg, legacyV1LkgPath, migrateV1Lkg } from "../config-lkg.js";
|
|
@@ -22,11 +21,11 @@ import { buildSealedKeyPublicFace, ensureSealedKeyStore, reportExecutionPublicKe
|
|
|
22
21
|
import { applyEffective, applyCenterReadFace, buildReadFaceBaseline, buildReadFaceSwapCandidate, restoreReadFaceBaseline, mutateInPlace, logEffectiveDiff, applySkillsManifest, resolveMcpServers, resolveA2aPeers, restartReasons, modelPlaneChanged, withModelPlaneOf, fullyLandedForLkg, fetchPromptArtifact } from "../web-admin-client/facade.js";
|
|
23
22
|
import { buildConfigHandoff, buildRestartSignal, configHandoffMissing } from "../fleet/engine-signal.js";
|
|
24
23
|
import { createMcpRevocationLedger, enabledMcpEntries } from "../web-admin-client/mcp-revocation.js";
|
|
25
|
-
import { buildUnreadConfigFileFields } from "../web-admin-client/read-warnings.js";
|
|
24
|
+
import { buildUnreadConfigFileFields, buildUnreadConfigKeyFields } from "../web-admin-client/read-warnings.js";
|
|
26
25
|
import { CONFIG_DOMAIN_INVALID_NOTE, buildCandidateRejectedFields, candidateRejectionOf, judgeConfigCandidate } from "../web-admin-client/candidate-gate.js";
|
|
27
26
|
import { SHA256_HEX_RE } from "../digest-form.js";
|
|
28
27
|
import { BOOT_REJUDGE_OF_REFUSED_GROUP, createConfigApplyLedger, modelPlaneCommitted, refusedGroups } from "../web-admin-client/apply-ledger.js";
|
|
29
|
-
import { buildDeploymentPostureSeats } from "./runner-deps.js";
|
|
28
|
+
import { announceReadDenyRows, buildDeploymentPostureSeats } from "./runner-deps.js";
|
|
30
29
|
function lkgReadNote(scope) {
|
|
31
30
|
switch (scope) {
|
|
32
31
|
case "whole":
|
|
@@ -143,6 +142,8 @@ export async function createWebAdminRuntime(ctx) {
|
|
|
143
142
|
const warnReadNotices = (r, phase) => {
|
|
144
143
|
for (const f of r.unreadFiles ?? [])
|
|
145
144
|
logger.warn("config_unread_file", buildUnreadConfigFileFields(f, localDirField.dir));
|
|
145
|
+
for (const k of r.unreadKeys ?? [])
|
|
146
|
+
logger.warn("config_unread_key", buildUnreadConfigKeyFields(k, localDirField.dir));
|
|
146
147
|
for (const d of r.droppedEntries ?? []) {
|
|
147
148
|
logger.warn("config_entry_dropped", {
|
|
148
149
|
domain: d.domain,
|
|
@@ -202,15 +203,15 @@ export async function createWebAdminRuntime(ctx) {
|
|
|
202
203
|
applyLedger.recordApply(rep);
|
|
203
204
|
publishModelRefusals(buildModelRefusalsSignal(rep.modelRefusals));
|
|
204
205
|
};
|
|
205
|
-
let
|
|
206
|
-
let
|
|
206
|
+
let adoptedArtifact;
|
|
207
|
+
let pendingCenterTarget;
|
|
207
208
|
const retryPendingCatalog = async (phase) => {
|
|
208
|
-
if (!
|
|
209
|
+
if (!pendingCenterTarget)
|
|
209
210
|
return;
|
|
210
|
-
const { target } =
|
|
211
|
-
if (await
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
const { target } = pendingCenterTarget;
|
|
212
|
+
if (await applyCenterArtifact(catalogSource, target, adoptedArtifact, logger, phase)) {
|
|
213
|
+
adoptedArtifact = target;
|
|
214
|
+
pendingCenterTarget = undefined;
|
|
214
215
|
}
|
|
215
216
|
};
|
|
216
217
|
const promptEpochDir = join(config.localDataRoot ?? localRoot, "prompt-epoch");
|
|
@@ -253,6 +254,7 @@ export async function createWebAdminRuntime(ctx) {
|
|
|
253
254
|
},
|
|
254
255
|
});
|
|
255
256
|
const withByDigestBackfill = (inner) => cc?.baseUrl ? withPromptArtifactBackfill(inner, (d) => fetchPromptArtifact(cc, d), logger) : inner;
|
|
257
|
+
const sourceOnError = centerSourceOnError(logger);
|
|
256
258
|
const promptSource = (() => {
|
|
257
259
|
try {
|
|
258
260
|
const bootBin = promptStateBin();
|
|
@@ -261,15 +263,15 @@ export async function createWebAdminRuntime(ctx) {
|
|
|
261
263
|
return new CenterPromptSource({
|
|
262
264
|
store: withByDigestBackfill(new FilePromptArtifactStore(promptEpochDir)),
|
|
263
265
|
stateStore: recordingStateStore(binnedPromptStateStore(fileStateStoreFor)),
|
|
264
|
-
|
|
266
|
+
onError: sourceOnError,
|
|
265
267
|
});
|
|
266
268
|
}
|
|
267
269
|
catch (e) {
|
|
268
|
-
logger.warn("center_prompts_store_unwritable", { dir: promptEpochDir, err: String(e), note: "file-backed prompt-epoch store unavailable — memory fallback (
|
|
270
|
+
logger.warn("center_prompts_store_unwritable", { dir: promptEpochDir, err: String(e), note: "file-backed prompt-epoch store unavailable — memory fallback (the center candidate is not restart-durable); built-ins unaffected" });
|
|
269
271
|
return new CenterPromptSource({
|
|
270
272
|
store: withByDigestBackfill(new MemoryPromptArtifactStore()),
|
|
271
273
|
stateStore: recordingStateStore(binnedPromptStateStore(storePerBin(() => new MemoryPromptSourceStateStore()))),
|
|
272
|
-
|
|
274
|
+
onError: sourceOnError,
|
|
273
275
|
});
|
|
274
276
|
}
|
|
275
277
|
})();
|
|
@@ -281,14 +283,14 @@ export async function createWebAdminRuntime(ctx) {
|
|
|
281
283
|
};
|
|
282
284
|
const rebasePromptState = async (identity, phase) => {
|
|
283
285
|
promptStateIdentity = identity;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
+
adoptedArtifact = undefined;
|
|
287
|
+
pendingCenterTarget = undefined;
|
|
286
288
|
promptPersisted = undefined;
|
|
287
289
|
try {
|
|
288
290
|
await promptSource.restore();
|
|
289
291
|
}
|
|
290
292
|
catch (e) {
|
|
291
|
-
logger.warn("center_prompts_catalog_restore_failed", { phase, err: String(e), note: "the persisted
|
|
293
|
+
logger.warn("center_prompts_catalog_restore_failed", { phase, err: String(e), note: "the persisted center-layer state for this credential identity could not be loaded — the center candidate is absent until the next adopt; built-ins unaffected" });
|
|
292
294
|
}
|
|
293
295
|
if (cc !== undefined && identity !== undefined && currentIdentity() !== identity) {
|
|
294
296
|
promptStateIdentity = undefined;
|
|
@@ -304,36 +306,33 @@ export async function createWebAdminRuntime(ctx) {
|
|
|
304
306
|
await rebasePromptState(adoptedIdentity, phase);
|
|
305
307
|
}
|
|
306
308
|
if (prompts === undefined) {
|
|
307
|
-
if (
|
|
308
|
-
logger.info("center_prompts_cleared", { phase, note: "effective carries no prompts key (publish gate off) — built-in
|
|
309
|
-
const cleared = await
|
|
309
|
+
if (adoptedArtifact)
|
|
310
|
+
logger.info("center_prompts_cleared", { phase, note: "effective carries no prompts key (publish gate off / nothing published) — the built-in prompt serves new tasks" });
|
|
311
|
+
const cleared = await applyCenterArtifact(catalogSource, undefined, adoptedArtifact, logger, phase);
|
|
310
312
|
if (cleared) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
+
adoptedArtifact = undefined;
|
|
314
|
+
pendingCenterTarget = undefined;
|
|
313
315
|
}
|
|
314
316
|
else {
|
|
315
|
-
|
|
317
|
+
pendingCenterTarget = { target: undefined };
|
|
316
318
|
}
|
|
317
319
|
return;
|
|
318
320
|
}
|
|
319
|
-
if (
|
|
321
|
+
if (adoptedArtifact?.artifactDigest !== prompts.artifactDigest) {
|
|
320
322
|
logger.info("center_prompts_adopted", {
|
|
321
323
|
phase,
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
: {}),
|
|
326
|
-
...(prompts.catalog ? { artifactDigest: prompts.catalog.artifact.artifactDigest, catalogDigest: prompts.catalog.artifact.payload.catalogDigest, sourceRevision: prompts.catalog.sourceRevision } : {}),
|
|
327
|
-
note: "new tasks assemble the new pack (epoch re-pins at the next task boundary); in-flight sessions stay pinned",
|
|
324
|
+
artifactDigest: prompts.artifactDigest,
|
|
325
|
+
sourceRevision: prompts.sourceRevision,
|
|
326
|
+
note: "new sessions adopt this center layer (a session pins it at its first run); in-flight sessions stay pinned",
|
|
328
327
|
});
|
|
329
328
|
}
|
|
330
|
-
const transitioned = await
|
|
329
|
+
const transitioned = await applyCenterArtifact(catalogSource, prompts, adoptedArtifact, logger, phase);
|
|
331
330
|
if (transitioned) {
|
|
332
|
-
|
|
333
|
-
|
|
331
|
+
adoptedArtifact = prompts;
|
|
332
|
+
pendingCenterTarget = undefined;
|
|
334
333
|
}
|
|
335
334
|
else {
|
|
336
|
-
|
|
335
|
+
pendingCenterTarget = { target: prompts };
|
|
337
336
|
}
|
|
338
337
|
};
|
|
339
338
|
let bootConfigPending;
|
|
@@ -666,6 +665,8 @@ export async function createWebAdminRuntime(ctx) {
|
|
|
666
665
|
restoreReadFaceBaseline(config, before);
|
|
667
666
|
throw err;
|
|
668
667
|
}
|
|
668
|
+
if (changedSeats.includes("readDenyPatterns"))
|
|
669
|
+
announceReadDenyRows(config, logger);
|
|
669
670
|
};
|
|
670
671
|
let ccTimer;
|
|
671
672
|
return {
|
|
@@ -678,7 +679,6 @@ export async function createWebAdminRuntime(ctx) {
|
|
|
678
679
|
},
|
|
679
680
|
mcpRevocationState: () => (configProvider ? mcpRevocations.view() : undefined),
|
|
680
681
|
getKeyResolver: () => keyResolver,
|
|
681
|
-
getCenterPrompts: () => centerPrompts,
|
|
682
682
|
modelReady: () => modelReadyState.ready,
|
|
683
683
|
onSelfReportChange: (listener) => {
|
|
684
684
|
selfReportListeners.push(listener);
|
package/dist/brain.js
CHANGED
|
@@ -4,7 +4,7 @@ import { buildDefaultResilience } from "./config-types.js";
|
|
|
4
4
|
import { resolveModelApiKey } from "./key-resolver.js";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { isModelKeyPoison, modelKeyPoisonIdentity } from "./key-resolver.js";
|
|
7
|
-
import {
|
|
7
|
+
import { anthropicRouteRoot, brainLaneFor, mountRoutes, routeTableOf } from "./model-provider.js";
|
|
8
8
|
import { openaiRouteBaseUrl } from "./model-route-endpoint.js";
|
|
9
9
|
import { catalogEntryFingerprint } from "./web-admin-client/restart-signal.js";
|
|
10
10
|
import { buildDisplaySafeRefusal, buildDisplaySafeUrl } from "./trace/redact.js";
|
|
@@ -77,23 +77,18 @@ export function createBrainAssembly(config, deps = {}) {
|
|
|
77
77
|
: openaiBrains.length > 1
|
|
78
78
|
? createFailoverBrain(openaiBrains)
|
|
79
79
|
: openaiBrains[0];
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}))
|
|
93
|
-
: undefined;
|
|
94
|
-
let brain = anthropicBrain
|
|
95
|
-
? createRoutingBrain({ anthropic: anthropicBrain }, { fallback: gatewayBrain })
|
|
96
|
-
: gatewayBrain;
|
|
80
|
+
const brainRoutes = mountRoutes(config, (anthropicCfg) => constructRouteBrain("anthropic route", [anthropicCfg.baseUrl], () => createAnthropicBrain({
|
|
81
|
+
...(anthropicCfg.authToken
|
|
82
|
+
? { headers: { Authorization: `Bearer ${anthropicCfg.authToken}` } }
|
|
83
|
+
: { apiKey: anthropicCfg.apiKey }),
|
|
84
|
+
baseUrl: anthropicRouteRoot(anthropicCfg),
|
|
85
|
+
version: anthropicCfg.version,
|
|
86
|
+
cacheBreakpoints: anthropicCfg.cacheBreakpoints,
|
|
87
|
+
...(anthropicCfg.maxRetries !== undefined ? { maxRetries: anthropicCfg.maxRetries } : {}),
|
|
88
|
+
fetchImpl,
|
|
89
|
+
...timeouts,
|
|
90
|
+
})));
|
|
91
|
+
let brain = Object.keys(brainRoutes).length > 0 ? createRoutingBrain(brainRoutes, { fallback: gatewayBrain }) : gatewayBrain;
|
|
97
92
|
let degradeBaked = null;
|
|
98
93
|
if (config.degrade?.reactive) {
|
|
99
94
|
const degradeTo = config.degrade.to;
|
|
@@ -104,12 +99,12 @@ export function createBrainAssembly(config, deps = {}) {
|
|
|
104
99
|
const ownEnvRef = credential.apiKeyEnv !== undefined ? { [fallbackModel.name]: credential.apiKeyEnv } : {};
|
|
105
100
|
const ownSealed = credential.sealed !== undefined ? { [fallbackModel.name]: credential.sealed } : {};
|
|
106
101
|
const fbOwnApiKey = () => resolveModelApiKey(fallbackModel.name, ownEnvRef, process.env, ownSealed);
|
|
107
|
-
const anthropicLaneHop =
|
|
102
|
+
const anthropicLaneHop = brainLaneFor(fallbackModel.provider, brainRoutes) === "anthropic";
|
|
108
103
|
const fbDeclaredRoot = degradeDeclaredRoot(fallbackModel.baseUrl, config);
|
|
109
104
|
const fbDeploymentKey = deploymentGatewayKey(config);
|
|
110
|
-
const fallback = anthropicLaneHop
|
|
105
|
+
const fallback = anthropicLaneHop
|
|
111
106
|
?
|
|
112
|
-
|
|
107
|
+
brainRoutes.anthropic
|
|
113
108
|
: constructRouteBrain(`degrade target "${degradeTo}"`, [fallbackModel.baseUrl, config.gatewayBaseUrl], () => createOpenAIBrain({
|
|
114
109
|
...(fbDeclaredRoot !== undefined ? { baseUrl: fbDeclaredRoot } : {}),
|
|
115
110
|
...(fbDeploymentKey ? { apiKey: fbDeploymentKey } : {}),
|
|
@@ -223,7 +218,7 @@ export function brainSummary(config) {
|
|
|
223
218
|
const target = degradeTarget;
|
|
224
219
|
if (!target)
|
|
225
220
|
return { reactiveDegradeRoutePairing: null, reactiveDegradeRouteRefusal: null };
|
|
226
|
-
if (
|
|
221
|
+
if (brainLaneFor(target.provider, routeTableOf(config)) === "anthropic") {
|
|
227
222
|
return { reactiveDegradeRoutePairing: "anthropic-lane", reactiveDegradeRouteRefusal: null };
|
|
228
223
|
}
|
|
229
224
|
const credential = degradeCredentialIdentityOf(config, target);
|
package/dist/budget.js
CHANGED
|
@@ -93,9 +93,11 @@ export function createTracer(metrics, costQuota, modelUsage, fleetUsage, fleetLe
|
|
|
93
93
|
const weightedTokens = Math.round((e.totalInputTokens + e.completionTokens) * qw);
|
|
94
94
|
fleetUsage?.record(currentPrincipal(), e.model, e.taskId, { inputTokens: e.totalInputTokens, outputTokens: e.completionTokens, ...(e.costMicroUsd !== undefined ? { costMicroUsd: e.costMicroUsd } : {}), weightedTokens, quotaWeightAtUse: qw });
|
|
95
95
|
fleetLease?.recordSpend(currentPrincipal(), { weightedTokens, ...(e.costMicroUsd !== undefined ? { costMicroUsd: e.costMicroUsd } : {}) });
|
|
96
|
-
if (e.
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
if (e.turn !== undefined) {
|
|
97
|
+
if (e.firstTokenMs !== undefined)
|
|
98
|
+
metrics.observe("brain_first_token_ms", e.firstTokenMs);
|
|
99
|
+
metrics.observe("brain_call_latency_ms", e.latencyMs);
|
|
100
|
+
}
|
|
99
101
|
}
|
|
100
102
|
else if (e.kind === "tool.call") {
|
|
101
103
|
metrics.inc("tool_calls_total", { name: toolName(e.name), ok: String(e.ok) });
|
|
@@ -107,7 +109,6 @@ export function createTracer(metrics, costQuota, modelUsage, fleetUsage, fleetLe
|
|
|
107
109
|
metrics.inc("degraded_total", { reason: e.reason });
|
|
108
110
|
}
|
|
109
111
|
else if (e.kind === "prompt.assembled") {
|
|
110
|
-
metrics.inc("prompt_constitution_total", { mode: e.constitution });
|
|
111
112
|
promptManifests?.record(e.taskId, promptManifestRecordOf(e));
|
|
112
113
|
}
|
|
113
114
|
else if (e.kind === "config.assembled") {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** 回显的字符上限(剥完控制与双向字符之后数)。 */
|
|
2
|
+
export declare const CALLER_TEXT_ECHO_MAX_CHARS = 64;
|
|
3
|
+
/** 站点给的回显选项。 */
|
|
4
|
+
export interface EchoCallerTextOptions {
|
|
5
|
+
/** 回显的字符上限(剥完控制与双向字符之后数);不给 = {@link CALLER_TEXT_ECHO_MAX_CHARS}。必须是正整数,否则抛 `RangeError`(编程错误,不静默落成某个长度)。 */
|
|
6
|
+
readonly maxChars?: number;
|
|
7
|
+
}
|
|
8
|
+
/** 调用方写的串的回显形(不带引号):剥控制与双向字符 → 截到 `maxChars`(缺省 {@link CALLER_TEXT_ECHO_MAX_CHARS})字 + 「…」。 */
|
|
9
|
+
export declare function echoCallerText(text: string, opts?: EchoCallerTextOptions): string;
|
|
10
|
+
/** 句子里点名一个值的写法:{@link echoCallerText} 外加一对双引号。 */
|
|
11
|
+
export declare function quotedCallerText(text: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* 一个**判不过**的申报名(MCP server / A2A 对端的 `name`)在拒句 / 告警元数据里的回显:非串只说种类、空串说 `empty`,否则按本口径的引号形
|
|
14
|
+
* 外加送来的原长度(运维要的是「我那个名字长了多少」,不是一屏乱码)。判据本身不在这里:「能不能用」只有契约包的 `isUsableWireName` 一只
|
|
15
|
+
* (请求腿 / 声明腿同读),本函数只管回显 —— 回显清洗是消费方按自己的腿定的(契约包的判官模块头注同此分工)。
|
|
16
|
+
*/
|
|
17
|
+
export declare function describeBadWireName(v: unknown): string;
|
|
18
|
+
/** 一个词表外的 `contentOrigin` 值在拒句 / 告警元数据里的回显:串 ⇒ 本口径的引号形;非串 ⇒ 只说种类。判据是契约包的 `isContentOriginWord`(不在这里)。 */
|
|
19
|
+
export declare function describeBadContentOrigin(v: unknown): string;
|
|
20
|
+
//# sourceMappingURL=caller-text-echo.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TOOL_WIRE_NAME_MAX_CHARS } from "@sema-agent/settings-schema";
|
|
2
|
+
import { CONTROL_AND_BIDI_STRIP_RE } from "./text-bidi.js";
|
|
3
|
+
export const CALLER_TEXT_ECHO_MAX_CHARS = 64;
|
|
4
|
+
export function echoCallerText(text, opts) {
|
|
5
|
+
const max = opts?.maxChars ?? CALLER_TEXT_ECHO_MAX_CHARS;
|
|
6
|
+
if (!Number.isInteger(max) || max < 1)
|
|
7
|
+
throw new RangeError(`echoCallerText: maxChars must be a positive integer, got ${String(max)}`);
|
|
8
|
+
const clean = text.replace(CONTROL_AND_BIDI_STRIP_RE, "");
|
|
9
|
+
return clean.length > max ? `${clean.slice(0, max)}…` : clean;
|
|
10
|
+
}
|
|
11
|
+
export function quotedCallerText(text) {
|
|
12
|
+
return `"${echoCallerText(text)}"`;
|
|
13
|
+
}
|
|
14
|
+
export function describeBadWireName(v) {
|
|
15
|
+
if (typeof v !== "string")
|
|
16
|
+
return v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
|
|
17
|
+
if (v.length === 0)
|
|
18
|
+
return "empty";
|
|
19
|
+
return `${quotedCallerText(v)} (${v.length} chars > ${TOOL_WIRE_NAME_MAX_CHARS})`;
|
|
20
|
+
}
|
|
21
|
+
export function describeBadContentOrigin(v) {
|
|
22
|
+
return typeof v === "string" ? quotedCallerText(v) : v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=caller-text-echo.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 品牌行(`SEMA_IDENTITY`)—— 品牌部署(local / TOC:`CONFIG_PROVIDER=local`、`run-local`)的 `default` / `code` 两场景,模型的 role 层以它开头。
|
|
3
|
+
*
|
|
4
|
+
* 律:品牌行是**部署类的一条 overlay**,不是每请求的分叉。部署座(`RunnerDeps.mods`)上一张 `prompt.compose` 注册,恒答同一条 overlay ——
|
|
5
|
+
* `add` 到 `role` 档(部署类的 add rank 99,排在目录的角色基底 `core/role.base` rank 100 之前),带 `when`:
|
|
6
|
+
* · `binding.anyOf: ["default", "code"]` —— 场景名由 `buildPromptSeats` 写进 `TaskSpec.promptBinding`(恒写);`code-review` / `scan` 与中心声明的场景
|
|
7
|
+
* 不在表里 ⇒ 不挂(它们与 `default` 同为 `general` 角色,`host.role` 分不开,只有 binding 分得开);
|
|
8
|
+
* · `facts.isSubagent: false` —— 委派子代(Agent 工具 / workflow 腿)经父 spec 座继承 binding,但它拿的是子代角色(引擎 sub-agent persona 或定义的
|
|
9
|
+
* systemPrompt),品牌行只属于与用户对话的那一腿(与 7.131.0 同:场景的提示从来不进子代)。
|
|
10
|
+
* 判它挂不挂的只有引擎一处(`whenHolds`,每一类 overlay 同一只);本服务不读 `e.selectors`,不写任何每请求的分支。
|
|
11
|
+
* 文本只在 `prompts/identity.ts` 一处(本模块不复述);「这台部署是不是品牌部署」只有一只判官 {@link isBrandedDeployment} —— HTTP 服务的三个读者
|
|
12
|
+
* (部署座的品牌行 `createDeploymentMods`、commit 尾注署名、场景详情读面的 `promptSummary`)同调它;本地 CLI(`run-local`)恒是品牌形,直接表态 `true`。
|
|
13
|
+
*/
|
|
14
|
+
import type { EngineDollar, ModRegistration, PromptOverlay } from "@sema-agent/core";
|
|
15
|
+
import type { ServiceConfig } from "../config-types.js";
|
|
16
|
+
/** 🔴 **品牌部署的唯一判官**:local 配置源(`CONFIG_PROVIDER=local`,TOC / Sema 产品线)⇒ 品牌部署。读者见本模块头注;再多一个读者也调它,不各写一遍。 */
|
|
17
|
+
export declare function isBrandedDeployment(config: Pick<ServiceConfig, "configProvider">): boolean;
|
|
18
|
+
/** 注册名(admission / 清单 / `superseded` 归因里的那个名字)。 */
|
|
19
|
+
export declare const BRAND_IDENTITY_REGISTRATION = "server.brand-identity";
|
|
20
|
+
/** 品牌行挂的场景(binding 表)。 */
|
|
21
|
+
export declare const BRAND_IDENTITY_SCENARIOS: readonly ["default", "code"];
|
|
22
|
+
/** 那一条 overlay(数据;注册恒答它)。 */
|
|
23
|
+
export declare const BRAND_IDENTITY_OVERLAY: PromptOverlay;
|
|
24
|
+
/** 品牌行的部署注册:`prompt.compose` 是收集型站点 —— 先 `await next(e)`,原样保留它交回的 overlays,再接上自己的一条。 */
|
|
25
|
+
export declare function createBrandIdentityRegistration(): ModRegistration<EngineDollar>;
|
|
26
|
+
//# sourceMappingURL=brand-identity.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SEMA_IDENTITY } from "./prompts/identity.js";
|
|
2
|
+
export function isBrandedDeployment(config) {
|
|
3
|
+
return config.configProvider === "local";
|
|
4
|
+
}
|
|
5
|
+
export const BRAND_IDENTITY_REGISTRATION = "server.brand-identity";
|
|
6
|
+
export const BRAND_IDENTITY_SCENARIOS = ["default", "code"];
|
|
7
|
+
export const BRAND_IDENTITY_OVERLAY = {
|
|
8
|
+
id: "sema/identity",
|
|
9
|
+
op: "add",
|
|
10
|
+
target: "role",
|
|
11
|
+
text: SEMA_IDENTITY,
|
|
12
|
+
when: { binding: { anyOf: [...BRAND_IDENTITY_SCENARIOS] }, facts: { isSubagent: false } },
|
|
13
|
+
};
|
|
14
|
+
export function createBrandIdentityRegistration() {
|
|
15
|
+
return {
|
|
16
|
+
name: BRAND_IDENTITY_REGISTRATION,
|
|
17
|
+
tier: "prepend",
|
|
18
|
+
uses: { events: ["prompt.compose"], calls: [] },
|
|
19
|
+
register(on) {
|
|
20
|
+
on("prompt.compose", async (_$, e, next) => {
|
|
21
|
+
const lower = (await next(e))?.overlays;
|
|
22
|
+
return { overlays: [...(Array.isArray(lower) ? lower : []), BRAND_IDENTITY_OVERLAY] };
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=brand-identity.js.map
|
|
@@ -196,7 +196,7 @@ export async function applyCenterPlugins(baseline, eff, opts) {
|
|
|
196
196
|
}
|
|
197
197
|
if (!rootCheck.dir)
|
|
198
198
|
continue;
|
|
199
|
-
const loaded = loadSkills(rootCheck.dir, { confineTo: liveDir });
|
|
199
|
+
const loaded = loadSkills(rootCheck.dir, { confineTo: liveDir, ...(opts.logger !== undefined ? { logger: opts.logger } : {}) });
|
|
200
200
|
for (const skill of loaded) {
|
|
201
201
|
if (taken.has(skill.spec.name)) {
|
|
202
202
|
out.letGo.push({ plugin: v.name, skill: skill.spec.name });
|
|
@@ -1,48 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* 中心提示层的采纳腿:判官(`prompts-domain-validate.ts` 的 `judgePromptsWire`,经候选判官)收下的那份 artifact → 引擎的中心源
|
|
3
|
+
* (`CenterPromptSource`,经 `RunnerDeps.promptSource` 由引擎采用)。
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* 仅有的一层「形校验」不是语义复检,是**防炸底线**(详见其现居所 `src/prompts-domain-validate.ts`——
|
|
12
|
-
* 判形半场已下沉到该中立叶子,本文件 re-export 保兼容;[ref] S6,lens2 §G):core 对坏形声明的
|
|
13
|
-
* 守卫是 THROW(assemble 期),server 在采用前做结构判形,坏形=拒绝采用该候选的 prompts 面。
|
|
14
|
-
*
|
|
15
|
-
* 生效语义(两段史):1.222 时 core 1.315 的 epoch 是 bundled-only(声明不进 descriptor),热换=resume
|
|
16
|
-
* 三失真,故临时 restart-to-apply;core 1.316([ref] 裁 a/[ref]d)把声明以 (id,slot,chars,contentHash?)
|
|
17
|
-
* 纳入 artifactDigest——声明变=digest 变=**下任务边界自动重 pin**(既有 legacy_migration 机制接手),
|
|
18
|
-
* 进行中会话 epoch pin 保稳。自此恢复**热采用**(main.ts boot+refresh 双点 adopt),与 center
|
|
19
|
-
* 「发布=新任务生效」产品语义对齐([ref]②b)。字节级检测只认 opt-in contentHash(文本不进 digest,
|
|
20
|
-
* 防会话可导出面字典预映)——center 链路恒逐 section 铸([ref]),本投影逐字透传即全强度。
|
|
5
|
+
* 律:中心层只有一种形(引擎当期 schema 的发布形 artifact),只有一个座(`RunnerDeps.promptSource`)。本服务不展开、不选包、不按场景挑段:
|
|
6
|
+
* 「哪个场景用哪段」在 artifact 的 `when.binding` 里,由引擎按每个请求的 `TaskSpec.promptBinding`(场景名,`buildPromptSeats` 一处写)判。
|
|
7
|
+
* 本模块只管三件事:① 把判官交出的值推进中心源的两态过渡({@link applyCenterArtifact});② 按 digest 补拉一份本副本没有的 artifact
|
|
8
|
+
* ({@link withPromptArtifactBackfill},钉着它的会话续跑时用);③ 中心源自己的运维句(启动恢复读到一份引擎拒的 / 读不出的副本)
|
|
9
|
+
* 落进本服务的日志({@link centerSourceOnError})。
|
|
21
10
|
*/
|
|
22
|
-
import { type
|
|
23
|
-
|
|
24
|
-
/** 判形半场(validateCenterPrompts/validatePromptsDomain/CORE_ENGINE_VERSION 及两 interface)已下沉到
|
|
25
|
-
* 中立叶子 `src/prompts-domain-validate.ts`([ref] S6);消费者直引真源([ref] 兼容面全清,
|
|
26
|
-
* 此处兼容 re-export 已删)。 */
|
|
27
|
-
/** [ref]b / [ref] — §9.4 by-digest 补拉组合店:local miss ⇒ fetchRaw(digest) 从 center 拉 envelope ⇒
|
|
28
|
-
* core verifyPromptArtifact 全管线 + **回验「拿到的=要的」digest 逐位**(center 答非所问=丢弃)⇒
|
|
29
|
-
* best-effort 回写 inner(下次直命中)。任何失败=undefined(诚实缺席,fail-loud 归 core 的
|
|
30
|
-
* prompt_snapshot_unavailable——绝不拼杂交)。 */
|
|
31
|
-
export declare function withPromptArtifactBackfill(inner: {
|
|
32
|
-
get(d: string, o: {
|
|
33
|
-
engineVersion: string;
|
|
34
|
-
}): Promise<PublishedPromptArtifactEnvelope | undefined>;
|
|
35
|
-
put(e: PublishedPromptArtifactEnvelope): Promise<void>;
|
|
36
|
-
}, fetchRaw: (artifactDigest: string) => Promise<unknown>, log: {
|
|
11
|
+
import { type PromptArtifactStore, type PublishedPromptArtifact, type RunnerDeps } from "@sema-agent/core";
|
|
12
|
+
type Log = {
|
|
37
13
|
info: (msg: string, meta?: Record<string, unknown>) => void;
|
|
38
14
|
warn: (msg: string, meta?: Record<string, unknown>) => void;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export
|
|
15
|
+
};
|
|
16
|
+
/** §9.4 按 digest 补拉的组合店:本地 miss ⇒ `fetchRaw(digest)` 从中心拉 ⇒ 引擎 `verifyPromptArtifact` 全管线 + **回验「拿到的 = 要的」digest 逐位**
|
|
17
|
+
* (中心答非所问 = 丢弃)⇒ best-effort 回写本地店(下次直命中)。任何失败 = undefined(诚实缺席;响亮归引擎的 `prompt.snapshot_unavailable` —— 绝不拼杂交)。
|
|
18
|
+
* 本地店的 `onRefused`(一份副本在、却用不了:引擎拒 / 读不出)原样交给本地店报,不吞:那是「为什么缺」的那一句。 */
|
|
19
|
+
export declare function withPromptArtifactBackfill(inner: PromptArtifactStore, fetchRaw: (artifactDigest: string) => Promise<unknown>, log: Log): PromptArtifactStore;
|
|
20
|
+
/** 中心源的推进面(引擎 `CenterPromptSource` 的两只写口 + 两只「欠不欠撤下」的读口)。 */
|
|
21
|
+
export interface CenterSourceTransitions {
|
|
46
22
|
applySnapshot(raw: unknown): Promise<{
|
|
47
23
|
ok: true;
|
|
48
24
|
artifactDigest: string;
|
|
@@ -52,27 +28,24 @@ export declare function applyCatalogToSource(source: {
|
|
|
52
28
|
reason: string;
|
|
53
29
|
}>;
|
|
54
30
|
applyDisabled(sourceRevision: string): Promise<void>;
|
|
55
|
-
/** codex-2 F2(restart-owed disable):撤下写盘失败后重启,内存 prev 丢了但持久态还 active——
|
|
56
|
-
* 以 source 自身的 live candidate 为准判「欠 disable」,不是只看内存 prev。 */
|
|
31
|
+
/** codex-2 F2(restart-owed disable):撤下写盘失败后重启,内存 prev 丢了但持久态还 active —— 以中心源自身的活候选为准判「欠撤下」,不是只看内存 prev。 */
|
|
57
32
|
current?(): unknown;
|
|
58
|
-
/** S-651(codex 修复验证轮 V1):本箱**持久记录**是 active —— 即使那份 artifact 此刻加载不出(活候选为空)
|
|
59
|
-
*
|
|
33
|
+
/** S-651(codex 修复验证轮 V1):本箱**持久记录**是 active —— 即使那份 artifact 此刻加载不出(活候选为空)。「欠撤下」的真源是持久记录;
|
|
34
|
+
* 活候选只是它能加载时的影子。缺席 = 调用方不掌握持久记录(沿用前两条判据)。 */
|
|
60
35
|
persistedActive?(): boolean;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 判官交出的值推进中心源的两态过渡:`next` 在场(且 digest 变)⇒ `applySnapshot`(引擎重验 + 落盘 + 原子换候选);`next` 缺席
|
|
39
|
+
* (候选不带 prompts 键 = 闸关 / 没发布)而中心层此前在(内存 prev / 活候选 / 持久 active 任一)⇒ `applyDisabled`(显式撤下,离线重启不复活)。
|
|
40
|
+
* 去重键是 artifact 的内容身份(digest;发布出处 `sourceRevision` 不进身份)。返回过渡是否落地 —— false ⇒ 调用方**不推进**已采纳的值,
|
|
41
|
+
* 下一拍同一过渡自动重试(codex-2 F2:吞错推进曾让失败的采纳 / 撤下永久静默)。
|
|
42
|
+
*/
|
|
43
|
+
export declare function applyCenterArtifact(source: CenterSourceTransitions, next: PublishedPromptArtifact | undefined, prev: PublishedPromptArtifact | undefined, log: Log, phase: string): Promise<boolean>;
|
|
65
44
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* (
|
|
45
|
+
* 中心源自己的运维句(`CenterPromptSource` 的 `onError` 选项,引擎的 `RunnerDeps.onError` 形)落进本服务的日志:启动恢复读到持久记录指着的那份 artifact
|
|
46
|
+
* 被引擎拒(退役 schema 的拒句点名重发写法)/ 读不出 / 根本没有副本 —— 中心源无状态起服并说一句。行名与 Runner 的 `prompt-constitution` 阶段同一个
|
|
47
|
+
* (`prompt_composition_warning`):那一阶段的句子都在说「交给组装的东西没有照写的那样生效」。不传 = 这几句静默(引擎的缺省),所以每个起中心源的入口都传它。
|
|
69
48
|
*/
|
|
70
|
-
export declare function
|
|
71
|
-
|
|
72
|
-
* M9 迁移卫在 provider.stableBlocks 的 identity 声明上探同三锚,命中即走 pass-through 臂(其保留集无
|
|
73
|
-
* `core/role.append`,任何 append rider/outputStyle 会被静默丢)。选包与 {@link centerPromptProvider}
|
|
74
|
-
* 同式(`overrides[s] ?? sections`);锚谓词由调用方注入(task-settings `hasConstitutionAnchors` 单真源)。
|
|
75
|
-
* [ref]①f 的「server 不做语义复检」不动:这不是复检语义,是为 capabilities.appendSystemPrompt 的诚实面
|
|
76
|
-
* 探 core 会走哪条臂。 */
|
|
77
|
-
export declare function centerIdentityAssembled(prompts: EffectiveCenterPrompts, scenarioName: string, isAssembled: (text: unknown) => boolean): boolean;
|
|
49
|
+
export declare function centerSourceOnError(log: Pick<Log, "warn">): NonNullable<RunnerDeps["onError"]>;
|
|
50
|
+
export {};
|
|
78
51
|
//# sourceMappingURL=center-prompts.d.ts.map
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { verifyPromptArtifact } from "@sema-agent/core";
|
|
2
|
-
import { CORE_ENGINE_VERSION } from "../prompts-domain-validate.js";
|
|
3
2
|
import { SHA256_HEX_RE } from "../digest-form.js";
|
|
4
3
|
import { recordFailOpen } from "../observability/fail-open.js";
|
|
5
4
|
export function withPromptArtifactBackfill(inner, fetchRaw, log) {
|
|
6
5
|
const inFlight = new Map();
|
|
7
6
|
return {
|
|
8
|
-
put: (
|
|
9
|
-
get: async (digest,
|
|
7
|
+
put: (artifact) => inner.put(artifact),
|
|
8
|
+
get: async (digest, onRefused) => {
|
|
10
9
|
const hex = digest.replace(/^sha256:/i, "").toLowerCase();
|
|
11
10
|
if (!SHA256_HEX_RE.test(hex))
|
|
12
11
|
return undefined;
|
|
13
12
|
const canonical = `sha256:${hex}`;
|
|
14
|
-
const local = await inner.get(canonical,
|
|
13
|
+
const local = await inner.get(canonical, onRefused);
|
|
15
14
|
if (local)
|
|
16
15
|
return local;
|
|
17
16
|
const pending = inFlight.get(canonical);
|
|
@@ -20,14 +19,14 @@ export function withPromptArtifactBackfill(inner, fetchRaw, log) {
|
|
|
20
19
|
const run = (async () => {
|
|
21
20
|
try {
|
|
22
21
|
const raw = await fetchRaw(canonical);
|
|
23
|
-
const v = verifyPromptArtifact(raw
|
|
22
|
+
const v = verifyPromptArtifact(raw);
|
|
24
23
|
if (!v.ok || v.artifact.artifactDigest.replace(/^sha256:/, "").toLowerCase() !== hex) {
|
|
25
24
|
log.warn("center_prompts_backfill_rejected", { digest: canonical, ...(v.ok ? { got: v.artifact.artifactDigest, code: "digest_mismatch" } : { code: v.code, reason: v.reason }) });
|
|
26
25
|
return undefined;
|
|
27
26
|
}
|
|
28
|
-
await inner.put(
|
|
27
|
+
await inner.put(v.artifact).catch(() => recordFailOpen("server.prompts.artifact-cache-write-failed", `digest=${canonical}`));
|
|
29
28
|
log.info("center_prompts_backfilled", { digest: canonical });
|
|
30
|
-
return
|
|
29
|
+
return v.artifact;
|
|
31
30
|
}
|
|
32
31
|
catch (e) {
|
|
33
32
|
log.warn("center_prompts_backfill_failed", { digest: canonical, err: String(e) });
|
|
@@ -42,22 +41,22 @@ export function withPromptArtifactBackfill(inner, fetchRaw, log) {
|
|
|
42
41
|
},
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
|
-
export async function
|
|
44
|
+
export async function applyCenterArtifact(source, next, prev, log, phase) {
|
|
46
45
|
try {
|
|
47
|
-
if (next
|
|
48
|
-
if (prev?.
|
|
46
|
+
if (next !== undefined) {
|
|
47
|
+
if (prev?.artifactDigest === next.artifactDigest)
|
|
49
48
|
return true;
|
|
50
|
-
const r = await source.applySnapshot(next
|
|
49
|
+
const r = await source.applySnapshot(next);
|
|
51
50
|
if (r.ok) {
|
|
52
51
|
log.info("center_prompts_catalog_applied", { phase, artifactDigest: r.artifactDigest });
|
|
53
52
|
return true;
|
|
54
53
|
}
|
|
55
|
-
log.warn("center_prompts_catalog_apply_failed", { phase, code: r.code, reason: r.reason, note: "
|
|
54
|
+
log.warn("center_prompts_catalog_apply_failed", { phase, code: r.code, reason: r.reason, note: "the candidate passed the judge but the source apply failed (disk/state) — built-ins unaffected; candidate unchanged; the transition retries on the next refresh tick" });
|
|
56
55
|
return false;
|
|
57
56
|
}
|
|
58
|
-
if (prev
|
|
59
|
-
await source.applyDisabled(`${phase}:
|
|
60
|
-
log.info("center_prompts_catalog_disabled", { phase, note: "
|
|
57
|
+
if (prev !== undefined || source.current?.() !== undefined || source.persistedActive?.() === true) {
|
|
58
|
+
await source.applyDisabled(`${phase}:prompts-absent`);
|
|
59
|
+
log.info("center_prompts_catalog_disabled", { phase, note: "center layer withdrawn — the engine's candidate is cleared (does not revive offline)" });
|
|
61
60
|
}
|
|
62
61
|
return true;
|
|
63
62
|
}
|
|
@@ -66,22 +65,9 @@ export async function applyCatalogToSource(source, next, prev, log, phase) {
|
|
|
66
65
|
return false;
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
|
-
export function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
export function centerIdentityAssembled(prompts, scenarioName, isAssembled) {
|
|
74
|
-
return scenarioDecls(prompts, scenarioName).some((d) => d.slot === "identity" && isAssembled(d.text));
|
|
75
|
-
}
|
|
76
|
-
function scenarioDecls(prompts, scenarioName) {
|
|
77
|
-
const overrides = prompts.scenarioOverrides;
|
|
78
|
-
if (overrides) {
|
|
79
|
-
if (Object.hasOwn(overrides, scenarioName)) {
|
|
80
|
-
const hit = overrides[scenarioName];
|
|
81
|
-
if (hit)
|
|
82
|
-
return hit;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return prompts.sections;
|
|
68
|
+
export function centerSourceOnError(log) {
|
|
69
|
+
return (err, ctx) => {
|
|
70
|
+
log.warn("prompt_composition_warning", { sessionId: ctx.sessionId, ...(ctx.classification !== undefined ? { classification: ctx.classification } : {}), info: err instanceof Error ? err.message : String(err) });
|
|
71
|
+
};
|
|
86
72
|
}
|
|
87
73
|
//# sourceMappingURL=center-prompts.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ENGINE_CAPABILITIES } from "@sema-agent/core";
|
|
2
|
-
import { ownCredentialsWithheld } from "../server-secret-env.js";
|
|
2
|
+
import { ownCredentialsWithheld, ownCredentialValuesWithheld } from "../server-secret-env.js";
|
|
3
3
|
const ENGINE_CAPABILITY_FACTS = {
|
|
4
4
|
"inherit_env.own_credentials_withheld": ownCredentialsWithheld,
|
|
5
|
+
"inherit_env.own_credential_values_withheld": ownCredentialValuesWithheld,
|
|
5
6
|
};
|
|
6
7
|
export function engineCapabilityBits() {
|
|
7
8
|
const out = {};
|