@sema-agent/core 7.62.0 → 7.64.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 +936 -0
- package/dist/agents/cc-peer-directory.js +1 -0
- package/dist/agents/cc-peer-wire.d.ts +4 -0
- package/dist/agents/cc-peer-wire.js +1 -0
- package/dist/agents/cc-uds-peer-channel.js +5 -0
- package/dist/agents/cross-session-judge.d.ts +3 -1
- package/dist/agents/cross-session-judge.js +4 -1
- package/dist/agents/peer-directory.d.ts +8 -0
- package/dist/agents/peer-directory.js +4 -0
- package/dist/agents/peer-held-queue.d.ts +9 -3
- package/dist/agents/peer-held-queue.js +12 -9
- package/dist/agents/peer-idle.d.ts +20 -1
- package/dist/agents/peer-idle.js +23 -12
- package/dist/agents/peer-notice-route.d.ts +16 -5
- package/dist/agents/peer-notice-route.js +11 -9
- package/dist/agents/peer-notices.d.ts +25 -8
- package/dist/agents/peer-notices.js +6 -1
- package/dist/agents/peer-session-drain.d.ts +32 -6
- package/dist/agents/peer-session-drain.js +100 -26
- package/dist/agents/send-message-tool.d.ts +7 -0
- package/dist/agents/send-message-tool.js +18 -6
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.js +102 -54
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/allow-entry.d.ts +4 -0
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-origin.d.ts +1 -1
- package/dist/core/ask-origin.js +2 -2
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/ask-unresolvable-notice.d.ts +13 -4
- package/dist/core/ask-unresolvable-notice.js +10 -3
- package/dist/core/auto-compaction.d.ts +7 -5
- package/dist/core/background-agent-store.d.ts +7 -0
- package/dist/core/background-agent-store.js +3 -0
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-queries.d.ts +50 -4
- package/dist/core/checkpoint-queries.js +42 -17
- package/dist/core/checkpoint-requirements.d.ts +3 -3
- package/dist/core/checkpoint-requirements.js +2 -1
- package/dist/core/checkpoint-row-verdict.d.ts +15 -4
- package/dist/core/checkpoint-row-verdict.js +22 -2
- package/dist/core/checkpoint-store.d.ts +28 -11
- package/dist/core/checkpoint-store.js +45 -4
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/context-settings.d.ts +40 -9
- package/dist/core/context-settings.js +32 -10
- package/dist/core/engine-attestation.d.ts +27 -7
- package/dist/core/engine-attestation.js +5 -1
- package/dist/core/engine-notice.d.ts +43 -5
- package/dist/core/extension-requester.d.ts +9 -0
- package/dist/core/extension-requester.js +7 -0
- package/dist/core/file-history-store.d.ts +28 -0
- package/dist/core/file-history-store.js +48 -5
- package/dist/core/fs-write-gate-policy.js +1 -1
- package/dist/core/gate-fold.js +2 -0
- package/dist/core/gate-lanes.js +2 -0
- package/dist/core/gate-outcome.d.ts +39 -2
- package/dist/core/gate-outcome.js +20 -1
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +9 -3
- package/dist/core/governance-codes.js +17 -3
- package/dist/core/leg-identity.d.ts +19 -1
- package/dist/core/leg-identity.js +12 -0
- package/dist/core/mailbox-store.d.ts +39 -4
- package/dist/core/mailbox-store.js +14 -2
- package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +74 -10
- package/dist/core/memory-engine/consolidation.js +183 -11
- package/dist/core/memory-engine/control-objects.d.ts +25 -0
- package/dist/core/memory-engine/control-objects.js +151 -0
- package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
- package/dist/core/memory-engine/control-plane-adoption.js +159 -0
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +58 -40
- package/dist/core/memory-engine/delegation-settlement.js +270 -85
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +11 -7
- package/dist/core/memory-engine/engine.d.ts +136 -58
- package/dist/core/memory-engine/engine.js +491 -394
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +62 -60
- package/dist/core/memory-engine/file-backend.js +122 -198
- package/dist/core/memory-engine/index.d.ts +8 -7
- package/dist/core/memory-engine/index.js +7 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +127 -46
- package/dist/core/memory-engine/layout.js +264 -109
- package/dist/core/memory-engine/memory-backend-contract.d.ts +26 -1
- package/dist/core/memory-engine/memory-backend-contract.js +476 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +42 -11
- package/dist/core/memory-engine/memory-deployment.js +54 -15
- package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
- package/dist/core/memory-engine/origin-clearance.js +68 -9
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +37 -2
- package/dist/core/memory-engine/session-write-home.js +38 -11
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +155 -19
- package/dist/core/memory-engine/types.js +2 -0
- package/dist/core/memory.js +15 -6
- package/dist/core/mode-policy.js +3 -3
- package/dist/core/mods/agent-stations.d.ts +18 -0
- package/dist/core/mods/agent-stations.js +8 -6
- package/dist/core/mods/extension-call.d.ts +4 -0
- package/dist/core/mods/extension-call.js +8 -0
- package/dist/core/mods/stations.d.ts +20 -1
- package/dist/core/mods/stations.js +21 -2
- package/dist/core/mods/tool-call.js +3 -4
- package/dist/core/parent-spec-seat.d.ts +2 -2
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/peer-channel.d.ts +5 -0
- package/dist/core/permission-rule-consent.d.ts +26 -8
- package/dist/core/permission-rule-consent.js +76 -36
- package/dist/core/permission-rule-store.d.ts +72 -13
- package/dist/core/permission-rule-store.js +29 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/refusal-echo.d.ts +20 -0
- package/dist/core/refusal-echo.js +33 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/retention.d.ts +180 -10
- package/dist/core/retention.js +45 -0
- package/dist/core/retired-keys.d.ts +5 -0
- package/dist/core/retired-keys.js +3 -0
- package/dist/core/rule-offer-read.d.ts +0 -4
- package/dist/core/rule-offer-read.js +2 -18
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/classifier-ladder.d.ts +7 -1
- package/dist/core/runner/classifier-ladder.js +4 -2
- package/dist/core/runner/compact-session.js +10 -7
- package/dist/core/runner/compaction-call-options.d.ts +7 -7
- package/dist/core/runner/compaction-call-options.js +3 -2
- package/dist/core/runner/contracts.d.ts +39 -11
- package/dist/core/runner/delegation-owner.d.ts +10 -3
- package/dist/core/runner/delegation-owner.js +4 -1
- package/dist/core/runner/gate-exit.d.ts +6 -0
- package/dist/core/runner/gate-exit.js +13 -4
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.d.ts +10 -5
- package/dist/core/runner/memory-consolidation-driver.js +12 -9
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/person-path-rows.d.ts +8 -3
- package/dist/core/runner/person-path-rows.js +5 -1
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-ask-lane.js +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -2
- package/dist/core/runner/prepare-caps-and-workflow.js +7 -4
- package/dist/core/runner/prepare-config-doors.js +4 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +2 -2
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
- package/dist/core/runner/prepare-gate-stations.js +5 -5
- package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
- package/dist/core/runner/prepare-hands-readface.js +5 -4
- package/dist/core/runner/prepare-inherited-gate.d.ts +13 -9
- package/dist/core/runner/prepare-inherited-gate.js +12 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +7 -2
- package/dist/core/runner/prepare-memory.js +41 -39
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-policy-chain.js +7 -7
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-task.js +26 -18
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/resume-admission.d.ts +2 -2
- package/dist/core/runner/resume-admission.js +2 -23
- package/dist/core/runner/role-resolution-table.d.ts +98 -0
- package/dist/core/runner/role-resolution-table.js +62 -0
- package/dist/core/runner/run-compaction-machinery.js +2 -2
- package/dist/core/runner/run-identity-wiring.js +12 -9
- package/dist/core/runner/run-leg.js +9 -5
- package/dist/core/runner/run-notification-lane.js +22 -22
- package/dist/core/runner/run-recovery-lanes.js +3 -3
- package/dist/core/runner/run-settle-and-teardown.js +3 -2
- package/dist/core/runner/run-terminal-adoption.js +1 -1
- package/dist/core/runner/run-turn-boundary.js +14 -15
- package/dist/core/runner/runtask.js +1 -1
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner/tool-occurrence.d.ts +4 -2
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner-deps.d.ts +7 -3
- package/dist/core/secret-env.d.ts +1 -1
- package/dist/core/secret-env.js +4 -4
- package/dist/core/session-checkout.d.ts +168 -0
- package/dist/core/session-checkout.js +579 -0
- package/dist/core/session-store.d.ts +12 -4
- package/dist/core/session-store.js +23 -3
- package/dist/core/session.d.ts +16 -2
- package/dist/core/session.js +3 -0
- package/dist/core/shell-read-silence.js +8 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
- package/dist/core/store-contracts/peer-directory-contract.js +8 -1
- package/dist/core/store-contracts/session-store-contract.js +39 -0
- package/dist/core/task-event.d.ts +30 -5
- package/dist/core/task-notification.d.ts +119 -32
- package/dist/core/task-notification.js +186 -100
- package/dist/core/task-registry-agent.d.ts +25 -2
- package/dist/core/task-registry-agent.js +56 -22
- package/dist/core/task-registry-shared.d.ts +33 -11
- package/dist/core/task-registry.d.ts +33 -9
- package/dist/core/task-registry.js +36 -18
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +27 -2
- package/dist/core/tool-errors.d.ts +14 -6
- package/dist/core/tool-errors.js +1 -1
- package/dist/core/tool-policy.d.ts +32 -13
- package/dist/core/tool-policy.js +27 -17
- package/dist/core/tool-result-store.d.ts +20 -0
- package/dist/core/tool-spec.d.ts +42 -19
- package/dist/core/trace.d.ts +3 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workflow-journal-store.d.ts +11 -0
- package/dist/core/workflow-journal-store.js +7 -0
- package/dist/core/workflow-run-store.d.ts +9 -0
- package/dist/core/workflow-run-store.js +6 -0
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/compaction/compaction.d.ts +2 -1
- package/dist/engine/harness/types.d.ts +67 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +30 -1
- package/dist/engine/session/session.js +48 -1
- package/dist/index.d.ts +12 -7
- package/dist/index.js +12 -7
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +8 -1
- package/dist/orchestration/run-workflow-tool.js +8 -0
- package/dist/orchestration/workflow-types.d.ts +2 -1
- package/dist/orchestration/workflow.d.ts +6 -0
- package/dist/orchestration/workflow.js +5 -2
- package/dist/stores/file/checkpoint-store.d.ts +6 -0
- package/dist/stores/file/checkpoint-store.js +4 -1
- package/dist/stores/file/file-history-store.d.ts +13 -0
- package/dist/stores/file/file-history-store.js +75 -13
- package/dist/stores/file/index.d.ts +11 -1
- package/dist/stores/file/index.js +7 -11
- package/dist/stores/file/permission-rule-store.d.ts +23 -0
- package/dist/stores/file/permission-rule-store.js +75 -7
- package/dist/stores/file/session-store.js +2 -1
- package/dist/stores/file/tool-result-store.d.ts +14 -0
- package/dist/stores/file/tool-result-store.js +39 -2
- package/dist/stores/file/workflow-journal-store.d.ts +4 -0
- package/dist/stores/file/workflow-journal-store.js +17 -0
- package/dist/stores/file/workflow-run-store.d.ts +3 -0
- package/dist/stores/file/workflow-run-store.js +15 -0
- package/dist/tools/fs/bash-program-position.js +3 -3
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +28 -3
- package/dist/tools/fs/read-deny.js +18 -2
- package/dist/tools/fs/removal-targets.js +3 -3
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +8 -1
- package/dist/tools/fs/shell-read-argv.js +34 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
- package/dist/tools/fs/shell-read-bindings.js +5 -1
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.d.ts +8 -2
- package/dist/tools/fs/shell-read-check.js +16 -14
- package/dist/tools/fs/shell-read-establish.js +23 -16
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-plan.d.ts +10 -0
- package/dist/tools/fs/shell-read-plan.js +189 -93
- package/dist/tools/fs/shell-read-start.d.ts +19 -9
- package/dist/tools/fs/shell-read-start.js +20 -12
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
- package/dist/tools/fs/shell-read-workdir.js +73 -12
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +135 -11
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core-stores-sql@7.64.0.json +30 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/core@7.64.0.json +2653 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/mods-kernel@7.64.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/wire-changes/primitives@7.64.0.json +30 -0
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
|
@@ -96,25 +96,30 @@ function basesFor(candidate, boundary) {
|
|
|
96
96
|
const bases = candidate.bases.length > 0 ? candidate.bases : [boundary.cwd ?? boundary.roots[0] ?? ""];
|
|
97
97
|
return candidate.repositoryTop !== undefined ? everyAncestor(bases) : bases;
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
function placedSpellings(spelled, bases, homeDir) {
|
|
100
|
+
const out = [];
|
|
101
|
+
for (const base of bases) {
|
|
102
|
+
const at = resolveOperandSpellings(base === "" ? undefined : base, spelled, homeDir);
|
|
103
|
+
if (at === undefined)
|
|
104
|
+
continue;
|
|
105
|
+
out.push(at.folded);
|
|
106
|
+
if (at.spelled !== undefined)
|
|
107
|
+
out.push(at.spelled);
|
|
102
108
|
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
function lexicalReadsOf(candidate, boundary, placed) {
|
|
112
|
+
const rewritten = candidate.expands === "unresolvable" ? `"${candidate.raw}" is rewritten by the shell before the program sees it` : undefined;
|
|
103
113
|
const bases = placed ?? basesFor(candidate, boundary);
|
|
104
114
|
if (bases === "unmodelled") {
|
|
105
115
|
const floorsAt = candidate.floorBases ?? [boundary.cwd ?? boundary.roots[0] ?? ""];
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (viaFloor === undefined)
|
|
111
|
-
continue;
|
|
112
|
-
spellings.push(viaFloor.folded);
|
|
113
|
-
if (viaFloor.spelled !== undefined)
|
|
114
|
-
spellings.push(viaFloor.spelled);
|
|
115
|
-
}
|
|
116
|
-
return [{ candidate, established: "unestablishable", spellings, cause: `"${candidate.raw}" is relative to a working directory this command's text does not settle` }];
|
|
116
|
+
const spellings = [candidate.spelled, ...placedSpellings(candidate.spelled, floorsAt.filter((f) => f !== ""), boundary.homeDir)];
|
|
117
|
+
const anywhereAbove = candidate.repositoryTop !== undefined || candidate.unsettledStart === true;
|
|
118
|
+
const ancestorViews = anywhereAbove ? [...new Set(placedSpellings(candidate.spelled, everyAncestor(floorsAt.filter((f) => f !== "")), boundary.homeDir))].filter((v) => !spellings.includes(v)) : [];
|
|
119
|
+
return [{ candidate, established: "unestablishable", spellings, ...(ancestorViews.length > 0 ? { ancestorViews } : {}), cause: rewritten ?? `"${candidate.raw}" is relative to a working directory this command's text does not settle` }];
|
|
117
120
|
}
|
|
121
|
+
if (rewritten !== undefined)
|
|
122
|
+
return [{ candidate, established: "unestablishable", spellings: [...new Set([candidate.spelled, ...placedSpellings(candidate.spelled, bases, boundary.homeDir)])], cause: rewritten }];
|
|
118
123
|
const out = [];
|
|
119
124
|
const seen = new Set();
|
|
120
125
|
for (const base of bases) {
|
|
@@ -174,8 +179,10 @@ function writtenByText(plan, boundary) {
|
|
|
174
179
|
return { targets, unplaced };
|
|
175
180
|
}
|
|
176
181
|
function unfollowedBackupReads(j, boundary, cause) {
|
|
177
|
-
const
|
|
178
|
-
const
|
|
182
|
+
const named = sedBackupNames(j.followed.operand.spelled, j.followed.suffix).flatMap((name) => lexicalReadsOf({ ...j.candidate, spelled: name }, boundary));
|
|
183
|
+
const spellings = named.flatMap((r) => [...(r.target !== undefined ? [r.target] : []), ...r.spellings]);
|
|
184
|
+
const ancestorViews = [...new Set(named.flatMap((r) => r.ancestorViews ?? []))];
|
|
185
|
+
const read = { candidate: j.candidate, established: "unestablishable", spellings: [...new Set(spellings)], ...(ancestorViews.length > 0 ? { ancestorViews } : {}), cause };
|
|
179
186
|
return (j.seats ?? ["landing"]).map((seat) => writtenAt(read, j, seat));
|
|
180
187
|
}
|
|
181
188
|
function writtenAt(read, j, seat) {
|
|
@@ -198,6 +198,9 @@ export interface ShellReadBoundary extends BashReadonlyRootBoundary {
|
|
|
198
198
|
/** The deny table's WRITE face (`compileWriteDeny`, read-deny.ts): judges a command's write targets (candidates marked
|
|
199
199
|
* `face: "write"`) and returns the matched row's rule, or null. PRESENT-IFF there is something to judge. */
|
|
200
200
|
readonly writeDenyMatch?: (resolvedPath: string) => string | null;
|
|
201
|
+
/** Does the row `writeDenyMatch` named (its rule) guard the READ face too — a `Read(…)` rule on the write face
|
|
202
|
+
* ({@link import("./read-deny.js").WriteDenyMatcher.guardsReads})? Read once per hit, so the refusal says which family refused. */
|
|
203
|
+
readonly writeDenyGuardsReads?: (pattern: string) => boolean;
|
|
201
204
|
/** The read table's rows AT or BELOW a path (`readDenySeat`'s `denyAtOrBelow`, read-deny.ts): read by the station's
|
|
202
205
|
* `writesPlaced` fact only, through {@link denyRowAtOrBelow}. */
|
|
203
206
|
readonly denyAtOrBelow?: (resolvedPath: string) => string | null;
|
|
@@ -254,6 +257,13 @@ export interface EstablishedRead {
|
|
|
254
257
|
* and the lexical one, read through the same chain reader. Deny views only: not a spelling the
|
|
255
258
|
* command wrote, not a containment candidate, not a write view of its own. Absent ⇒ none read. */
|
|
256
259
|
readonly hops?: readonly string[];
|
|
260
|
+
/** Beside an unplaced read whose start may be any directory at or above its floor — a word made from a directory the text
|
|
261
|
+
* does not know ({@link ReadCandidate.unsettledStart}), an object path relative to a repository top it does not settle
|
|
262
|
+
* ({@link ReadCandidate.repositoryTop}) —: the spelling at each directory above the floor. Views of the word itself, met by
|
|
263
|
+
* the deny rows' match and by nothing else: not where the text stood (that is {@link spellings}, which the removal guard
|
|
264
|
+
* judges), not a containment candidate, and not a place a row may lie below (a recursive read's root, a moved or copied
|
|
265
|
+
* target) — each reaches `/`, below which every row lies. Absent ⇒ none. */
|
|
266
|
+
readonly ancestorViews?: readonly string[];
|
|
257
267
|
/** The pattern or traversal root an `expansion` came from, as folded. */
|
|
258
268
|
readonly origin?: string;
|
|
259
269
|
/** What the environment said the target IS, where a read asked — only a traversal root asks (it lists the root
|
|
@@ -287,6 +297,7 @@ export interface ReadFinding {
|
|
|
287
297
|
readonly pattern: string;
|
|
288
298
|
readonly matchedView: string;
|
|
289
299
|
readonly face?: "write";
|
|
300
|
+
readonly readRow?: true;
|
|
290
301
|
};
|
|
291
302
|
readonly containment: "inside" | "outside" | "open" | "unknown";
|
|
292
303
|
}
|
|
@@ -46,16 +46,16 @@ export function judgeRead(read, boundary) {
|
|
|
46
46
|
const writeTarget = read.candidate.face === "write";
|
|
47
47
|
const deny = writeTarget ? boundary.writeDenyMatch : boundary.denyMatch;
|
|
48
48
|
if (deny !== undefined) {
|
|
49
|
-
const views = [...(read.target !== undefined ? [read.target] : []), ...read.spellings, ...(read.hops ?? [])];
|
|
49
|
+
const views = [...(read.target !== undefined ? [read.target] : []), ...read.spellings, ...(read.ancestorViews ?? []), ...(read.hops ?? [])];
|
|
50
50
|
for (const view of views) {
|
|
51
51
|
const folded = normalizeAbsPathLexically(view);
|
|
52
52
|
const pattern = writeTarget ? boundary.writeDenyMatch(folded) : boundary.denyMatch(folded);
|
|
53
53
|
if (pattern !== null)
|
|
54
|
-
return { read, kind: "deny_hit", deny: { pattern, matchedView: folded, ...(writeTarget ? { face: "write" } : {}) }, containment: writeTarget ? writeContainmentOf(read, boundary) : containmentOf(read, boundary) };
|
|
54
|
+
return { read, kind: "deny_hit", deny: { pattern, matchedView: folded, ...(writeTarget ? { face: "write", ...(boundary.writeDenyGuardsReads?.(pattern) === true ? { readRow: true } : {}) } : {}) }, containment: writeTarget ? writeContainmentOf(read, boundary) : containmentOf(read, boundary) };
|
|
55
55
|
}
|
|
56
56
|
if (!writeTarget && read.candidate.provenance === "traversal_root" && boundary.denyUnder !== undefined) {
|
|
57
57
|
let unplaced;
|
|
58
|
-
for (const view of
|
|
58
|
+
for (const view of [...(read.target !== undefined ? [read.target] : []), ...read.spellings, ...(read.hops ?? [])]) {
|
|
59
59
|
const folded = normalizeAbsPathLexically(view);
|
|
60
60
|
const under = boundary.denyUnder(folded);
|
|
61
61
|
if (typeof under === "string")
|
|
@@ -75,6 +75,12 @@ export interface ReadCandidate {
|
|
|
75
75
|
* A deny row is a floor, so the judge resolves the spelling against these for deny rows ONLY — never to
|
|
76
76
|
* establish a read. `cd sub && cd $'\x2e' && cat <deny row under sub>` (bash: `cd .`) is refused through it. */
|
|
77
77
|
readonly floorBases?: readonly string[];
|
|
78
|
+
/** Only beside `bases: "unmodelled"`: the text makes this word from a directory it does not know — a launcher's working
|
|
79
|
+
* directory value or a `cd` target the shell computes (a substitution, a name, a pattern) —, one that may be anywhere at
|
|
80
|
+
* or above where the text stood. The deny rows' match meets the spelling at every directory at or above its floor
|
|
81
|
+
* ({@link floorBases}), as it meets a word relative to a repository top the text does not settle; the floor itself stays
|
|
82
|
+
* where the text stood, and is where a row below the word (a recursive read's root) is looked for. */
|
|
83
|
+
readonly unsettledStart?: true;
|
|
78
84
|
/** Only on an object path relative to its repository's top (shell-read-object-path.ts): `bases` / `floorBases` are where
|
|
79
85
|
* git starts, the top one of them or above — the one discovery finds (`discovered`, read where a filesystem answers),
|
|
80
86
|
* else any: every ancestor meets the deny rows. */
|
|
@@ -143,6 +149,10 @@ export interface ShellReadSegment {
|
|
|
143
149
|
/** The working directories this segment may be standing in (what every relative candidate's `bases` is), or
|
|
144
150
|
* `"unmodelled"` when the text does not settle it. */
|
|
145
151
|
readonly bases: readonly string[] | "unmodelled";
|
|
152
|
+
/** The directory the segment's PROGRAM starts in, as the candidate `.` placed where the program's relative words are: where
|
|
153
|
+
* the command line stands, or where a launcher moved it (`env -C <dir>` — its deny floor both places). Set on every segment
|
|
154
|
+
* the planner makes; a segment without it names no place its program starts in. */
|
|
155
|
+
readonly programStart?: ReadCandidate;
|
|
146
156
|
/** Substitution bodies, unquoted here-document substitutions, and re-entered shell text, each its own plan. */
|
|
147
157
|
readonly nested: readonly ShellReadPlan[];
|
|
148
158
|
/** Texts a literal printer's words say this segment's shell is fed (a pipe's producer, the body of a `<(…)` script file or
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { expansionsInHeredocBody, lexShell, PARSE_FAILURE_SENTENCE, substitutionsInHeredocBody, literalTextOf, literalTildeSpelling, parameterRereadsValue, UNRESOLVED_SENTENCE, } from "../../shell/lex.js";
|
|
2
2
|
import { programTextOf, readOfText, readsOf, rewritten, segmentReadingsOf, settledFieldsOf, spelledWithHome, unreadableSentenceOf } from "./shell-read-word.js";
|
|
3
|
+
import { braceWordListsOf } from "./shell-read-brace.js";
|
|
3
4
|
import { assignmentArithmetic, bare, listedVerbCandidates, pathSubcommandOf, programTextSentence, pushAssignment, roleReads, subscriptOnly, unlistedWords } from "./shell-read-argv.js";
|
|
4
5
|
import { ARITHMETIC_TEST_OPERATORS, BindingThread, arithmeticSubstitutions, assignsAsStatement, inheritedFunctionsOf, inheritedExportedFunctions, isArithmeticCommand, bindingEffectOf, joinRebound, loopListHeadAt, namesBoundIn, parameterBodySubstitutions, projectSegments, valueOf, } from "./shell-read-bindings.js";
|
|
5
6
|
import { commandEnvironmentNames, isShellSyntaxWord, programBasename, programPositionRunsShell, readProgramPosition, shellScanDeclineOf, } from "./bash-program-position.js";
|
|
@@ -76,23 +77,27 @@ function planText(command, decl, depth, start, from) {
|
|
|
76
77
|
tables[si] ??= table;
|
|
77
78
|
return (facts[si] ??= segmentFacts(lexed.segments[si], projected[si], decl, table, nestedPlanner(table, si), fedAt(si), inheritedFns));
|
|
78
79
|
};
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const
|
|
80
|
+
const placesOf = () => ({ bases: projected.map(() => new Set()), unmodelled: projected.map(() => false), unsettledIn: projected.map(() => false), floors: projected.map(() => []) });
|
|
81
|
+
const written = placesOf(), later = placesOf();
|
|
82
|
+
const { bases: basesOf, unmodelled, unsettledIn } = written;
|
|
83
|
+
let places = written;
|
|
84
|
+
const stood = projected.map(() => ({ at: new Map(), lost: false }));
|
|
85
|
+
const keyOf = (c) => JSON.stringify([c.base, c.pwd, c.old, c.dirStack]);
|
|
86
|
+
const moves = textMovesOf(new Set(projected.flatMap((p) => p.defines)), lexed.segments, projected.map((p) => p.argv), (si) => names.inFunctionBody(si), start?.thread);
|
|
82
87
|
names.runsBodies(moves.runsBodyAt, moves.bodiesAt.some((b) => b.length > 0), moves.mayCallAt.map((c, si) => (c ? commandEnvironmentNames(projected[si].argv) : undefined)));
|
|
83
|
-
|
|
88
|
+
let workdir = new WorkdirThread(depth > 0 && from === undefined && start?.bases === undefined ? [nestedStartOf(decl.cwd)] : (from ?? start?.bases ?? [decl.cwd]), start?.thread?.physical === true);
|
|
84
89
|
if (start?.thread?.reached !== undefined)
|
|
85
90
|
workdir.reach(start.thread.reached);
|
|
86
91
|
const workdirContext = {
|
|
87
92
|
...(decl.homeDir !== undefined ? { homeDir: decl.homeDir } : {}),
|
|
88
93
|
textBinds: boundAnywhere,
|
|
89
|
-
evalEnd: (text,
|
|
94
|
+
evalEnd: (text, from, table) => {
|
|
90
95
|
if (moves.bodyMoves && textCalls(text, moves.functions))
|
|
91
96
|
return { end: "unmodelled", physical: false, reached: new Set() };
|
|
92
97
|
if (!textMayMove(text, moves.functions) && !textSetsPhysical(text))
|
|
93
|
-
return { end:
|
|
94
|
-
const ran = planText(text, decl, depth + 1, { initial: (name) => table.stateOf(name), boundAnywhere, homeTouched: table.homeTouched, inherited: table.inherited, thread: heldThread(moves.unread), names: heldAt(table, names.functionBound()) },
|
|
95
|
-
return { end: ran.end, physical: ran.physical, reached: ran.reached };
|
|
98
|
+
return { end: from, physical: false, reached: new Set() };
|
|
99
|
+
const ran = planText(text, decl, depth + 1, { initial: (name) => table.stateOf(name), boundAnywhere, homeTouched: table.homeTouched, inherited: table.inherited, thread: heldThread(moves.unread), names: heldAt(table, names.functionBound()) }, from);
|
|
100
|
+
return { end: ran.end, physical: ran.physical, reached: ran.reached, ...(ran.unsettled === true ? { unsettled: true } : {}) };
|
|
96
101
|
},
|
|
97
102
|
};
|
|
98
103
|
const heldThread = (unread, physical = workdir.mayBePhysical) => ({ physical, functions: moves.functions, unread, reached: workdir.reached });
|
|
@@ -101,7 +106,6 @@ function planText(command, decl, depth, start, from) {
|
|
|
101
106
|
let crossedAnyOr = false;
|
|
102
107
|
let previousEmitted = -1;
|
|
103
108
|
const reaches = projected.map(() => undefined);
|
|
104
|
-
const loops = [];
|
|
105
109
|
const scopes = [];
|
|
106
110
|
const closeScopes = (j) => {
|
|
107
111
|
const k = scopes.findIndex((s) => !names.reaches(s.at, j));
|
|
@@ -132,11 +136,20 @@ function planText(command, decl, depth, start, from) {
|
|
|
132
136
|
crossedAllAnd = true;
|
|
133
137
|
crossedAnyOr = false;
|
|
134
138
|
previousEmitted = si;
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
const runsHere = places === later || !names.inFunctionBody(si);
|
|
140
|
+
if (workdir.lost) {
|
|
141
|
+
places.unmodelled[si] = true;
|
|
142
|
+
if (workdir.unsettled)
|
|
143
|
+
places.unsettledIn[si] = true;
|
|
144
|
+
if (runsHere)
|
|
145
|
+
stood[si].lost = true;
|
|
146
|
+
}
|
|
137
147
|
else
|
|
138
|
-
for (const c of workdir.reachable(andRunStart))
|
|
139
|
-
|
|
148
|
+
for (const c of workdir.reachable(andRunStart)) {
|
|
149
|
+
places.bases[si].add(c.base);
|
|
150
|
+
if (runsHere)
|
|
151
|
+
stood[si].at.set(keyOf(c), c);
|
|
152
|
+
}
|
|
140
153
|
const losesBase = moves.losesBaseAt(si, tables[si]);
|
|
141
154
|
if (names.runsApart(si) && (moves.physicalAt[si] || (f.shift !== undefined && call !== "named") || losesBase))
|
|
142
155
|
scopes.push({ at: si, state: workdir.snapshot() });
|
|
@@ -165,90 +178,167 @@ function planText(command, decl, depth, start, from) {
|
|
|
165
178
|
if (moves.bodiesAt[si].length > 0)
|
|
166
179
|
names.runsLater(si, moves.bodiesAt[si].reduce((held, b) => joinRebound(held, namesBoundIn(b)), names.functionBound()));
|
|
167
180
|
};
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
181
|
+
const walk = (run, first, within = 1) => {
|
|
182
|
+
const steps = [...new Set([...run, ...run.flatMap((si) => (loopShapes[si] === "head" && loopEndOf.has(si) ? [loopEndOf.get(si)] : []))])].sort((a, b) => a - b);
|
|
183
|
+
const loops = [];
|
|
184
|
+
for (const si of steps) {
|
|
185
|
+
const shapeOfLoop = loopShapes[si];
|
|
186
|
+
if (first && named[si].all === "reset")
|
|
187
|
+
names.apply(si, { bindings: [], all: "reset" }, false);
|
|
188
|
+
thread(si, !first);
|
|
189
|
+
if (first)
|
|
190
|
+
bind(si);
|
|
191
|
+
if (shapeOfLoop === "head") {
|
|
192
|
+
loops.push({ bodyStart: si + 1, beats: facts[si].loopHead?.beats });
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (shapeOfLoop !== "end")
|
|
196
|
+
continue;
|
|
197
|
+
const frame = loops.pop();
|
|
198
|
+
if (frame === undefined)
|
|
199
|
+
continue;
|
|
200
|
+
if (!facts.slice(frame.bodyStart, si).some((b, k) => b?.shift !== undefined || (tables[frame.bodyStart + k] !== undefined && moves.losesBaseAt(frame.bodyStart + k, tables[frame.bodyStart + k]))))
|
|
201
|
+
continue;
|
|
202
|
+
const beat = steps.filter((k) => k >= frame.bodyStart && k < si);
|
|
203
|
+
const around = loops.reduce((n, l) => n * (l.beats ?? 1), within);
|
|
204
|
+
if (frame.beats === undefined || around * frame.beats > POLL_LOOP_MAX_BEATS) {
|
|
205
|
+
workdir.lose(si, workdir.reachable(andRunStart), [], true);
|
|
206
|
+
for (const k of beat) {
|
|
207
|
+
places.unmodelled[k] = true;
|
|
208
|
+
places.unsettledIn[k] = true;
|
|
209
|
+
}
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
for (let n = 1; n < frame.beats && !workdir.lost; n++)
|
|
213
|
+
walk(beat, false, around * frame.beats);
|
|
214
|
+
if (workdir.lost && frame.beats > 1)
|
|
215
|
+
for (const k of beat) {
|
|
216
|
+
places.unmodelled[k] = true;
|
|
217
|
+
if (workdir.unsettled)
|
|
218
|
+
places.unsettledIn[k] = true;
|
|
219
|
+
}
|
|
194
220
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
unmodelled[k] = true;
|
|
198
|
-
}
|
|
221
|
+
};
|
|
222
|
+
walk(projected.map((_, si) => si), true);
|
|
199
223
|
closeScopes();
|
|
224
|
+
const end = workdir.end();
|
|
225
|
+
const gather = (ats) => {
|
|
226
|
+
const at = new Map();
|
|
227
|
+
for (const p of ats)
|
|
228
|
+
for (const c of p.at)
|
|
229
|
+
at.set(keyOf(c), c);
|
|
230
|
+
return { at: [...at.values()], lost: ats.some((p) => p.lost) };
|
|
231
|
+
};
|
|
232
|
+
const ended = { at: end === "unmodelled" ? [] : end, lost: end === "unmodelled" };
|
|
233
|
+
const after = (s) => gather([ended, ...stood.slice(s + 1).map((p) => ({ at: p.at.values(), lost: p.lost }))]);
|
|
234
|
+
const callers = () => gather(stood.flatMap((p, j) => (moves.runsBodyAt[j] ? [{ at: p.at.values(), lost: p.lost }, ...(moves.bodiesAt[j].length > 0 ? [after(j)] : [])] : [])));
|
|
235
|
+
const main = workdir;
|
|
236
|
+
const bodies = new Map();
|
|
237
|
+
projected.forEach((_, si) => {
|
|
238
|
+
const id = names.bodyOf(si);
|
|
239
|
+
if (id !== undefined && facts[si] !== undefined)
|
|
240
|
+
bodies.set(id, [...(bodies.get(id) ?? []), si]);
|
|
241
|
+
});
|
|
242
|
+
const went = new Set();
|
|
243
|
+
const walkBodies = (from, floor = []) => {
|
|
244
|
+
for (const segs of bodies.values())
|
|
245
|
+
for (const start of [...(from.at.length > 0 ? [from.at] : []), ...(from.lost ? ["lost"] : [])]) {
|
|
246
|
+
workdir = main.fork(start, floor);
|
|
247
|
+
scopes.length = 0;
|
|
248
|
+
andRunStart = segs[0];
|
|
249
|
+
crossedAllAnd = true;
|
|
250
|
+
crossedAnyOr = false;
|
|
251
|
+
previousEmitted = -1;
|
|
252
|
+
walk(segs, false);
|
|
253
|
+
closeScopes();
|
|
254
|
+
for (const k of segs)
|
|
255
|
+
if (later.unmodelled[k])
|
|
256
|
+
later.floors[k] = [...new Set([...later.floors[k], ...(workdir.floorBases ?? [])])];
|
|
257
|
+
for (const p of workdir.reached)
|
|
258
|
+
if (!main.reached.has(p))
|
|
259
|
+
went.add(p);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const standing = () => stood.reduce((n, p) => n + p.at.size + (p.lost ? 1 : 0), 0);
|
|
263
|
+
places = later;
|
|
264
|
+
let grew = bodies.size > 0;
|
|
265
|
+
for (let pass = 0; grew && pass <= bodies.size; pass++) {
|
|
266
|
+
const before = standing();
|
|
267
|
+
walkBodies(callers());
|
|
268
|
+
grew = standing() > before;
|
|
269
|
+
}
|
|
270
|
+
if (grew)
|
|
271
|
+
walkBodies({ at: [], lost: true }, [...new Set(stood.flatMap((p) => [...p.at.values()].map((c) => c.base)))]);
|
|
272
|
+
workdir = main;
|
|
273
|
+
places = written;
|
|
274
|
+
main.widen(went);
|
|
200
275
|
const planned = facts.map((f) => f);
|
|
201
276
|
const inert = depth === 0 && unreadable === undefined && planned.every((f) => (f.readings ?? [f]).every(segmentOpensNothing));
|
|
202
277
|
const settled = inert ? planned.map((f) => ({ ...f, reads: f.reads.filter((c) => c.provenance !== "env_assignment"), ...(f.readings !== undefined ? { readings: f.readings.map((g) => ({ ...g, reads: g.reads.filter((c) => c.provenance !== "env_assignment") })) } : {}) })) : planned;
|
|
203
278
|
shape.grouped = projected.some((p) => p.grouped);
|
|
204
279
|
shape.backgrounded = lexed.segments.some((s) => s.connector === "&") || settled.some((f) => (f.readings ?? [f]).some((g) => g.backgrounds === true));
|
|
205
280
|
shape.strayRedirection = projected.some((p) => p.argv.length === 0 && p.redirects.length > 0);
|
|
281
|
+
const placedRead = (c, at, atFloor, gitVariables) => {
|
|
282
|
+
const relative = relativeSpelling(c.spelled);
|
|
283
|
+
if (c.provenance === "object_path" && relative) {
|
|
284
|
+
const { repository, ...read } = c;
|
|
285
|
+
return { ...read, ...objectPathPlacement(c.spelled, repository, at, atFloor, decl.homeDir, gitVariables) };
|
|
286
|
+
}
|
|
287
|
+
return { ...c, bases: relative ? at : [], ...(relative && atFloor !== undefined ? { floorBases: atFloor } : {}) };
|
|
288
|
+
};
|
|
289
|
+
const placedAt = (at, atFloor, unsettled, gitVariables = true) => (c) => {
|
|
290
|
+
const read = placedRead(c, at, atFloor, gitVariables);
|
|
291
|
+
return unsettled && read.bases === "unmodelled" ? { ...read, unsettledStart: true } : read;
|
|
292
|
+
};
|
|
206
293
|
const segments = [];
|
|
207
294
|
for (let si = 0; si < settled.length; si++) {
|
|
208
295
|
const threaded = settled[si];
|
|
209
296
|
if (threaded.empty)
|
|
210
297
|
continue;
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const withBases = placedAt(bases, floor);
|
|
298
|
+
const floorBases = workdir.floorBases ?? [];
|
|
299
|
+
const placed = new Set([...(unmodelled[si] ? [] : basesOf[si]), ...later.bases[si]]);
|
|
300
|
+
const lostFloor = [...new Set([...(unmodelled[si] ? floorBases : []), ...(later.unmodelled[si] ? later.floors[si] : [])])];
|
|
301
|
+
const standings = [
|
|
302
|
+
...(!unmodelled[si] || placed.size > 0 ? [{ bases: [...placed], unsettled: false }] : []),
|
|
303
|
+
...(unmodelled[si] || later.unmodelled[si] ? [{ bases: "unmodelled", ...(lostFloor.length > 0 ? { floor: lostFloor } : {}), unsettled: (unmodelled[si] === true && unsettledIn[si] === true) || (later.unmodelled[si] === true && later.unsettledIn[si] === true) }] : []),
|
|
304
|
+
];
|
|
305
|
+
const firesAt = settled[si].readings?.some((g) => g.runLater !== undefined) === true || settled[si].runLater !== undefined ? after(si) : undefined;
|
|
306
|
+
const firedAt = [...new Set((firesAt?.at ?? []).map((c) => c.base))].filter((b) => !placed.has(b));
|
|
307
|
+
const firedLost = firesAt?.lost === true && (!(unmodelled[si] || later.unmodelled[si]) || floorBases.some((b) => !lostFloor.includes(b)) || (workdir.unsettled && !standings.some((st) => st.bases === "unmodelled" && st.unsettled)));
|
|
308
|
+
const fired = (n) => [...(firedAt.length > 0 ? [rebasePlan(n, firedAt, firedAt)] : []), ...(firedLost ? [rebasePlan(n, "unmodelled", floorBases.length > 0 ? floorBases : undefined, workdir.unsettled)] : [])];
|
|
223
309
|
const move = threaded.baseMove;
|
|
224
|
-
for (const
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
310
|
+
for (const [k, { bases, floor, unsettled: unsettledHere }] of standings.entries())
|
|
311
|
+
for (const f of threaded.readings ?? [threaded]) {
|
|
312
|
+
const withBases = placedAt(bases, floor, unsettledHere);
|
|
313
|
+
const launched = launchedAt(f.launchedIn, bases, floor, decl.homeDir);
|
|
314
|
+
const gitVariables = mayCarryGitVariables(decl.receivedEnvNames ?? "all", tables[si]?.rebound ?? "all", commandEnvironmentNames(f.argv));
|
|
315
|
+
const programPlaced = launched !== undefined ? placedAt("unmodelled", launched.words, unsettledHere || launched.unsettled === true, gitVariables) : placedAt(bases, floor, unsettledHere, gitVariables);
|
|
316
|
+
const programRead = (c) => (c.provenance === "stdin_redirect" ? withBases(c) : programPlaced(c));
|
|
317
|
+
const placeNested = (n) => (f.elsewhere?.has(n) === true ? n : launched !== undefined && f.shellSide?.has(n) !== true ? rebasePlan(n, launched.to, launched.floor, unsettledHere || launched.unsettled === true) : rebasePlan(n, bases, bases === "unmodelled" ? floor : bases, unsettledHere));
|
|
318
|
+
segments.push({
|
|
319
|
+
text: f.text,
|
|
320
|
+
connector: f.connector,
|
|
321
|
+
argv: f.argv,
|
|
322
|
+
launcherChain: f.launcherChain,
|
|
323
|
+
...(f.verb !== undefined ? { verb: f.verb } : {}),
|
|
324
|
+
...(f.reentry !== undefined ? { reentry: f.reentry } : {}),
|
|
325
|
+
...(f.unreadProgramText !== undefined ? { unreadProgramText: f.unreadProgramText } : {}),
|
|
326
|
+
...(f.stdin !== undefined ? { stdin: f.stdin } : {}),
|
|
327
|
+
declines: f.declines,
|
|
328
|
+
reads: dedupe(f.reads).map(programRead),
|
|
329
|
+
redirects: f.redirects.map((r) => ({ op: r.op, direction: r.direction, ...(r.fd !== undefined ? { fd: r.fd } : {}), ...(r.target !== undefined ? { target: withBases(r.target) } : {}) })),
|
|
330
|
+
...(move !== undefined ? { baseMove: { target: typeof move.target === "string" ? move.target : withBases(move.target) } } : {}),
|
|
331
|
+
bases,
|
|
332
|
+
programStart: programPlaced({ spelled: ".", raw: ".", provenance: "unlisted_word", expands: false }),
|
|
333
|
+
nested: [...f.nested.map(placeNested), ...(k === 0 ? [...(f.runLater ?? [])].flatMap(fired) : [])],
|
|
334
|
+
...(f.printed.length > 0 ? { printed: f.printed.map(placeNested) } : {}),
|
|
335
|
+
reach: reaches[si] ?? { andJoined: false, orBroken: false, moveProvable: false },
|
|
336
|
+
rebound: tables[si]?.rebound ?? "all",
|
|
337
|
+
});
|
|
338
|
+
}
|
|
250
339
|
}
|
|
251
|
-
|
|
340
|
+
const reached = workdir.lost ? new Set([...workdir.reached, ...(workdir.floorBases ?? [])]) : workdir.reached;
|
|
341
|
+
return { plan: { segments, shape, ...(unreadable !== undefined ? { unreadable } : {}) }, end: workdir.end(), physical: workdir.mayBePhysical, reached, ...(workdir.unsettled ? { unsettled: true } : {}) };
|
|
252
342
|
}
|
|
253
343
|
function loopShapeOf(p) {
|
|
254
344
|
if (p.argv[0] === undefined)
|
|
@@ -273,13 +363,14 @@ function segmentOpensNothing(f) {
|
|
|
273
363
|
const inertProgram = program === undefined || (program.name === program.basename && isInertBuiltin(program.basename) && !(isDeclarationBuiltin(program.basename) && f.argv.slice(at + 1).some((w) => /^[-+]/.test(w.folded))));
|
|
274
364
|
return inertProgram && f.argv.every((w) => !/[[\]$`]/.test(w.raw)) && f.nested.length === 0 && f.reentry === undefined && f.declines.length === 0 && f.launcherChain.length === 0 && f.redirects.every((r) => r.direction !== "in") && f.reads.every((c) => c.provenance === "env_assignment");
|
|
275
365
|
}
|
|
276
|
-
function segmentFacts(segment,
|
|
277
|
-
const
|
|
278
|
-
const
|
|
366
|
+
function segmentFacts(segment, p0, decl, table, nestedPlan, fed, inheritedFns = new Set()) {
|
|
367
|
+
const argvs = isShellSyntaxWord(p0.argv[0], BLOCK_WORD_NAMES) ? [p0.argv] : braceWordListsOf(p0.argv);
|
|
368
|
+
const targets = p0.redirects.flatMap((r) => (r.target === undefined ? [] : [r.target]));
|
|
369
|
+
const readings = argvs.flatMap((argv) => segmentReadingsOf(argv, targets, table, decl.homeDir));
|
|
279
370
|
if (readings.length === 1)
|
|
280
|
-
return readingFacts(segment, { ...
|
|
371
|
+
return readingFacts(segment, { ...p0, argv: readings[0].argv }, decl, readings[0], nestedPlan, fed, inheritedFns);
|
|
281
372
|
const once = plannedOnce(nestedPlan);
|
|
282
|
-
return readInSeveral(readings.map((reading) => readingFacts(segment, { ...
|
|
373
|
+
return readInSeveral(readings.map((reading) => readingFacts(segment, { ...p0, argv: reading.argv }, decl, reading, once, fed, inheritedFns)));
|
|
283
374
|
}
|
|
284
375
|
function readInSeveral(each) {
|
|
285
376
|
const first = each[0];
|
|
@@ -329,6 +420,7 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
|
|
|
329
420
|
const nested = [];
|
|
330
421
|
const printed = [];
|
|
331
422
|
const elsewhere = new Set();
|
|
423
|
+
const runLater = new Set();
|
|
332
424
|
const ctx = { table, reentered: [], programTextSeen: false };
|
|
333
425
|
const enclosedToo = (e) => [e, ...(e.inner ?? []).flatMap(enclosedToo)];
|
|
334
426
|
const expansionsOf = (sg) => sg.tokens.flatMap((t) => (t.kind === "word" ? t : t.kind === "redirect" ? t.target : undefined)?.pieces ?? []).flatMap((q) => (q.expansion !== undefined ? enclosedToo(q.expansion) : []));
|
|
@@ -390,6 +482,7 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
|
|
|
390
482
|
...(f.unreadProgramText === undefined && ctx.programText !== undefined ? { unreadProgramText: ctx.programText } : {}),
|
|
391
483
|
...(elsewhere.size > 0 ? { elsewhere } : {}),
|
|
392
484
|
...(shellSide.size > 0 ? { shellSide } : {}),
|
|
485
|
+
...(runLater.size > 0 ? { runLater } : {}),
|
|
393
486
|
...(launchedIn !== undefined ? { launchedIn } : {}),
|
|
394
487
|
};
|
|
395
488
|
};
|
|
@@ -435,7 +528,7 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
|
|
|
435
528
|
const listed = basename !== undefined && (decl.readers.has(basename) || basename === "cd");
|
|
436
529
|
const verb = program === undefined ? undefined : { name: program.name, basename: program.basename, listed };
|
|
437
530
|
for (const k of pos.assignments) {
|
|
438
|
-
pushAssignment(reads, toks[k].word, "env_assignment", assignsAsStatement(pos));
|
|
531
|
+
pushAssignment(reads, toks[k].word, "env_assignment", assignsAsStatement(pos) ? "statement" : "shell");
|
|
439
532
|
assignmentArithmetic(toks[k].word, table.isInteger(toks[k].word.assignment?.name ?? ""), ctx);
|
|
440
533
|
}
|
|
441
534
|
for (const l of pos.launchers) {
|
|
@@ -496,7 +589,7 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
|
|
|
496
589
|
continue;
|
|
497
590
|
}
|
|
498
591
|
if (r.word.assignment !== undefined) {
|
|
499
|
-
pushAssignment(reads, r.word, "env_assignment");
|
|
592
|
+
pushAssignment(reads, r.word, "env_assignment", table);
|
|
500
593
|
continue;
|
|
501
594
|
}
|
|
502
595
|
reads.push(bare(r, "unlisted_word"));
|
|
@@ -615,10 +708,10 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
|
|
|
615
708
|
for (const r of argReads) {
|
|
616
709
|
const a = r.word.assignment;
|
|
617
710
|
if (a !== undefined && (r.expands !== "unresolvable" || a.value.expansions.length > 0))
|
|
618
|
-
pushAssignment(reads, r.word, "env_assignment");
|
|
711
|
+
pushAssignment(reads, r.word, "env_assignment", table);
|
|
619
712
|
else if (r.expands === "unresolvable") {
|
|
620
713
|
reads.push(bare(r, "unlisted_word"));
|
|
621
|
-
pushAssignment(reads, r.word, "unlisted_word");
|
|
714
|
+
pushAssignment(reads, r.word, "unlisted_word", table);
|
|
622
715
|
}
|
|
623
716
|
assignmentArithmetic(r.word, integer || (a !== undefined && table.isInteger(a.name)), ctx, asWritten);
|
|
624
717
|
}
|
|
@@ -660,8 +753,11 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
|
|
|
660
753
|
const bodies = new Set([...codeBodies(basename, texts), ...codeBodies(basename, args)]);
|
|
661
754
|
if (bodies.size > 0)
|
|
662
755
|
reentry = "shell";
|
|
663
|
-
for (const body of bodies)
|
|
664
|
-
|
|
756
|
+
for (const body of bodies) {
|
|
757
|
+
const plan = nestedPlan(body, "later");
|
|
758
|
+
nested.push(plan);
|
|
759
|
+
runLater.add(plan);
|
|
760
|
+
}
|
|
665
761
|
return done({
|
|
666
762
|
empty: false,
|
|
667
763
|
launcherChain,
|
|
@@ -96,17 +96,21 @@ export declare function nestedStartOf(cwd: string): string;
|
|
|
96
96
|
*/
|
|
97
97
|
export declare function walkFromStart(base: string): string | undefined;
|
|
98
98
|
/** Where a segment's launcher chain runs its program, where a launcher moves the base it runs in ({@link launchedInOf}): each
|
|
99
|
-
* launcher's working directory, in chain order
|
|
100
|
-
*
|
|
101
|
-
|
|
99
|
+
* launcher's working directory, in chain order — `null` for a value the text does not settle, a directory it does not
|
|
100
|
+
* know —, or `unmodelled`: a move the text does not say (another base moved, a value with two readings). */
|
|
101
|
+
/** The one spelling of the unmodelled word is `ReadCandidate["bases"]`'s — read from there, never respelled here. */
|
|
102
|
+
export type LaunchedIn = readonly (string | null)[] | Extract<ReadCandidate["bases"], string>;
|
|
102
103
|
/**
|
|
103
104
|
* {@link LaunchedIn} of a segment whose launcher chain moves the base (`undefined` where none does), read off the options
|
|
104
105
|
* the program position stepped ({@link ProgramPosition.baseMovedAt}): a value whose role is a working directory (`env -C`,
|
|
105
106
|
* `sudo -D`, `unshare -w`) is where that launcher runs what follows, the LAST one of a launcher's options winning (each
|
|
106
|
-
* implementation keeps the last before it changes directory).
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
107
|
+
* implementation keeps the last before it changes directory). A value the text does not settle (a substitution, a name
|
|
108
|
+
* it does not bind to a literal, a pattern) is a directory the text does not know (`null`); a name the text binds to a
|
|
109
|
+
* literal — `HOME` included — is that literal, as a `cd` to it is. Any other move — a root, a
|
|
110
|
+
* program search, a directory taken from elsewhere (`nsenter -w` with no value), an optional value spelled `=V` (util-linux
|
|
111
|
+
* 2.41 drops the `=`, getopt and util-linux 2.38 keep it: two places), an empty value (no directory: the launcher runs
|
|
112
|
+
* nothing) — leaves it unsaid. Which word is whose option is the walk's reading and no other (env steps a lone `-` and reads
|
|
113
|
+
* on; a `--` ends the options).
|
|
110
114
|
*/
|
|
111
115
|
export declare function launchedInOf(pos: ProgramPosition, toks: readonly Read[]): LaunchedIn | undefined;
|
|
112
116
|
/**
|
|
@@ -115,12 +119,16 @@ export declare function launchedInOf(pos: ProgramPosition, toks: readonly Read[]
|
|
|
115
119
|
* `chdir()`s to it ({@link chdirFrom}). `to` is where the text the program hands a shell starts ({@link rebasePlan} moves it
|
|
116
120
|
* there) — `unmodelled` where the text does not say (an unsettled move, a lost walk, a spelling naming no place), `floor`
|
|
117
121
|
* its deny floor then; `words` is the deny floor of the segment's own relative words, which may be the launcher's (where
|
|
118
|
-
* the command line stands) or the program's (where the launcher put it). `
|
|
122
|
+
* the command line stands) or the program's (where the launcher put it). `unsettled`: a launcher's value is one the text
|
|
123
|
+
* does not settle — the shell computes it where the command line stands, so the floor is where the launcher stood and where
|
|
124
|
+
* the command line stands, and what the program does from there it does from a directory the text does not know
|
|
125
|
+
* ({@link ReadCandidate.unsettledStart}). `undefined`: no launcher moves the base.
|
|
119
126
|
*/
|
|
120
127
|
export declare function launchedAt(launchedIn: LaunchedIn | undefined, bases: ReadCandidate["bases"], floor: readonly string[] | undefined, homeDir: string | undefined): {
|
|
121
128
|
readonly to: ReadCandidate["bases"];
|
|
122
129
|
readonly floor?: readonly string[];
|
|
123
130
|
readonly words?: readonly string[];
|
|
131
|
+
readonly unsettled?: true;
|
|
124
132
|
} | undefined;
|
|
125
133
|
/**
|
|
126
134
|
* A nested plan (a substitution body, a here-document's substitution, a launcher's command string) was planned from
|
|
@@ -133,6 +141,8 @@ export declare function launchedAt(launchedIn: LaunchedIn | undefined, bases: Re
|
|
|
133
141
|
* text stood when it lost track (its floor, {@link ReadCandidate.floorBases}): the places the nested text derived move with
|
|
134
142
|
* it like its bases, an enclosing segment that lost its base itself hands on its own floor (`floor`), and a derived place
|
|
135
143
|
* with nowhere to land is no place (an unplaced candidate with no floor is judged at the declared working directory).
|
|
144
|
+
* `unsettled`: the enclosing segment stands in a directory the text does not know — a candidate the nested text derived
|
|
145
|
+
* from its start is made from there ({@link ReadCandidate.unsettledStart}).
|
|
136
146
|
* A plan re-based onto the same place twice is one plan (a segment read in several readings hands its nested plans on alike).
|
|
137
147
|
*/
|
|
138
|
-
export declare function rebasePlan(plan: ShellReadPlan, to: ReadCandidate["bases"], floor?: readonly string[]): ShellReadPlan;
|
|
148
|
+
export declare function rebasePlan(plan: ShellReadPlan, to: ReadCandidate["bases"], floor?: readonly string[], unsettled?: boolean): ShellReadPlan;
|