@bastani/atomic 0.9.2 → 0.9.3-alpha.2

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 (606) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +2 -2
  3. package/dist/builtin/cursor/CHANGELOG.md +15 -0
  4. package/dist/builtin/cursor/README.md +2 -1
  5. package/dist/builtin/cursor/package.json +2 -2
  6. package/dist/builtin/cursor/src/cursor-models-raw.json +2 -9
  7. package/dist/builtin/cursor/src/model-mapper.ts +14 -3
  8. package/dist/builtin/cursor/src/proto/protobuf-codec-base64.ts +22 -0
  9. package/dist/builtin/cursor/src/proto/protobuf-codec-request.ts +53 -13
  10. package/dist/builtin/cursor/src/proto/protobuf-codec-wire.ts +24 -7
  11. package/dist/builtin/cursor/src/proto/protobuf-codec.ts +3 -2
  12. package/dist/builtin/cursor/src/stream.ts +5 -11
  13. package/dist/builtin/cursor/src/transport-types.ts +3 -0
  14. package/dist/builtin/cursor/src/transport.ts +1 -0
  15. package/dist/builtin/intercom/package.json +1 -1
  16. package/dist/builtin/mcp/CHANGELOG.md +6 -0
  17. package/dist/builtin/mcp/direct-tools.ts +4 -2
  18. package/dist/builtin/mcp/package.json +1 -1
  19. package/dist/builtin/mcp/proxy-call.ts +3 -1
  20. package/dist/builtin/mcp/utils.ts +18 -7
  21. package/dist/builtin/subagents/CHANGELOG.md +20 -0
  22. package/dist/builtin/subagents/README.md +6 -6
  23. package/dist/builtin/subagents/agents/code-simplifier.md +7 -6
  24. package/dist/builtin/subagents/agents/codebase-analyzer.md +5 -4
  25. package/dist/builtin/subagents/agents/codebase-locator.md +3 -3
  26. package/dist/builtin/subagents/agents/codebase-online-researcher.md +10 -10
  27. package/dist/builtin/subagents/agents/codebase-pattern-finder.md +4 -4
  28. package/dist/builtin/subagents/agents/codebase-research-analyzer.md +3 -3
  29. package/dist/builtin/subagents/agents/codebase-research-locator.md +4 -4
  30. package/dist/builtin/subagents/agents/debugger.md +5 -5
  31. package/dist/builtin/subagents/agents/worker.md +56 -0
  32. package/dist/builtin/subagents/package.json +1 -1
  33. package/dist/builtin/subagents/skills/subagent/SKILL.md +11 -11
  34. package/dist/builtin/subagents/src/agents/agent-loaders.ts +3 -5
  35. package/dist/builtin/subagents/src/agents/agent-management-helpers.ts +3 -3
  36. package/dist/builtin/subagents/src/extension/fanout-child.ts +1 -0
  37. package/dist/builtin/subagents/src/extension/index.ts +6 -3
  38. package/dist/builtin/subagents/src/extension/schemas.ts +2 -7
  39. package/dist/builtin/subagents/src/intercom/result-intercom.ts +4 -3
  40. package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +1 -4
  41. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +15 -1
  42. package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +35 -1
  43. package/dist/builtin/subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +1 -1
  44. package/dist/builtin/subagents/src/runs/shared/nested-render.ts +2 -2
  45. package/dist/builtin/subagents/src/runs/shared/pi-args.ts +2 -1
  46. package/dist/builtin/subagents/src/runs/shared/subagent-prompt-runtime.ts +4 -2
  47. package/dist/builtin/subagents/src/shared/types-async.ts +1 -0
  48. package/dist/builtin/subagents/src/shared/types-depth.ts +5 -5
  49. package/dist/builtin/subagents/src/shared/types-runtime.ts +2 -1
  50. package/dist/builtin/subagents/src/slash/prompt-template-bridge.ts +27 -5
  51. package/dist/builtin/subagents/src/tui/render-event-formatting.ts +2 -2
  52. package/dist/builtin/subagents/src/tui/render-layout.ts +27 -4
  53. package/dist/builtin/subagents/src/tui/render-result-animation.ts +22 -31
  54. package/dist/builtin/subagents/src/tui/render-result-compact.ts +6 -6
  55. package/dist/builtin/subagents/src/tui/render-result.ts +20 -19
  56. package/dist/builtin/subagents/src/tui/render-status-progress.ts +3 -3
  57. package/dist/builtin/subagents/src/tui/render-widget.ts +46 -7
  58. package/dist/builtin/subagents/src/tui/render.ts +2 -2
  59. package/dist/builtin/web-access/package.json +1 -1
  60. package/dist/builtin/workflows/CHANGELOG.md +56 -0
  61. package/dist/builtin/workflows/README.md +3 -3
  62. package/dist/builtin/workflows/builtin/goal-artifacts.ts +11 -6
  63. package/dist/builtin/workflows/builtin/goal-ledger.ts +33 -1
  64. package/dist/builtin/workflows/builtin/goal-prompts.ts +23 -28
  65. package/dist/builtin/workflows/builtin/goal-reducer.ts +2 -2
  66. package/dist/builtin/workflows/builtin/goal-reports.ts +2 -5
  67. package/dist/builtin/workflows/builtin/goal-review.ts +1 -1
  68. package/dist/builtin/workflows/builtin/goal-runner.ts +10 -17
  69. package/dist/builtin/workflows/builtin/open-claude-design-feedback.ts +3 -3
  70. package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +1 -3
  71. package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +1 -1
  72. package/dist/builtin/workflows/builtin/ralph-core.ts +7 -17
  73. package/dist/builtin/workflows/builtin/ralph-runner.ts +11 -18
  74. package/dist/builtin/workflows/builtin/shared-prompts.ts +1 -1
  75. package/dist/builtin/workflows/package.json +1 -1
  76. package/dist/builtin/workflows/src/authoring.d.ts +1 -1
  77. package/dist/builtin/workflows/src/durable/backend.ts +343 -0
  78. package/dist/builtin/workflows/src/durable/child-primitive.ts +79 -0
  79. package/dist/builtin/workflows/src/durable/dbos-backend.ts +421 -0
  80. package/dist/builtin/workflows/src/durable/dbos-envelope.ts +171 -0
  81. package/dist/builtin/workflows/src/durable/factory.ts +96 -0
  82. package/dist/builtin/workflows/src/durable/file-backend.ts +433 -0
  83. package/dist/builtin/workflows/src/durable/index.ts +73 -0
  84. package/dist/builtin/workflows/src/durable/resume-catalog.ts +217 -0
  85. package/dist/builtin/workflows/src/durable/resume-runtime.ts +299 -0
  86. package/dist/builtin/workflows/src/durable/scoped-backend.ts +171 -0
  87. package/dist/builtin/workflows/src/durable/stage-primitive.ts +284 -0
  88. package/dist/builtin/workflows/src/durable/tool-primitive.ts +180 -0
  89. package/dist/builtin/workflows/src/durable/types.ts +168 -0
  90. package/dist/builtin/workflows/src/durable/ui-primitive.ts +96 -0
  91. package/dist/builtin/workflows/src/engine/options.ts +3 -0
  92. package/dist/builtin/workflows/src/engine/primitives/parallel.ts +2 -2
  93. package/dist/builtin/workflows/src/engine/primitives/task.ts +4 -4
  94. package/dist/builtin/workflows/src/engine/primitives/ui.ts +22 -8
  95. package/dist/builtin/workflows/src/engine/primitives/workflow.ts +8 -0
  96. package/dist/builtin/workflows/src/engine/run-durable-finalize.ts +69 -0
  97. package/dist/builtin/workflows/src/engine/run-durable-stage-session.ts +31 -0
  98. package/dist/builtin/workflows/src/engine/run.ts +148 -6
  99. package/dist/builtin/workflows/src/engine/runtime.ts +8 -2
  100. package/dist/builtin/workflows/src/extension/config-loader.ts +35 -15
  101. package/dist/builtin/workflows/src/extension/discovery.ts +20 -8
  102. package/dist/builtin/workflows/src/extension/extension-factory.ts +6 -12
  103. package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +5 -1
  104. package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +4 -2
  105. package/dist/builtin/workflows/src/extension/runtime.ts +48 -9
  106. package/dist/builtin/workflows/src/extension/wiring.ts +1 -1
  107. package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +143 -4
  108. package/dist/builtin/workflows/src/runs/background/quit.ts +61 -0
  109. package/dist/builtin/workflows/src/runs/background/status.ts +1 -0
  110. package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +5 -5
  111. package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +74 -33
  112. package/dist/builtin/workflows/src/runs/foreground/executor-stage-context.ts +20 -1
  113. package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +8 -7
  114. package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +1 -0
  115. package/dist/builtin/workflows/src/runs/foreground/executor-stage-types.ts +1 -1
  116. package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +19 -2
  117. package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +4 -0
  118. package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +10 -10
  119. package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +5 -1
  120. package/dist/builtin/workflows/src/runs/foreground/stage-runner-send-user-message.ts +25 -0
  121. package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +3 -0
  122. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +16 -0
  123. package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +20 -0
  124. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +23 -1
  125. package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +30 -1
  126. package/dist/builtin/workflows/src/shared/store-public-types.ts +6 -2
  127. package/dist/builtin/workflows/src/shared/store-run-methods.ts +12 -6
  128. package/dist/builtin/workflows/src/shared/types.ts +55 -0
  129. package/dist/builtin/workflows/src/tui/dispatch-confirm.ts +11 -10
  130. package/dist/builtin/workflows/src/tui/graph-view-constants.ts +1 -1
  131. package/dist/builtin/workflows/src/tui/graph-view-graph-render.ts +41 -0
  132. package/dist/builtin/workflows/src/tui/graph-view-input.ts +82 -24
  133. package/dist/builtin/workflows/src/tui/graph-view-render.ts +7 -0
  134. package/dist/builtin/workflows/src/tui/graph-view-state.ts +22 -2
  135. package/dist/builtin/workflows/src/tui/graph-view-types.ts +4 -5
  136. package/dist/builtin/workflows/src/tui/overlay-adapter.ts +9 -11
  137. package/dist/builtin/workflows/src/tui/stage-chat-view-footer-status.ts +9 -3
  138. package/dist/builtin/workflows/src/tui/stage-chat-view-input.ts +11 -2
  139. package/dist/builtin/workflows/src/tui/stage-chat-view-live-events.ts +35 -0
  140. package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +51 -17
  141. package/dist/builtin/workflows/src/tui/stage-chat-view-status.ts +36 -0
  142. package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +5 -1
  143. package/dist/builtin/workflows/src/tui/stage-chat-view.ts +3 -1
  144. package/dist/builtin/workflows/src/tui/status-list.ts +14 -2
  145. package/dist/builtin/workflows/src/tui/widget.ts +23 -8
  146. package/dist/builtin/workflows/src/tui/workflow-attach-pane-types.ts +5 -4
  147. package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +8 -8
  148. package/dist/builtin/workflows/src/tui/workflow-resume-selector.ts +151 -0
  149. package/dist/cli/args.d.ts.map +1 -1
  150. package/dist/cli/args.js +9 -9
  151. package/dist/cli/args.js.map +1 -1
  152. package/dist/config-self-update.d.ts.map +1 -1
  153. package/dist/config-self-update.js +3 -4
  154. package/dist/config-self-update.js.map +1 -1
  155. package/dist/config.d.ts.map +1 -1
  156. package/dist/config.js +4 -5
  157. package/dist/config.js.map +1 -1
  158. package/dist/core/agent-session-bash.d.ts +1 -0
  159. package/dist/core/agent-session-bash.d.ts.map +1 -1
  160. package/dist/core/agent-session-bash.js +1 -0
  161. package/dist/core/agent-session-bash.js.map +1 -1
  162. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  163. package/dist/core/agent-session-tool-registry.js +23 -0
  164. package/dist/core/agent-session-tool-registry.js.map +1 -1
  165. package/dist/core/bash-executor.d.ts +2 -0
  166. package/dist/core/bash-executor.d.ts.map +1 -1
  167. package/dist/core/bash-executor.js +1 -0
  168. package/dist/core/bash-executor.js.map +1 -1
  169. package/dist/core/compaction/compaction.d.ts +29 -0
  170. package/dist/core/compaction/compaction.d.ts.map +1 -1
  171. package/dist/core/compaction/compaction.js +36 -1
  172. package/dist/core/compaction/compaction.js.map +1 -1
  173. package/dist/core/compaction/context-compaction-metrics.d.ts +14 -2
  174. package/dist/core/compaction/context-compaction-metrics.d.ts.map +1 -1
  175. package/dist/core/compaction/context-compaction-metrics.js +50 -1
  176. package/dist/core/compaction/context-compaction-metrics.js.map +1 -1
  177. package/dist/core/compaction/context-compaction-prompt.d.ts.map +1 -1
  178. package/dist/core/compaction/context-compaction-prompt.js +2 -0
  179. package/dist/core/compaction/context-compaction-prompt.js.map +1 -1
  180. package/dist/core/compaction/context-compaction-runner.d.ts.map +1 -1
  181. package/dist/core/compaction/context-compaction-runner.js +1 -1
  182. package/dist/core/compaction/context-compaction-runner.js.map +1 -1
  183. package/dist/core/compaction/context-deletion-application.d.ts.map +1 -1
  184. package/dist/core/compaction/context-deletion-application.js +5 -5
  185. package/dist/core/compaction/context-deletion-application.js.map +1 -1
  186. package/dist/core/compaction/context-deletion-targets.d.ts +2 -0
  187. package/dist/core/compaction/context-deletion-targets.d.ts.map +1 -1
  188. package/dist/core/compaction/context-deletion-targets.js +23 -3
  189. package/dist/core/compaction/context-deletion-targets.js.map +1 -1
  190. package/dist/core/compaction/context-deletion-tool-definitions.d.ts +6 -0
  191. package/dist/core/compaction/context-deletion-tool-definitions.d.ts.map +1 -1
  192. package/dist/core/compaction/context-deletion-tool-definitions.js.map +1 -1
  193. package/dist/core/compaction/context-deletion-tools.d.ts.map +1 -1
  194. package/dist/core/compaction/context-deletion-tools.js +18 -10
  195. package/dist/core/compaction/context-deletion-tools.js.map +1 -1
  196. package/dist/core/compaction/context-transcript-analysis.d.ts.map +1 -1
  197. package/dist/core/compaction/context-transcript-analysis.js +2 -4
  198. package/dist/core/compaction/context-transcript-analysis.js.map +1 -1
  199. package/dist/core/copilot-gemini-tool-arguments.d.ts.map +1 -1
  200. package/dist/core/copilot-gemini-tool-arguments.js +2 -60
  201. package/dist/core/copilot-gemini-tool-arguments.js.map +1 -1
  202. package/dist/core/extensions/context-types.d.ts +2 -0
  203. package/dist/core/extensions/context-types.d.ts.map +1 -1
  204. package/dist/core/extensions/context-types.js.map +1 -1
  205. package/dist/core/extensions/index.d.ts +2 -2
  206. package/dist/core/extensions/index.d.ts.map +1 -1
  207. package/dist/core/extensions/index.js +1 -1
  208. package/dist/core/extensions/index.js.map +1 -1
  209. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  210. package/dist/core/extensions/loader-virtual-modules.js +57 -32
  211. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  212. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  213. package/dist/core/extensions/runner-context.js +11 -0
  214. package/dist/core/extensions/runner-context.js.map +1 -1
  215. package/dist/core/extensions/tool-events.d.ts +13 -13
  216. package/dist/core/extensions/tool-events.d.ts.map +1 -1
  217. package/dist/core/extensions/tool-events.js +3 -3
  218. package/dist/core/extensions/tool-events.js.map +1 -1
  219. package/dist/core/extensions/types.d.ts +1 -1
  220. package/dist/core/extensions/types.d.ts.map +1 -1
  221. package/dist/core/extensions/types.js +1 -1
  222. package/dist/core/extensions/types.js.map +1 -1
  223. package/dist/core/flattened-tool-arguments.d.ts +18 -0
  224. package/dist/core/flattened-tool-arguments.d.ts.map +1 -1
  225. package/dist/core/flattened-tool-arguments.js +104 -0
  226. package/dist/core/flattened-tool-arguments.js.map +1 -1
  227. package/dist/core/messages.d.ts +1 -0
  228. package/dist/core/messages.d.ts.map +1 -1
  229. package/dist/core/messages.js +46 -1
  230. package/dist/core/messages.js.map +1 -1
  231. package/dist/core/sdk-exports.d.ts +1 -1
  232. package/dist/core/sdk-exports.d.ts.map +1 -1
  233. package/dist/core/sdk-exports.js +1 -1
  234. package/dist/core/sdk-exports.js.map +1 -1
  235. package/dist/core/sdk-types.d.ts +2 -2
  236. package/dist/core/sdk-types.d.ts.map +1 -1
  237. package/dist/core/sdk-types.js.map +1 -1
  238. package/dist/core/sdk.d.ts.map +1 -1
  239. package/dist/core/sdk.js +12 -0
  240. package/dist/core/sdk.js.map +1 -1
  241. package/dist/core/session-manager-core.d.ts +15 -7
  242. package/dist/core/session-manager-core.d.ts.map +1 -1
  243. package/dist/core/session-manager-core.js +20 -9
  244. package/dist/core/session-manager-core.js.map +1 -1
  245. package/dist/core/session-manager-entries.d.ts +2 -2
  246. package/dist/core/session-manager-entries.d.ts.map +1 -1
  247. package/dist/core/session-manager-entries.js +9 -3
  248. package/dist/core/session-manager-entries.js.map +1 -1
  249. package/dist/core/session-manager-history.d.ts.map +1 -1
  250. package/dist/core/session-manager-history.js +2 -1
  251. package/dist/core/session-manager-history.js.map +1 -1
  252. package/dist/core/session-manager-list.d.ts +3 -3
  253. package/dist/core/session-manager-list.d.ts.map +1 -1
  254. package/dist/core/session-manager-list.js +27 -8
  255. package/dist/core/session-manager-list.js.map +1 -1
  256. package/dist/core/session-manager-storage.d.ts +3 -1
  257. package/dist/core/session-manager-storage.d.ts.map +1 -1
  258. package/dist/core/session-manager-storage.js +55 -12
  259. package/dist/core/session-manager-storage.js.map +1 -1
  260. package/dist/core/session-manager-tool-dependencies.d.ts +10 -0
  261. package/dist/core/session-manager-tool-dependencies.d.ts.map +1 -0
  262. package/dist/core/session-manager-tool-dependencies.js +133 -0
  263. package/dist/core/session-manager-tool-dependencies.js.map +1 -0
  264. package/dist/core/session-manager-types.d.ts +22 -0
  265. package/dist/core/session-manager-types.d.ts.map +1 -1
  266. package/dist/core/session-manager-types.js.map +1 -1
  267. package/dist/core/session-manager.d.ts +2 -2
  268. package/dist/core/session-manager.d.ts.map +1 -1
  269. package/dist/core/session-manager.js +1 -1
  270. package/dist/core/session-manager.js.map +1 -1
  271. package/dist/core/settings-manager-basic-accessors.d.ts +4 -0
  272. package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
  273. package/dist/core/settings-manager-basic-accessors.js +18 -0
  274. package/dist/core/settings-manager-basic-accessors.js.map +1 -1
  275. package/dist/core/settings-manager-resource-accessors.d.ts +4 -0
  276. package/dist/core/settings-manager-resource-accessors.d.ts.map +1 -1
  277. package/dist/core/settings-manager-resource-accessors.js +15 -0
  278. package/dist/core/settings-manager-resource-accessors.js.map +1 -1
  279. package/dist/core/settings-types.d.ts +11 -0
  280. package/dist/core/settings-types.d.ts.map +1 -1
  281. package/dist/core/settings-types.js.map +1 -1
  282. package/dist/core/system-prompt.d.ts +1 -1
  283. package/dist/core/system-prompt.d.ts.map +1 -1
  284. package/dist/core/system-prompt.js +3 -2
  285. package/dist/core/system-prompt.js.map +1 -1
  286. package/dist/core/tools/artifact-protocol.d.ts +11 -0
  287. package/dist/core/tools/artifact-protocol.d.ts.map +1 -0
  288. package/dist/core/tools/artifact-protocol.js +76 -0
  289. package/dist/core/tools/artifact-protocol.js.map +1 -0
  290. package/dist/core/tools/artifacts.d.ts +18 -0
  291. package/dist/core/tools/artifacts.d.ts.map +1 -0
  292. package/dist/core/tools/artifacts.js +90 -0
  293. package/dist/core/tools/artifacts.js.map +1 -0
  294. package/dist/core/tools/bash-async-jobs.d.ts +20 -0
  295. package/dist/core/tools/bash-async-jobs.d.ts.map +1 -0
  296. package/dist/core/tools/bash-async-jobs.js +59 -0
  297. package/dist/core/tools/bash-async-jobs.js.map +1 -0
  298. package/dist/core/tools/bash-async-output.d.ts +10 -0
  299. package/dist/core/tools/bash-async-output.d.ts.map +1 -0
  300. package/dist/core/tools/bash-async-output.js +80 -0
  301. package/dist/core/tools/bash-async-output.js.map +1 -0
  302. package/dist/core/tools/bash-interceptor.d.ts +10 -0
  303. package/dist/core/tools/bash-interceptor.d.ts.map +1 -0
  304. package/dist/core/tools/bash-interceptor.js +39 -0
  305. package/dist/core/tools/bash-interceptor.js.map +1 -0
  306. package/dist/core/tools/bash-leading-cd.d.ts +7 -0
  307. package/dist/core/tools/bash-leading-cd.d.ts.map +1 -0
  308. package/dist/core/tools/bash-leading-cd.js +59 -0
  309. package/dist/core/tools/bash-leading-cd.js.map +1 -0
  310. package/dist/core/tools/bash-pty-native.d.ts +14 -0
  311. package/dist/core/tools/bash-pty-native.d.ts.map +1 -0
  312. package/dist/core/tools/bash-pty-native.js +71 -0
  313. package/dist/core/tools/bash-pty-native.js.map +1 -0
  314. package/dist/core/tools/bash.d.ts +28 -17
  315. package/dist/core/tools/bash.d.ts.map +1 -1
  316. package/dist/core/tools/bash.js +152 -35
  317. package/dist/core/tools/bash.js.map +1 -1
  318. package/dist/core/tools/block-resolver.d.ts +16 -0
  319. package/dist/core/tools/block-resolver.d.ts.map +1 -0
  320. package/dist/core/tools/block-resolver.js +74 -0
  321. package/dist/core/tools/block-resolver.js.map +1 -0
  322. package/dist/core/tools/conflict-registry.d.ts +16 -0
  323. package/dist/core/tools/conflict-registry.d.ts.map +1 -0
  324. package/dist/core/tools/conflict-registry.js +44 -0
  325. package/dist/core/tools/conflict-registry.js.map +1 -0
  326. package/dist/core/tools/directory-tree.d.ts +13 -0
  327. package/dist/core/tools/directory-tree.d.ts.map +1 -0
  328. package/dist/core/tools/directory-tree.js +81 -0
  329. package/dist/core/tools/directory-tree.js.map +1 -0
  330. package/dist/core/tools/edit.d.ts +4 -29
  331. package/dist/core/tools/edit.d.ts.map +1 -1
  332. package/dist/core/tools/edit.js +136 -228
  333. package/dist/core/tools/edit.js.map +1 -1
  334. package/dist/core/tools/fetch-url.d.ts +74 -0
  335. package/dist/core/tools/fetch-url.d.ts.map +1 -0
  336. package/dist/core/tools/fetch-url.js +518 -0
  337. package/dist/core/tools/fetch-url.js.map +1 -0
  338. package/dist/core/tools/find.d.ts +27 -9
  339. package/dist/core/tools/find.d.ts.map +1 -1
  340. package/dist/core/tools/find.js +400 -176
  341. package/dist/core/tools/find.js.map +1 -1
  342. package/dist/core/tools/glob-path-utils.d.ts +8 -0
  343. package/dist/core/tools/glob-path-utils.d.ts.map +1 -0
  344. package/dist/core/tools/glob-path-utils.js +26 -0
  345. package/dist/core/tools/glob-path-utils.js.map +1 -0
  346. package/dist/core/tools/grep.d.ts +12 -0
  347. package/dist/core/tools/grep.d.ts.map +1 -1
  348. package/dist/core/tools/grep.js +141 -17
  349. package/dist/core/tools/grep.js.map +1 -1
  350. package/dist/core/tools/hashline-engine/apply.d.ts +11 -0
  351. package/dist/core/tools/hashline-engine/apply.d.ts.map +1 -0
  352. package/dist/core/tools/hashline-engine/apply.js +752 -0
  353. package/dist/core/tools/hashline-engine/apply.js.map +1 -0
  354. package/dist/core/tools/hashline-engine/block.d.ts +40 -0
  355. package/dist/core/tools/hashline-engine/block.d.ts.map +1 -0
  356. package/dist/core/tools/hashline-engine/block.js +117 -0
  357. package/dist/core/tools/hashline-engine/block.js.map +1 -0
  358. package/dist/core/tools/hashline-engine/diff-preview.d.ts +15 -0
  359. package/dist/core/tools/hashline-engine/diff-preview.d.ts.map +1 -0
  360. package/dist/core/tools/hashline-engine/diff-preview.js +98 -0
  361. package/dist/core/tools/hashline-engine/diff-preview.js.map +1 -0
  362. package/dist/core/tools/hashline-engine/format.d.ts +71 -0
  363. package/dist/core/tools/hashline-engine/format.d.ts.map +1 -0
  364. package/dist/core/tools/hashline-engine/format.js +178 -0
  365. package/dist/core/tools/hashline-engine/format.js.map +1 -0
  366. package/dist/core/tools/hashline-engine/fs.d.ts +81 -0
  367. package/dist/core/tools/hashline-engine/fs.d.ts.map +1 -0
  368. package/dist/core/tools/hashline-engine/fs.js +143 -0
  369. package/dist/core/tools/hashline-engine/fs.js.map +1 -0
  370. package/dist/core/tools/hashline-engine/index.d.ts +18 -0
  371. package/dist/core/tools/hashline-engine/index.d.ts.map +1 -0
  372. package/dist/core/tools/hashline-engine/index.js +20 -0
  373. package/dist/core/tools/hashline-engine/index.js.map +1 -0
  374. package/dist/core/tools/hashline-engine/input.d.ts +101 -0
  375. package/dist/core/tools/hashline-engine/input.d.ts.map +1 -0
  376. package/dist/core/tools/hashline-engine/input.js +398 -0
  377. package/dist/core/tools/hashline-engine/input.js.map +1 -0
  378. package/dist/core/tools/hashline-engine/messages.d.ts +99 -0
  379. package/dist/core/tools/hashline-engine/messages.d.ts.map +1 -0
  380. package/dist/core/tools/hashline-engine/messages.js +144 -0
  381. package/dist/core/tools/hashline-engine/messages.js.map +1 -0
  382. package/dist/core/tools/hashline-engine/mismatch.d.ts +45 -0
  383. package/dist/core/tools/hashline-engine/mismatch.d.ts.map +1 -0
  384. package/dist/core/tools/hashline-engine/mismatch.js +90 -0
  385. package/dist/core/tools/hashline-engine/mismatch.js.map +1 -0
  386. package/dist/core/tools/hashline-engine/normalize.d.ts +21 -0
  387. package/dist/core/tools/hashline-engine/normalize.d.ts.map +1 -0
  388. package/dist/core/tools/hashline-engine/normalize.js +33 -0
  389. package/dist/core/tools/hashline-engine/normalize.js.map +1 -0
  390. package/dist/core/tools/hashline-engine/parser.d.ts +24 -0
  391. package/dist/core/tools/hashline-engine/parser.d.ts.map +1 -0
  392. package/dist/core/tools/hashline-engine/parser.js +381 -0
  393. package/dist/core/tools/hashline-engine/parser.js.map +1 -0
  394. package/dist/core/tools/hashline-engine/patcher.d.ts +118 -0
  395. package/dist/core/tools/hashline-engine/patcher.d.ts.map +1 -0
  396. package/dist/core/tools/hashline-engine/patcher.js +341 -0
  397. package/dist/core/tools/hashline-engine/patcher.js.map +1 -0
  398. package/dist/core/tools/hashline-engine/prefixes.d.ts +43 -0
  399. package/dist/core/tools/hashline-engine/prefixes.d.ts.map +1 -0
  400. package/dist/core/tools/hashline-engine/prefixes.js +135 -0
  401. package/dist/core/tools/hashline-engine/prefixes.js.map +1 -0
  402. package/dist/core/tools/hashline-engine/recovery.d.ts +41 -0
  403. package/dist/core/tools/hashline-engine/recovery.d.ts.map +1 -0
  404. package/dist/core/tools/hashline-engine/recovery.js +168 -0
  405. package/dist/core/tools/hashline-engine/recovery.js.map +1 -0
  406. package/dist/core/tools/hashline-engine/snapshots.d.ts +65 -0
  407. package/dist/core/tools/hashline-engine/snapshots.d.ts.map +1 -0
  408. package/dist/core/tools/hashline-engine/snapshots.js +108 -0
  409. package/dist/core/tools/hashline-engine/snapshots.js.map +1 -0
  410. package/dist/core/tools/hashline-engine/stream.d.ts +3 -0
  411. package/dist/core/tools/hashline-engine/stream.d.ts.map +1 -0
  412. package/dist/core/tools/hashline-engine/stream.js +111 -0
  413. package/dist/core/tools/hashline-engine/stream.js.map +1 -0
  414. package/dist/core/tools/hashline-engine/tokenizer.d.ts +69 -0
  415. package/dist/core/tools/hashline-engine/tokenizer.d.ts.map +1 -0
  416. package/dist/core/tools/hashline-engine/tokenizer.js +430 -0
  417. package/dist/core/tools/hashline-engine/tokenizer.js.map +1 -0
  418. package/dist/core/tools/hashline-engine/types.d.ts +166 -0
  419. package/dist/core/tools/hashline-engine/types.d.ts.map +1 -0
  420. package/dist/core/tools/hashline-engine/types.js +9 -0
  421. package/dist/core/tools/hashline-engine/types.js.map +1 -0
  422. package/dist/core/tools/hashline.d.ts +29 -0
  423. package/dist/core/tools/hashline.d.ts.map +1 -0
  424. package/dist/core/tools/hashline.js +110 -0
  425. package/dist/core/tools/hashline.js.map +1 -0
  426. package/dist/core/tools/index.d.ts +6 -4
  427. package/dist/core/tools/index.d.ts.map +1 -1
  428. package/dist/core/tools/index.js +52 -35
  429. package/dist/core/tools/index.js.map +1 -1
  430. package/dist/core/tools/notebook.d.ts +38 -0
  431. package/dist/core/tools/notebook.d.ts.map +1 -0
  432. package/dist/core/tools/notebook.js +125 -0
  433. package/dist/core/tools/notebook.js.map +1 -0
  434. package/dist/core/tools/read-document-extract.d.ts +9 -0
  435. package/dist/core/tools/read-document-extract.d.ts.map +1 -0
  436. package/dist/core/tools/read-document-extract.js +212 -0
  437. package/dist/core/tools/read-document-extract.js.map +1 -0
  438. package/dist/core/tools/read-selectors.d.ts +24 -0
  439. package/dist/core/tools/read-selectors.d.ts.map +1 -0
  440. package/dist/core/tools/read-selectors.js +277 -0
  441. package/dist/core/tools/read-selectors.js.map +1 -0
  442. package/dist/core/tools/read-url.d.ts +37 -0
  443. package/dist/core/tools/read-url.d.ts.map +1 -0
  444. package/dist/core/tools/read-url.js +39 -0
  445. package/dist/core/tools/read-url.js.map +1 -0
  446. package/dist/core/tools/read.d.ts +11 -11
  447. package/dist/core/tools/read.d.ts.map +1 -1
  448. package/dist/core/tools/read.js +224 -94
  449. package/dist/core/tools/read.js.map +1 -1
  450. package/dist/core/tools/resource-selectors.d.ts +44 -0
  451. package/dist/core/tools/resource-selectors.d.ts.map +1 -0
  452. package/dist/core/tools/resource-selectors.js +808 -0
  453. package/dist/core/tools/resource-selectors.js.map +1 -0
  454. package/dist/core/tools/search-details.d.ts +26 -0
  455. package/dist/core/tools/search-details.d.ts.map +1 -0
  456. package/dist/core/tools/search-details.js +24 -0
  457. package/dist/core/tools/search-details.js.map +1 -0
  458. package/dist/core/tools/search-line-ranges.d.ts +11 -0
  459. package/dist/core/tools/search-line-ranges.d.ts.map +1 -0
  460. package/dist/core/tools/search-line-ranges.js +65 -0
  461. package/dist/core/tools/search-line-ranges.js.map +1 -0
  462. package/dist/core/tools/search-native.d.ts +97 -0
  463. package/dist/core/tools/search-native.d.ts.map +1 -0
  464. package/dist/core/tools/search-native.js +27 -0
  465. package/dist/core/tools/search-native.js.map +1 -0
  466. package/dist/core/tools/search.d.ts +24 -0
  467. package/dist/core/tools/search.d.ts.map +1 -0
  468. package/dist/core/tools/search.js +573 -0
  469. package/dist/core/tools/search.js.map +1 -0
  470. package/dist/core/tools/truncate.d.ts +4 -4
  471. package/dist/core/tools/truncate.d.ts.map +1 -1
  472. package/dist/core/tools/truncate.js +3 -3
  473. package/dist/core/tools/truncate.js.map +1 -1
  474. package/dist/core/tools/url-ip-guards.d.ts +4 -0
  475. package/dist/core/tools/url-ip-guards.d.ts.map +1 -0
  476. package/dist/core/tools/url-ip-guards.js +126 -0
  477. package/dist/core/tools/url-ip-guards.js.map +1 -0
  478. package/dist/core/tools/write.d.ts +12 -2
  479. package/dist/core/tools/write.d.ts.map +1 -1
  480. package/dist/core/tools/write.js +166 -14
  481. package/dist/core/tools/write.js.map +1 -1
  482. package/dist/core/trust-manager.d.ts.map +1 -1
  483. package/dist/core/trust-manager.js +2 -3
  484. package/dist/core/trust-manager.js.map +1 -1
  485. package/dist/index-extensions.d.ts +2 -2
  486. package/dist/index-extensions.d.ts.map +1 -1
  487. package/dist/index-extensions.js +1 -1
  488. package/dist/index-extensions.js.map +1 -1
  489. package/dist/index.d.ts +3 -3
  490. package/dist/index.d.ts.map +1 -1
  491. package/dist/index.js +3 -3
  492. package/dist/index.js.map +1 -1
  493. package/dist/modes/interactive/components/chat-session-host-runtime.d.ts +1 -0
  494. package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
  495. package/dist/modes/interactive/components/chat-session-host-runtime.js +12 -0
  496. package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -1
  497. package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts +4 -0
  498. package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts.map +1 -0
  499. package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.js +131 -0
  500. package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.js.map +1 -0
  501. package/dist/modes/interactive/components/chat-session-host.d.ts +2 -0
  502. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  503. package/dist/modes/interactive/components/chat-session-host.js +7 -1
  504. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  505. package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
  506. package/dist/modes/interactive/components/chat-transcript.js +15 -4
  507. package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
  508. package/dist/modes/interactive/components/custom-editor.d.ts +1 -0
  509. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  510. package/dist/modes/interactive/components/custom-editor.js +9 -2
  511. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  512. package/dist/modes/interactive/components/settings-selector-handlers.d.ts.map +1 -1
  513. package/dist/modes/interactive/components/settings-selector-handlers.js +3 -0
  514. package/dist/modes/interactive/components/settings-selector-handlers.js.map +1 -1
  515. package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
  516. package/dist/modes/interactive/components/settings-selector-items.js +7 -0
  517. package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
  518. package/dist/modes/interactive/components/settings-selector-types.d.ts +2 -0
  519. package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
  520. package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
  521. package/dist/modes/interactive/components/tool-execution.d.ts +3 -0
  522. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  523. package/dist/modes/interactive/components/tool-execution.js +26 -0
  524. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  525. package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
  526. package/dist/modes/interactive/components/tree-selector-content.js +0 -5
  527. package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
  528. package/dist/modes/interactive/interactive-auth-login.d.ts.map +1 -1
  529. package/dist/modes/interactive/interactive-auth-login.js +1 -0
  530. package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
  531. package/dist/modes/interactive/interactive-autocomplete.d.ts.map +1 -1
  532. package/dist/modes/interactive/interactive-autocomplete.js +80 -2
  533. package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
  534. package/dist/modes/interactive/interactive-hotkeys-debug.d.ts.map +1 -1
  535. package/dist/modes/interactive/interactive-hotkeys-debug.js +3 -0
  536. package/dist/modes/interactive/interactive-hotkeys-debug.js.map +1 -1
  537. package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
  538. package/dist/modes/interactive/interactive-input-handling.js +51 -0
  539. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  540. package/dist/modes/interactive/interactive-mode-base.d.ts +5 -0
  541. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  542. package/dist/modes/interactive/interactive-mode-base.js +5 -0
  543. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  544. package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
  545. package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
  546. package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
  547. package/dist/modes/interactive/interactive-mode-surface.d.ts +12 -0
  548. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  549. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  550. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  551. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  552. package/dist/modes/interactive/interactive-mode.js +1 -0
  553. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  554. package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
  555. package/dist/modes/interactive/interactive-model-routing.js +4 -1
  556. package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
  557. package/dist/modes/interactive/interactive-onboarding.d.ts +11 -0
  558. package/dist/modes/interactive/interactive-onboarding.d.ts.map +1 -0
  559. package/dist/modes/interactive/interactive-onboarding.js +220 -0
  560. package/dist/modes/interactive/interactive-onboarding.js.map +1 -0
  561. package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
  562. package/dist/modes/interactive/interactive-selectors.js +4 -0
  563. package/dist/modes/interactive/interactive-selectors.js.map +1 -1
  564. package/dist/modes/interactive/interactive-session-routing.d.ts.map +1 -1
  565. package/dist/modes/interactive/interactive-session-routing.js +6 -0
  566. package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
  567. package/dist/modes/interactive/interactive-slash-commands.d.ts.map +1 -1
  568. package/dist/modes/interactive/interactive-slash-commands.js +9 -4
  569. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  570. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  571. package/dist/modes/interactive/interactive-startup.js +28 -0
  572. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  573. package/dist/utils/child-process.d.ts.map +1 -1
  574. package/dist/utils/child-process.js +21 -1
  575. package/dist/utils/child-process.js.map +1 -1
  576. package/dist/utils/markit.d.ts +8 -0
  577. package/dist/utils/markit.d.ts.map +1 -0
  578. package/dist/utils/markit.js +53 -0
  579. package/dist/utils/markit.js.map +1 -0
  580. package/dist/utils/paths.d.ts +2 -1
  581. package/dist/utils/paths.d.ts.map +1 -1
  582. package/dist/utils/paths.js +14 -1
  583. package/dist/utils/paths.js.map +1 -1
  584. package/docs/compaction.md +18 -1
  585. package/docs/containerization.md +1 -1
  586. package/docs/docs.json +1 -0
  587. package/docs/extensions.md +25 -36
  588. package/docs/models.md +1 -1
  589. package/docs/providers.md +2 -1
  590. package/docs/quickstart.md +11 -6
  591. package/docs/sdk.md +5 -5
  592. package/docs/session-format.md +6 -0
  593. package/docs/sessions.md +6 -0
  594. package/docs/settings.md +7 -0
  595. package/docs/subagents.md +3 -2
  596. package/docs/tools.md +49 -0
  597. package/docs/usage.md +3 -3
  598. package/docs/workflows.md +112 -8
  599. package/examples/extensions/subagent/README.md +5 -5
  600. package/examples/extensions/subagent/agents/planner.md +1 -1
  601. package/examples/extensions/subagent/agents/reviewer.md +1 -1
  602. package/examples/extensions/subagent/agents/scout.md +2 -2
  603. package/examples/extensions/subagent/display.ts +3 -3
  604. package/examples/sdk/05-tools.ts +3 -3
  605. package/examples/sdk/README.md +1 -1
  606. package/package.json +5 -3
