@sema-agent/core 7.71.1 → 7.73.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 +500 -0
- package/dist/agents/cross-session-ref.d.ts +2 -2
- package/dist/agents/cross-session-ref.js +7 -2
- package/dist/agents/inherited-tool-pool.d.ts +30 -2
- package/dist/agents/inherited-tool-pool.js +53 -7
- package/dist/agents/parked-resume-drive.d.ts +10 -0
- package/dist/agents/parked-resume-drive.js +9 -0
- package/dist/agents/retain-ledger.d.ts +3 -0
- package/dist/agents/send-message-tool.js +7 -2
- package/dist/agents/send-user-message-tool.d.ts +12 -0
- package/dist/agents/send-user-message-tool.js +67 -0
- package/dist/agents/subagent-steps.d.ts +9 -0
- package/dist/agents/subagent-steps.js +38 -0
- package/dist/agents/subagent.d.ts +2 -0
- package/dist/agents/subagent.js +47 -12
- package/dist/agents/verify.js +23 -7
- package/dist/agents/yield-adoption.js +3 -1
- package/dist/brain/anthropic.js +14 -9
- package/dist/brain/open-responses.js +4 -5
- package/dist/brain/openai.js +30 -23
- package/dist/brain/stream-engine.js +159 -151
- package/dist/core/a2a.d.ts +24 -3
- package/dist/core/a2a.js +27 -8
- package/dist/core/actions-digest.d.ts +43 -0
- package/dist/core/actions-digest.js +22 -0
- package/dist/core/agent-state.d.ts +28 -7
- package/dist/core/agent-state.js +19 -6
- package/dist/core/allow-entry.js +3 -3
- package/dist/core/approval-object.d.ts +7 -3
- package/dist/core/approval-object.js +30 -9
- package/dist/core/auto-mode.d.ts +7 -9
- package/dist/core/auto-mode.js +114 -8
- package/dist/core/checkpoint-features.d.ts +16 -5
- package/dist/core/checkpoint-features.js +35 -6
- package/dist/core/checkpoint-rekey.d.ts +1 -1
- package/dist/core/checkpoint-rekey.js +6 -1
- package/dist/core/checkpoint-requirements.d.ts +23 -3
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-row-verdict.d.ts +1 -1
- package/dist/core/checkpoint-row-verdict.js +10 -4
- package/dist/core/checkpoint-store.d.ts +24 -2
- package/dist/core/checkpoint-store.js +1 -0
- package/dist/core/child-clamp-seats.d.ts +15 -0
- package/dist/core/child-clamp-seats.js +15 -0
- package/dist/core/delegation-frames.d.ts +1 -0
- package/dist/core/delegation-frames.js +1 -1
- package/dist/core/effective-path-target.d.ts +19 -0
- package/dist/core/effective-path-target.js +95 -38
- package/dist/core/engine-capabilities.d.ts +5 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +34 -23
- package/dist/core/engine-version.js +1 -1
- package/dist/core/entries-not-applied.d.ts +19 -7
- package/dist/core/entries-not-applied.js +33 -1
- package/dist/core/file-history-store.d.ts +15 -4
- package/dist/core/file-history-store.js +53 -23
- package/dist/core/gate-fold.js +3 -1
- package/dist/core/governance-codes.d.ts +10 -1
- package/dist/core/governance-codes.js +17 -5
- package/dist/core/hooks.d.ts +3 -0
- package/dist/core/hooks.js +1 -0
- package/dist/core/host-instance.d.ts +23 -0
- package/dist/core/host-instance.js +69 -0
- package/dist/core/instruction-preview.d.ts +63 -0
- package/dist/core/instruction-preview.js +406 -0
- package/dist/core/judged-read.d.ts +57 -0
- package/dist/core/judged-read.js +1 -0
- package/dist/core/leg-budget.d.ts +26 -0
- package/dist/core/leg-budget.js +9 -0
- package/dist/core/leg-identity.d.ts +51 -1
- package/dist/core/leg-identity.js +45 -2
- package/dist/core/manager-launch-check.d.ts +48 -0
- package/dist/core/manager-launch-check.js +64 -0
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-host-seat.d.ts +5 -0
- package/dist/core/mcp-host-seat.js +7 -1
- package/dist/core/mcp-injection-drop.d.ts +20 -10
- package/dist/core/mcp-injection-drop.js +9 -3
- package/dist/core/mcp-server-spec.d.ts +2 -1
- package/dist/core/mcp.js +3 -1
- package/dist/core/member-outcome.d.ts +3 -2
- package/dist/core/member-outcome.js +1 -1
- package/dist/core/memory-engine/deletion-record.d.ts +46 -0
- package/dist/core/memory-engine/deletion-record.js +96 -0
- package/dist/core/memory-engine/engine.js +24 -16
- package/dist/core/memory-engine/file-backend.js +7 -5
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/index.js +1 -1
- package/dist/core/memory-engine/layout.js +6 -4
- package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
- package/dist/core/memory-engine/projection-ledger.js +1 -1
- package/dist/core/memory-engine/scope-contract.d.ts +69 -11
- package/dist/core/memory-engine/scope-contract.js +99 -34
- package/dist/core/memory-engine/sync-client.js +26 -6
- package/dist/core/memory-engine/sync.d.ts +20 -2
- package/dist/core/memory-engine/sync.js +18 -17
- package/dist/core/mode-policy.d.ts +21 -6
- package/dist/core/mode-policy.js +15 -6
- package/dist/core/mounted-mcp.d.ts +7 -2
- package/dist/core/mounted-mcp.js +10 -1
- package/dist/core/own-property-receipt.js +11 -4
- package/dist/core/param-rule-reach.d.ts +8 -3
- package/dist/core/param-rule-reach.js +9 -1
- package/dist/core/parent-spec-seat.d.ts +13 -1
- package/dist/core/parent-spec-seat.js +18 -0
- package/dist/core/peer-registration.d.ts +52 -0
- package/dist/core/peer-registration.js +37 -0
- package/dist/core/peer-seat.d.ts +3 -1
- package/dist/core/peer-seat.js +3 -3
- package/dist/core/peer-task-store.d.ts +365 -0
- package/dist/core/peer-task-store.js +682 -0
- package/dist/core/permission-rule-consent.js +6 -11
- package/dist/core/permission-rule-model.d.ts +27 -0
- package/dist/core/permission-rule-model.js +34 -6
- package/dist/core/permission-rule-provider.d.ts +35 -33
- package/dist/core/permission-rule-provider.js +38 -295
- package/dist/core/permission-rule-store.d.ts +181 -8
- package/dist/core/permission-rule-store.js +420 -17
- package/dist/core/permission-rule-sync.js +15 -1
- package/dist/core/project-seat.d.ts +55 -0
- package/dist/core/project-seat.js +96 -0
- package/dist/core/protocol-http-auth.d.ts +3 -2
- package/dist/core/protocol-http-auth.js +26 -18
- package/dist/core/remote-env.d.ts +4 -4
- package/dist/core/retired-keys.js +1 -0
- package/dist/core/rule-offer-read.d.ts +1 -1
- package/dist/core/rule-offer-read.js +32 -4
- package/dist/core/run-ledger-seat.d.ts +66 -0
- package/dist/core/run-ledger-seat.js +70 -0
- package/dist/core/run-ledger.d.ts +332 -0
- package/dist/core/run-ledger.js +550 -0
- package/dist/core/runner/chain-mismatch.d.ts +32 -0
- package/dist/core/runner/chain-mismatch.js +29 -0
- package/dist/core/runner/changes-history.d.ts +1 -0
- package/dist/core/runner/changes-history.js +2 -2
- package/dist/core/runner/checkpoint-scope.d.ts +13 -3
- package/dist/core/runner/checkpoint-scope.js +12 -4
- package/dist/core/runner/construction-doors.js +6 -0
- package/dist/core/runner/contracts.d.ts +22 -3
- package/dist/core/runner/delegation-owner.d.ts +30 -0
- package/dist/core/runner/delegation-owner.js +20 -4
- package/dist/core/runner/file-history-restore.d.ts +3 -1
- package/dist/core/runner/file-history-restore.js +9 -6
- package/dist/core/runner/finish-reason-seat.js +4 -2
- package/dist/core/runner/leg-frame.js +3 -0
- package/dist/core/runner/loaded-skills.d.ts +2 -0
- package/dist/core/runner/loaded-skills.js +10 -0
- package/dist/core/runner/nested-memory-lane.d.ts +22 -5
- package/dist/core/runner/nested-memory-lane.js +91 -30
- package/dist/core/runner/person-path-rows.d.ts +23 -20
- package/dist/core/runner/person-path-rows.js +82 -18
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +105 -90
- package/dist/core/runner/prepare-config-doors.d.ts +1 -0
- package/dist/core/runner/prepare-config-doors.js +5 -3
- package/dist/core/runner/prepare-context-lane.js +1 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +6 -0
- package/dist/core/runner/prepare-execution-env.d.ts +3 -3
- package/dist/core/runner/prepare-file-history.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +10 -2
- package/dist/core/runner/prepare-hands-readface.js +36 -22
- package/dist/core/runner/prepare-inherited-gate.d.ts +8 -5
- package/dist/core/runner/prepare-inherited-gate.js +14 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -2
- package/dist/core/runner/prepare-memory-engine-session.js +2 -2
- package/dist/core/runner/prepare-memory.js +3 -15
- package/dist/core/runner/prepare-project-context.d.ts +1 -1
- package/dist/core/runner/prepare-project-context.js +3 -7
- package/dist/core/runner/prepare-protocol-tools.d.ts +5 -0
- package/dist/core/runner/prepare-protocol-tools.js +2 -2
- package/dist/core/runner/prepare-run-refs.d.ts +1 -1
- package/dist/core/runner/prepare-run-refs.js +3 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
- package/dist/core/runner/prepare-suspend-saga.js +4 -2
- package/dist/core/runner/prepare-task.js +50 -37
- package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
- package/dist/core/runner/prepare-turn-wiring.js +2 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -1
- package/dist/core/runner/prepare-wiring-manifest.js +8 -4
- package/dist/core/runner/read-session-changes.js +1 -1
- package/dist/core/runner/resume-apply.js +11 -5
- package/dist/core/runner/resume-checkpoint-screen.d.ts +8 -7
- package/dist/core/runner/resume-checkpoint-screen.js +7 -6
- package/dist/core/runner/resume-review-outcome.d.ts +3 -0
- package/dist/core/runner/resume-review-outcome.js +24 -1
- package/dist/core/runner/rewind-files.js +3 -2
- package/dist/core/runner/run-harness-handlers.js +3 -0
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +9 -2
- package/dist/core/runner/run-notification-lane.js +20 -1
- package/dist/core/runner/run-settle-and-teardown.js +21 -12
- package/dist/core/runner/run-stop-and-final-verify.js +6 -0
- package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
- package/dist/core/runner/runtask.d.ts +6 -2
- package/dist/core/runner/runtask.js +21 -9
- package/dist/core/runner/shell-env-withheld.d.ts +3 -2
- package/dist/core/runner/shell-env-withheld.js +1 -2
- package/dist/core/runner/stop-tail-notice.d.ts +10 -2
- package/dist/core/runner/stop-tail-notice.js +9 -2
- package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/task-start-doors.js +6 -3
- package/dist/core/runner/terminal-account.d.ts +10 -1
- package/dist/core/runner/terminal-account.js +23 -3
- package/dist/core/runner/tool-face-overlay.d.ts +2 -11
- package/dist/core/runner/tool-face-overlay.js +39 -0
- package/dist/core/runner/trim-stretch.js +7 -2
- package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
- package/dist/core/runner-deps.d.ts +13 -10
- package/dist/core/scheduler.d.ts +47 -7
- package/dist/core/scheduler.js +19 -7
- package/dist/core/secret-env.d.ts +60 -37
- package/dist/core/secret-env.js +45 -48
- package/dist/core/sensitive-path-policy.js +14 -7
- package/dist/core/session-checkout.d.ts +3 -0
- package/dist/core/session-checkout.js +1 -0
- package/dist/core/session-store.d.ts +12 -6
- package/dist/core/session-store.js +26 -6
- package/dist/core/session.d.ts +31 -8
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +17 -0
- package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
- package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
- package/dist/core/store-contracts/session-store-contract.js +87 -3
- package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
- package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
- package/dist/core/task-event.d.ts +11 -3
- package/dist/core/task-notification.d.ts +97 -10
- package/dist/core/task-notification.js +129 -5
- package/dist/core/task-registry-shared.d.ts +12 -1
- package/dist/core/task-registry-shared.js +3 -1
- package/dist/core/task-registry-workflow.d.ts +1 -1
- package/dist/core/task-registry-workflow.js +9 -1
- package/dist/core/task-registry.d.ts +39 -2
- package/dist/core/task-registry.js +76 -12
- package/dist/core/task-result.d.ts +13 -0
- package/dist/core/task-spec-members.d.ts +3 -1
- package/dist/core/task-spec-members.js +11 -3
- package/dist/core/task-spec.d.ts +57 -23
- package/dist/core/tool-catalog-entries.js +4 -0
- package/dist/core/tool-face-reader.js +1 -1
- package/dist/core/tool-face.d.ts +7 -0
- package/dist/core/tool-face.js +1 -0
- package/dist/core/tool-mount-facts.d.ts +5 -3
- package/dist/core/tool-mount-facts.js +4 -3
- package/dist/core/tool-mount-plan.d.ts +7 -3
- package/dist/core/tool-mount-plan.js +11 -5
- package/dist/core/tool-mount-static.d.ts +2 -2
- package/dist/core/tool-mount-static.js +28 -14
- package/dist/core/tool-registry.d.ts +33 -1
- package/dist/core/tool-registry.js +33 -0
- package/dist/core/tool-result-store.d.ts +19 -2
- package/dist/core/tool-result-store.js +51 -2
- package/dist/core/tool-roster.d.ts +16 -0
- package/dist/core/tool-roster.js +6 -0
- package/dist/core/tool-spec.d.ts +13 -4
- package/dist/core/tools.d.ts +6 -0
- package/dist/core/tools.js +1 -1
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +14 -7
- package/dist/core/wiring-manifest.d.ts +89 -29
- package/dist/core/wiring-manifest.js +44 -4
- package/dist/core/workflow-journal-store.d.ts +53 -10
- package/dist/core/workflow-journal-store.js +27 -4
- package/dist/core/workflow-run-store-contract.js +16 -0
- package/dist/core/workflow-run-store.d.ts +9 -7
- package/dist/core/workflow-run-store.js +4 -1
- package/dist/engine/execution-env/node-execution-env.js +3 -1
- package/dist/engine/harness/messages.d.ts +1 -1
- package/dist/engine/harness/messages.js +2 -1
- package/dist/engine/harness/types.d.ts +24 -1
- package/dist/engine/harness/types.js +10 -0
- package/dist/engine/llm/types.d.ts +5 -7
- package/dist/engine/loop/types.d.ts +2 -0
- package/dist/engine/lsp/node-lsp-manager.js +2 -1
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +15 -2
- package/dist/engine/session/session.js +35 -5
- package/dist/index.d.ts +27 -12
- package/dist/index.js +20 -8
- package/dist/orchestration/run-workflow-tool.js +40 -32
- package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
- package/dist/orchestration/workflow-park-adoption.js +47 -12
- package/dist/orchestration/workflow-stop.d.ts +128 -0
- package/dist/orchestration/workflow-stop.js +156 -0
- package/dist/orchestration/workflow.d.ts +30 -6
- package/dist/orchestration/workflow.js +117 -54
- package/dist/prompts/manager-recipe.d.ts +18 -0
- package/dist/prompts/manager-recipe.js +24 -0
- package/dist/stores/file/adoption/marker.d.ts +2 -27
- package/dist/stores/file/adoption/marker.js +12 -0
- package/dist/stores/file/index.d.ts +1 -1
- package/dist/stores/file/index.js +1 -1
- package/dist/stores/file/permission-rule-store.d.ts +3 -1
- package/dist/stores/file/permission-rule-store.js +0 -1
- package/dist/stores/file/workflow-journal-store.d.ts +16 -3
- package/dist/stores/file/workflow-journal-store.js +93 -5
- package/dist/stores/file/workflow-run-store.d.ts +1 -1
- package/dist/tools/artifact/artifact-tool.js +11 -6
- package/dist/tools/fs/file-read-check.d.ts +45 -11
- package/dist/tools/fs/file-read-check.js +200 -57
- package/dist/tools/fs/file-write-check.js +9 -3
- package/dist/tools/fs/index.d.ts +8 -7
- package/dist/tools/fs/index.js +4 -4
- package/dist/tools/fs/judged-reads.d.ts +51 -0
- package/dist/tools/fs/judged-reads.js +68 -0
- package/dist/tools/fs/read-deny-home.d.ts +1 -1
- package/dist/tools/fs/read-deny-home.js +5 -5
- package/dist/tools/fs/read-deny.d.ts +33 -8
- package/dist/tools/fs/read-deny.js +114 -25
- package/dist/tools/fs/safety.d.ts +12 -1
- package/dist/tools/fs/safety.js +16 -3
- package/dist/tools/fs/shell-read-check.d.ts +25 -5
- package/dist/tools/fs/shell-read-check.js +100 -15
- package/dist/tools/fs/shell-read-establish.d.ts +9 -0
- package/dist/tools/fs/shell-read-establish.js +34 -14
- package/dist/tools/fs/shell-read-judge.d.ts +13 -1
- package/dist/tools/fs/shell-read-judge.js +26 -7
- package/dist/tools/fs/shell-read-plan.d.ts +5 -0
- package/dist/tools/fs/shell-read-write-targets.js +17 -9
- package/dist/tools/scheduler-store-move.d.ts +74 -0
- package/dist/tools/scheduler-store-move.js +103 -0
- package/dist/tools/scheduler-tools.d.ts +43 -29
- package/dist/tools/scheduler-tools.js +161 -118
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +173 -3
- package/wire-changes/answers/core-stores-sql@7.72.0.json +12 -0
- package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
- package/wire-changes/answers/core@7.72.0.json +84 -0
- package/wire-changes/answers/core@7.73.0.json +216 -0
- package/wire-changes/answers/mods-kernel@7.72.0.json +7 -0
- package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
- package/wire-changes/answers/primitives@7.72.0.json +6 -0
- package/wire-changes/answers/primitives@7.73.0.json +12 -0
- package/wire-changes/answers/wiki-gate@7.72.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
- package/wire-changes/core-stores-sql@7.72.0.json +215 -0
- package/wire-changes/core-stores-sql@7.73.0.json +326 -0
- package/wire-changes/core@7.72.0.json +2426 -0
- package/wire-changes/core@7.73.0.json +6480 -0
- package/wire-changes/mods-kernel@7.72.0.json +147 -0
- package/wire-changes/mods-kernel@7.73.0.json +147 -0
- package/wire-changes/primitives@7.72.0.json +143 -0
- package/wire-changes/primitives@7.73.0.json +227 -0
- package/wire-changes/wiki-gate@7.72.0.json +145 -0
- package/wire-changes/wiki-gate@7.73.0.json +145 -0
|
@@ -150,15 +150,80 @@ function denyTargetViews(canonicalKey, lexicalView, opts) {
|
|
|
150
150
|
views.push({ path: hop, kind: "hop" });
|
|
151
151
|
return { views };
|
|
152
152
|
}
|
|
153
|
-
export function compileWriteDeny(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
153
|
+
export function compileWriteDeny(table) {
|
|
154
|
+
if (table === null || typeof table !== "object" || !Array.isArray(table.tableRows)) {
|
|
155
|
+
throw new TypeError("compileWriteDeny: expected a table compiled by compileReadDeny (missing tableRows) — pass the compiled table, not a separate rule list.");
|
|
156
|
+
}
|
|
157
|
+
let cachedSource;
|
|
158
|
+
let cached;
|
|
159
|
+
const projected = () => {
|
|
160
|
+
const source = table.tableRows;
|
|
161
|
+
if (!Array.isArray(source)) {
|
|
162
|
+
throw new TypeError("compileWriteDeny: the table carries no compiled tableRows to project.");
|
|
163
|
+
}
|
|
164
|
+
if (cached === undefined || cachedSource !== source) {
|
|
165
|
+
const rows = source.filter((r) => r.faces.includes("write"));
|
|
166
|
+
const ruleRows = [];
|
|
167
|
+
const writeSegments = [];
|
|
168
|
+
for (const r of rows) {
|
|
169
|
+
if ("rule" in r)
|
|
170
|
+
ruleRows.push(r.rule);
|
|
171
|
+
else if ("compiledSegment" in r)
|
|
172
|
+
writeSegments.push(r.compiledSegment);
|
|
173
|
+
}
|
|
174
|
+
const readRows = new Set(rows.filter((r) => r.faces.includes("read")).map((r) => r.name));
|
|
175
|
+
cachedSource = source;
|
|
176
|
+
cached = { rows, ruleRows, writeSegments, readRows };
|
|
177
|
+
}
|
|
178
|
+
return cached;
|
|
160
179
|
};
|
|
161
|
-
|
|
180
|
+
projected();
|
|
181
|
+
return {
|
|
182
|
+
face: "write",
|
|
183
|
+
get hasRows() {
|
|
184
|
+
return projected().rows.length > 0;
|
|
185
|
+
},
|
|
186
|
+
get ruleRows() {
|
|
187
|
+
return projected().ruleRows;
|
|
188
|
+
},
|
|
189
|
+
matchPath: (path) => {
|
|
190
|
+
const hit = denyTableHit(projected().rows, { views: [{ path, kind: "lexical" }] });
|
|
191
|
+
return hit === null ? null : { pattern: hit.pattern };
|
|
192
|
+
},
|
|
193
|
+
matchTarget: (canonicalKey, lexicalView, opts) => denyTableHit(projected().rows, denyTargetViews(canonicalKey, lexicalView, opts)),
|
|
194
|
+
guardsReads: (pattern) => projected().readRows.has(pattern),
|
|
195
|
+
rowUnderRoot: (scope) => {
|
|
196
|
+
const { writeSegments } = projected();
|
|
197
|
+
if (writeSegments.length === 0 || !isAbsoluteForFamily("own", scope))
|
|
198
|
+
return null;
|
|
199
|
+
return rowNamedByRootOf(writeSegments, normalizeAbsPathLexically(scope));
|
|
200
|
+
},
|
|
201
|
+
rowAtOrBelow: (path) => {
|
|
202
|
+
const { writeSegments, ruleRows } = projected();
|
|
203
|
+
const hit = rowAtOrBelowOf(writeSegments, path);
|
|
204
|
+
if (hit !== null)
|
|
205
|
+
return { pattern: hit };
|
|
206
|
+
return ruleRows.length === 0 ? null : { pattern: ruleRows[0].rule };
|
|
207
|
+
},
|
|
208
|
+
get unanchoredRows() {
|
|
209
|
+
return projected().writeSegments.filter(unanchoredRow).map((pat) => pat.raw);
|
|
210
|
+
},
|
|
211
|
+
rowLedByName: (name) => rowLedByNameOf(projected().writeSegments, name),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function unanchoredRow(pat) {
|
|
215
|
+
return pat.anchors === undefined && pat.rootedOnly !== true;
|
|
216
|
+
}
|
|
217
|
+
function rowLedByNameOf(rows, name) {
|
|
218
|
+
const readings = foldedViewsOf([[name]]);
|
|
219
|
+
for (const pat of rows) {
|
|
220
|
+
if (!unanchoredRow(pat))
|
|
221
|
+
continue;
|
|
222
|
+
const lead = pat.segments.find((s) => !s.anything);
|
|
223
|
+
if (lead === undefined || readings(pat.fold).some((view) => lead.test(view[0])))
|
|
224
|
+
return pat.raw;
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
162
227
|
}
|
|
163
228
|
export function seatForCall(seat, toolCallId) {
|
|
164
229
|
const forCall = seat?.forCall;
|
|
@@ -196,21 +261,34 @@ export function readDenyRefusal(finding) {
|
|
|
196
261
|
const write = finding.face === "write";
|
|
197
262
|
const canonicalNote = finding.canonical !== undefined && finding.canonical !== finding.target ? `(canonical target: "${fitMiddle(finding.canonical, READ_DENY_SENTENCE_PART_MAX)}") ` : "";
|
|
198
263
|
const lexicalHit = finding.matchedView !== undefined && finding.matchedView !== (finding.canonical ?? finding.target);
|
|
199
|
-
const under = finding.under === true
|
|
200
|
-
const frame = `${finding.action ?? (under ? "searching below" : write ? "writing" : "reading")} "${fitMiddle(finding.target, READ_DENY_SENTENCE_PART_MAX)}" ${canonicalNote}is refused:`;
|
|
264
|
+
const under = finding.under === true;
|
|
265
|
+
const frame = `${finding.action ?? (under && !write ? "searching below" : write ? "writing" : "reading")} "${fitMiddle(finding.target, READ_DENY_SENTENCE_PART_MAX)}" ${canonicalNote}is refused:`;
|
|
201
266
|
const pattern = fitMiddle(finding.pattern, READ_DENY_SENTENCE_PART_MAX);
|
|
202
267
|
const echoed = Object.freeze([
|
|
203
268
|
Object.freeze({ kind: "path", value: finding.target, ...(finding.canonical !== undefined && finding.canonical !== finding.target ? { canonical: finding.canonical } : {}) }),
|
|
204
269
|
...(lexicalHit ? [Object.freeze({ kind: "path", value: finding.matchedView })] : []),
|
|
205
270
|
Object.freeze({ kind: "pattern", value: finding.pattern }),
|
|
206
271
|
]);
|
|
272
|
+
if (write && finding.lookup !== undefined) {
|
|
273
|
+
const row = finding.readRow === true ? `the read deny row "${pattern}"` : sensitivePathDenyList(pattern, "write");
|
|
274
|
+
const found = finding.lookup.found;
|
|
275
|
+
const held = `it holds "${fitMiddle(found, READ_DENY_SENTENCE_PART_MAX)}", a name ${row} starts with, and a recursive removal removes everything below it`;
|
|
276
|
+
const quoted = [echoed[0], Object.freeze({ kind: "path", value: found }), echoed.at(-1)];
|
|
277
|
+
return { sentence: `${frame} ${held}. ${finding.readRow === true ? READ_ROW_WRITE_SCOPE : WRITE_DENY_SCOPE}`, echoed: Object.freeze(quoted) };
|
|
278
|
+
}
|
|
207
279
|
if (write && finding.readRow === true) {
|
|
208
|
-
const reaches =
|
|
280
|
+
const reaches = under
|
|
281
|
+
? lexicalHit
|
|
282
|
+
? `the requested path's spelling ("${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}") holds a location the read deny row "${pattern}" denies reading`
|
|
283
|
+
: `that path holds a location the read deny row "${pattern}" denies reading`
|
|
284
|
+
: lexicalHit
|
|
285
|
+
? `the path passes through "${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}", which the read deny row "${pattern}" denies reading`
|
|
286
|
+
: `the target is a path the read deny row "${pattern}" denies reading`;
|
|
209
287
|
return { sentence: `${frame} ${reaches} — a path whose reads are denied is not written either. ${READ_ROW_WRITE_SCOPE}`, echoed };
|
|
210
288
|
}
|
|
211
289
|
if (under) {
|
|
212
290
|
const holder = lexicalHit ? `the requested path's spelling ("${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}")` : "that path";
|
|
213
|
-
return { sentence: `${frame} ${holder} holds a location on ${sensitivePathDenyList(pattern)} — locations are checked, not which files exist, so no such file need be there. ${SENSITIVE_PATH_DENY_SCOPE}`, echoed };
|
|
291
|
+
return { sentence: `${frame} ${holder} holds a location on ${sensitivePathDenyList(pattern, write ? "write" : "read")} — locations are checked, not which files exist, so no such file need be there. ${write ? WRITE_DENY_SCOPE : SENSITIVE_PATH_DENY_SCOPE}`, echoed };
|
|
214
292
|
}
|
|
215
293
|
const judged = lexicalHit ? `the requested path's spelling ("${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}") matches` : "the target matches";
|
|
216
294
|
return { sentence: `${frame} ${judged} ${sensitivePathDenyList(pattern, write ? "write" : "read")}. ${write ? WRITE_DENY_SCOPE : SENSITIVE_PATH_DENY_SCOPE}`, echoed };
|
|
@@ -618,8 +696,9 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
|
|
|
618
696
|
const ruleRows = rules.filter((r) => r.faces.includes("read"));
|
|
619
697
|
const normalized = [];
|
|
620
698
|
const seen = new Set();
|
|
699
|
+
const entryKey = (e) => `${e.caseSensitive ? "s" : "i"}:${e.pattern}`;
|
|
621
700
|
const push = (e) => {
|
|
622
|
-
const key =
|
|
701
|
+
const key = entryKey(e);
|
|
623
702
|
if (seen.has(key))
|
|
624
703
|
return;
|
|
625
704
|
seen.add(key);
|
|
@@ -629,14 +708,16 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
|
|
|
629
708
|
for (const row of resolveReadDenyBuiltins(builtin)) {
|
|
630
709
|
const e = normalizeEntry(row.pattern, "built-in");
|
|
631
710
|
push(e);
|
|
632
|
-
|
|
633
|
-
|
|
711
|
+
const k = entryKey(e);
|
|
712
|
+
if (!columns.has(k))
|
|
713
|
+
columns.set(k, { origin: "builtin", tier: row.tier });
|
|
634
714
|
}
|
|
635
715
|
for (const entry of additions) {
|
|
636
716
|
const e = normalizeEntry(entry, layer);
|
|
637
717
|
push(e);
|
|
638
|
-
|
|
639
|
-
|
|
718
|
+
const k = entryKey(e);
|
|
719
|
+
const prev = columns.get(k);
|
|
720
|
+
columns.set(k, { origin: "addition", ...(prev?.tier !== undefined ? { tier: prev.tier } : {}) });
|
|
640
721
|
}
|
|
641
722
|
const homeSegments = [...new Set(checkedReadDenyHomes(homes))].flatMap(homeAnchorSegments);
|
|
642
723
|
const compiled = normalized.map((e) => {
|
|
@@ -664,16 +745,23 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
|
|
|
664
745
|
return;
|
|
665
746
|
const c = compiled[i];
|
|
666
747
|
const rest = c.segments.slice(readDenyRunHead(run));
|
|
748
|
+
const key = entryKey(e);
|
|
667
749
|
for (const location of new Set(checkedReadDenyHomes(locations, "readDenyHomeLinks"))) {
|
|
668
|
-
linkedPlacements.push({ raw: e.pattern, segments: rest, fold: c.fold, anchors: homeAnchorSegments(location).map((segs) => foldSegments(c.fold, segs)), rootedOnly: true });
|
|
750
|
+
linkedPlacements.push({ pat: { raw: e.pattern, segments: rest, fold: c.fold, anchors: homeAnchorSegments(location).map((segs) => foldSegments(c.fold, segs)), rootedOnly: true }, key });
|
|
669
751
|
}
|
|
670
752
|
});
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
753
|
+
const judgedEntries = [
|
|
754
|
+
...compiled.map((pat, i) => ({ pat, key: entryKey(normalized[i]) })),
|
|
755
|
+
...linkedPlacements,
|
|
756
|
+
];
|
|
757
|
+
const judged = judgedEntries.map((x) => x.pat);
|
|
758
|
+
const segmentRows = judgedEntries.map(({ pat, key }) => {
|
|
759
|
+
const col = columns.get(key) ?? { origin: "addition" };
|
|
760
|
+
const faces = col.origin === "addition" ? ["read", "write"] : ["read"];
|
|
761
|
+
return Object.assign(segmentGuardRow(pat, { faces, polarity: "deny", exemptible: false, fold: pat.fold === "ascii" ? "ascii" : "exact", origin: col.origin, ...(col.tier !== undefined ? { tier: col.tier } : {}) }), { compiledSegment: pat });
|
|
675
762
|
});
|
|
676
|
-
const
|
|
763
|
+
const allTableRows = Object.freeze([...segmentRows, ...rules.map(ruleGuardRow)]);
|
|
764
|
+
const readTableRows = allTableRows.filter((r) => r.faces.includes("read"));
|
|
677
765
|
const rgExclusionGlobs = [];
|
|
678
766
|
const rgProbeGlobs = [];
|
|
679
767
|
for (const row of segmentRows) {
|
|
@@ -698,20 +786,21 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
|
|
|
698
786
|
return rowNamedByRootOf(judged, normalizeAbsPathLexically(scope));
|
|
699
787
|
};
|
|
700
788
|
const matchPath = (path, opts) => {
|
|
701
|
-
const hit = denyTableHit(
|
|
789
|
+
const hit = denyTableHit(readTableRows, { views: [{ path, kind: "lexical", ...(opts?.aliasResolved === true ? { aliasResolved: true } : {}) }] });
|
|
702
790
|
return hit === null ? null : { pattern: hit.pattern };
|
|
703
791
|
};
|
|
704
792
|
const table = {
|
|
705
793
|
entries: normalized,
|
|
706
794
|
...(ruleRows.length > 0 ? { ruleRows } : {}),
|
|
707
795
|
matchPath,
|
|
708
|
-
matchTarget: (canonicalKey, lexicalView, opts) => denyTableHit(
|
|
796
|
+
matchTarget: (canonicalKey, lexicalView, opts) => denyTableHit(readTableRows, denyTargetViews(canonicalKey, lexicalView, opts)),
|
|
709
797
|
rgExclusionGlobs,
|
|
710
798
|
rgProbeGlobs,
|
|
711
799
|
unexcludableUnder,
|
|
712
800
|
rowUnderRoot,
|
|
713
801
|
rowAtOrBelow,
|
|
714
802
|
compiledSegments: Object.freeze([...judged]),
|
|
803
|
+
tableRows: allTableRows,
|
|
715
804
|
};
|
|
716
805
|
Object.defineProperty(table, "id", { value: `rdt-${randomUUID()}`, enumerable: false });
|
|
717
806
|
return table;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type DenyFace } from "./read-deny.js";
|
|
2
|
+
import type { RefusalEcho } from "../../core/refusal-echo.js";
|
|
2
3
|
import { type HomeViewSource } from "./read-deny-home.js";
|
|
3
4
|
import type { AssertAllKeysHandled } from "../../core/ask-origin.js";
|
|
4
5
|
import type { ExecutionEnv } from "../../internal/harness-types.js";
|
|
@@ -21,6 +22,12 @@ export { familyFor, foldRedundantPathSegments, isAbsoluteForFamily, isWinFormPat
|
|
|
21
22
|
* normalization is identity for it.
|
|
22
23
|
*/
|
|
23
24
|
export declare function writeTargetPath(call: ToolCallLike, pt?: ReturnType<typeof protectivePathTargetOf>): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* EVERY target a call names — the reader for a fence that may meet a declared read, in the read station's one reading
|
|
27
|
+
* ({@link declaredReadValuesOf}): a declared read slot is every non-empty string its one reading carries (never falling back
|
|
28
|
+
* to {@link writeTargetPath}); any other call is the one target {@link writeTargetPath} reads. `[]` ⇔ no resolvable path.
|
|
29
|
+
*/
|
|
30
|
+
export declare function targetPathsOf(call: ToolCallLike, pt?: ReturnType<typeof protectivePathTargetOf>): readonly string[];
|
|
24
31
|
/**
|
|
25
32
|
* The "hand" file tools' safety invariants, ported from CC's `FileEditTool`: without these a weak
|
|
26
33
|
* model blind-edits / overwrites files (a safety property, not polish). This module is the
|
|
@@ -104,10 +111,12 @@ export interface FsViolation {
|
|
|
104
111
|
/** Set ONLY on `path_not_in_root` — the containment roots in effect (primary first,
|
|
105
112
|
* then additionalDirectories), canonical form. */
|
|
106
113
|
roots?: readonly string[];
|
|
107
|
-
/** Set
|
|
114
|
+
/** Set on `read_path_denied` and `write_path_denied` — the deny-list pattern (verbatim entry text)
|
|
108
115
|
* the judged target matched. Absent on the refusal of a deny judgment that could not finish (a home view nobody could
|
|
109
116
|
* read, read-deny-home.ts `HomeView.unread`): no row matched, so none is named and no deny card is minted. */
|
|
110
117
|
pattern?: string;
|
|
118
|
+
/** The literals quoted by a deny refusal sentence, minted with the sentence ({@link readDenyRefusal}). */
|
|
119
|
+
echoed?: readonly RefusalEcho[];
|
|
111
120
|
message: string;
|
|
112
121
|
}
|
|
113
122
|
/**
|
|
@@ -126,6 +135,7 @@ export declare function isProcSensitiveFile(key: string): boolean;
|
|
|
126
135
|
export declare function holdsProcSensitiveFile(dir: string): boolean;
|
|
127
136
|
export declare function ownProcessSpelling(spelled: string): string | undefined;
|
|
128
137
|
export declare function belowOwnProcessLink(spelled: string, walks?: boolean): boolean;
|
|
138
|
+
export declare function isBareOwnDescriptorLink(spelled: string): boolean;
|
|
129
139
|
/**
|
|
130
140
|
* Expand a LEADING `~` (bare, or followed by a separator of either family) against `home`; every other
|
|
131
141
|
* spelling is returned untouched — a `~` anywhere but the front is an ordinary filename character.
|
|
@@ -494,6 +504,7 @@ export declare function violationDetails(v: FsViolation): {
|
|
|
494
504
|
code: "path_not_in_root";
|
|
495
505
|
target: string;
|
|
496
506
|
roots: readonly string[];
|
|
507
|
+
targets?: readonly string[];
|
|
497
508
|
} | ReadPathDeniedCard | undefined;
|
|
498
509
|
/** The read face's refusal card: which target, which deny pattern. */
|
|
499
510
|
export type ReadPathDeniedCard = {
|
package/dist/tools/fs/safety.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { readDenyRefusal } from "./read-deny.js";
|
|
3
3
|
import { envErrorDetail } from "./env-error-detail.js";
|
|
4
4
|
import { homeViewsOf, homeViewUnreadSentence } from "./read-deny-home.js";
|
|
5
5
|
import { skipsRootsContainment } from "./containment-face.js";
|
|
6
6
|
import { sliceHeadSafe } from "../../core/surrogate-safe-slice.js";
|
|
7
|
-
import { fileArgPath, pathTargetValue, protectivePathTargetOf } from "../../core/tool-registry.js";
|
|
7
|
+
import { declaredReadValuesOf, fileArgPath, pathTargetValue, protectivePathTargetOf } from "../../core/tool-registry.js";
|
|
8
8
|
import { readPath } from "../../core/effective-path-target.js";
|
|
9
9
|
import { familyFor, foldRedundantPathSegments, isAbsoluteForFamily, isUncSpelling, isWinFormPath, nativeSepOf, normalizeAbsPathLexically, pathFamilyOf, rejoinMissingTail, stripWin32ExtendedPrefix, win32NamespacePrefixFolded, WIN_RESERVED_RE, } from "../../core/unc-spelling.js";
|
|
10
10
|
export { familyFor, foldRedundantPathSegments, isAbsoluteForFamily, isWinFormPath, normalizeAbsPathLexically, pathFamilyOf };
|
|
@@ -17,6 +17,13 @@ export function writeTargetPath(call, pt = protectivePathTargetOf(call)) {
|
|
|
17
17
|
const notebook = typeof np === "string" && np.length > 0 ? np : undefined;
|
|
18
18
|
return fileArgPath(call.args) ?? notebook;
|
|
19
19
|
}
|
|
20
|
+
export function targetPathsOf(call, pt = protectivePathTargetOf(call)) {
|
|
21
|
+
const declared = declaredReadValuesOf(call);
|
|
22
|
+
if (declared !== undefined)
|
|
23
|
+
return declared.values.filter((e) => typeof e === "string" && e.length > 0);
|
|
24
|
+
const one = writeTargetPath(call, pt);
|
|
25
|
+
return typeof one === "string" && one.length > 0 ? [one] : [];
|
|
26
|
+
}
|
|
20
27
|
export const FRAME_TRANSMISSION_PREFIX = "attachment:";
|
|
21
28
|
export function sha256(content) {
|
|
22
29
|
return createHash("sha256").update(content, "utf8").digest("hex");
|
|
@@ -74,6 +81,10 @@ export function belowOwnProcessLink(spelled, walks = false) {
|
|
|
74
81
|
const link = OWN_PROCESS_LINK.exec(p);
|
|
75
82
|
return link !== null && (walks || /^\/[^/]/.test(p.slice(link[0].length)));
|
|
76
83
|
}
|
|
84
|
+
const BARE_OWN_DESCRIPTOR_LINK = /^\/(?:proc\/(?:self|thread-self)\/(?:task\/[^/]+\/)?fd\/\d+|dev\/fd\/\d+)\/?$/;
|
|
85
|
+
export function isBareOwnDescriptorLink(spelled) {
|
|
86
|
+
return BARE_OWN_DESCRIPTOR_LINK.test(behindOwnRootLinks(spelled).p);
|
|
87
|
+
}
|
|
77
88
|
export function expandHomeTilde(p, home) {
|
|
78
89
|
if (p === "~")
|
|
79
90
|
return home;
|
|
@@ -513,13 +524,15 @@ export async function resolveKey(env, rootCanonical, path, signal, baseCwd, addi
|
|
|
513
524
|
}
|
|
514
525
|
}
|
|
515
526
|
if (hit !== null) {
|
|
527
|
+
const refusal = readDenyRefusal({ target: path, canonical: key, pattern: hit.pattern, ...(hit.matchedView !== undefined ? { matchedView: hit.matchedView } : {}), ...(write ? { face: "write", ...(readDeny.guardsReads?.(hit.pattern) === true ? { readRow: true } : {}) } : {}) });
|
|
516
528
|
return {
|
|
517
529
|
ok: false,
|
|
518
530
|
violation: {
|
|
519
531
|
code: write ? "write_path_denied" : "read_path_denied",
|
|
520
|
-
message:
|
|
532
|
+
message: refusal.sentence,
|
|
521
533
|
target: key,
|
|
522
534
|
pattern: hit.pattern,
|
|
535
|
+
echoed: refusal.echoed,
|
|
523
536
|
},
|
|
524
537
|
};
|
|
525
538
|
}
|
|
@@ -36,14 +36,20 @@ declare function containmentDetails(paths: readonly string[]): {
|
|
|
36
36
|
};
|
|
37
37
|
/** The ONE mint of the card of a finding that established nothing: where the command reads could not be established
|
|
38
38
|
* (an unreadable or re-entered program text, a program named from its input, a station that could not answer). */
|
|
39
|
-
declare function unestablishedDetails(): {
|
|
39
|
+
export declare function unestablishedDetails(): {
|
|
40
40
|
readonly type: "read_unestablished";
|
|
41
41
|
readonly code: "read_unestablished";
|
|
42
42
|
};
|
|
43
|
+
/** The card of a declared read refused for the SHAPE of what it names (the file read station): more targets than one call may name,
|
|
44
|
+
* or a value in its slot that is not a path. The word is the reason (`code`, which `tool_end.errorCode` lifts). */
|
|
45
|
+
export declare function readTargetsRefusedDetails(code: "read_targets_over_limit" | "read_target_not_a_path"): {
|
|
46
|
+
readonly type: "read_targets_refused";
|
|
47
|
+
readonly code: "read_targets_over_limit" | "read_target_not_a_path";
|
|
48
|
+
};
|
|
43
49
|
/** The structured details a refusal or a mandated card carries: the deny card is the read faces' own (`violationDetails`,
|
|
44
50
|
* safety.ts), the containment and the unestablished cards are minted above, and a call the target refused before it started
|
|
45
51
|
* carries the shell's own card for that word ({@link targetUnavailableCard}). */
|
|
46
|
-
export type ShellReadRefusalDetails = NonNullable<ReturnType<typeof violationDetails>> | ReturnType<typeof containmentDetails> | ReturnType<typeof unestablishedDetails> | TargetUnavailableCard;
|
|
52
|
+
export type ShellReadRefusalDetails = NonNullable<ReturnType<typeof violationDetails>> | ReturnType<typeof containmentDetails> | ReturnType<typeof unestablishedDetails> | ReturnType<typeof readTargetsRefusedDetails> | TargetUnavailableCard;
|
|
47
53
|
/**
|
|
48
54
|
* What the station answers for ONE call: a VOUCH — the finding `none`, nothing beside it but the facts — or a QUESTION, a
|
|
49
55
|
* disposition the decision table gives its finding ({@link import("./shell-read-judge.js").dispositionsOfRow}). A vouch carries no
|
|
@@ -64,6 +70,7 @@ export interface ShellReadVouch extends ShellReadVerdictFacts {
|
|
|
64
70
|
readonly details?: never;
|
|
65
71
|
readonly echoed?: never;
|
|
66
72
|
readonly readRootCandidate?: never;
|
|
73
|
+
readonly cause?: never;
|
|
67
74
|
readonly unestablished?: never;
|
|
68
75
|
}
|
|
69
76
|
/** The station refuses the call or puts a question about it. */
|
|
@@ -95,6 +102,9 @@ export interface ShellReadQuestion extends ShellReadVerdictFacts {
|
|
|
95
102
|
readonly echoed?: readonly RefusalEcho[];
|
|
96
103
|
/** `mandated` on an `outside_roots` finding: the directory whose grant would clear this ask. */
|
|
97
104
|
readonly readRootCandidate?: ReadRootGrantCandidate;
|
|
105
|
+
/** A question's structured account for the card a person answers (`AskRequest.probeCause`, the park row's twin): the file read
|
|
106
|
+
* station names every target a yes admits (`roots`), as many as the call names. */
|
|
107
|
+
readonly cause?: import("../../core/checkpoint-store.js").ProbeCause;
|
|
98
108
|
/** A FACT beside the disposition: some read of the command could not be established (an `unestablishable` or `declined`
|
|
99
109
|
* finding anywhere in it, whichever finding won). A mode that releases the call releases it past the read-deny table. */
|
|
100
110
|
readonly unestablished?: true;
|
|
@@ -167,7 +177,10 @@ export interface ShellReadCheck {
|
|
|
167
177
|
readonly toolCallId?: string;
|
|
168
178
|
readonly seat?: "rejudge";
|
|
169
179
|
}): Promise<ShellReadVerdict> | null;
|
|
170
|
-
|
|
180
|
+
/** `call.toolCallId`: the call the gate gave up on (a station that hands a call something on its judgment withdraws it). */
|
|
181
|
+
unanswered(call: ReadStationCall & {
|
|
182
|
+
readonly toolCallId?: string;
|
|
183
|
+
}, cause: string): ShellReadVerdict;
|
|
171
184
|
}
|
|
172
185
|
/** The call a read station judges: its wire name and the face the gate stamped (whose `names` the station reads). */
|
|
173
186
|
export type ReadStationCall = Pick<ToolCallLike, "toolName" | "face">;
|
|
@@ -235,6 +248,11 @@ export interface ShellReadStationOptions {
|
|
|
235
248
|
* questions name no directory to add — a card offering one would offer what nothing grants. Absent ⇒ offered. */
|
|
236
249
|
readonly offersReadRootGrant?: false;
|
|
237
250
|
}
|
|
251
|
+
/** The bound of ONE recursive removal's subtree search ({@link applyRemovalSearch}) — its own, shorter than the gate's outer
|
|
252
|
+
* wait (`DEFAULT_GATE_AWAIT_TIMEOUT_MS`); and the folders it lists at most. Either reached ⇒ the search did not finish: a
|
|
253
|
+
* check that did not finish, asked like any other ({@link applyRemovalSearch}). */
|
|
254
|
+
export declare const SUBTREE_SEARCH_MS = 2000;
|
|
255
|
+
export declare const SUBTREE_SEARCH_DIRS = 16384;
|
|
238
256
|
/** What a consumer hands {@link judgeShellRead}: the command as written, the environment whose filesystem
|
|
239
257
|
* answers where its words land (symlinks resolved, patterns expanded — a `NodeExecutionEnv` over a real
|
|
240
258
|
* directory is what the gate itself runs on), the boundary it is judged against, and the trust-policy seat
|
|
@@ -292,8 +310,10 @@ export interface ShellReadJudgment {
|
|
|
292
310
|
* home and the account home the account database answers once, for this call (`readDenyHomesOf`'s homes). Every home
|
|
293
311
|
* beside the declared one waits at most a short bound of its own.
|
|
294
312
|
*
|
|
295
|
-
* It carries NO deadline
|
|
296
|
-
*
|
|
313
|
+
* It carries NO deadline but one: a recursive removal's subtree search answers under its own short bound
|
|
314
|
+
* ({@link SUBTREE_SEARCH_MS}), as the extra homes above do — a search that ran out is the search's own refusal, not a
|
|
315
|
+
* silence. Bounding the judgment's other environment-facing waits and substituting a fail-closed verdict is the
|
|
316
|
+
* gate FOLD's policy on the gate's one deadline seat; the station holds no other on either entry, and a
|
|
297
317
|
* second default here would decide the same number twice and turn a slow-but-correct filesystem's true
|
|
298
318
|
* answer into a fail-closed one unasked. A consumer wanting that posture races its own deadline and reads
|
|
299
319
|
* the row the gate's fallback reads: `SHELL_READ_DECISION.unanswered[seat]`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { observeEnvironment } from "./shell-read-environment.js";
|
|
1
|
+
import { isAbsence, observeEnvironment } from "./shell-read-environment.js";
|
|
2
2
|
import { errorResult } from "../../core/tools.js";
|
|
3
3
|
import { BASH_READONLY_CONFINEMENT_NOTE, targetUnavailableCard, targetUnavailableSentence } from "./fs-shared.js";
|
|
4
4
|
import { envErrorDetail } from "./env-error-detail.js";
|
|
@@ -8,7 +8,7 @@ import { INLINE_TRUNCATION_MARK_CODEPOINTS, inlineUntrusted, PROBE_REASON_MAX }
|
|
|
8
8
|
import { NOT_AUTO_ALLOWED, declinedProgramReason } from "./bash-program-position.js";
|
|
9
9
|
import { bashClassifyDefaultAllow } from "./bash-readonly-classifier.js";
|
|
10
10
|
import { planShellReads } from "./shell-read-plan.js";
|
|
11
|
-
import { createShellReadEstablisher, establishShellReadsLexically } from "./shell-read-establish.js";
|
|
11
|
+
import { createShellReadEstablisher, establishShellReadsLexically, writtenOnLineBefore } from "./shell-read-establish.js";
|
|
12
12
|
import { readLandingsOf } from "./shell-read-identity.js";
|
|
13
13
|
import { declaredReadDenyHomes, homeViewsAt } from "./read-deny-home.js";
|
|
14
14
|
import { anyOptionWord, programArgs } from "./shell-read-write-targets.js";
|
|
@@ -23,9 +23,12 @@ import { assertNoRetiredShellReadBoundaryKeys } from "../../core/retired-keys.js
|
|
|
23
23
|
function containmentDetails(paths) {
|
|
24
24
|
return { type: "readonly_out_of_root", code: "readonly_out_of_root", paths };
|
|
25
25
|
}
|
|
26
|
-
function unestablishedDetails() {
|
|
26
|
+
export function unestablishedDetails() {
|
|
27
27
|
return { type: "read_unestablished", code: "read_unestablished" };
|
|
28
28
|
}
|
|
29
|
+
export function readTargetsRefusedDetails(code) {
|
|
30
|
+
return { type: "read_targets_refused", code };
|
|
31
|
+
}
|
|
29
32
|
function findingDetails(finding, paths) {
|
|
30
33
|
return finding === "unestablishable" || finding === "declined" || finding === "unanswered" ? unestablishedDetails() : containmentDetails(paths);
|
|
31
34
|
}
|
|
@@ -173,11 +176,7 @@ async function writeGuardsOf(judged, boundary, env, signal) {
|
|
|
173
176
|
const dest = await probe(parentOf(view));
|
|
174
177
|
return dest === undefined || dest.ok || (dest.error.code !== "not_found" && dest.error.code !== "not_directory");
|
|
175
178
|
};
|
|
176
|
-
const changedBefore = (view, at) =>
|
|
177
|
-
const fold = (p) => p.normalize("NFC").toLowerCase();
|
|
178
|
-
const dir = fold(parentOf(view));
|
|
179
|
-
return writtenBy.some((paths, i) => i !== at && (i < at || concurrent) && paths.some((w) => withinAnyRoot([fold(w)], dir) || withinAnyRoot([dir], fold(w))));
|
|
180
|
-
};
|
|
179
|
+
const changedBefore = (view, at) => writtenOnLineBefore(writtenBy, at, concurrent, parentOf(view));
|
|
181
180
|
const answer = async (view, key) => (await judge(view, { fs: env, ...(signal !== undefined ? { signal } : {}), ...(key ? { canonical: true } : {}) })) ?? "clear";
|
|
182
181
|
const asked = [...[...asKey].map(([view, v]) => [view, v, true]), ...[...asSpelling].filter(([view]) => !landingKeys.has(view)).map(([view, v]) => [view, v, false])];
|
|
183
182
|
const slotOf = (view, key) => `${key || landingKeys.has(view) ? "key" : "spelling"}\u0000${view}`;
|
|
@@ -364,8 +363,8 @@ function refusalOf(tool, fold, boundary, paths) {
|
|
|
364
363
|
if (fold.finding === "deny_hit" && w?.deny !== undefined) {
|
|
365
364
|
const target = w.read.target ?? w.deny.matchedView;
|
|
366
365
|
const write = w.deny.face === "write";
|
|
367
|
-
const under =
|
|
368
|
-
const { sentence: core, echoed } = readDenyRefusal({ target, pattern: w.deny.pattern, matchedView: w.deny.matchedView, ...(write ? { face: "write" } : {}), ...(w.deny.readRow === true ? { readRow: true } : {}), ...(under ? { under: true } : {}) });
|
|
366
|
+
const under = w.deny.under === true;
|
|
367
|
+
const { sentence: core, echoed } = readDenyRefusal({ target, pattern: w.deny.pattern, matchedView: w.deny.matchedView, ...(write ? { face: "write" } : {}), ...(w.deny.readRow === true ? { readRow: true } : {}), ...(under ? { under: true } : {}), ...(w.deny.lookup !== undefined ? { lookup: w.deny.lookup, action: "removing" } : {}) });
|
|
369
368
|
const through = deniedThrough(w.read, boundary);
|
|
370
369
|
const sentence = `Error (${tool}): ${core} ${write ? writeDenyRefusalNote() : under ? DENY_UNDER_REFUSAL_NOTE : DENY_REFUSAL_NOTE}${through !== undefined ? ` ${DENIED_THROUGH_NOTE[through]}` : ""}`;
|
|
371
370
|
return { sentence, echoed, ...(write ? {} : { details: violationDetails({ code: "read_path_denied", message: sentence, target, pattern: w.deny.pattern }) }) };
|
|
@@ -470,12 +469,96 @@ async function applyAlsoInside(judged, boundary) {
|
|
|
470
469
|
});
|
|
471
470
|
return rewrite(judged);
|
|
472
471
|
}
|
|
473
|
-
|
|
474
|
-
|
|
472
|
+
export const SUBTREE_SEARCH_MS = 2_000;
|
|
473
|
+
export const SUBTREE_SEARCH_DIRS = 16_384;
|
|
474
|
+
async function searchSubtree(env, root, named, signal) {
|
|
475
|
+
const stop = new AbortController();
|
|
476
|
+
const timer = setTimeout(() => stop.abort(), SUBTREE_SEARCH_MS);
|
|
477
|
+
const onAbort = () => stop.abort();
|
|
478
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
479
|
+
const ended = new Promise((resolve) => stop.signal.addEventListener("abort", () => resolve("ended"), { once: true }));
|
|
480
|
+
const unfinished = (why) => ({ kind: "unfinished", why: signal?.aborted === true ? "the call was cancelled" : why });
|
|
481
|
+
const outOfTime = `the search ran past its ${SUBTREE_SEARCH_MS / 1000} s bound`;
|
|
482
|
+
try {
|
|
483
|
+
if (signal?.aborted === true)
|
|
484
|
+
return unfinished("");
|
|
485
|
+
const top = await Promise.race([env.fileInfo(root, stop.signal), ended]);
|
|
486
|
+
if (top === "ended")
|
|
487
|
+
return unfinished(outOfTime);
|
|
488
|
+
if (!top.ok)
|
|
489
|
+
return isAbsence(top.error.code) ? { kind: "clear" } : unfinished(`it could not be inspected (${top.error.code})`);
|
|
490
|
+
if (top.value.kind !== "directory")
|
|
491
|
+
return { kind: "clear" };
|
|
492
|
+
const queue = [root];
|
|
493
|
+
for (let listed = 0; queue.length > 0; listed++) {
|
|
494
|
+
if (listed >= SUBTREE_SEARCH_DIRS)
|
|
495
|
+
return unfinished(`it holds more than ${SUBTREE_SEARCH_DIRS} folders`);
|
|
496
|
+
const dir = queue.shift();
|
|
497
|
+
const entries = await Promise.race([env.listDir(dir, stop.signal), ended]);
|
|
498
|
+
if (entries === "ended")
|
|
499
|
+
return unfinished(outOfTime);
|
|
500
|
+
if (!entries.ok) {
|
|
501
|
+
if (isAbsence(entries.error.code))
|
|
502
|
+
continue;
|
|
503
|
+
return unfinished(`"${dir}" could not be listed (${entries.error.code})`);
|
|
504
|
+
}
|
|
505
|
+
for (const entry of entries.value) {
|
|
506
|
+
const at = `${dir.replace(/[\\/]+$/, "")}/${entry.name}`;
|
|
507
|
+
const pattern = named.ledBy(entry.name);
|
|
508
|
+
if (pattern !== null)
|
|
509
|
+
return { kind: "found", pattern, at };
|
|
510
|
+
if (entry.kind === "directory")
|
|
511
|
+
queue.push(at);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return { kind: "clear" };
|
|
515
|
+
}
|
|
516
|
+
catch {
|
|
517
|
+
return unfinished("the environment threw");
|
|
518
|
+
}
|
|
519
|
+
finally {
|
|
520
|
+
clearTimeout(timer);
|
|
521
|
+
signal?.removeEventListener("abort", onAbort);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function removesSubtree(f) {
|
|
525
|
+
const r = f.read;
|
|
526
|
+
return r.candidate.face === "write" && r.candidate.subtree === "removed" && r.written !== undefined && r.target !== undefined && (r.established === "canonical" || r.established === "expansion") && (f.kind === "none" || f.kind === "outside_roots");
|
|
527
|
+
}
|
|
528
|
+
async function applyRemovalSearch(judged, boundary, env, signal) {
|
|
529
|
+
const named = boundary.writeDenyNamed;
|
|
530
|
+
if (named === undefined || named.rows.length === 0)
|
|
531
|
+
return judged;
|
|
532
|
+
const searched = new Map();
|
|
533
|
+
const answered = new Map();
|
|
534
|
+
for (const f of allFindings(judged)) {
|
|
535
|
+
if (!removesSubtree(f))
|
|
536
|
+
continue;
|
|
537
|
+
const target = f.read.target;
|
|
538
|
+
let search = searched.get(target);
|
|
539
|
+
if (search === undefined)
|
|
540
|
+
searched.set(target, (search = searchSubtree(env, target, named, signal)));
|
|
541
|
+
const found = await search;
|
|
542
|
+
if (found.kind === "clear")
|
|
543
|
+
continue;
|
|
544
|
+
if (found.kind === "unfinished") {
|
|
545
|
+
const cause = `the folders below "${target}" could not all be searched for a name the deny rows ${named.rows.map((p) => `"${p}"`).join(", ")} start with: ${found.why}`;
|
|
546
|
+
answered.set(f, { read: { ...f.read, cause }, kind: "unanswered", denyRowUnasked: true, containment: f.containment });
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
const readRow = boundary.writeDenyGuardsReads?.(found.pattern) === true ? { readRow: true } : {};
|
|
550
|
+
answered.set(f, { ...f, kind: "deny_hit", deny: { pattern: found.pattern, matchedView: normalizeAbsPathLexically(target), face: "write", under: true, lookup: { found: found.at }, ...readRow } });
|
|
551
|
+
}
|
|
552
|
+
if (answered.size === 0)
|
|
553
|
+
return judged;
|
|
554
|
+
const rewrite = (j) => ({ ...j, segments: j.segments.map((s) => ({ ...s, findings: s.findings.map((f) => answered.get(f) ?? f), nested: s.nested.map(rewrite) })) });
|
|
555
|
+
return rewrite(judged);
|
|
556
|
+
}
|
|
557
|
+
async function runShellReadStation(tool, plan, declared, seat, establisher, env, signal) {
|
|
475
558
|
const door = observeEnvironment(env);
|
|
476
559
|
const established = await establisher.establish(plan, declared, signal, door);
|
|
477
560
|
const boundary = { ...declared, roots: established.roots };
|
|
478
|
-
const onPlan = await applyAlsoInside(judgePlan(plan, established, boundary), boundary);
|
|
561
|
+
const onPlan = await applyRemovalSearch(await applyAlsoInside(judgePlan(plan, established, boundary), boundary), boundary, env, signal);
|
|
479
562
|
const judgedNow = () => {
|
|
480
563
|
const unfinished = door.incomplete();
|
|
481
564
|
return unfinished.length > 0 ? { ...onPlan, incomplete: unfinished } : onPlan;
|
|
@@ -500,7 +583,8 @@ async function runShellReadStation(tool, command, declared, seat, readers, estab
|
|
|
500
583
|
export async function judgeShellRead(input) {
|
|
501
584
|
assertNoRetiredShellReadBoundaryKeys(input.boundary);
|
|
502
585
|
const readers = input.readers ?? new Set(bashClassifyDefaultAllow());
|
|
503
|
-
const
|
|
586
|
+
const plan = planShellReads(input.command, declarationsOf(input.boundary, readers, input.env.cdPath, input.env.receivedEnvNames));
|
|
587
|
+
const run = await runShellReadStation(input.tool ?? "Bash", plan, input.boundary, commandSeatOf(input.seat), createShellReadEstablisher(input.env, input.boundary.roots, { homeViews: homeViewsAt(input.env, input.readDenyHomes === undefined ? declaredReadDenyHomes(input.env) : checkedReadDenyHomes(input.readDenyHomes)) }), input.env, input.signal);
|
|
504
588
|
const offer = normalizeReadRootCandidate(run.verdict.readRootCandidate);
|
|
505
589
|
return {
|
|
506
590
|
plan: run.plan,
|
|
@@ -564,7 +648,8 @@ export function createShellReadStation(opts) {
|
|
|
564
648
|
return null;
|
|
565
649
|
const seat = callOpts.seat ?? opts.seatOf(member);
|
|
566
650
|
return (async () => {
|
|
567
|
-
const
|
|
651
|
+
const plan = planShellReads(command, declarationsOf(boundary, readers, opts.env.cdPath, opts.env.receivedEnvNames));
|
|
652
|
+
const run = await runShellReadStation(call.toolName, plan, boundary, seat, establisherFor(boundary.roots), opts.env, signal);
|
|
568
653
|
if (run.verdict.disposition !== "refuse" && callOpts.toolCallId !== undefined)
|
|
569
654
|
remember(callOpts.toolCallId, { toolName: member, boundary: run.boundary, established: run.established, command });
|
|
570
655
|
const verdict = opts.offersReadRootGrant === false ? withoutGrantOffer(run.verdict) : run.verdict;
|
|
@@ -92,6 +92,15 @@ export interface ShellReadEstablisher {
|
|
|
92
92
|
readonly changed: readonly EstablishedRead[];
|
|
93
93
|
}>;
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* THE order judgment of a line's writes, one for every reader of a filesystem fact taken before the line runs (the
|
|
97
|
+
* establishment's {@link JudgedCandidate.onlyIf} facts, the write guards' writability): does a run BEFORE run `at` — or beside
|
|
98
|
+
* it, where the line runs segments at once (a pipe, a background) — write on the line of `place` (that path, a path above it
|
|
99
|
+
* or one below it)? A later run cannot change what run `at` meets (`cp a b && touch b`: the copy meets the tree before the
|
|
100
|
+
* touch). `writes[i]` is what the i-th run writes. Compared with letter case and composition folded: on a filesystem that
|
|
101
|
+
* ignores them (`mkdir BOX && cp x box`) two spellings are one place, and a fold that only over-matches keeps the fact unsettled.
|
|
102
|
+
*/
|
|
103
|
+
export declare function writtenOnLineBefore(writes: readonly (readonly string[])[], at: number, concurrent: boolean, place: string): boolean;
|
|
95
104
|
/**
|
|
96
105
|
* The PURE, lexical establishment of a whole plan — what an isolated sandbox gets, and what any consumer
|
|
97
106
|
* with no environment in hand (a unit pin, a lexical pre-read) can compute. Patterns and traversal roots
|