@sema-agent/core 7.64.0 → 7.66.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 +571 -0
- package/dist/agents/delegation-registry-seat.d.ts +15 -0
- package/dist/agents/delegation-registry-seat.js +13 -0
- package/dist/agents/org-delivery-gate.d.ts +8 -1
- package/dist/agents/org-delivery-gate.js +9 -3
- package/dist/agents/peer-held-queue.js +1 -1
- package/dist/agents/peer-idle.js +1 -1
- package/dist/agents/peer-session-drain.d.ts +51 -12
- package/dist/agents/peer-session-drain.js +47 -34
- package/dist/agents/read-inbox-tool.d.ts +6 -2
- package/dist/agents/read-inbox-tool.js +18 -5
- package/dist/agents/subagent.d.ts +3 -1
- package/dist/agents/subagent.js +84 -77
- package/dist/brain/reasoning.d.ts +2 -0
- package/dist/brain/reasoning.js +1 -0
- package/dist/core/allow-entry.d.ts +9 -0
- package/dist/core/allow-entry.js +7 -1
- package/dist/core/ask-origin.d.ts +23 -3
- package/dist/core/ask-origin.js +11 -1
- package/dist/core/auto-promote.d.ts +3 -2
- package/dist/core/background-agent-store.d.ts +7 -0
- package/dist/core/checkpoint-store.d.ts +2 -3
- package/dist/core/context-settings.d.ts +1 -2
- package/dist/core/context-settings.js +1 -1
- package/dist/core/engine-attestation.d.ts +2 -2
- package/dist/core/engine-notice.d.ts +13 -1
- package/dist/core/engine-notice.js +3 -1
- package/dist/core/file-history-store.d.ts +2 -2
- package/dist/core/file-history-store.js +0 -4
- package/dist/core/gate-fold.js +3 -1
- package/dist/core/governance-codes.d.ts +6 -4
- package/dist/core/governance-codes.js +5 -3
- package/dist/core/human-input-projection.d.ts +9 -0
- package/dist/core/human-input-projection.js +13 -0
- package/dist/core/input-author.d.ts +66 -6
- package/dist/core/input-author.js +21 -3
- package/dist/core/leg-identity.d.ts +18 -2
- package/dist/core/leg-identity.js +5 -7
- package/dist/core/mailbox-store.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.d.ts +30 -10
- package/dist/core/memory-engine/consolidation.js +41 -6
- package/dist/core/memory-engine/control-objects.d.ts +36 -3
- package/dist/core/memory-engine/control-objects.js +134 -12
- package/dist/core/memory-engine/control-plane-adoption.d.ts +13 -9
- package/dist/core/memory-engine/control-plane-adoption.js +58 -31
- package/dist/core/memory-engine/delegation-settlement.d.ts +75 -52
- package/dist/core/memory-engine/delegation-settlement.js +211 -228
- package/dist/core/memory-engine/dual-root.d.ts +3 -2
- package/dist/core/memory-engine/dual-root.js +5 -1
- package/dist/core/memory-engine/engine.d.ts +33 -16
- package/dist/core/memory-engine/engine.js +213 -177
- package/dist/core/memory-engine/file-backend.d.ts +21 -12
- package/dist/core/memory-engine/file-backend.js +58 -104
- package/dist/core/memory-engine/index.d.ts +2 -2
- package/dist/core/memory-engine/index.js +2 -2
- package/dist/core/memory-engine/layout.d.ts +184 -83
- package/dist/core/memory-engine/layout.js +267 -172
- package/dist/core/memory-engine/memory-age.d.ts +12 -0
- package/dist/core/memory-engine/memory-age.js +17 -0
- package/dist/core/memory-engine/memory-backend-contract.js +12 -11
- package/dist/core/memory-engine/memory-deployment.d.ts +4 -3
- package/dist/core/memory-engine/memory-deployment.js +6 -3
- package/dist/core/memory-engine/origin-clearance.d.ts +43 -15
- package/dist/core/memory-engine/origin-clearance.js +142 -58
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +7 -7
- package/dist/core/memory-engine/types.d.ts +16 -10
- package/dist/core/memory-vector.d.ts +6 -14
- package/dist/core/memory.d.ts +0 -462
- package/dist/core/memory.js +0 -333
- package/dist/core/model-receipt.d.ts +2 -1
- package/dist/core/model-receipt.js +5 -0
- package/dist/core/mods/dollar.d.ts +12 -0
- package/dist/core/mods/kernel/dispatch.d.ts +3 -1
- package/dist/core/mods/kernel/dispatch.js +5 -2
- package/dist/core/mods/kernel/events.d.ts +3 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/prompt-submit.d.ts +4 -0
- package/dist/core/mods/prompt-submit.js +24 -0
- package/dist/core/mods/stations.d.ts +23 -4
- package/dist/core/mods/stations.js +14 -7
- package/dist/core/permission-rule-consent.d.ts +49 -18
- package/dist/core/permission-rule-consent.js +59 -38
- package/dist/core/permission-rule-store.d.ts +24 -14
- package/dist/core/retention.d.ts +2 -7
- package/dist/core/retention.js +0 -1
- package/dist/core/retired-host-table-account.d.ts +19 -0
- package/dist/core/retired-host-table-account.js +28 -0
- package/dist/core/retired-tool-name-account.d.ts +60 -0
- package/dist/core/retired-tool-name-account.js +32 -0
- package/dist/core/roles.d.ts +3 -1
- package/dist/core/roles.js +5 -2
- package/dist/core/runner/classifier-ladder.d.ts +3 -1
- package/dist/core/runner/classifier-ladder.js +2 -2
- package/dist/core/runner/compact-session.js +2 -1
- package/dist/core/runner/contracts.d.ts +9 -9
- package/dist/core/runner/delegation-owner.d.ts +0 -8
- package/dist/core/runner/delegation-owner.js +1 -3
- package/dist/core/runner/gate-exit.js +9 -2
- package/dist/core/runner/memory-consolidation-driver.js +2 -2
- package/dist/core/runner/prepare-config-doors.js +1 -1
- package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
- package/dist/core/runner/prepare-delegation-surface.js +5 -3
- package/dist/core/runner/prepare-gate-stations.d.ts +8 -5
- package/dist/core/runner/prepare-gate-stations.js +13 -5
- package/dist/core/runner/prepare-inherited-gate.js +2 -0
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.js +35 -14
- package/dist/core/runner/prepare-policy-chain.js +12 -3
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-task.d.ts +9 -1
- package/dist/core/runner/prepare-task.js +6 -5
- package/dist/core/runner/prepare-wiring-manifest.js +5 -4
- package/dist/core/runner/prompt-suggestions.js +1 -1
- package/dist/core/runner/run-identity-wiring.js +2 -2
- package/dist/core/runner/run-leg.js +3 -3
- package/dist/core/runner/run-notification-lane.d.ts +3 -0
- package/dist/core/runner/run-notification-lane.js +2 -2
- package/dist/core/runner/runtask.js +6 -3
- package/dist/core/runner/steer-admission.d.ts +11 -2
- package/dist/core/runner/stream-steer-verb.d.ts +5 -2
- package/dist/core/runner/stream-steer-verb.js +67 -14
- package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -8
- package/dist/core/runner/sub-agent-deny-lists.js +22 -8
- package/dist/core/runner-deps.d.ts +4 -4
- package/dist/core/secret-env.d.ts +2 -2
- package/dist/core/secret-env.js +6 -20
- package/dist/core/session-store.d.ts +6 -6
- package/dist/core/session-store.js +3 -3
- package/dist/core/shell-run-candidates.js +3 -3
- package/dist/core/side-query.js +1 -1
- package/dist/core/skill-grant.d.ts +7 -0
- package/dist/core/skill-grant.js +14 -5
- package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
- package/dist/core/task-event.d.ts +14 -0
- package/dist/core/task-notification.d.ts +35 -8
- package/dist/core/task-notification.js +31 -13
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +4 -0
- package/dist/core/tool-errors.d.ts +3 -3
- package/dist/core/tool-policy.js +2 -3
- package/dist/core/tool-spec.d.ts +20 -10
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +11 -5
- package/dist/core/write-protect.d.ts +16 -0
- package/dist/core/write-protect.js +10 -0
- package/dist/engine/harness/agent-harness.d.ts +19 -11
- package/dist/engine/harness/agent-harness.js +7 -4
- package/dist/engine/llm/types.d.ts +22 -10
- package/dist/engine/session/repo-utils.d.ts +14 -4
- package/dist/engine/session/repo-utils.js +5 -4
- package/dist/index.d.ts +10 -8
- package/dist/index.js +9 -7
- package/dist/prompts/default.d.ts +1 -2
- package/dist/scenarios/full-body.d.ts +1 -1
- package/dist/shell/lex.d.ts +50 -15
- package/dist/shell/lex.js +43 -9
- package/dist/stores/file/adoption/adopt.d.ts +1 -1
- package/dist/stores/file/index.d.ts +1 -15
- package/dist/stores/file/index.js +1 -15
- package/dist/stores/file/permission-rule-store.d.ts +12 -1
- package/dist/stores/file/permission-rule-store.js +31 -4
- package/dist/stores/file/session-store.js +1 -1
- package/dist/tools/fs/fs-bash.js +3 -3
- package/dist/tools/fs/removal-targets.d.ts +8 -2
- package/dist/tools/fs/removal-targets.js +31 -4
- package/dist/tools/fs/shell-read-argv.js +7 -1
- package/dist/tools/fs/shell-read-bindings.d.ts +21 -5
- package/dist/tools/fs/shell-read-bindings.js +130 -44
- package/dist/tools/fs/shell-read-plan.js +95 -29
- package/dist/tools/fs/shell-read-sourced.d.ts +25 -0
- package/dist/tools/fs/shell-read-sourced.js +119 -0
- package/dist/tools/fs/shell-read-word.d.ts +2 -2
- package/dist/tools/fs/shell-read-word.js +4 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +19 -3
- package/dist/tools/fs/shell-read-workdir.js +60 -15
- package/dist/tools/fs/shell-reentry-text.d.ts +10 -2
- package/dist/tools/fs/shell-reentry-text.js +11 -4
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +21 -79
- package/wire-changes/core-stores-sql@7.65.0.json +30 -0
- package/wire-changes/core-stores-sql@7.66.0.json +30 -0
- package/wire-changes/core@7.65.0.json +1650 -0
- package/wire-changes/core@7.66.0.json +1218 -0
- package/wire-changes/mods-kernel@7.65.0.json +30 -0
- package/wire-changes/mods-kernel@7.66.0.json +65 -0
- package/wire-changes/primitives@7.65.0.json +337 -0
- package/wire-changes/primitives@7.66.0.json +30 -0
- package/dist/core/memory-recall.d.ts +0 -208
- package/dist/core/memory-recall.js +0 -136
- package/dist/stores/file/memory-store.d.ts +0 -124
- package/dist/stores/file/memory-store.js +0 -353
|
@@ -493,6 +493,15 @@ export function valueOf(word, table, quoted, overlay = new Map(), split = false)
|
|
|
493
493
|
export function wordFloorValues(word, table) {
|
|
494
494
|
if (table === undefined)
|
|
495
495
|
return [];
|
|
496
|
+
for (let kept = Number.POSITIVE_INFINITY;; kept = Math.min(kept, WORD_VALUES_MAX) - 1) {
|
|
497
|
+
const combos = floorCombos(word, table, kept);
|
|
498
|
+
if (combos !== "past")
|
|
499
|
+
return combos;
|
|
500
|
+
if (kept === 0)
|
|
501
|
+
return [];
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
function floorCombos(word, table, kept) {
|
|
496
505
|
let combos = [{ spelled: "" }];
|
|
497
506
|
for (const p of word.pieces) {
|
|
498
507
|
const e = p.expansion;
|
|
@@ -504,7 +513,9 @@ export function wordFloorValues(word, table) {
|
|
|
504
513
|
}
|
|
505
514
|
else if (e.kind === "parameter" && e.name !== undefined) {
|
|
506
515
|
const state = table.stateOf(e.name);
|
|
507
|
-
|
|
516
|
+
const known = state !== "unknown" && (e.body === undefined || e.body === e.name) ? state : undefined;
|
|
517
|
+
const floor = known === undefined ? table.floorOf(e.name) : [];
|
|
518
|
+
options = known !== undefined ? known.map(floorOf) : [...floor.filter((o) => o.held !== true), ...floor.filter((o) => o.held === true).slice(0, kept)];
|
|
508
519
|
}
|
|
509
520
|
else
|
|
510
521
|
return [];
|
|
@@ -518,7 +529,7 @@ export function wordFloorValues(word, table) {
|
|
|
518
529
|
}
|
|
519
530
|
}
|
|
520
531
|
if (next.length > WORD_VALUES_MAX)
|
|
521
|
-
return
|
|
532
|
+
return "past";
|
|
522
533
|
combos = next;
|
|
523
534
|
}
|
|
524
535
|
return combos;
|
|
@@ -527,7 +538,7 @@ export function loopListHeadAt(argv) {
|
|
|
527
538
|
const at = isShellSyntaxWord(argv[0], LOOP_LIST_HEADS) ? 0 : readProgramPosition(argv).written;
|
|
528
539
|
return at !== undefined && isShellSyntaxWord(argv[at], LOOP_LIST_HEADS) ? at : undefined;
|
|
529
540
|
}
|
|
530
|
-
export function bindingEffectOf(segment, argv, shape, readValue, shadow, availability) {
|
|
541
|
+
export function bindingEffectOf(segment, argv, shape, readValue, shadow, availability, fed, fedByLoop = false) {
|
|
531
542
|
const bindings = [];
|
|
532
543
|
let all = shape.defines.length > 0 ? "reset" : undefined;
|
|
533
544
|
const unknownAll = () => void (all = "unknown");
|
|
@@ -567,8 +578,8 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
|
|
|
567
578
|
kill(name);
|
|
568
579
|
}
|
|
569
580
|
segment.tokens.forEach((t, i) => {
|
|
570
|
-
if (t.kind === "word" && namesRedirectDescriptor(
|
|
571
|
-
|
|
581
|
+
if (t.kind === "word" && namesRedirectDescriptor(segment.tokens[i + 1]))
|
|
582
|
+
bind({ name: t.raw.slice(1, -1), state: "unknown", prefix: true });
|
|
572
583
|
});
|
|
573
584
|
const tokens = segment.tokens;
|
|
574
585
|
if (isArithmeticCommand(segment)) {
|
|
@@ -627,7 +638,8 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
|
|
|
627
638
|
if (program === undefined || shadow === "named")
|
|
628
639
|
return { bindings, all };
|
|
629
640
|
const settled = bindings.length;
|
|
630
|
-
const
|
|
641
|
+
const chainIsBuiltin = program.name === program.basename && pos.launchers.every((l, i) => (l.name === "builtin" || l.name === "command") && argv[l.index].folded === l.name && l.index + 1 === (pos.launchers[i + 1]?.index ?? program.index));
|
|
642
|
+
const runsAsBuiltin = chainIsBuiltin && !segment.tokens.some((t) => t.kind === "redirect" || t.kind === "heredoc");
|
|
631
643
|
const available = runsAsBuiltin ? chainAvailability([...pos.launchers.map((l) => l.name), program.basename], availability) : "enabled";
|
|
632
644
|
if (available === "disabled")
|
|
633
645
|
return { bindings, all };
|
|
@@ -691,6 +703,17 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
|
|
|
691
703
|
if (w.pieces.every((p) => p.literal !== undefined && p.expansion === undefined))
|
|
692
704
|
bind({ name: functionKey(w.folded), state: FUNCTION_ABSENT, prefix: true });
|
|
693
705
|
}
|
|
706
|
+
if (program.basename === "read" && chainIsBuiltin && !pos.assignments.some((k) => argv[k].assignment?.name === "IFS")) {
|
|
707
|
+
const readAvailable = chainAvailability([...pos.launchers.map((l) => l.name), program.basename], availability);
|
|
708
|
+
if (readAvailable === "disabled")
|
|
709
|
+
return finish({ bindings, all });
|
|
710
|
+
const line = readBuiltinLines(args, fed, fedByLoop);
|
|
711
|
+
if (line !== undefined) {
|
|
712
|
+
const mayFail = segment.tokens.some((t) => t.kind === "redirect" && t.op !== "<<<");
|
|
713
|
+
bind({ name: line.name, state: line.values, loopVar: true, ...(mayFail || readAvailable === "maybe" || shadow === "maybe" ? { prefix: true } : {}) });
|
|
714
|
+
return finish({ bindings, all });
|
|
715
|
+
}
|
|
716
|
+
}
|
|
694
717
|
for (const e of readArgRoles(row, folded)) {
|
|
695
718
|
const role = e.kind === "value" || e.kind === "operand" ? e.role : e.kind === "option" && typeof e.reading === "object" ? e.reading.role : undefined;
|
|
696
719
|
if (role?.kind === "program-text" && role.language === "arithmetic" && e.kind !== "end-of-options" && e.kind !== "dash-word-operand") {
|
|
@@ -711,6 +734,34 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
|
|
|
711
734
|
unknownAll();
|
|
712
735
|
return finish({ bindings, all });
|
|
713
736
|
}
|
|
737
|
+
function readBuiltinLines(args, fed, fedByLoop) {
|
|
738
|
+
if (fed === undefined || fed.length === 0 || fed.some((t) => t.literal === undefined))
|
|
739
|
+
return undefined;
|
|
740
|
+
if (args.some((w) => w.expansions.length > 0))
|
|
741
|
+
return undefined;
|
|
742
|
+
const words = args.map((w) => w.folded).filter((w) => w !== "--");
|
|
743
|
+
const options = words.filter((w) => w.startsWith("-") && w !== "-");
|
|
744
|
+
if (!options.every((o) => /^-r+$/.test(o)))
|
|
745
|
+
return undefined;
|
|
746
|
+
const names = words.filter((w) => !w.startsWith("-") || w === "-");
|
|
747
|
+
if (names.length !== 1 || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(names[0]) || names[0] === "HOME")
|
|
748
|
+
return undefined;
|
|
749
|
+
const raw = options.length === 0;
|
|
750
|
+
const lines = [];
|
|
751
|
+
for (const t of fed) {
|
|
752
|
+
const text = t.literal;
|
|
753
|
+
if (raw && text.includes("\\"))
|
|
754
|
+
return undefined;
|
|
755
|
+
const parts = text.split("\n");
|
|
756
|
+
if (parts.length > 1 && parts[parts.length - 1] === "")
|
|
757
|
+
parts.pop();
|
|
758
|
+
for (const l of parts)
|
|
759
|
+
lines.push(l.replace(/^[ \t]+|[ \t]+$/g, ""));
|
|
760
|
+
}
|
|
761
|
+
const consumed = fedByLoop ? lines : fed.map((t) => (t.literal.split("\n")[0] ?? "").replace(/^[ \t]+|[ \t]+$/g, ""));
|
|
762
|
+
const unique = [...new Set(consumed.length === 0 ? [""] : consumed)];
|
|
763
|
+
return { name: names[0], values: unique.map((spelled) => ({ spelled })) };
|
|
764
|
+
}
|
|
714
765
|
function nameIn(text) {
|
|
715
766
|
return /^([A-Za-z_][A-Za-z0-9_]*)(?:\[.*\])?$/s.exec(text)?.[1];
|
|
716
767
|
}
|
|
@@ -735,17 +786,10 @@ function unsetOperands(args) {
|
|
|
735
786
|
}
|
|
736
787
|
return { operands: args.slice(at), variablesOnly: variables && !otherwise };
|
|
737
788
|
}
|
|
738
|
-
function compoundElementWords(
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
return [];
|
|
743
|
-
return l.segments.flatMap((sg) => argvOf(sg)).flatMap((element) => {
|
|
744
|
-
const prefix = /^\[[^\]]*\]\+?=/.exec(element.raw)?.[0];
|
|
745
|
-
const assigned = prefix === undefined ? undefined : lexShell(`V=${element.raw.slice(prefix.length)}`);
|
|
746
|
-
const value = assigned === undefined || "parseFailure" in assigned ? undefined : argvOf(assigned.segments[0])[0]?.assignment?.value;
|
|
747
|
-
const folded = /^\[[^\]]*\]\+?=/.exec(element.folded)?.[0];
|
|
748
|
-
return [prefix === undefined ? element : value, ...(folded !== undefined ? [{ pieces: element.pieces, folded: element.folded.slice(folded.length), tail: true }] : [])].filter((w) => w !== undefined);
|
|
789
|
+
function compoundElementWords(a) {
|
|
790
|
+
return (a.elements ?? []).flatMap(({ word, stored }) => {
|
|
791
|
+
const folded = /^\[[^\]]*\]\+?=/.exec(word.folded)?.[0];
|
|
792
|
+
return [stored.assignment.subscript === undefined ? word : stored.assignment.value, ...(folded !== undefined ? [{ pieces: word.pieces, folded: word.folded.slice(folded.length), tail: true }] : [])];
|
|
749
793
|
});
|
|
750
794
|
}
|
|
751
795
|
export function bindsArrayElement(a) {
|
|
@@ -755,7 +799,7 @@ export function assignsAsStatement(pos) {
|
|
|
755
799
|
return pos.program === undefined && pos.launchers.length === 0 && pos.refusal === undefined;
|
|
756
800
|
}
|
|
757
801
|
function arrayElementFloor(a, readValue, overlay) {
|
|
758
|
-
const words = a.form === "compound" ? compoundElementWords(a
|
|
802
|
+
const words = a.form === "compound" ? compoundElementWords(a) : [{ pieces: a.value.pieces, folded: a.value.folded }];
|
|
759
803
|
return words.flatMap((w) => {
|
|
760
804
|
const v = w.tail === true ? "unknown" : readValue(w, true, overlay);
|
|
761
805
|
if (v !== "unknown")
|
|
@@ -975,6 +1019,21 @@ export class BindingThread {
|
|
|
975
1019
|
}
|
|
976
1020
|
return out;
|
|
977
1021
|
}
|
|
1022
|
+
functionMaybeBound() {
|
|
1023
|
+
const maybe = new Set();
|
|
1024
|
+
const certain = new Set();
|
|
1025
|
+
for (let at = 0; at < this.named.length; at++) {
|
|
1026
|
+
const effect = this.named[at];
|
|
1027
|
+
for (const b of effect.bindings) {
|
|
1028
|
+
if (this.bodyBinding(b, at) === undefined || this.declaredLocal(b.name, at, this.bodyBinding(b, at)))
|
|
1029
|
+
continue;
|
|
1030
|
+
(b.prefix === true || this.segments[at].spliced === true ? maybe : certain).add(b.name);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
for (const name of certain)
|
|
1034
|
+
maybe.delete(name);
|
|
1035
|
+
return maybe;
|
|
1036
|
+
}
|
|
978
1037
|
bodyBinding(b, at) {
|
|
979
1038
|
const own = this.standingOf(at, b.name).body;
|
|
980
1039
|
return own !== undefined && b.scope !== "local" ? own : undefined;
|
|
@@ -1037,14 +1096,14 @@ export class BindingThread {
|
|
|
1037
1096
|
return false;
|
|
1038
1097
|
return true;
|
|
1039
1098
|
}
|
|
1040
|
-
apply(at, effect, andRun, loopEnd) {
|
|
1099
|
+
apply(at, effect, andRun, loopEnd, spliced = false) {
|
|
1041
1100
|
const body = this.blocks[at].body;
|
|
1042
1101
|
const refused = effect.inFunction === true && body === undefined;
|
|
1043
1102
|
if (effect.all !== undefined)
|
|
1044
|
-
this.entries.push({ at, standing: this.standingOf(at), state: effect.all === "reset" ? "reset" : "unknown", detached:
|
|
1103
|
+
this.entries.push({ at, standing: this.standingOf(at), state: effect.all === "reset" ? "reset" : "unknown", detached: spliced || effect.all === "unknown", andRun: false });
|
|
1045
1104
|
for (const b of effect.bindings) {
|
|
1046
1105
|
const standing = this.standingOf(at, b.name);
|
|
1047
|
-
const detached = this.detachedAt(at, standing) || b.prefix === true;
|
|
1106
|
+
const detached = this.detachedAt(at, standing) || b.prefix === true || spliced;
|
|
1048
1107
|
this.entries.push({
|
|
1049
1108
|
at, standing, name: b.name, state: refused ? "unknown" : b.state, detached, andRun,
|
|
1050
1109
|
...(b.loopVar === true && loopEnd !== undefined ? { certainUntil: loopEnd } : {}),
|
|
@@ -1060,14 +1119,14 @@ export class BindingThread {
|
|
|
1060
1119
|
const readerBody = this.blocks[j].body;
|
|
1061
1120
|
return readerBody !== undefined && readerBody.id !== u.body.id;
|
|
1062
1121
|
}
|
|
1063
|
-
kill(at, names) {
|
|
1122
|
+
kill(at, names, spliced = false) {
|
|
1064
1123
|
const standing = this.standingOf(at);
|
|
1065
1124
|
if (names === "all") {
|
|
1066
|
-
this.entries.push({ at, standing, state: "unknown", detached:
|
|
1125
|
+
this.entries.push({ at, standing, state: "unknown", detached: spliced, andRun: false });
|
|
1067
1126
|
return;
|
|
1068
1127
|
}
|
|
1069
1128
|
for (const name of names)
|
|
1070
|
-
this.entries.push({ at, standing, name, state: "unknown", detached:
|
|
1129
|
+
this.entries.push({ at, standing, name, state: "unknown", detached: spliced, andRun: false });
|
|
1071
1130
|
}
|
|
1072
1131
|
tableAt(j, andRunStart, where) {
|
|
1073
1132
|
const certain = (e) => {
|
|
@@ -1086,6 +1145,7 @@ export class BindingThread {
|
|
|
1086
1145
|
const add = (vs) => { for (const v of vs)
|
|
1087
1146
|
if (!values.some((x) => sameValue(x, v)))
|
|
1088
1147
|
values.push(v); };
|
|
1148
|
+
let unknownMayNotHaveRun = false;
|
|
1089
1149
|
for (let i = this.entries.length - 1; i >= 0; i--) {
|
|
1090
1150
|
const e = this.entries[i];
|
|
1091
1151
|
if (!before(e) || (e.name !== undefined && !speaksFor(e.name, name)))
|
|
@@ -1093,42 +1153,49 @@ export class BindingThread {
|
|
|
1093
1153
|
if (e.state === "reset" && isBuiltinKey(name))
|
|
1094
1154
|
continue;
|
|
1095
1155
|
const state = e.state === "reset" ? ((name === "HOME" && this.boundAnywhere("HOME")) || this.bindsInText(name) ? "unknown" : this.initial(name)) : e.state;
|
|
1096
|
-
if (state === "unknown")
|
|
1097
|
-
|
|
1156
|
+
if (state === "unknown") {
|
|
1157
|
+
if (certain(e))
|
|
1158
|
+
return { state: "unknown", values };
|
|
1159
|
+
unknownMayNotHaveRun = true;
|
|
1160
|
+
continue;
|
|
1161
|
+
}
|
|
1098
1162
|
if (e.name !== undefined && given(e.name, e.at))
|
|
1099
|
-
return { state: "unknown" };
|
|
1163
|
+
return { state: "unknown", values };
|
|
1100
1164
|
add(state);
|
|
1101
1165
|
if (certain(e))
|
|
1102
|
-
return { state: values, decided: e };
|
|
1166
|
+
return unknownMayNotHaveRun ? { state: "unknown", values } : { state: values, decided: e, values };
|
|
1103
1167
|
}
|
|
1104
|
-
if (start
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1168
|
+
if (start !== "unknown")
|
|
1169
|
+
add(start);
|
|
1170
|
+
if (start === "unknown" || unknownMayNotHaveRun)
|
|
1171
|
+
return { state: "unknown", values };
|
|
1172
|
+
return { state: values, values };
|
|
1108
1173
|
};
|
|
1109
1174
|
const later = this.boundLater(j);
|
|
1110
1175
|
const boundLater = (name) => later === "all" || later.has(name) || (isBuiltinKey(name) && later.has(BUILTINS_ALL));
|
|
1111
|
-
const
|
|
1176
|
+
const readName = (name) => {
|
|
1177
|
+
const unknown = (values = []) => ({ state: "unknown", floor: values.map((v) => ({ ...floorOf(v), held: true })) });
|
|
1112
1178
|
if (shellKeepsName(name))
|
|
1113
|
-
return
|
|
1179
|
+
return unknown();
|
|
1114
1180
|
if (this.unreadable.some((u) => speaksFor(u.name, name) && lost(u)))
|
|
1115
|
-
return
|
|
1181
|
+
return unknown();
|
|
1116
1182
|
if (!isWorkingDirectoryName(name)) {
|
|
1117
1183
|
const walked = walk(name, this.startOf(name));
|
|
1118
1184
|
const own = walked.decided !== undefined && walked.decided.state !== "reset" && readerBody !== undefined && walked.decided.standing.body?.id === readerBody.id;
|
|
1119
|
-
return boundLater(name) && !own
|
|
1185
|
+
return (boundLater(name) && !own) || walked.state === "unknown" ? unknown(walked.values) : { state: walked.state, floor: [] };
|
|
1120
1186
|
}
|
|
1121
|
-
if (boundLater(name))
|
|
1122
|
-
return "unknown";
|
|
1123
1187
|
const assigned = walk(name, []);
|
|
1188
|
+
if (boundLater(name))
|
|
1189
|
+
return unknown(assigned.values);
|
|
1124
1190
|
if (assigned.decided !== undefined && where !== undefined && readerBody === undefined && assigned.decided.at > where.movedAt)
|
|
1125
|
-
return assigned.state;
|
|
1191
|
+
return { state: assigned.state, floor: [] };
|
|
1126
1192
|
const thread = readerBody === undefined ? where?.[name] ?? "unknown" : "unknown";
|
|
1127
1193
|
if (thread === "unknown" || assigned.state === "unknown")
|
|
1128
|
-
return
|
|
1194
|
+
return unknown(assigned.values);
|
|
1129
1195
|
const held = assigned.state;
|
|
1130
|
-
return [...held, ...thread.filter((v) => !held.some((x) => sameValue(x, v)))];
|
|
1196
|
+
return { state: [...held, ...thread.filter((v) => !held.some((x) => sameValue(x, v)))], floor: [] };
|
|
1131
1197
|
};
|
|
1198
|
+
const stateOf = (name) => readName(name).state;
|
|
1132
1199
|
const touched = (name) => this.entries.some((e) => before(e) && (e.name === undefined || e.name === name));
|
|
1133
1200
|
let rebound = this.startRebound;
|
|
1134
1201
|
for (const e of this.entries)
|
|
@@ -1138,13 +1205,32 @@ export class BindingThread {
|
|
|
1138
1205
|
if (lost(u))
|
|
1139
1206
|
rebound = joinRebound(rebound, u.name === undefined ? "all" : [u.name]);
|
|
1140
1207
|
const settled = joinRebound(rebound, later);
|
|
1208
|
+
const floorsOf = (name) => [...this.entries.filter((e) => e.at < j && e.name === name).flatMap((e) => e.floor ?? []), ...readName(name).floor, ...(this.startFloors.get(name) ?? [])];
|
|
1209
|
+
let started;
|
|
1210
|
+
const nestedStart = () => {
|
|
1211
|
+
if (started !== undefined)
|
|
1212
|
+
return started;
|
|
1213
|
+
const start = this.inheritedAt(j);
|
|
1214
|
+
const floors = new Map(start.floors ?? []);
|
|
1215
|
+
let held = false;
|
|
1216
|
+
for (const name of new Set(this.entries.flatMap((e) => (e.name !== undefined && before(e) && !isFunctionKey(e.name) && !isBuiltinKey(e.name) ? [e.name] : [])))) {
|
|
1217
|
+
const floor = readName(name).floor;
|
|
1218
|
+
if (floor.length === 0)
|
|
1219
|
+
continue;
|
|
1220
|
+
floors.set(name, [...(floors.get(name) ?? []), ...floor]);
|
|
1221
|
+
held = true;
|
|
1222
|
+
}
|
|
1223
|
+
return (started = held ? { ...start, floors } : start);
|
|
1224
|
+
};
|
|
1141
1225
|
return {
|
|
1142
1226
|
stateOf,
|
|
1143
1227
|
isInteger: (name) => SHELL_INTEGER_VARIABLES.has(name) || given(name, j, true),
|
|
1144
1228
|
ifsTouched: touched("IFS") || boundLater("IFS"),
|
|
1145
1229
|
homeTouched: this.homeStartsTouched || touched("HOME") || boundLater("HOME"),
|
|
1146
|
-
floorOf:
|
|
1147
|
-
inherited
|
|
1230
|
+
floorOf: floorsOf,
|
|
1231
|
+
get inherited() {
|
|
1232
|
+
return nestedStart();
|
|
1233
|
+
},
|
|
1148
1234
|
rebound: settled,
|
|
1149
1235
|
providedByShell: (name) => settled !== "all" && !settled.has(name),
|
|
1150
1236
|
functionState: (name) => {
|
|
@@ -1211,7 +1297,7 @@ export function subscriptsOf(text) {
|
|
|
1211
1297
|
}
|
|
1212
1298
|
return out;
|
|
1213
1299
|
}
|
|
1214
|
-
function substitutionBodies(subscript, keepQuotes = false) {
|
|
1300
|
+
export function substitutionBodies(subscript, keepQuotes = false) {
|
|
1215
1301
|
if (!/\$\(|`|[<>]\(/.test(subscript))
|
|
1216
1302
|
return [];
|
|
1217
1303
|
const unquoted = keepQuotes ? subscript : subscript.replace(/["']/g, "");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expansionsInHeredocBody, lexShell, PARSE_FAILURE_SENTENCE, substitutionsInHeredocBody, literalTextOf, literalTildeSpelling, parameterRereadsValue, UNRESOLVED_SENTENCE, } from "../../shell/lex.js";
|
|
1
|
+
import { assignedWords, expansionsInHeredocBody, descriptorNameWords, 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
3
|
import { braceWordListsOf } from "./shell-read-brace.js";
|
|
4
4
|
import { assignmentArithmetic, bare, listedVerbCandidates, pathSubcommandOf, programTextSentence, pushAssignment, roleReads, subscriptOnly, unlistedWords } from "./shell-read-argv.js";
|
|
@@ -10,8 +10,9 @@ import { mayCarryGitVariables, objectPathPlacement } from "./shell-read-object-p
|
|
|
10
10
|
import { BLOCK_WORD_NAMES, commandLineOf, commandLineOptionSpellings, declaredAttributes, isDeclarationBuiltin, isInertBuiltin, launcherOptionPathRole, launcherOptionStep, readOptionRole, programLanguageOf, programTextOpensOf, selectedOptions, movesBaseByStack, opensNoOperand, programDelivery, programRow, readArgRoles, runsShellText, } from "./program-read-model.js";
|
|
11
11
|
import { shellWordsOf } from "../../shell/shell-words.js";
|
|
12
12
|
import { isAbsoluteForFamily } from "./safety.js";
|
|
13
|
-
import { codeBodies, launchedInput, pipedTextOf, printedByProcess, reentersShell, reentryText, scriptFileAt, stdinTextsOf } from "./shell-reentry-text.js";
|
|
13
|
+
import { codeBodies, launchedInput, literalEvalText, pipedTextOf, printedByProcess, reentersShell, reentryText, scriptFileAt, stdinTextsOf } from "./shell-reentry-text.js";
|
|
14
14
|
import { heldAt, launchedAt, launchedInOf, nestedStartOf, plannedOnce, rebasePlan, startedAt, stdinFeeds } from "./shell-read-start.js";
|
|
15
|
+
import { inlineSourcedLiterals } from "./shell-read-sourced.js";
|
|
15
16
|
import { markStandardDevices } from "./shell-read-device.js";
|
|
16
17
|
export const READ_CANDIDATE_PROVENANCES = Object.freeze([
|
|
17
18
|
"operand",
|
|
@@ -38,19 +39,13 @@ function planText(command, decl, depth, start, from) {
|
|
|
38
39
|
const none = new Set();
|
|
39
40
|
if (depth > NESTING_MAX)
|
|
40
41
|
return { plan: { segments: [], unreadable: `command text nested more than ${NESTING_MAX} levels deep`, shape }, end: "unmodelled", physical: false, reached: none };
|
|
41
|
-
const
|
|
42
|
-
if ("parseFailure" in
|
|
43
|
-
return { plan: { segments: [], unreadable: PARSE_FAILURE_SENTENCE[
|
|
42
|
+
const lexedAsWritten = lexShell(command);
|
|
43
|
+
if ("parseFailure" in lexedAsWritten)
|
|
44
|
+
return { plan: { segments: [], unreadable: PARSE_FAILURE_SENTENCE[lexedAsWritten.parseFailure.reason], shape }, end: "unmodelled", physical: false, reached: none };
|
|
45
|
+
const lexed = inlineSourcedLiterals(lexedAsWritten);
|
|
44
46
|
const unreadable = unreadableSentenceOf(lexed, command);
|
|
45
47
|
const projected = projectSegments(lexed.segments);
|
|
46
48
|
const exportedFunctions = inheritedFunctionsOf(projected, start?.exportedFunctions), exportedNames = new Set(exportedFunctions.keys());
|
|
47
|
-
const named = projected.map((p, si) => bindingEffectOf(lexed.segments[si], p.argv, p, () => "unknown"));
|
|
48
|
-
const boundHere = (name) => named.some((e) => e.all === "unknown" || e.bindings.some((b) => b.name === name));
|
|
49
|
-
const boundAnywhere = (name) => boundHere(name) || start?.boundAnywhere(name) === true;
|
|
50
|
-
const declaredHome = decl.homeDir !== undefined ? [{ spelled: decl.homeDir }] : "unknown";
|
|
51
|
-
const declaredCdPath = decl.cdPath === "unknown" ? "unknown" : [{ spelled: (decl.cdPath ?? []).join(":") }];
|
|
52
|
-
const declared = (name, rebound) => (rebound ? "unknown" : name === "HOME" ? declaredHome : name === "CDPATH" ? declaredCdPath : "unknown");
|
|
53
|
-
const initial = start?.initial ?? ((name) => declared(name, false));
|
|
54
49
|
const loopShapes = projected.map((p) => loopShapeOf(p));
|
|
55
50
|
const loopEndOf = new Map();
|
|
56
51
|
{
|
|
@@ -65,13 +60,42 @@ function planText(command, decl, depth, start, from) {
|
|
|
65
60
|
}
|
|
66
61
|
});
|
|
67
62
|
}
|
|
63
|
+
const fedBase = stdinFeeds(lexed.segments, start?.stdin ?? [], (si) => [pipedTextOf(lexed.segments[si - 1])]);
|
|
64
|
+
const loopFeedOf = (si) => {
|
|
65
|
+
if (lexed.segments[si].connector === "|")
|
|
66
|
+
return undefined;
|
|
67
|
+
const heads = [...loopEndOf].filter(([h, end]) => h <= si && si < end).map(([h]) => h).sort((a, b) => b - a);
|
|
68
|
+
const inner = [];
|
|
69
|
+
for (const h of heads) {
|
|
70
|
+
const own = stdinTextsOf(lexed.segments[loopEndOf.get(h)], []);
|
|
71
|
+
if (own.some((t) => t.allocated !== true))
|
|
72
|
+
return [...own, ...inner];
|
|
73
|
+
inner.unshift(...own);
|
|
74
|
+
}
|
|
75
|
+
return inner.length > 0 ? [...fedBase(si), ...inner] : undefined;
|
|
76
|
+
};
|
|
77
|
+
const fedAt = (si) => loopFeedOf(si) ?? fedBase(si);
|
|
78
|
+
const stdinOf = (si) => stdinTextsOf(lexed.segments[si], fedAt(si));
|
|
79
|
+
const declaredHome = decl.homeDir !== undefined ? [{ spelled: decl.homeDir }] : "unknown";
|
|
80
|
+
const declaredCdPath = decl.cdPath === "unknown" ? "unknown" : [{ spelled: (decl.cdPath ?? []).join(":") }];
|
|
81
|
+
const declared = (name, rebound) => (rebound ? "unknown" : name === "HOME" ? declaredHome : name === "CDPATH" ? declaredCdPath : "unknown");
|
|
82
|
+
const initial = start?.initial ?? ((name) => declared(name, false));
|
|
83
|
+
const named0 = projected.map((p, si) => bindingEffectOf(lexed.segments[si], p.argv, p, () => "unknown"));
|
|
84
|
+
const boundHere = (name) => named0.some((e) => e.all === "unknown" || e.bindings.some((b) => b.name === name));
|
|
85
|
+
const boundAnywhere = (name) => boundHere(name) || start?.boundAnywhere(name) === true;
|
|
86
|
+
const unknownAt = (j) => named0[j].all === "unknown" || named0[j].bindings.some((b) => b.name === "IFS");
|
|
87
|
+
const bodies0 = new BindingThread(lexed.segments, named0, initial, boundAnywhere, loopEndOf, start?.homeTouched === true, start?.inherited, start?.names);
|
|
88
|
+
const ifsBoundBefore = (si) => start?.boundAnywhere("IFS") === true || (bodies0.inFunctionBody(si) && boundHere("IFS")) || named0.some((_, j) => j < si && unknownAt(j)) || [...loopEndOf].some(([h, end]) => h <= si && si < end && named0.some((_, j) => h <= j && j < end && unknownAt(j)));
|
|
89
|
+
const feedsItself = (si) => lexed.segments[si].tokens.some((t) => (t.kind === "heredoc" && (t.fd ?? 0) === 0) || (t.kind === "redirect" && (t.fd ?? (t.op === "<" || t.op === "<<<" || t.op === "<>" || t.op === "<&" ? 0 : 1)) === 0));
|
|
90
|
+
const readFeedOf = (si) => ifsBoundBefore(si) ? [undefined, false] : [stdinOf(si), !feedsItself(si) && loopFeedOf(si) !== undefined];
|
|
91
|
+
const named = projected.map((p, si) => (ifsBoundBefore(si) ? named0[si] : bindingEffectOf(lexed.segments[si], p.argv, p, () => "unknown", undefined, undefined, ...readFeedOf(si))));
|
|
68
92
|
const names = new BindingThread(lexed.segments, named, initial, boundAnywhere, loopEndOf, start?.homeTouched === true, start?.inherited, start?.names);
|
|
69
93
|
const laterStart = { initial: (name) => declared(name, boundAnywhere(name)), boundAnywhere, homeTouched: boundAnywhere("HOME"), inherited: names.inheritedAt() };
|
|
70
|
-
const
|
|
94
|
+
const nestedTextStart = (table, si, kind, at, exported = exportedNames) => kind === "substitution" ? { initial: (name) => table.stateOf(name), boundAnywhere, homeTouched: table.homeTouched, inherited: table.inherited, thread: heldThread(moves.functions), names: heldAt(table), ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}) } : startedAt(kind === "now" ? { ...laterStart, inherited: { ...laterStart.inherited, rebound: joinRebound(table.inherited.rebound, commandEnvironmentNames(projected[si].argv)) }, ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}), ...(readProgramPosition(projected[si].argv).program?.basename === "eval" ? { thread: heldThread(moves.unread), names: heldAt(table, names.functionBound()) } : exportedFunctions.size > 0 ? { thread: { physical: false, functions: exported, unread: exported, reached: workdir.reached }, names: inheritedExportedFunctions(exportedFunctions) } : {}) } : { ...laterStart, thread: heldThread(moves.functions, workdir.mayBePhysical || moves.physicalAt.some(Boolean)), names: names.heldAnywhere(), ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}) }, at);
|
|
95
|
+
const nestedPlanner = (table, si) => (text, kind, at) => planShellReads(text, decl, depth + 1, nestedTextStart(table, si, kind, at));
|
|
71
96
|
const empty = lexed.segments.map((segment, si) => segmentIsEmpty(segment, projected[si]));
|
|
72
97
|
const facts = projected.map(() => undefined);
|
|
73
98
|
const tables = projected.map(() => undefined);
|
|
74
|
-
const fedAt = stdinFeeds(lexed.segments, start?.stdin ?? [], (si) => [pipedTextOf(lexed.segments[si - 1])]);
|
|
75
99
|
const inheritedFns = new Set([...(start?.exportedFunctions ?? [])].flatMap(([name, body]) => (body === "unread" ? [name] : [])));
|
|
76
100
|
const factsAt = (si, table) => {
|
|
77
101
|
tables[si] ??= table;
|
|
@@ -83,7 +107,7 @@ function planText(command, decl, depth, start, from) {
|
|
|
83
107
|
let places = written;
|
|
84
108
|
const stood = projected.map(() => ({ at: new Map(), lost: false }));
|
|
85
109
|
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);
|
|
110
|
+
const moves = textMovesOf(new Set(projected.flatMap((p) => p.defines)), lexed.segments, projected.map((p) => p.argv), (si) => names.inFunctionBody(si), start?.thread, exportedNames, fedAt);
|
|
87
111
|
names.runsBodies(moves.runsBodyAt, moves.bodiesAt.some((b) => b.length > 0), moves.mayCallAt.map((c, si) => (c ? commandEnvironmentNames(projected[si].argv) : undefined)));
|
|
88
112
|
let workdir = new WorkdirThread(depth > 0 && from === undefined && start?.bases === undefined ? [nestedStartOf(decl.cwd)] : (from ?? start?.bases ?? [decl.cwd]), start?.thread?.physical === true);
|
|
89
113
|
if (start?.thread?.reached !== undefined)
|
|
@@ -96,10 +120,11 @@ function planText(command, decl, depth, start, from) {
|
|
|
96
120
|
return { end: "unmodelled", physical: false, reached: new Set() };
|
|
97
121
|
if (!textMayMove(text, moves.functions) && !textSetsPhysical(text))
|
|
98
122
|
return { end: from, physical: false, reached: new Set() };
|
|
99
|
-
const ran = planText(text, decl, depth + 1,
|
|
123
|
+
const ran = planText(text, decl, depth + 1, evalStart(table), from);
|
|
100
124
|
return { end: ran.end, physical: ran.physical, reached: ran.reached, ...(ran.unsettled === true ? { unsettled: true } : {}) };
|
|
101
125
|
},
|
|
102
126
|
};
|
|
127
|
+
const evalStart = (table) => ({ initial: (name) => table.stateOf(name), boundAnywhere, homeTouched: table.homeTouched, inherited: table.inherited, thread: heldThread(moves.unread), names: heldAt(table, names.functionBound()) });
|
|
103
128
|
const heldThread = (unread, physical = workdir.mayBePhysical) => ({ physical, functions: moves.functions, unread, reached: workdir.reached });
|
|
104
129
|
let andRunStart = 0;
|
|
105
130
|
let crossedAllAnd = true;
|
|
@@ -167,14 +192,22 @@ function planText(command, decl, depth, start, from) {
|
|
|
167
192
|
const end = loopEndOf.get(si);
|
|
168
193
|
if (end !== undefined) {
|
|
169
194
|
const body = named.slice(si + 1, end);
|
|
170
|
-
names.kill(si, body.some((e) => e.all === "unknown") ? "all" : [...body.flatMap((e) => e.bindings.map((b) => b.name)), ...(moves.mayMove.slice(si + 1, end).some(Boolean) ? ["PWD", "OLDPWD"] : [])]);
|
|
195
|
+
names.kill(si, body.some((e) => e.all === "unknown") ? "all" : [...body.flatMap((e) => e.bindings.map((b) => b.name)), ...(moves.mayMove.slice(si + 1, end).some(Boolean) ? ["PWD", "OLDPWD"] : [])], lexed.segments[si].spliced === true);
|
|
171
196
|
}
|
|
172
197
|
const segment = lexed.segments[si];
|
|
173
|
-
const effect = bindingEffectOf(segment, projected[si].argv, projected[si], (w, quoted, overlay) => valueOf(w, table, quoted, overlay), moves.callAt(si, table), (builtin) => table.builtinState(builtin));
|
|
198
|
+
const effect = bindingEffectOf(segment, projected[si].argv, projected[si], (w, quoted, overlay) => valueOf(w, table, quoted, overlay), moves.callAt(si, table), (builtin) => table.builtinState(builtin), ...readFeedOf(si));
|
|
174
199
|
const { all, ...rest } = effect;
|
|
175
|
-
names.apply(si, all === "reset" ? rest : effect, segment.connector === "&&" || segment.connector === "||", end);
|
|
176
|
-
if (moves.callAt(si, table) !== undefined)
|
|
177
|
-
|
|
200
|
+
names.apply(si, all === "reset" ? rest : effect, segment.connector === "&&" || segment.connector === "||", end, segment.spliced === true);
|
|
201
|
+
if (moves.callAt(si, table) !== undefined) {
|
|
202
|
+
const bound = moves.callsUnread(si, table) ? "all" : names.functionBound();
|
|
203
|
+
if (bound === "all")
|
|
204
|
+
names.kill(si, "all", segment.spliced === true);
|
|
205
|
+
else {
|
|
206
|
+
const maybe = names.functionMaybeBound();
|
|
207
|
+
names.kill(si, [...bound].filter((n) => !maybe.has(n)), segment.spliced === true);
|
|
208
|
+
names.kill(si, maybe, true);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
178
211
|
if (moves.bodiesAt[si].length > 0)
|
|
179
212
|
names.runsLater(si, moves.bodiesAt[si].reduce((held, b) => joinRebound(held, namesBoundIn(b)), names.functionBound()));
|
|
180
213
|
};
|
|
@@ -184,7 +217,7 @@ function planText(command, decl, depth, start, from) {
|
|
|
184
217
|
for (const si of steps) {
|
|
185
218
|
const shapeOfLoop = loopShapes[si];
|
|
186
219
|
if (first && named[si].all === "reset")
|
|
187
|
-
names.apply(si, { bindings: [], all: "reset" }, false);
|
|
220
|
+
names.apply(si, { bindings: [], all: "reset" }, false, undefined, lexed.segments[si].spliced === true);
|
|
188
221
|
thread(si, !first);
|
|
189
222
|
if (first)
|
|
190
223
|
bind(si);
|
|
@@ -231,7 +264,32 @@ function planText(command, decl, depth, start, from) {
|
|
|
231
264
|
};
|
|
232
265
|
const ended = { at: end === "unmodelled" ? [] : end, lost: end === "unmodelled" };
|
|
233
266
|
const after = (s) => gather([ended, ...stood.slice(s + 1).map((p) => ({ at: p.at.values(), lost: p.lost }))]);
|
|
234
|
-
const
|
|
267
|
+
const handedCallers = new Map();
|
|
268
|
+
const textCallers = (j, t, here) => {
|
|
269
|
+
const table = tables[j];
|
|
270
|
+
if (table === undefined)
|
|
271
|
+
return here;
|
|
272
|
+
const launched = t.in !== "child" ? [] : (facts[j]?.readings ?? [facts[j]]).map((g) => (g === undefined ? undefined : launchedAt(g.launchedIn, here.at.map((c) => c.base), undefined, decl.homeDir)));
|
|
273
|
+
const starts = launched.some((l) => l !== undefined) ? launched.map((l) => (l === undefined ? here : l.to === "unmodelled" ? { at: [], lost: true } : { at: l.to.map((base) => ({ base, skippedCd: -1 })), lost: here.lost })) : [here];
|
|
274
|
+
return gather(starts.map((s) => {
|
|
275
|
+
if (s.at.length === 0)
|
|
276
|
+
return s;
|
|
277
|
+
const key = JSON.stringify([j, t.text, t.in, s.at.map(keyOf)]);
|
|
278
|
+
let ran = handedCallers.get(key);
|
|
279
|
+
if (ran === undefined) {
|
|
280
|
+
const start = t.in === "shell" ? evalStart(table) : nestedTextStart(table, j, t.in === "child" ? "now" : "substitution", undefined, t.functions);
|
|
281
|
+
ran = planText(t.text, decl, depth + 1, start, s.at).callers ?? s;
|
|
282
|
+
handedCallers.set(key, ran);
|
|
283
|
+
}
|
|
284
|
+
return { at: ran.at, lost: ran.lost || s.lost };
|
|
285
|
+
}));
|
|
286
|
+
};
|
|
287
|
+
const callers = () => gather(stood.flatMap((p, j) => {
|
|
288
|
+
if (!moves.runsBodyAt[j])
|
|
289
|
+
return [];
|
|
290
|
+
const runs = moves.bodyRunsAt[j], here = { at: [...p.at.values()], lost: p.lost };
|
|
291
|
+
return [...(runs.here ? [here] : []), ...runs.texts.map((t) => textCallers(j, t, here)), ...(moves.bodiesAt[j].length > 0 ? [after(j)] : [])];
|
|
292
|
+
}));
|
|
235
293
|
const main = workdir;
|
|
236
294
|
const bodies = new Map();
|
|
237
295
|
projected.forEach((_, si) => {
|
|
@@ -272,6 +330,8 @@ function planText(command, decl, depth, start, from) {
|
|
|
272
330
|
workdir = main;
|
|
273
331
|
places = written;
|
|
274
332
|
main.widen(went);
|
|
333
|
+
const ownCallers = callers();
|
|
334
|
+
const callersOut = grew ? { at: ownCallers.at, lost: true } : ownCallers;
|
|
275
335
|
const planned = facts.map((f) => f);
|
|
276
336
|
const inert = depth === 0 && unreadable === undefined && planned.every((f) => (f.readings ?? [f]).every(segmentOpensNothing));
|
|
277
337
|
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;
|
|
@@ -338,7 +398,7 @@ function planText(command, decl, depth, start, from) {
|
|
|
338
398
|
}
|
|
339
399
|
}
|
|
340
400
|
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 } : {}) };
|
|
401
|
+
return { plan: { segments, shape, ...(unreadable !== undefined ? { unreadable } : {}) }, end: workdir.end(), physical: workdir.mayBePhysical, reached, ...(workdir.unsettled ? { unsettled: true } : {}), callers: callersOut };
|
|
342
402
|
}
|
|
343
403
|
function loopShapeOf(p) {
|
|
344
404
|
if (p.argv[0] === undefined)
|
|
@@ -423,7 +483,7 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
|
|
|
423
483
|
const runLater = new Set();
|
|
424
484
|
const ctx = { table, reentered: [], programTextSeen: false };
|
|
425
485
|
const enclosedToo = (e) => [e, ...(e.inner ?? []).flatMap(enclosedToo)];
|
|
426
|
-
const expansionsOf = (sg) => sg.tokens.flatMap((t) => (t.kind === "word" ? t : t.kind === "redirect"
|
|
486
|
+
const expansionsOf = (sg) => sg.tokens.flatMap((t) => (t.kind === "word" ? assignedWords(t) : t.kind === "redirect" && t.target !== undefined ? [t.target] : [])).flatMap((w) => w.pieces).flatMap((q) => (q.expansion !== undefined ? enclosedToo(q.expansion) : []));
|
|
427
487
|
const count = (list, body) => list.filter((b) => b === body).length;
|
|
428
488
|
const substitute = (body, here) => void (here ? ctx.reentered.push(body) : nested.push(nestedPlan(body, "substitution")));
|
|
429
489
|
const unread = (sentence) => void nested.push({ segments: [], unreadable: sentence, shape: { grouped: false, backgrounded: false, strayRedirection: false } });
|
|
@@ -675,12 +735,18 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
|
|
|
675
735
|
reads.push(bare(programRead, "program_path"));
|
|
676
736
|
if (rewritten(programRead) && !programRead.word.pieces.some((p) => p.literal?.includes("/") === true))
|
|
677
737
|
shift = { kind: "lost" };
|
|
678
|
-
if (basename === "eval")
|
|
679
|
-
|
|
738
|
+
if (basename === "eval") {
|
|
739
|
+
const text = literalEvalText(argReads.map((r) => r.word));
|
|
740
|
+
shift = text !== undefined ? { kind: "eval", text } : { kind: "lost" };
|
|
741
|
+
}
|
|
680
742
|
if (basename === "source" || basename === ".")
|
|
681
743
|
shift = { kind: "lost" };
|
|
682
|
-
if (reentersShell(basename, args))
|
|
683
|
-
|
|
744
|
+
if (reentersShell(basename, args)) {
|
|
745
|
+
const named = descriptorNameWords(segment);
|
|
746
|
+
const kept = argReads.map((r) => !named.has(r.word));
|
|
747
|
+
const allocatedReading = kept.includes(false) ? [{ shell: basename, texts: texts.filter((_, k) => kept[k]), args: args.filter((_, k) => kept[k]), words: argReads.filter((_, k) => kept[k]) }] : [];
|
|
748
|
+
return reenterShell(verb, [{ shell: basename, texts, args, words: argReads }, ...allocatedReading]);
|
|
749
|
+
}
|
|
684
750
|
const row = programRow(basename);
|
|
685
751
|
const delivery = programDelivery(row, args);
|
|
686
752
|
if (delivery !== undefined)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sourced file this very command WROTE is the text it sources (#3400).
|
|
3
|
+
*
|
|
4
|
+
* `. ./lib.sh` / `source lib.sh` run a file's text in THIS shell: the functions it defines stand after it, and a call
|
|
5
|
+
* to one later runs its body where the call stands. The station cannot read a file — but where the same command wrote
|
|
6
|
+
* the file first, with a literal printer and a `>` redirection (`printf 'f(){ …; }\n' > lib.sh; . ./lib.sh`), the text
|
|
7
|
+
* it sources IS the literal the printer spells: the segments of that literal are spliced in place of the `source`
|
|
8
|
+
* segment, before anything is projected, so every later reader (definitions, bodies, callers, bindings, the
|
|
9
|
+
* working-directory thread) reads them as the shell runs them — no reader of its own.
|
|
10
|
+
*
|
|
11
|
+
* Fail-closed where the claim does not hold: a file the command did not write IMMEDIATELY before the source (another
|
|
12
|
+
* segment between — a second write, a move, a pipe, a group — is a claim the station does not make), a write reached
|
|
13
|
+
* through `&&` / `||` that the source is not chained to (it may not have run), a write with `>>`, through a pipe, with
|
|
14
|
+
* a word the shell rewrites or a format that converts, a printer with a launcher or a prefix assignment, a `source`
|
|
15
|
+
* carrying a redirection of its own, or a literal the lexer cannot read, splices nothing — the `source` segment stays what it was (text run in this shell that the
|
|
16
|
+
* station does not hold: an unsettled start, the #3358 law). Bash's `sourcepath` PATH search of a bare name is not
|
|
17
|
+
* read: the file the command wrote at that spelling is taken as the text (docs/KNOWN-LIMITS.md KL-3400-a).
|
|
18
|
+
*/
|
|
19
|
+
import { type LexedCommand } from "../../shell/lex.js";
|
|
20
|
+
/**
|
|
21
|
+
* THE splice ({@link module}): each `source` / `.` of a file this text wrote with a literal printer earlier, no base move
|
|
22
|
+
* between, is replaced by the segments of the written literal (the first taking the `source` segment's connector).
|
|
23
|
+
* Returns the command unchanged where nothing splices.
|
|
24
|
+
*/
|
|
25
|
+
export declare function inlineSourcedLiterals(lexed: LexedCommand): LexedCommand;
|