@bastani/atomic 0.9.8 → 0.9.9-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 (814) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/builtin/cursor/CHANGELOG.md +12 -0
  3. package/dist/builtin/cursor/package.json +3 -3
  4. package/dist/builtin/intercom/CHANGELOG.md +13 -0
  5. package/dist/builtin/intercom/package.json +3 -3
  6. package/dist/builtin/mcp/CHANGELOG.md +13 -0
  7. package/dist/builtin/mcp/package.json +4 -4
  8. package/dist/builtin/subagents/CHANGELOG.md +13 -0
  9. package/dist/builtin/subagents/package.json +5 -5
  10. package/dist/builtin/subagents/src/runs/background/async-execution-chain.ts +2 -0
  11. package/dist/builtin/subagents/src/runs/background/async-execution-common.ts +7 -1
  12. package/dist/builtin/subagents/src/runs/background/async-execution-single.ts +2 -0
  13. package/dist/builtin/subagents/src/runs/background/async-execution-types.ts +8 -2
  14. package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-runner.ts +2 -0
  15. package/dist/builtin/subagents/src/runs/foreground/chain-execution-sequential-step.ts +2 -0
  16. package/dist/builtin/subagents/src/runs/foreground/execution-attempt.ts +2 -1
  17. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-async.ts +2 -0
  18. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel-task.ts +2 -0
  19. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-resume.ts +2 -0
  20. package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +2 -0
  21. package/dist/builtin/subagents/src/runs/shared/pi-args.ts +6 -0
  22. package/dist/builtin/subagents/src/shared/types-config.ts +4 -0
  23. package/dist/builtin/subagents/src/shared/types-depth.ts +29 -2
  24. package/dist/builtin/web-access/CHANGELOG.md +13 -0
  25. package/dist/builtin/web-access/package.json +3 -3
  26. package/dist/builtin/web-access/web-search-tool.ts +1 -2
  27. package/dist/builtin/workflows/CHANGELOG.md +29 -0
  28. package/dist/builtin/workflows/README.md +17 -8
  29. package/dist/builtin/workflows/builtin/goal-prompts.ts +8 -2
  30. package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +26 -9
  31. package/dist/builtin/workflows/builtin/ralph-forked-prompts.ts +1 -1
  32. package/dist/builtin/workflows/builtin/ralph-reviewer-prompt.ts +8 -3
  33. package/dist/builtin/workflows/builtin/ralph-runner.ts +2 -0
  34. package/dist/builtin/workflows/builtin/shared-prompts.ts +24 -1
  35. package/dist/builtin/workflows/package.json +3 -3
  36. package/dist/builtin/workflows/src/durable/backend.ts +53 -15
  37. package/dist/builtin/workflows/src/durable/completed-catalog.ts +245 -0
  38. package/dist/builtin/workflows/src/durable/completed-inspection.ts +213 -0
  39. package/dist/builtin/workflows/src/durable/dbos-backend.ts +120 -170
  40. package/dist/builtin/workflows/src/durable/dbos-envelope.ts +84 -8
  41. package/dist/builtin/workflows/src/durable/dbos-metadata.ts +98 -0
  42. package/dist/builtin/workflows/src/durable/dbos-tombstone.ts +27 -0
  43. package/dist/builtin/workflows/src/durable/factory.ts +1 -1
  44. package/dist/builtin/workflows/src/durable/file-backend.ts +247 -241
  45. package/dist/builtin/workflows/src/durable/file-lock.ts +153 -0
  46. package/dist/builtin/workflows/src/durable/file-state.ts +104 -0
  47. package/dist/builtin/workflows/src/durable/format-version.ts +12 -0
  48. package/dist/builtin/workflows/src/durable/index.ts +12 -0
  49. package/dist/builtin/workflows/src/durable/resume-catalog.ts +16 -27
  50. package/dist/builtin/workflows/src/durable/resume-eligibility.ts +20 -0
  51. package/dist/builtin/workflows/src/durable/resume-runtime.ts +29 -29
  52. package/dist/builtin/workflows/src/durable/scoped-backend.ts +20 -3
  53. package/dist/builtin/workflows/src/durable/stage-primitive.ts +29 -8
  54. package/dist/builtin/workflows/src/durable/types.ts +3 -0
  55. package/dist/builtin/workflows/src/engine/primitives/task.ts +1 -0
  56. package/dist/builtin/workflows/src/engine/run.ts +14 -14
  57. package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +39 -9
  58. package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +10 -0
  59. package/dist/builtin/workflows/src/extension/runtime-durable-resume.ts +133 -0
  60. package/dist/builtin/workflows/src/extension/runtime.ts +15 -40
  61. package/dist/builtin/workflows/src/extension/wiring.ts +9 -6
  62. package/dist/builtin/workflows/src/extension/workflow-durable-resume-command.ts +226 -0
  63. package/dist/builtin/workflows/src/extension/workflow-prompts.ts +1 -0
  64. package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +66 -112
  65. package/dist/builtin/workflows/src/extension/workflow-schema.ts +5 -5
  66. package/dist/builtin/workflows/src/extension/workflow-tool-control.ts +16 -1
  67. package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +50 -43
  68. package/dist/builtin/workflows/src/runs/foreground/executor-direct-output.ts +91 -0
  69. package/dist/builtin/workflows/src/runs/foreground/executor-direct.ts +95 -46
  70. package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +3 -1
  71. package/dist/builtin/workflows/src/runs/foreground/executor-task-prompts.ts +1 -1
  72. package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +3 -0
  73. package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +1 -1
  74. package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +36 -7
  75. package/dist/builtin/workflows/src/runs/shared/worktree-cache-lifecycle.ts +25 -0
  76. package/dist/builtin/workflows/src/runs/shared/worktree-cwd.ts +103 -0
  77. package/dist/builtin/workflows/src/runs/shared/worktree-generation.ts +57 -0
  78. package/dist/builtin/workflows/src/runs/shared/worktree-git.ts +134 -8
  79. package/dist/builtin/workflows/src/runs/shared/worktree.ts +2 -0
  80. package/dist/builtin/workflows/src/shared/resumable-workflow-notices.ts +43 -0
  81. package/dist/builtin/workflows/src/shared/serializable.ts +1 -1
  82. package/dist/builtin/workflows/src/shared/timing.ts +4 -0
  83. package/dist/builtin/workflows/src/shared/types.ts +5 -3
  84. package/dist/builtin/workflows/src/tui/graph-view-constants.ts +1 -0
  85. package/dist/builtin/workflows/src/tui/graph-view-input.ts +24 -14
  86. package/dist/builtin/workflows/src/tui/workflow-resume-selector.ts +43 -13
  87. package/dist/bun/cli.d.ts.map +1 -1
  88. package/dist/bun/internal-intercom-broker.d.ts.map +1 -1
  89. package/dist/bun/register-bedrock.d.ts.map +1 -1
  90. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  91. package/dist/bun/split-loader.d.ts.map +1 -1
  92. package/dist/cli/args.d.ts.map +1 -1
  93. package/dist/cli/config-selector.d.ts.map +1 -1
  94. package/dist/cli/file-processor.d.ts.map +1 -1
  95. package/dist/cli/initial-message.d.ts.map +1 -1
  96. package/dist/cli/list-models.d.ts.map +1 -1
  97. package/dist/cli/project-trust.d.ts.map +1 -1
  98. package/dist/cli/session-picker.d.ts.map +1 -1
  99. package/dist/cli/startup-ui.d.ts.map +1 -1
  100. package/dist/cli.d.ts.map +1 -1
  101. package/dist/config-self-update.d.ts.map +1 -1
  102. package/dist/config.d.ts.map +1 -1
  103. package/dist/core/agent-session-accessors.d.ts.map +1 -1
  104. package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
  105. package/dist/core/agent-session-auto-compaction.js +5 -7
  106. package/dist/core/agent-session-auto-compaction.js.map +1 -1
  107. package/dist/core/agent-session-bash.d.ts.map +1 -1
  108. package/dist/core/agent-session-compaction.d.ts +6 -34
  109. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  110. package/dist/core/agent-session-compaction.js +95 -233
  111. package/dist/core/agent-session-compaction.js.map +1 -1
  112. package/dist/core/agent-session-events.d.ts.map +1 -1
  113. package/dist/core/agent-session-export.d.ts.map +1 -1
  114. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  115. package/dist/core/agent-session-message-queue.d.ts +0 -4
  116. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  117. package/dist/core/agent-session-message-queue.js +1 -5
  118. package/dist/core/agent-session-message-queue.js.map +1 -1
  119. package/dist/core/agent-session-methods.d.ts +5 -6
  120. package/dist/core/agent-session-methods.d.ts.map +1 -1
  121. package/dist/core/agent-session-methods.js.map +1 -1
  122. package/dist/core/agent-session-models.d.ts.map +1 -1
  123. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  124. package/dist/core/agent-session-retry.d.ts.map +1 -1
  125. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  126. package/dist/core/agent-session-services.d.ts.map +1 -1
  127. package/dist/core/agent-session-skill-block.d.ts.map +1 -1
  128. package/dist/core/agent-session-state.d.ts.map +1 -1
  129. package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
  130. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  131. package/dist/core/agent-session-tree.d.ts.map +1 -1
  132. package/dist/core/agent-session-types.d.ts +2 -12
  133. package/dist/core/agent-session-types.d.ts.map +1 -1
  134. package/dist/core/agent-session-types.js.map +1 -1
  135. package/dist/core/agent-session.d.ts.map +1 -1
  136. package/dist/core/anthropic-thinking-guard.d.ts.map +1 -1
  137. package/dist/core/async/format.d.ts.map +1 -1
  138. package/dist/core/async/job-manager.d.ts.map +1 -1
  139. package/dist/core/async/session-manager.d.ts.map +1 -1
  140. package/dist/core/async/types.d.ts.map +1 -1
  141. package/dist/core/atomic-guide-command.d.ts.map +1 -1
  142. package/dist/core/auth-guidance.d.ts.map +1 -1
  143. package/dist/core/auth-storage-backends.d.ts.map +1 -1
  144. package/dist/core/auth-storage.d.ts +4 -0
  145. package/dist/core/auth-storage.d.ts.map +1 -1
  146. package/dist/core/bash-executor.d.ts.map +1 -1
  147. package/dist/core/builtin-packages.d.ts.map +1 -1
  148. package/dist/core/codex-fast-mode.d.ts.map +1 -1
  149. package/dist/core/compaction/branch-summarization.d.ts +1 -1
  150. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  151. package/dist/core/compaction/branch-summarization.js +1 -2
  152. package/dist/core/compaction/branch-summarization.js.map +1 -1
  153. package/dist/core/compaction/compaction-boundary.d.ts +9 -0
  154. package/dist/core/compaction/compaction-boundary.d.ts.map +1 -0
  155. package/dist/core/compaction/compaction-boundary.js +115 -0
  156. package/dist/core/compaction/compaction-boundary.js.map +1 -0
  157. package/dist/core/compaction/compaction-parameters.d.ts +5 -0
  158. package/dist/core/compaction/compaction-parameters.d.ts.map +1 -0
  159. package/dist/core/compaction/compaction-parameters.js +27 -0
  160. package/dist/core/compaction/compaction-parameters.js.map +1 -0
  161. package/dist/core/compaction/compaction-runner.d.ts +14 -0
  162. package/dist/core/compaction/compaction-runner.d.ts.map +1 -0
  163. package/dist/core/compaction/compaction-runner.js +29 -0
  164. package/dist/core/compaction/compaction-runner.js.map +1 -0
  165. package/dist/core/compaction/compaction-types.d.ts +79 -0
  166. package/dist/core/compaction/compaction-types.d.ts.map +1 -0
  167. package/dist/core/compaction/compaction-types.js +6 -0
  168. package/dist/core/compaction/compaction-types.js.map +1 -0
  169. package/dist/core/compaction/compaction.d.ts.map +1 -1
  170. package/dist/core/compaction/deleted-ranges.d.ts +6 -0
  171. package/dist/core/compaction/deleted-ranges.d.ts.map +1 -0
  172. package/dist/core/compaction/deleted-ranges.js +134 -0
  173. package/dist/core/compaction/deleted-ranges.js.map +1 -0
  174. package/dist/core/compaction/index.d.ts +7 -1
  175. package/dist/core/compaction/index.d.ts.map +1 -1
  176. package/dist/core/compaction/index.js +7 -1
  177. package/dist/core/compaction/index.js.map +1 -1
  178. package/dist/core/compaction/range-planner.d.ts +21 -0
  179. package/dist/core/compaction/range-planner.d.ts.map +1 -0
  180. package/dist/core/compaction/range-planner.js +145 -0
  181. package/dist/core/compaction/range-planner.js.map +1 -0
  182. package/dist/core/compaction/transcript-serialization.d.ts +11 -0
  183. package/dist/core/compaction/transcript-serialization.d.ts.map +1 -0
  184. package/dist/core/compaction/transcript-serialization.js +104 -0
  185. package/dist/core/compaction/transcript-serialization.js.map +1 -0
  186. package/dist/core/compaction/utils.d.ts.map +1 -1
  187. package/dist/core/context-window.d.ts.map +1 -1
  188. package/dist/core/copilot-anthropic-sse-repair.d.ts.map +1 -1
  189. package/dist/core/copilot-errors.d.ts.map +1 -1
  190. package/dist/core/copilot-gemini-payload-sanitizer.d.ts.map +1 -1
  191. package/dist/core/copilot-gemini-reasoning.d.ts.map +1 -1
  192. package/dist/core/copilot-gemini-tool-arguments.d.ts.map +1 -1
  193. package/dist/core/copilot-hosts.d.ts.map +1 -1
  194. package/dist/core/copilot-model-catalog.d.ts.map +1 -1
  195. package/dist/core/copilot-model-static-fallbacks.d.ts.map +1 -1
  196. package/dist/core/copilot-model-synthesis.d.ts.map +1 -1
  197. package/dist/core/defaults.d.ts.map +1 -1
  198. package/dist/core/diagnostics.d.ts.map +1 -1
  199. package/dist/core/event-bus.d.ts.map +1 -1
  200. package/dist/core/exec.d.ts.map +1 -1
  201. package/dist/core/experimental.d.ts.map +1 -1
  202. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  203. package/dist/core/export-html/index.d.ts.map +1 -1
  204. package/dist/core/export-html/template-script.d.ts.map +1 -1
  205. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  206. package/dist/core/extensions/agent-events.d.ts.map +1 -1
  207. package/dist/core/extensions/api-types.d.ts.map +1 -1
  208. package/dist/core/extensions/command-types.d.ts.map +1 -1
  209. package/dist/core/extensions/context-types.d.ts +2 -2
  210. package/dist/core/extensions/context-types.d.ts.map +1 -1
  211. package/dist/core/extensions/context-types.js.map +1 -1
  212. package/dist/core/extensions/event-results.d.ts +2 -2
  213. package/dist/core/extensions/event-results.d.ts.map +1 -1
  214. package/dist/core/extensions/event-results.js.map +1 -1
  215. package/dist/core/extensions/event-types.d.ts.map +1 -1
  216. package/dist/core/extensions/index.d.ts.map +1 -1
  217. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  218. package/dist/core/extensions/loader-core.d.ts.map +1 -1
  219. package/dist/core/extensions/loader-discovery.d.ts.map +1 -1
  220. package/dist/core/extensions/loader-resources.d.ts.map +1 -1
  221. package/dist/core/extensions/loader-runtime.d.ts.map +1 -1
  222. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  223. package/dist/core/extensions/loader.d.ts.map +1 -1
  224. package/dist/core/extensions/message-types.d.ts.map +1 -1
  225. package/dist/core/extensions/provider-types.d.ts.map +1 -1
  226. package/dist/core/extensions/reactive-widget.d.ts.map +1 -1
  227. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  228. package/dist/core/extensions/runner-events.d.ts.map +1 -1
  229. package/dist/core/extensions/runner-handlers.d.ts.map +1 -1
  230. package/dist/core/extensions/runner-project-trust.d.ts.map +1 -1
  231. package/dist/core/extensions/runner-registries.d.ts.map +1 -1
  232. package/dist/core/extensions/runner-shortcuts.d.ts.map +1 -1
  233. package/dist/core/extensions/runner-ui.d.ts.map +1 -1
  234. package/dist/core/extensions/runner.d.ts.map +1 -1
  235. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  236. package/dist/core/extensions/session-events.d.ts +7 -7
  237. package/dist/core/extensions/session-events.d.ts.map +1 -1
  238. package/dist/core/extensions/session-events.js.map +1 -1
  239. package/dist/core/extensions/tool-events.d.ts.map +1 -1
  240. package/dist/core/extensions/tool-types.d.ts.map +1 -1
  241. package/dist/core/extensions/types.d.ts.map +1 -1
  242. package/dist/core/extensions/ui-types.d.ts.map +1 -1
  243. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  244. package/dist/core/flattened-tool-arguments.d.ts.map +1 -1
  245. package/dist/core/footer-data-provider.d.ts.map +1 -1
  246. package/dist/core/http-dispatcher.d.ts.map +1 -1
  247. package/dist/core/index.d.ts +1 -1
  248. package/dist/core/index.d.ts.map +1 -1
  249. package/dist/core/index.js.map +1 -1
  250. package/dist/core/keybindings.d.ts.map +1 -1
  251. package/dist/core/messages.d.ts +4 -0
  252. package/dist/core/messages.d.ts.map +1 -1
  253. package/dist/core/messages.js +11 -0
  254. package/dist/core/messages.js.map +1 -1
  255. package/dist/core/model-registry-auth.d.ts.map +1 -1
  256. package/dist/core/model-registry-builtins.d.ts.map +1 -1
  257. package/dist/core/model-registry-builtins.js.map +1 -1
  258. package/dist/core/model-registry-custom-loader.d.ts.map +1 -1
  259. package/dist/core/model-registry-custom-loader.js.map +1 -1
  260. package/dist/core/model-registry-dynamic.d.ts.map +1 -1
  261. package/dist/core/model-registry-loader.d.ts.map +1 -1
  262. package/dist/core/model-registry-schemas.d.ts +65 -13
  263. package/dist/core/model-registry-schemas.d.ts.map +1 -1
  264. package/dist/core/model-registry-schemas.js +5 -1
  265. package/dist/core/model-registry-schemas.js.map +1 -1
  266. package/dist/core/model-registry-types.d.ts.map +1 -1
  267. package/dist/core/model-registry.d.ts.map +1 -1
  268. package/dist/core/model-resolver-cli.d.ts.map +1 -1
  269. package/dist/core/model-resolver-defaults.d.ts.map +1 -1
  270. package/dist/core/model-resolver-initial.d.ts.map +1 -1
  271. package/dist/core/model-resolver-patterns.d.ts.map +1 -1
  272. package/dist/core/model-resolver-scope.d.ts.map +1 -1
  273. package/dist/core/model-resolver-types.d.ts.map +1 -1
  274. package/dist/core/model-resolver.d.ts.map +1 -1
  275. package/dist/core/openai-responses-payload-sanitizer.d.ts.map +1 -1
  276. package/dist/core/output-guard.d.ts.map +1 -1
  277. package/dist/core/package-manager-auto-resources.d.ts.map +1 -1
  278. package/dist/core/package-manager-command.d.ts.map +1 -1
  279. package/dist/core/package-manager-constants.d.ts.map +1 -1
  280. package/dist/core/package-manager-env.d.ts.map +1 -1
  281. package/dist/core/package-manager-git.d.ts.map +1 -1
  282. package/dist/core/package-manager-manifest.d.ts.map +1 -1
  283. package/dist/core/package-manager-npm.d.ts.map +1 -1
  284. package/dist/core/package-manager-operations.d.ts.map +1 -1
  285. package/dist/core/package-manager-paths.d.ts.map +1 -1
  286. package/dist/core/package-manager-progress.d.ts.map +1 -1
  287. package/dist/core/package-manager-resolver.d.ts.map +1 -1
  288. package/dist/core/package-manager-resource-accumulator.d.ts.map +1 -1
  289. package/dist/core/package-manager-resource-collector.d.ts.map +1 -1
  290. package/dist/core/package-manager-resource-files.d.ts.map +1 -1
  291. package/dist/core/package-manager-resource-patterns.d.ts.map +1 -1
  292. package/dist/core/package-manager-settings.d.ts.map +1 -1
  293. package/dist/core/package-manager-source.d.ts.map +1 -1
  294. package/dist/core/package-manager-types.d.ts.map +1 -1
  295. package/dist/core/package-manager.d.ts.map +1 -1
  296. package/dist/core/project-trust.d.ts.map +1 -1
  297. package/dist/core/prompt-templates-async.d.ts.map +1 -1
  298. package/dist/core/prompt-templates.d.ts.map +1 -1
  299. package/dist/core/provider-attribution.d.ts.map +1 -1
  300. package/dist/core/provider-context-usage.d.ts.map +1 -1
  301. package/dist/core/provider-context-usage.js +1 -2
  302. package/dist/core/provider-context-usage.js.map +1 -1
  303. package/dist/core/provider-display-names.d.ts.map +1 -1
  304. package/dist/core/resolve-config-value.d.ts.map +1 -1
  305. package/dist/core/resource-loader-assets.d.ts.map +1 -1
  306. package/dist/core/resource-loader-context-files.d.ts.map +1 -1
  307. package/dist/core/resource-loader-core.d.ts.map +1 -1
  308. package/dist/core/resource-loader-discovery.d.ts.map +1 -1
  309. package/dist/core/resource-loader-extensions.d.ts.map +1 -1
  310. package/dist/core/resource-loader-helpers.d.ts.map +1 -1
  311. package/dist/core/resource-loader-internals.d.ts.map +1 -1
  312. package/dist/core/resource-loader-package-resources.d.ts.map +1 -1
  313. package/dist/core/resource-loader-paths.d.ts.map +1 -1
  314. package/dist/core/resource-loader-reload.d.ts.map +1 -1
  315. package/dist/core/resource-loader-source-info.d.ts.map +1 -1
  316. package/dist/core/resource-loader-types.d.ts.map +1 -1
  317. package/dist/core/resource-loader.d.ts.map +1 -1
  318. package/dist/core/sdk-exports.d.ts.map +1 -1
  319. package/dist/core/sdk-types.d.ts.map +1 -1
  320. package/dist/core/sdk.d.ts.map +1 -1
  321. package/dist/core/session-cwd.d.ts.map +1 -1
  322. package/dist/core/session-entry-normalization.d.ts.map +1 -1
  323. package/dist/core/session-manager-archive.d.ts +2 -1
  324. package/dist/core/session-manager-archive.d.ts.map +1 -1
  325. package/dist/core/session-manager-archive.js +2 -2
  326. package/dist/core/session-manager-archive.js.map +1 -1
  327. package/dist/core/session-manager-classification.d.ts +9 -0
  328. package/dist/core/session-manager-classification.d.ts.map +1 -0
  329. package/dist/core/session-manager-classification.js +37 -0
  330. package/dist/core/session-manager-classification.js.map +1 -0
  331. package/dist/core/session-manager-core.d.ts +4 -4
  332. package/dist/core/session-manager-core.d.ts.map +1 -1
  333. package/dist/core/session-manager-core.js +13 -8
  334. package/dist/core/session-manager-core.js.map +1 -1
  335. package/dist/core/session-manager-entries.d.ts +4 -3
  336. package/dist/core/session-manager-entries.d.ts.map +1 -1
  337. package/dist/core/session-manager-entries.js +12 -10
  338. package/dist/core/session-manager-entries.js.map +1 -1
  339. package/dist/core/session-manager-history.d.ts +6 -23
  340. package/dist/core/session-manager-history.d.ts.map +1 -1
  341. package/dist/core/session-manager-history.js +23 -256
  342. package/dist/core/session-manager-history.js.map +1 -1
  343. package/dist/core/session-manager-list.d.ts.map +1 -1
  344. package/dist/core/session-manager-list.js +3 -3
  345. package/dist/core/session-manager-list.js.map +1 -1
  346. package/dist/core/session-manager-migrations.d.ts.map +1 -1
  347. package/dist/core/session-manager-paths.d.ts.map +1 -1
  348. package/dist/core/session-manager-storage.d.ts +1 -1
  349. package/dist/core/session-manager-storage.d.ts.map +1 -1
  350. package/dist/core/session-manager-storage.js +3 -2
  351. package/dist/core/session-manager-storage.js.map +1 -1
  352. package/dist/core/session-manager-types.d.ts +14 -15
  353. package/dist/core/session-manager-types.d.ts.map +1 -1
  354. package/dist/core/session-manager-types.js.map +1 -1
  355. package/dist/core/session-manager-validation.d.ts.map +1 -1
  356. package/dist/core/session-manager.d.ts +3 -2
  357. package/dist/core/session-manager.d.ts.map +1 -1
  358. package/dist/core/session-manager.js +1 -1
  359. package/dist/core/session-manager.js.map +1 -1
  360. package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
  361. package/dist/core/settings-manager-core.d.ts.map +1 -1
  362. package/dist/core/settings-manager-internals.d.ts.map +1 -1
  363. package/dist/core/settings-manager-resource-accessors.d.ts.map +1 -1
  364. package/dist/core/settings-manager-ui-accessors.d.ts.map +1 -1
  365. package/dist/core/settings-manager.d.ts.map +1 -1
  366. package/dist/core/settings-merge.d.ts.map +1 -1
  367. package/dist/core/settings-storage.d.ts.map +1 -1
  368. package/dist/core/settings-types.d.ts.map +1 -1
  369. package/dist/core/skills-async.d.ts.map +1 -1
  370. package/dist/core/skills.d.ts.map +1 -1
  371. package/dist/core/slash-commands.d.ts.map +1 -1
  372. package/dist/core/slash-commands.js +1 -1
  373. package/dist/core/slash-commands.js.map +1 -1
  374. package/dist/core/source-info.d.ts.map +1 -1
  375. package/dist/core/system-prompt.d.ts.map +1 -1
  376. package/dist/core/telemetry.d.ts.map +1 -1
  377. package/dist/core/thinking-blocks.d.ts.map +1 -1
  378. package/dist/core/timings.d.ts.map +1 -1
  379. package/dist/core/tools/artifact-protocol.d.ts.map +1 -1
  380. package/dist/core/tools/artifacts.d.ts.map +1 -1
  381. package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
  382. package/dist/core/tools/ask-user-question/config.d.ts.map +1 -1
  383. package/dist/core/tools/ask-user-question/index.d.ts.map +1 -1
  384. package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts.map +1 -1
  385. package/dist/core/tools/ask-user-question/state/inline-input.d.ts.map +1 -1
  386. package/dist/core/tools/ask-user-question/state/key-router.d.ts.map +1 -1
  387. package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts.map +1 -1
  388. package/dist/core/tools/ask-user-question/state/row-intent.d.ts.map +1 -1
  389. package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts.map +1 -1
  390. package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts.map +1 -1
  391. package/dist/core/tools/ask-user-question/state/selectors/focus.d.ts.map +1 -1
  392. package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts.map +1 -1
  393. package/dist/core/tools/ask-user-question/state/state-reducer.d.ts.map +1 -1
  394. package/dist/core/tools/ask-user-question/state/state.d.ts.map +1 -1
  395. package/dist/core/tools/ask-user-question/tool/format-answer.d.ts.map +1 -1
  396. package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts.map +1 -1
  397. package/dist/core/tools/ask-user-question/tool/types.d.ts.map +1 -1
  398. package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts.map +1 -1
  399. package/dist/core/tools/ask-user-question/view/body-residual-spacer.d.ts.map +1 -1
  400. package/dist/core/tools/ask-user-question/view/component-binding.d.ts.map +1 -1
  401. package/dist/core/tools/ask-user-question/view/components/chat-row-view.d.ts.map +1 -1
  402. package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts.map +1 -1
  403. package/dist/core/tools/ask-user-question/view/components/option-list-view.d.ts.map +1 -1
  404. package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts.map +1 -1
  405. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts.map +1 -1
  406. package/dist/core/tools/ask-user-question/view/components/preview/preview-box-renderer.d.ts.map +1 -1
  407. package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts.map +1 -1
  408. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts.map +1 -1
  409. package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts.map +1 -1
  410. package/dist/core/tools/ask-user-question/view/components/tab-bar.d.ts.map +1 -1
  411. package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts.map +1 -1
  412. package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts.map +1 -1
  413. package/dist/core/tools/ask-user-question/view/props-adapter.d.ts.map +1 -1
  414. package/dist/core/tools/ask-user-question/view/stateful-view.d.ts.map +1 -1
  415. package/dist/core/tools/ask-user-question/view/tab-components.d.ts.map +1 -1
  416. package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts.map +1 -1
  417. package/dist/core/tools/bash-async-execution.d.ts.map +1 -1
  418. package/dist/core/tools/bash-async-jobs.d.ts.map +1 -1
  419. package/dist/core/tools/bash-async-output.d.ts.map +1 -1
  420. package/dist/core/tools/bash-interceptor.d.ts.map +1 -1
  421. package/dist/core/tools/bash-leading-cd.d.ts.map +1 -1
  422. package/dist/core/tools/bash-pty-native.d.ts.map +1 -1
  423. package/dist/core/tools/bash.d.ts.map +1 -1
  424. package/dist/core/tools/block-resolver.d.ts.map +1 -1
  425. package/dist/core/tools/conflict-registry.d.ts.map +1 -1
  426. package/dist/core/tools/directory-tree.d.ts.map +1 -1
  427. package/dist/core/tools/edit-diff-preserve.d.ts.map +1 -1
  428. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  429. package/dist/core/tools/edit.d.ts.map +1 -1
  430. package/dist/core/tools/fetch-url.d.ts.map +1 -1
  431. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  432. package/dist/core/tools/find.d.ts.map +1 -1
  433. package/dist/core/tools/glob-path-utils.d.ts.map +1 -1
  434. package/dist/core/tools/grep.d.ts.map +1 -1
  435. package/dist/core/tools/hashline-engine/apply.d.ts.map +1 -1
  436. package/dist/core/tools/hashline-engine/block.d.ts.map +1 -1
  437. package/dist/core/tools/hashline-engine/diff-preview.d.ts.map +1 -1
  438. package/dist/core/tools/hashline-engine/format.d.ts.map +1 -1
  439. package/dist/core/tools/hashline-engine/fs.d.ts.map +1 -1
  440. package/dist/core/tools/hashline-engine/index.d.ts.map +1 -1
  441. package/dist/core/tools/hashline-engine/input.d.ts.map +1 -1
  442. package/dist/core/tools/hashline-engine/messages.d.ts.map +1 -1
  443. package/dist/core/tools/hashline-engine/mismatch.d.ts.map +1 -1
  444. package/dist/core/tools/hashline-engine/normalize.d.ts.map +1 -1
  445. package/dist/core/tools/hashline-engine/parser.d.ts.map +1 -1
  446. package/dist/core/tools/hashline-engine/patcher.d.ts.map +1 -1
  447. package/dist/core/tools/hashline-engine/prefixes.d.ts.map +1 -1
  448. package/dist/core/tools/hashline-engine/recovery.d.ts.map +1 -1
  449. package/dist/core/tools/hashline-engine/snapshots.d.ts.map +1 -1
  450. package/dist/core/tools/hashline-engine/stream.d.ts.map +1 -1
  451. package/dist/core/tools/hashline-engine/tokenizer.d.ts.map +1 -1
  452. package/dist/core/tools/hashline-engine/types.d.ts.map +1 -1
  453. package/dist/core/tools/hashline.d.ts.map +1 -1
  454. package/dist/core/tools/index.d.ts.map +1 -1
  455. package/dist/core/tools/ls.d.ts.map +1 -1
  456. package/dist/core/tools/notebook.d.ts.map +1 -1
  457. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  458. package/dist/core/tools/oversized-tool-result.d.ts.map +1 -1
  459. package/dist/core/tools/path-utils.d.ts.map +1 -1
  460. package/dist/core/tools/read-document-extract.d.ts.map +1 -1
  461. package/dist/core/tools/read-selectors.d.ts.map +1 -1
  462. package/dist/core/tools/read-url.d.ts.map +1 -1
  463. package/dist/core/tools/read.d.ts.map +1 -1
  464. package/dist/core/tools/render-utils.d.ts.map +1 -1
  465. package/dist/core/tools/resource-selectors.d.ts.map +1 -1
  466. package/dist/core/tools/search-details.d.ts.map +1 -1
  467. package/dist/core/tools/search-line-ranges.d.ts.map +1 -1
  468. package/dist/core/tools/search-native.d.ts.map +1 -1
  469. package/dist/core/tools/search.d.ts.map +1 -1
  470. package/dist/core/tools/structured-output.d.ts.map +1 -1
  471. package/dist/core/tools/todos-execute.d.ts.map +1 -1
  472. package/dist/core/tools/todos-locks.d.ts.map +1 -1
  473. package/dist/core/tools/todos-model.d.ts.map +1 -1
  474. package/dist/core/tools/todos-mutations.d.ts.map +1 -1
  475. package/dist/core/tools/todos-paths.d.ts.map +1 -1
  476. package/dist/core/tools/todos-render.d.ts.map +1 -1
  477. package/dist/core/tools/todos-storage.d.ts.map +1 -1
  478. package/dist/core/tools/todos-types.d.ts.map +1 -1
  479. package/dist/core/tools/todos-types.js +1 -1
  480. package/dist/core/tools/todos-types.js.map +1 -1
  481. package/dist/core/tools/todos.d.ts.map +1 -1
  482. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  483. package/dist/core/tools/tool-definition-wrapper.js +6 -2
  484. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  485. package/dist/core/tools/tool-limits.d.ts.map +1 -1
  486. package/dist/core/tools/truncate.d.ts.map +1 -1
  487. package/dist/core/tools/url-ip-guards.d.ts.map +1 -1
  488. package/dist/core/tools/write.d.ts.map +1 -1
  489. package/dist/core/trust-manager.d.ts.map +1 -1
  490. package/dist/core/typebox-compat.d.ts +12 -0
  491. package/dist/core/typebox-compat.d.ts.map +1 -0
  492. package/dist/core/typebox-compat.js +10 -0
  493. package/dist/core/typebox-compat.js.map +1 -0
  494. package/dist/index-extensions.d.ts.map +1 -1
  495. package/dist/index.d.ts +4 -2
  496. package/dist/index.d.ts.map +1 -1
  497. package/dist/index.js +3 -1
  498. package/dist/index.js.map +1 -1
  499. package/dist/main-app-mode.d.ts.map +1 -1
  500. package/dist/main-deferred-startup.d.ts.map +1 -1
  501. package/dist/main-early-input.d.ts.map +1 -1
  502. package/dist/main-session-options.d.ts.map +1 -1
  503. package/dist/main-session.d.ts +1 -0
  504. package/dist/main-session.d.ts.map +1 -1
  505. package/dist/main-session.js +7 -0
  506. package/dist/main-session.js.map +1 -1
  507. package/dist/main-stdio.d.ts.map +1 -1
  508. package/dist/main.d.ts.map +1 -1
  509. package/dist/main.js +2 -2
  510. package/dist/main.js.map +1 -1
  511. package/dist/migrations-config-values.d.ts.map +1 -1
  512. package/dist/migrations.d.ts.map +1 -1
  513. package/dist/modes/index.d.ts.map +1 -1
  514. package/dist/modes/interactive/chat-input-actions.d.ts.map +1 -1
  515. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  516. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  517. package/dist/modes/interactive/components/atomic-banner.d.ts.map +1 -1
  518. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  519. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  520. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  521. package/dist/modes/interactive/components/chat-message-renderer.d.ts +4 -1
  522. package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
  523. package/dist/modes/interactive/components/chat-message-renderer.js +12 -22
  524. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  525. package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
  526. package/dist/modes/interactive/components/chat-session-host-editor.d.ts.map +1 -1
  527. package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
  528. package/dist/modes/interactive/components/chat-session-host-events.js +5 -11
  529. package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
  530. package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
  531. package/dist/modes/interactive/components/chat-session-host-rendering.js +3 -0
  532. package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
  533. package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
  534. package/dist/modes/interactive/components/chat-session-host-state.d.ts +1 -0
  535. package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
  536. package/dist/modes/interactive/components/chat-session-host-state.js +1 -0
  537. package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
  538. package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts.map +1 -1
  539. package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
  540. package/dist/modes/interactive/components/chat-session-host-utils.d.ts.map +1 -1
  541. package/dist/modes/interactive/components/chat-session-host-utils.js +1 -1
  542. package/dist/modes/interactive/components/chat-session-host-utils.js.map +1 -1
  543. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  544. package/dist/modes/interactive/components/chat-session-host.js +1 -0
  545. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  546. package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
  547. package/dist/modes/interactive/components/compaction-boundary-message.d.ts +20 -0
  548. package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -0
  549. package/dist/modes/interactive/components/compaction-boundary-message.js +48 -0
  550. package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -0
  551. package/dist/modes/interactive/components/config-selector-list.d.ts.map +1 -1
  552. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  553. package/dist/modes/interactive/components/context-window-selector.d.ts.map +1 -1
  554. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  555. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  556. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  557. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  558. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  559. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  560. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  561. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  562. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  563. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  564. package/dist/modes/interactive/components/fast-mode-selector.d.ts.map +1 -1
  565. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  566. package/dist/modes/interactive/components/index.d.ts +1 -1
  567. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  568. package/dist/modes/interactive/components/index.js +1 -1
  569. package/dist/modes/interactive/components/index.js.map +1 -1
  570. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  571. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  572. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  573. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  574. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  575. package/dist/modes/interactive/components/session-selector-delete.d.ts.map +1 -1
  576. package/dist/modes/interactive/components/session-selector-header.d.ts.map +1 -1
  577. package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -1
  578. package/dist/modes/interactive/components/session-selector-list.js +3 -0
  579. package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
  580. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  581. package/dist/modes/interactive/components/session-selector-tree.d.ts.map +1 -1
  582. package/dist/modes/interactive/components/session-selector-types.d.ts.map +1 -1
  583. package/dist/modes/interactive/components/session-selector-utils.d.ts.map +1 -1
  584. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  585. package/dist/modes/interactive/components/settings-selector-handlers.d.ts.map +1 -1
  586. package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
  587. package/dist/modes/interactive/components/settings-selector-options.d.ts.map +1 -1
  588. package/dist/modes/interactive/components/settings-selector-submenus.d.ts.map +1 -1
  589. package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
  590. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  591. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  592. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  593. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  594. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  595. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  596. package/dist/modes/interactive/components/tree-selector-component.d.ts.map +1 -1
  597. package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
  598. package/dist/modes/interactive/components/tree-selector-help.d.ts.map +1 -1
  599. package/dist/modes/interactive/components/tree-selector-label-input.d.ts.map +1 -1
  600. package/dist/modes/interactive/components/tree-selector-list.d.ts.map +1 -1
  601. package/dist/modes/interactive/components/tree-selector-model.d.ts.map +1 -1
  602. package/dist/modes/interactive/components/tree-selector-types.d.ts.map +1 -1
  603. package/dist/modes/interactive/components/tree-selector-viewport.d.ts.map +1 -1
  604. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  605. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  606. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  607. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  608. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  609. package/dist/modes/interactive/components/working-status.d.ts.map +1 -1
  610. package/dist/modes/interactive/interactive-agent-events.d.ts.map +1 -1
  611. package/dist/modes/interactive/interactive-agent-events.js +3 -47
  612. package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
  613. package/dist/modes/interactive/interactive-auth-login.d.ts.map +1 -1
  614. package/dist/modes/interactive/interactive-auth-routing.d.ts.map +1 -1
  615. package/dist/modes/interactive/interactive-autocomplete.d.ts.map +1 -1
  616. package/dist/modes/interactive/interactive-bash-compact.d.ts.map +1 -1
  617. package/dist/modes/interactive/interactive-child-ordering.d.ts.map +1 -1
  618. package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
  619. package/dist/modes/interactive/interactive-editor-actions.d.ts.map +1 -1
  620. package/dist/modes/interactive/interactive-extension-context.d.ts.map +1 -1
  621. package/dist/modes/interactive/interactive-extension-custom-ui.d.ts.map +1 -1
  622. package/dist/modes/interactive/interactive-extension-dialogs.d.ts.map +1 -1
  623. package/dist/modes/interactive/interactive-extension-runtime.d.ts.map +1 -1
  624. package/dist/modes/interactive/interactive-extension-widgets.d.ts.map +1 -1
  625. package/dist/modes/interactive/interactive-hotkeys-debug.d.ts.map +1 -1
  626. package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
  627. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  628. package/dist/modes/interactive/interactive-mode-deps.d.ts +2 -2
  629. package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
  630. package/dist/modes/interactive/interactive-mode-deps.js +1 -1
  631. package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
  632. package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
  633. package/dist/modes/interactive/interactive-mode-surface.d.ts +5 -3
  634. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  635. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  636. package/dist/modes/interactive/interactive-mode-types.d.ts.map +1 -1
  637. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  638. package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
  639. package/dist/modes/interactive/interactive-onboarding.d.ts.map +1 -1
  640. package/dist/modes/interactive/interactive-process-lifecycle.d.ts.map +1 -1
  641. package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -1
  642. package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -1
  643. package/dist/modes/interactive/interactive-render-chat.js +21 -12
  644. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  645. package/dist/modes/interactive/interactive-resource-disclosure.d.ts.map +1 -1
  646. package/dist/modes/interactive/interactive-resource-paths.d.ts.map +1 -1
  647. package/dist/modes/interactive/interactive-resource-rendering.d.ts.map +1 -1
  648. package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
  649. package/dist/modes/interactive/interactive-session-routing.d.ts.map +1 -1
  650. package/dist/modes/interactive/interactive-session-runtime.d.ts.map +1 -1
  651. package/dist/modes/interactive/interactive-slash-commands.d.ts.map +1 -1
  652. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  653. package/dist/modes/interactive/model-search.d.ts.map +1 -1
  654. package/dist/modes/interactive/theme/color-utils.d.ts.map +1 -1
  655. package/dist/modes/interactive/theme/export-colors.d.ts.map +1 -1
  656. package/dist/modes/interactive/theme/global-theme.d.ts.map +1 -1
  657. package/dist/modes/interactive/theme/terminal-detection.d.ts.map +1 -1
  658. package/dist/modes/interactive/theme/theme-class.d.ts.map +1 -1
  659. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  660. package/dist/modes/interactive/theme/theme-loading.d.ts.map +1 -1
  661. package/dist/modes/interactive/theme/theme-parse.d.ts.map +1 -1
  662. package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -1
  663. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  664. package/dist/modes/interactive/theme/tui-theme.d.ts.map +1 -1
  665. package/dist/modes/interactive/whimsical-messages.d.ts.map +1 -1
  666. package/dist/modes/print-mode.d.ts.map +1 -1
  667. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  668. package/dist/modes/rpc/rpc-client.d.ts +3 -5
  669. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  670. package/dist/modes/rpc/rpc-client.js +1 -6
  671. package/dist/modes/rpc/rpc-client.js.map +1 -1
  672. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  673. package/dist/modes/rpc/rpc-command-handler.js +0 -4
  674. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  675. package/dist/modes/rpc/rpc-extension-ui.d.ts.map +1 -1
  676. package/dist/modes/rpc/rpc-input.d.ts.map +1 -1
  677. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  678. package/dist/modes/rpc/rpc-responses.d.ts.map +1 -1
  679. package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
  680. package/dist/modes/rpc/rpc-types.d.ts +2 -11
  681. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  682. package/dist/modes/rpc/rpc-types.js.map +1 -1
  683. package/dist/package-manager-cli-parser.d.ts.map +1 -1
  684. package/dist/package-manager-cli.d.ts.map +1 -1
  685. package/dist/rpc-entry.d.ts.map +1 -1
  686. package/dist/utils/ansi.d.ts.map +1 -1
  687. package/dist/utils/changelog.d.ts.map +1 -1
  688. package/dist/utils/child-process.d.ts.map +1 -1
  689. package/dist/utils/clipboard-image.d.ts.map +1 -1
  690. package/dist/utils/clipboard-native.d.ts.map +1 -1
  691. package/dist/utils/clipboard.d.ts.map +1 -1
  692. package/dist/utils/deprecation.d.ts.map +1 -1
  693. package/dist/utils/event-loop.d.ts.map +1 -1
  694. package/dist/utils/exif-orientation.d.ts.map +1 -1
  695. package/dist/utils/frontmatter.d.ts.map +1 -1
  696. package/dist/utils/fs-watch.d.ts.map +1 -1
  697. package/dist/utils/git-env.d.ts.map +1 -1
  698. package/dist/utils/git.d.ts.map +1 -1
  699. package/dist/utils/html.d.ts.map +1 -1
  700. package/dist/utils/image-convert.d.ts.map +1 -1
  701. package/dist/utils/image-process.d.ts.map +1 -1
  702. package/dist/utils/image-resize-core.d.ts.map +1 -1
  703. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  704. package/dist/utils/image-resize.d.ts.map +1 -1
  705. package/dist/utils/json.d.ts.map +1 -1
  706. package/dist/utils/markit.d.ts.map +1 -1
  707. package/dist/utils/mime.d.ts.map +1 -1
  708. package/dist/utils/module-require.d.ts.map +1 -1
  709. package/dist/utils/open-browser.d.ts.map +1 -1
  710. package/dist/utils/paths.d.ts.map +1 -1
  711. package/dist/utils/photon.d.ts.map +1 -1
  712. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  713. package/dist/utils/shell.d.ts.map +1 -1
  714. package/dist/utils/sleep.d.ts.map +1 -1
  715. package/dist/utils/split-launcher.d.ts.map +1 -1
  716. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  717. package/dist/utils/tools-manager.d.ts.map +1 -1
  718. package/dist/utils/version-check.d.ts.map +1 -1
  719. package/dist/utils/windows-self-update.d.ts.map +1 -1
  720. package/docs/compaction.md +97 -772
  721. package/docs/custom-provider.md +7 -1
  722. package/docs/extensions.md +31 -33
  723. package/docs/json.md +2 -2
  724. package/docs/rpc.md +32 -24
  725. package/docs/sdk.md +3 -3
  726. package/docs/session-format.md +49 -30
  727. package/docs/sessions.md +5 -3
  728. package/docs/settings.md +14 -4
  729. package/docs/usage.md +1 -1
  730. package/docs/workflows.md +30 -15
  731. package/examples/extensions/README.md +3 -1
  732. package/examples/extensions/custom-compaction.ts +14 -58
  733. package/examples/extensions/handoff.ts +2 -3
  734. package/examples/extensions/subagent/schemas.ts +1 -1
  735. package/examples/extensions/tic-tac-toe.ts +1 -2
  736. package/examples/extensions/todo.ts +1 -2
  737. package/npm-shrinkwrap.json +214 -98
  738. package/package.json +12 -12
  739. package/dist/core/compaction/context-assistant-turns.d.ts +0 -42
  740. package/dist/core/compaction/context-assistant-turns.d.ts.map +0 -1
  741. package/dist/core/compaction/context-assistant-turns.js +0 -87
  742. package/dist/core/compaction/context-assistant-turns.js.map +0 -1
  743. package/dist/core/compaction/context-compaction-critical.d.ts +0 -15
  744. package/dist/core/compaction/context-compaction-critical.d.ts.map +0 -1
  745. package/dist/core/compaction/context-compaction-critical.js +0 -57
  746. package/dist/core/compaction/context-compaction-critical.js.map +0 -1
  747. package/dist/core/compaction/context-compaction-eviction-alternates.d.ts +0 -18
  748. package/dist/core/compaction/context-compaction-eviction-alternates.d.ts.map +0 -1
  749. package/dist/core/compaction/context-compaction-eviction-alternates.js +0 -186
  750. package/dist/core/compaction/context-compaction-eviction-alternates.js.map +0 -1
  751. package/dist/core/compaction/context-compaction-eviction.d.ts +0 -12
  752. package/dist/core/compaction/context-compaction-eviction.d.ts.map +0 -1
  753. package/dist/core/compaction/context-compaction-eviction.js +0 -222
  754. package/dist/core/compaction/context-compaction-eviction.js.map +0 -1
  755. package/dist/core/compaction/context-compaction-metrics.d.ts +0 -28
  756. package/dist/core/compaction/context-compaction-metrics.d.ts.map +0 -1
  757. package/dist/core/compaction/context-compaction-metrics.js +0 -107
  758. package/dist/core/compaction/context-compaction-metrics.js.map +0 -1
  759. package/dist/core/compaction/context-compaction-prompt.d.ts +0 -9
  760. package/dist/core/compaction/context-compaction-prompt.d.ts.map +0 -1
  761. package/dist/core/compaction/context-compaction-prompt.js +0 -163
  762. package/dist/core/compaction/context-compaction-prompt.js.map +0 -1
  763. package/dist/core/compaction/context-compaction-runner.d.ts +0 -11
  764. package/dist/core/compaction/context-compaction-runner.d.ts.map +0 -1
  765. package/dist/core/compaction/context-compaction-runner.js +0 -273
  766. package/dist/core/compaction/context-compaction-runner.js.map +0 -1
  767. package/dist/core/compaction/context-compaction-strategy.d.ts +0 -5
  768. package/dist/core/compaction/context-compaction-strategy.d.ts.map +0 -1
  769. package/dist/core/compaction/context-compaction-strategy.js +0 -27
  770. package/dist/core/compaction/context-compaction-strategy.js.map +0 -1
  771. package/dist/core/compaction/context-compaction-types.d.ts +0 -75
  772. package/dist/core/compaction/context-compaction-types.d.ts.map +0 -1
  773. package/dist/core/compaction/context-compaction-types.js +0 -6
  774. package/dist/core/compaction/context-compaction-types.js.map +0 -1
  775. package/dist/core/compaction/context-compaction.d.ts +0 -10
  776. package/dist/core/compaction/context-compaction.d.ts.map +0 -1
  777. package/dist/core/compaction/context-compaction.js +0 -8
  778. package/dist/core/compaction/context-compaction.js.map +0 -1
  779. package/dist/core/compaction/context-deletion-application.d.ts +0 -14
  780. package/dist/core/compaction/context-deletion-application.d.ts.map +0 -1
  781. package/dist/core/compaction/context-deletion-application.js +0 -261
  782. package/dist/core/compaction/context-deletion-application.js.map +0 -1
  783. package/dist/core/compaction/context-deletion-store.d.ts +0 -78
  784. package/dist/core/compaction/context-deletion-store.d.ts.map +0 -1
  785. package/dist/core/compaction/context-deletion-store.js +0 -162
  786. package/dist/core/compaction/context-deletion-store.js.map +0 -1
  787. package/dist/core/compaction/context-deletion-targets.d.ts +0 -43
  788. package/dist/core/compaction/context-deletion-targets.d.ts.map +0 -1
  789. package/dist/core/compaction/context-deletion-targets.js +0 -292
  790. package/dist/core/compaction/context-deletion-targets.js.map +0 -1
  791. package/dist/core/compaction/context-deletion-tool-definitions.d.ts +0 -193
  792. package/dist/core/compaction/context-deletion-tool-definitions.d.ts.map +0 -1
  793. package/dist/core/compaction/context-deletion-tool-definitions.js +0 -98
  794. package/dist/core/compaction/context-deletion-tool-definitions.js.map +0 -1
  795. package/dist/core/compaction/context-deletion-tool-helpers.d.ts +0 -19
  796. package/dist/core/compaction/context-deletion-tool-helpers.d.ts.map +0 -1
  797. package/dist/core/compaction/context-deletion-tool-helpers.js +0 -210
  798. package/dist/core/compaction/context-deletion-tool-helpers.js.map +0 -1
  799. package/dist/core/compaction/context-deletion-tools.d.ts +0 -4
  800. package/dist/core/compaction/context-deletion-tools.d.ts.map +0 -1
  801. package/dist/core/compaction/context-deletion-tools.js +0 -403
  802. package/dist/core/compaction/context-deletion-tools.js.map +0 -1
  803. package/dist/core/compaction/context-transcript-analysis.d.ts +0 -11
  804. package/dist/core/compaction/context-transcript-analysis.d.ts.map +0 -1
  805. package/dist/core/compaction/context-transcript-analysis.js +0 -228
  806. package/dist/core/compaction/context-transcript-analysis.js.map +0 -1
  807. package/dist/core/session-manager-tool-dependencies.d.ts +0 -10
  808. package/dist/core/session-manager-tool-dependencies.d.ts.map +0 -1
  809. package/dist/core/session-manager-tool-dependencies.js +0 -133
  810. package/dist/core/session-manager-tool-dependencies.js.map +0 -1
  811. package/dist/modes/interactive/components/context-compaction-summary-message.d.ts +0 -17
  812. package/dist/modes/interactive/components/context-compaction-summary-message.d.ts.map +0 -1
  813. package/dist/modes/interactive/components/context-compaction-summary-message.js +0 -83
  814. package/dist/modes/interactive/components/context-compaction-summary-message.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-builder.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/view/dialog-builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,KAAK,SAAS,EAAa,KAAK,KAAK,EAAU,MAAM,wBAAwB,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OA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M,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,qBAAa,UAAW,YAAW,YAAY,CAAC,WAAW,CAAC;IAC3D,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;IACtD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiC;IAChE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAE3C,YAAY,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAqB1D;IAED,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAEjC;IAED,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAG;IAKnC,UAAU,IAAI,IAAI,CAAG;IAErB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAI9B;IAED,OAAO,CAAC,0BAA0B;CA2BlC","sourcesContent":["import { DynamicBorder } from \"../../../../modes/interactive/components/index.ts\";\nimport type { Theme } from \"../../../../modes/interactive/theme/theme.ts\";\nimport { type Component, Container, type Input, Spacer } from \"@earendil-works/pi-tui\";\nimport type { QuestionnaireState } from \"../state/state.ts\";\nimport type { QuestionData } from \"../tool/types.ts\";\nimport { BodyResidualSpacer } from \"./body-residual-spacer.ts\";\nimport type { ChatRowView } from \"./components/chat-row-view.ts\";\nimport type { PreviewPaneProps } from \"./components/preview/preview-pane.ts\";\nimport type { TabBar } from \"./components/tab-bar.ts\";\nimport type { StatefulView } from \"./stateful-view.ts\";\nimport type { TabComponents } from \"./tab-components.ts\";\nimport { QuestionTabStrategy, SubmitTabStrategy, type TabContentStrategy } from \"./tab-content-strategy.ts\";\n\nexport const HINT_PART_ENTER = \"enter select\";\nexport const HINT_PART_NAV = \"↑/↓ navigate\";\nexport const HINT_PART_TOGGLE = \"space toggle\";\nexport const HINT_PART_NOTES = \"n add notes\";\nexport const HINT_PART_TAB = \"tab switch questions\";\nexport const HINT_PART_CANCEL = \"esc cancel\";\nexport const HINT_SINGLE = [HINT_PART_ENTER, HINT_PART_NAV, HINT_PART_CANCEL].join(\" · \");\nexport const HINT_MULTI = [HINT_PART_ENTER, HINT_PART_NAV, HINT_PART_TAB, HINT_PART_CANCEL].join(\" · \");\nexport const HINT_MULTISELECT_SUFFIX = ` · ${HINT_PART_TOGGLE}`;\nexport const HINT_NOTES_SUFFIX = ` · ${HINT_PART_NOTES}`;\nexport const REVIEW_HEADING = \"Review your answers\";\nexport const READY_PROMPT = \"Ready to submit your answers?\";\nexport const INCOMPLETE_WARNING_PREFIX = \"⚠ Answer remaining questions before submitting:\";\n\nexport type DialogState = QuestionnaireState;\n\n/** Per-tick projection of dialog state. Written by the adapter; read by the strategy thunk. */\nexport interface DialogProps {\n\tstate: DialogState;\n\tactivePreviewPane: StatefulView<PreviewPaneProps>;\n}\n\n/** Construction-time config for `DialogView`. Frozen after construction. */\nexport interface DialogConfig {\n\ttheme: Theme;\n\tquestions: readonly QuestionData[];\n\ttabBar: TabBar | undefined;\n\tnotesInput: Input;\n\tchatRow: ChatRowView;\n\tisMulti: boolean;\n\ttabsByIndex: ReadonlyArray<TabComponents>;\n\t/** Optional so single-question mode and non-submit tests can omit it; SubmitTabStrategy falls back to Spacer rows. */\n\tsubmitPicker?: Component;\n\t/** Worst-case body height across all tabs/options. Determines the stable overall dialog footprint. */\n\tgetBodyHeight: (width: number) => number;\n\t/** Body height of the CURRENTLY active tab/option. The chrome subtracts this from `getBodyHeight` to absorb the residual OUTSIDE the bordered region. */\n\tgetCurrentBodyHeight: (width: number) => number;\n}\n\n/**\n * The 7th renderable, promoted from a structural literal to a named class so\n * all view-layer components share one explicit `implements StatefulView<P>`\n * contract. `setProps(DialogProps)` writes the live cell read by the\n * strategy thunk during `render()`. `liveProps.activePreviewPane` is a\n * resolved pane reference threaded by the adapter per tick — the dialog\n * itself does not derive it.\n */\nexport class DialogView implements StatefulView<DialogProps> {\n\tprivate liveProps: DialogProps;\n\tprivate readonly config: DialogConfig;\n\tprivate readonly questionStrategy: TabContentStrategy;\n\tprivate readonly submitStrategy: TabContentStrategy | undefined;\n\tprivate readonly maxFooterRowCount: number;\n\n\tconstructor(config: DialogConfig, initialProps: DialogProps) {\n\t\tthis.config = config;\n\t\tthis.liveProps = initialProps;\n\t\tthis.questionStrategy = new QuestionTabStrategy({\n\t\t\ttheme: config.theme,\n\t\t\tquestions: config.questions,\n\t\t\tgetPreviewPane: () => this.liveProps.activePreviewPane,\n\t\t\ttabsByIndex: config.tabsByIndex,\n\t\t\tnotesInput: config.notesInput,\n\t\t\tchatRow: config.chatRow,\n\t\t\tisMulti: config.isMulti,\n\t\t\tgetCurrentBodyHeight: config.getCurrentBodyHeight,\n\t\t});\n\t\tthis.submitStrategy = config.isMulti\n\t\t\t? new SubmitTabStrategy({\n\t\t\t\t\ttheme: config.theme,\n\t\t\t\t\tquestions: config.questions,\n\t\t\t\t\tsubmitPicker: config.submitPicker,\n\t\t\t\t})\n\t\t\t: undefined;\n\t\tthis.maxFooterRowCount = Math.max(this.questionStrategy.footerRowCount, this.submitStrategy?.footerRowCount ?? 0);\n\t}\n\n\tsetProps(props: DialogProps): void {\n\t\tthis.liveProps = props;\n\t}\n\n\thandleInput(_data: string): void {}\n\n\t// Invalidation is driven by `QuestionnairePropsAdapter.invalidate()`, which\n\t// owns the full set of renderables (binding registries + extras like\n\t// `notesInput`). DialogView has no cached layout of its own.\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst onSubmit = this.config.isMulti && this.liveProps.state.currentTab === this.config.questions.length;\n\t\tconst strategy = onSubmit && this.submitStrategy ? this.submitStrategy : this.questionStrategy;\n\t\treturn this.buildContainerFromStrategy(strategy).render(width);\n\t}\n\n\tprivate buildContainerFromStrategy(strategy: TabContentStrategy): Container {\n\t\tconst { theme, isMulti, tabBar } = this.config;\n\t\tconst state = this.liveProps.state;\n\t\tconst container = new Container();\n\t\tconst border = () => new DynamicBorder((s) => theme.fg(\"accent\", s));\n\n\t\tcontainer.addChild(border());\n\t\tif (isMulti && tabBar) container.addChild(tabBar);\n\t\tcontainer.addChild(new Spacer(1));\n\n\t\tfor (const c of strategy.headingRows(state)) container.addChild(c);\n\t\tcontainer.addChild(strategy.bodyComponent(state));\n\t\tcontainer.addChild(new Spacer(1));\n\t\tfor (const c of strategy.midRows(state)) container.addChild(c);\n\n\t\tcontainer.addChild(border());\n\t\tfor (const c of strategy.footerRows(state)) container.addChild(c);\n\n\t\t// Residual spacer equalizes total height across strategies; rendered AFTER the bottom border.\n\t\tcontainer.addChild(\n\t\t\tnew BodyResidualSpacer(\n\t\t\t\t(w) => this.config.getBodyHeight(w) + this.maxFooterRowCount,\n\t\t\t\t(w) => strategy.bodyHeight(w, state) + strategy.footerRowCount,\n\t\t\t),\n\t\t);\n\t\treturn container;\n\t}\n}\n"]}
