@tomsun28/pizza 0.0.9 → 0.1.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 (382) hide show
  1. package/README.md +20 -143
  2. package/README.zh-CN.md +36 -0
  3. package/dist/bun/cli.d.ts +2 -0
  4. package/dist/bun/cli.js +6 -0
  5. package/dist/bun/register-bedrock.d.ts +1 -0
  6. package/dist/bun/register-bedrock.js +3 -0
  7. package/dist/cli/args.d.ts +48 -0
  8. package/dist/cli/args.js +330 -0
  9. package/dist/cli/config-selector.d.ts +13 -0
  10. package/dist/cli/config-selector.js +30 -0
  11. package/dist/cli/file-processor.d.ts +14 -0
  12. package/dist/cli/file-processor.js +82 -0
  13. package/dist/cli/initial-message.d.ts +17 -0
  14. package/dist/cli/initial-message.js +21 -0
  15. package/dist/cli/list-models.d.ts +8 -0
  16. package/dist/cli/list-models.js +96 -0
  17. package/dist/cli.d.ts +2 -0
  18. package/dist/cli.js +68 -0
  19. package/dist/config.d.ts +79 -0
  20. package/dist/config.js +223 -0
  21. package/dist/core/agent/index.d.ts +6 -0
  22. package/dist/core/agent/index.js +6 -0
  23. package/dist/core/agent/types.d.ts +202 -0
  24. package/dist/core/agent/types.js +51 -0
  25. package/dist/core/auth-storage.d.ts +135 -0
  26. package/dist/core/auth-storage.js +417 -0
  27. package/dist/core/bash-executor.d.ts +31 -0
  28. package/dist/core/bash-executor.js +107 -0
  29. package/dist/core/compaction/branch-summarization.d.ts +87 -0
  30. package/dist/core/compaction/branch-summarization.js +242 -0
  31. package/dist/core/compaction/compaction-engine.d.ts +40 -0
  32. package/dist/core/compaction/compaction-engine.js +292 -0
  33. package/dist/core/compaction/compaction.d.ts +106 -0
  34. package/dist/core/compaction/compaction.js +295 -0
  35. package/dist/core/compaction/index.d.ts +7 -0
  36. package/dist/core/compaction/index.js +7 -0
  37. package/dist/core/compaction/utils.d.ts +37 -0
  38. package/dist/core/compaction/utils.js +152 -0
  39. package/dist/core/defaults.d.ts +2 -0
  40. package/dist/core/defaults.js +1 -0
  41. package/dist/core/diagnostics.d.ts +14 -0
  42. package/dist/core/diagnostics.js +1 -0
  43. package/dist/core/event-bus.d.ts +8 -0
  44. package/dist/core/event-bus.js +24 -0
  45. package/dist/core/event-store/events.d.ts +465 -0
  46. package/dist/core/event-store/events.js +6 -0
  47. package/dist/core/event-store/index.d.ts +10 -0
  48. package/dist/core/event-store/index.js +10 -0
  49. package/dist/core/event-store/sqlite-store.d.ts +27 -0
  50. package/dist/core/event-store/sqlite-store.js +275 -0
  51. package/dist/core/event-store/store.d.ts +91 -0
  52. package/dist/core/event-store/store.js +7 -0
  53. package/dist/core/event-store/thread-scoped-store.d.ts +29 -0
  54. package/dist/core/event-store/thread-scoped-store.js +50 -0
  55. package/dist/core/event-store/types.d.ts +70 -0
  56. package/dist/core/event-store/types.js +7 -0
  57. package/dist/core/event-store/workspace.d.ts +37 -0
  58. package/dist/core/event-store/workspace.js +71 -0
  59. package/dist/core/exec.d.ts +28 -0
  60. package/dist/core/exec.js +74 -0
  61. package/dist/core/export-html/ansi-to-html.d.ts +21 -0
  62. package/dist/core/export-html/ansi-to-html.js +248 -0
  63. package/dist/core/export-html/index.d.ts +29 -0
  64. package/dist/core/export-html/index.js +186 -0
  65. package/dist/core/export-html/template.css +1017 -0
  66. package/dist/core/export-html/template.html +55 -0
  67. package/dist/core/export-html/template.js +1742 -0
  68. package/dist/core/export-html/tool-renderer.d.ts +39 -0
  69. package/dist/core/export-html/tool-renderer.js +94 -0
  70. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  71. package/dist/core/export-html/vendor/marked.min.js +6 -0
  72. package/dist/core/extensions/index.d.ts +12 -0
  73. package/dist/core/extensions/index.js +9 -0
  74. package/dist/core/extensions/loader.d.ts +24 -0
  75. package/dist/core/extensions/loader.js +492 -0
  76. package/dist/core/extensions/runner.d.ts +167 -0
  77. package/dist/core/extensions/runner.js +898 -0
  78. package/dist/core/extensions/session-context.d.ts +67 -0
  79. package/dist/core/extensions/session-context.js +272 -0
  80. package/dist/core/extensions/types.d.ts +1147 -0
  81. package/dist/core/extensions/types.js +44 -0
  82. package/dist/core/extensions/wrapper.d.ts +19 -0
  83. package/dist/core/extensions/wrapper.js +21 -0
  84. package/dist/core/footer-data-provider.d.ts +47 -0
  85. package/dist/core/footer-data-provider.js +321 -0
  86. package/dist/core/goal/index.d.ts +3 -0
  87. package/dist/core/goal/index.js +1 -0
  88. package/dist/core/goal/scheduler.d.ts +83 -0
  89. package/dist/core/goal/scheduler.js +154 -0
  90. package/dist/core/goal/types.d.ts +182 -0
  91. package/dist/core/goal/types.js +11 -0
  92. package/dist/core/index.d.ts +8 -0
  93. package/dist/core/index.js +8 -0
  94. package/dist/core/intent/classifier.d.ts +53 -0
  95. package/dist/core/intent/classifier.js +353 -0
  96. package/dist/core/intent/index.d.ts +8 -0
  97. package/dist/core/intent/index.js +8 -0
  98. package/dist/core/intent/tool-adapter.d.ts +31 -0
  99. package/dist/core/intent/tool-adapter.js +168 -0
  100. package/dist/core/intent/types.d.ts +71 -0
  101. package/dist/core/intent/types.js +6 -0
  102. package/dist/core/keybindings.d.ts +297 -0
  103. package/dist/core/keybindings.js +250 -0
  104. package/dist/core/messages.d.ts +30 -0
  105. package/dist/core/messages.js +134 -0
  106. package/dist/core/model-registry.d.ts +131 -0
  107. package/dist/core/model-registry.js +634 -0
  108. package/dist/core/model-resolver.d.ts +109 -0
  109. package/dist/core/model-resolver.js +486 -0
  110. package/dist/core/output-guard.d.ts +5 -0
  111. package/dist/core/output-guard.js +58 -0
  112. package/dist/core/package-manager.d.ts +196 -0
  113. package/dist/core/package-manager.js +1873 -0
  114. package/dist/core/projection/boundary-inferrer.d.ts +58 -0
  115. package/dist/core/projection/boundary-inferrer.js +122 -0
  116. package/dist/core/projection/event-to-message.d.ts +35 -0
  117. package/dist/core/projection/event-to-message.js +253 -0
  118. package/dist/core/projection/goal-projection.d.ts +67 -0
  119. package/dist/core/projection/goal-projection.js +339 -0
  120. package/dist/core/projection/index.d.ts +13 -0
  121. package/dist/core/projection/index.js +13 -0
  122. package/dist/core/projection/session-manager.d.ts +100 -0
  123. package/dist/core/projection/session-manager.js +331 -0
  124. package/dist/core/projection/session-projection.d.ts +58 -0
  125. package/dist/core/projection/session-projection.js +257 -0
  126. package/dist/core/projection/task-history.d.ts +13 -0
  127. package/dist/core/projection/task-history.js +61 -0
  128. package/dist/core/projection/timeline-projection.d.ts +82 -0
  129. package/dist/core/projection/timeline-projection.js +276 -0
  130. package/dist/core/projection/types.d.ts +69 -0
  131. package/dist/core/projection/types.js +6 -0
  132. package/dist/core/prompt-templates.d.ts +51 -0
  133. package/dist/core/prompt-templates.js +249 -0
  134. package/dist/core/resolve-config-value.d.ts +22 -0
  135. package/dist/core/resolve-config-value.js +125 -0
  136. package/dist/core/resource-loader.d.ts +193 -0
  137. package/dist/core/resource-loader.js +685 -0
  138. package/dist/core/runtime/ai-client.d.ts +12 -0
  139. package/dist/core/runtime/ai-client.js +153 -0
  140. package/dist/core/runtime/checkpoint.d.ts +12 -0
  141. package/dist/core/runtime/checkpoint.js +78 -0
  142. package/dist/core/runtime/index.d.ts +12 -0
  143. package/dist/core/runtime/index.js +12 -0
  144. package/dist/core/runtime/llm-types.d.ts +99 -0
  145. package/dist/core/runtime/llm-types.js +6 -0
  146. package/dist/core/runtime/local-runtime.d.ts +23 -0
  147. package/dist/core/runtime/local-runtime.js +59 -0
  148. package/dist/core/runtime/policies.d.ts +72 -0
  149. package/dist/core/runtime/policies.js +37 -0
  150. package/dist/core/runtime/reactor.d.ts +213 -0
  151. package/dist/core/runtime/reactor.js +992 -0
  152. package/dist/core/runtime/runtime.d.ts +191 -0
  153. package/dist/core/runtime/runtime.js +449 -0
  154. package/dist/core/runtime/types.d.ts +42 -0
  155. package/dist/core/runtime/types.js +1 -0
  156. package/dist/core/sdk.d.ts +12 -0
  157. package/dist/core/sdk.js +10 -0
  158. package/dist/core/session-context-builder.d.ts +9 -0
  159. package/dist/core/session-context-builder.js +87 -0
  160. package/dist/core/session-cwd.d.ts +18 -0
  161. package/dist/core/session-cwd.js +36 -0
  162. package/dist/core/session-facade-factory.d.ts +79 -0
  163. package/dist/core/session-facade-factory.js +460 -0
  164. package/dist/core/session-facade.d.ts +57 -0
  165. package/dist/core/session-facade.js +91 -0
  166. package/dist/core/session-listing.d.ts +30 -0
  167. package/dist/core/session-listing.js +168 -0
  168. package/dist/core/session-reader.d.ts +19 -0
  169. package/dist/core/session-reader.js +101 -0
  170. package/dist/core/session-ref.d.ts +7 -0
  171. package/dist/core/session-ref.js +25 -0
  172. package/dist/core/session-services.d.ts +51 -0
  173. package/dist/core/session-services.js +90 -0
  174. package/dist/core/session-stats.d.ts +43 -0
  175. package/dist/core/session-stats.js +41 -0
  176. package/dist/core/settings-manager.d.ts +236 -0
  177. package/dist/core/settings-manager.js +706 -0
  178. package/dist/core/skill-block-parser.d.ts +12 -0
  179. package/dist/core/skill-block-parser.js +15 -0
  180. package/dist/core/skills.d.ts +59 -0
  181. package/dist/core/skills.js +408 -0
  182. package/dist/core/slash-commands.d.ts +13 -0
  183. package/dist/core/slash-commands.js +17 -0
  184. package/dist/core/source-info.d.ts +17 -0
  185. package/dist/core/source-info.js +18 -0
  186. package/dist/core/system-prompt.d.ts +27 -0
  187. package/dist/core/system-prompt.js +179 -0
  188. package/dist/core/timings.d.ts +7 -0
  189. package/dist/core/timings.js +30 -0
  190. package/dist/core/tools/bash.d.ts +95 -0
  191. package/dist/core/tools/bash.js +513 -0
  192. package/dist/core/tools/builtin-commands.d.ts +75 -0
  193. package/dist/core/tools/builtin-commands.js +503 -0
  194. package/dist/core/tools/compat-commands.d.ts +12 -0
  195. package/dist/core/tools/compat-commands.js +1280 -0
  196. package/dist/core/tools/edit-diff.d.ts +59 -0
  197. package/dist/core/tools/edit-diff.js +263 -0
  198. package/dist/core/tools/edit.d.ts +49 -0
  199. package/dist/core/tools/edit.js +340 -0
  200. package/dist/core/tools/file-mutation-queue.d.ts +5 -0
  201. package/dist/core/tools/file-mutation-queue.js +36 -0
  202. package/dist/core/tools/find.d.ts +34 -0
  203. package/dist/core/tools/find.js +459 -0
  204. package/dist/core/tools/grep.d.ts +36 -0
  205. package/dist/core/tools/grep.js +422 -0
  206. package/dist/core/tools/index.d.ts +70 -0
  207. package/dist/core/tools/index.js +129 -0
  208. package/dist/core/tools/line-anchors.d.ts +33 -0
  209. package/dist/core/tools/line-anchors.js +151 -0
  210. package/dist/core/tools/ls.d.ts +36 -0
  211. package/dist/core/tools/ls.js +268 -0
  212. package/dist/core/tools/path-utils.d.ts +7 -0
  213. package/dist/core/tools/path-utils.js +80 -0
  214. package/dist/core/tools/read.d.ts +35 -0
  215. package/dist/core/tools/read.js +244 -0
  216. package/dist/core/tools/render-utils.d.ts +20 -0
  217. package/dist/core/tools/render-utils.js +48 -0
  218. package/dist/core/tools/session-split.d.ts +9 -0
  219. package/dist/core/tools/session-split.js +77 -0
  220. package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
  221. package/dist/core/tools/tool-definition-wrapper.js +32 -0
  222. package/dist/core/tools/truncate.d.ts +69 -0
  223. package/dist/core/tools/truncate.js +204 -0
  224. package/dist/core/tools/write.d.ts +25 -0
  225. package/dist/core/tools/write.js +211 -0
  226. package/dist/core/types/session-types.d.ts +123 -0
  227. package/dist/core/types/session-types.js +8 -0
  228. package/dist/index.d.ts +27 -0
  229. package/dist/index.js +38 -0
  230. package/dist/main.d.ts +11 -2
  231. package/dist/main.js +577 -149
  232. package/dist/modes/event-mapper.d.ts +115 -0
  233. package/dist/modes/event-mapper.js +200 -0
  234. package/dist/modes/gui/server.d.ts +14 -0
  235. package/dist/modes/gui/server.js +1032 -0
  236. package/dist/modes/index.d.ts +10 -0
  237. package/dist/modes/index.js +9 -0
  238. package/dist/modes/interactive/assets/clankolas.png +0 -0
  239. package/dist/modes/interactive/components/armin.d.ts +33 -0
  240. package/dist/modes/interactive/components/armin.js +328 -0
  241. package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
  242. package/dist/modes/interactive/components/assistant-message.js +115 -0
  243. package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
  244. package/dist/modes/interactive/components/bash-execution.js +169 -0
  245. package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
  246. package/dist/modes/interactive/components/bordered-loader.js +50 -0
  247. package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
  248. package/dist/modes/interactive/components/branch-summary-message.js +41 -0
  249. package/dist/modes/interactive/components/brand-header.d.ts +33 -0
  250. package/dist/modes/interactive/components/brand-header.js +235 -0
  251. package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
  252. package/dist/modes/interactive/components/compaction-summary-message.js +42 -0
  253. package/dist/modes/interactive/components/config-selector.d.ts +70 -0
  254. package/dist/modes/interactive/components/config-selector.js +469 -0
  255. package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
  256. package/dist/modes/interactive/components/countdown-timer.js +27 -0
  257. package/dist/modes/interactive/components/custom-editor.d.ts +27 -0
  258. package/dist/modes/interactive/components/custom-editor.js +94 -0
  259. package/dist/modes/interactive/components/custom-message.d.ts +19 -0
  260. package/dist/modes/interactive/components/custom-message.js +73 -0
  261. package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
  262. package/dist/modes/interactive/components/daxnuts.js +137 -0
  263. package/dist/modes/interactive/components/diff.d.ts +11 -0
  264. package/dist/modes/interactive/components/diff.js +132 -0
  265. package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
  266. package/dist/modes/interactive/components/dynamic-border.js +19 -0
  267. package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
  268. package/dist/modes/interactive/components/earendil-announcement.js +39 -0
  269. package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
  270. package/dist/modes/interactive/components/extension-editor.js +105 -0
  271. package/dist/modes/interactive/components/extension-input.d.ts +22 -0
  272. package/dist/modes/interactive/components/extension-input.js +54 -0
  273. package/dist/modes/interactive/components/extension-selector.d.ts +23 -0
  274. package/dist/modes/interactive/components/extension-selector.js +70 -0
  275. package/dist/modes/interactive/components/footer.d.ts +55 -0
  276. package/dist/modes/interactive/components/footer.js +207 -0
  277. package/dist/modes/interactive/components/index.d.ts +31 -0
  278. package/dist/modes/interactive/components/index.js +32 -0
  279. package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
  280. package/dist/modes/interactive/components/keybinding-hints.js +21 -0
  281. package/dist/modes/interactive/components/login-dialog.d.ts +41 -0
  282. package/dist/modes/interactive/components/login-dialog.js +138 -0
  283. package/dist/modes/interactive/components/model-selector.d.ts +32 -0
  284. package/dist/modes/interactive/components/model-selector.js +209 -0
  285. package/dist/modes/interactive/components/oauth-selector.d.ts +18 -0
  286. package/dist/modes/interactive/components/oauth-selector.js +91 -0
  287. package/dist/modes/interactive/components/settings-selector.d.ts +57 -0
  288. package/dist/modes/interactive/components/settings-selector.js +299 -0
  289. package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
  290. package/dist/modes/interactive/components/show-images-selector.js +37 -0
  291. package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
  292. package/dist/modes/interactive/components/skill-invocation-message.js +44 -0
  293. package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
  294. package/dist/modes/interactive/components/theme-selector.js +47 -0
  295. package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
  296. package/dist/modes/interactive/components/thinking-selector.js +50 -0
  297. package/dist/modes/interactive/components/timeline-view.d.ts +31 -0
  298. package/dist/modes/interactive/components/timeline-view.js +81 -0
  299. package/dist/modes/interactive/components/tool-execution.d.ts +64 -0
  300. package/dist/modes/interactive/components/tool-execution.js +305 -0
  301. package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
  302. package/dist/modes/interactive/components/tree-selector.js +1072 -0
  303. package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
  304. package/dist/modes/interactive/components/user-message-selector.js +110 -0
  305. package/dist/modes/interactive/components/user-message.d.ts +9 -0
  306. package/dist/modes/interactive/components/user-message.js +27 -0
  307. package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
  308. package/dist/modes/interactive/components/visual-truncate.js +32 -0
  309. package/dist/modes/interactive/interactive-mode.d.ts +394 -0
  310. package/dist/modes/interactive/interactive-mode.js +4116 -0
  311. package/dist/modes/interactive/theme/dark.json +85 -0
  312. package/dist/modes/interactive/theme/light.json +84 -0
  313. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  314. package/dist/modes/interactive/theme/theme.d.ts +80 -0
  315. package/dist/modes/interactive/theme/theme.js +973 -0
  316. package/dist/modes/print-mode.d.ts +27 -0
  317. package/dist/modes/print-mode.js +102 -0
  318. package/dist/modes/rpc/jsonl.d.ts +16 -0
  319. package/dist/modes/rpc/jsonl.js +48 -0
  320. package/dist/modes/rpc/rpc-client.d.ts +219 -0
  321. package/dist/modes/rpc/rpc-client.js +405 -0
  322. package/dist/modes/rpc/rpc-mode.d.ts +19 -0
  323. package/dist/modes/rpc/rpc-mode.js +381 -0
  324. package/dist/modes/rpc/rpc-types.d.ts +406 -0
  325. package/dist/modes/rpc/rpc-types.js +7 -0
  326. package/dist/package-manager-cli.d.ts +3 -0
  327. package/dist/package-manager-cli.js +233 -0
  328. package/dist/utils/changelog.d.ts +20 -0
  329. package/dist/utils/changelog.js +86 -0
  330. package/dist/utils/child-process.d.ts +10 -0
  331. package/dist/utils/child-process.js +77 -0
  332. package/dist/utils/clipboard-image.d.ts +10 -0
  333. package/dist/utils/clipboard-image.js +244 -0
  334. package/dist/utils/clipboard-native.d.ts +7 -0
  335. package/dist/utils/clipboard-native.js +13 -0
  336. package/dist/utils/clipboard.d.ts +1 -0
  337. package/dist/utils/clipboard.js +77 -0
  338. package/dist/utils/exif-orientation.d.ts +4 -0
  339. package/dist/utils/exif-orientation.js +157 -0
  340. package/dist/utils/frontmatter.d.ts +7 -0
  341. package/dist/utils/frontmatter.js +25 -0
  342. package/dist/utils/git.d.ts +25 -0
  343. package/dist/utils/git.js +162 -0
  344. package/dist/utils/image-convert.d.ts +8 -0
  345. package/dist/utils/image-convert.js +38 -0
  346. package/dist/utils/image-resize.d.ts +35 -0
  347. package/dist/utils/image-resize.js +136 -0
  348. package/dist/utils/mime.d.ts +1 -0
  349. package/dist/utils/mime.js +25 -0
  350. package/dist/utils/path-shims.d.ts +1 -0
  351. package/dist/utils/path-shims.js +90 -0
  352. package/dist/utils/paths.d.ts +6 -0
  353. package/dist/utils/paths.js +18 -0
  354. package/dist/utils/photon.d.ts +20 -0
  355. package/dist/utils/photon.js +120 -0
  356. package/dist/utils/shell.d.ts +29 -0
  357. package/dist/utils/shell.js +189 -0
  358. package/dist/utils/sleep.d.ts +4 -0
  359. package/dist/utils/sleep.js +16 -0
  360. package/dist/utils/tools-manager.d.ts +3 -0
  361. package/dist/utils/tools-manager.js +101 -0
  362. package/dist/vendor/bin/darwin-arm64/fd +0 -0
  363. package/dist/vendor/bin/darwin-arm64/rg +0 -0
  364. package/dist/vendor/bin/darwin-x64/fd +0 -0
  365. package/dist/vendor/bin/darwin-x64/rg +0 -0
  366. package/dist/vendor/bin/linux-arm64/fd +0 -0
  367. package/dist/vendor/bin/linux-arm64/rg +0 -0
  368. package/dist/vendor/bin/linux-x64/fd +0 -0
  369. package/dist/vendor/bin/linux-x64/rg +0 -0
  370. package/dist/vendor/bin/win32-arm64/fd.exe +0 -0
  371. package/dist/vendor/bin/win32-arm64/rg.exe +0 -0
  372. package/dist/vendor/bin/win32-x64/fd.exe +0 -0
  373. package/dist/vendor/bin/win32-x64/rg.exe +0 -0
  374. package/package.json +90 -26
  375. package/dist/extension/core.d.ts +0 -69
  376. package/dist/extension/core.js +0 -270
  377. package/dist/extension/core.js.map +0 -1
  378. package/dist/extension/index.d.ts +0 -25
  379. package/dist/extension/index.js +0 -303
  380. package/dist/extension/index.js.map +0 -1
  381. package/dist/main.js.map +0 -1
  382. package/themes/pizza.json +0 -87
