@sema-agent/core 7.69.0 → 7.69.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/CHANGELOG.md +583 -0
  2. package/dist/agents/repair-loop.js +6 -14
  3. package/dist/agents/subagent.js +2 -1
  4. package/dist/agents/verify.d.ts +1 -1
  5. package/dist/agents/verify.js +7 -1
  6. package/dist/brain/reasoning-request.d.ts +7 -0
  7. package/dist/brain/reasoning-request.js +6 -0
  8. package/dist/core/agent-config-dir.d.ts +39 -3
  9. package/dist/core/agent-config-dir.js +67 -11
  10. package/dist/core/allow-entry.d.ts +5 -5
  11. package/dist/core/allow-entry.js +12 -6
  12. package/dist/core/ask-headline.d.ts +2 -2
  13. package/dist/core/ask-origin.d.ts +31 -31
  14. package/dist/core/ask-origin.js +20 -13
  15. package/dist/core/attachment-source.d.ts +1 -1
  16. package/dist/core/attachment-source.js +1 -0
  17. package/dist/core/auto-compaction.d.ts +44 -62
  18. package/dist/core/auto-compaction.js +44 -103
  19. package/dist/core/cache-break-detector.d.ts +23 -11
  20. package/dist/core/cache-break-detector.js +11 -5
  21. package/dist/core/checkpoint-features.d.ts +1 -1
  22. package/dist/core/checkpoint-features.js +1 -1
  23. package/dist/core/checkpoint-requirements.d.ts +19 -1
  24. package/dist/core/checkpoint-requirements.js +6 -0
  25. package/dist/core/checkpoint-row-verdict.js +3 -0
  26. package/dist/core/checkpoint-store.d.ts +13 -2
  27. package/dist/core/child-clamp-seats.d.ts +30 -3
  28. package/dist/core/child-clamp-seats.js +24 -0
  29. package/dist/core/compaction-retired-members.d.ts +12 -0
  30. package/dist/core/compaction-retired-members.js +22 -0
  31. package/dist/core/config-refusal-codes.d.ts +1 -1
  32. package/dist/core/config-refusal-codes.js +2 -0
  33. package/dist/core/context-edit.d.ts +32 -17
  34. package/dist/core/context-edit.js +28 -0
  35. package/dist/core/cron.d.ts +68 -0
  36. package/dist/core/cron.js +259 -0
  37. package/dist/core/engine-attestation.d.ts +16 -0
  38. package/dist/core/engine-attestation.js +2 -0
  39. package/dist/core/engine-capabilities.d.ts +14 -1
  40. package/dist/core/engine-capabilities.js +1 -1
  41. package/dist/core/engine-notice.d.ts +18 -7
  42. package/dist/core/engine-version.js +1 -1
  43. package/dist/core/gate-outcome.d.ts +29 -2
  44. package/dist/core/gate-outcome.js +6 -0
  45. package/dist/core/git-read-only.d.ts +10 -0
  46. package/dist/core/git-read-only.js +1 -0
  47. package/dist/core/git-worktree-env.js +9 -8
  48. package/dist/core/governance-codes.d.ts +9 -2
  49. package/dist/core/governance-codes.js +9 -0
  50. package/dist/core/locked-config.js +7 -3
  51. package/dist/core/lsp.d.ts +3 -0
  52. package/dist/core/lsp.js +3 -2
  53. package/dist/core/memory-engine/engine.d.ts +48 -12
  54. package/dist/core/memory-engine/engine.js +108 -46
  55. package/dist/core/memory-engine/file-backend.d.ts +2 -1
  56. package/dist/core/memory-engine/index-copies.d.ts +47 -0
  57. package/dist/core/memory-engine/index-copies.js +88 -0
  58. package/dist/core/memory-engine/layout.d.ts +20 -3
  59. package/dist/core/memory-engine/layout.js +39 -3
  60. package/dist/core/memory-engine/origin-clearance.d.ts +9 -7
  61. package/dist/core/memory-engine/origin-clearance.js +2 -4
  62. package/dist/core/memory-engine/types.d.ts +16 -3
  63. package/dist/core/mode-policy.d.ts +7 -1
  64. package/dist/core/mode-policy.js +9 -0
  65. package/dist/core/mods/session-compact.js +3 -3
  66. package/dist/core/mods/stations.d.ts +2 -0
  67. package/dist/core/mods/stations.js +2 -1
  68. package/dist/core/path-guard-rows.d.ts +8 -3
  69. package/dist/core/path-guard-rows.js +18 -5
  70. package/dist/core/peer-seat.d.ts +3 -0
  71. package/dist/core/peer-seat.js +3 -0
  72. package/dist/core/permission-rule-model.js +3 -2
  73. package/dist/core/process-identity.d.ts +11 -3
  74. package/dist/core/process-identity.js +26 -16
  75. package/dist/core/runner/assemble-result.d.ts +5 -0
  76. package/dist/core/runner/assemble-result.js +1 -1
  77. package/dist/core/runner/cleared-results-record.d.ts +33 -0
  78. package/dist/core/runner/cleared-results-record.js +56 -0
  79. package/dist/core/runner/compact-session.js +14 -9
  80. package/dist/core/runner/compaction-knobs.d.ts +1 -1
  81. package/dist/core/runner/continuation-gate.js +2 -1
  82. package/dist/core/runner/continues-from.d.ts +1 -1
  83. package/dist/core/runner/continues-from.js +1 -1
  84. package/dist/core/runner/contracts.d.ts +83 -31
  85. package/dist/core/runner/conversation-segment.d.ts +19 -12
  86. package/dist/core/runner/conversation-segment.js +27 -7
  87. package/dist/core/runner/derived-route-fallback.d.ts +2 -12
  88. package/dist/core/runner/derived-route-fallback.js +0 -6
  89. package/dist/core/runner/gate-exit.d.ts +2 -1
  90. package/dist/core/runner/gate-exit.js +4 -2
  91. package/dist/core/runner/git-status-frame.d.ts +2 -2
  92. package/dist/core/runner/git-status-frame.js +2 -1
  93. package/dist/core/runner/initial-run-state.js +1 -1
  94. package/dist/core/runner/leg-caller-places.d.ts +39 -0
  95. package/dist/core/runner/leg-caller-places.js +23 -0
  96. package/dist/core/runner/leg-frame.d.ts +8 -2
  97. package/dist/core/runner/leg-receipt.d.ts +29 -2
  98. package/dist/core/runner/leg-receipt.js +37 -6
  99. package/dist/core/runner/media-removed-seat.d.ts +10 -6
  100. package/dist/core/runner/media-removed-seat.js +6 -3
  101. package/dist/core/runner/messages-omitted-seat.d.ts +2 -1
  102. package/dist/core/runner/messages-omitted-seat.js +15 -5
  103. package/dist/core/runner/person-path-rows.d.ts +25 -7
  104. package/dist/core/runner/person-path-rows.js +16 -2
  105. package/dist/core/runner/prefix-ledger.d.ts +120 -0
  106. package/dist/core/runner/prefix-ledger.js +176 -0
  107. package/dist/core/runner/prepare-advisor.d.ts +2 -0
  108. package/dist/core/runner/prepare-advisor.js +2 -1
  109. package/dist/core/runner/prepare-artifact.d.ts +3 -0
  110. package/dist/core/runner/prepare-artifact.js +2 -2
  111. package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
  112. package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
  113. package/dist/core/runner/prepare-config-doors.d.ts +9 -8
  114. package/dist/core/runner/prepare-config-doors.js +15 -12
  115. package/dist/core/runner/prepare-context-lane.d.ts +25 -6
  116. package/dist/core/runner/prepare-context-lane.js +82 -27
  117. package/dist/core/runner/prepare-gate-stations.d.ts +1 -2
  118. package/dist/core/runner/prepare-gate-stations.js +2 -4
  119. package/dist/core/runner/prepare-hands-readface.d.ts +18 -5
  120. package/dist/core/runner/prepare-hands-readface.js +41 -22
  121. package/dist/core/runner/prepare-inherited-gate.d.ts +5 -0
  122. package/dist/core/runner/prepare-inherited-gate.js +2 -0
  123. package/dist/core/runner/prepare-memory.d.ts +10 -2
  124. package/dist/core/runner/prepare-memory.js +51 -5
  125. package/dist/core/runner/prepare-policy-chain.d.ts +3 -0
  126. package/dist/core/runner/prepare-policy-chain.js +13 -2
  127. package/dist/core/runner/prepare-prompt-assembly.d.ts +12 -4
  128. package/dist/core/runner/prepare-prompt-assembly.js +10 -4
  129. package/dist/core/runner/prepare-prompt-inputs.d.ts +3 -7
  130. package/dist/core/runner/prepare-prompt-inputs.js +6 -7
  131. package/dist/core/runner/prepare-safety-scan.js +7 -0
  132. package/dist/core/runner/prepare-suspend-saga.d.ts +4 -0
  133. package/dist/core/runner/prepare-suspend-saga.js +3 -2
  134. package/dist/core/runner/prepare-task.js +59 -53
  135. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +5 -11
  136. package/dist/core/runner/prepare-tool-disclosure-mount.js +7 -8
  137. package/dist/core/runner/prepare-turn-wiring.d.ts +16 -25
  138. package/dist/core/runner/prepare-turn-wiring.js +8 -18
  139. package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
  140. package/dist/core/runner/prepare-wiring-manifest.js +3 -2
  141. package/dist/core/runner/prompt-suggestions.d.ts +3 -1
  142. package/dist/core/runner/prompt-suggestions.js +1 -1
  143. package/dist/core/runner/read-block-judge.d.ts +47 -0
  144. package/dist/core/runner/read-block-judge.js +33 -0
  145. package/dist/core/runner/role-resolution-table.d.ts +15 -10
  146. package/dist/core/runner/role-resolution-table.js +4 -5
  147. package/dist/core/runner/rule-store-unreadable-notice.d.ts +7 -4
  148. package/dist/core/runner/rule-store-unreadable-notice.js +4 -3
  149. package/dist/core/runner/run-compaction-machinery.d.ts +0 -10
  150. package/dist/core/runner/run-compaction-machinery.js +3 -39
  151. package/dist/core/runner/run-harness-handlers.js +4 -17
  152. package/dist/core/runner/run-identity-wiring.js +4 -1
  153. package/dist/core/runner/run-leg.js +11 -1
  154. package/dist/core/runner/run-recovery-lanes.d.ts +0 -4
  155. package/dist/core/runner/run-recovery-lanes.js +34 -18
  156. package/dist/core/runner/run-settle-and-teardown.d.ts +1 -3
  157. package/dist/core/runner/run-settle-and-teardown.js +14 -22
  158. package/dist/core/runner/run-telemetry-and-budget-seats.js +0 -1
  159. package/dist/core/runner/run-terminal-adoption.d.ts +11 -30
  160. package/dist/core/runner/run-terminal-adoption.js +5 -88
  161. package/dist/core/runner/run-tool-mount-facts.js +1 -5
  162. package/dist/core/runner/run-turn-boundary.js +56 -26
  163. package/dist/core/runner/runtask.js +7 -7
  164. package/dist/core/runner/session-hash-salt.d.ts +18 -0
  165. package/dist/core/runner/session-hash-salt.js +36 -0
  166. package/dist/core/runner/shell-env-withheld.d.ts +8 -5
  167. package/dist/core/runner/shell-env-withheld.js +3 -3
  168. package/dist/core/runner/side-call-account.d.ts +9 -1
  169. package/dist/core/runner/side-call-account.js +15 -4
  170. package/dist/core/runner/skill-mention.d.ts +12 -0
  171. package/dist/core/runner/skill-mention.js +50 -0
  172. package/dist/core/runner/stream-settle-backstop.js +1 -0
  173. package/dist/core/runner/synthetic-tools.js +2 -2
  174. package/dist/core/runner/tool-table-view.d.ts +5 -9
  175. package/dist/core/runner/tool-table-view.js +23 -21
  176. package/dist/core/runner/write-protection-station.d.ts +5 -2
  177. package/dist/core/runner/write-protection-station.js +1 -1
  178. package/dist/core/runner-deps.d.ts +25 -27
  179. package/dist/core/scheduler.d.ts +13 -3
  180. package/dist/core/scheduler.js +0 -12
  181. package/dist/core/secret-env.d.ts +47 -11
  182. package/dist/core/secret-env.js +65 -4
  183. package/dist/core/sensitive-path-policy.js +4 -0
  184. package/dist/core/session-checkout.js +10 -9
  185. package/dist/core/shell-read-silence.d.ts +2 -1
  186. package/dist/core/shell-run-candidates.d.ts +1 -1
  187. package/dist/core/shell-run-candidates.js +11 -3
  188. package/dist/core/task-event.d.ts +32 -10
  189. package/dist/core/task-intake.d.ts +5 -3
  190. package/dist/core/task-intake.js +6 -2
  191. package/dist/core/task-result.d.ts +39 -0
  192. package/dist/core/task-spec-members.d.ts +3 -0
  193. package/dist/core/task-spec-members.js +2 -2
  194. package/dist/core/task-spec.d.ts +37 -20
  195. package/dist/core/tool-policy.d.ts +30 -18
  196. package/dist/core/tool-policy.js +44 -32
  197. package/dist/core/tool-roster.d.ts +21 -7
  198. package/dist/core/tool-roster.js +34 -6
  199. package/dist/core/tool-spec-members.js +1 -1
  200. package/dist/core/tool-spec.d.ts +27 -0
  201. package/dist/core/tools.js +1 -0
  202. package/dist/core/trace.d.ts +42 -19
  203. package/dist/core/unc-spelling.d.ts +31 -0
  204. package/dist/core/unc-spelling.js +51 -0
  205. package/dist/core/wiring-manifest.d.ts +30 -3
  206. package/dist/core/wiring-manifest.js +10 -0
  207. package/dist/core/workflow-run-store-contract.js +22 -0
  208. package/dist/core/workflow-run-store.d.ts +17 -13
  209. package/dist/core/workflow-run-store.js +1 -1
  210. package/dist/core/write-protect.d.ts +4 -0
  211. package/dist/core/write-protect.js +17 -15
  212. package/dist/engine/compaction/compaction.d.ts +48 -98
  213. package/dist/engine/compaction/compaction.js +136 -216
  214. package/dist/engine/compaction/utils.d.ts +2 -11
  215. package/dist/engine/compaction/utils.js +4 -13
  216. package/dist/engine/execution-env/node-execution-env.js +17 -6
  217. package/dist/engine/harness/agent-harness.d.ts +19 -5
  218. package/dist/engine/harness/agent-harness.js +18 -7
  219. package/dist/engine/harness/types.d.ts +5 -7
  220. package/dist/engine/loop/agent-loop.d.ts +14 -1
  221. package/dist/engine/loop/agent-loop.js +31 -11
  222. package/dist/engine/loop/types.d.ts +8 -2
  223. package/dist/index.d.ts +9 -6
  224. package/dist/index.js +8 -6
  225. package/dist/internal/harness-types.d.ts +1 -1
  226. package/dist/internal/harness.d.ts +1 -1
  227. package/dist/internal/harness.js +1 -1
  228. package/dist/orchestration/run-spec.js +7 -2
  229. package/dist/orchestration/run-workflow-tool.js +5 -3
  230. package/dist/orchestration/workflow-park-adoption.d.ts +66 -8
  231. package/dist/orchestration/workflow-park-adoption.js +195 -45
  232. package/dist/orchestration/workflow-types.d.ts +20 -0
  233. package/dist/orchestration/workflow-types.js +1 -0
  234. package/dist/orchestration/workflow.d.ts +3 -2
  235. package/dist/orchestration/workflow.js +10 -4
  236. package/dist/prompt-assembly/catalog/core-behavior.js +6 -0
  237. package/dist/prompt-assembly/catalog/events.d.ts +8 -0
  238. package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +6 -0
  239. package/dist/prompt-assembly/catalog/locales/zh-Hans/mechanism.js +1 -0
  240. package/dist/prompt-assembly/catalog/mechanism.d.ts +8 -0
  241. package/dist/prompt-assembly/catalog/mechanism.js +1 -0
  242. package/dist/prompt-assembly/catalog/schema.d.ts +1 -1
  243. package/dist/prompt-assembly/catalog/schema.js +1 -0
  244. package/dist/prompt-assembly/catalog/sections.js +8 -0
  245. package/dist/prompt-assembly/event-registry.js +1 -0
  246. package/dist/prompt-assembly/select.js +1 -0
  247. package/dist/prompt-assembly/turn-snapshot.d.ts +14 -27
  248. package/dist/prompt-assembly/turn-snapshot.js +6 -18
  249. package/dist/prompt-assembly/types.d.ts +3 -0
  250. package/dist/prompts/default.d.ts +9 -0
  251. package/dist/prompts/default.js +4 -0
  252. package/dist/shell/lex.d.ts +75 -11
  253. package/dist/shell/lex.js +340 -76
  254. package/dist/tools/fs/bash-program-position.js +2 -6
  255. package/dist/tools/fs/bash-readonly-classifier.d.ts +18 -3
  256. package/dist/tools/fs/bash-readonly-classifier.js +19 -9
  257. package/dist/tools/fs/containment-face.d.ts +12 -3
  258. package/dist/tools/fs/containment-face.js +16 -7
  259. package/dist/tools/fs/file-read-check.d.ts +26 -1
  260. package/dist/tools/fs/file-read-check.js +20 -2
  261. package/dist/tools/fs/fs-bash.js +4 -4
  262. package/dist/tools/fs/fs-read.d.ts +3 -0
  263. package/dist/tools/fs/fs-read.js +2 -2
  264. package/dist/tools/fs/fs-search-tools.d.ts +2 -2
  265. package/dist/tools/fs/fs-search-tools.js +4 -4
  266. package/dist/tools/fs/index.js +5 -3
  267. package/dist/tools/fs/pdf.js +12 -4
  268. package/dist/tools/fs/read-deny-home.d.ts +13 -2
  269. package/dist/tools/fs/read-deny-home.js +26 -22
  270. package/dist/tools/fs/read-deny.js +15 -6
  271. package/dist/tools/fs/removal-targets.d.ts +33 -17
  272. package/dist/tools/fs/removal-targets.js +160 -61
  273. package/dist/tools/fs/repo-map.d.ts +1 -1
  274. package/dist/tools/fs/repo-map.js +2 -2
  275. package/dist/tools/fs/safety.d.ts +28 -5
  276. package/dist/tools/fs/safety.js +72 -8
  277. package/dist/tools/fs/shell-read-bindings.d.ts +8 -2
  278. package/dist/tools/fs/shell-read-bindings.js +25 -6
  279. package/dist/tools/fs/shell-read-check.d.ts +3 -0
  280. package/dist/tools/fs/shell-read-check.js +22 -4
  281. package/dist/tools/fs/shell-read-establish.js +73 -43
  282. package/dist/tools/fs/shell-read-judge.d.ts +32 -14
  283. package/dist/tools/fs/shell-read-judge.js +13 -5
  284. package/dist/tools/fs/shell-read-object-path.d.ts +5 -1
  285. package/dist/tools/fs/shell-read-object-path.js +17 -4
  286. package/dist/tools/fs/shell-read-plan.d.ts +8 -2
  287. package/dist/tools/fs/shell-read-plan.js +36 -22
  288. package/dist/tools/fs/shell-read-sourced.js +12 -4
  289. package/dist/tools/fs/shell-read-start.d.ts +4 -2
  290. package/dist/tools/fs/shell-read-start.js +3 -3
  291. package/dist/tools/fs/shell-read-workdir.d.ts +14 -6
  292. package/dist/tools/fs/shell-read-workdir.js +35 -17
  293. package/dist/tools/scheduler-tools.d.ts +7 -17
  294. package/dist/tools/scheduler-tools.js +9 -85
  295. package/dist/tools/worktree.js +5 -4
  296. package/package.json +3 -2
  297. package/test/export-surface.snapshot.json +47 -1
  298. package/wire-changes/core-stores-sql@7.68.6.json +39 -0
  299. package/wire-changes/core-stores-sql@7.69.1.json +39 -0
  300. package/wire-changes/core@7.68.6.json +125 -0
  301. package/wire-changes/core@7.69.1.json +2561 -0
  302. package/wire-changes/mods-kernel@7.68.6.json +39 -0
  303. package/wire-changes/mods-kernel@7.69.1.json +39 -0
  304. package/wire-changes/primitives@7.68.6.json +39 -0
  305. package/wire-changes/primitives@7.69.1.json +39 -0
  306. package/wire-changes/wiki-gate@7.68.6.json +39 -0
  307. package/wire-changes/wiki-gate@7.69.1.json +39 -0
  308. package/dist/core/runner/prompt-hash-salt.d.ts +0 -1
  309. package/dist/core/runner/prompt-hash-salt.js +0 -2
