@sema-agent/core 7.69.0 → 7.69.1
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 +583 -0
- package/dist/agents/repair-loop.js +6 -14
- package/dist/agents/subagent.js +2 -1
- package/dist/agents/verify.d.ts +1 -1
- package/dist/agents/verify.js +7 -1
- package/dist/brain/reasoning-request.d.ts +7 -0
- package/dist/brain/reasoning-request.js +6 -0
- package/dist/core/agent-config-dir.d.ts +39 -3
- package/dist/core/agent-config-dir.js +67 -11
- package/dist/core/allow-entry.d.ts +5 -5
- package/dist/core/allow-entry.js +12 -6
- package/dist/core/ask-headline.d.ts +2 -2
- package/dist/core/ask-origin.d.ts +31 -31
- package/dist/core/ask-origin.js +20 -13
- package/dist/core/attachment-source.d.ts +1 -1
- package/dist/core/attachment-source.js +1 -0
- package/dist/core/auto-compaction.d.ts +44 -62
- package/dist/core/auto-compaction.js +44 -103
- package/dist/core/cache-break-detector.d.ts +23 -11
- package/dist/core/cache-break-detector.js +11 -5
- package/dist/core/checkpoint-features.d.ts +1 -1
- package/dist/core/checkpoint-features.js +1 -1
- package/dist/core/checkpoint-requirements.d.ts +19 -1
- package/dist/core/checkpoint-requirements.js +6 -0
- package/dist/core/checkpoint-row-verdict.js +3 -0
- package/dist/core/checkpoint-store.d.ts +13 -2
- package/dist/core/child-clamp-seats.d.ts +30 -3
- package/dist/core/child-clamp-seats.js +24 -0
- package/dist/core/compaction-retired-members.d.ts +12 -0
- package/dist/core/compaction-retired-members.js +22 -0
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +2 -0
- package/dist/core/context-edit.d.ts +32 -17
- package/dist/core/context-edit.js +28 -0
- package/dist/core/cron.d.ts +68 -0
- package/dist/core/cron.js +259 -0
- package/dist/core/engine-attestation.d.ts +16 -0
- package/dist/core/engine-attestation.js +2 -0
- package/dist/core/engine-capabilities.d.ts +14 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +18 -7
- package/dist/core/engine-version.js +1 -1
- package/dist/core/gate-outcome.d.ts +29 -2
- package/dist/core/gate-outcome.js +6 -0
- package/dist/core/git-read-only.d.ts +10 -0
- package/dist/core/git-read-only.js +1 -0
- package/dist/core/git-worktree-env.js +9 -8
- package/dist/core/governance-codes.d.ts +9 -2
- package/dist/core/governance-codes.js +9 -0
- package/dist/core/locked-config.js +7 -3
- package/dist/core/lsp.d.ts +3 -0
- package/dist/core/lsp.js +3 -2
- package/dist/core/memory-engine/engine.d.ts +48 -12
- package/dist/core/memory-engine/engine.js +108 -46
- package/dist/core/memory-engine/file-backend.d.ts +2 -1
- package/dist/core/memory-engine/index-copies.d.ts +47 -0
- package/dist/core/memory-engine/index-copies.js +88 -0
- package/dist/core/memory-engine/layout.d.ts +20 -3
- package/dist/core/memory-engine/layout.js +39 -3
- package/dist/core/memory-engine/origin-clearance.d.ts +9 -7
- package/dist/core/memory-engine/origin-clearance.js +2 -4
- package/dist/core/memory-engine/types.d.ts +16 -3
- package/dist/core/mode-policy.d.ts +7 -1
- package/dist/core/mode-policy.js +9 -0
- package/dist/core/mods/session-compact.js +3 -3
- package/dist/core/mods/stations.d.ts +2 -0
- package/dist/core/mods/stations.js +2 -1
- package/dist/core/path-guard-rows.d.ts +8 -3
- package/dist/core/path-guard-rows.js +18 -5
- package/dist/core/peer-seat.d.ts +3 -0
- package/dist/core/peer-seat.js +3 -0
- package/dist/core/permission-rule-model.js +3 -2
- package/dist/core/process-identity.d.ts +11 -3
- package/dist/core/process-identity.js +26 -16
- package/dist/core/runner/assemble-result.d.ts +5 -0
- package/dist/core/runner/assemble-result.js +1 -1
- package/dist/core/runner/cleared-results-record.d.ts +33 -0
- package/dist/core/runner/cleared-results-record.js +56 -0
- package/dist/core/runner/compact-session.js +14 -9
- package/dist/core/runner/compaction-knobs.d.ts +1 -1
- package/dist/core/runner/continuation-gate.js +2 -1
- package/dist/core/runner/continues-from.d.ts +1 -1
- package/dist/core/runner/continues-from.js +1 -1
- package/dist/core/runner/contracts.d.ts +83 -31
- package/dist/core/runner/conversation-segment.d.ts +19 -12
- package/dist/core/runner/conversation-segment.js +27 -7
- package/dist/core/runner/derived-route-fallback.d.ts +2 -12
- package/dist/core/runner/derived-route-fallback.js +0 -6
- package/dist/core/runner/gate-exit.d.ts +2 -1
- package/dist/core/runner/gate-exit.js +4 -2
- package/dist/core/runner/git-status-frame.d.ts +2 -2
- package/dist/core/runner/git-status-frame.js +2 -1
- package/dist/core/runner/initial-run-state.js +1 -1
- package/dist/core/runner/leg-caller-places.d.ts +39 -0
- package/dist/core/runner/leg-caller-places.js +23 -0
- package/dist/core/runner/leg-frame.d.ts +8 -2
- package/dist/core/runner/leg-receipt.d.ts +29 -2
- package/dist/core/runner/leg-receipt.js +37 -6
- package/dist/core/runner/media-removed-seat.d.ts +10 -6
- package/dist/core/runner/media-removed-seat.js +6 -3
- package/dist/core/runner/messages-omitted-seat.d.ts +2 -1
- package/dist/core/runner/messages-omitted-seat.js +15 -5
- package/dist/core/runner/person-path-rows.d.ts +25 -7
- package/dist/core/runner/person-path-rows.js +16 -2
- package/dist/core/runner/prefix-ledger.d.ts +120 -0
- package/dist/core/runner/prefix-ledger.js +176 -0
- package/dist/core/runner/prepare-advisor.d.ts +2 -0
- package/dist/core/runner/prepare-advisor.js +2 -1
- package/dist/core/runner/prepare-artifact.d.ts +3 -0
- package/dist/core/runner/prepare-artifact.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
- package/dist/core/runner/prepare-config-doors.d.ts +9 -8
- package/dist/core/runner/prepare-config-doors.js +15 -12
- package/dist/core/runner/prepare-context-lane.d.ts +25 -6
- package/dist/core/runner/prepare-context-lane.js +82 -27
- package/dist/core/runner/prepare-gate-stations.d.ts +1 -2
- package/dist/core/runner/prepare-gate-stations.js +2 -4
- package/dist/core/runner/prepare-hands-readface.d.ts +18 -5
- package/dist/core/runner/prepare-hands-readface.js +41 -22
- package/dist/core/runner/prepare-inherited-gate.d.ts +5 -0
- package/dist/core/runner/prepare-inherited-gate.js +2 -0
- package/dist/core/runner/prepare-memory.d.ts +10 -2
- package/dist/core/runner/prepare-memory.js +51 -5
- package/dist/core/runner/prepare-policy-chain.d.ts +3 -0
- package/dist/core/runner/prepare-policy-chain.js +13 -2
- package/dist/core/runner/prepare-prompt-assembly.d.ts +12 -4
- package/dist/core/runner/prepare-prompt-assembly.js +10 -4
- package/dist/core/runner/prepare-prompt-inputs.d.ts +3 -7
- package/dist/core/runner/prepare-prompt-inputs.js +6 -7
- package/dist/core/runner/prepare-safety-scan.js +7 -0
- package/dist/core/runner/prepare-suspend-saga.d.ts +4 -0
- package/dist/core/runner/prepare-suspend-saga.js +3 -2
- package/dist/core/runner/prepare-task.js +59 -53
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +5 -11
- package/dist/core/runner/prepare-tool-disclosure-mount.js +7 -8
- package/dist/core/runner/prepare-turn-wiring.d.ts +16 -25
- package/dist/core/runner/prepare-turn-wiring.js +8 -18
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/prompt-suggestions.d.ts +3 -1
- package/dist/core/runner/prompt-suggestions.js +1 -1
- package/dist/core/runner/read-block-judge.d.ts +47 -0
- package/dist/core/runner/read-block-judge.js +33 -0
- package/dist/core/runner/role-resolution-table.d.ts +15 -10
- package/dist/core/runner/role-resolution-table.js +4 -5
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +7 -4
- package/dist/core/runner/rule-store-unreadable-notice.js +4 -3
- package/dist/core/runner/run-compaction-machinery.d.ts +0 -10
- package/dist/core/runner/run-compaction-machinery.js +3 -39
- package/dist/core/runner/run-harness-handlers.js +4 -17
- package/dist/core/runner/run-identity-wiring.js +4 -1
- package/dist/core/runner/run-leg.js +11 -1
- package/dist/core/runner/run-recovery-lanes.d.ts +0 -4
- package/dist/core/runner/run-recovery-lanes.js +34 -18
- package/dist/core/runner/run-settle-and-teardown.d.ts +1 -3
- package/dist/core/runner/run-settle-and-teardown.js +14 -22
- package/dist/core/runner/run-telemetry-and-budget-seats.js +0 -1
- package/dist/core/runner/run-terminal-adoption.d.ts +11 -30
- package/dist/core/runner/run-terminal-adoption.js +5 -88
- package/dist/core/runner/run-tool-mount-facts.js +1 -5
- package/dist/core/runner/run-turn-boundary.js +56 -26
- package/dist/core/runner/runtask.js +7 -7
- package/dist/core/runner/session-hash-salt.d.ts +18 -0
- package/dist/core/runner/session-hash-salt.js +36 -0
- package/dist/core/runner/shell-env-withheld.d.ts +8 -5
- package/dist/core/runner/shell-env-withheld.js +3 -3
- package/dist/core/runner/side-call-account.d.ts +9 -1
- package/dist/core/runner/side-call-account.js +15 -4
- package/dist/core/runner/skill-mention.d.ts +12 -0
- package/dist/core/runner/skill-mention.js +50 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/synthetic-tools.js +2 -2
- package/dist/core/runner/tool-table-view.d.ts +5 -9
- package/dist/core/runner/tool-table-view.js +23 -21
- package/dist/core/runner/write-protection-station.d.ts +5 -2
- package/dist/core/runner/write-protection-station.js +1 -1
- package/dist/core/runner-deps.d.ts +25 -27
- package/dist/core/scheduler.d.ts +13 -3
- package/dist/core/scheduler.js +0 -12
- package/dist/core/secret-env.d.ts +47 -11
- package/dist/core/secret-env.js +65 -4
- package/dist/core/sensitive-path-policy.js +4 -0
- package/dist/core/session-checkout.js +10 -9
- package/dist/core/shell-read-silence.d.ts +2 -1
- package/dist/core/shell-run-candidates.d.ts +1 -1
- package/dist/core/shell-run-candidates.js +11 -3
- package/dist/core/task-event.d.ts +32 -10
- package/dist/core/task-intake.d.ts +5 -3
- package/dist/core/task-intake.js +6 -2
- package/dist/core/task-result.d.ts +39 -0
- package/dist/core/task-spec-members.d.ts +3 -0
- package/dist/core/task-spec-members.js +2 -2
- package/dist/core/task-spec.d.ts +37 -20
- package/dist/core/tool-policy.d.ts +30 -18
- package/dist/core/tool-policy.js +44 -32
- package/dist/core/tool-roster.d.ts +21 -7
- package/dist/core/tool-roster.js +34 -6
- package/dist/core/tool-spec-members.js +1 -1
- package/dist/core/tool-spec.d.ts +27 -0
- package/dist/core/tools.js +1 -0
- package/dist/core/trace.d.ts +42 -19
- package/dist/core/unc-spelling.d.ts +31 -0
- package/dist/core/unc-spelling.js +51 -0
- package/dist/core/wiring-manifest.d.ts +30 -3
- package/dist/core/wiring-manifest.js +10 -0
- package/dist/core/workflow-run-store-contract.js +22 -0
- package/dist/core/workflow-run-store.d.ts +17 -13
- package/dist/core/workflow-run-store.js +1 -1
- package/dist/core/write-protect.d.ts +4 -0
- package/dist/core/write-protect.js +17 -15
- package/dist/engine/compaction/compaction.d.ts +48 -98
- package/dist/engine/compaction/compaction.js +136 -216
- package/dist/engine/compaction/utils.d.ts +2 -11
- package/dist/engine/compaction/utils.js +4 -13
- package/dist/engine/execution-env/node-execution-env.js +17 -6
- package/dist/engine/harness/agent-harness.d.ts +19 -5
- package/dist/engine/harness/agent-harness.js +18 -7
- package/dist/engine/harness/types.d.ts +5 -7
- package/dist/engine/loop/agent-loop.d.ts +14 -1
- package/dist/engine/loop/agent-loop.js +31 -11
- package/dist/engine/loop/types.d.ts +8 -2
- package/dist/index.d.ts +9 -6
- package/dist/index.js +8 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +1 -1
- package/dist/internal/harness.js +1 -1
- package/dist/orchestration/run-spec.js +7 -2
- package/dist/orchestration/run-workflow-tool.js +5 -3
- package/dist/orchestration/workflow-park-adoption.d.ts +66 -8
- package/dist/orchestration/workflow-park-adoption.js +195 -45
- package/dist/orchestration/workflow-types.d.ts +20 -0
- package/dist/orchestration/workflow-types.js +1 -0
- package/dist/orchestration/workflow.d.ts +3 -2
- package/dist/orchestration/workflow.js +10 -4
- package/dist/prompt-assembly/catalog/core-behavior.js +6 -0
- package/dist/prompt-assembly/catalog/events.d.ts +8 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +6 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/mechanism.js +1 -0
- package/dist/prompt-assembly/catalog/mechanism.d.ts +8 -0
- package/dist/prompt-assembly/catalog/mechanism.js +1 -0
- package/dist/prompt-assembly/catalog/schema.d.ts +1 -1
- package/dist/prompt-assembly/catalog/schema.js +1 -0
- package/dist/prompt-assembly/catalog/sections.js +8 -0
- package/dist/prompt-assembly/event-registry.js +1 -0
- package/dist/prompt-assembly/select.js +1 -0
- package/dist/prompt-assembly/turn-snapshot.d.ts +14 -27
- package/dist/prompt-assembly/turn-snapshot.js +6 -18
- package/dist/prompt-assembly/types.d.ts +3 -0
- package/dist/prompts/default.d.ts +9 -0
- package/dist/prompts/default.js +4 -0
- package/dist/shell/lex.d.ts +75 -11
- package/dist/shell/lex.js +340 -76
- package/dist/tools/fs/bash-program-position.js +2 -6
- package/dist/tools/fs/bash-readonly-classifier.d.ts +18 -3
- package/dist/tools/fs/bash-readonly-classifier.js +19 -9
- package/dist/tools/fs/containment-face.d.ts +12 -3
- package/dist/tools/fs/containment-face.js +16 -7
- package/dist/tools/fs/file-read-check.d.ts +26 -1
- package/dist/tools/fs/file-read-check.js +20 -2
- package/dist/tools/fs/fs-bash.js +4 -4
- package/dist/tools/fs/fs-read.d.ts +3 -0
- package/dist/tools/fs/fs-read.js +2 -2
- package/dist/tools/fs/fs-search-tools.d.ts +2 -2
- package/dist/tools/fs/fs-search-tools.js +4 -4
- package/dist/tools/fs/index.js +5 -3
- package/dist/tools/fs/pdf.js +12 -4
- package/dist/tools/fs/read-deny-home.d.ts +13 -2
- package/dist/tools/fs/read-deny-home.js +26 -22
- package/dist/tools/fs/read-deny.js +15 -6
- package/dist/tools/fs/removal-targets.d.ts +33 -17
- package/dist/tools/fs/removal-targets.js +160 -61
- package/dist/tools/fs/repo-map.d.ts +1 -1
- package/dist/tools/fs/repo-map.js +2 -2
- package/dist/tools/fs/safety.d.ts +28 -5
- package/dist/tools/fs/safety.js +72 -8
- package/dist/tools/fs/shell-read-bindings.d.ts +8 -2
- package/dist/tools/fs/shell-read-bindings.js +25 -6
- package/dist/tools/fs/shell-read-check.d.ts +3 -0
- package/dist/tools/fs/shell-read-check.js +22 -4
- package/dist/tools/fs/shell-read-establish.js +73 -43
- package/dist/tools/fs/shell-read-judge.d.ts +32 -14
- package/dist/tools/fs/shell-read-judge.js +13 -5
- package/dist/tools/fs/shell-read-object-path.d.ts +5 -1
- package/dist/tools/fs/shell-read-object-path.js +17 -4
- package/dist/tools/fs/shell-read-plan.d.ts +8 -2
- package/dist/tools/fs/shell-read-plan.js +36 -22
- package/dist/tools/fs/shell-read-sourced.js +12 -4
- package/dist/tools/fs/shell-read-start.d.ts +4 -2
- package/dist/tools/fs/shell-read-start.js +3 -3
- package/dist/tools/fs/shell-read-workdir.d.ts +14 -6
- package/dist/tools/fs/shell-read-workdir.js +35 -17
- package/dist/tools/scheduler-tools.d.ts +7 -17
- package/dist/tools/scheduler-tools.js +9 -85
- package/dist/tools/worktree.js +5 -4
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +47 -1
- package/wire-changes/core-stores-sql@7.68.6.json +39 -0
- package/wire-changes/core-stores-sql@7.69.1.json +39 -0
- package/wire-changes/core@7.68.6.json +125 -0
- package/wire-changes/core@7.69.1.json +2561 -0
- package/wire-changes/mods-kernel@7.68.6.json +39 -0
- package/wire-changes/mods-kernel@7.69.1.json +39 -0
- package/wire-changes/primitives@7.68.6.json +39 -0
- package/wire-changes/primitives@7.69.1.json +39 -0
- package/wire-changes/wiki-gate@7.68.6.json +39 -0
- package/wire-changes/wiki-gate@7.69.1.json +39 -0
- package/dist/core/runner/prompt-hash-salt.d.ts +0 -1
- package/dist/core/runner/prompt-hash-salt.js +0 -2
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { describeRejectedValue } from "../../core/tool-search-setting.js";
|
|
3
3
|
import { sliceHeadSafe, sliceTailSafe } from "../../core/surrogate-safe-slice.js";
|
|
4
4
|
import { isAbsoluteForFamily, normalizeAbsPathLexically, pathFamilyOf, pathIdentityOf, spellingOfIdentity } from "./safety.js";
|
|
5
|
+
import { localDriveSpellingOf } from "../../core/unc-spelling.js";
|
|
5
6
|
import { PROBE_REASON_MAX } from "../../core/untrusted-text.js";
|
|
6
7
|
import { wildcardMatch } from "../../core/namespaced-rule-name.js";
|
|
7
8
|
import { validatePath } from "../../core/effective-path-target.js";
|
|
@@ -272,6 +273,10 @@ export const READ_FACE_BUILTIN_DENY_TABLE = [
|
|
|
272
273
|
{ pattern: "~/.ai-agent/.env", tier: "agent-config" },
|
|
273
274
|
{ pattern: "~/.sema/engine-data/.env", tier: "agent-config" },
|
|
274
275
|
{ pattern: "~/.sema/config-lkg-*.json", tier: "agent-config" },
|
|
276
|
+
{ pattern: "~/.sema/settings.json.*", tier: "agent-config" },
|
|
277
|
+
{ pattern: "~/.sema/settings.local.json.*", tier: "agent-config" },
|
|
278
|
+
{ pattern: "~/.sema/.sema.*", tier: "agent-config" },
|
|
279
|
+
{ pattern: "~/.sema/.config.json*", tier: "agent-config" },
|
|
275
280
|
{ pattern: "~/.codex/config.toml", tier: "agent-config" },
|
|
276
281
|
{ pattern: "~/.cursor/mcp.json", tier: "agent-config" },
|
|
277
282
|
{ pattern: "~/.continue/config.json", tier: "agent-config" },
|
|
@@ -509,7 +514,7 @@ function rowNamedByRoot(pat, segs, rooted) {
|
|
|
509
514
|
}
|
|
510
515
|
function rowNamedByRootOf(rows, path) {
|
|
511
516
|
const rooted = isAbsoluteForFamily("own", path);
|
|
512
|
-
const foldedViews = foldedViewsOf(
|
|
517
|
+
const foldedViews = foldedViewsOf(shareDriveReadingsOf(path).flatMap((at) => segmentViewsOf(at)));
|
|
513
518
|
let unplaced;
|
|
514
519
|
for (const pat of rows) {
|
|
515
520
|
for (const view of foldedViews(pat.fold)) {
|
|
@@ -524,7 +529,7 @@ function rowNamedByRootOf(rows, path) {
|
|
|
524
529
|
}
|
|
525
530
|
function rowAtOrBelowOf(rows, path) {
|
|
526
531
|
const rooted = isAbsoluteForFamily("own", path);
|
|
527
|
-
const foldedViews = foldedViewsOf(
|
|
532
|
+
const foldedViews = foldedViewsOf(shareDriveReadingsOf(path).flatMap((at) => segmentViewsOf(at)));
|
|
528
533
|
for (const pat of rows) {
|
|
529
534
|
for (const view of foldedViews(pat.fold))
|
|
530
535
|
if (rowMeetsPath(pat, view, rooted))
|
|
@@ -532,8 +537,13 @@ function rowAtOrBelowOf(rows, path) {
|
|
|
532
537
|
}
|
|
533
538
|
return null;
|
|
534
539
|
}
|
|
540
|
+
function shareDriveReadingsOf(path) {
|
|
541
|
+
const drive = localDriveSpellingOf(path);
|
|
542
|
+
const at = drive === undefined ? undefined : normalizeAbsPathLexically(drive);
|
|
543
|
+
return at === undefined || at === normalizeAbsPathLexically(path) ? [path] : [path, at];
|
|
544
|
+
}
|
|
535
545
|
function homeAnchorSegments(home) {
|
|
536
|
-
return
|
|
546
|
+
return shareDriveReadingsOf(home).map((at) => normalizeAbsPathLexically(at).split(/[\\/]/).filter(Boolean));
|
|
537
547
|
}
|
|
538
548
|
function rgGlobEscape(pattern) {
|
|
539
549
|
return pattern.replace(/[?[\]{}]/g, (c) => `[${c}]`);
|
|
@@ -623,7 +633,7 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
|
|
|
623
633
|
if (!columns.has(e.pattern))
|
|
624
634
|
columns.set(e.pattern, { origin: "addition" });
|
|
625
635
|
}
|
|
626
|
-
const homeSegments = [...new Set(checkedReadDenyHomes(homes))].
|
|
636
|
+
const homeSegments = [...new Set(checkedReadDenyHomes(homes))].flatMap(homeAnchorSegments);
|
|
627
637
|
const compiled = normalized.map((e) => {
|
|
628
638
|
const { run } = readDenyPatternRun(e.pattern);
|
|
629
639
|
const rowAnchor = readDenyRowAnchor(e.pattern);
|
|
@@ -650,8 +660,7 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
|
|
|
650
660
|
const c = compiled[i];
|
|
651
661
|
const rest = c.segments.slice(readDenyRunHead(run));
|
|
652
662
|
for (const location of new Set(checkedReadDenyHomes(locations, "readDenyHomeLinks"))) {
|
|
653
|
-
|
|
654
|
-
linkedPlacements.push({ raw: e.pattern, segments: rest, fold: c.fold, anchors: [foldSegments(c.fold, segs)], rootedOnly: true });
|
|
663
|
+
linkedPlacements.push({ raw: e.pattern, segments: rest, fold: c.fold, anchors: homeAnchorSegments(location).map((segs) => foldSegments(c.fold, segs)), rootedOnly: true });
|
|
655
664
|
}
|
|
656
665
|
});
|
|
657
666
|
const judged = linkedPlacements.length === 0 ? compiled : [...compiled, ...linkedPlacements];
|
|
@@ -9,25 +9,34 @@ export declare const SHELL_REMOVAL_COMMANDS: readonly ["rm", "rmdir"];
|
|
|
9
9
|
export type ShellRemovalCommand = (typeof SHELL_REMOVAL_COMMANDS)[number];
|
|
10
10
|
/** What makes a removal target dangerous, in the order a card names it. */
|
|
11
11
|
export type DangerousRemovalKind = "filesystem_root" | "home" | "workspace" | "top_level" | "mounted_drive";
|
|
12
|
-
/** The protected locations a removal is judged against
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
12
|
+
/** The protected locations a removal is judged against, each at its spelling and at the location the environment answers
|
|
13
|
+
* for it (a link, an alias or a mapped drive leads to one location: it is protected however it is reached). `homes`: the
|
|
14
|
+
* environment's declared home; `workspace`: the task root, the additional working directories — and, judged at one removal
|
|
15
|
+
* ({@link removalSeatAt}), the working directory; `startedIn`: the directory the command starts in (its spelling and its
|
|
16
|
+
* answered location), the removal's working directory wherever the plan does not prove the removal's shell left it
|
|
17
|
+
* (absent: `workspace` holds every one); `departures`: the plan's working-directory bases PROVEN to stand outside
|
|
18
|
+
* `startedIn` ({@link departuresOf}), each as the plan spells it (absent or empty: no base is). */
|
|
18
19
|
export interface RemovalSeat {
|
|
19
20
|
readonly homes: readonly string[];
|
|
20
21
|
readonly workspace: readonly string[];
|
|
21
|
-
readonly startedIn?: string;
|
|
22
|
+
readonly startedIn?: readonly string[];
|
|
22
23
|
readonly departures?: ReadonlySet<string>;
|
|
23
24
|
}
|
|
24
|
-
/** One dangerous removal a command makes: the removal program, the operand as written, the
|
|
25
|
+
/** One dangerous removal a command makes: the removal program, the operand as written, and the location judged
|
|
26
|
+
* protected — the cell the guard judged ({@link JudgedRemoval}), which the question names. */
|
|
25
27
|
export interface DangerousRemoval {
|
|
26
28
|
readonly kind: DangerousRemovalKind;
|
|
27
29
|
readonly program: string;
|
|
28
30
|
readonly operand: string;
|
|
29
31
|
readonly target: string;
|
|
30
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Where the environment answers a directory a removal empties is: the location `<dir>/*` reaches through a link, a link to
|
|
35
|
+
* a link, an alias or a mapped drive — `answered(dir)`, the environment's answer for the directory as spelled ({@link
|
|
36
|
+
* answeredLocation}), `undefined` where it gave none. The removal is judged there by the same pattern (`<answered dir>/*`),
|
|
37
|
+
* so it reads as the same removal written by the directory's own name.
|
|
38
|
+
*/
|
|
39
|
+
type AnsweredDirectory = (dir: string) => string | undefined;
|
|
31
40
|
/**
|
|
32
41
|
* The ONE dangerous-removal predicate: is removing this absolute path removing a protected location? The reference
|
|
33
42
|
* implementation's set — the filesystem root (a drive root, a UNC share root), a home directory
|
|
@@ -35,12 +44,13 @@ export interface DangerousRemoval {
|
|
|
35
44
|
* additional working directory — whether the home lies inside the task root or the task root inside the home), a top-level
|
|
36
45
|
* directory (one segment below the root) — and, for an `rm` that walks what it removes (`rm`: present; `recursive`: it
|
|
37
46
|
* selects a recursive option; or the path names every entry of a directory), a mounted drive ({@link MOUNTED_DRIVE_KEY}):
|
|
38
|
-
* the folder that holds drives, a drive, or an entry at a drive's top level. `
|
|
39
|
-
*
|
|
47
|
+
* the folder that holds drives, a drive, or an entry at a drive's top level. `every`: the run that names every entry for the
|
|
48
|
+
* operand this path is a cell of ({@link everyEntryRunOf}; a run of `*` by default). Judged by the keys as written, then — only
|
|
49
|
+
* where they find nothing — by the keys' drive reading ({@link KeyReading}). `undefined` for a relative path or any other target.
|
|
40
50
|
*/
|
|
41
51
|
export declare function dangerousRemovalOf(path: string, seat: RemovalSeat, rm?: {
|
|
42
52
|
readonly recursive: boolean;
|
|
43
|
-
}): DangerousRemovalKind | undefined;
|
|
53
|
+
}, every?: RegExp): DangerousRemovalKind | undefined;
|
|
44
54
|
/** What one removal finding asks: a protected location (`dangerous_delete`; `untrackedFrom` — the segment the working
|
|
45
55
|
* directory stops being tracked at, where the target is relative and was judged where the text stood then); a recursive
|
|
46
56
|
* forced removal whose target the
|
|
@@ -48,7 +58,7 @@ export declare function dangerousRemovalOf(path: string, seat: RemovalSeat, rm?:
|
|
|
48
58
|
* (`rewritten`), the operands of a removal its argv stream fills in (`stream`), or an operand relative to the directory a
|
|
49
59
|
* launcher option moved the removal into (`relocated`); or a shell handed text the engine cannot read
|
|
50
60
|
* (`unverifiable_shell_text`) — a text a program produces (`produced`: what a pipe or a `<(…)` carries, an argv a stream
|
|
51
|
-
* fills in, a substitution, a program word taken from a positional parameter), a text nobody read (`unread`: one the lexer could not read
|
|
61
|
+
* fills in, a substitution, a program word taken from a positional parameter), a text nobody read (`unread`: one the lexer could not read, all of it or the rest from where it stopped, {@link unreadPlan}), or a
|
|
52
62
|
* segment whose program the walk could not name (`position`, {@link programUnread}: the program-position reader's own refusal
|
|
53
63
|
* of the segment's argv, the reading the planner declined it by). */
|
|
54
64
|
export type RemovalFinding = (DangerousRemoval & {
|
|
@@ -99,9 +109,11 @@ export declare const KNOWN_SAFE_ROOTS: readonly string[];
|
|
|
99
109
|
* where it lands, as `rm -rf ./build` is. A shell handed a text the engine cannot read — one a program produces
|
|
100
110
|
* ({@link runtimeScriptOf}), or one nobody read ({@link unreadPlan}, {@link programUnread}) — is an unreadable text of its
|
|
101
111
|
* own, and so is a segment whose program word takes its value from the command's own text ({@link programWordFromOwnText}: a positional
|
|
102
|
-
* parameter, a name the text set, a substitution): which program runs is built when the command runs.
|
|
112
|
+
* parameter, a name the text set, a substitution): which program runs is built when the command runs. Text nobody read never
|
|
113
|
+
* stands in for the text that was read: what the lexer read in full before it stopped is judged as any text's (bash runs
|
|
114
|
+
* those lines), beside the finding of the rest. The read-face copy of an operand is not judged: it follows a link the removal does not follow.
|
|
103
115
|
*/
|
|
104
|
-
export declare function removalFindingsOf(established: EstablishedPlan, seat: RemovalSeat, safeRoots?: readonly string[],
|
|
116
|
+
export declare function removalFindingsOf(established: EstablishedPlan, seat: RemovalSeat, safeRoots?: readonly string[], answered?: AnsweredDirectory): RemovalFinding[];
|
|
105
117
|
/** Does the removal program refuse this operand by its own first step — its last path component is `.` or `..`, trailing
|
|
106
118
|
* separators stripped (POSIX `rm` step 1, which GNU, BSD and BusyBox `rm` keep; `rmdir(2)` fails on such a component
|
|
107
119
|
* too)? It removes nothing there, wherever the name lands. The name is the one the program RECEIVES: a pattern's match
|
|
@@ -131,14 +143,18 @@ export interface RemovalGuardSeat {
|
|
|
131
143
|
/**
|
|
132
144
|
* The removal guard's READING of one command — undefined when no segment of it (nested shell text included) runs a
|
|
133
145
|
* removal program or hands a shell a script built when it runs, and every text in it was read, so a command that removes
|
|
134
|
-
* nothing costs the gate no suspension (a text the lexer could not read is not one:
|
|
135
|
-
* syntax error,
|
|
146
|
+
* nothing costs the gate no suspension (a text the lexer could not read to its end is not one: the rest is a finding of its
|
|
147
|
+
* own, and the lines before its syntax error, which bash runs, are judged as any). Otherwise `judge` establishes the plan the read
|
|
136
148
|
* station plans (the same planner, the same value table, the same write-target reading) lexically against the request's
|
|
137
149
|
* `cwd` and the seat's home, and — where an environment is seated — through its resolver too, and returns what either
|
|
138
150
|
* establishment finds ({@link removalFindingsOf}: the protected-location word first, then the unverifiable target, then the
|
|
139
|
-
* unreadable text).
|
|
151
|
+
* unreadable text). One location is one location however it is reached: with an environment seated, every protected location
|
|
152
|
+
* is held at its spelling and where the environment answers it is ({@link RemovalSeat}), and a directory a removal empties is
|
|
153
|
+
* judged where the environment answers it is ({@link AnsweredDirectory}); a location it gives no answer for is judged by its
|
|
154
|
+
* spelling alone.
|
|
140
155
|
* `safeRoots`: the known-safe roots ({@link KNOWN_SAFE_ROOTS}, with a deployment's own added by the policy).
|
|
141
156
|
*/
|
|
142
157
|
export declare function removalReadingOf(command: string, req: Pick<ToolCallRequest, "cwd" | "root">, seat: RemovalGuardSeat | undefined, safeRoots?: readonly string[]): {
|
|
143
158
|
judge(signal?: AbortSignal): Promise<RemovalVerdict | undefined>;
|
|
144
159
|
} | undefined;
|
|
160
|
+
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { posix, win32 } from "node:path";
|
|
1
2
|
import { planShellReads } from "./shell-read-plan.js";
|
|
2
3
|
import { literalTextOf, SUBSTITUTION_PLACEHOLDER } from "../../shell/lex.js";
|
|
3
4
|
import { createShellReadEstablisher, establishShellReadsLexically } from "./shell-read-establish.js";
|
|
4
5
|
import { isAbsoluteForFamily, isWinFormPath, normalizeAbsPathLexically } from "./safety.js";
|
|
6
|
+
import { isDeviceSpelling, localDriveSpellingOf, nativeSepOf } from "../../core/unc-spelling.js";
|
|
5
7
|
import { launchedCommands, launchedReadings, reentryText, runsStoredLine, scriptFileAt, spellLaunched, streamSuppliesOnlyData } from "./shell-reentry-text.js";
|
|
6
8
|
import { programPositionRefusalSentence, readProgramPosition } from "./bash-program-position.js";
|
|
7
9
|
import { bashClassifyDefaultAllow } from "./bash-readonly-classifier.js";
|
|
@@ -11,32 +13,76 @@ import { inlineUntrusted } from "../../core/untrusted-text.js";
|
|
|
11
13
|
export const SHELL_REMOVAL_COMMANDS = Object.freeze(["rm", "rmdir"]);
|
|
12
14
|
const REMOVAL_COMMAND_SET = new Set(SHELL_REMOVAL_COMMANDS);
|
|
13
15
|
function removalSeatAt(seat, plan, segment, apart) {
|
|
14
|
-
const started = seat.startedIn;
|
|
15
|
-
const left = started
|
|
16
|
-
return { homes: seat.homes, workspace: [...seat.workspace, ...(left
|
|
16
|
+
const started = seat.startedIn ?? [];
|
|
17
|
+
const left = started.length > 0 && !apart && segment.bases !== "unmodelled" && segment.bases.length > 0 && segment.bases.every((b) => seat.departures?.has(b) === true) && !plan.shape.backgrounded;
|
|
18
|
+
return { homes: seat.homes, workspace: [...seat.workspace, ...(left ? [] : started)] };
|
|
17
19
|
}
|
|
18
20
|
function standsWithin(path, dir) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
return KEY_READINGS.some((reading) => {
|
|
22
|
+
const k = removalKey(path, STAR_RUN, reading);
|
|
23
|
+
const d = removalKey(dir, STAR_RUN, reading);
|
|
24
|
+
return k === d || k.startsWith(d.endsWith("/") ? d : `${d}/`);
|
|
25
|
+
});
|
|
22
26
|
}
|
|
23
|
-
async function departuresOf(plan, startedIn, env, signal) {
|
|
24
|
-
const start = await resolvedOrUndefined(env.canonicalPath(startedIn, signal), signal);
|
|
27
|
+
async function departuresOf(plan, startedIn, start, env, signal) {
|
|
25
28
|
const out = new Set();
|
|
26
|
-
if (start === undefined
|
|
29
|
+
if (start === undefined)
|
|
27
30
|
return out;
|
|
28
31
|
for (const base of new Set(plan.segments.flatMap((s) => (s.bases === "unmodelled" ? [] : s.bases)))) {
|
|
29
|
-
if (standsWithin(base, startedIn) || standsWithin(base, start
|
|
32
|
+
if (standsWithin(base, startedIn) || standsWithin(base, start))
|
|
30
33
|
continue;
|
|
31
|
-
const canonical = await
|
|
32
|
-
if (canonical !== undefined &&
|
|
33
|
-
out.add(
|
|
34
|
+
const canonical = await answeredLocation(env, base, signal);
|
|
35
|
+
if (canonical !== undefined && !standsWithin(canonical, start))
|
|
36
|
+
out.add(base);
|
|
34
37
|
}
|
|
35
38
|
return out;
|
|
36
39
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
const EVERY_ENTRY_SEGMENT = String.raw `(?:\*+(?:\?\**)?|\?\*+|\**\[[!^]\.\]\*+)`;
|
|
41
|
+
const STAR_RUN = /(?:[\\/]+\*+)+[\\/]*$/;
|
|
42
|
+
const ENTRY_SEGMENT = new RegExp(`^${EVERY_ENTRY_SEGMENT}$`);
|
|
43
|
+
function bareRunOf(word, windows) {
|
|
44
|
+
const units = word.pieces.flatMap((p) => {
|
|
45
|
+
const glob = p.expansion?.pattern;
|
|
46
|
+
if (glob !== undefined) {
|
|
47
|
+
const negated = /^\[[!^]/.test(glob.written) && /^\.+$/.test(glob.folded.slice(2, -1));
|
|
48
|
+
return [{ folded: glob.folded, ...(glob.folded.length === 1 ? { entry: glob.folded } : negated ? { entry: "[!.]" } : {}) }];
|
|
49
|
+
}
|
|
50
|
+
return p.literal === undefined ? [{}] : [...p.literal].map((c) => (c === "/" || (windows && c === "\\") ? { sep: true } : {}));
|
|
51
|
+
});
|
|
52
|
+
const run = [];
|
|
53
|
+
let end = units.length;
|
|
54
|
+
while (end > 0 && units[end - 1].sep === true)
|
|
55
|
+
end--;
|
|
56
|
+
while (end > 0) {
|
|
57
|
+
let start = end;
|
|
58
|
+
while (start > 0 && units[start - 1].sep !== true)
|
|
59
|
+
start--;
|
|
60
|
+
const segment = units.slice(start, end);
|
|
61
|
+
if (!segment.every((u) => u.entry !== undefined) || !ENTRY_SEGMENT.test(segment.map((u) => u.entry).join("")))
|
|
62
|
+
break;
|
|
63
|
+
run.unshift(segment.map((u) => u.folded).join(""));
|
|
64
|
+
end = start;
|
|
65
|
+
while (end > 0 && units[end - 1].sep === true)
|
|
66
|
+
end--;
|
|
67
|
+
}
|
|
68
|
+
return run;
|
|
69
|
+
}
|
|
70
|
+
const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
71
|
+
const exactRun = (segments) => new RegExp(`${segments.map((s) => `[\\\\/]+${escapeRegExp(s)}`).join("")}[\\\\/]*$`);
|
|
72
|
+
function everyEntryRunOf(read, word) {
|
|
73
|
+
const windows = isWinFormPath(read.target ?? read.origin ?? read.candidate.spelled);
|
|
74
|
+
const bare = read.candidate.expands === "glob" && word !== undefined ? bareRunOf(word, windows) : [];
|
|
75
|
+
if (bare.every((s) => /^\*+$/.test(s)))
|
|
76
|
+
return () => STAR_RUN;
|
|
77
|
+
const exact = exactRun(bare);
|
|
78
|
+
const listed = read.established === "expansion" ? read.target : undefined;
|
|
79
|
+
return (view) => (view !== listed && exact.test(view) ? exact : STAR_RUN);
|
|
80
|
+
}
|
|
81
|
+
const trailingSeparatorOf = (read) => /\/+$/.exec(read.candidate.raw)?.[0] ?? "";
|
|
82
|
+
function removalKey(path, every = STAR_RUN, reading = "as_written") {
|
|
83
|
+
const read = reading === "drive" ? (localDriveSpellingOf(path) ?? path) : path;
|
|
84
|
+
let k = normalizeAbsPathLexically(read.normalize("NFC")).replace(/\\/g, "/").toLowerCase();
|
|
85
|
+
k = k.replace(every, "");
|
|
40
86
|
const drive = driveOf(path, k);
|
|
41
87
|
let rest = k.slice(drive.length);
|
|
42
88
|
if (rest === "")
|
|
@@ -45,45 +91,88 @@ function removalKey(path) {
|
|
|
45
91
|
rest = rest.replace(/\/+$/, "");
|
|
46
92
|
return drive + rest.replace(/^\/private\/(etc|var|tmp|home)(?=\/|$)/, "/$1");
|
|
47
93
|
}
|
|
94
|
+
const KEY_READINGS = ["as_written", "drive"];
|
|
48
95
|
function driveOf(path, key) {
|
|
49
96
|
return isWinFormPath(path) && key.length >= 2 && key[1] === ":" ? key.slice(0, 2) : "";
|
|
50
97
|
}
|
|
51
98
|
const MOUNTED_DRIVE_KEY = /^\/(?:system\/)?volumes(?:\/[^/]+){0,2}$|^\/mnt\/(?:[^/]+|[a-z]\/[^/]+)$|^\/(?:run\/)?media(?:\/[^/]+){0,3}$/;
|
|
52
|
-
|
|
53
|
-
|
|
99
|
+
function segmentsUp(path, levels) {
|
|
100
|
+
const family = isWinFormPath(path) ? win32 : posix;
|
|
101
|
+
let at = path;
|
|
102
|
+
for (let i = 0; i < levels; i++)
|
|
103
|
+
at = family.dirname(at);
|
|
104
|
+
return at;
|
|
105
|
+
}
|
|
106
|
+
const runParts = (run) => run.match(/[\\/]+[^\\/]+/g) ?? [];
|
|
107
|
+
const runAt = (dir, run) => `${dir.replace(isWinFormPath(dir) ? /[\\/]+$/ : /\/+$/, "")}${run.replace(/[\\/]+/g, nativeSepOf(dir))}`;
|
|
108
|
+
function emptiedDirectoriesOf(read, views, everyFor) {
|
|
109
|
+
const tail = trailingSeparatorOf(read);
|
|
110
|
+
const levelOf = (every, parts) => (every === STAR_RUN ? STAR_RUN : exactRun(parts.map((p) => p.replace(/^[\\/]+/, ""))));
|
|
111
|
+
const every = read.origin !== undefined ? everyFor(read.origin) : STAR_RUN;
|
|
112
|
+
const pattern = read.established === "expansion" && read.origin !== undefined ? every.exec(read.origin) : null;
|
|
113
|
+
if (pattern !== null) {
|
|
114
|
+
const match = read.spellings.find((s) => s !== read.origin);
|
|
115
|
+
const parts = runParts(pattern[0]);
|
|
116
|
+
return match === undefined ? [] : parts.map((_, i) => ({ dir: segmentsUp(match, parts.length - i), run: `${parts.slice(i).join("")}${tail}`, every: levelOf(every, parts.slice(i)) }));
|
|
117
|
+
}
|
|
118
|
+
return views.flatMap((view) => {
|
|
119
|
+
const viewEvery = everyFor(view);
|
|
120
|
+
const m = viewEvery.exec(view);
|
|
121
|
+
return m === null ? [] : [{ dir: segmentsUp(view, runParts(m[0]).length), run: `${runParts(m[0]).join("")}${tail}`, every: viewEvery }];
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export function dangerousRemovalOf(path, seat, rm, every = STAR_RUN) {
|
|
54
125
|
if (!isAbsoluteForFamily("own", path))
|
|
55
126
|
return undefined;
|
|
56
|
-
|
|
127
|
+
return removalKindIn("as_written", path, seat, rm, every) ?? removalKindIn("drive", path, seat, rm, every);
|
|
128
|
+
}
|
|
129
|
+
function removalKindIn(reading, path, seat, rm, every) {
|
|
130
|
+
const k = removalKey(path, every, reading);
|
|
57
131
|
const drive = driveOf(path, k);
|
|
58
132
|
const rest = k.slice(drive.length);
|
|
59
133
|
if (rest === "/" || /^\/\/[^/]+\/[^/]+$/.test(k))
|
|
60
134
|
return "filesystem_root";
|
|
61
|
-
if (seat.homes.some((h) => isAbsoluteForFamily("own", h) && removalKey(h) === k))
|
|
135
|
+
if (seat.homes.some((h) => isAbsoluteForFamily("own", h) && removalKey(h, STAR_RUN, reading) === k))
|
|
62
136
|
return "home";
|
|
63
137
|
const prefix = k.endsWith("/") ? k : `${k}/`;
|
|
64
|
-
if (seat.workspace.some((w) => isAbsoluteForFamily("own", w) && (removalKey(w) === k || removalKey(w).startsWith(prefix))))
|
|
138
|
+
if (seat.workspace.some((w) => isAbsoluteForFamily("own", w) && (removalKey(w, STAR_RUN, reading) === k || removalKey(w, STAR_RUN, reading).startsWith(prefix))))
|
|
65
139
|
return "workspace";
|
|
66
140
|
if (/^\/[^/]+$/.test(rest))
|
|
67
141
|
return "top_level";
|
|
68
|
-
if (rm !== undefined && (rm.recursive ||
|
|
142
|
+
if (rm !== undefined && (rm.recursive || every.test(path)) && drive === "" && !k.startsWith("//") && MOUNTED_DRIVE_KEY.test(rest))
|
|
69
143
|
return "mounted_drive";
|
|
70
144
|
return undefined;
|
|
71
145
|
}
|
|
72
|
-
function tildeNamesAHome(spelled) {
|
|
146
|
+
function tildeNamesAHome(spelled, everyFor) {
|
|
73
147
|
const m = /^~([^/]*)(\/.*)?$/.exec(spelled);
|
|
74
148
|
if (m === null)
|
|
75
149
|
return false;
|
|
76
|
-
const
|
|
150
|
+
const home = `/~home${m[2] ?? ""}`;
|
|
151
|
+
const key = removalKey(home, everyFor(home));
|
|
77
152
|
return key === "/~home" || !key.startsWith("/~home/");
|
|
78
153
|
}
|
|
79
|
-
function removalKindOf(read, seat, rm) {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
154
|
+
function removalKindOf(read, word, seat, rm, answered) {
|
|
155
|
+
const everyFor = everyEntryRunOf(read, word);
|
|
156
|
+
const unplaced = read.established === "unestablishable";
|
|
157
|
+
const floors = unplaced && read.candidate.bases === "unmodelled" ? read.spellings : [];
|
|
158
|
+
const views = [read.target, read.origin, ...floors].filter((v) => v !== undefined);
|
|
159
|
+
const assumed = new Set([...floors, ...(isDeviceSpelling(read.candidate.spelled) && read.target !== undefined ? [read.target] : [])]);
|
|
160
|
+
const tail = trailingSeparatorOf(read);
|
|
161
|
+
for (const view of views) {
|
|
162
|
+
const every = everyFor(view);
|
|
163
|
+
const kind = dangerousRemovalOf(view, seat, rm, every);
|
|
83
164
|
if (kind !== undefined)
|
|
84
|
-
return kind;
|
|
165
|
+
return { kind, at: assumed.has(view) ? read.candidate.spelled : tail !== "" && every.test(view) ? `${view.replace(/[\\/]+$/, "")}${tail}` : view };
|
|
85
166
|
}
|
|
86
|
-
|
|
167
|
+
for (const { dir, run, every } of emptiedDirectoriesOf(read, views, everyFor)) {
|
|
168
|
+
const answer = isAbsoluteForFamily("own", dir) ? answered(dir) : undefined;
|
|
169
|
+
for (const at of [...(answer !== undefined ? [runAt(answer, run)] : []), runAt(dir, run)]) {
|
|
170
|
+
const kind = dangerousRemovalOf(at, seat, rm, every);
|
|
171
|
+
if (kind !== undefined)
|
|
172
|
+
return { kind, at };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return unplaced && tildeNamesAHome(read.candidate.spelled, everyFor) ? { kind: "home", at: read.candidate.spelled } : undefined;
|
|
87
176
|
}
|
|
88
177
|
export const KNOWN_SAFE_ROOTS = Object.freeze(["TMPDIR", "HOME"]);
|
|
89
178
|
function belowKnownSafeRoot(word, safe, segment) {
|
|
@@ -113,9 +202,11 @@ function selectsOptions(row, args, shellChooses, ...wanted) {
|
|
|
113
202
|
return wanted.every((has) => selected.some(has) || (shellChooses && declaresOption(view, has)));
|
|
114
203
|
});
|
|
115
204
|
}
|
|
116
|
-
export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOTS,
|
|
117
|
-
|
|
118
|
-
|
|
205
|
+
export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOTS, answered = () => undefined) {
|
|
206
|
+
const unread = unreadPlan(established.plan) ? [{ guard: "unverifiable_shell_text", program: "bash", text: established.plan.unreadable, source: "unread" }] : [];
|
|
207
|
+
return [...unread, ...segmentFindingsOf(established, seat, safeRoots, answered, false, false)];
|
|
208
|
+
}
|
|
209
|
+
function segmentFindingsOf(established, seat, safeRoots, answered, enclosingRelocated, apart) {
|
|
119
210
|
const out = [];
|
|
120
211
|
const safe = new Set(safeRoots);
|
|
121
212
|
for (const segment of established.plan.segments) {
|
|
@@ -139,15 +230,15 @@ export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOT
|
|
|
139
230
|
continue;
|
|
140
231
|
if (refusedByRemoval(read))
|
|
141
232
|
continue;
|
|
142
|
-
const
|
|
143
|
-
|
|
233
|
+
const word = segment.argv.find((w) => w.raw === read.candidate.raw);
|
|
234
|
+
const judged = removalKindOf(read, word, removalSeatAt(seat, established.plan, segment, apart), rm, answered);
|
|
235
|
+
if (judged !== undefined) {
|
|
144
236
|
const untracked = read.candidate.bases === "unmodelled" ? established.plan.segments.find((s) => s.bases === "unmodelled")?.text.trim() : undefined;
|
|
145
|
-
out.push({ guard: "dangerous_delete", kind, program: removal.program, operand: read.candidate.raw, target:
|
|
237
|
+
out.push({ guard: "dangerous_delete", kind: judged.kind, program: removal.program, operand: read.candidate.raw, target: judged.at, ...(untracked !== undefined ? { untrackedFrom: untracked } : {}) });
|
|
146
238
|
continue;
|
|
147
239
|
}
|
|
148
240
|
if (!forced || read.established !== "unestablishable" || (read.candidate.expands !== "unresolvable" && !relocated))
|
|
149
241
|
continue;
|
|
150
|
-
const word = segment.argv.find((w) => w.raw === read.candidate.raw);
|
|
151
242
|
if (word !== undefined && belowKnownSafeRoot(word, safe, segment))
|
|
152
243
|
continue;
|
|
153
244
|
out.push({ guard: "unverifiable_delete", program: removal.program, operand: read.candidate.raw, source: read.candidate.expands === "unresolvable" ? "rewritten" : "relocated" });
|
|
@@ -165,13 +256,11 @@ export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOT
|
|
|
165
256
|
}
|
|
166
257
|
const handedRelocated = enclosingRelocated || position.baseMovedAt.length > 0;
|
|
167
258
|
for (const nested of segment.nested) {
|
|
168
|
-
if (unreadPlan(nested))
|
|
259
|
+
if (unreadPlan(nested))
|
|
169
260
|
out.push({ guard: "unverifiable_shell_text", program: program ?? segment.text.trim(), text: segment.text.trim(), source: "unread" });
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
261
|
const sub = established.nested.get(nested);
|
|
173
262
|
if (sub !== undefined)
|
|
174
|
-
out.push(...
|
|
263
|
+
out.push(...segmentFindingsOf(sub, seat, safeRoots, answered, handedRelocated, true));
|
|
175
264
|
}
|
|
176
265
|
}
|
|
177
266
|
return out;
|
|
@@ -206,7 +295,7 @@ function runtimeScriptOf(segment, dataContext = false) {
|
|
|
206
295
|
const text = texts.find((t) => t?.includes(MARK) === true);
|
|
207
296
|
return text === undefined ? undefined : text.split(MARK).join("");
|
|
208
297
|
}
|
|
209
|
-
const unreadPlan = (plan) => plan.unreadable !== undefined && plan.segments.length === 0;
|
|
298
|
+
const unreadPlan = (plan) => plan.unreadable !== undefined && (plan.unreadTail !== undefined || plan.segments.length === 0);
|
|
210
299
|
const programUnread = (s) => s.declines.includes("unreadable_program_position");
|
|
211
300
|
const unsettledProgramReads = (s) => s.verb === undefined ? [] : s.reads.filter((c) => c.provenance === "program_path" && c.expands === "unresolvable");
|
|
212
301
|
const programNameUnsettled = (s) => unsettledProgramReads(s).length > 0;
|
|
@@ -252,18 +341,18 @@ const REMOVAL_GUARD_SENTENCE = {
|
|
|
252
341
|
},
|
|
253
342
|
},
|
|
254
343
|
unverifiable_delete: {
|
|
255
|
-
card: (row) => `
|
|
344
|
+
card: (row) => `This delete could not be checked first: ${row}. Writing the exact path into the command (or setting the variable to a literal path in the same command, e.g. \`DIR=/exact/path; rm -rf "$DIR"\`) lets the engine check it.`,
|
|
256
345
|
rows: {
|
|
257
|
-
rewritten: (f) => `\`${f.program}\`
|
|
258
|
-
stream: (f) => `\`${f.program}\`
|
|
259
|
-
relocated: (f) => `\`${f.program}\`
|
|
346
|
+
rewritten: (f) => `\`${f.program}\` deletes ${inlineUntrusted(f.operand, 200)} recursively and by force, and the shell fills that path in from a value this command does not set (a name with no value here or one set in a form the engine cannot read, a substitution, a parameter operator)`,
|
|
347
|
+
stream: (f) => `\`${f.program}\` deletes recursively and by force the paths named by the input it is fed (${inlineUntrusted(f.operand, 200)})`,
|
|
348
|
+
relocated: (f) => `\`${f.program}\` deletes ${inlineUntrusted(f.operand, 200)} recursively and by force, relative to a directory a launcher option moved it into, which this command does not say`,
|
|
260
349
|
},
|
|
261
350
|
},
|
|
262
351
|
unverifiable_shell_text: {
|
|
263
|
-
card: (row) => `
|
|
352
|
+
card: (row) => `This command could not be checked first: ${row}.`,
|
|
264
353
|
rows: {
|
|
265
|
-
produced: (f) => `\`${f.program}\` runs shell text that is
|
|
266
|
-
unread: (f) => `\`${f.program}\` runs shell text
|
|
354
|
+
produced: (f) => `\`${f.program}\` runs shell text that is only put together when the command runs (${inlineUntrusted(f.text, 200)}), so the engine cannot read it beforehand — writing that text into the command itself (a \`-c\` string, a here-document or a here-string) lets the engine read it. Where values are data, pass them as whole quoted operands after \`--\` in a literal script, e.g. \`sh -c 'cat -- "$1"' _ VALUE\`; program or expression positions still need review, and read checks still apply`,
|
|
355
|
+
unread: (f) => `\`${f.program}\` runs shell text the engine cannot read (${inlineUntrusted(f.text, 200)})`,
|
|
267
356
|
position: (f) => inlineUntrusted(programPositionRefusalSentence(f.refusal), 400),
|
|
268
357
|
},
|
|
269
358
|
},
|
|
@@ -309,22 +398,32 @@ export function removalReadingOf(command, req, seat, safeRoots = KNOWN_SAFE_ROOT
|
|
|
309
398
|
return {
|
|
310
399
|
async judge(signal) {
|
|
311
400
|
const env = seat?.env;
|
|
312
|
-
const
|
|
313
|
-
const
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const lexical = removalFindingsOf(
|
|
321
|
-
if (lexical.some((f) => f.guard === "dangerous_delete") || env === undefined
|
|
401
|
+
const answer = (p) => (env === undefined ? Promise.resolve(undefined) : answeredLocation(env, p, signal));
|
|
402
|
+
const withAnswers = async (spelled) => [...spelled, ...(await Promise.all(spelled.map(answer))).filter((a) => a !== undefined)];
|
|
403
|
+
const [homes, start] = await Promise.all([withAnswers(homeDir !== undefined ? [homeDir] : []), req.cwd !== undefined ? answer(req.cwd) : undefined]);
|
|
404
|
+
const departures = env !== undefined && req.cwd !== undefined ? await departuresOf(plan, req.cwd, start, env, signal) : undefined;
|
|
405
|
+
const startedIn = req.cwd !== undefined ? { startedIn: [req.cwd, ...(start !== undefined ? [start] : [])] } : {};
|
|
406
|
+
const workspace = [...(req.root !== undefined ? [req.root] : []), ...(seat?.additionalRoots?.() ?? [])];
|
|
407
|
+
const spelledSeat = { homes, workspace, ...startedIn, ...(departures !== undefined ? { departures } : {}) };
|
|
408
|
+
const lexicalPlan = establishShellReadsLexically(plan, boundary);
|
|
409
|
+
const lexical = removalFindingsOf(lexicalPlan, spelledSeat, safeRoots);
|
|
410
|
+
if (lexical.some((f) => f.guard === "dangerous_delete") || env === undefined)
|
|
322
411
|
return verdictOf(lexical);
|
|
323
|
-
const established = await resolvedOrUndefined(createShellReadEstablisher(env, roots, { rootsCanonical: true }).establish(plan, boundary, signal), signal);
|
|
324
|
-
|
|
412
|
+
const established = roots.length === 0 ? undefined : await resolvedOrUndefined(createShellReadEstablisher(env, roots, { rootsCanonical: true }).establish(plan, boundary, signal), signal);
|
|
413
|
+
const plans = established === undefined ? [lexicalPlan] : [established, lexicalPlan];
|
|
414
|
+
const removalSeat = { ...spelledSeat, workspace: await withAnswers(workspace) };
|
|
415
|
+
const wanted = new Set();
|
|
416
|
+
for (const p of plans)
|
|
417
|
+
removalFindingsOf(p, removalSeat, safeRoots, (dir) => void wanted.add(dir));
|
|
418
|
+
const answers = new Map(await Promise.all([...wanted].map(async (dir) => [dir, await answer(dir)])));
|
|
419
|
+
return verdictOf(plans.flatMap((p) => removalFindingsOf(p, removalSeat, safeRoots, (dir) => answers.get(dir))));
|
|
325
420
|
},
|
|
326
421
|
};
|
|
327
422
|
}
|
|
423
|
+
async function answeredLocation(env, path, signal) {
|
|
424
|
+
const r = await resolvedOrUndefined(env.canonicalPath(path, signal), signal);
|
|
425
|
+
return r !== undefined && r.ok ? r.value : undefined;
|
|
426
|
+
}
|
|
328
427
|
async function resolvedOrUndefined(leg, signal) {
|
|
329
428
|
let timer;
|
|
330
429
|
try {
|
|
@@ -15,4 +15,4 @@ import type { CwdRef } from "./fs-shared.js";
|
|
|
15
15
|
* (src/core/auto-promote.ts) consumes it in ESCALATE-ONLY mode — a clean scan contributes nothing;
|
|
16
16
|
* it can only ever raise an escalation, never clear one. */
|
|
17
17
|
export declare function extractSymbols(text: string): string[];
|
|
18
|
-
export declare function createRepoMapTool(env: ExecutionEnv, rootCanonical: string, rootsSeat?: RootsSeat, denySeat?: ReadDenyMatcher, readFace?: ContainmentFace, cwdRef?: CwdRef, readAdmission?: (toolCallId: string | undefined, canonicalKey: string) => boolean): AgentTool;
|
|
18
|
+
export declare function createRepoMapTool(env: ExecutionEnv, rootCanonical: string, rootsSeat?: RootsSeat, denySeat?: ReadDenyMatcher, readFace?: ContainmentFace, cwdRef?: CwdRef, readAdmission?: (toolCallId: string | undefined, canonicalKey: string) => boolean, outsideRemedy?: string): AgentTool;
|
|
@@ -83,7 +83,7 @@ function rankEntries(a, b) {
|
|
|
83
83
|
return b.symbols.length - a.symbols.length;
|
|
84
84
|
return a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0;
|
|
85
85
|
}
|
|
86
|
-
export function createRepoMapTool(env, rootCanonical, rootsSeat, denySeat, readFace, cwdRef, readAdmission) {
|
|
86
|
+
export function createRepoMapTool(env, rootCanonical, rootsSeat, denySeat, readFace, cwdRef, readAdmission, outsideRemedy) {
|
|
87
87
|
const declaredTarget = toolFace("repo-map").pathTarget;
|
|
88
88
|
return defineTool({
|
|
89
89
|
name: "RepoMap",
|
|
@@ -107,7 +107,7 @@ export function createRepoMapTool(env, rootCanonical, rootsSeat, denySeat, readF
|
|
|
107
107
|
const scopeSpelling = declaredTarget === undefined ? undefined : pathTargetValue(a, declaredTarget);
|
|
108
108
|
if (scopeSpelling !== undefined) {
|
|
109
109
|
const baseCwd = pathTargetBaseOf(declaredTarget, { root: rootCanonical, cwd: cwdRef?.current });
|
|
110
|
-
const r = await resolveKey(env, rootCanonical, scopeSpelling, signal, baseCwd, additionalRoots, readAdmission && ((key) => readAdmission(ctx.toolCallId, key)), readDeny, readFace);
|
|
110
|
+
const r = await resolveKey(env, rootCanonical, scopeSpelling, signal, baseCwd, additionalRoots, readAdmission && ((key) => readAdmission(ctx.toolCallId, key)), readDeny, readFace, outsideRemedy);
|
|
111
111
|
if (!r.ok)
|
|
112
112
|
return errorResult(violationText("RepoMap", r.violation), violationDetails(r.violation));
|
|
113
113
|
start = r.key;
|
|
@@ -122,6 +122,10 @@ export declare function startsWithDriveLetter(p: string): boolean;
|
|
|
122
122
|
/** Does this absolute spelling name the opening process's STANDARD INPUT (`/dev/stdin`, `/dev/fd/0`, `/proc/<pid>/fd/0`),
|
|
123
123
|
* folded lexically first (`/dev/./stdin`, `/dev//fd/0`)? */
|
|
124
124
|
export declare function namesStandardInput(path: string): boolean;
|
|
125
|
+
export declare function isProcSensitiveFile(key: string): boolean;
|
|
126
|
+
export declare function holdsProcSensitiveFile(dir: string): boolean;
|
|
127
|
+
export declare function ownProcessSpelling(spelled: string): string | undefined;
|
|
128
|
+
export declare function belowOwnProcessLink(spelled: string, walks?: boolean): boolean;
|
|
125
129
|
/**
|
|
126
130
|
* Expand a LEADING `~` (bare, or followed by a separator of either family) against `home`; every other
|
|
127
131
|
* spelling is returned untouched — a `~` anywhere but the front is an ordinary filename character.
|
|
@@ -302,10 +306,29 @@ export declare function spellingOfIdentity(identity: PathIdentity, family: PathF
|
|
|
302
306
|
export declare function carriesDotSegment(spelled: string, family: PathFamily | undefined): boolean;
|
|
303
307
|
/** A model-spelled path bounded for error text (the spelling is unbounded input). */
|
|
304
308
|
export declare function clipSpelling(spelled: string): string;
|
|
305
|
-
/**
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
+
/**
|
|
310
|
+
* The SHELL's spelling of a drive on a win tree. The win32 adapter runs Git for Windows bash (the MSYS line — the only
|
|
311
|
+
* shells its discovery answers there), which names drive X's root `/x`, either case. A `/`-rooted spelling is read the way
|
|
312
|
+
* that shell reads it: a leading run of three or more `/` is one `/` (exactly two name a UNC or a server there); a backslash
|
|
313
|
+
* separates too; the first segment, ONE ASCII letter, is that drive: `/c/rest` and `/C/rest` ⇒ `C:\rest`, `/c` ⇒ `C:\`. A `..`
|
|
314
|
+
* inside the drive is kept (the walk resolves a link before it steps up, as for every spelling); a `..` that climbs above the
|
|
315
|
+
* drive's root reaches the emulation's own root `/`, so such a spelling is folded first, as a POSIX path (`/c/../d/f` is `/d/f`).
|
|
316
|
+
* `undefined` for every other spelling — the emulation's own tree (`/etc`, `/tmp`, `/cygdrive/…`), a UNC, a backslash-rooted
|
|
317
|
+
* one (Win32's current-drive form) — and on any tree that is not win, where `/c/x` is an ordinary path. The family is the
|
|
318
|
+
* tree's, never the spelling's. The ONE reading of that shell's drive spelling: the shell operand resolver (with
|
|
319
|
+
* {@link shellAnchoredSpellingOf}), the tracked working directory the shell reports, and {@link isShellRootedSpellingUnmapped}.
|
|
320
|
+
*/
|
|
321
|
+
export declare function shellDriveSpellingOf(family: PathFamily | undefined, spelled: string): string | undefined;
|
|
322
|
+
/** A drive path the SHELL anchored itself — a relative operand joined to its working directory, a `~` word to its home — is
|
|
323
|
+
* walked in that shell's namespace: where a `..` climbs above the drive's root it reaches the emulation's root, so the path is
|
|
324
|
+
* read as {@link shellDriveSpellingOf} reads `/x/…` (`C:\proj\..\..\d\f` ⇒ `D:\f`, not the Win32 clamp's `C:\d\f`). `undefined`
|
|
325
|
+
* where no `..` climbs above the drive's root, where the climb lands in the emulation's own tree (`C:\proj\..\..\etc` is `/etc`
|
|
326
|
+
* there, a place only that shell knows — the anchored, clamped reading stands, as before), and for any other spelling or family. */
|
|
327
|
+
export declare function shellAnchoredSpellingOf(family: PathFamily | undefined, anchored: string): string | undefined;
|
|
328
|
+
/** A ROOTED (not qualified) spelling handed to the SHELL on a win tree (`/etc`, `/cygdrive/d/x`, `\\x`) that is not the
|
|
329
|
+
* shell's drive spelling ({@link shellDriveSpellingOf}) is the shell's to map — the win32 adapter runs Git Bash, where
|
|
330
|
+
* `/etc` is the MSYS root, not the cwd's drive root — so no lexical reader may resolve it (fail-closed: the operand is
|
|
331
|
+
* unresolvable). The ONE statement of that rule, for every shell-facing resolver. */
|
|
309
332
|
export declare function isShellRootedSpellingUnmapped(family: PathFamily | undefined, spelled: string): boolean;
|
|
310
333
|
/** The win family's native spelling of a UNC written with any leading-separator mix (`//host/share/x`, `\\/host/…`
|
|
311
334
|
* ⇒ `\\\\host\\share\\x`), for a lexical normalizer that recognises the backslash form only; every other spelling is
|
|
@@ -382,7 +405,7 @@ export declare function resolveKey(env: ExecutionEnv, rootCanonical: string, pat
|
|
|
382
405
|
} | null;
|
|
383
406
|
/** The write face's {@link import("./read-deny.js").WriteDenyMatcher.guardsReads}: the row a hit named also guards reads. */
|
|
384
407
|
guardsReads?(pattern: string): boolean;
|
|
385
|
-
}, containmentFace?: "open" | "roots"): Promise<{
|
|
408
|
+
}, containmentFace?: "open" | "roots", outsideRemedy?: string): Promise<{
|
|
386
409
|
ok: true;
|
|
387
410
|
key: string;
|
|
388
411
|
} | {
|