@@ -0,0 +1,503 @@
1
+ /**
2
+ * Built-in CLI commands for file operations.
3
+ * These are exposed to the LLM via the cli tool.
4
+ *
5
+ * Supports heredoc syntax for multi-line content:
6
+ * write <path> <<EOF
7
+ * line1
8
+ * line2
9
+ * EOF
10
+ */
11
+ import { readFile, writeFile, mkdir } from "fs/promises";
12
+ import { resolve, join } from "path";
13
+ import { applyEditsToNormalizedContent, detectLineEnding, normalizeToLF, restoreLineEndings, stripBom, } from "./edit-diff.js";
14
+ import { annotateTextWithLineAnchors } from "./line-anchors.js";
15
+ import { truncateHead } from "./truncate.js";
16
+ /**
17
+ * Parse builtin command with optional heredoc.
18
+ * Supports:
19
+ * write <path> <<EOF
20
+ * line1
21
+ * line2
22
+ * EOF
23
+ */
24
+ export function parseBuiltinCommandWithHeredoc(input) {
25
+ const trimmed = input.trim();
26
+ // Match: command args <<DELIM\ncontent\nDELIM
27
+ const heredocMatch = trimmed.match(/^(.*?)\s+<<\s*(\w+)\s*\n([\s\S]*)\n\2\s*$/);
28
+ if (!heredocMatch) {
29
+ return null;
30
+ }
31
+ const [, prefix, delimiter, content] = heredocMatch;
32
+ const parts = splitShellWords(prefix.trim());
33
+ return {
34
+ command: parts[0],
35
+ args: parts.slice(1),
36
+ heredoc: content,
37
+ };
38
+ }
39
+ export function parseBuiltinCommand(input) {
40
+ const parsedHeredoc = parseBuiltinCommandWithHeredoc(input);
41
+ if (parsedHeredoc) {
42
+ return parsedHeredoc;
43
+ }
44
+ const parts = splitShellWords(input.trim());
45
+ return {
46
+ command: parts[0] ?? "",
47
+ args: parts.slice(1),
48
+ };
49
+ }
50
+ export function parseBuiltinToolInput(command, args, heredoc) {
51
+ const normalized = command.toLowerCase();
52
+ switch (normalized) {
53
+ case "read":
54
+ return { command: "read", input: parseReadInput(args) };
55
+ case "write":
56
+ return { command: "write", input: parseWriteInput(args, heredoc) };
57
+ case "edit":
58
+ return { command: "edit", input: parseEditInput(args) };
59
+ default:
60
+ return null;
61
+ }
62
+ }
63
+ function parseReadInput(args) {
64
+ let path = "";
65
+ let offset;
66
+ let limit;
67
+ let anchors;
68
+ for (let i = 0; i < args.length; i++) {
69
+ const arg = args[i];
70
+ if (arg === "--path" || arg === "-p") {
71
+ path = args[++i] ?? "";
72
+ }
73
+ else if (arg === "--offset" || arg === "-o") {
74
+ offset = parseOptionalInt(args[++i]);
75
+ }
76
+ else if (arg === "--limit" || arg === "-l") {
77
+ limit = parseOptionalInt(args[++i]);
78
+ }
79
+ else if (arg === "--anchors") {
80
+ const value = args[++i];
81
+ if (value !== "line" && value !== "none") {
82
+ throw new Error('read --anchors must be "line" or "none"');
83
+ }
84
+ anchors = value;
85
+ }
86
+ else if (arg === "--raw") {
87
+ anchors = "none";
88
+ }
89
+ else if (!path) {
90
+ path = arg;
91
+ }
92
+ else if (offset === undefined) {
93
+ offset = parseOptionalInt(arg);
94
+ }
95
+ else if (limit === undefined) {
96
+ limit = parseOptionalInt(arg);
97
+ }
98
+ }
99
+ return { path, offset, limit, anchors };
100
+ }
101
+ function parseWriteInput(args, heredoc) {
102
+ let path = "";
103
+ let content = heredoc;
104
+ const positionalContent = [];
105
+ for (let i = 0; i < args.length; i++) {
106
+ const arg = args[i];
107
+ if (arg === "--path" || arg === "-p") {
108
+ path = args[++i] ?? "";
109
+ }
110
+ else if (arg === "--content" || arg === "-c") {
111
+ content = args[++i] ?? "";
112
+ }
113
+ else if (!path) {
114
+ path = arg;
115
+ }
116
+ else if (content === undefined) {
117
+ positionalContent.push(arg);
118
+ }
119
+ }
120
+ if (content === undefined) {
121
+ content = positionalContent.join(" ");
122
+ }
123
+ return { path, content };
124
+ }
125
+ function parseEditInput(args) {
126
+ let path = "";
127
+ let editsJson;
128
+ const edits = [];
129
+ const positional = [];
130
+ let op;
131
+ let range;
132
+ let newValue;
133
+ for (let i = 0; i < args.length; i++) {
134
+ const arg = args[i];
135
+ if (arg === "--path" || arg === "-p") {
136
+ path = args[++i] ?? "";
137
+ }
138
+ else if (arg === "--edits" || arg === "-e") {
139
+ editsJson = args[++i] ?? "[]";
140
+ }
141
+ else if (arg === "--op") {
142
+ op = parseEditOp(args[++i] ?? "");
143
+ }
144
+ else if (arg === "--old" || arg === "-o") {
145
+ throw new Error("edit no longer supports --old. Read the file and use --range from the line anchors.");
146
+ }
147
+ else if (arg === "--range-id" || arg === "--rangeId") {
148
+ throw new Error("edit no longer supports --range-id. Use --range.");
149
+ }
150
+ else if (arg === "--range" || arg === "-r") {
151
+ range = args[++i] ?? "";
152
+ }
153
+ else if (arg === "--new" || arg === "-n") {
154
+ newValue = args[++i] ?? "";
155
+ }
156
+ else if (!path) {
157
+ path = arg;
158
+ }
159
+ else {
160
+ positional.push(arg);
161
+ }
162
+ }
163
+ if (editsJson !== undefined) {
164
+ const parsed = JSON.parse(editsJson);
165
+ if (!Array.isArray(parsed)) {
166
+ throw new Error("edit --edits must be a JSON array");
167
+ }
168
+ for (const entry of parsed) {
169
+ edits.push(parseEditEntry(entry));
170
+ }
171
+ }
172
+ if (edits.length === 0) {
173
+ if (op !== undefined || range !== undefined) {
174
+ edits.push(buildEditFromParts(op, range, newValue));
175
+ }
176
+ else if (positional.length >= 2) {
177
+ edits.push(buildEditFromParts(parseEditOp(positional[0] ?? ""), positional[1], positional.slice(2).join(" ")));
178
+ }
179
+ }
180
+ return { path, edits };
181
+ }
182
+ function parseEditOp(value) {
183
+ if (value === "replace" || value === "insert_before" || value === "insert_after" || value === "delete") {
184
+ return value;
185
+ }
186
+ throw new Error("edit op must be one of: replace, insert_before, insert_after, delete");
187
+ }
188
+ function parseEditEntry(entry) {
189
+ if (!entry || typeof entry !== "object") {
190
+ throw new Error('edit --edits entries must be objects with op, range, and new (unless op is "delete")');
191
+ }
192
+ const record = entry;
193
+ return buildEditFromParts(parseEditOp(String(record.op ?? "")), typeof record.range === "string" ? record.range : undefined, typeof record.new === "string" ? record.new : undefined);
194
+ }
195
+ function buildEditFromParts(op, range, newValue) {
196
+ if (!op) {
197
+ throw new Error("edit requires --op");
198
+ }
199
+ if (typeof range !== "string") {
200
+ throw new Error("edit requires --range");
201
+ }
202
+ if (op === "delete") {
203
+ return { op, range };
204
+ }
205
+ if (typeof newValue !== "string") {
206
+ throw new Error('edit requires --new unless --op is "delete"');
207
+ }
208
+ return { op, range, new: newValue };
209
+ }
210
+ function parseOptionalInt(value) {
211
+ if (value === undefined)
212
+ return undefined;
213
+ const parsed = parseInt(value, 10);
214
+ return Number.isNaN(parsed) ? undefined : parsed;
215
+ }
216
+ function splitShellWords(input) {
217
+ const words = [];
218
+ let current = "";
219
+ let quote;
220
+ let escaped = false;
221
+ for (const char of input) {
222
+ if (escaped) {
223
+ current += char;
224
+ escaped = false;
225
+ continue;
226
+ }
227
+ if (char === "\\") {
228
+ escaped = true;
229
+ continue;
230
+ }
231
+ if (quote) {
232
+ if (char === quote) {
233
+ quote = undefined;
234
+ }
235
+ else {
236
+ current += char;
237
+ }
238
+ continue;
239
+ }
240
+ if (char === "'" || char === "\"") {
241
+ quote = char;
242
+ continue;
243
+ }
244
+ if (/\s/.test(char)) {
245
+ if (current.length > 0) {
246
+ words.push(current);
247
+ current = "";
248
+ }
249
+ continue;
250
+ }
251
+ current += char;
252
+ }
253
+ if (escaped) {
254
+ current += "\\";
255
+ }
256
+ if (current.length > 0) {
257
+ words.push(current);
258
+ }
259
+ return words;
260
+ }
261
+ function isHelpRequest(args) {
262
+ if (args.length !== 1)
263
+ return false;
264
+ const value = args[0]?.toLowerCase();
265
+ return value === "-h" || value === "--help" || value === "help";
266
+ }
267
+ export function getBuiltinCommandHelp(command) {
268
+ switch (command.toLowerCase()) {
269
+ case "read":
270
+ return [
271
+ "read - Read a file",
272
+ "",
273
+ "Description:",
274
+ " Reads a text file or supported image file from the current working directory.",
275
+ " Text output includes 2-hex hashline anchors by default: <line>#<hash> | content.",
276
+ " Use those anchors as edit range values. Images are returned as image content",
277
+ " when routed through the cli tool's built-in read implementation.",
278
+ "",
279
+ "Parameters:",
280
+ " path File path to read. Relative paths are resolved from the working directory.",
281
+ " offset Optional 1-based line number to start reading from.",
282
+ " limit Optional maximum number of lines to return.",
283
+ " --path, -p File path to read.",
284
+ " --offset, -o 1-based line number to start reading from.",
285
+ " --limit, -l Maximum number of lines to return.",
286
+ " --anchors line or none. Defaults to line.",
287
+ " --raw Alias for --anchors none.",
288
+ " -h, --help Show this help.",
289
+ "",
290
+ "Examples:",
291
+ " read src/main.ts",
292
+ " read src/main.ts 20",
293
+ " read src/main.ts 20 50",
294
+ " read --path src/main.ts --offset 20 --limit 50",
295
+ " read -p src/main.ts -o 20 -l 50",
296
+ " read --path src/main.ts --anchors none",
297
+ ].join("\n");
298
+ case "write":
299
+ return [
300
+ "write - Create or overwrite a file",
301
+ "",
302
+ "Description:",
303
+ " Writes complete content to a file. Creates parent directories when needed.",
304
+ " If the target file already exists, it is overwritten.",
305
+ "",
306
+ "Parameters:",
307
+ " path Target file path. Relative paths are resolved from the working directory.",
308
+ " content Complete file content to write.",
309
+ " --path, -p Target file path.",
310
+ " --content, -c Complete file content to write.",
311
+ " <<EOF Heredoc form for multi-line content.",
312
+ " -h, --help Show this help.",
313
+ "",
314
+ "Examples:",
315
+ " write notes.txt hello",
316
+ " write --path notes.txt --content \"hello world\"",
317
+ " write -p notes.txt -c \"hello world\"",
318
+ " write src/generated.ts <<EOF",
319
+ " export const value = 1;",
320
+ " EOF",
321
+ ].join("\n");
322
+ case "edit":
323
+ return [
324
+ "edit - Edit a file with read range anchors",
325
+ "",
326
+ "Description:",
327
+ " Edits one existing file using hashline ranges from read output. Each edit",
328
+ " can replace, insert before, insert after, or delete one whole line or a",
329
+ " continuous whole-line range. Ranges fail safely",
330
+ " if the referenced lines changed or became ambiguous.",
331
+ "",
332
+ "Parameters:",
333
+ " path File path to edit. Relative paths are resolved from the working directory.",
334
+ " op replace, insert_before, insert_after, or delete.",
335
+ " range Line anchor or range from read output, e.g. 12#ab or 12#ab..14#de.",
336
+ " new New text for replace and insert operations. Omit for delete.",
337
+ " --path, -p File path to edit.",
338
+ " --op Edit operation.",
339
+ " --range, -r Line anchor or range from read output.",
340
+ " --new, -n New text for replace and insert operations.",
341
+ " --edits, -e JSON array of {\"op\":\"...\",\"range\":\"...\",\"new\":\"...\"} edits.",
342
+ " -h, --help Show this help.",
343
+ "",
344
+ "Examples:",
345
+ " read src/app.ts",
346
+ " edit src/app.ts replace 12#ab \"const a = 2\"",
347
+ " edit --path src/app.ts --op insert_after --range 12#ab --new \"const b = 3\"",
348
+ " edit --path src/app.ts --op delete --range 12#ab..14#de",
349
+ " edit --path src/app.ts --edits '[{\"op\":\"replace\",\"range\":\"12#ab\",\"new\":\"const a = 2\"}]'",
350
+ ].join("\n");
351
+ default:
352
+ return undefined;
353
+ }
354
+ }
355
+ export function getBuiltinCommandHelpForArgs(command, args) {
356
+ if (!isHelpRequest(args))
357
+ return undefined;
358
+ return getBuiltinCommandHelp(command);
359
+ }
360
+ /** @deprecated Use parseBuiltinCommandWithHeredoc */
361
+ export const parseCommandWithHeredoc = parseBuiltinCommandWithHeredoc;
362
+ async function executeRead(options) {
363
+ try {
364
+ const filePath = resolve(options.cwd, options.path);
365
+ const anchors = options.anchors ?? "line";
366
+ const rawContent = await readFile(filePath, "utf-8");
367
+ const content = anchors === "line" ? normalizeToLF(rawContent) : rawContent;
368
+ let lines = content.split("\n");
369
+ const totalLines = lines.length;
370
+ // Apply offset (1-indexed)
371
+ const startLine = options.offset && options.offset > 0 ? options.offset - 1 : 0;
372
+ if (startLine > 0) {
373
+ lines = lines.slice(startLine);
374
+ }
375
+ // Apply limit
376
+ let userLimited = false;
377
+ if (options.limit !== undefined && options.limit > 0) {
378
+ lines = lines.slice(0, options.limit);
379
+ userLimited = true;
380
+ }
381
+ // Apply truncation
382
+ const truncation = truncateHead(lines.join("\n"));
383
+ const startLineDisplay = startLine + 1;
384
+ let output = anchors === "line" ? annotateTextWithLineAnchors(truncation.content, startLineDisplay) : truncation.content;
385
+ if (truncation.truncated) {
386
+ const endLine = startLineDisplay + truncation.outputLines - 1;
387
+ const nextOffset = endLine + 1;
388
+ output += `\n\n[Showing lines ${startLineDisplay}-${endLine} of ${totalLines}. Use: read ${options.path} ${nextOffset}]`;
389
+ }
390
+ else if (userLimited && startLine + lines.length < totalLines) {
391
+ const remaining = totalLines - (startLine + lines.length);
392
+ const nextOffset = startLine + lines.length + 1;
393
+ output += `\n\n[${remaining} more lines. Use: read ${options.path} ${nextOffset}]`;
394
+ }
395
+ return {
396
+ stdout: output,
397
+ stderr: "",
398
+ exitCode: 0,
399
+ };
400
+ }
401
+ catch (error) {
402
+ const message = error instanceof Error ? error.message : String(error);
403
+ return {
404
+ stdout: "",
405
+ stderr: `Error reading file: ${message}`,
406
+ exitCode: 1,
407
+ };
408
+ }
409
+ }
410
+ async function executeWrite(options) {
411
+ try {
412
+ const filePath = resolve(options.cwd, options.path);
413
+ // Ensure parent directory exists
414
+ const parentDir = join(filePath, "..");
415
+ await mkdir(parentDir, { recursive: true });
416
+ await writeFile(filePath, options.content, "utf-8");
417
+ return {
418
+ stdout: `File written: ${options.path}`,
419
+ stderr: "",
420
+ exitCode: 0,
421
+ };
422
+ }
423
+ catch (error) {
424
+ const message = error instanceof Error ? error.message : String(error);
425
+ return {
426
+ stdout: "",
427
+ stderr: `Error writing file: ${message}`,
428
+ exitCode: 1,
429
+ };
430
+ }
431
+ }
432
+ async function executeEdit(options) {
433
+ try {
434
+ const filePath = resolve(options.cwd, options.path);
435
+ const rawContent = await readFile(filePath, "utf-8");
436
+ const { bom, text: content } = stripBom(rawContent);
437
+ const originalEnding = detectLineEnding(content);
438
+ const normalizedContent = normalizeToLF(content);
439
+ const { newContent } = applyEditsToNormalizedContent(normalizedContent, options.edits, options.path);
440
+ await writeFile(filePath, bom + restoreLineEndings(newContent, originalEnding), "utf-8");
441
+ return {
442
+ stdout: `File edited: ${options.path}`,
443
+ stderr: "",
444
+ exitCode: 0,
445
+ };
446
+ }
447
+ catch (error) {
448
+ const message = error instanceof Error ? error.message : String(error);
449
+ return {
450
+ stdout: "",
451
+ stderr: `Error editing file: ${message}`,
452
+ exitCode: 1,
453
+ };
454
+ }
455
+ }
456
+ export async function executeBuiltinCommand(command, args, context) {
457
+ const help = getBuiltinCommandHelpForArgs(command, args);
458
+ if (help) {
459
+ return {
460
+ stdout: help,
461
+ stderr: "",
462
+ exitCode: 0,
463
+ };
464
+ }
465
+ let parsed;
466
+ try {
467
+ parsed = parseBuiltinToolInput(command, args);
468
+ }
469
+ catch (error) {
470
+ const message = error instanceof Error ? error.message : String(error);
471
+ return {
472
+ stdout: "",
473
+ stderr: message,
474
+ exitCode: 1,
475
+ };
476
+ }
477
+ switch (parsed?.command) {
478
+ case "read": {
479
+ return executeRead({ ...parsed.input, cwd: context.cwd });
480
+ }
481
+ case "write": {
482
+ return executeWrite({ ...parsed.input, cwd: context.cwd });
483
+ }
484
+ case "edit": {
485
+ return executeEdit({
486
+ path: parsed.input.path,
487
+ edits: parsed.input.edits,
488
+ cwd: context.cwd,
489
+ });
490
+ }
491
+ default:
492
+ return {
493
+ stdout: "",
494
+ stderr: `Unknown builtin command: ${command}. Available commands: ${BUILTIN_COMMANDS.join(", ")}`,
495
+ exitCode: 1,
496
+ };
497
+ }
498
+ }
499
+ export const BUILTIN_COMMANDS = ["read", "write", "edit"];
500
+ /** @deprecated Use executeBuiltinCommand */
501
+ export const executeNativeCommand = executeBuiltinCommand;
502
+ /** @deprecated Use BUILTIN_COMMANDS */
503
+ export const NATIVE_COMMANDS = BUILTIN_COMMANDS;
@@ -0,0 +1,12 @@
1
+ export interface CompatCommandContext {
2
+ cwd: string;
3
+ }
4
+ export interface CompatCommandResult {
5
+ stdout: string;
6
+ stderr: string;
7
+ exitCode: number;
8
+ }
9
+ type CompatCommandName = "grep" | "find" | "ls";
10
+ export declare function executeCompatCommand(command: string, args: string[], context: CompatCommandContext): Promise<CompatCommandResult>;
11
+ export declare const COMPAT_COMMANDS: CompatCommandName[];
12
+ export {};