@sema-agent/core 7.66.1 → 7.67.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 (904) hide show
  1. package/CHANGELOG.md +3518 -0
  2. package/LICENSE +2 -1
  3. package/dist/agents/agent-definition.js +2 -1
  4. package/dist/agents/agent-transcript-tool.d.ts +1 -1
  5. package/dist/agents/agent-transcript-tool.js +4 -3
  6. package/dist/agents/builtin-agents.d.ts +10 -7
  7. package/dist/agents/builtin-agents.js +1 -0
  8. package/dist/agents/cascade.d.ts +24 -11
  9. package/dist/agents/cascade.js +21 -9
  10. package/dist/agents/child-failure.d.ts +30 -0
  11. package/dist/agents/child-failure.js +25 -1
  12. package/dist/agents/composition-placement.d.ts +6 -2
  13. package/dist/agents/composition-placement.js +7 -3
  14. package/dist/agents/cross-session-envelope.d.ts +10 -1
  15. package/dist/agents/cross-session-envelope.js +6 -2
  16. package/dist/agents/cross-session-judge.d.ts +7 -1
  17. package/dist/agents/cross-session-judge.js +1 -0
  18. package/dist/agents/cumulative-stats.d.ts +36 -2
  19. package/dist/agents/cumulative-stats.js +44 -9
  20. package/dist/agents/delegation-registry-seat.js +2 -3
  21. package/dist/agents/inherited-tool-pool.d.ts +9 -4
  22. package/dist/agents/inherited-tool-pool.js +7 -1
  23. package/dist/agents/leg-label.d.ts +28 -0
  24. package/dist/agents/leg-label.js +9 -0
  25. package/dist/agents/list-agents-tool.d.ts +1 -1
  26. package/dist/agents/list-agents-tool.js +4 -4
  27. package/dist/agents/org-delivery-gate.d.ts +129 -23
  28. package/dist/agents/org-delivery-gate.js +41 -20
  29. package/dist/agents/peer-held-queue.d.ts +15 -10
  30. package/dist/agents/peer-held-queue.js +47 -19
  31. package/dist/agents/peer-notice-route.js +2 -2
  32. package/dist/agents/peer-notices.d.ts +13 -2
  33. package/dist/agents/peer-notices.js +12 -2
  34. package/dist/agents/peer-session-drain.d.ts +65 -15
  35. package/dist/agents/peer-session-drain.js +198 -41
  36. package/dist/agents/read-inbox-tool.d.ts +3 -2
  37. package/dist/agents/read-inbox-tool.js +7 -5
  38. package/dist/agents/repair-loop.js +20 -16
  39. package/dist/agents/retain-ledger.d.ts +1 -1
  40. package/dist/agents/retain-ledger.js +2 -4
  41. package/dist/agents/root-session-lane.d.ts +27 -0
  42. package/dist/agents/root-session-lane.js +57 -0
  43. package/dist/agents/roster-store.js +1 -2
  44. package/dist/agents/send-message-tool.js +6 -4
  45. package/dist/agents/subagent.d.ts +20 -4
  46. package/dist/agents/subagent.js +218 -183
  47. package/dist/agents/tool-filter.d.ts +3 -10
  48. package/dist/agents/tool-filter.js +0 -13
  49. package/dist/agents/verifier-independence.d.ts +31 -0
  50. package/dist/agents/verifier-independence.js +23 -0
  51. package/dist/agents/verify.d.ts +23 -11
  52. package/dist/agents/verify.js +28 -12
  53. package/dist/agents/yield-adoption.d.ts +24 -0
  54. package/dist/agents/yield-adoption.js +84 -0
  55. package/dist/bench/metrics.d.ts +2 -2
  56. package/dist/brain/anthropic.d.ts +4 -2
  57. package/dist/brain/anthropic.js +49 -35
  58. package/dist/brain/brain-faces.d.ts +11 -0
  59. package/dist/brain/brain-faces.js +6 -0
  60. package/dist/brain/cache-retention.d.ts +2 -0
  61. package/dist/brain/cache-retention.js +9 -0
  62. package/dist/brain/circuit-breaker.js +51 -26
  63. package/dist/brain/errors.d.ts +15 -1
  64. package/dist/brain/errors.js +8 -0
  65. package/dist/brain/failover.d.ts +6 -0
  66. package/dist/brain/failover.js +52 -37
  67. package/dist/brain/media-degrade.d.ts +5 -0
  68. package/dist/brain/media-degrade.js +4 -0
  69. package/dist/brain/model-capability.d.ts +2 -1
  70. package/dist/brain/model-lane.d.ts +169 -0
  71. package/dist/brain/model-lane.js +505 -0
  72. package/dist/brain/open-responses.js +19 -22
  73. package/dist/brain/openai.js +23 -22
  74. package/dist/brain/provider-message.d.ts +9 -0
  75. package/dist/brain/provider-message.js +18 -0
  76. package/dist/brain/reasoning-request.d.ts +9 -7
  77. package/dist/brain/reasoning-request.js +9 -10
  78. package/dist/brain/reasoning.d.ts +47 -13
  79. package/dist/brain/reasoning.js +20 -10
  80. package/dist/brain/route-adjudicator.d.ts +8 -2
  81. package/dist/brain/route-adjudicator.js +35 -1
  82. package/dist/brain/route-conformance.js +17 -0
  83. package/dist/brain/routing.d.ts +2 -0
  84. package/dist/brain/routing.js +19 -8
  85. package/dist/brain/status-sink.d.ts +5 -4
  86. package/dist/brain/status-sink.js +2 -2
  87. package/dist/brain/stream-engine.js +8 -2
  88. package/dist/brain/stream-shared.d.ts +12 -0
  89. package/dist/brain/stream-shared.js +18 -0
  90. package/dist/brain/timeout.d.ts +28 -0
  91. package/dist/brain/timeout.js +13 -4
  92. package/dist/brain/tool-schema-projection.d.ts +2 -0
  93. package/dist/brain/tool-schema-projection.js +108 -0
  94. package/dist/brain/usage-reading.d.ts +49 -0
  95. package/dist/brain/usage-reading.js +44 -0
  96. package/dist/brain/usage-reasoning.d.ts +38 -0
  97. package/dist/brain/usage-reasoning.js +9 -0
  98. package/dist/config/catalog.d.ts +3 -0
  99. package/dist/config/catalog.js +18 -9
  100. package/dist/core/a2a.d.ts +22 -4
  101. package/dist/core/a2a.js +191 -50
  102. package/dist/core/agent-definition.d.ts +3 -1
  103. package/dist/core/agent-state.d.ts +29 -16
  104. package/dist/core/agent-state.js +36 -9
  105. package/dist/core/allow-entry.d.ts +12 -3
  106. package/dist/core/allow-entry.js +10 -3
  107. package/dist/core/approval-display.d.ts +18 -0
  108. package/dist/core/approval-display.js +26 -0
  109. package/dist/core/approval-object.js +2 -2
  110. package/dist/core/approval-route.d.ts +16 -0
  111. package/dist/core/approval-route.js +5 -0
  112. package/dist/core/approval-words.d.ts +43 -0
  113. package/dist/core/approval-words.js +37 -0
  114. package/dist/core/ask-origin.d.ts +37 -10
  115. package/dist/core/ask-origin.js +19 -7
  116. package/dist/core/ask-question.d.ts +36 -8
  117. package/dist/core/ask-question.js +24 -9
  118. package/dist/core/ask-unresolvable-notice.d.ts +3 -2
  119. package/dist/core/ask-unresolvable-notice.js +3 -2
  120. package/dist/core/attachment-source.d.ts +50 -0
  121. package/dist/core/attachment-source.js +46 -0
  122. package/dist/core/auto-compaction.d.ts +151 -40
  123. package/dist/core/auto-compaction.js +115 -50
  124. package/dist/core/auto-mode.d.ts +5 -0
  125. package/dist/core/auto-mode.js +11 -4
  126. package/dist/core/background-agent-store.d.ts +151 -23
  127. package/dist/core/background-agent-store.js +201 -61
  128. package/dist/core/background-shell.d.ts +4 -1
  129. package/dist/core/background-shell.js +1 -0
  130. package/dist/core/cache-break-detector.d.ts +49 -25
  131. package/dist/core/cache-break-detector.js +99 -44
  132. package/dist/core/caller-text.d.ts +28 -0
  133. package/dist/core/caller-text.js +12 -0
  134. package/dist/core/canonical-json.d.ts +5 -0
  135. package/dist/core/canonical-json.js +7 -0
  136. package/dist/core/checkpoint-features.d.ts +80 -9
  137. package/dist/core/checkpoint-features.js +1 -1
  138. package/dist/core/checkpoint-generation.d.ts +8 -1
  139. package/dist/core/checkpoint-generation.js +3 -0
  140. package/dist/core/checkpoint-queries.d.ts +47 -14
  141. package/dist/core/checkpoint-queries.js +63 -30
  142. package/dist/core/checkpoint-requirements.d.ts +36 -3
  143. package/dist/core/checkpoint-requirements.js +11 -1
  144. package/dist/core/checkpoint-row-verdict.d.ts +0 -2
  145. package/dist/core/checkpoint-row-verdict.js +5 -8
  146. package/dist/core/checkpoint-store.d.ts +166 -41
  147. package/dist/core/checkpoint-store.js +96 -15
  148. package/dist/core/child-clamp-seats.d.ts +10 -2
  149. package/dist/core/child-clamp-seats.js +2 -2
  150. package/dist/core/classifier-unavailable-arm.d.ts +11 -9
  151. package/dist/core/classifier-unavailable-arm.js +4 -2
  152. package/dist/core/command-sandbox-dispatch.d.ts +13 -0
  153. package/dist/core/command-sandbox-dispatch.js +8 -0
  154. package/dist/core/command-sandbox.d.ts +231 -0
  155. package/dist/core/command-sandbox.js +344 -0
  156. package/dist/core/completion-id.d.ts +21 -0
  157. package/dist/core/completion-id.js +14 -0
  158. package/dist/core/config-refusal-codes.d.ts +22 -0
  159. package/dist/core/config-refusal-codes.js +196 -0
  160. package/dist/core/context-edit.d.ts +26 -0
  161. package/dist/core/context-edit.js +4 -2
  162. package/dist/core/context-guard.d.ts +80 -7
  163. package/dist/core/context-guard.js +126 -25
  164. package/dist/core/context-settings.d.ts +32 -0
  165. package/dist/core/context-settings.js +41 -3
  166. package/dist/core/contract-faces.d.ts +22 -0
  167. package/dist/core/contract-faces.js +1 -0
  168. package/dist/core/credential-echo.d.ts +2 -2
  169. package/dist/core/credential-echo.js +2 -2
  170. package/dist/core/cross-boundary-taint.d.ts +10 -8
  171. package/dist/core/decision-receipt.d.ts +3 -2
  172. package/dist/core/decision-receipt.js +1 -1
  173. package/dist/core/definition-entry-grammar.d.ts +42 -0
  174. package/dist/core/definition-entry-grammar.js +15 -0
  175. package/dist/core/engine-attestation.d.ts +19 -4
  176. package/dist/core/engine-attestation.js +4 -0
  177. package/dist/core/engine-capabilities.d.ts +8 -1
  178. package/dist/core/engine-capabilities.js +1 -1
  179. package/dist/core/engine-contracts/open-face-contract.d.ts +39 -0
  180. package/dist/core/engine-contracts/open-face-contract.js +57 -0
  181. package/dist/core/engine-notice.d.ts +164 -33
  182. package/dist/core/exclusive-temp.d.ts +25 -0
  183. package/dist/core/exclusive-temp.js +19 -0
  184. package/dist/core/existing-target.d.ts +112 -0
  185. package/dist/core/existing-target.js +88 -0
  186. package/dist/core/file-history-store.d.ts +14 -6
  187. package/dist/core/gate-lanes.js +8 -3
  188. package/dist/core/gate-outcome.d.ts +2 -1
  189. package/dist/core/git-worktree-env.d.ts +92 -1
  190. package/dist/core/git-worktree-env.js +87 -6
  191. package/dist/core/governance-codes.d.ts +49 -8
  192. package/dist/core/governance-codes.js +59 -8
  193. package/dist/core/hands-band.d.ts +10 -6
  194. package/dist/core/hooks.d.ts +60 -6
  195. package/dist/core/hooks.js +10 -2
  196. package/dist/core/host-floor.d.ts +24 -8
  197. package/dist/core/host-floor.js +45 -16
  198. package/dist/core/human-input-projection.d.ts +7 -0
  199. package/dist/core/human-input-projection.js +11 -3
  200. package/dist/core/image-admission.d.ts +16 -4
  201. package/dist/core/image-admission.js +29 -17
  202. package/dist/core/input-author.d.ts +43 -1
  203. package/dist/core/input-author.js +19 -0
  204. package/dist/core/isolation-scope.d.ts +41 -0
  205. package/dist/core/isolation-scope.js +10 -0
  206. package/dist/core/json-schema-seats.d.ts +11 -0
  207. package/dist/core/json-schema-seats.js +5 -0
  208. package/dist/core/leg-identity.d.ts +53 -5
  209. package/dist/core/leg-identity.js +32 -1
  210. package/dist/core/locked-config.d.ts +33 -38
  211. package/dist/core/locked-config.js +21 -3
  212. package/dist/core/lsp.js +2 -1
  213. package/dist/core/mailbox-store.d.ts +111 -18
  214. package/dist/core/mailbox-store.js +101 -13
  215. package/dist/core/mcp-call-meta.js +1 -1
  216. package/dist/core/mcp-connection-pool.d.ts +8 -2
  217. package/dist/core/mcp-connection-pool.js +3 -1
  218. package/dist/core/mcp-failure.d.ts +6 -1
  219. package/dist/core/mcp-failure.js +10 -0
  220. package/dist/core/mcp-host-read.d.ts +293 -0
  221. package/dist/core/mcp-host-read.js +428 -0
  222. package/dist/core/mcp-server-link.d.ts +28 -6
  223. package/dist/core/mcp-server-link.js +35 -7
  224. package/dist/core/mcp-server-spec.d.ts +22 -29
  225. package/dist/core/mcp-server-spec.js +7 -14
  226. package/dist/core/mcp-server-unavailable-notice.d.ts +32 -0
  227. package/dist/core/mcp-server-unavailable-notice.js +15 -0
  228. package/dist/core/mcp-session-end.d.ts +5 -2
  229. package/dist/core/mcp-session-end.js +7 -2
  230. package/dist/core/mcp-tool-meta.d.ts +6 -0
  231. package/dist/core/mcp-tool-meta.js +1 -0
  232. package/dist/core/mcp.d.ts +54 -19
  233. package/dist/core/mcp.js +194 -241
  234. package/dist/core/memory-engine/committed-shadow-read.d.ts +16 -0
  235. package/dist/core/memory-engine/committed-shadow-read.js +21 -0
  236. package/dist/core/memory-engine/consolidation-driver.js +2 -1
  237. package/dist/core/memory-engine/consolidation.d.ts +3 -3
  238. package/dist/core/memory-engine/control-objects.d.ts +4 -3
  239. package/dist/core/memory-engine/control-objects.js +6 -4
  240. package/dist/core/memory-engine/delegation-settlement.d.ts +127 -25
  241. package/dist/core/memory-engine/delegation-settlement.js +145 -18
  242. package/dist/core/memory-engine/distiller.d.ts +2 -1
  243. package/dist/core/memory-engine/distiller.js +10 -5
  244. package/dist/core/memory-engine/dual-root.js +2 -2
  245. package/dist/core/memory-engine/engine.d.ts +127 -33
  246. package/dist/core/memory-engine/engine.js +774 -323
  247. package/dist/core/memory-engine/entry-scan.d.ts +3 -0
  248. package/dist/core/memory-engine/entry-scan.js +8 -0
  249. package/dist/core/memory-engine/export-bundle.d.ts +4 -0
  250. package/dist/core/memory-engine/export-bundle.js +2 -0
  251. package/dist/core/memory-engine/file-backend.d.ts +62 -17
  252. package/dist/core/memory-engine/file-backend.js +155 -99
  253. package/dist/core/memory-engine/index.d.ts +1 -1
  254. package/dist/core/memory-engine/index.js +1 -1
  255. package/dist/core/memory-engine/layer-observations.d.ts +7 -1
  256. package/dist/core/memory-engine/layer-observations.js +6 -0
  257. package/dist/core/memory-engine/layout.d.ts +88 -26
  258. package/dist/core/memory-engine/layout.js +105 -29
  259. package/dist/core/memory-engine/memory-deployment.js +4 -4
  260. package/dist/core/memory-engine/mount-failed-notice.d.ts +24 -0
  261. package/dist/core/memory-engine/mount-failed-notice.js +22 -0
  262. package/dist/core/memory-engine/origin-clearance.d.ts +15 -1
  263. package/dist/core/memory-engine/origin-clearance.js +30 -10
  264. package/dist/core/memory-engine/scan.js +1 -1
  265. package/dist/core/memory-engine/scope-contract.js +4 -3
  266. package/dist/core/memory-engine/session-write-home.js +13 -1
  267. package/dist/core/memory-engine/sync-client.d.ts +1 -1
  268. package/dist/core/memory-engine/sync-client.js +3 -1
  269. package/dist/core/memory-engine/tools.d.ts +5 -4
  270. package/dist/core/memory-engine/tools.js +1 -1
  271. package/dist/core/memory-engine/types.d.ts +18 -1
  272. package/dist/core/memory-engine/types.js +1 -0
  273. package/dist/core/memory.d.ts +1 -1
  274. package/dist/core/memory.js +2 -6
  275. package/dist/core/mode-policy.d.ts +8 -1
  276. package/dist/core/mode-policy.js +6 -2
  277. package/dist/core/model-fallbacks.d.ts +105 -0
  278. package/dist/core/model-fallbacks.js +79 -0
  279. package/dist/core/model-receipt.d.ts +15 -3
  280. package/dist/core/model-receipt.js +22 -1
  281. package/dist/core/model-seat.d.ts +1 -1
  282. package/dist/core/mods/classic-events.d.ts +5 -1
  283. package/dist/core/mods/dollar.d.ts +47 -2
  284. package/dist/core/mods/dollar.js +28 -5
  285. package/dist/core/mods/kernel/budget.d.ts +6 -0
  286. package/dist/core/mods/kernel/budget.js +6 -0
  287. package/dist/core/mods/kernel/dispatch.d.ts +23 -2
  288. package/dist/core/mods/kernel/dispatch.js +104 -15
  289. package/dist/core/mods/kernel/events.d.ts +18 -1
  290. package/dist/core/mods/kernel/events.js +7 -6
  291. package/dist/core/mods/kernel/index.d.ts +2 -2
  292. package/dist/core/mods/kernel/index.js +1 -1
  293. package/dist/core/mods/kernel/receive.d.ts +2 -1
  294. package/dist/core/mods/lifecycle-stations.d.ts +13 -4
  295. package/dist/core/mods/lifecycle-stations.js +8 -3
  296. package/dist/core/mods/message-display.d.ts +81 -0
  297. package/dist/core/mods/message-display.js +369 -0
  298. package/dist/core/mods/prompt-submit.d.ts +1 -1
  299. package/dist/core/mods/prompt-submit.js +5 -2
  300. package/dist/core/mods/session-append.d.ts +2 -2
  301. package/dist/core/mods/session-append.js +2 -1
  302. package/dist/core/mods/session-compact.js +2 -2
  303. package/dist/core/mods/stations.d.ts +48 -18
  304. package/dist/core/mods/stations.js +100 -19
  305. package/dist/core/mods/stop-answers.d.ts +23 -0
  306. package/dist/core/mods/stop-answers.js +20 -0
  307. package/dist/core/mounted-mcp.d.ts +48 -8
  308. package/dist/core/mounted-mcp.js +82 -16
  309. package/dist/core/namespaced-rule-name.js +2 -1
  310. package/dist/core/own-property-receipt.js +3 -5
  311. package/dist/core/parent-spec-seat.d.ts +20 -1
  312. package/dist/core/parent-spec-seat.js +13 -3
  313. package/dist/core/park-selfcheck.js +1 -0
  314. package/dist/core/path-identity.js +2 -1
  315. package/dist/core/peer-seat.d.ts +21 -7
  316. package/dist/core/peer-seat.js +25 -16
  317. package/dist/core/permission-rule-consent.js +15 -5
  318. package/dist/core/permission-rule-model.d.ts +4 -2
  319. package/dist/core/permission-rule-model.js +43 -23
  320. package/dist/core/permission-rule-store.d.ts +31 -16
  321. package/dist/core/permission-rule-store.js +27 -18
  322. package/dist/core/present-plan-tool.d.ts +6 -1
  323. package/dist/core/present-plan-tool.js +11 -3
  324. package/dist/core/pricing.d.ts +8 -6
  325. package/dist/core/pricing.js +1 -1
  326. package/dist/core/principal-name.d.ts +13 -0
  327. package/dist/core/principal-name.js +9 -2
  328. package/dist/core/process-identity.d.ts +140 -0
  329. package/dist/core/process-identity.js +215 -0
  330. package/dist/core/protocol-http-auth.d.ts +28 -6
  331. package/dist/core/protocol-http-auth.js +22 -5
  332. package/dist/core/protocol-naming.d.ts +7 -0
  333. package/dist/core/protocol-naming.js +12 -2
  334. package/dist/core/protocol-revocation.d.ts +72 -0
  335. package/dist/core/protocol-revocation.js +98 -0
  336. package/dist/core/protocol-table.d.ts +4 -4
  337. package/dist/core/protocol-table.js +3 -2
  338. package/dist/core/push-queue.d.ts +35 -2
  339. package/dist/core/push-queue.js +60 -4
  340. package/dist/core/read-only-shell.d.ts +19 -0
  341. package/dist/core/read-only-shell.js +38 -11
  342. package/dist/core/real-approval.d.ts +26 -0
  343. package/dist/core/real-approval.js +15 -0
  344. package/dist/core/redaction-marks.d.ts +6 -2
  345. package/dist/core/redaction-marks.js +3 -0
  346. package/dist/core/reminder-mint.d.ts +6 -0
  347. package/dist/core/reminder-mint.js +9 -8
  348. package/dist/core/remote-env.d.ts +31 -15
  349. package/dist/core/remote-env.js +29 -0
  350. package/dist/core/request-copy-projection.d.ts +51 -0
  351. package/dist/core/request-copy-projection.js +410 -0
  352. package/dist/core/resume-config-judge.d.ts +69 -0
  353. package/dist/core/resume-config-judge.js +78 -0
  354. package/dist/core/resume-startup-cause.d.ts +14 -4
  355. package/dist/core/resume-startup-cause.js +12 -2
  356. package/dist/core/retention-policy.js +2 -1
  357. package/dist/core/retention.d.ts +119 -24
  358. package/dist/core/retention.js +60 -16
  359. package/dist/core/retired-keys.d.ts +0 -10
  360. package/dist/core/retired-keys.js +2 -3
  361. package/dist/core/roles.d.ts +24 -25
  362. package/dist/core/roles.js +148 -21
  363. package/dist/core/row-shape.d.ts +149 -0
  364. package/dist/core/row-shape.js +184 -0
  365. package/dist/core/runner/advertised-writable-dirs.js +10 -9
  366. package/dist/core/runner/advisor-instructions.d.ts +11 -27
  367. package/dist/core/runner/advisor-instructions.js +18 -20
  368. package/dist/core/runner/advisor-tool.js +1 -0
  369. package/dist/core/runner/announce-once-ledger.js +4 -1
  370. package/dist/core/runner/approval-feedback.d.ts +17 -8
  371. package/dist/core/runner/approval-feedback.js +18 -13
  372. package/dist/core/runner/approver-defect-announcer.d.ts +17 -0
  373. package/dist/core/runner/approver-defect-announcer.js +22 -0
  374. package/dist/core/runner/assemble-result.d.ts +29 -14
  375. package/dist/core/runner/assemble-result.js +16 -25
  376. package/dist/core/runner/cache-hit-account.d.ts +77 -0
  377. package/dist/core/runner/cache-hit-account.js +46 -0
  378. package/dist/core/runner/call-hook-stations.d.ts +3 -2
  379. package/dist/core/runner/call-hook-stations.js +5 -4
  380. package/dist/core/runner/changed-files-scan.d.ts +43 -0
  381. package/dist/core/runner/changed-files-scan.js +34 -0
  382. package/dist/core/runner/checkpoint-scope.d.ts +33 -9
  383. package/dist/core/runner/checkpoint-scope.js +27 -1
  384. package/dist/core/runner/classifier-ladder.d.ts +2 -2
  385. package/dist/core/runner/classifier-ladder.js +18 -9
  386. package/dist/core/runner/clock-and-limits.d.ts +15 -4
  387. package/dist/core/runner/clock-and-limits.js +19 -1
  388. package/dist/core/runner/compact-session.js +84 -14
  389. package/dist/core/runner/compaction-call-options.d.ts +2 -29
  390. package/dist/core/runner/compaction-call-options.js +2 -9
  391. package/dist/core/runner/compaction-restate.d.ts +18 -2
  392. package/dist/core/runner/compaction-restate.js +36 -2
  393. package/dist/core/runner/construction-doors.js +8 -0
  394. package/dist/core/runner/context-room.d.ts +55 -0
  395. package/dist/core/runner/context-room.js +71 -0
  396. package/dist/core/runner/contracts.d.ts +313 -205
  397. package/dist/core/runner/conversation-segment.d.ts +49 -14
  398. package/dist/core/runner/conversation-segment.js +92 -19
  399. package/dist/core/runner/cross-boundary-lane.d.ts +4 -0
  400. package/dist/core/runner/cross-boundary-lane.js +9 -6
  401. package/dist/core/runner/decide-continuation.js +1 -1
  402. package/dist/core/runner/deferred-ask.d.ts +62 -0
  403. package/dist/core/runner/deferred-ask.js +44 -0
  404. package/dist/core/runner/delegation-owner.d.ts +19 -0
  405. package/dist/core/runner/delegation-owner.js +27 -1
  406. package/dist/core/runner/denial-limit-arms.d.ts +10 -6
  407. package/dist/core/runner/denial-limit-arms.js +13 -7
  408. package/dist/core/runner/env-capability-census.d.ts +1 -1
  409. package/dist/core/runner/file-history-request.js +2 -1
  410. package/dist/core/runner/file-history-restore.d.ts +16 -2
  411. package/dist/core/runner/file-history-restore.js +9 -1
  412. package/dist/core/runner/gate-exit.d.ts +18 -5
  413. package/dist/core/runner/gate-exit.js +26 -15
  414. package/dist/core/runner/git-status-frame.d.ts +26 -8
  415. package/dist/core/runner/git-status-frame.js +14 -9
  416. package/dist/core/runner/halt-attribution.d.ts +29 -12
  417. package/dist/core/runner/halt-attribution.js +38 -11
  418. package/dist/core/runner/image.js +3 -2
  419. package/dist/core/runner/initial-run-state.d.ts +1 -1
  420. package/dist/core/runner/initial-run-state.js +4 -4
  421. package/dist/core/runner/language-frame.d.ts +66 -0
  422. package/dist/core/runner/language-frame.js +76 -0
  423. package/dist/core/runner/leg-frame.d.ts +81 -0
  424. package/dist/core/runner/leg-frame.js +68 -0
  425. package/dist/core/runner/main-call-account.d.ts +34 -0
  426. package/dist/core/runner/main-call-account.js +50 -0
  427. package/dist/core/runner/mcp-redial.d.ts +9 -7
  428. package/dist/core/runner/mcp-redial.js +20 -21
  429. package/dist/core/runner/memory-consolidation-driver.d.ts +2 -0
  430. package/dist/core/runner/memory-consolidation-driver.js +5 -3
  431. package/dist/core/runner/messages-omitted-seat.d.ts +2 -0
  432. package/dist/core/runner/messages-omitted-seat.js +21 -0
  433. package/dist/core/runner/model-fallback-seat.d.ts +23 -0
  434. package/dist/core/runner/model-fallback-seat.js +64 -0
  435. package/dist/core/runner/model-lane-seat.d.ts +12 -0
  436. package/dist/core/runner/model-lane-seat.js +35 -0
  437. package/dist/core/runner/nested-memory-content.d.ts +33 -0
  438. package/dist/core/runner/nested-memory-content.js +171 -0
  439. package/dist/core/runner/nested-memory-lane.d.ts +181 -0
  440. package/dist/core/runner/nested-memory-lane.js +673 -0
  441. package/dist/core/runner/park-commit.d.ts +7 -0
  442. package/dist/core/runner/park-commit.js +3 -0
  443. package/dist/core/runner/prepare-advisor.d.ts +7 -9
  444. package/dist/core/runner/prepare-advisor.js +11 -5
  445. package/dist/core/runner/prepare-artifact.d.ts +1 -1
  446. package/dist/core/runner/prepare-artifact.js +8 -3
  447. package/dist/core/runner/prepare-ask-lane.d.ts +21 -3
  448. package/dist/core/runner/prepare-ask-lane.js +32 -28
  449. package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
  450. package/dist/core/runner/prepare-boundary-parks.js +21 -17
  451. package/dist/core/runner/prepare-caps-and-workflow.d.ts +10 -2
  452. package/dist/core/runner/prepare-caps-and-workflow.js +24 -18
  453. package/dist/core/runner/prepare-config-doors.d.ts +51 -5
  454. package/dist/core/runner/prepare-config-doors.js +73 -73
  455. package/dist/core/runner/prepare-context-lane.d.ts +68 -3
  456. package/dist/core/runner/prepare-context-lane.js +137 -27
  457. package/dist/core/runner/prepare-defer-classify.d.ts +0 -4
  458. package/dist/core/runner/prepare-defer-classify.js +9 -13
  459. package/dist/core/runner/prepare-delegation-surface.d.ts +8 -8
  460. package/dist/core/runner/prepare-delegation-surface.js +72 -64
  461. package/dist/core/runner/prepare-execution-env.js +1 -9
  462. package/dist/core/runner/prepare-file-history.d.ts +3 -2
  463. package/dist/core/runner/prepare-file-history.js +11 -4
  464. package/dist/core/runner/prepare-gate-stations.d.ts +21 -11
  465. package/dist/core/runner/prepare-gate-stations.js +13 -13
  466. package/dist/core/runner/prepare-hands-readface.d.ts +23 -6
  467. package/dist/core/runner/prepare-hands-readface.js +18 -12
  468. package/dist/core/runner/prepare-inherited-gate.d.ts +12 -5
  469. package/dist/core/runner/prepare-inherited-gate.js +14 -10
  470. package/dist/core/runner/prepare-lsp.js +2 -1
  471. package/dist/core/runner/prepare-memory-engine-session.js +30 -10
  472. package/dist/core/runner/prepare-memory.d.ts +4 -0
  473. package/dist/core/runner/prepare-memory.js +38 -16
  474. package/dist/core/runner/prepare-offload-wrappers.d.ts +3 -16
  475. package/dist/core/runner/prepare-offload-wrappers.js +6 -5
  476. package/dist/core/runner/prepare-park-ask.d.ts +11 -3
  477. package/dist/core/runner/prepare-park-ask.js +23 -19
  478. package/dist/core/runner/prepare-policy-chain.d.ts +17 -3
  479. package/dist/core/runner/prepare-policy-chain.js +144 -120
  480. package/dist/core/runner/prepare-project-context.d.ts +15 -53
  481. package/dist/core/runner/prepare-project-context.js +20 -83
  482. package/dist/core/runner/prepare-prompt-assembly.d.ts +7 -1
  483. package/dist/core/runner/prepare-prompt-assembly.js +9 -7
  484. package/dist/core/runner/prepare-prompt-inputs.d.ts +9 -3
  485. package/dist/core/runner/prepare-prompt-inputs.js +5 -3
  486. package/dist/core/runner/prepare-protocol-tools.d.ts +9 -4
  487. package/dist/core/runner/prepare-protocol-tools.js +46 -27
  488. package/dist/core/runner/prepare-question-face.d.ts +6 -5
  489. package/dist/core/runner/prepare-question-face.js +7 -6
  490. package/dist/core/runner/prepare-suspend-saga.d.ts +3 -0
  491. package/dist/core/runner/prepare-suspend-saga.js +1 -1
  492. package/dist/core/runner/prepare-task.d.ts +3 -3
  493. package/dist/core/runner/prepare-task.js +113 -61
  494. package/dist/core/runner/prepare-tool-disclosure-mount.js +6 -5
  495. package/dist/core/runner/prepare-turn-wiring.d.ts +33 -7
  496. package/dist/core/runner/prepare-turn-wiring.js +53 -17
  497. package/dist/core/runner/prepare-wiring-manifest.d.ts +42 -5
  498. package/dist/core/runner/prepare-wiring-manifest.js +81 -42
  499. package/dist/core/runner/prepare-workspace-restore.js +3 -2
  500. package/dist/core/runner/read-root-grant.js +2 -1
  501. package/dist/core/runner/reply-pricing.d.ts +31 -18
  502. package/dist/core/runner/reply-pricing.js +10 -15
  503. package/dist/core/runner/resume-admission.js +10 -15
  504. package/dist/core/runner/resume-apply.js +20 -9
  505. package/dist/core/runner/resume-checkpoint-screen.js +2 -4
  506. package/dist/core/runner/resume-internals-and-config.d.ts +12 -9
  507. package/dist/core/runner/resume-internals-and-config.js +37 -9
  508. package/dist/core/runner/resume-preflight.js +3 -3
  509. package/dist/core/runner/retired-runner-deps.js +3 -0
  510. package/dist/core/runner/rewind-files.js +6 -6
  511. package/dist/core/runner/run-attachment-seats.d.ts +1 -3
  512. package/dist/core/runner/run-attachment-seats.js +1 -6
  513. package/dist/core/runner/run-brain-sinks.d.ts +4 -7
  514. package/dist/core/runner/run-brain-sinks.js +7 -10
  515. package/dist/core/runner/run-clock-and-content.d.ts +8 -5
  516. package/dist/core/runner/run-clock-and-content.js +18 -3
  517. package/dist/core/runner/run-compaction-machinery.d.ts +8 -4
  518. package/dist/core/runner/run-compaction-machinery.js +4 -19
  519. package/dist/core/runner/run-git-lane.d.ts +8 -3
  520. package/dist/core/runner/run-git-lane.js +5 -3
  521. package/dist/core/runner/run-harness-handlers.d.ts +4 -1
  522. package/dist/core/runner/run-harness-handlers.js +70 -45
  523. package/dist/core/runner/run-identity-wiring.d.ts +6 -0
  524. package/dist/core/runner/run-identity-wiring.js +17 -8
  525. package/dist/core/runner/run-leg.d.ts +5 -2
  526. package/dist/core/runner/run-leg.js +156 -71
  527. package/dist/core/runner/run-notification-lane.d.ts +1 -1
  528. package/dist/core/runner/run-notification-lane.js +22 -10
  529. package/dist/core/runner/run-recovery-lanes.js +8 -6
  530. package/dist/core/runner/run-settle-and-teardown.d.ts +4 -0
  531. package/dist/core/runner/run-settle-and-teardown.js +77 -26
  532. package/dist/core/runner/run-stop-and-final-verify.js +46 -12
  533. package/dist/core/runner/run-telemetry-and-budget-seats.js +19 -28
  534. package/dist/core/runner/run-terminal-adoption.d.ts +2 -2
  535. package/dist/core/runner/run-terminal-adoption.js +14 -9
  536. package/dist/core/runner/run-tool-mount-facts.js +5 -9
  537. package/dist/core/runner/run-turn-boundary.d.ts +3 -2
  538. package/dist/core/runner/run-turn-boundary.js +112 -106
  539. package/dist/core/runner/runtask.d.ts +28 -8
  540. package/dist/core/runner/runtask.js +132 -41
  541. package/dist/core/runner/session-file-state-replay.d.ts +5 -3
  542. package/dist/core/runner/session-file-state-replay.js +10 -3
  543. package/dist/core/runner/session-rule-policy.d.ts +3 -3
  544. package/dist/core/runner/session-verb-doors.d.ts +18 -3
  545. package/dist/core/runner/session-verb-doors.js +38 -6
  546. package/dist/core/runner/shell-env-withheld.d.ts +8 -5
  547. package/dist/core/runner/shell-env-withheld.js +4 -4
  548. package/dist/core/runner/side-call-account.d.ts +12 -8
  549. package/dist/core/runner/side-call-account.js +24 -15
  550. package/dist/core/runner/stream-halt-verbs.js +1 -0
  551. package/dist/core/runner/stream-mode-verb.js +2 -1
  552. package/dist/core/runner/stream-settle-backstop.js +4 -1
  553. package/dist/core/runner/stream-steer-verb.js +35 -19
  554. package/dist/core/runner/sub-agent-deny-lists.d.ts +47 -11
  555. package/dist/core/runner/sub-agent-deny-lists.js +140 -39
  556. package/dist/core/runner/teardown-bounded.d.ts +6 -0
  557. package/dist/core/runner/teardown-bounded.js +12 -7
  558. package/dist/core/runner/terminal-account.d.ts +2 -0
  559. package/dist/core/runner/terminal-account.js +6 -1
  560. package/dist/core/runner/tool-disclosure.js +2 -1
  561. package/dist/core/runner/tool-end-body.js +3 -1
  562. package/dist/core/runner/tool-face-overlay.d.ts +1 -1
  563. package/dist/core/runner/tool-face-overlay.js +1 -1
  564. package/dist/core/runner/tool-occurrence.d.ts +34 -9
  565. package/dist/core/runner/tool-occurrence.js +32 -21
  566. package/dist/core/runner/tool-progress-lane.d.ts +20 -5
  567. package/dist/core/runner/tool-progress-lane.js +27 -5
  568. package/dist/core/runner/tool-result-media-seat.d.ts +15 -4
  569. package/dist/core/runner/tool-result-media-seat.js +17 -1
  570. package/dist/core/runner/tool-table-view.js +1 -1
  571. package/dist/core/runner/turn-attachments.d.ts +44 -71
  572. package/dist/core/runner/turn-attachments.js +52 -104
  573. package/dist/core/runner/usage-accounting.d.ts +3 -2
  574. package/dist/core/runner/usage-accounting.js +3 -2
  575. package/dist/core/runner/void-verifier-pause.js +1 -1
  576. package/dist/core/runner-deps.d.ts +42 -158
  577. package/dist/core/runtime-caps.d.ts +16 -4
  578. package/dist/core/secret-env.d.ts +20 -3
  579. package/dist/core/secret-env.js +46 -23
  580. package/dist/core/sensitive-path-policy.d.ts +8 -0
  581. package/dist/core/sensitive-path-policy.js +10 -2
  582. package/dist/core/session-checkout.d.ts +32 -27
  583. package/dist/core/session-checkout.js +109 -61
  584. package/dist/core/session-log-transfer.js +2 -1
  585. package/dist/core/session-policy-store.d.ts +24 -11
  586. package/dist/core/session-policy-store.js +11 -2
  587. package/dist/core/session-store.d.ts +16 -2
  588. package/dist/core/session-store.js +43 -17
  589. package/dist/core/session.d.ts +31 -3
  590. package/dist/core/session.js +33 -2
  591. package/dist/core/shell-run-candidates.d.ts +20 -8
  592. package/dist/core/shell-run-candidates.js +44 -21
  593. package/dist/core/side-query.d.ts +17 -5
  594. package/dist/core/side-query.js +17 -14
  595. package/dist/core/skill-grant.js +2 -3
  596. package/dist/core/skills-directory.js +3 -66
  597. package/dist/core/snapshot-frame-seat.d.ts +8 -0
  598. package/dist/core/snapshot-frame-seat.js +24 -0
  599. package/dist/core/steer-replay.d.ts +19 -3
  600. package/dist/core/steer-replay.js +8 -1
  601. package/dist/core/store-contracts/background-agent-store-contract.d.ts +17 -2
  602. package/dist/core/store-contracts/background-agent-store-contract.js +131 -2
  603. package/dist/core/store-contracts/checkpoint-store-contract.js +63 -1
  604. package/dist/core/store-contracts/mailbox-store-contract.d.ts +15 -2
  605. package/dist/core/store-contracts/mailbox-store-contract.js +213 -3
  606. package/dist/core/store-contracts/permission-rule-write-contract.js +24 -0
  607. package/dist/core/store-contracts/session-deletion-cascade-contract.d.ts +15 -0
  608. package/dist/core/store-contracts/session-deletion-cascade-contract.js +288 -0
  609. package/dist/core/store-contracts/session-policy-store-contract.js +57 -36
  610. package/dist/core/store-contracts/session-repo-contract.js +130 -5
  611. package/dist/core/store-contracts/session-store-contract.d.ts +1 -1
  612. package/dist/core/store-contracts/session-store-contract.js +17 -0
  613. package/dist/core/store-contracts/task-list-store-contract.d.ts +32 -0
  614. package/dist/core/store-contracts/task-list-store-contract.js +240 -0
  615. package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
  616. package/dist/core/store-contracts/tool-result-store-contract.js +41 -0
  617. package/dist/core/stub-env.d.ts +2 -2
  618. package/dist/core/stub-env.js +1 -0
  619. package/dist/core/synthetic-read-verdict.d.ts +38 -28
  620. package/dist/core/synthetic-read-verdict.js +19 -28
  621. package/dist/core/task-event.d.ts +171 -19
  622. package/dist/core/task-intake.d.ts +26 -0
  623. package/dist/core/task-intake.js +31 -0
  624. package/dist/core/task-limits.d.ts +8 -6
  625. package/dist/core/task-notification.d.ts +88 -8
  626. package/dist/core/task-notification.js +45 -5
  627. package/dist/core/task-registry-agent.d.ts +24 -7
  628. package/dist/core/task-registry-agent.js +51 -28
  629. package/dist/core/task-registry-monitor.js +16 -14
  630. package/dist/core/task-registry-shared.d.ts +177 -35
  631. package/dist/core/task-registry-shared.js +44 -17
  632. package/dist/core/task-registry-workflow.js +8 -5
  633. package/dist/core/task-registry-yield.d.ts +32 -0
  634. package/dist/core/task-registry-yield.js +85 -0
  635. package/dist/core/task-registry.d.ts +88 -10
  636. package/dist/core/task-registry.js +124 -33
  637. package/dist/core/task-result.d.ts +126 -31
  638. package/dist/core/task-spec-members.d.ts +140 -1
  639. package/dist/core/task-spec-members.js +23 -8
  640. package/dist/core/task-spec.d.ts +181 -51
  641. package/dist/core/task-spec.js +1 -1
  642. package/dist/core/task-stream.d.ts +12 -2
  643. package/dist/core/terminal-cause.d.ts +12 -4
  644. package/dist/core/thrown-value.d.ts +49 -7
  645. package/dist/core/thrown-value.js +38 -2
  646. package/dist/core/tool-catalog-entries.js +13 -3
  647. package/dist/core/tool-data-door.d.ts +7 -0
  648. package/dist/core/tool-data-door.js +13 -0
  649. package/dist/core/tool-face-lists.d.ts +25 -0
  650. package/dist/core/tool-face-lists.js +38 -0
  651. package/dist/core/tool-face-reader.d.ts +0 -10
  652. package/dist/core/tool-face-reader.js +5 -3
  653. package/dist/core/tool-list-grammar.d.ts +103 -0
  654. package/dist/core/tool-list-grammar.js +130 -0
  655. package/dist/core/tool-mount-facts.d.ts +47 -0
  656. package/dist/core/tool-mount-facts.js +50 -0
  657. package/dist/core/tool-mount-plan.d.ts +196 -0
  658. package/dist/core/tool-mount-plan.js +404 -0
  659. package/dist/core/tool-mount-static.d.ts +12 -0
  660. package/dist/core/tool-mount-static.js +174 -0
  661. package/dist/core/tool-name-aliases.d.ts +60 -2
  662. package/dist/core/tool-name-aliases.js +22 -2
  663. package/dist/core/tool-name-list.d.ts +3 -0
  664. package/dist/core/tool-name-readings.d.ts +4 -0
  665. package/dist/core/tool-name-readings.js +1 -0
  666. package/dist/core/tool-policy.d.ts +246 -51
  667. package/dist/core/tool-policy.js +165 -71
  668. package/dist/core/tool-registry.d.ts +4 -11
  669. package/dist/core/tool-registry.js +0 -3
  670. package/dist/core/tool-result-bytes.d.ts +94 -0
  671. package/dist/core/tool-result-bytes.js +34 -0
  672. package/dist/core/tool-result-store.d.ts +97 -13
  673. package/dist/core/tool-result-store.js +52 -4
  674. package/dist/core/tool-roster.d.ts +71 -10
  675. package/dist/core/tool-roster.js +71 -21
  676. package/dist/core/tool-search-setting.d.ts +7 -9
  677. package/dist/core/tool-search-setting.js +23 -7
  678. package/dist/core/tool-spec.d.ts +32 -2
  679. package/dist/core/tools.js +6 -20
  680. package/dist/core/trace.d.ts +63 -11
  681. package/dist/core/trace.js +19 -0
  682. package/dist/core/types.d.ts +8 -6
  683. package/dist/core/types.js +3 -1
  684. package/dist/core/unmatched-tool-names.d.ts +37 -0
  685. package/dist/core/unmatched-tool-names.js +18 -0
  686. package/dist/core/untrusted-egress.d.ts +16 -5
  687. package/dist/core/untrusted-egress.js +202 -32
  688. package/dist/core/untrusted-text.d.ts +29 -8
  689. package/dist/core/untrusted-text.js +6 -3
  690. package/dist/core/user-attachment.d.ts +129 -35
  691. package/dist/core/user-attachment.js +124 -57
  692. package/dist/core/user-row-origin.d.ts +63 -0
  693. package/dist/core/user-row-origin.js +61 -0
  694. package/dist/core/wiring-manifest.d.ts +161 -39
  695. package/dist/core/wiring-manifest.js +42 -6
  696. package/dist/core/workflow-run-store-contract.d.ts +11 -1
  697. package/dist/core/workflow-run-store-contract.js +60 -7
  698. package/dist/core/workflow-run-store.d.ts +61 -12
  699. package/dist/core/workflow-run-store.js +100 -15
  700. package/dist/core/workspace-snapshot.d.ts +10 -14
  701. package/dist/core/workspace-snapshot.js +3 -22
  702. package/dist/core/write-protect.d.ts +3 -5
  703. package/dist/core/write-protect.js +2 -4
  704. package/dist/engine/compaction/compaction.d.ts +3 -0
  705. package/dist/engine/compaction/compaction.js +4 -3
  706. package/dist/engine/execution-env/node-execution-env.d.ts +15 -4
  707. package/dist/engine/execution-env/node-execution-env.js +80 -27
  708. package/dist/engine/harness/agent-harness.d.ts +143 -27
  709. package/dist/engine/harness/agent-harness.js +162 -74
  710. package/dist/engine/harness/types.d.ts +84 -13
  711. package/dist/engine/harness/types.js +21 -1
  712. package/dist/engine/llm/tool-turns.d.ts +4 -0
  713. package/dist/engine/llm/tool-turns.js +7 -2
  714. package/dist/engine/llm/types.d.ts +111 -24
  715. package/dist/engine/llm/types.js +69 -5
  716. package/dist/engine/llm/validation.js +2 -1
  717. package/dist/engine/loop/agent-loop.d.ts +39 -6
  718. package/dist/engine/loop/agent-loop.js +172 -82
  719. package/dist/engine/loop/types.d.ts +43 -4
  720. package/dist/engine/lsp/node-lsp-manager.d.ts +5 -3
  721. package/dist/engine/lsp/node-lsp-manager.js +14 -10
  722. package/dist/engine/session/import-validate.js +9 -0
  723. package/dist/engine/session/memory-repo.d.ts +8 -1
  724. package/dist/engine/session/memory-repo.js +20 -12
  725. package/dist/engine/session/repo-utils.d.ts +10 -0
  726. package/dist/engine/session/repo-utils.js +11 -5
  727. package/dist/engine/session/row-cells.d.ts +32 -0
  728. package/dist/engine/session/row-cells.js +25 -0
  729. package/dist/index.d.ts +64 -34
  730. package/dist/index.js +45 -21
  731. package/dist/internal/harness.d.ts +8 -6
  732. package/dist/internal/harness.js +6 -4
  733. package/dist/internal/llm.d.ts +2 -2
  734. package/dist/internal/llm.js +1 -1
  735. package/dist/orchestration/governance-baseline-validity.d.ts +7 -0
  736. package/dist/orchestration/governance-baseline-validity.js +33 -9
  737. package/dist/orchestration/run-workflow-tool.d.ts +2 -0
  738. package/dist/orchestration/run-workflow-tool.js +25 -12
  739. package/dist/orchestration/workflow-governance.d.ts +19 -4
  740. package/dist/orchestration/workflow-governance.js +30 -9
  741. package/dist/orchestration/workflow-primitives.d.ts +4 -1
  742. package/dist/orchestration/workflow-primitives.js +2 -2
  743. package/dist/orchestration/workflow-script-runner.d.ts +1 -1
  744. package/dist/orchestration/workflow-size-guideline.d.ts +1 -1
  745. package/dist/orchestration/workflow-types.d.ts +21 -12
  746. package/dist/orchestration/workflow-types.js +15 -4
  747. package/dist/orchestration/workflow.d.ts +37 -7
  748. package/dist/orchestration/workflow.js +81 -35
  749. package/dist/prompt-assembly/artifact-store.js +6 -9
  750. package/dist/prompt-assembly/assemble.d.ts +4 -10
  751. package/dist/prompt-assembly/assemble.js +1 -3
  752. package/dist/prompt-assembly/catalog/constitution.d.ts +0 -20
  753. package/dist/prompt-assembly/catalog/constitution.js +2 -0
  754. package/dist/prompt-assembly/catalog/core-behavior.js +5 -3
  755. package/dist/prompt-assembly/catalog/engine.d.ts +108 -0
  756. package/dist/prompt-assembly/catalog/engine.js +19 -0
  757. package/dist/prompt-assembly/catalog/environment.d.ts +276 -0
  758. package/dist/prompt-assembly/catalog/environment.js +61 -0
  759. package/dist/prompt-assembly/catalog/index.d.ts +9 -2
  760. package/dist/prompt-assembly/catalog/index.js +73 -2
  761. package/dist/prompt-assembly/catalog/locales/index.d.ts +16 -0
  762. package/dist/prompt-assembly/catalog/locales/index.js +22 -0
  763. package/dist/prompt-assembly/catalog/locales/zh-Hans/constitution.d.ts +7 -0
  764. package/dist/prompt-assembly/catalog/locales/zh-Hans/constitution.js +124 -0
  765. package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.d.ts +6 -0
  766. package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +120 -0
  767. package/dist/prompt-assembly/catalog/locales/zh-Hans/cowork.d.ts +8 -0
  768. package/dist/prompt-assembly/catalog/locales/zh-Hans/cowork.js +442 -0
  769. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.d.ts +7 -0
  770. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +15 -0
  771. package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.d.ts +7 -0
  772. package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.js +50 -0
  773. package/dist/prompt-assembly/catalog/locales/zh-Hans/modes.d.ts +7 -0
  774. package/dist/prompt-assembly/catalog/locales/zh-Hans/modes.js +163 -0
  775. package/dist/prompt-assembly/catalog/locales/zh-Hans/role.d.ts +7 -0
  776. package/dist/prompt-assembly/catalog/locales/zh-Hans/role.js +148 -0
  777. package/dist/prompt-assembly/catalog/locales/zh-Hans/team.d.ts +6 -0
  778. package/dist/prompt-assembly/catalog/locales/zh-Hans/team.js +246 -0
  779. package/dist/prompt-assembly/catalog/role.js +3 -6
  780. package/dist/prompt-assembly/catalog/schema.d.ts +23 -1
  781. package/dist/prompt-assembly/catalog/schema.js +2 -0
  782. package/dist/prompt-assembly/composer.d.ts +6 -11
  783. package/dist/prompt-assembly/composer.js +7 -7
  784. package/dist/prompt-assembly/engine-text.d.ts +9 -0
  785. package/dist/prompt-assembly/engine-text.js +33 -0
  786. package/dist/prompt-assembly/event-registry.js +3 -3
  787. package/dist/prompt-assembly/explain.d.ts +1 -0
  788. package/dist/prompt-assembly/explain.js +1 -1
  789. package/dist/prompt-assembly/locale-review.d.ts +13 -0
  790. package/dist/prompt-assembly/locale-review.js +19 -0
  791. package/dist/prompt-assembly/overlay.d.ts +7 -3
  792. package/dist/prompt-assembly/overlay.js +27 -5
  793. package/dist/prompt-assembly/renderers.d.ts +4 -4
  794. package/dist/prompt-assembly/renderers.js +26 -17
  795. package/dist/prompt-assembly/role-base.d.ts +1 -1
  796. package/dist/prompt-assembly/select.d.ts +26 -5
  797. package/dist/prompt-assembly/select.js +25 -2
  798. package/dist/prompt-assembly/slots.d.ts +19 -0
  799. package/dist/prompt-assembly/slots.js +16 -0
  800. package/dist/prompt-assembly/sugar.d.ts +4 -7
  801. package/dist/prompt-assembly/sugar.js +1 -2
  802. package/dist/prompt-assembly/tool-catalog.d.ts +5 -1
  803. package/dist/prompt-assembly/tool-catalog.js +5 -1
  804. package/dist/prompt-assembly/turn-snapshot.d.ts +38 -10
  805. package/dist/prompt-assembly/turn-snapshot.js +43 -13
  806. package/dist/prompt-assembly/types.d.ts +3 -0
  807. package/dist/prompts/cowork.d.ts +6 -25
  808. package/dist/prompts/cowork.js +10 -12
  809. package/dist/prompts/default.d.ts +10 -32
  810. package/dist/prompts/default.js +37 -63
  811. package/dist/shell/lex.d.ts +39 -13
  812. package/dist/shell/lex.js +70 -30
  813. package/dist/stores/file/background-agent-store.d.ts +5 -0
  814. package/dist/stores/file/background-agent-store.js +35 -61
  815. package/dist/stores/file/checkpoint-store.d.ts +5 -3
  816. package/dist/stores/file/checkpoint-store.js +8 -10
  817. package/dist/stores/file/fs-atomic.d.ts +27 -70
  818. package/dist/stores/file/fs-atomic.js +52 -148
  819. package/dist/stores/file/index.d.ts +12 -0
  820. package/dist/stores/file/index.js +27 -2
  821. package/dist/stores/file/mailbox-store.d.ts +10 -1
  822. package/dist/stores/file/mailbox-store.js +40 -12
  823. package/dist/stores/file/permission-rule-adopt.js +5 -2
  824. package/dist/stores/file/permission-rule-store.d.ts +81 -20
  825. package/dist/stores/file/permission-rule-store.js +126 -33
  826. package/dist/stores/file/session-policy-store.d.ts +2 -2
  827. package/dist/stores/file/session-store.d.ts +21 -2
  828. package/dist/stores/file/session-store.js +27 -14
  829. package/dist/stores/file/task-list-store.js +23 -25
  830. package/dist/stores/file/tool-result-store.d.ts +45 -7
  831. package/dist/stores/file/tool-result-store.js +99 -36
  832. package/dist/stores/file/workflow-run-store.d.ts +1 -0
  833. package/dist/stores/file/workflow-run-store.js +14 -11
  834. package/dist/tools/artifact/artifact-tool.js +2 -0
  835. package/dist/tools/artifact/local-stub.js +6 -6
  836. package/dist/tools/fs/bash-program-position.d.ts +1 -2
  837. package/dist/tools/fs/bash-readonly-classifier.d.ts +35 -0
  838. package/dist/tools/fs/bash-readonly-classifier.js +50 -12
  839. package/dist/tools/fs/env-error-detail.d.ts +1 -0
  840. package/dist/tools/fs/env-error-detail.js +7 -0
  841. package/dist/tools/fs/fs-bash.d.ts +24 -6
  842. package/dist/tools/fs/fs-bash.js +73 -25
  843. package/dist/tools/fs/fs-pdf.js +6 -4
  844. package/dist/tools/fs/fs-read.d.ts +76 -31
  845. package/dist/tools/fs/fs-read.js +159 -79
  846. package/dist/tools/fs/fs-search-tools.d.ts +1 -1
  847. package/dist/tools/fs/fs-search-tools.js +3 -1
  848. package/dist/tools/fs/fs-shared.d.ts +59 -63
  849. package/dist/tools/fs/fs-shared.js +31 -18
  850. package/dist/tools/fs/fs-write.d.ts +13 -0
  851. package/dist/tools/fs/fs-write.js +69 -13
  852. package/dist/tools/fs/index.d.ts +19 -1
  853. package/dist/tools/fs/index.js +10 -2
  854. package/dist/tools/fs/pdf.js +10 -9
  855. package/dist/tools/fs/read-deny.js +4 -10
  856. package/dist/tools/fs/read-floor.d.ts +5 -4
  857. package/dist/tools/fs/removal-targets.d.ts +11 -5
  858. package/dist/tools/fs/removal-targets.js +62 -32
  859. package/dist/tools/fs/safety.d.ts +26 -19
  860. package/dist/tools/fs/safety.js +13 -8
  861. package/dist/tools/fs/search.d.ts +1 -1
  862. package/dist/tools/fs/shell-read-argv.js +1 -0
  863. package/dist/tools/fs/shell-read-bindings.d.ts +128 -26
  864. package/dist/tools/fs/shell-read-bindings.js +667 -139
  865. package/dist/tools/fs/shell-read-check.js +1 -1
  866. package/dist/tools/fs/shell-read-judge.d.ts +4 -1
  867. package/dist/tools/fs/shell-read-judge.js +5 -1
  868. package/dist/tools/fs/shell-read-plan.d.ts +4 -0
  869. package/dist/tools/fs/shell-read-plan.js +21 -19
  870. package/dist/tools/fs/shell-read-sourced.d.ts +4 -3
  871. package/dist/tools/fs/shell-read-sourced.js +18 -1
  872. package/dist/tools/fs/shell-read-start.d.ts +6 -6
  873. package/dist/tools/fs/shell-read-start.js +1 -6
  874. package/dist/tools/fs/shell-read-word.d.ts +4 -2
  875. package/dist/tools/fs/shell-read-word.js +7 -6
  876. package/dist/tools/fs/shell-read-workdir.d.ts +1 -1
  877. package/dist/tools/fs/shell-reentry-text.d.ts +24 -9
  878. package/dist/tools/fs/shell-reentry-text.js +50 -20
  879. package/dist/tools/monitor.d.ts +4 -0
  880. package/dist/tools/monitor.js +14 -4
  881. package/dist/tools/scheduler-tools.d.ts +5 -2
  882. package/dist/tools/scheduler-tools.js +8 -6
  883. package/dist/tools/task-list.d.ts +49 -20
  884. package/dist/tools/task-list.js +115 -35
  885. package/dist/tools/web.d.ts +13 -3
  886. package/dist/tools/web.js +17 -6
  887. package/dist/tools/worktree.d.ts +3 -2
  888. package/dist/tools/worktree.js +24 -25
  889. package/package.json +10 -3
  890. package/test/export-surface.snapshot.json +340 -32
  891. package/wire-changes/core-stores-sql@7.67.0.json +39 -0
  892. package/wire-changes/core-stores-sql@7.67.1.json +39 -0
  893. package/wire-changes/core@7.67.0.json +12578 -0
  894. package/wire-changes/core@7.67.1.json +406 -0
  895. package/wire-changes/mods-kernel@7.67.0.json +167 -0
  896. package/wire-changes/mods-kernel@7.67.1.json +39 -0
  897. package/wire-changes/primitives@7.67.0.json +325 -0
  898. package/wire-changes/primitives@7.67.1.json +39 -0
  899. package/wire-changes/wiki-gate@7.67.0.json +1636 -0
  900. package/wire-changes/wiki-gate@7.67.1.json +39 -0
  901. package/dist/brain/degrading.d.ts +0 -93
  902. package/dist/brain/degrading.js +0 -189
  903. package/dist/core/tool-conformance.d.ts +0 -20
  904. package/dist/core/tool-conformance.js +0 -37
