@sema-agent/core 7.72.0 → 7.74.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 +565 -0
- package/dist/agents/inherited-tool-pool.d.ts +26 -1
- package/dist/agents/inherited-tool-pool.js +46 -2
- package/dist/agents/list-agents-tool.js +1 -1
- 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/retain-ledger.js +3 -3
- package/dist/agents/send-message-tool.js +5 -4
- 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 +43 -12
- package/dist/agents/verify.js +23 -8
- package/dist/agents/yield-adoption.js +3 -1
- package/dist/brain/anthropic.d.ts +42 -1
- package/dist/brain/anthropic.js +68 -13
- package/dist/brain/failover.d.ts +5 -0
- package/dist/brain/failover.js +51 -22
- package/dist/brain/model-lane.d.ts +12 -3
- package/dist/brain/model-lane.js +5 -5
- package/dist/brain/open-responses.js +7 -8
- package/dist/brain/openai.js +31 -24
- package/dist/brain/route-adjudicator.d.ts +33 -4
- package/dist/brain/route-adjudicator.js +49 -12
- package/dist/brain/stream-engine.js +166 -156
- package/dist/brain/stream-shared.d.ts +4 -3
- package/dist/brain/stream-shared.js +2 -2
- package/dist/core/actions-digest.d.ts +43 -0
- package/dist/core/actions-digest.js +22 -0
- package/dist/core/allow-entry.js +4 -4
- package/dist/core/ask-class.d.ts +2 -2
- package/dist/core/ask-headline.d.ts +1 -1
- package/dist/core/ask-origin.d.ts +44 -4
- package/dist/core/ask-origin.js +29 -10
- package/dist/core/auto-mode.d.ts +7 -9
- package/dist/core/auto-mode.js +114 -8
- package/dist/core/background-agent-store.d.ts +1 -0
- package/dist/core/background-agent-store.js +49 -8
- package/dist/core/checkpoint-features.d.ts +3 -2
- package/dist/core/checkpoint-features.js +1 -1
- 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 +9 -3
- package/dist/core/checkpoint-store.d.ts +26 -2
- package/dist/core/checkpoint-store.js +9 -2
- package/dist/core/child-clamp-seats.d.ts +15 -0
- package/dist/core/child-clamp-seats.js +15 -0
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +1 -0
- package/dist/core/cron.js +9 -1
- package/dist/core/delegation-frames.d.ts +1 -0
- package/dist/core/delegation-frames.js +1 -1
- package/dist/core/deployment-shape.d.ts +7 -0
- package/dist/core/deployment-shape.js +19 -0
- package/dist/core/engine-capabilities.d.ts +13 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +41 -28
- 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/gate-fold.js +5 -4
- package/dist/core/gate-lanes.js +8 -12
- package/dist/core/gate-outcome.d.ts +8 -2
- package/dist/core/gate-outcome.js +10 -3
- package/dist/core/governance-codes.d.ts +14 -2
- package/dist/core/governance-codes.js +22 -6
- package/dist/core/hook-condition.d.ts +37 -0
- package/dist/core/hook-condition.js +567 -0
- package/dist/core/hooks.d.ts +5 -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/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-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/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/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 +18 -13
- package/dist/core/memory-engine/scope-contract.js +18 -18
- 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 +25 -6
- package/dist/core/mode-policy.js +33 -8
- package/dist/core/model-seat.d.ts +8 -5
- package/dist/core/model-shell.d.ts +129 -0
- package/dist/core/model-shell.js +249 -0
- package/dist/core/mods/kernel/digest.d.ts +4 -0
- package/dist/core/mods/kernel/digest.js +5 -0
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +15 -6
- package/dist/core/mods/kernel/events.d.ts +21 -5
- package/dist/core/mods/kernel/events.js +19 -10
- package/dist/core/mods/kernel/hash-mirror.d.ts +1 -0
- package/dist/core/mods/kernel/hash-mirror.js +55 -0
- package/dist/core/mods/kernel/index.d.ts +1 -0
- package/dist/core/mods/kernel/index.js +1 -0
- package/dist/core/mods/kernel/package-reader.d.ts +48 -0
- package/dist/core/mods/kernel/package-reader.js +149 -0
- package/dist/core/mods/kernel/site-rules.d.ts +4 -0
- package/dist/core/mods/kernel/site-rules.js +13 -0
- package/dist/core/mods/package.d.ts +7 -3
- package/dist/core/mods/package.js +47 -80
- package/dist/core/own-property-receipt.js +11 -4
- package/dist/core/parent-spec-seat.d.ts +13 -11
- package/dist/core/parent-spec-seat.js +13 -9
- 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 +33 -5
- package/dist/core/permission-rule-org.js +13 -3
- 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/permission-rules.js +4 -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/retain-seat.d.ts +42 -0
- package/dist/core/retain-seat.js +76 -0
- package/dist/core/retired-keys.js +1 -0
- package/dist/core/rewind-refusal-codes.d.ts +8 -0
- package/dist/core/rewind-refusal-codes.js +12 -0
- package/dist/core/roles.d.ts +2 -2
- package/dist/core/roles.js +15 -1
- package/dist/core/rule-offer-read.d.ts +1 -1
- package/dist/core/rule-offer-read.js +32 -4
- package/dist/core/rule-store-fault.d.ts +9 -7
- package/dist/core/rule-store-fault.js +8 -3
- 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/checkpoint-scope.d.ts +14 -3
- package/dist/core/runner/checkpoint-scope.js +16 -6
- package/dist/core/runner/compact-session.js +1 -1
- package/dist/core/runner/construction-doors.js +8 -0
- package/dist/core/runner/contracts.d.ts +21 -5
- package/dist/core/runner/cross-boundary-lane.d.ts +8 -1
- package/dist/core/runner/cross-boundary-lane.js +4 -0
- package/dist/core/runner/delegation-owner.d.ts +30 -0
- package/dist/core/runner/delegation-owner.js +20 -4
- package/dist/core/runner/finish-reason-seat.js +4 -2
- package/dist/core/runner/gate-exit.d.ts +7 -0
- package/dist/core/runner/gate-exit.js +2 -1
- package/dist/core/runner/leg-frame.js +3 -0
- package/dist/core/runner/model-lane-seat.d.ts +3 -0
- package/dist/core/runner/model-lane-seat.js +4 -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 +27 -16
- package/dist/core/runner/person-path-rows.js +93 -15
- package/dist/core/runner/prepare-caps-and-workflow.js +98 -88
- package/dist/core/runner/prepare-config-doors.d.ts +1 -0
- package/dist/core/runner/prepare-config-doors.js +13 -7
- 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-gate-stations.d.ts +6 -0
- package/dist/core/runner/prepare-gate-stations.js +3 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +5 -2
- package/dist/core/runner/prepare-hands-readface.js +15 -3
- package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
- package/dist/core/runner/prepare-inherited-gate.js +13 -5
- package/dist/core/runner/prepare-offload-wrappers.js +1 -1
- 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 +42 -30
- 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 +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +8 -6
- package/dist/core/runner/resume-apply.js +11 -5
- package/dist/core/runner/resume-policy-outcome.js +5 -2
- 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/role-seat-defaulted.d.ts +3 -3
- package/dist/core/runner/role-seat-defaulted.js +1 -1
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +1 -1
- package/dist/core/runner/rule-store-unreadable-notice.js +3 -3
- package/dist/core/runner/run-harness-handlers.js +4 -1
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +5 -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 +6 -4
- package/dist/core/runner/shell-env-withheld.js +25 -3
- 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/sub-agent-deny-lists.js +9 -5
- package/dist/core/runner/task-start-doors.js +6 -3
- package/dist/core/runner/terminal-account.d.ts +6 -1
- package/dist/core/runner/terminal-account.js +16 -1
- package/dist/core/runner/tool-end-body.d.ts +1 -1
- package/dist/core/runner/tool-not-executed.d.ts +27 -8
- package/dist/core/runner/tool-not-executed.js +22 -11
- package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
- package/dist/core/runner/write-protection-station.d.ts +1 -1
- package/dist/core/runner/write-protection-station.js +1 -1
- package/dist/core/runner-deps.d.ts +17 -10
- package/dist/core/secret-env.d.ts +61 -37
- package/dist/core/secret-env.js +49 -49
- 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.d.ts +40 -2
- package/dist/core/shell-read-silence.js +23 -4
- package/dist/core/store-contracts/checkpoint-store-contract.js +10 -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 +14 -7
- package/dist/core/task-notification.d.ts +96 -10
- package/dist/core/task-notification.js +135 -6
- package/dist/core/task-registry-agent.d.ts +1 -0
- package/dist/core/task-registry-agent.js +1 -1
- 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 +40 -2
- package/dist/core/task-registry.js +80 -15
- package/dist/core/task-result.d.ts +18 -3
- package/dist/core/task-spec-members.d.ts +3 -1
- package/dist/core/task-spec-members.js +19 -3
- package/dist/core/task-spec.d.ts +48 -22
- package/dist/core/tool-catalog-entries.js +2 -0
- package/dist/core/tool-gate-phase.d.ts +6 -3
- package/dist/core/tool-gate-phase.js +1 -0
- package/dist/core/tool-mount-facts.d.ts +8 -4
- package/dist/core/tool-mount-facts.js +7 -2
- package/dist/core/tool-mount-plan.d.ts +3 -1
- package/dist/core/tool-mount-plan.js +10 -3
- package/dist/core/tool-mount-static.d.ts +1 -1
- package/dist/core/tool-mount-static.js +4 -2
- package/dist/core/tool-result-store.d.ts +56 -3
- package/dist/core/tool-result-store.js +219 -25
- package/dist/core/tool-spec.d.ts +9 -2
- package/dist/core/trace.d.ts +3 -3
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +14 -7
- package/dist/core/wiring-manifest.d.ts +26 -20
- package/dist/core/wiring-manifest.js +7 -3
- 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.d.ts +75 -1
- package/dist/engine/execution-env/node-execution-env.js +227 -13
- package/dist/engine/harness/types.d.ts +49 -1
- package/dist/engine/harness/types.js +10 -0
- package/dist/engine/llm/types.d.ts +13 -7
- package/dist/engine/llm/validation.d.ts +8 -1
- package/dist/engine/llm/validation.js +31 -2
- 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 +34 -4
- package/dist/host-env.d.ts +10 -0
- package/dist/host-env.js +1 -0
- package/dist/index.d.ts +28 -9
- package/dist/index.js +22 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/goal.js +1 -1
- 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-primitives.js +10 -1
- package/dist/orchestration/workflow-script-runner.d.ts +2 -2
- package/dist/orchestration/workflow-stop.d.ts +128 -0
- package/dist/orchestration/workflow-stop.js +156 -0
- package/dist/orchestration/workflow.d.ts +31 -7
- package/dist/orchestration/workflow.js +119 -57
- package/dist/prompts/manager-recipe.d.ts +18 -0
- package/dist/prompts/manager-recipe.js +24 -0
- package/dist/shell/lex.d.ts +2 -2
- package/dist/shell/lex.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/fs/bash-model-shell.d.ts +23 -0
- package/dist/tools/fs/bash-model-shell.js +25 -0
- package/dist/tools/fs/bash-readonly-classifier.d.ts +6 -0
- package/dist/tools/fs/bash-readonly-classifier.js +3 -0
- package/dist/tools/fs/file-write-check.js +9 -3
- package/dist/tools/fs/fs-bash.js +13 -11
- package/dist/tools/fs/index.d.ts +8 -7
- package/dist/tools/fs/index.js +4 -4
- 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 +4 -1
- package/dist/tools/fs/safety.js +4 -2
- package/dist/tools/fs/shell-read-argv.js +1 -0
- package/dist/tools/fs/shell-read-check.d.ts +9 -2
- package/dist/tools/fs/shell-read-check.js +134 -22
- package/dist/tools/fs/shell-read-establish.d.ts +9 -0
- package/dist/tools/fs/shell-read-establish.js +21 -11
- 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 +7 -3
- package/dist/tools/fs/shell-read-plan.js +8 -5
- package/dist/tools/fs/shell-read-word.d.ts +8 -0
- package/dist/tools/fs/shell-read-word.js +13 -4
- package/dist/tools/fs/shell-read-write-targets.js +17 -9
- package/dist/tools/monitor.js +12 -8
- package/dist/tools/scheduler-tools.d.ts +1 -0
- package/dist/tools/scheduler-tools.js +5 -2
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +192 -3
- package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
- package/wire-changes/answers/core-stores-sql@7.74.0.json +7 -0
- package/wire-changes/answers/core@7.73.0.json +216 -0
- package/wire-changes/answers/core@7.74.0.json +68 -0
- package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
- package/wire-changes/answers/mods-kernel@7.74.0.json +21 -0
- package/wire-changes/answers/primitives@7.73.0.json +12 -0
- package/wire-changes/answers/primitives@7.74.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.74.0.json +8 -0
- package/wire-changes/core-stores-sql@7.73.0.json +326 -0
- package/wire-changes/core-stores-sql@7.74.0.json +143 -0
- package/wire-changes/core@7.73.0.json +6480 -0
- package/wire-changes/core@7.74.0.json +2210 -0
- package/wire-changes/mods-kernel@7.73.0.json +147 -0
- package/wire-changes/mods-kernel@7.74.0.json +421 -0
- package/wire-changes/primitives@7.73.0.json +227 -0
- package/wire-changes/primitives@7.74.0.json +174 -0
- package/wire-changes/wiki-gate@7.73.0.json +145 -0
- package/wire-changes/wiki-gate@7.74.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";
|
|
@@ -110,10 +111,12 @@ export interface FsViolation {
|
|
|
110
111
|
/** Set ONLY on `path_not_in_root` — the containment roots in effect (primary first,
|
|
111
112
|
* then additionalDirectories), canonical form. */
|
|
112
113
|
roots?: readonly string[];
|
|
113
|
-
/** Set
|
|
114
|
+
/** Set on `read_path_denied` and `write_path_denied` — the deny-list pattern (verbatim entry text)
|
|
114
115
|
* the judged target matched. Absent on the refusal of a deny judgment that could not finish (a home view nobody could
|
|
115
116
|
* read, read-deny-home.ts `HomeView.unread`): no row matched, so none is named and no deny card is minted. */
|
|
116
117
|
pattern?: string;
|
|
118
|
+
/** The literals quoted by a deny refusal sentence, minted with the sentence ({@link readDenyRefusal}). */
|
|
119
|
+
echoed?: readonly RefusalEcho[];
|
|
117
120
|
message: string;
|
|
118
121
|
}
|
|
119
122
|
/**
|
package/dist/tools/fs/safety.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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";
|
|
@@ -524,13 +524,15 @@ export async function resolveKey(env, rootCanonical, path, signal, baseCwd, addi
|
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
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 } : {}) } : {}) });
|
|
527
528
|
return {
|
|
528
529
|
ok: false,
|
|
529
530
|
violation: {
|
|
530
531
|
code: write ? "write_path_denied" : "read_path_denied",
|
|
531
|
-
message:
|
|
532
|
+
message: refusal.sentence,
|
|
532
533
|
target: key,
|
|
533
534
|
pattern: hit.pattern,
|
|
535
|
+
echoed: refusal.echoed,
|
|
534
536
|
},
|
|
535
537
|
};
|
|
536
538
|
}
|
|
@@ -139,6 +139,7 @@ export function bare(r, provenance, spelled = r.folded) {
|
|
|
139
139
|
raw: r.raw,
|
|
140
140
|
provenance,
|
|
141
141
|
expands: r.expands,
|
|
142
|
+
...(r.bracket === true ? { bracket: true } : {}),
|
|
142
143
|
...(pattern !== undefined ? { pattern } : {}),
|
|
143
144
|
...(whole && r.homeFloor !== undefined ? { floorSpelled: r.homeFloor } : {}),
|
|
144
145
|
...(whole && r.floorValues !== undefined ? { floors: r.floorValues } : {}),
|
|
@@ -248,6 +248,11 @@ export interface ShellReadStationOptions {
|
|
|
248
248
|
* questions name no directory to add — a card offering one would offer what nothing grants. Absent ⇒ offered. */
|
|
249
249
|
readonly offersReadRootGrant?: false;
|
|
250
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;
|
|
251
256
|
/** What a consumer hands {@link judgeShellRead}: the command as written, the environment whose filesystem
|
|
252
257
|
* answers where its words land (symlinks resolved, patterns expanded — a `NodeExecutionEnv` over a real
|
|
253
258
|
* directory is what the gate itself runs on), the boundary it is judged against, and the trust-policy seat
|
|
@@ -305,8 +310,10 @@ export interface ShellReadJudgment {
|
|
|
305
310
|
* home and the account home the account database answers once, for this call (`readDenyHomesOf`'s homes). Every home
|
|
306
311
|
* beside the declared one waits at most a short bound of its own.
|
|
307
312
|
*
|
|
308
|
-
* It carries NO deadline
|
|
309
|
-
*
|
|
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
|
|
310
317
|
* second default here would decide the same number twice and turn a slow-but-correct filesystem's true
|
|
311
318
|
* answer into a fail-closed one unasked. A consumer wanting that posture races its own deadline and reads
|
|
312
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,8 @@ 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 {
|
|
11
|
+
import { readStationAnswer } from "../../core/shell-read-silence.js";
|
|
12
|
+
import { createShellReadEstablisher, establishShellReadsLexically, writtenOnLineBefore } from "./shell-read-establish.js";
|
|
12
13
|
import { readLandingsOf } from "./shell-read-identity.js";
|
|
13
14
|
import { declaredReadDenyHomes, homeViewsAt } from "./read-deny-home.js";
|
|
14
15
|
import { anyOptionWord, programArgs } from "./shell-read-write-targets.js";
|
|
@@ -176,11 +177,7 @@ async function writeGuardsOf(judged, boundary, env, signal) {
|
|
|
176
177
|
const dest = await probe(parentOf(view));
|
|
177
178
|
return dest === undefined || dest.ok || (dest.error.code !== "not_found" && dest.error.code !== "not_directory");
|
|
178
179
|
};
|
|
179
|
-
const changedBefore = (view, at) =>
|
|
180
|
-
const fold = (p) => p.normalize("NFC").toLowerCase();
|
|
181
|
-
const dir = fold(parentOf(view));
|
|
182
|
-
return writtenBy.some((paths, i) => i !== at && (i < at || concurrent) && paths.some((w) => withinAnyRoot([fold(w)], dir) || withinAnyRoot([dir], fold(w))));
|
|
183
|
-
};
|
|
180
|
+
const changedBefore = (view, at) => writtenOnLineBefore(writtenBy, at, concurrent, parentOf(view));
|
|
184
181
|
const answer = async (view, key) => (await judge(view, { fs: env, ...(signal !== undefined ? { signal } : {}), ...(key ? { canonical: true } : {}) })) ?? "clear";
|
|
185
182
|
const asked = [...[...asKey].map(([view, v]) => [view, v, true]), ...[...asSpelling].filter(([view]) => !landingKeys.has(view)).map(([view, v]) => [view, v, false])];
|
|
186
183
|
const slotOf = (view, key) => `${key || landingKeys.has(view) ? "key" : "spelling"}\u0000${view}`;
|
|
@@ -367,8 +364,8 @@ function refusalOf(tool, fold, boundary, paths) {
|
|
|
367
364
|
if (fold.finding === "deny_hit" && w?.deny !== undefined) {
|
|
368
365
|
const target = w.read.target ?? w.deny.matchedView;
|
|
369
366
|
const write = w.deny.face === "write";
|
|
370
|
-
const under =
|
|
371
|
-
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 } : {}) });
|
|
367
|
+
const under = w.deny.under === true;
|
|
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 } : {}), ...(w.deny.lookup !== undefined ? { lookup: w.deny.lookup, action: "removing" } : {}) });
|
|
372
369
|
const through = deniedThrough(w.read, boundary);
|
|
373
370
|
const sentence = `Error (${tool}): ${core} ${write ? writeDenyRefusalNote() : under ? DENY_UNDER_REFUSAL_NOTE : DENY_REFUSAL_NOTE}${through !== undefined ? ` ${DENIED_THROUGH_NOTE[through]}` : ""}`;
|
|
374
371
|
return { sentence, echoed, ...(write ? {} : { details: violationDetails({ code: "read_path_denied", message: sentence, target, pattern: w.deny.pattern }) }) };
|
|
@@ -473,12 +470,119 @@ async function applyAlsoInside(judged, boundary) {
|
|
|
473
470
|
});
|
|
474
471
|
return rewrite(judged);
|
|
475
472
|
}
|
|
476
|
-
|
|
477
|
-
|
|
473
|
+
export const SUBTREE_SEARCH_MS = 2_000;
|
|
474
|
+
export const SUBTREE_SEARCH_DIRS = 16_384;
|
|
475
|
+
async function searchSubtree(env, root, named, signal) {
|
|
476
|
+
const stop = new AbortController();
|
|
477
|
+
const timer = setTimeout(() => stop.abort(), SUBTREE_SEARCH_MS);
|
|
478
|
+
const onAbort = () => stop.abort();
|
|
479
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
480
|
+
const ended = new Promise((resolve) => stop.signal.addEventListener("abort", () => resolve("ended"), { once: true }));
|
|
481
|
+
const unfinished = (why) => ({ kind: "unfinished", why: signal?.aborted === true ? "the call was cancelled" : why });
|
|
482
|
+
const outOfTime = `the search ran past its ${SUBTREE_SEARCH_MS / 1000} s bound`;
|
|
483
|
+
try {
|
|
484
|
+
if (signal?.aborted === true)
|
|
485
|
+
return unfinished("");
|
|
486
|
+
const top = await Promise.race([env.fileInfo(root, stop.signal), ended]);
|
|
487
|
+
if (top === "ended")
|
|
488
|
+
return unfinished(outOfTime);
|
|
489
|
+
if (!top.ok)
|
|
490
|
+
return isAbsence(top.error.code) ? { kind: "clear" } : unfinished(`it could not be inspected (${top.error.code})`);
|
|
491
|
+
if (top.value.kind !== "directory")
|
|
492
|
+
return { kind: "clear" };
|
|
493
|
+
const queue = [root];
|
|
494
|
+
for (let listed = 0; queue.length > 0; listed++) {
|
|
495
|
+
if (listed >= SUBTREE_SEARCH_DIRS)
|
|
496
|
+
return unfinished(`it holds more than ${SUBTREE_SEARCH_DIRS} folders`);
|
|
497
|
+
const dir = queue.shift();
|
|
498
|
+
const entries = await Promise.race([env.listDir(dir, stop.signal), ended]);
|
|
499
|
+
if (entries === "ended")
|
|
500
|
+
return unfinished(outOfTime);
|
|
501
|
+
if (!entries.ok) {
|
|
502
|
+
if (isAbsence(entries.error.code))
|
|
503
|
+
continue;
|
|
504
|
+
return unfinished(`"${dir}" could not be listed (${entries.error.code})`);
|
|
505
|
+
}
|
|
506
|
+
for (const entry of entries.value) {
|
|
507
|
+
const at = `${dir.replace(/[\\/]+$/, "")}/${entry.name}`;
|
|
508
|
+
const pattern = named.ledBy(entry.name);
|
|
509
|
+
if (pattern !== null)
|
|
510
|
+
return { kind: "found", pattern, at };
|
|
511
|
+
if (entry.kind === "directory")
|
|
512
|
+
queue.push(at);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return { kind: "clear" };
|
|
516
|
+
}
|
|
517
|
+
catch {
|
|
518
|
+
return unfinished("the environment threw");
|
|
519
|
+
}
|
|
520
|
+
finally {
|
|
521
|
+
clearTimeout(timer);
|
|
522
|
+
signal?.removeEventListener("abort", onAbort);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
function removesSubtree(f) {
|
|
526
|
+
const r = f.read;
|
|
527
|
+
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");
|
|
528
|
+
}
|
|
529
|
+
async function applyRemovalSearch(judged, boundary, env, signal) {
|
|
530
|
+
const named = boundary.writeDenyNamed;
|
|
531
|
+
if (named === undefined || named.rows.length === 0)
|
|
532
|
+
return judged;
|
|
533
|
+
const searched = new Map();
|
|
534
|
+
const answered = new Map();
|
|
535
|
+
for (const f of allFindings(judged)) {
|
|
536
|
+
if (!removesSubtree(f))
|
|
537
|
+
continue;
|
|
538
|
+
const target = f.read.target;
|
|
539
|
+
let search = searched.get(target);
|
|
540
|
+
if (search === undefined)
|
|
541
|
+
searched.set(target, (search = searchSubtree(env, target, named, signal)));
|
|
542
|
+
const found = await search;
|
|
543
|
+
if (found.kind === "clear")
|
|
544
|
+
continue;
|
|
545
|
+
if (found.kind === "unfinished") {
|
|
546
|
+
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}`;
|
|
547
|
+
answered.set(f, { read: { ...f.read, cause }, kind: "unanswered", denyRowUnasked: true, containment: f.containment });
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
const readRow = boundary.writeDenyGuardsReads?.(found.pattern) === true ? { readRow: true } : {};
|
|
551
|
+
answered.set(f, { ...f, kind: "deny_hit", deny: { pattern: found.pattern, matchedView: normalizeAbsPathLexically(target), face: "write", under: true, lookup: { found: found.at }, ...readRow } });
|
|
552
|
+
}
|
|
553
|
+
if (answered.size === 0)
|
|
554
|
+
return judged;
|
|
555
|
+
const rewrite = (j) => ({ ...j, segments: j.segments.map((s) => ({ ...s, findings: s.findings.map((f) => answered.get(f) ?? f), nested: s.nested.map(rewrite) })) });
|
|
556
|
+
return rewrite(judged);
|
|
557
|
+
}
|
|
558
|
+
const holdsBracket = (c) => c.bracket === true;
|
|
559
|
+
const bracketCause = (spelled) => `"${spelled}" holds a bracket expression, which the shell matches by its own collation and options, so it may reach names this station does not list`;
|
|
560
|
+
function bracketWordsUnvouched(tool, seat, run, verdict) {
|
|
561
|
+
if (readStationAnswer(verdict, { toolName: tool }).kind !== "vouch")
|
|
562
|
+
return verdict;
|
|
563
|
+
const unread = new Map();
|
|
564
|
+
for (const f of allFindings(run.judged)) {
|
|
565
|
+
if (f.kind === "none" && holdsBracket(f.read.candidate))
|
|
566
|
+
unread.set(f, { ...f, kind: "unestablishable", read: { ...f.read, cause: bracketCause(f.read.candidate.spelled) } });
|
|
567
|
+
}
|
|
568
|
+
if (unread.size === 0)
|
|
569
|
+
return verdict;
|
|
570
|
+
const rewrite = (j) => ({ ...j, segments: j.segments.map((s) => ({ ...s, findings: s.findings.map((f) => unread.get(f) ?? f), nested: s.nested.map(rewrite) })) });
|
|
571
|
+
const judged = rewrite(run.judged);
|
|
572
|
+
const fold = foldShellReadFindings(judged);
|
|
573
|
+
if (fold.finding === "none")
|
|
574
|
+
return verdict;
|
|
575
|
+
const question = withReadAsk(verdictOf(tool, seat, fold, judged, run.boundary), judged);
|
|
576
|
+
if (question.disposition === "refuse")
|
|
577
|
+
return question;
|
|
578
|
+
const { disposition: _vouch, finding: _none, ...facts } = verdict;
|
|
579
|
+
return { ...facts, ...question };
|
|
580
|
+
}
|
|
581
|
+
async function runShellReadStation(tool, plan, declared, seat, establisher, env, signal) {
|
|
478
582
|
const door = observeEnvironment(env);
|
|
479
583
|
const established = await establisher.establish(plan, declared, signal, door);
|
|
480
584
|
const boundary = { ...declared, roots: established.roots };
|
|
481
|
-
const onPlan = await applyAlsoInside(judgePlan(plan, established, boundary), boundary);
|
|
585
|
+
const onPlan = await applyRemovalSearch(await applyAlsoInside(judgePlan(plan, established, boundary), boundary), boundary, env, signal);
|
|
482
586
|
const judgedNow = () => {
|
|
483
587
|
const unfinished = door.incomplete();
|
|
484
588
|
return unfinished.length > 0 ? { ...onPlan, incomplete: unfinished } : onPlan;
|
|
@@ -503,12 +607,16 @@ async function runShellReadStation(tool, command, declared, seat, readers, estab
|
|
|
503
607
|
export async function judgeShellRead(input) {
|
|
504
608
|
assertNoRetiredShellReadBoundaryKeys(input.boundary);
|
|
505
609
|
const readers = input.readers ?? new Set(bashClassifyDefaultAllow());
|
|
506
|
-
const
|
|
507
|
-
const
|
|
610
|
+
const plan = planShellReads(input.command, declarationsOf(input.boundary, readers, input.env.cdPath, input.env.receivedEnvNames));
|
|
611
|
+
const tool = input.tool ?? "Bash";
|
|
612
|
+
const seat = commandSeatOf(input.seat);
|
|
613
|
+
const run = await runShellReadStation(tool, plan, input.boundary, seat, createShellReadEstablisher(input.env, input.boundary.roots, { homeViews: homeViewsAt(input.env, input.readDenyHomes === undefined ? declaredReadDenyHomes(input.env) : checkedReadDenyHomes(input.readDenyHomes)) }), input.env, input.signal);
|
|
614
|
+
const verdict = bracketWordsUnvouched(tool, seat, run, run.verdict);
|
|
615
|
+
const offer = normalizeReadRootCandidate(verdict.readRootCandidate);
|
|
508
616
|
return {
|
|
509
617
|
plan: run.plan,
|
|
510
618
|
establishment: allFindings(run.judged).map((f) => f.read),
|
|
511
|
-
verdict
|
|
619
|
+
verdict,
|
|
512
620
|
...(offer !== undefined ? { offer } : {}),
|
|
513
621
|
};
|
|
514
622
|
}
|
|
@@ -567,16 +675,20 @@ export function createShellReadStation(opts) {
|
|
|
567
675
|
return null;
|
|
568
676
|
const seat = callOpts.seat ?? opts.seatOf(member);
|
|
569
677
|
return (async () => {
|
|
570
|
-
const
|
|
678
|
+
const plan = planShellReads(command, declarationsOf(boundary, readers, opts.env.cdPath, opts.env.receivedEnvNames));
|
|
679
|
+
const run = await runShellReadStation(call.toolName, plan, boundary, seat, establisherFor(boundary.roots), opts.env, signal);
|
|
571
680
|
if (run.verdict.disposition !== "refuse" && callOpts.toolCallId !== undefined)
|
|
572
681
|
remember(callOpts.toolCallId, { toolName: member, boundary: run.boundary, established: run.established, command });
|
|
573
682
|
const verdict = opts.offersReadRootGrant === false ? withoutGrantOffer(run.verdict) : run.verdict;
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
683
|
+
const answered = (() => {
|
|
684
|
+
if (boundary.unreadPartitions !== true)
|
|
685
|
+
return verdict;
|
|
686
|
+
if (verdict.disposition !== "vouch")
|
|
687
|
+
return { ...verdict, rowsUnread: true };
|
|
688
|
+
const unread = unansweredOver(call.toolName, seat, "the rules this check stands on could not all be read", boundary, { rowsUnread: true });
|
|
689
|
+
return unread.disposition === "refuse" || verdict.askRule === undefined ? unread : { ...unread, askRule: verdict.askRule, ...(verdict.askRuleOfPolicy === true ? { askRuleOfPolicy: true } : {}) };
|
|
690
|
+
})();
|
|
691
|
+
return bracketWordsUnvouched(call.toolName, seat, run, answered);
|
|
580
692
|
})();
|
|
581
693
|
},
|
|
582
694
|
unanswered(call, cause) {
|
|
@@ -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
|
|
@@ -160,11 +160,20 @@ function lexicalReadsOf(candidate, boundary, placed) {
|
|
|
160
160
|
}
|
|
161
161
|
function writtenByText(plan, boundary) {
|
|
162
162
|
const targets = new Set();
|
|
163
|
-
const
|
|
163
|
+
const runs = [];
|
|
164
|
+
const writes = [];
|
|
165
|
+
let concurrent = false;
|
|
164
166
|
const speculativeSeen = new Set();
|
|
165
167
|
let unplaced = false;
|
|
166
168
|
const walk = (p) => {
|
|
167
169
|
for (const s of p.segments) {
|
|
170
|
+
for (const n of s.nested)
|
|
171
|
+
walk(n);
|
|
172
|
+
const wrote = [];
|
|
173
|
+
runs.push(s);
|
|
174
|
+
writes.push(wrote);
|
|
175
|
+
if (p.shape.backgrounded || s.connector === "|")
|
|
176
|
+
concurrent = true;
|
|
168
177
|
for (const c of s.reads) {
|
|
169
178
|
if (c.speculative === undefined || c.expands !== false || c.bases === "unmodelled")
|
|
170
179
|
continue;
|
|
@@ -190,16 +199,19 @@ function writtenByText(plan, boundary) {
|
|
|
190
199
|
else {
|
|
191
200
|
const t = normalizeAbsPathLexically(r.target);
|
|
192
201
|
targets.add(t);
|
|
193
|
-
|
|
202
|
+
wrote.push(t);
|
|
194
203
|
}
|
|
195
204
|
}
|
|
196
205
|
}
|
|
197
|
-
for (const n of s.nested)
|
|
198
|
-
walk(n);
|
|
199
206
|
}
|
|
200
207
|
};
|
|
201
208
|
walk(plan);
|
|
202
|
-
return { targets, unplaced,
|
|
209
|
+
return { targets, unplaced, runs, writes, concurrent };
|
|
210
|
+
}
|
|
211
|
+
export function writtenOnLineBefore(writes, at, concurrent, place) {
|
|
212
|
+
const fold = (p) => p.normalize("NFC").toLowerCase();
|
|
213
|
+
const here = fold(place);
|
|
214
|
+
return writes.some((paths, i) => i !== at && (i < at || concurrent) && paths.some((w) => withinAnyRoot([fold(w)], here) || withinAnyRoot([here], fold(w))));
|
|
203
215
|
}
|
|
204
216
|
function unfollowedBackupReads(j, boundary, cause) {
|
|
205
217
|
const named = sedBackupNames(j.followed.operand.spelled, j.followed.suffix).flatMap((name) => lexicalReadsOf({ ...j.candidate, spelled: name }, boundary));
|
|
@@ -558,15 +570,13 @@ function establishLegOver(seen, readRoots) {
|
|
|
558
570
|
for (const r of lexicalReadsOf(fact.candidate, boundary)) {
|
|
559
571
|
if (r.established !== "lexical" || r.target === undefined)
|
|
560
572
|
return undefined;
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
if ((t === place || withinAnyRoot([place], t)) && [...by].some((s) => s !== segment))
|
|
564
|
-
return undefined;
|
|
573
|
+
if (writtenOnLineBefore(written.writes, written.runs.indexOf(segment), written.concurrent, normalizeAbsPathLexically(r.target)))
|
|
574
|
+
return undefined;
|
|
565
575
|
const at = fact.seat === "entry" ? await entryOf(r.target, signal) : await resolve(r.target, signal);
|
|
566
576
|
if (at === undefined || (!at.exact && at.missing !== true))
|
|
567
577
|
return undefined;
|
|
568
|
-
const info = at.missing === true && !at.exact ? undefined : await env.fileInfo(at.value, signal);
|
|
569
|
-
const here = info === undefined ? false : info.ok ? info.value.kind === "directory" : isAbsence(info.error.code) ? false : undefined;
|
|
578
|
+
const info = at.missing === true && !at.exact ? undefined : fact.seat === "entry" ? await env.fileInfo(at.value, signal) : await env.listDir(at.value, signal);
|
|
579
|
+
const here = info === undefined ? false : info.ok ? Array.isArray(info.value) || info.value.kind === "directory" : isAbsence(info.error.code) ? false : undefined;
|
|
570
580
|
if (here === undefined || (directory !== undefined && directory !== here))
|
|
571
581
|
return undefined;
|
|
572
582
|
directory = here;
|
|
@@ -27,7 +27,7 @@ import type { ReadCandidate, ShellReadPlan, ShellReadSegment } from "./shell-rea
|
|
|
27
27
|
import type { Incomplete, ObservedFilesystem } from "./shell-read-environment.js";
|
|
28
28
|
import type { WriteSeat } from "./shell-read-write-targets.js";
|
|
29
29
|
import { type ContainmentFace } from "./containment-face.js";
|
|
30
|
-
import { type JudgedPathRow } from "./read-deny.js";
|
|
30
|
+
import { type JudgedPathRow, type ReadDenyFinding, type ReadDenyRootAnswer } from "./read-deny.js";
|
|
31
31
|
import type { AssertAllKeysHandled } from "../../core/ask-origin.js";
|
|
32
32
|
/** WHAT the judge found about a command — a closed set, registered in `docs/CLOSED-SETS.md`. */
|
|
33
33
|
export declare const SHELL_READ_FINDINGS: readonly ["deny_hit", "outside_roots", "unestablishable", "declined", "identity_changed", "unanswered", "target_unavailable", "none"];
|
|
@@ -241,6 +241,17 @@ export interface ShellReadBoundary extends BashReadonlyRootBoundary {
|
|
|
241
241
|
/** Does the row `writeDenyMatch` named (its rule) guard the READ face too — a `Read(…)` rule on the write face
|
|
242
242
|
* ({@link import("./read-deny.js").WriteDenyMatcher.guardsReads})? Read once per hit, so the refusal says which family refused. */
|
|
243
243
|
readonly writeDenyGuardsReads?: (pattern: string) => boolean;
|
|
244
|
+
/** The write table's rows named by or below a subtree removal/rename target (`WriteDenyMatcher.rowUnderRoot`). */
|
|
245
|
+
readonly writeDenyUnder?: (resolvedPath: string) => ReadDenyRootAnswer;
|
|
246
|
+
/** The write table's unanchored rows (`WriteDenyMatcher.unanchoredRows`, never empty here) and the first of them whose leading
|
|
247
|
+
* name one directory entry name matches (`WriteDenyMatcher.rowLedByName`): what the station searches a recursive removal's
|
|
248
|
+
* subtree for, under its own bound ({@link import("./shell-read-check.js").SUBTREE_SEARCH_MS}). PRESENT-IFF such a row. */
|
|
249
|
+
readonly writeDenyNamed?: {
|
|
250
|
+
readonly rows: readonly string[];
|
|
251
|
+
readonly ledBy: (entryName: string) => string | null;
|
|
252
|
+
};
|
|
253
|
+
/** The write table's rows AT or BELOW a path (`WriteDenyMatcher.rowAtOrBelow`): read by `writesPlaced` via {@link denyRowAtOrBelow}. */
|
|
254
|
+
readonly writeDenyAtOrBelow?: (resolvedPath: string) => string | null;
|
|
244
255
|
/** The read table's rows AT or BELOW a path (`readDenySeat`'s `denyAtOrBelow`, read-deny.ts): read by the station's
|
|
245
256
|
* `writesPlaced` fact only, through {@link denyRowAtOrBelow}. */
|
|
246
257
|
readonly denyAtOrBelow?: (resolvedPath: string) => string | null;
|
|
@@ -355,6 +366,7 @@ export interface ReadFinding {
|
|
|
355
366
|
readonly face?: "write";
|
|
356
367
|
readonly readRow?: true;
|
|
357
368
|
readonly under?: true;
|
|
369
|
+
readonly lookup?: ReadDenyFinding["lookup"];
|
|
358
370
|
};
|
|
359
371
|
/** A `deny_hit` on no row: the read's target is a process-private /proc file (`isProcSensitiveFile`, safety.ts — the set the
|
|
360
372
|
* file read tools refuse), or a tree walk's root holds such files (`holdsProcSensitiveFile`); the view it was matched on. */
|