@@ -1,4 +1,4 @@
1
- import { hasWin32AliasedComponent, normalizeAbsPathLexically, withinAnyRoot } from "./safety.js";
1
+ import { hasWin32AliasedComponent, holdsProcSensitiveFile, isProcSensitiveFile, normalizeAbsPathLexically, withinAnyRoot } from "./safety.js";
2
2
  import { globInWord } from "./bash-readonly-classifier.js";
3
3
  import { readOfText } from "./shell-read-word.js";
4
4
  import { passesUnasked } from "./shell-read-device.js";
@@ -46,6 +46,14 @@ export function dispositionsOfRow(finding) {
46
46
  }
47
47
  export function judgeRead(read, boundary) {
48
48
  const writeTarget = read.candidate.face === "write";
49
+ if (!writeTarget) {
50
+ const walks = read.candidate.provenance === "traversal_root";
51
+ for (const view of read.target !== undefined ? [read.target] : read.spellings) {
52
+ const folded = normalizeAbsPathLexically(view);
53
+ if (isProcSensitiveFile(folded) || (walks && holdsProcSensitiveFile(folded)))
54
+ return { read, kind: "deny_hit", processPrivate: { matchedView: folded }, containment: containmentOf(read, boundary) };
55
+ }
56
+ }
49
57
  const deny = writeTarget ? boundary.writeDenyMatch : boundary.denyMatch;
50
58
  if (deny !== undefined) {
51
59
  const views = [...(read.target !== undefined ? [read.target] : []), ...read.spellings, ...(read.ancestorViews ?? []), ...(read.hops ?? [])];
@@ -137,7 +145,7 @@ export function anyFaceGuards(boundary) {
137
145
  export function foldShellReadFindings(judged) {
138
146
  let best = { finding: "none" };
139
147
  let unestablished = false;
140
- let unplacedRead = false;
148
+ let outsideOrUnresolved = false;
141
149
  const reentered = [];
142
150
  const raise = (next) => {
143
151
  if (next.finding === "unestablishable" || next.finding === "declined" || next.finding === "unanswered") {
@@ -145,8 +153,6 @@ export function foldShellReadFindings(judged) {
145
153
  if (!(next.witness === undefined ? judged.guards || judged.writeGuards : face === "write" ? judged.writeGuards : judged.guards))
146
154
  return;
147
155
  unestablished = true;
148
- if (next.finding === "unestablishable" && face !== "write")
149
- unplacedRead = true;
150
156
  }
151
157
  const rank = SHELL_READ_FINDING_RANK[next.finding] - SHELL_READ_FINDING_RANK[best.finding];
152
158
  if (rank > 0 || (rank === 0 && next.witness?.read.candidate.face === "write" && best.witness?.read.candidate.face !== "write"))
@@ -158,6 +164,8 @@ export function foldShellReadFindings(judged) {
158
164
  raise({ finding: "unestablishable", cause: j.plan.unreadable });
159
165
  for (const s of j.segments) {
160
166
  for (const f of s.findings) {
167
+ if (f.kind === "outside_roots" || (f.kind === "unestablishable" && f.read.unresolved === true && f.read.candidate.face !== "write"))
168
+ outsideOrUnresolved = true;
161
169
  if (denyOnly && f.kind !== "deny_hit" && (reading === "deny-hit" || f.kind !== "unanswered"))
162
170
  continue;
163
171
  if (f.kind !== "none")
@@ -192,7 +200,7 @@ export function foldShellReadFindings(judged) {
192
200
  unestablished = true;
193
201
  best = { finding: "unanswered", cause: unfinished.detail, ...(best.finding === "unestablishable" ? { ...(best.witness !== undefined ? { witness: best.witness } : {}), ...(best.declined !== undefined ? { declined: best.declined } : {}) } : {}) };
194
202
  }
195
- return { ...best, ...(unestablished ? { unestablished: true } : {}), ...(unplacedRead ? { unplacedRead: true } : {}), ...(unestablished && reentered.length > 0 ? { reentered } : {}) };
203
+ return { ...best, ...(unestablished ? { unestablished: true } : {}), ...(outsideOrUnresolved ? { outsideOrUnresolved: true } : {}), ...(unestablished && reentered.length > 0 ? { reentered } : {}) };
196
204
  }
197
205
  export function judgeEstablishedPlan(plan, established, boundary, nestedOf, printedOf) {
198
206
  return {
@@ -33,8 +33,12 @@ export declare function objectPathRepositoryOf(row: ProgramRow | undefined, glob
33
33
  export declare function mayCarryGitVariables(...names: readonly (Iterable<string> | "all")[]): boolean;
34
34
  /** Where a process stands after it `chdir()`s to `spelling` from each of `bases` (git's `-C`, a launcher's working-directory
35
35
  * option): the kernel's walk of the spelling, a `..` kept (`<base>/link/..` is the link target's parent, not `<base>`).
36
- * `undefined` where the spelling resolves to no place from some base (`~user`, a namespace spelling the base's family refuses). */
36
+ * `undefined` where the spelling resolves to no place from some base (`~user`, a namespace spelling the base's family refuses —
37
+ * a device spelling's drive stand-in is where it MAY lead, no place a process stands). */
37
38
  export declare function chdirFrom(bases: readonly string[], spelling: string, homeDir: string | undefined): string[] | undefined;
39
+ /** Where a `chdir()` to `spelling` from `bases` MAY lead without naming a place ({@link chdirFrom}): a device spelling's drive
40
+ * stand-in from each base — the deny floor of a directory the text does not place, never a place a process stands. */
41
+ export declare function chdirMayLeadTo(bases: readonly string[], spelling: string, homeDir: string | undefined): string[];
38
42
  /** The place of a RELATIVE object path: the directories it is relative to (`at`: where the command stands; `floor`: the deny
39
43
  * floor of an unsettled `at`), and how its top is found where it is relative to the top. */
40
44
  export declare function objectPathPlacement(spelled: string, repository: ObjectPathRepository | undefined, at: readonly string[] | "unmodelled", floor: readonly string[] | undefined, homeDir: string | undefined, variables: boolean): {
@@ -30,15 +30,28 @@ export function mayCarryGitVariables(...names) {
30
30
  return names.some((part) => part === "all" || [...part].some((n) => n.startsWith("GIT_")));
31
31
  }
32
32
  export function chdirFrom(bases, spelling, homeDir) {
33
- const out = bases.map((b) => resolveOperandSpellings(b, spelling, homeDir)).map((s) => s?.spelled ?? s?.folded);
33
+ const out = bases.map((b) => resolveOperandSpellings(b, spelling, homeDir)).map((s) => (s?.standIn === true ? undefined : (s?.spelled ?? s?.folded)));
34
34
  return out.every((p) => p !== undefined) ? [...new Set(out)] : undefined;
35
35
  }
36
+ export function chdirMayLeadTo(bases, spelling, homeDir) {
37
+ return [...new Set(bases.flatMap((b) => {
38
+ const s = resolveOperandSpellings(b, spelling, homeDir);
39
+ return s?.standIn === true ? [s.spelled ?? s.folded] : [];
40
+ }))];
41
+ }
36
42
  export function objectPathPlacement(spelled, repository, at, floor, homeDir, variables) {
37
43
  const dotted = /^\.\.?(?:\/|$)/.test(spelled);
38
- const place = (bases, word) => chdirFrom(bases, word, homeDir);
44
+ const mayLead = new Set();
45
+ const place = (bases, word) => {
46
+ const to = chdirFrom(bases, word, homeDir);
47
+ if (to === undefined)
48
+ for (const p of chdirMayLeadTo(bases, word, homeDir))
49
+ mayLead.add(p);
50
+ return to;
51
+ };
39
52
  const unplaced = (top) => {
40
- const floors = at === "unmodelled" ? floor : at;
41
- return { bases: "unmodelled", ...(floors !== undefined && floors.length > 0 ? { floorBases: floors } : {}), ...(top !== undefined ? { repositoryTop: top } : {}) };
53
+ const floors = [...new Set([...((at === "unmodelled" ? floor : at) ?? []), ...mayLead])];
54
+ return { bases: "unmodelled", ...(floors.length > 0 ? { floorBases: floors } : {}), ...(top !== undefined ? { repositoryTop: top } : {}) };
42
55
  };
43
56
  let starts = at === "unmodelled" ? undefined : at;
44
57
  for (const move of repository?.moves ?? [])
@@ -170,9 +170,15 @@ export interface ShellReadSegment {
170
170
  }
171
171
  export interface ShellReadPlan {
172
172
  readonly segments: readonly ShellReadSegment[];
173
- /** The lexer refused the whole text (an unterminated construct, nesting past the bound). UNCONDITIONAL
174
- * fail-closed for the consumer: a quote-blind re-read yields more words, never zero, so this is not "no candidates". */
173
+ /** Some of the text could not be read, in words: the lexer stopped before its end (an unterminated construct, see
174
+ * {@link unreadTail}), the text is nested past the bound, or a word's value is one the text does not hold. UNCONDITIONAL
175
+ * fail-closed for the consumer: a quote-blind re-read yields more words, never zero, so this is not "no candidates" —
176
+ * and never a reason to skip the segments the plan does hold: each of them is judged as any text's. */
175
177
  readonly unreadable?: string;
178
+ /** The lexer stopped before the text's end: the text from the segment it stopped in to the end, whose first segment nobody
179
+ * read in full (empty where an unterminated here-document took the text to its end). The plan's segments are the ones a
180
+ * shell may run around the stop ({@link segmentsAroundStop}). */
181
+ readonly unreadTail?: string;
176
182
  /** Shape facts the same lex produced, for the shape consumers; the read judgment does not read them. */
177
183
  readonly shape: {
178
184
  readonly grouped: boolean;
@@ -1,4 +1,4 @@
1
- import { assignedWords, expansionsInHeredocBody, descriptorNameWords, lexShell, PARSE_FAILURE_SENTENCE, substitutionsInHeredocBody, literalTextOf, literalTildeSpelling, parameterRereadsValue, UNRESOLVED_SENTENCE, } from "../../shell/lex.js";
1
+ import { assignedWords, expansionsInHeredocBody, descriptorNameWords, lexShell, PARSE_FAILURE_SENTENCE, segmentsAroundStop, substitutionsInHeredocBody, literalTextOf, literalTildeSpelling, parameterOperandLines, parameterRereadsValue, UNRESOLVED_SENTENCE, } from "../../shell/lex.js";
2
2
  import { programTextOf, readOfText, readsOf, rewritten, segmentReadingsOf, settledFieldsOf, spelledWithHome, unreadableSentenceOf } from "./shell-read-word.js";
3
3
  import { braceWordListsOf } from "./shell-read-brace.js";
4
4
  import { assignmentArithmetic, bare, listedVerbCandidates, pathSubcommandOf, programTextSentence, pushAssignment, roleReads, subscriptOnly, unlistedWords } from "./shell-read-argv.js";
@@ -9,7 +9,7 @@ import { POLL_LOOP_MAX_BEATS, attachedOptionPayloads, isPathShapedToken, program
9
9
  import { mayCarryGitVariables, objectPathPlacement } from "./shell-read-object-path.js";
10
10
  import { BLOCK_WORD_NAMES, commandLineOf, commandLineOptionSpellings, declaredAttributes, isDeclarationBuiltin, isInertBuiltin, launcherOptionPathRole, launcherOptionStep, readOptionRole, programLanguageOf, programTextOpensOf, selectedOptions, movesBaseByStack, opensNoOperand, programDelivery, programRow, readArgRoles, runsShellText, } from "./program-read-model.js";
11
11
  import { shellWordsOf } from "../../shell/shell-words.js";
12
- import { isAbsoluteForFamily } from "./safety.js";
12
+ import { isAbsoluteForFamily, ownProcessSpelling } from "./safety.js";
13
13
  import { codeBodies, launchedInput, literalEvalText, pipedTextOf, printedByProcess, reentersShell, reentryText, scriptFileAt, stdinTextOf, stdinTextsOf } from "./shell-reentry-text.js";
14
14
  import { heldAt, launchedAt, launchedInOf, nestedStartOf, plannedOnce, rebasePlan, startedAt, stdinFeeds } from "./shell-read-start.js";
15
15
  import { inlineSourcedLiterals } from "./shell-read-sourced.js";
@@ -40,10 +40,11 @@ function planText(command, decl, depth, start, from) {
40
40
  if (depth > NESTING_MAX)
41
41
  return { plan: { segments: [], unreadable: `command text nested more than ${NESTING_MAX} levels deep`, shape }, end: "unmodelled", physical: false, reached: none };
42
42
  const lexedAsWritten = lexShell(command);
43
- if ("parseFailure" in lexedAsWritten)
44
- return { plan: { segments: [], unreadable: PARSE_FAILURE_SENTENCE[lexedAsWritten.parseFailure.reason], shape }, end: "unmodelled", physical: false, reached: none };
45
- const lexed = inlineSourcedLiterals(lexedAsWritten);
46
- const unreadable = unreadableSentenceOf(lexed, command);
43
+ const failed = "parseFailure" in lexedAsWritten ? lexedAsWritten : undefined;
44
+ const readAround = failed !== undefined ? segmentsAroundStop(command, failed) : [];
45
+ const lexed = inlineSourcedLiterals("parseFailure" in lexedAsWritten ? { segments: readAround, substitutions: readAround.flatMap((s) => s.substitutions) } : lexedAsWritten);
46
+ const unreadTail = failed?.readBefore.at(-1)?.text;
47
+ const unreadable = failed !== undefined ? PARSE_FAILURE_SENTENCE[failed.parseFailure.reason] : unreadableSentenceOf(lexed, command);
47
48
  const projected = projectSegments(lexed.segments);
48
49
  const exportedFunctions = inheritedFunctionsOf(projected, start?.exportedFunctions), exportedNames = new Set(exportedFunctions.keys());
49
50
  const loopShapes = projected.map((p) => loopShapeOf(p));
@@ -81,17 +82,21 @@ function planText(command, decl, depth, start, from) {
81
82
  const declared = (name, rebound) => (rebound ? "unknown" : name === "HOME" ? declaredHome : name === "CDPATH" ? declaredCdPath : "unknown");
82
83
  const initial = start?.initial ?? ((name) => declared(name, false));
83
84
  const named0 = projected.map((p, si) => bindingEffectOf(lexed.segments[si], p.argv, p, () => "unknown"));
84
- const boundHere = (name) => named0.some((e) => e.all === "unknown" || e.bindings.some((b) => b.name === name));
85
- const boundAnywhere = (name) => boundHere(name) || start?.boundAnywhere(name) === true;
86
- const unknownAt = (j) => named0[j].all === "unknown" || named0[j].bindings.some((b) => b.name === "IFS");
85
+ const bindsAt = (j, name) => named0[j].all === "unknown" || named0[j].bindings.some((b) => b.name === name);
86
+ const boundAnywhere = (name) => named0.some((_, j) => bindsAt(j, name)) || start?.enclosingBinds(name) === true;
87
87
  const bodies0 = new BindingThread(lexed.segments, named0, initial, boundAnywhere, loopEndOf, start?.homeTouched === true, start?.inherited, start?.names);
88
- const ifsBoundBefore = (si) => start?.boundAnywhere("IFS") === true || (bodies0.inFunctionBody(si) && boundHere("IFS")) || named0.some((_, j) => j < si && unknownAt(j)) || [...loopEndOf].some(([h, end]) => h <= si && si < end && named0.some((_, j) => h <= j && j < end && unknownAt(j)));
88
+ const boundBefore = (name, si) => start?.enclosingBinds(name) === true || bodies0.bindsBefore(name, si);
89
89
  const feedsItself = (si) => lexed.segments[si].tokens.some((t) => (t.kind === "heredoc" && (t.fd ?? 0) === 0) || (t.kind === "redirect" && (t.fd ?? (t.op === "<" || t.op === "<<<" || t.op === "<>" || t.op === "<&" ? 0 : 1)) === 0));
90
- const readFeedOf = (si) => [stdinOf(si), !feedsItself(si) && loopFeedOf(si) !== undefined, ifsBoundBefore(si)];
90
+ const readFeedOf = (si) => [stdinOf(si), !feedsItself(si) && loopFeedOf(si) !== undefined, boundBefore("IFS", si)];
91
91
  const named = projected.map((p, si) => bindingEffectOf(lexed.segments[si], p.argv, p, (w, quoted, overlay) => valueOf(w, undefined, quoted, overlay), undefined, undefined, ...readFeedOf(si)));
92
92
  const names = new BindingThread(lexed.segments, named, initial, boundAnywhere, loopEndOf, start?.homeTouched === true, start?.inherited, start?.names);
93
- const laterStart = { initial: (name) => declared(name, boundAnywhere(name)), boundAnywhere, homeTouched: boundAnywhere("HOME"), inherited: names.inheritedAt() };
94
- const nestedTextStart = (table, si, kind, at, exported = exportedNames) => kind === "substitution" ? { initial: (name) => table.stateOf(name), boundAnywhere, homeTouched: table.homeTouched, inherited: table.inherited, thread: heldThread(moves.functions), names: heldAt(table), ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}) } : startedAt(kind === "now" && readProgramPosition(projected[si].argv).program?.basename === "eval" ? evalStart(withCommandEnvironment(table, projected[si].argv)) : kind === "now" ? { ...laterStart, inherited: { ...laterStart.inherited, rebound: joinRebound(table.inherited.rebound, commandEnvironmentNames(projected[si].argv)) }, ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}), ...(exportedFunctions.size > 0 ? { thread: { physical: false, functions: exported, unread: exported, reached: workdir.reached }, names: inheritedExportedFunctions(exportedFunctions) } : {}) } : { ...laterStart, thread: heldThread(moves.functions, workdir.mayBePhysical || moves.physicalAt.some(Boolean)), names: names.heldAnywhere(), ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}) }, at);
93
+ const boundAt = (name, si) => {
94
+ const environment = commandEnvironmentNames(projected[si].argv);
95
+ return boundBefore(name, si) || bindsAt(si, name) || (environment !== "all" && environment.has(name));
96
+ };
97
+ const laterStart = { initial: (name) => declared(name, boundAnywhere(name)), enclosingBinds: boundAnywhere, homeTouched: boundAnywhere("HOME"), inherited: names.inheritedAt() };
98
+ const childStart = (table, si, env = commandEnvironmentNames(projected[si].argv), held = withCommandEnvironment(table, projected[si].argv)) => { const sets = (name) => env !== "all" && env.has(name), bound = (name) => boundAnywhere(name) || sets(name); return { ...laterStart, initial: (name) => (sets(name) ? held.stateOf(name) : declared(name, boundAnywhere(name))), enclosingBinds: bound, homeTouched: bound("HOME") }; };
99
+ const nestedTextStart = (table, si, kind, at, exported = exportedNames) => kind === "substitution" ? { initial: (name) => table.stateOf(name), enclosingBinds: (name) => boundAt(name, si), homeTouched: table.homeTouched, inherited: table.inherited, thread: heldThread(moves.functions), names: heldAt(table), ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}) } : startedAt(kind === "now" && readProgramPosition(projected[si].argv).program?.basename === "eval" ? evalStart(withCommandEnvironment(table, projected[si].argv), si) : kind === "now" ? { ...childStart(table, si), inherited: { ...laterStart.inherited, rebound: joinRebound(table.inherited.rebound, commandEnvironmentNames(projected[si].argv)) }, ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}), ...(exportedFunctions.size > 0 ? { thread: { physical: false, functions: exported, unread: exported, reached: workdir.reached }, names: inheritedExportedFunctions(exportedFunctions) } : {}) } : { ...laterStart, thread: heldThread(moves.functions, workdir.mayBePhysical || moves.physicalAt.some(Boolean)), names: names.heldAnywhere(), ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}) }, at);
95
100
  const nestedPlanner = (table, si) => (text, kind, at) => planShellReads(text, decl, depth + 1, nestedTextStart(table, si, kind, at));
96
101
  const empty = lexed.segments.map((segment, si) => segmentIsEmpty(segment, projected[si]));
97
102
  const facts = projected.map(() => undefined);
@@ -114,17 +119,17 @@ function planText(command, decl, depth, start, from) {
114
119
  workdir.reach(start.thread.reached);
115
120
  const workdirContext = {
116
121
  ...(decl.homeDir !== undefined ? { homeDir: decl.homeDir } : {}),
117
- textBinds: boundAnywhere,
118
- evalEnd: (text, from, table) => {
122
+ textBinds: boundAt,
123
+ evalEnd: (text, from, table, si) => {
119
124
  if (moves.bodyMoves && textCalls(text, moves.functions))
120
125
  return { end: "unmodelled", physical: false, reached: new Set() };
121
126
  if (!textMayMove(text, moves.functions) && !textSetsPhysical(text))
122
127
  return { end: from, physical: false, reached: new Set() };
123
- const ran = planText(text, decl, depth + 1, evalStart(table), from);
128
+ const ran = planText(text, decl, depth + 1, evalStart(table, si), from);
124
129
  return { end: ran.end, physical: ran.physical, reached: ran.reached, ...(ran.unsettled === true ? { unsettled: true } : {}) };
125
130
  },
126
131
  };
127
- const evalStart = (table) => ({ initial: (name) => table.stateOf(name), boundAnywhere, homeTouched: table.homeTouched || table.commandSets.has("HOME"), inherited: { ...table.inherited, rebound: joinRebound(table.inherited.rebound, table.commandSets) }, thread: heldThread(moves.unread), names: heldAt(table, names.functionBound()), ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}) });
132
+ const evalStart = (table, si) => ({ initial: (name) => table.stateOf(name), enclosingBinds: (name) => boundAt(name, si), homeTouched: table.homeTouched || table.commandSets.has("HOME"), inherited: { ...table.inherited, rebound: joinRebound(table.inherited.rebound, table.commandSets) }, thread: heldThread(moves.unread), names: heldAt(table, names.functionBound()), ...(exportedFunctions.size > 0 ? { exportedFunctions } : {}) });
128
133
  const heldThread = (unread, physical = workdir.mayBePhysical) => ({ physical, functions: moves.functions, unread, reached: workdir.reached });
129
134
  let andRunStart = 0;
130
135
  let crossedAllAnd = true;
@@ -279,7 +284,7 @@ function planText(command, decl, depth, start, from) {
279
284
  const key = JSON.stringify([j, t.text, t.in, s.at.map(keyOf)]);
280
285
  let ran = handedCallers.get(key);
281
286
  if (ran === undefined) {
282
- const start = t.in === "shell" ? evalStart(withCommandEnvironment(table, projected[j].argv)) : nestedTextStart(table, j, t.in === "child" ? "now" : "substitution", undefined, t.functions);
287
+ const start = t.in === "shell" ? evalStart(withCommandEnvironment(table, projected[j].argv), j) : nestedTextStart(table, j, t.in === "child" ? "now" : "substitution", undefined, t.functions);
283
288
  ran = planText(t.text, decl, depth + 1, start, s.at).callers ?? s;
284
289
  handedCallers.set(key, ran);
285
290
  }
@@ -341,7 +346,7 @@ function planText(command, decl, depth, start, from) {
341
346
  shape.backgrounded = lexed.segments.some((s) => s.connector === "&") || settled.some((f) => (f.readings ?? [f]).some((g) => g.backgrounds === true));
342
347
  shape.strayRedirection = projected.some((p) => p.argv.length === 0 && p.redirects.length > 0);
343
348
  const placedRead = (c, at, atFloor, gitVariables) => {
344
- const relative = relativeSpelling(c.spelled);
349
+ const relative = relativeSpelling(c.spelled) || (c.provenance !== "object_path" && ownProcessSpelling(c.spelled)?.startsWith(".") === true);
345
350
  if (c.provenance === "object_path" && relative) {
346
351
  const { repository, ...read } = c;
347
352
  return { ...read, ...objectPathPlacement(c.spelled, repository, at, atFloor, decl.homeDir, gitVariables) };
@@ -399,8 +404,8 @@ function planText(command, decl, depth, start, from) {
399
404
  });
400
405
  }
401
406
  }
402
- const reached = workdir.lost ? new Set([...workdir.reached, ...(workdir.floorBases ?? [])]) : workdir.reached;
403
- return { plan: { segments, shape, ...(unreadable !== undefined ? { unreadable } : {}) }, end: workdir.end(), physical: workdir.mayBePhysical, reached, ...(workdir.unsettled ? { unsettled: true } : {}), callers: callersOut };
407
+ const reached = workdir.lost ? new Set([...workdir.reached, ...workdir.carriedFloor]) : workdir.reached;
408
+ return { plan: { segments, shape, ...(unreadable !== undefined ? { unreadable } : {}), ...(unreadTail !== undefined ? { unreadTail } : {}) }, end: unreadTail !== undefined ? "unmodelled" : workdir.end(), physical: workdir.mayBePhysical, reached, ...(workdir.unsettled ? { unsettled: true } : {}), callers: callersOut };
404
409
  }
405
410
  function loopShapeOf(p) {
406
411
  if (p.argv[0] === undefined)
@@ -462,7 +467,7 @@ function readingFacts(segment, p, decl, reading, nestedPlan, fed, inheritedFns =
462
467
  const f = (c.expands === "unresolvable" || c.spelled.startsWith("./~")) && decl.homeDir !== undefined ? spelledWithHome(c.spelled, c.raw, decl.homeDir) : undefined;
463
468
  return f === undefined ? c : { ...c, floorSpelled: f };
464
469
  };
465
- const unsettle = (c) => floor((unresolvedRaw.has(c.raw) || (homeWithheld && c.spelled.startsWith("~"))) && c.expands !== "unresolvable" ? { ...c, expands: "unresolvable" } : c);
470
+ const unsettle = (c) => floor((unresolvedRaw.has(c.raw) || (homeWithheld && /^~(?:\/|$)/.test(c.spelled))) && c.expands !== "unresolvable" ? { ...c, expands: "unresolvable" } : c);
466
471
  const each = (c) => {
467
472
  const { floors, ...one } = c;
468
473
  const shadows = (floors ?? []).map((v) => ({ spelled: v.spelled, ...(v.pattern !== undefined ? { pattern: v.pattern } : {}), raw: one.raw, provenance: one.provenance, expands: v.piece === true ? "unresolvable" : v.glob === true ? "glob" : false, denyOnly: true }));
@@ -514,6 +519,15 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
514
519
  expandedText(expansionsInHeredocBody(t.body), "a here-document body carries a substitution this lexer cannot delimit");
515
520
  for (const e of expansionsOf(segment))
516
521
  parameter(e);
522
+ for (const t of segment.tokens) {
523
+ const words = t.kind === "word" ? assignedWords(t) : t.kind === "redirect" && t.target !== undefined ? [t.target] : [];
524
+ for (const q of words.flatMap((w) => w.pieces)) {
525
+ for (const e of q.expansion !== undefined ? enclosedToo(q.expansion) : [])
526
+ if (e.kind === "parameter" && e.body !== undefined)
527
+ for (const line of parameterOperandLines(e.body, q.quotedBy !== undefined))
528
+ substitute(line, false);
529
+ }
530
+ }
517
531
  const shellSide = new Set(nested);
518
532
  if (isArithmeticCommand(segment))
519
533
  ctx.reentered.push(...arithmeticSubstitutions(p.argv.map((w) => w.folded).join(" "), table));
@@ -1,4 +1,4 @@
1
- import { ANSI_C_ESCAPES, argvOf, lexShell, literalTextOf } from "../../shell/lex.js";
1
+ import { ANSI_C_ESCAPES, argvOf, lexShell, literalTextOf, segmentsAroundStop } from "../../shell/lex.js";
2
2
  import { readProgramPosition } from "./bash-program-position.js";
3
3
  const SOURCE_WORDS = new Set([".", "source"]);
4
4
  const SPLICE_DEPTH_MAX = 4;
@@ -106,12 +106,19 @@ export function inlineSourcedLiterals(lexed) {
106
106
  const out = [];
107
107
  for (let si = 0; si < segments.length; si++) {
108
108
  const segment = segments[si];
109
+ if (segment.stopHead === true) {
110
+ out.push(segment);
111
+ continue;
112
+ }
109
113
  const file = sourcedFileOf(argvOf(segment));
110
114
  if (file === undefined || segment.connector === "|" || segment.sourced === true || segment.tokens.some((t) => t.kind !== "word")) {
111
115
  out.push(segment);
112
116
  continue;
113
117
  }
114
- const prev = out[out.length - 1];
118
+ let back = out.length - 1;
119
+ while (back >= 0 && out[back].stopHead === true)
120
+ back--;
121
+ const prev = out[back];
115
122
  const written = prev === undefined || prev.connector === "|" ? undefined : writtenLiteralOf(prev);
116
123
  const conditional = prev !== undefined && (prev.connector === "||" || segment.connector === "||" || (prev.connector === "&&" && segment.connector !== "&&"));
117
124
  const text = written !== undefined && !conditional && sameFileSpelling(written.file, file) ? written.text : undefined;
@@ -120,11 +127,12 @@ export function inlineSourcedLiterals(lexed) {
120
127
  continue;
121
128
  }
122
129
  const inner = lexShell(text);
123
- if ("parseFailure" in inner || inner.segments.length === 0) {
130
+ const read = "parseFailure" in inner ? segmentsAroundStop(text, inner) : inner.segments;
131
+ if (read.length === 0) {
124
132
  out.push(segment);
125
133
  continue;
126
134
  }
127
- inner.segments.forEach((s, k) => out.push(k === 0 ? { ...s, connector: segment.connector, spliced: true } : { ...s, spliced: true }));
135
+ read.forEach((s, k) => out.push(k === 0 ? { ...s, connector: segment.connector, spliced: true } : { ...s, spliced: true }));
128
136
  out.push({ ...segment, connector: ";", spliced: true, sourced: true });
129
137
  spliced = true;
130
138
  }
@@ -15,10 +15,12 @@ import type { Read } from "./shell-read-word.js";
15
15
  /** Where a nested text starts its names: a substitution body inherits the table of the segment it sits in (a subshell
16
16
  * holds every variable of the shell that forks it); a text the shell runs later or elsewhere (a code body, `eval`'s
17
17
  * text, a child shell's `-c`) starts from the text's own start — every name unknown, `HOME` the declared home unless
18
- * the enclosing text binds it anywhere. `boundAnywhere` answers for the enclosing texts. */
18
+ * the enclosing text binds it where that reaches the nested text. `enclosingBinds` answers for the enclosing texts: a
19
+ * binding that may run before the segment handing the text on, or by that segment, for a text run there now; any
20
+ * binding, for a text run later. */
19
21
  export interface PlanStart {
20
22
  readonly initial: NameReader;
21
- readonly boundAnywhere: (name: string) => boolean;
23
+ readonly enclosingBinds: (name: string) => boolean;
22
24
  /** `HOME` may already hold something other than the declared home where the nested text starts. */
23
25
  readonly homeTouched: boolean;
24
26
  /** The attributes, name references and deny floors in force where the nested text starts. */
@@ -2,7 +2,7 @@ import { literalTildeSpelling } from "../../shell/lex.js";
2
2
  import { joinedFloors } from "./shell-read-bindings.js";
3
3
  import { programBasename } from "./bash-program-position.js";
4
4
  import { launcherOptionPathRole, launcherOptionStep, programRow, readOptionRole } from "./program-read-model.js";
5
- import { chdirFrom } from "./shell-read-object-path.js";
5
+ import { chdirFrom, chdirMayLeadTo } from "./shell-read-object-path.js";
6
6
  import { anchorSpelling, pathFamilyOf } from "./safety.js";
7
7
  const NO_NAMES = new Set();
8
8
  export function heldAt(table, bound = NO_NAMES) {
@@ -112,12 +112,12 @@ export function launchedAt(launchedIn, bases, floor, homeDir) {
112
112
  else if (to !== "unmodelled") {
113
113
  const next = chdirFrom(to, dir, homeDir);
114
114
  if (next === undefined)
115
- to = "unmodelled";
115
+ [toFloor, to] = [[...new Set([...(toFloor ?? []), ...chdirMayLeadTo(to, dir, homeDir)])], "unmodelled"];
116
116
  else
117
117
  toFloor = to = next;
118
118
  }
119
119
  else if (toFloor !== undefined)
120
- toFloor = chdirFrom(toFloor, dir, homeDir) ?? toFloor;
120
+ toFloor = chdirFrom(toFloor, dir, homeDir) ?? [...new Set([...toFloor, ...chdirMayLeadTo(toFloor, dir, homeDir)])];
121
121
  }
122
122
  const words = [...new Set([...(here ?? []), ...(toFloor ?? [])])];
123
123
  return { to, ...(toFloor !== undefined && toFloor.length > 0 ? { floor: toFloor } : {}), ...(words.length > 0 ? { words } : {}), ...(unsettled ? { unsettled: true } : {}) };
@@ -44,14 +44,16 @@ export type BaseShift = {
44
44
  readonly kind: "eval";
45
45
  readonly text: string;
46
46
  };
47
- /** What the walk asks of the plan around it: the declared home (a `~` target), whether the text binds a name anywhere
48
- * (`OLDPWD` — then `cd -` reads the table's value; `PWD` — then a move's `OLDPWD` is not the base the candidate stood
49
- * in), and where a literal `eval` text started at candidates — a candidate, the floor of a walk that lost track, or a place
50
- * the walk does not know — ends ({@link WorkdirThread.end}), and where its walk went that its end does not say (`reached`). */
47
+ /** What the walk asks of the plan around it: the declared home (a `~` target), whether the text binds a name where it takes
48
+ * effect before the moving segment's move — before the segment, or by its own words, redirections and command environment
49
+ * (`OLDPWD` — then `cd -` reads the table's value; `PWD` — then a move's `OLDPWD` is not the base the candidate stood in; a
50
+ * binding that runs after the move does not reach it), and where a literal `eval`
51
+ * text at a segment, started at candidates — a candidate, the floor of a walk that lost track, or a place the walk does not
52
+ * know — ends ({@link WorkdirThread.end}), and where its walk went that its end does not say (`reached`). */
51
53
  export interface WorkdirContext {
52
54
  readonly homeDir?: string;
53
- readonly textBinds: (name: string) => boolean;
54
- readonly evalEnd: (text: string, from: readonly BaseCandidate[] | "unmodelled", table: CommandTable) => {
55
+ readonly textBinds: (name: string, si: number) => boolean;
56
+ readonly evalEnd: (text: string, from: readonly BaseCandidate[] | "unmodelled", table: CommandTable, si: number) => {
55
57
  readonly end: readonly BaseCandidate[] | "unmodelled";
56
58
  readonly physical: boolean;
57
59
  readonly reached: ReadonlySet<string>;
@@ -96,6 +98,12 @@ export declare class WorkdirThread {
96
98
  /** The deny floor of the words the walk could not place: a closed scope that lost track keeps its floor for its words. */
97
99
  get floorBases(): readonly string[] | undefined;
98
100
  private closedFloors;
101
+ /** The floor's places the walk carries ({@link floorBases} without {@link mayLead}): what it hands a walk that runs it. */
102
+ get carriedFloor(): readonly string[];
103
+ /** Where a word MAY stand that only a device spelling's drive stand-in says, or a move from one ({@link floorOf}): judged beside
104
+ * the floor, never a place the walk carries — not counted toward {@link BASE_CANDIDATE_MAX}, never where an `eval` text or a
105
+ * closed scope is walked from, never handed to a fork's floor. */
106
+ private mayLead;
99
107
  /** The candidates a reader whose `&&` run starts at `andRunStart` may stand in. */
100
108
  reachable(andRunStart: number): readonly BaseCandidate[];
101
109
  /** Where the text ends: every candidate, or `unmodelled`. */
@@ -10,7 +10,7 @@ import { isAbsoluteForFamily } from "./safety.js";
10
10
  import { walkFromStart } from "./shell-read-start.js";
11
11
  const TEXT_RUNNING_PROGRAMS = new Set(["eval", "source", "."]);
12
12
  const BASE_CANDIDATE_MAX = 256;
13
- const tableSays = (name, at, ctx) => ctx.textBinds(name) || at.table.commandSets.has(name);
13
+ const tableSays = (name, si, at, ctx) => ctx.textBinds(name, si) || at.table.commandSets.has(name);
14
14
  export class WorkdirThread {
15
15
  candidates;
16
16
  lostAt = false;
@@ -32,9 +32,13 @@ export class WorkdirThread {
32
32
  }
33
33
  unsettledAt = false;
34
34
  get floorBases() {
35
- return this.closedFloors.length === 0 ? this.floors : [...new Set([...(this.floors ?? []), ...this.closedFloors])];
35
+ return this.closedFloors.length === 0 && this.mayLead.length === 0 ? this.floors : [...new Set([...(this.floors ?? []), ...this.closedFloors, ...this.mayLead])];
36
36
  }
37
37
  closedFloors = [];
38
+ get carriedFloor() {
39
+ return [...new Set([...(this.floors ?? []), ...this.closedFloors])];
40
+ }
41
+ mayLead = [];
38
42
  reachable(andRunStart) {
39
43
  return this.candidates.filter((c) => c.skippedCd < andRunStart);
40
44
  }
@@ -87,9 +91,10 @@ export class WorkdirThread {
87
91
  const w = new WorkdirThread(at === "lost" ? "unmodelled" : at, this.physical);
88
92
  if (at === "lost") {
89
93
  w.candidates = this.candidates;
90
- const floors = [...new Set([...(this.floorBases ?? []), ...floor])];
94
+ const floors = [...new Set([...this.carriedFloor, ...floor])];
91
95
  if (floors.length > 0)
92
96
  w.floors = floors;
97
+ w.mayLead = this.mayLead;
93
98
  }
94
99
  w.scopeReached = this.scopeReached;
95
100
  w.unsettledAt = this.unsettledAt;
@@ -115,9 +120,14 @@ export class WorkdirThread {
115
120
  if (named.length > BASE_CANDIDATE_MAX)
116
121
  this.unsettledAt = true;
117
122
  const from = floors.length === 0 ? [] : named.length > BASE_CANDIDATE_MAX ? [...new Set(before)] : named;
118
- const ran = at.shift.kind === "eval" ? ctx.evalEnd(at.shift.text, from.length === 0 ? "unmodelled" : from.map((base) => ({ base, skippedCd: -1 })), at.table) : undefined;
123
+ const ran = at.shift.kind === "eval" ? ctx.evalEnd(at.shift.text, from.length === 0 ? "unmodelled" : from.map((base) => ({ base, skippedCd: -1 })), at.table, si) : undefined;
124
+ const led = [];
119
125
  if (from.length > 0)
120
- this.floors = [...new Set([...floors, ...(ran === undefined ? floorOf(at.shift, from, ctx) : [...ran.reached, ...(ran.end === "unmodelled" ? [] : ran.end.map((c) => c.base))])])];
126
+ this.floors = [...new Set([...floors, ...(ran === undefined ? floorOf(at.shift, from, ctx, led) : [...ran.reached, ...(ran.end === "unmodelled" ? [] : ran.end.map((c) => c.base))])])];
127
+ if (ran === undefined && this.mayLead.length > 0 && this.mayLead.length <= BASE_CANDIDATE_MAX)
128
+ led.push(...floorOf(at.shift, this.mayLead, ctx, led));
129
+ if (led.length > 0)
130
+ this.mayLead = [...new Set([...this.mayLead, ...led])];
121
131
  if (movesToUnsettled(at.shift) || ran?.unsettled === true)
122
132
  this.unsettledAt = true;
123
133
  return;
@@ -134,11 +144,14 @@ export class WorkdirThread {
134
144
  const branched = [];
135
145
  for (const c of this.candidates) {
136
146
  if (c.skippedCd < at.andRunStart) {
137
- const moved = this.movedFrom(c, at, ctx);
147
+ const moved = this.movedFrom(c, si, at, ctx);
138
148
  if (moved === "lost") {
139
149
  if (movesToUnsettled(s))
140
150
  this.unsettledAt = true;
141
- return this.lose(si, reachable, floorOf(s, reachable.map((r) => r.base), ctx));
151
+ const led = [];
152
+ const targets = floorOf(s, reachable.map((r) => r.base), ctx, led);
153
+ this.mayLead = [...new Set([...this.mayLead, ...led])];
154
+ return this.lose(si, reachable, targets);
142
155
  }
143
156
  for (const m of moved)
144
157
  branched.push({ ...m, skippedCd: c.skippedCd });
@@ -158,10 +171,10 @@ export class WorkdirThread {
158
171
  else
159
172
  this.candidates = next;
160
173
  }
161
- movedFrom(c, at, ctx) {
174
+ movedFrom(c, si, at, ctx) {
162
175
  const s = at.shift;
163
176
  if (s.kind === "eval") {
164
- const ran = ctx.evalEnd(s.text, [c], at.table);
177
+ const ran = ctx.evalEnd(s.text, [c], at.table, si);
165
178
  if (ran.physical)
166
179
  this.physical = true;
167
180
  if (ran.unsettled === true)
@@ -169,7 +182,7 @@ export class WorkdirThread {
169
182
  this.reach(ran.reached);
170
183
  return ran.end === "unmodelled" ? "lost" : ran.end.map((e) => (this.physical ? withoutPwd(e) : e));
171
184
  }
172
- const old = tableSays("PWD", at, ctx) ? {} : c.pwd !== undefined ? { old: c.pwd } : {};
185
+ const old = tableSays("PWD", si, at, ctx) ? {} : c.pwd !== undefined ? { old: c.pwd } : {};
173
186
  const land = (base, physical, stack) => ({ base, skippedCd: c.skippedCd, ...(physical || this.physical || !this.readable ? {} : { pwd: base }), ...old, ...(stack !== undefined ? { dirStack: stack } : {}) });
174
187
  if (s.kind === "swap" || s.kind === "pop") {
175
188
  const top = c.dirStack?.[0];
@@ -180,7 +193,7 @@ export class WorkdirThread {
180
193
  if (s.kind !== "cd")
181
194
  return "lost";
182
195
  const stack = s.push === true ? (c.dirStack === undefined ? undefined : [c.base, ...c.dirStack]) : c.dirStack;
183
- const targets = targetsOf(s.target, c, at, ctx);
196
+ const targets = targetsOf(s.target, c, si, at, ctx);
184
197
  if (targets === "lost")
185
198
  return "lost";
186
199
  const out = [];
@@ -196,7 +209,7 @@ export class WorkdirThread {
196
209
  }
197
210
  }
198
211
  const withoutPwd = ({ pwd: _, ...c }) => c;
199
- function floorOf(s, from, ctx) {
212
+ function floorOf(s, from, ctx, mayLead) {
200
213
  if (s.kind !== "cd")
201
214
  return [];
202
215
  if (s.target === "home")
@@ -204,16 +217,19 @@ function floorOf(s, from, ctx) {
204
217
  if (typeof s.target === "string")
205
218
  return [];
206
219
  const target = s.target;
207
- 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]; }) : [])];
220
+ return [...(target.floorSpelled !== undefined ? [target.floorSpelled] : []), ...(target.expands === false ? from.flatMap((base) => { const at = resolveOperandSpellings(base, target.spelled, ctx.homeDir); if (at?.standIn === true) {
221
+ mayLead.push(at.spelled ?? at.folded);
222
+ return [];
223
+ } return at === undefined ? [] : [at.spelled ?? at.folded]; }) : [])];
208
224
  }
209
225
  function movesToUnsettled(s) {
210
226
  return s.kind === "cd" && typeof s.target !== "string" && s.target.expands !== false;
211
227
  }
212
- function targetsOf(target, c, at, ctx) {
228
+ function targetsOf(target, c, si, at, ctx) {
213
229
  if (target === "home")
214
230
  return settledValues(at.table.stateOf("HOME"));
215
231
  if (target === "previous")
216
- return tableSays("OLDPWD", at, ctx) ? settledValues(at.table.stateOf("OLDPWD")) : c.old === undefined ? "lost" : [c.old];
232
+ return tableSays("OLDPWD", si, at, ctx) ? settledValues(at.table.stateOf("OLDPWD")) : c.old === undefined ? "lost" : [c.old];
217
233
  if (target.expands !== false)
218
234
  return "lost";
219
235
  const dir = target.spelled;
@@ -393,14 +409,16 @@ export function textMovesOf(defined, segments, argvs, inFunctionBody, inherited,
393
409
  const unread = new Set([...evalDefinedFunctions(argvs), ...(inherited?.unread ?? [])]);
394
410
  const functions = new Set([...defined, ...unread, ...(inherited?.functions ?? [])]);
395
411
  const programs = argvs.map(programOf);
396
- const exportedAt = (si) => new Set([...exportedInherited, ...argvs.slice(0, si).flatMap(exportedFunctionNames)].filter((n) => functions.has(n)));
412
+ const exportedSoFar = new Set(exportedInherited);
413
+ const exportedAt = argvs.map((argv) => { const at = new Set([...exportedSoFar].filter((n) => functions.has(n))); for (const name of exportedFunctionNames(argv))
414
+ exportedSoFar.add(name); return at; });
397
415
  const mayMove = argvs.map((argv) => segmentMayMove(argv, functions));
398
416
  const bodyMoves = mayMove.some((m, si) => m && inFunctionBody(si));
399
417
  const bodiesAt = programs.map((p) => (p === undefined ? [] : codeBodies(p.name, p.args)));
400
418
  const mayCallAt = argvs.map((argv) => functionCallOf(argv, functions) !== undefined);
401
419
  const callAt = (si, table) => functionCallOf(argvs[si], functions, (name) => table.functionState(name));
402
420
  const callsUnread = (si, table) => functionCallOf(argvs[si], unread, (name) => table.functionState(name)) !== undefined;
403
- const bodyRunsAt = argvs.map((argv, si) => segmentRunsBody(segments[si], argv, functions, exportedAt(si), fedAt?.(si) ?? []));
421
+ const bodyRunsAt = argvs.map((argv, si) => segmentRunsBody(segments[si], argv, functions, exportedAt[si], fedAt?.(si) ?? []));
404
422
  return {
405
423
  functions, unread, mayMove, mayCallAt, runsBodyAt: bodyRunsAt.map(runsAny), bodyRunsAt, bodiesAt, bodyMoves, callAt, callsUnread,
406
424
  physicalAt: programs.map(setsPhysical),
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * design/105 — Scheduler 工具壳(CronCreate / CronDelete / CronList + ScheduleWakeup)。模型可调,把未来意图交给注入的
3
- * daemon backend(`env` 实现 {@link SchedulerCapability})。**core 薄壳**:工具只做 ① cron expr 白名单校验
3
+ * daemon backend(`env` 实现 {@link SchedulerCapability})。**core 薄壳**:工具只做 ① cron expr 收单判定(引擎唯一的匹配器 `nextCronFireTime`,到点算下一次的也是它)
4
4
  * ② 组装 `intent`(模型面) + `SchedulerContext`(Runner-held,闭包捕获 principal/scope/sessionId) ③ 调
5
5
  * `env.schedule/cancel/list`。持久化/触发/起新 task 全在 daemon。
6
6
  * design/136 §2.2(BREAKING 去超集批):`Sleep` 工具已撤除(CC 无此工具;等待抽象=Monitor/后台通知,定时再醒
@@ -39,6 +39,8 @@ export interface SchedulerToolContext {
39
39
  isolationScope?: string;
40
40
  sessionId?: string;
41
41
  taskConfig?: unknown;
42
+ /** The user's zone as the engine judged it ({@link SchedulerContext.timeZone}); rides every context handed to the backend. */
43
+ timeZone?: string;
42
44
  /** `ctx.requestStopAfterTurn`(干净结束本 run 的 runner 原语出口)。design/136 §2.2:Sleep 撤除后本槽位
43
45
  * 保留(human-suspend saga 等共用同一 runner 原语;prepare-task 仍注入)——当前 scheduler 三件不消费。 */
44
46
  requestStopAfterTurn?: () => void;
@@ -79,25 +81,13 @@ export declare function listScheduled(env: ExecutionEnv, lanes: SchedulerLanes):
79
81
  * environment with no scheduler seam. A lane without a key is refused (`config.invalid_argument`) before the backend is asked.
80
82
  */
81
83
  export declare function cancelScheduled(env: ExecutionEnv, lanes: SchedulerLanes, id: ScheduledTaskId): Promise<Result<void, SchedulerError>>;
82
- /**
83
- * cron 深校验(CC CronCreateTool.validateInput parity):arity(RB-438 D4)+ 数值域(如 `61 * * * *` 分钟越域)
84
- * + 永不触发(如 `31 2 30 2 *` 二月 30 日)。返回给模型自纠的错误句;合法返回 null。
85
- *
86
- * RB-438 D4 — **只收 5 字段**。带秒的 6 段此前收单成功并回执「Scheduled.」,而兑现腿(常驻 daemon)按标准
87
- * 5 字段解析:6 段记录算不出 next-run,首次 tick 即被当作坏记录丢弃 ⇒ 任务永不触发,且没有任何回执说过它
88
- * 没排上。收单 arity 必须等于开火 arity,差额只能用响亮拒绝补,不能用静默丢弃补。seam 上没有「秒粒度」
89
- * 能力位可判({@link SchedulerCapability} 只有 supported / 上下限 / 两个 session 位),故取保守形:一律拒。
90
- * 将来若真出现支持秒的 backend,加一个 additive 能力位在此开口(缺省仍拒),不要悄悄放行。
91
- *
92
- * 永不触发判定:标准 cron OR 语义(CC utils/cron.ts:150-158)—— dom 与 dow **都**受限时任一匹配即触发,而任何受限
93
- * dow 每周都出现 → 必触发。所以唯一永不触发形态 = dom 受限 + dow 通配 + dom 值全部超出所有排程月份的天数上限。
94
- */
95
- export declare function cronScheduleError(expr: string): string | null;
84
+ /** CronCreate's intake judge, asked now: {@link cronIntakeRefusal}, the matcher the firing side computes with. Absent a judged
85
+ * zone UTC stands in — whether an expression ever fires does not depend on the zone, and the instant is not used. */
86
+ export declare function cronScheduleError(expr: string, timeZone?: string): string | null;
96
87
  /**
97
88
  * cron → 人话(CC utils/cron.ts cronToHuman:218-308 类比,收窄到常见形态):"star/N * * * *"→"every N minutes"、
98
89
  * "M star/N * * *"→"every N hours"、`M H * * *`→"daily at H:MM"、`M H * * D`→"weekly on <day> at H:MM"、
99
- * `M H * * 1-5`→"weekdays at H:MM";其余原样返回(调用方以 `human !== expr` 判断是否可译)。
100
- * 收 backend 的 `cron <expr>` 显示串(见 {@link cronExprFromSummary});6 段带秒不译(D4 已在收单面拒收)。
90
+ * `M H * * 1-5`→"weekdays at H:MM";其余原样返回(调用方以 `human !== expr` 判断是否可译);收 backend 的 `cron <expr>` 显示串(见 {@link cronExprFromSummary})。
101
91
  */
102
92
  export declare function cronToHuman(expr: string): string;
103
93
  /**