@@ -1,8 +1,8 @@
1
- import { argvOf, arithmeticTextIsPlain, expansionHidesRun, expansionsInHeredocBody, lexShell, literalTildeSpelling, namesRedirectDescriptor, parameterArithmeticTexts } from "../../shell/lex.js";
1
+ import { argvOf, arithmeticTextIsPlain, expansionHidesRun, expansionsInHeredocBody, lexShell, literalTextOf, literalTildeSpelling, namesRedirectDescriptor, parameterArithmeticTexts } from "../../shell/lex.js";
2
2
  import { shellWordsOf } from "../../shell/shell-words.js";
3
3
  import { isShellSyntaxWord, LOOP_LIST_HEADS, readProgramPosition } from "./bash-program-position.js";
4
4
  import { declaredAttributes, programRow, readArgRoles } from "./program-read-model.js";
5
- import { codeBodies } from "./shell-reentry-text.js";
5
+ import { codeBodies, descriptorTextsOf } from "./shell-reentry-text.js";
6
6
  import { braceWordListsOf } from "./shell-read-brace.js";
7
7
  import { BUILTIN_ENABLED, BUILTINS_ALL, ENABLE_BUILTIN, builtinKey, chainAvailability, enableBindings, isBuiltinKey, isDisabledValue, speaksFor } from "./shell-read-builtins.js";
