@sema-agent/core 7.70.0 → 7.71.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 (439) hide show
  1. package/CHANGELOG.md +740 -0
  2. package/dist/agents/agent-transcript-tool.js +43 -19
  3. package/dist/agents/inherited-tool-pool.d.ts +5 -1
  4. package/dist/agents/inherited-tool-pool.js +6 -0
  5. package/dist/agents/retain-ledger.js +2 -0
  6. package/dist/agents/send-message-tool.d.ts +12 -1
  7. package/dist/agents/send-message-tool.js +47 -9
  8. package/dist/agents/subagent.js +31 -10
  9. package/dist/agents/tool-filter.js +1 -2
  10. package/dist/agents/verify.js +13 -2
  11. package/dist/agents/yield-adoption.js +11 -1
  12. package/dist/brain/claude-model-id.d.ts +11 -0
  13. package/dist/brain/claude-model-id.js +3 -1
  14. package/dist/config/catalog.js +10 -1
  15. package/dist/config/defaults.d.ts +3 -0
  16. package/dist/config/defaults.js +1 -0
  17. package/dist/core/allow-entry.js +1 -2
  18. package/dist/core/ask-origin.d.ts +55 -21
  19. package/dist/core/ask-origin.js +19 -11
  20. package/dist/core/ask-question.d.ts +4 -7
  21. package/dist/core/ask-question.js +2 -4
  22. package/dist/core/ask-unresolvable-notice.d.ts +17 -3
  23. package/dist/core/ask-unresolvable-notice.js +18 -4
  24. package/dist/core/attachment-source.d.ts +1 -1
  25. package/dist/core/attachment-source.js +2 -0
  26. package/dist/core/auto-compaction.d.ts +14 -4
  27. package/dist/core/auto-compaction.js +3 -2
  28. package/dist/core/auto-strip.js +2 -0
  29. package/dist/core/caller-text.d.ts +2 -33
  30. package/dist/core/caller-text.js +2 -23
  31. package/dist/core/caller-tool-name.js +1 -2
  32. package/dist/core/canonical-json.d.ts +9 -0
  33. package/dist/core/canonical-json.js +6 -0
  34. package/dist/core/checkpoint-features.d.ts +43 -80
  35. package/dist/core/checkpoint-features.js +10 -20
  36. package/dist/core/checkpoint-generation.d.ts +89 -19
  37. package/dist/core/checkpoint-generation.js +89 -14
  38. package/dist/core/checkpoint-queries.d.ts +95 -15
  39. package/dist/core/checkpoint-queries.js +108 -7
  40. package/dist/core/checkpoint-rekey.d.ts +2 -1
  41. package/dist/core/checkpoint-rekey.js +2 -2
  42. package/dist/core/checkpoint-requirements.d.ts +21 -7
  43. package/dist/core/checkpoint-requirements.js +2 -5
  44. package/dist/core/checkpoint-row-verdict.d.ts +3 -4
  45. package/dist/core/checkpoint-row-verdict.js +20 -41
  46. package/dist/core/checkpoint-store.d.ts +69 -41
  47. package/dist/core/checkpoint-store.js +28 -14
  48. package/dist/core/command-sandbox.d.ts +5 -3
  49. package/dist/core/command-sandbox.js +17 -9
  50. package/dist/core/config-refusal-codes.d.ts +1 -1
  51. package/dist/core/config-refusal-codes.js +1 -0
  52. package/dist/core/declaration-words.d.ts +2 -1
  53. package/dist/core/declaration-words.js +13 -2
  54. package/dist/core/effective-path-target.d.ts +23 -0
  55. package/dist/core/effective-path-target.js +15 -1
  56. package/dist/core/engine-attestation.d.ts +5 -1
  57. package/dist/core/engine-attestation.js +1 -0
  58. package/dist/core/engine-capabilities.d.ts +14 -9
  59. package/dist/core/engine-capabilities.js +1 -1
  60. package/dist/core/engine-notice.d.ts +62 -32
  61. package/dist/core/engine-version.js +1 -1
  62. package/dist/core/entries-not-applied.d.ts +1 -1
  63. package/dist/core/entries-not-applied.js +1 -0
  64. package/dist/core/file-history-store.d.ts +95 -11
  65. package/dist/core/file-history-store.js +117 -19
  66. package/dist/core/gate-fold.js +13 -7
  67. package/dist/core/gate-lanes.js +9 -9
  68. package/dist/core/governance-codes.d.ts +56 -7
  69. package/dist/core/governance-codes.js +105 -7
  70. package/dist/core/grant-holder.d.ts +53 -0
  71. package/dist/core/grant-holder.js +80 -0
  72. package/dist/core/hooks.d.ts +7 -3
  73. package/dist/core/hooks.js +2 -2
  74. package/dist/core/locked-config.d.ts +7 -1
  75. package/dist/core/locked-config.js +9 -2
  76. package/dist/core/mcp-call-meta.d.ts +52 -7
  77. package/dist/core/mcp-call-meta.js +21 -2
  78. package/dist/core/mcp-host-read.d.ts +1 -1
  79. package/dist/core/mcp-server-spec.d.ts +18 -0
  80. package/dist/core/mcp-server-spec.js +1 -0
  81. package/dist/core/mcp.js +2 -2
  82. package/dist/core/member-outcome.d.ts +22 -1
  83. package/dist/core/member-outcome.js +18 -6
  84. package/dist/core/memory-engine/delegation-settlement.js +5 -5
  85. package/dist/core/memory-engine/engine.js +19 -19
  86. package/dist/core/memory-engine/file-backend.d.ts +7 -2
  87. package/dist/core/memory-engine/file-backend.js +14 -12
  88. package/dist/core/memory-engine/frontmatter.js +1 -1
  89. package/dist/core/memory-engine/index.d.ts +1 -0
  90. package/dist/core/memory-engine/index.js +1 -0
  91. package/dist/core/memory-engine/layout.d.ts +34 -9
  92. package/dist/core/memory-engine/layout.js +36 -19
  93. package/dist/core/memory-engine/memory-deployment.js +8 -8
  94. package/dist/core/memory-engine/mount-failed-notice.d.ts +8 -5
  95. package/dist/core/memory-engine/mount-failed-notice.js +5 -2
  96. package/dist/core/mode-policy.d.ts +5 -0
  97. package/dist/core/mode-policy.js +6 -0
  98. package/dist/core/mods/host.d.ts +2 -1
  99. package/dist/core/mods/host.js +7 -6
  100. package/dist/core/mods/kernel/index.d.ts +1 -1
  101. package/dist/core/mods/kernel/index.js +1 -1
  102. package/dist/core/mods/kernel/registration.d.ts +5 -2
  103. package/dist/core/mods/kernel/registration.js +19 -3
  104. package/dist/core/mods/package.d.ts +12 -1
  105. package/dist/core/mods/package.js +36 -9
  106. package/dist/core/mods/stations.d.ts +7 -1
  107. package/dist/core/mods/stations.js +17 -3
  108. package/dist/core/mods/teammate-stations.d.ts +4 -1
  109. package/dist/core/mods/teammate-stations.js +1 -1
  110. package/dist/core/native-signal.d.ts +13 -0
  111. package/dist/core/native-signal.js +18 -0
  112. package/dist/core/park-resumability.d.ts +16 -14
  113. package/dist/core/park-resumability.js +9 -4
  114. package/dist/core/path-rule-binding.js +1 -1
  115. package/dist/core/permission-rule-model.d.ts +11 -5
  116. package/dist/core/permission-rule-model.js +5 -3
  117. package/dist/core/permission-rule-org.js +1 -1
  118. package/dist/core/permission-rule-provider.d.ts +5 -1
  119. package/dist/core/permission-rule-provider.js +6 -1
  120. package/dist/core/permission-rule-session.d.ts +35 -5
  121. package/dist/core/permission-rule-session.js +32 -1
  122. package/dist/core/permission-rule-store.d.ts +5 -1
  123. package/dist/core/permission-rule-store.js +28 -5
  124. package/dist/core/permission-rules.d.ts +2 -2
  125. package/dist/core/permission-rules.js +2 -3
  126. package/dist/core/principal-name.d.ts +12 -0
  127. package/dist/core/principal-name.js +6 -2
  128. package/dist/core/read-root-grant-screen.d.ts +7 -6
  129. package/dist/core/read-root-grant-screen.js +7 -8
  130. package/dist/core/remote-env.d.ts +42 -8
  131. package/dist/core/resume-config-judge.js +1 -1
  132. package/dist/core/resume-startup-cause.d.ts +19 -4
  133. package/dist/core/resume-startup-cause.js +25 -6
  134. package/dist/core/rewind-conversation.d.ts +4 -0
  135. package/dist/core/rewrite-rejudge.d.ts +9 -1
  136. package/dist/core/rewrite-rejudge.js +11 -1
  137. package/dist/core/rule-offer-read.js +3 -2
  138. package/dist/core/runner/assemble-result.d.ts +21 -11
  139. package/dist/core/runner/assemble-result.js +24 -4
  140. package/dist/core/runner/boundary-reminders.d.ts +104 -0
  141. package/dist/core/runner/boundary-reminders.js +108 -0
  142. package/dist/core/runner/branch-writeback.d.ts +21 -7
  143. package/dist/core/runner/branch-writeback.js +44 -6
  144. package/dist/core/runner/command-sandbox-frame.js +2 -1
  145. package/dist/core/runner/compact-session.js +11 -4
  146. package/dist/core/runner/constraint-layers.d.ts +24 -5
  147. package/dist/core/runner/constraint-layers.js +21 -2
  148. package/dist/core/runner/continuation-gate.js +3 -1
  149. package/dist/core/runner/contracts.d.ts +83 -13
  150. package/dist/core/runner/cross-boundary-lane.js +2 -1
  151. package/dist/core/runner/delegation-owner.d.ts +246 -45
  152. package/dist/core/runner/delegation-owner.js +237 -63
  153. package/dist/core/runner/expire-settle.d.ts +17 -0
  154. package/dist/core/runner/expire-settle.js +8 -2
  155. package/dist/core/runner/file-history-request.d.ts +4 -3
  156. package/dist/core/runner/file-history-request.js +4 -1
  157. package/dist/core/runner/file-history-restore.d.ts +11 -3
  158. package/dist/core/runner/file-history-restore.js +11 -3
  159. package/dist/core/runner/gate-exit.d.ts +22 -1
  160. package/dist/core/runner/gate-exit.js +12 -14
  161. package/dist/core/runner/nested-memory-content.js +1 -1
  162. package/dist/core/runner/nested-memory-lane.d.ts +10 -2
  163. package/dist/core/runner/nested-memory-lane.js +29 -8
  164. package/dist/core/runner/own-model-money-door.d.ts +13 -0
  165. package/dist/core/runner/own-model-money-door.js +17 -0
  166. package/dist/core/runner/park-commit.d.ts +4 -2
  167. package/dist/core/runner/park-commit.js +2 -1
  168. package/dist/core/runner/permission-rule-lanes.d.ts +4 -0
  169. package/dist/core/runner/permission-rule-lanes.js +7 -0
  170. package/dist/core/runner/person-path-rows.js +1 -1
  171. package/dist/core/runner/placement-fence.d.ts +8 -2
  172. package/dist/core/runner/placement-fence.js +8 -3
  173. package/dist/core/runner/policy-throw.d.ts +3 -2
  174. package/dist/core/runner/policy-throw.js +2 -2
  175. package/dist/core/runner/prepare-acquire-reconcile.d.ts +23 -14
  176. package/dist/core/runner/prepare-acquire-reconcile.js +33 -15
  177. package/dist/core/runner/prepare-artifact.d.ts +14 -1
  178. package/dist/core/runner/prepare-artifact.js +7 -2
  179. package/dist/core/runner/prepare-ask-lane.d.ts +8 -0
  180. package/dist/core/runner/prepare-ask-lane.js +14 -5
  181. package/dist/core/runner/prepare-boundary-parks.js +5 -4
  182. package/dist/core/runner/prepare-config-doors.d.ts +9 -4
  183. package/dist/core/runner/prepare-config-doors.js +25 -8
  184. package/dist/core/runner/prepare-defer-classify.d.ts +8 -4
  185. package/dist/core/runner/prepare-defer-classify.js +6 -6
  186. package/dist/core/runner/prepare-execution-env.d.ts +4 -1
  187. package/dist/core/runner/prepare-execution-env.js +8 -3
  188. package/dist/core/runner/prepare-file-history.d.ts +26 -0
  189. package/dist/core/runner/prepare-file-history.js +15 -1
  190. package/dist/core/runner/prepare-inherited-gate.d.ts +8 -3
  191. package/dist/core/runner/prepare-inherited-gate.js +9 -2
  192. package/dist/core/runner/prepare-leg-adoption.d.ts +2 -2
  193. package/dist/core/runner/prepare-park-ask.js +8 -5
  194. package/dist/core/runner/prepare-policy-chain.d.ts +5 -0
  195. package/dist/core/runner/prepare-policy-chain.js +18 -7
  196. package/dist/core/runner/prepare-prompt-assembly.d.ts +3 -0
  197. package/dist/core/runner/prepare-prompt-assembly.js +4 -3
  198. package/dist/core/runner/prepare-suspend-saga.d.ts +4 -1
  199. package/dist/core/runner/prepare-suspend-saga.js +19 -5
  200. package/dist/core/runner/prepare-task.d.ts +2 -5
  201. package/dist/core/runner/prepare-task.js +71 -26
  202. package/dist/core/runner/prepare-turn-wiring.js +7 -5
  203. package/dist/core/runner/prepare-workspace-restore.js +59 -28
  204. package/dist/core/runner/read-root-grant.d.ts +1 -0
  205. package/dist/core/runner/read-root-grant.js +1 -2
  206. package/dist/core/runner/resume-admission.d.ts +3 -0
  207. package/dist/core/runner/resume-admission.js +6 -4
  208. package/dist/core/runner/resume-apply.js +7 -5
  209. package/dist/core/runner/resume-claim.d.ts +2 -2
  210. package/dist/core/runner/resume-claim.js +4 -4
  211. package/dist/core/runner/resume-policy-outcome.d.ts +1 -1
  212. package/dist/core/runner/resume-policy-outcome.js +6 -4
  213. package/dist/core/runner/resume-preflight.d.ts +3 -0
  214. package/dist/core/runner/resume-preflight.js +10 -3
  215. package/dist/core/runner/rewind-conversation.js +11 -4
  216. package/dist/core/runner/rewind-files.js +29 -14
  217. package/dist/core/runner/rewind-outcome.d.ts +27 -0
  218. package/dist/core/runner/rewind-outcome.js +14 -0
  219. package/dist/core/runner/run-attachment-seats.js +2 -1
  220. package/dist/core/runner/run-clock-and-content.js +2 -0
  221. package/dist/core/runner/run-identity-wiring.js +2 -0
  222. package/dist/core/runner/run-leg.js +11 -1
  223. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  224. package/dist/core/runner/run-notification-lane.js +2 -2
  225. package/dist/core/runner/run-settle-and-teardown.d.ts +4 -2
  226. package/dist/core/runner/run-settle-and-teardown.js +52 -40
  227. package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
  228. package/dist/core/runner/run-stop-and-final-verify.js +5 -4
  229. package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
  230. package/dist/core/runner/run-terminal-adoption.js +3 -3
  231. package/dist/core/runner/run-turn-boundary.js +7 -0
  232. package/dist/core/runner/runtask.d.ts +7 -4
  233. package/dist/core/runner/runtask.js +18 -9
  234. package/dist/core/runner/session-call-grant-station.d.ts +64 -0
  235. package/dist/core/runner/session-call-grant-station.js +119 -0
  236. package/dist/core/runner/session-file-state-replay.js +2 -2
  237. package/dist/core/runner/session-prompt-seats.d.ts +95 -0
  238. package/dist/core/runner/session-prompt-seats.js +62 -0
  239. package/dist/core/runner/session-rule-policy.js +1 -1
  240. package/dist/core/runner/session-write-ledger.d.ts +8 -0
  241. package/dist/core/runner/session-write-ledger.js +16 -0
  242. package/dist/core/runner/side-call-account.js +5 -1
  243. package/dist/core/runner/stop-tail-notice.d.ts +7 -0
  244. package/dist/core/runner/stop-tail-notice.js +23 -8
  245. package/dist/core/runner/stream-reap.js +4 -2
  246. package/dist/core/runner/stream-settle-backstop.d.ts +1 -1
  247. package/dist/core/runner/stream-settle-backstop.js +17 -18
  248. package/dist/core/runner/terminal-account.js +17 -8
  249. package/dist/core/runner/terminal-projection.d.ts +3 -2
  250. package/dist/core/runner/terminal-projection.js +1 -1
  251. package/dist/core/runner/tool-turn-repair-seat.d.ts +2 -2
  252. package/dist/core/runner/tool-turn-repair-seat.js +12 -7
  253. package/dist/core/runner/turn-attachments.d.ts +22 -1
  254. package/dist/core/runner/turn-attachments.js +20 -3
  255. package/dist/core/runner-deps.d.ts +6 -2
  256. package/dist/core/secret-env.d.ts +26 -6
  257. package/dist/core/secret-env.js +6 -6
  258. package/dist/core/session-call-grant-screen.d.ts +58 -0
  259. package/dist/core/session-call-grant-screen.js +18 -0
  260. package/dist/core/session-call-grant.d.ts +93 -0
  261. package/dist/core/session-call-grant.js +524 -0
  262. package/dist/core/session-checkout.d.ts +3 -0
  263. package/dist/core/session-checkout.js +8 -3
  264. package/dist/core/session-policy-store.d.ts +14 -0
  265. package/dist/core/session-policy-store.js +16 -2
  266. package/dist/core/session-store.d.ts +18 -1
  267. package/dist/core/session-store.js +20 -4
  268. package/dist/core/session.d.ts +36 -4
  269. package/dist/core/shared-artifact-reads.d.ts +93 -0
  270. package/dist/core/shared-artifact-reads.js +94 -0
  271. package/dist/core/skill-grant.js +1 -1
  272. package/dist/core/skills-directory.d.ts +9 -45
  273. package/dist/core/skills-directory.js +9 -722
  274. package/dist/core/spend-account.js +3 -0
  275. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +22 -4
  276. package/dist/core/store-contracts/checkpoint-store-contract.js +363 -29
  277. package/dist/core/store-contracts/file-history-store-contract.d.ts +11 -3
  278. package/dist/core/store-contracts/file-history-store-contract.js +62 -2
  279. package/dist/core/store-contracts/grant-fixture.d.ts +52 -0
  280. package/dist/core/store-contracts/grant-fixture.js +84 -0
  281. package/dist/core/store-contracts/session-repo-contract.js +18 -0
  282. package/dist/core/store-contracts/session-store-contract.d.ts +15 -1
  283. package/dist/core/store-contracts/session-store-contract.js +211 -2
  284. package/dist/core/store-contracts/workflow-journal-store-contract.js +47 -8
  285. package/dist/core/suspend-lane-reasons.d.ts +13 -0
  286. package/dist/core/suspend-lane-reasons.js +5 -0
  287. package/dist/core/synthetic-read-verdict.d.ts +5 -3
  288. package/dist/core/synthetic-read-verdict.js +1 -1
  289. package/dist/core/task-limits.d.ts +15 -0
  290. package/dist/core/task-notification.d.ts +33 -7
  291. package/dist/core/task-notification.js +34 -9
  292. package/dist/core/task-registry-agent.d.ts +1 -1
  293. package/dist/core/task-registry-agent.js +18 -7
  294. package/dist/core/task-registry-shared.d.ts +29 -4
  295. package/dist/core/task-registry-shared.js +7 -0
  296. package/dist/core/task-registry.d.ts +21 -1
  297. package/dist/core/task-registry.js +36 -9
  298. package/dist/core/task-result.d.ts +55 -1
  299. package/dist/core/task-spec.d.ts +17 -3
  300. package/dist/core/terminal-cause.d.ts +68 -5
  301. package/dist/core/tool-catalog-entries.js +1 -1
  302. package/dist/core/tool-check-reading.js +2 -1
  303. package/dist/core/tool-errors.js +1 -0
  304. package/dist/core/tool-list-grammar.d.ts +0 -47
  305. package/dist/core/tool-list-grammar.js +1 -75
  306. package/dist/core/tool-model-gate.d.ts +7 -11
  307. package/dist/core/tool-model-gate.js +5 -8
  308. package/dist/core/tool-name-aliases.js +2 -3
  309. package/dist/core/tool-name-readings.d.ts +4 -0
  310. package/dist/core/tool-name-readings.js +1 -0
  311. package/dist/core/tool-policy.d.ts +46 -4
  312. package/dist/core/tool-policy.js +47 -18
  313. package/dist/core/tool-result-store.d.ts +0 -24
  314. package/dist/core/tool-result-store.js +1 -36
  315. package/dist/core/tool-spec.d.ts +8 -4
  316. package/dist/core/untrusted-egress.js +2 -2
  317. package/dist/core/untrusted-text.d.ts +8 -0
  318. package/dist/core/untrusted-text.js +14 -0
  319. package/dist/core/user-attachment.d.ts +16 -1
  320. package/dist/core/user-attachment.js +42 -18
  321. package/dist/core/wiring-manifest.d.ts +4 -9
  322. package/dist/core/wiring-manifest.js +1 -1
  323. package/dist/core/workflow-journal-store.d.ts +55 -8
  324. package/dist/core/workflow-journal-store.js +34 -10
  325. package/dist/core/workflow-run-store-contract.js +56 -1
  326. package/dist/core/workflow-run-store.d.ts +43 -19
  327. package/dist/core/workflow-run-store.js +17 -2
  328. package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
  329. package/dist/engine/execution-env/node-execution-env.js +4 -0
  330. package/dist/engine/harness/agent-harness.d.ts +10 -5
  331. package/dist/engine/harness/agent-harness.js +12 -4
  332. package/dist/engine/harness/types.d.ts +18 -0
  333. package/dist/engine/llm/tool-turns.d.ts +1 -1
  334. package/dist/engine/llm/types.d.ts +5 -4
  335. package/dist/engine/session/memory-repo.d.ts +15 -3
  336. package/dist/engine/session/memory-repo.js +21 -3
  337. package/dist/engine/session/memory-storage.d.ts +5 -0
  338. package/dist/engine/session/memory-storage.js +8 -3
  339. package/dist/engine/session/repo-utils.d.ts +9 -0
  340. package/dist/engine/session/repo-utils.js +14 -0
  341. package/dist/engine/session/storage-base.d.ts +20 -7
  342. package/dist/engine/session/storage-base.js +13 -1
  343. package/dist/index.d.ts +39 -21
  344. package/dist/index.js +32 -17
  345. package/dist/internal/harness.d.ts +1 -1
  346. package/dist/internal/harness.js +1 -1
  347. package/dist/orchestration/run-workflow-tool.d.ts +13 -1
  348. package/dist/orchestration/run-workflow-tool.js +101 -32
  349. package/dist/orchestration/workflow-park-adoption.d.ts +309 -92
  350. package/dist/orchestration/workflow-park-adoption.js +588 -323
  351. package/dist/orchestration/workflow-tree-id.d.ts +66 -0
  352. package/dist/orchestration/workflow-tree-id.js +66 -0
  353. package/dist/orchestration/workflow-types.d.ts +90 -11
  354. package/dist/orchestration/workflow-types.js +10 -1
  355. package/dist/orchestration/workflow.d.ts +30 -4
  356. package/dist/orchestration/workflow.js +424 -114
  357. package/dist/prompt-assembly/catalog/constitution.js +5 -1
  358. package/dist/prompt-assembly/catalog/core-behavior.d.ts +3 -4
  359. package/dist/prompt-assembly/catalog/core-behavior.js +61 -22
  360. package/dist/prompt-assembly/catalog/environment.js +2 -2
  361. package/dist/prompt-assembly/catalog/events.d.ts +16 -0
  362. package/dist/prompt-assembly/catalog/events.js +2 -0
  363. package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +72 -44
  364. package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.js +2 -2
  365. package/dist/prompt-assembly/catalog/locales/zh-Hans/events.js +2 -0
  366. package/dist/prompt-assembly/catalog/schema.d.ts +5 -1
  367. package/dist/prompt-assembly/catalog/schema.js +2 -0
  368. package/dist/prompt-assembly/catalog/sections.js +3 -14
  369. package/dist/prompt-assembly/event-registry.js +2 -0
  370. package/dist/prompt-assembly/select.js +1 -0
  371. package/dist/prompt-assembly/tool-catalog.d.ts +10 -7
  372. package/dist/prompt-assembly/tool-catalog.js +21 -7
  373. package/dist/prompt-assembly/types.d.ts +3 -0
  374. package/dist/prompts/default.d.ts +4 -1
  375. package/dist/prompts/default.js +6 -0
  376. package/dist/stores/file/checkpoint-store.d.ts +11 -10
  377. package/dist/stores/file/checkpoint-store.js +36 -10
  378. package/dist/stores/file/file-history-store.d.ts +6 -0
  379. package/dist/stores/file/file-history-store.js +21 -4
  380. package/dist/stores/file/fs-atomic.d.ts +1 -1
  381. package/dist/stores/file/index.d.ts +14 -4
  382. package/dist/stores/file/index.js +21 -5
  383. package/dist/stores/file/process-anchor.d.ts +9 -1
  384. package/dist/stores/file/session-policy-store.js +2 -17
  385. package/dist/stores/file/session-store.d.ts +27 -0
  386. package/dist/stores/file/session-store.js +81 -9
  387. package/dist/stores/file/workflow-journal-store.d.ts +14 -4
  388. package/dist/stores/file/workflow-journal-store.js +32 -24
  389. package/dist/stores/file/workflow-run-store.d.ts +15 -4
  390. package/dist/stores/file/workflow-run-store.js +76 -0
  391. package/dist/tools/artifact/artifact-tool.d.ts +10 -3
  392. package/dist/tools/artifact/artifact-tool.js +16 -1
  393. package/dist/tools/fs/bash-program-position.d.ts +10 -4
  394. package/dist/tools/fs/bash-program-position.js +11 -8
  395. package/dist/tools/fs/bash-readonly-classifier.d.ts +3 -1
  396. package/dist/tools/fs/bash-readonly-classifier.js +9 -2
  397. package/dist/tools/fs/find-actions.d.ts +30 -16
  398. package/dist/tools/fs/find-actions.js +272 -19
  399. package/dist/tools/fs/fs-bash.js +8 -5
  400. package/dist/tools/fs/fs-shared.d.ts +0 -29
  401. package/dist/tools/fs/fs-shared.js +0 -5
  402. package/dist/tools/fs/fs-write.js +2 -1
  403. package/dist/tools/fs/read-deny.d.ts +6 -1
  404. package/dist/tools/fs/read-deny.js +6 -1
  405. package/dist/tools/fs/read-floor.d.ts +6 -0
  406. package/dist/tools/fs/read-floor.js +5 -1
  407. package/dist/tools/fs/removal-actions.d.ts +43 -0
  408. package/dist/tools/fs/removal-actions.js +25 -0
  409. package/dist/tools/fs/removal-targets.d.ts +2 -21
  410. package/dist/tools/fs/removal-targets.js +2 -3
  411. package/dist/tools/fs/safety.d.ts +37 -1
  412. package/dist/tools/fs/safety.js +52 -0
  413. package/dist/tools/fs/shell-climb.d.ts +46 -0
  414. package/dist/tools/fs/shell-climb.js +79 -0
  415. package/dist/tools/fs/shell-read-check.js +47 -19
  416. package/dist/tools/fs/shell-read-establish.js +36 -22
  417. package/dist/tools/fs/shell-read-judge.d.ts +10 -2
  418. package/dist/tools/fs/shell-read-judge.js +4 -4
  419. package/dist/tools/fs/shell-read-plan.d.ts +3 -0
  420. package/dist/tools/fs/shell-read-plan.js +1 -1
  421. package/dist/tools/fs/shell-read-workdir.js +3 -2
  422. package/dist/tools/fs/shell-read-write-targets.d.ts +4 -3
  423. package/dist/tools/fs/shell-read-write-targets.js +3 -0
  424. package/package.json +2 -2
  425. package/test/export-surface.snapshot.json +173 -15
  426. package/wire-changes/core-stores-sql@7.71.0.json +40 -0
  427. package/wire-changes/core-stores-sql@7.71.1.json +40 -0
  428. package/wire-changes/core@7.71.0.json +5827 -0
  429. package/wire-changes/core@7.71.1.json +118 -0
  430. package/wire-changes/mods-kernel@7.71.0.json +52 -0
  431. package/wire-changes/mods-kernel@7.71.1.json +40 -0
  432. package/wire-changes/primitives@7.71.0.json +473 -0
  433. package/wire-changes/primitives@7.71.1.json +40 -0
  434. package/wire-changes/wiki-gate@7.71.0.json +40 -0
  435. package/wire-changes/wiki-gate@7.71.1.json +40 -0
  436. package/dist/core/frontmatter-fence.d.ts +0 -10
  437. package/dist/core/frontmatter-fence.js +0 -6
  438. package/dist/core/permission-rule-syntax.d.ts +0 -46
  439. package/dist/core/permission-rule-syntax.js +0 -52
