@sema-agent/core 7.71.1 → 7.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/CHANGELOG.md +500 -0
  2. package/dist/agents/cross-session-ref.d.ts +2 -2
  3. package/dist/agents/cross-session-ref.js +7 -2
  4. package/dist/agents/inherited-tool-pool.d.ts +30 -2
  5. package/dist/agents/inherited-tool-pool.js +53 -7
  6. package/dist/agents/parked-resume-drive.d.ts +10 -0
  7. package/dist/agents/parked-resume-drive.js +9 -0
  8. package/dist/agents/retain-ledger.d.ts +3 -0
  9. package/dist/agents/send-message-tool.js +7 -2
  10. package/dist/agents/send-user-message-tool.d.ts +12 -0
  11. package/dist/agents/send-user-message-tool.js +67 -0
  12. package/dist/agents/subagent-steps.d.ts +9 -0
  13. package/dist/agents/subagent-steps.js +38 -0
  14. package/dist/agents/subagent.d.ts +2 -0
  15. package/dist/agents/subagent.js +47 -12
  16. package/dist/agents/verify.js +23 -7
  17. package/dist/agents/yield-adoption.js +3 -1
  18. package/dist/brain/anthropic.js +14 -9
  19. package/dist/brain/open-responses.js +4 -5
  20. package/dist/brain/openai.js +30 -23
  21. package/dist/brain/stream-engine.js +159 -151
  22. package/dist/core/a2a.d.ts +24 -3
  23. package/dist/core/a2a.js +27 -8
  24. package/dist/core/actions-digest.d.ts +43 -0
  25. package/dist/core/actions-digest.js +22 -0
  26. package/dist/core/agent-state.d.ts +28 -7
  27. package/dist/core/agent-state.js +19 -6
  28. package/dist/core/allow-entry.js +3 -3
  29. package/dist/core/approval-object.d.ts +7 -3
  30. package/dist/core/approval-object.js +30 -9
  31. package/dist/core/auto-mode.d.ts +7 -9
  32. package/dist/core/auto-mode.js +114 -8
  33. package/dist/core/checkpoint-features.d.ts +16 -5
  34. package/dist/core/checkpoint-features.js +35 -6
  35. package/dist/core/checkpoint-rekey.d.ts +1 -1
  36. package/dist/core/checkpoint-rekey.js +6 -1
  37. package/dist/core/checkpoint-requirements.d.ts +23 -3
  38. package/dist/core/checkpoint-requirements.js +5 -1
  39. package/dist/core/checkpoint-row-verdict.d.ts +1 -1
  40. package/dist/core/checkpoint-row-verdict.js +10 -4
  41. package/dist/core/checkpoint-store.d.ts +24 -2
  42. package/dist/core/checkpoint-store.js +1 -0
  43. package/dist/core/child-clamp-seats.d.ts +15 -0
  44. package/dist/core/child-clamp-seats.js +15 -0
  45. package/dist/core/delegation-frames.d.ts +1 -0
  46. package/dist/core/delegation-frames.js +1 -1
  47. package/dist/core/effective-path-target.d.ts +19 -0
  48. package/dist/core/effective-path-target.js +95 -38
  49. package/dist/core/engine-capabilities.d.ts +5 -1
  50. package/dist/core/engine-capabilities.js +1 -1
  51. package/dist/core/engine-notice.d.ts +34 -23
  52. package/dist/core/engine-version.js +1 -1
  53. package/dist/core/entries-not-applied.d.ts +19 -7
  54. package/dist/core/entries-not-applied.js +33 -1
  55. package/dist/core/file-history-store.d.ts +15 -4
  56. package/dist/core/file-history-store.js +53 -23
  57. package/dist/core/gate-fold.js +3 -1
  58. package/dist/core/governance-codes.d.ts +10 -1
  59. package/dist/core/governance-codes.js +17 -5
  60. package/dist/core/hooks.d.ts +3 -0
  61. package/dist/core/hooks.js +1 -0
  62. package/dist/core/host-instance.d.ts +23 -0
  63. package/dist/core/host-instance.js +69 -0
  64. package/dist/core/instruction-preview.d.ts +63 -0
  65. package/dist/core/instruction-preview.js +406 -0
  66. package/dist/core/judged-read.d.ts +57 -0
  67. package/dist/core/judged-read.js +1 -0
  68. package/dist/core/leg-budget.d.ts +26 -0
  69. package/dist/core/leg-budget.js +9 -0
  70. package/dist/core/leg-identity.d.ts +51 -1
  71. package/dist/core/leg-identity.js +45 -2
  72. package/dist/core/manager-launch-check.d.ts +48 -0
  73. package/dist/core/manager-launch-check.js +64 -0
  74. package/dist/core/mcp-call-meta.d.ts +2 -2
  75. package/dist/core/mcp-host-seat.d.ts +5 -0
  76. package/dist/core/mcp-host-seat.js +7 -1
  77. package/dist/core/mcp-injection-drop.d.ts +20 -10
  78. package/dist/core/mcp-injection-drop.js +9 -3
  79. package/dist/core/mcp-server-spec.d.ts +2 -1
  80. package/dist/core/mcp.js +3 -1
  81. package/dist/core/member-outcome.d.ts +3 -2
  82. package/dist/core/member-outcome.js +1 -1
  83. package/dist/core/memory-engine/deletion-record.d.ts +46 -0
  84. package/dist/core/memory-engine/deletion-record.js +96 -0
  85. package/dist/core/memory-engine/engine.js +24 -16
  86. package/dist/core/memory-engine/file-backend.js +7 -5
  87. package/dist/core/memory-engine/index.d.ts +1 -1
  88. package/dist/core/memory-engine/index.js +1 -1
  89. package/dist/core/memory-engine/layout.js +6 -4
  90. package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
  91. package/dist/core/memory-engine/projection-ledger.js +1 -1
  92. package/dist/core/memory-engine/scope-contract.d.ts +69 -11
  93. package/dist/core/memory-engine/scope-contract.js +99 -34
  94. package/dist/core/memory-engine/sync-client.js +26 -6
  95. package/dist/core/memory-engine/sync.d.ts +20 -2
  96. package/dist/core/memory-engine/sync.js +18 -17
  97. package/dist/core/mode-policy.d.ts +21 -6
  98. package/dist/core/mode-policy.js +15 -6
  99. package/dist/core/mounted-mcp.d.ts +7 -2
  100. package/dist/core/mounted-mcp.js +10 -1
  101. package/dist/core/own-property-receipt.js +11 -4
  102. package/dist/core/param-rule-reach.d.ts +8 -3
  103. package/dist/core/param-rule-reach.js +9 -1
  104. package/dist/core/parent-spec-seat.d.ts +13 -1
  105. package/dist/core/parent-spec-seat.js +18 -0
  106. package/dist/core/peer-registration.d.ts +52 -0
  107. package/dist/core/peer-registration.js +37 -0
  108. package/dist/core/peer-seat.d.ts +3 -1
  109. package/dist/core/peer-seat.js +3 -3
  110. package/dist/core/peer-task-store.d.ts +365 -0
  111. package/dist/core/peer-task-store.js +682 -0
  112. package/dist/core/permission-rule-consent.js +6 -11
  113. package/dist/core/permission-rule-model.d.ts +27 -0
  114. package/dist/core/permission-rule-model.js +34 -6
  115. package/dist/core/permission-rule-provider.d.ts +35 -33
  116. package/dist/core/permission-rule-provider.js +38 -295
  117. package/dist/core/permission-rule-store.d.ts +181 -8
  118. package/dist/core/permission-rule-store.js +420 -17
  119. package/dist/core/permission-rule-sync.js +15 -1
  120. package/dist/core/project-seat.d.ts +55 -0
  121. package/dist/core/project-seat.js +96 -0
  122. package/dist/core/protocol-http-auth.d.ts +3 -2
  123. package/dist/core/protocol-http-auth.js +26 -18
  124. package/dist/core/remote-env.d.ts +4 -4
  125. package/dist/core/retired-keys.js +1 -0
  126. package/dist/core/rule-offer-read.d.ts +1 -1
  127. package/dist/core/rule-offer-read.js +32 -4
  128. package/dist/core/run-ledger-seat.d.ts +66 -0
  129. package/dist/core/run-ledger-seat.js +70 -0
  130. package/dist/core/run-ledger.d.ts +332 -0
  131. package/dist/core/run-ledger.js +550 -0
  132. package/dist/core/runner/chain-mismatch.d.ts +32 -0
  133. package/dist/core/runner/chain-mismatch.js +29 -0
  134. package/dist/core/runner/changes-history.d.ts +1 -0
  135. package/dist/core/runner/changes-history.js +2 -2
  136. package/dist/core/runner/checkpoint-scope.d.ts +13 -3
  137. package/dist/core/runner/checkpoint-scope.js +12 -4
  138. package/dist/core/runner/construction-doors.js +6 -0
  139. package/dist/core/runner/contracts.d.ts +22 -3
  140. package/dist/core/runner/delegation-owner.d.ts +30 -0
  141. package/dist/core/runner/delegation-owner.js +20 -4
  142. package/dist/core/runner/file-history-restore.d.ts +3 -1
  143. package/dist/core/runner/file-history-restore.js +9 -6
  144. package/dist/core/runner/finish-reason-seat.js +4 -2
  145. package/dist/core/runner/leg-frame.js +3 -0
  146. package/dist/core/runner/loaded-skills.d.ts +2 -0
  147. package/dist/core/runner/loaded-skills.js +10 -0
  148. package/dist/core/runner/nested-memory-lane.d.ts +22 -5
  149. package/dist/core/runner/nested-memory-lane.js +91 -30
  150. package/dist/core/runner/person-path-rows.d.ts +23 -20
  151. package/dist/core/runner/person-path-rows.js +82 -18
  152. package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
  153. package/dist/core/runner/prepare-caps-and-workflow.js +105 -90
  154. package/dist/core/runner/prepare-config-doors.d.ts +1 -0
  155. package/dist/core/runner/prepare-config-doors.js +5 -3
  156. package/dist/core/runner/prepare-context-lane.js +1 -0
  157. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  158. package/dist/core/runner/prepare-delegation-surface.js +6 -0
  159. package/dist/core/runner/prepare-execution-env.d.ts +3 -3
  160. package/dist/core/runner/prepare-file-history.js +1 -1
  161. package/dist/core/runner/prepare-hands-readface.d.ts +10 -2
  162. package/dist/core/runner/prepare-hands-readface.js +36 -22
  163. package/dist/core/runner/prepare-inherited-gate.d.ts +8 -5
  164. package/dist/core/runner/prepare-inherited-gate.js +14 -6
  165. package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -2
  166. package/dist/core/runner/prepare-memory-engine-session.js +2 -2
  167. package/dist/core/runner/prepare-memory.js +3 -15
  168. package/dist/core/runner/prepare-project-context.d.ts +1 -1
  169. package/dist/core/runner/prepare-project-context.js +3 -7
  170. package/dist/core/runner/prepare-protocol-tools.d.ts +5 -0
  171. package/dist/core/runner/prepare-protocol-tools.js +2 -2
  172. package/dist/core/runner/prepare-run-refs.d.ts +1 -1
  173. package/dist/core/runner/prepare-run-refs.js +3 -2
  174. package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
  175. package/dist/core/runner/prepare-suspend-saga.js +4 -2
  176. package/dist/core/runner/prepare-task.js +50 -37
  177. package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
  178. package/dist/core/runner/prepare-turn-wiring.js +2 -1
  179. package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -1
  180. package/dist/core/runner/prepare-wiring-manifest.js +8 -4
  181. package/dist/core/runner/read-session-changes.js +1 -1
  182. package/dist/core/runner/resume-apply.js +11 -5
  183. package/dist/core/runner/resume-checkpoint-screen.d.ts +8 -7
  184. package/dist/core/runner/resume-checkpoint-screen.js +7 -6
  185. package/dist/core/runner/resume-review-outcome.d.ts +3 -0
  186. package/dist/core/runner/resume-review-outcome.js +24 -1
  187. package/dist/core/runner/rewind-files.js +3 -2
  188. package/dist/core/runner/run-harness-handlers.js +3 -0
  189. package/dist/core/runner/run-identity-wiring.js +3 -2
  190. package/dist/core/runner/run-leg.js +9 -2
  191. package/dist/core/runner/run-notification-lane.js +20 -1
  192. package/dist/core/runner/run-settle-and-teardown.js +21 -12
  193. package/dist/core/runner/run-stop-and-final-verify.js +6 -0
  194. package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
  195. package/dist/core/runner/runtask.d.ts +6 -2
  196. package/dist/core/runner/runtask.js +21 -9
  197. package/dist/core/runner/shell-env-withheld.d.ts +3 -2
  198. package/dist/core/runner/shell-env-withheld.js +1 -2
  199. package/dist/core/runner/stop-tail-notice.d.ts +10 -2
  200. package/dist/core/runner/stop-tail-notice.js +9 -2
  201. package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
  202. package/dist/core/runner/stream-settle-backstop.js +1 -0
  203. package/dist/core/runner/task-start-doors.js +6 -3
  204. package/dist/core/runner/terminal-account.d.ts +10 -1
  205. package/dist/core/runner/terminal-account.js +23 -3
  206. package/dist/core/runner/tool-face-overlay.d.ts +2 -11
  207. package/dist/core/runner/tool-face-overlay.js +39 -0
  208. package/dist/core/runner/trim-stretch.js +7 -2
  209. package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
  210. package/dist/core/runner-deps.d.ts +13 -10
  211. package/dist/core/scheduler.d.ts +47 -7
  212. package/dist/core/scheduler.js +19 -7
  213. package/dist/core/secret-env.d.ts +60 -37
  214. package/dist/core/secret-env.js +45 -48
  215. package/dist/core/sensitive-path-policy.js +14 -7
  216. package/dist/core/session-checkout.d.ts +3 -0
  217. package/dist/core/session-checkout.js +1 -0
  218. package/dist/core/session-store.d.ts +12 -6
  219. package/dist/core/session-store.js +26 -6
  220. package/dist/core/session.d.ts +31 -8
  221. package/dist/core/shell-read-silence.js +1 -0
  222. package/dist/core/store-contracts/checkpoint-store-contract.js +17 -0
  223. package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
  224. package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
  225. package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
  226. package/dist/core/store-contracts/session-store-contract.js +87 -3
  227. package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
  228. package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
  229. package/dist/core/task-event.d.ts +11 -3
  230. package/dist/core/task-notification.d.ts +97 -10
  231. package/dist/core/task-notification.js +129 -5
  232. package/dist/core/task-registry-shared.d.ts +12 -1
  233. package/dist/core/task-registry-shared.js +3 -1
  234. package/dist/core/task-registry-workflow.d.ts +1 -1
  235. package/dist/core/task-registry-workflow.js +9 -1
  236. package/dist/core/task-registry.d.ts +39 -2
  237. package/dist/core/task-registry.js +76 -12
  238. package/dist/core/task-result.d.ts +13 -0
  239. package/dist/core/task-spec-members.d.ts +3 -1
  240. package/dist/core/task-spec-members.js +11 -3
  241. package/dist/core/task-spec.d.ts +57 -23
  242. package/dist/core/tool-catalog-entries.js +4 -0
  243. package/dist/core/tool-face-reader.js +1 -1
  244. package/dist/core/tool-face.d.ts +7 -0
  245. package/dist/core/tool-face.js +1 -0
  246. package/dist/core/tool-mount-facts.d.ts +5 -3
  247. package/dist/core/tool-mount-facts.js +4 -3
  248. package/dist/core/tool-mount-plan.d.ts +7 -3
  249. package/dist/core/tool-mount-plan.js +11 -5
  250. package/dist/core/tool-mount-static.d.ts +2 -2
  251. package/dist/core/tool-mount-static.js +28 -14
  252. package/dist/core/tool-registry.d.ts +33 -1
  253. package/dist/core/tool-registry.js +33 -0
  254. package/dist/core/tool-result-store.d.ts +19 -2
  255. package/dist/core/tool-result-store.js +51 -2
  256. package/dist/core/tool-roster.d.ts +16 -0
  257. package/dist/core/tool-roster.js +6 -0
  258. package/dist/core/tool-spec.d.ts +13 -4
  259. package/dist/core/tools.d.ts +6 -0
  260. package/dist/core/tools.js +1 -1
  261. package/dist/core/user-attachment.d.ts +5 -1
  262. package/dist/core/user-attachment.js +14 -7
  263. package/dist/core/wiring-manifest.d.ts +89 -29
  264. package/dist/core/wiring-manifest.js +44 -4
  265. package/dist/core/workflow-journal-store.d.ts +53 -10
  266. package/dist/core/workflow-journal-store.js +27 -4
  267. package/dist/core/workflow-run-store-contract.js +16 -0
  268. package/dist/core/workflow-run-store.d.ts +9 -7
  269. package/dist/core/workflow-run-store.js +4 -1
  270. package/dist/engine/execution-env/node-execution-env.js +3 -1
  271. package/dist/engine/harness/messages.d.ts +1 -1
  272. package/dist/engine/harness/messages.js +2 -1
  273. package/dist/engine/harness/types.d.ts +24 -1
  274. package/dist/engine/harness/types.js +10 -0
  275. package/dist/engine/llm/types.d.ts +5 -7
  276. package/dist/engine/loop/types.d.ts +2 -0
  277. package/dist/engine/lsp/node-lsp-manager.js +2 -1
  278. package/dist/engine/session/import-validate.js +6 -1
  279. package/dist/engine/session/session.d.ts +15 -2
  280. package/dist/engine/session/session.js +35 -5
  281. package/dist/index.d.ts +27 -12
  282. package/dist/index.js +20 -8
  283. package/dist/orchestration/run-workflow-tool.js +40 -32
  284. package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
  285. package/dist/orchestration/workflow-park-adoption.js +47 -12
  286. package/dist/orchestration/workflow-stop.d.ts +128 -0
  287. package/dist/orchestration/workflow-stop.js +156 -0
  288. package/dist/orchestration/workflow.d.ts +30 -6
  289. package/dist/orchestration/workflow.js +117 -54
  290. package/dist/prompts/manager-recipe.d.ts +18 -0
  291. package/dist/prompts/manager-recipe.js +24 -0
  292. package/dist/stores/file/adoption/marker.d.ts +2 -27
  293. package/dist/stores/file/adoption/marker.js +12 -0
  294. package/dist/stores/file/index.d.ts +1 -1
  295. package/dist/stores/file/index.js +1 -1
  296. package/dist/stores/file/permission-rule-store.d.ts +3 -1
  297. package/dist/stores/file/permission-rule-store.js +0 -1
  298. package/dist/stores/file/workflow-journal-store.d.ts +16 -3
  299. package/dist/stores/file/workflow-journal-store.js +93 -5
  300. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  301. package/dist/tools/artifact/artifact-tool.js +11 -6
  302. package/dist/tools/fs/file-read-check.d.ts +45 -11
  303. package/dist/tools/fs/file-read-check.js +200 -57
  304. package/dist/tools/fs/file-write-check.js +9 -3
  305. package/dist/tools/fs/index.d.ts +8 -7
  306. package/dist/tools/fs/index.js +4 -4
  307. package/dist/tools/fs/judged-reads.d.ts +51 -0
  308. package/dist/tools/fs/judged-reads.js +68 -0
  309. package/dist/tools/fs/read-deny-home.d.ts +1 -1
  310. package/dist/tools/fs/read-deny-home.js +5 -5
  311. package/dist/tools/fs/read-deny.d.ts +33 -8
  312. package/dist/tools/fs/read-deny.js +114 -25
  313. package/dist/tools/fs/safety.d.ts +12 -1
  314. package/dist/tools/fs/safety.js +16 -3
  315. package/dist/tools/fs/shell-read-check.d.ts +25 -5
  316. package/dist/tools/fs/shell-read-check.js +100 -15
  317. package/dist/tools/fs/shell-read-establish.d.ts +9 -0
  318. package/dist/tools/fs/shell-read-establish.js +34 -14
  319. package/dist/tools/fs/shell-read-judge.d.ts +13 -1
  320. package/dist/tools/fs/shell-read-judge.js +26 -7
  321. package/dist/tools/fs/shell-read-plan.d.ts +5 -0
  322. package/dist/tools/fs/shell-read-write-targets.js +17 -9
  323. package/dist/tools/scheduler-store-move.d.ts +74 -0
  324. package/dist/tools/scheduler-store-move.js +103 -0
  325. package/dist/tools/scheduler-tools.d.ts +43 -29
  326. package/dist/tools/scheduler-tools.js +161 -118
  327. package/package.json +2 -2
  328. package/test/export-surface.snapshot.json +173 -3
  329. package/wire-changes/answers/core-stores-sql@7.72.0.json +12 -0
  330. package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
  331. package/wire-changes/answers/core@7.72.0.json +84 -0
  332. package/wire-changes/answers/core@7.73.0.json +216 -0
  333. package/wire-changes/answers/mods-kernel@7.72.0.json +7 -0
  334. package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
  335. package/wire-changes/answers/primitives@7.72.0.json +6 -0
  336. package/wire-changes/answers/primitives@7.73.0.json +12 -0
  337. package/wire-changes/answers/wiki-gate@7.72.0.json +7 -0
  338. package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
  339. package/wire-changes/core-stores-sql@7.72.0.json +215 -0
  340. package/wire-changes/core-stores-sql@7.73.0.json +326 -0
  341. package/wire-changes/core@7.72.0.json +2426 -0
  342. package/wire-changes/core@7.73.0.json +6480 -0
  343. package/wire-changes/mods-kernel@7.72.0.json +147 -0
  344. package/wire-changes/mods-kernel@7.73.0.json +147 -0
  345. package/wire-changes/primitives@7.72.0.json +143 -0
  346. package/wire-changes/primitives@7.73.0.json +227 -0
  347. package/wire-changes/wiki-gate@7.72.0.json +145 -0
  348. package/wire-changes/wiki-gate@7.73.0.json +145 -0
