@bastani/atomic 0.9.2-alpha.1 → 0.9.3-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (455) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +2 -2
  3. package/dist/builtin/cursor/CHANGELOG.md +6 -0
  4. package/dist/builtin/cursor/package.json +2 -2
  5. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  6. package/dist/builtin/intercom/package.json +1 -1
  7. package/dist/builtin/mcp/CHANGELOG.md +12 -0
  8. package/dist/builtin/mcp/direct-tools.ts +4 -2
  9. package/dist/builtin/mcp/package.json +1 -1
  10. package/dist/builtin/mcp/proxy-call.ts +3 -1
  11. package/dist/builtin/mcp/utils.ts +18 -7
  12. package/dist/builtin/subagents/CHANGELOG.md +17 -0
  13. package/dist/builtin/subagents/README.md +6 -6
  14. package/dist/builtin/subagents/agents/code-simplifier.md +7 -6
  15. package/dist/builtin/subagents/agents/codebase-analyzer.md +5 -4
  16. package/dist/builtin/subagents/agents/codebase-locator.md +3 -3
  17. package/dist/builtin/subagents/agents/codebase-online-researcher.md +10 -10
  18. package/dist/builtin/subagents/agents/codebase-pattern-finder.md +4 -4
  19. package/dist/builtin/subagents/agents/codebase-research-analyzer.md +3 -3
  20. package/dist/builtin/subagents/agents/codebase-research-locator.md +4 -4
  21. package/dist/builtin/subagents/agents/debugger.md +5 -5
  22. package/dist/builtin/subagents/agents/worker.md +56 -0
  23. package/dist/builtin/subagents/package.json +1 -1
  24. package/dist/builtin/subagents/skills/subagent/SKILL.md +11 -11
  25. package/dist/builtin/subagents/src/agents/agent-loaders.ts +3 -5
  26. package/dist/builtin/subagents/src/agents/agent-management-helpers.ts +3 -3
  27. package/dist/builtin/subagents/src/extension/schemas.ts +2 -2
  28. package/dist/builtin/subagents/src/intercom/result-intercom.ts +4 -3
  29. package/dist/builtin/subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +1 -1
  30. package/dist/builtin/subagents/src/runs/shared/nested-render.ts +2 -2
  31. package/dist/builtin/subagents/src/runs/shared/pi-args.ts +2 -1
  32. package/dist/builtin/subagents/src/shared/types-depth.ts +5 -5
  33. package/dist/builtin/subagents/src/shared/types-runtime.ts +2 -1
  34. package/dist/builtin/subagents/src/tui/render-event-formatting.ts +2 -2
  35. package/dist/builtin/web-access/CHANGELOG.md +6 -0
  36. package/dist/builtin/web-access/package.json +1 -1
  37. package/dist/builtin/workflows/CHANGELOG.md +21 -0
  38. package/dist/builtin/workflows/README.md +2 -2
  39. package/dist/builtin/workflows/builtin/goal-artifacts.ts +11 -6
  40. package/dist/builtin/workflows/builtin/goal-ledger.ts +33 -1
  41. package/dist/builtin/workflows/builtin/goal-prompts.ts +23 -28
  42. package/dist/builtin/workflows/builtin/goal-reducer.ts +2 -2
  43. package/dist/builtin/workflows/builtin/goal-reports.ts +2 -5
  44. package/dist/builtin/workflows/builtin/goal-review.ts +1 -1
  45. package/dist/builtin/workflows/builtin/goal-runner.ts +10 -17
  46. package/dist/builtin/workflows/builtin/open-claude-design-feedback.ts +3 -3
  47. package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +1 -3
  48. package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +1 -1
  49. package/dist/builtin/workflows/builtin/ralph-core.ts +7 -17
  50. package/dist/builtin/workflows/builtin/ralph-runner.ts +11 -18
  51. package/dist/builtin/workflows/builtin/shared-prompts.ts +1 -1
  52. package/dist/builtin/workflows/package.json +1 -1
  53. package/dist/builtin/workflows/src/extension/config-loader.ts +35 -15
  54. package/dist/builtin/workflows/src/extension/discovery.ts +20 -8
  55. package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +1 -2
  56. package/dist/builtin/workflows/src/extension/wiring.ts +1 -1
  57. package/dist/builtin/workflows/src/tui/dispatch-confirm.ts +11 -10
  58. package/dist/cli/args.d.ts.map +1 -1
  59. package/dist/cli/args.js +9 -9
  60. package/dist/cli/args.js.map +1 -1
  61. package/dist/config-self-update.d.ts.map +1 -1
  62. package/dist/config-self-update.js +3 -4
  63. package/dist/config-self-update.js.map +1 -1
  64. package/dist/config.d.ts.map +1 -1
  65. package/dist/config.js +4 -5
  66. package/dist/config.js.map +1 -1
  67. package/dist/core/agent-session-bash.d.ts +1 -0
  68. package/dist/core/agent-session-bash.d.ts.map +1 -1
  69. package/dist/core/agent-session-bash.js +1 -0
  70. package/dist/core/agent-session-bash.js.map +1 -1
  71. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  72. package/dist/core/agent-session-tool-registry.js +23 -0
  73. package/dist/core/agent-session-tool-registry.js.map +1 -1
  74. package/dist/core/bash-executor.d.ts +2 -0
  75. package/dist/core/bash-executor.d.ts.map +1 -1
  76. package/dist/core/bash-executor.js +1 -0
  77. package/dist/core/bash-executor.js.map +1 -1
  78. package/dist/core/compaction/compaction.d.ts +29 -0
  79. package/dist/core/compaction/compaction.d.ts.map +1 -1
  80. package/dist/core/compaction/compaction.js +36 -1
  81. package/dist/core/compaction/compaction.js.map +1 -1
  82. package/dist/core/compaction/context-compaction-metrics.d.ts +14 -2
  83. package/dist/core/compaction/context-compaction-metrics.d.ts.map +1 -1
  84. package/dist/core/compaction/context-compaction-metrics.js +50 -1
  85. package/dist/core/compaction/context-compaction-metrics.js.map +1 -1
  86. package/dist/core/compaction/context-compaction-prompt.d.ts.map +1 -1
  87. package/dist/core/compaction/context-compaction-prompt.js +2 -0
  88. package/dist/core/compaction/context-compaction-prompt.js.map +1 -1
  89. package/dist/core/compaction/context-compaction-runner.d.ts.map +1 -1
  90. package/dist/core/compaction/context-compaction-runner.js +1 -1
  91. package/dist/core/compaction/context-compaction-runner.js.map +1 -1
  92. package/dist/core/compaction/context-deletion-application.d.ts.map +1 -1
  93. package/dist/core/compaction/context-deletion-application.js +5 -5
  94. package/dist/core/compaction/context-deletion-application.js.map +1 -1
  95. package/dist/core/compaction/context-deletion-targets.d.ts +2 -0
  96. package/dist/core/compaction/context-deletion-targets.d.ts.map +1 -1
  97. package/dist/core/compaction/context-deletion-targets.js +23 -3
  98. package/dist/core/compaction/context-deletion-targets.js.map +1 -1
  99. package/dist/core/compaction/context-deletion-tool-definitions.d.ts +6 -0
  100. package/dist/core/compaction/context-deletion-tool-definitions.d.ts.map +1 -1
  101. package/dist/core/compaction/context-deletion-tool-definitions.js.map +1 -1
  102. package/dist/core/compaction/context-deletion-tools.d.ts.map +1 -1
  103. package/dist/core/compaction/context-deletion-tools.js +18 -10
  104. package/dist/core/compaction/context-deletion-tools.js.map +1 -1
  105. package/dist/core/compaction/context-transcript-analysis.d.ts.map +1 -1
  106. package/dist/core/compaction/context-transcript-analysis.js +2 -4
  107. package/dist/core/compaction/context-transcript-analysis.js.map +1 -1
  108. package/dist/core/copilot-gemini-tool-arguments.d.ts.map +1 -1
  109. package/dist/core/copilot-gemini-tool-arguments.js +2 -60
  110. package/dist/core/copilot-gemini-tool-arguments.js.map +1 -1
  111. package/dist/core/extensions/context-types.d.ts +2 -0
  112. package/dist/core/extensions/context-types.d.ts.map +1 -1
  113. package/dist/core/extensions/context-types.js.map +1 -1
  114. package/dist/core/extensions/index.d.ts +2 -2
  115. package/dist/core/extensions/index.d.ts.map +1 -1
  116. package/dist/core/extensions/index.js +1 -1
  117. package/dist/core/extensions/index.js.map +1 -1
  118. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  119. package/dist/core/extensions/loader-virtual-modules.js +11 -3
  120. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  121. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  122. package/dist/core/extensions/runner-context.js +11 -0
  123. package/dist/core/extensions/runner-context.js.map +1 -1
  124. package/dist/core/extensions/tool-events.d.ts +13 -13
  125. package/dist/core/extensions/tool-events.d.ts.map +1 -1
  126. package/dist/core/extensions/tool-events.js +3 -3
  127. package/dist/core/extensions/tool-events.js.map +1 -1
  128. package/dist/core/extensions/types.d.ts +1 -1
  129. package/dist/core/extensions/types.d.ts.map +1 -1
  130. package/dist/core/extensions/types.js +1 -1
  131. package/dist/core/extensions/types.js.map +1 -1
  132. package/dist/core/flattened-tool-arguments.d.ts +18 -0
  133. package/dist/core/flattened-tool-arguments.d.ts.map +1 -1
  134. package/dist/core/flattened-tool-arguments.js +104 -0
  135. package/dist/core/flattened-tool-arguments.js.map +1 -1
  136. package/dist/core/sdk-exports.d.ts +1 -1
  137. package/dist/core/sdk-exports.d.ts.map +1 -1
  138. package/dist/core/sdk-exports.js +1 -1
  139. package/dist/core/sdk-exports.js.map +1 -1
  140. package/dist/core/sdk-types.d.ts +2 -2
  141. package/dist/core/sdk-types.d.ts.map +1 -1
  142. package/dist/core/sdk-types.js.map +1 -1
  143. package/dist/core/settings-manager-basic-accessors.d.ts +4 -0
  144. package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
  145. package/dist/core/settings-manager-basic-accessors.js +18 -0
  146. package/dist/core/settings-manager-basic-accessors.js.map +1 -1
  147. package/dist/core/settings-manager-resource-accessors.d.ts +4 -0
  148. package/dist/core/settings-manager-resource-accessors.d.ts.map +1 -1
  149. package/dist/core/settings-manager-resource-accessors.js +15 -0
  150. package/dist/core/settings-manager-resource-accessors.js.map +1 -1
  151. package/dist/core/settings-types.d.ts +11 -0
  152. package/dist/core/settings-types.d.ts.map +1 -1
  153. package/dist/core/settings-types.js.map +1 -1
  154. package/dist/core/system-prompt.d.ts +1 -1
  155. package/dist/core/system-prompt.d.ts.map +1 -1
  156. package/dist/core/system-prompt.js +3 -2
  157. package/dist/core/system-prompt.js.map +1 -1
  158. package/dist/core/tools/artifact-protocol.d.ts +11 -0
  159. package/dist/core/tools/artifact-protocol.d.ts.map +1 -0
  160. package/dist/core/tools/artifact-protocol.js +76 -0
  161. package/dist/core/tools/artifact-protocol.js.map +1 -0
  162. package/dist/core/tools/artifacts.d.ts +18 -0
  163. package/dist/core/tools/artifacts.d.ts.map +1 -0
  164. package/dist/core/tools/artifacts.js +90 -0
  165. package/dist/core/tools/artifacts.js.map +1 -0
  166. package/dist/core/tools/bash-async-jobs.d.ts +20 -0
  167. package/dist/core/tools/bash-async-jobs.d.ts.map +1 -0
  168. package/dist/core/tools/bash-async-jobs.js +59 -0
  169. package/dist/core/tools/bash-async-jobs.js.map +1 -0
  170. package/dist/core/tools/bash-async-output.d.ts +10 -0
  171. package/dist/core/tools/bash-async-output.d.ts.map +1 -0
  172. package/dist/core/tools/bash-async-output.js +80 -0
  173. package/dist/core/tools/bash-async-output.js.map +1 -0
  174. package/dist/core/tools/bash-interceptor.d.ts +10 -0
  175. package/dist/core/tools/bash-interceptor.d.ts.map +1 -0
  176. package/dist/core/tools/bash-interceptor.js +39 -0
  177. package/dist/core/tools/bash-interceptor.js.map +1 -0
  178. package/dist/core/tools/bash-leading-cd.d.ts +7 -0
  179. package/dist/core/tools/bash-leading-cd.d.ts.map +1 -0
  180. package/dist/core/tools/bash-leading-cd.js +59 -0
  181. package/dist/core/tools/bash-leading-cd.js.map +1 -0
  182. package/dist/core/tools/bash-pty-native.d.ts +14 -0
  183. package/dist/core/tools/bash-pty-native.d.ts.map +1 -0
  184. package/dist/core/tools/bash-pty-native.js +71 -0
  185. package/dist/core/tools/bash-pty-native.js.map +1 -0
  186. package/dist/core/tools/bash.d.ts +28 -17
  187. package/dist/core/tools/bash.d.ts.map +1 -1
  188. package/dist/core/tools/bash.js +152 -35
  189. package/dist/core/tools/bash.js.map +1 -1
  190. package/dist/core/tools/block-resolver.d.ts +16 -0
  191. package/dist/core/tools/block-resolver.d.ts.map +1 -0
  192. package/dist/core/tools/block-resolver.js +74 -0
  193. package/dist/core/tools/block-resolver.js.map +1 -0
  194. package/dist/core/tools/conflict-registry.d.ts +16 -0
  195. package/dist/core/tools/conflict-registry.d.ts.map +1 -0
  196. package/dist/core/tools/conflict-registry.js +44 -0
  197. package/dist/core/tools/conflict-registry.js.map +1 -0
  198. package/dist/core/tools/directory-tree.d.ts +13 -0
  199. package/dist/core/tools/directory-tree.d.ts.map +1 -0
  200. package/dist/core/tools/directory-tree.js +81 -0
  201. package/dist/core/tools/directory-tree.js.map +1 -0
  202. package/dist/core/tools/edit.d.ts +4 -29
  203. package/dist/core/tools/edit.d.ts.map +1 -1
  204. package/dist/core/tools/edit.js +136 -228
  205. package/dist/core/tools/edit.js.map +1 -1
  206. package/dist/core/tools/fetch-url.d.ts +74 -0
  207. package/dist/core/tools/fetch-url.d.ts.map +1 -0
  208. package/dist/core/tools/fetch-url.js +518 -0
  209. package/dist/core/tools/fetch-url.js.map +1 -0
  210. package/dist/core/tools/find.d.ts +27 -9
  211. package/dist/core/tools/find.d.ts.map +1 -1
  212. package/dist/core/tools/find.js +400 -176
  213. package/dist/core/tools/find.js.map +1 -1
  214. package/dist/core/tools/glob-path-utils.d.ts +8 -0
  215. package/dist/core/tools/glob-path-utils.d.ts.map +1 -0
  216. package/dist/core/tools/glob-path-utils.js +26 -0
  217. package/dist/core/tools/glob-path-utils.js.map +1 -0
  218. package/dist/core/tools/grep.d.ts +12 -0
  219. package/dist/core/tools/grep.d.ts.map +1 -1
  220. package/dist/core/tools/grep.js +141 -17
  221. package/dist/core/tools/grep.js.map +1 -1
  222. package/dist/core/tools/hashline-engine/apply.d.ts +11 -0
  223. package/dist/core/tools/hashline-engine/apply.d.ts.map +1 -0
  224. package/dist/core/tools/hashline-engine/apply.js +752 -0
  225. package/dist/core/tools/hashline-engine/apply.js.map +1 -0
  226. package/dist/core/tools/hashline-engine/block.d.ts +40 -0
  227. package/dist/core/tools/hashline-engine/block.d.ts.map +1 -0
  228. package/dist/core/tools/hashline-engine/block.js +117 -0
  229. package/dist/core/tools/hashline-engine/block.js.map +1 -0
  230. package/dist/core/tools/hashline-engine/diff-preview.d.ts +15 -0
  231. package/dist/core/tools/hashline-engine/diff-preview.d.ts.map +1 -0
  232. package/dist/core/tools/hashline-engine/diff-preview.js +98 -0
  233. package/dist/core/tools/hashline-engine/diff-preview.js.map +1 -0
  234. package/dist/core/tools/hashline-engine/format.d.ts +71 -0
  235. package/dist/core/tools/hashline-engine/format.d.ts.map +1 -0
  236. package/dist/core/tools/hashline-engine/format.js +178 -0
  237. package/dist/core/tools/hashline-engine/format.js.map +1 -0
  238. package/dist/core/tools/hashline-engine/fs.d.ts +81 -0
  239. package/dist/core/tools/hashline-engine/fs.d.ts.map +1 -0
  240. package/dist/core/tools/hashline-engine/fs.js +143 -0
  241. package/dist/core/tools/hashline-engine/fs.js.map +1 -0
  242. package/dist/core/tools/hashline-engine/index.d.ts +18 -0
  243. package/dist/core/tools/hashline-engine/index.d.ts.map +1 -0
  244. package/dist/core/tools/hashline-engine/index.js +20 -0
  245. package/dist/core/tools/hashline-engine/index.js.map +1 -0
  246. package/dist/core/tools/hashline-engine/input.d.ts +101 -0
  247. package/dist/core/tools/hashline-engine/input.d.ts.map +1 -0
  248. package/dist/core/tools/hashline-engine/input.js +398 -0
  249. package/dist/core/tools/hashline-engine/input.js.map +1 -0
  250. package/dist/core/tools/hashline-engine/messages.d.ts +99 -0
  251. package/dist/core/tools/hashline-engine/messages.d.ts.map +1 -0
  252. package/dist/core/tools/hashline-engine/messages.js +144 -0
  253. package/dist/core/tools/hashline-engine/messages.js.map +1 -0
  254. package/dist/core/tools/hashline-engine/mismatch.d.ts +45 -0
  255. package/dist/core/tools/hashline-engine/mismatch.d.ts.map +1 -0
  256. package/dist/core/tools/hashline-engine/mismatch.js +90 -0
  257. package/dist/core/tools/hashline-engine/mismatch.js.map +1 -0
  258. package/dist/core/tools/hashline-engine/normalize.d.ts +21 -0
  259. package/dist/core/tools/hashline-engine/normalize.d.ts.map +1 -0
  260. package/dist/core/tools/hashline-engine/normalize.js +33 -0
  261. package/dist/core/tools/hashline-engine/normalize.js.map +1 -0
  262. package/dist/core/tools/hashline-engine/parser.d.ts +24 -0
  263. package/dist/core/tools/hashline-engine/parser.d.ts.map +1 -0
  264. package/dist/core/tools/hashline-engine/parser.js +381 -0
  265. package/dist/core/tools/hashline-engine/parser.js.map +1 -0
  266. package/dist/core/tools/hashline-engine/patcher.d.ts +118 -0
  267. package/dist/core/tools/hashline-engine/patcher.d.ts.map +1 -0
  268. package/dist/core/tools/hashline-engine/patcher.js +341 -0
  269. package/dist/core/tools/hashline-engine/patcher.js.map +1 -0
  270. package/dist/core/tools/hashline-engine/prefixes.d.ts +43 -0
  271. package/dist/core/tools/hashline-engine/prefixes.d.ts.map +1 -0
  272. package/dist/core/tools/hashline-engine/prefixes.js +135 -0
  273. package/dist/core/tools/hashline-engine/prefixes.js.map +1 -0
  274. package/dist/core/tools/hashline-engine/recovery.d.ts +41 -0
  275. package/dist/core/tools/hashline-engine/recovery.d.ts.map +1 -0
  276. package/dist/core/tools/hashline-engine/recovery.js +168 -0
  277. package/dist/core/tools/hashline-engine/recovery.js.map +1 -0
  278. package/dist/core/tools/hashline-engine/snapshots.d.ts +65 -0
  279. package/dist/core/tools/hashline-engine/snapshots.d.ts.map +1 -0
  280. package/dist/core/tools/hashline-engine/snapshots.js +108 -0
  281. package/dist/core/tools/hashline-engine/snapshots.js.map +1 -0
  282. package/dist/core/tools/hashline-engine/stream.d.ts +3 -0
  283. package/dist/core/tools/hashline-engine/stream.d.ts.map +1 -0
  284. package/dist/core/tools/hashline-engine/stream.js +111 -0
  285. package/dist/core/tools/hashline-engine/stream.js.map +1 -0
  286. package/dist/core/tools/hashline-engine/tokenizer.d.ts +69 -0
  287. package/dist/core/tools/hashline-engine/tokenizer.d.ts.map +1 -0
  288. package/dist/core/tools/hashline-engine/tokenizer.js +430 -0
  289. package/dist/core/tools/hashline-engine/tokenizer.js.map +1 -0
  290. package/dist/core/tools/hashline-engine/types.d.ts +166 -0
  291. package/dist/core/tools/hashline-engine/types.d.ts.map +1 -0
  292. package/dist/core/tools/hashline-engine/types.js +9 -0
  293. package/dist/core/tools/hashline-engine/types.js.map +1 -0
  294. package/dist/core/tools/hashline.d.ts +29 -0
  295. package/dist/core/tools/hashline.d.ts.map +1 -0
  296. package/dist/core/tools/hashline.js +110 -0
  297. package/dist/core/tools/hashline.js.map +1 -0
  298. package/dist/core/tools/index.d.ts +6 -4
  299. package/dist/core/tools/index.d.ts.map +1 -1
  300. package/dist/core/tools/index.js +52 -35
  301. package/dist/core/tools/index.js.map +1 -1
  302. package/dist/core/tools/notebook.d.ts +38 -0
  303. package/dist/core/tools/notebook.d.ts.map +1 -0
  304. package/dist/core/tools/notebook.js +125 -0
  305. package/dist/core/tools/notebook.js.map +1 -0
  306. package/dist/core/tools/read-document-extract.d.ts +9 -0
  307. package/dist/core/tools/read-document-extract.d.ts.map +1 -0
  308. package/dist/core/tools/read-document-extract.js +212 -0
  309. package/dist/core/tools/read-document-extract.js.map +1 -0
  310. package/dist/core/tools/read-selectors.d.ts +24 -0
  311. package/dist/core/tools/read-selectors.d.ts.map +1 -0
  312. package/dist/core/tools/read-selectors.js +277 -0
  313. package/dist/core/tools/read-selectors.js.map +1 -0
  314. package/dist/core/tools/read-url.d.ts +37 -0
  315. package/dist/core/tools/read-url.d.ts.map +1 -0
  316. package/dist/core/tools/read-url.js +39 -0
  317. package/dist/core/tools/read-url.js.map +1 -0
  318. package/dist/core/tools/read.d.ts +11 -11
  319. package/dist/core/tools/read.d.ts.map +1 -1
  320. package/dist/core/tools/read.js +224 -94
  321. package/dist/core/tools/read.js.map +1 -1
  322. package/dist/core/tools/resource-selectors.d.ts +44 -0
  323. package/dist/core/tools/resource-selectors.d.ts.map +1 -0
  324. package/dist/core/tools/resource-selectors.js +808 -0
  325. package/dist/core/tools/resource-selectors.js.map +1 -0
  326. package/dist/core/tools/search-details.d.ts +26 -0
  327. package/dist/core/tools/search-details.d.ts.map +1 -0
  328. package/dist/core/tools/search-details.js +24 -0
  329. package/dist/core/tools/search-details.js.map +1 -0
  330. package/dist/core/tools/search-line-ranges.d.ts +11 -0
  331. package/dist/core/tools/search-line-ranges.d.ts.map +1 -0
  332. package/dist/core/tools/search-line-ranges.js +65 -0
  333. package/dist/core/tools/search-line-ranges.js.map +1 -0
  334. package/dist/core/tools/search-native.d.ts +97 -0
  335. package/dist/core/tools/search-native.d.ts.map +1 -0
  336. package/dist/core/tools/search-native.js +27 -0
  337. package/dist/core/tools/search-native.js.map +1 -0
  338. package/dist/core/tools/search.d.ts +24 -0
  339. package/dist/core/tools/search.d.ts.map +1 -0
  340. package/dist/core/tools/search.js +573 -0
  341. package/dist/core/tools/search.js.map +1 -0
  342. package/dist/core/tools/truncate.d.ts +4 -4
  343. package/dist/core/tools/truncate.d.ts.map +1 -1
  344. package/dist/core/tools/truncate.js +3 -3
  345. package/dist/core/tools/truncate.js.map +1 -1
  346. package/dist/core/tools/url-ip-guards.d.ts +4 -0
  347. package/dist/core/tools/url-ip-guards.d.ts.map +1 -0
  348. package/dist/core/tools/url-ip-guards.js +126 -0
  349. package/dist/core/tools/url-ip-guards.js.map +1 -0
  350. package/dist/core/tools/write.d.ts +12 -2
  351. package/dist/core/tools/write.d.ts.map +1 -1
  352. package/dist/core/tools/write.js +166 -14
  353. package/dist/core/tools/write.js.map +1 -1
  354. package/dist/core/trust-manager.d.ts.map +1 -1
  355. package/dist/core/trust-manager.js +2 -3
  356. package/dist/core/trust-manager.js.map +1 -1
  357. package/dist/index-extensions.d.ts +2 -2
  358. package/dist/index-extensions.d.ts.map +1 -1
  359. package/dist/index-extensions.js +1 -1
  360. package/dist/index-extensions.js.map +1 -1
  361. package/dist/index.d.ts +3 -3
  362. package/dist/index.d.ts.map +1 -1
  363. package/dist/index.js +3 -3
  364. package/dist/index.js.map +1 -1
  365. package/dist/modes/interactive/components/custom-editor.d.ts +1 -0
  366. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  367. package/dist/modes/interactive/components/custom-editor.js +9 -2
  368. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  369. package/dist/modes/interactive/components/settings-selector-handlers.d.ts.map +1 -1
  370. package/dist/modes/interactive/components/settings-selector-handlers.js +3 -0
  371. package/dist/modes/interactive/components/settings-selector-handlers.js.map +1 -1
  372. package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
  373. package/dist/modes/interactive/components/settings-selector-items.js +7 -0
  374. package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
  375. package/dist/modes/interactive/components/settings-selector-types.d.ts +2 -0
  376. package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
  377. package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
  378. package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
  379. package/dist/modes/interactive/components/tree-selector-content.js +0 -5
  380. package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
  381. package/dist/modes/interactive/interactive-auth-login.d.ts.map +1 -1
  382. package/dist/modes/interactive/interactive-auth-login.js +1 -0
  383. package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
  384. package/dist/modes/interactive/interactive-autocomplete.d.ts.map +1 -1
  385. package/dist/modes/interactive/interactive-autocomplete.js +80 -2
  386. package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
  387. package/dist/modes/interactive/interactive-hotkeys-debug.d.ts.map +1 -1
  388. package/dist/modes/interactive/interactive-hotkeys-debug.js +3 -0
  389. package/dist/modes/interactive/interactive-hotkeys-debug.js.map +1 -1
  390. package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
  391. package/dist/modes/interactive/interactive-input-handling.js +51 -0
  392. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  393. package/dist/modes/interactive/interactive-mode-base.d.ts +5 -0
  394. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  395. package/dist/modes/interactive/interactive-mode-base.js +5 -0
  396. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  397. package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
  398. package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
  399. package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
  400. package/dist/modes/interactive/interactive-mode-surface.d.ts +12 -0
  401. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  402. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  403. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  404. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  405. package/dist/modes/interactive/interactive-mode.js +1 -0
  406. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  407. package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
  408. package/dist/modes/interactive/interactive-model-routing.js +4 -1
  409. package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
  410. package/dist/modes/interactive/interactive-onboarding.d.ts +11 -0
  411. package/dist/modes/interactive/interactive-onboarding.d.ts.map +1 -0
  412. package/dist/modes/interactive/interactive-onboarding.js +220 -0
  413. package/dist/modes/interactive/interactive-onboarding.js.map +1 -0
  414. package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
  415. package/dist/modes/interactive/interactive-selectors.js +4 -0
  416. package/dist/modes/interactive/interactive-selectors.js.map +1 -1
  417. package/dist/modes/interactive/interactive-session-routing.d.ts.map +1 -1
  418. package/dist/modes/interactive/interactive-session-routing.js +6 -0
  419. package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
  420. package/dist/modes/interactive/interactive-slash-commands.d.ts.map +1 -1
  421. package/dist/modes/interactive/interactive-slash-commands.js +9 -4
  422. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  423. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  424. package/dist/modes/interactive/interactive-startup.js +28 -0
  425. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  426. package/dist/utils/child-process.d.ts.map +1 -1
  427. package/dist/utils/child-process.js +21 -1
  428. package/dist/utils/child-process.js.map +1 -1
  429. package/dist/utils/markit.d.ts +8 -0
  430. package/dist/utils/markit.d.ts.map +1 -0
  431. package/dist/utils/markit.js +53 -0
  432. package/dist/utils/markit.js.map +1 -0
  433. package/dist/utils/paths.d.ts +2 -1
  434. package/dist/utils/paths.d.ts.map +1 -1
  435. package/dist/utils/paths.js +14 -1
  436. package/dist/utils/paths.js.map +1 -1
  437. package/docs/compaction.md +16 -1
  438. package/docs/containerization.md +1 -1
  439. package/docs/docs.json +1 -0
  440. package/docs/extensions.md +25 -36
  441. package/docs/quickstart.md +11 -6
  442. package/docs/sdk.md +5 -5
  443. package/docs/settings.md +7 -0
  444. package/docs/subagents.md +3 -2
  445. package/docs/tools.md +49 -0
  446. package/docs/usage.md +3 -3
  447. package/docs/workflows.md +7 -5
  448. package/examples/extensions/subagent/README.md +5 -5
  449. package/examples/extensions/subagent/agents/planner.md +1 -1
  450. package/examples/extensions/subagent/agents/reviewer.md +1 -1
  451. package/examples/extensions/subagent/agents/scout.md +2 -2
  452. package/examples/extensions/subagent/display.ts +3 -3
  453. package/examples/sdk/05-tools.ts +3 -3
  454. package/examples/sdk/README.md +1 -1
  455. package/package.json +3 -2
