@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
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { effectivePathSpellingOf } from "../../core/effective-path-target.js";
|
|
2
|
-
import { pathTargetOf } from "../../core/tool-registry.js";
|
|
1
|
+
import { effectivePathSpellingOf, effectivePathSpellingsOf } from "../../core/effective-path-target.js";
|
|
2
|
+
import { declaredReadSlotOf, PATH_TARGET_ELEMENTS_MAX, pathTargetOf } from "../../core/tool-registry.js";
|
|
3
|
+
import { judgedReadsOf as portOf } from "./judged-reads.js";
|
|
3
4
|
import { fitMiddle, READ_DENY_SENTENCE_PART_MAX, seatForCall } from "./read-deny.js";
|
|
4
|
-
import { resolveKey, violationDetails, violationText } from "./safety.js";
|
|
5
|
-
import { readStationMemberOf } from "./shell-read-check.js";
|
|
5
|
+
import { resolveKey, violationDetails, violationText, withinAnyRoot } from "./safety.js";
|
|
6
|
+
import { readStationMemberOf, readTargetsRefusedDetails as readTargetsRefusedCard, unestablishedDetails as unestablishedCard } from "./shell-read-check.js";
|
|
6
7
|
import { decideShellRead, grantOfferFor, parentDirLexically } from "./shell-read-judge.js";
|
|
7
8
|
const ADMISSION_MAX = 1024;
|
|
8
9
|
export function outsideReadDisposition(leg) {
|
|
@@ -11,70 +12,190 @@ export function outsideReadDisposition(leg) {
|
|
|
11
12
|
return leg.readOnlyMount ? "tool_fence" : "question";
|
|
12
13
|
}
|
|
13
14
|
export const READ_BLOCK_REMEDY = "This task refuses reads outside its directories (blockReadsOutsideRoots); ask the user to add the directory to the task's directories.";
|
|
15
|
+
export function declaredReadOf(call) {
|
|
16
|
+
return declaredReadSlotOf(call);
|
|
17
|
+
}
|
|
14
18
|
const VOUCH = { disposition: "vouch", finding: "none" };
|
|
19
|
+
function setBounded(map, key, value) {
|
|
20
|
+
map.delete(key);
|
|
21
|
+
if (map.size >= ADMISSION_MAX) {
|
|
22
|
+
const oldest = map.keys().next().value;
|
|
23
|
+
if (oldest !== undefined)
|
|
24
|
+
map.delete(oldest);
|
|
25
|
+
}
|
|
26
|
+
map.set(key, value);
|
|
27
|
+
}
|
|
28
|
+
function namedTargets(targets) {
|
|
29
|
+
if (targets.length === 1)
|
|
30
|
+
return `"${fitMiddle(targets[0], READ_DENY_SENTENCE_PART_MAX)}"`;
|
|
31
|
+
const shown = [];
|
|
32
|
+
for (const t of targets) {
|
|
33
|
+
const next = [...shown, `"${t}"`].join(", ");
|
|
34
|
+
if (next.length > READ_DENY_SENTENCE_PART_MAX)
|
|
35
|
+
break;
|
|
36
|
+
shown.push(`"${t}"`);
|
|
37
|
+
}
|
|
38
|
+
if (shown.length === targets.length)
|
|
39
|
+
return shown.join(", ");
|
|
40
|
+
return `${shown.length > 0 ? `${shown.join(", ")} and ` : ""}${targets.length - shown.length} more (${targets.length} in all)`;
|
|
41
|
+
}
|
|
15
42
|
export function createFileReadStation(opts) {
|
|
16
43
|
const admissions = new Map();
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
44
|
+
const declaredCalls = new Map();
|
|
45
|
+
const pendingDeclared = new Map();
|
|
46
|
+
const tables = {
|
|
47
|
+
env: opts.env,
|
|
48
|
+
rootCanonical: opts.rootCanonical,
|
|
49
|
+
roots: opts.roots,
|
|
50
|
+
...(opts.readDeny !== undefined ? { readDeny: opts.readDeny } : {}),
|
|
51
|
+
...(opts.readFace !== undefined ? { readFace: opts.readFace } : {}),
|
|
52
|
+
...(opts.excluded !== undefined ? { excluded: opts.excluded } : {}),
|
|
53
|
+
...(opts.exempt !== undefined ? { exempt: opts.exempt } : {}),
|
|
54
|
+
...(opts.outsideReads === "refusal" ? { outsideRemedy: READ_BLOCK_REMEDY } : {}),
|
|
55
|
+
};
|
|
56
|
+
const refuse = (sentence, finding, details) => ({ disposition: "refuse", finding, sentence, ...(details !== undefined ? { details } : {}) });
|
|
57
|
+
const judgeTargets = async (j, signal) => {
|
|
58
|
+
const only = (verdict) => ({ verdict });
|
|
59
|
+
const { toolName } = j;
|
|
60
|
+
const extra = seatForCall(opts.roots, j.toolCallId)();
|
|
61
|
+
const deny = seatForCall(opts.readDeny, j.toolCallId);
|
|
62
|
+
const roots = [opts.rootCanonical, ...extra];
|
|
63
|
+
const allowed = fitMiddle(roots.join(", "), READ_DENY_SENTENCE_PART_MAX);
|
|
64
|
+
const outside = [];
|
|
65
|
+
const keys = [];
|
|
66
|
+
for (const t of j.targets) {
|
|
67
|
+
const r = await resolveKey(opts.env, opts.rootCanonical, t.spelled, signal, t.base, extra, undefined, deny, opts.readFace);
|
|
68
|
+
if (r.ok) {
|
|
69
|
+
keys.push(r.key);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const v = r.violation;
|
|
73
|
+
const outsideTarget = v.code === "path_not_in_root" ? v.target : undefined;
|
|
74
|
+
if (outsideTarget !== undefined && opts.exempt?.(outsideTarget) === true) {
|
|
75
|
+
keys.push(outsideTarget);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const details = violationDetails(v);
|
|
79
|
+
if (opts.outsideReads === "refusal") {
|
|
80
|
+
if (outsideTarget === undefined)
|
|
81
|
+
return only(refuse(violationText(toolName, v), v.code === "read_path_denied" ? "deny_hit" : "none", details));
|
|
82
|
+
return only(refuse(`Error (${toolName}): "${fitMiddle(outsideTarget, READ_DENY_SENTENCE_PART_MAX)}" is outside the directories this task may read (${allowed}). ${READ_BLOCK_REMEDY}`, "outside_roots", details));
|
|
83
|
+
}
|
|
84
|
+
if (outsideTarget !== undefined && opts.outsideReads !== "tool_fence" && opts.excluded?.(outsideTarget) !== true) {
|
|
85
|
+
outside.push({ target: outsideTarget, v });
|
|
86
|
+
keys.push(outsideTarget);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (j.declared)
|
|
90
|
+
return only(refuse(violationText(toolName, v), v.code === "read_path_denied" ? "deny_hit" : "none", details));
|
|
91
|
+
return only(VOUCH);
|
|
92
|
+
}
|
|
93
|
+
if (outside.length === 0)
|
|
94
|
+
return { verdict: VOUCH, keys };
|
|
95
|
+
const targets = outside.map((o) => o.target);
|
|
96
|
+
const named = namedTargets(targets);
|
|
97
|
+
const first = violationDetails(outside[0].v);
|
|
98
|
+
const details = first !== undefined && first.code === "path_not_in_root" && targets.length > 1 ? { ...first, targets } : first;
|
|
99
|
+
const disposition = decideShellRead("outside_roots", j.seat === "rejudge" ? "rejudge" : "file_tool");
|
|
100
|
+
const are = targets.length === 1 ? "is" : "are";
|
|
101
|
+
if (disposition === "refuse") {
|
|
102
|
+
return only(refuse(j.seat === "rejudge"
|
|
103
|
+
? `Error (${toolName}): the approved edit reads ${named}, outside the directories allowed for this session (${allowed}) — re-submit it as a fresh call and answer its card.`
|
|
104
|
+
: `Error (${toolName}): ${named} ${are} outside the directories allowed for this session (${allowed}).`, "outside_roots", details));
|
|
105
|
+
}
|
|
106
|
+
const head = targets[0];
|
|
107
|
+
const info = j.mayBeDirectory ? await opts.env.fileInfo(head, signal) : undefined;
|
|
108
|
+
const proposed = grantOfferFor(info?.ok === true && info.value.kind === "directory" ? head : parentDirLexically(head), targets.length === 1 ? head : undefined, { roots, ...(opts.homeDir !== undefined ? { homeDir: opts.homeDir } : {}) });
|
|
109
|
+
const offer = proposed !== undefined && targets.every((t) => withinAnyRoot([proposed.dir], t)) ? proposed : undefined;
|
|
110
|
+
return {
|
|
111
|
+
verdict: {
|
|
112
|
+
disposition,
|
|
113
|
+
finding: "outside_roots",
|
|
114
|
+
sentence: `reads outside the allowed directories for this session: ${named} ${are} not under ${allowed}`,
|
|
115
|
+
...(details !== undefined ? { details } : {}),
|
|
116
|
+
...(offer !== undefined ? { readRootCandidate: { dir: offer.dir, ...(offer.covers !== undefined ? { covers: offer.covers } : {}), clearsThisAsk: true } } : {}),
|
|
117
|
+
...(j.declared ? { cause: { code: "read.outside_roots", roots: { shown: targets, total: targets.length } } } : {}),
|
|
118
|
+
admit: () => j.admit(targets),
|
|
119
|
+
},
|
|
120
|
+
keys,
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
const judgeDeclared = (call, pt, args, cwd, signal, callOpts) => {
|
|
124
|
+
const toolName = call.toolName;
|
|
125
|
+
const toolCallId = callOpts.toolCallId;
|
|
126
|
+
const mine = {};
|
|
127
|
+
if (toolCallId !== undefined) {
|
|
128
|
+
declaredCalls.delete(toolCallId);
|
|
129
|
+
setBounded(pendingDeclared, toolCallId, mine);
|
|
22
130
|
}
|
|
23
|
-
|
|
131
|
+
let judged;
|
|
132
|
+
const landed = (verdict) => {
|
|
133
|
+
if (toolCallId === undefined || pendingDeclared.get(toolCallId) !== mine)
|
|
134
|
+
return verdict;
|
|
135
|
+
pendingDeclared.delete(toolCallId);
|
|
136
|
+
if (verdict.disposition !== "refuse" && judged !== undefined)
|
|
137
|
+
setBounded(declaredCalls, toolCallId, judged);
|
|
138
|
+
return verdict;
|
|
139
|
+
};
|
|
140
|
+
const sels = effectivePathSpellingsOf({ toolName, args, ...(call.face !== undefined ? { face: call.face } : {}) }, pt, { root: opts.rootCanonical, cwd }) ?? [];
|
|
141
|
+
if (sels.length > PATH_TARGET_ELEMENTS_MAX)
|
|
142
|
+
return Promise.resolve(landed(refuse(`Error (${toolName}): this call names ${sels.length} paths; a call may name at most ${PATH_TARGET_ELEMENTS_MAX}. Split it into calls of at most ${PATH_TARGET_ELEMENTS_MAX}; the call was not run.`, "none", readTargetsRefusedCard("read_targets_over_limit"))));
|
|
143
|
+
const targets = [];
|
|
144
|
+
for (const sel of sels) {
|
|
145
|
+
if ("refused" in sel)
|
|
146
|
+
return Promise.resolve(landed(refuse(`Error (${toolName}): a path this call names is one this environment refuses (${String(sel.refused)}); the call was not run.`, "none")));
|
|
147
|
+
const spelled = "malformed" in sel ? undefined : (sel.spelled ?? sel.base);
|
|
148
|
+
if ("malformed" in sel || spelled === undefined)
|
|
149
|
+
return Promise.resolve(landed(refuse(`Error (${toolName}): a value of "${pt.param}" is not a path (the slot takes a non-empty string${pt.each === true ? " or a list of them" : ""}); the call was not run.`, "none", readTargetsRefusedCard("read_target_not_a_path"))));
|
|
150
|
+
targets.push({ spelled, base: sel.spelled !== undefined ? sel.base : undefined });
|
|
151
|
+
}
|
|
152
|
+
mine.targets = targets.length;
|
|
153
|
+
const admitted = new Set();
|
|
154
|
+
return judgeTargets({ toolName, targets, toolCallId, seat: callOpts.seat, declared: true, mayBeDirectory: true, admit: (outside) => outside.forEach((o) => admitted.add(o)) }, signal).then(({ verdict, keys }) => {
|
|
155
|
+
if (verdict.disposition !== "refuse" && keys !== undefined)
|
|
156
|
+
judged = { toolName, elements: targets.map((t, i) => ({ spelled: t.spelled, base: t.base, key: keys[i] })), admitted };
|
|
157
|
+
return landed(verdict);
|
|
158
|
+
});
|
|
24
159
|
};
|
|
25
160
|
const check = {
|
|
26
161
|
judge(call, args, cwd, signal, callOpts) {
|
|
162
|
+
const declared = declaredReadOf(call);
|
|
163
|
+
if (declared !== undefined)
|
|
164
|
+
return judgeDeclared(call, declared, args, cwd, signal, callOpts);
|
|
27
165
|
const member = readStationMemberOf(call, opts.tools)?.name;
|
|
28
166
|
if (member === undefined)
|
|
29
167
|
return null;
|
|
30
|
-
const
|
|
31
|
-
const selection = effectivePathSpellingOf({ toolName, args }, pathTargetOf(member), { root: opts.rootCanonical, cwd });
|
|
168
|
+
const selection = effectivePathSpellingOf({ toolName: call.toolName, args }, pathTargetOf(member), { root: opts.rootCanonical, cwd });
|
|
32
169
|
if (selection === undefined || "refused" in selection || selection.spelled === undefined)
|
|
33
170
|
return null;
|
|
34
|
-
const
|
|
35
|
-
return (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
const info = pathTargetOf(member)?.absent === "base" ? await opts.env.fileInfo(target, signal) : undefined;
|
|
63
|
-
const readsDirectory = info?.ok === true && info.value.kind === "directory";
|
|
64
|
-
const offer = grantOfferFor(readsDirectory ? target : parentDirLexically(target), target, { roots, ...(opts.homeDir !== undefined ? { homeDir: opts.homeDir } : {}) });
|
|
65
|
-
return {
|
|
66
|
-
disposition,
|
|
67
|
-
finding: "outside_roots",
|
|
68
|
-
sentence: `reads outside the allowed directories for this session: "${fitMiddle(target, READ_DENY_SENTENCE_PART_MAX)}" is not under ${allowed}`,
|
|
69
|
-
details,
|
|
70
|
-
...(offer !== undefined ? { readRootCandidate: { dir: offer.dir, ...(offer.covers !== undefined ? { covers: offer.covers } : {}), clearsThisAsk: true } } : {}),
|
|
71
|
-
...(toolCallId !== undefined ? { admit: () => remember(toolCallId, target) } : {}),
|
|
72
|
-
};
|
|
73
|
-
})();
|
|
171
|
+
const toolCallId = callOpts.toolCallId;
|
|
172
|
+
return judgeTargets({
|
|
173
|
+
toolName: call.toolName,
|
|
174
|
+
targets: [{ spelled: selection.spelled, base: selection.base }],
|
|
175
|
+
toolCallId,
|
|
176
|
+
seat: callOpts.seat,
|
|
177
|
+
declared: false,
|
|
178
|
+
mayBeDirectory: pathTargetOf(member)?.absent === "base",
|
|
179
|
+
admit: (outside) => {
|
|
180
|
+
if (toolCallId !== undefined && outside[0] !== undefined)
|
|
181
|
+
setBounded(admissions, toolCallId, outside[0]);
|
|
182
|
+
},
|
|
183
|
+
}, signal).then(({ verdict }) => verdict);
|
|
184
|
+
},
|
|
185
|
+
unanswered: (call, cause) => {
|
|
186
|
+
const id = call.toolCallId;
|
|
187
|
+
const named = id !== undefined ? pendingDeclared.get(id)?.targets : undefined;
|
|
188
|
+
if (id !== undefined) {
|
|
189
|
+
pendingDeclared.delete(id);
|
|
190
|
+
declaredCalls.delete(id);
|
|
191
|
+
}
|
|
192
|
+
const remedy = named !== undefined && named > 1 ? `This call names ${named} paths: split them into several calls, each naming fewer.` : "Try the call again.";
|
|
193
|
+
if (declaredReadOf(call) !== undefined)
|
|
194
|
+
return { disposition: "refuse", finding: "unanswered", environmentSilent: true, sentence: `Error (${call.toolName}): where this call reads could not be established (${cause}), and nothing after the read station judges what this tool reads, so the call was not run. ${remedy}`, details: unestablishedCard() };
|
|
195
|
+
return opts.outsideReads === "refusal"
|
|
196
|
+
? { disposition: "refuse", finding: "unanswered", environmentSilent: true, sentence: `Error (${call.toolName}): where this call reads could not be established (${cause}), and this task refuses reads it cannot place inside its directories (blockReadsOutsideRoots). Try the call again.` }
|
|
197
|
+
: VOUCH;
|
|
74
198
|
},
|
|
75
|
-
unanswered: (call, cause) => opts.outsideReads === "refusal"
|
|
76
|
-
? { disposition: "refuse", finding: "unanswered", environmentSilent: true, sentence: `Error (${call.toolName}): where this call reads could not be established (${cause}), and this task refuses reads it cannot place inside its directories (blockReadsOutsideRoots). Try the call again.` }
|
|
77
|
-
: VOUCH,
|
|
78
199
|
};
|
|
79
200
|
const admitted = (toolCallId, key) => {
|
|
80
201
|
if (toolCallId === undefined || admissions.get(toolCallId) !== key)
|
|
@@ -82,7 +203,14 @@ export function createFileReadStation(opts) {
|
|
|
82
203
|
admissions.delete(toolCallId);
|
|
83
204
|
return true;
|
|
84
205
|
};
|
|
85
|
-
|
|
206
|
+
const judgedReadsOf = (toolCallId) => {
|
|
207
|
+
const judged = declaredCalls.get(toolCallId);
|
|
208
|
+
return judged === undefined ? undefined : portOf(tables, toolCallId, judged);
|
|
209
|
+
};
|
|
210
|
+
return { check, tools: opts.tools, admitted, judgedReadsOf, declares: (call) => declaredReadOf(call) !== undefined };
|
|
211
|
+
}
|
|
212
|
+
export function readStationsHold(stations, call) {
|
|
213
|
+
return stations.some((s) => readStationMemberOf(call, s.tools) !== undefined || s.declares?.(call) === true);
|
|
86
214
|
}
|
|
87
215
|
export function composeReadChecks(stations) {
|
|
88
216
|
if (stations.length === 0)
|
|
@@ -94,9 +222,24 @@ export function composeReadChecks(stations) {
|
|
|
94
222
|
for (const n of s.tools)
|
|
95
223
|
if (!byName.has(n))
|
|
96
224
|
byName.set(n, s);
|
|
97
|
-
const stationOf = (call) => readStationMemberOf(call, byName)?.value;
|
|
225
|
+
const stationOf = (call) => stations.find((s) => s.declares?.(call) === true) ?? readStationMemberOf(call, byName)?.value;
|
|
98
226
|
return {
|
|
99
227
|
judge: (call, args, cwd, signal, callOpts) => stationOf(call)?.check.judge(call, args, cwd, signal, callOpts) ?? null,
|
|
100
228
|
unanswered: (call, cause) => (stationOf(call) ?? stations[0]).check.unanswered(call, cause),
|
|
101
229
|
};
|
|
102
230
|
}
|
|
231
|
+
export function unjudgedReadsMember(ported) {
|
|
232
|
+
const declares = (call) => declaredReadOf(call) !== undefined && !ported(call.toolName);
|
|
233
|
+
const refusal = (call) => ({
|
|
234
|
+
disposition: "refuse",
|
|
235
|
+
finding: "unanswered",
|
|
236
|
+
environmentSilent: true,
|
|
237
|
+
sentence: `Error (${call.toolName}): this leg has no execution environment, so nothing can judge the paths this tool declares it reads, and the tool opens them itself; the call was not run. Give the Runner an execution environment (executionEnv or executionEnvFactory), or drop the tool's read declaration (its pathTarget).`,
|
|
238
|
+
details: unestablishedCard(),
|
|
239
|
+
});
|
|
240
|
+
return {
|
|
241
|
+
tools: new Set(),
|
|
242
|
+
declares,
|
|
243
|
+
check: { judge: (call) => (declares(call) ? Promise.resolve(refusal(call)) : null), unanswered: (call) => (declares(call) ? refusal(call) : VOUCH) },
|
|
244
|
+
};
|
|
245
|
+
}
|
|
@@ -23,10 +23,16 @@ export function createFileWriteStation(opts) {
|
|
|
23
23
|
return null;
|
|
24
24
|
return (async () => {
|
|
25
25
|
const r = await opts.contain(spelled, signal, callOpts.toolCallId);
|
|
26
|
-
if (r.ok
|
|
26
|
+
if (r.ok)
|
|
27
27
|
return VOUCH;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (r.violation.code === "path_not_in_root") {
|
|
29
|
+
const details = violationDetails(r.violation);
|
|
30
|
+
return { disposition: "refuse", finding: "outside_roots", face: "write", sentence: violationText(call.toolName, r.violation), ...(details !== undefined ? { details } : {}) };
|
|
31
|
+
}
|
|
32
|
+
if (r.violation.code === "write_path_denied") {
|
|
33
|
+
return { disposition: "refuse", finding: "deny_hit", face: "write", sentence: violationText(call.toolName, r.violation), ...(r.violation.echoed !== undefined ? { echoed: r.violation.echoed } : {}) };
|
|
34
|
+
}
|
|
35
|
+
return VOUCH;
|
|
30
36
|
})();
|
|
31
37
|
},
|
|
32
38
|
unanswered: () => VOUCH,
|
package/dist/tools/fs/index.d.ts
CHANGED
|
@@ -180,13 +180,14 @@ export interface HandsToolkitOptions {
|
|
|
180
180
|
* roster (the Runner mounts Monitor, this band never does). `false` drops the gh rate-limit hint's
|
|
181
181
|
* Monitor clause; absent ⇒ the full wording. */
|
|
182
182
|
monitorToolActive?: boolean;
|
|
183
|
-
/** ADDITIONS to the
|
|
184
|
-
* (
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
183
|
+
/** ADDITIONS to the sensitive-path deny set ({@link import("./read-deny.js").READ_FACE_DEFAULT_DENY_ENTRIES}):
|
|
184
|
+
* judged on BOTH the read faces (Read/Grep/Glob/RepoMap and their traversals) and the write faces
|
|
185
|
+
* (Write/Edit/NotebookEdit/SaveToolResult; this band's Bash meets them only through a caller-supplied shell
|
|
186
|
+
* station, which judges literal write operands) in every containment mode. Built-in tiers
|
|
187
|
+
* stay read-only (their write side is the write-protection table). Add-only: additions union with the active
|
|
188
|
+
* built-ins, `[]` ≡ absent (union identity), and additions never remove a built-in — the one removal channel
|
|
189
|
+
* is the deployment's built-in configuration ({@link readDenyBuiltinTiers} / {@link readDenyBuiltinExclude}).
|
|
190
|
+
* Bad entry shapes throw at wiring time. */
|
|
190
191
|
readDenyPatterns?: readonly ReadDenyEntry[];
|
|
191
192
|
/** The deployment's built-in-table TIER selection ({@link import("./read-deny.js").ReadDenyBuiltinConfig}
|
|
192
193
|
* `tiers` key) — the switch for the built-in table:
|
package/dist/tools/fs/index.js
CHANGED
|
@@ -91,12 +91,12 @@ export function createHandsToolkit(env, readFileState, rootCanonical, opts = {})
|
|
|
91
91
|
afterPlacement(createReadFileTool(env, readFileState, rootCanonical, readCwd, readFaceRoots, opts.imageProcessor, opts.pdfModelCapabilities, bgOutputReadExemption, readDeny, readFace, opts.reminderMark, opts.reminderDisclosureCounts, reader)),
|
|
92
92
|
];
|
|
93
93
|
if (handsWriteHalfMounts({ readOnly })) {
|
|
94
|
-
tools.push(createEditFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny, readDeny, opts.readFirstWaiver), createWriteFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny, opts.readFirstWaiver), createNotebookEditTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny));
|
|
94
|
+
tools.push(afterPlacement(createEditFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny, readDeny, opts.readFirstWaiver)), afterPlacement(createWriteFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny, opts.readFirstWaiver)), afterPlacement(createNotebookEditTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny)));
|
|
95
95
|
const keptBytes = opts.toolResultBytes;
|
|
96
96
|
if (opts.writeContainmentSeat !== undefined)
|
|
97
97
|
opts.writeContainmentSeat.current = writeContainmentOf(env, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, writeDeny, writeFaceOf);
|
|
98
98
|
if (keptBytes?.bytesOf !== undefined)
|
|
99
|
-
tools.push(createSaveToolResultTool(env, keptBytes, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny));
|
|
99
|
+
tools.push(afterPlacement(createSaveToolResultTool(env, keptBytes, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny)));
|
|
100
100
|
}
|
|
101
101
|
tools.push(afterPlacement(createGrepTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission, outsideRemedy)), afterPlacement(createGlobTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission, outsideRemedy)), afterPlacement(createRepoMapTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission, outsideRemedy)));
|
|
102
102
|
if (includeShell) {
|
|
@@ -171,7 +171,7 @@ function bandOwnTables(env, opts) {
|
|
|
171
171
|
return await tool.execute(...args);
|
|
172
172
|
},
|
|
173
173
|
};
|
|
174
|
-
const writeDenyCompiled = compileWriteDeny(
|
|
175
|
-
const writeDeny = writeDenyCompiled.
|
|
174
|
+
const writeDenyCompiled = compileWriteDeny(readDeny);
|
|
175
|
+
const writeDeny = writeDenyCompiled.hasRows ? carryHomeViews(writeDenyCompiled, readDeny.homeViews) : undefined;
|
|
176
176
|
return { readDeny, writeDeny, afterPlacement };
|
|
177
177
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The judged-read PORT of a caller tool's declared read ({@link import("../../core/tool-spec.js").ToolExecuteContext.judgedReads}):
|
|
3
|
+
* the one way such a tool reads a target the model named. Each entry is a target the file read station judged for the call; `open`
|
|
4
|
+
* is that judgment again, on the key the station judged, then the environment's bound open, then the judgment once more — and only
|
|
5
|
+
* the held object leaves. An environment that cannot hold the object is a refusal: the target is never read by name instead.
|
|
6
|
+
*/
|
|
7
|
+
import type { ExecutionEnv } from "../../internal/harness-types.js";
|
|
8
|
+
import type { JudgedRead, JudgedReadsUnavailable } from "../../core/judged-read.js";
|
|
9
|
+
import type { ToolExecuteContext } from "../../core/tool-spec.js";
|
|
10
|
+
/** The closed set of {@link JudgedReadsUnavailable}, as a list (every word once). */
|
|
11
|
+
export declare const JUDGED_READS_UNAVAILABLE: readonly JudgedReadsUnavailable[];
|
|
12
|
+
/** The port seat of one leg: the station's ports per call, or none when the leg mounts no file read station; and the wire names of
|
|
13
|
+
* the tools the leg mounted with the port (`ported`, written where they are mounted). */
|
|
14
|
+
export type JudgedReadsSeat = {
|
|
15
|
+
current?: ((toolCallId: string) => readonly JudgedRead[] | undefined) | null;
|
|
16
|
+
ported?: Set<string>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* `ctx` with the port of a tool that declares a read target: a fresh object with `ctx`'s own property descriptors (its getters stay
|
|
20
|
+
* getters) and `judgedReads`, read when the tool reads it — the station's judgment of this call, or why there is none.
|
|
21
|
+
*/
|
|
22
|
+
export declare function withJudgedReads(ctx: ToolExecuteContext, seat: JudgedReadsSeat): ToolExecuteContext;
|
|
23
|
+
import type { ContainmentFace } from "./containment-face.js";
|
|
24
|
+
import { type ReadDenyMatcher } from "./read-deny.js";
|
|
25
|
+
/** One element of a call's declared read as the station recorded it: its spelling, the base it resolves against, and the
|
|
26
|
+
* canonical key the judgment landed on. */
|
|
27
|
+
export interface JudgedElement {
|
|
28
|
+
readonly spelled: string;
|
|
29
|
+
readonly base: string | undefined;
|
|
30
|
+
readonly key: string;
|
|
31
|
+
}
|
|
32
|
+
/** What the station holds for one judged call: the call's name (the refusals say it), its elements in slot order, and the targets
|
|
33
|
+
* outside the roots whose question the gate applied (an open may read them; nothing else outside the roots). */
|
|
34
|
+
export interface JudgedCall {
|
|
35
|
+
readonly toolName: string;
|
|
36
|
+
readonly elements: readonly JudgedElement[];
|
|
37
|
+
readonly admitted: Set<string>;
|
|
38
|
+
}
|
|
39
|
+
/** The judgment the port asks again: the station's own tables, read for the call. */
|
|
40
|
+
export interface JudgedReadTables {
|
|
41
|
+
readonly env: ExecutionEnv;
|
|
42
|
+
readonly rootCanonical: string;
|
|
43
|
+
readonly roots: () => readonly string[];
|
|
44
|
+
readonly readDeny?: ReadDenyMatcher;
|
|
45
|
+
readonly readFace?: ContainmentFace;
|
|
46
|
+
readonly excluded?: (canonicalKey: string) => boolean;
|
|
47
|
+
readonly exempt?: (canonicalKey: string) => boolean;
|
|
48
|
+
readonly outsideRemedy?: string;
|
|
49
|
+
}
|
|
50
|
+
/** The port's entries for one judged call (`toolCallId`), in slot order. Never throws: every refusal is a result. */
|
|
51
|
+
export declare function judgedReadsOf(tables: JudgedReadTables, toolCallId: string, call: JudgedCall): readonly JudgedRead[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { FileError, err, ok } from "../../internal/harness.js";
|
|
2
|
+
import { thrownText } from "../../core/thrown-value.js";
|
|
3
|
+
export const JUDGED_READS_UNAVAILABLE = Object.freeze(["no_read_station", "not_judged"]);
|
|
4
|
+
export function withJudgedReads(ctx, seat) {
|
|
5
|
+
const read = () => {
|
|
6
|
+
const ports = seat.current;
|
|
7
|
+
if (ports === undefined || ports === null)
|
|
8
|
+
return Object.freeze({ kind: "unavailable", reason: "no_read_station" });
|
|
9
|
+
const targets = ports(ctx.toolCallId);
|
|
10
|
+
return targets === undefined ? Object.freeze({ kind: "unavailable", reason: "not_judged" }) : Object.freeze({ kind: "judged", targets });
|
|
11
|
+
};
|
|
12
|
+
return Object.create(Object.getPrototypeOf(ctx), { ...Object.getOwnPropertyDescriptors(ctx), judgedReads: { get: read, enumerable: true, configurable: true } });
|
|
13
|
+
}
|
|
14
|
+
import { openBoundAt } from "./bound-open.js";
|
|
15
|
+
import { createEntryDenyJudge, enumerateDirectory } from "./dir-entries.js";
|
|
16
|
+
import { seatForCall } from "./read-deny.js";
|
|
17
|
+
import { resolveKey, violationText } from "./safety.js";
|
|
18
|
+
export function judgedReadsOf(tables, toolCallId, call) {
|
|
19
|
+
return Object.freeze(call.elements.map((el) => Object.freeze({ spelled: el.spelled, key: el.key, open: (signal) => openJudged(tables, toolCallId, call, el, signal) })));
|
|
20
|
+
}
|
|
21
|
+
async function openJudged(tables, toolCallId, call, el, signal) {
|
|
22
|
+
try {
|
|
23
|
+
const { env } = tables;
|
|
24
|
+
const deny = seatForCall(tables.readDeny, toolCallId);
|
|
25
|
+
const target = el.key;
|
|
26
|
+
const judge = (s) => resolveKey(env, tables.rootCanonical, target, s, el.base, seatForCall(tables.roots, toolCallId)(), (k) => call.admitted.has(k) || tables.exempt?.(k) === true, deny, tables.readFace, tables.outsideRemedy);
|
|
27
|
+
const first = await judge(signal);
|
|
28
|
+
if (!first.ok)
|
|
29
|
+
return err(new FileError("permission_denied", violationText(call.toolName, first.violation), first.violation.target ?? target));
|
|
30
|
+
if (first.key !== el.key)
|
|
31
|
+
return err(new FileError("precondition_failed", `Error (${call.toolName}): "${el.spelled}" no longer lands on the file that was judged; it was not read`, el.key));
|
|
32
|
+
if (tables.excluded?.(first.key) === true)
|
|
33
|
+
return err(new FileError("permission_denied", `Error (${call.toolName}): "${el.spelled}" is in the engine's artifact store, which no tool reads`, first.key));
|
|
34
|
+
const opening = await openBoundAt(env, first.key, signal);
|
|
35
|
+
if (opening.kind === "unbindable")
|
|
36
|
+
return err(new FileError("not_supported", `Error (${call.toolName}): this environment cannot hold the file it judged ("${el.spelled}"), so it is not read`, first.key));
|
|
37
|
+
if (opening.kind === "refused")
|
|
38
|
+
return err(opening.error);
|
|
39
|
+
const object = opening.object;
|
|
40
|
+
const again = await judge(signal);
|
|
41
|
+
if (!again.ok || again.key !== first.key) {
|
|
42
|
+
await object.close();
|
|
43
|
+
return err(again.ok ? new FileError("precondition_failed", `Error (${call.toolName}): "${el.spelled}" moved while it was opened; it was not read`, first.key) : new FileError("permission_denied", violationText(call.toolName, again.violation), first.key));
|
|
44
|
+
}
|
|
45
|
+
return ok(heldFile(env, first.key, object, deny));
|
|
46
|
+
}
|
|
47
|
+
catch (thrown) {
|
|
48
|
+
return err(new FileError("unknown", `Error (${call.toolName}): "${el.spelled}" could not be judged: ${thrownText(thrown)}`, el.key));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function heldFile(env, key, object, deny) {
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
key,
|
|
54
|
+
identity: object.identity,
|
|
55
|
+
kind: object.kind,
|
|
56
|
+
size: () => object.size(),
|
|
57
|
+
readBytes: async (max, signal) => (object.kind === "file" ? object.readBytes(max, signal) : { ok: false, error: new FileError("is_directory", "The object is a directory", key) }),
|
|
58
|
+
list: async (signal) => {
|
|
59
|
+
if (object.kind !== "directory")
|
|
60
|
+
return { ok: false, error: new FileError("not_directory", "The object is a file", key) };
|
|
61
|
+
const listing = await enumerateDirectory(env, key, deny !== undefined ? createEntryDenyJudge(env, deny, signal) : undefined, signal, () => object.list(signal));
|
|
62
|
+
if (!listing.ok)
|
|
63
|
+
return listing;
|
|
64
|
+
return { ok: true, value: { entries: listing.value.entries.map((e) => ({ name: e.name, kind: e.kind })), omitted: listing.value.omitted, more: listing.value.more } };
|
|
65
|
+
},
|
|
66
|
+
close: () => object.close(),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
@@ -171,7 +171,7 @@ export declare function homeViewsAt(env: HomeViewEnv, homes: readonly string[]):
|
|
|
171
171
|
/** The home views of one judgment, off the judge it judges with: the views of the judge's placement. A judge that
|
|
172
172
|
* carries none (one built outside a mount) reads the declared home alone. */
|
|
173
173
|
export declare function homeViewsOf(env: HomeViewEnv, judge: HomeViewsCarrier | undefined, signal?: AbortSignal): HomeViews;
|
|
174
|
-
/** A judge with the home views `source` gives it. */
|
|
174
|
+
/** A judge with the home views `source` gives it, preserving getters (live projections) and non-enumerable identity (`id`). */
|
|
175
175
|
export declare function carryHomeViews<T extends object>(judge: T, source: HomeViewSource): T & {
|
|
176
176
|
readonly homeViews: HomeViewSource;
|
|
177
177
|
};
|
|
@@ -397,6 +397,9 @@ export function readDenyOver(current, homeViews) {
|
|
|
397
397
|
get compiledSegments() {
|
|
398
398
|
return current().compiledSegments;
|
|
399
399
|
},
|
|
400
|
+
get tableRows() {
|
|
401
|
+
return current().tableRows;
|
|
402
|
+
},
|
|
400
403
|
homeViews: homeViews ?? { views: (signal) => current().homeViews.views(signal) },
|
|
401
404
|
};
|
|
402
405
|
}
|
|
@@ -418,11 +421,8 @@ export function homeViewsOf(env, judge, signal) {
|
|
|
418
421
|
return (judge?.homeViews ?? homeViewsAt(env, [])).views(signal, env);
|
|
419
422
|
}
|
|
420
423
|
export function carryHomeViews(judge, source) {
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
if (typeof id === "string")
|
|
424
|
-
Object.defineProperty(carried, "id", { value: id, enumerable: false });
|
|
425
|
-
return carried;
|
|
424
|
+
const descriptors = Object.getOwnPropertyDescriptors(judge);
|
|
425
|
+
return Object.defineProperties({}, { ...descriptors, homeViews: { value: source, enumerable: true, writable: true, configurable: true } });
|
|
426
426
|
}
|
|
427
427
|
export async function placeReadDenyAtHome(env, compile, homes, signal, places) {
|
|
428
428
|
const entries = compile([]).entries;
|
|
@@ -152,13 +152,17 @@ export declare function segmentGuardRow(pat: CompiledSegmentPattern, columns: {
|
|
|
152
152
|
readonly tier?: string;
|
|
153
153
|
}): PathGuardRow;
|
|
154
154
|
/**
|
|
155
|
-
* The WRITE face of the deny table: the
|
|
156
|
-
*
|
|
157
|
-
*
|
|
155
|
+
* The WRITE face of the deny table: every row of the one deny table whose faces include `write` — deployment / task
|
|
156
|
+
* `readDenyPatterns` additions (`faces: ["read", "write"]`) and `Read(…)` / `Edit(…)` rule rows — judged for
|
|
157
|
+
* file write tools (`Write`, `Edit`, `NotebookEdit`, `SaveToolResult`) and shell write targets (a redirection, `tee`,
|
|
158
|
+
* `sed -i`, `cp` / `mv` / `touch` / `mkdir` / `rm` operands). Built-in read-deny tiers stay `faces: ["read"]`. Same row
|
|
159
|
+
* type and judgment ({@link judgePathRows}) as the read face.
|
|
158
160
|
*/
|
|
159
161
|
export interface WriteDenyMatcher {
|
|
160
162
|
/** Which face this judge is — the write tools' path resolution reads it to word and code the refusal as a write. */
|
|
161
163
|
readonly face: "write";
|
|
164
|
+
/** True iff the write projection holds at least one row (a `readDenyPatterns` addition or a write-facing rule row). */
|
|
165
|
+
readonly hasRows: boolean;
|
|
162
166
|
readonly ruleRows: readonly PathRuleDenyRow[];
|
|
163
167
|
matchPath(path: string): ReadDenyHit | null;
|
|
164
168
|
/** The target judgment the read face makes, on this face's rows: canonical key, lexical view, the leaf chain's hops. */
|
|
@@ -168,13 +172,26 @@ export interface WriteDenyMatcher {
|
|
|
168
172
|
}): ReadDenyHit | null;
|
|
169
173
|
/** The table ONE call judges with ({@link ReadDenyMatcher.forCall}). */
|
|
170
174
|
forCall?(toolCallId: string | undefined): WriteDenyMatcher;
|
|
171
|
-
/** Is the row a hit named (its rule text) a row that guards the READ face too — a `
|
|
172
|
-
* paths are not written because their reads are denied — rather than a
|
|
173
|
-
* says which of the two refused ({@link readDenySentence}'s `readRow`). Absent ⇒
|
|
175
|
+
/** Is the row a hit named (its pattern or rule text) a row that guards the READ face too — a `readDenyPatterns` addition
|
|
176
|
+
* or a `Read(…)` rule, whose paths are not written because their reads are denied — rather than a write-only row (`Edit(…)`)?
|
|
177
|
+
* The refusal's sentence says which of the two refused ({@link readDenySentence}'s `readRow`). Absent ⇒ none. */
|
|
174
178
|
guardsReads?(pattern: string): boolean;
|
|
179
|
+
/** The write-facing segment row the absolute directory `scope` names or contains ({@link ReadDenyMatcher.rowUnderRoot}),
|
|
180
|
+
* judged on locations alone without enumerating disk (used for subtree removal / rename operations). */
|
|
181
|
+
rowUnderRoot?(scope: string): ReadDenyRootHit | null;
|
|
182
|
+
/** A write-facing row that lies AT or BELOW `path` ({@link ReadDenyMatcher.rowAtOrBelow}): segment rows are judged per row;
|
|
183
|
+
* non-enumerable rule rows answer for any path. */
|
|
184
|
+
rowAtOrBelow?(path: string): ReadDenyHit | null;
|
|
185
|
+
/** The write-facing segment rows no location places (an unanchored row: its match may start in any folder), in table order —
|
|
186
|
+
* the rows a recursive removal's subtree is searched for by name, since {@link rowUnderRoot} cannot place them below an
|
|
187
|
+
* operand that does not spell them. */
|
|
188
|
+
readonly unanchoredRows?: readonly string[];
|
|
189
|
+
/** The first {@link unanchoredRows} row whose leading named segment (its first segment that is not stars only) the ONE
|
|
190
|
+
* directory entry name `name` matches, folded as that row folds; null where none. */
|
|
191
|
+
rowLedByName?(name: string): string | null;
|
|
175
192
|
}
|
|
176
|
-
/**
|
|
177
|
-
export declare function compileWriteDeny(
|
|
193
|
+
/** Project the write face (`faces.includes("write")`) out of one compiled deny table ({@link compileReadDeny}). */
|
|
194
|
+
export declare function compileWriteDeny(table: ReadDenyMatcher): WriteDenyMatcher;
|
|
178
195
|
/** One compiled ripgrep glob flag for the traversal legs (`--iglob` = case-insensitive entry). */
|
|
179
196
|
export interface ReadDenyRgGlob {
|
|
180
197
|
flag: "--glob" | "--iglob";
|
|
@@ -243,6 +260,9 @@ export interface ReadDenyMatcher {
|
|
|
243
260
|
* OS confinement translates the table from (read-floor.ts); the rule rows are {@link ruleRows}. Absent on a hand-built
|
|
244
261
|
* matcher: such a table has no confinement. */
|
|
245
262
|
readonly compiledSegments?: readonly CompiledSegmentPattern[];
|
|
263
|
+
/** Every compiled row of this table (built-in tiers, additions, placements, and rule rows across both faces),
|
|
264
|
+
* each carrying its `faces` column — the one source {@link compileWriteDeny} projects the write face from. */
|
|
265
|
+
readonly tableRows?: readonly PathGuardRow[];
|
|
246
266
|
/** The table's identity, minted once where {@link compileReadDeny} compiles it: a compiled table never changes its
|
|
247
267
|
* judgment, so two tables with one `id` judge every path alike. Not enumerable: a spread copy (which may replace the
|
|
248
268
|
* judgment) has none; the copy that only carries other home views (`carryHomeViews`) keeps it. Absent on a hand-built
|
|
@@ -326,6 +346,11 @@ export interface ReadDenyFinding {
|
|
|
326
346
|
* alone. The sentence then says the search below the folder is refused for a location it holds, and that no file need be
|
|
327
347
|
* there — naming a row as what "the target matches" would send the reader looking for a file that may not exist. */
|
|
328
348
|
readonly under?: true;
|
|
349
|
+
/** On the write face, a recursive REMOVAL whose subtree was searched by name for an unanchored row
|
|
350
|
+
* ({@link WriteDenyMatcher.rowLedByName}) and FOUND below it: `found` — the entry the search found, which the sentence names. */
|
|
351
|
+
readonly lookup?: {
|
|
352
|
+
readonly found: string;
|
|
353
|
+
};
|
|
329
354
|
}
|
|
330
355
|
/**
|
|
331
356
|
* The deny finding minted ONCE as both of its faces: the sentence ({@link readDenySentence}) and the literals that sentence
|