@@ -1,5 +1,5 @@
1
1
  import { canonicalRootsOnce, isAbsence, observeEnvironment } from "./shell-read-environment.js";
2
- import { anchorSpelling, belowOwnProcessLink, isAbsoluteForFamily, normalizeAbsPathLexically, ownProcessSpelling, pathFamilyOf, withinAnyRoot } from "./safety.js";
2
+ import { anchorSpelling, belowOwnProcessLink, isAbsoluteForFamily, isBareOwnDescriptorLink, normalizeAbsPathLexically, ownProcessSpelling, pathFamilyOf, withinAnyRoot } from "./safety.js";
3
3
  import { landingsOf, noteClimb, readingsAt, withClimbedPatterns, withClimbedViews, withFloorClimbs } from "./shell-climb.js";
4
4
  import { boundaryIsTheSandbox } from "../../core/remote-env.js";
5
5
  import { resolveOperandSpellings, tildeNamesAnAccount } from "./bash-readonly-classifier.js";
@@ -160,11 +160,20 @@ function lexicalReadsOf(candidate, boundary, placed) {
160
160
  }
161
161
  function writtenByText(plan, boundary) {
162
162
  const targets = new Set();
163
- const writers = new Map();
163
+ const runs = [];
164
+ const writes = [];
165
+ let concurrent = false;
164
166
  const speculativeSeen = new Set();
165
167
  let unplaced = false;
166
168
  const walk = (p) => {
167
169
  for (const s of p.segments) {
170
+ for (const n of s.nested)
171
+ walk(n);
172
+ const wrote = [];
173
+ runs.push(s);
174
+ writes.push(wrote);
175
+ if (p.shape.backgrounded || s.connector === "|")
176
+ concurrent = true;
168
177
  for (const c of s.reads) {
169
178
  if (c.speculative === undefined || c.expands !== false || c.bases === "unmodelled")
170
179
  continue;
@@ -190,16 +199,19 @@ function writtenByText(plan, boundary) {
190
199
  else {
191
200
  const t = normalizeAbsPathLexically(r.target);
192
201
  targets.add(t);
193
- writers.set(t, (writers.get(t) ?? new Set()).add(s));
202
+ wrote.push(t);
194
203
  }
195
204
  }
196
205
  }
197
- for (const n of s.nested)
198
- walk(n);
199
206
  }
200
207
  };
201
208
  walk(plan);
202
- return { targets, unplaced, writers };
209
+ return { targets, unplaced, runs, writes, concurrent };
210
+ }
211
+ export function writtenOnLineBefore(writes, at, concurrent, place) {
212
+ const fold = (p) => p.normalize("NFC").toLowerCase();
213
+ const here = fold(place);
214
+ return writes.some((paths, i) => i !== at && (i < at || concurrent) && paths.some((w) => withinAnyRoot([fold(w)], here) || withinAnyRoot([here], fold(w))));
203
215
  }