@@ -2,7 +2,7 @@ export { createBashTool, createBashToolDefinition, createLocalBashOperations, }
2
2
  export { createEditTool, createEditToolDefinition, } from "./edit.js";
3
3
  export { withFileMutationQueue } from "./file-mutation-queue.js";
4
4
  export { createFindTool, createFindToolDefinition, } from "./find.js";
5
- export { createGrepTool, createGrepToolDefinition, } from "./grep.js";
5
+ export { createSearchTool, createSearchToolDefinition, } from "./search.js";
6
6
  export { createLsTool, createLsToolDefinition, } from "./ls.js";
7
7
  export { createReadTool, createReadToolDefinition, } from "./read.js";
8
8
  export { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead, truncateLine, truncateTail, } from "./truncate.js";
@@ -11,11 +11,12 @@ export { createAskUserQuestionToolDefinition } from "./ask-user-question/index.j
11
11
  export { STRUCTURED_OUTPUT_TOOL_NAME, createStructuredOutputCapture, createStructuredOutputTool, } from "./structured-output.js";
12
12
  export { createTodoToolDefinition } from "./todos.js";
13
13
  import { createAskUserQuestionToolDefinition } from "./ask-user-question/index.js";
14
+ import { createHashlineSnapshotStore } from "./hashline.js";
14
15
  import { createBashTool, createBashToolDefinition } from "./bash.js";
