@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
|
@@ -74,7 +74,7 @@ export function walkFromStart(base) {
|
|
|
74
74
|
const at = base.search(/[\\/]\u0000(?:[\\/]|$)/);
|
|
75
75
|
return at < 0 ? undefined : base.slice(at + 3);
|
|
76
76
|
}
|
|
77
|
-
const settledWord = (r) => r.expands === false && (r.values?.length ?? 1) <= 1 && r.
|
|
77
|
+
const settledWord = (r) => r.expands === false && (r.values?.length ?? 1) <= 1 && r.word.pieces.every((q) => q.literal !== undefined || q.expansion !== undefined);
|
|
78
78
|
export function launchedInOf(pos, toks) {
|
|
79
79
|
if (pos.baseMovedAt.length === 0)
|
|
80
80
|
return undefined;
|
|
@@ -92,14 +92,14 @@ export function launchedInOf(pos, toks) {
|
|
|
92
92
|
const word = toks[step === 2 ? at + 1 : at];
|
|
93
93
|
const twoWays = own?.form === "attached" && own.spec?.arity === "attached" && own.value.startsWith("=");
|
|
94
94
|
const value = step === 2 ? word.folded : own?.form === "attached" && !twoWays ? literalTildeSpelling(own.value) : undefined;
|
|
95
|
-
const dir = value !== undefined && value !== ""
|
|
95
|
+
const dir = !settledWord(word) ? null : value !== undefined && value !== "" ? value : undefined;
|
|
96
96
|
if (l.index === owner)
|
|
97
97
|
dirs[dirs.length - 1] = dir;
|
|
98
98
|
else
|
|
99
99
|
dirs.push(dir);
|
|
100
100
|
owner = l.index;
|
|
101
101
|
}
|
|
102
|
-
return dirs.
|
|
102
|
+
return dirs.includes(undefined) ? "unmodelled" : dirs;
|
|
103
103
|
}
|
|
104
104
|
export function launchedAt(launchedIn, bases, floor, homeDir) {
|
|
105
105
|
if (launchedIn === undefined)
|
|
@@ -107,8 +107,14 @@ export function launchedAt(launchedIn, bases, floor, homeDir) {
|
|
|
107
107
|
const here = bases !== "unmodelled" ? bases : floor;
|
|
108
108
|
let to = launchedIn === "unmodelled" ? "unmodelled" : bases;
|
|
109
109
|
let toFloor = here;
|
|
110
|
+
let unsettled = false;
|
|
110
111
|
for (const dir of launchedIn === "unmodelled" ? [] : launchedIn) {
|
|
111
|
-
if (
|
|
112
|
+
if (dir === null) {
|
|
113
|
+
toFloor = [...new Set([...(to !== "unmodelled" ? to : (toFloor ?? [])), ...(here ?? [])])];
|
|
114
|
+
to = "unmodelled";
|
|
115
|
+
unsettled = true;
|
|
116
|
+
}
|
|
117
|
+
else if (to !== "unmodelled") {
|
|
112
118
|
const next = chdirFrom(to, dir, homeDir);
|
|
113
119
|
if (next === undefined)
|
|
114
120
|
to = "unmodelled";
|
|
@@ -119,19 +125,19 @@ export function launchedAt(launchedIn, bases, floor, homeDir) {
|
|
|
119
125
|
toFloor = chdirFrom(toFloor, dir, homeDir) ?? toFloor;
|
|
120
126
|
}
|
|
121
127
|
const words = [...new Set([...(here ?? []), ...(toFloor ?? [])])];
|
|
122
|
-
return { to, ...(toFloor !== undefined && toFloor.length > 0 ? { floor: toFloor } : {}), ...(words.length > 0 ? { words } : {}) };
|
|
128
|
+
return { to, ...(toFloor !== undefined && toFloor.length > 0 ? { floor: toFloor } : {}), ...(words.length > 0 ? { words } : {}), ...(unsettled ? { unsettled: true } : {}) };
|
|
123
129
|
}
|
|
124
|
-
export function rebasePlan(plan, to, floor) {
|
|
125
|
-
const key = JSON.stringify([to, floor]);
|
|
130
|
+
export function rebasePlan(plan, to, floor, unsettled = false) {
|
|
131
|
+
const key = JSON.stringify([to, floor, unsettled]);
|
|
126
132
|
const known = REBASED.get(plan)?.get(key);
|
|
127
133
|
if (known !== undefined)
|
|
128
134
|
return known;
|
|
129
|
-
const out = rebasedOnto(plan, to, floor);
|
|
135
|
+
const out = rebasedOnto(plan, to, floor, unsettled);
|
|
130
136
|
REBASED.set(plan, (REBASED.get(plan) ?? new Map()).set(key, out));
|
|
131
137
|
return out;
|
|
132
138
|
}
|
|
133
139
|
const REBASED = new WeakMap();
|
|
134
|
-
function rebasedOnto(plan, to, floor) {
|
|
140
|
+
function rebasedOnto(plan, to, floor, unsettled) {
|
|
135
141
|
const placed = (into, b) => {
|
|
136
142
|
const rest = walkFromStart(b);
|
|
137
143
|
if (rest === undefined)
|
|
@@ -142,7 +148,8 @@ function rebasedOnto(plan, to, floor) {
|
|
|
142
148
|
const floorAt = to === "unmodelled" ? floor : to;
|
|
143
149
|
const floorsOf = (bases, into) => {
|
|
144
150
|
const floors = [...new Set(bases.flatMap((b) => placed(into, b)))];
|
|
145
|
-
|
|
151
|
+
const fromStart = unsettled && to === "unmodelled" && bases.some((b) => walkFromStart(b) !== undefined);
|
|
152
|
+
return { ...(floors.length > 0 ? { floorBases: floors } : {}), ...(fromStart ? { unsettledStart: true } : {}) };
|
|
146
153
|
};
|
|
147
154
|
const moveCandidate = (c) => {
|
|
148
155
|
if (c.bases === "unmodelled") {
|
|
@@ -165,8 +172,9 @@ function rebasedOnto(plan, to, floor) {
|
|
|
165
172
|
redirects: s.redirects.map((r) => (r.target === undefined ? r : { ...r, target: moveCandidate(r.target) })),
|
|
166
173
|
...(s.baseMove !== undefined ? { baseMove: { target: typeof s.baseMove.target === "string" ? s.baseMove.target : moveCandidate(s.baseMove.target) } } : {}),
|
|
167
174
|
bases: s.bases === "unmodelled" || to === "unmodelled" ? "unmodelled" : [...new Set(s.bases.flatMap(moveBase))],
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
...(s.programStart !== undefined ? { programStart: moveCandidate(s.programStart) } : {}),
|
|
176
|
+
nested: s.nested.map((n) => rebasePlan(n, to, floor, unsettled)),
|
|
177
|
+
...(s.printed !== undefined ? { printed: s.printed.map((n) => rebasePlan(n, to, floor, unsettled)) } : {}),
|
|
170
178
|
})),
|
|
171
179
|
};
|
|
172
180
|
}
|
|
@@ -62,6 +62,14 @@ export interface SegmentReading {
|
|
|
62
62
|
* one reading.
|
|
63
63
|
*/
|
|
64
64
|
export declare function segmentReadingsOf(argv: readonly LexedWord[], targets: readonly LexedWord[], table: BindingTable, homeDir: string | undefined): SegmentReading[];
|
|
65
|
+
/** The word the shell hands the program for one read in a reading: its one value as the argument word it is
|
|
66
|
+
* ({@link argumentWordOf}), named by the read's `raw` — the word's own spelling as written, or a split field's own text —
|
|
67
|
+
* where the read settled into one value that is no pattern and is not the word's own spelling; the word as written
|
|
68
|
+
* otherwise. An assignment the shell PERFORMS (at command position) stays the assignment it is; an assignment-shaped
|
|
69
|
+
* ARGUMENT (`dd of="$T"`) is the value it expands to, as any argument is — and a word whose value is assignment-shaped
|
|
70
|
+
* is that argument (`X=of=k; dd "$X"` hands dd the keyed `of=k`): the readers that ask an argument's `NAME=value` shape
|
|
71
|
+
* ask it of this word. */
|
|
72
|
+
export declare function receivedWordOf(r: Read): LexedWord;
|
|
65
73
|
/** The spelling a reader names a value by, read directly as a path — for a pattern, the name the program opens where it
|
|
66
74
|
* matches nothing: its text, a leading `~` spelled as the literal tilde it is ({@link literalTildeSpelling}, the lexer's
|
|
67
75
|
* spelling of a written one) — the shell never tilde-expands what a quoted piece or an expansion produced, so a value that
|
|
@@ -113,6 +121,8 @@ export declare function spelledWithHome(spelled: string, raw: string, home: stri
|
|
|
113
121
|
* arithmetic expression (`$((2*(3+4)))`), which bash evaluates and never globs. A compound assignment's value is no
|
|
114
122
|
* such word — the assignment reads nothing — unless the unread value may run something ({@link compoundValueHidesRun}). */
|
|
115
123
|
export declare function unreadableSentenceOf(lexed: LexedCommand, text: string, globs?: boolean): string | undefined;
|
|
124
|
+
/** The mark a settled value carries: `"glob"` when an unquoted pathname-expansion character survives in it. */
|
|
125
|
+
export declare function globMark(glob: boolean): WordExpands;
|
|
116
126
|
/** What the shell does to a word (or an assignment's value) before the program sees it, read off its pieces: the
|
|
117
127
|
* lexer's expansion facts alone. A quoted text that an evaluator or an interpreter later RUNS (an arithmetic
|
|
118
128
|
* subscript, an inline program) is no rewrite of the word: the slot it stands in says what it is (the program read
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { argvOf, compoundValueHidesRun, lexShell, literalTildeSpelling, UNRESOLVED_SENTENCE } from "../../shell/lex.js";
|
|
2
2
|
import { expansionInWord, extglobOpenerIn, globInWord, homeExpansionOf } from "./bash-readonly-classifier.js";
|
|
3
3
|
import { floorOf, judgedSpellingOf, namesIn, wordFloorValues, wordValues } from "./shell-read-bindings.js";
|
|
4
|
+
import { READINGS_MAX } from "./shell-read-brace.js";
|
|
4
5
|
export function readsOf(words, table, homeDir, split = false) {
|
|
5
6
|
return words.map((word) => {
|
|
6
7
|
const refersToName = word.pieces.some((p) => p.expansion?.kind === "parameter") || namesIn(word).length > 0;
|
|
@@ -24,14 +25,13 @@ export function readsOf(words, table, homeDir, split = false) {
|
|
|
24
25
|
raw: word.raw,
|
|
25
26
|
folded: spellingOf(values[0]),
|
|
26
27
|
...(pattern !== undefined ? { pattern } : {}),
|
|
27
|
-
expands: glob
|
|
28
|
+
expands: globMark(glob),
|
|
28
29
|
settled: true,
|
|
29
30
|
values,
|
|
30
31
|
...(floor !== undefined && !values.every((v) => spellingOf(v) === floor) ? { homeFloor: floor } : {}),
|
|
31
32
|
};
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
|
-
const READINGS_MAX = 64;
|
|
35
35
|
export function segmentReadingsOf(argv, targets, table, homeDir) {
|
|
36
36
|
const several = new Map();
|
|
37
37
|
for (const word of [...argv, ...targets]) {
|
|
@@ -73,7 +73,7 @@ export function segmentReadingsOf(argv, targets, table, homeDir) {
|
|
|
73
73
|
floors.set(name, floor);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
return { table: reading, reads: fielded, argv: fielded.map(
|
|
76
|
+
return { table: reading, reads: fielded, argv: fielded.map(receivedWordOf), floors };
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
function namesReadIn(word, table) {
|
|
@@ -96,9 +96,10 @@ function overlaidTable(table, overlay) {
|
|
|
96
96
|
inherited: table.inherited,
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
export function receivedWordOf(r) {
|
|
100
|
+
const word = r.word;
|
|
100
101
|
const v = r.values?.length === 1 ? r.values[0] : undefined;
|
|
101
|
-
if (word.assignment !== undefined || v === undefined || v.glob === true || v.spelled === word.folded)
|
|
102
|
+
if ((word.assignment !== undefined && word.atCommandPosition) || v === undefined || v.glob === true || v.spelled === word.folded)
|
|
102
103
|
return word;
|
|
103
104
|
return argumentWordOf(v.spelled, r.raw) ?? word;
|
|
104
105
|
}
|
|
@@ -158,6 +159,9 @@ export function unreadableSentenceOf(lexed, text, globs = true) {
|
|
|
158
159
|
}
|
|
159
160
|
return globs && extglobOpenerIn(lexed, text) ? "an extended pattern (`?(…)` `*(…)` `+(…)` `@(…)` `!(…)`) is one this reader does not expand" : undefined;
|
|
160
161
|
}
|
|
162
|
+
export function globMark(glob) {
|
|
163
|
+
return glob ? "glob" : false;
|
|
164
|
+
}
|
|
161
165
|
export function expandsOf(w) {
|
|
162
166
|
if (expansionInWord(w))
|
|
163
167
|
return "unresolvable";
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import type { Bare } from "./shell-read-argv.js";
|
|
15
15
|
import type { BindingTable, WorkingDirectoryState } from "./shell-read-bindings.js";
|
|
16
16
|
import type { Read } from "./shell-read-word.js";
|
|
17
|
-
import { type LexedWord } from "../../shell/lex.js";
|
|
17
|
+
import { type LexedSegment, type LexedWord } from "../../shell/lex.js";
|
|
18
18
|
import { type FunctionCall } from "./shell-read-functions.js";
|
|
19
19
|
/** A working directory the shell could be standing in, with the latest move this candidate assumes did NOT run
|
|
20
20
|
* (`skippedCd`), and what the shell holds there: `pwd` — what `PWD` spells (absent: not the base's spelling — a physical
|
|
@@ -45,14 +45,16 @@ export type BaseShift = {
|
|
|
45
45
|
};
|
|
46
46
|
/** What the walk asks of the plan around it: the declared home (a `~` target), whether the text binds a name anywhere
|
|
47
47
|
* (`OLDPWD` — then `cd -` reads the table's value; `PWD` — then a move's `OLDPWD` is not the base the candidate stood
|
|
48
|
-
* in), and where a literal `eval` text started at a candidate
|
|
48
|
+
* in), and where a literal `eval` text started at candidates — a candidate, the floor of a walk that lost track, or a place
|
|
49
|
+
* the walk does not know — ends ({@link WorkdirThread.end}), and where its walk went that its end does not say (`reached`). */
|
|
49
50
|
export interface WorkdirContext {
|
|
50
51
|
readonly homeDir?: string;
|
|
51
52
|
readonly textBinds: (name: string) => boolean;
|
|
52
|
-
readonly evalEnd: (text: string, from: BaseCandidate, table: BindingTable) => {
|
|
53
|
+
readonly evalEnd: (text: string, from: readonly BaseCandidate[] | "unmodelled", table: BindingTable) => {
|
|
53
54
|
readonly end: readonly BaseCandidate[] | "unmodelled";
|
|
54
55
|
readonly physical: boolean;
|
|
55
56
|
readonly reached: ReadonlySet<string>;
|
|
57
|
+
readonly unsettled?: true;
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
/** One segment's move as the walk applies it: the shift, whether an `&&` run proves it ran, the first segment of the
|
|
@@ -83,6 +85,13 @@ export declare class WorkdirThread {
|
|
|
83
85
|
/** The physical mode may already be on where the text starts (an `eval` text run in a shell that set it). */
|
|
84
86
|
startsPhysical?: boolean);
|
|
85
87
|
get lost(): boolean;
|
|
88
|
+
/** The walk lost track at a move to a directory the text does not settle ({@link movesToUnsettled}, a literal `eval` text's
|
|
89
|
+
* own such move): what the text does after it, it does from a directory it does not know
|
|
90
|
+
* ({@link import("./shell-read-plan.js").ReadCandidate.unsettledStart}); so does a loop it does not count that moved it
|
|
91
|
+
* (each beat moves again from where the last one went). Once set it stays: a closed scope's places stay
|
|
92
|
+
* in the deny floor ({@link restore}), and a function body that moved may run at any later call. */
|
|
93
|
+
get unsettled(): boolean;
|
|
94
|
+
private unsettledAt;
|
|
86
95
|
/** The deny floor of the words the walk could not place: a closed scope that lost track keeps its floor for its words. */
|
|
87
96
|
get floorBases(): readonly string[] | undefined;
|
|
88
97
|
private closedFloors;
|
|
@@ -106,9 +115,18 @@ export declare class WorkdirThread {
|
|
|
106
115
|
private scopeReached;
|
|
107
116
|
get reached(): ReadonlySet<string>;
|
|
108
117
|
reach(bases: Iterable<string>): void;
|
|
118
|
+
/** The walk once more, from `at` — candidates, or `lost` where this walk's floor says —, holding what this walk holds where
|
|
119
|
+
* it ends: its mode, the places its scopes went, whether it went to a directory it does not know. Where a text written
|
|
120
|
+
* earlier runs later (a function body at a call after it) it is walked from there. `floor`: places a walk started where it
|
|
121
|
+
* does not know may stand, beside this walk's floor. */
|
|
122
|
+
fork(at: readonly BaseCandidate[] | "lost", floor?: readonly string[]): WorkdirThread;
|
|
123
|
+
/** Where a text this walk runs later went (`places`) is where a word it could not place may stand: they join the deny floor,
|
|
124
|
+
* where it has one. */
|
|
125
|
+
widen(places: Iterable<string>): void;
|
|
109
126
|
/** Stop placing anything from segment `at` on: the reachable bases (and a target's floor spellings, the places a closed
|
|
110
|
-
* scope went) become the deny floor.
|
|
111
|
-
|
|
127
|
+
* scope went) become the deny floor. `unsettled`: the walk no longer knows where it stands either (a move it ran a number
|
|
128
|
+
* of times it does not count). */
|
|
129
|
+
lose(at: number, reachable: readonly BaseCandidate[], floorTargets?: readonly string[], unsettled?: boolean): void;
|
|
112
130
|
/** Apply segment `si`'s move. */
|
|
113
131
|
shift(si: number, at: ShiftAt, ctx: WorkdirContext): void;
|
|
114
132
|
/** Where one candidate goes: the places (the CDPATH entries a bare target is searched through, then the target itself),
|
|
@@ -158,7 +176,8 @@ export interface TextMoves {
|
|
|
158
176
|
readonly mayMove: readonly boolean[];
|
|
159
177
|
/** Segment `si` may call a function (read before the walk, to bound where bodies run). */
|
|
160
178
|
readonly mayCallAt: readonly boolean[];
|
|
161
|
-
/** Segment `si` may run a function body: it may call one, hands a code body to run
|
|
179
|
+
/** Segment `si` may run a function body where it stands ({@link segmentRunsBody}): it may call one, hands a code body to run
|
|
180
|
+
* later, runs text the plan does not read, or hands a shell a text that may (a substitution). */
|
|
162
181
|
readonly runsBodyAt: readonly boolean[];
|
|
163
182
|
readonly bodiesAt: readonly (readonly string[])[];
|
|
164
183
|
readonly physicalAt: readonly boolean[];
|
|
@@ -171,7 +190,7 @@ export interface TextMoves {
|
|
|
171
190
|
/** The segment runs a body that may move the base where the walk cannot follow it: a call when a body may move or whose body is not read, a code body that may move or call one. */
|
|
172
191
|
losesBaseAt(si: number, table: BindingTable): boolean;
|
|
173
192
|
}
|
|
174
|
-
export declare function textMovesOf(defined: ReadonlySet<string>, argvs: readonly (readonly LexedWord[])[], inFunctionBody: (si: number) => boolean, inherited?: {
|
|
193
|
+
export declare function textMovesOf(defined: ReadonlySet<string>, segments: readonly LexedSegment[], argvs: readonly (readonly LexedWord[])[], inFunctionBody: (si: number) => boolean, inherited?: {
|
|
175
194
|
readonly functions: ReadonlySet<string>;
|
|
176
195
|
readonly unread: ReadonlySet<string>;
|
|
177
196
|
}): TextMoves;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { argvOf, lexShell } from "../../shell/lex.js";
|
|
1
|
+
import { argvOf, expansionsInHeredocBody, lexShell } from "../../shell/lex.js";
|
|
2
2
|
import { shellWordsOf } from "../../shell/shell-words.js";
|
|
3
3
|
import { resolveOperandLexically, resolveOperandSpellings } from "./bash-readonly-classifier.js";
|
|
4
4
|
import { readProgramPosition } from "./bash-program-position.js";
|
|
@@ -26,6 +26,10 @@ export class WorkdirThread {
|
|
|
26
26
|
get lost() {
|
|
27
27
|
return this.lostAt;
|
|
28
28
|
}
|
|
29
|
+
get unsettled() {
|
|
30
|
+
return this.unsettledAt;
|
|
31
|
+
}
|
|
32
|
+
unsettledAt = false;
|
|
29
33
|
get floorBases() {
|
|
30
34
|
return this.closedFloors.length === 0 ? this.floors : [...new Set([...(this.floors ?? []), ...this.closedFloors])];
|
|
31
35
|
}
|
|
@@ -78,15 +82,43 @@ export class WorkdirThread {
|
|
|
78
82
|
reach(bases) {
|
|
79
83
|
this.scopeReached = new Set([...this.scopeReached, ...bases]);
|
|
80
84
|
}
|
|
81
|
-
|
|
85
|
+
fork(at, floor = []) {
|
|
86
|
+
const w = new WorkdirThread(at === "lost" ? "unmodelled" : at, this.physical);
|
|
87
|
+
if (at === "lost") {
|
|
88
|
+
w.candidates = this.candidates;
|
|
89
|
+
const floors = [...new Set([...(this.floorBases ?? []), ...floor])];
|
|
90
|
+
if (floors.length > 0)
|
|
91
|
+
w.floors = floors;
|
|
92
|
+
}
|
|
93
|
+
w.scopeReached = this.scopeReached;
|
|
94
|
+
w.unsettledAt = this.unsettledAt;
|
|
95
|
+
w.movedAt = this.movedAt;
|
|
96
|
+
return w;
|
|
97
|
+
}
|
|
98
|
+
widen(places) {
|
|
99
|
+
if ((this.floorBases ?? []).length > 0)
|
|
100
|
+
this.closedFloors = [...new Set([...this.closedFloors, ...places])];
|
|
101
|
+
}
|
|
102
|
+
lose(at, reachable, floorTargets = [], unsettled = false) {
|
|
82
103
|
this.movedAt = Math.max(this.movedAt, at);
|
|
83
104
|
this.lostAt = true;
|
|
105
|
+
if (unsettled)
|
|
106
|
+
this.unsettledAt = true;
|
|
84
107
|
this.floors ??= [...new Set([...reachable.map((c) => c.base), ...floorTargets, ...this.scopeReached])];
|
|
85
108
|
}
|
|
86
109
|
shift(si, at, ctx) {
|
|
87
110
|
if (this.lostAt) {
|
|
88
|
-
|
|
89
|
-
|
|
111
|
+
const floors = this.floors ?? [];
|
|
112
|
+
const before = this.reachable(at.andRunStart).map((c) => c.base);
|
|
113
|
+
const named = [...new Set([...floors, ...before])];
|
|
114
|
+
if (named.length > BASE_CANDIDATE_MAX)
|
|
115
|
+
this.unsettledAt = true;
|
|
116
|
+
const from = floors.length === 0 ? [] : named.length > BASE_CANDIDATE_MAX ? [...new Set(before)] : named;
|
|
117
|
+
const ran = at.shift.kind === "eval" ? ctx.evalEnd(at.shift.text, from.length === 0 ? "unmodelled" : from.map((base) => ({ base, skippedCd: -1 })), at.table) : undefined;
|
|
118
|
+
if (from.length > 0)
|
|
119
|
+
this.floors = [...new Set([...floors, ...(ran === undefined ? floorOf(at.shift, from, ctx) : [...ran.reached, ...(ran.end === "unmodelled" ? [] : ran.end.map((c) => c.base))])])];
|
|
120
|
+
if (movesToUnsettled(at.shift) || ran?.unsettled === true)
|
|
121
|
+
this.unsettledAt = true;
|
|
90
122
|
return;
|
|
91
123
|
}
|
|
92
124
|
this.movedAt = si;
|
|
@@ -102,8 +134,11 @@ export class WorkdirThread {
|
|
|
102
134
|
for (const c of this.candidates) {
|
|
103
135
|
if (c.skippedCd < at.andRunStart) {
|
|
104
136
|
const moved = this.movedFrom(c, at, ctx);
|
|
105
|
-
if (moved === "lost")
|
|
106
|
-
|
|
137
|
+
if (moved === "lost") {
|
|
138
|
+
if (movesToUnsettled(s))
|
|
139
|
+
this.unsettledAt = true;
|
|
140
|
+
return this.lose(si, reachable, floorOf(s, reachable.map((r) => r.base), ctx));
|
|
141
|
+
}
|
|
107
142
|
for (const m of moved)
|
|
108
143
|
branched.push({ ...m, skippedCd: c.skippedCd });
|
|
109
144
|
}
|
|
@@ -125,9 +160,11 @@ export class WorkdirThread {
|
|
|
125
160
|
movedFrom(c, at, ctx) {
|
|
126
161
|
const s = at.shift;
|
|
127
162
|
if (s.kind === "eval") {
|
|
128
|
-
const ran = ctx.evalEnd(s.text, c, at.table);
|
|
163
|
+
const ran = ctx.evalEnd(s.text, [c], at.table);
|
|
129
164
|
if (ran.physical)
|
|
130
165
|
this.physical = true;
|
|
166
|
+
if (ran.unsettled === true)
|
|
167
|
+
this.unsettledAt = true;
|
|
131
168
|
this.reach(ran.reached);
|
|
132
169
|
return ran.end === "unmodelled" ? "lost" : ran.end.map((e) => (this.physical ? withoutPwd(e) : e));
|
|
133
170
|
}
|
|
@@ -158,7 +195,7 @@ export class WorkdirThread {
|
|
|
158
195
|
}
|
|
159
196
|
}
|
|
160
197
|
const withoutPwd = ({ pwd: _, ...c }) => c;
|
|
161
|
-
function floorOf(s,
|
|
198
|
+
function floorOf(s, from, ctx) {
|
|
162
199
|
if (s.kind !== "cd")
|
|
163
200
|
return [];
|
|
164
201
|
if (s.target === "home")
|
|
@@ -166,7 +203,10 @@ function floorOf(s, reachable, ctx) {
|
|
|
166
203
|
if (typeof s.target === "string")
|
|
167
204
|
return [];
|
|
168
205
|
const target = s.target;
|
|
169
|
-
return [...(target.floorSpelled !== undefined ? [target.floorSpelled] : []), ...(target.expands === false ?
|
|
206
|
+
return [...(target.floorSpelled !== undefined ? [target.floorSpelled] : []), ...(target.expands === false ? from.flatMap((base) => { const at = resolveOperandSpellings(base, target.spelled, ctx.homeDir); return at === undefined ? [] : [at.spelled ?? at.folded]; }) : [])];
|
|
207
|
+
}
|
|
208
|
+
function movesToUnsettled(s) {
|
|
209
|
+
return s.kind === "cd" && typeof s.target !== "string" && s.target.expands !== false;
|
|
170
210
|
}
|
|
171
211
|
function targetsOf(target, c, at, ctx) {
|
|
172
212
|
if (target === "home")
|
|
@@ -284,7 +324,29 @@ export function segmentMayMove(argv, functions) {
|
|
|
284
324
|
const word = argv[pos.program.index];
|
|
285
325
|
return shellWordsOf("base_mover").has(pos.program.basename) || TEXT_RUNNING_PROGRAMS.has(pos.program.basename) || functionCallOf(argv, functions) !== undefined || word.pieces.some((p) => p.expansion !== undefined || p.literal === undefined);
|
|
286
326
|
}
|
|
287
|
-
|
|
327
|
+
function segmentRunsBody(segment, argv, functions) {
|
|
328
|
+
const pos = readProgramPosition(argv);
|
|
329
|
+
const word = pos.program === undefined ? undefined : argv[pos.program.index];
|
|
330
|
+
const p = programOf(argv);
|
|
331
|
+
if (functionCallOf(argv, functions) !== undefined || (p !== undefined && codeBodies(p.name, p.args).length > 0))
|
|
332
|
+
return true;
|
|
333
|
+
if (word !== undefined && (TEXT_RUNNING_PROGRAMS.has(pos.program.basename) || word.pieces.some((q) => q.expansion !== undefined || q.literal === undefined)))
|
|
334
|
+
return true;
|
|
335
|
+
if (functions.size === 0)
|
|
336
|
+
return false;
|
|
337
|
+
const words = segment.tokens.flatMap((t) => (t.kind === "word" ? [t] : t.kind === "redirect" && t.target !== undefined ? [t.target] : []));
|
|
338
|
+
if (words.some((w) => w.unresolved === "parameter_text"))
|
|
339
|
+
return true;
|
|
340
|
+
const heredocs = segment.tokens.flatMap((t) => (t.kind === "heredoc" && !t.quoted ? [expansionsInHeredocBody(t.body)] : []));
|
|
341
|
+
if (heredocs.some((b) => b === undefined || b.some((x) => x.unresolved !== undefined)))
|
|
342
|
+
return true;
|
|
343
|
+
const texts = [...segment.substitutions, ...heredocs.flatMap((b) => (b ?? []).flatMap((x) => (x.expansion.kind === "command" ? [x.expansion.body ?? ""] : [])))];
|
|
344
|
+
return texts.some((text) => {
|
|
345
|
+
const lexed = lexShell(text);
|
|
346
|
+
return "parseFailure" in lexed || lexed.segments.some((s) => segmentRunsBody(s, argvOf(s), functions));
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
export function textMovesOf(defined, segments, argvs, inFunctionBody, inherited) {
|
|
288
350
|
const unread = new Set([...evalDefinedFunctions(argvs), ...(inherited?.unread ?? [])]);
|
|
289
351
|
const functions = new Set([...defined, ...unread, ...(inherited?.functions ?? [])]);
|
|
290
352
|
const programs = argvs.map(programOf);
|
|
@@ -292,11 +354,10 @@ export function textMovesOf(defined, argvs, inFunctionBody, inherited) {
|
|
|
292
354
|
const bodyMoves = mayMove.some((m, si) => m && inFunctionBody(si));
|
|
293
355
|
const bodiesAt = programs.map((p) => (p === undefined ? [] : codeBodies(p.name, p.args)));
|
|
294
356
|
const mayCallAt = argvs.map((argv) => functionCallOf(argv, functions) !== undefined);
|
|
295
|
-
const runsTextAt = argvs.map((argv) => { const pos = readProgramPosition(argv); const word = pos.program === undefined ? undefined : argv[pos.program.index]; return word !== undefined && (["eval", "source", "."].includes(pos.program.basename) || word.pieces.some((p) => p.expansion !== undefined || p.literal === undefined)); });
|
|
296
357
|
const callAt = (si, table) => functionCallOf(argvs[si], functions, (name) => table.functionState(name));
|
|
297
358
|
const callsUnread = (si, table) => functionCallOf(argvs[si], unread, (name) => table.functionState(name)) !== undefined;
|
|
298
359
|
return {
|
|
299
|
-
functions, unread, mayMove, mayCallAt, runsBodyAt:
|
|
360
|
+
functions, unread, mayMove, mayCallAt, runsBodyAt: argvs.map((argv, si) => segmentRunsBody(segments[si], argv, functions)), bodiesAt, bodyMoves, callAt, callsUnread,
|
|
300
361
|
physicalAt: programs.map(setsPhysical),
|
|
301
362
|
cdableFrom: programs.findIndex((p) => p?.name === "shopt" && p.args.includes("-s") && p.args.includes("cdable_vars")),
|
|
302
363
|
losesBaseAt: (si, table) => (callAt(si, table) !== undefined && bodyMoves) || callsUnread(si, table) || bodiesAt[si].some((b) => bodyMoves || textMayMove(b, functions)),
|
|
@@ -105,7 +105,7 @@ function writeTargetsOf(segment) {
|
|
|
105
105
|
writeOnly.add(c);
|
|
106
106
|
}
|
|
107
107
|
for (const o of owners) {
|
|
108
|
-
for (const c of copyDestinationChildren(segment, o.row, o.words, o.
|
|
108
|
+
for (const c of copyDestinationChildren(segment, o.row, o.words, o.all))
|
|
109
109
|
write(c, ["landing", "entry"], undefined, true);
|
|
110
110
|
out.push(...backupTargetsOf(edited.get(o) ?? [], o.readings, o.override));
|
|
111
111
|
}
|
|
@@ -134,23 +134,28 @@ function backupTargetsOf(edited, readings, override) {
|
|
|
134
134
|
}
|
|
135
135
|
function copyDestinationChildren(segment, row, words, readings) {
|
|
136
136
|
const candidateOf = (raw) => segment.reads.find((c) => c.raw === raw && WORD_PROVENANCES.has(c.provenance));
|
|
137
|
+
const start = segment.programStart;
|
|
137
138
|
const children = new Map();
|
|
138
139
|
for (const r of readings) {
|
|
139
140
|
if (r.copy === undefined)
|
|
140
141
|
continue;
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
142
|
+
const { destination, sources } = r.copy;
|
|
143
|
+
const destWord = destination !== undefined ? words[destination.at] : { raw: ".", spelled: "." };
|
|
144
|
+
const dest = { raw: destWord.raw, spelled: destination?.value ?? destWord.spelled };
|
|
145
|
+
const destCandidate = destination !== undefined ? candidateOf(dest.raw) : start;
|
|
144
146
|
if (destCandidate !== undefined && destCandidate.expands !== false)
|
|
145
147
|
continue;
|
|
146
|
-
const destRole = r.written.find((w) => w.at ===
|
|
148
|
+
const destRole = r.written.find((w) => w.at === destination?.at)?.role;
|
|
147
149
|
if (destCandidate !== undefined && destRole !== undefined && passesUnasked({ ...destCandidate, face: "write", ...(writesThrough([destRole], row, words) ? { through: true } : {}) }))
|
|
148
150
|
continue;
|
|
149
|
-
for (const at of
|
|
151
|
+
for (const at of sources) {
|
|
150
152
|
const src = words[at];
|
|
151
153
|
const source = candidateOf(src.raw);
|
|
152
|
-
if (source !== undefined && source.expands !== false)
|
|
153
|
-
|
|
154
|
+
if (source !== undefined && source.expands !== false) {
|
|
155
|
+
if (destination !== undefined)
|
|
156
|
+
continue;
|
|
157
|
+
children.set(`\0${source.raw}`, source);
|
|
158
|
+
}
|
|
154
159
|
const child = `${dest.spelled.replace(/\/+$/, "")}/${src.spelled.replace(/\/+$/, "").split("/").pop() ?? ""}`;
|
|
155
160
|
if (child.endsWith("/") || children.has(child))
|
|
156
161
|
continue;
|
package/dist/tools/worktree.d.ts
CHANGED
|
@@ -90,8 +90,9 @@ export declare function currentCheckoutOf(session: WorktreeSessionRef | undefine
|
|
|
90
90
|
}): string;
|
|
91
91
|
/** A leg's write-location seat (the EnterWorktree session; empty until the worktree mount seeds it) and its readers, minted
|
|
92
92
|
* before any write-root reader: `writeLocation` ({@link currentCheckoutOf} over the seat) and `checkout` — the write location
|
|
93
|
-
* when it is a managed tree (a switch,
|
|
94
|
-
* carry it under, for the write-protection
|
|
93
|
+
* when it is in a managed tree (a switch, a task root that IS one, or a task root below one — a session's tree with the task
|
|
94
|
+
* root in `pkg/`): the tree's canonical identity and the spelling the leg's paths carry it under, for the write-protection
|
|
95
|
+
* judge's current-tree reading (`WriteProtectionCompileOptions.checkoutOf`). */
|
|
95
96
|
export declare function writeLocationOf(taskRoot: {
|
|
96
97
|
readonly spelled: string;
|
|
97
98
|
readonly canonical: string;
|
package/dist/tools/worktree.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { defineTool, errorResult } from "../core/tools.js";
|
|
4
|
-
import { addWorktree, managedWorktreeBaseOf, pruneWorktrees, removeManagedWorktree, worktreeNameProblem, WORKTREE_PARENT } from "../core/git-worktree-env.js";
|
|
4
|
+
import { addWorktree, managedTreeAt, managedWorktreeBaseOf, pruneWorktrees, removeManagedWorktree, resolveBaseCommit, worktreeNameProblem, WORKTREE_PARENT } from "../core/git-worktree-env.js";
|
|
5
5
|
import { mountRuleFace, toolFace } from "../core/tool-catalog-entries.js";
|
|
6
6
|
import { thrownText } from "../core/thrown-value.js";
|
|
7
7
|
export function currentCheckoutOf(session, taskRoot) {
|
|
@@ -18,10 +18,10 @@ export function writeLocationOf(taskRoot) {
|
|
|
18
18
|
const writeLocation = () => currentCheckoutOf(seat, taskRoot);
|
|
19
19
|
const checkout = () => {
|
|
20
20
|
const views = [];
|
|
21
|
-
for (const [
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
views.push({ root, base, kind });
|
|
21
|
+
for (const [at, kind] of [[writeLocation(), "canonical"], [seat.current?.worktreeDir ?? taskRoot.spelled, "spelled"]]) {
|
|
22
|
+
const tree = managedTreeAt(at);
|
|
23
|
+
if (tree !== undefined)
|
|
24
|
+
views.push({ root: tree.root, base: tree.base, kind });
|
|
25
25
|
}
|
|
26
26
|
return views.length > 0 ? views : undefined;
|
|
27
27
|
};
|
|
@@ -105,34 +105,6 @@ function reasonOf(e) {
|
|
|
105
105
|
}
|
|
106
106
|
return thrownText(e);
|
|
107
107
|
}
|
|
108
|
-
async function resolveBaseCommit(env, repoRoot, baseRef, readFloor) {
|
|
109
|
-
const rev = async (ref) => {
|
|
110
|
-
const r = await env.exec(`git rev-parse --verify --quiet ${shq(`${ref}^{commit}`)}`, { cwd: repoRoot, ...(readFloor !== undefined ? { readFloor } : {}) });
|
|
111
|
-
return r.ok && r.value.exitCode === 0 ? r.value.stdout.trim() : undefined;
|
|
112
|
-
};
|
|
113
|
-
if (baseRef === "head") {
|
|
114
|
-
const sha = await rev("HEAD");
|
|
115
|
-
return sha ? { sha, label: "HEAD" } : { error: "cannot resolve HEAD (empty repository with no commits?)" };
|
|
116
|
-
}
|
|
117
|
-
const sym = await env.exec("git symbolic-ref --quiet refs/remotes/origin/HEAD", { cwd: repoRoot, ...(readFloor !== undefined ? { readFloor } : {}) });
|
|
118
|
-
if (sym.ok && sym.value.exitCode === 0) {
|
|
119
|
-
const branch = sym.value.stdout.trim().replace(/^refs\/remotes\//, "");
|
|
120
|
-
if (branch) {
|
|
121
|
-
const sha = await rev(branch);
|
|
122
|
-
if (sha)
|
|
123
|
-
return { sha, label: branch };
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
for (const candidate of ["main", "master"]) {
|
|
127
|
-
const sha = await rev(candidate);
|
|
128
|
-
if (sha)
|
|
129
|
-
return { sha, label: candidate };
|
|
130
|
-
}
|
|
131
|
-
const sha = await rev("HEAD");
|
|
132
|
-
return sha
|
|
133
|
-
? { sha, label: "HEAD", note: " (no remote default branch or local main/master found — fell back to HEAD)" }
|
|
134
|
-
: { error: "cannot resolve a fresh base (no default branch and no HEAD)" };
|
|
135
|
-
}
|
|
136
108
|
export function createWorktreeTools(env, opts) {
|
|
137
109
|
const { repoRoot, cwdRef } = opts;
|
|
138
110
|
const session = opts.session ?? {};
|
|
@@ -207,7 +179,7 @@ export function createWorktreeTools(env, opts) {
|
|
|
207
179
|
}
|
|
208
180
|
const rootCanon = await env.canonicalPath(repoRoot);
|
|
209
181
|
const fence = rootCanon.ok ? rootCanon.value : repoRoot;
|
|
210
|
-
if (target !== fence && !target.startsWith(fence.endsWith("/") ? fence : `${fence}/`)) {
|
|
182
|
+
if (target !== fence && !target.startsWith(fence.endsWith("/") ? fence : `${fence}/`) && managedWorktreeBaseOf(target) === undefined) {
|
|
211
183
|
return errorResult(`Error (EnterWorktree): the worktree ${target} lives outside the task root ${repoRoot}; ` +
|
|
212
184
|
"read containment stays anchored at the task root, so it cannot be entered from this session.");
|
|
213
185
|
}
|
|
@@ -412,7 +384,7 @@ export function createWorktreeTools(env, opts) {
|
|
|
412
384
|
details: { type: "worktree", action: "exit", worktreeDir: active.worktreeDir, kept: true },
|
|
413
385
|
};
|
|
414
386
|
}
|
|
415
|
-
const removal = await removeManagedWorktree(env, repoRoot, active.worktreeDir, active.branch !== undefined ? { name: active.branch, baseSha: active.baseSha } : undefined, () => readFloor);
|
|
387
|
+
const removal = await removeManagedWorktree(env, repoRoot, active.worktreeDir, active.branch !== undefined ? { name: active.branch, baseSha: active.baseSha } : undefined, () => readFloor, "discard");
|
|
416
388
|
const removeFailure = removal.ok ? undefined : removal.detail.trim();
|
|
417
389
|
const branchNote = !removal.ok ? "" : removal.branchKept !== undefined ? ` Its branch was kept: ${removal.branchKept}.` : removal.branchDeleted !== undefined ? ` Its branch ${removal.branchDeleted} was deleted.` : "";
|
|
418
390
|
const pruned = await pruneWorktrees(env, repoRoot, readFloor);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sema-agent/core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.64.0",
|
|
4
4
|
"description": "Stateless, task-oriented AI agent core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "BUSL-1.1",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
"dependencies": {
|
|
125
125
|
"@modelcontextprotocol/client": "2.4.0",
|
|
126
126
|
"@modelcontextprotocol/core": "2.4.0",
|
|
127
|
-
"@sema-agent/primitives": "7.
|
|
127
|
+
"@sema-agent/primitives": "7.64.0",
|
|
128
128
|
"typebox": "1.1.39",
|
|
129
129
|
"undici": "7.30.0"
|
|
130
130
|
},
|
|
@@ -135,6 +135,7 @@
|
|
|
135
135
|
"@modelcontextprotocol/server": "2.4.0",
|
|
136
136
|
"@types/node": "22.10.2",
|
|
137
137
|
"@types/pg": "^8.20.0",
|
|
138
|
+
"mysql2": "^3.22.4",
|
|
138
139
|
"pg": "^8.22.0",
|
|
139
140
|
"pg-mem": "^3.0.14",
|
|
140
141
|
"tsx": "4.19.2",
|