204
216
  function unfollowedBackupReads(j, boundary, cause) {
205
217
  const named = sedBackupNames(j.followed.operand.spelled, j.followed.suffix).flatMap((name) => lexicalReadsOf({ ...j.candidate, spelled: name }, boundary));
@@ -451,12 +463,22 @@ function establishLegOver(seen, readRoots) {
451
463
  return undefined;
452
464
  return { value: joinUnder(parent.value, leaf), exact: parent.exact, ...(parent.missing !== undefined ? { missing: parent.missing } : {}) };
453
465
  };
466
+ const takenAsSpelled = (candidate, spelling, spellings, origin) => ({
467
+ candidate,
468
+ established: "lexical",
469
+ target: normalizeAbsPathLexically(spelling),
470
+ spellings,
471
+ ...(origin !== undefined ? { origin } : {}),
472
+ });
454
473
  const canonicalReadOf = async (candidate, spelling, spellings, established, origin, canonicalKnown, signal, seat = "landing", climbs) => {
455
- const real = canonicalKnown !== undefined ? { value: canonicalKnown, exact: true } : candidate.provenance === "traversal_root" && belowOwnProcessLink(spelling, true) ? { value: spelling, exact: false } : seat === "entry" ? await entryOf(spelling, signal, climbs) : await resolve(spelling, signal, candidate.face === "write", WRITE_LINK_HOPS, climbs);
474
+ const unplacedOwnLink = belowOwnProcessLink(spelling, candidate.provenance === "traversal_root");
475
+ if (isBareOwnDescriptorLink(spelling) && !unplacedOwnLink)
476
+ return takenAsSpelled(candidate, spelling, spellings, origin);
477
+ const real = canonicalKnown !== undefined ? { value: canonicalKnown, exact: true } : unplacedOwnLink ? { value: spelling, exact: false } : seat === "entry" ? await entryOf(spelling, signal, climbs) : await resolve(spelling, signal, candidate.face === "write", WRITE_LINK_HOPS, climbs);
456
478
  if (real === undefined) {
457
479
  if (resolverIsAuthoritative)
458
480
  return { candidate, established: "unestablishable", spellings, ...(origin !== undefined ? { origin } : {}), cause: `"${spelling}" cannot be resolved to verify where it reads`, unresolved: true };
459
- return { candidate, established: "lexical", target: normalizeAbsPathLexically(spelling), spellings, ...(origin !== undefined ? { origin } : {}) };
481
+ return takenAsSpelled(candidate, spelling, spellings, origin);
460
482
  }
461
483
  if (!real.exact && real.missing !== true) {
462
484
  return { candidate, established: "unestablishable", spellings, ...(origin !== undefined ? { origin } : {}), cause: `"${spelling}" cannot be resolved to verify where it reads`, unresolved: true };
@@ -548,15 +570,13 @@ function establishLegOver(seen, readRoots) {
548
570
  for (const r of lexicalReadsOf(fact.candidate, boundary)) {
549
571
  if (r.established !== "lexical" || r.target === undefined)
550
572
  return undefined;
551
- const place = normalizeAbsPathLexically(r.target);
552
- for (const [t, by] of written.writers)
553
- if ((t === place || withinAnyRoot([place], t)) && [...by].some((s) => s !== segment))
554
- return undefined;
573
+ if (writtenOnLineBefore(written.writes, written.runs.indexOf(segment), written.concurrent, normalizeAbsPathLexically(r.target)))
574
+ return undefined;
555
575
  const at = fact.seat === "entry" ? await entryOf(r.target, signal) : await resolve(r.target, signal);
556
576
  if (at === undefined || (!at.exact && at.missing !== true))
557
577
  return undefined;
558
- const info = at.missing === true && !at.exact ? undefined : await env.fileInfo(at.value, signal);
559
- const here = info === undefined ? false : info.ok ? info.value.kind === "directory" : isAbsence(info.error.code) ? false : undefined;
578
+ const info = at.missing === true && !at.exact ? undefined : fact.seat === "entry" ? await env.fileInfo(at.value, signal) : await env.listDir(at.value, signal);
579
+ const here = info === undefined ? false : info.ok ? Array.isArray(info.value) || info.value.kind === "directory" : isAbsence(info.error.code) ? false : undefined;
560
580
  if (here === undefined || (directory !== undefined && directory !== here))
561
581
  return undefined;
562
582
  directory = here;
@@ -27,7 +27,7 @@ import type { ReadCandidate, ShellReadPlan, ShellReadSegment } from "./shell-rea
27
27
  import type { Incomplete, ObservedFilesystem } from "./shell-read-environment.js";
28
28
  import type { WriteSeat } from "./shell-read-write-targets.js";
29
29
  import { type ContainmentFace } from "./containment-face.js";
30
- import { type JudgedPathRow } from "./read-deny.js";
30
+ import { type JudgedPathRow, type ReadDenyFinding, type ReadDenyRootAnswer } from "./read-deny.js";
31
31
  import type { AssertAllKeysHandled } from "../../core/ask-origin.js";
32
32
  /** WHAT the judge found about a command — a closed set, registered in `docs/CLOSED-SETS.md`. */
33
33
  export declare const SHELL_READ_FINDINGS: readonly ["deny_hit", "outside_roots", "unestablishable", "declined", "identity_changed", "unanswered", "target_unavailable", "none"];
@@ -241,6 +241,17 @@ export interface ShellReadBoundary extends BashReadonlyRootBoundary {
241
241
  /** Does the row `writeDenyMatch` named (its rule) guard the READ face too — a `Read(…)` rule on the write face
242
242
  * ({@link import("./read-deny.js").WriteDenyMatcher.guardsReads})? Read once per hit, so the refusal says which family refused. */
243
243
  readonly writeDenyGuardsReads?: (pattern: string) => boolean;
244
+ /** The write table's rows named by or below a subtree removal/rename target (`WriteDenyMatcher.rowUnderRoot`). */
245
+ readonly writeDenyUnder?: (resolvedPath: string) => ReadDenyRootAnswer;
246
+ /** The write table's unanchored rows (`WriteDenyMatcher.unanchoredRows`, never empty here) and the first of them whose leading
247
+ * name one directory entry name matches (`WriteDenyMatcher.rowLedByName`): what the station searches a recursive removal's
248
+ * subtree for, under its own bound ({@link import("./shell-read-check.js").SUBTREE_SEARCH_MS}). PRESENT-IFF such a row. */
249
+ readonly writeDenyNamed?: {
250
+ readonly rows: readonly string[];
251
+ readonly ledBy: (entryName: string) => string | null;
252
+ };
253
+ /** The write table's rows AT or BELOW a path (`WriteDenyMatcher.rowAtOrBelow`): read by `writesPlaced` via {@link denyRowAtOrBelow}. */
254
+ readonly writeDenyAtOrBelow?: (resolvedPath: string) => string | null;
244
255
  /** The read table's rows AT or BELOW a path (`readDenySeat`'s `denyAtOrBelow`, read-deny.ts): read by the station's
245
256
  * `writesPlaced` fact only, through {@link denyRowAtOrBelow}. */
246
257
  readonly denyAtOrBelow?: (resolvedPath: string) => string | null;
@@ -355,6 +366,7 @@ export interface ReadFinding {
355
366
  readonly face?: "write";
356
367
  readonly readRow?: true;
357
368
  readonly under?: true;
369
+ readonly lookup?: ReadDenyFinding["lookup"];
358
370
  };
359
371
  /** A `deny_hit` on no row: the read's target is a process-private /proc file (`isProcSensitiveFile`, safety.ts — the set the
360
372
  * file read tools refuse), or a tree walk's root holds such files (`holdsProcSensitiveFile`); the view it was matched on. */
@@ -64,19 +64,32 @@ export function judgeRead(read, boundary) {
64
64
  if (pattern !== null)
65
65
  return { read, kind: "deny_hit", deny: { pattern, matchedView: folded, ...(writeTarget ? { face: "write", ...(boundary.writeDenyGuardsReads?.(pattern) === true ? { readRow: true } : {}) } : {}) }, containment: writeTarget ? writeContainmentOf(read, boundary) : containmentOf(read, boundary) };
66
66
  }
67
- if (!writeTarget && read.candidate.provenance === "traversal_root" && boundary.denyUnder !== undefined) {
67
+ const checksUnder = writeTarget ? read.candidate.subtree !== undefined && read.written !== undefined : read.candidate.provenance === "traversal_root";
68
+ const denyUnder = writeTarget ? boundary.writeDenyUnder : boundary.denyUnder;
69
+ if (checksUnder && denyUnder !== undefined) {
68
70
  let unplaced;
69
71
  for (const view of [...(read.target !== undefined ? [read.target] : []), ...read.spellings, ...(read.hops ?? [])]) {
70
72
  const folded = normalizeAbsPathLexically(view);
71
- const under = boundary.denyUnder(folded);
72
- if (typeof under === "string")
73
- return { read, kind: "deny_hit", deny: { pattern: under, matchedView: folded, under: true }, containment: containmentOf(read, boundary) };
73
+ const under = denyUnder(folded);
74
+ if (typeof under === "string") {
75
+ return {
76
+ read,
77
+ kind: "deny_hit",
78
+ deny: {
79
+ pattern: under,
80
+ matchedView: folded,
81
+ under: true,
82
+ ...(writeTarget ? { face: "write", ...(boundary.writeDenyGuardsReads?.(under) === true ? { readRow: true } : {}) } : {}),
83
+ },
84
+ containment: writeTarget ? writeContainmentOf(read, boundary) : containmentOf(read, boundary),
85
+ };
86
+ }
74
87
  if (under !== null && typeof under === "object")
75
88
  unplaced ??= under.unplaced;
76
89
  }
77
90
  if (unplaced !== undefined) {
78
91
  const cause = `the home-anchored deny row "${unplaced}" cannot be placed (no home directory is known for this environment), so "${read.target ?? read.candidate.spelled}" may hold it`;
79
- return { read: { ...read, cause }, kind: "unanswered", denyRowUnasked: true, containment: containmentOf(read, boundary) };
92
+ return { read: { ...read, cause }, kind: "unanswered", denyRowUnasked: true, containment: writeTarget ? writeContainmentOf(read, boundary) : containmentOf(read, boundary) };
80
93
  }
81
94
  }
82
95
  }
@@ -138,14 +151,20 @@ function personAllowAdmits(read, boundary) {
138
151
  return hit !== undefined && hit.unreadable === undefined;
139
152
  }
140
153
  export function denyRowAtOrBelow(read, boundary, carriesContent) {
141
- if (boundary.writeDenyMatch !== undefined)
154
+ const views = [...(read.target !== undefined ? [read.target] : []), ...read.spellings];
155
+ if (boundary.writeDenyAtOrBelow !== undefined) {
156
+ if (views.some((view) => boundary.writeDenyAtOrBelow(normalizeAbsPathLexically(view)) !== null))
157
+ return true;
158
+ }
159
+ else if (boundary.writeDenyMatch !== undefined) {
142
160
  return true;
161
+ }
143
162
  if (!carriesContent)
144
163
  return false;
145
164
  const atOrBelow = boundary.denyAtOrBelow;
146
165
  if (atOrBelow === undefined)
147
166
  return false;
148
- return [...(read.target !== undefined ? [read.target] : []), ...read.spellings].some((view) => atOrBelow(normalizeAbsPathLexically(view)) !== null);
167
+ return views.some((view) => atOrBelow(normalizeAbsPathLexically(view)) !== null);
149
168
  }
150
169
  export function denyFloorShadowsOf(candidates) {
151
170
  return candidates.flatMap((c) => (c.floorSpelled === undefined ? [] : [{ spelled: c.floorSpelled, raw: c.raw, provenance: c.provenance, expands: globInWord(readOfText(c.raw).word) ? "glob" : false, bases: [], denyOnly: true, ...(c.face !== undefined ? { face: c.face } : {}), ...(c.face === "write" && c.expands === "unresolvable" && !/[$`]/.test(c.floorSpelled) ? { twin: true } : {}) }]));
@@ -101,6 +101,11 @@ export interface ReadCandidate {
101
101
  /** A WRITE target (a `>`-family redirection, a `sed` `w` file, a file-writing command's operand): established like a
102
102
  * read, judged on the WRITE face — the write deny rows, then the write roots where written — never as a read. */
103
103
  readonly face?: "write";
104
+ /** On a write target: the command takes the entire subtree at this path with it — `removed` (`rm -r`, `find -delete`'s
105
+ * starting points) or `moved` (an `mv` source) — so a write-facing deny row whose location lies beneath it refuses the
106
+ * operation ({@link ShellReadBoundary.writeDenyUnder}); below a `removed` one an unanchored row is also searched for by
107
+ * name ({@link ShellReadBoundary.writeDenyNamed}). A moved subtree keeps its names, so an unanchored row still meets them. */
108
+ readonly subtree?: "removed" | "moved";
104
109
  /** A reading the station takes where no row says the program opens the word — a word of a program with no row, a
105
110
  * role only another implementation reads — so the filesystem decides it: `containment` = the spelling always meets
106
111
  * the deny rows and is a containment candidate only where it exists; `whole` = a whole word (`NAME=value`, an option
@@ -51,7 +51,7 @@ function writeOwnersOf(segment) {
51
51
  function writeTargetsOf(segment) {
52
52
  const out = [];
53
53
  const writeOnly = new Set();
54
- const write = (c, seats, written, child, onlyIf, through) => void out.push({ candidate: { ...c, face: "write", ...(through === true ? { through } : {}) }, ...(seats !== undefined ? { seats } : {}), ...(written !== undefined ? { written } : {}), ...(child === true ? { child } : {}), ...(onlyIf !== undefined ? { onlyIf } : {}) });
54
+ const write = (c, seats, written, child, onlyIf, through, subtree) => void out.push({ candidate: { ...c, face: "write", ...(through === true ? { through } : {}), ...(subtree !== undefined ? { subtree } : {}) }, ...(seats !== undefined ? { seats } : {}), ...(written !== undefined ? { written } : {}), ...(child === true ? { child } : {}), ...(onlyIf !== undefined ? { onlyIf } : {}) });
55
55
  for (const r of segment.redirects)
56
56
  if (r.direction === "out" && r.target !== undefined)
57
57
  write(r.target, undefined, undefined, undefined, undefined, true);
@@ -63,7 +63,8 @@ function writeTargetsOf(segment) {
63
63
  const all = writeReadings(row, args);
64
64
  const selected = implementationsOf(row).flatMap((view) => selectedOptions(view, args, "one-implementation"));
65
65
  const moved = [...new Set(selected.flatMap((o) => o.writesAt ?? []))];
66
- return { row, words, program, all, readings: all.filter((r) => r.written.length > 0 || (r.unexplained && r.operandRole !== undefined)), override: moved.length > 0 ? moved : undefined, beyondOperands: selected.some((o) => o.effect === "writes" || o.effect === "executes") };
66
+ const recursiveRemove = row.key === "rm" && selected.some((o) => o.selects === "traversal");
67
+ return { row, words, program, all, readings: all.filter((r) => r.written.length > 0 || (r.unexplained && r.operandRole !== undefined)), override: moved.length > 0 ? moved : undefined, beyondOperands: selected.some((o) => o.effect === "writes" || o.effect === "executes"), recursiveRemove };
67
68
  });
68
69
  const edited = new Map();
69
70
  for (const c of segment.reads) {
@@ -99,7 +100,8 @@ function writeTargetsOf(segment) {
99
100
  const seats = stated ? [...new Set(roles.flatMap((role) => o.override ?? role.seats ?? ["landing"]))] : undefined;
100
101
  const written = unexplained || roles.some((role) => role.writtenAt === undefined) ? undefined : [...new Set(roles.flatMap((role) => role.writtenAt ?? []))];
101
102
  const speculative = readings < o.all.length && roles.every((role) => role.effect === "edit-in-place") ? { candidate: c, holds: "present" } : undefined;
102
- write(c, seats, written, undefined, speculative, !unexplained && writesThrough(roles, o.row, o.words) ? true : undefined);
103
+ const subtree = o.recursiveRemove ? "removed" : o.row.key === "mv" && (unexplained || o.all.some((r) => r.copy !== undefined && r.copy.sources.some((idx) => at.has(idx)))) ? "moved" : undefined;
104
+ write(c, seats, written, undefined, speculative, !unexplained && writesThrough(roles, o.row, o.words) ? true : undefined, subtree);
103
105
  if (roles.some((role) => role.effect === "edit-in-place") && c.expands === false)
104
106
  edited.set(o, [...(edited.get(o) ?? []), { candidate: c, ...(speculative !== undefined ? { onlyIf: speculative } : {}) }]);
105
107
  }
@@ -107,12 +109,12 @@ function writeTargetsOf(segment) {
107
109
  writeOnly.add(c);
108
110
  }
109
111
  for (const o of owners) {
110
- for (const c of copyDestinationChildren(segment, o.row, o.words, o.all))
111
- write(c, ["landing", "entry"], undefined, true);
112
+ for (const { candidate, onlyIf } of copyDestinationChildren(segment, o.row, o.words, o.all))
113
+ write(candidate, ["landing", "entry"], undefined, true, onlyIf);
112
114
  out.push(...backupTargetsOf(edited.get(o) ?? [], o.readings, o.override));
113
115
  }
114
116
  for (const c of walkRemovalTargetsOf(segment))
115
- write(c, ["landing", "entry"]);
117
+ write(c, ["landing", "entry"], undefined, undefined, undefined, undefined, "removed");
116
118
  const readWords = new Set();
117
119
  for (const o of owners) {
118
120
  if (!o.program)
@@ -140,6 +142,11 @@ function copyDestinationChildren(segment, row, words, readings) {
140
142
  const candidateOf = (raw) => segment.reads.find((c) => c.raw === raw && WORD_PROVENANCES.has(c.provenance));
141
143
  const start = segment.programStart;
142
144
  const children = new Map();
145
+ const keep = (key, candidate, onlyIf) => {
146
+ const prev = children.get(key);
147
+ if (prev === undefined || (prev.onlyIf !== undefined && onlyIf === undefined))
148
+ children.set(key, onlyIf !== undefined ? { candidate, onlyIf } : { candidate });
149
+ };
143
150
  for (const r of readings) {
144
151
  if (r.copy === undefined)
145
152
  continue;
@@ -152,18 +159,19 @@ function copyDestinationChildren(segment, row, words, readings) {
152
159
  const destRole = r.written.find((w) => w.at === destination?.at)?.role;
153
160
  if (destCandidate !== undefined && destRole !== undefined && passesUnasked({ ...destCandidate, face: "write", ...(writesThrough([destRole], row, words) ? { through: true } : {}) }))
154
161
  continue;
162
+ const destDirFact = destination !== undefined && destCandidate !== undefined ? { candidate: destCandidate, holds: "directory" } : undefined;
155
163
  for (const at of sources) {
156
164
  const src = words[at];
157
165
  const source = candidateOf(src.raw);
158
166
  if (source !== undefined && source.expands !== false) {
159
167
  if (destination !== undefined)
160
168
  continue;
161
- children.set(`\0${source.raw}`, source);
169
+ keep(`\0${source.raw}`, source);
162
170
  }
163
171
  const child = `${dest.spelled.replace(/\/+$/, "")}/${src.spelled.replace(/\/+$/, "").split("/").pop() ?? ""}`;
164
- if (child.endsWith("/") || children.has(child))
172
+ if (child.endsWith("/"))
165
173
  continue;
166
- children.set(child, destCandidate !== undefined && source !== undefined ? renamed(destCandidate, child) : { spelled: child, raw: src.raw, provenance: "unlisted_word", expands: "unresolvable", bases: [] });
174
+ keep(child, destCandidate !== undefined && source !== undefined ? renamed(destCandidate, child) : { spelled: child, raw: src.raw, provenance: "unlisted_word", expands: "unresolvable", bases: [] }, destDirFact);
167
175
  }
168
176
  }
169
177
  return [...children.values()];
@@ -0,0 +1,74 @@
1
+ /** One stored row as the store's owner hands it to a move. Only these members are read; the rest of the row is the owner's and comes back untouched. */
2
+ export interface SchedulerStoredRow {
3
+ /** The key the row is filed under now. */
4
+ readonly scope: unknown;
5
+ /** The row's stored `ScheduledIntent.lifetime` (absent when the store kept none). */
6
+ readonly lifetime?: unknown;
7
+ /** The row's stored `ScheduledIntent.mode` (absent when the store kept none). */
8
+ readonly mode?: unknown;
9
+ /** The row's stored label. */
10
+ readonly label?: unknown;
11
+ /** The session the row's firings go to (the `SchedulerContext.sessionId` it was scheduled with): the owner of a session-lane row's key. */
12
+ readonly sessionId?: unknown;
13
+ /** The owner's own word on the row's lane (`"session"` / `"durable"`), for a row whose stored members do not name it. Read by the forward move only. */
14
+ readonly lane?: unknown;
15
+ }
16
+ /** Why a move hands a row back unmoved — the closed set of {@link SchedulerStoreMove.refused}'s `code`. */
17
+ export type SchedulerRowRefusalCode =
18
+ /** Its key is not a non-empty string (forward) or not a lane key (rollback), or a `lifetime` / `mode` / `lane` is outside the seam's words. */
19
+ "row_invalid"
20
+ /** Neither its stored members nor a stated `lane` name its lane: no `lifetime: "session"`, no `mode`, and the wakeup's label — a session
21
+ * wakeup on a store that kept no `mode`, or a job that was given that label. */
22
+ | "lane_unknown"
23
+ /** The stated `lane` is not the lane its stored members name. */
24
+ | "lane_contradicted"
25
+ /** A session-lane row whose firing destination (`sessionId`) is not a non-empty string: it has no owner to key. */
26
+ | "destination_unknown"
27
+ /** Rollback: a session-lane row and a durable-lane row of one owner would share one bare key, where an older release lists and stops
28
+ * them as one lane's rows. */
29
+ | "bare_key_shared"
30
+ /** Forward: rows filed under different bare keys would share one lane key (two explicit session scopes over one session id — two
31
+ * tenants' `A/42` and `B/42` — where the lane key is the session id alone): the move does not merge them. */
32
+ | "lane_key_shared";
33
+ /** What a move answers: the rows it placed, each with the key to file it under, in input order; and the rows it did not, each with why. */
34
+ export interface SchedulerStoreMove<R extends SchedulerStoredRow> {
35
+ readonly moved: ReadonlyArray<{
36
+ readonly row: R;
37
+ readonly scope: string;
38
+ }>;
39
+ readonly refused: ReadonlyArray<{
40
+ readonly row: R;
41
+ readonly code: SchedulerRowRefusalCode;
42
+ readonly reason: string;
43
+ }>;
44
+ }
45
+ /** A whole store, as its owner hands it to a move: its rows and its own key declaration (the `scopeKeys` it declares today). */
46
+ export interface SchedulerStoreRows<R extends SchedulerStoredRow> {
47
+ readonly scopeKeys?: unknown;
48
+ readonly rows: readonly R[];
49
+ }
50
+ /**
51
+ * Pure forward placement: each row filed under bare keys (a release before 7.72.0: a key was its owner alone) gets one lane key or one
52
+ * refusal — `session:<sessionId>` for a row of the session lane (keyed by the session it fires into: an older factory took an explicit
53
+ * session scope, so the bare key need not be the session), `durable:<bare key>` for a row of the durable lane. A row's lane is read off its
54
+ * stored `lifetime` and `mode` as scheduling picks it (`lifetime: "session"` or `mode: "session-wakeup"` ⇒ session); a row with no `mode`,
55
+ * a `lifetime` absent or `"durable"` and the wakeup's label is refused `lane_unknown` unless the owner states its `lane`. A bare key is never
56
+ * judged by its head. Rows of different bare keys that would land on one lane key are not merged: each is refused `lane_key_shared` (only
57
+ * the rows of this call are compared).
58
+ *
59
+ * Pure and write-free: call it once to move a store (writing `moved` and `scopeKeys: "lane"` in one write once `refused` is empty), or on
60
+ * every read in a backend that keeps bare keys stored and answers lane keys at its port (that backend's duties are written at
61
+ * `SchedulerCapability.schedulerCapabilities.scopeKeys`). `store.scopeKeys` is the stored rows' form (absent or `"bare"`; `"lane"` is refused
62
+ * whole, `config.invalid_argument`).
63
+ */
64
+ export declare function migrateSchedulerStore<R extends SchedulerStoredRow>(store: SchedulerStoreRows<R>): SchedulerStoreMove<R>;
65
+ /**
66
+ * The rollback: every row of a store that declares lane keys with its bare key (the lane name and its `:` taken off), for an older release.
67
+ * Two lanes' rows that would share one bare key — a session whose id is some isolation scope's name — are both refused `bare_key_shared`:
68
+ * an older release reads them as one lane's rows, so one owner's stop or delete reaches the other's. Settle them (remove one, or keep
69
+ * the newer release) before rolling back. A row whose key is not a lane key is refused `row_invalid`.
70
+ *
71
+ * `store.scopeKeys` must be `"lane"` (anything else is refused whole, `config.invalid_argument`). Write `moved` together with the
72
+ * declaration `scopeKeys: "bare"`, and only when `refused` is empty.
73
+ */
74
+ export declare function rollbackSchedulerStore<R extends SchedulerStoredRow>(store: SchedulerStoreRows<R>): SchedulerStoreMove<R>;
@@ -0,0 +1,103 @@
1
+ import { codedRefusal } from "../core/thrown-value.js";
2
+ import { describeRejectedValue } from "../core/tool-search-setting.js";
3
+ import { isLaneKey, laneKeyOf, laneOfIntent, WAKEUP_LABEL } from "./scheduler-tools.js";
4
+ const LIFETIMES = [undefined, "durable", "session"];
5
+ const MODES = [undefined, "task", "session-wakeup"];
6
+ const LANES = [undefined, "session", "durable"];
7
+ function rowsOf(store, direction, wanted, want) {
8
+ const held = store;
9
+ if (typeof held !== "object" || held === null || !Array.isArray(held.rows)) {
10
+ throw codedRefusal("config.invalid_argument", `the scheduler store handed to the ${direction} is ${describeRejectedValue(held)}, not { scopeKeys?, rows: [...] } — the ${direction} reads the whole store at once.`);
11
+ }
12
+ const keys = held.scopeKeys;
13
+ if (!wanted(keys))
14
+ throw codedRefusal("config.invalid_argument", `the scheduler store declares scopeKeys ${describeRejectedValue(keys)}; the ${direction} runs on a store that declares ${want} — it runs once, and a key's head does not say which form it is.`);
15
+ return held.rows;
16
+ }
17
+ function storedLaneOf(row) {
18
+ if (!LIFETIMES.includes(row.lifetime))
19
+ return { fault: `its lifetime is ${describeRejectedValue(row.lifetime)}, not "durable", "session" or absent` };
20
+ if (!MODES.includes(row.mode))
21
+ return { fault: `its mode is ${describeRejectedValue(row.mode)}, not "task", "session-wakeup" or absent` };
22
+ const lane = laneOfIntent(row);
23
+ return lane === "durable" && row.mode === undefined && row.label === WAKEUP_LABEL ? "unknown" : lane;
24
+ }
25
+ export function migrateSchedulerStore(store) {
26
+ const rows = rowsOf(store, "move", (keys) => keys === undefined || keys === "bare", 'none, or "bare"');
27
+ const placed = [];
28
+ const refused = [];
29
+ const refuse = (row, code, reason) => void refused.push({ row, code, reason });
30
+ for (const row of rows) {
31
+ const key = row?.scope;
32
+ if (typeof key !== "string" || key === "") {
33
+ refuse(row, "row_invalid", `the row's key is ${describeRejectedValue(key)}, not a non-empty string — there is no owner to file it under.`);
34
+ continue;
35
+ }
36
+ const stored = storedLaneOf(row);
37
+ if (typeof stored === "object") {
38
+ refuse(row, "row_invalid", `${stored.fault} — its lane cannot be read.`);
39
+ continue;
40
+ }
41
+ if (!LANES.includes(row.lane)) {
42
+ refuse(row, "row_invalid", `its stated lane is ${describeRejectedValue(row.lane)}, not "session", "durable" or absent.`);
43
+ continue;
44
+ }
45
+ const stated = row.lane;
46
+ if (stated !== undefined && stored !== "unknown" && stated !== stored) {
47
+ refuse(row, "lane_contradicted", `its stated lane is "${stated}", but its stored lifetime and mode file it on the ${stored} lane.`);
48
+ continue;
49
+ }
50
+ const lane = stated ?? stored;
51
+ if (lane === "unknown") {
52
+ refuse(row, "lane_unknown", `it carries ${row.lifetime === undefined ? "no lifetime" : `lifetime "${String(row.lifetime)}"`} and no mode, and the wakeup's label "${WAKEUP_LABEL}" — a row both lanes may have written: a session wakeup on a store that kept no mode, or a job given that label. State its lane.`);
53
+ continue;
54
+ }
55
+ if (lane === "durable") {
56
+ placed.push({ row, scope: laneKeyOf("durable", key), from: key });
57
+ continue;
58
+ }
59
+ const destination = row.sessionId;
60
+ if (typeof destination !== "string" || destination === "") {
61
+ refuse(row, "destination_unknown", `it is a session-lane row whose session (sessionId) is ${describeRejectedValue(destination)}, not a non-empty string — the session it fires into is the owner of its key.`);
62
+ continue;
63
+ }
64
+ placed.push({ row, scope: laneKeyOf("session", destination), from: key });
65
+ }
66
+ const moved = unshared(placed, refused, (shared, froms) => ({
67
+ code: "lane_key_shared",
68
+ reason: `its lane key ${JSON.stringify(shared)} would be shared by rows filed under ${froms.map((k) => JSON.stringify(k)).join(" and ")}: the move does not merge two owners' rows into one lane.`,
69
+ }));
70
+ return { moved, refused };
71
+ }
72
+ function unshared(placed, refused, why) {
73
+ const fromsOf = new Map();
74
+ for (const p of placed)
75
+ fromsOf.set(p.scope, (fromsOf.get(p.scope) ?? new Set()).add(p.from));
76
+ const moved = [];
77
+ for (const p of placed) {
78
+ const froms = fromsOf.get(p.scope);
79
+ if (froms.size === 1)
80
+ moved.push({ row: p.row, scope: p.scope });
81
+ else
82
+ refused.push({ row: p.row, ...why(p.scope, [...froms]) });
83
+ }
84
+ return moved;
85
+ }
86
+ export function rollbackSchedulerStore(store) {
87
+ const rows = rowsOf(store, "rollback", (keys) => keys === "lane", '"lane"');
88
+ const placed = [];
89
+ const refused = [];
90
+ for (const row of rows) {
91
+ const key = row?.scope;
92
+ const lane = ["session", "durable"].find((l) => isLaneKey(l, key));
93
+ if (lane === undefined)
94
+ refused.push({ row, code: "row_invalid", reason: `the row's key is ${describeRejectedValue(key)}, not a lane's name, \`:\` and a non-empty owner.` });
95
+ else
96
+ placed.push({ row, scope: key.slice(lane.length + 1), from: key });
97
+ }
98
+ const moved = unshared(placed, refused, (_shared, froms) => ({
99
+ code: "bare_key_shared",
100
+ reason: `its bare key is shared by ${froms.map((k) => JSON.stringify(k)).join(" and ")}: an older release lists and stops them as one lane's rows.`,
101
+ }));
102
+ return { moved, refused };
103
+ }
@@ -19,24 +19,23 @@
19
19
  * `createHandsToolkit` —— 与 present_plan/AskUserQuestion 同:这些工具都在 prepare-task 单独挂,那里有 spec.principal)。
20
20
  */
21
21
  import type { AgentTool, ExecutionEnv, Result } from "../internal/harness-types.js";
22
- import { SchedulerError, type SchedulerContext, type ScheduledTaskId, type ScheduledTaskSummary } from "../core/scheduler.js";
23
- import { type IsolationScopeHolder } from "../core/isolation-scope.js";
22
+ import { SchedulerError, type SchedulerReading, type SchedulerContext, type ScheduledTaskId, type ScheduledTaskSummary } from "../core/scheduler.js";
23
+ import { type EngineNotice } from "../core/engine-notice.js";
24
24
  export declare const SCHEDULE_WAKEUP_TOOL_NAME = "ScheduleWakeup";
25
25
  /** CronCreate-based autonomous-loop 哨兵(CC `Ldt`)。loop runtime(部署侧)在 fire 时解析回 autonomous-loop 指令。 */
26
26
  export declare const AUTONOMOUS_LOOP_SENTINEL = "<<autonomous-loop>>";
27
27
  /** ScheduleWakeup(dynamic-pacing)哨兵(CC `ePe`)——ScheduleWakeup 一律用 `-dynamic` 变体。 */
28
28
  export declare const AUTONOMOUS_LOOP_DYNAMIC_SENTINEL = "<<autonomous-loop-dynamic>>";
29
+ /** wakeup intent 的保留 label:老 backend(list 不回 mode)时 stop 过滤的兜底键;店的迁移据它认出判不清车道的行。 */
30
+ export declare const WAKEUP_LABEL = "loop-wakeup";
29
31
  /** Runner-held 上下文 + run-stop 出口,工具工厂闭包捕获(模型触不到)。 */
30
32
  export interface SchedulerToolContext {
31
- /**
32
- * **会话腿**的越界隔离键(Runner 填 sessionId ?? isolation scope ?? taskId)。durable 腿不用这条链——它的键由
33
- * {@link durableScopeOf} 从 isolation scope 独立铸(ruled 2026-08-03,见该函数注释)。
34
- */
35
- scope: string;
36
- /** 任务的人(`TaskSpec.principal`),原样交给宿主 capability;缺 `isolationScope` 时也是 durable 腿的键。 */
33
+ /** 任务的人(`TaskSpec.principal`),原样交给宿主 capability;缺 `isolationScope` 时也是 durable lane 的主人。 */
37
34
  principal?: string;
38
- /** 任务的 isolation scope(`TaskSpec.isolationScope`):在场时 durable 腿按它铸键(同一人的另一 scope 看不见这条 job)。 */
35
+ /** 任务的 isolation scope(`TaskSpec.isolationScope`):在场时是 durable lane 的主人(同一人的另一 scope 看不见这条 job)。 */
39
36
  isolationScope?: string;
37
+ /** The session the run belongs to: the owner of the session lane (`session:<sessionId>`). Absent = the run has no session lane — the
38
+ * readers read the durable lane alone, and the two tools that schedule do not mount. */
40
39
  sessionId?: string;
41
40
  taskConfig?: unknown;
42
41
  /** The user's zone as the engine judged it ({@link SchedulerContext.timeZone}); rides every context handed to the backend. */
@@ -45,26 +44,32 @@ export interface SchedulerToolContext {
45
44
  * 保留(human-suspend saga 等共用同一 runner 原语;prepare-task 仍注入)——当前 scheduler 三件不消费。 */
46
45
  requestStopAfterTurn?: () => void;
47
46
  }
48
- /** The key of the SESSION lane: the session's id; else the run's isolation scope (its member when it sets one, else its principal); else
49
- * the task's id; else the anonymous working scope ({@link ANONYMOUS_SCOPE}). The one place this chain is written — the Runner mounts the scheduler tools with it, and a host that
50
- * derives the lanes of a session it holds calls it with that session's facts. `sessionId` and `taskId` read as `??` (an empty string is a
51
- * value), the isolation scope as {@link isolationScopeOf} reads it (a principal of `""` is none). A key that comes out as anything but a
52
- * non-empty string (an empty session id or task id) is refused, not handed on. */
53
- export declare function sessionLaneScopeOf(c: IsolationScopeHolder & {
54
- readonly sessionId?: string | undefined;
55
- readonly taskId?: string | undefined;
56
- }): string;
57
- /** The two lanes of one run, each as the context the scheduler backend isolates by. */
47
+ /** The two lanes, the closed set a scheduler key starts with. */
48
+ export type LaneName = "session" | "durable";
49
+ /** The one spelling of a scheduler key: the lane's name, `:`, the owner. */
50
+ export declare function laneKeyOf(lane: LaneName, owner: string): string;
51
+ /** Whether `scope` is a key of `lane`: the lane's name, `:` and at least one more character. */
52
+ export declare function isLaneKey(lane: LaneName, scope: unknown): boolean;
53
+ /** The lanes of one run, each as the context the scheduler backend isolates by. Which lane an entry is on is {@link laneOfIntent}'s answer. */
58
54
  export interface SchedulerLanes {
59
- /** Jobs bound to this session (`lifetime: "session"`, and every pending wakeup). Keyed by {@link SchedulerToolContext.scope}. */
60
- readonly session: SchedulerContext;
61
- /** Jobs filed under the run's isolation scope (`lifetime: "durable"`): visible from every session of that scope. */
55
+ /** The entries bound to this session — a session-lifetime job, or a session wakeup (it ends with the session only on a backend that vouches for
56
+ * the session lifetime) — keyed `session:<session id>`. Absent for a run with no session. */
57
+ readonly session?: SchedulerContext;
58
+ /** Every other entry of the run's isolation scope, keyed `durable:<isolation scope>` (else `durable:default`): visible from every session of that scope. */
62
59
  readonly durable: SchedulerContext;
63
60
  }
64
- /** The lanes of the run whose factory context is `ctx`: the session lane keyed by `ctx.scope` as handed (a caller's explicit scope stands),
65
- * the durable lane by the isolation scope (else `"default"`). Derive `ctx` from a verified session / run — see the note above. A lane whose
66
- * key is not a non-empty string is refused. */
61
+ /** The lanes of the run whose factory context is `ctx`: the session lane keyed by `ctx.sessionId` when it has one, the durable lane by the
62
+ * isolation scope (else `default`). Derive `ctx` from a verified session / run — see the note above. A lane whose key does not come out
63
+ * of its lane's form (an empty or non-string session id) is refused. */
67
64
  export declare function schedulerLanesOf(ctx: SchedulerToolContext): SchedulerLanes;
65
+ /** The lane an intent is filed on: the session lane for a job that ends with its session (`lifetime: "session"`) or a session wakeup
66
+ * (`mode: "session-wakeup"`), the durable lane for every other. Read off those two members only, never the label (a label is the
67
+ * caller's word: CronCreate may write the wakeup's label too). Scheduling picks a lane with it, and the store's move
68
+ * (`migrateSchedulerStore`) reads a stored row's lane with it. */
69
+ export declare function laneOfIntent(intent: {
70
+ readonly lifetime?: unknown;
71
+ readonly mode?: unknown;
72
+ }): LaneName;
68
73
  /**
69
74
  * Every entry of both lanes: the session lane's rows, then the durable lane's rows the first did not already list (a backend that does
70
75
  * not filter by scope answers both lanes with the same rows; one id prints once). A lane that fails fails the whole read with that lane's
@@ -73,8 +78,8 @@ export declare function schedulerLanesOf(ctx: SchedulerToolContext): SchedulerLa
73
78
  */
74
79
  export declare function listScheduled(env: ExecutionEnv, lanes: SchedulerLanes): Promise<Result<ScheduledTaskSummary[], SchedulerError>>;
75
80
  /**
76
- * Cancel one entry by id, on the lane that holds it. A bare id no longer names its lane, so the holder is found by listing both lanes
77
- * (both belong to this run, so reading both widens nothing): a backend whose `cancel` answers ok for an id it does not hold would let a
81
+ * Cancel one entry by id, on the lane that holds it (a run with the durable lane alone asks that lane, with no listing). A bare id no longer
82
+ * names its lane, so the holder is found by listing the lanes in order until one holds it (both belong to this run, so reading both widens nothing): a backend whose `cancel` answers ok for an id it does not hold would let a
78
83
  * first-lane try swallow the call while the real job on the other lane stays live under a receipt that says it is gone. Only when the
79
84
  * listing is unavailable, or the id is not in the snapshot, does it fall back to trying each lane in turn — and then only a `not_found`
80
85
  * is a reason to ask the next lane. The result is the backend's own: `not_found` for an id neither lane holds, `unsupported` for an
@@ -94,6 +99,15 @@ export declare function cutToUnits(text: string, limit: number): string;
94
99
  */
95
100
  export declare function cronToHuman(expr: string): string;
96
101
  /**
97
- * 构建三个 scheduler 工具(仅当 `env` 暴露 {@link SchedulerCapability} 且 `supported:true`)。否则返回 `[]`(INERT)。
102
+ * Tells the operator, once per declared value per notice sink, that the env's scheduler backend offers the seam but does not declare its
103
+ * store holds lane keys — so {@link createSchedulerTools} mounts nothing on it (`config.scheduler_store_unmoved`). Every other reading:
104
+ * silence. `scheduler` is the leg's one reading of the declaration ({@link readSchedulerDeclaration}).
98
105
  */
99
- export declare function createSchedulerTools(env: ExecutionEnv, ctx: SchedulerToolContext): AgentTool[];
106
+ export declare function announceSchedulerStoreUnmoved(scheduler: SchedulerReading, onNotice: ((notice: EngineNotice) => void) | undefined): void;
107
+ /**
108
+ * 构建 scheduler 工具(仅当 `env` 暴露 {@link SchedulerCapability}、`supported:true` 且店声明 `scopeKeys: "lane"`;否则返回 `[]`,INERT):有会话 = CronCreate /
109
+ * CronDelete / CronList / ScheduleWakeup 四只,无会话 = CronDelete / CronList 两只(只读写 durable lane)。`scheduler` = 一条腿对声明的那一次读数
110
+ * ({@link readSchedulerDeclaration};缺 = 这里读一次):挂载与工具执行时读的能力位都出自它;CronList / CronDelete 经 {@link listScheduled} /
111
+ * {@link cancelScheduled},那两只读口每次调用再读一次声明(声明在实例寿命内不变)。
112
+ */
113
+ export declare function createSchedulerTools(env: ExecutionEnv, ctx: SchedulerToolContext, scheduler?: SchedulerReading): AgentTool[];