15
16
  import { createEditTool, createEditToolDefinition } from "./edit.js";
16
17
  import { createFindTool, createFindToolDefinition } from "./find.js";
17
- import { createGrepTool, createGrepToolDefinition } from "./grep.js";
18
18
  import { createLsTool, createLsToolDefinition } from "./ls.js";
19
+ import { createSearchTool, createSearchToolDefinition } from "./search.js";
19
20
  import { createReadTool, createReadToolDefinition } from "./read.js";
20
21
  import { createTodoToolDefinition } from "./todos.js";
21
22
  import { wrapToolDefinition } from "./tool-definition-wrapper.js";
@@ -25,8 +26,8 @@ export const allToolNames = new Set([
25
26
  "bash",
26
27
  "edit",
27
28
  "write",
28
- "grep",
29
29
  "find",
30
+ "search",
30
31
  "ls",
31
32
  "ask_user_question",
32
33
  "todo",
@@ -36,23 +37,28 @@ export const defaultToolNames = [
36
37
  "bash",
37
38
  "edit",
38
39
  "write",
40
+ "find",
41
+ "search",
39
42
  "ask_user_question",
40
43
  "todo",
41
44
  ];
42
45
  export function createToolDefinition(toolName, cwd, options) {
46
+ // Default a shared store so the singular factories don't hand read/edit/
47
+ // write/search isolated stores (which silently degrades drift recovery).
48
+ const hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();
43
49
  switch (toolName) {
44
50
  case "read":
45
- return createReadToolDefinition(cwd, options?.read);
51
+ return createReadToolDefinition(cwd, { ...options?.read, hashlineStore });
46
52
  case "bash":
47
53
  return createBashToolDefinition(cwd, options?.bash);
48
54
  case "edit":
49
- return createEditToolDefinition(cwd, options?.edit);
55
+ return createEditToolDefinition(cwd, { ...options?.edit, hashlineStore });
50
56
  case "write":
51
- return createWriteToolDefinition(cwd, options?.write);
52
- case "grep":
53
- return createGrepToolDefinition(cwd, options?.grep);
57
+ return createWriteToolDefinition(cwd, { ...options?.write, hashlineStore });
54
58
  case "find":
55
59
  return createFindToolDefinition(cwd, options?.find);
60
+ case "search":
61
+ return createSearchToolDefinition(cwd, { ...options?.search, hashlineStore });
56
62
  case "ls":
57
63
  return createLsToolDefinition(cwd, options?.ls);
58
64
  case "ask_user_question":
@@ -64,19 +70,20 @@ export function createToolDefinition(toolName, cwd, options) {
64
70
  }
65
71
  }
66
72
  export function createTool(toolName, cwd, options) {
73
+ const hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();
67
74
  switch (toolName) {
68
75
  case "read":
69
- return createReadTool(cwd, options?.read);
76
+ return createReadTool(cwd, { ...options?.read, hashlineStore });
70
77
  case "bash":
71
78
  return createBashTool(cwd, options?.bash);
72
79
  case "edit":
73
- return createEditTool(cwd, options?.edit);
80
+ return createEditTool(cwd, { ...options?.edit, hashlineStore });
74
81
  case "write":
75
- return createWriteTool(cwd, options?.write);
76
- case "grep":
77
- return createGrepTool(cwd, options?.grep);
82
+ return createWriteTool(cwd, { ...options?.write, hashlineStore });
78
83
  case "find":
79
84
  return createFindTool(cwd, options?.find);
85
+ case "search":
86
+ return createSearchTool(cwd, { ...options?.search, hashlineStore });
80
87
  case "ls":
81
88
  return createLsTool(cwd, options?.ls);
82
89
  case "ask_user_question":
@@ -88,58 +95,68 @@ export function createTool(toolName, cwd, options) {
88
95
  }
89
96
  }
90
97
  export function createCodingToolDefinitions(cwd, options) {
98
+ const hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();
91
99
  return [
92
- createReadToolDefinition(cwd, options?.read),
93
- createBashToolDefinition(cwd, options?.bash),
94
- createEditToolDefinition(cwd, options?.edit),
95
- createWriteToolDefinition(cwd, options?.write),
100
+ createReadToolDefinition(cwd, { ...options?.read, hashlineStore }),
101
+ createBashToolDefinition(cwd, { asyncEnabled: true, ...options?.bash }),
102
+ createEditToolDefinition(cwd, { ...options?.edit, hashlineStore }),
103
+ createWriteToolDefinition(cwd, { ...options?.write, hashlineStore }),
104
+ createFindToolDefinition(cwd, options?.find),
105
+ createSearchToolDefinition(cwd, { ...options?.search, hashlineStore }),
96
106
  ];
97
107
  }
98
108
  export function createReadOnlyToolDefinitions(cwd, options) {
109
+ const hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();
99
110
  return [
100
- createReadToolDefinition(cwd, options?.read),
101
- createGrepToolDefinition(cwd, options?.grep),
111
+ createReadToolDefinition(cwd, { ...options?.read, hashlineStore }),
102
112
  createFindToolDefinition(cwd, options?.find),
113
+ createSearchToolDefinition(cwd, { ...options?.search, hashlineStore }),
103
114
  createLsToolDefinition(cwd, options?.ls),
104
115
  ];
105
116
  }
106
117
  export function createAllToolDefinitions(cwd, options) {
118
+ const hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();
107
119
  return {
108
- read: createReadToolDefinition(cwd, options?.read),
109
- bash: createBashToolDefinition(cwd, options?.bash),
110
- edit: createEditToolDefinition(cwd, options?.edit),
111
- write: createWriteToolDefinition(cwd, options?.write),
112
- grep: createGrepToolDefinition(cwd, options?.grep),
120
+ read: createReadToolDefinition(cwd, { ...options?.read, hashlineStore }),
121
+ bash: createBashToolDefinition(cwd, { asyncEnabled: true, ...options?.bash }),
122
+ edit: createEditToolDefinition(cwd, { ...options?.edit, hashlineStore }),
123
+ write: createWriteToolDefinition(cwd, { ...options?.write, hashlineStore }),
113
124
  find: createFindToolDefinition(cwd, options?.find),
125
+ search: createSearchToolDefinition(cwd, { ...options?.search, hashlineStore }),
114
126
  ls: createLsToolDefinition(cwd, options?.ls),
115
127
  ask_user_question: createAskUserQuestionToolDefinition(),
116
128
  todo: createTodoToolDefinition(cwd),
117
129
  };
118
130
  }
119
131
  export function createCodingTools(cwd, options) {
132
+ const hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();
120
133
  return [
121
- createReadTool(cwd, options?.read),
122
- createBashTool(cwd, options?.bash),
123
- createEditTool(cwd, options?.edit),
124
- createWriteTool(cwd, options?.write),
134
+ createReadTool(cwd, { ...options?.read, hashlineStore }),
135
+ createBashTool(cwd, { asyncEnabled: true, ...options?.bash }),
136
+ createEditTool(cwd, { ...options?.edit, hashlineStore }),
137
+ createWriteTool(cwd, { ...options?.write, hashlineStore }),
138
+ createFindTool(cwd, options?.find),
139
+ createSearchTool(cwd, { ...options?.search, hashlineStore }),
125
140
  ];
126
141
  }
127
142
  export function createReadOnlyTools(cwd, options) {
143
+ const hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();
128
144
  return [
129
- createReadTool(cwd, options?.read),
130
- createGrepTool(cwd, options?.grep),
145
+ createReadTool(cwd, { ...options?.read, hashlineStore }),
131
146
  createFindTool(cwd, options?.find),
147
+ createSearchTool(cwd, { ...options?.search, hashlineStore }),
132
148
  createLsTool(cwd, options?.ls),
133
149
  ];
134
150
  }
135
151
  export function createAllTools(cwd, options) {
152
+ const hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();
136
153
  return {
137
- read: createReadTool(cwd, options?.read),
138
- bash: createBashTool(cwd, options?.bash),
139
- edit: createEditTool(cwd, options?.edit),
140
- write: createWriteTool(cwd, options?.write),
141
- grep: createGrepTool(cwd, options?.grep),
154
+ read: createReadTool(cwd, { ...options?.read, hashlineStore }),
155
+ bash: createBashTool(cwd, { asyncEnabled: true, ...options?.bash }),
156
+ edit: createEditTool(cwd, { ...options?.edit, hashlineStore }),
157
+ write: createWriteTool(cwd, { ...options?.write, hashlineStore }),
142
158
  find: createFindTool(cwd, options?.find),
159
+ search: createSearchTool(cwd, { ...options?.search, hashlineStore }),
143
160
  ls: createLsTool(cwd, options?.ls),
144
161
  ask_user_question: wrapToolDefinition(createAskUserQuestionToolDefinition()),
145
162
  todo: wrapToolDefinition(createTodoToolDefinition(cwd)),
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,cAAc,EACd,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,wBAAwB,GAKxB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,YAAY,EACZ,s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E,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;KAC9B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAsB;IACjE,OAAO;QACN,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,KAAK,EAAE,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC;QAC3C,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,EAAE,EAAE,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;QAClC,iBAAiB,EAAE,kBAAkB,CAAC,mCAAmC,EAAE,CAAC;QAC5E,IAAI,EAAE,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC;KACvD,CAAC;AACH,CAAC","sourcesContent":["export {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.ts\";\nexport {\n\tcreateGrepTool,\n\tcreateGrepToolDefinition,\n\ttype GrepOperations,\n\ttype GrepToolDetails,\n\ttype GrepToolInput,\n\ttype GrepToolOptions,\n} from \"./grep.ts\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.ts\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.ts\";\nexport { createAskUserQuestionToolDefinition } from \"./ask-user-question/index.ts\";\nexport {\n\tSTRUCTURED_OUTPUT_TOOL_NAME,\n\tcreateStructuredOutputCapture,\n\tcreateStructuredOutputTool,\n\ttype JsonObject,\n\ttype JsonPrimitive,\n\ttype JsonValue,\n\ttype StructuredOutputCapture,\n\ttype StructuredOutputFileCapture,\n\ttype StructuredOutputToolOptions,\n} from \"./structured-output.ts\";\nexport { createTodoToolDefinition } from \"./todos.ts\";\n\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { TSchema } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { createAskUserQuestionToolDefinition } from \"./ask-user-question/index.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.ts\";\nimport { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from \"./grep.ts\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createTodoToolDefinition } from \"./todos.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport type Tool = AgentTool<TSchema, unknown>;\nexport type ToolDef = ToolDefinition<TSchema, unknown>;\nexport type ToolName =\n\t| \"read\"\n\t| \"bash\"\n\t| \"edit\"\n\t| \"write\"\n\t| \"grep\"\n\t| \"find\"\n\t| \"ls\"\n\t| \"ask_user_question\"\n\t| \"todo\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"ask_user_question\",\n\t\"todo\",\n]);\n\nexport const defaultToolNames: readonly ToolName[] = [\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"ask_user_question\",\n\t\"todo\",\n];\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tgrep?: GrepToolOptions;\n\tfind?: FindToolOptions;\n\tls?: LsToolOptions;\n}\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadToolDefinition(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashToolDefinition(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditToolDefinition(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteToolDefinition(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepToolDefinition(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindToolDefinition(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsToolDefinition(cwd, options?.ls);\n\t\tcase \"ask_user_question\":\n\t\t\treturn createAskUserQuestionToolDefinition();\n\t\tcase \"todo\":\n\t\t\treturn createTodoToolDefinition(cwd);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool {\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadTool(cwd, options?.read);\n\t\tcase \"bash\":\n\t\t\treturn createBashTool(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditTool(cwd, options?.edit);\n\t\tcase \"write\":\n\t\t\treturn createWriteTool(cwd, options?.write);\n\t\tcase \"grep\":\n\t\t\treturn createGrepTool(cwd, options?.grep);\n\t\tcase \"find\":\n\t\t\treturn createFindTool(cwd, options?.find);\n\t\tcase \"ls\":\n\t\t\treturn createLsTool(cwd, options?.ls);\n\t\tcase \"ask_user_question\":\n\t\t\treturn wrapToolDefinition(createAskUserQuestionToolDefinition());\n\t\tcase \"todo\":\n\t\t\treturn wrapToolDefinition(createTodoToolDefinition(cwd));\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateBashToolDefinition(cwd, options?.bash),\n\t\tcreateEditToolDefinition(cwd, options?.edit),\n\t\tcreateWriteToolDefinition(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\treturn [\n\t\tcreateReadToolDefinition(cwd, options?.read),\n\t\tcreateGrepToolDefinition(cwd, options?.grep),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nexport function createAllToolDefinitions(cwd: string, options?: ToolsOptions): Record<ToolName, ToolDef> {\n\treturn {\n\t\tread: createReadToolDefinition(cwd, options?.read),\n\t\tbash: createBashToolDefinition(cwd, options?.bash),\n\t\tedit: createEditToolDefinition(cwd, options?.edit),\n\t\twrite: createWriteToolDefinition(cwd, options?.write),\n\t\tgrep: createGrepToolDefinition(cwd, options?.grep),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t\task_user_question: createAskUserQuestionToolDefinition(),\n\t\ttodo: createTodoToolDefinition(cwd),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateBashTool(cwd, options?.bash),\n\t\tcreateEditTool(cwd, options?.edit),\n\t\tcreateWriteTool(cwd, options?.write),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\treturn [\n\t\tcreateReadTool(cwd, options?.read),\n\t\tcreateGrepTool(cwd, options?.grep),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> {\n\treturn {\n\t\tread: createReadTool(cwd, options?.read),\n\t\tbash: createBashTool(cwd, options?.bash),\n\t\tedit: createEditTool(cwd, options?.edit),\n\t\twrite: createWriteTool(cwd, options?.write),\n\t\tgrep: createGrepTool(cwd, options?.grep),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\task_user_question: wrapToolDefinition(createAskUserQuestionToolDefinition()),\n\t\ttodo: wrapToolDefinition(createTodoToolDefinition(cwd)),\n\t};\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAA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,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC;QACnE,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;QAC9D,KAAK,EAAE,eAAe,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;QACjE,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,MAAM,EAAE,gBAAgB,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;QACpE,EAAE,EAAE,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;QAClC,iBAAiB,EAAE,kBAAkB,CAAC,mCAAmC,EAAE,CAAC;QAC5E,IAAI,EAAE,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC;KACvD,CAAC;AACH,CAAC","sourcesContent":["export {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tcreateBashTool,\n\tcreateBashToolDefinition,\n\tcreateLocalBashOperations,\n} from \"./bash.ts\";\nexport {\n\tcreateEditTool,\n\tcreateEditToolDefinition,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n} from \"./edit.ts\";\nexport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nexport {\n\tcreateFindTool,\n\tcreateFindToolDefinition,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n} from \"./find.ts\";\nexport {\n\tcreateSearchTool,\n\tcreateSearchToolDefinition,\n\ttype SearchToolDetails,\n\ttype SearchToolInput,\n\ttype SearchToolOptions,\n} from \"./search.ts\";\nexport {\n\tcreateLsTool,\n\tcreateLsToolDefinition,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n} from \"./ls.ts\";\nexport {\n\tcreateReadTool,\n\tcreateReadToolDefinition,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n} from \"./read.ts\";\nexport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\tformatSize,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n} from \"./truncate.ts\";\nexport {\n\tcreateWriteTool,\n\tcreateWriteToolDefinition,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n} from \"./write.ts\";\nexport { createAskUserQuestionToolDefinition } from \"./ask-user-question/index.ts\";\nexport {\n\tSTRUCTURED_OUTPUT_TOOL_NAME,\n\tcreateStructuredOutputCapture,\n\tcreateStructuredOutputTool,\n\ttype JsonObject,\n\ttype JsonPrimitive,\n\ttype JsonValue,\n\ttype StructuredOutputCapture,\n\ttype StructuredOutputFileCapture,\n\ttype StructuredOutputToolOptions,\n} from \"./structured-output.ts\";\nexport { createTodoToolDefinition } from \"./todos.ts\";\n\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { TSchema } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { createAskUserQuestionToolDefinition } from \"./ask-user-question/index.ts\";\nimport { createHashlineSnapshotStore, type HashlineSnapshotStore } from \"./hashline.ts\";\nimport { type BashToolOptions, createBashTool, createBashToolDefinition } from \"./bash.ts\";\nimport { createEditTool, createEditToolDefinition, type EditToolOptions } from \"./edit.ts\";\nimport { createFindTool, createFindToolDefinition, type FindToolOptions } from \"./find.ts\";\nimport { createLsTool, createLsToolDefinition, type LsToolOptions } from \"./ls.ts\";\nimport { createSearchTool, createSearchToolDefinition, type SearchToolOptions } from \"./search.ts\";\nimport { createReadTool, createReadToolDefinition, type ReadToolOptions } from \"./read.ts\";\nimport { createTodoToolDefinition } from \"./todos.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from \"./write.ts\";\n\nexport type Tool = AgentTool<TSchema, unknown>;\nexport type ToolDef = ToolDefinition<TSchema, unknown>;\nexport type ToolName =\n\t| \"read\"\n\t| \"bash\"\n\t| \"edit\"\n\t| \"write\"\n\t| \"find\"\n\t| \"search\"\n\t| \"ls\"\n\t| \"ask_user_question\"\n\t| \"todo\";\nexport const allToolNames: Set<ToolName> = new Set([\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"find\",\n\t\"search\",\n\t\"ls\",\n\t\"ask_user_question\",\n\t\"todo\",\n]);\n\nexport const defaultToolNames: readonly ToolName[] = [\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"find\",\n\t\"search\",\n\t\"ask_user_question\",\n\t\"todo\",\n];\n\nexport interface ToolsOptions {\n\tread?: ReadToolOptions;\n\tbash?: BashToolOptions;\n\twrite?: WriteToolOptions;\n\tedit?: EditToolOptions;\n\tfind?: FindToolOptions;\n\tsearch?: SearchToolOptions;\n\tls?: LsToolOptions;\n\thashlineStore?: HashlineSnapshotStore;\n}\n\nexport function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {\n\t// Default a shared store so the singular factories don't hand read/edit/\n\t// write/search isolated stores (which silently degrades drift recovery).\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadToolDefinition(cwd, { ...options?.read, hashlineStore });\n\t\tcase \"bash\":\n\t\t\treturn createBashToolDefinition(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditToolDefinition(cwd, { ...options?.edit, hashlineStore });\n\t\tcase \"write\":\n\t\t\treturn createWriteToolDefinition(cwd, { ...options?.write, hashlineStore });\n\t\tcase \"find\":\n\t\t\treturn createFindToolDefinition(cwd, options?.find);\n\t\tcase \"search\":\n\t\t\treturn createSearchToolDefinition(cwd, { ...options?.search, hashlineStore });\n\t\tcase \"ls\":\n\t\t\treturn createLsToolDefinition(cwd, options?.ls);\n\t\tcase \"ask_user_question\":\n\t\t\treturn createAskUserQuestionToolDefinition();\n\t\tcase \"todo\":\n\t\t\treturn createTodoToolDefinition(cwd);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool {\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\tswitch (toolName) {\n\t\tcase \"read\":\n\t\t\treturn createReadTool(cwd, { ...options?.read, hashlineStore });\n\t\tcase \"bash\":\n\t\t\treturn createBashTool(cwd, options?.bash);\n\t\tcase \"edit\":\n\t\t\treturn createEditTool(cwd, { ...options?.edit, hashlineStore });\n\t\tcase \"write\":\n\t\t\treturn createWriteTool(cwd, { ...options?.write, hashlineStore });\n\t\tcase \"find\":\n\t\t\treturn createFindTool(cwd, options?.find);\n\t\tcase \"search\":\n\t\t\treturn createSearchTool(cwd, { ...options?.search, hashlineStore });\n\t\tcase \"ls\":\n\t\t\treturn createLsTool(cwd, options?.ls);\n\t\tcase \"ask_user_question\":\n\t\t\treturn wrapToolDefinition(createAskUserQuestionToolDefinition());\n\t\tcase \"todo\":\n\t\t\treturn wrapToolDefinition(createTodoToolDefinition(cwd));\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown tool name: ${toolName}`);\n\t}\n}\n\nexport function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\treturn [\n\t\tcreateReadToolDefinition(cwd, { ...options?.read, hashlineStore }),\n\t\tcreateBashToolDefinition(cwd, { asyncEnabled: true, ...options?.bash }),\n\t\tcreateEditToolDefinition(cwd, { ...options?.edit, hashlineStore }),\n\t\tcreateWriteToolDefinition(cwd, { ...options?.write, hashlineStore }),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateSearchToolDefinition(cwd, { ...options?.search, hashlineStore }),\n\t];\n}\n\nexport function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\treturn [\n\t\tcreateReadToolDefinition(cwd, { ...options?.read, hashlineStore }),\n\t\tcreateFindToolDefinition(cwd, options?.find),\n\t\tcreateSearchToolDefinition(cwd, { ...options?.search, hashlineStore }),\n\t\tcreateLsToolDefinition(cwd, options?.ls),\n\t];\n}\n\nexport function createAllToolDefinitions(cwd: string, options?: ToolsOptions): Record<ToolName, ToolDef> {\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\treturn {\n\t\tread: createReadToolDefinition(cwd, { ...options?.read, hashlineStore }),\n\t\tbash: createBashToolDefinition(cwd, { asyncEnabled: true, ...options?.bash }),\n\t\tedit: createEditToolDefinition(cwd, { ...options?.edit, hashlineStore }),\n\t\twrite: createWriteToolDefinition(cwd, { ...options?.write, hashlineStore }),\n\t\tfind: createFindToolDefinition(cwd, options?.find),\n\t\tsearch: createSearchToolDefinition(cwd, { ...options?.search, hashlineStore }),\n\t\tls: createLsToolDefinition(cwd, options?.ls),\n\t\task_user_question: createAskUserQuestionToolDefinition(),\n\t\ttodo: createTodoToolDefinition(cwd),\n\t};\n}\n\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\treturn [\n\t\tcreateReadTool(cwd, { ...options?.read, hashlineStore }),\n\t\tcreateBashTool(cwd, { asyncEnabled: true, ...options?.bash }),\n\t\tcreateEditTool(cwd, { ...options?.edit, hashlineStore }),\n\t\tcreateWriteTool(cwd, { ...options?.write, hashlineStore }),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateSearchTool(cwd, { ...options?.search, hashlineStore }),\n\t];\n}\n\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\treturn [\n\t\tcreateReadTool(cwd, { ...options?.read, hashlineStore }),\n\t\tcreateFindTool(cwd, options?.find),\n\t\tcreateSearchTool(cwd, { ...options?.search, hashlineStore }),\n\t\tcreateLsTool(cwd, options?.ls),\n\t];\n}\n\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> {\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\treturn {\n\t\tread: createReadTool(cwd, { ...options?.read, hashlineStore }),\n\t\tbash: createBashTool(cwd, { asyncEnabled: true, ...options?.bash }),\n\t\tedit: createEditTool(cwd, { ...options?.edit, hashlineStore }),\n\t\twrite: createWriteTool(cwd, { ...options?.write, hashlineStore }),\n\t\tfind: createFindTool(cwd, options?.find),\n\t\tsearch: createSearchTool(cwd, { ...options?.search, hashlineStore }),\n\t\tls: createLsTool(cwd, options?.ls),\n\t\task_user_question: wrapToolDefinition(createAskUserQuestionToolDefinition()),\n\t\ttodo: wrapToolDefinition(createTodoToolDefinition(cwd)),\n\t};\n}\n"]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Editable notebook projection, mirrored from oh-my-pi's
3
+ * `packages/coding-agent/src/edit/notebook.ts` at 15b5c1397fc.
4
+ *
5
+ * A notebook is projected to an editable text form using cell markers:
6
+ *
7
+ * # %% [code|markdown|raw] cell:<index>
8
+ *
9
+ * Source lines that themselves look like a cell marker are escaped by adding
10
+ * one extra `%`. Edits applied to the projected text are mapped back to the
11
+ * underlying notebook JSON, preserving cell metadata/outputs/execution counts.
12
+ */
13
+ export type NotebookCellType = "code" | "markdown" | "raw";
14
+ export interface NotebookCell {
15
+ cell_type: NotebookCellType;
16
+ source?: string | string[];
17
+ metadata?: Record<string, unknown>;
18
+ execution_count?: number | null;
19
+ outputs?: unknown[];
20
+ [key: string]: unknown;
21
+ }
22
+ export interface NotebookDocument {
23
+ cells: NotebookCell[];
24
+ metadata: Record<string, unknown>;
25
+ nbformat: number;
26
+ nbformat_minor: number;
27
+ [key: string]: unknown;
28
+ }
29
+ export declare function isNotebookPath(absolutePath: string): boolean;
30
+ export declare function cellSourceToString(source: NotebookCell["source"]): string;
31
+ export declare function splitNotebookSource(content: string): string[];
32
+ export declare function emptyNotebook(): NotebookDocument;
33
+ export declare function newNotebookCell(cellType: NotebookCellType, source: string): NotebookCell;
34
+ export declare function notebookToEditableText(notebook: NotebookDocument): string;
35
+ export declare function applyNotebookEditableText(notebook: NotebookDocument, text: string, displayPath: string): NotebookDocument;
36
+ export declare function readEditableNotebookText(absolutePath: string, displayPath: string): string;
37
+ export declare function serializeEditedNotebookText(absolutePath: string, displayPath: string, text: string): string;
38
+ //# sourceMappingURL=notebook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notebook.d.ts","sourceRoot":"","sources":["../../../src/core/tools/notebook.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC;AAE3D,MAAM,WAAW,YAAY;IAC5B,SAAS,EAAE,gBAAgB,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAMD,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAE5D;AAYD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,MAAM,CAIzE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAE7D;AAED,wBAAgB,aAAa,IAAI,gBAAgB,CAEhD;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAIxF;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAQzE;AAkCD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,gBAAgB,CAyBzH;AAED,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAG1F;AAED,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI3G","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\n\n/**\n * Editable notebook projection, mirrored from oh-my-pi's\n * `packages/coding-agent/src/edit/notebook.ts` at 15b5c1397fc.\n *\n * A notebook is projected to an editable text form using cell markers:\n *\n * # %% [code|markdown|raw] cell:<index>\n *\n * Source lines that themselves look like a cell marker are escaped by adding\n * one extra `%`. Edits applied to the projected text are mapped back to the\n * underlying notebook JSON, preserving cell metadata/outputs/execution counts.\n */\n\nexport type NotebookCellType = \"code\" | \"markdown\" | \"raw\";\n\nexport interface NotebookCell {\n\tcell_type: NotebookCellType;\n\tsource?: string | string[];\n\tmetadata?: Record<string, unknown>;\n\texecution_count?: number | null;\n\toutputs?: unknown[];\n\t[key: string]: unknown;\n}\n\nexport interface NotebookDocument {\n\tcells: NotebookCell[];\n\tmetadata: Record<string, unknown>;\n\tnbformat: number;\n\tnbformat_minor: number;\n\t[key: string]: unknown;\n}\n\nconst CELL_MARKER_RE = /^# %% \\[(code|markdown|raw)\\](?: cell:(\\d+))?$/;\nconst ESCAPABLE_MARKER_RE = /^# %%+ \\[(?:code|markdown|raw)\\](?: cell:\\d+)?$/;\nconst ESCAPED_MARKER_RE = /^# %%%+ \\[(?:code|markdown|raw)\\](?: cell:\\d+)?$/;\n\nexport function isNotebookPath(absolutePath: string): boolean {\n\treturn /\\.ipynb$/i.test(absolutePath);\n}\n\nfunction escapeMarkerLikeSourceLine(line: string): string {\n\tif (ESCAPABLE_MARKER_RE.test(line)) return `${line.slice(0, 2)}%${line.slice(2)}`;\n\treturn line;\n}\n\nfunction unescapeMarkerLikeSourceLine(line: string): string {\n\tif (ESCAPED_MARKER_RE.test(line)) return `${line.slice(0, 2)}${line.slice(3)}`;\n\treturn line;\n}\n\nexport function cellSourceToString(source: NotebookCell[\"source\"]): string {\n\tif (source === undefined) return \"\";\n\tif (typeof source === \"string\") return source;\n\treturn source.join(\"\");\n}\n\nexport function splitNotebookSource(content: string): string[] {\n\treturn content.match(/[^\\n]*\\n|[^\\n]+$/g) ?? [];\n}\n\nexport function emptyNotebook(): NotebookDocument {\n\treturn { cells: [], metadata: {}, nbformat: 4, nbformat_minor: 5 };\n}\n\nexport function newNotebookCell(cellType: NotebookCellType, source: string): NotebookCell {\n\tconst cell: NotebookCell = { cell_type: cellType, metadata: {}, source: splitNotebookSource(source) };\n\tif (cellType === \"code\") { cell.execution_count = null; cell.outputs = []; }\n\treturn cell;\n}\n\nexport function notebookToEditableText(notebook: NotebookDocument): string {\n\tconst lines: string[] = [];\n\tfor (const [index, cell] of notebook.cells.entries()) {\n\t\tconst source = cellSourceToString(cell.source);\n\t\tlines.push(`# %% [${cell.cell_type}] cell:${index}`);\n\t\tif (source !== \"\") for (const line of source.split(\"\\n\")) lines.push(escapeMarkerLikeSourceLine(line));\n\t}\n\treturn lines.join(\"\\n\");\n}\n\ninterface ParsedVirtualCell {\n\tcellType: NotebookCellType;\n\tcellIndex?: number;\n\tsource: string;\n}\n\nfunction parseNotebookEditableText(text: string, displayPath: string): ParsedVirtualCell[] {\n\tconst lines = text.split(\"\\n\");\n\tconst cells: ParsedVirtualCell[] = [];\n\tlet current: ParsedVirtualCell | null = null;\n\tlet sawMarker = false;\n\tfor (const line of lines) {\n\t\tconst match = line.match(CELL_MARKER_RE);\n\t\tif (match) {\n\t\t\tsawMarker = true;\n\t\t\tconst cellType = (match[1] ?? \"raw\") as NotebookCellType;\n\t\t\tconst cellIndex = match[2] !== undefined ? Number.parseInt(match[2], 10) : undefined;\n\t\t\tcurrent = { cellType, cellIndex, source: \"\" };\n\t\t\tcells.push(current);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!sawMarker) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid notebook editable representation for ${displayPath}: expected first line to be \"# %% [code] cell:0\", \"# %% [markdown] cell:0\", or \"# %% [raw] cell:0\".`,\n\t\t\t);\n\t\t}\n\t\tconst restored = unescapeMarkerLikeSourceLine(line);\n\t\tcurrent!.source = current!.source === \"\" ? restored : `${current!.source}\\n${restored}`;\n\t}\n\treturn cells;\n}\n\nexport function applyNotebookEditableText(notebook: NotebookDocument, text: string, displayPath: string): NotebookDocument {\n\tconst parsed = parseNotebookEditableText(text, displayPath);\n\tconst next = structuredClone(notebook) as NotebookDocument;\n\tconst used = new Set<number>();\n\tnext.cells = parsed.map((parsedCell) => {\n\t\tlet cell: NotebookCell;\n\t\tconst cellIndex = parsedCell.cellIndex;\n\t\tif (cellIndex !== undefined && cellIndex >= 0 && cellIndex < notebook.cells.length && !used.has(cellIndex)) {\n\t\t\tused.add(cellIndex);\n\t\t\tcell = structuredClone(notebook.cells[cellIndex]!) as NotebookCell;\n\t\t} else {\n\t\t\tcell = newNotebookCell(parsedCell.cellType, \"\");\n\t\t}\n\t\tcell.cell_type = parsedCell.cellType;\n\t\tcell.source = splitNotebookSource(parsedCell.source);\n\t\tif (parsedCell.cellType === \"code\") {\n\t\t\tif (cell.execution_count === undefined) cell.execution_count = null;\n\t\t\tif (cell.outputs === undefined) cell.outputs = [];\n\t\t} else {\n\t\t\tdelete cell.execution_count;\n\t\t\tdelete cell.outputs;\n\t\t}\n\t\treturn cell;\n\t});\n\treturn next;\n}\n\nexport function readEditableNotebookText(absolutePath: string, displayPath: string): string {\n\tconst notebook = existsSync(absolutePath) ? parseNotebookSafe(readFileSync(absolutePath, \"utf8\"), displayPath) : emptyNotebook();\n\treturn notebookToEditableText(notebook);\n}\n\nexport function serializeEditedNotebookText(absolutePath: string, displayPath: string, text: string): string {\n\tconst notebook = existsSync(absolutePath) ? parseNotebookSafe(readFileSync(absolutePath, \"utf8\"), displayPath) : emptyNotebook();\n\tconst next = applyNotebookEditableText(notebook, text, displayPath);\n\treturn JSON.stringify(next, null, 1);\n}\n\nfunction parseNotebookSafe(raw: string, displayPath: string): NotebookDocument {\n\tlet parsed: unknown;\n\ttry { parsed = JSON.parse(raw); } catch { throw new Error(`Invalid notebook JSON for ${displayPath}`); }\n\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) throw new Error(`Invalid notebook JSON for ${displayPath}`);\n\tconst doc = parsed as Partial<NotebookDocument>;\n\treturn { ...doc, cells: Array.isArray(doc.cells) ? doc.cells as NotebookCell[] : [], metadata: (doc.metadata ?? {}) as Record<string, unknown>, nbformat: doc.nbformat ?? 4, nbformat_minor: doc.nbformat_minor ?? 5 };\n}\n"]}
@@ -0,0 +1,125 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ const CELL_MARKER_RE = /^# %% \[(code|markdown|raw)\](?: cell:(\d+))?$/;
3
+ const ESCAPABLE_MARKER_RE = /^# %%+ \[(?:code|markdown|raw)\](?: cell:\d+)?$/;
4
+ const ESCAPED_MARKER_RE = /^# %%%+ \[(?:code|markdown|raw)\](?: cell:\d+)?$/;
5
+ export function isNotebookPath(absolutePath) {
6
+ return /\.ipynb$/i.test(absolutePath);
7
+ }
8
+ function escapeMarkerLikeSourceLine(line) {
9
+ if (ESCAPABLE_MARKER_RE.test(line))
10
+ return `${line.slice(0, 2)}%${line.slice(2)}`;
11
+ return line;
12
+ }
13
+ function unescapeMarkerLikeSourceLine(line) {
14
+ if (ESCAPED_MARKER_RE.test(line))
15
+ return `${line.slice(0, 2)}${line.slice(3)}`;
16
+ return line;
17
+ }
18
+ export function cellSourceToString(source) {
19
+ if (source === undefined)
20
+ return "";
21
+ if (typeof source === "string")
22
+ return source;
23
+ return source.join("");
24
+ }
25
+ export function splitNotebookSource(content) {
26
+ return content.match(/[^\n]*\n|[^\n]+$/g) ?? [];
27
+ }
28
+ export function emptyNotebook() {
29
+ return { cells: [], metadata: {}, nbformat: 4, nbformat_minor: 5 };
30
+ }
31
+ export function newNotebookCell(cellType, source) {
32
+ const cell = { cell_type: cellType, metadata: {}, source: splitNotebookSource(source) };
33
+ if (cellType === "code") {
34
+ cell.execution_count = null;
35
+ cell.outputs = [];
36
+ }
37
+ return cell;
38
+ }
39
+ export function notebookToEditableText(notebook) {
40
+ const lines = [];
41
+ for (const [index, cell] of notebook.cells.entries()) {
42
+ const source = cellSourceToString(cell.source);
43
+ lines.push(`# %% [${cell.cell_type}] cell:${index}`);
44
+ if (source !== "")
45
+ for (const line of source.split("\n"))
46
+ lines.push(escapeMarkerLikeSourceLine(line));
47
+ }
48
+ return lines.join("\n");
49
+ }
50
+ function parseNotebookEditableText(text, displayPath) {
51
+ const lines = text.split("\n");
52
+ const cells = [];
53
+ let current = null;
54
+ let sawMarker = false;
55
+ for (const line of lines) {
56
+ const match = line.match(CELL_MARKER_RE);
57
+ if (match) {
58
+ sawMarker = true;
59
+ const cellType = (match[1] ?? "raw");
60
+ const cellIndex = match[2] !== undefined ? Number.parseInt(match[2], 10) : undefined;
61
+ current = { cellType, cellIndex, source: "" };
62
+ cells.push(current);
63
+ continue;
64
+ }
65
+ if (!sawMarker) {
66
+ throw new Error(`Invalid notebook editable representation for ${displayPath}: expected first line to be "# %% [code] cell:0", "# %% [markdown] cell:0", or "# %% [raw] cell:0".`);
67
+ }
68
+ const restored = unescapeMarkerLikeSourceLine(line);
69
+ current.source = current.source === "" ? restored : `${current.source}\n${restored}`;
70
+ }
71
+ return cells;
72
+ }
73
+ export function applyNotebookEditableText(notebook, text, displayPath) {
74
+ const parsed = parseNotebookEditableText(text, displayPath);
75
+ const next = structuredClone(notebook);
76
+ const used = new Set();
77
+ next.cells = parsed.map((parsedCell) => {
78
+ let cell;
79
+ const cellIndex = parsedCell.cellIndex;
80
+ if (cellIndex !== undefined && cellIndex >= 0 && cellIndex < notebook.cells.length && !used.has(cellIndex)) {
81
+ used.add(cellIndex);
82
+ cell = structuredClone(notebook.cells[cellIndex]);
83
+ }
84
+ else {
85
+ cell = newNotebookCell(parsedCell.cellType, "");
86
+ }
87
+ cell.cell_type = parsedCell.cellType;
88
+ cell.source = splitNotebookSource(parsedCell.source);
89
+ if (parsedCell.cellType === "code") {
90
+ if (cell.execution_count === undefined)
91
+ cell.execution_count = null;
92
+ if (cell.outputs === undefined)
93
+ cell.outputs = [];
94
+ }
95
+ else {
96
+ delete cell.execution_count;
97
+ delete cell.outputs;
98
+ }
99
+ return cell;
100
+ });
101
+ return next;
102
+ }
103
+ export function readEditableNotebookText(absolutePath, displayPath) {
104
+ const notebook = existsSync(absolutePath) ? parseNotebookSafe(readFileSync(absolutePath, "utf8"), displayPath) : emptyNotebook();
105
+ return notebookToEditableText(notebook);
106
+ }
107
+ export function serializeEditedNotebookText(absolutePath, displayPath, text) {
108
+ const notebook = existsSync(absolutePath) ? parseNotebookSafe(readFileSync(absolutePath, "utf8"), displayPath) : emptyNotebook();
109
+ const next = applyNotebookEditableText(notebook, text, displayPath);
110
+ return JSON.stringify(next, null, 1);
111
+ }
112
+ function parseNotebookSafe(raw, displayPath) {
113
+ let parsed;
114
+ try {
115
+ parsed = JSON.parse(raw);
116
+ }
117
+ catch {
118
+ throw new Error(`Invalid notebook JSON for ${displayPath}`);
119
+ }
120
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
121
+ throw new Error(`Invalid notebook JSON for ${displayPath}`);
122
+ const doc = parsed;
123
+ return { ...doc, cells: Array.isArray(doc.cells) ? doc.cells : [], metadata: (doc.metadata ?? {}), nbformat: doc.nbformat ?? 4, nbformat_minor: doc.nbformat_minor ?? 5 };
124
+ }
125
+ //# sourceMappingURL=notebook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notebook.js","sourceRoot":"","sources":["../../../src/core/tools/notebook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAkCnD,MAAM,cAAc,GAAG,gDAAgD,CAAC;AACxE,MAAM,mBAAmB,GAAG,iDAAiD,CAAC;AAC9E,MAAM,iBAAiB,GAAG,kDAAkD,CAAC;AAE7E,MAAM,UAAU,cAAc,CAAC,YAAoB;IAClD,OAAO,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,0BAA0B,CAAC,IAAY;IAC/C,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAClF,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,4BAA4B,CAAC,IAAY;IACjD,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/E,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,UAAU,kBAAkB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CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,WAAW,EAAE,CAAC,CAAC;IAChI,MAAM,GAAG,GAAG,MAAmC,CAAC;IAChD,OAAO,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAuB,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAA4B,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,CAAC,EAAE,cAAc,EAAE,GAAG,CAAC,cAAc,IAAI,CAAC,EAAE,CAAC;AACxN,CAAC","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\n\n/**\n * Editable notebook projection, mirrored from oh-my-pi's\n * `packages/coding-agent/src/edit/notebook.ts` at 15b5c1397fc.\n *\n * A notebook is projected to an editable text form using cell markers:\n *\n * # %% [code|markdown|raw] cell:<index>\n *\n * Source lines that themselves look like a cell marker are escaped by adding\n * one extra `%`. Edits applied to the projected text are mapped back to the\n * underlying notebook JSON, preserving cell metadata/outputs/execution counts.\n */\n\nexport type NotebookCellType = \"code\" | \"markdown\" | \"raw\";\n\nexport interface NotebookCell {\n\tcell_type: NotebookCellType;\n\tsource?: string | string[];\n\tmetadata?: Record<string, unknown>;\n\texecution_count?: number | null;\n\toutputs?: unknown[];\n\t[key: string]: unknown;\n}\n\nexport interface NotebookDocument {\n\tcells: NotebookCell[];\n\tmetadata: Record<string, unknown>;\n\tnbformat: number;\n\tnbformat_minor: number;\n\t[key: string]: unknown;\n}\n\nconst CELL_MARKER_RE = /^# %% \\[(code|markdown|raw)\\](?: cell:(\\d+))?$/;\nconst ESCAPABLE_MARKER_RE = /^# %%+ \\[(?:code|markdown|raw)\\](?: cell:\\d+)?$/;\nconst ESCAPED_MARKER_RE = /^# %%%+ \\[(?:code|markdown|raw)\\](?: cell:\\d+)?$/;\n\nexport function isNotebookPath(absolutePath: string): boolean {\n\treturn /\\.ipynb$/i.test(absolutePath);\n}\n\nfunction escapeMarkerLikeSourceLine(line: string): string {\n\tif (ESCAPABLE_MARKER_RE.test(line)) return `${line.slice(0, 2)}%${line.slice(2)}`;\n\treturn line;\n}\n\nfunction unescapeMarkerLikeSourceLine(line: string): string {\n\tif (ESCAPED_MARKER_RE.test(line)) return `${line.slice(0, 2)}${line.slice(3)}`;\n\treturn line;\n}\n\nexport function cellSourceToString(source: NotebookCell[\"source\"]): string {\n\tif (source === undefined) return \"\";\n\tif (typeof source === \"string\") return source;\n\treturn source.join(\"\");\n}\n\nexport function splitNotebookSource(content: string): string[] {\n\treturn content.match(/[^\\n]*\\n|[^\\n]+$/g) ?? [];\n}\n\nexport function emptyNotebook(): NotebookDocument {\n\treturn { cells: [], metadata: {}, nbformat: 4, nbformat_minor: 5 };\n}\n\nexport function newNotebookCell(cellType: NotebookCellType, source: string): NotebookCell {\n\tconst cell: NotebookCell = { cell_type: cellType, metadata: {}, source: splitNotebookSource(source) };\n\tif (cellType === \"code\") { cell.execution_count = null; cell.outputs = []; }\n\treturn cell;\n}\n\nexport function notebookToEditableText(notebook: NotebookDocument): string {\n\tconst lines: string[] = [];\n\tfor (const [index, cell] of notebook.cells.entries()) {\n\t\tconst source = cellSourceToString(cell.source);\n\t\tlines.push(`# %% [${cell.cell_type}] cell:${index}`);\n\t\tif (source !== \"\") for (const line of source.split(\"\\n\")) lines.push(escapeMarkerLikeSourceLine(line));\n\t}\n\treturn lines.join(\"\\n\");\n}\n\ninterface ParsedVirtualCell {\n\tcellType: NotebookCellType;\n\tcellIndex?: number;\n\tsource: string;\n}\n\nfunction parseNotebookEditableText(text: string, displayPath: string): ParsedVirtualCell[] {\n\tconst lines = text.split(\"\\n\");\n\tconst cells: ParsedVirtualCell[] = [];\n\tlet current: ParsedVirtualCell | null = null;\n\tlet sawMarker = false;\n\tfor (const line of lines) {\n\t\tconst match = line.match(CELL_MARKER_RE);\n\t\tif (match) {\n\t\t\tsawMarker = true;\n\t\t\tconst cellType = (match[1] ?? \"raw\") as NotebookCellType;\n\t\t\tconst cellIndex = match[2] !== undefined ? Number.parseInt(match[2], 10) : undefined;\n\t\t\tcurrent = { cellType, cellIndex, source: \"\" };\n\t\t\tcells.push(current);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!sawMarker) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid notebook editable representation for ${displayPath}: expected first line to be \"# %% [code] cell:0\", \"# %% [markdown] cell:0\", or \"# %% [raw] cell:0\".`,\n\t\t\t);\n\t\t}\n\t\tconst restored = unescapeMarkerLikeSourceLine(line);\n\t\tcurrent!.source = current!.source === \"\" ? restored : `${current!.source}\\n${restored}`;\n\t}\n\treturn cells;\n}\n\nexport function applyNotebookEditableText(notebook: NotebookDocument, text: string, displayPath: string): NotebookDocument {\n\tconst parsed = parseNotebookEditableText(text, displayPath);\n\tconst next = structuredClone(notebook) as NotebookDocument;\n\tconst used = new Set<number>();\n\tnext.cells = parsed.map((parsedCell) => {\n\t\tlet cell: NotebookCell;\n\t\tconst cellIndex = parsedCell.cellIndex;\n\t\tif (cellIndex !== undefined && cellIndex >= 0 && cellIndex < notebook.cells.length && !used.has(cellIndex)) {\n\t\t\tused.add(cellIndex);\n\t\t\tcell = structuredClone(notebook.cells[cellIndex]!) as NotebookCell;\n\t\t} else {\n\t\t\tcell = newNotebookCell(parsedCell.cellType, \"\");\n\t\t}\n\t\tcell.cell_type = parsedCell.cellType;\n\t\tcell.source = splitNotebookSource(parsedCell.source);\n\t\tif (parsedCell.cellType === \"code\") {\n\t\t\tif (cell.execution_count === undefined) cell.execution_count = null;\n\t\t\tif (cell.outputs === undefined) cell.outputs = [];\n\t\t} else {\n\t\t\tdelete cell.execution_count;\n\t\t\tdelete cell.outputs;\n\t\t}\n\t\treturn cell;\n\t});\n\treturn next;\n}\n\nexport function readEditableNotebookText(absolutePath: string, displayPath: string): string {\n\tconst notebook = existsSync(absolutePath) ? parseNotebookSafe(readFileSync(absolutePath, \"utf8\"), displayPath) : emptyNotebook();\n\treturn notebookToEditableText(notebook);\n}\n\nexport function serializeEditedNotebookText(absolutePath: string, displayPath: string, text: string): string {\n\tconst notebook = existsSync(absolutePath) ? parseNotebookSafe(readFileSync(absolutePath, \"utf8\"), displayPath) : emptyNotebook();\n\tconst next = applyNotebookEditableText(notebook, text, displayPath);\n\treturn JSON.stringify(next, null, 1);\n}\n\nfunction parseNotebookSafe(raw: string, displayPath: string): NotebookDocument {\n\tlet parsed: unknown;\n\ttry { parsed = JSON.parse(raw); } catch { throw new Error(`Invalid notebook JSON for ${displayPath}`); }\n\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) throw new Error(`Invalid notebook JSON for ${displayPath}`);\n\tconst doc = parsed as Partial<NotebookDocument>;\n\treturn { ...doc, cells: Array.isArray(doc.cells) ? doc.cells as NotebookCell[] : [], metadata: (doc.metadata ?? {}) as Record<string, unknown>, nbformat: doc.nbformat ?? 4, nbformat_minor: doc.nbformat_minor ?? 5 };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { type ReadLineRange } from "./read-selectors.ts";
2
+ export declare function isDocumentPath(pathValue: string): boolean;
3
+ export declare function extractDocumentMarkdown(buffer: Buffer, source: string): Promise<string>;
4
+ export declare function decodeReadableUrl(response: Response, url: string): Promise<string>;
5
+ export declare function applyReadLineSelection(allLines: string[], ranges: ReadLineRange[] | undefined, offset?: number, limit?: number, exact?: boolean): {
6
+ lines: string[];
7
+ firstLine: number;
8
+ };
9
+ //# sourceMappingURL=read-document-extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-document-extract.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read-document-extract.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKlG,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAgD;AAwJ1G,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAI7F;AAED,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAQxF;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAMtL","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { convertBufferWithMarkit, convertFileWithMarkit } from \"../../utils/markit.ts\";\nimport { selectExactReadRanges, selectReadRanges, type ReadLineRange } from \"./read-selectors.ts\";\n\nconst DOCUMENT_EXTENSIONS = /\\.(?:pdf|doc|docx|ppt|pptx|xls|xlsx|rtf|epub|ipynb)(?:$|[?#])/i;\nconst MARKIT_EXTENSIONS = /\\.(?:pdf|doc|docx|ppt|pptx|xls|xlsx|rtf|epub)(?:$|[?#])/i;\n\nexport function isDocumentPath(pathValue: string): boolean { return DOCUMENT_EXTENSIONS.test(pathValue); }\n\nfunction documentExtensionFromContentType(contentType: string): string | undefined {\n\tif (/ipynb|jupyter/i.test(contentType)) return \".ipynb\";\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 (/epub/i.test(contentType)) return \".epub\";\n\tif (/ms-excel|vnd\\.ms-excel/i.test(contentType)) return \".xls\";\n\tif (/rtf/i.test(contentType)) return \".rtf\";\n\treturn undefined;\n}\n\nfunction isHtmlWhitespace(char: string | undefined): boolean { return char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\r\" || char === \"\\f\"; }\n\nfunction findElementStart(lowerHtml: string, tagName: string, fromIndex: number): number {\n\tconst needle = `<${tagName}`;\n\tlet index = fromIndex;\n\tfor (;;) {\n\t\tconst found = lowerHtml.indexOf(needle, index);\n\t\tif (found < 0) return -1;\n\t\tconst next = lowerHtml[found + needle.length];\n\t\tif (next === undefined || next === \">\" || next === \"/\" || isHtmlWhitespace(next)) return found;\n\t\tindex = found + needle.length;\n\t}\n}\n\nfunction findClosingTag(lowerHtml: string, tagName: string, fromIndex: number): number {\n\tconst needle = `</${tagName}`;\n\tlet index = fromIndex;\n\tfor (;;) {\n\t\tconst found = lowerHtml.indexOf(needle, index);\n\t\tif (found < 0) return -1;\n\t\tlet cursor = found + needle.length;\n\t\twhile (isHtmlWhitespace(lowerHtml[cursor])) cursor++;\n\t\tif (lowerHtml[cursor] === \">\") return found;\n\t\tindex = found + needle.length;\n\t}\n}\n\nfunction stripElementBlocks(html: string, tagName: string): string {\n\tconst lowerHtml = html.toLowerCase();\n\tconst chunks: string[] = [];\n\tlet index = 0;\n\tfor (;;) {\n\t\tconst start = findElementStart(lowerHtml, tagName, index);\n\t\tif (start < 0) break;\n\t\tchunks.push(html.slice(index, start));\n\t\tconst startEnd = html.indexOf(\">\", start);\n\t\tif (startEnd < 0) { index = html.length; break; }\n\t\tconst closeStart = findClosingTag(lowerHtml, tagName, startEnd + 1);\n\t\tif (closeStart < 0) { index = html.length; break; }\n\t\tconst closeEnd = html.indexOf(\">\", closeStart);\n\t\tif (closeEnd < 0) { index = html.length; break; }\n\t\tindex = closeEnd + 1;\n\t}\n\tchunks.push(html.slice(index));\n\treturn chunks.join(\"\");\n}\n\nfunction extractElementText(html: string, tagName: string): string | undefined {\n\tconst lowerHtml = html.toLowerCase();\n\tconst start = findElementStart(lowerHtml, tagName, 0);\n\tif (start < 0) return undefined;\n\tconst startEnd = html.indexOf(\">\", start);\n\tif (startEnd < 0) return undefined;\n\tconst closeStart = findClosingTag(lowerHtml, tagName, startEnd + 1);\n\treturn closeStart < 0 ? undefined : html.slice(startEnd + 1, closeStart);\n}\n\nfunction readTagName(tagContent: string): { closing: boolean; name: string } {\n\tlet index = 0;\n\twhile (isHtmlWhitespace(tagContent[index])) index++;\n\tconst closing = tagContent[index] === \"/\";\n\tif (closing) index++;\n\twhile (isHtmlWhitespace(tagContent[index])) index++;\n\tconst start = index;\n\twhile (index < tagContent.length) {\n\t\tconst char = tagContent[index];\n\t\tif (!char || !(char >= \"a\" && char <= \"z\") && !(char >= \"A\" && char <= \"Z\") && !(char >= \"0\" && char <= \"9\")) break;\n\t\tindex++;\n\t}\n\treturn { closing, name: tagContent.slice(start, index).toLowerCase() };\n}\n\nfunction htmlMarkupToPlainText(html: string): string {\n\tlet output = \"\";\n\tlet index = 0;\n\twhile (index < html.length) {\n\t\tconst open = html.indexOf(\"<\", index);\n\t\tif (open < 0) { output += html.slice(index); break; }\n\t\toutput += html.slice(index, open);\n\t\tconst close = html.indexOf(\">\", open + 1);\n\t\tif (close < 0) break;\n\t\tconst tag = readTagName(html.slice(open + 1, close));\n\t\tif (tag.name === \"br\" || tag.closing && [\"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\", \"p\", \"div\", \"li\", \"tr\", \"blockquote\", \"pre\"].includes(tag.name)) output += \"\\n\";\n\t\telse if (!tag.closing && tag.name === \"li\") output += \"- \";\n\t\tindex = close + 1;\n\t}\n\treturn normalizeDecodedText(output);\n}\n\nfunction normalizeDecodedText(value: string): string {\n\treturn decodeEntities(value).split(\"\\n\").map((line) => line.trim()).filter(Boolean).join(\"\\n\");\n}\n\nfunction htmlToReadableText(html: string): string {\n\tconst stripped = stripElementBlocks(stripElementBlocks(html, \"script\"), \"style\");\n\tconst title = extractElementText(stripped, \"title\");\n\tconst titleText = title ? htmlMarkupToPlainText(title).split(\"\\n\").join(\" \").trim() : undefined;\n\tconst text = htmlMarkupToPlainText(stripped);\n\treturn titleText && !text.startsWith(titleText) ? `# ${titleText}\\n\\n${text}` : text;\n}\n\nfunction decodeEntities(value: string): string {\n\tconst entities: Record<string, string> = { nbsp: \" \", amp: \"&\", lt: \"<\", gt: \">\", quot: '\"', \"#39\": \"'\" };\n\tlet output = \"\";\n\tlet index = 0;\n\twhile (index < value.length) {\n\t\tconst ampersand = value.indexOf(\"&\", index);\n\t\tif (ampersand < 0) { output += value.slice(index); break; }\n\t\toutput += value.slice(index, ampersand);\n\t\tconst semicolon = value.indexOf(\";\", ampersand + 1);\n\t\tif (semicolon < 0 || semicolon - ampersand > 12) { output += \"&\"; index = ampersand + 1; continue; }\n\t\tconst entity = value.slice(ampersand + 1, semicolon).toLowerCase();\n\t\tconst decoded = entities[entity];\n\t\toutput += decoded ?? value.slice(ampersand, semicolon + 1);\n\t\tindex = semicolon + 1;\n\t}\n\treturn output;\n}\n\nfunction notebookMarkdown(buffer: Buffer, source: string): string {\n\tconst nb = JSON.parse(buffer.toString(\"utf8\")) as { cells?: Array<{ cell_type?: string; source?: string | string[] }> };\n\tconst cells = nb.cells ?? [];\n\treturn cells.map((cell, index) => {\n\t\tconst sourceText = Array.isArray(cell.source) ? cell.source.join(\"\") : cell.source ?? \"\";\n\t\treturn `# %% [${cell.cell_type ?? \"raw\"}] cell:${index}\\n${sourceText.trimEnd()}`;\n\t}).join(\"\\n\\n\") || `# ${source}\\n\\n(empty notebook)`;\n}\n\nfunction documentExtension(source: string): string { return `.${source.match(/\\.(pdf|docx?|pptx?|xlsx?|rtf|epub)(?:$|[?#])/i)?.[1]?.toLowerCase() ?? \"bin\"}`; }\n\nasync function extractMarkitDocument(buffer: Buffer, source: string): Promise<string> {\n\tconst ext = documentExtension(source);\n\tconst result = existsSync(source) ? await convertFileWithMarkit(source) : await convertBufferWithMarkit(buffer, ext);\n\treturn result.ok ? result.content : `[Cannot read ${ext} file: ${result.error || \"conversion failed\"}]`;\n}\n\nexport async function extractDocumentMarkdown(buffer: Buffer, source: string): Promise<string> {\n\tif (/\\.ipynb(?:$|[?#])/i.test(source)) return notebookMarkdown(buffer, source);\n\tif (MARKIT_EXTENSIONS.test(source)) return extractMarkitDocument(buffer, source);\n\treturn buffer.toString(\"utf8\");\n}\n\nexport async function decodeReadableUrl(response: Response, url: string): Promise<string> {\n\tconst contentType = response.headers.get(\"content-type\") ?? \"\";\n\tconst buffer = Buffer.from(await response.arrayBuffer());\n\tconst contentTypeExtension = documentExtensionFromContentType(contentType);\n\tif (contentTypeExtension || isDocumentPath(url)) return extractDocumentMarkdown(buffer, contentTypeExtension && !isDocumentPath(url) ? `${url}${contentTypeExtension}` : url);\n\tconst text = buffer.toString(\"utf8\");\n\tif (/html/i.test(contentType) || /<html[\\s>]/i.test(text)) return htmlToReadableText(text);\n\treturn text;\n}\n\nexport function applyReadLineSelection(allLines: string[], ranges: ReadLineRange[] | undefined, offset?: number, limit?: number, exact = false): { lines: string[]; firstLine: number } {\n\tconst rangeSelection = (exact ? selectExactReadRanges : selectReadRanges)(allLines, ranges);\n\tconst rangeStart = ranges?.[0]?.start;\n\tconst startLine = rangeSelection ? (rangeSelection.selectedLines.length === 0 ? rangeStart ?? rangeSelection.firstLine : rangeSelection.firstLine) - 1 : offset ? Math.max(0, offset - 1) : 0;\n\tconst endLine = limit !== undefined ? Math.min(startLine + limit, allLines.length) : allLines.length;\n\treturn { lines: rangeSelection?.selectedLines ?? allLines.slice(startLine, endLine), firstLine: startLine + 1 };\n}\n"]}