1
+ {"version":3,"file":"dialog-builder.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/view/dialog-builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,KAAK,SAAS,EAAa,KAAK,KAAK,EAAU,MAAM,wBAAwB,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,eAAO,MAAM,eAAe,iBAAiB,CAAC;AAC9C,eAAO,MAAM,aAAa,2BAA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AAa,CAAC,aAAa,CAAC,CAAC;IAC1C,WAAW,EAAE,KAAK,CAAC;IACnB,cAAc,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAClD,cAAc,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAClD;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;CACnD;AAED;;;;;;;;GAQG;AACH,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAyC;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IACpD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+C;IAC1E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+B;IAC3D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoC;IACnE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoC;IACnE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA+B;IAEnE,YAAY,MAAM,EAAE,+BAA+B,EASlD;IAED,KAAK,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAwCrC;IAED;;;;;;OAMG;IACH,UAAU,IAAI,IAAI,CAQjB;CACD","sourcesContent":["import type { Input } from \"@earendil-works/pi-tui\";\nimport type { BindingContext, PerTabBindingContext } from \"../state/selectors/contract.ts\";\nimport { selectActivePreviewPaneIndex } from \"../state/selectors/derivations.ts\";\nimport { selectActiveView } from \"../state/selectors/focus.ts\";\nimport type { QuestionnaireState } from \"../state/state.ts\";\nimport type { QuestionData } from \"../tool/types.ts\";\nimport type { BoundGlobalBinding, BoundPerTabBinding } from \"./component-binding.ts\";\nimport type { WrappingSelectItem } from \"./components/wrapping-select.ts\";\nimport type { TabComponents } from \"./tab-components.ts\";\n\n/** Cache-invalidation contract used by the adapter. `pi-tui` `Component` already satisfies it. */\ninterface Invalidatable {\n\tinvalidate(): void;\n}\n\nexport interface QuestionnairePropsAdapterConfig {\n\ttui: { requestRender(): void };\n\tquestions: readonly QuestionData[];\n\titemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\ttabsByIndex: ReadonlyArray<TabComponents>;\n\tinlineInput: Input;\n\tglobalBindings: ReadonlyArray<BoundGlobalBinding>;\n\tperTabBindings: ReadonlyArray<BoundPerTabBinding>;\n\t/**\n\t * Renderables not reached by the binding registries (e.g. the notes\n\t * `Input`, which is typed into directly and has no props). Walked by\n\t * `invalidate()` after the binding-driven components.\n\t */\n\textraInvalidatables?: ReadonlyArray<Invalidatable>;\n}\n\n/**\n * View fan-out: drives every component setter from the canonical state via\n * two binding registries. `globalBindings` covers the cross-tab components\n * (chatRow, dialog, submitPicker?, tabBar?); `perTabBindings` covers the\n * per-tab kinds (optionList, preview, multiSelect?). The hand-coded fan-out\n * collapses to one global loop + one nested per-tab loop. The shared inline\n * input is projected through owner-specific draft slots so the option list and\n * chat footer never display each other's in-flight text.\n */\nexport class QuestionnairePropsAdapter {\n\tprivate readonly tui: QuestionnairePropsAdapterConfig[\"tui\"];\n\tprivate readonly questions: readonly QuestionData[];\n\tprivate readonly itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;\n\tprivate readonly tabsByIndex: ReadonlyArray<TabComponents>;\n\tprivate readonly inlineInput: Input;\n\tprivate readonly globalBindings: ReadonlyArray<BoundGlobalBinding>;\n\tprivate readonly perTabBindings: ReadonlyArray<BoundPerTabBinding>;\n\tprivate readonly extraInvalidatables: ReadonlyArray<Invalidatable>;\n\n\tconstructor(config: QuestionnairePropsAdapterConfig) {\n\t\tthis.tui = config.tui;\n\t\tthis.questions = config.questions;\n\t\tthis.itemsByTab = config.itemsByTab;\n\t\tthis.tabsByIndex = config.tabsByIndex;\n\t\tthis.inlineInput = config.inlineInput;\n\t\tthis.globalBindings = config.globalBindings;\n\t\tthis.perTabBindings = config.perTabBindings;\n\t\tthis.extraInvalidatables = config.extraInvalidatables ?? [];\n\t}\n\n\tapply(state: QuestionnaireState): void {\n\t\tconst totalQuestions = this.questions.length;\n\t\tconst activeView = selectActiveView(state, totalQuestions);\n\t\tconst paneIndex = selectActivePreviewPaneIndex(state.currentTab, totalQuestions);\n\t\tconst activePreviewPane = this.tabsByIndex[paneIndex]?.preview ?? this.tabsByIndex[0]!.preview;\n\n\t\tconst liveInlineValue = this.inlineInput.getValue();\n\t\tconst inputBuffer =\n\t\t\tstate.customDraftByTab.get(state.currentTab) ??\n\t\t\t(state.inlineInputOwner === \"other\" ? liveInlineValue : \"\");\n\t\tconst inputCaret = state.customCaretByTab.get(state.currentTab) ?? inputBuffer.length;\n\t\tconst chatInputBuffer =\n\t\t\tstate.chatDraftByTab.get(state.currentTab) ??\n\t\t\t(state.inlineInputOwner === \"chat\" ? liveInlineValue : \"\");\n\t\tconst chatInputCaret = state.chatCaretByTab.get(state.currentTab) ?? chatInputBuffer.length;\n\t\tconst ctx: BindingContext = {\n\t\t\tquestions: this.questions,\n\t\t\titemsByTab: this.itemsByTab,\n\t\t\ttotalQuestions,\n\t\t\tactiveView,\n\t\t\tinputBuffer,\n\t\t\tinputCaret,\n\t\t\tchatInputBuffer,\n\t\t\tchatInputCaret,\n\t\t\tactivePreviewPane,\n\t\t};\n\n\t\tfor (const binding of this.globalBindings) {\n\t\t\tbinding.apply(state, ctx);\n\t\t}\n\n\t\tfor (let i = 0; i < this.tabsByIndex.length; i++) {\n\t\t\tconst tab = this.tabsByIndex[i]!;\n\t\t\tconst tabCtx: PerTabBindingContext = { ...ctx, tab, i };\n\t\t\tfor (const binding of this.perTabBindings) {\n\t\t\t\tbinding.apply(state, tabCtx);\n\t\t\t}\n\t\t}\n\n\t\tthis.tui.requestRender();\n\t}\n\n\t/**\n\t * Invalidates every owned renderable. Called by the session in place of\n\t * the old `dialog.invalidate()` forwarding chain — DialogView no longer\n\t * reaches into siblings (chatRow, tabBar, notesInput, activePreviewPane).\n\t * Iterates the same registries used by `apply()` plus\n\t * `extraInvalidatables` for components outside the binding system.\n\t */\n\tinvalidate(): void {\n\t\tfor (const b of this.globalBindings) b.invalidate();\n\t\tfor (const tab of this.tabsByIndex) {\n\t\t\ttab.optionList.invalidate();\n\t\t\ttab.preview.invalidate();\n\t\t\ttab.multiSelect?.invalidate();\n\t\t}\n\t\tfor (const x of this.extraInvalidatables) x.invalidate();\n\t}\n}\n"]}
1
+ {"version":3,"file":"props-adapter.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/view/props-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAIpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,kGAAkG;AAClG,UAAU,aAAa;IACtB,UAAU,IAAI,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,+BAA+B;IAC/C,GAAG,EAAE;QAAE,aAAa,IAAI,IAAI,CAAA;KAAE,CAAC;IAC/B,SAAS,EAAE,SAAS,YAAY,EAAE,CAAC;IACnC,UAAU,EAAE,aAAa,CAAC,SAAS,kBAAkB,EAAE,CAAC,CAAC;IACzD,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IAC1C,WAAW,EAAE,KAAK,CAAC;IACnB,cAAc,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAClD,cAAc,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAClD;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;CACnD;AAED;;;;;;;;GAQG;AACH,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAyC;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IACpD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+C;IAC1E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+B;IAC3D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoC;IACnE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoC;IACnE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA+B;IAEnE,YAAY,MAAM,EAAE,+BAA+B,EASlD;IAED,KAAK,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAwCrC;IAED;;;;;;OAMG;IACH,UAAU,IAAI,IAAI,CAQjB;CACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"stateful-view.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/view/stateful-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,SAAS;IACjD,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CACzB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC","sourcesContent":["import type { Component } from \"@earendil-works/pi-tui\";\n\n/**\n * Generic prop-driven component contract. Every renderable owns its own `P` shape;\n * the adapter computes `P` from canonical state via per-component selectors and\n * pushes it via `setProps`. `focused: boolean` is a field on `P` only where the\n * component needs it.\n */\nexport interface StatefulView<P> extends Component {\n\tsetProps(props: P): void;\n}\n\n/**\n * Discriminated focus union — encodes the four-cell focus invariant\n * (`notesVisible`, submit-tab, `chatFocused`, options) that was previously\n * structural-only. Dispatcher cascade (`key-router.ts:151-178`) and reducer's\n * defensive clears (`state-reducer.ts:104-126`) enforce mutual exclusion;\n * this type makes it explicit so per-component `focused: boolean` flags\n * derive from one equality check against this discriminant rather than\n * four parallel boolean reads.\n *\n * Priority order: notes > submit > chat > options. Matches the dispatcher\n * cascade exactly so the union is observably equivalent to today's reads.\n */\nexport type ActiveView = \"notes\" | \"chat\" | \"options\" | \"submit\";\n"]}
1
+ {"version":3,"file":"stateful-view.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/view/stateful-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,SAAS;IACjD,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CACzB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tab-components.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/view/tab-components.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,aAAa;IAC7B,UAAU,EAAE,YAAY,CAAC,mBAAmB,CAAC,CAAC;IAC9C,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,CAAC,EAAE,YAAY,CAAC,oBAAoB,CAAC,CAAC;IACjD,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,cAAc,CAAC;CAC/C","sourcesContent":["import type { MultiSelectViewProps } from \"./components/multi-select-view.ts\";\nimport type { OptionListViewProps } from \"./components/option-list-view.ts\";\nimport type { PreviewPane } from \"./components/preview/preview-pane.ts\";\nimport type { StatefulView } from \"./stateful-view.ts\";\n\nexport interface TabBodyHeights {\n\tcurrent: number;\n\tmax: number;\n}\n\nexport interface TabComponents {\n\toptionList: StatefulView<OptionListViewProps>;\n\tpreview: PreviewPane;\n\tmultiSelect?: StatefulView<MultiSelectViewProps>;\n\tbodyHeights: (width: number) => TabBodyHeights;\n}\n"]}
1
+ {"version":3,"file":"tab-components.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/view/tab-components.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,aAAa;IAC7B,UAAU,EAAE,YAAY,CAAC,mBAAmB,CAAC,CAAC;IAC9C,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,CAAC,EAAE,YAAY,CAAC,oBAAoB,CAAC,CAAC;IACjD,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,cAAc,CAAC;CAC/C"}
@@ -1 +1 @@
1
- {"version":3,"file":"tab-content-strategy.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/view/tab-content-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8CAA8C,CAAC;A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EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAS9G","sourcesContent":["import type { Theme } from \"../../../../modes/interactive/theme/theme.ts\";\nimport { type Component, Container, type Input, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { formatAnswerScalar } from \"../tool/format-answer.ts\";\nimport type { QuestionData } from \"../tool/types.ts\";\nimport type { ChatRowView } from \"./components/chat-row-view.ts\";\nimport type { PreviewPaneProps } from \"./components/preview/preview-pane.ts\";\nimport {\n\ttype DialogState,\n\tHINT_PART_CANCEL,\n\tHINT_PART_ENTER,\n\tHINT_PART_NAV,\n\tHINT_PART_NOTES,\n\tHINT_PART_TAB,\n\tHINT_PART_TOGGLE,\n\tINCOMPLETE_WARNING_PREFIX,\n\tREADY_PROMPT,\n\tREVIEW_HEADING,\n} from \"./dialog-builder.ts\";\nimport type { StatefulView } from \"./stateful-view.ts\";\nimport type { TabComponents } from \"./tab-components.ts\";\n\nconst NOTES_HEADER = \"Notes:\";\n\n/**\n * Per-tab content provider. Pure functional — closes over construction-time\n * config; per-tick state threads through method args. The chrome wrapper\n * enforces height equality across tabs via `bodyHeight + footerRowCount`.\n */\nexport interface TabContentStrategy {\n\t/** Total RENDERED footer rows — MUST equal what `footerRows()` actually emits. Drives residual math. */\n\treadonly footerRowCount: number;\n\n\t/** Variable rows above the body, after top chrome (border + tabBar + Spacer). */\n\theadingRows(state: DialogState): Component[];\n\n\t/** Body Component placed at the body slot. */\n\tbodyComponent(state: DialogState): Component;\n\n\t/** Natural rendered height of `bodyComponent(state)` at given width. */\n\tbodyHeight(width: number, state: DialogState): number;\n\n\t/** Optional rows between body's trailing Spacer and the bottom border. */\n\tmidRows(state: DialogState): Component[];\n\n\t/** Footer rows below the bottom border. Rendered row count MUST equal `footerRowCount`. */\n\tfooterRows(state: DialogState): Component[];\n}\n\nexport interface QuestionTabStrategyConfig {\n\ttheme: Theme;\n\tquestions: readonly QuestionData[];\n\tgetPreviewPane: () => StatefulView<PreviewPaneProps>;\n\ttabsByIndex: ReadonlyArray<TabComponents>;\n\tnotesInput: Input;\n\tchatRow: ChatRowView;\n\tisMulti: boolean;\n\tgetCurrentBodyHeight: (width: number) => number;\n}\n\nexport class QuestionTabStrategy implements TabContentStrategy {\n\t/** Spacer(1) + chatRow(1) + Spacer(1) + Text(hint, 1) = 4 rendered rows. */\n\treadonly footerRowCount = 4;\n\n\tdeclare private readonly config: QuestionTabStrategyConfig;\n\n\tconstructor(config: QuestionTabStrategyConfig) {\n\t\tthis.config = config;\n\t}\n\n\theadingRows(state: DialogState): Component[] {\n\t\tconst out: Component[] = [];\n\t\tconst question = this.config.questions[state.currentTab];\n\t\t// In multi-question mode the tab bar already shows the header; suppress the inline badge.\n\t\tif (!this.config.isMulti && question?.header && question.header.length > 0) {\n\t\t\tout.push(new Text(this.config.theme.bg(\"selectedBg\", ` ${question.header} `), 1, 0));\n\t\t\tout.push(new Spacer(1));\n\t\t}\n\t\tif (question) {\n\t\t\tout.push(new Text(this.config.theme.bold(question.question), 1, 0));\n\t\t\tout.push(new Spacer(1));\n\t\t}\n\t\treturn out;\n\t}\n\n\tbodyComponent(state: DialogState): Component {\n\t\tconst question = this.config.questions[state.currentTab];\n\t\tconst mso = this.config.tabsByIndex[state.currentTab]?.multiSelect;\n\t\tif (question?.multiSelect === true && mso) return mso;\n\t\treturn this.config.getPreviewPane();\n\t}\n\n\tbodyHeight(width: number, _state: DialogState): number {\n\t\treturn this.config.getCurrentBodyHeight(width);\n\t}\n\n\tmidRows(state: DialogState): Component[] {\n\t\tif (!state.notesVisible) return [];\n\t\treturn [\n\t\t\tnew Text(this.config.theme.fg(\"muted\", NOTES_HEADER), 1, 0),\n\t\t\tthis.config.notesInput,\n\t\t\tnew Spacer(1),\n\t\t];\n\t}\n\n\tfooterRows(state: DialogState): Component[] {\n\t\tconst question = this.config.questions[state.currentTab];\n\t\treturn [\n\t\t\tnew Spacer(1),\n\t\t\tthis.config.chatRow,\n\t\t\tnew Spacer(1),\n\t\t\tnew Text(this.config.theme.fg(\"dim\", buildHintText(question, this.config.isMulti, state)), 1, 0),\n\t\t];\n\t}\n}\n\nexport interface SubmitTabStrategyConfig {\n\ttheme: Theme;\n\tquestions: readonly QuestionData[];\n\tsubmitPicker: Component | undefined;\n}\n\nexport class SubmitTabStrategy implements TabContentStrategy {\n\t/** Spacer(1) + Text(prompt, 1) + Spacer(1) + submitPicker(2) = 5 rendered rows. Fallback path lands at 5 via 2 trailing Spacer(1)s. */\n\treadonly footerRowCount = 5;\n\n\tdeclare private readonly config: SubmitTabStrategyConfig;\n\n\tconstructor(config: SubmitTabStrategyConfig) {\n\t\tthis.config = config;\n\t}\n\n\theadingRows(_state: DialogState): Component[] {\n\t\treturn [\n\t\t\tnew Text(this.config.theme.bold(this.config.theme.fg(\"accent\", REVIEW_HEADING)), 1, 0),\n\t\t\tnew Spacer(1),\n\t\t];\n\t}\n\n\tbodyComponent(state: DialogState): Component {\n\t\tconst c = new Container();\n\t\tfor (let i = 0; i < this.config.questions.length; i++) {\n\t\t\tconst q = this.config.questions[i];\n\t\t\tconst a = state.answers.get(i);\n\t\t\tif (!a) continue;\n\t\t\tconst label = q.header && q.header.length > 0 ? q.header : `Q${i + 1}`;\n\t\t\tconst answerText = formatAnswerScalar(a, \"summary\");\n\t\t\tc.addChild(new Text(this.config.theme.fg(\"muted\", ` ● ${label}`), 1, 0));\n\t\t\tc.addChild(\n\t\t\t\tnew Text(` ${this.config.theme.fg(\"muted\", \"→\")} ${this.config.theme.fg(\"text\", answerText)}`, 1, 0),\n\t\t\t);\n\t\t\tif (a.notes && a.notes.length > 0) {\n\t\t\t\tc.addChild(new Text(this.config.theme.fg(\"dim\", ` notes: ${a.notes}`), 1, 0));\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tbodyHeight(width: number, state: DialogState): number {\n\t\treturn this.bodyComponent(state).render(width).length;\n\t}\n\n\tmidRows(_state: DialogState): Component[] {\n\t\treturn [];\n\t}\n\n\tfooterRows(state: DialogState): Component[] {\n\t\tconst missing: string[] = [];\n\t\tfor (let i = 0; i < this.config.questions.length; i++) {\n\t\t\tconst q = this.config.questions[i];\n\t\t\tif (!state.answers.has(i)) {\n\t\t\t\tmissing.push(q.header && q.header.length > 0 ? q.header : `Q${i + 1}`);\n\t\t\t}\n\t\t}\n\t\tconst promptText =\n\t\t\tmissing.length === 0\n\t\t\t\t? this.config.theme.fg(\"muted\", READY_PROMPT)\n\t\t\t\t: this.config.theme.fg(\n\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t`${INCOMPLETE_WARNING_PREFIX} ${missing.join(\", \")}`,\n\t\t\t\t\t);\n\t\tconst out: Component[] = [new Spacer(1), new Text(promptText, 1, 0), new Spacer(1)];\n\t\tif (this.config.submitPicker) {\n\t\t\tout.push(this.config.submitPicker);\n\t\t} else {\n\t\t\t// Padding when the picker isn't wired — keeps rendered row count at footerRowCount=5.\n\t\t\tout.push(new Spacer(1));\n\t\t\tout.push(new Spacer(1));\n\t\t}\n\t\treturn out;\n\t}\n}\n\n/**\n * Build the controls hint line. Order is fixed so `HINT_SINGLE` / `HINT_MULTI`\n * remain contiguous substrings of the result:\n * Enter · ↑/↓ [· Space toggle] [· n notes] [· Tab switch] · Esc\n */\nexport function buildHintText(question: QuestionData | undefined, isMulti: boolean, state: DialogState): string {\n\tconst parts: string[] = [HINT_PART_ENTER, HINT_PART_NAV];\n\tif (question?.multiSelect === true) parts.push(HINT_PART_TOGGLE);\n\tif (question && question.multiSelect !== true && state.focusedOptionHasPreview && !state.notesVisible) {\n\t\tparts.push(HINT_PART_NOTES);\n\t}\n\tif (isMulti) parts.push(HINT_PART_TAB);\n\tparts.push(HINT_PART_CANCEL);\n\treturn parts.join(\" · \");\n}\n"]}
1
+ {"version":3,"file":"tab-content-strategy.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/view/tab-content-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,E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AAE,WAAW,GAAG,MAAM,CAS9G"}
@@ -1 +1 @@
1
- {"version":3,"file":"bash-async-execution.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-async-execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAIjE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjE,UAAU,4BAA4B;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,eAAe,CAAC,EAAE,uBAAuB,CAAC;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC;IAC3F,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,EAAE,eAAe,CAAC;CACzB,CAAC,CA2DD","sourcesContent":["import type { AsyncJobManager } from \"../async/job-manager.js\";\nimport type { AsyncJobDeliveryHandler } from \"../async/types.js\";\nimport { invalidateNativeSearchCache } from \"./search-native.js\";\nimport { createAsyncOutputAppender } from \"./bash-async-output.js\";\nimport { createManagedBashJob, discardManagedBashJob, formatAsyncJobError } from \"./bash-async-jobs.js\";\nimport type { BashOperations, BashToolDetails } from \"./bash.js\";\n\ninterface StartAsyncBashCommandOptions {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n\tpty?: boolean;\n\ttimeoutSeconds: number;\n\trequestedTimeoutSeconds?: number;\n\tsignal?: AbortSignal;\n\toperations: BashOperations;\n\tmanager?: AsyncJobManager;\n\tdeliveryHandler?: AsyncJobDeliveryHandler;\n\tsessionId?: symbol;\n}\n\nexport async function startAsyncBashCommand(options: StartAsyncBashCommandOptions): Promise<{\n\tcontent: Array<{ type: \"text\"; text: string }>;\n\tdetails: BashToolDetails;\n}> {\n\tif (options.manager?.atCapacity) throw new Error(\"Background job limit reached. Wait for running jobs to finish or cancel one.\");\n\tconst job = createManagedBashJob(options.command, options.cwd, options.timeoutSeconds, options.requestedTimeoutSeconds);\n\ttry {\n\t\toptions.manager?.registerBashJob(job, options.deliveryHandler, options.sessionId);\n\t} catch (registerError) {\n\t\t// The job was inserted into the managed map but never started; drop it so\n\t\t// it cannot linger as a permanently-\"running\" zombie entry (see\n\t\t// discardManagedBashJob). Registration failures (disposed manager/session,\n\t\t// capacity race) still surface to the caller as tool errors.\n\t\tdiscardManagedBashJob(job.jobId);\n\t\tthrow registerError;\n\t}\n\tconst appendAsyncOutput = createAsyncOutputAppender(job, { persistAfterBytes: 12_000 });\n\tconst onParentAbort = () => {\n\t\toptions.manager?.acknowledgeDeliveries([job.jobId]);\n\t\tjob.abortController?.abort();\n\t};\n\tif (options.signal?.aborted) onParentAbort();\n\telse options.signal?.addEventListener(\"abort\", onParentAbort, { once: true });\n\tvoid (async () => {\n\t\tlet error: Error | string | undefined;\n\t\tlet exitCode: number | null | undefined;\n\t\ttry {\n\t\t\texitCode = (await options.operations.exec(options.command, options.cwd, {\n\t\t\t\tonData: appendAsyncOutput.append,\n\t\t\t\ttimeout: options.timeoutSeconds,\n\t\t\t\tenv: options.env,\n\t\t\t\tpty: options.pty,\n\t\t\t\tsignal: job.abortController?.signal,\n\t\t\t})).exitCode;\n\t\t} catch (execError) {\n\t\t\terror = execError instanceof Error ? execError : String(execError);\n\t\t}\n\t\ttry {\n\t\t\tawait appendAsyncOutput.close();\n\t\t} catch (closeError) {\n\t\t\terror ??= closeError instanceof Error ? closeError : String(closeError);\n\t\t}\n\t\tif (error !== undefined) {\n\t\t\tjob.status = \"failed\";\n\t\t\tjob.error = job.abortController?.signal.aborted ? \"aborted\" : formatAsyncJobError(error);\n\t\t} else {\n\t\t\tjob.exitCode = exitCode;\n\t\t\tjob.status = exitCode && exitCode !== 0 ? \"failed\" : \"completed\";\n\t\t}\n\t\tjob.endedAt = Date.now();\n\t\tinvalidateNativeSearchCache();\n\t\toptions.manager?.completeBashJob(job);\n\t\toptions.signal?.removeEventListener(\"abort\", onParentAbort);\n\t})();\n\treturn {\n\t\tcontent: [{ type: \"text\", text: `Started async bash command ${job.jobId}: ${options.command}\\nPoll with bash({ command: \"__atomic_bash_job ${job.jobId}\" }); cancel with bash({ command: \"__atomic_bash_job_cancel ${job.jobId}\" })` }],\n\t\tdetails: {\n\t\t\tasync: { jobId: job.jobId, type: \"bash\", state: \"running\", command: options.command, status: \"running\" },\n\t\t\ttimeoutSeconds: options.timeoutSeconds,\n\t\t\t...(options.requestedTimeoutSeconds !== undefined ? { requestedTimeoutSeconds: options.requestedTimeoutSeconds } : {}),\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"bash-async-execution.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-async-execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAIjE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjE,UAAU,4BAA4B;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,cA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,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,uBAAuB,CAAC,EAAE,MAAM,GAAG,cAAc,CAO5I;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAKzD;AAED,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAM3E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAK7E","sourcesContent":["import { rmSync } from \"node:fs\";\n\nexport interface ManagedBashJob {\n\tjobId: string;\n\tcommand: string;\n\tcwd: string;\n\tstatus: \"running\" | \"completed\" | \"failed\";\n\toutput: string;\n\tfullOutputPath?: string;\n\texitCode?: number | null;\n\terror?: string;\n\tstartedAt: number;\n\tendedAt?: number;\n\ttimeoutSeconds?: number;\n\trequestedTimeoutSeconds?: number;\n\tabortController?: AbortController;\n}\n\nexport const MAX_MANAGED_BASH_JOBS = 100;\nexport const COMPLETED_JOB_TTL_MS = 30 * 60 * 1000;\nconst managedBashJobs = new Map<string, ManagedBashJob>();\nexport function formatAsyncJobError(error: unknown): string {\n\tconst message = error instanceof Error ? error.message : String(error);\n\tif (message.startsWith(\"timeout:\")) return `Command timed out after ${message.slice(\"timeout:\".length)} seconds`;\n\treturn message;\n}\nfunction deleteJobOutput(job: ManagedBashJob): void {\n\tif (!job.fullOutputPath) return;\n\ttry { rmSync(job.fullOutputPath, { force: true }); } catch { /* best-effort temp cleanup */ }\n}\n\nfunction cleanupManagedBashJobs(now = Date.now()): void {\n\tfor (const [jobId, job] of managedBashJobs) if (job.status !== \"running\" && job.endedAt !== undefined && now - job.endedAt > COMPLETED_JOB_TTL_MS) { deleteJobOutput(job); managedBashJobs.delete(jobId); }\n\twhile (managedBashJobs.size > MAX_MANAGED_BASH_JOBS) {\n\t\tconst oldest = [...managedBashJobs.values()].sort((a, b) => (a.endedAt ?? a.startedAt) - (b.endedAt ?? b.startedAt))[0];\n\t\tif (!oldest) break;\n\t\tif (oldest.status === \"running\") oldest.abortController?.abort(); else deleteJobOutput(oldest);\n\t\tmanagedBashJobs.delete(oldest.jobId);\n\t}\n}\n\nexport function createManagedBashJob(command: string, cwd: string, timeoutSeconds?: number, requestedTimeoutSeconds?: number): ManagedBashJob {\n\tcleanupManagedBashJobs();\n\tconst jobId = `bash-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;\n\tconst job: ManagedBashJob = { jobId, command, cwd, status: \"running\", output: \"\", startedAt: Date.now(), timeoutSeconds, requestedTimeoutSeconds, abortController: new AbortController() };\n\tmanagedBashJobs.set(jobId, job);\n\tcleanupManagedBashJobs();\n\treturn job;\n}\n\n/**\n * Remove a managed job that never actually started executing (for example when\n * async-manager registration fails after the map insert). Without this, the\n * entry would stay \"running\" forever: TTL cleanup only evicts settled jobs, so\n * the zombie would linger until the max-jobs overflow forcibly removed it.\n */\nexport function discardManagedBashJob(jobId: string): void {\n\tconst job = managedBashJobs.get(jobId);\n\tif (!job) return;\n\tdeleteJobOutput(job);\n\tmanagedBashJobs.delete(jobId);\n}\n\nexport function listManagedBashJobIds(): string[] {\n\treturn [...managedBashJobs.keys()];\n}\n\nexport function getManagedBashJob(jobId: string): ManagedBashJob | undefined {\n\tcleanupManagedBashJobs();\n\tconst job = managedBashJobs.get(jobId);\n\tif (!job) return undefined;\n\tconst { abortController: _abortController, ...snapshot } = job;\n\treturn { ...snapshot };\n}\n\nexport function abortManagedBashJob(jobId: string): ManagedBashJob | undefined {\n\tconst job = managedBashJobs.get(jobId);\n\tif (!job) return undefined;\n\tjob.abortController?.abort();\n\treturn job;\n}\n"]}
1
+ {"version":3,"file":"bash-async-jobs.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-async-jobs.ts"],"names":[],"mappings":"A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CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACvC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAeD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,qBAAqB,EAAE,OAAO,CAAC,EAAE;IAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,uBAAuB,CAqDvI","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { createWriteStream, type WriteStream } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { APP_NAME } from \"../../config.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize } from \"./truncate.ts\";\n\nexport interface BashAsyncOutputTarget {\n\toutput: string;\n\tfullOutputPath?: string;\n}\n\nexport interface BashAsyncOutputAppender {\n\tappend(chunk: Buffer): void;\n\tclose(): Promise<void>;\n}\n\nfunction outputPath(): string {\n\treturn join(tmpdir(), `${APP_NAME}-bash-async-${randomBytes(8).toString(\"hex\")}.log`);\n}\n\nfunction byteLength(text: string): number { return Buffer.byteLength(text, \"utf8\"); }\nfunction sanitizeDecodedOutput(text: string): string { return sanitizeBinaryOutput(stripAnsi(text)).replace(/\\r/g, \"\"); }\nfunction utf8Prefix(text: string, maxBytes: number): string {\n\tif (byteLength(text) <= maxBytes) return text;\n\tlet end = text.length;\n\twhile (end > 0 && byteLength(text.slice(0, end)) > maxBytes) end--;\n\treturn text.slice(0, end);\n}\n\nexport function createAsyncOutputAppender(job: BashAsyncOutputTarget, options?: { persistAfterBytes?: number }): BashAsyncOutputAppender {\n\tconst persistAfterBytes = options?.persistAfterBytes ?? DEFAULT_MAX_BYTES;\n\tlet outputBytes = 0;\n\tlet truncated = false;\n\tlet fullOutputStream: WriteStream | undefined;\n\tlet bufferedChunks: Buffer[] = [];\n\tconst decoder = new TextDecoder();\n\n\tconst ensureFullOutputStream = (): WriteStream => {\n\t\tif (fullOutputStream) return fullOutputStream;\n\t\tjob.fullOutputPath = outputPath();\n\t\tfullOutputStream = createWriteStream(job.fullOutputPath);\n\t\tfor (const chunk of bufferedChunks) fullOutputStream.write(chunk);\n\t\tbufferedChunks = [];\n\t\treturn fullOutputStream;\n\t};\n\tconst appendDecodedText = (decoded: string): void => {\n\t\tif (truncated || decoded.length === 0) return;\n\t\tconst text = sanitizeDecodedOutput(decoded);\n\t\tif (text.length === 0) return;\n\t\tconst bytes = byteLength(text);\n\t\tif (outputBytes + bytes > persistAfterBytes) ensureFullOutputStream();\n\t\tif (outputBytes + bytes > DEFAULT_MAX_BYTES) {\n\t\t\tensureFullOutputStream();\n\t\t\tconst remaining = Math.max(0, DEFAULT_MAX_BYTES - outputBytes);\n\t\t\tif (remaining > 0) job.output += utf8Prefix(text, remaining);\n\t\t\tjob.output += `\\n[Output truncated at ${formatSize(DEFAULT_MAX_BYTES)} for async job polling. Full output: ${job.fullOutputPath}]`;\n\t\t\toutputBytes += bytes;\n\t\t\ttruncated = true;\n\t\t\treturn;\n\t\t}\n\t\toutputBytes += bytes;\n\t\tjob.output += text;\n\t};\n\n\treturn {\n\t\tappend(chunk) {\n\t\t\tif (fullOutputStream) fullOutputStream.write(chunk);\n\t\t\telse bufferedChunks.push(chunk);\n\t\t\tappendDecodedText(decoder.decode(chunk, { stream: true }));\n\t\t},\n\t\tasync close() {\n\t\t\tappendDecodedText(decoder.decode());\n\t\t\tif (!fullOutputStream) return;\n\t\t\tconst stream = fullOutputStream;\n\t\t\tfullOutputStream = undefined;\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tstream.once(\"error\", reject);\n\t\t\t\tstream.once(\"finish\", resolve);\n\t\t\t\tstream.end();\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"bash-async-output.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-async-output.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACvC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAeD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,qBAAqB,EAAE,OAAO,CAAC,EAAE;IAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,uBAAuB,CAqDvI"}
@@ -1 +1 @@
1
- {"version":3,"file":"bash-interceptor.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-interceptor.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,8BAA8B,EAAE,mBAAmB,EAQ/D,CAAC;AAEF,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,SAAS,MAAM,EAAE,EACjC,KAAK,GAAE,SAAS,mBAAmB,EAAmC,GACpE,MAAM,GAAG,SAAS,CAWpB;AAED,wBAAgB,+BAA+B,CAC9C,UAAU,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,EACrC,cAAc,EAAE,SAAS,MAAM,EAAE,EACjC,KAAK,GAAE,SAAS,mBAAmB,EAAmC,GACpE,IAAI,CASN","sourcesContent":["export interface BashInterceptorRule {\n\tpattern: string;\n\tflags?: string;\n\ttool: string;\n\tmessage: string;\n}\n\nexport const DEFAULT_BASH_INTERCEPTOR_RULES: BashInterceptorRule[] = [\n\t{ pattern: \"^\\\\s*(cat|head|tail|less|more)\\\\s+\", tool: \"read\", message: \"Use the read tool instead of shell commands to inspect file contents.\" },\n\t{ pattern: \"^\\\\s*(grep|rg|ripgrep|ag|ack)\\\\s+\", tool: \"search\", message: \"Use the search tool instead of shell grep commands.\" },\n\t{ pattern: \"^\\\\s*(find|fd|locate)\\\\s+.*(-name|-iname|-type|--type|-glob)\", tool: \"find\", message: \"Use the find tool instead of shell find/fd/locate commands.\" },\n\t{ pattern: \"^\\\\s*sed\\\\s+(-i|--in-place)\", tool: \"edit\", message: \"Use the edit tool instead of in-place sed.\" },\n\t{ pattern: \"^\\\\s*perl\\\\s+.*-[pn]?i\", tool: \"edit\", message: \"Use the edit tool instead of in-place perl.\" },\n\t{ pattern: \"^\\\\s*awk\\\\s+.*-i\\\\s+inplace\", tool: \"edit\", message: \"Use the edit tool instead of in-place awk.\" },\n\t{ pattern: \"^\\\\s*(echo|printf|cat\\\\s*<<)\\\\s+(?:[^\\\"'>]|\\\"[^\\\"]*\\\"|'[^']*')*(?<!\\\\|)>{1,2}\\\\|?\\\\s*[$\\\\w./~\\\"'-]\", tool: \"write\", message: \"Use the write tool instead of shell redirection to write files.\" },\n];\n\nexport function checkBashInterception(\n\tcommand: string,\n\tavailableTools: readonly string[],\n\trules: readonly BashInterceptorRule[] = DEFAULT_BASH_INTERCEPTOR_RULES,\n): string | undefined {\n\tfor (const rule of rules) {\n\t\tif (!availableTools.includes(rule.tool)) continue;\n\t\tlet matcher: RegExp;\n\t\ttry { matcher = new RegExp(rule.pattern, rule.flags); }\n\t\tcatch (error) { throw new Error(`Invalid bash interceptor rule for ${rule.tool}: ${error instanceof Error ? error.message : String(error)}`); }\n\t\tif (matcher.test(command.trim())) {\n\t\t\treturn `Blocked: ${rule.message}\\n\\nOriginal command: ${command}`;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nexport function checkBashInterceptionCandidates(\n\tcandidates: Array<string | undefined>,\n\tavailableTools: readonly string[],\n\trules: readonly BashInterceptorRule[] = DEFAULT_BASH_INTERCEPTOR_RULES,\n): void {\n\tconst seen = new Set<string>();\n\tfor (const candidate of candidates) {\n\t\tconst command = candidate?.trim();\n\t\tif (!command || seen.has(command)) continue;\n\t\tseen.add(command);\n\t\tconst blocked = checkBashInterception(command, availableTools, rules);\n\t\tif (blocked) throw new Error(blocked);\n\t}\n}\n"]}
1
+ {"version":3,"file":"bash-interceptor.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-interceptor.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,8BAA8B,EAAE,mBAAmB,EAQ/D,CAAC;AAEF,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,SAAS,MAAM,EAAE,EACjC,KAAK,GAAE,SAAS,mBAAmB,EAAmC,GACpE,MAAM,GAAG,SAAS,CAWpB;AAED,wBAAgB,+BAA+B,CAC9C,UAAU,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,EACrC,cAAc,EAAE,SAAS,MAAM,EAAE,EACjC,KAAK,GAAE,SAAS,mBAAmB,EAAmC,GACpE,IAAI,CASN"}
@@ -1 +1 @@
1
- {"version":3,"file":"bash-leading-cd.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-leading-cd.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACvB;AAUD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CA+BrG","sourcesContent":["import { homedir } from \"node:os\";\nimport { resolve as resolvePath } from \"node:path\";\nimport { getShellEnv } from \"../../utils/shell.ts\";\n\nexport interface LeadingCdSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nfunction isShellWhitespace(char: string | undefined): boolean { return char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\r\"; }\nfunction requiresShellExpansion(pathValue: string): boolean { return pathValue.includes(\"$\") || pathValue.includes(\"`\") || pathValue.includes(\"(\"); }\nfunction expandHomePath(pathValue: string): string {\n\tif (pathValue === \"~\") return homedir();\n\tif (pathValue.startsWith(\"~/\")) return resolvePath(homedir(), pathValue.slice(2));\n\treturn pathValue;\n}\n\nexport function stripLeadingCdCommand(command: string, cwd: string): LeadingCdSpawnContext | undefined {\n\tlet index = 0;\n\twhile (isShellWhitespace(command[index])) index++;\n\tif (command.slice(index, index + 2) !== \"cd\" || !isShellWhitespace(command[index + 2])) return undefined;\n\tindex += 2;\n\twhile (isShellWhitespace(command[index])) index++;\n\tlet rawPath = \"\";\n\tconst quote = command[index];\n\tif (quote === \"'\" || quote === '\"') {\n\t\tindex++;\n\t\tconst pathStart = index;\n\t\twhile (index < command.length && command[index] !== quote) index++;\n\t\tif (index >= command.length) return undefined;\n\t\trawPath = command.slice(pathStart, index);\n\t\tindex++;\n\t} else {\n\t\tconst pathStart = index;\n\t\twhile (index < command.length && command[index] !== \"&\" && command[index] !== \";\") index++;\n\t\trawPath = command.slice(pathStart, index).trim();\n\t}\n\tif (!rawPath) return undefined;\n\tif (requiresShellExpansion(rawPath)) return undefined;\n\twhile (isShellWhitespace(command[index])) index++;\n\tlet separatorLength = 0;\n\tif (command[index] === \"&\" && command[index + 1] === \"&\") separatorLength = 2;\n\telse if (command[index] === \";\") separatorLength = 1;\n\telse return undefined;\n\tindex += separatorLength;\n\twhile (isShellWhitespace(command[index])) index++;\n\tconst nextCommand = command.slice(index);\n\treturn nextCommand ? { command: nextCommand, cwd: resolvePath(cwd, expandHomePath(rawPath)), env: { ...getShellEnv() } } : undefined;\n}\n"]}
1
+ {"version":3,"file":"bash-leading-cd.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-leading-cd.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACvB;AAUD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CA+BrG"}
@@ -1 +1 @@
1
- {"version":3,"file":"bash-pty-native.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AA4CA,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAqBD,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CA+BxI","sourcesContent":["import { createModuleRequire } from \"../../utils/module-require.ts\";\nimport { getShellConfig, getShellEnv } from \"../../utils/shell.ts\";\n\nconst NATIVE_PACKAGE = \"@bastani/atomic-natives\";\n\ninterface NativePtyRunResult {\n\texitCode?: number;\n\texit_code?: number;\n\tcancelled?: boolean;\n\ttimedOut?: boolean;\n\ttimed_out?: boolean;\n}\n\ninterface NativePtySession {\n\tstart(\n\t\toptions: {\n\t\t\tcommand: string;\n\t\t\tcwd?: string;\n\t\t\tenv?: Record<string, string>;\n\t\t\ttimeoutMs?: number;\n\t\t\tcols?: number;\n\t\t\trows?: number;\n\t\t\tshell?: string;\n\t\t\tshellArgs?: string[];\n\t\t\tcommandTransport?: \"argv\" | \"stdin\";\n\t\t\tcloseStdinAfterCommand?: boolean;\n\t\t},\n\t\tonChunk?: (error: Error | null, chunk: string) => void,\n\t): Promise<NativePtyRunResult>;\n\twrite(data: string): void;\n\tresize(cols: number, rows: number): void;\n\tkill(): void;\n}\n\ninterface NativePtyBinding {\n\tPtySession: new () => NativePtySession;\n}\n\ntype NativeLoadResult =\n\t| { ok: true; binding: NativePtyBinding }\n\t| { ok: false; error: Error };\n\nlet cachedLoadResult: NativeLoadResult | undefined;\n\nexport function resetNativePtyBindingCache(): void {\n\tcachedLoadResult = undefined;\n}\n\nfunction loadNativePtyBinding(): NativeLoadResult {\n\tif (cachedLoadResult) return cachedLoadResult;\n\ttry {\n\t\tconst loaded = createModuleRequire(import.meta.url)(NATIVE_PACKAGE) as Partial<NativePtyBinding>;\n\t\tif (typeof loaded.PtySession !== \"function\") {\n\t\t\tcachedLoadResult = { ok: false, error: new Error(`Native package ${NATIVE_PACKAGE} is missing PtySession.`) };\n\t\t\treturn cachedLoadResult;\n\t\t}\n\t\tcachedLoadResult = { ok: true, binding: loaded as NativePtyBinding };\n\t\treturn cachedLoadResult;\n\t} catch (error) {\n\t\tcachedLoadResult = {\n\t\t\tok: false,\n\t\t\terror: new Error(`Native PTY package ${NATIVE_PACKAGE} is unavailable for ${process.platform}-${process.arch}: ${error instanceof Error ? error.message : String(error)}`),\n\t\t};\n\t\treturn cachedLoadResult;\n\t}\n}\n\nexport interface NativePtyExecOptions {\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n\tenv?: NodeJS.ProcessEnv;\n\tshellPath?: string;\n\tcols?: number;\n\trows?: number;\n}\n\nexport async function executeNativePty(command: string, cwd: string, options: NativePtyExecOptions): Promise<{ exitCode: number | null }> {\n\tconst loaded = loadNativePtyBinding();\n\tif (!loaded.ok) throw loaded.error;\n\tif (options.signal?.aborted) throw new Error(\"aborted\");\n\tconst shellConfig = getShellConfig(options.shellPath);\n\tconst session = new loaded.binding.PtySession();\n\tconst onAbort = () => {\n\t\ttry { session.kill(); } catch {}\n\t};\n\tif (options.signal) options.signal.addEventListener(\"abort\", onAbort, { once: true });\n\ttry {\n\t\tconst result = await session.start({\n\t\t\tcommand,\n\t\t\tcwd,\n\t\t\tenv: { ...getShellEnv(), ...(options.env ?? {}), TERM: \"xterm-256color\" },\n\t\t\ttimeoutMs: options.timeout !== undefined ? Math.max(1, Math.floor(options.timeout * 1000)) : undefined,\n\t\t\tcols: options.cols ?? 120,\n\t\t\trows: options.rows ?? 40,\n\t\t\tshell: shellConfig.shell,\n\t\t\tshellArgs: shellConfig.args,\n\t\t\tcommandTransport: shellConfig.commandTransport,\n\t\t\tcloseStdinAfterCommand: shellConfig.commandTransport === \"stdin\",\n\t\t}, (_error, chunk) => {\n\t\t\tif (chunk) options.onData(Buffer.from(chunk));\n\t\t});\n\t\tif (options.signal?.aborted || result.cancelled) throw new Error(\"aborted\");\n\t\tif (result.timedOut ?? result.timed_out) throw new Error(`timeout:${options.timeout}`);\n\t\treturn { exitCode: result.exitCode ?? result.exit_code ?? null };\n\t} finally {\n\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n"]}
1
+ {"version":3,"file":"bash-pty-native.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash-pty-native.ts"],"names":[],"mappings":"AA4CA,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAqBD,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAA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AqB,GAAG,SAAS,CAAC;AAC5I,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,gEAAgE;IAChE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,wEAAwE;IACxE,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,kBAAkB,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IAC/C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACzC,6EAA6E;IAC7E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,uBAAuB,CAAC,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAQD,KAAK,eAAe,GAAG;IACtB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;CACrC,CAAC;AAyGF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CAqOjF;AACD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import { constants } from \"node:fs\";\nimport { resolve as resolvePath } from \"node:path\";\nimport { access as fsAccess, stat as fsStat } from \"node:fs/promises\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Container, Text, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { APP_NAME } from \"../../config.ts\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport { getShellConfig, getShellEnv, killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\nimport type { AsyncJobManager } from \"../async/job-manager.js\";\nimport type { AsyncJobDeliveryMessage } from \"../async/types.js\";\nimport type { BashResult } from \"../bash-executor.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { startAsyncBashCommand } from \"./bash-async-execution.js\";\nimport { abortManagedBashJob, getManagedBashJob } from \"./bash-async-jobs.ts\";\nimport { stripLeadingCdCommand } from \"./bash-leading-cd.ts\";\nimport { executeNativePty } from \"./bash-pty-native.ts\";\nimport { checkBashInterceptionCandidates, DEFAULT_BASH_INTERCEPTOR_RULES, type BashInterceptorRule } from \"./bash-interceptor.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { expandShellInternalUrls, type InternalResourceContext } from \"./resource-selectors.ts\";\nimport { getTextOutput, invalidArgText, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { invalidateNativeSearchCache } from \"./search-native.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult } from \"./truncate.ts\";\nconst envSchema = Type.Unsafe<Record<string, string>>({ type: \"object\", description: \"Environment variables to add or override.\", additionalProperties: { type: \"string\" }, propertyNames: { pattern: \"^[A-Za-z_][A-Za-z0-9_]*$\" } });\nconst bashBaseSchema = Type.Object({ command: Type.String({ description: \"Shell command to execute.\" }), env: Type.Optional(envSchema), timeout: Type.Optional(Type.Number({ description: \"Timeout in seconds.\" })), cwd: Type.Optional(Type.String({ description: \"Working directory for the command.\" })), pty: Type.Optional(Type.Boolean({ description: \"Run with PTY handling.\" })) }, { additionalProperties: false });\nconst bashSchema = Type.Object({ ...bashBaseSchema.properties, async: Type.Optional(Type.Boolean({ description: \"Run as a background job.\" })) }, { additionalProperties: false });\nexport type BashToolInput = Static<typeof bashSchema>;\nexport interface BashToolDetails { truncation?: TruncationResult; fullOutputPath?: string; exitCode?: number | null; async?: { jobId: string; type: \"bash\"; state: \"running\" | \"completed\" | \"failed\"; command?: string; status?: \"running\" | \"completed\" | \"failed\" }; timeoutSeconds?: number; requestedTimeoutSeconds?: number; wallTimeMs?: number }\nconst DEFAULT_TIMEOUT_SECONDS = 300, MAX_TIMEOUT_SECONDS = 3600;\nfunction validateExplicitTimeoutSeconds(timeout: number): void { if (!Number.isFinite(timeout) || timeout <= 0 || timeout > MAX_TIMEOUT_SECONDS) throw new Error(`Invalid timeout ${String(timeout)}: timeout must be a finite number greater than 0 and no more than ${MAX_TIMEOUT_SECONDS} seconds`); }\nfunction normalizeTimeoutSeconds(timeout: number | undefined): number {\n\tif (timeout === undefined) return DEFAULT_TIMEOUT_SECONDS;\n\tvalidateExplicitTimeoutSeconds(timeout); return Math.max(1, Math.floor(timeout));\n}\n\nexport interface BashOperations {\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t\tpty?: boolean;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\nexport function createLocalBashOperations(options?: { shellPath?: string }): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env, pty }) => {\n\t\t\tif (timeout !== undefined) validateExplicitTimeoutSeconds(timeout);\n\n\t\t\tif (pty && process.env.PI_NO_PTY !== \"1\" && process.env.ATOMIC_NO_PTY !== \"1\") {\n\t\t\t\ttry { return await executeNativePty(command, cwd, { onData, signal, timeout, env, shellPath: options?.shellPath }); }\n\t\t\t\tcatch (error) { const message = String(error instanceof Error ? error.message : error); if (!message.includes(\"Native PTY\") && !message.includes(\"PtySession\")) throw error; }\n\t\t\t}\n\t\t\tconst shellConfig = getShellConfig(options?.shellPath);\n\t\t\ttry { const cwdStat = await fsStat(cwd); if (!cwdStat.isDirectory()) throw new Error(`Working directory is not a directory: ${cwd}`); await fsAccess(cwd, constants.F_OK); } catch (error) {\n\t\t\t\tif (error instanceof Error && error.message.startsWith(\"Working directory is not a directory\")) throw error;\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`);\n\t\t\t}\n\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(command);\n\t\t\t}\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tif (timeout !== undefined && timeout > 0) {\n\t\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t\t}, timeout * 1000);\n\t\t\t\t}\n\t\t\t\tchild.stdout?.on(\"data\", onData);\n\t\t\t\tchild.stderr?.on(\"data\", onData);\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new Error(`timeout:${timeout}`);\n\t\t\t\t}\n\t\t\t\treturn { exitCode };\n\t\t\t} finally {\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t},\n\t};\n}\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\nexport interface BashInterceptorResult {\n\toperations?: BashOperations;\n\tresult?: BashResult;\n}\nexport type BashInterceptor = (context: BashSpawnContext) => Promise<BashInterceptorResult | undefined> | BashInterceptorResult | undefined;\nexport interface BashToolOptions {\n\toperations?: BashOperations;\n\t/** Prefix prepended to every shell command before execution. */\n\tcommandPrefix?: string;\n\t/** Override shell executable resolution for local bash operations. */\n\tshellPath?: string;\n\t/** Last-mile hook for rewriting the command/cwd/env spawn context. */\n\tspawnHook?: BashSpawnHook;\n\t/** Optional command interceptor used by extensions and parity tests. */\n\tinterceptor?: BashInterceptor;\n\tinterceptorEnabled?: boolean | (() => boolean);\n\tavailableTools?: string[];\n\tinterceptorRules?: BashInterceptorRule[];\n\t/** Enable background bash jobs and session-managed async result delivery. */\n\tasyncEnabled?: boolean;\n\tasyncJobManager?: AsyncJobManager;\n\tasyncJobDeliveryHandler?: (message: AsyncJobDeliveryMessage) => void | Promise<void>;\n\tasyncJobSessionId?: symbol;\n}\nconst BASH_PREVIEW_LINES = 5, BASH_UPDATE_THROTTLE_MS = 100;\nfunction bashResultToToolResult(result: BashResult): { content: Array<{ type: \"text\"; text: string }>; details: BashToolDetails | undefined } {\n\tconst details: BashToolDetails | undefined = result.truncated ? { fullOutputPath: result.fullOutputPath } : undefined;\n\tconst status = result.cancelled ? \"Command aborted\" : result.exitCode && result.exitCode !== 0 ? `Command exited with code ${result.exitCode}` : undefined;\n\tconst text = `${result.output || \"(no output)\"}${status ? `\\n\\n${status}` : \"\"}`;\n\treturn { content: [{ type: \"text\", text }], details };\n}\ntype BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\nfunction formatDuration(ms: number): string {\n\tconst totalSeconds = Math.floor(Math.max(0, ms) / 1000);\n\tconst hours = Math.floor(totalSeconds / 3600);\n\tconst minutes = Math.floor((totalSeconds % 3600) / 60);\n\tconst seconds = totalSeconds % 60;\n\tif (hours > 0) return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;\n\tif (minutes > 0) return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;\n\treturn `${seconds}s`;\n}\nfunction formatBashCall(args: { command?: string; timeout?: number } | undefined): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tconst commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\treturn theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix;\n}\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\tlet output = getTextOutput(result, showImages).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tif (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith(\"]\")) {\n\t\tconst footerStart = output.lastIndexOf(\"\\n\\n[\");\n\t\tif (footerStart !== -1 && output.slice(footerStart).includes(fullOutputPath)) {\n\t\t\toutput = output.slice(0, footerStart).trimEnd();\n\t\t}\n\t}\n\tif (output) {\n\t\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\t\tif (options.expanded) {\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines;\n\t\t\t\t\t\tstate.cachedSkipped = preview.skippedCount;\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\tif (state.cachedSkipped && state.cachedSkipped > 0) {\n\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${state.cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"Expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...(state.cachedLines ?? [])];\n\t\t\t\t\t}\n\t\t\t\t\treturn [\"\", ...(state.cachedLines ?? [])];\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t\tstate.cachedSkipped = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\tif (truncation?.truncated || fullOutputPath) {\n\t\tconst warnings: string[] = [];\n\t\tif (fullOutputPath) {\n\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t}\n\t\tif (truncation?.truncated) {\n\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t} else {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t}\n\tif (startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst defaultOps = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\tconst interceptor = options?.interceptor;\n\tconst isInterceptorEnabled = (): boolean => typeof options?.interceptorEnabled === \"function\" ? options.interceptorEnabled() : options?.interceptorEnabled ?? !!interceptor;\n\tconst availableTools = options?.availableTools ?? [\"read\", \"search\", \"find\", \"edit\", \"write\"];\n\tconst interceptorRules = options?.interceptorRules ?? DEFAULT_BASH_INTERCEPTOR_RULES;\n\tconst asyncEnabled = options?.asyncEnabled ?? false;\n\tconst asyncJobManager = options?.asyncJobManager, asyncJobDeliveryHandler = options?.asyncJobDeliveryHandler, asyncJobSessionId = options?.asyncJobSessionId;\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: \"Execute a shell command in the session workspace, with optional PTY or background-job handling.\",\n\t\tpromptSnippet: \"Execute a shell command.\",\n\t\tparameters: asyncEnabled ? bashSchema : bashBaseSchema as typeof bashSchema,\n\t\tmaxResultSizeChars: Infinity,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tbashCommand: BashToolInput,\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst { command } = bashCommand;\n\t\t\tconst jobStatusMatch = command.match(/^__atomic_bash_job\\s+(\\S+)$/);\n\t\t\tif (jobStatusMatch) {\n\t\t\t\tconst job = getManagedBashJob(jobStatusMatch[1]!);\n\t\t\t\tif (!job) throw new Error(`Unknown bash async job: ${jobStatusMatch[1]}`);\n\t\t\t\tif (job.status !== \"running\") asyncJobManager?.acknowledgeDeliveries([job.jobId]);\n\t\t\t\tconst text = [`Job ${job.jobId}: ${job.status}`, `Command: ${job.command}`, job.error ? `Error: ${job.error}` : undefined, job.output].filter(Boolean).join(\"\\n\");\n\t\t\t\treturn { content: [{ type: \"text\", text }], details: { async: { jobId: job.jobId, type: \"bash\", state: job.status, command: job.command, status: job.status }, exitCode: job.exitCode, timeoutSeconds: job.timeoutSeconds, ...(job.requestedTimeoutSeconds !== undefined ? { requestedTimeoutSeconds: job.requestedTimeoutSeconds } : {}), ...(job.fullOutputPath ? { fullOutputPath: job.fullOutputPath } : {}), wallTimeMs: (job.endedAt ?? Date.now()) - job.startedAt } };\n\t\t\t}\n\t\t\tconst jobCancelMatch = command.match(/^__atomic_bash_job_cancel\\s+(\\S+)$/);\n\t\t\tif (jobCancelMatch) {\n\t\t\t\tconst job = abortManagedBashJob(jobCancelMatch[1]!);\n\t\t\t\tif (!job) throw new Error(`Unknown bash async job: ${jobCancelMatch[1]}`);\n\t\t\t\tasyncJobManager?.acknowledgeDeliveries([job.jobId]);\n\t\t\t\treturn { content: [{ type: \"text\", text: `Cancellation requested for bash job ${job.jobId}` }], details: { async: { jobId: job.jobId, type: \"bash\", state: job.status, command: job.command, status: job.status } } };\n\t\t\t}\n\t\t\tconst timeout = normalizeTimeoutSeconds(bashCommand.timeout);\n\t\t\tconst resourceCtx = _ctx as InternalResourceContext | undefined;\n\t\t\tconst hasExplicitCwd = typeof bashCommand.cwd === \"string\";\n\t\t\tconst rawStrippedContext = hasExplicitCwd ? undefined : stripLeadingCdCommand(command, cwd);\n\t\t\tconst interceptorEnabled = isInterceptorEnabled();\n\t\t\tif (interceptorEnabled) checkBashInterceptionCandidates([command, rawStrippedContext?.command], availableTools, interceptorRules);\n\t\t\tconst cwdInput = hasExplicitCwd ? await expandShellInternalUrls(bashCommand.cwd!, cwd, resourceCtx) : cwd, requestedCwd = resolvePath(cwd, cwdInput);\n\t\t\tconst expandedCommand = await expandShellInternalUrls(command, cwd, resourceCtx, true);\n\t\t\tconst strippedExpandedContext = hasExplicitCwd ? undefined : stripLeadingCdCommand(expandedCommand, requestedCwd);\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${expandedCommand}` : expandedCommand;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, requestedCwd, spawnHook);\n\t\t\tconst strippedCdContext = strippedExpandedContext ? resolveSpawnContext(commandPrefix ? `${commandPrefix}\\n${strippedExpandedContext.command}` : strippedExpandedContext.command, strippedExpandedContext.cwd, spawnHook) : undefined;\n\t\t\tif (interceptorEnabled) checkBashInterceptionCandidates([expandedCommand, strippedExpandedContext?.command, resolvedCommand, spawnContext.command, strippedCdContext?.command], availableTools, interceptorRules);\n\t\t\tlet expandedEnv: NodeJS.ProcessEnv | undefined;\n\t\t\tif (bashCommand.env) {\n\t\t\t\texpandedEnv = {};\n\t\t\t\tfor (const [key, value] of Object.entries(bashCommand.env)) {\n\t\t\t\t\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid bash env name: ${key}`);\n\t\t\t\t\texpandedEnv[key] = await expandShellInternalUrls(value, cwd, resourceCtx);\n\t\t\t\t}\n\t\t\t\tspawnContext.env = { ...spawnContext.env, ...expandedEnv };\n\t\t\t}\n\t\t\tif (strippedCdContext && expandedEnv) strippedCdContext.env = { ...strippedCdContext.env, ...expandedEnv };\n\t\t\tconst primaryInterception = interceptorEnabled && interceptor ? await interceptor(spawnContext) : undefined;\n\t\t\tconst fallbackInterception = !primaryInterception && strippedCdContext && interceptorEnabled && interceptor ? await interceptor(strippedCdContext) : undefined;\n\t\t\tconst intercepted = primaryInterception ?? fallbackInterception;\n\t\t\tif (intercepted?.result) return bashResultToToolResult(intercepted.result);\n\t\t\tconst ops = intercepted?.operations ?? defaultOps;\n\t\t\tconst executionContext = primaryInterception ? spawnContext : (strippedCdContext ?? spawnContext);\n\t\t\tif (bashCommand.async) {\n\t\t\t\tif (!asyncEnabled) throw new Error(\"bash async execution is disabled\");\n\t\t\t\treturn startAsyncBashCommand({\n\t\t\t\t\tcommand: executionContext.command,\n\t\t\t\t\tcwd: executionContext.cwd,\n\t\t\t\t\tenv: executionContext.env,\n\t\t\t\t\tpty: bashCommand.pty,\n\t\t\t\t\ttimeoutSeconds: timeout,\n\t\t\t\t\trequestedTimeoutSeconds: bashCommand.timeout !== undefined && bashCommand.timeout !== timeout ? bashCommand.timeout : undefined,\n\t\t\t\t\tsignal,\n\t\t\t\t\toperations: ops,\n\t\t\t\t\tmanager: asyncJobManager,\n\t\t\t\t\tdeliveryHandler: asyncJobDeliveryHandler,\n\t\t\t\t\tsessionId: asyncJobSessionId,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst output = new OutputAccumulator({ tempFilePrefix: `${APP_NAME}-bash` });\n\t\t\tlet acceptingOutput = true;\n\t\t\tlet updateTimer: NodeJS.Timeout | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\t\t\tconst emitOutputUpdate = () => {\n\t\t\t\tif (!onUpdate || !updateDirty) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: snapshot.content || \"\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\t\t\tconst clearUpdateTimer = () => {\n\t\t\t\tif (updateTimer) {\n\t\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst scheduleOutputUpdate = () => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\tif (!acceptingOutput) return;\n\t\t\t\toutput.append(data);\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\t\t\tconst finishOutput = async () => {\n\t\t\t\tacceptingOutput = false;\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\treturn snapshot;\n\t\t\t};\n\t\t\tconst formatOutput = (snapshot: Awaited<ReturnType<typeof finishOutput>>, emptyText = \"(no output)\") => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tlet text = snapshot.content || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\t\t\tconst startedAt = Date.now();\n\t\t\tconst withTiming = (details: BashToolDetails | undefined): BashToolDetails => ({ ...details, timeoutSeconds: timeout, ...(bashCommand.timeout !== undefined && bashCommand.timeout !== timeout ? { requestedTimeoutSeconds: bashCommand.timeout } : {}), wallTimeMs: Date.now() - startedAt });\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(executionContext.command, executionContext.cwd, {\n\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tenv: executionContext.env,\n\t\t\t\t\t\tpty: bashCommand.pty,\n\t\t\t\t\t});\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\tconst { text } = formatOutput(snapshot, \"\");\n\t\t\t\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\t\t\t\tthrow new Error(appendStatus(text, \"Command aborted\"));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\tthrow new Error(appendStatus(text, `Command timed out after ${timeoutSecs} seconds`));\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\n\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\treturn { content: [{ type: \"text\", text: appendStatus(outputText, `Command exited with code ${exitCode}`) }], details: { ...withTiming(details), exitCode }, isError: true };\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details: withTiming(details) };\n\t\t\t} finally { invalidateNativeSearchCache(); clearUpdateTimer(); }\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatBashCall(args));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM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IACrF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAQD,KAAK,eAAe,GAAG;IACtB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;CACrC,CAAC;AAyGF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CAqOjF;AACD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG"}
@@ -1 +1 @@
1
- {"version":3,"file":"block-resolver.d.ts","sourceRoot":"","sources":["../../../src/core/tools/block-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,aAAa,EAAmC,MAAM,4BAA4B,CAAC;AAoDjG,iFAAiF;AACjF,eAAO,MAAM,mBAAmB,EAAE,aAOjC,CAAC","sourcesContent":["/**\n * Host-provided block resolver for the hashline engine.\n *\n * Resolves `replace block N:` / `delete block N` / `insert after block N:`\n * anchors with the Rust tree-sitter `blockRangeAt` primitive in\n * `@bastani/atomic-natives` (mirrors oh-my-pi's native resolver): it infers the\n * language from the path and returns the 1-indexed line span of the syntactic\n * block beginning on line N, or `null` when none resolves (blank line, pure\n * closing delimiter, unsupported language, or a syntax error in the subtree).\n * A small brace/indent heuristic is used only when the native binding is\n * unavailable.\n */\nimport type { BlockResolver, BlockResolverRequest, BlockSpan } from \"./hashline-engine/index.ts\";\nimport { loadNativeSearchBinding } from \"./search-native.ts\";\n\nconst PURE_CLOSER_RE = /^[)\\]}]+[;,]?\\s*$/;\n\n/** Strip line comments and same-line string literals so delimiters inside them are not counted. */\nfunction stripNonCode(line: string): string {\n\tlet out = \"\";\n\tlet quote = \"\";\n\tfor (let i = 0; i < line.length; i++) {\n\t\tconst ch = line[i]!;\n\t\tif (quote) {\n\t\t\tif (ch === \"\\\\\") { i++; continue; }\n\t\t\tif (ch === quote) quote = \"\";\n\t\t\tcontinue;\n\t\t}\n\t\tif (ch === '\"' || ch === \"'\" || ch === \"`\") { quote = ch; continue; }\n\t\tif (ch === \"/\" && line[i + 1] === \"/\") break;\n\t\tif (ch === \"#\") break;\n\t\tout += ch;\n\t}\n\treturn out;\n}\n\n/** Fallback: resolve a brace-delimited block by `{`/`}` balance, or an indented block. */\nfunction heuristicResolve(request: BlockResolverRequest): BlockSpan | null {\n\tconst lines = request.text.split(\"\\n\");\n\tconst startIndex = request.line - 1;\n\tconst opener = lines[startIndex];\n\tif (opener === undefined || opener.trim() === \"\" || PURE_CLOSER_RE.test(opener.trim())) return null;\n\tif (stripNonCode(opener).includes(\"{\")) {\n\t\tlet balance = 0;\n\t\tfor (let i = startIndex; i < lines.length; i++) {\n\t\t\tfor (const ch of stripNonCode(lines[i]!)) {\n\t\t\t\tif (ch === \"{\") balance++;\n\t\t\t\telse if (ch === \"}\") { balance--; if (balance === 0) return { start: request.line, end: i + 1 }; }\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\tconst baseIndent = opener.length - opener.trimStart().length;\n\tlet end = startIndex;\n\tfor (let i = startIndex + 1; i < lines.length; i++) {\n\t\tconst line = lines[i]!;\n\t\tif (line.trim() === \"\") continue;\n\t\tconst indent = line.length - line.trimStart().length;\n\t\tif (indent <= baseIndent) break;\n\t\tend = i;\n\t}\n\treturn end > startIndex ? { start: request.line, end: end + 1 } : null;\n}\n\n/** Tree-sitter-backed block resolver wired into the hashline {@link Patcher}. */\nexport const nativeBlockResolver: BlockResolver = (request: BlockResolverRequest): BlockSpan | null => {\n\tconst native = loadNativeSearchBinding();\n\tif (native?.blockRangeAt) {\n\t\tconst range = native.blockRangeAt({ code: request.text, path: request.path, line: request.line });\n\t\treturn range ? { start: range.startLine, end: range.endLine } : null;\n\t}\n\treturn heuristicResolve(request);\n};\n"]}
1
+ {"version":3,"file":"block-resolver.d.ts","sourceRoot":"","sources":["../../../src/core/tools/block-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,aAAa,EAAmC,MAAM,4BAA4B,CAAC;AAoDjG,iFAAiF;AACjF,eAAO,MAAM,mBAAmB,EAAE,aAOjC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"conflict-registry.d.ts","sourceRoot":"","sources":["../../../src/core/tools/conflict-registry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;CACf;AAID,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAwB/E;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAEjF;AAED,6FAA6F;AAC7F,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,EAAE,CAExE;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE7F","sourcesContent":["export interface ConflictBlock {\n\tfile: string;\n\tstart: number;\n\tsep: number;\n\tend: number;\n\tbaseSep?: number;\n\tours: string[];\n\ttheirs: string[];\n\tbase: string[];\n}\n\nconst conflictRegistry = new Map<string, ConflictBlock[]>();\n\nexport function parseConflictBlocks(file: string, text: string): ConflictBlock[] {\n\tconst lines = text.split(\"\\n\"), blocks: ConflictBlock[] = [];\n\tfor (let index = 0; index < lines.length; index++) {\n\t\tif (!lines[index]?.startsWith(\"<<<<<<<\")) continue;\n\t\tlet baseSep: number | undefined, sep = -1, end = -1;\n\t\tfor (let cursor = index + 1; cursor < lines.length; cursor++) {\n\t\t\tif (lines[cursor]?.startsWith(\"|||||||\")) baseSep = cursor;\n\t\t\telse if (lines[cursor]?.startsWith(\"=======\")) sep = cursor;\n\t\t\telse if (lines[cursor]?.startsWith(\">>>>>>>\")) { end = cursor; break; }\n\t\t}\n\t\tif (sep < 0 || end < 0) continue;\n\t\tblocks.push({\n\t\t\tfile,\n\t\t\tstart: index,\n\t\t\tsep,\n\t\t\tend,\n\t\t\tbaseSep,\n\t\t\tours: lines.slice(index + 1, baseSep ?? sep),\n\t\t\tbase: baseSep === undefined ? [] : lines.slice(baseSep + 1, sep),\n\t\t\ttheirs: lines.slice(sep + 1, end),\n\t\t});\n\t\tindex = end;\n\t}\n\treturn blocks;\n}\n\nexport function registerConflictBlocks(cwd: string, blocks: ConflictBlock[]): void {\n\tconflictRegistry.set(cwd, blocks);\n}\n\n/** All conflict blocks a prior `read …:conflicts` registered for this cwd, in read order. */\nexport function getRegisteredConflictBlocks(cwd: string): ConflictBlock[] {\n\treturn conflictRegistry.get(cwd) ?? [];\n}\n\nexport function getRegisteredConflictBlock(cwd: string, id: number): ConflictBlock | undefined {\n\treturn conflictRegistry.get(cwd)?.[id - 1];\n}\n"]}
1
+ {"version":3,"file":"conflict-registry.d.ts","sourceRoot":"","sources":["../../../src/core/tools/conflict-registry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;CACf;AAID,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAwB/E;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAEjF;AAED,6FAA6F;AAC7F,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,EAAE,CAExE;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE7F"}
@@ -1 +1 @@
1
- {"version":3,"file":"directory-tree.d.ts","sourceRoot":"","sources":["../../../src/core/tools/directory-tree.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACnB;AAaD,UAAU,oBAAoB;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AA+DD,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAO3H","sourcesContent":["import { readdir, stat } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { formatSize } from \"./truncate.ts\";\n\nexport interface DirectoryTreeResult {\n\trendered: string;\n\ttruncated: boolean;\n\ttotalLines: number;\n}\n\ninterface TreeNode {\n\tname: string;\n\tpath: string;\n\tisDir: boolean;\n\tmtimeMs: number;\n\tsize: number;\n\tdepth: number;\n\tchildren: TreeNode[];\n\tdroppedCount: number;\n}\n\ninterface DirectoryTreeOptions {\n\tmaxDepth?: number;\n\tperDirLimit?: number | null;\n\trootLimit?: number | null;\n}\n\nfunction formatAge(ageSeconds: number): string {\n\tif (ageSeconds < 60) return `${ageSeconds}s`;\n\tconst minutes = Math.floor(ageSeconds / 60);\n\tif (minutes < 60) return `${minutes}m`;\n\tconst hours = Math.floor(minutes / 60);\n\tif (hours < 24) return `${hours}h`;\n\tconst days = Math.floor(hours / 24);\n\tif (days < 30) return `${days}d`;\n\tconst months = Math.floor(days / 30);\n\tif (months < 12) return `${months}mo`;\n\treturn `${Math.floor(months / 12)}y`;\n}\n\nfunction shouldSkipDirectory(name: string): boolean { return name === \".git\" || name === \"node_modules\"; }\n\nfunction byRecency(a: TreeNode, b: TreeNode): number {\n\treturn b.mtimeMs - a.mtimeMs || a.name.localeCompare(b.name);\n}\n\nasync function buildNode(fullPath: string, name: string, depth: number, maxDepth: number): Promise<TreeNode | undefined> {\n\tconst info = await stat(fullPath).catch(() => undefined);\n\tif (!info) return undefined;\n\tconst node: TreeNode = { name, path: fullPath, isDir: info.isDirectory(), mtimeMs: info.mtimeMs, size: info.size, depth, children: [], droppedCount: 0 };\n\tif (!node.isDir || depth >= maxDepth) return node;\n\tconst entries = (await readdir(fullPath, { withFileTypes: true }).catch(() => [])).filter((entry) => !entry.isDirectory() || !shouldSkipDirectory(entry.name));\n\tconst children = await Promise.all(entries.map((entry) => buildNode(resolve(fullPath, entry.name), entry.name, depth + 1, maxDepth)));\n\tnode.children = children.filter((child): child is TreeNode => child !== undefined).sort(byRecency);\n\treturn node;\n}\n\nfunction applyChildLimit(node: TreeNode, perDirLimit: number | null, rootLimit: number | null): boolean {\n\tlet truncated = false;\n\tconst limit = node.depth === 0 ? rootLimit : perDirLimit;\n\tif (limit !== null && node.children.length > limit) {\n\t\tconst originalCount = node.children.length;\n\t\tnode.children = limit <= 1 ? node.children.slice(0, Math.max(0, limit)) : [...node.children.slice(0, limit - 1), node.children.at(-1)!];\n\t\tnode.droppedCount = originalCount - node.children.length;\n\t\ttruncated = true;\n\t}\n\tfor (const child of node.children) if (child.isDir) truncated = applyChildLimit(child, perDirLimit, rootLimit) || truncated;\n\treturn truncated;\n}\n\nfunction renderNode(node: TreeNode, now: number, out: string[]): void {\n\tif (node.depth === 0) out.push(\".\");\n\telse {\n\t\tconst indent = \" \".repeat(node.depth);\n\t\tconst suffix = node.isDir ? \"/\" : \"\";\n\t\tconst meta = node.isDir ? \"\" : ` ${formatSize(node.size).padEnd(8)} ${formatAge(Math.max(0, Math.floor((now - node.mtimeMs) / 1000)))}`;\n\t\tout.push(`${indent}- ${node.name}${suffix}${meta}`.trimEnd());\n\t}\n\tif (node.droppedCount === 0) {\n\t\tfor (const child of node.children) renderNode(child, now, out);\n\t\treturn;\n\t}\n\tconst recent = node.children.slice(0, -1), oldest = node.children.at(-1);\n\tfor (const child of recent) renderNode(child, now, out);\n\tout.push(`${\" \".repeat(node.depth + 1)}- … ${node.droppedCount} more`);\n\tif (oldest) renderNode(oldest, now, out);\n}\n\nexport async function buildDirectoryTree(rootPath: string, options: DirectoryTreeOptions = {}): Promise<DirectoryTreeResult> {\n\tconst root = await buildNode(rootPath, \".\", 0, options.maxDepth ?? 2);\n\tif (!root || root.children.length === 0) return { rendered: \"(empty directory)\", truncated: false, totalLines: 1 };\n\tconst truncated = applyChildLimit(root, options.perDirLimit ?? 12, options.rootLimit === undefined ? null : options.rootLimit);\n\tconst lines: string[] = [];\n\trenderNode(root, Date.now(), lines);\n\treturn { rendered: lines.join(\"\\n\"), truncated, totalLines: lines.length };\n}\n"]}
1
+ {"version":3,"file":"directory-tree.d.ts","sourceRoot":"","sources":["../../../src/core/tools/directory-tree.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACnB;AAaD,UAAU,oBAAoB;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AA+DD,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAO3H"}
@@ -1 +1 @@
1
- {"version":3,"file":"edit-diff-preserve.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit-diff-preserve.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CAChB;AA0CD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,EAAE,MAAM,SAAI,GAAG,MAAM,CAStG;AAED;;;;;;;;;GASG;AACH,wBAAgB,yCAAyC,CACxD,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,eAAe,EAAE,GAC7B,MAAM,CAqCR","sourcesContent":["interface LineSpan {\n\tstart: number;\n\tend: number;\n}\n\nexport interface TextReplacement {\n\tmatchIndex: number;\n\tmatchLength: number;\n\tnewText: string;\n}\n\nfunction splitLinesWithEndings(content: string): string[] {\n\treturn content.match(/[^\\n]*\\n|[^\\n]+/g) ?? [];\n}\n\nfunction getLineSpans(content: string): LineSpan[] {\n\tlet offset = 0;\n\treturn splitLinesWithEndings(content).map((line) => {\n\t\tconst span = { start: offset, end: offset + line.length };\n\t\toffset = span.end;\n\t\treturn span;\n\t});\n}\n\nfunction getReplacementLineRange(lines: LineSpan[], replacement: TextReplacement) {\n\tconst replacementStart = replacement.matchIndex;\n\tconst replacementEnd = replacement.matchIndex + replacement.matchLength;\n\n\tlet startLine = -1;\n\tfor (let i = 0; i < lines.length; i++) {\n\t\tconst line = lines[i];\n\t\tif (replacementStart >= line.start && replacementStart < line.end) {\n\t\t\tstartLine = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (startLine === -1) {\n\t\tthrow new Error(\"Replacement range is outside the base content.\");\n\t}\n\n\tlet endLine = startLine;\n\twhile (endLine < lines.length && lines[endLine].end < replacementEnd) {\n\t\tendLine++;\n\t}\n\tif (endLine >= lines.length) {\n\t\tthrow new Error(\"Replacement range is outside the base content.\");\n\t}\n\n\treturn { startLine, endLine: endLine + 1 };\n}\n\nexport function applyReplacements(content: string, replacements: TextReplacement[], offset = 0): string {\n\tlet result = content;\n\tfor (let i = replacements.length - 1; i >= 0; i--) {\n\t\tconst replacement = replacements[i];\n\t\tconst matchIndex = replacement.matchIndex - offset;\n\t\tresult =\n\t\t\tresult.substring(0, matchIndex) + replacement.newText + result.substring(matchIndex + replacement.matchLength);\n\t}\n\treturn result;\n}\n\n/**\n * Apply replacements matched against `baseContent` to `originalContent` while\n * preserving unchanged line blocks from the original.\n *\n * This is useful when `baseContent` is a normalized view of the original. Each\n * replacement is widened to the lines it actually touches, those touched lines\n * are rewritten from the normalized base, and all other lines are copied back\n * from `originalContent`. The actual replacement ranges drive preservation so\n * duplicate normalized lines cannot be aligned to the wrong occurrence.\n */\nexport function applyReplacementsPreservingUnchangedLines(\n\toriginalContent: string,\n\tbaseContent: string,\n\treplacements: TextReplacement[],\n): string {\n\tconst originalLines = splitLinesWithEndings(originalContent);\n\tconst baseLines = getLineSpans(baseContent);\n\tif (originalLines.length !== baseLines.length) {\n\t\tthrow new Error(\"Cannot preserve unchanged lines because the base content has a different line count.\");\n\t}\n\n\tconst groups: Array<{ startLine: number; endLine: number; replacements: TextReplacement[] }> = [];\n\tconst sortedReplacements = [...replacements].sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (const replacement of sortedReplacements) {\n\t\tconst range = getReplacementLineRange(baseLines, replacement);\n\t\tconst current = groups[groups.length - 1];\n\t\tif (current && range.startLine < current.endLine) {\n\t\t\tcurrent.endLine = Math.max(current.endLine, range.endLine);\n\t\t\tcurrent.replacements.push(replacement);\n\t\t\tcontinue;\n\t\t}\n\t\tgroups.push({ ...range, replacements: [replacement] });\n\t}\n\n\tlet originalLineIndex = 0;\n\tlet result = \"\";\n\tfor (const group of groups) {\n\t\tresult += originalLines.slice(originalLineIndex, group.startLine).join(\"\");\n\n\t\tconst groupStartOffset = baseLines[group.startLine].start;\n\t\tconst groupEndOffset = baseLines[group.endLine - 1].end;\n\t\tresult += applyReplacements(\n\t\t\tbaseContent.slice(groupStartOffset, groupEndOffset),\n\t\t\tgroup.replacements,\n\t\t\tgroupStartOffset,\n\t\t);\n\t\toriginalLineIndex = group.endLine;\n\t}\n\tresult += originalLines.slice(originalLineIndex).join(\"\");\n\n\treturn result;\n}\n"]}
1
+ {"version":3,"file":"edit-diff-preserve.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit-diff-preserve.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CAChB;AA0CD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,EAAE,MAAM,SAAI,GAAG,MAAM,CAStG;AAED;;;;;;;;;GASG;AACH,wBAAgB,yCAAyC,CACxD,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,eAAe,EAAE,GAC7B,MAAM,CAqCR"}
@@ -1 +1 @@
1
- {"version":3,"file":"edit-diff.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM/D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB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,YAAY,SAAI,GACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAuHxD;AAED,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACrC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,IAAI,EAAE,EACb,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CAyBzC;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CAEzC","sourcesContent":["/**\n * Shared diff computation utilities for the edit and similar tools.\n */\n\nimport * as Diff from \"diff\";\nimport { constants } from \"fs\";\nimport { access, readFile } from \"fs/promises\";\nimport {\n\tapplyReplacements,\n\tapplyReplacementsPreservingUnchangedLines,\n\ttype TextReplacement,\n} from \"./edit-diff-preserve.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\n\nexport function detectLineEnding(content: string): \"\\r\\n\" | \"\\n\" {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: \"\\r\\n\" | \"\\n\"): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching. Applies progressive transformations:\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn (\n\t\ttext\n\t\t\t.normalize(\"NFKC\")\n\t\t\t// Strip trailing whitespace per line\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trimEnd())\n\t\t\t.join(\"\\n\")\n\t\t\t// Smart single quotes → '\n\t\t\t.replace(/[\\u2018\\u2019\\u201A\\u201B]/g, \"'\")\n\t\t\t// Smart double quotes → \"\n\t\t\t.replace(/[\\u201C\\u201D\\u201E\\u201F]/g, '\"')\n\t\t\t// Various dashes/hyphens → -\n\t\t\t// U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,\n\t\t\t// U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus\n\t\t\t.replace(/[\\u2010\\u2011\\u2012\\u2013\\u2014\\u2015\\u2212]/g, \"-\")\n\t\t\t// Special spaces → regular space\n\t\t\t// U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,\n\t\t\t// U+205F medium math space, U+3000 ideographic space\n\t\t\t.replace(/[\\u00A0\\u2002-\\u200A\\u202F\\u205F\\u3000]/g, \" \")\n\t);\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/**\n\t * The content to use for replacement operations.\n\t * When exact match: original content. When fuzzy match: normalized content.\n\t */\n\tcontentForReplacement: string;\n}\n\nexport interface Edit {\n\toldText: string;\n\tnewText: string;\n}\n\ninterface MatchedEdit extends TextReplacement {\n\teditIndex: number;\n}\n\nexport interface AppliedEditsResult {\n\tbaseContent: string;\n\tnewContent: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n * When fuzzy matching is used, the returned contentForReplacement is the\n * fuzzy-normalized version of the content (trailing whitespace stripped,\n * Unicode quotes/dashes normalized to ASCII).\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\t// Try exact match first\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// Try fuzzy match - work entirely in normalized space\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// When fuzzy matching, return offsets in normalized space. Callers can use\n\t// the normalized content to compute replacements, then decide how much of\n\t// that normalized output should be written back.\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: fuzzyOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: fuzzyContent,\n\t};\n}\n\n/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */\nexport function stripBom(content: string): { bom: string; text: string } {\n\treturn content.startsWith(\"\\uFEFF\") ? { bom: \"\\uFEFF\", text: content.slice(1) } : { bom: \"\", text: content };\n}\n\nfunction countOccurrences(content: string, oldText: string): number {\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\treturn fuzzyContent.split(fuzzyOldText).length - 1;\n}\n\nfunction getNotFoundError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Could not find edits[${editIndex}] in ${path}. The oldText must match exactly including all whitespace and newlines.`,\n\t);\n}\n\nfunction getDuplicateError(path: string, editIndex: number, totalEdits: number, occurrences: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Found ${occurrences} occurrences of edits[${editIndex}] in ${path}. Each oldText must be unique. Please provide more context to make it unique.`,\n\t);\n}\n\nfunction getEmptyOldTextError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(`oldText must not be empty in ${path}.`);\n\t}\n\treturn new Error(`edits[${editIndex}].oldText must not be empty in ${path}.`);\n}\n\nfunction getNoChangeError(path: string, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`No changes made to ${path}. The replacement produced identical content. This might indicate an issue with special characters or the text not existing as expected.`,\n\t\t);\n\t}\n\treturn new Error(`No changes made to ${path}. The replacements produced identical content.`);\n}\n\n/**\n * Apply one or more exact-text replacements to LF-normalized content.\n *\n * All edits are matched against the same original content. Replacements are\n * then applied in reverse order so offsets remain stable. If any edit needs\n * fuzzy matching, the operation runs in fuzzy-normalized content space and then\n * overlays those line-level changes onto the original content so unchanged line\n * blocks keep their original bytes.\n */\nexport function applyEditsToNormalizedContent(\n\tnormalizedContent: string,\n\tedits: Edit[],\n\tpath: string,\n): AppliedEditsResult {\n\tconst normalizedEdits = edits.map((edit) => ({\n\t\toldText: normalizeToLF(edit.oldText),\n\t\tnewText: normalizeToLF(edit.newText),\n\t}));\n\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tif (normalizedEdits[i].oldText.length === 0) {\n\t\t\tthrow getEmptyOldTextError(path, i, normalizedEdits.length);\n\t\t}\n\t}\n\n\tconst initialMatches = normalizedEdits.map((edit) => fuzzyFindText(normalizedContent, edit.oldText));\n\tconst usedFuzzyMatch = initialMatches.some((match) => match.usedFuzzyMatch);\n\tconst replacementBaseContent = usedFuzzyMatch ? normalizeForFuzzyMatch(normalizedContent) : normalizedContent;\n\n\tconst matchedEdits: MatchedEdit[] = [];\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tconst edit = normalizedEdits[i];\n\t\tconst matchResult = fuzzyFindText(replacementBaseContent, edit.oldText);\n\t\tif (!matchResult.found) {\n\t\t\tthrow getNotFoundError(path, i, normalizedEdits.length);\n\t\t}\n\n\t\tconst occurrences = countOccurrences(replacementBaseContent, edit.oldText);\n\t\tif (occurrences > 1) {\n\t\t\tthrow getDuplicateError(path, i, normalizedEdits.length, occurrences);\n\t\t}\n\n\t\tmatchedEdits.push({\n\t\t\teditIndex: i,\n\t\t\tmatchIndex: matchResult.index,\n\t\t\tmatchLength: matchResult.matchLength,\n\t\t\tnewText: edit.newText,\n\t\t});\n\t}\n\n\tmatchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (let i = 1; i < matchedEdits.length; i++) {\n\t\tconst previous = matchedEdits[i - 1];\n\t\tconst current = matchedEdits[i];\n\t\tif (previous.matchIndex + previous.matchLength > current.matchIndex) {\n\t\t\tthrow new Error(\n\t\t\t\t`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst baseContent = normalizedContent;\n\tconst newContent = usedFuzzyMatch\n\t\t? applyReplacementsPreservingUnchangedLines(normalizedContent, replacementBaseContent, matchedEdits)\n\t\t: applyReplacements(replacementBaseContent, matchedEdits);\n\n\tif (baseContent === newContent) {\n\t\tthrow getNoChangeError(path, normalizedEdits.length);\n\t}\n\n\treturn { baseContent, newContent };\n}\n\n/** Generate a standard unified patch. */\nexport function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines = 4): string {\n\treturn Diff.createTwoFilesPatch(path, path, oldContent, newContent, undefined, undefined, {\n\t\tcontext: contextLines,\n\t\theaderOptions: Diff.FILE_HEADERS_ONLY,\n\t});\n}\n\n/**\n * Generate a display-oriented diff string with line numbers and context.\n * Returns both the diff string and the first changed line number (in the new file).\n */\nexport function generateDiffString(\n\toldContent: string,\n\tnewContent: string,\n\tcontextLines = 4,\n): { diff: string; firstChangedLine: number | undefined } {\n\tconst parts = Diff.diffLines(oldContent, newContent);\n\tconst output: string[] = [];\n\n\tconst oldLines = oldContent.split(\"\\n\");\n\tconst newLines = newContent.split(\"\\n\");\n\tconst maxLineNum = Math.max(oldLines.length, newLines.length);\n\tconst lineNumWidth = String(maxLineNum).length;\n\n\tlet oldLineNum = 1;\n\tlet newLineNum = 1;\n\tlet lastWasChange = false;\n\tlet firstChangedLine: number | undefined;\n\n\tfor (let i = 0; i < parts.length; i++) {\n\t\tconst part = parts[i];\n\t\tconst raw = part.value.split(\"\\n\");\n\t\tif (raw[raw.length - 1] === \"\") {\n\t\t\traw.pop();\n\t\t}\n\n\t\tif (part.added || part.removed) {\n\t\t\t// Capture the first changed line (in the new file)\n\t\t\tif (firstChangedLine === undefined) {\n\t\t\t\tfirstChangedLine = newLineNum;\n\t\t\t}\n\n\t\t\t// Show the change\n\t\t\tfor (const line of raw) {\n\t\t\t\tif (part.added) {\n\t\t\t\t\tconst lineNum = String(newLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`+${lineNum} ${line}`);\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t} else {\n\t\t\t\t\t// removed\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`-${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlastWasChange = true;\n\t\t} else {\n\t\t\t// Context lines - only show a few before/after changes\n\t\t\tconst nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);\n\t\t\tconst hasLeadingChange = lastWasChange;\n\t\t\tconst hasTrailingChange = nextPartIsChange;\n\n\t\t\tif (hasLeadingChange && hasTrailingChange) {\n\t\t\t\tif (raw.length <= contextLines * 2) {\n\t\t\t\t\tfor (const line of raw) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst leadingLines = raw.slice(0, contextLines);\n\t\t\t\t\tconst trailingLines = raw.slice(raw.length - contextLines);\n\t\t\t\t\tconst skippedLines = raw.length - leadingLines.length - trailingLines.length;\n\n\t\t\t\t\tfor (const line of leadingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\n\t\t\t\t\tfor (const line of trailingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (hasLeadingChange) {\n\t\t\t\tconst shownLines = raw.slice(0, contextLines);\n\t\t\t\tconst skippedLines = raw.length - shownLines.length;\n\n\t\t\t\tfor (const line of shownLines) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\t\t\t} else if (hasTrailingChange) {\n\t\t\t\tconst skippedLines = Math.max(0, raw.length - contextLines);\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\n\t\t\t\tfor (const line of raw.slice(skippedLines)) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Skip these context lines entirely\n\t\t\t\toldLineNum += raw.length;\n\t\t\t\tnewLineNum += raw.length;\n\t\t\t}\n\n\t\t\tlastWasChange = false;\n\t\t}\n\t}\n\n\treturn { diff: output.join(\"\\n\"), firstChangedLine };\n}\n\nexport interface EditDiffResult {\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nexport interface EditDiffError {\n\terror: string;\n}\n\n/**\n * Compute the diff for one or more edit operations without applying them.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeEditsDiff(\n\tpath: string,\n\tedits: Edit[],\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, cwd);\n\n\ttry {\n\t\t// Check if file exists and is readable\n\t\ttry {\n\t\t\tawait access(absolutePath, constants.R_OK);\n\t\t} catch (error: unknown) {\n\t\t\tconst errorMessage = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\treturn { error: `Could not edit file: ${path}. ${errorMessage}.` };\n\t\t}\n\n\t\t// Read the file\n\t\tconst rawContent = await readFile(absolutePath, \"utf-8\");\n\n\t\t// Strip BOM before matching (LLM won't include invisible BOM in oldText)\n\t\tconst { text: content } = stripBom(rawContent);\n\t\tconst normalizedContent = normalizeToLF(content);\n\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\n\t\t// Generate the diff\n\t\treturn generateDiffString(baseContent, newContent);\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n\n/**\n * Compute the diff for a single edit operation without applying it.\n * Kept as a convenience wrapper for single-edit callers.\n */\nexport async function computeEditDiff(\n\tpath: string,\n\toldText: string,\n\tnewText: string,\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\treturn computeEditsDiff(path, [{ oldText, newText }], cwd);\n}\n"]}
1
+ {"version":3,"file":"edit-diff.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM/D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAE9E;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqB3D;AAED,MAAM,WAAW,gBAAgB;IAChC,gCAAgC;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,4FAA4F;IAC5F,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,4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;AAwGD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAoE/I;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { Filesystem, Patch, Patcher, type PatchSectionResult, type PreparedSection, type WriteResult } from \"./hashline-engine/index.ts\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { generateDiffString, generateUnifiedPatch, normalizeToLF, stripBom } from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { createHashlineSnapshotStore, formatCompactHashlineEditResult, recordHashlineSnapshot, type HashlineSnapshotStore } from \"./hashline.ts\";\nimport { invalidateNativeSearchCache } from \"./search-native.ts\";\nimport { isNotebookPath, readEditableNotebookText, serializeEditedNotebookText } from \"./notebook.ts\";\nimport { nativeBlockResolver } from \"./block-resolver.ts\";\nimport { resolveReadPath } from \"./path-utils.ts\";\nimport { renderToolPath } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst editSchema = Type.Object(\n\t{ input: Type.String({ description: \"One or more hashline file sections. Must start with [PATH#TAG]; tag comes from the latest read, search, write, or successful edit output.\" }) },\n\t{ additionalProperties: false },\n);\n\nexport type EditToolInput = Static<typeof editSchema>;\n\nexport interface EditToolDetails {\n\tdiff: string;\n\tpatch: string;\n\tfirstChangedLine?: number;\n}\n\nexport interface EditOperations {\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\toperations?: EditOperations;\n\thashlineStore?: HashlineSnapshotStore;\n}\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\nclass EditFilesystem extends Filesystem {\n\tprivate readonly cwd: string;\n\tprivate readonly operations: EditOperations;\n\tconstructor(cwd: string, operations: EditOperations) { super(); this.cwd = cwd; this.operations = operations; }\n\n\tcanonicalPath(path: string): string { return resolveReadPath(path, this.cwd); }\n\n\tasync preflightWrite(path: string): Promise<void> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\ttry { await this.operations.access(absolutePath); }\n\t\tcatch (error: unknown) {\n\t\t\tconst message = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\tthrow new Error(`Could not edit file: ${path}. ${message}.`);\n\t\t}\n\t}\n\n\tasync readText(path: string): Promise<string> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\treturn isNotebookPath(absolutePath) ? readEditableNotebookText(absolutePath, path) : (await this.operations.readFile(absolutePath)).toString(\"utf-8\");\n\t}\n\n\tasync writeText(path: string, content: string): Promise<WriteResult> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\tconst persisted = isNotebookPath(absolutePath) ? serializeEditedNotebookText(absolutePath, path, normalizeToLF(stripBom(content).text)) : content;\n\t\tawait this.operations.writeFile(absolutePath, persisted);\n\t\treturn { text: persisted };\n\t}\n}\n\nfunction isFourDigitHexTag(value: string): boolean {\n\treturn value.length === 4 && [...value].every((char) => (char >= \"0\" && char <= \"9\") || (char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\"));\n}\n\nfunction extractFirstHeaderPath(input: string | undefined): string | undefined {\n\tif (!input) return undefined;\n\tfor (const line of input.split(\"\\n\")) {\n\t\tconst trimmed = line.trimStart();\n\t\tif (!trimmed.startsWith(\"[\")) continue;\n\t\tconst hashIndex = trimmed.indexOf(\"#\", 1);\n\t\tconst closeIndex = hashIndex >= 0 ? trimmed.indexOf(\"]\", hashIndex + 1) : -1;\n\t\tif (hashIndex <= 1 || closeIndex !== hashIndex + 5) continue;\n\t\tconst tag = trimmed.slice(hashIndex + 1, closeIndex);\n\t\tif (isFourDigitHexTag(tag)) return trimmed.slice(1, hashIndex);\n\t}\n\treturn undefined;\n}\n\nfunction formatEditCall(args: unknown, theme: Theme, cwd: string): string {\n\tconst input = args && typeof args === \"object\" && \"input\" in args ? (args as { input?: unknown }).input : undefined;\n\tconst pathDisplay = renderToolPath(extractFirstHeaderPath(typeof input === \"string\" ? input : undefined) ?? null, theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(result: EditToolResultLike, theme: Theme, isError: boolean): string | undefined {\n\tif (isError) {\n\t\tconst errorText = result.content.filter((c) => c.type === \"text\").map((c) => c.text || \"\").join(\"\\n\");\n\t\treturn errorText ? theme.fg(\"error\", errorText) : undefined;\n\t}\n\treturn result.details?.diff ? renderDiff(result.details.diff) : undefined;\n}\n\nasync function withFileMutationQueues<T>(filePaths: readonly string[], fn: () => Promise<T>): Promise<T> {\n\tconst sorted = [...new Set(filePaths)].sort();\n\tconst run = (index: number): Promise<T> => {\n\t\tconst filePath = sorted[index];\n\t\treturn filePath ? withFileMutationQueue(filePath, () => run(index + 1)) : fn();\n\t};\n\treturn run(0);\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n}\n\nfunction formatNoopMessage(path: string, count: number): string {\n\treturn `Edits to ${path} parsed and applied cleanly, but produced no change: your body row(s) are byte-identical to the file at the targeted lines. The bug is somewhere else — re-read the file before issuing another edit. Do NOT widen the payload or add lines; verify the anchor first.${count > 1 ? `\\nNo-op count for this identical payload: ${count}.` : \"\"}`;\n}\n\nfunction blockMessages(item: PreparedSection | PatchSectionResult): string[] {\n\tconst warnings = \"parseWarnings\" in item ? [...item.parseWarnings, ...(item.applyResult.warnings ?? [])] : item.warnings;\n\tconst resolutions = (\"applyResult\" in item ? item.applyResult.blockResolutions : item.blockResolutions)?.map((resolution) => {\n\t\tconst verb = resolution.op === \"insert_after\" ? \"insert after block\" : `${resolution.op} block`;\n\t\tconst lands = resolution.op === \"insert_after\" ? `; body lands after line ${resolution.end}` : \"\";\n\t\treturn `${verb} ${resolution.anchorLine} → resolved lines ${resolution.start}-${resolution.end} (${resolution.end - resolution.start + 1} lines)${lands}`;\n\t}) ?? [];\n\treturn [...warnings, ...resolutions];\n}\n\nfunction assertUniquePreparedPaths(prepared: readonly PreparedSection[]): void {\n\tconst seen = new Map<string, string>();\n\tfor (const entry of prepared) {\n\t\tconst previous = seen.get(entry.canonicalPath);\n\t\tif (previous) throw new Error(`Multiple hashline sections resolve to the same file (${previous} and ${entry.section.path}). Merge their ops under one header before applying.`);\n\t\tseen.set(entry.canonicalPath, entry.section.path);\n\t}\n}\n\nexport function createEditToolDefinition(cwd: string, options?: EditToolOptions): ToolDefinition<typeof editSchema, EditToolDetails | undefined> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\tconst fs = new EditFilesystem(cwd, ops);\n\tconst patcher = new Patcher({ fs, snapshots: hashlineStore.snapshots, blockResolver: nativeBlockResolver });\n\tconst noopCounts = new Map<string, number>();\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription: \"Edit existing files with the hashline patch language: each section starts with [PATH#TAG] (TAG is the 4-hex snapshot tag from your latest read/search), then hunk headers (replace N..M:, replace block N:, delete N..M, delete block N, insert before|after N:, insert after block N:, insert head:, insert tail:) followed by +TEXT body rows. Numbers refer to the original file. Use the write tool to create new files.\",\n\t\tpromptSnippet: \"Apply source edits with hashline patch input\",\n\t\tpromptGuidelines: [\n\t\t\t\"hashline edit format: a header ending in ':' is followed by '+'TEXT body rows; 'delete' has no body. Every section starts with [PATH#TAG]; TAG is REQUIRED (the 4-hex snapshot tag from your latest read/search) — there is no hashless form. Use the write tool to create new files.\",\n\t\t\t\"Ops: 'replace N..M:' replaces original lines N..M (INCLUSIVE — line M is consumed); 'replace block N:' replaces the whole syntactic block that BEGINS on line N (Atomic resolves the closing line with a brace/indent heuristic; point N at the opener); 'delete N..M' / 'delete block N' delete (no body); 'insert before N:' / 'insert after N:' insert relative to a line; 'insert after block N:' inserts after the END of the block beginning on N; 'insert head:' / 'insert tail:' insert at file start/end. Single line: 'replace N..N:' / 'delete N'. The range is the ORIGINAL lines you touch; body length is irrelevant.\",\n\t\t\t\"Body rows appear only under a ':' header. Every row is '+TEXT' (adds a literal line, leading whitespace kept; '+' alone adds a blank line). There is NO other body row kind — never write '-old' or a bare/context line. To keep a line, leave it out of every range. For a literal line starting with '-' or '+', prefix it: '+-x', '++x'.\",\n\t\t\t\"Numbers refer to the ORIGINAL file and do not shift as hunks apply; they die with the call — every applied edit mints a fresh #TAG and renumbers, so anchor the next edit on the edit response or a fresh read. Ranges are TIGHT: cover ONLY lines whose content changes; a stale wide range shreds everything it spans. Pure additions use 'insert', never a widened 'replace'. Whole construct → 'replace block N'; lines inside it → 'replace N..M'.\",\n\t\t\t\"On a stale-tag rejection or any surprising result: STOP and re-read before further edits. Never start or end a range mid-expression/mid-block, and never span a hunk across an elided ('…') region — read it first. Never use edit to reformat/restyle code; run the project formatter instead.\",\n\t\t],\n\t\tparameters: editSchema,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal) {\n\t\t\tif (typeof input.input !== \"string\" || input.input.trim() === \"\") throw new Error(\"edit input must be a non-empty hashline script with [PATH#TAG] sections.\");\n\t\t\tconst patch = Patch.parse(input.input, { cwd });\n\t\t\tconst prepared: PreparedSection[] = [];\n\t\t\tfor (const section of patch.sections) { throwIfAborted(signal); prepared.push(await patcher.prepare(section)); }\n\t\t\tassertUniquePreparedPaths(prepared);\n\t\t\tconst noops = prepared.filter((item) => item.isNoop);\n\t\t\tif (noops.length > 0) {\n\t\t\t\tif (noops.length !== prepared.length) throw new Error(`Hashline edit for ${noops[0]!.section.path} did not change the file.`);\n\t\t\t\tconst key = prepared.map((item) => `${item.canonicalPath}\\0${item.applyResult.text}`).join(\"\\0\\0\");\n\t\t\t\tconst count = (noopCounts.get(key) ?? 0) + 1;\n\t\t\t\tnoopCounts.set(key, count);\n\t\t\t\tif (count >= 3) throw new Error(`STOP. ${formatNoopMessage(prepared[0]!.section.path, count)}`);\n\t\t\t\treturn { content: [{ type: \"text\", text: formatNoopMessage(prepared[0]!.section.path, count) }], details: { diff: \"\", patch: \"\" } };\n\t\t\t}\n\t\t\treturn withFileMutationQueues(prepared.map((item) => item.canonicalPath), async () => {\n\t\t\t\tfor (const item of prepared) if (normalizeToLF(stripBom(await fs.readText(item.section.path)).text) !== item.normalized) throw new Error(`Stale hashline tag for ${item.section.path}: file content changed before write. Re-read before editing.`);\n\t\t\t\tconst applyResult = await patcher.apply(patch);\n\t\t\t\tconst outputs: string[] = [];\n\t\t\t\tlet combinedDiff = \"\", combinedPatch = \"\";\n\t\t\t\tlet firstChangedLine: number | undefined;\n\t\t\t\tfor (const result of applyResult.sections) {\n\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\tinvalidateNativeSearchCache(result.canonicalPath);\n\t\t\t\t\tconst snapshot = recordHashlineSnapshot(result.canonicalPath, cwd, result.after, hashlineStore);\n\t\t\t\t\tconst diffResult = generateDiffString(result.before, result.after);\n\t\t\t\t\tcombinedDiff += `${combinedDiff ? \"\\n\" : \"\"}${diffResult.diff}`;\n\t\t\t\t\tcombinedPatch += `${combinedPatch ? \"\\n\" : \"\"}${generateUnifiedPatch(result.path, result.before, result.after)}`;\n\t\t\t\t\tfirstChangedLine ??= diffResult.firstChangedLine;\n\t\t\t\t\toutputs.push(formatCompactHashlineEditResult(snapshot, diffResult, blockMessages(result)));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputs.join(\"\\n\\n\") }], details: { diff: combinedDiff, patch: combinedPatch, firstChangedLine } };\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatEditCall(args, theme, context.cwd));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst output = formatEditResult(result as EditToolResultLike, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) return component;\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAK/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAAwF,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAQjJ,QAAA,MAAM,UAAU;;EAGf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UA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AE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;CACnB;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAoCrG;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAG9D;AAOD,MAAM,WAAW,oBAAoB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,kBAAkB,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,OAAO,CAAC;CACb;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAgB9K;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA+BlL;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAExC","sourcesContent":["/// <reference path=\"../../utils/turndown.d.ts\" />\n/**\n * URL fetch / cache / artifact / markdown-discovery pipeline, mirrored from\n * oh-my-pi's `packages/coding-agent/src/tools/fetch.ts` at 15b5c1397fc.\n *\n * Responsibilities:\n * - parseReadUrlTarget: URL + line selectors (:raw, :N, :A-B, :A+B, :A-B,C-D),\n * collapsed-scheme repair, host-port protection.\n * - session-scoped LRU cache keyed by `<scope>::<raw|rendered>::<normalizedUrl>`,\n * cached under both requested and final (redirected) URLs.\n * - renderUrl: markdown discovery (alternate <link>, .md suffix, content\n * negotiation, llms.txt/llms.md endpoints) + native HTML-to-markdown, with\n * quality gating.\n * - artifact persistence of the rendered output, with artifactId surfaced in\n * truncation metadata when the visible output is head-truncated.\n */\nimport { lookup } from \"node:dns/promises\";\nimport { ipFamily, isPrivateIpAddress, normalizeIpLiteralHost } from \"./url-ip-guards.ts\";\nimport { LRUCache } from \"lru-cache\";\nimport TurndownService from \"turndown\";\nimport { Agent, request as undiciRequest, type Dispatcher } from \"undici\";\nimport { getArtifactManager } from \"./artifacts.ts\";\nimport { extractDocumentMarkdown, isDocumentPath } from \"./read-document-extract.ts\";\nimport type { TruncationResult } from \"./truncate.ts\";\n\nexport const FETCH_DEFAULT_MAX_LINES = 300;\nexport const READ_URL_CACHE_MAX_ENTRIES = 100;\nconst REMOTE_FETCH_TIMEOUT_MS = 10_000;\nconst MAX_URL_REDIRECTS = 5;\nconst MAX_URL_RESPONSE_BYTES = 10 * 1024 * 1024;\nconst MIN_CONTENT_LENGTH = 100;\n\nexport interface LineRange { start: number; end?: number }\n\nexport interface ParsedReadUrlTarget {\n\turl: string;\n\traw: boolean;\n\toffset?: number;\n\tlimit?: number;\n\tranges?: readonly LineRange[];\n}\n\nexport interface ReadUrlToolDetails {\n\turl: string;\n\tfinalUrl: string;\n\tcontentType: string;\n\tmethod: string;\n\ttruncated: boolean;\n\tnotes: string[];\n\tmeta?: { artifactId?: string; truncation?: TruncationResult };\n}\n\ninterface ReadUrlCacheEntry {\n\tartifactId?: string;\n\tdetails: ReadUrlToolDetails;\n\toutput: string;\n}\n\nexport interface LoadedPage {\n\tok: boolean;\n\tstatus: number;\n\tcontent: string;\n\tcontentType: string;\n\tfinalUrl: string;\n}\n\nconst readUrlCache = new LRUCache<string, ReadUrlCacheEntry>({ max: READ_URL_CACHE_MAX_ENTRIES });\nlet turndown: TurndownService | undefined;\nfunction getTurndown(): TurndownService {\n\tif (!turndown) turndown = new TurndownService({ headingStyle: \"atx\", codeBlockStyle: \"fenced\", bulletListMarker: \"-\" });\n\treturn turndown;\n}\n\nexport function repairCollapsedScheme(url: string): string {\n\treturn url.replace(/^(https?):\\/([^/])/i, \"$1://$2\");\n}\n\nexport function isReadableUrlPath(readPath: string): boolean {\n\tconst repaired = repairCollapsedScheme(readPath);\n\treturn /^https?:\\/\\//i.test(repaired) || /^www\\./i.test(readPath);\n}\n\nfunction normalizeUrlForCache(url: string): string {\n\tconst repaired = repairCollapsedScheme(url);\n\tif (/^[a-z][a-z0-9+.-]*:\\/\\//i.test(repaired)) return repaired;\n\treturn /^https?:\\/\\//i.test(repaired) ? repaired : `https://${repaired}`;\n}\nconst RANGE_TOKEN_RE = /^(raw|\\d+(?:\\+(?:\\d+)|(?:-|\\.\\.)\\d+)?)$/i;\nconst MULTI_RANGE_RE = /^\\d+(?:(?:-|\\.\\.|,|\\+)\\d+)*$/;\n\nfunction isUrlSelectorToken(token: string): boolean {\n\treturn /^raw$/i.test(token) || RANGE_TOKEN_RE.test(token) || MULTI_RANGE_RE.test(token);\n}\n\nfunction parseSingleRange(token: string): LineRange | undefined {\n\tconst plus = token.match(/^(\\d+)\\+(\\d+)$/);\n\tif (plus) {\n\t\tconst start = Number.parseInt(plus[1]!, 10), count = Number.parseInt(plus[2]!, 10);\n\t\treturn start < 1 || count < 1 ? undefined : { start, end: start + count - 1 };\n\t}\n\tconst range = token.match(/^(\\d+)(?:-|\\.\\.)(\\d+)$/);\n\tif (range) { const start = Number.parseInt(range[1]!, 10); const end = Number.parseInt(range[2]!, 10); return start < 1 || end < start ? undefined : { start, end }; }\n\tconst single = token.match(/^(\\d+)$/);\n\tif (single) { const start = Number.parseInt(single[1]!, 10); return start < 1 ? undefined : { start }; }\n\treturn undefined;\n}\n\nfunction parseRangeGroup(token: string): LineRange[] | undefined {\n\tconst groups = token.split(\",\");\n\tconst ranges: LineRange[] = [];\n\tfor (const group of groups) { const r = parseSingleRange(group); if (!r) return undefined; ranges.push(r); }\n\treturn ranges;\n}\n\nfunction tryExtractEmbeddedUrlSelector(readPath: string): { path: string; sels: string[] } | null {\n\tlet basePath = readPath;\n\tconst sels: string[] = [];\n\tfor (;;) {\n\t\tconst lastColonIndex = basePath.lastIndexOf(\":\");\n\t\tif (lastColonIndex <= 0) break;\n\t\tconst candidate = basePath.slice(lastColonIndex + 1);\n\t\tconst remainder = basePath.slice(0, lastColonIndex);\n\t\tif (!isReadableUrlPath(remainder) || !isUrlSelectorToken(candidate)) break;\n\t\ttry { new URL(remainder.startsWith(\"http://\") || remainder.startsWith(\"https://\") ? remainder : `https://${remainder}`); } catch { break; }\n\t\tsels.unshift(candidate);\n\t\tbasePath = remainder;\n\t}\n\treturn sels.length === 0 ? null : { path: basePath, sels };\n}\n\nexport function parseReadUrlTarget(readPath: string): ParsedReadUrlTarget | null {\n\tconst repaired = repairCollapsedScheme(readPath);\n\tconst embedded = tryExtractEmbeddedUrlSelector(repaired);\n\tconst urlPath = embedded?.path ?? repaired;\n\tif (!isReadableUrlPath(urlPath)) return null;\n\tlet raw = false;\n\tlet ranges: LineRange[] | undefined;\n\tfor (const sel of embedded?.sels ?? []) {\n\t\tif (/^raw$/i.test(sel)) { raw = true; continue; }\n\t\tif (ranges !== undefined) throw new Error(\"URL selector has multiple range groups; combine them with commas (e.g. `:5-10,20-30`).\");\n\t\tconst parsed = parseRangeGroup(sel);\n\t\tif (!parsed) throw new Error(`Invalid URL line selector: ${sel}`);\n\t\tranges = parsed;\n\t}\n\tif (!ranges || ranges.length === 0) return { url: urlPath, raw };\n\tif (ranges.length === 1) {\n\t\tconst r = ranges[0]!;\n\t\treturn { url: urlPath, raw, offset: r.start, limit: r.end !== undefined ? r.end - r.start + 1 : undefined };\n\t}\n\treturn { url: urlPath, raw, ranges };\n}\n\nexport function getReadUrlCacheKey(scope: string, requestedUrl: string, raw: boolean): string {\n\treturn `${scope}::${raw ? \"raw\" : \"rendered\"}::${normalizeUrlForCache(requestedUrl)}`;\n}\n\nfunction looksLikeHtml(text: string): boolean {\n\treturn /<html[\\s>]/i.test(text) || (/<head[\\s>]/i.test(text) && /<body[\\s>]/i.test(text));\n}\n\nfunction documentExtensionFromContentType(contentType: string): string | undefined {\n\tif (/pdf/i.test(contentType)) return \".pdf\";\n\tif (/msword/i.test(contentType)) return \".doc\";\n\tif (/wordprocessingml|officedocument\\.word/i.test(contentType)) return \".docx\";\n\tif (/presentationml|officedocument\\.presentation/i.test(contentType)) return \".pptx\";\n\tif (/ms-powerpoint|vnd\\.ms-powerpoint/i.test(contentType)) return \".ppt\";\n\tif (/spreadsheetml|officedocument\\.spreadsheet/i.test(contentType)) return \".xlsx\";\n\tif (/ms-excel|vnd\\.ms-excel/i.test(contentType)) return \".xls\";\n\tif (/epub/i.test(contentType)) return \".epub\";\n\tif (/\\bjson\\b|ipynb|jupyter/i.test(contentType)) return \".ipynb\";\n\tif (/rtf/i.test(contentType)) return \".rtf\";\n\treturn undefined;\n}\n\ninterface SafeFetchAddress { address: string; family: 4 | 6; /** True only when the address came from DNS resolution and must be pinned to prevent rebinding at connect time. */ pinned: boolean }\ntype LookupCallback = (error: NodeJS.ErrnoException | null, address: string | SafeFetchAddress[], family?: number) => void;\n\nfunction createPinnedDispatcher(pinned: SafeFetchAddress): Agent {\n\treturn new Agent({ connect: { lookup: (_hostname: string, options: { all?: boolean }, callback: LookupCallback) => { if (options.all) callback(null, [pinned]); else callback(null, pinned.address, pinned.family); } } });\n}\n\nasync function closePinnedDispatcher(dispatcher: Agent | undefined): Promise<void> {\n\tconst close = (dispatcher as { close?: () => Promise<void> | void } | undefined)?.close;\n\tif (typeof close === \"function\") await close.call(dispatcher);\n}\n/**\n * Fetch a URL through undici with the pinned dispatcher so the validated\n * address is the one actually connected to. Unlike `globalThis.fetch`, which\n * silently ignores the undici `dispatcher` option under Bun's compiled binary\n * (reopening a DNS-rebinding TOCTOU window for hostname targets), undici's own\n * client honors the dispatcher's custom `lookup` regardless of host runtime.\n * Adapts the undici response to the WHATWG-Response shape loadPage consumes.\n */\nasync function pinnedFetch(url: string, dispatcher: Dispatcher, options: { signal: AbortSignal; headers?: Record<string, string> }): Promise<Response> {\n\tconst result = await undiciRequest(url, { method: \"GET\", dispatcher, signal: options.signal, headers: options.headers });\n\tconst body = result.body;\n\tconst status = result.statusCode;\n\tconst headers = new Headers();\n\tfor (const [key, value] of Object.entries(result.headers as Record<string, string | string[] | undefined>)) {\n\t\tif (value === undefined) continue;\n\t\tconst values = Array.isArray(value) ? value : [value];\n\t\tfor (const entry of values) headers.append(key, entry);\n\t}\n\tconst stream = new ReadableStream({\n\t\tstart(controller) { body.on(\"data\", (chunk: Buffer) => controller.enqueue(new Uint8Array(chunk))); body.on(\"end\", () => controller.close()); body.on(\"error\", (error: unknown) => controller.error(error)); },\n\t\tcancel() { body.destroy(); },\n\t});\n\treturn new Response(stream, { status, headers });\n}\n\n\nasync function assertSafeFetchUrl(url: string): Promise<SafeFetchAddress | undefined> {\n\tconst parsed = new URL(url);\n\tif (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") throw new Error(`Unsupported URL protocol: ${parsed.protocol}`);\n\tif (process.env.ATOMIC_ALLOW_PRIVATE_URL_READS === \"1\") return undefined;\n\tconst hostname = parsed.hostname.replace(/^\\[|\\]$/g, \"\").replace(/\\.$/, \"\").toLowerCase();\n\tif (hostname === \"localhost\" || hostname.endsWith(\".localhost\") || hostname === \"metadata.google.internal\") throw new Error(`Refusing to fetch private or metadata URL: ${url}`);\n\tconst literalAddress = normalizeIpLiteralHost(hostname);\n\tif (literalAddress) { if (isPrivateIpAddress(literalAddress)) throw new Error(`Refusing to fetch private or metadata URL: ${url}`); return { address: literalAddress, family: ipFamily(literalAddress), pinned: false }; }\n\tconst addresses = await lookup(hostname, { all: true }).catch((error: unknown) => { throw new Error(`Could not resolve URL host ${hostname}: ${error instanceof Error ? error.message : String(error)}`); });\n\tif (addresses.length === 0) throw new Error(`Could not resolve URL host ${hostname}: no addresses returned`);\n\tfor (const address of addresses) if (isPrivateIpAddress(address.address)) throw new Error(`Refusing to fetch private or metadata URL: ${url}`);\n\tconst first = addresses[0]!;\n\treturn { address: first.address, family: first.family === 6 ? 6 : 4, pinned: true };\n}\n\nasync function readResponseTextWithLimit(response: Response): Promise<string> {\n\tif (!response.body) { const buffer = Buffer.from(await response.arrayBuffer()); if (buffer.length > MAX_URL_RESPONSE_BYTES) throw new Error(`URL response exceeds ${MAX_URL_RESPONSE_BYTES} byte limit`); return buffer.toString(\"utf8\"); }\n\tconst reader = response.body.getReader();\n\tconst decoder = new TextDecoder();\n\tconst chunks: string[] = [];\n\tlet totalBytes = 0;\n\tfor (;;) {\n\t\tconst { done, value } = await reader.read();\n\t\tif (done) break;\n\t\ttotalBytes += value.byteLength;\n\t\tif (totalBytes > MAX_URL_RESPONSE_BYTES) { await reader.cancel(); throw new Error(`URL response exceeds ${MAX_URL_RESPONSE_BYTES} byte limit`); }\n\t\tchunks.push(decoder.decode(value, { stream: true }));\n\t}\n\tchunks.push(decoder.decode());\n\treturn chunks.join(\"\");\n}\nexport async function loadPage(url: string, timeoutMs: number, signal?: AbortSignal, accept?: string): Promise<LoadedPage> {\n\turl = normalizeUrlForCache(url);\n\tconst controller = new AbortController();\n\tconst timer = setTimeout(() => controller.abort(), Math.min(timeoutMs, REMOTE_FETCH_TIMEOUT_MS));\n\tconst onParentAbort = () => controller.abort();\n\tsignal?.addEventListener(\"abort\", onParentAbort, { once: true });\n\ttry {\n\t\tlet currentUrl = url;\n\t\tfor (let redirects = 0; redirects <= MAX_URL_REDIRECTS; redirects++) {\n\t\t\tconst pinned = await assertSafeFetchUrl(currentUrl);\n\t\t\t// Only a DNS-resolved hostname needs pinning: a literal-IP host is\n\t\t\t// validated directly and cannot be re-resolved at connect time, so\n\t\t\t// global fetch is sufficient and stays redirect/mock-friendly.\n\t\t\tconst dispatcher = pinned?.pinned ? createPinnedDispatcher(pinned) : undefined;\n\t\t\ttry {\n\t\t\t\tconst headers = accept ? { Accept: accept } : undefined;\n\t\t\t\t// Route pinned (hostname) fetches through undici directly so the\n\t\t\t\t// dispatcher's custom lookup is honored even under Bun's compiled\n\t\t\t\t// fetch, which silently ignores the `dispatcher` option.\n\t\t\t\tconst response = dispatcher\n\t\t\t\t\t? await pinnedFetch(currentUrl, dispatcher, { signal: controller.signal, headers })\n\t\t\t\t\t: await fetch(currentUrl, { signal: controller.signal, headers, redirect: \"manual\" });\n\t\t\t\tif (response.status >= 300 && response.status < 400 && response.headers.get(\"location\")) { await response.body?.cancel().catch(() => {}); currentUrl = new URL(response.headers.get(\"location\")!, currentUrl).href; continue; }\n\t\t\t\tconst contentLength = Number.parseInt(response.headers.get(\"content-length\") ?? \"0\", 10);\n\t\t\t\tif (contentLength > MAX_URL_RESPONSE_BYTES) throw new Error(`URL response exceeds ${MAX_URL_RESPONSE_BYTES} byte limit: ${currentUrl}`);\n\t\t\t\tconst contentType = response.headers.get(\"content-type\") ?? \"\";\n\t\t\t\tconst content = await readResponseTextWithLimit(response);\n\t\t\t\treturn { ok: response.ok, status: response.status, content, contentType, finalUrl: response.url || currentUrl };\n\t\t\t} finally {\n\t\t\t\tawait closePinnedDispatcher(dispatcher).catch(() => undefined);\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`Too many redirects while fetching URL: ${url}`);\n\t} finally {\n\t\tclearTimeout(timer);\n\t\tsignal?.removeEventListener(\"abort\", onParentAbort);\n\t}\n}\n\nfunction isLowQuality(content: string): boolean {\n\tconst lower = content.toLowerCase();\n\tif (/(enable javascript|javascript required|turn on javascript|please enable javascript|browser not supported)/.test(lower) && content.trim().length < 2000) return true;\n\tconst nonblank = content.split(\"\\n\").filter((line) => line.trim().length > 0);\n\tif (nonblank.length > 10 && nonblank.filter((line) => line.trim().length < 40).length / nonblank.length > 0.7) return true;\n\treturn false;\n}\n\nfunction buildLlmEndpointCandidates(url: string): string[] {\n\tconst parsed = (() => { try { return new URL(url); } catch { return undefined; } })();\n\tif (!parsed) return [];\n\tconst origin = parsed.origin;\n\tif (parsed.pathname === \"/\" || parsed.pathname === \"\") return [`${origin}/.well-known/llms.txt`, `${origin}/llms.txt`, `${origin}/llms.md`];\n\tconst trimmed = parsed.pathname.replace(/\\/+$/, \"\");\n\tconst segments = trimmed.split(\"/\").filter(Boolean);\n\tconst candidates: string[] = [];\n\tconst depth = parsed.pathname.endsWith(\"/\") ? segments.length : Math.max(segments.length - 1, 1);\n\tfor (let scope = Math.min(depth, segments.length); scope >= 1; scope--) {\n\t\tconst base = `${origin}/${segments.slice(0, scope).join(\"/\")}`;\n\t\tcandidates.push(`${base}/llms.txt`, `${base}/llms.md`);\n\t}\n\tcandidates.push(`${origin}/llms.txt`, `${origin}/llms.md`);\n\treturn [...new Set(candidates)];\n}\n\nasync function tryLlmEndpoints(url: string, signal?: AbortSignal): Promise<{ content: string; endpoint: string } | null> {\n\tfor (const endpoint of buildLlmEndpointCandidates(url)) {\n\t\ttry {\n\t\t\tconst page = await loadPage(endpoint, 5000, signal);\n\t\t\tif (page.ok && page.content.trim().length > MIN_CONTENT_LENGTH && !looksLikeHtml(page.content)) return { content: page.content, endpoint };\n\t\t} catch {}\n\t}\n\treturn null;\n}\n\nfunction parseAlternateMarkdownLink(html: string, pageUrl: string): string | undefined {\n\tconst headEnd = html.toLowerCase().indexOf(\"</head>\");\n\tconst head = html.slice(0, headEnd >= 0 ? headEnd + 7 : html.length);\n\tconst links = [...head.matchAll(/<link\\b[^>]*>/gi)].map((m) => m[0] ?? \"\");\n\tfor (const tag of links) {\n\t\tconst rel = /rel=[\"']?([^\"'>]+)[\"']?/i.exec(tag)?.[1] ?? \"\";\n\t\tconst type = /type=[\"']?([^\"'>]+)[\"']?/i.exec(tag)?.[1] ?? \"\";\n\t\tconst href = /href=[\"']?([^\"'>]+)[\"']?/i.exec(tag)?.[1] ?? \"\";\n\t\tif (!/alternate/i.test(rel) || !href) continue;\n\t\tif (/RecentChanges|Special:|\\/feed\\/|action=feed/i.test(href)) continue;\n\t\tif (type.includes(\"markdown\") || href.endsWith(\".md\")) {\n\t\t\ttry { return new URL(href, pageUrl).href; } catch {}\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function tryMdSuffix(url: string, signal?: AbortSignal): Promise<string | null> {\n\tconst candidates: string[] = [];\n\tif (/\\/$/.test(url)) candidates.push(`${url}index.html.md`);\n\telse if (/\\.\\w+\\/?$/.test(url)) candidates.push(`${url}.md`);\n\telse candidates.push(`${url}.md`, `${url}/index.html.md`);\n\tfor (const candidate of candidates) {\n\t\ttry {\n\t\t\tconst page = await loadPage(candidate, 5000, signal);\n\t\t\tif (page.ok && page.content.trim().length > MIN_CONTENT_LENGTH && !looksLikeHtml(page.content)) return page.content;\n\t\t} catch {}\n\t}\n\treturn null;\n}\n\nasync function tryContentNegotiation(url: string, signal?: AbortSignal): Promise<string | null> {\n\ttry {\n\t\tconst page = await loadPage(url, 5000, signal, \"text/markdown, text/plain;q=0.9, text/html;q=0.8\");\n\t\tconst mime = page.contentType.toLowerCase();\n\t\tif (page.ok && page.content.trim().length > MIN_CONTENT_LENGTH && !looksLikeHtml(page.content) && (mime.includes(\"markdown\") || mime.includes(\"text/plain\"))) return page.content;\n\t} catch {}\n\treturn null;\n}\n\nexport interface RenderedUrl {\n\tcontent: string;\n\tfinalUrl: string;\n\tcontentType: string;\n\tmethod: string;\n\tnotes: string[];\n\ttruncated: boolean;\n}\n\nexport async function renderUrl(url: string, raw: boolean, signal?: AbortSignal): Promise<RenderedUrl> {\n\tconst notes: string[] = [];\n\tlet method = \"text\";\n\tlet contentType = \"\";\n\tlet finalUrl: string;\n\tlet body = \"\";\n\tconst page = await loadPage(url, REMOTE_FETCH_TIMEOUT_MS, signal);\n\tfinalUrl = page.finalUrl;\n\tcontentType = page.contentType;\n\tif (!page.ok) return { content: page.content || `(request failed with status ${page.status})`, finalUrl, contentType, method: \"failed\", notes, truncated: false };\n\tif (raw) return { content: page.content, finalUrl, contentType, method: \"raw\", notes, truncated: false };\n\tconst buffer = Buffer.from(page.content, \"utf8\");\n\tconst docExt = documentExtensionFromContentType(contentType) ?? (isDocumentPath(finalUrl) ? (finalUrl.match(/\\.\\w+(?:$|[?#])/)?.[0] ?? \"\") : \"\");\n\tif (docExt) {\n\t\ttry { body = await extractDocumentMarkdown(buffer, `${finalUrl}${docExt}`); method = \"document\"; }\n\t\tcatch (error) { body = `[Cannot read ${docExt} file: ${error instanceof Error ? error.message : \"conversion failed\"}]`; method = \"document-error\"; }\n\t\treturn { content: body, finalUrl, contentType, method, notes, truncated: false };\n\t}\n\tconst isHtml = /html/i.test(contentType) || looksLikeHtml(page.content);\n\tif (isHtml) {\n\t\tconst altMd = parseAlternateMarkdownLink(page.content, finalUrl);\n\t\tif (altMd) { try { const alt = await loadPage(altMd, 5000, signal); if (alt.ok && alt.content.trim().length > MIN_CONTENT_LENGTH && !looksLikeHtml(alt.content)) { return { content: alt.content, finalUrl: alt.finalUrl, contentType: alt.contentType, method: \"alternate-markdown\", notes, truncated: false }; } } catch {} notes.push(\"alternate markdown link unusable\"); }\n\t\tconst md = await tryMdSuffix(finalUrl, signal); if (md) return { content: md, finalUrl, contentType: \"text/markdown\", method: \"md-suffix\", notes, truncated: false };\n\t\tconst neg = await tryContentNegotiation(finalUrl, signal); if (neg) return { content: neg, finalUrl, contentType: \"text/markdown\", method: \"content-negotiation\", notes, truncated: false };\n\t\tlet rendered = getTurndown().turndown(page.content).trim();\n\t\tmethod = \"native\";\n\t\tif (rendered.length <= MIN_CONTENT_LENGTH || isLowQuality(rendered)) {\n\t\t\tconst llms = await tryLlmEndpoints(finalUrl, signal);\n\t\t\tif (llms) { return { content: llms.content, finalUrl, contentType: \"text/plain\", method: `llms-txt (${llms.endpoint})`, notes, truncated: false }; }\n\t\t\tnotes.push(\"rendered content low quality; no markdown source discovered\");\n\t\t}\n\t\tbody = rendered;\n\t} else {\n\t\tbody = page.content;\n\t}\n\treturn { content: body, finalUrl, contentType, method, notes, truncated: false };\n}\n\nexport function buildUrlReadOutput(result: RenderedUrl): string {\n\tconst header = [`URL: ${result.finalUrl}`, `Content-Type: ${result.contentType}`, `Method: ${result.method}`, ...(result.notes.length ? [`Notes: ${result.notes.join(\"; \")}`] : [])].join(\"\\n\");\n\treturn `${header}\\n\\n---\\n\\n${result.content}`;\n}\n\nfunction persistReadUrlArtifact(artifactsDir: string | undefined, output: string): string | undefined {\n\tif (!artifactsDir) return undefined;\n\treturn getArtifactManager(artifactsDir).save(output, \"read\");\n}\n\nexport interface ExecuteReadUrlResult {\n\tcontent: string;\n\tdetails: ReadUrlToolDetails;\n\tartifactId?: string;\n}\n\nexport interface LoadedReadUrl {\n\toutput: string;\n\tdetails: ReadUrlToolDetails;\n\tartifactId?: string;\n\traw: boolean;\n}\n\n/**\n * Resolve a URL to its full rendered (or raw) output, using the session-scoped\n * cache and persisting the rendered body as a `read` artifact. Returns the\n * complete untruncated output so callers can apply their own line selection.\n */\nexport async function loadReadUrlOutput(scope: string, params: { path: string; raw?: boolean }, artifactsDir: string | undefined, signal?: AbortSignal): Promise<LoadedReadUrl> {\n\tconst parsed = parseReadUrlTarget(params.path);\n\tif (!parsed) throw new Error(`Not a readable URL: ${params.path}`);\n\tconst raw = params.raw ?? parsed.raw;\n\tconst key = getReadUrlCacheKey(scope, parsed.url, raw);\n\tlet entry = readUrlCache.get(key);\n\tif (!entry) {\n\t\tconst rendered = await renderUrl(parsed.url, raw, signal);\n\t\tconst output = raw ? rendered.content : buildUrlReadOutput(rendered);\n\t\tconst artifactId = persistReadUrlArtifact(artifactsDir, output);\n\t\tconst details: ReadUrlToolDetails = { url: parsed.url, finalUrl: rendered.finalUrl, contentType: rendered.contentType, method: rendered.method, truncated: rendered.truncated, notes: rendered.notes, meta: artifactId ? { artifactId } : undefined };\n\t\tentry = { artifactId, details, output };\n\t\treadUrlCache.set(key, entry);\n\t\treadUrlCache.set(getReadUrlCacheKey(scope, rendered.finalUrl, raw), entry);\n\t}\n\treturn { output: entry.output, details: entry.details, artifactId: entry.artifactId, raw };\n}\n\nexport async function executeReadUrl(scope: string, params: { path: string; raw?: boolean }, artifactsDir: string | undefined, signal?: AbortSignal): Promise<ExecuteReadUrlResult> {\n\tconst loaded = await loadReadUrlOutput(scope, params, artifactsDir, signal);\n\tconst entry = { output: loaded.output, details: loaded.details, artifactId: loaded.artifactId };\n\tconst fetchDefaultBytes = 50 * 1024;\n\tconst lines = entry.output.split(\"\\n\");\n\tconst visibleLines = lines.slice(0, FETCH_DEFAULT_MAX_LINES);\n\tlet content = visibleLines.join(\"\\n\");\n\tconst bytesBeforeByteClamp = Buffer.byteLength(content, \"utf8\");\n\tconst byteTruncated = bytesBeforeByteClamp > fetchDefaultBytes;\n\tconst lineTruncated = lines.length > FETCH_DEFAULT_MAX_LINES;\n\tif (byteTruncated) content = content.slice(0, fetchDefaultBytes);\n\tconst truncated = lineTruncated || byteTruncated;\n\tlet artifactId = entry.artifactId;\n\tif (truncated && !artifactId) artifactId = persistReadUrlArtifact(artifactsDir, entry.output);\n\tconst outputLines = content.length === 0 ? 0 : content.split(\"\\n\").length;\n\tconst truncation: TruncationResult | undefined = truncated ? {\n\t\tcontent,\n\t\ttruncated: true,\n\t\ttruncatedBy: byteTruncated ? \"bytes\" : \"lines\",\n\t\ttotalLines: lines.length,\n\t\ttotalBytes: Buffer.byteLength(entry.output, \"utf8\"),\n\t\toutputLines,\n\t\toutputBytes: Buffer.byteLength(content, \"utf8\"),\n\t\tlastLinePartial: byteTruncated,\n\t\tfirstLineExceedsLimit: false,\n\t\tmaxLines: FETCH_DEFAULT_MAX_LINES,\n\t\tmaxBytes: fetchDefaultBytes,\n\t} : undefined;\n\tconst details: ReadUrlToolDetails = { ...entry.details, truncated, meta: { ...(entry.details.meta ?? {}), ...(artifactId ? { artifactId } : {}), ...(truncation ? { truncation } : {}) } };\n\tif (truncated) content += `\\n\\n[Showing first ${visibleLines.length} of ${lines.length} lines.${artifactId ? ` Full output: artifact://${artifactId}` : \"\"}]`;\n\treturn { content, details, artifactId };\n}\n\nexport function resetReadUrlCache(): void {\n\treadUrlCache.clear();\n}\n"]}
1
+ {"version":3,"file":"fetch-url.d.ts","sourceRoot":"","sources":["../../../src/core/tools/fetch-url.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAM9C,MAAM,WAAW,SAAS;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE;AAE1D,MAAM,WAAW,mBAAmB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,kBAAkB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,gBAAgB,CAAA;KAAE,CAAC;CAC9D;AAQD,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,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;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAgB9K;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA+BlL;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
@@ -1 +1 @@
1
- {"version":3,"file":"file-mutation-queue.d.ts","sourceRoot":"","sources":["../../../src/core/tools/file-mutation-queue.ts"],"names":[],"mappings":"AA2BA;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA6BjG","sourcesContent":["import { realpath } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\n\nconst fileMutationQueues = new Map<string, Promise<void>>();\nlet registrationQueue = Promise.resolve();\n\nfunction isMissingPathError(error: unknown): boolean {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"code\" in error &&\n\t\t(error.code === \"ENOENT\" || error.code === \"ENOTDIR\")\n\t);\n}\n\nasync function getMutationQueueKey(filePath: string): Promise<string> {\n\tconst resolvedPath = resolve(filePath);\n\ttry {\n\t\treturn await realpath(resolvedPath);\n\t} catch (error) {\n\t\tif (isMissingPathError(error)) {\n\t\t\treturn resolvedPath;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * Serialize file mutation operations targeting the same file.\n * Operations for different files still run in parallel.\n */\nexport async function withFileMutationQueue<T>(filePath: string, fn: () => Promise<T>): Promise<T> {\n\tconst registration = registrationQueue.then(async () => {\n\t\tconst key = await getMutationQueueKey(filePath);\n\t\tconst currentQueue = fileMutationQueues.get(key) ?? Promise.resolve();\n\n\t\tlet releaseNext!: () => void;\n\t\tconst nextQueue = new Promise<void>((resolveQueue) => {\n\t\t\treleaseNext = resolveQueue;\n\t\t});\n\t\tconst chainedQueue = currentQueue.then(() => nextQueue);\n\t\tfileMutationQueues.set(key, chainedQueue);\n\n\t\treturn { key, currentQueue, chainedQueue, releaseNext };\n\t});\n\tregistrationQueue = registration.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\n\tconst { key, currentQueue, chainedQueue, releaseNext } = await registration;\n\tawait currentQueue;\n\ttry {\n\t\treturn await fn();\n\t} finally {\n\t\treleaseNext();\n\t\tif (fileMutationQueues.get(key) === chainedQueue) {\n\t\t\tfileMutationQueues.delete(key);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"file-mutation-queue.d.ts","sourceRoot":"","sources":["../../../src/core/tools/file-mutation-queue.ts"],"names":[],"mappings":"AA2BA;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA6BjG"}