@sema-agent/core 7.71.0 → 7.72.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/CHANGELOG.md +193 -0
- package/dist/agents/cross-session-ref.d.ts +2 -2
- package/dist/agents/cross-session-ref.js +7 -2
- package/dist/agents/inherited-tool-pool.d.ts +4 -1
- package/dist/agents/inherited-tool-pool.js +7 -5
- package/dist/agents/send-message-tool.js +6 -2
- package/dist/agents/subagent.js +5 -1
- package/dist/agents/verify.js +1 -0
- package/dist/core/a2a.d.ts +24 -3
- package/dist/core/a2a.js +27 -8
- package/dist/core/agent-state.d.ts +28 -7
- package/dist/core/agent-state.js +19 -6
- package/dist/core/approval-object.d.ts +7 -3
- package/dist/core/approval-object.js +30 -9
- package/dist/core/checkpoint-features.d.ts +13 -3
- package/dist/core/checkpoint-features.js +34 -5
- package/dist/core/checkpoint-requirements.d.ts +14 -1
- package/dist/core/checkpoint-row-verdict.d.ts +1 -1
- package/dist/core/checkpoint-row-verdict.js +3 -3
- package/dist/core/checkpoint-store.d.ts +4 -0
- package/dist/core/effective-path-target.d.ts +19 -0
- package/dist/core/effective-path-target.js +95 -38
- package/dist/core/engine-notice.d.ts +4 -1
- package/dist/core/engine-version.js +1 -1
- package/dist/core/file-history-store.d.ts +15 -4
- package/dist/core/file-history-store.js +53 -23
- package/dist/core/gate-fold.js +3 -1
- package/dist/core/governance-codes.d.ts +4 -1
- package/dist/core/governance-codes.js +4 -0
- package/dist/core/judged-read.d.ts +57 -0
- package/dist/core/judged-read.js +1 -0
- package/dist/core/mcp-host-seat.d.ts +5 -0
- package/dist/core/mcp-host-seat.js +7 -1
- package/dist/core/mcp.js +3 -1
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/index.js +1 -1
- package/dist/core/memory-engine/layout.js +6 -4
- package/dist/core/memory-engine/scope-contract.d.ts +59 -6
- package/dist/core/memory-engine/scope-contract.js +90 -25
- package/dist/core/mounted-mcp.d.ts +7 -2
- package/dist/core/mounted-mcp.js +10 -1
- package/dist/core/param-rule-reach.d.ts +8 -3
- package/dist/core/param-rule-reach.js +9 -1
- package/dist/core/parent-spec-seat.d.ts +11 -1
- package/dist/core/parent-spec-seat.js +14 -0
- package/dist/core/peer-registration.d.ts +52 -0
- package/dist/core/peer-registration.js +37 -0
- package/dist/core/peer-seat.d.ts +3 -1
- package/dist/core/permission-rule-model.js +1 -1
- package/dist/core/runner/chain-mismatch.d.ts +32 -0
- package/dist/core/runner/chain-mismatch.js +29 -0
- package/dist/core/runner/changes-history.d.ts +1 -0
- package/dist/core/runner/changes-history.js +2 -2
- package/dist/core/runner/contracts.d.ts +3 -0
- package/dist/core/runner/file-history-restore.d.ts +3 -1
- package/dist/core/runner/file-history-restore.js +9 -6
- package/dist/core/runner/loaded-skills.d.ts +2 -0
- package/dist/core/runner/loaded-skills.js +10 -0
- package/dist/core/runner/person-path-rows.d.ts +2 -4
- package/dist/core/runner/person-path-rows.js +2 -3
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +7 -2
- package/dist/core/runner/prepare-file-history.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +5 -0
- package/dist/core/runner/prepare-hands-readface.js +24 -21
- package/dist/core/runner/prepare-inherited-gate.d.ts +2 -2
- package/dist/core/runner/prepare-inherited-gate.js +1 -1
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -2
- package/dist/core/runner/prepare-memory-engine-session.js +2 -2
- package/dist/core/runner/prepare-memory.js +3 -15
- package/dist/core/runner/prepare-project-context.d.ts +1 -1
- package/dist/core/runner/prepare-project-context.js +3 -7
- package/dist/core/runner/prepare-protocol-tools.d.ts +5 -0
- package/dist/core/runner/prepare-protocol-tools.js +2 -2
- package/dist/core/runner/prepare-task.js +20 -16
- package/dist/core/runner/prepare-wiring-manifest.d.ts +2 -0
- package/dist/core/runner/prepare-wiring-manifest.js +4 -3
- package/dist/core/runner/read-session-changes.js +1 -1
- package/dist/core/runner/resume-checkpoint-screen.d.ts +8 -7
- package/dist/core/runner/resume-checkpoint-screen.js +7 -6
- package/dist/core/runner/rewind-files.js +3 -2
- package/dist/core/runner/run-leg.js +6 -2
- package/dist/core/runner/terminal-account.d.ts +4 -0
- package/dist/core/runner/terminal-account.js +7 -2
- package/dist/core/runner/tool-face-overlay.d.ts +2 -11
- package/dist/core/runner/tool-face-overlay.js +39 -0
- package/dist/core/runner/trim-stretch.js +7 -2
- package/dist/core/scheduler.d.ts +47 -7
- package/dist/core/scheduler.js +19 -7
- package/dist/core/secret-env.d.ts +7 -0
- package/dist/core/secret-env.js +1 -1
- package/dist/core/sensitive-path-policy.js +14 -7
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +7 -0
- package/dist/core/task-event.d.ts +4 -3
- package/dist/core/task-notification.d.ts +2 -1
- package/dist/core/task-spec.d.ts +13 -5
- package/dist/core/tool-catalog-entries.js +2 -0
- package/dist/core/tool-face-reader.js +1 -1
- package/dist/core/tool-face.d.ts +7 -0
- package/dist/core/tool-face.js +1 -0
- package/dist/core/tool-mount-facts.d.ts +4 -2
- package/dist/core/tool-mount-facts.js +3 -3
- package/dist/core/tool-mount-plan.d.ts +4 -2
- package/dist/core/tool-mount-plan.js +5 -5
- package/dist/core/tool-mount-static.d.ts +1 -1
- package/dist/core/tool-mount-static.js +25 -13
- package/dist/core/tool-registry.d.ts +33 -1
- package/dist/core/tool-registry.js +33 -0
- package/dist/core/tool-roster.d.ts +16 -0
- package/dist/core/tool-roster.js +6 -0
- package/dist/core/tool-spec.d.ts +4 -2
- package/dist/core/tools.d.ts +6 -0
- package/dist/core/tools.js +1 -1
- package/dist/core/wiring-manifest.d.ts +66 -12
- package/dist/core/wiring-manifest.js +37 -1
- package/dist/engine/harness/messages.d.ts +1 -1
- package/dist/engine/harness/messages.js +2 -1
- package/dist/engine/loop/types.d.ts +2 -0
- package/dist/engine/session/session.js +1 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.js +9 -6
- package/dist/orchestration/workflow.js +2 -1
- package/dist/stores/file/adoption/marker.d.ts +2 -27
- package/dist/stores/file/adoption/marker.js +12 -0
- package/dist/stores/file/index.d.ts +1 -1
- package/dist/stores/file/index.js +1 -1
- package/dist/tools/artifact/artifact-tool.js +11 -6
- package/dist/tools/fs/file-read-check.d.ts +45 -11
- package/dist/tools/fs/file-read-check.js +200 -57
- package/dist/tools/fs/judged-reads.d.ts +51 -0
- package/dist/tools/fs/judged-reads.js +68 -0
- package/dist/tools/fs/safety.d.ts +8 -0
- package/dist/tools/fs/safety.js +12 -1
- package/dist/tools/fs/shell-read-check.d.ts +16 -3
- package/dist/tools/fs/shell-read-check.js +4 -1
- package/dist/tools/fs/shell-read-establish.js +13 -3
- package/dist/tools/scheduler-store-move.d.ts +74 -0
- package/dist/tools/scheduler-store-move.js +103 -0
- package/dist/tools/scheduler-tools.d.ts +43 -29
- package/dist/tools/scheduler-tools.js +161 -118
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +47 -3
- package/wire-changes/answers/core-stores-sql@7.72.0.json +12 -0
- package/wire-changes/answers/core@7.72.0.json +84 -0
- package/wire-changes/answers/mods-kernel@7.72.0.json +7 -0
- package/wire-changes/answers/primitives@7.72.0.json +6 -0
- package/wire-changes/answers/wiki-gate@7.72.0.json +7 -0
- package/wire-changes/core-stores-sql@7.71.1.json +40 -0
- package/wire-changes/core-stores-sql@7.72.0.json +215 -0
- package/wire-changes/core@7.71.1.json +118 -0
- package/wire-changes/core@7.72.0.json +2426 -0
- package/wire-changes/mods-kernel@7.71.1.json +40 -0
- package/wire-changes/mods-kernel@7.72.0.json +147 -0
- package/wire-changes/primitives@7.71.1.json +40 -0
- package/wire-changes/primitives@7.72.0.json +143 -0
- package/wire-changes/wiki-gate@7.71.1.json +40 -0
- package/wire-changes/wiki-gate@7.72.0.json +145 -0
package/dist/core/a2a.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { type PeerSeat } from "./peer-seat.js";
|
|
|
4
4
|
import { type HostFloor } from "./host-floor.js";
|
|
5
5
|
import { type A2aRevocationStopCode, type ProtocolRevocationLedger, type RevocationProbe } from "./protocol-revocation.js";
|
|
6
6
|
import { type McpFailureFields } from "./mcp-failure.js";
|
|
7
|
-
import type { A2aServerSpec } from "./types.js";
|
|
7
|
+
import type { A2aServerSpec, ToolExecuteContext } from "./types.js";
|
|
8
|
+
import { type ToolCtxEnricher } from "./tools.js";
|
|
9
|
+
import { type TaskRegistry } from "./task-registry.js";
|
|
8
10
|
import type { AskDestination } from "./mcp-server-spec.js";
|
|
9
11
|
import type { EngineNotice } from "./engine-notice.js";
|
|
10
12
|
/** The hard per-skill description bound (ruled 2026-08-03: ~2KiB), counted in code points — the unit every cut in the description is made in. */
|
|
@@ -153,6 +155,22 @@ export declare const A2A_CALL_REFUSAL_CODES: Readonly<{
|
|
|
153
155
|
readonly changeable: "a2a.call_refused_changeable";
|
|
154
156
|
readonly retry_later: "a2a.call_refused_retry_later";
|
|
155
157
|
}>;
|
|
158
|
+
/** What ONE call of a peer's tool reaches beyond the peer: the task registry the run's background rows live in, the one completion sink the
|
|
159
|
+
* call's ctx carries, and whether a completion would come back through it (`admitsBackgroundLaunch` — the admission every background
|
|
160
|
+
* producer applies, judged at the call). One source for all three: the ctx the leg's builder makes for the call. */
|
|
161
|
+
export interface PeerCallReach {
|
|
162
|
+
readonly registry: TaskRegistry;
|
|
163
|
+
readonly completionSink: ToolExecuteContext["onTaskNotification"];
|
|
164
|
+
readonly admitted: boolean;
|
|
165
|
+
}
|
|
166
|
+
/** The reach of one call, computed from the ctx the leg's per-call builder (the one every mounted tool runs with) makes for it — the
|
|
167
|
+
* builder's answer with the call's own identity stamped over it (`stampCallIdentity`, the stamp every `defineTool` product applies). The
|
|
168
|
+
* registry is the ctx's (the run's), else the engine's one. Nothing computes it at a call today: a call is sent whether or not it is
|
|
169
|
+
* admitted, and reading a run's seats costs a call its host objects' accessors, so the work waits for the lane that consumes it. */
|
|
170
|
+
export declare function peerCallReach(enrichCtx: ToolCtxEnricher, toolCallId: string, signal: AbortSignal | undefined): PeerCallReach;
|
|
171
|
+
/** The means a peer tool carries to compute the reach of one call (`toolCallId`, `signal`): run once, it builds the call's ctx through the leg's
|
|
172
|
+
* builder and reads the registry, the completion sink and the admission off it. `undefined` ⇒ the tool was minted with no builder. */
|
|
173
|
+
export declare function peerToolReachOf(tool: AgentTool): ((toolCallId: string, signal?: AbortSignal) => PeerCallReach) | undefined;
|
|
156
174
|
/**
|
|
157
175
|
* Where a call goes, per tool name, for a leg's declared peers (the preparation door's frozen snapshot, the list the leg materializes):
|
|
158
176
|
* a tool under a peer's prefix answers that peer's {@link AskDestination}, read off its declaration; any other tool answers nothing. The
|
|
@@ -183,7 +201,10 @@ revocations?: ProtocolRevocationLedger & {
|
|
|
183
201
|
* prefix) — a pure predicate that answers a boolean and does not throw — asked of each declared peer before anything is sent to it. A peer
|
|
184
202
|
* it answers `false` for stays declared and is not contacted (no card request, no status row, no tool). Absent ⇒ every declared peer is
|
|
185
203
|
* dialed. It has no guard against a throwing or non-boolean answer (the MCP materialization's `dialable` is host-suppliable and has one);
|
|
186
|
-
* a form opened to a host needs that guard and a refusal code of its own.
|
|
204
|
+
* a form opened to a host needs that guard and a refusal code of its own. `enrichCtx` is the leg's per-call ctx builder, which every tool the
|
|
205
|
+
* materialization mints (a refresh's included) carries the means to compute its calls' reach with ({@link peerToolReachOf}); absent ⇒ the
|
|
206
|
+
* tools carry none (the library entrance). */
|
|
187
207
|
export declare function materializeLegA2aTools(revocations: RevocationProbe | undefined, specs: readonly A2aServerSpec[], principal: string | undefined, signal: AbortSignal | undefined, hostFloor: HostFloor | undefined, peerSeat: PeerSeat | undefined, onCredentialEchoed: ((peer: string, where: CredentialEchoSite) => void) | undefined, dialable?: (spec: {
|
|
188
208
|
readonly name: string;
|
|
189
|
-
}) => boolean, isolatePeers?: boolean)
|
|
209
|
+
}) => boolean, isolatePeers?: boolean, // the deployment's `RunnerDeps.a2a.isolatePeers`: an inside peer's skills keep the egress default ({@link a2aInsideRelaxed})
|
|
210
|
+
enrichCtx?: ToolCtxEnricher): Promise<MaterializedA2a>;
|
package/dist/core/a2a.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { A2A_NAMESPACE, a2aRegistrationProblems, findNamespacePrefixCollision, mintNamespacePrefix, mintNamespacedToolName } from "@sema-agent/primitives";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
|
+
import { a2aPeerRegistration, peerRegistrationDigestOf } from "./peer-registration.js";
|
|
4
5
|
import { A2A_SEMA_EXTENSIONS, A2A_SEMA_REFUSAL_CODES, A2A_SEMA_SKILL_ID_KEY, A2A_STATE_TABLE, A2A_TASK_STATES, readA2APeerState } from "./a2a-task-state.js";
|
|
5
6
|
import { PROTOCOL_PLAINTEXT_CREDENTIALS_CODE, assertEndpointBound, carriesDeclaredHeaders, crossesNetworkInClear, eraseSentCredentials, foreignLine, resolveProtocolHttpHeaders, underDeclaredHeaders } from "./protocol-http-auth.js";
|
|
6
7
|
import { carrierEcho, echoAnnouncer, erasedEcho, nameEchoes } from "./credential-echo.js";
|
|
@@ -9,6 +10,9 @@ import { fetchFollowing, hopRefusal, HOST_FLOOR_REFUSED_CODE } from "./host-floo
|
|
|
9
10
|
import { A2A_REVOCATION_UNREADABLE_CODE, ProtocolRevokedRefusal, REVOKED_PEER_CODES, libraryRevocationProbe } from "./protocol-revocation.js";
|
|
10
11
|
import { revokedCallResult } from "./mcp-server-link.js";
|
|
11
12
|
import { classifyMcpFailure, DELIVERED_BY_KIND, describeHttpTransportFailure, failureFields } from "./mcp-failure.js";
|
|
13
|
+
import { stampCallIdentity } from "./tools.js";
|
|
14
|
+
import { admitsBackgroundLaunch } from "./task-notification.js";
|
|
15
|
+
import { defaultTaskRegistry } from "./task-registry.js";
|
|
12
16
|
import { judgeA2aEntryRegistration, judgeEntryToolAxes, refusedDeclarer, snapshotDeclaredEntry } from "./locked-config.js";
|
|
13
17
|
import { INLINE_TRUNCATION_MARK_CODEPOINTS, delimitUntrusted, inlineUntrusted } from "./untrusted-text.js";
|
|
14
18
|
import { renderListEntry } from "./allow-entry.js";
|
|
@@ -756,16 +760,26 @@ async function awaitTaskOutcome(t, peerLabel, skillId, firstTask, signal, declar
|
|
|
756
760
|
observed = next;
|
|
757
761
|
}
|
|
758
762
|
}
|
|
759
|
-
function
|
|
763
|
+
export function peerCallReach(enrichCtx, toolCallId, signal) {
|
|
764
|
+
const ctx = stampCallIdentity(enrichCtx({ toolCallId, signal }), toolCallId, signal);
|
|
765
|
+
const completionSink = ctx.onTaskNotification;
|
|
766
|
+
return { registry: ctx.taskRegistry ?? defaultTaskRegistry, completionSink, admitted: admitsBackgroundLaunch(completionSink) };
|
|
767
|
+
}
|
|
768
|
+
const peerToolReach = new WeakMap();
|
|
769
|
+
export function peerToolReachOf(tool) {
|
|
770
|
+
return peerToolReach.get(tool);
|
|
771
|
+
}
|
|
772
|
+
function buildSkillTool(spec, t, skill, lifecycle, speaks, registration, enrichCtx) {
|
|
760
773
|
const peerLabel = inlineUntrusted(spec.name, A2A_ID_MAX_CHARS);
|
|
761
774
|
const name = mintNamespacedToolName(A2A_NAMESPACE, spec.name, skill.id);
|
|
762
|
-
|
|
775
|
+
const tool = {
|
|
763
776
|
name,
|
|
764
777
|
label: `${spec.name}:${skill.id}`,
|
|
765
778
|
description: skillDescription(peerLabel, skill),
|
|
766
779
|
parameters: a2aToolParameters(),
|
|
780
|
+
peerRegistration: registration,
|
|
767
781
|
permissionSeat: "passthrough",
|
|
768
|
-
execute: async (_toolCallId, params,
|
|
782
|
+
execute: async (_toolCallId, params, callSignal) => {
|
|
769
783
|
if (lifecycle.disposed) {
|
|
770
784
|
throw new Error(`a2a: the task that mounted peer "${peerLabel}" has ended — this tool no longer sends anything to the remote agent.`);
|
|
771
785
|
}
|
|
@@ -774,6 +788,7 @@ function buildSkillTool(spec, t, skill, lifecycle, speaks) {
|
|
|
774
788
|
if (message === undefined || message.trim() === "") {
|
|
775
789
|
throw new Error(`a2a: "message" is required — say what the remote agent "${peerLabel}" should do.`);
|
|
776
790
|
}
|
|
791
|
+
const signal = callSignal;
|
|
777
792
|
const taskId = asString(args["taskId"]);
|
|
778
793
|
const contextId = asString(args["contextId"]);
|
|
779
794
|
const result = await jsonRpc(t, "message/send", {
|
|
@@ -809,6 +824,9 @@ function buildSkillTool(spec, t, skill, lifecycle, speaks) {
|
|
|
809
824
|
throw new Error(`a2a: peer "${peerLabel}" answered message/send with ${JSON.stringify(foreignLine(kind ?? "(no kind)", A2A_ID_MAX_CHARS))}, which is neither a message nor a task`);
|
|
810
825
|
},
|
|
811
826
|
};
|
|
827
|
+
if (enrichCtx !== undefined)
|
|
828
|
+
peerToolReach.set(tool, (toolCallId, signal) => peerCallReach(enrichCtx, toolCallId, signal));
|
|
829
|
+
return tool;
|
|
812
830
|
}
|
|
813
831
|
function extendedCardReasonOf(err) {
|
|
814
832
|
if (err instanceof A2aNothingCarried || err instanceof PeerSeatFailure)
|
|
@@ -909,7 +927,7 @@ function declaredPeerOf(declared, index) {
|
|
|
909
927
|
const judged = judgeEntryToolAxes(snapshot, "a2a");
|
|
910
928
|
return judged.ok ? { spec: judged.entry } : { spec: snapshot, refusal: judged.error };
|
|
911
929
|
}
|
|
912
|
-
async function materializePeer(peer, principal, lifecycle, signal, floor, seat, announceEcho, revocations, isolatePeers) {
|
|
930
|
+
async function materializePeer(peer, principal, lifecycle, signal, floor, seat, announceEcho, revocations, isolatePeers, enrichCtx) {
|
|
913
931
|
if ("refusal" in peer)
|
|
914
932
|
throw peer.refusal;
|
|
915
933
|
const { spec } = peer;
|
|
@@ -937,11 +955,12 @@ async function materializePeer(peer, principal, lifecycle, signal, floor, seat,
|
|
|
937
955
|
const cardDrift = inside ? cardDriftOf(spec.allowSkills ?? [], mounted.skills.map((s) => s.id)) : undefined;
|
|
938
956
|
const tools = [];
|
|
939
957
|
const skillAxes = [];
|
|
958
|
+
const registration = peerRegistrationDigestOf("a2a", a2aPeerRegistration(spec));
|
|
940
959
|
for (const skill of mounted.skills) {
|
|
941
960
|
if (spec.allowSkills !== undefined && !spec.allowSkills.includes(skill.id))
|
|
942
961
|
continue;
|
|
943
962
|
const declared = declaredAxes?.[skill.id];
|
|
944
|
-
const tool = buildSkillTool(spec, transport, skill, lifecycle, card.speaks);
|
|
963
|
+
const tool = buildSkillTool(spec, transport, skill, lifecycle, card.speaks, registration, enrichCtx);
|
|
945
964
|
tools.push(tool);
|
|
946
965
|
skillAxes.push(a2aAxisFor(tool.name, declared, a2aInsideRelaxed(spec, isolatePeers)));
|
|
947
966
|
}
|
|
@@ -1007,7 +1026,7 @@ function asPeerWarning(spec, err) {
|
|
|
1007
1026
|
export async function materializeA2aTools(specs, principal, signal, hostFloor, given, onCredentialEchoed, revocations) {
|
|
1008
1027
|
return materializeLegA2aTools(libraryRevocationProbe(revocations, "materializeA2aTools revocations"), specs, principal, signal, hostFloor, receivePeerSeat(given, "materializeA2aTools peerSeat"), onCredentialEchoed);
|
|
1009
1028
|
}
|
|
1010
|
-
export async function materializeLegA2aTools(revocations, specs, principal, signal, hostFloor, peerSeat, onCredentialEchoed, dialable, isolatePeers = false) {
|
|
1029
|
+
export async function materializeLegA2aTools(revocations, specs, principal, signal, hostFloor, peerSeat, onCredentialEchoed, dialable, isolatePeers = false, enrichCtx) {
|
|
1011
1030
|
const peers = specs.map((spec, index) => declaredPeerOf(spec, index));
|
|
1012
1031
|
if (peers.length > 0) {
|
|
1013
1032
|
const collision = findNamespacePrefixCollision(A2A_NAMESPACE, peers.map((p) => p.spec.name));
|
|
@@ -1028,7 +1047,7 @@ export async function materializeLegA2aTools(revocations, specs, principal, sign
|
|
|
1028
1047
|
const announceEcho = echoAnnouncer(onCredentialEchoed);
|
|
1029
1048
|
const dialed = peers.map((peer) => dialable === undefined || dialable(peer.spec));
|
|
1030
1049
|
const undialed = new Set(peers.filter((_, i) => !dialed[i]));
|
|
1031
|
-
const settled = await Promise.allSettled(peers.map((peer, i) => (dialed[i] ? materializePeer(peer, principal, lifecycle, signal, hostFloor, peerSeat, announceEcho, revocations, isolatePeers) : Promise.resolve(null))));
|
|
1050
|
+
const settled = await Promise.allSettled(peers.map((peer, i) => (dialed[i] ? materializePeer(peer, principal, lifecycle, signal, hostFloor, peerSeat, announceEcho, revocations, isolatePeers, enrichCtx) : Promise.resolve(null))));
|
|
1032
1051
|
for (let i = 0; i < peers.length; i++) {
|
|
1033
1052
|
const spec = peers[i].spec;
|
|
1034
1053
|
const outcome = settled[i];
|
|
@@ -1070,7 +1089,7 @@ export async function materializeLegA2aTools(revocations, specs, principal, sign
|
|
|
1070
1089
|
}
|
|
1071
1090
|
const previous = statuses.find((s) => s.name === spec.name)?.toolNames ?? [];
|
|
1072
1091
|
try {
|
|
1073
|
-
const fresh = await materializePeer(target, principal, lifecycle, signal, hostFloor, peerSeat, announceEcho, revocations, isolatePeers);
|
|
1092
|
+
const fresh = await materializePeer(target, principal, lifecycle, signal, hostFloor, peerSeat, announceEcho, revocations, isolatePeers, enrichCtx);
|
|
1074
1093
|
const names = fresh.tools.map((t) => t.name);
|
|
1075
1094
|
results.push({
|
|
1076
1095
|
peer: spec.name,
|
|
@@ -25,10 +25,17 @@ import { type CheckpointSeat } from "./checkpoint-seat.js";
|
|
|
25
25
|
import type { CheckpointGate } from "./checkpoint-store.js";
|
|
26
26
|
import { type ResourceLimitReason } from "./resource-limit-reasons.js";
|
|
27
27
|
import { type CheckpointIdMissing } from "./checkpoint-identity.js";
|
|
28
|
+
import type { AssertAllKeysHandled } from "@sema-agent/primitives";
|
|
28
29
|
/** The park card's state: the checkpoint row's own `status`, plus `missing` (the row names no card, or
|
|
29
|
-
* the store holds none under its token) and `unreadable` (
|
|
30
|
-
*
|
|
30
|
+
* the store holds none under its token) and `unreadable` (why is stated by {@link AgentPark.unreadableCause}:
|
|
31
|
+
* `no_seat`, `store_failed`, or `status_unknown`). The same five answers the parked-row reconciliation sweep
|
|
32
|
+
* gives the same question. */
|
|
31
33
|
export type AgentParkState = "pending" | "resolved" | "expired" | "missing" | "unreadable";
|
|
34
|
+
/** Why an `unreadable` park card could not be read: `no_seat` — this face was given no checkpoint store;
|
|
35
|
+
* `store_failed` — the checkpoint store threw on this read; `status_unknown` — the card was read, and its
|
|
36
|
+
* status word is one this engine version does not know (`pending`, `resolved`, `expired`). */
|
|
37
|
+
export declare const AGENT_PARK_UNREADABLE_CAUSES: readonly ["no_seat", "store_failed", "status_unknown"];
|
|
38
|
+
export type AgentParkUnreadableCause = (typeof AGENT_PARK_UNREADABLE_CAUSES)[number];
|
|
32
39
|
/** What a parked agent waits on — its checkpoint's gate, reduced to the non-secret kind (and, for a resource
|
|
33
40
|
* limit, the closed reason word; the other kinds' free-text reason never leaves the card). */
|
|
34
41
|
export type AgentParkGate = {
|
|
@@ -40,6 +47,11 @@ export type AgentParkGate = {
|
|
|
40
47
|
/** The checkpoint a parked agent waits on. */
|
|
41
48
|
export interface AgentPark {
|
|
42
49
|
state: AgentParkState;
|
|
50
|
+
/** Why {@link state} is `unreadable` ({@link AGENT_PARK_UNREADABLE_CAUSES}): `no_seat` — this face was given no
|
|
51
|
+
* checkpoint store; `store_failed` — the checkpoint store threw on this read; `status_unknown` — the card was
|
|
52
|
+
* read, and its status word is one this engine version does not know. Present exactly when {@link state} is
|
|
53
|
+
* `unreadable`; absent otherwise. */
|
|
54
|
+
unreadableCause?: AgentParkUnreadableCause;
|
|
43
55
|
/** What the park waits on, read off the checkpoint. Present when the card was read and carries a known gate. */
|
|
44
56
|
gate?: AgentParkGate;
|
|
45
57
|
/** The checkpoint's non-secret identity (the card id a person sees in an approval inbox). Present when
|
|
@@ -122,15 +134,24 @@ export declare function agentActivityClause(s: AgentState): string;
|
|
|
122
134
|
/** `<what it waits on> <card id> <state>[ (deadline in <age> | deadline passed <age> ago)]` — facts only; a pending
|
|
123
135
|
* yield adds when it continues (nobody decides it: its owner's next run does). */
|
|
124
136
|
export declare function agentParkClause(p: AgentPark, readAt: number): string;
|
|
137
|
+
declare const AGENT_PARK_UNREADABLE_SENTENCES: {
|
|
138
|
+
readonly no_seat: "This run keeps no record of parked steps, so whether the agent is waiting on a decision cannot be read here, and asking again will not change that; it may be waiting for an approval decision.";
|
|
139
|
+
readonly store_failed: "The record of the parked step could not be read just now (a later read may succeed, and if it keeps failing the record itself may be damaged); it may be waiting for an approval decision.";
|
|
140
|
+
readonly status_unknown: "The parked step carries a state this engine version does not know; it may be waiting for an approval decision.";
|
|
141
|
+
};
|
|
142
|
+
export type UnreadableSentencesCoverEveryCause = AssertAllKeysHandled<Exclude<AgentParkUnreadableCause, keyof typeof AGENT_PARK_UNREADABLE_SENTENCES>>;
|
|
125
143
|
/**
|
|
126
144
|
* The sentence under a parked agent's state line, read off the park card's gate — the same card, the same table, as the
|
|
127
145
|
* state line. A yield (`resource_limit` / `preempt`) is not an approval: the agent left with its owner and continues when its
|
|
128
|
-
* owner runs again. Any other resource limit says it paused at that limit. A card that cannot be read
|
|
129
|
-
* a
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
146
|
+
* owner runs again. Any other resource limit says it paused at that limit. A card that cannot be read keeps the one
|
|
147
|
+
* possibility a reader must not lose — a person may be waiting to decide an approval: an `unreadable` card carrying
|
|
148
|
+
* {@link AgentPark.unreadableCause} states which of the three causes happened (`no_seat`, `store_failed`, `status_unknown`),
|
|
149
|
+
* while `missing`, an absent park, an `unreadable` card without the member, or a `pending` card with no known gate keeps
|
|
150
|
+
* the general blind sentence. A card that WAS read and is no longer pending (decided, or expired), whatever gate it carries
|
|
151
|
+
* or lacks, promises nothing about what happens next, as the state line's park clause promises no continuation for one: the
|
|
152
|
+
* sentence and the line read the card's state alike.
|
|
133
153
|
*/
|
|
134
154
|
export declare function agentParkSentence(p: AgentPark | undefined): string;
|
|
135
155
|
/** The one-line state sentence: `<status> · <activity clause>[ · <park clause>]`. */
|
|
136
156
|
export declare function agentStateSummary(s: AgentState): string;
|
|
157
|
+
export {};
|
package/dist/core/agent-state.js
CHANGED
|
@@ -6,6 +6,7 @@ import { deliverEngineNotice } from "./engine-notice.js";
|
|
|
6
6
|
import { inlineUntrusted } from "./untrusted-text.js";
|
|
7
7
|
import { ANONYMOUS_SCOPE } from "./isolation-scope.js";
|
|
8
8
|
const STATUS_WORDS = { pending: true, running: true, parked: true, completed: true, failed: true, killed: true, cancelled: true };
|
|
9
|
+
export const AGENT_PARK_UNREADABLE_CAUSES = Object.freeze(["no_seat", "store_failed", "status_unknown"]);
|
|
9
10
|
export function agentStateSourceOfHandle(h) {
|
|
10
11
|
return {
|
|
11
12
|
status: h.status,
|
|
@@ -56,7 +57,7 @@ async function readParkCard(store, token, agent) {
|
|
|
56
57
|
cp = (await store.get(token));
|
|
57
58
|
}
|
|
58
59
|
catch {
|
|
59
|
-
return { state: "unreadable" };
|
|
60
|
+
return { state: "unreadable", unreadableCause: "store_failed" };
|
|
60
61
|
}
|
|
61
62
|
if (cp === null || cp === undefined)
|
|
62
63
|
return { state: "missing" };
|
|
@@ -67,6 +68,7 @@ async function readParkCard(store, token, agent) {
|
|
|
67
68
|
announceUntrustedCardId(agent);
|
|
68
69
|
return {
|
|
69
70
|
state,
|
|
71
|
+
...(state === "unreadable" ? { unreadableCause: "status_unknown" } : {}),
|
|
70
72
|
...(gate !== undefined ? { gate } : {}),
|
|
71
73
|
...identity,
|
|
72
74
|
...(finite(cp.deadline) ? { deadline: cp.deadline } : {}),
|
|
@@ -98,7 +100,7 @@ export function readAgentState(src, seat, now) {
|
|
|
98
100
|
return { ...base, park: { state: "missing" } };
|
|
99
101
|
const store = checkpointStoreOfSeat(seat);
|
|
100
102
|
if (store === undefined)
|
|
101
|
-
return { ...base, park: { state: "unreadable" } };
|
|
103
|
+
return { ...base, park: { state: "unreadable", unreadableCause: "no_seat" } };
|
|
102
104
|
return readParkCard(store, src.parkedCheckpointToken, src).then((park) => ({ ...base, park }));
|
|
103
105
|
}
|
|
104
106
|
export function formatAgo(ms) {
|
|
@@ -140,15 +142,26 @@ export function agentParkClause(p, readAt) {
|
|
|
140
142
|
const continues = p.state === "pending" && p.gate?.kind === "resource_limit" && p.gate.reason === "preempt" ? " — continues when its owner runs again" : "";
|
|
141
143
|
return `${parkWord(p.gate)}${id} ${p.state}${deadline}${continues}`;
|
|
142
144
|
}
|
|
145
|
+
const PARK_BLIND_CLOSING = "it may be waiting for an approval decision.";
|
|
146
|
+
const PARK_BLIND_SENTENCE = `What this agent is waiting on cannot be read here; ${PARK_BLIND_CLOSING}`;
|
|
147
|
+
const AGENT_PARK_UNREADABLE_SENTENCES = {
|
|
148
|
+
no_seat: `This run keeps no record of parked steps, so whether the agent is waiting on a decision cannot be read here, and asking again will not change that; ${PARK_BLIND_CLOSING}`,
|
|
149
|
+
store_failed: `The record of the parked step could not be read just now (a later read may succeed, and if it keeps failing the record itself may be damaged); ${PARK_BLIND_CLOSING}`,
|
|
150
|
+
status_unknown: `The parked step carries a state this engine version does not know; ${PARK_BLIND_CLOSING}`,
|
|
151
|
+
};
|
|
143
152
|
export function agentParkSentence(p) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
if (p === undefined || p.state === "missing")
|
|
154
|
+
return PARK_BLIND_SENTENCE;
|
|
155
|
+
if (p.state === "unreadable") {
|
|
156
|
+
return p.unreadableCause !== undefined && Object.hasOwn(AGENT_PARK_UNREADABLE_SENTENCES, p.unreadableCause)
|
|
157
|
+
? AGENT_PARK_UNREADABLE_SENTENCES[p.unreadableCause]
|
|
158
|
+
: PARK_BLIND_SENTENCE;
|
|
159
|
+
}
|
|
147
160
|
if (p.state !== "pending")
|
|
148
161
|
return "What this agent waited on is no longer pending (the state line says how it ended); its row has not been settled yet.";
|
|
149
162
|
const gate = p.gate;
|
|
150
163
|
if (gate === undefined)
|
|
151
|
-
return
|
|
164
|
+
return PARK_BLIND_SENTENCE;
|
|
152
165
|
if (gate.kind !== "resource_limit")
|
|
153
166
|
return PARK_GATE_SENTENCES[gate.kind];
|
|
154
167
|
if (gate.reason === "preempt")
|
|
@@ -13,10 +13,11 @@ export declare const APPROVAL_TARGET_ROLES: readonly ["protective", "declared"];
|
|
|
13
13
|
export type ApprovalTargetRole = (typeof APPROVAL_TARGET_ROLES)[number];
|
|
14
14
|
/** The row's `targets` member: per role, the location the target RESOLVED to when the card was asked (the canonical
|
|
15
15
|
* view of that reading), or `null` when the environment was asked and did not answer — an unresolved target binds
|
|
16
|
-
* "unresolved", so a later resolution is a move. A
|
|
17
|
-
*
|
|
16
|
+
* "unresolved", so a later resolution is a move. A slot that names several targets (`pathTarget.each`) records the list of
|
|
17
|
+
* its elements' locations, in slot order. A role the environment was not asked about is absent; a row with no such role
|
|
18
|
+
* carries none. */
|
|
18
19
|
export type ApprovalTargets = {
|
|
19
|
-
readonly [R in ApprovalTargetRole]?: string | null;
|
|
20
|
+
readonly [R in ApprovalTargetRole]?: string | null | readonly (string | null)[];
|
|
20
21
|
};
|
|
21
22
|
/** The row's `targetReads` member: per read candidate the shell read station judged for the parked bytes (its key's
|
|
22
23
|
* digest), where it landed (its settled targets' digest — a pattern lands on a set). A sibling of `targets`, not a key
|
|
@@ -94,6 +95,9 @@ export interface LiveApprovalObject {
|
|
|
94
95
|
readonly targetReading?: CallTargetReading | undefined;
|
|
95
96
|
/** execution: where this leg's shell read station found those bytes' reads land (`undefined`: it holds no judgment of them). */
|
|
96
97
|
readonly reads?: readonly ReadLanding[] | undefined;
|
|
98
|
+
/** execution: where this leg's file read station judged a declared read's targets land, in slot order — the keys its port opens.
|
|
99
|
+
* When present the targets member is judged on THEM (one reading for the admission and the comparison), not on `targetReading`. */
|
|
100
|
+
readonly landings?: readonly string[] | undefined;
|
|
97
101
|
/** execution: the bytes the decision rewrote the call to, as the tool reads them; absent when it rewrote nothing. When
|
|
98
102
|
* the row's binding does not cover them ({@link licenseCovers}, the one judge of "are these the approved bytes") the
|
|
99
103
|
* person approved bytes whose target the row never recorded, and the targets member is not judged. */
|
|
@@ -30,10 +30,18 @@ export function approvalObjectOf(row) {
|
|
|
30
30
|
}
|
|
31
31
|
export function approvalTargetsOf(reading, reads) {
|
|
32
32
|
const targets = {};
|
|
33
|
+
const landing = (view) => (view?.kind === "path" && (view.canonical !== undefined || view.unread === true) ? (view.canonical ?? null) : undefined);
|
|
33
34
|
for (const role of APPROVAL_TARGET_ROLES) {
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
36
|
-
|
|
35
|
+
const several = reading?.each?.[role];
|
|
36
|
+
if (several === undefined) {
|
|
37
|
+
const one = landing(reading?.[role]);
|
|
38
|
+
if (one !== undefined)
|
|
39
|
+
targets[role] = one;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const all = several.map(landing);
|
|
43
|
+
if (all.length > 0 && all.every((l) => l !== undefined))
|
|
44
|
+
targets[role] = Object.freeze(all);
|
|
37
45
|
}
|
|
38
46
|
return { ...(Object.keys(targets).length > 0 ? { targets } : {}), ...(reads !== undefined ? { targetReads: Object.fromEntries(reads.map((r) => [r.key, r.landing])) } : {}) };
|
|
39
47
|
}
|
|
@@ -51,7 +59,7 @@ function faceKey(face) {
|
|
|
51
59
|
const pt = face.pathTarget;
|
|
52
60
|
if (k !== "pathTarget")
|
|
53
61
|
return face[k] ?? null;
|
|
54
|
-
return pt === undefined ? null : { param: pt.param, access: pt.access, aliases: [...(pt.aliases ?? [])], ...pathTargetResolutionOf(pt), patternParam: pt.patternParam ?? null, skillScopeEligible: pt.skillScopeEligible === true };
|
|
62
|
+
return pt === undefined ? null : { param: pt.param, access: pt.access, aliases: [...(pt.aliases ?? [])], ...pathTargetResolutionOf(pt), patternParam: pt.patternParam ?? null, skillScopeEligible: pt.skillScopeEligible === true, ...(pt.each === true ? { each: true } : {}) };
|
|
55
63
|
};
|
|
56
64
|
return canonicalize(Object.fromEntries(FACE_MEMBERS.map((k) => [k, resolved(k)])));
|
|
57
65
|
}
|
|
@@ -78,7 +86,7 @@ function judgeTool(row, live, station) {
|
|
|
78
86
|
}
|
|
79
87
|
if (bound.declarationDigest === toolDeclarationDigestOf(entry))
|
|
80
88
|
return undefined;
|
|
81
|
-
return { member: "tool", disposition: "veto", code: "resume.target_moved", message: vetoed(row.toolName, "the tool's declaration (what it does, reaches and trusts: its effect, egress, irreversibility, content origin, boundary legs, rule face or model gate) changed after the approval") };
|
|
89
|
+
return { member: "tool", disposition: "veto", code: "resume.target_moved", message: vetoed(row.toolName, "the tool's declaration (what it does, reaches and trusts: its effect, egress, irreversibility, content origin, its peer's registration, boundary legs, rule face or model gate) changed after the approval") };
|
|
82
90
|
}
|
|
83
91
|
function judgeTargets(row, live) {
|
|
84
92
|
if ((row.targets === undefined && row.targetReads === undefined) || ("decided" in live && !licenseCovers(row.boundInputHash, row.toolName, live.decided)))
|
|
@@ -90,16 +98,29 @@ const DIGEST = /^[0-9a-f]{64}$/;
|
|
|
90
98
|
function landedElsewhere(bound, boundReads, live) {
|
|
91
99
|
if (bound !== undefined) {
|
|
92
100
|
const roles = typeof bound === "object" && bound !== null && !Array.isArray(bound) ? Object.entries(bound) : [];
|
|
93
|
-
const
|
|
101
|
+
const located = (v) => v === null || (typeof v === "string" && v.length > 0);
|
|
102
|
+
const whole = roles.length > 0 && roles.every(([k, v]) => APPROVAL_TARGET_ROLES.includes(k) && (located(v) || (Array.isArray(v) && v.length > 0 && v.every(located))));
|
|
94
103
|
if (!whole)
|
|
95
104
|
return "the target member of the approval on its checkpoint row is damaged (not a reading → resolved location record)";
|
|
96
|
-
const now =
|
|
105
|
+
const now = live.landings !== undefined
|
|
106
|
+
? Object.fromEntries(roles.map(([role, was]) => [role, Array.isArray(was) || live.landings.length !== 1 ? live.landings : live.landings[0]]))
|
|
107
|
+
: (approvalTargetsOf(live.targetReading).targets ?? {});
|
|
97
108
|
const where = (p) => (p === null ? "did not resolve" : `resolved to ${shown(p)}`);
|
|
98
109
|
for (const [role, was] of roles) {
|
|
99
110
|
const is = now[role];
|
|
100
|
-
if (is === was)
|
|
111
|
+
if (canonicalize(is) === canonicalize(was))
|
|
101
112
|
continue;
|
|
102
|
-
|
|
113
|
+
if (is === undefined)
|
|
114
|
+
return `where its target resolves (it ${typeof was === "object" && was !== null ? "named several" : where(was)} when the card was asked) could not be established on this leg`;
|
|
115
|
+
if (Array.isArray(was) || Array.isArray(is)) {
|
|
116
|
+
const a = (Array.isArray(was) ? was : [was]);
|
|
117
|
+
const b = (Array.isArray(is) ? is : [is]);
|
|
118
|
+
const i = a.findIndex((w, j) => b[j] !== w);
|
|
119
|
+
if (i < 0 || b[i] === undefined)
|
|
120
|
+
return `the call names ${b.length} target(s) now and named ${a.length} when the card was asked`;
|
|
121
|
+
return `its target ${i + 1} ${b[i] === null ? "does not resolve" : `resolves to ${shown(b[i])}`} now and ${where(a[i] ?? null)} when the card was asked`;
|
|
122
|
+
}
|
|
123
|
+
return `its target ${is === null ? "does not resolve" : `resolves to ${shown(is)}`} now and ${where(was)} when the card was asked`;
|
|
103
124
|
}
|
|
104
125
|
}
|
|
105
126
|
if (boundReads === undefined)
|
|
@@ -185,6 +185,13 @@ export type CheckpointErrorReason = "version_newer" | "env_factory_missing" | "g
|
|
|
185
185
|
* no installation record (a chain written before the record existed) / a record that does not cover the chain entry for
|
|
186
186
|
* entry / a record member naming no absolute root. */
|
|
187
187
|
| "installation_record_absent" | "installation_record_misaligned" | "installation_record_invalid"
|
|
188
|
+
/** On `resume.parent_constraint_mismatch` — its other three causes: the chain the resume runs under is not the one the row
|
|
189
|
+
* recorded (`"constraint_changed"`: another layer count, or a layer whose facts or frozen deny data differ — hand back the chain
|
|
190
|
+
* as it was at the park, or deny the card); the row's own recorded chain does not match the digest it records
|
|
191
|
+
* (`"constraint_chain_damaged"`: the row is damaged — expire it); the chain could not be judged (`"constraint_unjudgeable"`: an
|
|
192
|
+
* entry that is neither one caller policy nor one installation, or a judgment that threw — the host checks the chain it hands).
|
|
193
|
+
* Every refusal the engine answers on the code names one of its six causes. */
|
|
194
|
+
| "constraint_changed" | "constraint_chain_damaged" | "constraint_unjudgeable"
|
|
188
195
|
/** On `checkpoint.config_refused` with `detail.code` `config.tool_face_control` — the arm prepare's own refusal carries as its `detail.reason`:
|
|
189
196
|
* a tool-name list the row recorded is not a list / has a member that is not a string / has a spelling no tool name can have / is not in
|
|
190
197
|
* the one spelling a row records (`"not_a_list"`, `"not_a_string"`, `"unknown_name"`, `"unsupported_pattern"`; the re-supplied config's own four lists —
|
|
@@ -400,9 +407,12 @@ export declare class CheckpointError extends Error {
|
|
|
400
407
|
} | undefined);
|
|
401
408
|
}
|
|
402
409
|
/** THE copy mint: a second throw of an existing refusal — a new `CheckpointError` with the instance's own code, message, detail and
|
|
403
|
-
* `cause
|
|
404
|
-
* it does not spell (scripts/verify-closed-sets.mjs `COPY_MINT`); a construction
|
|
405
|
-
|
|
410
|
+
* `cause` (with `reason` given, `detail.reason` is that word). Its code is one the instance's mint was judged for, so this is the one
|
|
411
|
+
* construction `gate:closed-sets` reads with a code it does not spell (scripts/verify-closed-sets.mjs `COPY_MINT`); a construction
|
|
412
|
+
* anywhere else still spells its code. The instance may be a host's (the class is exported): its message, its detail's members and
|
|
413
|
+
* its `cause` are each read once under a guard, and one that throws when read is not carried — the copy keeps the code, never the
|
|
414
|
+
* host's failure. */
|
|
415
|
+
export declare function copyOfCheckpointError(refusal: CheckpointError, reason?: CheckpointErrorReason): CheckpointError;
|
|
406
416
|
/**
|
|
407
417
|
* Project an already-captured value onto what a backend of the given {@link StoreFidelity} can hold, so
|
|
408
418
|
* everything minted from it — the row's args, the approval preview, the binding hash, the risk
|
|
@@ -124,11 +124,40 @@ export class CheckpointError extends Error {
|
|
|
124
124
|
this.name = "CheckpointError";
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
export function copyOfCheckpointError(refusal) {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
export function copyOfCheckpointError(refusal, reason) {
|
|
128
|
+
const guarded = (read) => {
|
|
129
|
+
try {
|
|
130
|
+
return { ok: true, value: read() };
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return { ok: false };
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const message = guarded(() => refusal.message);
|
|
137
|
+
const members = guarded(() => {
|
|
138
|
+
const d = refusal.detail;
|
|
139
|
+
return typeof d === "object" && d !== null ? Object.keys(d).map((k) => [k, guarded(() => d[k])]) : [];
|
|
140
|
+
});
|
|
141
|
+
const kept = members.ok ? members.value.flatMap(([k, v]) => (v.ok && v.value !== undefined ? [[k, v.value]] : [])) : [];
|
|
142
|
+
const detail = Object.fromEntries([...kept.filter(([k]) => reason === undefined || k !== "reason"), ...(reason !== undefined ? [["reason", reason]] : [])]);
|
|
143
|
+
const cause = guarded(() => ("cause" in refusal ? { value: refusal.cause } : undefined));
|
|
144
|
+
const made = copy(new RefusalReading(refusal.code, message.ok && typeof message.value === "string" ? message.value : "", Object.keys(detail ?? {}).length > 0 ? detail : undefined));
|
|
145
|
+
if (cause.ok && cause.value !== undefined)
|
|
146
|
+
Object.defineProperty(made, "cause", { value: cause.value.value, writable: true, configurable: true, enumerable: false });
|
|
147
|
+
return made;
|
|
148
|
+
function copy(p) {
|
|
149
|
+
return new CheckpointError(p.code, p.message, p.detail);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
class RefusalReading {
|
|
153
|
+
code;
|
|
154
|
+
message;
|
|
155
|
+
detail;
|
|
156
|
+
constructor(code, message, detail) {
|
|
157
|
+
this.code = code;
|
|
158
|
+
this.message = message;
|
|
159
|
+
this.detail = detail;
|
|
160
|
+
}
|
|
132
161
|
}
|
|
133
162
|
export function encodeAtFidelity(fidelity, value) {
|
|
134
163
|
if (fidelity === "structured-clone")
|
|
@@ -1156,7 +1156,20 @@ export declare function requirementsDigestOf(cp: Checkpoint): string;
|
|
|
1156
1156
|
* spell one as a key holding `undefined` (the state serializer names every member), and the stamp leaves that key out —
|
|
1157
1157
|
* so every store holds an engine-written row with one key set, and a key-reading answers as the value-reading does. The
|
|
1158
1158
|
* members below those two levels are written as given: a tool call's arguments, a decision-read record and the
|
|
1159
|
-
* resource ledger are data whose keys the binding hash, the digest and the park's argument comparison read.
|
|
1159
|
+
* resource ledger are data whose keys the binding hash, the digest and the park's argument comparison read.
|
|
1160
|
+
*
|
|
1161
|
+
* FOR A HOST-MINTED ROW (exported at the package root for it — e.g. the `task_done` wake card a serving layer files and later
|
|
1162
|
+
* hands to the wake): stamp it here before the write, at the store's declared fidelity —
|
|
1163
|
+
* `put(token, stampCheckpointRequirements(checkpointFrom({ ... }), resolveDeclaredFidelity(store, "checkpointStore")))`. A store's
|
|
1164
|
+
* `put` does not stamp, and a row below the format is refused `checkpoint.unsupported_version` / `seat_retired`. As the commit
|
|
1165
|
+
* does, judge the stamped row once before the write (`judgeCheckpointRow`): a verdict that is not `ok` means a member the store's
|
|
1166
|
+
* fidelity does not keep or the digest cannot encode (e.g. a BigInt at `json` fidelity) — do not write it. A stamped row is the host's own word:
|
|
1167
|
+
* the resume takes it as a row this engine parked and does not judge again the decision it stands for (a host-minted
|
|
1168
|
+
* `tool_approval` row whose `boundInputHash` matches the call runs that call without asking `toolPolicy.check`, as an
|
|
1169
|
+
* engine-parked approval does — minting one is the host giving that approval). Stamp only rows
|
|
1170
|
+
* the host itself mints — never to re-date a row another engine release wrote (a re-stamped old row is admitted as a current
|
|
1171
|
+
* one: the judgments its old format owed are not run again). After the stamp, change no member a verdict reads:
|
|
1172
|
+
* the digest no longer matches and the row is judged damaged. */
|
|
1160
1173
|
export declare function stampCheckpointRequirements(row: Checkpoint, fidelity: StoreFidelity): Checkpoint;
|
|
1161
1174
|
/** The row as the store at `fidelity` hands it back, judged — the commit's question before the write. */
|
|
1162
1175
|
export declare function judgeAsStored(cp: Checkpoint, fidelity: StoreFidelity): CheckpointRequirementsVerdict;
|
|
@@ -91,7 +91,7 @@ export declare const ROW_REFUSAL_SENTENCES: Readonly<{
|
|
|
91
91
|
readonly "checkpoint.invalid_outcome|hands_coordinates_damaged": "This engine cannot resume this checkpoint: one of its recorded workspace coordinates is not an absolute path (a corruption guard). The checkpoint stays pending. Expire it, then start the task again.";
|
|
92
92
|
readonly "checkpoint.invalid_outcome|constraint_chain_missing": "This engine cannot resume this checkpoint: it requires parent constraints but does not carry both their frozen chain and its digest (a corruption or downgrade guard). The checkpoint stays pending. Expire it, then start the task again.";
|
|
93
93
|
readonly "checkpoint.walltime_axis_retired|": "This engine cannot resume this checkpoint: its budget carries a wall-clock allocation, an axis this engine retired, so resuming here would run the work with that ceiling unenforced. The checkpoint stays pending. Expire it and start a fresh task bounded by tokens or budget.";
|
|
94
|
-
readonly "resume.parent_constraint_mismatch|": "This engine cannot resume this checkpoint: its own recorded constraint chain does not match the digest it records (a corrupt or inconsistently minted row). The checkpoint stays pending. Expire it, then start the task again.";
|
|
94
|
+
readonly "resume.parent_constraint_mismatch|constraint_chain_damaged": "This engine cannot resume this checkpoint: its own recorded constraint chain does not match the digest it records (a corrupt or inconsistently minted row). The checkpoint stays pending. Expire it, then start the task again.";
|
|
95
95
|
readonly "config.permission_mode_invalid": "This engine cannot resume this checkpoint: a permission mode it records is not one this engine reads (or not one a plan can return to). The checkpoint stays pending. Expire it and run the work again.";
|
|
96
96
|
readonly "config.run_origin_invalid": "This engine cannot resume this checkpoint: the run origin it records is not a word this engine knows. The checkpoint stays pending. Expire it and run the work again.";
|
|
97
97
|
readonly "config.tool_face_control": "This engine cannot resume this checkpoint: its frozen inherited constraint chain records a tool name in a spelling this engine does not replay. The checkpoint stays pending. Expire it and run the work again under a policy that names each tool by its bare name.";
|
|
@@ -45,7 +45,7 @@ export const ROW_REFUSAL_SENTENCES = Object.freeze({
|
|
|
45
45
|
"checkpoint.invalid_outcome|hands_coordinates_damaged": "This engine cannot resume this checkpoint: one of its recorded workspace coordinates is not an absolute path (a corruption guard). The checkpoint stays pending. Expire it, then start the task again.",
|
|
46
46
|
"checkpoint.invalid_outcome|constraint_chain_missing": "This engine cannot resume this checkpoint: it requires parent constraints but does not carry both their frozen chain and its digest (a corruption or downgrade guard). The checkpoint stays pending. Expire it, then start the task again.",
|
|
47
47
|
"checkpoint.walltime_axis_retired|": "This engine cannot resume this checkpoint: its budget carries a wall-clock allocation, an axis this engine retired, so resuming here would run the work with that ceiling unenforced. The checkpoint stays pending. Expire it and start a fresh task bounded by tokens or budget.",
|
|
48
|
-
"resume.parent_constraint_mismatch|": "This engine cannot resume this checkpoint: its own recorded constraint chain does not match the digest it records (a corrupt or inconsistently minted row). The checkpoint stays pending. Expire it, then start the task again.",
|
|
48
|
+
"resume.parent_constraint_mismatch|constraint_chain_damaged": "This engine cannot resume this checkpoint: its own recorded constraint chain does not match the digest it records (a corrupt or inconsistently minted row). The checkpoint stays pending. Expire it, then start the task again.",
|
|
49
49
|
"config.permission_mode_invalid": "This engine cannot resume this checkpoint: a permission mode it records is not one this engine reads (or not one a plan can return to). The checkpoint stays pending. Expire it and run the work again.",
|
|
50
50
|
"config.run_origin_invalid": "This engine cannot resume this checkpoint: the run origin it records is not a word this engine knows. The checkpoint stays pending. Expire it and run the work again.",
|
|
51
51
|
"config.tool_face_control": "This engine cannot resume this checkpoint: its frozen inherited constraint chain records a tool name in a spelling this engine does not replay. The checkpoint stays pending. Expire it and run the work again under a policy that names each tool by its bare name.",
|
|
@@ -65,7 +65,7 @@ export const ROW_REFUSAL_TERMINAL = Object.freeze({
|
|
|
65
65
|
"checkpoint.invalid_outcome|hands_coordinates_damaged": true,
|
|
66
66
|
"checkpoint.invalid_outcome|constraint_chain_missing": true,
|
|
67
67
|
"checkpoint.walltime_axis_retired|": false,
|
|
68
|
-
"resume.parent_constraint_mismatch|": true,
|
|
68
|
+
"resume.parent_constraint_mismatch|constraint_chain_damaged": true,
|
|
69
69
|
"config.permission_mode_invalid": false,
|
|
70
70
|
"config.run_origin_invalid": false,
|
|
71
71
|
"config.tool_face_control": false,
|
|
@@ -250,7 +250,7 @@ function rowRefusalOf(cp) {
|
|
|
250
250
|
if (expectedDigest !== undefined && reading !== "same") {
|
|
251
251
|
return new CheckpointError("resume.parent_constraint_mismatch", "the checkpoint's OWN recorded constraint chain does not match its recorded digest " +
|
|
252
252
|
"(corrupt / inconsistently-minted row) — the frozen deny data the resume would execute is not the data the " +
|
|
253
|
-
"digest authenticates; rejected pre-CAS (the checkpoint stays pending)");
|
|
253
|
+
"digest authenticates; rejected pre-CAS (the checkpoint stays pending)", { reason: "constraint_chain_damaged" });
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
return undefined;
|
|
@@ -2414,6 +2414,10 @@ export type StoreFidelity = "structured-clone" | "json";
|
|
|
2414
2414
|
* Resolve a store's declared {@link StoreFidelity} (the read half of the declaration — the exact shape
|
|
2415
2415
|
* `resolveDeclaredFidelity`'s durability twin has): ABSENT → the fail-closed `"json"`, a recognized
|
|
2416
2416
|
* value verbatim, anything else refused loudly. Never duck-types the backend.
|
|
2417
|
+
*
|
|
2418
|
+
* Exported at the package root for a host that mints its own checkpoint rows (e.g. a `task_done` wake card): it reads the
|
|
2419
|
+
* fidelity to stamp at from its store's own declaration instead of writing a constant —
|
|
2420
|
+
* `put(token, stampCheckpointRequirements(checkpointFrom({ ... }), resolveDeclaredFidelity(store, "checkpointStore")))`.
|
|
2417
2421
|
*/
|
|
2418
2422
|
export declare function resolveDeclaredFidelity(store: {
|
|
2419
2423
|
readonly fidelity?: StoreFidelity;
|
|
@@ -133,6 +133,19 @@ export declare function effectivePathSpellingOf(call: ToolCallLike, pt: ToolCall
|
|
|
133
133
|
} | {
|
|
134
134
|
readonly refused: Win32NamespaceRefusal;
|
|
135
135
|
} | undefined;
|
|
136
|
+
/** One target's selection ({@link effectivePathSpellingOf}'s answer), or an element of a slot that names several which is not a
|
|
137
|
+
* non-empty string (`malformed`: nothing a reader can place). */
|
|
138
|
+
export type PathSpellingSelection = NonNullable<ReturnType<typeof effectivePathSpellingOf>> | {
|
|
139
|
+
readonly malformed: true;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* The SELECTION of EVERY target a call's slot names. A slot the call's own face declares for a read (a caller's or an MCP tool's) is
|
|
143
|
+
* read ONCE by {@link declaredReadValuesOf} (never falling back to {@link pathTargetValue}): every element that is a non-empty string
|
|
144
|
+
* selects against the slot's base, any other value is `malformed`, and an absent slot reads {@link absentPathSpellingOf}. Every other
|
|
145
|
+
* slot (an engine tool's, a write's) is the one selection {@link effectivePathSpellingOf} makes. `[]` ⇔ only empty lists; `undefined`
|
|
146
|
+
* ⇔ no target in this reading.
|
|
147
|
+
*/
|
|
148
|
+
export declare function effectivePathSpellingsOf(call: ToolCallLike, pt: ToolCallPathTarget | undefined, bases: ToolPathBases): readonly PathSpellingSelection[] | undefined;
|
|
136
149
|
/**
|
|
137
150
|
* THE path prelude: ONE spelling → the identity of the path the TOOL will open it as. Every reading of a spelling passes
|
|
138
151
|
* through here — the target slot's own value, a `patternParam`'s derived base, an empty slot's base, the views of
|
|
@@ -176,6 +189,12 @@ export type CallTargetView = {
|
|
|
176
189
|
export interface CallTargetReading {
|
|
177
190
|
readonly protective?: CallTargetView;
|
|
178
191
|
readonly declared?: CallTargetView;
|
|
192
|
+
/** A slot that names several targets (`pathTarget.each`): the views of EVERY element, per reading, in slot order — the call is
|
|
193
|
+
* about all of them, so `protective` / `declared` are absent. A rule lane reads them through {@link callTargetViewsOf}. */
|
|
194
|
+
readonly each?: {
|
|
195
|
+
readonly protective?: readonly CallTargetView[];
|
|
196
|
+
readonly declared?: readonly CallTargetView[];
|
|
197
|
+
};
|
|
179
198
|
/** Where each location on the way to a rule row's head that this leg's lanes hold LEADS in the leg's environment (a
|
|
180
199
|
* link, a firmlink, an alias of the tree) — the rows' twins are judged there too. A fact of the judging leg, taken
|
|
181
200
|
* once per location per leg; absent when no row head leads elsewhere. */
|