@sema-agent/core 7.57.0 → 7.58.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 +385 -0
- package/dist/agents/subagent-steps.js +2 -4
- package/dist/brain/route-adjudicator.js +2 -1
- package/dist/core/a2a.d.ts +2 -1
- package/dist/core/a2a.js +23 -10
- package/dist/core/allow-entry.d.ts +2 -1
- package/dist/core/allow-entry.js +2 -1
- package/dist/core/ask-origin.d.ts +21 -2
- package/dist/core/ask-origin.js +5 -1
- package/dist/core/auto-compaction.d.ts +4 -0
- package/dist/core/auto-compaction.js +1 -1
- package/dist/core/auto-mode-directive.d.ts +29 -5
- package/dist/core/auto-mode-directive.js +38 -8
- package/dist/core/checkpoint-requirements.d.ts +7 -1
- package/dist/core/checkpoint-requirements.js +2 -0
- package/dist/core/checkpoint-store.d.ts +27 -11
- package/dist/core/checkpoint-store.js +13 -3
- package/dist/core/engine-notice.d.ts +1 -1
- package/dist/core/fs-write-gate-policy.d.ts +4 -2
- package/dist/core/fs-write-gate-policy.js +7 -3
- package/dist/core/gate-fold.js +6 -3
- package/dist/core/gate-lanes.js +11 -2
- package/dist/core/git-worktree-env.d.ts +53 -11
- package/dist/core/git-worktree-env.js +96 -12
- package/dist/core/hooks.d.ts +4 -1
- package/dist/core/hooks.js +12 -5
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/locked-config.d.ts +15 -1
- package/dist/core/locked-config.js +38 -2
- package/dist/core/mcp-call-meta.d.ts +66 -0
- package/dist/core/mcp-call-meta.js +103 -0
- package/dist/core/mcp-connection-pool.d.ts +3 -1
- package/dist/core/mcp-connection-pool.js +3 -1
- package/dist/core/mcp-failure.d.ts +7 -1
- package/dist/core/mcp-failure.js +10 -0
- package/dist/core/mcp-probe.d.ts +4 -0
- package/dist/core/mcp-probe.js +1 -1
- package/dist/core/mcp-server-link.d.ts +5 -2
- package/dist/core/mcp-server-spec.d.ts +46 -18
- package/dist/core/mcp-server-spec.js +1 -18
- package/dist/core/mcp.d.ts +6 -14
- package/dist/core/mcp.js +77 -37
- package/dist/core/memory-engine/scope-contract.d.ts +45 -4
- package/dist/core/memory-engine/scope-contract.js +80 -11
- package/dist/core/mode-policy.d.ts +8 -5
- package/dist/core/mode-policy.js +5 -4
- package/dist/core/mods/host.js +1 -1
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +10 -8
- package/dist/core/mods/kernel/events.d.ts +5 -1
- package/dist/core/mods/kernel/events.js +1 -1
- package/dist/core/mods/kernel/registration.d.ts +5 -1
- package/dist/core/mods/kernel/site-rules.d.ts +3 -0
- package/dist/core/mods/kernel/site-rules.js +10 -0
- package/dist/core/mods/package.d.ts +23 -0
- package/dist/core/mods/package.js +118 -0
- package/dist/core/mods/stations.d.ts +2 -2
- package/dist/core/mods/stations.js +1 -1
- package/dist/core/mods/tool-call.d.ts +5 -1
- package/dist/core/mods/tool-call.js +12 -3
- package/dist/core/path-guard-rows.d.ts +20 -0
- package/dist/core/path-guard-rows.js +11 -0
- package/dist/core/peer-seat.d.ts +186 -0
- package/dist/core/peer-seat.js +307 -0
- package/dist/core/present-plan-tool.d.ts +10 -1
- package/dist/core/present-plan-tool.js +46 -2
- package/dist/core/protocol-http-auth.d.ts +40 -29
- package/dist/core/protocol-http-auth.js +30 -32
- package/dist/core/redaction-marks.d.ts +16 -0
- package/dist/core/redaction-marks.js +16 -0
- package/dist/core/redaction-passes.js +8 -9
- package/dist/core/retention.d.ts +41 -15
- package/dist/core/retention.js +59 -12
- package/dist/core/rewrite-rejudge.d.ts +37 -0
- package/dist/core/rewrite-rejudge.js +40 -0
- package/dist/core/run-origin.d.ts +40 -0
- package/dist/core/run-origin.js +37 -0
- package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
- package/dist/core/runner/advertised-writable-dirs.js +126 -0
- package/dist/core/runner/compaction-restate.d.ts +15 -6
- package/dist/core/runner/compaction-restate.js +28 -2
- package/dist/core/runner/contracts.d.ts +13 -5
- package/dist/core/runner/gate-exit.d.ts +18 -4
- package/dist/core/runner/gate-exit.js +5 -1
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
- package/dist/core/runner/prepare-config-doors.d.ts +8 -5
- package/dist/core/runner/prepare-config-doors.js +12 -10
- package/dist/core/runner/prepare-delegation-surface.d.ts +4 -0
- package/dist/core/runner/prepare-delegation-surface.js +15 -18
- package/dist/core/runner/prepare-gate-stations.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +7 -3
- package/dist/core/runner/prepare-hands-readface.js +4 -1
- package/dist/core/runner/prepare-memory.d.ts +3 -0
- package/dist/core/runner/prepare-memory.js +19 -23
- package/dist/core/runner/prepare-policy-chain.d.ts +4 -4
- package/dist/core/runner/prepare-policy-chain.js +2 -2
- package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
- package/dist/core/runner/prepare-protocol-tools.js +3 -3
- package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
- package/dist/core/runner/prepare-suspend-saga.js +2 -1
- package/dist/core/runner/prepare-task.js +25 -12
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
- package/dist/core/runner/prepare-wiring-manifest.js +2 -2
- package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
- package/dist/core/runner/prepare-workspace-restore.js +4 -4
- package/dist/core/runner/resume-admission.js +1 -1
- package/dist/core/runner/resume-checkpoint-screen.js +2 -0
- package/dist/core/runner/run-harness-handlers.d.ts +3 -4
- package/dist/core/runner/run-harness-handlers.js +1 -8
- package/dist/core/runner/run-identity-wiring.js +1 -0
- package/dist/core/runner/run-leg.js +5 -1
- package/dist/core/runner/run-notification-lane.js +3 -0
- package/dist/core/runner/terminal-account.js +3 -3
- package/dist/core/runner/tool-end-body.js +1 -0
- package/dist/core/runner/tool-occurrence.d.ts +4 -1
- package/dist/core/runner/tool-occurrence.js +2 -1
- package/dist/core/runner/write-protection-station.d.ts +8 -2
- package/dist/core/runner/write-protection-station.js +2 -0
- package/dist/core/runner-deps.d.ts +2 -2
- package/dist/core/sensitive-path-policy.js +6 -7
- package/dist/core/session-log-transfer.d.ts +24 -0
- package/dist/core/session-log-transfer.js +166 -0
- package/dist/core/session-store.d.ts +84 -19
- package/dist/core/session-store.js +162 -24
- package/dist/core/session.d.ts +92 -1
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/steer-replay.d.ts +4 -2
- package/dist/core/steer-replay.js +2 -1
- package/dist/core/store-contracts/checkpoint-store-contract.js +17 -0
- package/dist/core/store-contracts/session-repo-contract.js +112 -5
- package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
- package/dist/core/store-contracts/session-store-contract.js +236 -2
- package/dist/core/task-event.d.ts +68 -8
- package/dist/core/task-registry-shared.d.ts +2 -1
- package/dist/core/task-spec.d.ts +37 -0
- package/dist/core/task-stream.d.ts +2 -1
- package/dist/core/terminal-cause.d.ts +1 -1
- package/dist/core/tool-catalog-entries.js +1 -0
- package/dist/core/tool-result-store.d.ts +17 -10
- package/dist/core/tool-result-store.js +3 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +0 -2
- package/dist/core/untrusted-egress.js +10 -14
- package/dist/core/wiring-manifest.d.ts +12 -3
- package/dist/core/wiring-manifest.js +4 -3
- package/dist/core/workspace-snapshot.d.ts +44 -0
- package/dist/core/workspace-snapshot.js +34 -0
- package/dist/core/write-protect.d.ts +43 -3
- package/dist/core/write-protect.js +43 -16
- package/dist/engine/execution-env/node-execution-env.js +15 -11
- package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
- package/dist/engine/harness/agent-harness.d.ts +5 -0
- package/dist/engine/harness/agent-harness.js +2 -0
- package/dist/engine/harness/types.d.ts +48 -7
- package/dist/engine/harness/types.js +5 -1
- package/dist/engine/llm/types.d.ts +12 -3
- package/dist/engine/llm/types.js +1 -1
- package/dist/engine/session/import-validate.js +3 -0
- package/dist/engine/session/memory-repo.d.ts +17 -9
- package/dist/engine/session/memory-repo.js +44 -34
- package/dist/engine/session/repo-utils.d.ts +22 -4
- package/dist/engine/session/repo-utils.js +49 -1
- package/dist/engine/session/storage-base.d.ts +10 -1
- package/dist/engine/session/storage-base.js +7 -1
- package/dist/index.d.ts +13 -6
- package/dist/index.js +10 -4
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +2 -2
- package/dist/internal/harness.js +2 -2
- package/dist/stores/file/index.d.ts +4 -1
- package/dist/stores/file/index.js +4 -1
- package/dist/stores/file/session-store.d.ts +15 -8
- package/dist/stores/file/session-store.js +28 -13
- package/dist/tools/fs/fs-write.d.ts +6 -3
- package/dist/tools/fs/fs-write.js +8 -7
- package/dist/tools/fs/index.d.ts +3 -0
- package/dist/tools/fs/index.js +1 -1
- package/dist/tools/fs/safety.js +40 -8
- package/dist/tools/fs/search.js +6 -24
- package/dist/tools/fs/shell-read-check.d.ts +8 -1
- package/dist/tools/fs/shell-read-check.js +59 -15
- package/dist/tools/fs/shell-read-establish.js +2 -1
- package/dist/tools/fs/shell-read-identity.js +1 -1
- package/dist/tools/fs/shell-read-judge.d.ts +10 -1
- package/dist/tools/worktree.d.ts +42 -15
- package/dist/tools/worktree.js +60 -32
- package/package.json +4 -2
- package/test/export-surface.snapshot.json +63 -1
- package/wire-changes/core-stores-sql@7.58.0.json +29 -0
- package/wire-changes/core@7.58.0.json +2188 -0
- package/wire-changes/mods-kernel@7.58.0.json +81 -0
- package/wire-changes/primitives@7.58.0.json +29 -0
- package/dist/primitives/credential-ref.d.ts +0 -89
- package/dist/primitives/credential-ref.js +0 -125
- package/dist/primitives/index.d.ts +0 -2
- package/dist/primitives/index.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { types } from "node:util";
|
|
2
2
|
import { delimitUntrusted, inlineUntrusted, neutralizeForFence } from "./untrusted-text.js";
|
|
3
3
|
import { egressPasses, runRedactionPasses } from "./redaction-passes.js";
|
|
4
|
+
import { REDACTION_MARK, REDACTION_MARKS, redactionMarkerSpans } from "./redaction-marks.js";
|
|
4
5
|
import { CREDENTIAL_VOCABULARY, egressPassGroups, isSensitiveRecordKey, URI_SCHEME_SOURCE } from "./credential-vocabulary.js";
|
|
5
6
|
import { isErrorLike, readMember, thrownText } from "./thrown-value.js";
|
|
6
7
|
import { sliceHeadSafe } from "./surrogate-safe-slice.js";
|
|
@@ -10,20 +11,20 @@ const BARE_USERNAME_MAX_LEN = 20;
|
|
|
10
11
|
function redactUserinfo(scheme, userinfoWithAt) {
|
|
11
12
|
const userinfo = userinfoWithAt.slice(0, -1);
|
|
12
13
|
if (CREDENTIAL_VOCABULARY.policy.urlUserinfo === "whole" || userinfo.includes("@"))
|
|
13
|
-
return `${scheme}
|
|
14
|
+
return `${scheme}${REDACTION_MARKS.credentials}@`;
|
|
14
15
|
const colonIdx = userinfo.indexOf(":");
|
|
15
16
|
if (colonIdx === -1) {
|
|
16
|
-
return userinfo.length >= BARE_USERNAME_MAX_LEN ? `${scheme}
|
|
17
|
+
return userinfo.length >= BARE_USERNAME_MAX_LEN ? `${scheme}${REDACTION_MARKS.credentials}@` : `${scheme}${userinfo}@`;
|
|
17
18
|
}
|
|
18
|
-
return `${scheme}${userinfo.slice(0, colonIdx)}
|
|
19
|
+
return `${scheme}${userinfo.slice(0, colonIdx)}:${REDACTION_MARKS.credentials}@`;
|
|
19
20
|
}
|
|
20
21
|
const SECRET_TIER_PASSES = egressPasses(egressPassGroups(CREDENTIAL_VOCABULARY), {
|
|
21
22
|
"url-credentials": (_m, scheme, userinfo) => redactUserinfo(scheme, userinfo),
|
|
22
23
|
});
|
|
23
24
|
const HOST_LEAK_PASSES = [
|
|
24
25
|
...SECRET_TIER_PASSES,
|
|
25
|
-
{ kind: "url", confidence: "medium", marker:
|
|
26
|
-
{ kind: "fs-path", confidence: "low", marker:
|
|
26
|
+
{ kind: "url", confidence: "medium", marker: REDACTION_MARKS.url, source: "untrusted-egress", re: URL_OF_ANY_PROTOCOL, replace: REDACTION_MARKS.url },
|
|
27
|
+
{ kind: "fs-path", confidence: "low", marker: REDACTION_MARKS.path, source: "untrusted-egress", re: /(?:\/[A-Za-z0-9_.-]+){2,}/g, replace: REDACTION_MARKS.path },
|
|
27
28
|
];
|
|
28
29
|
const TIER_PASSES = { "same-principal": SECRET_TIER_PASSES, human: HOST_LEAK_PASSES };
|
|
29
30
|
export function egressText(tier, text, report) {
|
|
@@ -43,7 +44,6 @@ export function redactHostLeaks(s, report) {
|
|
|
43
44
|
}
|
|
44
45
|
const VALUE_DEPTH_MAX = 32;
|
|
45
46
|
const VALUE_MEMBERS_MAX = 2_000;
|
|
46
|
-
const WHOLE = "[redacted]";
|
|
47
47
|
export function egressValue(tier, value) {
|
|
48
48
|
return foreignValue(tier, value, new Map());
|
|
49
49
|
}
|
|
@@ -78,7 +78,7 @@ function foreignValue(tier, value, snapshots) {
|
|
|
78
78
|
};
|
|
79
79
|
const member = (read, depth, name) => {
|
|
80
80
|
const out = pass(read, depth + 1, name);
|
|
81
|
-
return typeof out === "string" && isSensitiveRecordKey(name) ?
|
|
81
|
+
return typeof out === "string" && isSensitiveRecordKey(name) ? REDACTION_MARK : out;
|
|
82
82
|
};
|
|
83
83
|
const fill = (o, depth, keys, snapshot) => {
|
|
84
84
|
snapshots.set(o, snapshot);
|
|
@@ -116,7 +116,7 @@ function foreignValue(tier, value, snapshots) {
|
|
|
116
116
|
if (known !== undefined)
|
|
117
117
|
return known;
|
|
118
118
|
if (depth >= VALUE_DEPTH_MAX)
|
|
119
|
-
return
|
|
119
|
+
return REDACTION_MARK;
|
|
120
120
|
if (isErrorLike(v))
|
|
121
121
|
return errorSnapshot(v, depth);
|
|
122
122
|
const toJSON = readMember(v, "toJSON");
|
|
@@ -126,7 +126,7 @@ function foreignValue(tier, value, snapshots) {
|
|
|
126
126
|
reading = toJSON.call(v, key);
|
|
127
127
|
}
|
|
128
128
|
catch {
|
|
129
|
-
return
|
|
129
|
+
return REDACTION_MARK;
|
|
130
130
|
}
|
|
131
131
|
if (reading !== v) {
|
|
132
132
|
const out = pass(reading, depth + 1, key);
|
|
@@ -172,7 +172,7 @@ export function egressAccount(tier, value) {
|
|
|
172
172
|
if (known !== undefined)
|
|
173
173
|
return known;
|
|
174
174
|
if (depth >= VALUE_DEPTH_MAX)
|
|
175
|
-
return
|
|
175
|
+
return REDACTION_MARK;
|
|
176
176
|
const shape = plainShape(v);
|
|
177
177
|
if (shape === undefined)
|
|
178
178
|
return foreignValue(tier, v, snapshots);
|
|
@@ -214,10 +214,6 @@ export function egressAccount(tier, value) {
|
|
|
214
214
|
};
|
|
215
215
|
return pass(value, 0);
|
|
216
216
|
}
|
|
217
|
-
const REDACTION_MARKER_RE = /\[redacted(?:-(?:credentials|url|path))?\]/g;
|
|
218
|
-
export function redactionMarkerSpans(s) {
|
|
219
|
-
return [...s.matchAll(REDACTION_MARKER_RE)].map((m) => [m.index, m.index + m[0].length]);
|
|
220
|
-
}
|
|
221
217
|
function countRedactionMarkers(s) {
|
|
222
218
|
return redactionMarkerSpans(s).length;
|
|
223
219
|
}
|
|
@@ -27,6 +27,7 @@ import type { ModAdmissionRecord } from "./mods/kernel/index.js";
|
|
|
27
27
|
import type { McpDelivered, McpFailureKind, McpServerLiveness } from "./mcp-failure.js";
|
|
28
28
|
import type { WriteProtectionTargetView } from "./write-protect.js";
|
|
29
29
|
import type { OnAsk } from "./tool-policy.js";
|
|
30
|
+
import { type RunOrigin } from "./run-origin.js";
|
|
30
31
|
export type { StoreDurability };
|
|
31
32
|
/** The manifest-face projection of {@link StoreDurability}: `"declared_durable"` (the name says it —
|
|
32
33
|
* a DECLARATION relayed, not a verification) vs `"process_local"` (declared so, or fail-closed
|
|
@@ -184,9 +185,13 @@ export declare function deriveLspSeam(mounted: boolean, diagnosticsLive: boolean
|
|
|
184
185
|
*/
|
|
185
186
|
export interface WiringManifest {
|
|
186
187
|
schemaVersion: 1;
|
|
187
|
-
/** Present on EFFECTIVE (per-leg) manifests only; the static half has no leg.
|
|
188
|
+
/** Present on EFFECTIVE (per-leg) manifests only; the static half has no leg. `runOrigin`: the word of the input that
|
|
189
|
+
* opened this leg, when its host said so (the objective's `TaskSpec.runOrigin`, or the newest input a wake hands over; read
|
|
190
|
+
* once at the config doors), and on a leg a decision resumed, the checkpoint row's — absent when the host said nothing, and
|
|
191
|
+
* on a delegated child (a child is its parent's model's work). */
|
|
188
192
|
leg?: {
|
|
189
193
|
kind: WiringLegKind;
|
|
194
|
+
runOrigin?: RunOrigin;
|
|
190
195
|
};
|
|
191
196
|
/** Effective half only — the leg's team role ({@link import("../agents/team-role.js").teamRoleOf}):
|
|
192
197
|
* `lead` for a top-level leg, `teammate` for a named delegation, `none` for an unnamed one. Leg-local
|
|
@@ -358,9 +363,11 @@ export interface WiringManifest {
|
|
|
358
363
|
tools?: import("./tool-roster.js").ToolRoster;
|
|
359
364
|
/**
|
|
360
365
|
* EFFECTIVE half only: the leg's mods admission — one record per registration of the two seats, in run order: a
|
|
361
|
-
* mounted one with the patterns it actually hung (`events`), the ones it
|
|
366
|
+
* mounted one with the patterns it actually hung (`events`), the ones among them it only watches (`observe`: every
|
|
367
|
+
* handler it hung on the pattern is a watcher — a registration that only watches has `observe` equal to `events`) and the
|
|
362
368
|
* judges skipped while it was judged (`skipped`), or a refused one with who refused it and why (`refusedBy`,
|
|
363
|
-
* `reason`)
|
|
369
|
+
* `reason`); either carries the registration's `provenance` label as the host gave it (absent when none was given — no
|
|
370
|
+
* default is minted). PRESENT IFF the leg has a registration — a deployment that wires none reports nothing here and its
|
|
364
371
|
* manifest (and {@link configFingerprint}) is byte-for-byte what it was. Absence reads as "this leg carries no
|
|
365
372
|
* registration", NOT as "no extension judges this leg's calls": a delegated child can still be screened by an
|
|
366
373
|
* ancestor's chain through the gate's constraint fold. EXCLUDED from {@link configFingerprint}: the task seat is a
|
|
@@ -526,6 +533,8 @@ export interface WiringFacts {
|
|
|
526
533
|
half: "static" | "effective";
|
|
527
534
|
/** Required on the effective half; must be absent on the static half. */
|
|
528
535
|
leg?: WiringLegKind;
|
|
536
|
+
/** Effective half only, reported inside `leg` — see {@link WiringManifest.leg}. */
|
|
537
|
+
runOrigin?: RunOrigin;
|
|
529
538
|
/** Effective half only — see {@link WiringManifest.teamRole}. */
|
|
530
539
|
teamRole?: import("../agents/team-role.js").TeamRole;
|
|
531
540
|
/** Effective half only — see {@link WiringManifest.peerPresence}; copied, never aliased. */
|
|
@@ -6,6 +6,7 @@ import { resolveCheckpointStore } from "./checkpoint-store.js";
|
|
|
6
6
|
import { isLiveQuestionFace } from "./ask-question.js";
|
|
7
7
|
import { AUTO_MODE_DENY_SOURCES, isAutoModeDenySource } from "./runtime-caps.js";
|
|
8
8
|
import { describeRejectedValue } from "./tool-search-setting.js";
|
|
9
|
+
import { RUN_ORIGINS } from "./run-origin.js";
|
|
9
10
|
export const APPROVAL_REACH = Object.freeze(["none"]);
|
|
10
11
|
const APPROVAL_REACH_SET = new Set(APPROVAL_REACH);
|
|
11
12
|
export function isApprovalReach(v) {
|
|
@@ -161,8 +162,8 @@ function readSessionRulesFact(fact) {
|
|
|
161
162
|
return { childrenReadLive: fact };
|
|
162
163
|
}
|
|
163
164
|
export function deriveWiringManifest(facts) {
|
|
164
|
-
if (facts.half === "static" && facts.leg !== undefined) {
|
|
165
|
-
throw new Error("a static wiring manifest has no leg — leg identity is an effective-half fact");
|
|
165
|
+
if (facts.half === "static" && (facts.leg !== undefined || facts.runOrigin !== undefined)) {
|
|
166
|
+
throw new Error("a static wiring manifest has no leg — leg identity (its kind and its run origin) is an effective-half fact");
|
|
166
167
|
}
|
|
167
168
|
if (facts.half === "effective" && facts.leg === undefined) {
|
|
168
169
|
throw new Error("an effective wiring manifest requires its leg kind");
|
|
@@ -179,7 +180,7 @@ export function deriveWiringManifest(facts) {
|
|
|
179
180
|
: "absent";
|
|
180
181
|
const manifest = {
|
|
181
182
|
schemaVersion: 1,
|
|
182
|
-
...(facts.leg !== undefined ? { leg: { kind: facts.leg } } : {}),
|
|
183
|
+
...(facts.leg !== undefined ? { leg: { kind: facts.leg, ...(facts.runOrigin !== undefined ? { runOrigin: readWordFact(facts.runOrigin, RUN_ORIGINS, "run origin") } : {}) } } : {}),
|
|
183
184
|
ask: {
|
|
184
185
|
form: facts.askForm,
|
|
185
186
|
...(facts.askProvenance !== undefined ? { provenance: facts.askProvenance } : {}),
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHERE A LEG STANDS, as one value: the ONE projection of it ({@link workspaceSnapshotOf}) and the ONE seat
|
|
3
|
+
* that announces it on the `workspace_changed` frame ({@link createWorkspaceFrameSeat}).
|
|
4
|
+
*
|
|
5
|
+
* The seat sends the leg-start snapshot when the leg binds its sink, and afterwards a frame only when the snapshot's digest
|
|
6
|
+
* differs from the last frame it sent — the digest is the snapshot's canonical JSON, so every member the projection carries
|
|
7
|
+
* takes part in the comparison with no second list to keep in step. The fixed members (root, project, remote) are leg
|
|
8
|
+
* facts handed in at prepare; the two live ones are read off the leg's own seats at each observation (the tracked cwd, the
|
|
9
|
+
* active EnterWorktree switch), never copied.
|
|
10
|
+
*/
|
|
11
|
+
import type { ActiveWorktreeSession } from "../internal/harness-types.js";
|
|
12
|
+
import type { SessionProject } from "./memory-engine/scope-contract.js";
|
|
13
|
+
import type { TaskEvent, TaskEventIdentity } from "./task-event.js";
|
|
14
|
+
/** The frame's value — derived from the `workspace_changed` arm of the event union (one source; never a hand-copied shape). */
|
|
15
|
+
export type WorkspaceSnapshot = Omit<Extract<TaskEvent, {
|
|
16
|
+
type: "workspace_changed";
|
|
17
|
+
}>, "type" | keyof TaskEventIdentity>;
|
|
18
|
+
/** What a leg's snapshot is projected from. */
|
|
19
|
+
export interface WorkspaceFacts {
|
|
20
|
+
/** The leg's task root as its root receiving point settled it (`resolveTaskRootCanonical`). */
|
|
21
|
+
readonly root: string;
|
|
22
|
+
/** The leg's tracked logical cwd — present only where a real shell is mounted; absent ⇒ the cwd is `root`. */
|
|
23
|
+
readonly cwdRef?: {
|
|
24
|
+
readonly current: string;
|
|
25
|
+
};
|
|
26
|
+
/** The leg's EnterWorktree seat — present only where the worktree tools are mounted. */
|
|
27
|
+
readonly worktreeSessionRef?: {
|
|
28
|
+
readonly current?: ActiveWorktreeSession;
|
|
29
|
+
};
|
|
30
|
+
/** The leg's project verdict (`resolveSessionProject`); absent ⇒ the leg has no project identity. */
|
|
31
|
+
readonly project?: SessionProject;
|
|
32
|
+
/** The leg's one remoteness reading (the restore phase's, the same value `ResolvedWorkspace.remote` carries). */
|
|
33
|
+
readonly remote: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** The ONE mint of the `workspace_changed` value. */
|
|
36
|
+
export declare function workspaceSnapshotOf(facts: WorkspaceFacts): WorkspaceSnapshot;
|
|
37
|
+
/** The leg's frame seat (held on `Prepared`): the run binds its sink once, and observes after every tool that may have moved the leg. */
|
|
38
|
+
export interface WorkspaceFrameSeat {
|
|
39
|
+
/** Bind this leg's frame sink and send the leg-start snapshot through it. The first binding wins; a later one is ignored. */
|
|
40
|
+
subscribe(push: (snapshot: WorkspaceSnapshot) => void): void;
|
|
41
|
+
/** Re-project, and send iff the snapshot differs from the last one sent. Nothing is sent before the sink is bound. */
|
|
42
|
+
observe(): void;
|
|
43
|
+
}
|
|
44
|
+
export declare function createWorkspaceFrameSeat(facts: WorkspaceFacts): WorkspaceFrameSeat;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { canonicalJsonStringify } from "./canonical-json.js";
|
|
2
|
+
export function workspaceSnapshotOf(facts) {
|
|
3
|
+
const active = facts.worktreeSessionRef?.current;
|
|
4
|
+
return {
|
|
5
|
+
cwd: facts.cwdRef?.current ?? facts.root,
|
|
6
|
+
root: facts.root,
|
|
7
|
+
...(active !== undefined ? { entered: { dir: active.worktreeDir, ...(active.entered === true ? { byPath: true } : {}) } } : {}),
|
|
8
|
+
...(facts.project !== undefined ? { project: { id: facts.project.id, source: facts.project.source } } : {}),
|
|
9
|
+
remote: facts.remote,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function createWorkspaceFrameSeat(facts) {
|
|
13
|
+
let push;
|
|
14
|
+
let lastSent;
|
|
15
|
+
const send = () => {
|
|
16
|
+
if (push === undefined)
|
|
17
|
+
return;
|
|
18
|
+
const snapshot = workspaceSnapshotOf(facts);
|
|
19
|
+
const digest = canonicalJsonStringify(snapshot);
|
|
20
|
+
if (digest === lastSent)
|
|
21
|
+
return;
|
|
22
|
+
lastSent = digest;
|
|
23
|
+
push(snapshot);
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
subscribe(sink) {
|
|
27
|
+
if (push !== undefined)
|
|
28
|
+
return;
|
|
29
|
+
push = sink;
|
|
30
|
+
send();
|
|
31
|
+
},
|
|
32
|
+
observe: send,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ExecutionEnv } from "../internal/harness-types.js";
|
|
2
2
|
import type { ObservedFilesystem } from "../tools/fs/shell-read-environment.js";
|
|
3
3
|
import type { PermissionResult } from "./tool-policy.js";
|
|
4
|
+
import { type GuardHitVia } from "./path-guard-rows.js";
|
|
4
5
|
import { type ToolCallLike } from "./tool-registry.js";
|
|
5
6
|
/**
|
|
6
7
|
* How one table row matches the judged path:
|
|
@@ -106,7 +107,7 @@ export type WriteProtectionVerdict = {
|
|
|
106
107
|
} | {
|
|
107
108
|
readonly kind: "hit";
|
|
108
109
|
readonly hit: WriteProtectedHit;
|
|
109
|
-
readonly via:
|
|
110
|
+
readonly via: GuardHitVia;
|
|
110
111
|
} | {
|
|
111
112
|
readonly kind: "unresolvable";
|
|
112
113
|
readonly cause: string;
|
|
@@ -206,6 +207,27 @@ export interface WriteProtectionCompileOptions {
|
|
|
206
207
|
* cannot answer path questions), and its consumer announces once per leg rather than once per write.
|
|
207
208
|
*/
|
|
208
209
|
readonly onViewAbsent?: (absence: WriteProtectionViewAbsence) => void;
|
|
210
|
+
/**
|
|
211
|
+
* The leg's CURRENT write location when it is a managed worktree — read once per judgment; `undefined` while the leg writes
|
|
212
|
+
* a directory that is not one. Each entry is one spelling of that tree: its `root` (`<base>/.sema/worktrees/<slug>`) and the
|
|
213
|
+
* `base` checkout it was minted under; `kind: "canonical"` is the tree's canonical identity, `kind: "spelled"` the spelling
|
|
214
|
+
* the leg's cwd and spellings carry it under (the task root as given, which may reach it through an alias).
|
|
215
|
+
*
|
|
216
|
+
* THE CURRENT-TREE READING (the reference implementation's `.claude/worktrees` exemption, narrowed to the one tree this leg
|
|
217
|
+
* writes): every view of a target that lies inside the tree is judged as the SAME relative path in `base` — only the managed
|
|
218
|
+
* prefix is removed, so the base checkout's own ancestry is judged as ever, a tree's own `.sema/settings.json` or `.git` is
|
|
219
|
+
* judged as the base checkout's, and an ordinary file of the tree meets no `.sema` row. A view outside the tree (a sibling
|
|
220
|
+
* tree, any other path) is judged as it stands. Narrow by construction, because this reading exempts: containment is
|
|
221
|
+
* byte-exact (no case fold), the canonical view is compared with the canonical identity alone, and a remainder that carries a
|
|
222
|
+
* `.` or `..` segment is judged as it stands (where it lands is not decided here).
|
|
223
|
+
*/
|
|
224
|
+
readonly checkoutOf?: () => ReadonlyArray<ManagedCheckoutView> | undefined;
|
|
225
|
+
}
|
|
226
|
+
/** One spelling of the leg's current managed tree ({@link WriteProtectionCompileOptions.checkoutOf}). */
|
|
227
|
+
export interface ManagedCheckoutView {
|
|
228
|
+
readonly root: string;
|
|
229
|
+
readonly base: string;
|
|
230
|
+
readonly kind: "canonical" | "spelled";
|
|
209
231
|
}
|
|
210
232
|
/**
|
|
211
233
|
* Compile the write-protection judge for a deployment configuration. Returns `undefined` when the
|
|
@@ -223,6 +245,12 @@ export declare function compileWriteProtection(entries?: readonly WriteProtected
|
|
|
223
245
|
* ask carries that table's class) or a deployment's guarded write row (`ToolPolicy.writeGuardRows`: the target is not
|
|
224
246
|
* placed). */
|
|
225
247
|
export type WriteTargetCoverage = "protected" | "guarded";
|
|
248
|
+
/** One file of the engine's own the table does not demote: its declared spelling and the canonical key the run admitted it
|
|
249
|
+
* under (the session plan file, `TaskSpec.planFile`, as the advertised-writable seat holds it). ENGINE-INTERNAL. */
|
|
250
|
+
export interface ExemptFile {
|
|
251
|
+
readonly spelled: string;
|
|
252
|
+
readonly key: string;
|
|
253
|
+
}
|
|
226
254
|
/** The leg's write judgment, compiled once ({@link compileLegWriteJudgment}). ENGINE-INTERNAL (not re-exported from
|
|
227
255
|
* `src/index.ts`). */
|
|
228
256
|
export interface LegWriteJudgment {
|
|
@@ -236,6 +264,7 @@ export interface LegWriteJudgment {
|
|
|
236
264
|
readonly fs: ObservedFilesystem;
|
|
237
265
|
readonly signal?: AbortSignal;
|
|
238
266
|
readonly canonical?: true;
|
|
267
|
+
readonly spellingOnly?: true;
|
|
239
268
|
}) => Promise<WriteTargetCoverage | undefined>) | undefined;
|
|
240
269
|
}
|
|
241
270
|
/**
|
|
@@ -246,6 +275,7 @@ export interface LegWriteJudgment {
|
|
|
246
275
|
*/
|
|
247
276
|
export declare function compileLegWriteJudgment(entries: readonly WriteProtectedEntry[], opts: Omit<WriteProtectionCompileOptions, "dataRoot"> & {
|
|
248
277
|
readonly exemptRoots: readonly string[];
|
|
278
|
+
readonly exemptFiles?: readonly ExemptFile[];
|
|
249
279
|
readonly guardRows?: import("./tool-policy.js").ToolPolicy["writeGuardRows"];
|
|
250
280
|
}): LegWriteJudgment;
|
|
251
281
|
/**
|
|
@@ -254,8 +284,11 @@ export declare function compileLegWriteJudgment(entries: readonly WriteProtected
|
|
|
254
284
|
* · `hit` ⇒ `ask` (`safety`; no `requiresRealApproval` — one explicit look, clearable by an approver, a
|
|
255
285
|
* blanket `onAsk:"allow"`, the classifier or a matching persisted rule). The matched row NAME goes on the
|
|
256
286
|
* message (table names are deployment-validated vocabulary); the model-authored target path deliberately
|
|
257
|
-
* does not — `message` is the classifier's `askMessage`, and the approval card already shows the args.
|
|
258
|
-
*
|
|
287
|
+
* does not — `message` is the classifier's `askMessage`, and the approval card already shows the args. ONE
|
|
288
|
+
* sentence for every view: the row first, then — when the reading that met it is not the spelling — the one reach
|
|
289
|
+
* clause every guard's sentence uses ({@link guardHitReachClause}); a hit through the real target and a hit through a
|
|
290
|
+
* hop of the link chain are one fact to the classifier and the approver, so they read one sentence. The spelling
|
|
291
|
+
* view's sentence is the historical one byte for byte.
|
|
259
292
|
* · `unresolvable` ⇒ `deny` (`safety`; reason word `target_unresolved` on the sentence): where the write lands could not be
|
|
260
293
|
* determined, so this table cannot say it is not a protected path — refused in every permission mode (a refusal, not a
|
|
261
294
|
* question a mode releases), the reference's write check form ("where it leads on disk could not be determined").
|
|
@@ -270,6 +303,13 @@ export declare function writeProtectionTightenDecision(toolName: string, verdict
|
|
|
270
303
|
* it took no part.
|
|
271
304
|
*/
|
|
272
305
|
export declare function writeProtectionMandated(verdict: WriteProtectionVerdict): boolean;
|
|
306
|
+
/**
|
|
307
|
+
* WHICH of the two table classes a verdict's hit is — the one reading of `via` as the class fact, beside the mandate predicate:
|
|
308
|
+
* `spelling` ⇒ the path as written names the row (`write_protection`); `target` / `chain` ⇒ the row is met only where the path
|
|
309
|
+
* resolves on disk (`write_protection_on_disk`) — the judge reads the spelling first and answers there on a hit, so a resolved
|
|
310
|
+
* reading is the answer only for a spelling that names no row. `undefined` for a verdict that is not a hit.
|
|
311
|
+
*/
|
|
312
|
+
export declare function writeProtectionReachOf(verdict: WriteProtectionVerdict): "spelling" | "on_disk" | undefined;
|
|
273
313
|
/**
|
|
274
314
|
* The ENGINE-FILLED gate input (`ToolGateInput.writeProtectionCheck`). Returns `null` SYNCHRONOUSLY when the
|
|
275
315
|
* call is not this layer's business — not a covered write, or no resolvable target string — and otherwise
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { anchorSpelling, canonicalizeTarget, isAbsoluteForFamily, isWinFormPath, writeTargetPath, isUncPath, pathFamilyOf } from "../tools/fs/safety.js";
|
|
2
|
-
import { judgePathRows } from "./path-guard-rows.js";
|
|
1
|
+
import { anchorSpelling, canonicalizeTarget, isAbsoluteForFamily, isWinFormPath, normalizeAbsPathLexically, writeTargetPath, isUncPath, pathFamilyOf } from "../tools/fs/safety.js";
|
|
2
|
+
import { checkoutReadingOf, guardHitReachClause, guardHitVia, judgePathRows } from "./path-guard-rows.js";
|
|
3
3
|
import { protectivePathTargetOf } from "./tool-registry.js";
|
|
4
4
|
import { pathTargetBaseOf } from "./effective-path-target.js";
|
|
5
5
|
import { canonicalDataRootKeys, dataRootSpellings, relativeUnderRoot } from "./sensitive-path-policy.js";
|
|
@@ -207,6 +207,22 @@ export function spelledExemptionOf(dataRootPaths) {
|
|
|
207
207
|
return (spelling) => relativeUnderDataRoot(spelling, roots);
|
|
208
208
|
}
|
|
209
209
|
export const WRITE_PROTECTION_TARGET_VIEWS = Object.freeze(["spelling-only", "target"]);
|
|
210
|
+
function judgedInCheckout(path, checkout, kind) {
|
|
211
|
+
const reading = checkoutReadingOf(kind);
|
|
212
|
+
for (const c of checkout ?? []) {
|
|
213
|
+
if (reading === "canonical-only" && c.kind !== "canonical")
|
|
214
|
+
continue;
|
|
215
|
+
const rel = relativeUnderRoot(path, c.root);
|
|
216
|
+
if (rel === null)
|
|
217
|
+
continue;
|
|
218
|
+
if (rel.split("/").some((s) => s === "." || s === ".."))
|
|
219
|
+
return path;
|
|
220
|
+
if (rel === "")
|
|
221
|
+
return c.base;
|
|
222
|
+
return c.base.endsWith("/") ? `${c.base}${rel}` : `${c.base}/${rel}`;
|
|
223
|
+
}
|
|
224
|
+
return path;
|
|
225
|
+
}
|
|
210
226
|
export function compileWriteProtection(entries, opts) {
|
|
211
227
|
const rows = resolveWriteProtectedTable(entries);
|
|
212
228
|
if (rows.length === 0)
|
|
@@ -223,6 +239,10 @@ export function compileLegWriteJudgment(entries, opts) {
|
|
|
223
239
|
judgeWriteTarget: rows.length === 0 && guardRows === undefined
|
|
224
240
|
? undefined
|
|
225
241
|
: async (target, judgeOpts) => {
|
|
242
|
+
if (judgeOpts.spellingOnly === true) {
|
|
243
|
+
const spelled = await compiled.judgment(target, {}, undefined);
|
|
244
|
+
return spelled !== undefined && spelled.unreadable === undefined && TABLE_ROWS.has(spelled.row) ? "protected" : undefined;
|
|
245
|
+
}
|
|
226
246
|
const hit = await compiled.judgment(target, { ...(judgeOpts.signal !== undefined ? { signal: judgeOpts.signal } : {}), ...(judgeOpts.canonical === true ? { canonical: true } : {}) }, judgeOpts.fs, guardRows);
|
|
227
247
|
return hit === undefined ? undefined : hit.unreadable === undefined && TABLE_ROWS.has(hit.row) ? "protected" : "guarded";
|
|
228
248
|
},
|
|
@@ -234,6 +254,8 @@ function heldRows(cause) {
|
|
|
234
254
|
}
|
|
235
255
|
function compileWriteJudgment(rows, origin, opts) {
|
|
236
256
|
const dataRootPaths = opts.exemptRoots;
|
|
257
|
+
const exemptFileKeys = (opts.exemptFiles ?? []).map((f) => f.key);
|
|
258
|
+
const exemptFileSpellings = new Set((opts.exemptFiles ?? []).flatMap((f) => [normalizeAbsPathLexically(f.spelled), normalizeAbsPathLexically(f.key)]));
|
|
237
259
|
const spelledRemainder = spelledExemptionOf(dataRootPaths);
|
|
238
260
|
const readingMemo = new Map();
|
|
239
261
|
const readingsOf = (spelling) => {
|
|
@@ -275,9 +297,10 @@ function compileWriteJudgment(rows, origin, opts) {
|
|
|
275
297
|
return readingsOf(view.path).some((segs) => roots.some((root) => atConfigRoot(segs, root.map(foldWriteProtectSegment), tail))) ? REACHED : NOT_REACHED;
|
|
276
298
|
}, { below: opts?.agentConfigDir ?? "" }));
|
|
277
299
|
const tableAt = (canonicalRoots) => (configTails.length === 0 ? tableRows : [...tableRows, ...configRowsAt(canonicalRoots)]);
|
|
278
|
-
const spelledView = (spelled, kind) => {
|
|
279
|
-
const
|
|
280
|
-
|
|
300
|
+
const spelledView = (spelled, kind, checkout) => {
|
|
301
|
+
const judgedPath = judgedInCheckout(spelled, checkout, kind);
|
|
302
|
+
const remainder = spelledRemainder(judgedPath);
|
|
303
|
+
return { path: judgedPath, kind, ...(remainder !== null ? { exemptRemainder: remainder } : {}) };
|
|
281
304
|
};
|
|
282
305
|
const anchoredSpelling = (path, cwd) => {
|
|
283
306
|
const base = typeof cwd === "string" && cwd.length > 0 ? cwd : undefined;
|
|
@@ -307,9 +330,11 @@ function compileWriteJudgment(rows, origin, opts) {
|
|
|
307
330
|
})();
|
|
308
331
|
const givenKey = ctx.canonical === true && env !== undefined;
|
|
309
332
|
const base = ctx.base ?? ctx.cwd ?? rootPath;
|
|
310
|
-
const
|
|
333
|
+
const checkout = opts.checkoutOf?.();
|
|
334
|
+
const lexical = givenKey ? undefined : spelledView(anchoredSpelling(path, ctx.base ?? ctx.cwd), "lexical", checkout);
|
|
311
335
|
const bySpelling = lexical === undefined ? undefined : judgePathRows([...tableAt([]), ...extra], { views: [lexical] }, "tighten");
|
|
312
|
-
|
|
336
|
+
const namesExemptFile = lexical !== undefined && env !== undefined && exemptFileSpellings.has(normalizeAbsPathLexically(lexical.path));
|
|
337
|
+
if (bySpelling !== undefined && bySpelling.unreadable === undefined && TABLE_ROWS.has(bySpelling.row) && !namesExemptFile)
|
|
313
338
|
return bySpelling;
|
|
314
339
|
if (env === undefined)
|
|
315
340
|
return bySpelling;
|
|
@@ -338,11 +363,13 @@ function compileWriteJudgment(rows, origin, opts) {
|
|
|
338
363
|
const canonicalRoots = canonKey === undefined || configTails.length === 0 || opts?.agentConfigDir === undefined ? [] : (await canonicalDataRootKeys(env, [opts.agentConfigDir], ctx.signal, rootLookupFailed)).map(agentConfigDirSegments);
|
|
339
364
|
const table = [...tableAt(canonicalRoots), ...extra];
|
|
340
365
|
const aliased = canonAliased ? { aliasResolved: true } : {};
|
|
341
|
-
const views = [...(lexical !== undefined ? [{ ...lexical, ...aliased }] : []), ...(canonKey !== undefined ? [{ path: canonKey, kind: "canonical", ...aliased }] : [])];
|
|
366
|
+
const views = [...(lexical !== undefined ? [{ ...lexical, ...aliased }] : []), ...(canonKey !== undefined ? [{ path: judgedInCheckout(canonKey, checkout, "canonical"), kind: "canonical", ...aliased }] : [])];
|
|
342
367
|
const identity = {};
|
|
343
368
|
const identityRemainder = () => (identity.asked ??= (async () => {
|
|
344
369
|
if (canonKey === undefined)
|
|
345
370
|
return undefined;
|
|
371
|
+
if (exemptFileKeys.includes(canonKey))
|
|
372
|
+
return "";
|
|
346
373
|
for (const rootKey of await canonicalDataRootKeys(env, dataRootPaths, ctx.signal, rootLookupFailed)) {
|
|
347
374
|
const relative = relativeUnderRoot(canonKey, rootKey);
|
|
348
375
|
if (relative !== null)
|
|
@@ -377,7 +404,7 @@ function compileWriteJudgment(rows, origin, opts) {
|
|
|
377
404
|
targetUnread ??= chain.value.cause;
|
|
378
405
|
}
|
|
379
406
|
for (const hop of chainHopsOrNone(chain.value))
|
|
380
|
-
views.push(spelledView(hop, "hop"));
|
|
407
|
+
views.push(spelledView(hop, "hop", checkout));
|
|
381
408
|
}
|
|
382
409
|
return judged();
|
|
383
410
|
};
|
|
@@ -385,7 +412,7 @@ function compileWriteJudgment(rows, origin, opts) {
|
|
|
385
412
|
rows,
|
|
386
413
|
targetView: opts?.env === undefined ? "spelling-only" : "target",
|
|
387
414
|
matchPath(path, cwd) {
|
|
388
|
-
const hit = judgePathRows(tableAt([]), { views: [spelledView(anchoredSpelling(path, cwd), "lexical")] }, "tighten");
|
|
415
|
+
const hit = judgePathRows(tableAt([]), { views: [spelledView(anchoredSpelling(path, cwd), "lexical", opts.checkoutOf?.())] }, "tighten");
|
|
389
416
|
return hit === undefined ? null : { name: hit.row.name, kind: hit.row.kind };
|
|
390
417
|
},
|
|
391
418
|
async judge(path, ctx = {}) {
|
|
@@ -417,7 +444,7 @@ function atConfigRoot(segs, root, tail) {
|
|
|
417
444
|
return segs.length >= root.length + tail.length && root.every((a, i) => segs[i] === a) && tail.every((t, i) => segs[root.length + i] === t);
|
|
418
445
|
}
|
|
419
446
|
function verdictOf(hit) {
|
|
420
|
-
return { kind: "hit", hit: { name: hit.row.name, kind: hit.row.kind }, via: hit.viewKind
|
|
447
|
+
return { kind: "hit", hit: { name: hit.row.name, kind: hit.row.kind }, via: guardHitVia(hit.viewKind) };
|
|
421
448
|
}
|
|
422
449
|
export function writeProtectionTightenDecision(toolName, verdict) {
|
|
423
450
|
if (verdict.kind === "clear")
|
|
@@ -429,19 +456,19 @@ export function writeProtectionTightenDecision(toolName, verdict) {
|
|
|
429
456
|
decisionReason: "safety",
|
|
430
457
|
};
|
|
431
458
|
}
|
|
459
|
+
const reach = guardHitReachClause(verdict.via);
|
|
432
460
|
return {
|
|
433
461
|
action: "ask",
|
|
434
|
-
message: verdict.
|
|
435
|
-
? `tool "${toolName}" writes to a write-protected path — its real target resolves onto table entry "${verdict.hit.name}" — explicit approval required`
|
|
436
|
-
: verdict.via === "chain"
|
|
437
|
-
? `tool "${toolName}" writes to a write-protected path — its symlink chain passes through table entry "${verdict.hit.name}" — explicit approval required`
|
|
438
|
-
: `tool "${toolName}" writes to a write-protected path (table entry "${verdict.hit.name}") — explicit approval required`,
|
|
462
|
+
message: `tool "${toolName}" writes to a write-protected path (table entry "${verdict.hit.name}")${reach !== undefined ? ` — ${reach}` : ""} — explicit approval required`,
|
|
439
463
|
decisionReason: "safety",
|
|
440
464
|
};
|
|
441
465
|
}
|
|
442
466
|
export function writeProtectionMandated(verdict) {
|
|
443
467
|
return verdict.kind === "hit";
|
|
444
468
|
}
|
|
469
|
+
export function writeProtectionReachOf(verdict) {
|
|
470
|
+
return verdict.kind !== "hit" ? undefined : verdict.via === "spelling" ? "spelling" : "on_disk";
|
|
471
|
+
}
|
|
445
472
|
export function createWriteProtectionCheck(entries, opts) {
|
|
446
473
|
const matcher = compileWriteProtection(entries, opts);
|
|
447
474
|
return matcher === undefined ? undefined : writeProtectionMountOver(matcher, opts?.rootPath);
|
|
@@ -3,20 +3,22 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { closeSync, constants, createReadStream, mkdtempSync, openSync, readSync, rmSync, statSync, truncateSync, unlinkSync } from "node:fs";
|
|
4
4
|
import { access, appendFile, lstat, mkdir, mkdtemp, open, readdir, readFile, readlink, rename, rm, stat, unlink, writeFile, } from "node:fs/promises";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
|
-
import { isAbsolute, join,
|
|
6
|
+
import { dirname, isAbsolute, join, sep } from "node:path";
|
|
7
7
|
import { createInterface } from "node:readline";
|
|
8
8
|
import { ExecutionError, err, FileError, ok, toError, } from "../harness/types.js";
|
|
9
9
|
import { killProcessTree, shutdownDebug } from "./kill-tree.js";
|
|
10
10
|
import { __resetSecretEnvScrubNoticeAnnouncement, announceSecretEnvScrub, inheritEnvPolicyProblem, inheritedHostEnv } from "../../core/secret-env.js";
|
|
11
11
|
import { physicalPathOfAsync } from "../../core/physical-path.js";
|
|
12
12
|
import { posixModeBitsMeaningful } from "../../core/posix-mode-face.js";
|
|
13
|
-
import { walkSymlinkChain } from "./symlink-chain.js";
|
|
13
|
+
import { anchorAtLinkDir, walkSymlinkChain } from "./symlink-chain.js";
|
|
14
14
|
import { RollingTailBuffer, markTruncated, newStreamCursorState, sliceStreamIncrement, } from "../../core/exec-output-tail.js";
|
|
15
15
|
import { BackgroundShellError } from "../../core/background-shell.js";
|
|
16
16
|
import { SchedulerError } from "../../core/scheduler.js";
|
|
17
17
|
const MAX_TIMER_TIMEOUT_MS = 2_147_000_000;
|
|
18
18
|
function resolvePath(cwd, path) {
|
|
19
|
-
|
|
19
|
+
if (isAbsolute(path))
|
|
20
|
+
return path;
|
|
21
|
+
return anchorAtLinkDir(isAbsolute(cwd) ? cwd : anchorAtLinkDir(process.cwd(), cwd, sep), path, sep);
|
|
20
22
|
}
|
|
21
23
|
export function resolveExecTimeoutMs(timeoutSeconds) {
|
|
22
24
|
if (typeof timeoutSeconds !== "number" ||
|
|
@@ -396,7 +398,9 @@ export class NodeExecutionEnv {
|
|
|
396
398
|
return ok(resolvePath(this.cwd, path));
|
|
397
399
|
}
|
|
398
400
|
async joinPath(parts) {
|
|
399
|
-
|
|
401
|
+
const leading = sep === "\\" ? /^[\\/]+/ : /^\/+/;
|
|
402
|
+
const named = parts.map((part, i) => (i === 0 ? part : part.replace(leading, ""))).filter((part) => part !== "");
|
|
403
|
+
return ok(named.length === 0 ? "." : named.reduce((at, part) => anchorAtLinkDir(at, part, sep)));
|
|
400
404
|
}
|
|
401
405
|
async exec(command, options) {
|
|
402
406
|
if (options?.abortSignal?.aborted) {
|
|
@@ -831,7 +835,7 @@ export class NodeExecutionEnv {
|
|
|
831
835
|
return aborted;
|
|
832
836
|
}
|
|
833
837
|
try {
|
|
834
|
-
await mkdir(
|
|
838
|
+
await mkdir(dirname(resolved), { recursive: true });
|
|
835
839
|
}
|
|
836
840
|
catch (error) {
|
|
837
841
|
return err(toFileError(error, resolved));
|
|
@@ -854,8 +858,8 @@ export class NodeExecutionEnv {
|
|
|
854
858
|
let hop;
|
|
855
859
|
try {
|
|
856
860
|
const link = await readlink(resolved);
|
|
857
|
-
const parentReal = await physicalPathOfAsync(
|
|
858
|
-
hop = isAbsolute(link) ? link :
|
|
861
|
+
const parentReal = await physicalPathOfAsync(dirname(resolved)).catch(() => dirname(resolved));
|
|
862
|
+
hop = isAbsolute(link) ? link : anchorAtLinkDir(parentReal, link, sep);
|
|
859
863
|
}
|
|
860
864
|
catch {
|
|
861
865
|
hop = undefined;
|
|
@@ -956,7 +960,7 @@ export class NodeExecutionEnv {
|
|
|
956
960
|
return aborted;
|
|
957
961
|
}
|
|
958
962
|
try {
|
|
959
|
-
await mkdir(
|
|
963
|
+
await mkdir(dirname(resolved), { recursive: true });
|
|
960
964
|
}
|
|
961
965
|
catch (error) {
|
|
962
966
|
return err(toFileError(error, resolved));
|
|
@@ -979,7 +983,7 @@ export class NodeExecutionEnv {
|
|
|
979
983
|
async appendFile(path, content) {
|
|
980
984
|
const resolved = resolvePath(this.cwd, path);
|
|
981
985
|
try {
|
|
982
|
-
await mkdir(
|
|
986
|
+
await mkdir(dirname(resolved), { recursive: true });
|
|
983
987
|
await appendFile(resolved, content);
|
|
984
988
|
return ok(undefined);
|
|
985
989
|
}
|
|
@@ -1036,7 +1040,7 @@ export class NodeExecutionEnv {
|
|
|
1036
1040
|
if (loopAbort) {
|
|
1037
1041
|
return loopAbort;
|
|
1038
1042
|
}
|
|
1039
|
-
const entryPath =
|
|
1043
|
+
const entryPath = anchorAtLinkDir(resolved, entry.name, sep);
|
|
1040
1044
|
try {
|
|
1041
1045
|
const info = fileInfoFromStats(entryPath, await lstat(entryPath));
|
|
1042
1046
|
if (info.ok) {
|
|
@@ -1152,7 +1156,7 @@ export class NodeExecutionEnv {
|
|
|
1152
1156
|
const loopAbort = abortResult(abortSignal, resolved);
|
|
1153
1157
|
if (loopAbort)
|
|
1154
1158
|
return loopAbort;
|
|
1155
|
-
const info = fileInfoFromStats(
|
|
1159
|
+
const info = fileInfoFromStats(anchorAtLinkDir(resolved, entry.name, sep), await lstat(anchorAtLinkDir(listed, entry.name, sep)));
|
|
1156
1160
|
if (info.ok)
|
|
1157
1161
|
infos.push(info.value);
|
|
1158
1162
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type FileError, type Result, type SymlinkChain } from "../harness/types.js";
|
|
2
2
|
/**
|
|
3
|
-
* Anchor a RELATIVE
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* Anchor a RELATIVE spelling at a directory, UNFOLDED, with exactly one separator between the two — the one anchor of
|
|
4
|
+
* this environment: a symlink target at its link's own directory (the walk below), a path at the environment's `cwd`
|
|
5
|
+
* and a name under the directory that holds it (`NodeExecutionEnv`'s every member). A root directory (`/`, `C:\`,
|
|
6
|
+
* `\\host\share\`) already ends in its own separator, and a second one mints a spelling (`//private/tmp`) that no
|
|
7
|
+
* guarded row matches; `path.resolve`/`join` would fix the separator and fold `..`, which no reader of a path may do —
|
|
8
|
+
* a `..` is the filesystem's to resolve. `separator` is the one the caller's `dirname` writes (a pure function of its
|
|
9
|
+
* inputs); a backslash terminates only where it IS a separator — on a POSIX tree `/a/b\` is an ordinary name.
|
|
8
10
|
*/
|
|
9
11
|
export declare function anchorAtLinkDir(linkDir: string, target: string, separator: string): string;
|
|
10
12
|
/** The walk's bound (the reference CLI's own); the terminal canonicalizer refuses at 16, so this only bounds what is REPORTED. */
|
|
@@ -4,6 +4,7 @@ import { runToolCall, type ExecutedToolCallOutcome } from "../loop/agent-loop.js
|
|
|
4
4
|
import type { HaltRemainingDirective } from "../loop/types.js";
|
|
5
5
|
import type { AgentMessage, AgentTool, AgentToolCall, LoopMalformedToolUseRecovery, LoopThinkingOnlyRecovery, LoopTruncatedOutputRecovery, QueueMode, ThinkingLevel } from "../loop/types.js";
|
|
6
6
|
import { type EngineSegment } from "../../core/untrusted-text.js";
|
|
7
|
+
import { type RunOrigin } from "../../core/run-origin.js";
|
|
7
8
|
import type { CommittedFrameCarrier } from "../../core/frame-settlement.js";
|
|
8
9
|
import type { AbortResult, AgentHarnessEvent, AgentHarnessEventResultMap, AgentHarnessOptions, AgentHarnessOwnEvent, AgentHarnessResources, AgentHarnessStreamOptions, ExecutionEnv, PromptTemplate, Skill } from "./types.js";
|
|
9
10
|
/** [c209-C] 收口 C1/C2 — engine-provenance metadata a caller can stamp on the user message it
|
|
@@ -85,6 +86,10 @@ export interface UserMessageProvenance {
|
|
|
85
86
|
* projection point `projectHumanInput`) BEFORE the frame wrapping — the harness never rewrites
|
|
86
87
|
* text, so annotation stays adjacent to the frame it attributes. */
|
|
87
88
|
actor?: ActorAssertion;
|
|
89
|
+
/** What brought the one input this message carries ({@link UserMessage.runOrigin}) — the caller passes it with a message
|
|
90
|
+
* that carries a single input only. Threaded onto the message when it is a member of the closed set; anything else is
|
|
91
|
+
* omitted at the mint. */
|
|
92
|
+
runOrigin?: RunOrigin;
|
|
88
93
|
/** backlog #389 — an OPAQUE record the caller rides on a CALLER-AUTHORED queued frame so a durable
|
|
89
94
|
* park can carry the instruction across the suspend instead of losing it. Same sidecar posture as
|
|
90
95
|
* {@link UserMessageProvenance.enginePayload} (a WeakMap entry, never a message field, never
|
|
@@ -3,6 +3,7 @@ import { finalizeToolOutcome, isBatchSafeToolCall, runAgentLoop, runToolCall } f
|
|
|
3
3
|
import { resolveAgentCoreStreamFn } from "../loop/runtime-deps.js";
|
|
4
4
|
import { normalizeEngineSegments } from "../../core/untrusted-text.js";
|
|
5
5
|
import { isCredentialHeaderName } from "../../core/secret-env.js";
|
|
6
|
+
import { isRunOrigin } from "../../core/run-origin.js";
|
|
6
7
|
import { isProviderEchoShape } from "../../brain/errors.js";
|
|
7
8
|
import { convertToLlm } from "./messages.js";
|
|
8
9
|
import { readMember, thrownText } from "../../core/thrown-value.js";
|
|
@@ -37,6 +38,7 @@ function createUserMessage(text, images, provenance) {
|
|
|
37
38
|
typeof provenance.actor.hostAsserted === "boolean"
|
|
38
39
|
? { actor: snapshotActorAssertion(provenance.actor) }
|
|
39
40
|
: {}),
|
|
41
|
+
...((runOrigin) => (isRunOrigin(runOrigin) ? { runOrigin } : {}))(provenance?.runOrigin),
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
function createTrailingMessage(seed) {
|