@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
|
@@ -2,10 +2,13 @@ import { readMcpSourceLabel } from "../mcp-source-label.js";
|
|
|
2
2
|
import { readMcpToolFaces } from "../mcp-tool-faces.js";
|
|
3
3
|
import { skillContentHash } from "@sema-agent/settings-schema";
|
|
4
4
|
import { readMcpToolAxes } from "@sema-agent/core";
|
|
5
|
-
import {
|
|
5
|
+
import { MCP_CONTENT_ORIGINS, isContentOriginWord, isUsableWireName } from "@sema-agent/settings-schema";
|
|
6
|
+
import { describeBadContentOrigin, describeBadWireName } from "../caller-text-echo.js";
|
|
6
7
|
import { noteMcpAssertionHeaderNotSent } from "../mcp-assertion-header.js";
|
|
7
8
|
import { SHA256_HEX_RE } from "../digest-form.js";
|
|
8
|
-
|
|
9
|
+
function skillBodyPresent(body) {
|
|
10
|
+
return body !== undefined && body !== "";
|
|
11
|
+
}
|
|
9
12
|
export async function applySkillsManifest(baseline, manifest, bodies, logger) {
|
|
10
13
|
const diskCacheDir = bodies.skillBodyCacheDir;
|
|
11
14
|
const { promises: fsp } = await import("node:fs");
|
|
@@ -19,7 +22,7 @@ export async function applySkillsManifest(baseline, manifest, bodies, logger) {
|
|
|
19
22
|
try {
|
|
20
23
|
const text = await fsp.readFile(joinPath(diskCacheDir, hex), "utf8");
|
|
21
24
|
if (skillContentHash(text) === hash)
|
|
22
|
-
return text;
|
|
25
|
+
return skillBodyPresent(text) ? text : undefined;
|
|
23
26
|
logger?.warn("web_admin_skill_cache_corrupt", { hash, note: "on-disk body fails its own hash — ignored, re-reading from the config source" });
|
|
24
27
|
}
|
|
25
28
|
catch {
|
|
@@ -53,8 +56,8 @@ export async function applySkillsManifest(baseline, manifest, bodies, logger) {
|
|
|
53
56
|
content = await diskRead(m.contentHash);
|
|
54
57
|
if (content === undefined) {
|
|
55
58
|
const answered = await bodies.fetchSkillContent(m.contentHash);
|
|
56
|
-
if (answered
|
|
57
|
-
logger?.warn("web_admin_skill_failed", { name: m.name, hash: m.contentHash, reason: "body_absent", note: "the config source holds no body for this hash — this entry is NOT installed; the baseline skill of this name (if any) stays" });
|
|
59
|
+
if (!skillBodyPresent(answered)) {
|
|
60
|
+
logger?.warn("web_admin_skill_failed", { name: m.name, hash: m.contentHash, reason: "body_absent", note: "the config source holds no body for this hash (absent, or an empty string) — this entry is NOT installed; the baseline skill of this name (if any) stays" });
|
|
58
61
|
continue;
|
|
59
62
|
}
|
|
60
63
|
content = answered;
|
|
@@ -109,7 +112,7 @@ export function resolveMcpServers(mcp, logger) {
|
|
|
109
112
|
logger?.warn("web_admin_mcp_content_class_invalid", {
|
|
110
113
|
server: s.name,
|
|
111
114
|
value: describeBadContentOrigin(s.contentOrigin),
|
|
112
|
-
allowed:
|
|
115
|
+
allowed: MCP_CONTENT_ORIGINS,
|
|
113
116
|
note: "declaration DROPPED — this server's tools keep the pre-378 default (external content, session gets marked). Fix the center entry; the server itself still mounts.",
|
|
114
117
|
});
|
|
115
118
|
}
|
|
@@ -371,9 +371,8 @@ export interface EffectiveConfig {
|
|
|
371
371
|
* 这条腿对本部署不存在,四键仍由 env / 引擎默认独占。restart-to-apply(boot 期被 `createRunnerDeps`
|
|
372
372
|
* 捕获),改动经 `read-face` restart 片通告。 */
|
|
373
373
|
readFace?: CenterReadFace;
|
|
374
|
-
/** prompts 域(
|
|
375
|
-
*
|
|
376
|
-
* 声明键位存在(unknown:候选门是唯一解释者,这里不复刻形)。 */
|
|
374
|
+
/** prompts 域(中心层;wire 形只有一种 = 契约包 `EffectivePromptsWire` `{ schemaVersion: 2, artifact }`)—— 判法只在候选判官一处
|
|
375
|
+
* (`prompts-domain-validate.ts` 的 `judgePromptsWire`,经 `judgeConfigCandidate`),本 interface 只声明键位存在(unknown:判官是唯一解释者,这里不复刻形)。 */
|
|
377
376
|
prompts?: unknown;
|
|
378
377
|
}
|
|
379
378
|
/** (stage7 P5,registry-core 0.8 `execution` 域): the center-resolved per-principal execution
|
|
@@ -39,6 +39,41 @@ export declare function workspaceCacheClaimOf(spaceKey: string): {
|
|
|
39
39
|
name: string;
|
|
40
40
|
label: string;
|
|
41
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* The directories of the sandbox image the cache volume must never hide — a CLOSED set of path prefixes: a mount that is one of them,
|
|
44
|
+
* sits under one, or is an ancestor of one (a volume mounted there shadows everything the image keeps at that path) refuses boot.
|
|
45
|
+
* - the system roots every image has (`/bin` `/boot` `/dev` `/etc` `/lib` `/lib64` `/proc` `/root` `/run` `/sbin` `/sys` `/usr` `/var`);
|
|
46
|
+
* - `/tmp` — the adapter's own scratch (the snapshot archive, the background-job directories);
|
|
47
|
+
* - `/opt/sema` — the image's package-source hook the pod start runs;
|
|
48
|
+
* - `/home/sandbox` — the sandbox user's home in the images this lane ships.
|
|
49
|
+
* One reading: the workspace mount is the set's one dynamic member (`K8S_MOUNT_PATH`); config reads both through {@link mountsOverlap}.
|
|
50
|
+
*/
|
|
51
|
+
export declare const WORKSPACE_CACHE_MOUNT_RESERVED: readonly ["/bin", "/boot", "/dev", "/etc", "/home/sandbox", "/lib", "/lib64", "/opt/sema", "/proc", "/root", "/run", "/sbin", "/sys", "/tmp", "/usr", "/var"];
|
|
52
|
+
/** The reserved directory a cache mount collides with (at / under / above it), or `undefined`. `mount` is absolute and normalized. */
|
|
53
|
+
export declare function reservedMountCollision(mount: string): (typeof WORKSPACE_CACHE_MOUNT_RESERVED)[number] | undefined;
|
|
54
|
+
/** The most spaces a {@link CacheMissMemory} holds at once (a process serving more spaces than this forgets the oldest first). */
|
|
55
|
+
export declare const CACHE_MISS_MEMORY_CAP = 1024;
|
|
56
|
+
/** A cache volume that could not be had for a pod and cost a wait: its claim did not bind in time, or it bound and the pod carrying it did not become ready. */
|
|
57
|
+
export interface CacheMissRecord {
|
|
58
|
+
readonly reason: "claim_unbound" | "claim_unmountable";
|
|
59
|
+
readonly detail: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The process's memory of cache volumes that could not be had — per space, for a window the caller states: a run that waited out a volume the cluster could not
|
|
63
|
+
* bind says so here, and the next runs of that space inside the window start without it at once (no claim request, no pod waiting on it) instead of each paying the
|
|
64
|
+
* whole wait again. A cache is regenerable, so "not asked for a while" costs only builds that re-download. Keyed by the claim's one-way digest (never the space key
|
|
65
|
+
* itself); bounded ({@link CACHE_MISS_MEMORY_CAP}: expired entries go first, then the oldest). One per deployment, held by the per-run binding — never process-global.
|
|
66
|
+
*/
|
|
67
|
+
export interface CacheMissMemory {
|
|
68
|
+
/** `spaceKey`'s volume could not be had: remembered for `windowMs` from now. */
|
|
69
|
+
remember(spaceKey: string, miss: CacheMissRecord, windowMs: number): void;
|
|
70
|
+
/** Inside the window ⇒ the remembered miss; otherwise `undefined` (and the entry is dropped). */
|
|
71
|
+
recall(spaceKey: string): CacheMissRecord | undefined;
|
|
72
|
+
/** Entries held (expired ones that were not read again included). */
|
|
73
|
+
size(): number;
|
|
74
|
+
}
|
|
75
|
+
/** A fresh {@link CacheMissMemory} (`now` = the clock, epoch ms; a test hands its own). */
|
|
76
|
+
export declare function createCacheMissMemory(now?: () => number): CacheMissMemory;
|
|
42
77
|
/** Does the cache mount overlap the workspace mount (equal, or one inside the other)? Both are absolute, normalized paths. */
|
|
43
78
|
export declare function mountsOverlap(a: string, b: string): boolean;
|
|
44
79
|
export {};
|
package/dist/workspace-cache.js
CHANGED
|
@@ -23,6 +23,42 @@ export function workspaceCacheClaimOf(spaceKey) {
|
|
|
23
23
|
const digest = createHash("sha256").update(spaceKey).digest("hex").slice(0, 20);
|
|
24
24
|
return { name: `ws-cache-${digest}`, label: digest };
|
|
25
25
|
}
|
|
26
|
+
export const WORKSPACE_CACHE_MOUNT_RESERVED = ["/bin", "/boot", "/dev", "/etc", "/home/sandbox", "/lib", "/lib64", "/opt/sema", "/proc", "/root", "/run", "/sbin", "/sys", "/tmp", "/usr", "/var"];
|
|
27
|
+
export function reservedMountCollision(mount) {
|
|
28
|
+
return WORKSPACE_CACHE_MOUNT_RESERVED.find((dir) => mountsOverlap(mount, dir));
|
|
29
|
+
}
|
|
30
|
+
export const CACHE_MISS_MEMORY_CAP = 1024;
|
|
31
|
+
export function createCacheMissMemory(now = Date.now) {
|
|
32
|
+
const held = new Map();
|
|
33
|
+
const keyOf = (spaceKey) => workspaceCacheClaimOf(spaceKey).label;
|
|
34
|
+
return {
|
|
35
|
+
remember(spaceKey, miss, windowMs) {
|
|
36
|
+
const at = now();
|
|
37
|
+
const key = keyOf(spaceKey);
|
|
38
|
+
held.delete(key);
|
|
39
|
+
held.set(key, { miss, until: at + windowMs });
|
|
40
|
+
if (held.size <= CACHE_MISS_MEMORY_CAP)
|
|
41
|
+
return;
|
|
42
|
+
for (const [k, e] of held)
|
|
43
|
+
if (e.until <= at)
|
|
44
|
+
held.delete(k);
|
|
45
|
+
while (held.size > CACHE_MISS_MEMORY_CAP)
|
|
46
|
+
held.delete(held.keys().next().value);
|
|
47
|
+
},
|
|
48
|
+
recall(spaceKey) {
|
|
49
|
+
const key = keyOf(spaceKey);
|
|
50
|
+
const e = held.get(key);
|
|
51
|
+
if (e === undefined)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (e.until <= now()) {
|
|
54
|
+
held.delete(key);
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return e.miss;
|
|
58
|
+
},
|
|
59
|
+
size: () => held.size,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
26
62
|
export function mountsOverlap(a, b) {
|
|
27
63
|
const inside = (x, y) => x === y || x.startsWith(y.endsWith("/") ? y : `${y}/`);
|
|
28
64
|
return inside(a, b) || inside(b, a);
|
|
@@ -71,8 +71,9 @@ export declare const WORKSPACE_SNAPSHOT_EXCLUDE_INVALID = "config.workspace_snap
|
|
|
71
71
|
* space snapshot and the park suspend share it). Unset / empty ⇒ no table (the upload command is what it always was).
|
|
72
72
|
*
|
|
73
73
|
* The item form is CLOSED: plain relative path segments — no leading `/`, no `.` / `..` / empty segment (`./x`, `a//b`, a
|
|
74
|
-
* trailing `/`), no whitespace, no quote characters, no control characters
|
|
75
|
-
*
|
|
74
|
+
* trailing `/`), no whitespace, no quote characters, no control characters, and no whole wildcard (an item made only of `*` / `?`
|
|
75
|
+
* names no path: `*` would exclude every top-level entry and the snapshot would be empty). Tar wildcards inside a segment (`*.log`)
|
|
76
|
+
* are items like any other. A project's `.gitignore` is NOT read (a second grammar, per project, not equivalent to tar's). Items are
|
|
76
77
|
* trimmed (the CSV separator's spacing is not part of an item); a bad item refuses boot naming its position — the value is a
|
|
77
78
|
* path pattern, never a secret, so it is echoed.
|
|
78
79
|
*/
|
package/dist/workspace-space.js
CHANGED
|
@@ -30,6 +30,8 @@ function snapshotExcludeItemProblem(item) {
|
|
|
30
30
|
return "not a plain path (it holds whitespace, a quote or a control character)";
|
|
31
31
|
if (item.startsWith("/"))
|
|
32
32
|
return "absolute (a leading /) — items are relative to the workspace root";
|
|
33
|
+
if (/^[*?]+$/.test(item))
|
|
34
|
+
return "a whole wildcard (only `*` / `?` — it names no path and would leave the snapshot without any top-level entry)";
|
|
33
35
|
const segments = item.split("/");
|
|
34
36
|
if (segments.includes(".."))
|
|
35
37
|
return "escaping the workspace (a .. segment)";
|
|
@@ -525,6 +525,7 @@ a moment ago. If you omit `created`, the consumer reports the weaker of the two
|
|
|
525
525
|
| `callback_error` | a callback/hook on the device side failed (exec family) |
|
|
526
526
|
| `invalid` | the arguments do not make sense for this target (e.g. `readLink` on a non-symlink) |
|
|
527
527
|
| `is_directory` | a file operation hit a directory |
|
|
528
|
+
| `liveness_no_output` | **you** killed the command because it produced no output for your own silence window (a hung command); the wall-clock budget `timeoutMs` running out stays `timeout`. The frame has no field for the window length — do not invent one |
|
|
528
529
|
| `not_directory` | a directory operation hit a non-directory |
|
|
529
530
|
| `not_found` | the path does not exist |
|
|
530
531
|
| `not_supported` | you do not implement this face (prefer simply not declaring it) |
|
|
@@ -539,10 +540,16 @@ a moment ago. If you omit `created`, the consumer reports the weaker of the two
|
|
|
539
540
|
| `transport_lost` | a transport the device itself depends on went away |
|
|
540
541
|
| `unknown` | none of the above |
|
|
541
542
|
|
|
542
|
-
|
|
543
|
+
Three codes carry load-bearing semantics upstream and must not be used loosely:
|
|
543
544
|
|
|
544
545
|
- `timeout` is treated as **retryable**. Use it only when you actually killed the work and know it is
|
|
545
546
|
dead. If you are not sure the command is dead, use `outcome_unknown`.
|
|
547
|
+
- `liveness_no_output` is the same kind of word — the command ran, you killed it, **retryable** — with a
|
|
548
|
+
different cause: it names the silence, `timeout` names the wall-clock budget. They are two different
|
|
549
|
+
numbers and the model is told a different sentence for each, so report the bound that actually fired.
|
|
550
|
+
The same rule applies: use it only when you actually killed the work and know it is dead; if you are
|
|
551
|
+
not sure, use `outcome_unknown`. On a file instruction it is a protocol violation (a file operation has
|
|
552
|
+
no silence window) and the server reads it as `unknown`.
|
|
546
553
|
- `outcome_unknown` is never auto-retried, anywhere. It is the honest answer for "the command may have
|
|
547
554
|
already run and I cannot confirm". Choosing `timeout`/`transport_lost` instead invites a second
|
|
548
555
|
execution of a command that already had side effects.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sema-agent/server",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.132.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",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"build:binary:run-local:darwin-arm64": "bun build --compile --target=bun-darwin-arm64 src/run-local.ts --outfile dist/run-local-darwin-arm64"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@sema-agent/core": "7.
|
|
68
|
-
"@sema-agent/settings-schema": "
|
|
67
|
+
"@sema-agent/core": "7.53.0",
|
|
68
|
+
"@sema-agent/settings-schema": "14.0.0",
|
|
69
69
|
"e2b": "^2.28.0",
|
|
70
70
|
"libsodium-wrappers": "^0.8.4",
|
|
71
71
|
"mysql2": "^3.22.4",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"sharp": "^0.35.3"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@sema-agent/sdk": "23.
|
|
83
|
+
"@sema-agent/sdk": "23.1.0",
|
|
84
84
|
"@types/libsodium-wrappers": "^0.7.14",
|
|
85
85
|
"@types/node": "22.10.2",
|
|
86
86
|
"@types/pg": "^8.20.0",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* 换钉前的**排空检查 —— `DB_BACKEND=local`(File 店)车道**,只读。随 npm 包出(`scripts/drain-check-local.mjs`)。
|
|
4
|
-
*
|
|
4
|
+
* 一次跑**八条判据**(判据表 {@link DRAIN_CRITERIA},每条一行末行、各自的命中行;SQL 车道的同一判据是同目录随包的 `drain-check.mysql.sql` / `drain-check.pg.sql`,
|
|
5
5
|
* 每条判据一段、段首标记 `-- drain-check:<判据名>:<后端>`,判据名与本表的 `name` 同一个词):
|
|
6
6
|
* · `skill-grants-rollback`(**回滚**到 7.115.x 前,即引擎从 7.41 退回 7.40):四样任一 ——
|
|
7
7
|
* ① pending 行带 `state.skillGrants`(本次 run 冻结在行上的技能授予行:模型激活 / 子代捕获写下的放行与禁止);
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
* 账本行的读法是服务里那一只(`src/orchestration/workflow-agent-session-index.ts` 的 `readAgentSessionLedgerLine`),经编译产物
|
|
31
31
|
* `dist/orchestration/workflow-agent-session-index.js` 取 —— 本脚本只按 runId 折叠;读不出的行计入 `corrupt`(rc 2:读不出的那一行可能正是点名某张待批卡的那一份);
|
|
32
32
|
* 窗与删码:本判据是一次性迁移 M9 的读侧半场 —— 窗口与删码清单见引擎启动期一次性迁移登记表(one-time-migrations)M9 一行,随 M9 一起删;这里不写第二份窗。
|
|
33
|
+
* · `parked-tool-lists`(升级到 7.132.0 前)/ `own-tool-lists-rollback`(从 7.132.0 回滚前):停驻行记下的工具名清单 / 7.52 写下的 `ownToolLists`(判据与出路见判据表那两条的注);
|
|
33
34
|
* · `retired-mode-seed`(换钉 7.113.0 前,core 7.39.0 删掉退役 mode-seed 的一次性迁移):pending 行的 `state.inheritedGate` 仍带退役成员;
|
|
34
35
|
* · `permissions-allow-list`(换钉 7.117.0 前,本服务把 `settings.permissions.allow` 整份交给引擎的 allow 层):pending 行所在会话的续跑上下文
|
|
35
36
|
* (`checkpoint-ctx/*.json` 的信封 `{ sessionId, updatedAt, ctx }`)里,`ctx.body.settings.permissions.allow` 是非空数组,且 `ctx.permissionsAllowReading` 不是 `"allow_layer"`
|
|
@@ -72,12 +73,15 @@
|
|
|
72
73
|
* · 每条命中一行:`SKILL-GRANTS-ROW token=<token> sessionId=<id> createdAt=<ms> member=<skillGrants|boundGrantDigest|userInvokedSkills|disallowedTools>` / `SKILL-MANIFEST-ROW token=<token> sessionId=<id> createdAt=<ms> member=<skills|agents.skills>` /
|
|
73
74
|
* `SKILL-DENY-INERT-ROW token=<token> sessionId=<id> createdAt=<ms> member=<skills|agents.skills>` /
|
|
74
75
|
* `WORKFLOW-PARK-ROW token=<token> sessionId=<id> createdAt=<ms> runId=<点名它的 run,逗号连接>` /
|
|
76
|
+
* `PARKED-TOOL-LISTS-ROW token=<token> sessionId=<id> createdAt=<ms> member=<toolCeiling|constraintChain|boundGrantDigest>` / `OWN-TOOL-LISTS-ROW token=<token> sessionId=<id> createdAt=<ms>` /
|
|
75
77
|
* `ALLOW-LIST-ROW token=<token> sessionId=<id> createdAt=<ms>` / `RETIRED-ROW token=<token> sessionId=<id> createdAt=<ms> member=<成员>`;
|
|
76
78
|
* · 每条判据一行末行(表序;`RETIRED-MODE-SEED` 那一行恒在最后,7.113.0 起读「最后一行」的下游不受影响;`PERMISSIONS-ALLOW-LIST` 仍是倒数第二行):
|
|
77
79
|
* `SKILL-GRANTS rows=<命中数> pending=<pending 行数> total=<行数> unknownEvents=<n> corrupt=<n> root=<实际读的数据根>`,
|
|
78
80
|
* `RETIRED-SKILL-MANIFEST rows=<命中数> pending=<pending 行数> total=<行数> unknownEvents=<n> corrupt=<n> root=<实际读的数据根>`,
|
|
79
81
|
* `SKILL-DENY-INERT rows=<命中数> pending=<pending 行数> total=<行数> unknownEvents=<n> corrupt=<n> root=<实际读的数据根>`,
|
|
80
82
|
* `WORKFLOW-PARK-HOLDER rows=<命中数> pending=<pending 行数> total=<行数> unknownEvents=<n> corrupt=<n> root=<实际读的数据根>`,
|
|
83
|
+
* `PARKED-TOOL-LISTS rows=<命中数> pending=<pending 行数> total=<行数> unknownEvents=<n> corrupt=<n> root=<实际读的数据根>`,
|
|
84
|
+
* `OWN-TOOL-LISTS-ROLLBACK rows=<命中数> pending=<pending 行数> total=<行数> unknownEvents=<n> corrupt=<n> root=<实际读的数据根>`,
|
|
81
85
|
* `PERMISSIONS-ALLOW-LIST rows=<命中数> pending=<pending 行数> total=<行数> unknownEvents=<n> corrupt=<n> root=<实际读的数据根>`,
|
|
82
86
|
* `RETIRED-MODE-SEED rows=<命中数> pending=<pending 行数> total=<行数> unknownEvents=<n> corrupt=<n> root=<实际读的数据根>`;
|
|
83
87
|
* `corrupt` = 共用扫描的坏记录 + 这条判据自己读不懂的旁路输入(`permissions-allow-list`:读不懂的 ctx 档,文件名进 stderr —— 一份读不懂的 ctx 可能正是某条 pending 行带 `allow` 的那一份;
|
|
@@ -427,6 +431,35 @@ export const DRAIN_CRITERIA = [
|
|
|
427
431
|
return runs === undefined ? undefined : ` runId=${runs.join(",")}`;
|
|
428
432
|
},
|
|
429
433
|
},
|
|
434
|
+
{
|
|
435
|
+
// 升级到 7.132.0 之前(引擎 7.52 在认领前按规范拼写读停驻行记下的工具名清单):pending 行带这三座任一 —— 子代的工具天花板 `state.toolCeiling`(键在场且不是空数组)、
|
|
436
|
+
// 冻结的父约束链 `state.inheritedGate.constraintChain`(非空数组)、Skill 卡的清单绑定 `pendingAction.boundGrantDigest`。7.51 按原拼写记它们,7.52 读到 `Bash(*)` / `Tool()` /
|
|
437
|
+
// 读不出的名 / deny `*` ⇒ 认领前拒(409 `checkpoint.config_refused`)、名字集的重复条目 ⇒ `resume.parent_constraint_mismatch`、Skill 清单读作空的条目 ⇒ `resume_outcome_invalid`;
|
|
438
|
+
// 卡都留 pending。引擎的拼写判法没有在包根给出 ⇒ 与随包 SQL 同一个**真超集**(座在不在、非空),不是精确判;命中行点名是哪一座。出路见随包 `MIGRATION.md` 7.132.0 节。
|
|
439
|
+
// 天花板一座不要求「是数组」:引擎对在场的天花板就读,非列表的值(JSON null / 对象 / 字符串)同样认领前拒(`not_a_list`);空数组读不出条目、引擎不拒。链只认数组(引擎 `Array.isArray(chain)` 才读)。
|
|
440
|
+
name: "parked-tool-lists",
|
|
441
|
+
tail: "PARKED-TOOL-LISTS",
|
|
442
|
+
hit: "PARKED-TOOL-LISTS-ROW",
|
|
443
|
+
load: () => ({ input: undefined, corrupt: 0, unreadable: [] }),
|
|
444
|
+
judge: (row) => {
|
|
445
|
+
const state = isObject(row.state) ? /** @type {Record<string, unknown>} */ (row.state) : {};
|
|
446
|
+
const nonEmptyList = (/** @type {unknown} */ v) => Array.isArray(v) && v.length > 0;
|
|
447
|
+
const emptyList = (/** @type {unknown} */ v) => Array.isArray(v) && v.length === 0;
|
|
448
|
+
if (Object.hasOwn(state, "toolCeiling") && !emptyList(state.toolCeiling)) return " member=toolCeiling";
|
|
449
|
+
const gate = isObject(state.inheritedGate) ? /** @type {Record<string, unknown>} */ (state.inheritedGate) : {};
|
|
450
|
+
if (nonEmptyList(gate.constraintChain)) return " member=constraintChain";
|
|
451
|
+
if (isObject(row.pendingAction) && Object.hasOwn(/** @type {Record<string, unknown>} */ (row.pendingAction), "boundGrantDigest")) return " member=boundGrantDigest";
|
|
452
|
+
return undefined;
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
// 从 7.132.0 回滚到 7.131.x 之前:7.52 写下 `state.ownToolLists` 的行(读方要求词 `own_tool_lists`,7.51 读不了)。键在不在,精确。
|
|
457
|
+
name: "own-tool-lists-rollback",
|
|
458
|
+
tail: "OWN-TOOL-LISTS-ROLLBACK",
|
|
459
|
+
hit: "OWN-TOOL-LISTS-ROW",
|
|
460
|
+
load: () => ({ input: undefined, corrupt: 0, unreadable: [] }),
|
|
461
|
+
judge: (row) => (isObject(row.state) && Object.hasOwn(/** @type {Record<string, unknown>} */ (row.state), "ownToolLists") ? "" : undefined),
|
|
462
|
+
},
|
|
430
463
|
{
|
|
431
464
|
name: "permissions-allow-list",
|
|
432
465
|
tail: "PERMISSIONS-ALLOW-LIST",
|
|
@@ -8,13 +8,15 @@
|
|
|
8
8
|
-- sessions 命中行所在的会话 id,逗号连接,新的在前。以 hit_rows 为准:这一列被会话变量 group_concat_max_len(缺省 1024 字节)截断时,列出的会话数会少于 hit_rows ——
|
|
9
9
|
-- 先处理列出的再跑一次,或先在同一个会话里 SET SESSION group_concat_max_len = 1048576; 再跑本文件(本文件自己只含 SELECT)。
|
|
10
10
|
-- 每段只数 pending 行(已决 / 已过期的行不数);判据只看**键在不在 / 值形**,不读行的其余内容。
|
|
11
|
-
-- DB_BACKEND=local(File 店)没有 SQL:用同目录的 drain-check-local.mjs
|
|
11
|
+
-- DB_BACKEND=local(File 店)没有 SQL:用同目录的 drain-check-local.mjs,八条判据同名。
|
|
12
12
|
--
|
|
13
|
-
--
|
|
13
|
+
-- 八条判据(顺序同 drain-check-local.mjs 的判据表):
|
|
14
14
|
-- skill-grants-rollback 回滚到 7.115.x(引擎 7.40)之前:7.116.0 停驻的行带 7.40 不读的技能授予节 / 卡绑定 / 会话上下文里的人点名技能 / 还没被激活的技能声明的禁止清单。
|
|
15
15
|
-- retired-skill-manifest 升级到 7.116.0 之前:停驻、持久化提交体里技能(顶层 skills[] 或子代 agents[].skills[])还带已退役的 manifest 键。
|
|
16
16
|
-- skill-deny-inert 换钉 7.117.0 之前:停驻、提交体里技能(顶层 skills[] 或子代 agents[].skills[])的 disallowedTools 有引擎会读成空的条目的**候选**(见该段注)。
|
|
17
17
|
-- workflow-park-holder 换钉 7.118.0 之前 / 从 7.118.0 回滚到 7.117.x 之前:此刻待批、且子会话被 workflow park 索引点名的卡(workflow 子代卡;见该段注)。
|
|
18
|
+
-- parked-tool-lists 升级到 7.132.0 之前:停驻行记着子代工具天花板 / 冻结的父约束链 / Skill 卡的清单绑定(7.52 在认领前按规范拼写读它们)的**候选**(见该段注)。
|
|
19
|
+
-- own-tool-lists-rollback 从 7.132.0 回滚到 7.131.x 之前:7.132.0 停驻、带 state.ownToolLists 的行(7.131.x 读不了)。
|
|
18
20
|
-- permissions-allow-list 换钉 7.117.0 之前:停驻、提交体 settings.permissions.allow 是非空数组且读法记号不是当前的 "allow_layer"(无记号 = 名单时代;"statement" = 表态时代)。
|
|
19
21
|
-- retired-mode-seed 换钉 7.113.0 之前:检查点的 inheritedGate 里仍带退役 mode-seed 成员。
|
|
20
22
|
|
|
@@ -87,6 +89,32 @@ FROM checkpoint k
|
|
|
87
89
|
WHERE k.status = 'pending'
|
|
88
90
|
AND EXISTS (SELECT 1 FROM workflow_agent_session w WHERE w.session_id = k.session_id);
|
|
89
91
|
|
|
92
|
+
-- drain-check:parked-tool-lists:mysql —— 期望 hit_rows = 0;每一行 = 一条**候选**:升级到 7.132.0 后续跑可能在认领前被拒的停驻行。
|
|
93
|
+
-- 在**升级之前**、对 7.131.x 的数据跑。7.131.x 的引擎(7.51)把行上的三样按原拼写记下,7.132.0 的引擎(7.52)在认领前按规范拼写读它们:
|
|
94
|
+
-- 子代的工具天花板 state.toolCeiling(`Bash(*)` / `Tool()` / 内容形 / 读不出的名 / deny `*` ⇒ 409 checkpoint.config_refused,blockedBy = config.tool_face_control,field = inheritedGate);
|
|
95
|
+
-- 冻结的父约束链 state.inheritedGate.constraintChain(非规范名同上;名字集里的重复条目 ⇒ 409 resume.parent_constraint_mismatch);
|
|
96
|
+
-- Skill 卡绑的两只清单 pendingAction.boundGrantDigest(清单里读作空的条目 ⇒ 409 resume_outcome_invalid,field = boundGrantDigest)。
|
|
97
|
+
-- 卡都留 pending、行留停驻。SQL 读不了引擎的拼写判法 ⇒ 数的是**真超集**:带这三样任一的 pending 行 —— 天花板键在场且不是空数组(引擎对在场的天花板就读:
|
|
98
|
+
-- 非列表的值〔JSON null / 对象 / 字符串〕同样认领前拒,所以不要求「是数组」;空数组读不出条目、不数),链是非空数组(引擎只读数组形的链),或卡带绑定摘要。
|
|
99
|
+
-- 出路(见随包 MIGRATION.md 7.132.0 节):升级前让它们在 7.131.x 上跑完 / 决完;已经升级的,在 7.131.x 的副本上续跑,或取消那条 run 重提。
|
|
100
|
+
SELECT 'parked-tool-lists' AS criterion, COUNT(*) AS hit_rows,
|
|
101
|
+
COALESCE(GROUP_CONCAT(k.session_id ORDER BY k.created_at_ms DESC SEPARATOR ','), '') AS sessions
|
|
102
|
+
FROM checkpoint k
|
|
103
|
+
WHERE k.status = 'pending'
|
|
104
|
+
AND ((JSON_CONTAINS_PATH(k.checkpoint, 'one', '$.state.toolCeiling')
|
|
105
|
+
AND NOT (JSON_TYPE(JSON_EXTRACT(k.checkpoint, '$.state.toolCeiling')) = 'ARRAY' AND JSON_LENGTH(JSON_EXTRACT(k.checkpoint, '$.state.toolCeiling')) = 0))
|
|
106
|
+
OR (JSON_TYPE(JSON_EXTRACT(k.checkpoint, '$.state.inheritedGate.constraintChain')) = 'ARRAY' AND JSON_LENGTH(JSON_EXTRACT(k.checkpoint, '$.state.inheritedGate.constraintChain')) > 0)
|
|
107
|
+
OR JSON_CONTAINS_PATH(k.checkpoint, 'one', '$.pendingAction.boundGrantDigest'));
|
|
108
|
+
|
|
109
|
+
-- drain-check:own-tool-lists-rollback:mysql —— 期望 hit_rows = 0;每一行 = 一条从 7.132.0 回滚到 7.131.x 后续跑会被拒的停驻行。
|
|
110
|
+
-- 在**回滚之前**、对 7.132.0 的数据跑:7.132.0 的引擎在子代行上记下这条腿的工具清单是谁写的(state.ownToolLists,行上的读方要求词 own_tool_lists),
|
|
111
|
+
-- 7.131.x 的引擎读不了 ⇒ 409 checkpoint.unsupported_version(writerVersion 比 readerVersion 新)、卡留 pending。判据 = 键在不在(精确)。
|
|
112
|
+
SELECT 'own-tool-lists-rollback' AS criterion, COUNT(*) AS hit_rows,
|
|
113
|
+
COALESCE(GROUP_CONCAT(k.session_id ORDER BY k.created_at_ms DESC SEPARATOR ','), '') AS sessions
|
|
114
|
+
FROM checkpoint k
|
|
115
|
+
WHERE k.status = 'pending'
|
|
116
|
+
AND JSON_CONTAINS_PATH(k.checkpoint, 'one', '$.state.ownToolLists');
|
|
117
|
+
|
|
90
118
|
-- drain-check:permissions-allow-list:mysql —— 期望 hit_rows = 0;每一行 = 一条升级后续跑会被拒的停驻行。
|
|
91
119
|
-- 读哪一份续跑上下文:与续跑腿同 —— workflow 子代的停驻行(在 workflow_agent_session 里登记过)续跑时读的是**发起这条 workflow 的会话**那一份
|
|
92
120
|
-- (workflow_run.run 的 originatingSessionId);其余行读自己会话那一份。一个子会话可以被好几条 workflow 记录点名(续跑链 / 分叉;7.118.0 起索引主键是
|
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
-- hit_rows 命中的停驻行数(pending 行里算命中的那些);**全部为 0 才算排空**,非 0 ⇒ 逐条答完或取消(各判据对应的升级 / 回滚说明见随包 MIGRATION.md);
|
|
8
8
|
-- sessions 命中行所在的会话 id,逗号连接,新的在前。
|
|
9
9
|
-- 每段只数 pending 行(已决 / 已过期的行不数);判据只看**键在不在 / 值形**,不读行的其余内容。
|
|
10
|
-
-- DB_BACKEND=local(File 店)没有 SQL:用同目录的 drain-check-local.mjs
|
|
10
|
+
-- DB_BACKEND=local(File 店)没有 SQL:用同目录的 drain-check-local.mjs,八条判据同名。
|
|
11
11
|
--
|
|
12
|
-
--
|
|
12
|
+
-- 八条判据(顺序同 drain-check-local.mjs 的判据表):
|
|
13
13
|
-- skill-grants-rollback 回滚到 7.115.x(引擎 7.40)之前:7.116.0 停驻的行带 7.40 不读的技能授予节 / 卡绑定 / 会话上下文里的人点名技能 / 还没被激活的技能声明的禁止清单。
|
|
14
14
|
-- retired-skill-manifest 升级到 7.116.0 之前:停驻、持久化提交体里技能(顶层 skills[] 或子代 agents[].skills[])还带已退役的 manifest 键。
|
|
15
15
|
-- skill-deny-inert 换钉 7.117.0 之前:停驻、提交体里技能(顶层 skills[] 或子代 agents[].skills[])的 disallowedTools 有引擎会读成空的条目的**候选**(见该段注)。
|
|
16
16
|
-- workflow-park-holder 换钉 7.118.0 之前 / 从 7.118.0 回滚到 7.117.x 之前:此刻待批、且子会话被 workflow park 索引点名的卡(workflow 子代卡;见该段注)。
|
|
17
|
+
-- parked-tool-lists 升级到 7.132.0 之前:停驻行记着子代工具天花板 / 冻结的父约束链 / Skill 卡的清单绑定(7.52 在认领前按规范拼写读它们)的**候选**(见该段注)。
|
|
18
|
+
-- own-tool-lists-rollback 从 7.132.0 回滚到 7.131.x 之前:7.132.0 停驻、带 state.ownToolLists 的行(7.131.x 读不了)。
|
|
17
19
|
-- permissions-allow-list 换钉 7.117.0 之前:停驻、提交体 settings.permissions.allow 是非空数组且读法记号不是当前的 "allow_layer"(无记号 = 名单时代;"statement" = 表态时代)。
|
|
18
20
|
-- retired-mode-seed 换钉 7.113.0 之前:检查点的 inheritedGate 里仍带退役 mode-seed 成员。
|
|
19
21
|
|
|
@@ -96,6 +98,31 @@ FROM checkpoint k
|
|
|
96
98
|
WHERE k.status = 'pending'
|
|
97
99
|
AND EXISTS (SELECT 1 FROM workflow_agent_session w WHERE w.session_id = k.session_id);
|
|
98
100
|
|
|
101
|
+
-- drain-check:parked-tool-lists:pg —— 期望 hit_rows = 0;每一行 = 一条**候选**:升级到 7.132.0 后续跑可能在认领前被拒的停驻行。
|
|
102
|
+
-- 在**升级之前**、对 7.131.x 的数据跑。7.131.x 的引擎(7.51)把行上的三样按原拼写记下,7.132.0 的引擎(7.52)在认领前按规范拼写读它们:
|
|
103
|
+
-- 子代的工具天花板 state.toolCeiling(`Bash(*)` / `Tool()` / 内容形 / 读不出的名 / deny `*` ⇒ 409 checkpoint.config_refused,blockedBy = config.tool_face_control,field = inheritedGate);
|
|
104
|
+
-- 冻结的父约束链 state.inheritedGate.constraintChain(非规范名同上;名字集里的重复条目 ⇒ 409 resume.parent_constraint_mismatch);
|
|
105
|
+
-- Skill 卡绑的两只清单 pendingAction.boundGrantDigest(清单里读作空的条目 ⇒ 409 resume_outcome_invalid,field = boundGrantDigest)。
|
|
106
|
+
-- 卡都留 pending、行留停驻。SQL 读不了引擎的拼写判法 ⇒ 数的是**真超集**:带这三样任一的 pending 行 —— 天花板键在场且不是空数组(引擎对在场的天花板就读:
|
|
107
|
+
-- 非列表的值〔JSON null / 对象 / 字符串〕同样认领前拒,所以不要求「是数组」;空数组读不出条目、不数),链是非空数组(引擎只读数组形的链),或卡带绑定摘要。
|
|
108
|
+
-- 出路(见随包 MIGRATION.md 7.132.0 节):升级前让它们在 7.131.x 上跑完 / 决完;已经升级的,在 7.131.x 的副本上续跑,或取消那条 run 重提。
|
|
109
|
+
SELECT 'parked-tool-lists' AS criterion, count(*) AS hit_rows,
|
|
110
|
+
coalesce(string_agg(k.session_id, ',' ORDER BY k.created_at_ms DESC), '') AS sessions
|
|
111
|
+
FROM checkpoint k
|
|
112
|
+
WHERE k.status = 'pending'
|
|
113
|
+
AND (((k.checkpoint #> '{state,toolCeiling}') IS NOT NULL AND (k.checkpoint #> '{state,toolCeiling}') <> '[]'::jsonb)
|
|
114
|
+
OR (jsonb_typeof(k.checkpoint #> '{state,inheritedGate,constraintChain}') = 'array' AND (k.checkpoint #> '{state,inheritedGate,constraintChain}') <> '[]'::jsonb)
|
|
115
|
+
OR (k.checkpoint -> 'pendingAction') ? 'boundGrantDigest');
|
|
116
|
+
|
|
117
|
+
-- drain-check:own-tool-lists-rollback:pg —— 期望 hit_rows = 0;每一行 = 一条从 7.132.0 回滚到 7.131.x 后续跑会被拒的停驻行。
|
|
118
|
+
-- 在**回滚之前**、对 7.132.0 的数据跑:7.132.0 的引擎在子代行上记下这条腿的工具清单是谁写的(state.ownToolLists,行上的读方要求词 own_tool_lists),
|
|
119
|
+
-- 7.131.x 的引擎读不了 ⇒ 409 checkpoint.unsupported_version(writerVersion 比 readerVersion 新)、卡留 pending。判据 = 键在不在(精确)。
|
|
120
|
+
SELECT 'own-tool-lists-rollback' AS criterion, count(*) AS hit_rows,
|
|
121
|
+
coalesce(string_agg(k.session_id, ',' ORDER BY k.created_at_ms DESC), '') AS sessions
|
|
122
|
+
FROM checkpoint k
|
|
123
|
+
WHERE k.status = 'pending'
|
|
124
|
+
AND (k.checkpoint -> 'state') ? 'ownToolLists';
|
|
125
|
+
|
|
99
126
|
-- drain-check:permissions-allow-list:pg —— 期望 hit_rows = 0;每一行 = 一条升级后续跑会被拒的停驻行。
|
|
100
127
|
-- 读哪一份续跑上下文:与续跑腿同 —— workflow 子代的停驻行(在 workflow_agent_session 里登记过)续跑时读的是**发起这条 workflow 的会话**那一份
|
|
101
128
|
-- (workflow_run.run 的 originatingSessionId);其余行读自己会话那一份。一个子会话可以被好几条 workflow 记录点名(续跑链 / 分叉;7.118.0 起索引主键是
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* [ref](板 [ref]②/[ref]④ 两次点名的 server 接线半场)—— 零记忆面部署形的**持久记忆披露**。
|
|
3
|
-
*
|
|
4
|
-
* 病(core [ref] 实测,[ref] 立案):一台没有任何持久记忆面的部署,用户说「请记住 X」,模型回一句
|
|
5
|
-
* 「已经记住了」——落盘处并不存在。用户带着「这条事实已入库」的信念离开,下一次会话才发现是空的。
|
|
6
|
-
*
|
|
7
|
-
* core 5.26.0 的分工:引擎**能自证**只读的两态(engine 侧 `writeScope:null` / runner 侧 `handsReadOnly`)
|
|
8
|
-
* 由引擎自动挂 `MEMORY_READONLY_NOTICE`;而「整台部署根本没有记忆面」这一形 core 只导出文本
|
|
9
|
-
* (`NO_PERSISTENT_MEMORY_NOTICE`)、**不注入** —— 逐字原文:「A deployment that composes its own prompt
|
|
10
|
-
* should include this block exactly when no memory face is mounted」。组装归宿主,与 `MEMORY_SAFETY`
|
|
11
|
-
* 同姿势。本模块就是那半场。
|
|
12
|
-
*
|
|
13
|
-
* ⚠️ 两条边界,越界即双重注入/假话:
|
|
14
|
-
* · **engine 在场就不是我们的座位**。哪怕 `memoryWrite:false`(writeScope null)——那恰恰是引擎自己
|
|
15
|
-
* 挂只读披露的状态,server 再叠一句口径不同的「你没有持久记忆」= 同一件事两种说法同框。
|
|
16
|
-
* · **推断到「有落盘路」就闭嘴**。判别式与 core 的 `rosterCanPersist` 同口径(已知落盘路 = 这一 run 名册上
|
|
17
|
-
* 真挂着的文件写工具 / 可写 shell)。「名册上还剩什么」**只读引擎的答案**:core 7.49.0(#1623)起一 run 的可用工具是
|
|
18
|
-
* 引擎一只选择器(`allowTools` ∩ … − `excludeTools`,别名 / `Tool(content)` / `mcp__srv…` 都由它读)在 prepare 算出的,
|
|
19
|
-
* 本模块不再读请求的任何一张工具名表 —— 名册臂在装配时刻读 provider 拿到的 `ctx.tools`(选择器之后的名册)。
|
|
20
|
-
* 负控仍然成立:必须**全部**已知落盘路都不在名册上才算断链(摘掉 `Write`,Bash / Edit 还在)。
|
|
21
|
-
*/
|
|
22
|
-
import { type PromptProvider, type ToolCatalogEntry } from "@sema-agent/core";
|
|
23
|
-
import type { ScenarioHands } from "./hands-lane.js";
|
|
24
|
-
import { type ExecutionLane } from "../execution-lane-caps.js";
|
|
25
|
-
/**
|
|
26
|
-
* 「已知落盘路」的判据,作用在 core **静态工具目录**的一行上(S-503 / [ref])—— 与 core 自己的
|
|
27
|
-
* `rosterCanPersist` 推断逐条同形,取的是同一批目录属性,不是它结论的抄件:
|
|
28
|
-
* · `mountedBy` 落在 core 的 `HANDS_BAND_TAGS` 里 —— 手带 band 之外的定义(记忆面工具、调度族)
|
|
29
|
-
* 不在本判别式说得着的面上:本判别式的输入全是**手带事实**(`hands` / `handsReadOnly` / 名册上的手带名),
|
|
30
|
-
* 把一只 band 外的写工具算进来,就是拿一条根本没挂的通道去撤回披露(fail-open);
|
|
31
|
-
* · `face.effect !== "read"`(缺席读 `write`,与 core 同缺省)—— 只读 shell 壳在这里出局,它与全壳
|
|
32
|
-
* 共用 `Bash` 这个 wire 名,靠的正是这一位分开;
|
|
33
|
-
* · `face.pathTarget.access !== "read"`(文件写工具)**或** `face.family === "shell"`(可写 shell)。
|
|
34
|
-
*
|
|
35
|
-
* 🔴 这条析取式**不是** effect=write 的全集:core 逐字裁过「a generic write-effect tool does NOT count
|
|
36
|
-
* — a mail sender's side effect is not a memory store」。`TaskStop` 正是那种(effect=write、没有路径
|
|
37
|
-
* 目标、不是 shell),它在这条判据下自己就出局 —— 改前那张手抄名单要靠人记得别把它写进去。
|
|
38
|
-
*
|
|
39
|
-
* 一条都派生不出来 ⇒ **抛**(不是回一个空集):空集会让下面那条判据读成「一条落盘路都不剩」⇒ 每台
|
|
40
|
-
* 有手的机器都开始披露「本部署没有持久记忆」,而那句话在那时是假的。目录换形是提货期事实(静态数据,
|
|
41
|
-
* 与请求/环境无关:要么恒抛要么恒不抛),所以这一抛是**提货门**,不是运行期风险。
|
|
42
|
-
*/
|
|
43
|
-
export declare function persistencePathToolNamesOf(entries: readonly ToolCatalogEntry[]): readonly string[];
|
|
44
|
-
/**
|
|
45
|
-
* 「已知落盘路」的工具名闭集 —— **由 core 的静态工具目录派生**,本仓不再存第二份名表
|
|
46
|
-
* (S-503 / [ref];改前是手抄的四名表 Write / Edit / NotebookEdit / Bash,没有任何差集门)。
|
|
47
|
-
*
|
|
48
|
-
* 为什么手抄在这一位上特别危险:core 改名/加一只写工具,手抄表静默失配(fail-open 方向)—— 名册上真正的
|
|
49
|
-
* 落盘路已经全不在了,而我们对着一张旧名单答「还剩」。
|
|
50
|
-
* 判据的属主现在是 {@link persistencePathToolNamesOf},值的属主是 core 的目录行。
|
|
51
|
-
*/
|
|
52
|
-
export declare const KNOWN_PERSISTENCE_TOOL_NAMES: readonly string[];
|
|
53
|
-
/** 披露段在 `prompt.assembled` 清单里的段 id(`core/` 命名空间是 core 保留的,部署段一律自家前缀)。 */
|
|
54
|
-
export declare const NO_PERSISTENT_MEMORY_SECTION_ID = "sema/memory.no-persistent";
|
|
55
|
-
/** 判别式的全部输入 —— 每一位都是**部署/装配期事实**,没有一位来自请求体的自我表态。 */
|
|
56
|
-
export interface MemoryFaceFacts {
|
|
57
|
-
/** 这一腿挂不挂记忆面 —— 由唯一属主 `memory-scope.ts` `memoryFaceMounted(spec.memory)` 算出(与 core `prepareMemory`
|
|
58
|
-
* 同判:`normalizeMemorySpec(...)?.enabled === true`)。`false` = 引擎未接 / 多租户 dark / remote lane fail-closed /
|
|
59
|
-
* S-405 `memory:"off"`(键在场但 `enabled:false`)—— 殊途同归:core 不会 prepare 记忆,也就不会挂任何披露。
|
|
60
|
-
* 🔴 不再收 `TaskSpec.memory` 本体:按「键在不在场」判是 7.84.0 前的病(合并复审 车HF F1)。
|
|
61
|
-
* 🔴 属主会**抛**(值闭包门没过的手搓 spec —— 单数 `scope` / 非 `"off"` 的 `capture`),理由与两个属主
|
|
62
|
-
* 的坐标逐字写在 `memory-scope.ts` 的 `memoryFaceMounted` 头注里;本判别式不接这条臂(接了就是在
|
|
63
|
-
* 披露轴上静默 fail-open)。 */
|
|
64
|
-
memoryFaceMounted: boolean;
|
|
65
|
-
/** 部署声明 `MEMORY_PERSISTENCE_CAPABLE`(三态)。`true` = operator 自证有推断看不见的持久通道
|
|
66
|
-
* (自定义 writer / MCP 记忆服务)⇒ 披露会变成假话,撤回;`false` = 强制披露;缺席 ⇒ 走推断。 */
|
|
67
|
-
declaredCapable: boolean | undefined;
|
|
68
|
-
/** 本请求命中场景的手带表态([ref] 判别位)。`none` = 该场景跑在不挂 `executionEnvFactory` 的 Runner 上,
|
|
69
|
-
* core 的手带 band(Bash/Edit/Write/…)整批不 mount。 */
|
|
70
|
-
hands: ScenarioHands;
|
|
71
|
-
/** 折完 governance+settings 后的最终 `handsReadOnly`(`AUTONOMY=read-only` 收窄;plan 模式不点亮它 —— plan 的手带照挂、调用时由引擎问)。手带只剩读腿。 */
|
|
72
|
-
handsReadOnly: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* 本部署的手带**挂没挂**(= core 拿没拿到执行环境;能力表 `coreRemoteExecutionEnv` 位,经
|
|
75
|
-
* {@link buildNoticeLaneFacts} 取)。`false` = `in-process`:core 落 `StubExecutionEnv`,手带整族不 mount
|
|
76
|
-
* ⇒ **一条落盘路都没有**,不管名册上写着什么名字。
|
|
77
|
-
* 🔴 S-602(clay 裁 [ref] A):改前这里只有一位 `remoteExecutionEnv`(判别位 = `REMOTE_EXEC` 设没设),
|
|
78
|
-
* 于是 in-process 读成「不是 remote ⇒ 手就在本机 fs 上 ⇒ 已知落盘路真的在」—— 而那条 lane 根本没有手,
|
|
79
|
-
* 用户说「记住 X」拿到的是无处落盘的幻觉回执([ref] 要消灭的原形)。一位拆成两位,各答各的问题。
|
|
80
|
-
*/
|
|
81
|
-
handsWired: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* 手带的文件平面**不在**本 worker(能力表 `hostFilePlane` 答否;经 {@link buildNoticeLaneFacts} 取)——
|
|
84
|
-
* 沙箱 / 远端 / 设备车道。为什么这一位必须进判别式(codex 复审 round2 [high],已核真):core 的
|
|
85
|
-
* `rosterCanPersist` 在沙箱盘上把 Write/Edit/NotebookEdit/Bash **全部不算**落盘路(每任务即焚,够不着
|
|
86
|
-
* host 记忆根)。而 server 在任何 remote 车道上默认让记忆引擎 dark —— 两件事合起来正是**最常见的云部署形**:
|
|
87
|
-
* 引擎不在、手带在,却一份持久面都没有。
|
|
88
|
-
* ⚠️ `host` 车道这一位是 `false`(文件平面就是本机);core 自己仍把 host 判 remote,那一面由装配层的
|
|
89
|
-
* `effectiveMemoryPersistenceCapable`(host 腿自动声明 capable)在臂② 接住,不归本位。
|
|
90
|
-
*/
|
|
91
|
-
filePlaneRemote: boolean;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* S-602 —— 判别式的两位**车道事实**,由能力表派生([ref]:不手抄投影)。resolve-spec 的装配点只调它,
|
|
95
|
-
* 不在调用点手写 `config.remoteExec !== undefined`(门 D R4)。
|
|
96
|
-
*/
|
|
97
|
-
export declare function buildNoticeLaneFacts(lane: ExecutionLane): Pick<MemoryFaceFacts, "handsWired" | "filePlaneRemote">;
|
|
98
|
-
/**
|
|
99
|
-
* 披露的三种结局。`"roster"` = 部署事实答不完,剩下的问题(「名册上还剩不剩已知落盘路」)只有引擎在 prepare
|
|
100
|
-
* 之后知道 —— 由 {@link withNoPersistentMemoryNotice} 在装配时刻读 provider 拿到的名册作答,不在 resolveSpec 期猜。
|
|
101
|
-
*/
|
|
102
|
-
export type NoPersistentMemoryNotice = "disclose" | "silent" | "roster";
|
|
103
|
-
/**
|
|
104
|
-
* 该不该把 `NO_PERSISTENT_MEMORY_NOTICE` 组进本次任务的 system prompt。
|
|
105
|
-
*
|
|
106
|
-
* 优先序(每一条都有独立理由,不是同一条判据的三种写法):
|
|
107
|
-
* ① engine 在场 ⇒ `silent`(引擎的座位,见文件头注);
|
|
108
|
-
* ② 部署显式声明(或 host 腿装配层自动声明)⇒ 声明说了算(`true` ⇒ `silent` / `false` ⇒ `disclose`)—— operator 的部署
|
|
109
|
-
* 事实压过我们的推断,与 core 对 `memoryPersistenceCapable` 的处置同向;
|
|
110
|
-
* ③ 否则推断:手带没挂 / 场景摘手 / 只读 / 文件平面不在本机 ⇒ `disclose`;都不是 ⇒ `roster`(名册上还剩不剩已知落盘路,
|
|
111
|
-
* 读引擎选择器之后的名册 —— 本模块不读请求的任何工具名表,core 7.49.0 #1623 起那是引擎一只运算的输入)。
|
|
112
|
-
* 🔴 S-602 只改臂③ 里「车道」那一段(`handsWired` / `filePlaneRemote`),①② 的优先序一字不动 —— 「in-process ⇒
|
|
113
|
-
* 披露」只在这两臂**之后**成立(挂了记忆面、或声明了 capable 的 in-process 部署照旧不披露)。
|
|
114
|
-
*/
|
|
115
|
-
export declare function noPersistentMemoryNotice(facts: MemoryFaceFacts): NoPersistentMemoryNotice;
|
|
116
|
-
/**
|
|
117
|
-
* 名册臂:引擎选择器之后的名册上还剩不剩已知落盘路(`KNOWN_PERSISTENCE_TOOL_NAMES` 任一名在册)。⚠️ 负控:摘掉**一个**
|
|
118
|
-
* `Write` 不算断链(Bash / Edit 还在)—— 必须**全部**已知落盘路都不在名册上。名册为空(`excludeAllTools`)⇒ 一条都不剩。
|
|
119
|
-
*/
|
|
120
|
-
export declare function rosterLeavesPersistencePath(tools: readonly {
|
|
121
|
-
readonly name: string;
|
|
122
|
-
}[]): boolean;
|
|
123
|
-
/**
|
|
124
|
-
* 把披露段组进一个 prompt provider,**按 provider 自己的钩子形分腿**(换形会改段身份与 append 座位):
|
|
125
|
-
* · typed(`stableBlocks`)⇒ {@link mountNotice}(普通形追加 behavior 声明;已组装 identity 形接在其文本后)。
|
|
126
|
-
* · string(`stableSystem`)⇒ 接在 role 层文本之后(落进 `core/role.base` 段)。
|
|
127
|
-
* · 两个钩子都没有(= core 会用 `defaultPromptProvider`)⇒ **只发一条 typed 声明**,role 层留给 core 自己铸。
|
|
128
|
-
*
|
|
129
|
-
* ⚠️ 最后一腿为什么不是「自铸 role 层」(2026-08-12 复扫 medium,已实测):自铸形
|
|
130
|
-
* `stableSystem: (ctx) => ${ctx.userSystemPrompt ?? DEFAULT_SYSTEM_PROMPT}\n\n${段落}` 把**调用方的**
|
|
131
|
-
* systemPrompt 逐字变成了 provider 的输出。调用方传一份已组装 prompt(集成方/center 的常见形)时,装配器的
|
|
132
|
-
* 迁移卫就在 provider 输出上探到三锚 ⇒ pass-through 臂 ⇒ 保留集无 `core/role.append` ⇒ 已被 append 门放行的
|
|
133
|
-
* `appendSystemPrompt`/`settings.outputStyle` 静默蒸发(门在包装**之前**按未包装的 provider 判,两边分家)。
|
|
134
|
-
* 走 typed 声明腿就没有这条耦合:role 层仍由 core 按 `userSystemPrompt ?? DEFAULT_SYSTEM_PROMPT` 自己铸,
|
|
135
|
-
* 我方只贡献一条 behavior 段,`providerDropsAppend` 的判决包装前后逐格相同。
|
|
136
|
-
*/
|
|
137
|
-
export declare function withNoPersistentMemoryNotice(provider: PromptProvider | undefined, when: Exclude<NoPersistentMemoryNotice, "silent">): PromptProvider;
|
|
138
|
-
//# sourceMappingURL=memory-notice.d.ts.map
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { describeToolCatalog, HANDS_BAND_TAGS, NO_PERSISTENT_MEMORY_NOTICE } from "@sema-agent/core";
|
|
2
|
-
import { hasConstitutionAnchors } from "../task-settings.js";
|
|
3
|
-
import { executionLaneCaps } from "../execution-lane-caps.js";
|
|
4
|
-
export function persistencePathToolNamesOf(entries) {
|
|
5
|
-
const names = new Set();
|
|
6
|
-
for (const e of entries) {
|
|
7
|
-
if (!e.mountedBy.some((tag) => HANDS_BAND_TAGS.has(tag)))
|
|
8
|
-
continue;
|
|
9
|
-
if ((e.face.effect ?? "write") === "read")
|
|
10
|
-
continue;
|
|
11
|
-
const pt = e.face.pathTarget;
|
|
12
|
-
if (!((pt !== undefined && pt.access !== "read") || e.face.family === "shell"))
|
|
13
|
-
continue;
|
|
14
|
-
names.add(e.name);
|
|
15
|
-
}
|
|
16
|
-
if (names.size === 0) {
|
|
17
|
-
throw new Error("core tool catalog yields no hand-band persistence path (file-write target or writable shell) — " +
|
|
18
|
-
"the #148 disclosure would start claiming 'no persistent memory' on every machine that HAS hands. " +
|
|
19
|
-
"Re-read core's rosterCanPersist inference and re-derive persistencePathToolNamesOf.");
|
|
20
|
-
}
|
|
21
|
-
return Object.freeze([...names]);
|
|
22
|
-
}
|
|
23
|
-
export const KNOWN_PERSISTENCE_TOOL_NAMES = persistencePathToolNamesOf(describeToolCatalog());
|
|
24
|
-
export const NO_PERSISTENT_MEMORY_SECTION_ID = "sema/memory.no-persistent";
|
|
25
|
-
export function buildNoticeLaneFacts(lane) {
|
|
26
|
-
const caps = executionLaneCaps(lane);
|
|
27
|
-
return { handsWired: caps.coreRemoteExecutionEnv === "supported", filePlaneRemote: caps.hostFilePlane !== "supported" };
|
|
28
|
-
}
|
|
29
|
-
export function noPersistentMemoryNotice(facts) {
|
|
30
|
-
if (facts.memoryFaceMounted)
|
|
31
|
-
return "silent";
|
|
32
|
-
if (facts.declaredCapable !== undefined)
|
|
33
|
-
return facts.declaredCapable ? "silent" : "disclose";
|
|
34
|
-
if (facts.hands === "none" || facts.handsReadOnly)
|
|
35
|
-
return "disclose";
|
|
36
|
-
if (!facts.handsWired)
|
|
37
|
-
return "disclose";
|
|
38
|
-
if (facts.filePlaneRemote)
|
|
39
|
-
return "disclose";
|
|
40
|
-
return "roster";
|
|
41
|
-
}
|
|
42
|
-
export function rosterLeavesPersistencePath(tools) {
|
|
43
|
-
return tools.some((t) => KNOWN_PERSISTENCE_TOOL_NAMES.includes(t.name));
|
|
44
|
-
}
|
|
45
|
-
const NOTICE_BLOCK = { id: NO_PERSISTENT_MEMORY_SECTION_ID, slot: "behavior", text: NO_PERSISTENT_MEMORY_NOTICE };
|
|
46
|
-
function mountNotice(decls) {
|
|
47
|
-
const assembledIdentity = decls.find((d) => d.slot === "identity" && hasConstitutionAnchors(d.text));
|
|
48
|
-
if (!assembledIdentity)
|
|
49
|
-
return [...decls, NOTICE_BLOCK];
|
|
50
|
-
return decls.map((d) => (d === assembledIdentity ? { id: d.id, slot: d.slot, text: `${d.text}\n\n${NO_PERSISTENT_MEMORY_NOTICE}` } : d));
|
|
51
|
-
}
|
|
52
|
-
export function withNoPersistentMemoryNotice(provider, when) {
|
|
53
|
-
const due = (ctx) => when === "disclose" || !rosterLeavesPersistencePath(ctx.tools);
|
|
54
|
-
if (provider?.stableBlocks) {
|
|
55
|
-
const blocks = provider.stableBlocks.bind(provider);
|
|
56
|
-
return { ...provider, stableBlocks: (ctx) => (due(ctx) ? mountNotice(blocks(ctx)) : blocks(ctx)) };
|
|
57
|
-
}
|
|
58
|
-
if (provider?.stableSystem) {
|
|
59
|
-
const stable = provider.stableSystem.bind(provider);
|
|
60
|
-
return { ...provider, stableSystem: (ctx) => (due(ctx) ? `${stable(ctx)}\n\n${NO_PERSISTENT_MEMORY_NOTICE}` : stable(ctx)) };
|
|
61
|
-
}
|
|
62
|
-
return { stableBlocks: (ctx) => (due(ctx) ? [NOTICE_BLOCK] : []) };
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=memory-notice.js.map
|