@@ -428,7 +428,9 @@ export interface OperandSpellings {
428
428
  /** The word as written is a device spelling the tree's namespace screen refuses, and these spellings are the drive path it
429
429
  * names ({@link localDriveSpellingOf}): a STAND-IN — where the word MAY lead, read only where a reading tightens: the deny
430
430
  * views of the word itself (whose own question stands beside whatever the stand-in meets) and the deny floor of a walk that
431
- * lost track at it. It is never a place the command is proven to stand in (a base after `cd`, a launcher's directory). */
431
+ * lost track at it. It is never a place the command is proven to stand in (a base after `cd`, a launcher's directory). A word
432
+ * the shell walks above a drive's root into the emulation's own tree (`C:\proj\..\..\etc` is `/etc` to Git Bash, a place only
433
+ * that shell knows) is one too: its Win32 clamp is the stand-in, `spelled` the shell's own walk of it. */
432
434
  standIn?: true;
433
435
  }
434
436
  /** Does a spelling open with a tilde-prefix bash answers from the ACCOUNT DATABASE — `~user`, `~user/…` (that account's home
@@ -1,4 +1,4 @@
1
- import { anchorSpelling, isAbsoluteForFamily, isBlockedDevicePath, isShellRootedSpellingUnmapped, nativeUncSpellingOf, normalizeAbsPathLexically, shellAnchoredSpellingOf, shellDriveSpellingOf, win32NamespaceScreen, pathFamilyOf } from "./safety.js";
1
+ import { anchorSpelling, isAbsoluteForFamily, isBlockedDevicePath, isShellRootedSpellingUnmapped, nativeUncSpellingOf, normalizeAbsPathLexically, shellAnchoredSpellingOf, shellDriveAliasOf, shellDrivePathOf, shellDriveSpellingOf, shellWalkLeavesDrive, win32NamespaceScreen, pathFamilyOf } from "./safety.js";
2
2
  import { localDriveSpellingOf } from "../../core/unc-spelling.js";
3
3
  import { PARSE_FAILURE_SENTENCE, UNRESOLVED_SENTENCE, argvOf, expansionHidesRun, lexShell, literalTildeSpelling, } from "../../shell/lex.js";
4
4
  import { shellWordsOf } from "../../shell/shell-words.js";
@@ -227,14 +227,21 @@ export function resolveOperandSpellings(base, operand, homeDir) {
227
227
  const standIn = family === "win" && raw === operand ? localDriveSpellingOf(raw, family) : undefined;
228
228
  return standIn === undefined ? undefined : { ...spellingsOf(standIn), standIn: true };
229
229
  }
230
- const shellAnchored = (anchored) => spellingsOf(shellAnchoredSpellingOf(family, anchored) ?? anchored);
230
+ const walkOf = (anchored) => spellingsOf(shellAnchoredSpellingOf(family, anchored) ?? anchored);
231
+ const shellAnchored = (anchored) => shellWalkLeavesDrive(family, anchored) && shellAnchoredSpellingOf(family, anchored) === undefined ? { ...spellingsOf(anchored), standIn: true } : walkOf(anchored);
231
232
  if (isAbsoluteForFamily(family ?? "own", raw))
232
233
  return raw === operand ? spellingsOf(nativeUncSpellingOf(family, raw)) : shellAnchored(nativeUncSpellingOf(family, raw));
234
+ const kept = shellDrivePathOf(family, raw);
235
+ if (kept !== undefined)
236
+ return shellAnchored(kept);
233
237
  const drive = shellDriveSpellingOf(family, raw);
234
238
  if (drive !== undefined)
235
239
  return spellingsOf(drive);
236
240
  if (base === undefined || family === undefined || !isAbsoluteForFamily(family, base))
237
241
  return undefined;
242
+ const alias = shellDriveAliasOf(family, raw, base);
243
+ if (alias !== undefined)
244
+ return { ...(alias.walk === "shell" ? walkOf(alias.path) : { folded: normalizeAbsPathLexically(alias.path) }), standIn: true };
238
245
  if (isShellRootedSpellingUnmapped(family, raw))
239
246
  return undefined;
240
247
  return shellAnchored(anchorSpelling(family, base, raw));
@@ -37,11 +37,19 @@ export type FindAction = {
37
37
  * ({@link narrowsAt}); every other test (`-type f`, `-mtime`, `-newer`, `-size`, `-mindepth`, `-user`, …) and every other action
38
38
  * (`-print`, `-prune`, …) is `other`. `name`: `-name` / `-iname`, a pattern over the entry's own name. `path`: `-path` / `-ipath` /
39
39
  * `-wholename` / `-iwholename` (a pattern) and `-regex` / `-iregex` (a regular expression), over the whole path `find` matches —
40
- * the starting point as written, then the entry below it. `empty`: `-empty`. `dirs`: `-type d`. A value the shell rewrites is
40
+ * the starting point as written, then the entry below it; a regular expression carries the dialect the command reads it in
41
+ * ({@link RegexDialect}). `empty`: `-empty`. `dirs`: `-type d`. A value the shell rewrites is
41
42
  * not in the command: `other`. Beside the narrowing set, what a predicate is on ANY entry ({@link certainlyRunOn}): `true` — the
42
43
  * predicates that hold everywhere (`-true`, the printing actions, the walk's options: `-depth`, `-maxdepth`, `-follow`, …);
43
44
  * `false` (`-false`); `prune` (`-prune`: holds, and the walk does not go below the entry); `quit` (`-quit`: the walk ends).
44
45
  */
46
+ /**
47
+ * The dialect a command has `find` read a regular expression in, by what it writes: `basic` — no `-E` and no `-regextype` in
48
+ * front of the test, or a basic one (`emacs`, `posix-basic`, `sed`, …): `\(` `\)` a group and `*` a count, on which GNU's
49
+ * default and BSD's basic dialect agree; `extended` — BSD's `-E` or an extended `-regextype` (`posix-extended`, `awk`, `gnu-awk`,
50
+ * …): `(` `)` a group, `|` a choice, `*` `?` `+` counts. Absent where the command names a dialect this reader does not know.
51
+ */
52
+ export type RegexDialect = "basic" | "extended";
45
53
  export type FindTest = {
46
54
  readonly kind: "name";
47
55
  readonly value: string;
@@ -51,6 +59,7 @@ export type FindTest = {
51
59
  readonly value: string;
52
60
  readonly caseless: boolean;
53
61
  readonly regex: boolean;
62
+ readonly dialect?: RegexDialect;
54
63
  } | {
55
64
  readonly kind: "empty" | "dirs" | "other" | "true" | "false" | "prune" | "quit";
56
65
  };
@@ -74,8 +83,7 @@ export type FindExpr = {
74
83
  * starting points are read from a file (`-files0-from`) and none of them is in the command. `actions`: the actions that remove or
75
84
  * hand on, in the order written (`deletes` / `handed`: the two kinds of them). `expr`: the expression; `undefined` where it does
76
85
  * not parse — `find` refuses it and runs nothing, and every action is read as reaching every entry. `depths`: the levels below a
77
- * starting point the walk acts at ({@link FindDepths}). `regexType`: a `-regextype` is written — a regular expression may be read
78
- * in a dialect other than the default. `certainDepth`: the deepest level below a starting point whose every entry the walk
86
+ * starting point the walk acts at ({@link FindDepths}). `certainDepth`: the deepest level below a starting point whose every entry the walk
79
87
  * evaluates, where an option lets it pass some by (options of the whole walk wherever they are written; the least counts) — 1
80
88
  * under `-xdev` and BSD `-x` (a mount point right below the start is evaluated, nothing under it is walked), 0 under `-mount`
81
89
  * (GNU findutils 4.11 passes a mount point by itself) and BSD `-X` (it passes by a name holding a blank, a quote or a
@@ -89,7 +97,6 @@ export interface FindActions {
89
97
  readonly handed: readonly FindHanded[];
90
98
  readonly expr: FindExpr | undefined;
91
99
  readonly depths: FindDepths;
92
- readonly regexType: boolean;
93
100
  readonly certainDepth?: number;
94
101
  }
95
102
  /**
@@ -105,18 +112,24 @@ export interface FindDepths {
105
112
  /** Read one `find` argv (the words after the program word). */
106
113
  export declare function findActionsOf(row: ProgramRow, args: readonly FindWord[]): FindActions;
107
114
  /**
108
- * Does this test, at this starting point, keep the action behind it from reaching every entry below the starting point — the
109
- * closed set: a NAME pattern whose text, bracket expressions taken out, holds a character no wildcard is (`*.tmp`; not `*`, `?*`,
110
- * `[!.]*`); a PATH pattern that does not match an entry below the starting point whatever the entry is named (at every depth its
111
- * separators allow, a bracket expression read as any one character: `./build/*` at `.`; not `./*`, `*`, two levels of `*` below
112
- * `.`, nor a leading `*` then `/proj/*` at `/w/proj`); a regular expression over the path that, its `^` and the starting point's
113
- * own spelling taken off its front, still holds a letter, a digit or an escaped character (`\./build/.*` at `.`; not `\./.*`,
114
- * `.*`); `-empty` (only entries that hold no data); `-type d` behind `-delete` only (`-delete` cannot remove a directory that holds
115
- * anything, and removes no file there — `-exec rm -rf` removes what such a directory holds). A starting point the shell rewrites
116
- * is not in the command: a path pattern narrows there only where, bracket expressions taken out, it holds a character no wildcard
117
- * or separator is (`/*` does not).
115
+ * Does this test, at this starting point, keep the action behind it from reaching every entry below the starting point? A NAME
116
+ * pattern whose text, bracket expressions taken out, holds a character no wildcard is (`*.tmp`; not `*`, `?*`, `[!.]*`); a PATH
117
+ * pattern or a regular expression over the path that 7.70.0 read as narrowing ({@link narrowsOn7700}) and that this reader does not
118
+ * PROVE reaches every entry there ({@link reachProofOf}: `.*`, `.*x*`, `\./.*` at `.`, `./*` at `.` are proved; `.*~`, a run then
119
+ * `/....` are not narrowing on 7.70.0 already) — what the reader does not read, or reads only in part, is judged as 7.70.0 judged it;
120
+ * `-empty` (only entries that hold no data); `-type d` behind `-delete` only (`-delete` cannot remove a directory that holds
121
+ * anything, and removes no file there — `-exec rm -rf` removes what such a directory holds).
118
122
  */
119
123
  export declare function narrowsAt(t: FindTest, start: FindWord, forDelete: boolean): boolean;
124
+ /**
125
+ * Does this path pattern or regular expression PROVABLY reach every entry below the starting point — the name of the proof (the
126
+ * arm the comparison probe prints), or `undefined` where the reader proves nothing (then 7.70.0's reading judges it,
127
+ * {@link narrowsAt}). A proof is a shape the pattern matches every path of ({@link reachShapes}, {@link globReachShape}) that
128
+ * matches every entry below the start ({@link shapeReachesEvery}).
129
+ */
130
+ export declare function reachProofOf(t: Extract<FindTest, {
131
+ kind: "path";
132
+ }>, start: FindWord): string | undefined;
120
133
  /** Does this test fail on the starting point itself — `-false`, a name or path pattern its own spelling does not match (a starting point
121
134
  * the shell rewrites is read as failing: its name is not in the command — known limit)? A regular expression, `-empty` and
122
135
  * `-type d` may hold for it (the conservative side). */
@@ -153,8 +166,9 @@ export declare function findDirsDown(start: FindWord, value: string, rel: readon
153
166
  * only: the expression parses and writes no `-quit`; `dir`'s level is within the walk's depth bounds, each of them known, and at
154
167
  * most the level whose every entry the walk evaluates ({@link FindActions.certainDepth}: a mount point, a name `-X` passes by); no
155
168
  * directory on `way` (the starting point, level 0, down to `dir`'s parent) is pruned, or may be; and the action is evaluated on
156
- * `dir` whatever is not known — each test on the way to it holds or fails by what the command spells ({@link truthOn}). Anything
157
- * less is no claim: the action is not read as running there.
169
+ * `dir` whatever is not known — each test on the way to it holds or fails by what the command spells ({@link truthOn}: where 7.70.0
170
+ * settled a regular expression, as it did; a choice in the command's dialect where one branch settles it, the walk then
171
+ * certainly running the action there — on GNU's `find` for `\|`). Anything less is no claim: the action is not read as running there.
158
172
  */
159
173
  export declare function certainlyRunOn(a: FindActions, way: readonly FindDir[], dir: FindDir): readonly boolean[];
160
174
  /** The starting points as words ({@link FIND_DEFAULT_START} where the command names none). */
@@ -5,6 +5,10 @@ export function findWordOf(w) {
5
5
  return { raw: w.raw, spelled: literal ?? w.folded, ...(literal === undefined ? { rewritten: true } : {}) };
6
6
  }
7
7
  export const FIND_DEFAULT_START = Object.freeze({ raw: ".", spelled: "." });
8
+ const REGEX_TYPES = Object.freeze({
9
+ "findutils-default": "basic", emacs: "basic", "posix-basic": "basic", sed: "basic", ed: "basic",
10
+ "posix-extended": "extended", awk: "extended", "gnu-awk": "extended", "posix-awk": "extended",
11
+ });
8
12
  const HANDS_ON = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
9
13
  const OPERATOR = Object.freeze({ "(": "(", ")": ")", "!": "!", "-not": "!", "-a": "and", "-and": "and", "-o": "or", "-or": "or", ",": "," });
10
14
  const isOperator = (w) => Object.hasOwn(OPERATOR, w);
@@ -17,7 +21,7 @@ function leadingOptionWords(row, word, next) {
17
21
  return readOptionRole(row, word, next).form === "separated" ? 2 : 1;
18
22
  }
19
23
  const ALWAYS_TRUE = new Set(["-true", "-print", "-print0", "-printf", "-fprint", "-fprint0", "-fprintf", "-ls", "-fls", "-depth", "-maxdepth", "-mindepth", "-follow", "-noleaf", "-daystart", "-warn", "-nowarn", "-ignore_readdir_race", "-noignore_readdir_race", "-regextype", "-xdev", "-mount"]);
20
- function testOf(predicate, value) {
24
+ function testOf(predicate, value, dialect) {
21
25
  if (predicate === "-prune" || predicate === "-quit" || predicate === "-false")
22
26
  return { kind: predicate === "-prune" ? "prune" : predicate === "-quit" ? "quit" : "false" };
23
27
  if (ALWAYS_TRUE.has(predicate) && (predicate !== "-depth" || value === undefined))
@@ -34,7 +38,7 @@ function testOf(predicate, value) {
34
38
  if (predicate === "-path" || predicate === "-ipath" || predicate === "-wholename" || predicate === "-iwholename")
35
39
  return { kind: "path", value: value.spelled, caseless, regex: false };
36
40
  if (predicate === "-regex" || predicate === "-iregex")
37
- return { kind: "path", value: value.spelled, caseless, regex: true };
41
+ return { kind: "path", value: value.spelled, caseless, regex: true, ...(dialect !== undefined ? { dialect } : {}) };
38
42
  return { kind: "other" };
39
43
  }
40
44
  function parseExpression(terms) {
@@ -117,6 +121,7 @@ export function findActionsOf(row, args) {
117
121
  const starts = [];
118
122
  let certainDepth;
119
123
  const passesBy = (depth) => void (certainDepth = Math.min(certainDepth ?? depth, depth));
124
+ let dialect = "basic";
120
125
  for (;;) {
121
126
  const w = args[i];
122
127
  if (w === undefined)
@@ -132,6 +137,8 @@ export function findActionsOf(row, args) {
132
137
  passesBy(1);
133
138
  if (/^-[HLPEXdsx]+$/.test(w.spelled) && w.spelled.includes("X"))
134
139
  passesBy(0);
140
+ if (/^-[HLPEXdsx]+$/.test(w.spelled) && w.spelled.includes("E"))
141
+ dialect = "extended";
135
142
  if (w.spelled === "-f" && n === 2)
136
143
  starts.push(i + 1);
137
144
  i += n;
@@ -142,13 +149,10 @@ export function findActionsOf(row, args) {
142
149
  const terms = [];
143
150
  let startsFromFile = false;
144
151
  const depths = {};
145
- let regexType = false;
146
152
  while (i < args.length) {
147
153
  const w = args[i].spelled;
148
154
  if (w === "-files0-from")
149
155
  startsFromFile = true;
150
- if (w === "-regextype")
151
- regexType = true;
152
156
  if (w === "-xdev" || w === "-mount")
153
157
  passesBy(w === "-xdev" ? 1 : 0);
154
158
  if (HANDS_ON.has(w)) {
@@ -186,11 +190,13 @@ export function findActionsOf(row, args) {
186
190
  const separated = readOptionRole(row, w, next?.spelled).form === "separated";
187
191
  if ((w === "-mindepth" || w === "-maxdepth") && next !== undefined && separated)
188
192
  depths[w === "-mindepth" ? "min" : "max"] = next.rewritten !== true && /^\d+$/.test(next.spelled) ? Number(next.spelled) : "unknown";
189
- terms.push({ t: "test", test: testOf(w, separated ? next : undefined) });
193
+ if (w === "-regextype")
194
+ dialect = next !== undefined && next.rewritten !== true && Object.hasOwn(REGEX_TYPES, next.spelled) ? REGEX_TYPES[next.spelled] : undefined;
195
+ terms.push({ t: "test", test: testOf(w, separated ? next : undefined, dialect) });
190
196
  i += separated ? 2 : 1;
191
197
  }
192
198
  const handed = actions.filter((a) => a.action !== "-delete");
193
- return { starts, startsFromFile, actions, deletes: handed.length < actions.length, handed, expr: parseExpression(terms), depths, regexType, ...(certainDepth !== undefined ? { certainDepth } : {}) };
199
+ return { starts, startsFromFile, actions, deletes: handed.length < actions.length, handed, expr: parseExpression(terms), depths, ...(certainDepth !== undefined ? { certainDepth } : {}) };
194
200
  }
195
201
  function bracketEnd(p, i) {
196
202
  let j = i + 1;
@@ -240,9 +246,7 @@ export function narrowsAt(t, start, forDelete) {
240
246
  case "name":
241
247
  return /[^*?]/.test(bracketsReplaced(t.value, ""));
242
248
  case "path":
243
- if (t.regex)
244
- return /[A-Za-z0-9_]|\\./.test(bracketsReplaced(regexWithoutStart(t, start), ""));
245
- return start.rewritten === true ? /[^*?/]/.test(bracketsReplaced(t.value, "")) : !selectsAnyEntryBelow(t.value, start, t.caseless);
249
+ return narrowsOn7700(t, start) && reachProofOf(t, start) === undefined;
246
250
  case "empty":
247
251
  return true;
248
252
  case "dirs":
@@ -251,8 +255,12 @@ export function narrowsAt(t, start, forDelete) {
251
255
  return false;
252
256
  }
253
257
  }
254
- const startSpellings = (start) => [...new Set([start.spelled, start.spelled.replace(/(.)\/+$/, "$1")])];
255
- function selectsAnyEntryBelow(pattern, start, caseless) {
258
+ function narrowsOn7700(t, start) {
259
+ if (t.regex)
260
+ return /[A-Za-z0-9_]|\\./.test(bracketsReplaced(regexWithoutStart7700(t, start), ""));
261
+ return start.rewritten === true ? /[^*?/]/.test(bracketsReplaced(t.value, "")) : !selectsAnyEntryBelow7700(t.value, start, t.caseless);
262
+ }
263
+ function selectsAnyEntryBelow7700(pattern, start, caseless) {
256
264
  const p = bracketsReplaced(pattern, "?");
257
265
  const depth = Math.min(MAX_PROBE_DEPTH, (p.match(/\//g)?.length ?? 0) + 1);
258
266
  for (const s of startSpellings(start)) {
@@ -262,7 +270,7 @@ function selectsAnyEntryBelow(pattern, start, caseless) {
262
270
  }
263
271
  return false;
264
272
  }
265
- function regexWithoutStart(t, start) {
273
+ function regexWithoutStart7700(t, start) {
266
274
  const re = t.value.replace(/^\^/, "");
267
275
  if (start.rewritten === true)
268
276
  return re;
@@ -273,6 +281,239 @@ function regexWithoutStart(t, start) {
273
281
  longest = Math.max(longest, s.length);
274
282
  return re.slice(longest);
275
283
  }
284
+ const startSpellings = (start) => [...new Set([start.spelled, start.spelled.replace(/(.)\/+$/, "$1")])];
285
+ function globReachShape(pattern) {
286
+ const out = [];
287
+ for (let i = 0; i < pattern.length; i++) {
288
+ const c = pattern[i];
289
+ if (c === "[")
290
+ return undefined;
291
+ if (c === "*")
292
+ out.push("run");
293
+ else if (c === "?")
294
+ out.push("one");
295
+ else {
296
+ if (c === "\\" && ++i >= pattern.length)
297
+ return undefined;
298
+ const lit = codePointAt(pattern, i);
299
+ out.push({ lit });
300
+ i += lit.length - 1;
301
+ }
302
+ }
303
+ return out;
304
+ }
305
+ export function reachProofOf(t, start) {
306
+ const glob = t.regex ? undefined : globReachShape(t.value);
307
+ const shapes = t.regex ? reachShapes(t.value, t.dialect) : glob === undefined ? undefined : [glob];
308
+ const proof = shapes?.find((s) => shapeReachesEvery(s, start, t.caseless));
309
+ if (proof === undefined)
310
+ return undefined;
311
+ return `${t.regex ? `regex (${t.dialect})` : "path pattern"}: ${proof.every((p) => typeof p !== "object") ? "runs only (any path of two characters or more)" : "the start's own spelling, then runs"}`;
312
+ }
313
+ function shapeReachesEvery(shape, start, caseless) {
314
+ const lits = shape.flatMap((p) => (typeof p === "object" ? [p.lit] : []));
315
+ if (caseless && [start.spelled, ...lits].some((s) => /[^\x00-\x7f]/.test(s)))
316
+ return false;
317
+ const tail = (from, room) => {
318
+ const rest = shape.slice(from);
319
+ return rest.includes("run") && rest.every((p) => p === "run" || p === "one") && rest.filter((p) => p === "one").length <= room;
320
+ };
321
+ if (tail(0, 2))
322
+ return true;
323
+ if (start.rewritten === true)
324
+ return false;
325
+ const same = (a, b) => (caseless ? a.toLowerCase() === b.toLowerCase() : a === b);
326
+ return startSpellings(start).every((s) => {
327
+ const printed = s === "/" ? "/" : `${s}/`;
328
+ let k = 0;
329
+ for (; k < shape.length && k < printed.length; k++) {
330
+ const p = shape[k];
331
+ if (typeof p !== "object" || !same(p.lit, printed[k]))
332
+ break;
333
+ }
334
+ return k > 0 && tail(k, printed.length - k + 1);
335
+ });
336
+ }
337
+ const codePointAt = (s, i) => String.fromCodePoint(s.codePointAt(i));
338
+ const LITERAL_ESCAPE = /^[.[\]*^$\\/\-~,:;=@#%&!"]$/;
339
+ function reachShapes(re, dialect) {
340
+ const tokens = dialect === undefined || re.includes("\n") ? undefined : regexTokens(re);
341
+ if (tokens === undefined)
342
+ return undefined;
343
+ const [open, close, choice] = dialect === "basic" ? ["\\(", "\\)", undefined] : ["(", ")", "|"];
344
+ const countOf = (t) => t === "*" || (dialect === "extended" && (t === "?" || t === "+"));
345
+ let k = 0;
346
+ const cross = (a, b) => {
347
+ const out = a.flatMap((x) => b.map((y) => [...x, ...y]));
348
+ return out.length > MAX_BRANCHES ? undefined : out;
349
+ };
350
+ const alternatives = (inGroup) => {
351
+ let out = [];
352
+ for (;;) {
353
+ const s = sequence(inGroup);
354
+ if (s === undefined || (out = [...out, ...s]).length > MAX_BRANCHES)
355
+ return undefined;
356
+ if (choice === undefined || tokens[k] !== choice)
357
+ return out;
358
+ k++;
359
+ }
360
+ };
361
+ const sequence = (inGroup) => {
362
+ let acc = [[]];
363
+ let empty = true;
364
+ for (;;) {
365
+ const t = tokens[k];
366
+ if (t === undefined || t === choice || (inGroup && t === close))
367
+ return acc;
368
+ k++;
369
+ let item;
370
+ if (t === open) {
371
+ item = alternatives(true);
372
+ if (item === undefined || tokens[k] !== close)
373
+ return undefined;
374
+ k++;
375
+ }
376
+ else if (t === "^" || t === "$") {
377
+ const atEdge = !inGroup && (t === "^" ? empty : tokens[k] === undefined || tokens[k] === choice);
378
+ if (!atEdge)
379
+ return undefined;
380
+ continue;
381
+ }
382
+ else if (t === ".")
383
+ item = [["one"]];
384
+ else if (t.startsWith("\\")) {
385
+ if (t.length !== 2 || !LITERAL_ESCAPE.test(t[1]))
386
+ return undefined;
387
+ item = [[{ lit: t[1] }]];
388
+ }
389
+ else if (t.startsWith("[") || countOf(t) || t === "*" || (dialect === "basic" ? t === "+" || t === "?" : t === "{" || t === "}" || t === ")"))
390
+ return undefined;
391
+ else
392
+ item = [[{ lit: t }]];
393
+ const n = tokens[k];
394
+ if (countOf(n)) {
395
+ k++;
396
+ if (countOf(tokens[k]) || tokens[k] === "{" || tokens[k] === "\\{")
397
+ return undefined;
398
+ if (n !== "+")
399
+ item = t === "." && n === "*" ? [["run"]] : [[]];
400
+ else if (t === ".")
401
+ item = [["one", "run"]];
402
+ }
403
+ const next = cross(acc, item);
404
+ if (next === undefined)
405
+ return undefined;
406
+ acc = next;
407
+ empty = false;
408
+ }
409
+ };
410
+ const out = alternatives(false);
411
+ return out === undefined || k !== tokens.length ? undefined : out;
412
+ }
413
+ function regexTokens(re) {
414
+ const out = [];
415
+ for (let i = 0; i < re.length;) {
416
+ if (re[i] === "\\") {
417
+ out.push(re.slice(i, i + 2));
418
+ i += 2;
419
+ }
420
+ else if (re[i] === "[") {
421
+ const close = posixBracketEnd(re, i);
422
+ if (close < 0 || re.slice(i, close + 1).includes("\\"))
423
+ return undefined;
424
+ out.push(re.slice(i, close + 1));
425
+ i = close + 1;
426
+ }
427
+ else {
428
+ const c = codePointAt(re, i);
429
+ out.push(c);
430
+ i += c.length;
431
+ }
432
+ }
433
+ return out;
434
+ }
435
+ const COUNT_TOKENS = new Set(["*", "?", "+", "{", "\\?", "\\+", "\\{"]);
436
+ const MAX_BRANCHES = 64;
437
+ function regexBranches(re, dialect) {
438
+ const tokens = re.includes("\n") || dialect === undefined ? undefined : regexTokens(re);
439
+ if (tokens === undefined)
440
+ return undefined;
441
+ const [open, close, choice, other] = dialect === "basic" ? ["\\(", "\\)", "\\|", "|"] : ["(", ")", "|", "\\|"];
442
+ if (!tokens.includes(choice))
443
+ return [re];
444
+ if (tokens.includes(other))
445
+ return undefined;
446
+ let depth = 0;
447
+ for (const t of tokens)
448
+ if ((depth += t === open ? 1 : t === close ? -1 : 0) < 0)
449
+ return undefined;
450
+ if (depth !== 0)
451
+ return undefined;
452
+ const split = (list) => {
453
+ const out = [[]];
454
+ let d = 0;
455
+ for (const t of list) {
456
+ if (t === open)
457
+ d++;
458
+ if (t === close)
459
+ d--;
460
+ if (t === choice && d === 0)
461
+ out.push([]);
462
+ else
463
+ out.at(-1).push(t);
464
+ }
465
+ return out;
466
+ };
467
+ const out = [];
468
+ for (const top of split(tokens)) {
469
+ let partial = [[]];
470
+ for (let i = 0; i < top.length;) {
471
+ if (top[i] !== open) {
472
+ for (const p of partial)
473
+ p.push(top[i]);
474
+ i++;
475
+ continue;
476
+ }
477
+ let j = i + 1;
478
+ for (let d = 1; j < top.length; j++) {
479
+ if (top[j] === open)
480
+ d++;
481
+ if (top[j] === close && --d === 0)
482
+ break;
483
+ }
484
+ const inner = top.slice(i + 1, j);
485
+ const holds = inner.includes(choice);
486
+ if (holds && COUNT_TOKENS.has(top[j + 1] ?? ""))
487
+ return undefined;
488
+ const alternatives = holds ? split(inner) : [top.slice(i, j + 1)];
489
+ partial = partial.flatMap((p) => alternatives.map((a) => [...p, ...a]));
490
+ if (partial.length > MAX_BRANCHES)
491
+ return undefined;
492
+ i = j + 1;
493
+ }
494
+ out.push(...partial);
495
+ }
496
+ return out.length > MAX_BRANCHES ? undefined : out.map((b) => b.join(""));
497
+ }
498
+ function posixBracketEnd(re, i) {
499
+ let j = i + 1;
500
+ if (re[j] === "^")
501
+ j++;
502
+ if (re[j] === "]")
503
+ j++;
504
+ for (; j < re.length; j++) {
505
+ const unit = re[j] === "[" ? re[j + 1] : undefined;
506
+ if (unit === ":" || unit === "=" || unit === ".") {
507
+ const close = re.indexOf(`${unit}]`, j + 2);
508
+ if (close < 0)
509
+ return -1;
510
+ j = close + 1;
511
+ }
512
+ else if (re[j] === "]")
513
+ return j;
514
+ }
515
+ return -1;
516
+ }
276
517
  export function failsOnStart(t, start) {
277
518
  if (t.kind === "false")
278
519
  return true;
@@ -420,16 +661,26 @@ function plainRegex(re, caseless) {
420
661
  }
421
662
  }
422
663
  const mayReadOtherwise = (pattern, subjects) => [pattern, ...subjects].some((s) => /[^\x00-\x7f]/.test(s)) || /\[[^\]]*\\/.test(pattern);
423
- function truthOn(t, dir, regexType) {
664
+ function truthOn(t, dir) {
665
+ const on = (hits) => (hits.every((h) => h === "T") ? "T" : hits.every((h) => h === "F") ? "F" : "M");
424
666
  switch (t.kind) {
425
667
  case "name":
426
668
  return mayReadOtherwise(t.value, [dir.name]) ? "M" : globReading(t.value, dir.name, t.caseless);
427
669
  case "path": {
428
- const re = !t.regex ? undefined : regexType ? null : (plainRegex(t.value, t.caseless) ?? null);
429
- if (re === null || mayReadOtherwise(t.value, dir.paths))
670
+ if (mayReadOtherwise(t.value, dir.paths))
671
+ return "M";
672
+ if (!t.regex)
673
+ return on(dir.paths.map((p) => globReading(t.value, p, t.caseless)));
674
+ if (t.dialect === undefined)
430
675
  return "M";
431
- const hits = dir.paths.map((p) => (re === undefined ? globReading(t.value, p, t.caseless) : re.test(p) ? "T" : "F"));
432
- return hits.every((h) => h === "T") ? "T" : hits.every((h) => h === "F") ? "F" : "M";
676
+ const whole = plainRegex(t.value, t.caseless);
677
+ if (whole !== undefined)
678
+ return on(dir.paths.map((p) => (whole.test(p) ? "T" : "F")));
679
+ const branches = regexBranches(t.value, t.dialect);
680
+ if (branches === undefined)
681
+ return "M";
682
+ const plain = branches.map((b) => plainRegex(b, t.caseless));
683
+ return on(dir.paths.map((p) => plain.reduce((held, re) => or3(held, re === undefined ? "M" : re.test(p) ? "T" : "F"), "F")));
433
684
  }
434
685
  case "dirs":
435
686
  case "true":
@@ -493,7 +744,7 @@ export function certainlyRunOn(a, way, dir) {
493
744
  if (a.expr === undefined || holdsQuit(a.expr) || min === "unknown" || max === "unknown" || dir.level < min || (max !== undefined && dir.level > max) || (a.certainDepth !== undefined && dir.level > a.certainDepth))
494
745
  return none;
495
746
  const expr = a.expr;
496
- const on = (d) => evaluatedOn(expr, a.actions.length, (t) => truthOn(t, d, a.regexType));
747
+ const on = (d) => evaluatedOn(expr, a.actions.length, (t) => truthOn(t, d));
497
748
  if (way.some((d) => on(d).prune !== "F"))
498
749
  return none;
499
750
  return on(dir).actions.map((r) => r === "T");
@@ -509,6 +760,8 @@ export function findHandedLines(row, args) {
509
760
  }
510
761
  export function findHandedCommands(row, args) {
511
762
  const a = findActionsOf(row, args);
763
+ if (a.handed.length === 0)
764
+ return [];
512
765
  const starts = findStartsOf(a, args);
513
766
  const reach = starts.map((s) => reachAt(a, s));
514
767
  const out = [];
@@ -487,16 +487,14 @@ async function runShell(env, cwd, toolName, command, timeoutSec, caps, signal, c
487
487
  },
488
488
  };
489
489
  }
490
- function bashDescription(coAuthor, caps, bgOffered = false, bgRetained = false, bgSessionScoped = false, bgEnvIsolatedOwned = false, confinement = "none") {
490
+ function bashDescription(coAuthor, caps, bgOffered = false, bgRetained = false, bgSessionScoped = false, bgEnvIsolatedOwned = false, confinement = "none", shellFirst = false) {
491
491
  const coAuthorLines = coAuthor === false
492
492
  ? "- Follow the deployment's commit-message conventions."
493
493
  : `- End git commit messages with:\nCo-Authored-By: ${coAuthor}`;
494
494
  return `Executes a bash command and returns its output.
495
495
 
496
496
  - Working directory persists between calls, but prefer absolute paths — each call starts in the directory the previous call ended in, so a \`cd\` carries over and moves the base for every later command. Shell state (env vars, functions) does not persist; the shell is re-initialized each call.
497
- - IMPORTANT: Avoid using this tool to run \`cat\`, \`head\`, \`tail\`, \`sed\`, \`awk\`, or \`echo\` commands, unless explicitly instructed or after you have verified that a dedicated tool cannot accomplish your task. Instead, use the appropriate dedicated tool as this will provide a much better experience for the user.
498
- - File search by name: use the Glob tool (NOT \`find\` or \`ls\`); content search: use the Grep tool (NOT \`grep\`/\`rg\` in the shell).
499
- - \`timeout\` is in milliseconds: default ${caps.defaultMs}, max ${caps.maxMs}.${bgOffered ? `\n- \`run_in_background\` runs the command detached: it keeps running across turns and re-invokes you when it exits. No \`&\` needed.${backgroundLifetimeNote(bgRetained, bgSessionScoped, bgEnvIsolatedOwned, "description")}` : ""}
497
+ ${shellFirst ? "" : DEDICATED_TOOLS_LINES}- \`timeout\` is in milliseconds: default ${caps.defaultMs}, max ${caps.maxMs}.${bgOffered ? `\n- \`run_in_background\` runs the command detached: it keeps running across turns and re-invokes you when it exits. No \`&\` needed.${backgroundLifetimeNote(bgRetained, bgSessionScoped, bgEnvIsolatedOwned, "description")}` : ""}
500
498
 
501
499
  # Git
502
500
  - Interactive flags (\`-i\`, e.g. \`git rebase -i\`, \`git add -i\`) are not supported in this environment.
@@ -508,6 +506,9 @@ ${coAuthorLines}
508
506
  - ${BASH_CONFINEMENT_NOTE[confinement]} Every call is subject to the deployment's approval policy (it may be denied or require confirmation); a denied call should not be retried verbatim.
509
507
  - Treat evidence of a deployment restriction — "Operation not permitted", "Read-only file system", a denied path, or a network failure — as a boundary, not a bug: adjust within the allowed scope or report the limit; don't reach for a destructive or privilege-escalating workaround.`;
510
508
  }
509
+ const DEDICATED_TOOLS_LINES = `- IMPORTANT: Avoid using this tool to run \`cat\`, \`head\`, \`tail\`, \`sed\`, \`awk\`, or \`echo\` commands, unless explicitly instructed or after you have verified that a dedicated tool cannot accomplish your task. Instead, use the appropriate dedicated tool as this will provide a much better experience for the user.
510
+ - File search by name: use the Glob tool (NOT \`find\` or \`ls\`); content search: use the Grep tool (NOT \`grep\`/\`rg\` in the shell).
511
+ `;
511
512
  const BASH_CONFINEMENT_NOTE = {
512
513
  command: "Commands run in the session's OS sandbox by default; see the sandbox instructions for what it allows.",
513
514
  env: "Commands run inside the isolated execution environment, not on the operator's machine.",
@@ -560,10 +561,12 @@ export function createBashTool(env, rootCanonical, coAuthor = false, cwdRef = {
560
561
  const bgRetained = hasBackgroundShell(env) && retainsBackgroundProcesses({ env: envDeclaresRetain(env), task: taskOpts.retainBackgroundProcesses === true });
561
562
  const bgSessionScoped = taskOpts.sessionId !== undefined && taskOpts.taskRegistry !== undefined;
562
563
  const bgEnvIsolatedOwned = hasDestroy(env) && isIsolated(env);
564
+ const cardOf = (shellFirst) => bashDescription(coAuthor, timeoutCaps, bgOffered, bgRetained, bgSessionScoped, bgEnvIsolatedOwned, taskOpts.commandSandbox !== undefined ? "command" : isIsolated(env) ? "env" : "none", shellFirst);
563
565
  return defineTool({
564
566
  name: "Bash",
565
567
  ...toolFace("bash"),
566
- description: bashDescription(coAuthor, timeoutCaps, bgOffered, bgRetained, bgSessionScoped, bgEnvIsolatedOwned, taskOpts.commandSandbox !== undefined ? "command" : isIsolated(env) ? "env" : "none"),
568
+ description: cardOf(false),
569
+ descriptionVariants: [{ id: "shell-first", traits: {}, facts: { shellFirstSession: true }, text: cardOf(true) }],
567
570
  parameters: Type.Object({
568
571
  command: Type.String({ description: "The command to execute" }),
569
572
  timeout: Type.Optional(Type.Number({ description: bashTimeoutParamDescription(timeoutCaps, false) })),
@@ -78,35 +78,6 @@ export declare const BASH_READONLY_CONFINEMENT_NOTE = "bash_readonly is confined
78
78
  * false-stale defect for those targets. Round-tripping the real bytes sidesteps the case analysis
79
79
  * and stays correct if the encoding rules ever change. */
80
80
  export declare function persistedTextOf(encoded: string | Uint8Array): string;
81
- /**
82
- * One APPLIED edit as the Edit tool's `details` card records it: the RESOLVED old/new strings
83
- * (post quote/escape resolution, post deletion-newline widening) in the normalized originalFile
84
- * coordinate. This is the card shape a transcript replay must re-apply, so the application step is a
85
- * single source shared by the Edit tool's own apply loop and the replay — two spellings of "apply"
86
- * could silently drift (e.g. one expanding `$&` and one not) and the replay's recomputed hash would
87
- * refuse edits the tool actually made.
88
- */
89
- export interface RecordedEdit {
90
- oldString: string;
91
- newString: string;
92
- replaceAll: boolean;
93
- }
94
- /**
95
- * Apply ONE recorded edit mechanically (no matching layers, no validation: the recording site
96
- * already resolved and validated the strings; a replay consumer that cannot prove `oldString` is
97
- * present must fall back to retracting its record, never guess here).
98
- *
99
- * Two load-bearing details, both shared with the Edit tool's historical inline apply:
100
- * - Function-form replacement: the callback's return value is NOT interpreted as a replacement
101
- * pattern, so `$&`/`$$`/`` $` ``/`$'` in `newString` are written literally (the replaceAll
102
- * split/join path is literal by construction).
103
- * - `oldString === ""` is the whole-content OVERWRITE shape: the Edit tool's whitespace-only-file
104
- * overwrite lane records `{oldString: "", newString: <full new text>}` after REPLACING the file's
105
- * content wholesale (fs-write.ts, the `old_string:""` existing-file branch). The tool's own apply
106
- * loop never reaches this arm (checkEditMatch refuses an empty old_string before application), so
107
- * it exists for the replay consumer alone — a plain `replace("", ...)` would PREPEND instead.
108
- */
109
- export declare function applyRecordedEdit(text: string, edit: RecordedEdit): string;
110
81
  /** Render the read-before-edit refusal: the bare "read it first", with a way out only where "read it first" is a dead end
111
82
  * that no Read of the file will explain.
112
83
  *
@@ -50,11 +50,6 @@ export const BASH_READONLY_CONFINEMENT_NOTE = "bash_readonly is confined to the
50
50
  export function persistedTextOf(encoded) {
51
51
  return decodeTextBytes(typeof encoded === "string" ? Buffer.from(encoded, "utf8") : encoded).text;
52
52
  }
53
- export function applyRecordedEdit(text, edit) {
54
- if (edit.oldString === "")
55
- return edit.newString;
56
- return edit.replaceAll ? text.split(edit.oldString).join(edit.newString) : text.replace(edit.oldString, () => edit.newString);
57
- }
58
53
  export function notReadRefusalText(toolName, key, v) {
59
54
  const base = `Error (${toolName}): ${v.message}`;
60
55
  const media = imageMimeForRead(key) !== undefined ? READ_SHOWS_IMAGE_HINT : isPdfPath(key) ? READ_SHOWS_PDF_HINT : undefined;
@@ -4,7 +4,8 @@ import { defineTool, errorResult } from "../../core/tools.js";
4
4
  import { sha256, resolveKey, violationText, violationDetails, requireRead, checkStale, checkEditMatch, checkNoChange, resolveQuoteMatch, adaptNewStringQuotes, resolveEscapeMatch, adaptNewStringEscapes, escapeMatchWasAttempted, ESCAPE_MATCH_MISS_NOTE, deletionOldString, countOccurrences, } from "./safety.js";
5
5
  import { decodeTextBytes, encodeTextForFile, normalizeEditText, normalizeFileText } from "./encoding.js";
6
6
  import { seatForCall } from "./read-deny.js";
7
- import { MAX_EDIT_BYTES, decodeEditBytes, tooLargeToEditMessage, malformedBodyMessage, persistedTextOf, notReadRefusalText, enoentMessage, FILE_STATE_TRAILER, FILE_PATH_PARAMS, coerceWriteArguments, ipynbRedirect, countLines, applyRecordedEdit, } from "./fs-shared.js";
7
+ import { MAX_EDIT_BYTES, decodeEditBytes, tooLargeToEditMessage, malformedBodyMessage, persistedTextOf, notReadRefusalText, enoentMessage, FILE_STATE_TRAILER, FILE_PATH_PARAMS, coerceWriteArguments, ipynbRedirect, countLines, } from "./fs-shared.js";
8
+ import { applyRecordedEdit } from "@sema-agent/primitives";
8
9
  import { envErrorDetail } from "./env-error-detail.js";
9
10
  import { objectOfOpening, openBoundAt, readWithin, sameKeyAgain } from "./bound-open.js";
10
11
  import { toolFace } from "../../core/tool-catalog-entries.js";