@@ -0,0 +1,41 @@
1
+ import type { SnapshotStore } from "./snapshots.js";
2
+ import type { Edit } from "./types.js";
3
+ export interface RecoveryArgs {
4
+ path: string;
5
+ currentText: string;
6
+ fileHash: string;
7
+ edits: readonly Edit[];
8
+ }
9
+ export interface RecoveryResult {
10
+ /** Post-recovery text. */
11
+ text: string;
12
+ /** First changed line (1-indexed) relative to the live `currentText`, or `undefined`. */
13
+ firstChangedLine: number | undefined;
14
+ /** Warnings collected during recovery, including the user-facing recovery banner. */
15
+ warnings: string[];
16
+ }
17
+ /**
18
+ * Stateless recovery driver over a {@link SnapshotStore}. Construct once and
19
+ * call {@link Recovery.tryRecover} per stale-tag incident. The default
20
+ * implementation tries two strategies in order:
21
+ *
22
+ * 1. Apply the edits on the full-file version the tag names, then 3-way-merge
23
+ * the resulting patch onto the live content (handles external writes).
24
+ * 2. (Session chain) If that version wasn't the head, replay the edits onto
25
+ * the live content directly when line counts match AND every edit's anchor
26
+ * line content is unchanged between version and current — a prior in-session
27
+ * edit advanced the tag and the model's anchors still name the same logical
28
+ * rows. Emits a dedicated {@link RECOVERY_SESSION_REPLAY_WARNING} because
29
+ * even with both guards a coincidental insert+delete pair on duplicate rows
30
+ * can still land the edit on the wrong row; see {@link replaySessionChainOnCurrent}.
31
+ */
32
+ export declare class Recovery {
33
+ readonly store: SnapshotStore;
34
+ constructor(store: SnapshotStore);
35
+ /**
36
+ * Attempt recovery. Returns `null` when no path forward is found — the
37
+ * caller should then surface a {@link MismatchError}.
38
+ */
39
+ tryRecover(args: RecoveryArgs): RecoveryResult | null;
40
+ }
41
+ //# sourceMappingURL=recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/hashline-engine/recovery.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAY,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAuB,IAAI,EAAE,MAAM,YAAY,CAAC;AAO5D,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC9B,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,yFAAyF;IACzF,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,qFAAqF;IACrF,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB;AAkHD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,QAAQ;IACpB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,YAAY,KAAK,EAAE,aAAa,EAAyB;IACzD;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,GAAG,IAAI,CAcpD;CACD","sourcesContent":["// @generated vendored verbatim from oh-my-pi packages/hashline @ 15b5c1397fc -- DO NOT EDIT.\n// Parity source for the Atomic hashline edit engine (issue #1483); adapted only for Atomic's Node runtime (relative imports, Bun->Node host calls, erasable constructor syntax).\n/**\n * Recover from a stale section snapshot tag by replaying the would-be edit\n * against a cached pre-edit snapshot of the file and 3-way-merging the\n * result onto the current on-disk content.\n *\n * The patcher consults this when a section tag resolves to a snapshot that no\n * longer matches the live file content. The recovery class is stateless apart\n * from the {@link SnapshotStore} it queries; the snapshot store is the seam\n * lets you plug in your own caching strategy.\n */\nimport * as Diff from \"diff\";\nimport { applyEdits } from \"./apply.js\";\nimport { RECOVERY_EXTERNAL_WARNING, RECOVERY_SESSION_CHAIN_WARNING, RECOVERY_SESSION_REPLAY_WARNING } from \"./messages.js\";\nimport type { Snapshot, SnapshotStore } from \"./snapshots.js\";\nimport type { Anchor, ApplyResult, Edit } from \"./types.js\";\n\n// Section tags are line-precise; never let Diff.applyPatch slide a hunk\n// onto a duplicate closer 100+ lines away. If snapshot replay does not\n// align exactly, refuse and let the caller re-read.\nconst RECOVERY_FUZZ_FACTOR = 0;\n\nexport interface RecoveryArgs {\n\tpath: string;\n\tcurrentText: string;\n\tfileHash: string;\n\tedits: readonly Edit[];\n}\n\nexport interface RecoveryResult {\n\t/** Post-recovery text. */\n\ttext: string;\n\t/** First changed line (1-indexed) relative to the live `currentText`, or `undefined`. */\n\tfirstChangedLine: number | undefined;\n\t/** Warnings collected during recovery, including the user-facing recovery banner. */\n\twarnings: string[];\n}\n\nfunction applyEditsToSnapshot(\n\tpreviousText: string,\n\tcurrentText: string,\n\tedits: readonly Edit[],\n\trecoveryWarning: string,\n): RecoveryResult | null {\n\tlet applied: ApplyResult;\n\ttry {\n\t\tapplied = applyEdits(previousText, [...edits]);\n\t} catch {\n\t\treturn null;\n\t}\n\tif (applied.text === previousText) return null;\n\n\tconst patch = Diff.structuredPatch(\"file\", \"file\", previousText, applied.text, \"\", \"\", { context: 3 });\n\tconst merged = Diff.applyPatch(currentText, patch, { fuzzFactor: RECOVERY_FUZZ_FACTOR });\n\tif (typeof merged !== \"string\" || merged === currentText) return null;\n\n\tconst firstChangedLine = findFirstChangedLine(currentText, merged) ?? applied.firstChangedLine;\n\tconst hasNetChange = firstChangedLine !== undefined;\n\tconst warnings = hasNetChange ? [recoveryWarning, ...(applied.warnings ?? [])] : [...(applied.warnings ?? [])];\n\n\treturn { text: merged, firstChangedLine, warnings };\n}\n\nfunction collectAnchorLines(edits: readonly Edit[]): number[] {\n\tconst lines: number[] = [];\n\tfor (const edit of edits) {\n\t\tfor (const anchor of getEditAnchors(edit)) lines.push(anchor.line);\n\t}\n\treturn lines;\n}\n\nfunction getEditAnchors(edit: Edit): Anchor[] {\n\tif (edit.kind === \"delete\") return [edit.anchor];\n\t// Recovery only ever receives already-resolved edits (no `block`); this arm\n\t// exists for type-exhaustiveness over the full `Edit` union.\n\tif (edit.kind === \"block\") return [edit.anchor];\n\treturn edit.cursor.kind === \"before_anchor\" || edit.cursor.kind === \"after_anchor\" ? [edit.cursor.anchor] : [];\n}\n\n/**\n * Returns true when every anchor line in `edits` has identical content in\n * `previousText` and `currentText`. The session-chain replay fast-path\n * requires this: if the prior in-session edit rewrote the line the model is\n * now re-targeting with a stale hash, replaying onto current would silently\n * overwrite the new content with whatever the model authored against the\n * old content — a corruption window, not a recovery.\n */\nfunction verifyAnchorContent(previousText: string, currentText: string, edits: readonly Edit[]): boolean {\n\tconst lines = collectAnchorLines(edits);\n\tif (lines.length === 0) return true;\n\tconst prev = previousText.split(\"\\n\");\n\tconst curr = currentText.split(\"\\n\");\n\tfor (const line of lines) {\n\t\tconst idx = line - 1;\n\t\tif (idx < 0 || idx >= prev.length || idx >= curr.length) return false;\n\t\tif (prev[idx] !== curr[idx]) return false;\n\t}\n\treturn true;\n}\n\nfunction replaySessionChainOnCurrent(\n\tpreviousText: string,\n\tcurrentText: string,\n\tedits: readonly Edit[],\n): RecoveryResult | null {\n\t// Two guards narrow the corruption window. Neither alone is sufficient,\n\t// and even together they don't fully prove correctness — replay is the\n\t// less-certain recovery mode and emits RECOVERY_SESSION_REPLAY_WARNING\n\t// so the caller can verify the diff.\n\t// - Equal line counts: every line number in `edits` still resolves to\n\t// SOME logical row (no net shift across the prior chain). A\n\t// coincidental insert+delete pair can still leave indices pointing\n\t// at different logical rows than the model anchored against.\n\t// - Anchor-content alignment: the row at each anchor's line index has\n\t// identical content in previous and current. Catches the common\n\t// case of a prior edit rewriting the targeted line; can still be\n\t// coincidentally satisfied by a duplicated row at the shifted\n\t// index.\n\tif (previousText.split(\"\\n\").length !== currentText.split(\"\\n\").length) return null;\n\tif (!verifyAnchorContent(previousText, currentText, edits)) return null;\n\tlet applied: ApplyResult;\n\ttry {\n\t\tapplied = applyEdits(currentText, [...edits]);\n\t} catch {\n\t\treturn null;\n\t}\n\tif (applied.text === currentText) return null;\n\treturn {\n\t\ttext: applied.text,\n\t\tfirstChangedLine: applied.firstChangedLine,\n\t\twarnings: [RECOVERY_SESSION_REPLAY_WARNING, ...(applied.warnings ?? [])],\n\t};\n}\n\n/** First 1-indexed line at which `a` and `b` diverge, or `undefined` if equal. */\nfunction findFirstChangedLine(a: string, b: string): number | undefined {\n\tif (a === b) return undefined;\n\tconst aLines = a.split(\"\\n\");\n\tconst bLines = b.split(\"\\n\");\n\tconst max = Math.max(aLines.length, bLines.length);\n\tfor (let i = 0; i < max; i++) {\n\t\tif (aLines[i] !== bLines[i]) return i + 1;\n\t}\n\treturn undefined;\n}\n\nfunction isHeadSnapshot(head: Snapshot | null, snapshot: Snapshot): boolean {\n\treturn head === snapshot;\n}\n\n/**\n * Stateless recovery driver over a {@link SnapshotStore}. Construct once and\n * call {@link Recovery.tryRecover} per stale-tag incident. The default\n * implementation tries two strategies in order:\n *\n * 1. Apply the edits on the full-file version the tag names, then 3-way-merge\n * the resulting patch onto the live content (handles external writes).\n * 2. (Session chain) If that version wasn't the head, replay the edits onto\n * the live content directly when line counts match AND every edit's anchor\n * line content is unchanged between version and current — a prior in-session\n * edit advanced the tag and the model's anchors still name the same logical\n * rows. Emits a dedicated {@link RECOVERY_SESSION_REPLAY_WARNING} because\n * even with both guards a coincidental insert+delete pair on duplicate rows\n * can still land the edit on the wrong row; see {@link replaySessionChainOnCurrent}.\n */\nexport class Recovery {\n\treadonly store: SnapshotStore;\n\tconstructor(store: SnapshotStore) { this.store = store; }\n\t/**\n\t * Attempt recovery. Returns `null` when no path forward is found — the\n\t * caller should then surface a {@link MismatchError}.\n\t */\n\ttryRecover(args: RecoveryArgs): RecoveryResult | null {\n\t\tconst { path, currentText, fileHash, edits } = args;\n\t\tconst snapshot = this.store.byHash(path, fileHash);\n\t\tif (!snapshot) return null;\n\t\tconst isHead = isHeadSnapshot(this.store.head(path), snapshot);\n\t\tconst recoveryWarning = isHead ? RECOVERY_EXTERNAL_WARNING : RECOVERY_SESSION_CHAIN_WARNING;\n\t\tconst merged = applyEditsToSnapshot(snapshot.text, currentText, edits, recoveryWarning);\n\t\tif (merged !== null) return merged;\n\t\t// Session-chain fallback: the 3-way merge on the version refused.\n\t\t// Replay onto current is gated by line-count equality AND\n\t\t// anchor-content alignment — see `replaySessionChainOnCurrent`\n\t\t// for why both guards together still don't fully prove correctness.\n\t\tif (!isHead) return replaySessionChainOnCurrent(snapshot.text, currentText, edits);\n\t\treturn null;\n\t}\n}\n"]}
@@ -0,0 +1,168 @@
1
+ // @generated vendored verbatim from oh-my-pi packages/hashline @ 15b5c1397fc -- DO NOT EDIT.
2
+ // Parity source for the Atomic hashline edit engine (issue #1483); adapted only for Atomic's Node runtime (relative imports, Bun->Node host calls, erasable constructor syntax).
3
+ /**
4
+ * Recover from a stale section snapshot tag by replaying the would-be edit
5
+ * against a cached pre-edit snapshot of the file and 3-way-merging the
6
+ * result onto the current on-disk content.
7
+ *
8
+ * The patcher consults this when a section tag resolves to a snapshot that no
9
+ * longer matches the live file content. The recovery class is stateless apart
10
+ * from the {@link SnapshotStore} it queries; the snapshot store is the seam
11
+ * lets you plug in your own caching strategy.
12
+ */
13
+ import * as Diff from "diff";
14
+ import { applyEdits } from "./apply.js";
15
+ import { RECOVERY_EXTERNAL_WARNING, RECOVERY_SESSION_CHAIN_WARNING, RECOVERY_SESSION_REPLAY_WARNING } from "./messages.js";
16
+ // Section tags are line-precise; never let Diff.applyPatch slide a hunk
17
+ // onto a duplicate closer 100+ lines away. If snapshot replay does not
18
+ // align exactly, refuse and let the caller re-read.
19
+ const RECOVERY_FUZZ_FACTOR = 0;
20
+ function applyEditsToSnapshot(previousText, currentText, edits, recoveryWarning) {
21
+ let applied;
22
+ try {
23
+ applied = applyEdits(previousText, [...edits]);
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ if (applied.text === previousText)
29
+ return null;
30
+ const patch = Diff.structuredPatch("file", "file", previousText, applied.text, "", "", { context: 3 });
31
+ const merged = Diff.applyPatch(currentText, patch, { fuzzFactor: RECOVERY_FUZZ_FACTOR });
32
+ if (typeof merged !== "string" || merged === currentText)
33
+ return null;
34
+ const firstChangedLine = findFirstChangedLine(currentText, merged) ?? applied.firstChangedLine;
35
+ const hasNetChange = firstChangedLine !== undefined;
36
+ const warnings = hasNetChange ? [recoveryWarning, ...(applied.warnings ?? [])] : [...(applied.warnings ?? [])];
37
+ return { text: merged, firstChangedLine, warnings };
38
+ }
39
+ function collectAnchorLines(edits) {
40
+ const lines = [];
41
+ for (const edit of edits) {
42
+ for (const anchor of getEditAnchors(edit))
43
+ lines.push(anchor.line);
44
+ }
45
+ return lines;
46
+ }
47
+ function getEditAnchors(edit) {
48
+ if (edit.kind === "delete")
49
+ return [edit.anchor];
50
+ // Recovery only ever receives already-resolved edits (no `block`); this arm
51
+ // exists for type-exhaustiveness over the full `Edit` union.
52
+ if (edit.kind === "block")
53
+ return [edit.anchor];
54
+ return edit.cursor.kind === "before_anchor" || edit.cursor.kind === "after_anchor" ? [edit.cursor.anchor] : [];
55
+ }
56
+ /**
57
+ * Returns true when every anchor line in `edits` has identical content in
58
+ * `previousText` and `currentText`. The session-chain replay fast-path
59
+ * requires this: if the prior in-session edit rewrote the line the model is
60
+ * now re-targeting with a stale hash, replaying onto current would silently
61
+ * overwrite the new content with whatever the model authored against the
62
+ * old content — a corruption window, not a recovery.
63
+ */
64
+ function verifyAnchorContent(previousText, currentText, edits) {
65
+ const lines = collectAnchorLines(edits);
66
+ if (lines.length === 0)
67
+ return true;
68
+ const prev = previousText.split("\n");
69
+ const curr = currentText.split("\n");
70
+ for (const line of lines) {
71
+ const idx = line - 1;
72
+ if (idx < 0 || idx >= prev.length || idx >= curr.length)
73
+ return false;
74
+ if (prev[idx] !== curr[idx])
75
+ return false;
76
+ }
77
+ return true;
78
+ }
79
+ function replaySessionChainOnCurrent(previousText, currentText, edits) {
80
+ // Two guards narrow the corruption window. Neither alone is sufficient,
81
+ // and even together they don't fully prove correctness — replay is the
82
+ // less-certain recovery mode and emits RECOVERY_SESSION_REPLAY_WARNING
83
+ // so the caller can verify the diff.
84
+ // - Equal line counts: every line number in `edits` still resolves to
85
+ // SOME logical row (no net shift across the prior chain). A
86
+ // coincidental insert+delete pair can still leave indices pointing
87
+ // at different logical rows than the model anchored against.
88
+ // - Anchor-content alignment: the row at each anchor's line index has
89
+ // identical content in previous and current. Catches the common
90
+ // case of a prior edit rewriting the targeted line; can still be
91
+ // coincidentally satisfied by a duplicated row at the shifted
92
+ // index.
93
+ if (previousText.split("\n").length !== currentText.split("\n").length)
94
+ return null;
95
+ if (!verifyAnchorContent(previousText, currentText, edits))
96
+ return null;
97
+ let applied;
98
+ try {
99
+ applied = applyEdits(currentText, [...edits]);
100
+ }
101
+ catch {
102
+ return null;
103
+ }
104
+ if (applied.text === currentText)
105
+ return null;
106
+ return {
107
+ text: applied.text,
108
+ firstChangedLine: applied.firstChangedLine,
109
+ warnings: [RECOVERY_SESSION_REPLAY_WARNING, ...(applied.warnings ?? [])],
110
+ };
111
+ }
112
+ /** First 1-indexed line at which `a` and `b` diverge, or `undefined` if equal. */
113
+ function findFirstChangedLine(a, b) {
114
+ if (a === b)
115
+ return undefined;
116
+ const aLines = a.split("\n");
117
+ const bLines = b.split("\n");
118
+ const max = Math.max(aLines.length, bLines.length);
119
+ for (let i = 0; i < max; i++) {
120
+ if (aLines[i] !== bLines[i])
121
+ return i + 1;
122
+ }
123
+ return undefined;
124
+ }
125
+ function isHeadSnapshot(head, snapshot) {
126
+ return head === snapshot;
127
+ }
128
+ /**
129
+ * Stateless recovery driver over a {@link SnapshotStore}. Construct once and
130
+ * call {@link Recovery.tryRecover} per stale-tag incident. The default
131
+ * implementation tries two strategies in order:
132
+ *
133
+ * 1. Apply the edits on the full-file version the tag names, then 3-way-merge
134
+ * the resulting patch onto the live content (handles external writes).
135
+ * 2. (Session chain) If that version wasn't the head, replay the edits onto
136
+ * the live content directly when line counts match AND every edit's anchor
137
+ * line content is unchanged between version and current — a prior in-session
138
+ * edit advanced the tag and the model's anchors still name the same logical
139
+ * rows. Emits a dedicated {@link RECOVERY_SESSION_REPLAY_WARNING} because
140
+ * even with both guards a coincidental insert+delete pair on duplicate rows
141
+ * can still land the edit on the wrong row; see {@link replaySessionChainOnCurrent}.
142
+ */
143
+ export class Recovery {
144
+ constructor(store) { this.store = store; }
145
+ /**
146
+ * Attempt recovery. Returns `null` when no path forward is found — the
147
+ * caller should then surface a {@link MismatchError}.
148
+ */
149
+ tryRecover(args) {
150
+ const { path, currentText, fileHash, edits } = args;
151
+ const snapshot = this.store.byHash(path, fileHash);
152
+ if (!snapshot)
153
+ return null;
154
+ const isHead = isHeadSnapshot(this.store.head(path), snapshot);
155
+ const recoveryWarning = isHead ? RECOVERY_EXTERNAL_WARNING : RECOVERY_SESSION_CHAIN_WARNING;
156
+ const merged = applyEditsToSnapshot(snapshot.text, currentText, edits, recoveryWarning);
157
+ if (merged !== null)
158
+ return merged;
159
+ // Session-chain fallback: the 3-way merge on the version refused.
160
+ // Replay onto current is gated by line-count equality AND
161
+ // anchor-content alignment — see `replaySessionChainOnCurrent`
162
+ // for why both guards together still don't fully prove correctness.
163
+ if (!isHead)
164
+ return replaySessionChainOnCurrent(snapshot.text, currentText, edits);
165
+ return null;
166
+ }
167
+ }
168
+ //# sourceMappingURL=recovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../../../src/core/tools/hashline-engine/recovery.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,iLAAiL;AACjL;;;;;;;;;GAS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AAE,QAAQ,CAAC,CAAC;QAC/D,MAAM,eAAe,GAAG,MAAM,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,8BAA8B,CAAC;QAC5F,MAAM,MAAM,GAAG,oBAAoB,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;QACxF,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QACnC,kEAAkE;QAClE,0DAA0D;QAC1D,+DAA+D;QAC/D,oEAAoE;QACpE,IAAI,CAAC,MAAM;YAAE,OAAO,2BAA2B,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;QACnF,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["// @generated vendored verbatim from oh-my-pi packages/hashline @ 15b5c1397fc -- DO NOT EDIT.\n// Parity source for the Atomic hashline edit engine (issue #1483); adapted only for Atomic's Node runtime (relative imports, Bun->Node host calls, erasable constructor syntax).\n/**\n * Recover from a stale section snapshot tag by replaying the would-be edit\n * against a cached pre-edit snapshot of the file and 3-way-merging the\n * result onto the current on-disk content.\n *\n * The patcher consults this when a section tag resolves to a snapshot that no\n * longer matches the live file content. The recovery class is stateless apart\n * from the {@link SnapshotStore} it queries; the snapshot store is the seam\n * lets you plug in your own caching strategy.\n */\nimport * as Diff from \"diff\";\nimport { applyEdits } from \"./apply.js\";\nimport { RECOVERY_EXTERNAL_WARNING, RECOVERY_SESSION_CHAIN_WARNING, RECOVERY_SESSION_REPLAY_WARNING } from \"./messages.js\";\nimport type { Snapshot, SnapshotStore } from \"./snapshots.js\";\nimport type { Anchor, ApplyResult, Edit } from \"./types.js\";\n\n// Section tags are line-precise; never let Diff.applyPatch slide a hunk\n// onto a duplicate closer 100+ lines away. If snapshot replay does not\n// align exactly, refuse and let the caller re-read.\nconst RECOVERY_FUZZ_FACTOR = 0;\n\nexport interface RecoveryArgs {\n\tpath: string;\n\tcurrentText: string;\n\tfileHash: string;\n\tedits: readonly Edit[];\n}\n\nexport interface RecoveryResult {\n\t/** Post-recovery text. */\n\ttext: string;\n\t/** First changed line (1-indexed) relative to the live `currentText`, or `undefined`. */\n\tfirstChangedLine: number | undefined;\n\t/** Warnings collected during recovery, including the user-facing recovery banner. */\n\twarnings: string[];\n}\n\nfunction applyEditsToSnapshot(\n\tpreviousText: string,\n\tcurrentText: string,\n\tedits: readonly Edit[],\n\trecoveryWarning: string,\n): RecoveryResult | null {\n\tlet applied: ApplyResult;\n\ttry {\n\t\tapplied = applyEdits(previousText, [...edits]);\n\t} catch {\n\t\treturn null;\n\t}\n\tif (applied.text === previousText) return null;\n\n\tconst patch = Diff.structuredPatch(\"file\", \"file\", previousText, applied.text, \"\", \"\", { context: 3 });\n\tconst merged = Diff.applyPatch(currentText, patch, { fuzzFactor: RECOVERY_FUZZ_FACTOR });\n\tif (typeof merged !== \"string\" || merged === currentText) return null;\n\n\tconst firstChangedLine = findFirstChangedLine(currentText, merged) ?? applied.firstChangedLine;\n\tconst hasNetChange = firstChangedLine !== undefined;\n\tconst warnings = hasNetChange ? [recoveryWarning, ...(applied.warnings ?? [])] : [...(applied.warnings ?? [])];\n\n\treturn { text: merged, firstChangedLine, warnings };\n}\n\nfunction collectAnchorLines(edits: readonly Edit[]): number[] {\n\tconst lines: number[] = [];\n\tfor (const edit of edits) {\n\t\tfor (const anchor of getEditAnchors(edit)) lines.push(anchor.line);\n\t}\n\treturn lines;\n}\n\nfunction getEditAnchors(edit: Edit): Anchor[] {\n\tif (edit.kind === \"delete\") return [edit.anchor];\n\t// Recovery only ever receives already-resolved edits (no `block`); this arm\n\t// exists for type-exhaustiveness over the full `Edit` union.\n\tif (edit.kind === \"block\") return [edit.anchor];\n\treturn edit.cursor.kind === \"before_anchor\" || edit.cursor.kind === \"after_anchor\" ? [edit.cursor.anchor] : [];\n}\n\n/**\n * Returns true when every anchor line in `edits` has identical content in\n * `previousText` and `currentText`. The session-chain replay fast-path\n * requires this: if the prior in-session edit rewrote the line the model is\n * now re-targeting with a stale hash, replaying onto current would silently\n * overwrite the new content with whatever the model authored against the\n * old content — a corruption window, not a recovery.\n */\nfunction verifyAnchorContent(previousText: string, currentText: string, edits: readonly Edit[]): boolean {\n\tconst lines = collectAnchorLines(edits);\n\tif (lines.length === 0) return true;\n\tconst prev = previousText.split(\"\\n\");\n\tconst curr = currentText.split(\"\\n\");\n\tfor (const line of lines) {\n\t\tconst idx = line - 1;\n\t\tif (idx < 0 || idx >= prev.length || idx >= curr.length) return false;\n\t\tif (prev[idx] !== curr[idx]) return false;\n\t}\n\treturn true;\n}\n\nfunction replaySessionChainOnCurrent(\n\tpreviousText: string,\n\tcurrentText: string,\n\tedits: readonly Edit[],\n): RecoveryResult | null {\n\t// Two guards narrow the corruption window. Neither alone is sufficient,\n\t// and even together they don't fully prove correctness — replay is the\n\t// less-certain recovery mode and emits RECOVERY_SESSION_REPLAY_WARNING\n\t// so the caller can verify the diff.\n\t// - Equal line counts: every line number in `edits` still resolves to\n\t// SOME logical row (no net shift across the prior chain). A\n\t// coincidental insert+delete pair can still leave indices pointing\n\t// at different logical rows than the model anchored against.\n\t// - Anchor-content alignment: the row at each anchor's line index has\n\t// identical content in previous and current. Catches the common\n\t// case of a prior edit rewriting the targeted line; can still be\n\t// coincidentally satisfied by a duplicated row at the shifted\n\t// index.\n\tif (previousText.split(\"\\n\").length !== currentText.split(\"\\n\").length) return null;\n\tif (!verifyAnchorContent(previousText, currentText, edits)) return null;\n\tlet applied: ApplyResult;\n\ttry {\n\t\tapplied = applyEdits(currentText, [...edits]);\n\t} catch {\n\t\treturn null;\n\t}\n\tif (applied.text === currentText) return null;\n\treturn {\n\t\ttext: applied.text,\n\t\tfirstChangedLine: applied.firstChangedLine,\n\t\twarnings: [RECOVERY_SESSION_REPLAY_WARNING, ...(applied.warnings ?? [])],\n\t};\n}\n\n/** First 1-indexed line at which `a` and `b` diverge, or `undefined` if equal. */\nfunction findFirstChangedLine(a: string, b: string): number | undefined {\n\tif (a === b) return undefined;\n\tconst aLines = a.split(\"\\n\");\n\tconst bLines = b.split(\"\\n\");\n\tconst max = Math.max(aLines.length, bLines.length);\n\tfor (let i = 0; i < max; i++) {\n\t\tif (aLines[i] !== bLines[i]) return i + 1;\n\t}\n\treturn undefined;\n}\n\nfunction isHeadSnapshot(head: Snapshot | null, snapshot: Snapshot): boolean {\n\treturn head === snapshot;\n}\n\n/**\n * Stateless recovery driver over a {@link SnapshotStore}. Construct once and\n * call {@link Recovery.tryRecover} per stale-tag incident. The default\n * implementation tries two strategies in order:\n *\n * 1. Apply the edits on the full-file version the tag names, then 3-way-merge\n * the resulting patch onto the live content (handles external writes).\n * 2. (Session chain) If that version wasn't the head, replay the edits onto\n * the live content directly when line counts match AND every edit's anchor\n * line content is unchanged between version and current — a prior in-session\n * edit advanced the tag and the model's anchors still name the same logical\n * rows. Emits a dedicated {@link RECOVERY_SESSION_REPLAY_WARNING} because\n * even with both guards a coincidental insert+delete pair on duplicate rows\n * can still land the edit on the wrong row; see {@link replaySessionChainOnCurrent}.\n */\nexport class Recovery {\n\treadonly store: SnapshotStore;\n\tconstructor(store: SnapshotStore) { this.store = store; }\n\t/**\n\t * Attempt recovery. Returns `null` when no path forward is found — the\n\t * caller should then surface a {@link MismatchError}.\n\t */\n\ttryRecover(args: RecoveryArgs): RecoveryResult | null {\n\t\tconst { path, currentText, fileHash, edits } = args;\n\t\tconst snapshot = this.store.byHash(path, fileHash);\n\t\tif (!snapshot) return null;\n\t\tconst isHead = isHeadSnapshot(this.store.head(path), snapshot);\n\t\tconst recoveryWarning = isHead ? RECOVERY_EXTERNAL_WARNING : RECOVERY_SESSION_CHAIN_WARNING;\n\t\tconst merged = applyEditsToSnapshot(snapshot.text, currentText, edits, recoveryWarning);\n\t\tif (merged !== null) return merged;\n\t\t// Session-chain fallback: the 3-way merge on the version refused.\n\t\t// Replay onto current is gated by line-count equality AND\n\t\t// anchor-content alignment — see `replaySessionChainOnCurrent`\n\t\t// for why both guards together still don't fully prove correctness.\n\t\tif (!isHead) return replaySessionChainOnCurrent(snapshot.text, currentText, edits);\n\t\treturn null;\n\t}\n}\n"]}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * One full-file version observed at a point in time. The tag the model sees is
3
+ * {@link Snapshot.hash}; recovery replays edits against {@link Snapshot.text}.
4
+ */
5
+ export interface Snapshot {
6
+ /** Canonical path this version belongs to. */
7
+ readonly path: string;
8
+ /** Full normalized (LF, no BOM) file text as observed. */
9
+ readonly text: string;
10
+ /** Content-derived tag for {@link Snapshot.text} (see {@link computeFileHash}). */
11
+ readonly hash: string;
12
+ /** Timestamp (ms since epoch) the version was recorded. */
13
+ recordedAt: number;
14
+ }
15
+ /**
16
+ * Storage seam for full-file version snapshots. The patcher calls {@link head}
17
+ * for the latest version of a path and {@link byHash} when it needs the
18
+ * specific historical version a section's stale tag names.
19
+ */
20
+ export declare abstract class SnapshotStore {
21
+ /** Most-recently recorded version for `path`, or `null` if none. */
22
+ abstract head(path: string): Snapshot | null;
23
+ /** Recorded unambiguous version for `path` whose tag equals `hash`, or `null`. */
24
+ abstract byHash(path: string, hash: string): Snapshot | null;
25
+ /** Recorded version for `path` whose tag and full text both match, or `null`. */
26
+ byHashAndText(path: string, hash: string, text: string): Snapshot | null;
27
+ /** Record the full normalized text of `path` and return its content tag. */
28
+ abstract record(path: string, fullText: string): string;
29
+ /** Drop the version history for a single path. */
30
+ abstract invalidate(path: string): void;
31
+ /** Drop every version history. */
32
+ abstract clear(): void;
33
+ }
34
+ export interface InMemorySnapshotStoreOptions {
35
+ /** Maximum number of distinct paths tracked at once (default 30). LRU eviction. */
36
+ maxPaths?: number;
37
+ /** Maximum full-file versions retained per path (default 4). Oldest dropped first. */
38
+ maxVersionsPerPath?: number;
39
+ /**
40
+ * Global ceiling on retained snapshot text summed across every path's
41
+ * version history, measured in UTF-16 code units (default 64 MiB).
42
+ * Least-recently-used path histories are evicted to stay under it.
43
+ */
44
+ maxTotalBytes?: number;
45
+ }
46
+ /**
47
+ * In-memory {@link SnapshotStore} backed by `lru-cache`. Per-path history is a
48
+ * short ring of full-file versions (oldest dropped first); per-session path
49
+ * tracking is LRU-bounded so cold paths age out automatically.
50
+ *
51
+ * Recording byte-identical content again refreshes recency and reuses the
52
+ * existing tag (read fusion); recording new content unshifts a fresh version
53
+ * onto the front of the path history.
54
+ */
55
+ export declare class InMemorySnapshotStore extends SnapshotStore {
56
+ #private;
57
+ constructor(options?: InMemorySnapshotStoreOptions);
58
+ head(path: string): Snapshot | null;
59
+ byHash(path: string, hash: string): Snapshot | null;
60
+ byHashAndText(path: string, hash: string, text: string): Snapshot | null;
61
+ record(path: string, fullText: string): string;
62
+ invalidate(path: string): void;
63
+ clear(): void;
64
+ }
65
+ //# sourceMappingURL=snapshots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshots.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/hashline-engine/snapshots.ts"],"names":[],"mappings":"AA2BA;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACxB,8CAA8C;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,8BAAsB,aAAa;IAClC,oEAAoE;IACpE,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;IAE7C,kFAAkF;IAClF,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;IAE7D,iFAAiF;IACjF,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAGvE;IAED,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAExD,kDAAkD;IAClD,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAExC,kCAAkC;IAClC,QAAQ,CAAC,KAAK,IAAI,IAAI,CAAC;CACvB;AAOD,MAAM,WAAW,4BAA4B;IAC5C,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,qBAAa,qBAAsB,SAAQ,aAAa;;IAIvD,YAAY,OAAO,GAAE,4BAAiC,EAYrD;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAElC;IAED,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAKlD;IAEQ,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAEhF;IAED,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAoB7C;IAED,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE7B;IAED,KAAK,IAAI,IAAI,CAEZ;CACD","sourcesContent":["// @generated vendored verbatim from oh-my-pi packages/hashline @ 15b5c1397fc -- DO NOT EDIT.\n// Parity source for the Atomic hashline edit engine (issue #1483); adapted only for Atomic's Node runtime (relative imports, Bun->Node host calls, erasable constructor syntax).\n/**\n * Per-session snapshot store used by {@link Recovery} and {@link Patcher} to\n * bind hashline section tags to the exact file content that minted them.\n *\n * A section tag is a content-derived hash of the *whole file* (see\n * {@link computeFileHash}). Any read of byte-identical content mints the same\n * tag, so reads of one file state fuse onto one anchor and a follow-up edit\n * anchored at any line validates whenever the live file still hashes to it.\n *\n * Producers (typically `read` / `search` / `write` tools) call\n * {@link SnapshotStore.record} with the full normalized text they observed.\n * The store hashes it, dedups against the per-path history, and returns the\n * tag. Consumers (the patcher) resolve an unambiguous stale tag back to the\n * recorded full text via {@link SnapshotStore.byHash} and 3-way-merge the\n * would-be edit onto the live content.\n *\n * The abstract base class lets callers plug in whatever storage they like\n * (LRU, persistent SQLite, etc.). {@link InMemorySnapshotStore} ships as a\n * sensible default backed by `lru-cache`: a bounded set of paths, each with a\n * short history of full-file versions so in-session edit chains can still\n * recover against the version a stale tag names.\n */\nimport { LRUCache } from \"lru-cache/raw\";\nimport { computeFileHash } from \"./format.js\";\n\n/**\n * One full-file version observed at a point in time. The tag the model sees is\n * {@link Snapshot.hash}; recovery replays edits against {@link Snapshot.text}.\n */\nexport interface Snapshot {\n\t/** Canonical path this version belongs to. */\n\treadonly path: string;\n\t/** Full normalized (LF, no BOM) file text as observed. */\n\treadonly text: string;\n\t/** Content-derived tag for {@link Snapshot.text} (see {@link computeFileHash}). */\n\treadonly hash: string;\n\t/** Timestamp (ms since epoch) the version was recorded. */\n\trecordedAt: number;\n}\n\n/**\n * Storage seam for full-file version snapshots. The patcher calls {@link head}\n * for the latest version of a path and {@link byHash} when it needs the\n * specific historical version a section's stale tag names.\n */\nexport abstract class SnapshotStore {\n\t/** Most-recently recorded version for `path`, or `null` if none. */\n\tabstract head(path: string): Snapshot | null;\n\n\t/** Recorded unambiguous version for `path` whose tag equals `hash`, or `null`. */\n\tabstract byHash(path: string, hash: string): Snapshot | null;\n\n\t/** Recorded version for `path` whose tag and full text both match, or `null`. */\n\tbyHashAndText(path: string, hash: string, text: string): Snapshot | null {\n\t\tconst snapshot = this.byHash(path, hash);\n\t\treturn snapshot?.text === text ? snapshot : null;\n\t}\n\n\t/** Record the full normalized text of `path` and return its content tag. */\n\tabstract record(path: string, fullText: string): string;\n\n\t/** Drop the version history for a single path. */\n\tabstract invalidate(path: string): void;\n\n\t/** Drop every version history. */\n\tabstract clear(): void;\n}\n\nconst DEFAULT_MAX_PATHS = 30;\nconst DEFAULT_MAX_VERSIONS_PER_PATH = 4;\n/** Global ceiling on retained snapshot text across all paths (UTF-16 code units). */\nconst DEFAULT_MAX_TOTAL_BYTES = 64 * 1024 * 1024;\n\nexport interface InMemorySnapshotStoreOptions {\n\t/** Maximum number of distinct paths tracked at once (default 30). LRU eviction. */\n\tmaxPaths?: number;\n\t/** Maximum full-file versions retained per path (default 4). Oldest dropped first. */\n\tmaxVersionsPerPath?: number;\n\t/**\n\t * Global ceiling on retained snapshot text summed across every path's\n\t * version history, measured in UTF-16 code units (default 64 MiB).\n\t * Least-recently-used path histories are evicted to stay under it.\n\t */\n\tmaxTotalBytes?: number;\n}\n\n/**\n * In-memory {@link SnapshotStore} backed by `lru-cache`. Per-path history is a\n * short ring of full-file versions (oldest dropped first); per-session path\n * tracking is LRU-bounded so cold paths age out automatically.\n *\n * Recording byte-identical content again refreshes recency and reuses the\n * existing tag (read fusion); recording new content unshifts a fresh version\n * onto the front of the path history.\n */\nexport class InMemorySnapshotStore extends SnapshotStore {\n\treadonly #versions: LRUCache<string, Snapshot[]>;\n\treadonly #maxVersionsPerPath: number;\n\n\tconstructor(options: InMemorySnapshotStoreOptions = {}) {\n\t\tsuper();\n\t\tthis.#versions = new LRUCache<string, Snapshot[]>({\n\t\t\tmax: options.maxPaths ?? DEFAULT_MAX_PATHS,\n\t\t\tmaxSize: options.maxTotalBytes ?? DEFAULT_MAX_TOTAL_BYTES,\n\t\t\tsizeCalculation: history => {\n\t\t\t\tlet total = 1;\n\t\t\t\tfor (const version of history) total += version.text.length;\n\t\t\t\treturn total;\n\t\t\t},\n\t\t});\n\t\tthis.#maxVersionsPerPath = options.maxVersionsPerPath ?? DEFAULT_MAX_VERSIONS_PER_PATH;\n\t}\n\n\thead(path: string): Snapshot | null {\n\t\treturn this.#versions.get(path)?.[0] ?? null;\n\t}\n\n\tbyHash(path: string, hash: string): Snapshot | null {\n\t\tconst matches = this.#versions.get(path)?.filter(version => version.hash === hash) ?? [];\n\t\t// A 4-hex tag can collide. Recovery only proceeds when the tag maps to a\n\t\t// single retained snapshot; otherwise the caller must re-read.\n\t\treturn matches.length === 1 ? matches[0]! : null;\n\t}\n\n\toverride byHashAndText(path: string, hash: string, text: string): Snapshot | null {\n\t\treturn this.#versions.get(path)?.find(version => version.hash === hash && version.text === text) ?? null;\n\t}\n\n\trecord(path: string, fullText: string): string {\n\t\tconst hash = computeFileHash(fullText);\n\t\t// `get` refreshes LRU recency for `path`.\n\t\tconst history = this.#versions.get(path) ?? [];\n\t\tconst existing = history.find(version => version.hash === hash && version.text === fullText);\n\t\tif (existing) {\n\t\t\t// Same content state observed again: refresh recency and promote to\n\t\t\t// head (it is the current file content), then reuse the tag. Hash\n\t\t\t// collisions with different text must be retained as distinct\n\t\t\t// snapshots; the 4-hex tag is only a lookup key, not proof of identity.\n\t\t\texisting.recordedAt = Date.now();\n\t\t\tif (history[0] !== existing) {\n\t\t\t\tthis.#versions.set(path, [existing, ...history.filter(version => version !== existing)]);\n\t\t\t}\n\t\t\treturn hash;\n\t\t}\n\n\t\tconst snapshot: Snapshot = { path, text: fullText, hash, recordedAt: Date.now() };\n\t\tthis.#versions.set(path, [snapshot, ...history].slice(0, this.#maxVersionsPerPath));\n\t\treturn hash;\n\t}\n\n\tinvalidate(path: string): void {\n\t\tthis.#versions.delete(path);\n\t}\n\n\tclear(): void {\n\t\tthis.#versions.clear();\n\t}\n}\n"]}
@@ -0,0 +1,108 @@
1
+ // @generated vendored verbatim from oh-my-pi packages/hashline @ 15b5c1397fc -- DO NOT EDIT.
2
+ // Parity source for the Atomic hashline edit engine (issue #1483); adapted only for Atomic's Node runtime (relative imports, Bun->Node host calls, erasable constructor syntax).
3
+ /**
4
+ * Per-session snapshot store used by {@link Recovery} and {@link Patcher} to
5
+ * bind hashline section tags to the exact file content that minted them.
6
+ *
7
+ * A section tag is a content-derived hash of the *whole file* (see
8
+ * {@link computeFileHash}). Any read of byte-identical content mints the same
9
+ * tag, so reads of one file state fuse onto one anchor and a follow-up edit
10
+ * anchored at any line validates whenever the live file still hashes to it.
11
+ *
12
+ * Producers (typically `read` / `search` / `write` tools) call
13
+ * {@link SnapshotStore.record} with the full normalized text they observed.
14
+ * The store hashes it, dedups against the per-path history, and returns the
15
+ * tag. Consumers (the patcher) resolve an unambiguous stale tag back to the
16
+ * recorded full text via {@link SnapshotStore.byHash} and 3-way-merge the
17
+ * would-be edit onto the live content.
18
+ *
19
+ * The abstract base class lets callers plug in whatever storage they like
20
+ * (LRU, persistent SQLite, etc.). {@link InMemorySnapshotStore} ships as a
21
+ * sensible default backed by `lru-cache`: a bounded set of paths, each with a
22
+ * short history of full-file versions so in-session edit chains can still
23
+ * recover against the version a stale tag names.
24
+ */
25
+ import { LRUCache } from "lru-cache/raw";
26
+ import { computeFileHash } from "./format.js";
27
+ /**
28
+ * Storage seam for full-file version snapshots. The patcher calls {@link head}
29
+ * for the latest version of a path and {@link byHash} when it needs the
30
+ * specific historical version a section's stale tag names.
31
+ */
32
+ export class SnapshotStore {
33
+ /** Recorded version for `path` whose tag and full text both match, or `null`. */
34
+ byHashAndText(path, hash, text) {
35
+ const snapshot = this.byHash(path, hash);
36
+ return snapshot?.text === text ? snapshot : null;
37
+ }
38
+ }
39
+ const DEFAULT_MAX_PATHS = 30;
40
+ const DEFAULT_MAX_VERSIONS_PER_PATH = 4;
41
+ /** Global ceiling on retained snapshot text across all paths (UTF-16 code units). */
42
+ const DEFAULT_MAX_TOTAL_BYTES = 64 * 1024 * 1024;
43
+ /**
44
+ * In-memory {@link SnapshotStore} backed by `lru-cache`. Per-path history is a
45
+ * short ring of full-file versions (oldest dropped first); per-session path
46
+ * tracking is LRU-bounded so cold paths age out automatically.
47
+ *
48
+ * Recording byte-identical content again refreshes recency and reuses the
49
+ * existing tag (read fusion); recording new content unshifts a fresh version
50
+ * onto the front of the path history.
51
+ */
52
+ export class InMemorySnapshotStore extends SnapshotStore {
53
+ #versions;
54
+ #maxVersionsPerPath;
55
+ constructor(options = {}) {
56
+ super();
57
+ this.#versions = new LRUCache({
58
+ max: options.maxPaths ?? DEFAULT_MAX_PATHS,
59
+ maxSize: options.maxTotalBytes ?? DEFAULT_MAX_TOTAL_BYTES,
60
+ sizeCalculation: history => {
61
+ let total = 1;
62
+ for (const version of history)
63
+ total += version.text.length;
64
+ return total;
65
+ },
66
+ });
67
+ this.#maxVersionsPerPath = options.maxVersionsPerPath ?? DEFAULT_MAX_VERSIONS_PER_PATH;
68
+ }
69
+ head(path) {
70
+ return this.#versions.get(path)?.[0] ?? null;
71
+ }
72
+ byHash(path, hash) {
73
+ const matches = this.#versions.get(path)?.filter(version => version.hash === hash) ?? [];
74
+ // A 4-hex tag can collide. Recovery only proceeds when the tag maps to a
75
+ // single retained snapshot; otherwise the caller must re-read.
76
+ return matches.length === 1 ? matches[0] : null;
77
+ }
78
+ byHashAndText(path, hash, text) {
79
+ return this.#versions.get(path)?.find(version => version.hash === hash && version.text === text) ?? null;
80
+ }
81
+ record(path, fullText) {
82
+ const hash = computeFileHash(fullText);
83
+ // `get` refreshes LRU recency for `path`.
84
+ const history = this.#versions.get(path) ?? [];
85
+ const existing = history.find(version => version.hash === hash && version.text === fullText);
86
+ if (existing) {
87
+ // Same content state observed again: refresh recency and promote to
88
+ // head (it is the current file content), then reuse the tag. Hash
89
+ // collisions with different text must be retained as distinct
90
+ // snapshots; the 4-hex tag is only a lookup key, not proof of identity.
91
+ existing.recordedAt = Date.now();
92
+ if (history[0] !== existing) {
93
+ this.#versions.set(path, [existing, ...history.filter(version => version !== existing)]);
94
+ }
95
+ return hash;
96
+ }
97
+ const snapshot = { path, text: fullText, hash, recordedAt: Date.now() };
98
+ this.#versions.set(path, [snapshot, ...history].slice(0, this.#maxVersionsPerPath));
99
+ return hash;
100
+ }
101
+ invalidate(path) {
102
+ this.#versions.delete(path);
103
+ }
104
+ clear() {
105
+ this.#versions.clear();
106
+ }
107
+ }
108
+ //# sourceMappingURL=snapshots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshots.js","sourceRoot":"","sources":["../../../../src/core/tools/hashline-engine/snapshots.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,iLAAiL;AACjL;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAiB9C;;;;GAIG;AACH,MAAM,OAAgB,aAAa;IAOlC,iFAAiF;IACjF,aAAa,CAAC,IAAY,EAAE,IAAY,EAAE,IAAY;QACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzC,OAAO,QAAQ,EAAE,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IAClD,CAAC;CAUD;AAED,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,6BAA6B,GAAG,CAAC,CAAC;AACxC,qFAAqF;AACrF,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAejD;;;;;;;;GAQG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IAC9C,SAAS,CAA+B;IACxC,mBAAmB,CAAS;IAErC,YAAY,OAAO,GAAiC,EAAE;QACrD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAqB;YACjD,GAAG,EAAE,OAAO,CAAC,QAAQ,IAAI,iBAAiB;YAC1C,OAAO,EAAE,OAAO,CAAC,aAAa,IAAI,uBAAuB;YACzD,eAAe,EAAE,OAAO,CAAC,EAAE;gBAC1B,IAAI,KAAK,GAAG,CAAC,CAAC;gBACd,KAAK,M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AAE,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;QAC7F,IAAI,QAAQ,EAAE,CAAC;YACd,oEAAoE;YACpE,kEAAkE;YAClE,8DAA8D;YAC9D,wEAAwE;YACxE,QAAQ,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACjC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC7B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;YAC1F,CAAC;YACD,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,QAAQ,GAAa,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QAClF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,GAAG,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;QACpF,OAAO,IAAI,CAAC;IACb,CAAC;IAED,UAAU,CAAC,IAAY;QACtB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACD","sourcesContent":["// @generated vendored verbatim from oh-my-pi packages/hashline @ 15b5c1397fc -- DO NOT EDIT.\n// Parity source for the Atomic hashline edit engine (issue #1483); adapted only for Atomic's Node runtime (relative imports, Bun->Node host calls, erasable constructor syntax).\n/**\n * Per-session snapshot store used by {@link Recovery} and {@link Patcher} to\n * bind hashline section tags to the exact file content that minted them.\n *\n * A section tag is a content-derived hash of the *whole file* (see\n * {@link computeFileHash}). Any read of byte-identical content mints the same\n * tag, so reads of one file state fuse onto one anchor and a follow-up edit\n * anchored at any line validates whenever the live file still hashes to it.\n *\n * Producers (typically `read` / `search` / `write` tools) call\n * {@link SnapshotStore.record} with the full normalized text they observed.\n * The store hashes it, dedups against the per-path history, and returns the\n * tag. Consumers (the patcher) resolve an unambiguous stale tag back to the\n * recorded full text via {@link SnapshotStore.byHash} and 3-way-merge the\n * would-be edit onto the live content.\n *\n * The abstract base class lets callers plug in whatever storage they like\n * (LRU, persistent SQLite, etc.). {@link InMemorySnapshotStore} ships as a\n * sensible default backed by `lru-cache`: a bounded set of paths, each with a\n * short history of full-file versions so in-session edit chains can still\n * recover against the version a stale tag names.\n */\nimport { LRUCache } from \"lru-cache/raw\";\nimport { computeFileHash } from \"./format.js\";\n\n/**\n * One full-file version observed at a point in time. The tag the model sees is\n * {@link Snapshot.hash}; recovery replays edits against {@link Snapshot.text}.\n */\nexport interface Snapshot {\n\t/** Canonical path this version belongs to. */\n\treadonly path: string;\n\t/** Full normalized (LF, no BOM) file text as observed. */\n\treadonly text: string;\n\t/** Content-derived tag for {@link Snapshot.text} (see {@link computeFileHash}). */\n\treadonly hash: string;\n\t/** Timestamp (ms since epoch) the version was recorded. */\n\trecordedAt: number;\n}\n\n/**\n * Storage seam for full-file version snapshots. The patcher calls {@link head}\n * for the latest version of a path and {@link byHash} when it needs the\n * specific historical version a section's stale tag names.\n */\nexport abstract class SnapshotStore {\n\t/** Most-recently recorded version for `path`, or `null` if none. */\n\tabstract head(path: string): Snapshot | null;\n\n\t/** Recorded unambiguous version for `path` whose tag equals `hash`, or `null`. */\n\tabstract byHash(path: string, hash: string): Snapshot | null;\n\n\t/** Recorded version for `path` whose tag and full text both match, or `null`. */\n\tbyHashAndText(path: string, hash: string, text: string): Snapshot | null {\n\t\tconst snapshot = this.byHash(path, hash);\n\t\treturn snapshot?.text === text ? snapshot : null;\n\t}\n\n\t/** Record the full normalized text of `path` and return its content tag. */\n\tabstract record(path: string, fullText: string): string;\n\n\t/** Drop the version history for a single path. */\n\tabstract invalidate(path: string): void;\n\n\t/** Drop every version history. */\n\tabstract clear(): void;\n}\n\nconst DEFAULT_MAX_PATHS = 30;\nconst DEFAULT_MAX_VERSIONS_PER_PATH = 4;\n/** Global ceiling on retained snapshot text across all paths (UTF-16 code units). */\nconst DEFAULT_MAX_TOTAL_BYTES = 64 * 1024 * 1024;\n\nexport interface InMemorySnapshotStoreOptions {\n\t/** Maximum number of distinct paths tracked at once (default 30). LRU eviction. */\n\tmaxPaths?: number;\n\t/** Maximum full-file versions retained per path (default 4). Oldest dropped first. */\n\tmaxVersionsPerPath?: number;\n\t/**\n\t * Global ceiling on retained snapshot text summed across every path's\n\t * version history, measured in UTF-16 code units (default 64 MiB).\n\t * Least-recently-used path histories are evicted to stay under it.\n\t */\n\tmaxTotalBytes?: number;\n}\n\n/**\n * In-memory {@link SnapshotStore} backed by `lru-cache`. Per-path history is a\n * short ring of full-file versions (oldest dropped first); per-session path\n * tracking is LRU-bounded so cold paths age out automatically.\n *\n * Recording byte-identical content again refreshes recency and reuses the\n * existing tag (read fusion); recording new content unshifts a fresh version\n * onto the front of the path history.\n */\nexport class InMemorySnapshotStore extends SnapshotStore {\n\treadonly #versions: LRUCache<string, Snapshot[]>;\n\treadonly #maxVersionsPerPath: number;\n\n\tconstructor(options: InMemorySnapshotStoreOptions = {}) {\n\t\tsuper();\n\t\tthis.#versions = new LRUCache<string, Snapshot[]>({\n\t\t\tmax: options.maxPaths ?? DEFAULT_MAX_PATHS,\n\t\t\tmaxSize: options.maxTotalBytes ?? DEFAULT_MAX_TOTAL_BYTES,\n\t\t\tsizeCalculation: history => {\n\t\t\t\tlet total = 1;\n\t\t\t\tfor (const version of history) total += version.text.length;\n\t\t\t\treturn total;\n\t\t\t},\n\t\t});\n\t\tthis.#maxVersionsPerPath = options.maxVersionsPerPath ?? DEFAULT_MAX_VERSIONS_PER_PATH;\n\t}\n\n\thead(path: string): Snapshot | null {\n\t\treturn this.#versions.get(path)?.[0] ?? null;\n\t}\n\n\tbyHash(path: string, hash: string): Snapshot | null {\n\t\tconst matches = this.#versions.get(path)?.filter(version => version.hash === hash) ?? [];\n\t\t// A 4-hex tag can collide. Recovery only proceeds when the tag maps to a\n\t\t// single retained snapshot; otherwise the caller must re-read.\n\t\treturn matches.length === 1 ? matches[0]! : null;\n\t}\n\n\toverride byHashAndText(path: string, hash: string, text: string): Snapshot | null {\n\t\treturn this.#versions.get(path)?.find(version => version.hash === hash && version.text === text) ?? null;\n\t}\n\n\trecord(path: string, fullText: string): string {\n\t\tconst hash = computeFileHash(fullText);\n\t\t// `get` refreshes LRU recency for `path`.\n\t\tconst history = this.#versions.get(path) ?? [];\n\t\tconst existing = history.find(version => version.hash === hash && version.text === fullText);\n\t\tif (existing) {\n\t\t\t// Same content state observed again: refresh recency and promote to\n\t\t\t// head (it is the current file content), then reuse the tag. Hash\n\t\t\t// collisions with different text must be retained as distinct\n\t\t\t// snapshots; the 4-hex tag is only a lookup key, not proof of identity.\n\t\t\texisting.recordedAt = Date.now();\n\t\t\tif (history[0] !== existing) {\n\t\t\t\tthis.#versions.set(path, [existing, ...history.filter(version => version !== existing)]);\n\t\t\t}\n\t\t\treturn hash;\n\t\t}\n\n\t\tconst snapshot: Snapshot = { path, text: fullText, hash, recordedAt: Date.now() };\n\t\tthis.#versions.set(path, [snapshot, ...history].slice(0, this.#maxVersionsPerPath));\n\t\treturn hash;\n\t}\n\n\tinvalidate(path: string): void {\n\t\tthis.#versions.delete(path);\n\t}\n\n\tclear(): void {\n\t\tthis.#versions.clear();\n\t}\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { StreamOptions } from "./types.js";
2
+ export declare function streamHashLines(source: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>, options?: StreamOptions): AsyncGenerator<string>;
3
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/hashline-engine/stream.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAoFhD,wBAAuB,eAAe,CACrC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,EAC9D,OAAO,GAAE,aAAkB,GACzB,cAAc,CAAC,MAAM,CAAC,CAkCxB","sourcesContent":["// @generated vendored verbatim from oh-my-pi packages/hashline @ 15b5c1397fc -- DO NOT EDIT.\n// Parity source for the Atomic hashline edit engine (issue #1483); adapted only for Atomic's Node runtime (relative imports, Bun->Node host calls, erasable constructor syntax).\n/**\n * Lazily format a stream of UTF-8 bytes into hashline-numbered lines, yielded\n * as bounded text chunks. Used to send `read`-style file content to consumers\n * without materializing the full file at once.\n *\n * Each yielded chunk is at most {@link StreamOptions.maxChunkLines} lines and\n * at most {@link StreamOptions.maxChunkBytes} UTF-8 bytes (whichever fires\n * first).\n */\nimport { formatNumberedLine } from \"./format.js\";\nimport type { StreamOptions } from \"./types.js\";\n\ninterface ResolvedStreamOptions {\n\tstartLine: number;\n\tmaxChunkLines: number;\n\tmaxChunkBytes: number;\n}\n\nfunction resolveStreamOptions(options: StreamOptions): ResolvedStreamOptions {\n\treturn {\n\t\tstartLine: options.startLine ?? 1,\n\t\tmaxChunkLines: options.maxChunkLines ?? 200,\n\t\tmaxChunkBytes: options.maxChunkBytes ?? 64 * 1024,\n\t};\n}\n\ninterface ChunkEmitter {\n\tpushLine: (line: string) => string[];\n\tflush: () => string | undefined;\n}\n\nfunction createChunkEmitter(options: ResolvedStreamOptions): ChunkEmitter {\n\tlet lineNumber = options.startLine;\n\tlet outLines: string[] = [];\n\tlet outBytes = 0;\n\n\tconst flush = (): string | undefined => {\n\t\tif (outLines.length === 0) return undefined;\n\t\tconst chunk = outLines.join(\"\\n\");\n\t\toutLines = [];\n\t\toutBytes = 0;\n\t\treturn chunk;\n\t};\n\n\tconst pushLine = (line: string): string[] => {\n\t\tconst formatted = formatNumberedLine(lineNumber, line);\n\t\tlineNumber++;\n\n\t\tconst chunks: string[] = [];\n\t\tconst sepBytes = outLines.length === 0 ? 0 : 1;\n\t\tconst lineBytes = Buffer.byteLength(formatted, \"utf-8\");\n\t\tconst wouldOverflow =\n\t\t\toutLines.length >= options.maxChunkLines || outBytes + sepBytes + lineBytes > options.maxChunkBytes;\n\n\t\tif (outLines.length > 0 && wouldOverflow) {\n\t\t\tconst flushed = flush();\n\t\t\tif (flushed) chunks.push(flushed);\n\t\t}\n\n\t\toutLines.push(formatted);\n\t\toutBytes += (outLines.length === 1 ? 0 : 1) + lineBytes;\n\n\t\tif (outLines.length >= options.maxChunkLines || outBytes >= options.maxChunkBytes) {\n\t\t\tconst flushed = flush();\n\t\t\tif (flushed) chunks.push(flushed);\n\t\t}\n\t\treturn chunks;\n\t};\n\n\treturn { pushLine, flush };\n}\n\nfunction isReadableStream(value: unknown): value is ReadableStream<Uint8Array> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"getReader\" in value &&\n\t\ttypeof (value as { getReader?: unknown }).getReader === \"function\"\n\t);\n}\n\nasync function* bytesFromReadableStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<Uint8Array> {\n\tconst reader = stream.getReader();\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) return;\n\t\t\tif (value) yield value;\n\t\t}\n\t} finally {\n\t\treader.releaseLock();\n\t}\n}\n\nexport async function* streamHashLines(\n\tsource: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>,\n\toptions: StreamOptions = {},\n): AsyncGenerator<string> {\n\tconst resolved = resolveStreamOptions(options);\n\tconst decoder = new TextDecoder(\"utf-8\");\n\tconst chunks = isReadableStream(source) ? bytesFromReadableStream(source) : source;\n\tconst emitter = createChunkEmitter(resolved);\n\n\tlet pending = \"\";\n\tlet sawAnyLine = false;\n\n\tfor await (const chunk of chunks) {\n\t\tpending += decoder.decode(chunk, { stream: true });\n\t\tlet nl = pending.indexOf(\"\\n\");\n\t\twhile (nl !== -1) {\n\t\t\tconst raw = pending.slice(0, nl);\n\t\t\tconst line = raw.endsWith(\"\\r\") ? raw.slice(0, -1) : raw;\n\t\t\tsawAnyLine = true;\n\t\t\tfor (const out of emitter.pushLine(line)) yield out;\n\t\t\tpending = pending.slice(nl + 1);\n\t\t\tnl = pending.indexOf(\"\\n\");\n\t\t}\n\t}\n\n\tpending += decoder.decode();\n\tif (pending.length > 0) {\n\t\tsawAnyLine = true;\n\t\tconst tail = pending.endsWith(\"\\r\") ? pending.slice(0, -1) : pending;\n\t\tfor (const out of emitter.pushLine(tail)) yield out;\n\t}\n\tif (!sawAnyLine) {\n\t\tfor (const out of emitter.pushLine(\"\")) yield out;\n\t}\n\n\tconst last = emitter.flush();\n\tif (last) yield last;\n}\n"]}
@@ -0,0 +1,111 @@
1
+ // @generated vendored verbatim from oh-my-pi packages/hashline @ 15b5c1397fc -- DO NOT EDIT.
2
+ // Parity source for the Atomic hashline edit engine (issue #1483); adapted only for Atomic's Node runtime (relative imports, Bun->Node host calls, erasable constructor syntax).
3
+ /**
4
+ * Lazily format a stream of UTF-8 bytes into hashline-numbered lines, yielded
5
+ * as bounded text chunks. Used to send `read`-style file content to consumers
6
+ * without materializing the full file at once.
7
+ *
8
+ * Each yielded chunk is at most {@link StreamOptions.maxChunkLines} lines and
9
+ * at most {@link StreamOptions.maxChunkBytes} UTF-8 bytes (whichever fires
10
+ * first).
11
+ */
12
+ import { formatNumberedLine } from "./format.js";
13
+ function resolveStreamOptions(options) {
14
+ return {
15
+ startLine: options.startLine ?? 1,
16
+ maxChunkLines: options.maxChunkLines ?? 200,
17
+ maxChunkBytes: options.maxChunkBytes ?? 64 * 1024,
18
+ };
19
+ }
20
+ function createChunkEmitter(options) {
21
+ let lineNumber = options.startLine;
22
+ let outLines = [];
23
+ let outBytes = 0;
24
+ const flush = () => {
25
+ if (outLines.length === 0)
26
+ return undefined;
27
+ const chunk = outLines.join("\n");
28
+ outLines = [];
29
+ outBytes = 0;
30
+ return chunk;
31
+ };
32
+ const pushLine = (line) => {
33
+ const formatted = formatNumberedLine(lineNumber, line);
34
+ lineNumber++;
35
+ const chunks = [];
36
+ const sepBytes = outLines.length === 0 ? 0 : 1;
37
+ const lineBytes = Buffer.byteLength(formatted, "utf-8");
38
+ const wouldOverflow = outLines.length >= options.maxChunkLines || outBytes + sepBytes + lineBytes > options.maxChunkBytes;
39
+ if (outLines.length > 0 && wouldOverflow) {
40
+ const flushed = flush();
41
+ if (flushed)
42
+ chunks.push(flushed);
43
+ }
44
+ outLines.push(formatted);
45
+ outBytes += (outLines.length === 1 ? 0 : 1) + lineBytes;
46
+ if (outLines.length >= options.maxChunkLines || outBytes >= options.maxChunkBytes) {
47
+ const flushed = flush();
48
+ if (flushed)
49
+ chunks.push(flushed);
50
+ }
51
+ return chunks;
52
+ };
53
+ return { pushLine, flush };
54
+ }
55
+ function isReadableStream(value) {
56
+ return (typeof value === "object" &&
57
+ value !== null &&
58
+ "getReader" in value &&
59
+ typeof value.getReader === "function");
60
+ }
61
+ async function* bytesFromReadableStream(stream) {
62
+ const reader = stream.getReader();
63
+ try {
64
+ while (true) {
65
+ const { done, value } = await reader.read();
66
+ if (done)
67
+ return;
68
+ if (value)
69
+ yield value;
70
+ }
71
+ }
72
+ finally {
73
+ reader.releaseLock();
74
+ }
75
+ }
76
+ export async function* streamHashLines(source, options = {}) {
77
+ const resolved = resolveStreamOptions(options);
78
+ const decoder = new TextDecoder("utf-8");
79
+ const chunks = isReadableStream(source) ? bytesFromReadableStream(source) : source;
80
+ const emitter = createChunkEmitter(resolved);
81
+ let pending = "";
82
+ let sawAnyLine = false;
83
+ for await (const chunk of chunks) {
84
+ pending += decoder.decode(chunk, { stream: true });
85
+ let nl = pending.indexOf("\n");
86
+ while (nl !== -1) {
87
+ const raw = pending.slice(0, nl);
88
+ const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
89
+ sawAnyLine = true;
90
+ for (const out of emitter.pushLine(line))
91
+ yield out;
92
+ pending = pending.slice(nl + 1);
93
+ nl = pending.indexOf("\n");
94
+ }
95
+ }
96
+ pending += decoder.decode();
97
+ if (pending.length > 0) {
98
+ sawAnyLine = true;
99
+ const tail = pending.endsWith("\r") ? pending.slice(0, -1) : pending;
100
+ for (const out of emitter.pushLine(tail))
101
+ yield out;
102
+ }
103
+ if (!sawAnyLine) {
104
+ for (const out of emitter.pushLine(""))
105
+ yield out;
106
+ }
107
+ const last = emitter.flush();
108
+ if (last)
109
+ yield last;
110
+ }
111
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../src/core/tools/hashline-engine/stream.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,iLAAiL;AACjL;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AASjD,SAAS,oBAAoB,CAAC,OAAsB;IACnD,OAAO;QACN,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC;QACjC,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,GAAG;QAC3C,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,EAAE,GAAG,IAAI;KACjD,CAAC;AACH,CAAC;AAOD,SAAS,kBAAkB,CAAC,OAA8B;IACzD,IAAI,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IACnC,IAAI,QAAQ,GAAa,EAAE,CAAC;IAC5B,IAAI,QAAQ,GAAG,CAAC,CAAC;IAEjB,MAAM,KAAK,GAAG,GAAuB,EAAE;QACtC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,QAAQ,GAAG,EAAE,CAAC;QACd,QAAQ,GAAG,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C7B,IAAI,IAAI;QAAE,MAAM,IAAI,CAAC;AACtB,CAAC","sourcesContent":["// @generated vendored verbatim from oh-my-pi packages/hashline @ 15b5c1397fc -- DO NOT EDIT.\n// Parity source for the Atomic hashline edit engine (issue #1483); adapted only for Atomic's Node runtime (relative imports, Bun->Node host calls, erasable constructor syntax).\n/**\n * Lazily format a stream of UTF-8 bytes into hashline-numbered lines, yielded\n * as bounded text chunks. Used to send `read`-style file content to consumers\n * without materializing the full file at once.\n *\n * Each yielded chunk is at most {@link StreamOptions.maxChunkLines} lines and\n * at most {@link StreamOptions.maxChunkBytes} UTF-8 bytes (whichever fires\n * first).\n */\nimport { formatNumberedLine } from \"./format.js\";\nimport type { StreamOptions } from \"./types.js\";\n\ninterface ResolvedStreamOptions {\n\tstartLine: number;\n\tmaxChunkLines: number;\n\tmaxChunkBytes: number;\n}\n\nfunction resolveStreamOptions(options: StreamOptions): ResolvedStreamOptions {\n\treturn {\n\t\tstartLine: options.startLine ?? 1,\n\t\tmaxChunkLines: options.maxChunkLines ?? 200,\n\t\tmaxChunkBytes: options.maxChunkBytes ?? 64 * 1024,\n\t};\n}\n\ninterface ChunkEmitter {\n\tpushLine: (line: string) => string[];\n\tflush: () => string | undefined;\n}\n\nfunction createChunkEmitter(options: ResolvedStreamOptions): ChunkEmitter {\n\tlet lineNumber = options.startLine;\n\tlet outLines: string[] = [];\n\tlet outBytes = 0;\n\n\tconst flush = (): string | undefined => {\n\t\tif (outLines.length === 0) return undefined;\n\t\tconst chunk = outLines.join(\"\\n\");\n\t\toutLines = [];\n\t\toutBytes = 0;\n\t\treturn chunk;\n\t};\n\n\tconst pushLine = (line: string): string[] => {\n\t\tconst formatted = formatNumberedLine(lineNumber, line);\n\t\tlineNumber++;\n\n\t\tconst chunks: string[] = [];\n\t\tconst sepBytes = outLines.length === 0 ? 0 : 1;\n\t\tconst lineBytes = Buffer.byteLength(formatted, \"utf-8\");\n\t\tconst wouldOverflow =\n\t\t\toutLines.length >= options.maxChunkLines || outBytes + sepBytes + lineBytes > options.maxChunkBytes;\n\n\t\tif (outLines.length > 0 && wouldOverflow) {\n\t\t\tconst flushed = flush();\n\t\t\tif (flushed) chunks.push(flushed);\n\t\t}\n\n\t\toutLines.push(formatted);\n\t\toutBytes += (outLines.length === 1 ? 0 : 1) + lineBytes;\n\n\t\tif (outLines.length >= options.maxChunkLines || outBytes >= options.maxChunkBytes) {\n\t\t\tconst flushed = flush();\n\t\t\tif (flushed) chunks.push(flushed);\n\t\t}\n\t\treturn chunks;\n\t};\n\n\treturn { pushLine, flush };\n}\n\nfunction isReadableStream(value: unknown): value is ReadableStream<Uint8Array> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"getReader\" in value &&\n\t\ttypeof (value as { getReader?: unknown }).getReader === \"function\"\n\t);\n}\n\nasync function* bytesFromReadableStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<Uint8Array> {\n\tconst reader = stream.getReader();\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) return;\n\t\t\tif (value) yield value;\n\t\t}\n\t} finally {\n\t\treader.releaseLock();\n\t}\n}\n\nexport async function* streamHashLines(\n\tsource: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>,\n\toptions: StreamOptions = {},\n): AsyncGenerator<string> {\n\tconst resolved = resolveStreamOptions(options);\n\tconst decoder = new TextDecoder(\"utf-8\");\n\tconst chunks = isReadableStream(source) ? bytesFromReadableStream(source) : source;\n\tconst emitter = createChunkEmitter(resolved);\n\n\tlet pending = \"\";\n\tlet sawAnyLine = false;\n\n\tfor await (const chunk of chunks) {\n\t\tpending += decoder.decode(chunk, { stream: true });\n\t\tlet nl = pending.indexOf(\"\\n\");\n\t\twhile (nl !== -1) {\n\t\t\tconst raw = pending.slice(0, nl);\n\t\t\tconst line = raw.endsWith(\"\\r\") ? raw.slice(0, -1) : raw;\n\t\t\tsawAnyLine = true;\n\t\t\tfor (const out of emitter.pushLine(line)) yield out;\n\t\t\tpending = pending.slice(nl + 1);\n\t\t\tnl = pending.indexOf(\"\\n\");\n\t\t}\n\t}\n\n\tpending += decoder.decode();\n\tif (pending.length > 0) {\n\t\tsawAnyLine = true;\n\t\tconst tail = pending.endsWith(\"\\r\") ? pending.slice(0, -1) : pending;\n\t\tfor (const out of emitter.pushLine(tail)) yield out;\n\t}\n\tif (!sawAnyLine) {\n\t\tfor (const out of emitter.pushLine(\"\")) yield out;\n\t}\n\n\tconst last = emitter.flush();\n\tif (last) yield last;\n}\n"]}