@sema-agent/core 7.58.0 → 7.59.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 +776 -0
- package/README.md +6 -4
- package/dist/agents/cc-peer-directory.js +8 -8
- package/dist/agents/child-model-seat.d.ts +4 -2
- package/dist/agents/child-model-seat.js +5 -3
- package/dist/agents/peer-directory.d.ts +9 -0
- package/dist/agents/peer-directory.js +6 -2
- package/dist/agents/send-message-tool.js +21 -12
- package/dist/agents/subagent.js +33 -34
- package/dist/brain/anthropic.js +161 -45
- package/dist/brain/errors.d.ts +9 -3
- package/dist/brain/errors.js +7 -1
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +3 -3
- package/dist/brain/openai.js +103 -53
- package/dist/brain/provider-dialect.d.ts +11 -0
- package/dist/brain/provider-dialect.js +5 -2
- package/dist/brain/reasoning-request.js +5 -4
- package/dist/brain/reasoning.d.ts +19 -0
- package/dist/brain/reasoning.js +17 -2
- package/dist/brain/request-route.d.ts +4 -1
- package/dist/brain/request-route.js +4 -1
- package/dist/brain/route-adjudicator.d.ts +84 -18
- package/dist/brain/route-adjudicator.js +87 -21
- package/dist/brain/route-conformance.js +1 -1
- package/dist/brain/stream-engine.js +84 -49
- package/dist/brain/stream-shared.d.ts +30 -0
- package/dist/brain/stream-shared.js +34 -1
- package/dist/brain/timeout.d.ts +62 -5
- package/dist/brain/timeout.js +93 -6
- package/dist/core/account-row.d.ts +61 -0
- package/dist/core/account-row.js +51 -0
- package/dist/core/advisor-verdict.d.ts +2 -1
- package/dist/core/advisor-verdict.js +1 -1
- package/dist/core/allow-entry.d.ts +18 -6
- package/dist/core/allow-entry.js +16 -8
- package/dist/core/approval-object.d.ts +29 -15
- package/dist/core/approval-object.js +47 -19
- package/dist/core/auto-compaction.js +1 -1
- package/dist/core/background-agent-store.d.ts +16 -3
- package/dist/core/checkpoint-requirements.d.ts +13 -1
- package/dist/core/checkpoint-requirements.js +3 -1
- package/dist/core/checkpoint-store.d.ts +58 -12
- package/dist/core/checkpoint-store.js +18 -6
- package/dist/core/child-clamp-seats.d.ts +29 -0
- package/dist/core/child-clamp-seats.js +56 -1
- package/dist/core/compliance.d.ts +2 -2
- package/dist/core/compliance.js +1 -1
- package/dist/core/effective-path-target.d.ts +8 -2
- package/dist/core/effective-path-target.js +8 -3
- package/dist/core/engine-notice.d.ts +98 -8
- package/dist/core/engine-notice.js +19 -5
- package/dist/core/gate-fold.js +1 -1
- package/dist/core/gate-lanes.js +8 -4
- package/dist/core/gate-outcome.d.ts +32 -3
- package/dist/core/gate-outcome.js +19 -1
- package/dist/core/governance-codes.d.ts +9 -1
- package/dist/core/governance-codes.js +13 -0
- package/dist/core/hooks.d.ts +31 -3
- package/dist/core/hooks.js +5 -6
- package/dist/core/image-admission.d.ts +6 -5
- package/dist/core/image-admission.js +18 -14
- package/dist/core/locked-config.d.ts +5 -2
- package/dist/core/locked-config.js +2 -1
- package/dist/core/mailbox-store.d.ts +45 -1
- package/dist/core/mailbox-store.js +53 -9
- package/dist/core/mcp-failure.d.ts +114 -18
- package/dist/core/mcp-failure.js +63 -5
- package/dist/core/mcp-server-link.d.ts +22 -1
- package/dist/core/mcp-server-link.js +25 -1
- package/dist/core/mcp.d.ts +12 -8
- package/dist/core/mcp.js +42 -25
- package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
- package/dist/core/memory-engine/consolidation-driver.js +3 -3
- package/dist/core/memory-engine/consolidation.d.ts +4 -0
- package/dist/core/memory-engine/consolidation.js +1 -0
- package/dist/core/memory-engine/delegation-settlement.js +5 -12
- package/dist/core/memory-engine/distiller.js +2 -2
- package/dist/core/memory-engine/dual-root.d.ts +50 -1
- package/dist/core/memory-engine/dual-root.js +44 -1
- package/dist/core/memory-engine/engine.d.ts +67 -14
- package/dist/core/memory-engine/engine.js +384 -212
- package/dist/core/memory-engine/export-bundle.d.ts +23 -0
- package/dist/core/memory-engine/export-bundle.js +23 -4
- package/dist/core/memory-engine/file-backend.d.ts +128 -55
- package/dist/core/memory-engine/file-backend.js +290 -117
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/layout.d.ts +59 -11
- package/dist/core/memory-engine/layout.js +190 -40
- package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
- package/dist/core/memory-engine/memory-backend-contract.js +39 -2
- package/dist/core/memory-engine/sync-client.d.ts +9 -1
- package/dist/core/memory-engine/sync-client.js +31 -8
- package/dist/core/memory-engine/sync.d.ts +5 -0
- package/dist/core/memory-engine/types.d.ts +6 -0
- package/dist/core/mods/classic-events.d.ts +5 -1
- package/dist/core/mods/kernel/dispatch.js +2 -1
- package/dist/core/mods/kernel/events.d.ts +2 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/kernel/registration.d.ts +4 -0
- package/dist/core/mods/kernel/registration.js +3 -0
- package/dist/core/mods/stations.d.ts +31 -10
- package/dist/core/mods/stations.js +44 -10
- package/dist/core/mods/tool-call.js +1 -1
- package/dist/core/parent-spec-seat.d.ts +8 -3
- package/dist/core/parent-spec-seat.js +2 -0
- package/dist/core/park-selfcheck.js +6 -0
- package/dist/core/peer-seat.d.ts +70 -8
- package/dist/core/peer-seat.js +143 -11
- package/dist/core/permission-rule-consent.js +10 -4
- package/dist/core/permission-rule-model.d.ts +16 -0
- package/dist/core/permission-rule-model.js +1 -1
- package/dist/core/present-plan-tool.d.ts +11 -3
- package/dist/core/present-plan-tool.js +2 -2
- package/dist/core/resume-startup-cause.js +1 -0
- package/dist/core/rewrite-rejudge.d.ts +1 -0
- package/dist/core/rewrite-rejudge.js +2 -2
- package/dist/core/roles.d.ts +34 -2
- package/dist/core/roles.js +43 -4
- package/dist/core/runner/announce-once-ledger.d.ts +5 -4
- package/dist/core/runner/announce-once-ledger.js +4 -2
- package/dist/core/runner/call-hook-stations.js +2 -2
- package/dist/core/runner/contracts.d.ts +20 -16
- package/dist/core/runner/credential-origin-seat.js +4 -3
- package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
- package/dist/core/runner/cwd-alignment-probe.js +21 -0
- package/dist/core/runner/decide-continuation.d.ts +2 -2
- package/dist/core/runner/gate-exit.d.ts +12 -4
- package/dist/core/runner/gate-exit.js +10 -7
- package/dist/core/runner/image-removed-seat.d.ts +12 -0
- package/dist/core/runner/image-removed-seat.js +19 -0
- package/dist/core/runner/inline-image.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.js +3 -3
- package/dist/core/runner/park-commit.d.ts +1 -1
- package/dist/core/runner/park-commit.js +3 -0
- package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
- package/dist/core/runner/prepare-ask-lane.js +2 -1
- package/dist/core/runner/prepare-boundary-parks.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -5
- package/dist/core/runner/prepare-caps-and-workflow.js +2 -0
- package/dist/core/runner/prepare-config-doors.js +2 -0
- package/dist/core/runner/prepare-context-lane.js +2 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +4 -0
- package/dist/core/runner/prepare-delegation-surface.js +1 -0
- package/dist/core/runner/prepare-hands-readface.d.ts +4 -0
- package/dist/core/runner/prepare-hands-readface.js +5 -0
- package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
- package/dist/core/runner/prepare-inherited-gate.js +14 -27
- package/dist/core/runner/prepare-memory.js +10 -17
- package/dist/core/runner/prepare-park-ask.d.ts +1 -1
- package/dist/core/runner/prepare-park-ask.js +2 -1
- package/dist/core/runner/prepare-policy-chain.d.ts +3 -3
- package/dist/core/runner/prepare-policy-chain.js +16 -13
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
- package/dist/core/runner/prepare-prompt-inputs.js +8 -19
- package/dist/core/runner/prepare-protocol-tools.js +9 -1
- package/dist/core/runner/prepare-run-refs.d.ts +2 -3
- package/dist/core/runner/prepare-run-refs.js +4 -1
- package/dist/core/runner/prepare-task.js +4 -2
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -1
- package/dist/core/runner/prepare-wiring-manifest.js +2 -1
- package/dist/core/runner/reply-pricing.d.ts +30 -0
- package/dist/core/runner/reply-pricing.js +19 -0
- package/dist/core/runner/resume-admission.js +4 -2
- package/dist/core/runner/resume-apply.js +6 -1
- package/dist/core/runner/resume-policy-outcome.js +5 -5
- package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
- package/dist/core/runner/role-seat-defaulted.js +40 -0
- package/dist/core/runner/run-brain-sinks.js +2 -0
- package/dist/core/runner/run-identity-wiring.d.ts +2 -5
- package/dist/core/runner/run-identity-wiring.js +5 -4
- package/dist/core/runner/run-leg.d.ts +2 -0
- package/dist/core/runner/run-leg.js +37 -28
- package/dist/core/runner/run-stop-and-final-verify.js +2 -2
- package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
- package/dist/core/runner/run-terminal-adoption.js +9 -3
- package/dist/core/runner/run-turn-boundary.js +77 -70
- package/dist/core/runner/runtask.d.ts +1 -1
- package/dist/core/runner/runtask.js +2 -2
- package/dist/core/runner/side-call-account.d.ts +1 -1
- package/dist/core/runner/side-call-account.js +3 -18
- package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
- package/dist/core/runner/sub-agent-deny-lists.js +10 -0
- package/dist/core/runner/tool-end-body.js +2 -2
- package/dist/core/runner/tool-occurrence.d.ts +1 -1
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner/turn-attachments.d.ts +26 -22
- package/dist/core/runner/turn-attachments.js +24 -26
- package/dist/core/runner-deps.d.ts +1 -1
- package/dist/core/secret-env.d.ts +32 -2
- package/dist/core/secret-env.js +65 -3
- package/dist/core/sensitive-path-policy.js +3 -3
- package/dist/core/session-policy-store.d.ts +3 -1
- package/dist/core/session-policy-store.js +13 -9
- package/dist/core/session-store.d.ts +2 -5
- package/dist/core/side-query.d.ts +11 -1
- package/dist/core/side-query.js +9 -0
- package/dist/core/skill-grant-binding.d.ts +31 -2
- package/dist/core/skill-grant-binding.js +31 -1
- package/dist/core/skill-grant.d.ts +8 -5
- package/dist/core/skill-grant.js +6 -6
- package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +3 -2
- package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
- package/dist/core/synthetic-read-verdict.js +2 -1
- package/dist/core/task-event.d.ts +32 -8
- package/dist/core/task-notification.js +16 -10
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +5 -0
- package/dist/core/task-spec.d.ts +12 -1
- package/dist/core/terminal-cause.d.ts +10 -0
- package/dist/core/tool-check-reading.d.ts +1 -0
- package/dist/core/tool-check-reading.js +3 -3
- package/dist/core/tool-policy.d.ts +16 -0
- package/dist/core/tool-roster.d.ts +112 -5
- package/dist/core/tool-roster.js +42 -1
- package/dist/core/tool-spec.d.ts +3 -1
- package/dist/core/types.d.ts +2 -2
- package/dist/core/types.js +1 -1
- package/dist/core/user-attachment.js +1 -1
- package/dist/core/wiring-manifest.d.ts +6 -3
- package/dist/engine/compaction/compaction.js +29 -3
- package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
- package/dist/engine/execution-env/node-execution-env.js +9 -12
- package/dist/engine/harness/agent-harness.d.ts +25 -2
- package/dist/engine/harness/agent-harness.js +41 -12
- package/dist/engine/harness/messages.d.ts +3 -1
- package/dist/engine/harness/messages.js +3 -2
- package/dist/engine/harness/types.d.ts +8 -0
- package/dist/engine/llm/rejected-images.d.ts +46 -0
- package/dist/engine/llm/rejected-images.js +54 -0
- package/dist/engine/llm/tool-turns.d.ts +2 -1
- package/dist/engine/llm/types.d.ts +18 -7
- package/dist/engine/loop/agent-loop.d.ts +8 -0
- package/dist/engine/loop/agent-loop.js +52 -15
- package/dist/engine/loop/types.d.ts +3 -1
- package/dist/engine/session/path-to-root.d.ts +38 -0
- package/dist/engine/session/path-to-root.js +39 -0
- package/dist/engine/session/storage-base.js +4 -21
- package/dist/index.d.ts +16 -10
- package/dist/index.js +11 -7
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +1 -0
- package/dist/internal/llm.d.ts +1 -0
- package/dist/orchestration/workflow-observe.d.ts +17 -1
- package/dist/orchestration/workflow-observe.js +20 -0
- package/dist/orchestration/workflow-types.d.ts +32 -7
- package/dist/orchestration/workflow.js +739 -489
- package/dist/shell/counting-pass.d.ts +50 -0
- package/dist/shell/counting-pass.js +502 -0
- package/dist/shell/lex.d.ts +4 -2
- package/dist/shell/lex.js +93 -34
- package/dist/shell/shell-words.d.ts +1 -1
- package/dist/shell/shell-words.js +7 -6
- package/dist/stores/file/mailbox-store.js +6 -10
- package/dist/tools/fs/fs-bash.d.ts +6 -0
- package/dist/tools/fs/fs-bash.js +6 -3
- package/dist/tools/fs/index.js +6 -2
- package/dist/tools/fs/program-read-model.d.ts +13 -0
- package/dist/tools/fs/program-read-model.js +15 -0
- package/dist/tools/fs/program-read-model.rows.js +1 -1
- package/dist/tools/fs/read-deny.d.ts +13 -10
- package/dist/tools/fs/read-deny.js +25 -5
- package/dist/tools/fs/read-floor.d.ts +19 -0
- package/dist/tools/fs/read-floor.js +23 -0
- package/dist/tools/fs/shell-read-check.d.ts +1 -1
- package/dist/tools/fs/shell-read-check.js +2 -1
- package/dist/tools/fs/shell-read-judge.d.ts +16 -8
- package/dist/tools/fs/shell-read-judge.js +10 -6
- package/dist/tools/fs/shell-read-plan.d.ts +6 -1
- package/dist/tools/fs/shell-read-plan.js +22 -15
- package/dist/tools/fs/shell-read-start.js +1 -0
- package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
- package/dist/tools/fs/shell-reentry-text.js +25 -3
- package/dist/tools/monitor.d.ts +4 -0
- package/dist/tools/monitor.js +2 -0
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +87 -1
- package/wire-changes/core-stores-sql@7.59.0.json +29 -0
- package/wire-changes/core@7.59.0.json +2459 -0
- package/wire-changes/mods-kernel@7.59.0.json +29 -0
- package/wire-changes/primitives@7.59.0.json +29 -0
package/dist/core/peer-seat.js
CHANGED
|
@@ -7,6 +7,97 @@ import { holdOwnCredentialValues, isSecretEnvKey } from "./secret-env.js";
|
|
|
7
7
|
import { inlineUntrusted } from "./untrusted-text.js";
|
|
8
8
|
export const PEER_ANSWER_LANES = Object.freeze({ http: "headers", a2a: "headers", stdio: "env" });
|
|
9
9
|
export const PEER_SEAT_WAIT_MS = 30_000;
|
|
10
|
+
export const AUTHORIZATION_URL_MAX = 2048;
|
|
11
|
+
export function authorizationUrlOf(raw) {
|
|
12
|
+
if (typeof raw !== "string" || /[\u0000-\u001f\u007f]/.test(raw))
|
|
13
|
+
return undefined;
|
|
14
|
+
let url;
|
|
15
|
+
try {
|
|
16
|
+
url = new URL(raw);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if ((url.protocol !== "https:" && url.protocol !== "http:") || url.username !== "" || url.password !== "")
|
|
22
|
+
return undefined;
|
|
23
|
+
const kept = url.origin + `${url.pathname}${url.search}${url.hash}`.replace(/[[\]()<>`"'{}|^\\]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
24
|
+
return kept.length <= AUTHORIZATION_URL_MAX ? kept : undefined;
|
|
25
|
+
}
|
|
26
|
+
export function bearerChallengeParams(header) {
|
|
27
|
+
if (header === null)
|
|
28
|
+
return undefined;
|
|
29
|
+
const token = /[!#$%&'*+.^_`|~0-9A-Za-z-]+/y;
|
|
30
|
+
const readToken = (at) => ((token.lastIndex = at), token.exec(header)?.[0]);
|
|
31
|
+
let i = 0;
|
|
32
|
+
let scheme;
|
|
33
|
+
let params = new Map();
|
|
34
|
+
let bearer;
|
|
35
|
+
let bareScheme = false;
|
|
36
|
+
const space = () => void (i += /^[ \t]*/.exec(header.slice(i))[0].length);
|
|
37
|
+
while (i < header.length) {
|
|
38
|
+
space();
|
|
39
|
+
const name = readToken(i);
|
|
40
|
+
if (name === undefined) {
|
|
41
|
+
if (header[i] === ",")
|
|
42
|
+
bareScheme = false;
|
|
43
|
+
i++;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
i += name.length;
|
|
47
|
+
space();
|
|
48
|
+
if (header[i] !== "=") {
|
|
49
|
+
if (bareScheme) {
|
|
50
|
+
bareScheme = false;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (scheme?.toLowerCase() === "bearer")
|
|
54
|
+
bearer ??= params;
|
|
55
|
+
scheme = name;
|
|
56
|
+
params = new Map();
|
|
57
|
+
bareScheme = true;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
bareScheme = false;
|
|
61
|
+
i++;
|
|
62
|
+
space();
|
|
63
|
+
let value = "";
|
|
64
|
+
if (header[i] === '"') {
|
|
65
|
+
for (i++; i < header.length && header[i] !== '"'; i++)
|
|
66
|
+
value += header[i] === "\\" ? (header[++i] ?? "") : header[i];
|
|
67
|
+
i++;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
value = readToken(i) ?? "";
|
|
71
|
+
i += value.length;
|
|
72
|
+
}
|
|
73
|
+
if (scheme !== undefined && !params.has(name.toLowerCase()))
|
|
74
|
+
params.set(name.toLowerCase(), value);
|
|
75
|
+
}
|
|
76
|
+
if (scheme?.toLowerCase() === "bearer")
|
|
77
|
+
bearer ??= params;
|
|
78
|
+
return bearer;
|
|
79
|
+
}
|
|
80
|
+
async function bodyHead(res, max) {
|
|
81
|
+
const reader = res.body?.getReader();
|
|
82
|
+
if (reader === undefined)
|
|
83
|
+
return undefined;
|
|
84
|
+
const decoder = new TextDecoder();
|
|
85
|
+
let text = "";
|
|
86
|
+
try {
|
|
87
|
+
while (text.length < max) {
|
|
88
|
+
const { done, value } = await reader.read();
|
|
89
|
+
if (done)
|
|
90
|
+
break;
|
|
91
|
+
text += decoder.decode(value, { stream: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
void reader.cancel().catch(() => undefined);
|
|
98
|
+
}
|
|
99
|
+
return text.slice(0, max);
|
|
100
|
+
}
|
|
10
101
|
export class PeerSeatFailure extends Error {
|
|
11
102
|
reason;
|
|
12
103
|
authorizeUrl;
|
|
@@ -19,6 +110,31 @@ export class PeerSeatFailure extends Error {
|
|
|
19
110
|
this.code = extra?.code ?? (reason === "answer_invalid" ? "config.peer_answer_invalid" : undefined);
|
|
20
111
|
}
|
|
21
112
|
}
|
|
113
|
+
export class PeerAuthorizationRefused extends StreamableHTTPError {
|
|
114
|
+
reason;
|
|
115
|
+
resourceMetadataUrl;
|
|
116
|
+
authorizeUrl;
|
|
117
|
+
renewed;
|
|
118
|
+
constructor(reason, facts) {
|
|
119
|
+
const lead = reason === "rejected" ? "the endpoint refused the request's authorization (HTTP 401)" : "the endpoint refused the request for insufficient scope (HTTP 403)";
|
|
120
|
+
super(reason === "rejected" ? 401 : 403, facts.body !== undefined && facts.body !== "" ? `${lead}: ${facts.body}` : lead);
|
|
121
|
+
this.name = "PeerAuthorizationRefused";
|
|
122
|
+
this.reason = reason;
|
|
123
|
+
this.resourceMetadataUrl = facts.resourceMetadataUrl;
|
|
124
|
+
this.authorizeUrl = facts.authorizeUrl;
|
|
125
|
+
this.renewed = facts.renewed === true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export const REFUSAL_BODY_MAX = 4096;
|
|
129
|
+
export function refusedThenRenewed(err) {
|
|
130
|
+
let at = err;
|
|
131
|
+
for (let depth = 0; depth < 6 && at instanceof Error; depth++) {
|
|
132
|
+
if (at instanceof PeerAuthorizationRefused)
|
|
133
|
+
return at.renewed;
|
|
134
|
+
at = at.cause;
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
22
138
|
const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
23
139
|
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
24
140
|
const VALUE_BREAK = /[\r\n\0]/;
|
|
@@ -62,10 +178,13 @@ export function readPeerAnswer(raw, lane) {
|
|
|
62
178
|
if (extra !== undefined)
|
|
63
179
|
return { problem: `answered the member ${inlineUntrusted(JSON.stringify(extra), 80)}, which a "${kind}" answer does not have` };
|
|
64
180
|
if (kind === "unauthorized") {
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
return {
|
|
68
|
-
|
|
181
|
+
const raw = record["authorizeUrl"];
|
|
182
|
+
if (raw === undefined)
|
|
183
|
+
return { unauthorized: {} };
|
|
184
|
+
const url = authorizationUrlOf(raw);
|
|
185
|
+
if (url === undefined)
|
|
186
|
+
return { problem: `answered an authorizeUrl that is not an absolute http(s) URL without user-info, of at most ${AUTHORIZATION_URL_MAX} characters, without control characters` };
|
|
187
|
+
return { unauthorized: { authorizeUrl: url } };
|
|
69
188
|
}
|
|
70
189
|
const own = PEER_ANSWER_LANES[lane];
|
|
71
190
|
const other = own === "headers" ? "env" : "headers";
|
|
@@ -145,13 +264,15 @@ export class PeerCarrier {
|
|
|
145
264
|
.then((pieces) => {
|
|
146
265
|
this.waiting = pieces;
|
|
147
266
|
this.renewed = pieces.digest !== carried.digest;
|
|
148
|
-
|
|
267
|
+
return { renewed: this.renewed };
|
|
268
|
+
}, (err) => {
|
|
149
269
|
this.renewed = false;
|
|
270
|
+
return err instanceof PeerSeatFailure && err.reason === "unauthorized" && err.authorizeUrl !== undefined ? { renewed: false, authorizeUrl: err.authorizeUrl } : { renewed: false };
|
|
150
271
|
})
|
|
151
272
|
.finally(() => {
|
|
152
273
|
this.rejection = undefined;
|
|
153
274
|
});
|
|
154
|
-
|
|
275
|
+
return this.rejection;
|
|
155
276
|
}
|
|
156
277
|
expired(now = Date.now()) {
|
|
157
278
|
return this.expiresAt !== undefined && now >= this.expiresAt;
|
|
@@ -212,9 +333,20 @@ export function peerFetch(carrier, principalHeader, principal) {
|
|
|
212
333
|
for (const [name, value] of Object.entries(own ?? {}))
|
|
213
334
|
headers.set(name, value);
|
|
214
335
|
const res = await fetch(url, { ...init, headers, redirect: "manual" });
|
|
215
|
-
if (res.status
|
|
216
|
-
|
|
217
|
-
|
|
336
|
+
if (res.status !== 401 && res.status !== 403)
|
|
337
|
+
return res;
|
|
338
|
+
const challenge = bearerChallengeParams(res.headers.get("www-authenticate"));
|
|
339
|
+
if (res.status === 403 && challenge?.get("error") !== "insufficient_scope")
|
|
340
|
+
return res;
|
|
341
|
+
const resourceMetadataUrl = authorizationUrlOf(challenge?.get("resource_metadata"));
|
|
342
|
+
const body = init?.method === "POST" ? await bodyHead(res, REFUSAL_BODY_MAX) : void (await res.body?.cancel().catch(() => undefined));
|
|
343
|
+
const reask = res.status === 401 ? await carrier.rejected(pieces, signal) : undefined;
|
|
344
|
+
throw new PeerAuthorizationRefused(res.status === 401 ? "rejected" : "scope", {
|
|
345
|
+
...(resourceMetadataUrl !== undefined ? { resourceMetadataUrl } : {}),
|
|
346
|
+
...(reask?.authorizeUrl !== undefined ? { authorizeUrl: reask.authorizeUrl } : {}),
|
|
347
|
+
renewed: reask?.renewed === true,
|
|
348
|
+
...(body !== undefined ? { body } : {}),
|
|
349
|
+
});
|
|
218
350
|
};
|
|
219
351
|
}
|
|
220
352
|
export const RETIRED_VALUE_MEMBERS = Object.freeze({ mcp: Object.freeze([Object.freeze(["transport", "headers"]), Object.freeze(["transport", "env"])]), a2a: Object.freeze([Object.freeze(["headers"])]) });
|
|
@@ -271,12 +403,12 @@ export class Reauthorized {
|
|
|
271
403
|
}
|
|
272
404
|
}
|
|
273
405
|
export async function sentOnceMore(attempt, mayResend) {
|
|
274
|
-
const first = await attempt();
|
|
406
|
+
const first = await attempt(false);
|
|
275
407
|
if (!(first instanceof Reauthorized))
|
|
276
408
|
return first;
|
|
277
409
|
if (!mayResend())
|
|
278
410
|
throw first.error;
|
|
279
|
-
const again = await attempt().catch((err) => {
|
|
411
|
+
const again = await attempt(true).catch((err) => {
|
|
280
412
|
const details = readMember(err, "details");
|
|
281
413
|
throw typeof details === "object" && details !== null && readMember(details, "delivered") === "no" ? first.error : err;
|
|
282
414
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { COMMAND_RULE_TOOL, cardRuleFormOf, escapeForDisclosure, hasUnrenderableCharacters, parseRuleText, ruleAdmitsCommand, ruleBreadthWarningsOf, segmentCoverageOf, suggestRuleForHost, suggestRuleForName, suggestRuleForTool, suggestRulesForCommand, EDITED_RULE_BREADTH_WARNING_CODES, RULE_OFFER_KINDS, UNCOVERED_SEGMENT_REASONS, RULE_BEHAVIORS, RULE_BEHAVIOR_PRECEDENCE, isRuleBehavior, } from "./permission-rule-model.js";
|
|
2
|
+
import { COMMAND_RULE_TOOL, cardRuleFormOf, escapeForDisclosure, foldSpacing, hasUnrenderableCharacters, parseRuleText, ruleAdmitsCommand, ruleBreadthWarningsOf, segmentCoverageOf, suggestRuleForHost, suggestRuleForName, suggestRuleForTool, suggestRulesForCommand, EDITED_RULE_BREADTH_WARNING_CODES, RULE_OFFER_KINDS, UNCOVERED_SEGMENT_REASONS, RULE_BEHAVIORS, RULE_BEHAVIOR_PRECEDENCE, isRuleBehavior, } from "./permission-rule-model.js";
|
|
3
3
|
import { readRuleOwner, sameRuleOwner } from "./rule-owner.js";
|
|
4
4
|
import { principalNameOf, readPrincipal } from "./principal-name.js";
|
|
5
5
|
import { isPlainRecord } from "./mods/kernel/receive.js";
|
|
@@ -535,12 +535,18 @@ export async function confirmRuleApproval(opts) {
|
|
|
535
535
|
return settled === chosen ? { ok: true } : no("selection_mismatch");
|
|
536
536
|
}
|
|
537
537
|
function normalizeEditedSpelling(text) {
|
|
538
|
-
const m = /^([A-Za-z][A-Za-z0-9_]*)\((.+)
|
|
538
|
+
const m = /^([A-Za-z][A-Za-z0-9_]*)\((.+)\)$/.exec(text);
|
|
539
539
|
if (m === null)
|
|
540
540
|
return text;
|
|
541
541
|
const head = m[1];
|
|
542
|
-
const
|
|
543
|
-
if (head === undefined ||
|
|
542
|
+
const content = m[2];
|
|
543
|
+
if (head === undefined || content === undefined)
|
|
544
|
+
return text;
|
|
545
|
+
const read = head === COMMAND_RULE_TOOL ? foldSpacing(content) : content;
|
|
546
|
+
if (read === undefined)
|
|
547
|
+
return text;
|
|
548
|
+
const body = /^(.+) \*$/.exec(read)?.[1];
|
|
549
|
+
if (body === undefined || body.includes("*"))
|
|
544
550
|
return text;
|
|
545
551
|
return `${head}(${body}:*)`;
|
|
546
552
|
}
|
|
@@ -628,6 +628,22 @@ export declare const SHELL_RESERVED_WORDS: ReadonlySet<string>;
|
|
|
628
628
|
* misled.
|
|
629
629
|
*/
|
|
630
630
|
export declare const SUGGESTION_LEXICON: readonly string[];
|
|
631
|
+
/**
|
|
632
|
+
* Collapse space/tab runs that are OUTSIDE quotes, and refuse a command whose quoting does not balance.
|
|
633
|
+
*
|
|
634
|
+
* A blanket fold is unsound here, and unsound in the direction that matters: an exact approval of
|
|
635
|
+
* `rm 'safe file'` would be stored as `rm 'safe file'` and would then admit a command naming a
|
|
636
|
+
* DIFFERENT path. An exact rule has exactly one job — to mean the action the person approved — so
|
|
637
|
+
* whitespace inside a quoted argument is data and is preserved verbatim.
|
|
638
|
+
*
|
|
639
|
+
* Unbalanced quoting yields `undefined`: the command's real argv is then not determinable from the text,
|
|
640
|
+
* and a rule lane that cannot determine what it is looking at does not match. It treats a backslash as text: a matched
|
|
641
|
+
* command has passed the simple-command floor (which rejects backslashes) before it is folded, and a rule text that holds
|
|
642
|
+
* one (a pattern's `\*` aside) is refused by that floor after its form is read.
|
|
643
|
+
*
|
|
644
|
+
* Exported so the card-edit face's spelling normalizer reads a command rule's content through THIS fold and no second one.
|
|
645
|
+
*/
|
|
646
|
+
export declare function foldSpacing(s: string): string | undefined;
|
|
631
647
|
/**
|
|
632
648
|
* THE spelling of a content rule on a call's tool under one behavior — its rule word and grammar with a placeholder for the
|
|
633
649
|
* content, never a rule minted for the call — or undefined: the tool takes no content rule (the catalog gives it no grammar,
|
|
@@ -23,6 +23,16 @@ export interface PlanFileSource {
|
|
|
23
23
|
readonly shown: string;
|
|
24
24
|
readonly read: (signal?: AbortSignal) => Promise<import("./runner/advertised-writable-dirs.js").PlanFileReading>;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* What the engine's plan-pause request primitive takes: the requester's own `reason`, and `requestedByCallId` — the id of
|
|
28
|
+
* the call that asks, which the ENGINE binds from that call's own context (the first-party tool passes its ctx's
|
|
29
|
+
* `toolCallId`; a caller tool's `ctx.requestReview` is wrapped per call), never a tool-supplied argument. Parked on the
|
|
30
|
+
* `plan_review` row as provenance: which call presented the plan awaiting a decision.
|
|
31
|
+
*/
|
|
32
|
+
export interface ReviewRequest {
|
|
33
|
+
reason?: string;
|
|
34
|
+
requestedByCallId?: string;
|
|
35
|
+
}
|
|
26
36
|
/**
|
|
27
37
|
* design/80 D-B — the first-party `present_plan` tool (CC `ExitPlanMode` parity). A THIN composition over the
|
|
28
38
|
* general `ctx.requestReview()` primitive: the model calls it with a plan; the tool returns the plan as its
|
|
@@ -31,6 +41,4 @@ export interface PlanFileSource {
|
|
|
31
41
|
* NO side effect (`effect:"read"`); the actual pause/mint is the engine's, gated on a wired `checkpointStore`.
|
|
32
42
|
* `requestReview` is the prepare-task closure (the same primitive `ctx.requestReview` exposes to caller tools).
|
|
33
43
|
*/
|
|
34
|
-
export declare function createPresentPlanTool(requestReview: (opts?:
|
|
35
|
-
reason?: string;
|
|
36
|
-
}) => void, planFile?: PlanFileSource): ToolSpec;
|
|
44
|
+
export declare function createPresentPlanTool(requestReview: (opts?: ReviewRequest) => void, planFile?: PlanFileSource): ToolSpec;
|
|
@@ -114,9 +114,9 @@ export function createPresentPlanTool(requestReview, planFile) {
|
|
|
114
114
|
description: "Your full proposed plan, in markdown. The human reviewer approves / edits / rejects it before you act.",
|
|
115
115
|
}),
|
|
116
116
|
}),
|
|
117
|
-
execute: async (args) => {
|
|
117
|
+
execute: async (args, ctx) => {
|
|
118
118
|
const { plan } = args;
|
|
119
|
-
requestReview({ reason: "ExitPlanMode" });
|
|
119
|
+
requestReview({ reason: "ExitPlanMode", ...(typeof ctx?.toolCallId === "string" && ctx.toolCallId !== "" ? { requestedByCallId: ctx.toolCallId } : {}) });
|
|
120
120
|
return {
|
|
121
121
|
content: `Plan presented for human review:\n\n${delimitUntrusted("plan", plan)}\n\n` +
|
|
122
122
|
"(The run is pausing for approval — you will continue once the plan is approved, edited, or rejected.)",
|
|
@@ -12,6 +12,7 @@ const CAUSE_OF_CODE = new Map([
|
|
|
12
12
|
["checkpoint.config_refused", "configuration"],
|
|
13
13
|
["resume.parent_constraint_missing", "configuration"],
|
|
14
14
|
["resume.parent_constraint_mismatch", "configuration"],
|
|
15
|
+
["revive.policy_floor_unreadable", "configuration"],
|
|
15
16
|
["checkpoint.gate_mismatch", "decision_rejected"],
|
|
16
17
|
["checkpoint.invalid_outcome", "decision_rejected"],
|
|
17
18
|
["resume.constraint_rejected", "decision_rejected"],
|
|
@@ -67,6 +67,7 @@ export type ScreeningRejudge = {
|
|
|
67
67
|
readonly kind: "refused";
|
|
68
68
|
readonly reason: string;
|
|
69
69
|
readonly by: "hook" | "engine";
|
|
70
|
+
readonly extension?: string;
|
|
70
71
|
};
|
|
71
72
|
/** The screening's second look at rewritten `bytes` (the gate's fold after a policy rewrite; the approved-edit pass). */
|
|
72
73
|
export declare function screenRewrite(screening: PreToolUseScreening, req: {
|
|
@@ -50,10 +50,10 @@ export function readRejudge(req, given, answer) {
|
|
|
50
50
|
export async function screenRewrite(screening, req, bytes, subject) {
|
|
51
51
|
const screened = await screening.screen(bytes, subject);
|
|
52
52
|
if (screened.kind === "refused")
|
|
53
|
-
return { kind: "refused", reason: screened.reason, by: "engine" };
|
|
53
|
+
return { kind: "refused", reason: screened.reason, by: "engine", ...(screened.extension !== undefined ? { extension: screened.extension } : {}) };
|
|
54
54
|
const r = screened.answer;
|
|
55
55
|
if (r?.action === "deny")
|
|
56
|
-
return { kind: "refused", reason: screening.deniedReason(r), by: "hook" };
|
|
56
|
+
return { kind: "refused", reason: screening.deniedReason(r), by: "hook", ...(screened.answeredBy !== undefined ? { extension: screened.answeredBy } : {}) };
|
|
57
57
|
if (readRejudge(req, bytes, r).kind === "rewritten")
|
|
58
58
|
return { kind: "refused", reason: rewriteChasedSentence(req.toolName), by: "engine" };
|
|
59
59
|
if (r === undefined)
|
package/dist/core/roles.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { type RoleBaseDeclaration } from "../prompt-assembly/role-base.js";
|
|
|
5
5
|
import { type ModelRef, type ModelRole, type ModelRoles, type RoleSpec } from "./types.js";
|
|
6
6
|
export type { ModelRole, RoleSpec, ModelRoles } from "./types.js";
|
|
7
7
|
export { MODEL_ROLES } from "./types.js";
|
|
8
|
+
/** A word in a refusal sentence, bounded and quoted; any other kind of value by its kind (rendering it could itself throw). */
|
|
9
|
+
export declare function bindingShown(value: unknown): string;
|
|
8
10
|
/**
|
|
9
11
|
* Resolve a ModelRef against the catalog (a Model object passes through). A word the catalog does not hold, and a value that is no model
|
|
10
12
|
* reference, are refused by `config.unknown_role` with `detail { field: seat, reason }` — `seat` names where the caller wrote the word
|
|
@@ -118,6 +120,34 @@ export declare function roleSpecNamesModel(spec: RoleSpec | undefined): boolean;
|
|
|
118
120
|
* maps, so an entry no task of this leg selects still refuses loudly.
|
|
119
121
|
*/
|
|
120
122
|
export declare function screenRoleMap(roles: ModelRoles | undefined, field: "RunnerDeps.roles" | "TaskSpec.roles"): void;
|
|
123
|
+
/** A role seat whose word the catalog does not hold: the role, the seat as the refusal names it, the word written there. */
|
|
124
|
+
export interface UnheldRoleSeat {
|
|
125
|
+
role: ModelRole;
|
|
126
|
+
seat: string;
|
|
127
|
+
word: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The ONE test of "this seat names a word the deployment's catalog does not declare": the word a role entry writes — the string
|
|
131
|
+
* itself, or the `model` member of a config record — when it is a string and no key of the catalog answers it. A Model object, a
|
|
132
|
+
* `select`, a preset-only record and an absent seat name no word. Total: it reads, never judges the shape (a value that is no binding
|
|
133
|
+
* is the screen's refusal, `screenRoleMap`).
|
|
134
|
+
*/
|
|
135
|
+
export declare function unheldSeatWord(spec: unknown, models: Record<string, Model> | undefined): string | undefined;
|
|
136
|
+
/** Every role seat of the merged maps (deployment and task) that names a word the catalog does not hold, in vocabulary order — the facts
|
|
137
|
+
* {@link seatRead} stands in for. `default` is never listed (it refuses) and neither is `classifier` unless asked (it says it itself). */
|
|
138
|
+
export declare function unheldRoleSeats(spec: {
|
|
139
|
+
roles?: ModelRoles;
|
|
140
|
+
}, deps: {
|
|
141
|
+
models?: Record<string, Model>;
|
|
142
|
+
roles?: ModelRoles;
|
|
143
|
+
}, only?: readonly ModelRole[]): UnheldRoleSeat[];
|
|
144
|
+
/** The refusal of an unheld seat — the seat's own `config.unknown_role` / `unknown_model_ref`, for the place where a chain ends with no model. */
|
|
145
|
+
export declare function unheldSeatRefusal(u: UnheldRoleSeat): Error;
|
|
146
|
+
/** The refusal for a chain of roles that supplied no model while one of its seats was written but not held — that seat's own
|
|
147
|
+
* `config.unknown_role`; `undefined` when no seat of the chain is unheld (the caller's own "no seat" refusal stands). */
|
|
148
|
+
export declare function unheldChainRefusal(chain: readonly ModelRole[], models: Record<string, Model> | undefined, roles: ModelRoles | undefined): Error | undefined;
|
|
149
|
+
/** The roles a role falls back to when its seat supplies nothing, nearest first (what {@link unheldRoleSeats} says it stands in for). */
|
|
150
|
+
export declare function roleFallbackChain(role: ModelRole): readonly ModelRole[];
|
|
121
151
|
export interface ResolvedRole {
|
|
122
152
|
model: Model;
|
|
123
153
|
/**
|
|
@@ -156,7 +186,8 @@ export declare function presetRoleBaseOf(spec: {
|
|
|
156
186
|
/**
|
|
157
187
|
* Resolve the model (and default thinking) for a task. Explicit `spec.model` wins; otherwise walk the
|
|
158
188
|
* `modelRole`'s fallback chain over the merged roles (task overrides runner) and use the first role
|
|
159
|
-
* that supplies a model.
|
|
189
|
+
* that supplies a model. A seat on that chain whose word the catalog does not hold supplies none ({@link seatRead}); when the whole
|
|
190
|
+
* chain supplies none, the first such seat's own refusal is the answer. Throws a helpful error if nothing resolves.
|
|
160
191
|
*
|
|
161
192
|
* @contract roles.side_channels_deployment_only — an engine SIDE CHANNEL (the auto-mode classifier,
|
|
162
193
|
* the compaction/summarize lane, memory consolidation, next-prompt suggestion) resolves here with a
|
|
@@ -179,7 +210,8 @@ export declare function resolveTaskModel(spec: {
|
|
|
179
210
|
/**
|
|
180
211
|
* Resolve a role's model **only if that exact role key is configured** (no fallback chain). Used for
|
|
181
212
|
* the `summarize` compaction model: override only when a summarize-specific model is set, otherwise
|
|
182
|
-
* let the caller fall back to the main model (unchanged behavior).
|
|
213
|
+
* let the caller fall back to the main model (unchanged behavior). A seat naming a word the catalog does not hold is "not set" here,
|
|
214
|
+
* as in the walk ({@link seatRead}); a caller that needs a model asks {@link unheldRoleSeats} for the refusal when it gets none.
|
|
183
215
|
*/
|
|
184
216
|
export declare function roleModelIfSet(role: ModelRole, spec: {
|
|
185
217
|
roles?: ModelRoles;
|
package/dist/core/roles.js
CHANGED
|
@@ -32,7 +32,7 @@ function isModelShaped(s) {
|
|
|
32
32
|
function isBindingObject(value) {
|
|
33
33
|
return (typeof value === "object" && value !== null) || typeof value === "function";
|
|
34
34
|
}
|
|
35
|
-
function bindingShown(value) {
|
|
35
|
+
export function bindingShown(value) {
|
|
36
36
|
if (typeof value === "string")
|
|
37
37
|
return JSON.stringify(value.length > 80 ? `${value.slice(0, 80)}…` : value);
|
|
38
38
|
return value === null ? "null" : isList(value) ? "a list" : `a ${typeof value}`;
|
|
@@ -296,6 +296,40 @@ function partsModel(parts, models, seat = "a role seat") {
|
|
|
296
296
|
}
|
|
297
297
|
return undefined;
|
|
298
298
|
}
|
|
299
|
+
export function unheldSeatWord(spec, models) {
|
|
300
|
+
const named = typeof spec === "string" ? spec : isBindingObject(spec) && !("id" in spec && "api" in spec) ? spec.model : undefined;
|
|
301
|
+
return typeof named === "string" && catalogModel(named, models) === undefined ? named : undefined;
|
|
302
|
+
}
|
|
303
|
+
const STRICT_SEATS = new Set(["default", "classifier"]);
|
|
304
|
+
function seatRead(parts, models, seat, role) {
|
|
305
|
+
const word = STRICT_SEATS.has(role) ? undefined : unheldSeatWord(parts.model, models);
|
|
306
|
+
if (word === undefined)
|
|
307
|
+
return { parts, model: partsModel(parts, models, seat), unheld: undefined };
|
|
308
|
+
const unset = { ...parts, model: undefined };
|
|
309
|
+
return { parts: unset, model: partsModel(unset, models, seat), unheld: { role, seat, word } };
|
|
310
|
+
}
|
|
311
|
+
export function unheldRoleSeats(spec, deps, only) {
|
|
312
|
+
const merged = mergeRoles(deps.roles, spec.roles);
|
|
313
|
+
const out = [];
|
|
314
|
+
for (const role of only ?? MODEL_ROLES) {
|
|
315
|
+
if (only === undefined && STRICT_SEATS.has(role))
|
|
316
|
+
continue;
|
|
317
|
+
const word = unheldSeatWord(merged[role], deps.models);
|
|
318
|
+
if (word !== undefined)
|
|
319
|
+
out.push({ role, seat: `roles.${role}`, word });
|
|
320
|
+
}
|
|
321
|
+
return out;
|
|
322
|
+
}
|
|
323
|
+
export function unheldSeatRefusal(u) {
|
|
324
|
+
return unknownModelRefRefusal(u.word, u.seat);
|
|
325
|
+
}
|
|
326
|
+
export function unheldChainRefusal(chain, models, roles) {
|
|
327
|
+
const first = unheldRoleSeats({}, { models, roles }, chain)[0];
|
|
328
|
+
return first !== undefined ? unheldSeatRefusal(first) : undefined;
|
|
329
|
+
}
|
|
330
|
+
export function roleFallbackChain(role) {
|
|
331
|
+
return FALLBACK[role];
|
|
332
|
+
}
|
|
299
333
|
function chainHead(spec, deps) {
|
|
300
334
|
const start = spec.modelRole === undefined ? "default" : spec.modelRole;
|
|
301
335
|
assertKnownRole(start, "modelRole");
|
|
@@ -318,20 +352,25 @@ export function resolveTaskModel(spec, deps) {
|
|
|
318
352
|
};
|
|
319
353
|
}
|
|
320
354
|
const { promptRole: startPromptRole, systemPrompt: startSystemPrompt } = startParts;
|
|
355
|
+
let firstUnheld;
|
|
321
356
|
for (const role of [start, ...FALLBACK[start]]) {
|
|
322
|
-
const
|
|
323
|
-
const
|
|
357
|
+
const read = seatRead(specParts(merged[role], `roles.${role}`), deps.models, `roles.${role}`, role);
|
|
358
|
+
const parts = read.parts;
|
|
359
|
+
firstUnheld ??= read.unheld;
|
|
360
|
+
const fromParts = read.model;
|
|
324
361
|
const model = fromParts ?? roleTierModel(role, deps.models);
|
|
325
362
|
if (model) {
|
|
326
363
|
const modelRef = fromParts !== undefined ? (parts.model ?? model) : (ROLE_TIER_DEFAULTS[role] ?? model);
|
|
327
364
|
return { model, modelRef, thinking: spec.thinking ?? parts.thinking, promptRole: startPromptRole, systemPrompt: startSystemPrompt };
|
|
328
365
|
}
|
|
329
366
|
}
|
|
367
|
+
if (firstUnheld !== undefined)
|
|
368
|
+
throw unheldSeatRefusal(firstUnheld);
|
|
330
369
|
throw new Error(`No model for role "${start}": set TaskSpec.model, or configure RunnerDeps.roles / TaskSpec.roles["${start}"] (or a "default" role). A "select" RoleSpec also fails here if no catalog model matches.`);
|
|
331
370
|
}
|
|
332
371
|
export function roleModelIfSet(role, spec, deps) {
|
|
333
372
|
const merged = mergeRoles(deps.roles, spec.roles);
|
|
334
373
|
const seat = `roles.${role}`;
|
|
335
374
|
const parts = specParts(merged[role], seat);
|
|
336
|
-
return
|
|
375
|
+
return seatRead(parts, deps.models, seat, role).model ?? roleTierModel(role, deps.models);
|
|
337
376
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AnnouncedListingSnapshot, AnnouncedListingSnapshotInput
|
|
1
|
+
import type { AnnouncedListingSnapshot, AnnouncedListingSnapshotInput } from "../../internal/harness.js";
|
|
2
2
|
import type { AnnounceOnceSink } from "./contracts.js";
|
|
3
3
|
import type { McpDroppedTool, McpServerStatus } from "../mcp.js";
|
|
4
|
+
import type { McpUnavailableEntry } from "../mcp-failure.js";
|
|
4
5
|
import type { RunnerDeps } from "../types.js";
|
|
5
6
|
/** Upper bound on the advisory-digest arm kept in the record (oldest dropped past it). A digest is
|
|
6
7
|
* 64 hex chars; a session accumulates a handful of distinct advisories, never hundreds — the bound
|
|
@@ -75,13 +76,13 @@ export declare function flushOwedAnnouncedSnapshot(prepared: {
|
|
|
75
76
|
*/
|
|
76
77
|
export declare function settleMcpUnavailable(prepared: {
|
|
77
78
|
readonly mcpUnavailable?: {
|
|
78
|
-
pending:
|
|
79
|
+
pending: McpUnavailableEntry[];
|
|
79
80
|
};
|
|
80
81
|
readonly announcedListingsRef: AnnouncedListingSnapshotInput;
|
|
81
82
|
readonly frameReceipts: {
|
|
82
83
|
listingSnapshotOwed: boolean;
|
|
83
84
|
};
|
|
84
|
-
}, delivered: ReadonlyArray<
|
|
85
|
+
}, delivered: ReadonlyArray<McpUnavailableEntry>): void;
|
|
85
86
|
/** The run-local ledger — see the module header for the two commit disciplines it serves. */
|
|
86
87
|
export interface AnnounceOnceLedger {
|
|
87
88
|
/** The nearest announced snapshot on the branch as read at prepare (undefined = pre-entry
|
|
@@ -109,7 +110,7 @@ export interface AnnounceOnceLedger {
|
|
|
109
110
|
* bounded at intake, the reminder's own bounds) MINUS the pairs already announced on this branch.
|
|
110
111
|
* As a side effect the record's `mcpFailed` arm is pruned to the pairs that are STILL failing —
|
|
111
112
|
* a recovered server leaves the record silently. Call once per prepare. */
|
|
112
|
-
mcpFailuresToAnnounce(statuses: ReadonlyArray<McpServerStatus>):
|
|
113
|
+
mcpFailuresToAnnounce(statuses: ReadonlyArray<McpServerStatus>): McpUnavailableEntry[];
|
|
113
114
|
/** Remove, IN PLACE, the dropped-tool entries whose model-facing digest is already recorded (the
|
|
114
115
|
* frame was delivered on an earlier run of this session). The operator line about each entry is a
|
|
115
116
|
* separate digest — run that loop BEFORE pruning so both faces are judged on the full list. */
|
|
@@ -36,6 +36,7 @@ export function withAnnounceDigests(existing, add) {
|
|
|
36
36
|
}
|
|
37
37
|
return out.length > ANNOUNCE_ONCE_MAX_DIGESTS ? out.slice(out.length - ANNOUNCE_ONCE_MAX_DIGESTS) : out;
|
|
38
38
|
}
|
|
39
|
+
const toldAuthorization = (a) => `needs authorization (${a.reason}, ${createHash("sha256").update(JSON.stringify([a.reason, a.authorizeUrl ?? ""])).digest("hex").slice(0, 16)})`;
|
|
39
40
|
function sameFailure(a, b) {
|
|
40
41
|
return a.name === b.name && a.error === b.error;
|
|
41
42
|
}
|
|
@@ -49,7 +50,8 @@ export async function flushOwedAnnouncedSnapshot(prepared) {
|
|
|
49
50
|
}
|
|
50
51
|
export function settleMcpUnavailable(prepared, delivered) {
|
|
51
52
|
prepared.mcpUnavailable?.pending.splice(0, delivered.length);
|
|
52
|
-
|
|
53
|
+
const told = delivered.map(({ name, error }) => ({ name, ...(error !== undefined ? { error } : {}) }));
|
|
54
|
+
prepared.announcedListingsRef.mcpFailed = [...(prepared.announcedListingsRef.mcpFailed ?? []), ...told];
|
|
53
55
|
prepared.frameReceipts.listingSnapshotOwed = true;
|
|
54
56
|
}
|
|
55
57
|
export async function loadAnnounceOnceLedger(session, checkpointMirror, onError) {
|
|
@@ -94,7 +96,7 @@ export async function loadAnnounceOnceLedger(session, checkpointMirror, onError)
|
|
|
94
96
|
mcpFailuresToAnnounce: (statuses) => {
|
|
95
97
|
const current = statuses
|
|
96
98
|
.filter((s) => s.status === "failed")
|
|
97
|
-
.map((s) => ({ name: inlineUntrusted(s.name, 160), ...(s.error !== undefined ? { error: inlineUntrusted(s.error, 240) } : {}) }));
|
|
99
|
+
.map((s) => ({ name: inlineUntrusted(s.name, 160), ...(s.authorization !== undefined ? { error: toldAuthorization(s.authorization), authorization: { ...s.authorization } } : s.error !== undefined ? { error: inlineUntrusted(s.error, 240) } : {}) }));
|
|
98
100
|
const carried = mcpFailed.filter((r) => current.some((c) => sameFailure(c, r)));
|
|
99
101
|
if (carried.length !== mcpFailed.length)
|
|
100
102
|
dirty = true;
|
|
@@ -109,10 +109,10 @@ export function createApprovedCallScreen(input) {
|
|
|
109
109
|
const subject = `this call to "${toolName}"`;
|
|
110
110
|
const screened = await screening.screen(args, subject);
|
|
111
111
|
if (screened.kind === "refused")
|
|
112
|
-
return { refused: screened.reason };
|
|
112
|
+
return { refused: screened.reason, ...(screened.extension !== undefined ? { extension: screened.extension } : {}) };
|
|
113
113
|
const r = screened.answer;
|
|
114
114
|
if (r?.action === "deny")
|
|
115
|
-
return { refused: screening.deniedReason(r) };
|
|
115
|
+
return { refused: screening.deniedReason(r), ...(screened.answeredBy !== undefined ? { extension: screened.answeredBy } : {}) };
|
|
116
116
|
if (r !== undefined && policyCannotAnswer(r, decidedBy))
|
|
117
117
|
return { refused: `a PreToolUse hook requires a person's approval for ${subject}, and this approval was the deployment's policy — not executed` };
|
|
118
118
|
const context = r?.additionalContext;
|