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