8
8
  export function judgedSpellingOf(v) {
@@ -15,6 +15,15 @@ export function floorOf(v) {
15
15
  const pattern = judgedSpellingOf(v);
16
16
  return v.glob === true ? { spelled: v.spelled, glob: true, ...(pattern !== undefined ? { pattern } : {}) } : { spelled: v.spelled };
17
17
  }
18
+ export function bindingValues(b) {
19
+ return joinFloors({ values: b.state === "unknown" ? [] : b.state.map(floorOf), pastBound: false }, b.floor ?? NO_FLOOR);
20
+ }
21
+ export function bindingFloors(bindings) {
22
+ const out = new Map();
23
+ for (const b of bindings)
24
+ out.set(b.name, joinFloors(out.get(b.name) ?? NO_FLOOR, bindingValues(b)));
25
+ return out;
26
+ }
18
27
  function sameValue(a, b) {
19
28
  if (a.spelled !== b.spelled || a.fields?.length !== b.fields?.length)
20
29
  return false;
@@ -28,7 +37,7 @@ export const SHELL_INTEGER_VARIABLES = new Set([
28
37
  "LISTMAX", "LOGCHECK", "PERIOD", "FUNCNEST", "UID", "EUID", "GID", "EGID", "REPORTTIME", "REPORTMEMORY", "DIRSTACKSIZE", "BAUD",
29
38
  "ZLE_RPROMPT_INDENT", "MBEGIN", "MEND", "PPID", "ARGC", "ZSH_SUBSHELL", "TTYIDLE", "status",
30
39
  ]);
31
- const SHELL_SET_VARIABLES = new Set(["REPLY", "OPTARG", "MAPFILE", "BASH_REMATCH", "PIPESTATUS", "FUNCNAME", "BASH_COMMAND", "BASH_SUBSHELL", "COPROC", "GROUPS", "SHELLOPTS", "BASHOPTS", "BASH_VERSINFO"]);
40
+ const SHELL_SET_VARIABLES = new Set(["REPLY", "OPTARG", "MAPFILE", "BASH_REMATCH", "PIPESTATUS", "FUNCNAME", "BASH_COMMAND", "BASH_SUBSHELL", "COPROC", "GROUPS", "SHELLOPTS", "BASHOPTS", "BASH_VERSINFO", "DIRSTACK", "BASH_ARGV", "BASH_ARGC", "BASH_SOURCE", "BASH_LINENO"]);
32
41
  export function shellKeepsName(name) {
33
42
  return SHELL_INTEGER_VARIABLES.has(name) || SHELL_SET_VARIABLES.has(name);
34
43
  }
@@ -41,6 +50,7 @@ const GROUP_WORDS = shellWordsOf("group"), DEFINITION_WORDS = shellWordsOf("defi
41
50
  export const SPECIAL_BUILTINS = new Set([":", ".", "break", "continue", "eval", "exec", "exit", "export", "readonly", "return", "set", "shift", "source", "times", "trap", "unset"]);
42
51
  const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
43
52
  const LOCAL_DECLARATION = "local";
53
+ const BODY_SCOPED_DECLARATIONS = new Set([LOCAL_DECLARATION, "declare", "typeset"]);
44
54
  const FUNCTION_KEY_PREFIX = "()";
45
55
  export const functionKey = (name) => FUNCTION_KEY_PREFIX + name;
46
56
  const isFunctionKey = (name) => name.startsWith(FUNCTION_KEY_PREFIX);
@@ -90,6 +100,13 @@ export function inheritedExportedFunctions(names) {
90
100
  }
91
101
  const ATTRIBUTE_KINDS = { integer: "integer", transformed: "transformed", frozen: "frozen" };
92
102
  const EVERY_ATTRIBUTE = Object.values(ATTRIBUTE_KINDS).map((kind) => ({ kind }));
103
+ export const NO_FLOOR_READER = () => NO_FLOOR;
104
+ export function floorReaderOf(table) {
105
+ return (word, overlay, floors) => wordFloorValues(word, overlay.size === 0 ? table : {
106
+ stateOf: (name) => overlay.get(name) ?? table.stateOf(name),
107
+ floorOf: (name) => (overlay.has(name) ? floors.get(name) ?? NO_FLOOR : table.floorOf(name)),
108
+ });
109
+ }
93
110
  export function projectSegments(segments) {
94
111
  const { dropped, arms } = segmentStructure(segments);
95
112
  return segments.map((segment, si) => projectSegment(segment, dropped[si], arms[si]));
@@ -397,6 +414,14 @@ function joinRuns(runs, more) {
397
414
  }
398
415
  export function valueOf(word, table, quoted, overlay = new Map(), split = false) {
399
416
  const stateOf = (name) => (table === undefined ? "unknown" : overlay.get(name) ?? table.stateOf(name));
417
+ if (split && table !== undefined && word.pieces.length === 1) {
418
+ const only = word.pieces[0];
419
+ const e = only.expansion;
420
+ if (only.quotedBy === '"' && e?.kind === "parameter" && e.name !== undefined && e.body === `${e.name}[@]`) {
421
+ const list = overlay.has(e.name) ? undefined : table.arrayOf(e.name);
422
+ return list === undefined ? "unknown" : [{ spelled: list.map((v) => v.spelled).join(" "), fields: list.map((v) => v.spelled) }];
423
+ }
424
+ }
400
425
  const EMPTY = { text: "", runs: [] };
401
426
  let combos = [{ field: EMPTY, closed: [], started: false, split: false }];
402
427
  const activeRun = (text) => ({ text, mode: "active" });
@@ -490,66 +515,106 @@ export function valueOf(word, table, quoted, overlay = new Map(), split = false)
490
515
  }
491
516
  return out;
492
517
  }
518
+ export const NO_FLOOR = { values: [], pastBound: false };
519
+ export function isEmptyFloor(f) {
520
+ return f.values.length === 0 && !f.pastBound;
521
+ }
522
+ export function joinFloors(...floors) {
523
+ return { values: floors.flatMap((f) => f.values), pastBound: floors.some((f) => f.pastBound) };
524
+ }
493
525
  export function wordFloorValues(word, table) {
494
526
  if (table === undefined)
495
- return [];
527
+ return { values: [], pastBound: false };
496
528
  for (let kept = Number.POSITIVE_INFINITY;; kept = Math.min(kept, WORD_VALUES_MAX) - 1) {
497
529
  const combos = floorCombos(word, table, kept);
498
530
  if (combos !== "past")
499
- return combos;
531
+ return kept === Number.POSITIVE_INFINITY ? combos : { values: combos.values, pastBound: true };
500
532
  if (kept === 0)
501
- return [];
533
+ return { values: [], pastBound: true };
502
534
  }
503
535
  }
536
+ function transformsValue(p) {
537
+ const e = p.expansion;
538
+ if (e?.kind !== "parameter" || e.name === undefined || e.body === undefined || e.body === e.name)
539
+ return false;
540
+ return !(e.body.startsWith(`${e.name}[`) && e.body.indexOf("]") === e.body.length - 1);
541
+ }
504
542
  function floorCombos(word, table, kept) {
505
543
  let combos = [{ spelled: "" }];
544
+ let pastBound = false;
545
+ const own = [];
546
+ const transformed = word.pieces.some(transformsValue);
506
547
  for (const p of word.pieces) {
507
548
  const e = p.expansion;
508
- let options;
549
+ let options = [];
509
550
  if (e === undefined) {
510
- if (p.literal === undefined)
511
- return [];
512
- options = [{ spelled: p.literal }];
551
+ if (p.literal !== undefined)
552
+ options = [{ spelled: p.literal }];
513
553
  }
514
554
  else if (e.kind === "parameter" && e.name !== undefined) {
515
555
  const state = table.stateOf(e.name);
516
556
  const known = state !== "unknown" && (e.body === undefined || e.body === e.name) ? state : undefined;
517
- const floor = known === undefined ? table.floorOf(e.name) : [];
518
- options = known !== undefined ? known.map(floorOf) : [...floor.filter((o) => o.held !== true), ...floor.filter((o) => o.held === true).slice(0, kept)];
557
+ const floor = known === undefined ? table.floorOf(e.name) : NO_FLOOR;
558
+ pastBound ||= floor.pastBound;
559
+ options = known !== undefined ? known.map(floorOf) : [...floor.values.filter((o) => o.held !== true), ...floor.values.filter((o) => o.held === true).slice(0, kept)];
519
560
  }
520
- else
521
- return [];
561
+ if (transformed)
562
+ own.push(...options.map((o) => ({ ...o, piece: true })));
522
563
  if (options.length === 0)
523
- return [];
564
+ combos = undefined;
565
+ if (combos === undefined)
566
+ continue;
524
567
  const next = [];
525
568
  for (const c of combos) {
526
- for (const o of options) {
569
+ for (const o of distinctSpellings(options)) {
527
570
  const pattern = c.pattern !== undefined || o.pattern !== undefined ? (c.pattern ?? c.spelled) + (o.pattern ?? o.spelled) : undefined;
528
- next.push(c.glob === true || o.glob === true ? { spelled: c.spelled + o.spelled, glob: true, ...(pattern !== undefined ? { pattern } : {}) } : { spelled: c.spelled + o.spelled });
571
+ const piece = c.piece === true || o.piece === true ? { piece: true } : {};
572
+ next.push(c.glob === true || o.glob === true ? { spelled: c.spelled + o.spelled, glob: true, ...(pattern !== undefined ? { pattern } : {}), ...piece } : { spelled: c.spelled + o.spelled, ...piece });
529
573
  }
530
574
  }
531
- if (next.length > WORD_VALUES_MAX)
575
+ combos = distinctSpellings(next);
576
+ if (combos.length > WORD_VALUES_MAX)
532
577
  return "past";
533
- combos = next;
534
578
  }
535
- return combos;
579
+ const values = transformed ? distinctSpellings([...(combos ?? []), ...own]) : combos ?? [];
580
+ return values.length > WORD_VALUES_MAX ? "past" : { values, pastBound };
581
+ }
582
+ function distinctSpellings(values) {
583
+ const kept = new Map();
584
+ for (const v of values) {
585
+ const key = `${v.glob === true ? "g" : "l"}\u0000${v.spelled}\u0000${v.pattern ?? ""}`;
586
+ const k = kept.get(key);
587
+ if (k === undefined || (k.piece === true && v.piece !== true))
588
+ kept.set(key, v);
589
+ }
590
+ return [...kept.values()];
536
591
  }
537
592
  export function loopListHeadAt(argv) {
538
593
  const at = isShellSyntaxWord(argv[0], LOOP_LIST_HEADS) ? 0 : readProgramPosition(argv).written;
539
594
  return at !== undefined && isShellSyntaxWord(argv[at], LOOP_LIST_HEADS) ? at : undefined;
540
595
  }
541
- export function bindingEffectOf(segment, argv, shape, readValue, shadow, availability, fed, fedByLoop = false) {
596
+ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availability, fed, fedByLoop = false, splitUnsettled = false, readFloor = NO_FLOOR_READER) {
542
597
  const bindings = [];
543
598
  let all = shape.defines.length > 0 ? "reset" : undefined;
544
599
  const unknownAll = () => void (all = "unknown");
545
600
  const overlay = new Map();
601
+ const floors = new Map();
546
602
  let scope;
547
603
  const bind = (b) => {
548
604
  bindings.push(scope !== undefined ? { ...b, scope } : b);
549
- if (b.prefix !== true)
550
- overlay.set(b.name, b.state);
605
+ if (b.prefix === true)
606
+ return;
607
+ overlay.set(b.name, b.state);
608
+ if (b.floor !== undefined)
609
+ floors.set(b.name, b.floor);
610
+ else
611
+ floors.delete(b.name);
551
612
  };
552
613
  const kill = (name) => bind({ name, state: "unknown" });
614
+ const floorFrom = (bound, values = overlay, held = floors) => {
615
+ const floor = sourcedFloor(bound, (w) => { const v = readValue(w, true, values); return v !== "unknown" ? { values: v.map(floorOf), pastBound: false } : readFloor(w, values, held); });
616
+ return isEmptyFloor(floor) ? {} : { floor };
617
+ };
553
618
  for (const name of shape.defines)
554
619
  bind({ name: functionKey(name), state: FUNCTION_DEFINED });
555
620
  const nameOf = (w) => {
@@ -599,9 +664,10 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
599
664
  }
600
665
  const inAt = argv.findIndex((w, i) => i >= loopAt + 2 && w.raw === "in");
601
666
  let state = "unknown";
602
- if (ITERATING_HEADS.has(headWord) && inAt === loopAt + 2 && argv.length > loopAt + 3) {
667
+ const listWords = inAt === loopAt + 2 && argv.length > loopAt + 3 ? [...new Map(braceWordListsOf(argv.slice(loopAt + 3)).flat().map((x) => [x.raw, x])).values()] : [];
668
+ if (ITERATING_HEADS.has(headWord) && listWords.length > 0) {
603
669
  const values = [];
604
- for (const w of new Map(braceWordListsOf(argv.slice(loopAt + 3)).flat().map((x) => [x.raw, x])).values()) {
670
+ for (const w of listWords) {
605
671
  const v = readValue(w, false, overlay);
606
672
  if (v === "unknown") {
607
673
  values.length = 0;
@@ -612,7 +678,8 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
612
678
  if (values.length > 0)
613
679
  state = values;
614
680
  }
615
- bind({ name, state, loopVar: true });
681
+ const splits = listWords.some((w) => w.pieces.some((p) => p.quotedBy === undefined && p.expansion?.kind === "parameter"));
682
+ bind({ name, state, loopVar: true, ...(state === "unknown" ? floorFrom({ name, sources: listWords.map(wordSource), cut: (t) => (splits ? [t, ...splitFields(plainChars(t), IFS_DEFAULT).fields] : [t]) }) : {}) });
616
683
  return { bindings, all };
617
684
  }
618
685
  if (argv[0] !== undefined && BACKGROUND_WORDS.has(argv[0].raw) && argv[1] !== undefined)
@@ -625,10 +692,12 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
625
692
  const a = argv[k].assignment;
626
693
  if (a === undefined)
627
694
  continue;
628
- if (statement)
629
- bind({ name: a.name, state: assignedState(a, readValue, overlay), ...(bindsArrayElement(a) ? { floor: arrayElementFloor(a, readValue, overlay) } : {}) });
695
+ if (statement) {
696
+ const array = literalElementsOf(a);
697
+ bind({ name: a.name, ...assignedBinding(a, readValue, readFloor, overlay, floors), ...(array !== undefined ? { array } : {}) });
698
+ }
630
699
  else if (program !== undefined && SPECIAL_BUILTINS.has(program.basename))
631
- bind({ name: a.name, state: assignedState(a, readValue, overlay), prefix: true });
700
+ bind({ name: a.name, ...assignedBinding(a, readValue, readFloor, overlay, floors), prefix: true });
632
701
  }
633
702
  const programWord = program === undefined ? undefined : argv[program.index];
634
703
  if (programWord !== undefined && nameOf(programWord) === "computed" && !programWord.pieces.some((p) => p.literal?.includes("/") === true)) {
@@ -648,27 +717,48 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
648
717
  const args = argv.slice(program.index + 1);
649
718
  if (program.basename === ENABLE_BUILTIN)
650
719
  return finish({ bindings: [...bindings, ...enableBindings(args)], all });
651
- if (row === undefined)
652
- return { bindings, all };
720
+ const ownIfsWord = pos.assignments.map((k) => argv[k].assignment).findLast((a) => a?.name === "IFS");
721
+ const ownIfs = ownIfsWord !== undefined;
722
+ const ifs = ownIfsWord !== undefined ? (storesValueWord(ownIfsWord) ? literalTextOf(ownIfsWord.value.pieces) : undefined) : splitUnsettled ? undefined : IFS_DEFAULT;
723
+ const input = (fd) => (fd === 0 ? fed ?? [] : [...(fd === undefined ? fed ?? [] : []), ...descriptorTextsOf(segment, fd)]);
724
+ const sourced = new Map((SOURCED_BINDERS[program.basename]?.(args, input, fedByLoop, ifs) ?? []).map((b) => [b.name, { ...floorFrom(b), ...(b.keeps === true ? { keeps: true } : {}) }]));
725
+ const named = new Set();
726
+ const bindNamed = (name) => {
727
+ const floor = name === undefined || name === "computed" ? undefined : sourced.get(name);
728
+ if (floor === undefined)
729
+ return killNamed(name);
730
+ named.add(name);
731
+ bind({ name: name, state: "unknown", ...floor });
732
+ };
733
+ const bindUnasked = () => {
734
+ for (const [name, floor] of sourced)
735
+ if (!named.has(name) && floor.floor !== undefined)
736
+ bind({ name, state: "unknown", ...floor });
737
+ };
738
+ if (row === undefined) {
739
+ bindUnasked();
740
+ return finish({ bindings, all });
741
+ }
653
742
  const folded = args.map((w) => w.folded);
654
743
  if (row.reentry?.kind === "shell" && (row.reentry.text === "words" || row.reentry.text === "file-operand"))
655
744
  unknownAll();
656
745
  for (const body of codeBodies(program.basename, folded)) {
657
- const inner = namesBoundIn(body);
746
+ const inner = bindingsIn(body);
658
747
  if (inner === "all")
659
748
  unknownAll();
660
749
  else
661
- for (const name of inner)
662
- kill(name);
750
+ for (const [name, floor] of inner)
751
+ bind({ name, state: "unknown", prefix: true, ...(!isEmptyFloor(floor) ? { floor } : {}) });
663
752
  }
664
753
  if (row.builtin === "declaration") {
665
- scope = args.some((w) => w.folded.startsWith("-") || w.folded.startsWith("+")) ? "unread" : program.basename === LOCAL_DECLARATION ? "local" : undefined;
754
+ scope = args.some((w) => w.folded.startsWith("-") || w.folded.startsWith("+")) ? "unread" : BODY_SCOPED_DECLARATIONS.has(program.basename) ? "local" : undefined;
666
755
  const assigns = declaredAttributes(row, folded);
667
756
  const kinds = [...assigns].filter((k) => k !== "reference" && k !== "unsettled");
668
757
  const storesText = [...assigns].every((k) => k === "frozen");
669
758
  let references = assigns.has("reference");
670
759
  const attributes = [];
671
760
  const expanded = new Map(overlay);
761
+ const expandedFloors = new Map(floors);
672
762
  for (const w of args) {
673
763
  const a = w.assignment;
674
764
  const name = a?.name ?? nameOf(w);
@@ -682,11 +772,15 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
682
772
  continue;
683
773
  const refused = attributes.some((x) => x.name === undefined || x.name === name);
684
774
  if (a !== undefined && bindsArrayElement(a))
685
- bind({ name, state: "unknown", floor: arrayElementFloor(a, readValue, expanded) });
686
- else if (a === undefined || !storesText || refused)
775
+ bind({ name, ...assignedBinding(a, readValue, readFloor, expanded, expandedFloors) });
776
+ else if (a === undefined && scope !== "local")
777
+ bind({ name, state: "unknown", prefix: true });
778
+ else if (a === undefined)
687
779
  kill(name);
780
+ else if (!storesText || refused)
781
+ bind({ name, state: "unknown", keeps: true, ...floorFrom({ name, sources: [wordSource({ pieces: a.value.pieces })], cut: (t) => [t, t.toLowerCase(), t.toUpperCase()] }, expanded, expandedFloors) });
688
782
  else
689
- bind({ name, state: assignedState(a, readValue, expanded) });
783
+ bind({ name, ...assignedBinding(a, readValue, readFloor, expanded, expandedFloors) });
690
784
  attributes.push(...kinds.map((kind) => ({ name, kind })));
691
785
  }
692
786
  const inFunction = program.basename === LOCAL_DECLARATION ? { inFunction: true } : {};
@@ -703,17 +797,65 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
703
797
  if (w.pieces.every((p) => p.literal !== undefined && p.expansion === undefined))
704
798
  bind({ name: functionKey(w.folded), state: FUNCTION_ABSENT, prefix: true });
705
799
  }
706
- if (program.basename === "read" && chainIsBuiltin && !pos.assignments.some((k) => argv[k].assignment?.name === "IFS")) {
800
+ if (program.basename === "read" && chainIsBuiltin) {
707
801
  const readAvailable = chainAvailability([...pos.launchers.map((l) => l.name), program.basename], availability);
708
802
  if (readAvailable === "disabled")
709
803
  return finish({ bindings, all });
710
804
  const line = readBuiltinLines(args, fed, fedByLoop);
711
805
  if (line !== undefined) {
712
806
  const mayFail = segment.tokens.some((t) => t.kind === "redirect" && t.op !== "<<<");
807
+ if (splitUnsettled || ownIfs) {
808
+ const floor = [...line.values, ...line.raw].reduce((acc, v) => (acc.some((x) => x.spelled === v.spelled) ? acc : [...acc, { spelled: v.spelled, held: true }]), []);
809
+ bind({ name: line.name, state: "unknown", prefix: true, ...(floor.length > 0 ? { floor: { values: floor, pastBound: false } } : {}) });
810
+ return finish({ bindings, all });
811
+ }
713
812
  bind({ name: line.name, state: line.values, loopVar: true, ...(mayFail || readAvailable === "maybe" || shadow === "maybe" ? { prefix: true } : {}) });
714
813
  return finish({ bindings, all });
715
814
  }
716
815
  }
816
+ if (program.basename === "printf" && chainIsBuiltin) {
817
+ const roles = readArgRoles(row, folded);
818
+ let name;
819
+ let arrayElement = false;
820
+ let nameComputed = false;
821
+ for (const e of roles) {
822
+ const role = e.kind === "value" || e.kind === "operand" ? e.role : e.kind === "option" && typeof e.reading === "object" ? e.reading.role : undefined;
823
+ if (role?.kind !== "binds-name")
824
+ continue;
825
+ if (nameOf(args[e.at]) === "computed") {
826
+ nameComputed = true;
827
+ break;
828
+ }
829
+ const text = e.kind === "option" && typeof e.reading === "object" ? e.reading.attached : args[e.at].pieces.map((p) => p.literal).join("");
830
+ name = nameIn(text);
831
+ arrayElement = text.includes("[");
832
+ break;
833
+ }
834
+ if (nameComputed) {
835
+ unknownAll();
836
+ return finish({ bindings, all });
837
+ }
838
+ if (name !== undefined) {
839
+ const operands = roles.flatMap((e) => (e.kind === "operand" ? [e] : [])).sort((a, b) => a.ordinal - b.ordinal).map((e) => args[e.at]);
840
+ const written = { name, sources: [{ words: operands, made: ([format, ...rest]) => (format === undefined || rest.some((t) => t === undefined) ? undefined : printfBoundValue(format, rest)) }], cut: (t) => [t], ...(operands.slice(1).some((w) => w.pieces.some(joinsValues)) ? { loose: true } : {}) };
841
+ const single = (w) => {
842
+ if (w === undefined)
843
+ return undefined;
844
+ const v = readValue(w, true, overlay);
845
+ return v !== "unknown" && v.length === 1 ? v[0].spelled : undefined;
846
+ };
847
+ const formatText = operands.length > 0 ? single(operands[0]) : "";
848
+ const argTexts = operands.slice(1).map(single);
849
+ const output = !arrayElement && formatText !== undefined && argTexts.every((t) => t !== undefined) ? printfBoundValue(formatText, argTexts) : undefined;
850
+ if (name === "HOME")
851
+ bind({ name, state: "unknown", ...floorFrom(written) });
852
+ else if (output !== undefined)
853
+ bind({ name, state: [{ spelled: output }] });
854
+ else
855
+ bind({ name, state: "unknown", prefix: true, ...floorFrom(written) });
856
+ }
857
+ return finish({ bindings, all });
858
+ }
717
859
  for (const e of readArgRoles(row, folded)) {
718
860
  const role = e.kind === "value" || e.kind === "operand" ? e.role : e.kind === "option" && typeof e.reading === "object" ? e.reading.role : undefined;
719
861
  if (role?.kind === "program-text" && role.language === "arithmetic" && e.kind !== "end-of-options" && e.kind !== "dash-word-operand") {
@@ -724,11 +866,12 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
724
866
  if (role?.kind !== "binds-name")
725
867
  continue;
726
868
  if (e.kind === "option" && typeof e.reading === "object") {
727
- killNamed(nameOf(args[e.at]) === "computed" ? "computed" : nameIn(e.reading.attached));
869
+ bindNamed(nameOf(args[e.at]) === "computed" ? "computed" : nameIn(e.reading.attached));
728
870
  continue;
729
871
  }
730
- killNamed(nameOf(args[e.at]));
872
+ bindNamed(nameOf(args[e.at]));
731
873
  }
874
+ bindUnasked();
732
875
  const nameLetters = new Set(row.grammars.flatMap((g) => Object.entries(g.short).flatMap(([letter, s]) => (s.value?.kind === "binds-name" ? [letter] : []))));
733
876
  if (nameLetters.size > 0 && readArgRoles(row, folded).some((e) => e.kind === "option" && e.reading === "speculative" && [...folded[e.at].slice(1)].some((ch) => nameLetters.has(ch))))
734
877
  unknownAll();
@@ -746,21 +889,49 @@ function readBuiltinLines(args, fed, fedByLoop) {
746
889
  const names = words.filter((w) => !w.startsWith("-") || w === "-");
747
890
  if (names.length !== 1 || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(names[0]) || names[0] === "HOME")
748
891
  return undefined;
749
- const raw = options.length === 0;
750
- const lines = [];
751
- for (const t of fed) {
752
- const text = t.literal;
753
- if (raw && text.includes("\\"))
892
+ const noBackslashProcessing = options.length === 0;
893
+ for (const t of fed)
894
+ if (noBackslashProcessing && t.literal.includes("\\"))
895
+ return undefined;
896
+ const consumed = fed.flatMap((t) => { const records = readRecords(t.literal, "\n", true); return fedByLoop ? records : records.slice(0, 1); });
897
+ const uniq = (xs) => [...new Set(xs.length === 0 ? [""] : xs)].map((spelled) => ({ spelled }));
898
+ return { name: names[0], values: uniq(consumed.map((r) => nameField(splitFields(r, IFS_DEFAULT), 0, 1))), raw: uniq(consumed.map(textOf)) };
899
+ }
900
+ function printfBoundValue(format, args) {
901
+ if (format.includes("\\") || !/%[sb%]/.test(format.replace(/%%/g, ""))) {
902
+ if (format.includes("\\") || /%(?![sb%])/.test(format))
754
903
  return undefined;
755
- const parts = text.split("\n");
756
- if (parts.length > 1 && parts[parts.length - 1] === "")
757
- parts.pop();
758
- for (const l of parts)
759
- lines.push(l.replace(/^[ \t]+|[ \t]+$/g, ""));
904
+ return format.replace(/%%/g, "%");
760
905
  }
761
- const consumed = fedByLoop ? lines : fed.map((t) => (t.literal.split("\n")[0] ?? "").replace(/^[ \t]+|[ \t]+$/g, ""));
762
- const unique = [...new Set(consumed.length === 0 ? [""] : consumed)];
763
- return { name: names[0], values: unique.map((spelled) => ({ spelled })) };
906
+ let out = "";
907
+ let ai = 0;
908
+ let guard = 0;
909
+ do {
910
+ const before = ai;
911
+ for (let i = 0; i < format.length; i++) {
912
+ if (format[i] !== "%") {
913
+ out += format[i];
914
+ continue;
915
+ }
916
+ const c = format[i + 1];
917
+ i++;
918
+ if (c === "%") {
919
+ out += "%";
920
+ continue;
921
+ }
922
+ if (c === "s" || c === "b") {
923
+ const arg = args[ai++] ?? "";
924
+ if (c === "b" && arg.includes("\\"))
925
+ return undefined;
926
+ out += arg;
927
+ continue;
928
+ }
929
+ return undefined;
930
+ }
931
+ if (ai === before)
932
+ return out;
933
+ } while (ai < args.length && ++guard < 64);
934
+ return ai < args.length ? undefined : out;
764
935
  }
765
936
  function nameIn(text) {
766
937
  return /^([A-Za-z_][A-Za-z0-9_]*)(?:\[.*\])?$/s.exec(text)?.[1];
@@ -795,24 +966,272 @@ function compoundElementWords(a) {
795
966
  export function bindsArrayElement(a) {
796
967
  return a.form === "compound" || a.subscript !== undefined;
797
968
  }
969
+ function literalElementsOf(a) {
970
+ if (a.form !== "compound" || a.op !== "=" || a.subscript !== undefined || a.elements === undefined)
971
+ return undefined;
972
+ const out = [];
973
+ for (const { word } of a.elements) {
974
+ if (word.pieces.some((p) => p.expansion !== undefined || p.literal === undefined))
975
+ return undefined;
976
+ out.push({ spelled: word.pieces.map((p) => p.literal).join("") });
977
+ }
978
+ return out;
979
+ }
798
980
  export function assignsAsStatement(pos) {
799
981
  return pos.program === undefined && pos.launchers.length === 0 && pos.refusal === undefined;
800
982
  }
801
- function arrayElementFloor(a, readValue, overlay) {
983
+ function arrayElementFloor(a, readValue, readFloor, overlay, floors) {
802
984
  const words = a.form === "compound" ? compoundElementWords(a) : [{ pieces: a.value.pieces, folded: a.value.folded }];
803
- return words.flatMap((w) => {
985
+ return joinFloors(...words.map((w) => {
804
986
  const v = w.tail === true ? "unknown" : readValue(w, true, overlay);
805
987
  if (v !== "unknown")
806
- return v.map(floorOf);
988
+ return { values: v.map(floorOf), pastBound: false };
807
989
  const text = w.pieces.some((q) => q.expansion?.kind === "tilde") ? w.folded : literalTildeSpelling(w.folded);
808
- return [w.pieces.some((q) => q.expansion?.kind === "glob") ? { spelled: text, glob: true } : { spelled: text }];
809
- });
990
+ const written = { values: [w.pieces.some((q) => q.expansion?.kind === "glob") ? { spelled: text, glob: true } : { spelled: text }], pastBound: false };
991
+ return w.tail === true ? written : joinFloors(readFloor(w, overlay, floors), written);
992
+ }));
993
+ }
994
+ function storesValueWord(a) {
995
+ return a.op === "=" && a.subscript === undefined && a.form === "scalar" && a.value.unresolved === undefined;
810
996
  }
811
997
  function assignedState(a, readValue, overlay) {
812
- if (a.op !== "=" || a.subscript !== undefined || a.form !== "scalar" || a.value.unresolved !== undefined)
998
+ if (!storesValueWord(a))
813
999
  return "unknown";
814
1000
  return readValue({ pieces: a.value.pieces }, true, overlay);
815
1001
  }
1002
+ function assignedFloor(a, readFloor, overlay, floors) {
1003
+ if (!storesValueWord(a))
1004
+ return undefined;
1005
+ const floor = readFloor({ pieces: a.value.pieces }, overlay, floors);
1006
+ return isEmptyFloor(floor) ? undefined : floor;
1007
+ }
1008
+ const joinsValues = (p) => p.expansion?.kind === "parameter" && (p.expansion.name === "@" || p.expansion.name === "*" || /^!?[@*]|\[[@*]\]|^![^}]*[@*]$/.test(p.expansion.body ?? ""));
1009
+ const wordSource = (word) => ({ words: [word], made: ([text]) => text });
1010
+ const combinations = (lists) => lists.reduce((acc, l) => acc.flatMap((c) => l.map((x) => [...c, x])), [[]]);
1011
+ export function sourcedFloor(bound, spellingsOf) {
1012
+ const values = [];
1013
+ let pastBound = false;
1014
+ const cut = (text, as, piece) => void values.push(...as(text).map((spelled) => (piece ? { spelled, piece } : { spelled })));
1015
+ for (const source of bound.sources) {
1016
+ const words = source.words.map(spellingsOf);
1017
+ pastBound ||= words.some((w) => w.pastBound);
1018
+ const count = words.reduce((n, w) => n * w.values.length, 1);
1019
+ const joins = source.words.some((w) => w.pieces.some(joinsValues));
1020
+ const made = !joins && count > 0 && count <= WORD_VALUES_MAX ? combinations(words.map((w) => w.values)).map((vs) => ({ text: source.made(vs.map((v) => v.spelled)), piece: vs.some((v) => v.piece === true) })) : [];
1021
+ for (const t of made)
1022
+ if (t.text !== undefined)
1023
+ cut(t.text, bound.cut, t.piece);
1024
+ if (made.length === 0 || made.some((t) => t.text === undefined) || source.words.some((w) => w.pieces.some(transformsValue))) {
1025
+ pastBound ||= count > WORD_VALUES_MAX;
1026
+ for (const w of words)
1027
+ for (const v of w.values)
1028
+ cut(v.spelled, bound.piece ?? bound.cut, v.piece === true);
1029
+ }
1030
+ }
1031
+ return { values: distinctSpellings(values), pastBound: pastBound || (bound.loose === true && values.length > 0) };
1032
+ }
1033
+ function builtinOptions(args, valued, switches) {
1034
+ const options = new Map();
1035
+ const words = new Map();
1036
+ const set = (letter, value) => {
1037
+ options.delete(letter);
1038
+ options.set(letter, value);
1039
+ };
1040
+ let settled = true;
1041
+ let i = 0;
1042
+ for (; i < args.length; i++) {
1043
+ const text = literalTextOf(args[i].pieces);
1044
+ if (text === undefined) {
1045
+ settled = false;
1046
+ continue;
1047
+ }
1048
+ if (text === "--") {
1049
+ i++;
1050
+ break;
1051
+ }
1052
+ if (!text.startsWith("-") || text === "-")
1053
+ break;
1054
+ for (let j = 1; j < text.length; j++) {
1055
+ const letter = text[j];
1056
+ if (valued.includes(letter)) {
1057
+ const attached = j + 1 < text.length;
1058
+ const word = attached ? args[i] : args[++i];
1059
+ const value = attached ? text.slice(j + 1) : word === undefined ? undefined : literalTextOf(word.pieces);
1060
+ if (value === undefined)
1061
+ settled = false;
1062
+ set(letter, value);
1063
+ if (word !== undefined)
1064
+ words.set(letter, attached ? { words: [word], made: ([t]) => t?.slice(j + 1) } : wordSource(word));
1065
+ break;
1066
+ }
1067
+ if (!switches.includes(letter))
1068
+ settled = false;
1069
+ set(letter, "");
1070
+ }
1071
+ }
1072
+ return { options, words, operands: args.slice(i), settled };
1073
+ }
1074
+ const descriptorOf = (value) => (value !== undefined && /^\d+$/.test(value) ? Number(value) : undefined);
1075
+ const delimiterOf = (options) => (!options.has("d") ? "\n" : options.get("d") === undefined ? undefined : options.get("d").slice(0, 1) || "\0");
1076
+ const IFS_DEFAULT = " \t\n";
1077
+ const plainChars = (text) => [...text].map((c) => ({ c, escaped: false }));
1078
+ function readRecords(text, delimiter, raw) {
1079
+ const records = [[]];
1080
+ for (let i = 0; i < text.length; i++) {
1081
+ const c = text[i];
1082
+ if (!raw && c === "\\" && i + 1 < text.length) {
1083
+ if (text[++i] !== "\n")
1084
+ records.at(-1).push({ c: text[i], escaped: true });
1085
+ continue;
1086
+ }
1087
+ if (c === delimiter)
1088
+ records.push([]);
1089
+ else
1090
+ records.at(-1).push({ c, escaped: false });
1091
+ }
1092
+ if (records.length > 1 && records.at(-1).length === 0)
1093
+ records.pop();
1094
+ return records;
1095
+ }
1096
+ const textOf = (chars) => chars.map((x) => x.c).join("");
1097
+ function splitFields(record, ifs) {
1098
+ const white = (x) => x !== undefined && !x.escaped && ifs.includes(x.c) && IFS_DEFAULT.includes(x.c);
1099
+ const other = (x) => x !== undefined && !x.escaped && ifs.includes(x.c) && !IFS_DEFAULT.includes(x.c);
1100
+ let start = 0;
1101
+ let end = record.length;
1102
+ while (start < end && white(record[start]))
1103
+ start++;
1104
+ while (end > start && white(record[end - 1]))
1105
+ end--;
1106
+ const fields = [];
1107
+ const starts = [];
1108
+ for (let i = start; i < end;) {
1109
+ let j = i;
1110
+ while (j < end && !white(record[j]) && !other(record[j]))
1111
+ j++;
1112
+ fields.push(textOf(record.slice(i, j)));
1113
+ starts.push(i);
1114
+ while (j < end && white(record[j]))
1115
+ j++;
1116
+ if (j < end && other(record[j]))
1117
+ for (j++; j < end && white(record[j]);)
1118
+ j++;
1119
+ i = j;
1120
+ }
1121
+ return { fields, rest: (k) => (k < starts.length ? textOf(record.slice(starts[k], end)) : "") };
1122
+ }
1123
+ const restsOf = (split) => Array.from({ length: Math.min(split.fields.length, WORD_VALUES_MAX + 1) }, (_, k) => split.rest(k));
1124
+ const nameField = (split, k, count) => (k < count - 1 || split.fields.length - k <= 1 ? split.fields[k] ?? "" : split.rest(k));
1125
+ function readSources(args, input, byLoop, ifs) {
1126
+ const { options, operands, settled } = builtinOptions(args, "adinNptu", "Eers");
1127
+ const operandNames = operands.flatMap((w) => { const name = nameIn(literalTextOf(w.pieces) ?? ""); return name === undefined ? [] : [name]; });
1128
+ const elements = new Set(operands.flatMap((w) => { const text = literalTextOf(w.pieces) ?? ""; const name = nameIn(text); return name !== undefined && name !== text ? [name] : []; }));
1129
+ const array = options.has("a") ? nameIn(options.get("a") ?? "") : undefined;
1130
+ const names = options.has("a") ? [] : operandNames.length > 0 ? operandNames : ["REPLY"];
1131
+ const bound = [...names, ...(array !== undefined ? [array] : [])];
1132
+ const counter = [...options.keys()].filter((k) => k === "n" || k === "N").at(-1);
1133
+ const count = counter !== undefined && /^\d+$/.test(options.get(counter) ?? "") ? Number(options.get(counter)) : undefined;
1134
+ const delimiter = counter === "N" ? undefined : delimiterOf(options);
1135
+ const exact = settled && ifs !== undefined && (delimiter !== undefined || counter === "N");
1136
+ const readsNothing = /^(0+(\.0*)?|\.0+)$/.test(options.get("t") ?? "");
1137
+ const chunks = (record) => (count === undefined || count === 0 ? [record] : Array.from({ length: byLoop ? Math.max(1, Math.ceil(record.length / count)) : 1 }, (_, k) => record.slice(k * count, (k + 1) * count)));
1138
+ const cuts = (text) => {
1139
+ const out = new Map();
1140
+ if (readsNothing)
1141
+ return out;
1142
+ const add = (name, ...xs) => {
1143
+ out.set(name, [...(out.get(name) ?? []), ...xs]);
1144
+ };
1145
+ const records = readRecords(text, delimiter, options.has("r"));
1146
+ for (const record of (byLoop ? records : records.slice(0, 1)).flatMap(chunks)) {
1147
+ if (counter === "N") {
1148
+ add(bound[0], textOf(record));
1149
+ continue;
1150
+ }
1151
+ if (!exact) {
1152
+ const split = splitFields(record, IFS_DEFAULT);
1153
+ for (const name of bound)
1154
+ add(name, textOf(record), ...split.fields, ...restsOf(split));
1155
+ continue;
1156
+ }
1157
+ const split = splitFields(record, ifs);
1158
+ if (array !== undefined)
1159
+ add(array, ...split.fields);
1160
+ const held = new Map(names.map((name, k) => [name, operandNames.length === 0 ? textOf(record) : nameField(split, k, names.length)]));
1161
+ for (const [name, value] of held)
1162
+ add(name, value);
1163
+ }
1164
+ return out;
1165
+ };
1166
+ const piece = (text) => (readsNothing ? [] : readRecords(text, delimiter, options.has("r")).flatMap((r) => { const split = splitFields(r, ifs ?? IFS_DEFAULT); return [textOf(r), ...split.fields, ...restsOf(split)]; }));
1167
+ const sources = sourcesOf(input(options.has("u") ? descriptorOf(options.get("u")) : 0));
1168
+ const loose = !exact && counter !== "N" && (bound.length > 1 || array !== undefined) ? { loose: true } : {};
1169
+ return bound.map((name) => ({ name, sources, cut: (text) => cuts(text).get(name) ?? [], piece, ...loose, ...(elements.has(name) ? { keeps: true } : {}) }));
1170
+ }
1171
+ function lineSources(args, input) {
1172
+ const { options, operands } = builtinOptions(args, "dnOsuCc", "t");
1173
+ const name = operands.length === 0 ? "MAPFILE" : nameIn(literalTextOf(operands[0].pieces) ?? "");
1174
+ if (name === undefined)
1175
+ return [];
1176
+ const delimiter = delimiterOf(options);
1177
+ const countOf = (letter) => (/^\d+$/.test(options.get(letter) ?? "") ? Number(options.get(letter)) : undefined);
1178
+ const skip = countOf("s") ?? 0;
1179
+ const keep = countOf("n") || Number.POSITIVE_INFINITY;
1180
+ const records = (text, from, count) => readRecords(text, delimiter ?? "\n", true).slice(from, from + count).flatMap((r) => (options.has("t") || delimiter === undefined ? [textOf(r)] : [textOf(r), `${textOf(r)}${delimiter}`]));
1181
+ const piece = (text) => records(text, 0, Number.POSITIVE_INFINITY);
1182
+ return [{ name, sources: sourcesOf(input(options.has("u") ? descriptorOf(options.get("u")) : 0)), cut: (text) => records(text, skip, keep), piece, keeps: true }];
1183
+ }
1184
+ const sourcesOf = (texts) => texts.flatMap((t) => (t.source !== undefined ? [t.source] : t.literal !== undefined ? [{ words: [], made: () => t.literal }] : []));
1185
+ function getoptsSources(operands) {
1186
+ const [optstring, nameWord, ...rest] = operands;
1187
+ const name = nameWord === undefined ? undefined : nameIn(literalTextOf(nameWord.pieces) ?? "");
1188
+ if (optstring === undefined)
1189
+ return [];
1190
+ const values = (joined) => {
1191
+ const [spec = "", ...args] = joined.split("\0");
1192
+ const takes = new Set([...spec.replace(/^:/, "").matchAll(/(\w)(?=:)/g)].map((m) => m[1]));
1193
+ return args.flatMap((arg, k) => {
1194
+ if (!/^-[^-]/.test(arg))
1195
+ return [];
1196
+ const at = [...arg.slice(1)].findIndex((c) => takes.has(c));
1197
+ return at < 0 ? [] : at + 2 < arg.length ? [arg.slice(at + 2)] : args[k + 1] !== undefined ? [args[k + 1]] : [];
1198
+ });
1199
+ };
1200
+ const suffixes = (t) => [t, ...(t.startsWith("-") ? Array.from({ length: Math.max(0, t.length - 2) }, (_, k) => t.slice(k + 2)) : [])];
1201
+ const words = { words: [optstring, ...rest], made: (texts) => (texts.some((t) => t === undefined) ? undefined : texts.join("\0")) };
1202
+ return [
1203
+ { name: "OPTARG", sources: rest.length > 0 ? [words] : [], cut: values, piece: suffixes },
1204
+ ...(name !== undefined ? [{ name, sources: [wordSource(optstring)], cut: (t) => [...t.replace(/:/g, ""), "?"] }] : []),
1205
+ ];
1206
+ }
1207
+ function aliasSources(args) {
1208
+ const values = args.filter((w) => !/^-/.test(literalTextOf(w.pieces) ?? "")).map((w) => ({ words: [w], made: ([t]) => (t?.includes("=") === true ? t.slice(t.indexOf("=") + 1) : undefined) }));
1209
+ return values.length === 0 ? [] : [{ name: "BASH_ALIASES", sources: values, cut: (t) => [t], keeps: true }];
1210
+ }
1211
+ function hashSources(args) {
1212
+ const path = builtinOptions(args, "p", "rdlt").words.get("p");
1213
+ return path === undefined ? [] : [{ name: "BASH_CMDS", sources: [path], cut: (t) => [t], keeps: true }];
1214
+ }
1215
+ function compgenSources(args, ifs) {
1216
+ const { options, words } = builtinOptions(args, "oAGWPSXVFC", "abcdefgjksuv");
1217
+ const name = nameIn(options.get("V") ?? "");
1218
+ if (name === undefined)
1219
+ return [];
1220
+ const listed = words.get("W");
1221
+ const loose = ifs === undefined || options.has("P") || options.has("S") ? { loose: true } : {};
1222
+ return [{ name, sources: listed !== undefined ? [listed] : [], cut: (t) => splitFields(plainChars(t), ifs ?? IFS_DEFAULT).fields, ...loose, keeps: true }];
1223
+ }
1224
+ const SOURCED_BINDERS = {
1225
+ read: readSources, mapfile: lineSources, readarray: lineSources, getopts: getoptsSources, alias: aliasSources, hash: hashSources,
1226
+ compgen: (args, _input, _byLoop, ifs) => compgenSources(args, ifs),
1227
+ };
1228
+ function assignedBinding(a, readValue, readFloor, overlay, floors) {
1229
+ if (bindsArrayElement(a))
1230
+ return { state: "unknown", floor: arrayElementFloor(a, readValue, readFloor, overlay, floors), ...(a.subscript !== undefined || a.op === "+=" ? { keeps: true } : {}) };
1231
+ const state = assignedState(a, readValue, overlay);
1232
+ const floor = state === "unknown" ? assignedFloor(a, readFloor, overlay, floors) : undefined;
1233
+ return { state, ...(floor !== undefined ? { floor } : {}) };
1234
+ }
816
1235
  function assignedByPieces(pieces) {
817
1236
  const out = [];
818
1237
  for (const p of pieces) {
@@ -830,30 +1249,80 @@ export function arithmeticAssignedNames(text) {
830
1249
  const assigns = /(?:^|[^=!<>])=(?!=)|\+\+|--/.test(text);
831
1250
  return assigns ? [...new Set(text.match(/[A-Za-z_][A-Za-z0-9_]*/g) ?? [])] : [];
832
1251
  }
833
- export function namesBoundIn(text, depth = 0) {
834
- if (depth > 4)
835
- return "all";
1252
+ export function namesBoundIn(text) {
1253
+ const bound = bindingsIn(text);
1254
+ return bound === "all" ? "all" : new Set(bound.keys());
1255
+ }
1256
+ export function bindingsIn(text) {
836
1257
  const lexed = lexShell(text);
837
1258
  if ("parseFailure" in lexed)
838
1259
  return "all";
839
- const names = new Set();
840
- const nothing = () => "unknown";
1260
+ const bound = [];
1261
+ const literal = (w, quoted, overlay) => valueOf(w, undefined, quoted, overlay);
841
1262
  const projected = projectSegments(lexed.segments);
842
1263
  for (const [si, segment] of lexed.segments.entries()) {
843
1264
  const p = projected[si];
844
- const effect = bindingEffectOf(segment, p.argv, p, nothing);
1265
+ const effect = bindingEffectOf(segment, p.argv, p, literal);
845
1266
  if (effect.all === "unknown")
846
1267
  return "all";
847
- for (const b of effect.bindings)
848
- names.add(b.name);
1268
+ bound.push(...effect.bindings);
849
1269
  }
850
- return names;
1270
+ return bindingFloors(bound);
851
1271
  }
852
1272
  export function textBindsHome(text) {
853
1273
  const names = namesBoundIn(text);
854
1274
  return names === "all" || names.has("HOME");
855
1275
  }
856
1276
  const NOTHING_INHERITED = { attributes: [], references: false };
1277
+ const NO_FLOORS = new Map();
1278
+ class FloorsByName {
1279
+ names;
1280
+ read;
1281
+ constructor(names, read) {
1282
+ this.names = names;
1283
+ this.read = read;
1284
+ }
1285
+ get(name) {
1286
+ const floor = this.read(name);
1287
+ return isEmptyFloor(floor) ? undefined : floor;
1288
+ }
1289
+ has(name) {
1290
+ return this.get(name) !== undefined;
1291
+ }
1292
+ get size() {
1293
+ return this.all().size;
1294
+ }
1295
+ entries() {
1296
+ return this.all().entries();
1297
+ }
1298
+ keys() {
1299
+ return this.all().keys();
1300
+ }
1301
+ values() {
1302
+ return this.all().values();
1303
+ }
1304
+ forEach(each, thisArg) {
1305
+ for (const [name, floor] of this.all())
1306
+ each.call(thisArg, floor, name, this);
1307
+ }
1308
+ [Symbol.iterator]() {
1309
+ return this.all()[Symbol.iterator]();
1310
+ }
1311
+ all() {
1312
+ const out = new Map();
1313
+ for (const name of this.names()) {
1314
+ if (out.has(name))
1315
+ continue;
1316
+ const floor = this.get(name);
1317
+ if (floor !== undefined)
1318
+ out.set(name, floor);
1319
+ }
1320
+ return out;
1321
+ }
1322
+ }
1323
+ export function joinedFloors(...sets) {
1324
+ return new FloorsByName(() => sets.flatMap((s) => [...(s?.keys() ?? [])]), (name) => joinFloors(...sets.map((s) => s?.get(name) ?? NO_FLOOR)));
1325
+ }
857
1326
  export function joinRebound(a, b) {
858
1327
  if (a === "all" || b === "all")
859
1328
  return "all";
@@ -875,7 +1344,7 @@ export class BindingThread {
875
1344
  ownSubshell;
876
1345
  startFloors;
877
1346
  startRebound;
878
- bodyRuns = { limit: -1, environment: [] };
1347
+ bodyRuns = { limit: -1, environment: [], points: [] };
879
1348
  constructor(segments, named, initial, boundAnywhere, loops, homeStartsTouched = false, inherited = NOTHING_INHERITED, inheritedFunctions) {
880
1349
  this.segments = segments;
881
1350
  this.named = named;
@@ -884,7 +1353,7 @@ export class BindingThread {
884
1353
  this.loops = loops;
885
1354
  this.homeStartsTouched = homeStartsTouched;
886
1355
  this.inheritedFunctions = inheritedFunctions;
887
- this.startFloors = inherited.floors ?? new Map();
1356
+ this.startFloors = inherited.floors ?? NO_FLOORS;
888
1357
  this.startRebound = inherited.rebound ?? new Set();
889
1358
  this.blocks = blockStructure(segments);
890
1359
  this.ownSubshell = segments.map((_, i) => segments[i + 1]?.connector === "|" || segments[i + 1]?.connector === "&");
@@ -894,10 +1363,10 @@ export class BindingThread {
894
1363
  inheritedAt(j) {
895
1364
  const holds = (at) => j === undefined || this.mayRunBefore(at, j);
896
1365
  const reaches = (e) => j === undefined || (this.mayRunBefore(e.at, j) && this.visible(e, j));
897
- const floors = new Map(this.startFloors);
1366
+ const own = new Map();
898
1367
  for (const e of this.entries)
899
- if (e.name !== undefined && e.floor !== undefined && (j === undefined || e.at < j))
900
- floors.set(e.name, [...(floors.get(e.name) ?? []), ...e.floor]);
1368
+ if (e.name !== undefined && e.floor !== undefined && (j === undefined || (e.at < j && this.inShellOf(e, j))))
1369
+ own.set(e.name, joinFloors(own.get(e.name) ?? NO_FLOOR, e.floor));
901
1370
  let rebound = this.startRebound;
902
1371
  for (const e of this.entries)
903
1372
  if (e.state !== "reset" && reaches(e))
@@ -909,7 +1378,7 @@ export class BindingThread {
909
1378
  return {
910
1379
  attributes: this.attributesAt.filter((x) => holds(x.at)).map(({ name, kind }) => (name !== undefined ? { name, kind } : { kind })),
911
1380
  references: this.unreadable.some((u) => u.name === undefined && u.body === undefined && holds(u.at)),
912
- ...(floors.size > 0 ? { floors } : {}),
1381
+ ...(own.size > 0 || this.startFloors !== NO_FLOORS ? { floors: own.size === 0 ? this.startFloors : joinedFloors(this.startFloors, own) } : {}),
913
1382
  rebound,
914
1383
  };
915
1384
  }
@@ -952,7 +1421,7 @@ export class BindingThread {
952
1421
  if (head <= si && si < end)
953
1422
  limit = Math.max(limit, end);
954
1423
  });
955
- this.bodyRuns = { limit, environment };
1424
+ this.bodyRuns = { limit, environment, points: runs.flatMap((r, si) => (r ? [si] : [])) };
956
1425
  const calling = new Set(runs.flatMap((r, si) => (r && this.blocks[si].body !== undefined ? [this.blocks[si].body.id] : [])));
957
1426
  this.named.forEach((effect, at) => {
958
1427
  for (const b of effect.bindings) {
@@ -981,6 +1450,15 @@ export class BindingThread {
981
1450
  }
982
1451
  return out;
983
1452
  }
1453
+ callEnvironmentValues(c, name, there) {
1454
+ const environment = this.bodyRuns.environment[c];
1455
+ if (environment === undefined || environment === "all" || !environment.has(name))
1456
+ return undefined;
1457
+ const argv = argvOf(this.segments[c]);
1458
+ const words = argv.slice(0, readProgramPosition(argv).program?.index ?? argv.length);
1459
+ const a = words.findLast((w) => w.assignment?.bare === true && w.assignment.name === name)?.assignment;
1460
+ return a === undefined ? undefined : assignedFloor(a, floorReaderOf(there), new Map(), new Map());
1461
+ }
984
1462
  ownSubshellAt(at, standing) {
985
1463
  return this.ownSubshell[at] === true && standing.depth >= this.blocks[at].after;
986
1464
  }
@@ -991,9 +1469,12 @@ export class BindingThread {
991
1469
  const reader = j === undefined ? undefined : this.blocks[j];
992
1470
  if (e.standing.body !== undefined && reader?.body?.id !== e.standing.body.id)
993
1471
  return false;
1472
+ return this.inShellOf(e, j);
1473
+ }
1474
+ inShellOf(e, j) {
994
1475
  if (j !== e.at && this.ownSubshellAt(e.at, e.standing))
995
1476
  return false;
996
- const around = reader?.subshells ?? [];
1477
+ const around = j === undefined ? [] : this.blocks[j].subshells;
997
1478
  return e.standing.subshells.every((id) => around.includes(id));
998
1479
  }
999
1480
  standingOf(at, name) {
@@ -1002,11 +1483,16 @@ export class BindingThread {
1002
1483
  return head?.standing ?? { ...(own.body !== undefined ? { body: own.body } : {}), subshells: own.subshells, depth: own.words };
1003
1484
  }
1004
1485
  functionBound() {
1005
- const out = new Set();
1486
+ const bound = this.functionBindings();
1487
+ return bound === "all" ? "all" : new Set(bound.keys());
1488
+ }
1489
+ functionBindings() {
1006
1490
  if (this.inheritedFunctions?.bound === "all")
1007
1491
  return "all";
1492
+ const out = new Map();
1493
+ const add = (name, floor) => { out.set(name, joinFloors(out.get(name) ?? NO_FLOOR, floor)); };
1008
1494
  for (const name of this.inheritedFunctions?.bound ?? [])
1009
- out.add(name);
1495
+ add(name, NO_FLOOR);
1010
1496
  for (let at = 0; at < this.named.length; at++) {
1011
1497
  const effect = this.named[at];
1012
1498
  if (this.blocks[at].body !== undefined && (effect.all === "unknown" || effect.references === true))
@@ -1014,26 +1500,11 @@ export class BindingThread {
1014
1500
  for (const b of effect.bindings) {
1015
1501
  const own = this.bodyBinding(b, at);
1016
1502
  if (own !== undefined && (b.scope === "unread" || !this.declaredLocal(b.name, at, own)))
1017
- out.add(b.name);
1503
+ add(b.name, bindingValues(b));
1018
1504
  }
1019
1505
  }
1020
1506
  return out;
1021
1507
  }
1022
- functionMaybeBound() {
1023
- const maybe = new Set();
1024
- const certain = new Set();
1025
- for (let at = 0; at < this.named.length; at++) {
1026
- const effect = this.named[at];
1027
- for (const b of effect.bindings) {
1028
- if (this.bodyBinding(b, at) === undefined || this.declaredLocal(b.name, at, this.bodyBinding(b, at)))
1029
- continue;
1030
- (b.prefix === true || this.segments[at].spliced === true ? maybe : certain).add(b.name);
1031
- }
1032
- }
1033
- for (const name of certain)
1034
- maybe.delete(name);
1035
- return maybe;
1036
- }
1037
1508
  bodyBinding(b, at) {
1038
1509
  const own = this.standingOf(at, b.name).body;
1039
1510
  return own !== undefined && b.scope !== "local" ? own : undefined;
@@ -1045,9 +1516,7 @@ export class BindingThread {
1045
1516
  const reader = j === undefined ? undefined : this.blocks[j];
1046
1517
  if (s.body !== undefined && !(reader?.within ?? []).includes(s.body.id))
1047
1518
  return false;
1048
- if (j !== at && this.ownSubshellAt(at, s))
1049
- return false;
1050
- return s.subshells.every((id) => (reader?.subshells ?? []).includes(id));
1519
+ return this.inShellOf({ at, standing: s }, j);
1051
1520
  }
1052
1521
  inFunctionBody(at) {
1053
1522
  return this.blocks[at].body !== undefined;
@@ -1103,11 +1572,12 @@ export class BindingThread {
1103
1572
  this.entries.push({ at, standing: this.standingOf(at), state: effect.all === "reset" ? "reset" : "unknown", detached: spliced || effect.all === "unknown", andRun: false });
1104
1573
  for (const b of effect.bindings) {
1105
1574
  const standing = this.standingOf(at, b.name);
1106
- const detached = this.detachedAt(at, standing) || b.prefix === true || spliced;
1575
+ const detached = this.detachedAt(at, standing) || b.prefix === true || b.keeps === true || spliced;
1107
1576
  this.entries.push({
1108
1577
  at, standing, name: b.name, state: refused ? "unknown" : b.state, detached, andRun,
1109
1578
  ...(b.loopVar === true && loopEnd !== undefined ? { certainUntil: loopEnd } : {}),
1110
- ...(b.floor !== undefined && b.floor.length > 0 ? { floor: b.floor } : {}),
1579
+ ...(b.floor !== undefined && !isEmptyFloor(b.floor) ? { floor: b.floor } : {}),
1580
+ ...(b.array !== undefined && !refused ? { array: b.array } : {}),
1111
1581
  });
1112
1582
  if (b.scope === "local" && body !== undefined && !refused && !detached && !andRun)
1113
1583
  this.localDeclarations.push({ at, name: b.name, body: body.id, standing });
@@ -1119,16 +1589,22 @@ export class BindingThread {
1119
1589
  const readerBody = this.blocks[j].body;
1120
1590
  return readerBody !== undefined && readerBody.id !== u.body.id;
1121
1591
  }
1122
- kill(at, names, spliced = false) {
1592
+ kill(at, names, carried = new Map()) {
1123
1593
  const standing = this.standingOf(at);
1124
- if (names === "all") {
1125
- this.entries.push({ at, standing, state: "unknown", detached: spliced, andRun: false });
1594
+ const entry = (name) => {
1595
+ const floor = carried.get(name) ?? NO_FLOOR;
1596
+ return { at, standing, name, state: "unknown", detached: true, andRun: false, ...(!isEmptyFloor(floor) ? { floor } : {}) };
1597
+ };
1598
+ if (names !== "all") {
1599
+ for (const name of names)
1600
+ this.entries.push(entry(name));
1126
1601
  return;
1127
1602
  }
1128
- for (const name of names)
1129
- this.entries.push({ at, standing, name, state: "unknown", detached: spliced, andRun: false });
1603
+ this.entries.push({ at, standing, state: "unknown", detached: true, andRun: false });
1604
+ for (const name of carried.keys())
1605
+ this.entries.push(entry(name));
1130
1606
  }
1131
- tableAt(j, andRunStart, where) {
1607
+ tableAt(j, andRunStart, where, asked) {
1132
1608
  const certain = (e) => {
1133
1609
  if (e.certainUntil !== undefined && j < e.certainUntil)
1134
1610
  return true;
@@ -1139,13 +1615,14 @@ export class BindingThread {
1139
1615
  const readerBody = this.blocks[j].body;
1140
1616
  const lost = (u) => this.lostAt(u, j);
1141
1617
  const before = (e) => (e.at < j || (e.at === j && e.state === "reset")) && this.visible(e, j);
1142
- const given = (name, at, integer) => this.attributesAt.some((x) => (x.name === undefined || x.name === name) && (integer !== true || x.kind === "integer") && x.at !== at && this.mayRunBefore(x.at, at));
1618
+ const given = (name, at, kind) => this.attributesAt.some((x) => (x.name === undefined || x.name === name) && (kind === undefined || x.kind === kind) && x.at !== at && this.mayRunBefore(x.at, at));
1619
+ const opensReaderBody = (e) => readerBody !== undefined && e.at === this.blocks.findIndex((b) => b.body?.id === readerBody.id);
1143
1620
  const walk = (name, start) => {
1144
1621
  const values = [];
1145
1622
  const add = (vs) => { for (const v of vs)
1146
1623
  if (!values.some((x) => sameValue(x, v)))
1147
1624
  values.push(v); };
1148
- let unknownMayNotHaveRun = false;
1625
+ let unspelled = false;
1149
1626
  for (let i = this.entries.length - 1; i >= 0; i--) {
1150
1627
  const e = this.entries[i];
1151
1628
  if (!before(e) || (e.name !== undefined && !speaksFor(e.name, name)))
@@ -1154,48 +1631,81 @@ export class BindingThread {
1154
1631
  continue;
1155
1632
  const state = e.state === "reset" ? ((name === "HOME" && this.boundAnywhere("HOME")) || this.bindsInText(name) ? "unknown" : this.initial(name)) : e.state;
1156
1633
  if (state === "unknown") {
1157
- if (certain(e))
1158
- return { state: "unknown", values };
1159
- unknownMayNotHaveRun = true;
1634
+ const refusedByFrozen = e.name !== undefined && given(e.name, e.at, "frozen");
1635
+ if (certain(e) && !refusedByFrozen)
1636
+ return { state: "unknown", values, ...(e.state === "reset" && opensReaderBody(e) ? { entered: true } : {}) };
1637
+ unspelled = true;
1160
1638
  continue;
1161
1639
  }
1162
- if (e.name !== undefined && given(e.name, e.at))
1163
- return { state: "unknown", values };
1164
1640
  add(state);
1641
+ if (e.name !== undefined && given(e.name, e.at)) {
1642
+ if (!given(e.name, e.at, "frozen"))
1643
+ return { state: "unknown", values };
1644
+ unspelled = true;
1645
+ continue;
1646
+ }
1165
1647
  if (certain(e))
1166
- return unknownMayNotHaveRun ? { state: "unknown", values } : { state: values, decided: e, values };
1648
+ return unspelled ? { state: "unknown", values } : { state: values, decided: e, values };
1167
1649
  }
1168
1650
  if (start !== "unknown")
1169
1651
  add(start);
1170
- if (start === "unknown" || unknownMayNotHaveRun)
1652
+ if (start === "unknown" || unspelled)
1171
1653
  return { state: "unknown", values };
1172
1654
  return { state: values, values };
1173
1655
  };
1174
1656
  const later = this.boundLater(j);
1175
1657
  const boundLater = (name) => later === "all" || later.has(name) || (isBuiltinKey(name) && later.has(BUILTINS_ALL));
1658
+ const atCalls = (name, calls) => {
1659
+ if (readerBody === undefined)
1660
+ return NO_FLOOR;
1661
+ const read = calls.get(name) ?? new Set();
1662
+ calls.set(name, read);
1663
+ return joinFloors(...this.bodyRuns.points.filter((c) => this.mayRunBefore(j, c)).map((c) => {
1664
+ if (read.has(c))
1665
+ return NO_FLOOR;
1666
+ read.add(c);
1667
+ const there = this.tableAt(c, c, undefined, calls);
1668
+ const set = this.callEnvironmentValues(c, name, there);
1669
+ if (set !== undefined)
1670
+ return set;
1671
+ const floor = there.floorOf(name);
1672
+ const held = there.stateOf(name);
1673
+ return joinFloors({ values: held === "unknown" ? [] : held.map(floorOf), pastBound: false }, floor);
1674
+ }));
1675
+ };
1676
+ const unsettledName = (name) => shellKeepsName(name) || this.unreadable.some((u) => speaksFor(u.name, name) && lost(u));
1176
1677
  const readName = (name) => {
1177
- const unknown = (values = []) => ({ state: "unknown", floor: values.map((v) => ({ ...floorOf(v), held: true })) });
1178
- if (shellKeepsName(name))
1179
- return unknown();
1180
- if (this.unreadable.some((u) => speaksFor(u.name, name) && lost(u)))
1181
- return unknown();
1678
+ const unknown = (values = []) => ({ state: "unknown", floor: { values: values.map((v) => ({ ...floorOf(v), held: true })), pastBound: false } });
1182
1679
  if (!isWorkingDirectoryName(name)) {
1183
1680
  const walked = walk(name, this.startOf(name));
1184
1681
  const own = walked.decided !== undefined && walked.decided.state !== "reset" && readerBody !== undefined && walked.decided.standing.body?.id === readerBody.id;
1185
- return (boundLater(name) && !own) || walked.state === "unknown" ? unknown(walked.values) : { state: walked.state, floor: [] };
1682
+ if (unsettledName(name) || (boundLater(name) && !own) || walked.entered === true)
1683
+ return { state: "unknown", get floor() { return joinFloors(unknown(walked.values).floor, atCalls(name, asked ?? new Map())); } };
1684
+ return walked.state === "unknown" ? unknown(walked.values) : { state: walked.state, floor: NO_FLOOR };
1186
1685
  }
1187
1686
  const assigned = walk(name, []);
1188
- if (boundLater(name))
1687
+ if (unsettledName(name) || boundLater(name))
1189
1688
  return unknown(assigned.values);
1190
1689
  if (assigned.decided !== undefined && where !== undefined && readerBody === undefined && assigned.decided.at > where.movedAt)
1191
- return { state: assigned.state, floor: [] };
1690
+ return { state: assigned.state, floor: NO_FLOOR };
1192
1691
  const thread = readerBody === undefined ? where?.[name] ?? "unknown" : "unknown";
1193
1692
  if (thread === "unknown" || assigned.state === "unknown")
1194
1693
  return unknown(assigned.values);
1195
1694
  const held = assigned.state;
1196
- return { state: [...held, ...thread.filter((v) => !held.some((x) => sameValue(x, v)))], floor: [] };
1695
+ return { state: [...held, ...thread.filter((v) => !held.some((x) => sameValue(x, v)))], floor: NO_FLOOR };
1197
1696
  };
1198
1697
  const stateOf = (name) => readName(name).state;
1698
+ const arrayOf = (name) => {
1699
+ if (unsettledName(name) || isWorkingDirectoryName(name))
1700
+ return undefined;
1701
+ for (let i = this.entries.length - 1; i >= 0; i--) {
1702
+ const e = this.entries[i];
1703
+ if (!before(e) || (e.name !== undefined && !speaksFor(e.name, name)))
1704
+ continue;
1705
+ return e.array !== undefined && e.state !== "reset" && certain(e) && !given(name, e.at) ? e.array : undefined;
1706
+ }
1707
+ return undefined;
1708
+ };
1199
1709
  const touched = (name) => this.entries.some((e) => before(e) && (e.name === undefined || e.name === name));
1200
1710
  let rebound = this.startRebound;
1201
1711
  for (const e of this.entries)
@@ -1205,26 +1715,42 @@ export class BindingThread {
1205
1715
  if (lost(u))
1206
1716
  rebound = joinRebound(rebound, u.name === undefined ? "all" : [u.name]);
1207
1717
  const settled = joinRebound(rebound, later);
1208
- const floorsOf = (name) => [...this.entries.filter((e) => e.at < j && e.name === name).flatMap((e) => e.floor ?? []), ...readName(name).floor, ...(this.startFloors.get(name) ?? [])];
1718
+ const floorsRead = new Map();
1719
+ const floorsOf = (name) => {
1720
+ const seen = floorsRead.get(name);
1721
+ if (seen !== undefined && seen.entries === this.entries.length)
1722
+ return seen.floor;
1723
+ const own = this.entries.filter((e) => e.at < j && e.name === name && this.inShellOf(e, j)).map((e) => e.floor ?? NO_FLOOR);
1724
+ const floor = joinFloors(...own, readName(name).floor, this.startFloors.get(name) ?? NO_FLOOR);
1725
+ floorsRead.set(name, { entries: this.entries.length, floor });
1726
+ return floor;
1727
+ };
1209
1728
  let started;
1210
1729
  const nestedStart = () => {
1211
- if (started !== undefined)
1212
- return started;
1730
+ if (started !== undefined && started.entries === this.entries.length)
1731
+ return started.start;
1213
1732
  const start = this.inheritedAt(j);
1214
- const floors = new Map(start.floors ?? []);
1215
- let held = false;
1216
- for (const name of new Set(this.entries.flatMap((e) => (e.name !== undefined && before(e) && !isFunctionKey(e.name) && !isBuiltinKey(e.name) ? [e.name] : [])))) {
1733
+ const handed = readerBody === undefined ? [] : this.bodyRuns.points.flatMap((c) => { const environment = this.bodyRuns.environment[c]; return environment === undefined || environment === "all" ? [] : [...environment]; });
1734
+ const names = new Set([...this.entries.flatMap((e) => (e.name !== undefined && (before(e) || readerBody !== undefined) && !isFunctionKey(e.name) && !isBuiltinKey(e.name) ? [e.name] : [])), ...handed]);
1735
+ const read = new Map();
1736
+ const readFloor = (name) => {
1737
+ if (!names.has(name))
1738
+ return NO_FLOOR;
1739
+ const seen = read.get(name);
1740
+ if (seen !== undefined)
1741
+ return seen;
1217
1742
  const floor = readName(name).floor;
1218
- if (floor.length === 0)
1219
- continue;
1220
- floors.set(name, [...(floors.get(name) ?? []), ...floor]);
1221
- held = true;
1222
- }
1223
- return (started = held ? { ...start, floors } : start);
1743
+ read.set(name, floor);
1744
+ return floor;
1745
+ };
1746
+ const asked = new FloorsByName(() => names, readFloor);
1747
+ started = { entries: this.entries.length, start: names.size > 0 ? { ...start, floors: joinedFloors(start.floors, asked) } : start };
1748
+ return started.start;
1224
1749
  };
1225
1750
  return {
1226
1751
  stateOf,
1227
- isInteger: (name) => SHELL_INTEGER_VARIABLES.has(name) || given(name, j, true),
1752
+ arrayOf,
1753
+ isInteger: (name) => SHELL_INTEGER_VARIABLES.has(name) || given(name, j, "integer"),
1228
1754
  ifsTouched: touched("IFS") || boundLater("IFS"),
1229
1755
  homeTouched: this.homeStartsTouched || touched("HOME") || boundLater("HOME"),
1230
1756
  floorOf: floorsOf,
@@ -1271,8 +1797,10 @@ export function arithmeticSubstitutions(text, table, chain = new Set(), budget =
1271
1797
  if (chain.has(name))
1272
1798
  continue;
1273
1799
  const state = table.stateOf(name);
1274
- const values = state === "unknown" ? table.floorOf(name) : state;
1275
- for (const v of values)
1800
+ const floor = state === "unknown" ? table.floorOf(name) : { values: state, pastBound: false };
1801
+ if (floor.pastBound)
1802
+ out.push(text);
1803
+ for (const v of floor.values)
1276
1804
  out.push(...arithmeticSubstitutions(v.spelled, table, new Set([...chain, name]), budget));
1277
1805
  }
1278
1806
  }