@lenylvt/pi-coding-agent 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (770) hide show
  1. package/CHANGELOG.md +3331 -0
  2. package/README.md +48 -0
  3. package/dist/bun/cli.d.ts +3 -0
  4. package/dist/bun/cli.d.ts.map +1 -0
  5. package/dist/bun/cli.js +5 -0
  6. package/dist/bun/cli.js.map +1 -0
  7. package/dist/cli/args.d.ts +49 -0
  8. package/dist/cli/args.d.ts.map +1 -0
  9. package/dist/cli/args.js +292 -0
  10. package/dist/cli/args.js.map +1 -0
  11. package/dist/cli/config-selector.d.ts +14 -0
  12. package/dist/cli/config-selector.d.ts.map +1 -0
  13. package/dist/cli/config-selector.js +31 -0
  14. package/dist/cli/config-selector.js.map +1 -0
  15. package/dist/cli/file-processor.d.ts +15 -0
  16. package/dist/cli/file-processor.d.ts.map +1 -0
  17. package/dist/cli/file-processor.js +83 -0
  18. package/dist/cli/file-processor.js.map +1 -0
  19. package/dist/cli/initial-message.d.ts +18 -0
  20. package/dist/cli/initial-message.d.ts.map +1 -0
  21. package/dist/cli/initial-message.js +22 -0
  22. package/dist/cli/initial-message.js.map +1 -0
  23. package/dist/cli/list-models.d.ts +9 -0
  24. package/dist/cli/list-models.d.ts.map +1 -0
  25. package/dist/cli/list-models.js +92 -0
  26. package/dist/cli/list-models.js.map +1 -0
  27. package/dist/cli/session-picker.d.ts +9 -0
  28. package/dist/cli/session-picker.d.ts.map +1 -0
  29. package/dist/cli/session-picker.js +35 -0
  30. package/dist/cli/session-picker.js.map +1 -0
  31. package/dist/cli.d.ts +3 -0
  32. package/dist/cli.d.ts.map +1 -0
  33. package/dist/cli.js +14 -0
  34. package/dist/cli.js.map +1 -0
  35. package/dist/config.d.ts +69 -0
  36. package/dist/config.d.ts.map +1 -0
  37. package/dist/config.js +178 -0
  38. package/dist/config.js.map +1 -0
  39. package/dist/core/agent-session.d.ts +622 -0
  40. package/dist/core/agent-session.d.ts.map +1 -0
  41. package/dist/core/agent-session.js +2688 -0
  42. package/dist/core/agent-session.js.map +1 -0
  43. package/dist/core/auth-storage.d.ts +132 -0
  44. package/dist/core/auth-storage.d.ts.map +1 -0
  45. package/dist/core/auth-storage.js +422 -0
  46. package/dist/core/auth-storage.js.map +1 -0
  47. package/dist/core/bash-executor.d.ts +46 -0
  48. package/dist/core/bash-executor.d.ts.map +1 -0
  49. package/dist/core/bash-executor.js +113 -0
  50. package/dist/core/bash-executor.js.map +1 -0
  51. package/dist/core/compaction/branch-summarization.d.ts +88 -0
  52. package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
  53. package/dist/core/compaction/branch-summarization.js +243 -0
  54. package/dist/core/compaction/branch-summarization.js.map +1 -0
  55. package/dist/core/compaction/compaction.d.ts +121 -0
  56. package/dist/core/compaction/compaction.d.ts.map +1 -0
  57. package/dist/core/compaction/compaction.js +613 -0
  58. package/dist/core/compaction/compaction.js.map +1 -0
  59. package/dist/core/compaction/index.d.ts +7 -0
  60. package/dist/core/compaction/index.d.ts.map +1 -0
  61. package/dist/core/compaction/index.js +7 -0
  62. package/dist/core/compaction/index.js.map +1 -0
  63. package/dist/core/compaction/utils.d.ts +38 -0
  64. package/dist/core/compaction/utils.d.ts.map +1 -0
  65. package/dist/core/compaction/utils.js +153 -0
  66. package/dist/core/compaction/utils.js.map +1 -0
  67. package/dist/core/defaults.d.ts +3 -0
  68. package/dist/core/defaults.d.ts.map +1 -0
  69. package/dist/core/defaults.js +2 -0
  70. package/dist/core/defaults.js.map +1 -0
  71. package/dist/core/diagnostics.d.ts +15 -0
  72. package/dist/core/diagnostics.d.ts.map +1 -0
  73. package/dist/core/diagnostics.js +2 -0
  74. package/dist/core/diagnostics.js.map +1 -0
  75. package/dist/core/event-bus.d.ts +9 -0
  76. package/dist/core/event-bus.d.ts.map +1 -0
  77. package/dist/core/event-bus.js +25 -0
  78. package/dist/core/event-bus.js.map +1 -0
  79. package/dist/core/exec.d.ts +29 -0
  80. package/dist/core/exec.d.ts.map +1 -0
  81. package/dist/core/exec.js +75 -0
  82. package/dist/core/exec.js.map +1 -0
  83. package/dist/core/export-html/ansi-to-html.d.ts +22 -0
  84. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
  85. package/dist/core/export-html/ansi-to-html.js +249 -0
  86. package/dist/core/export-html/ansi-to-html.js.map +1 -0
  87. package/dist/core/export-html/index.d.ts +37 -0
  88. package/dist/core/export-html/index.d.ts.map +1 -0
  89. package/dist/core/export-html/index.js +224 -0
  90. package/dist/core/export-html/index.js.map +1 -0
  91. package/dist/core/export-html/template.css +1001 -0
  92. package/dist/core/export-html/template.html +55 -0
  93. package/dist/core/export-html/template.js +1690 -0
  94. package/dist/core/export-html/tool-renderer.d.ts +38 -0
  95. package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
  96. package/dist/core/export-html/tool-renderer.js +95 -0
  97. package/dist/core/export-html/tool-renderer.js.map +1 -0
  98. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  99. package/dist/core/export-html/vendor/marked.min.js +6 -0
  100. package/dist/core/extensions/index.d.ts +12 -0
  101. package/dist/core/extensions/index.d.ts.map +1 -0
  102. package/dist/core/extensions/index.js +9 -0
  103. package/dist/core/extensions/index.js.map +1 -0
  104. package/dist/core/extensions/loader.d.ts +25 -0
  105. package/dist/core/extensions/loader.d.ts.map +1 -0
  106. package/dist/core/extensions/loader.js +436 -0
  107. package/dist/core/extensions/loader.js.map +1 -0
  108. package/dist/core/extensions/runner.d.ts +148 -0
  109. package/dist/core/extensions/runner.d.ts.map +1 -0
  110. package/dist/core/extensions/runner.js +700 -0
  111. package/dist/core/extensions/runner.js.map +1 -0
  112. package/dist/core/extensions/types.d.ts +1085 -0
  113. package/dist/core/extensions/types.d.ts.map +1 -0
  114. package/dist/core/extensions/types.js +35 -0
  115. package/dist/core/extensions/types.js.map +1 -0
  116. package/dist/core/extensions/wrapper.d.ts +20 -0
  117. package/dist/core/extensions/wrapper.d.ts.map +1 -0
  118. package/dist/core/extensions/wrapper.js +22 -0
  119. package/dist/core/extensions/wrapper.js.map +1 -0
  120. package/dist/core/footer-data-provider.d.ts +44 -0
  121. package/dist/core/footer-data-provider.d.ts.map +1 -0
  122. package/dist/core/footer-data-provider.js +252 -0
  123. package/dist/core/footer-data-provider.js.map +1 -0
  124. package/dist/core/index.d.ts +10 -0
  125. package/dist/core/index.d.ts.map +1 -0
  126. package/dist/core/index.js +10 -0
  127. package/dist/core/index.js.map +1 -0
  128. package/dist/core/keybindings.d.ts +275 -0
  129. package/dist/core/keybindings.d.ts.map +1 -0
  130. package/dist/core/keybindings.js +241 -0
  131. package/dist/core/keybindings.js.map +1 -0
  132. package/dist/core/messages.d.ts +77 -0
  133. package/dist/core/messages.d.ts.map +1 -0
  134. package/dist/core/messages.js +123 -0
  135. package/dist/core/messages.js.map +1 -0
  136. package/dist/core/model-registry.d.ts +132 -0
  137. package/dist/core/model-registry.d.ts.map +1 -0
  138. package/dist/core/model-registry.js +565 -0
  139. package/dist/core/model-registry.js.map +1 -0
  140. package/dist/core/model-resolver.d.ts +110 -0
  141. package/dist/core/model-resolver.d.ts.map +1 -0
  142. package/dist/core/model-resolver.js +464 -0
  143. package/dist/core/model-resolver.js.map +1 -0
  144. package/dist/core/output-guard.d.ts +6 -0
  145. package/dist/core/output-guard.d.ts.map +1 -0
  146. package/dist/core/output-guard.js +59 -0
  147. package/dist/core/output-guard.js.map +1 -0
  148. package/dist/core/package-manager.d.ts +172 -0
  149. package/dist/core/package-manager.d.ts.map +1 -0
  150. package/dist/core/package-manager.js +1801 -0
  151. package/dist/core/package-manager.js.map +1 -0
  152. package/dist/core/prompt-templates.d.ts +51 -0
  153. package/dist/core/prompt-templates.d.ts.map +1 -0
  154. package/dist/core/prompt-templates.js +249 -0
  155. package/dist/core/prompt-templates.js.map +1 -0
  156. package/dist/core/resolve-config-value.d.ts +23 -0
  157. package/dist/core/resolve-config-value.d.ts.map +1 -0
  158. package/dist/core/resolve-config-value.js +126 -0
  159. package/dist/core/resolve-config-value.js.map +1 -0
  160. package/dist/core/resource-loader.d.ts +185 -0
  161. package/dist/core/resource-loader.d.ts.map +1 -0
  162. package/dist/core/resource-loader.js +698 -0
  163. package/dist/core/resource-loader.js.map +1 -0
  164. package/dist/core/sdk.d.ts +90 -0
  165. package/dist/core/sdk.d.ts.map +1 -0
  166. package/dist/core/sdk.js +233 -0
  167. package/dist/core/sdk.js.map +1 -0
  168. package/dist/core/self-update.d.ts +3 -0
  169. package/dist/core/self-update.d.ts.map +1 -0
  170. package/dist/core/self-update.js +46 -0
  171. package/dist/core/self-update.js.map +1 -0
  172. package/dist/core/session-manager.d.ts +329 -0
  173. package/dist/core/session-manager.d.ts.map +1 -0
  174. package/dist/core/session-manager.js +1097 -0
  175. package/dist/core/session-manager.js.map +1 -0
  176. package/dist/core/settings-manager.d.ts +237 -0
  177. package/dist/core/settings-manager.d.ts.map +1 -0
  178. package/dist/core/settings-manager.js +708 -0
  179. package/dist/core/settings-manager.js.map +1 -0
  180. package/dist/core/skills.d.ts +60 -0
  181. package/dist/core/skills.d.ts.map +1 -0
  182. package/dist/core/skills.js +409 -0
  183. package/dist/core/skills.js.map +1 -0
  184. package/dist/core/slash-commands.d.ts +14 -0
  185. package/dist/core/slash-commands.d.ts.map +1 -0
  186. package/dist/core/slash-commands.js +22 -0
  187. package/dist/core/slash-commands.js.map +1 -0
  188. package/dist/core/source-info.d.ts +18 -0
  189. package/dist/core/source-info.d.ts.map +1 -0
  190. package/dist/core/source-info.js +19 -0
  191. package/dist/core/source-info.js.map +1 -0
  192. package/dist/core/system-prompt.d.ts +28 -0
  193. package/dist/core/system-prompt.d.ts.map +1 -0
  194. package/dist/core/system-prompt.js +116 -0
  195. package/dist/core/system-prompt.js.map +1 -0
  196. package/dist/core/timings.d.ts +8 -0
  197. package/dist/core/timings.d.ts.map +1 -0
  198. package/dist/core/timings.js +31 -0
  199. package/dist/core/timings.js.map +1 -0
  200. package/dist/core/tools/bash.d.ts +73 -0
  201. package/dist/core/tools/bash.d.ts.map +1 -0
  202. package/dist/core/tools/bash.js +342 -0
  203. package/dist/core/tools/bash.js.map +1 -0
  204. package/dist/core/tools/edit-diff.d.ts +85 -0
  205. package/dist/core/tools/edit-diff.d.ts.map +1 -0
  206. package/dist/core/tools/edit-diff.js +337 -0
  207. package/dist/core/tools/edit-diff.js.map +1 -0
  208. package/dist/core/tools/edit.d.ts +53 -0
  209. package/dist/core/tools/edit.d.ts.map +1 -0
  210. package/dist/core/tools/edit.js +196 -0
  211. package/dist/core/tools/edit.js.map +1 -0
  212. package/dist/core/tools/file-mutation-queue.d.ts +6 -0
  213. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
  214. package/dist/core/tools/file-mutation-queue.js +37 -0
  215. package/dist/core/tools/file-mutation-queue.js.map +1 -0
  216. package/dist/core/tools/find.d.ts +46 -0
  217. package/dist/core/tools/find.d.ts.map +1 -0
  218. package/dist/core/tools/find.js +258 -0
  219. package/dist/core/tools/find.js.map +1 -0
  220. package/dist/core/tools/grep.d.ts +56 -0
  221. package/dist/core/tools/grep.d.ts.map +1 -0
  222. package/dist/core/tools/grep.js +293 -0
  223. package/dist/core/tools/grep.js.map +1 -0
  224. package/dist/core/tools/index.d.ts +115 -0
  225. package/dist/core/tools/index.d.ts.map +1 -0
  226. package/dist/core/tools/index.js +86 -0
  227. package/dist/core/tools/index.js.map +1 -0
  228. package/dist/core/tools/ls.d.ts +46 -0
  229. package/dist/core/tools/ls.d.ts.map +1 -0
  230. package/dist/core/tools/ls.js +172 -0
  231. package/dist/core/tools/ls.js.map +1 -0
  232. package/dist/core/tools/path-utils.d.ts +8 -0
  233. package/dist/core/tools/path-utils.d.ts.map +1 -0
  234. package/dist/core/tools/path-utils.js +81 -0
  235. package/dist/core/tools/path-utils.js.map +1 -0
  236. package/dist/core/tools/read.d.ts +46 -0
  237. package/dist/core/tools/read.d.ts.map +1 -0
  238. package/dist/core/tools/read.js +225 -0
  239. package/dist/core/tools/read.js.map +1 -0
  240. package/dist/core/tools/render-utils.d.ts +21 -0
  241. package/dist/core/tools/render-utils.d.ts.map +1 -0
  242. package/dist/core/tools/render-utils.js +49 -0
  243. package/dist/core/tools/render-utils.js.map +1 -0
  244. package/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
  245. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
  246. package/dist/core/tools/tool-definition-wrapper.js +32 -0
  247. package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
  248. package/dist/core/tools/truncate.d.ts +70 -0
  249. package/dist/core/tools/truncate.d.ts.map +1 -0
  250. package/dist/core/tools/truncate.js +205 -0
  251. package/dist/core/tools/truncate.js.map +1 -0
  252. package/dist/core/tools/write.d.ts +35 -0
  253. package/dist/core/tools/write.d.ts.map +1 -0
  254. package/dist/core/tools/write.js +216 -0
  255. package/dist/core/tools/write.js.map +1 -0
  256. package/dist/core/version-check.d.ts +2 -0
  257. package/dist/core/version-check.d.ts.map +1 -0
  258. package/dist/core/version-check.js +73 -0
  259. package/dist/core/version-check.js.map +1 -0
  260. package/dist/index.d.ts +28 -0
  261. package/dist/index.d.ts.map +1 -0
  262. package/dist/index.js +43 -0
  263. package/dist/index.js.map +1 -0
  264. package/dist/main.d.ts +8 -0
  265. package/dist/main.d.ts.map +1 -0
  266. package/dist/main.js +811 -0
  267. package/dist/main.js.map +1 -0
  268. package/dist/migrations.d.ts +32 -0
  269. package/dist/migrations.d.ts.map +1 -0
  270. package/dist/migrations.js +258 -0
  271. package/dist/migrations.js.map +1 -0
  272. package/dist/modes/index.d.ts +9 -0
  273. package/dist/modes/index.d.ts.map +1 -0
  274. package/dist/modes/index.js +8 -0
  275. package/dist/modes/index.js.map +1 -0
  276. package/dist/modes/interactive/components/armin.d.ts +34 -0
  277. package/dist/modes/interactive/components/armin.d.ts.map +1 -0
  278. package/dist/modes/interactive/components/armin.js +333 -0
  279. package/dist/modes/interactive/components/armin.js.map +1 -0
  280. package/dist/modes/interactive/components/assistant-message.d.ts +18 -0
  281. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  282. package/dist/modes/interactive/components/assistant-message.js +107 -0
  283. package/dist/modes/interactive/components/assistant-message.js.map +1 -0
  284. package/dist/modes/interactive/components/bash-execution.d.ts +34 -0
  285. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  286. package/dist/modes/interactive/components/bash-execution.js +175 -0
  287. package/dist/modes/interactive/components/bash-execution.js.map +1 -0
  288. package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
  289. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  290. package/dist/modes/interactive/components/bordered-loader.js +51 -0
  291. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  292. package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
  293. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  294. package/dist/modes/interactive/components/branch-summary-message.js +44 -0
  295. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  296. package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
  297. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  298. package/dist/modes/interactive/components/compaction-summary-message.js +45 -0
  299. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  300. package/dist/modes/interactive/components/config-selector.d.ts +71 -0
  301. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  302. package/dist/modes/interactive/components/config-selector.js +479 -0
  303. package/dist/modes/interactive/components/config-selector.js.map +1 -0
  304. package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
  305. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  306. package/dist/modes/interactive/components/countdown-timer.js +33 -0
  307. package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  308. package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
  309. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  310. package/dist/modes/interactive/components/custom-editor.js +70 -0
  311. package/dist/modes/interactive/components/custom-editor.js.map +1 -0
  312. package/dist/modes/interactive/components/custom-message.d.ts +20 -0
  313. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  314. package/dist/modes/interactive/components/custom-message.js +79 -0
  315. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  316. package/dist/modes/interactive/components/diff.d.ts +12 -0
  317. package/dist/modes/interactive/components/diff.d.ts.map +1 -0
  318. package/dist/modes/interactive/components/diff.js +133 -0
  319. package/dist/modes/interactive/components/diff.js.map +1 -0
  320. package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
  321. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  322. package/dist/modes/interactive/components/dynamic-border.js +21 -0
  323. package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  324. package/dist/modes/interactive/components/extension-editor.d.ts +20 -0
  325. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  326. package/dist/modes/interactive/components/extension-editor.js +111 -0
  327. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  328. package/dist/modes/interactive/components/extension-input.d.ts +23 -0
  329. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  330. package/dist/modes/interactive/components/extension-input.js +61 -0
  331. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  332. package/dist/modes/interactive/components/extension-selector.d.ts +24 -0
  333. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  334. package/dist/modes/interactive/components/extension-selector.js +78 -0
  335. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  336. package/dist/modes/interactive/components/footer.d.ts +26 -0
  337. package/dist/modes/interactive/components/footer.d.ts.map +1 -0
  338. package/dist/modes/interactive/components/footer.js +198 -0
  339. package/dist/modes/interactive/components/footer.js.map +1 -0
  340. package/dist/modes/interactive/components/index.d.ts +31 -0
  341. package/dist/modes/interactive/components/index.d.ts.map +1 -0
  342. package/dist/modes/interactive/components/index.js +32 -0
  343. package/dist/modes/interactive/components/index.js.map +1 -0
  344. package/dist/modes/interactive/components/keybinding-hints.d.ts +8 -0
  345. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
  346. package/dist/modes/interactive/components/keybinding-hints.js +22 -0
  347. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
  348. package/dist/modes/interactive/components/login-dialog.d.ts +42 -0
  349. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
  350. package/dist/modes/interactive/components/login-dialog.js +145 -0
  351. package/dist/modes/interactive/components/login-dialog.js.map +1 -0
  352. package/dist/modes/interactive/components/model-selector.d.ts +47 -0
  353. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
  354. package/dist/modes/interactive/components/model-selector.js +275 -0
  355. package/dist/modes/interactive/components/model-selector.js.map +1 -0
  356. package/dist/modes/interactive/components/oauth-selector.d.ts +19 -0
  357. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
  358. package/dist/modes/interactive/components/oauth-selector.js +97 -0
  359. package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
  360. package/dist/modes/interactive/components/scoped-models-selector.d.ts +49 -0
  361. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
  362. package/dist/modes/interactive/components/scoped-models-selector.js +275 -0
  363. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
  364. package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
  365. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
  366. package/dist/modes/interactive/components/session-selector-search.js +155 -0
  367. package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
  368. package/dist/modes/interactive/components/session-selector.d.ts +95 -0
  369. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  370. package/dist/modes/interactive/components/session-selector.js +848 -0
  371. package/dist/modes/interactive/components/session-selector.js.map +1 -0
  372. package/dist/modes/interactive/components/settings-selector.d.ts +58 -0
  373. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  374. package/dist/modes/interactive/components/settings-selector.js +301 -0
  375. package/dist/modes/interactive/components/settings-selector.js.map +1 -0
  376. package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
  377. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  378. package/dist/modes/interactive/components/show-images-selector.js +39 -0
  379. package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  380. package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
  381. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  382. package/dist/modes/interactive/components/skill-invocation-message.js +47 -0
  383. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  384. package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
  385. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  386. package/dist/modes/interactive/components/theme-selector.js +50 -0
  387. package/dist/modes/interactive/components/theme-selector.js.map +1 -0
  388. package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
  389. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  390. package/dist/modes/interactive/components/thinking-selector.js +51 -0
  391. package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  392. package/dist/modes/interactive/components/tool-execution.d.ts +58 -0
  393. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  394. package/dist/modes/interactive/components/tool-execution.js +274 -0
  395. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  396. package/dist/modes/interactive/components/tree-selector.d.ts +87 -0
  397. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  398. package/dist/modes/interactive/components/tree-selector.js +1051 -0
  399. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  400. package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
  401. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  402. package/dist/modes/interactive/components/user-message-selector.js +113 -0
  403. package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  404. package/dist/modes/interactive/components/user-message.d.ts +9 -0
  405. package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  406. package/dist/modes/interactive/components/user-message.js +28 -0
  407. package/dist/modes/interactive/components/user-message.js.map +1 -0
  408. package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
  409. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
  410. package/dist/modes/interactive/components/visual-truncate.js +33 -0
  411. package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
  412. package/dist/modes/interactive/interactive-mode.d.ts +311 -0
  413. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  414. package/dist/modes/interactive/interactive-mode.js +3798 -0
  415. package/dist/modes/interactive/interactive-mode.js.map +1 -0
  416. package/dist/modes/interactive/theme/dark.json +85 -0
  417. package/dist/modes/interactive/theme/light.json +84 -0
  418. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  419. package/dist/modes/interactive/theme/theme.d.ts +81 -0
  420. package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
  421. package/dist/modes/interactive/theme/theme.js +975 -0
  422. package/dist/modes/interactive/theme/theme.js.map +1 -0
  423. package/dist/modes/print-mode.d.ts +28 -0
  424. package/dist/modes/print-mode.d.ts.map +1 -0
  425. package/dist/modes/print-mode.js +107 -0
  426. package/dist/modes/print-mode.js.map +1 -0
  427. package/dist/modes/rpc/jsonl.d.ts +17 -0
  428. package/dist/modes/rpc/jsonl.d.ts.map +1 -0
  429. package/dist/modes/rpc/jsonl.js +49 -0
  430. package/dist/modes/rpc/jsonl.js.map +1 -0
  431. package/dist/modes/rpc/rpc-client.d.ts +217 -0
  432. package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
  433. package/dist/modes/rpc/rpc-client.js +401 -0
  434. package/dist/modes/rpc/rpc-client.js.map +1 -0
  435. package/dist/modes/rpc/rpc-mode.d.ts +20 -0
  436. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
  437. package/dist/modes/rpc/rpc-mode.js +522 -0
  438. package/dist/modes/rpc/rpc-mode.js.map +1 -0
  439. package/dist/modes/rpc/rpc-types.d.ts +408 -0
  440. package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
  441. package/dist/modes/rpc/rpc-types.js +8 -0
  442. package/dist/modes/rpc/rpc-types.js.map +1 -0
  443. package/dist/utils/changelog.d.ts +21 -0
  444. package/dist/utils/changelog.d.ts.map +1 -0
  445. package/dist/utils/changelog.js +87 -0
  446. package/dist/utils/changelog.js.map +1 -0
  447. package/dist/utils/child-process.d.ts +11 -0
  448. package/dist/utils/child-process.d.ts.map +1 -0
  449. package/dist/utils/child-process.js +78 -0
  450. package/dist/utils/child-process.js.map +1 -0
  451. package/dist/utils/clipboard-image.d.ts +11 -0
  452. package/dist/utils/clipboard-image.d.ts.map +1 -0
  453. package/dist/utils/clipboard-image.js +245 -0
  454. package/dist/utils/clipboard-image.js.map +1 -0
  455. package/dist/utils/clipboard-native.d.ts +8 -0
  456. package/dist/utils/clipboard-native.d.ts.map +1 -0
  457. package/dist/utils/clipboard-native.js +14 -0
  458. package/dist/utils/clipboard-native.js.map +1 -0
  459. package/dist/utils/clipboard.d.ts +2 -0
  460. package/dist/utils/clipboard.d.ts.map +1 -0
  461. package/dist/utils/clipboard.js +78 -0
  462. package/dist/utils/clipboard.js.map +1 -0
  463. package/dist/utils/exif-orientation.d.ts +5 -0
  464. package/dist/utils/exif-orientation.d.ts.map +1 -0
  465. package/dist/utils/exif-orientation.js +158 -0
  466. package/dist/utils/exif-orientation.js.map +1 -0
  467. package/dist/utils/frontmatter.d.ts +8 -0
  468. package/dist/utils/frontmatter.d.ts.map +1 -0
  469. package/dist/utils/frontmatter.js +26 -0
  470. package/dist/utils/frontmatter.js.map +1 -0
  471. package/dist/utils/git.d.ts +26 -0
  472. package/dist/utils/git.d.ts.map +1 -0
  473. package/dist/utils/git.js +163 -0
  474. package/dist/utils/git.js.map +1 -0
  475. package/dist/utils/image-convert.d.ts +9 -0
  476. package/dist/utils/image-convert.d.ts.map +1 -0
  477. package/dist/utils/image-convert.js +39 -0
  478. package/dist/utils/image-convert.js.map +1 -0
  479. package/dist/utils/image-resize.d.ts +36 -0
  480. package/dist/utils/image-resize.d.ts.map +1 -0
  481. package/dist/utils/image-resize.js +137 -0
  482. package/dist/utils/image-resize.js.map +1 -0
  483. package/dist/utils/mime.d.ts +2 -0
  484. package/dist/utils/mime.d.ts.map +1 -0
  485. package/dist/utils/mime.js +26 -0
  486. package/dist/utils/mime.js.map +1 -0
  487. package/dist/utils/photon.d.ts +21 -0
  488. package/dist/utils/photon.d.ts.map +1 -0
  489. package/dist/utils/photon.js +121 -0
  490. package/dist/utils/photon.js.map +1 -0
  491. package/dist/utils/shell.d.ts +26 -0
  492. package/dist/utils/shell.d.ts.map +1 -0
  493. package/dist/utils/shell.js +186 -0
  494. package/dist/utils/shell.js.map +1 -0
  495. package/dist/utils/sleep.d.ts +5 -0
  496. package/dist/utils/sleep.d.ts.map +1 -0
  497. package/dist/utils/sleep.js +17 -0
  498. package/dist/utils/sleep.js.map +1 -0
  499. package/dist/utils/tools-manager.d.ts +3 -0
  500. package/dist/utils/tools-manager.d.ts.map +1 -0
  501. package/dist/utils/tools-manager.js +252 -0
  502. package/dist/utils/tools-manager.js.map +1 -0
  503. package/docs/compaction.md +394 -0
  504. package/docs/custom-provider.md +327 -0
  505. package/docs/extensions.md +2229 -0
  506. package/docs/images/doom-extension.png +0 -0
  507. package/docs/images/exy.png +0 -0
  508. package/docs/images/interactive-mode.png +0 -0
  509. package/docs/images/tree-view.png +0 -0
  510. package/docs/json.md +82 -0
  511. package/docs/keybindings.md +173 -0
  512. package/docs/models.md +197 -0
  513. package/docs/packages.md +218 -0
  514. package/docs/prompt-templates.md +67 -0
  515. package/docs/providers.md +98 -0
  516. package/docs/release.md +40 -0
  517. package/docs/rpc.md +1377 -0
  518. package/docs/sdk.md +971 -0
  519. package/docs/session.md +412 -0
  520. package/docs/settings.md +149 -0
  521. package/docs/shell-aliases.md +13 -0
  522. package/docs/skills.md +232 -0
  523. package/docs/terminal-setup.md +106 -0
  524. package/docs/termux.md +127 -0
  525. package/docs/themes.md +295 -0
  526. package/docs/tmux.md +61 -0
  527. package/docs/tree.md +228 -0
  528. package/docs/tui.md +887 -0
  529. package/docs/windows.md +17 -0
  530. package/examples/README.md +25 -0
  531. package/examples/extensions/README.md +204 -0
  532. package/examples/extensions/auto-commit-on-exit.ts +49 -0
  533. package/examples/extensions/bash-spawn-hook.ts +30 -0
  534. package/examples/extensions/bookmark.ts +50 -0
  535. package/examples/extensions/built-in-tool-renderer.ts +246 -0
  536. package/examples/extensions/claude-rules.ts +86 -0
  537. package/examples/extensions/commands.ts +72 -0
  538. package/examples/extensions/confirm-destructive.ts +59 -0
  539. package/examples/extensions/custom-compaction.ts +127 -0
  540. package/examples/extensions/custom-footer.ts +64 -0
  541. package/examples/extensions/custom-header.ts +73 -0
  542. package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
  543. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  544. package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
  545. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  546. package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  547. package/examples/extensions/dirty-repo-guard.ts +56 -0
  548. package/examples/extensions/doom-overlay/README.md +46 -0
  549. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  550. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  551. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  552. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  553. package/examples/extensions/doom-overlay/doom-component.ts +132 -0
  554. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  555. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  556. package/examples/extensions/doom-overlay/index.ts +74 -0
  557. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  558. package/examples/extensions/dynamic-resources/SKILL.md +8 -0
  559. package/examples/extensions/dynamic-resources/dynamic.json +79 -0
  560. package/examples/extensions/dynamic-resources/dynamic.md +5 -0
  561. package/examples/extensions/dynamic-resources/index.ts +15 -0
  562. package/examples/extensions/dynamic-tools.ts +74 -0
  563. package/examples/extensions/event-bus.ts +43 -0
  564. package/examples/extensions/file-trigger.ts +41 -0
  565. package/examples/extensions/git-checkpoint.ts +53 -0
  566. package/examples/extensions/handoff.ts +153 -0
  567. package/examples/extensions/hello.ts +25 -0
  568. package/examples/extensions/hidden-thinking-label.ts +57 -0
  569. package/examples/extensions/inline-bash.ts +94 -0
  570. package/examples/extensions/input-transform.ts +43 -0
  571. package/examples/extensions/interactive-shell.ts +196 -0
  572. package/examples/extensions/mac-system-theme.ts +47 -0
  573. package/examples/extensions/message-renderer.ts +59 -0
  574. package/examples/extensions/minimal-mode.ts +426 -0
  575. package/examples/extensions/modal-editor.ts +85 -0
  576. package/examples/extensions/model-status.ts +31 -0
  577. package/examples/extensions/notify.ts +55 -0
  578. package/examples/extensions/overlay-qa-tests.ts +1348 -0
  579. package/examples/extensions/overlay-test.ts +150 -0
  580. package/examples/extensions/permission-gate.ts +34 -0
  581. package/examples/extensions/pirate.ts +47 -0
  582. package/examples/extensions/plan-mode/README.md +65 -0
  583. package/examples/extensions/plan-mode/index.ts +340 -0
  584. package/examples/extensions/plan-mode/utils.ts +166 -0
  585. package/examples/extensions/preset.ts +397 -0
  586. package/examples/extensions/protected-paths.ts +30 -0
  587. package/examples/extensions/provider-payload.ts +14 -0
  588. package/examples/extensions/qna.ts +122 -0
  589. package/examples/extensions/question.ts +264 -0
  590. package/examples/extensions/questionnaire.ts +427 -0
  591. package/examples/extensions/rainbow-editor.ts +88 -0
  592. package/examples/extensions/reload-runtime.ts +37 -0
  593. package/examples/extensions/rpc-demo.ts +124 -0
  594. package/examples/extensions/sandbox/index.ts +321 -0
  595. package/examples/extensions/sandbox/package.json +19 -0
  596. package/examples/extensions/send-user-message.ts +97 -0
  597. package/examples/extensions/session-name.ts +27 -0
  598. package/examples/extensions/shutdown-command.ts +63 -0
  599. package/examples/extensions/snake.ts +343 -0
  600. package/examples/extensions/space-invaders.ts +560 -0
  601. package/examples/extensions/ssh.ts +220 -0
  602. package/examples/extensions/status-line.ts +40 -0
  603. package/examples/extensions/subagent/README.md +172 -0
  604. package/examples/extensions/subagent/agents/planner.md +37 -0
  605. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  606. package/examples/extensions/subagent/agents/scout.md +50 -0
  607. package/examples/extensions/subagent/agents/worker.md +24 -0
  608. package/examples/extensions/subagent/agents.ts +126 -0
  609. package/examples/extensions/subagent/index.ts +986 -0
  610. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  611. package/examples/extensions/subagent/prompts/implement.md +10 -0
  612. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  613. package/examples/extensions/summarize.ts +206 -0
  614. package/examples/extensions/system-prompt-header.ts +17 -0
  615. package/examples/extensions/timed-confirm.ts +70 -0
  616. package/examples/extensions/titlebar-spinner.ts +58 -0
  617. package/examples/extensions/todo.ts +299 -0
  618. package/examples/extensions/tool-override.ts +144 -0
  619. package/examples/extensions/tools.ts +146 -0
  620. package/examples/extensions/trigger-compact.ts +50 -0
  621. package/examples/extensions/truncated-tool.ts +195 -0
  622. package/examples/extensions/widget-placement.ts +17 -0
  623. package/examples/extensions/with-deps/index.ts +32 -0
  624. package/examples/extensions/with-deps/package.json +22 -0
  625. package/examples/rpc-extension-ui.ts +632 -0
  626. package/examples/sdk/01-minimal.ts +22 -0
  627. package/examples/sdk/02-custom-model.ts +49 -0
  628. package/examples/sdk/03-custom-prompt.ts +55 -0
  629. package/examples/sdk/04-skills.ts +52 -0
  630. package/examples/sdk/05-tools.ts +56 -0
  631. package/examples/sdk/06-extensions.ts +88 -0
  632. package/examples/sdk/07-context-files.ts +40 -0
  633. package/examples/sdk/08-prompt-templates.ts +48 -0
  634. package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
  635. package/examples/sdk/10-settings.ts +51 -0
  636. package/examples/sdk/11-sessions.ts +48 -0
  637. package/examples/sdk/12-full-control.ts +81 -0
  638. package/examples/sdk/README.md +144 -0
  639. package/package.json +95 -0
  640. package/src/bun/cli.ts +5 -0
  641. package/src/cli/args.ts +309 -0
  642. package/src/cli/config-selector.ts +52 -0
  643. package/src/cli/file-processor.ts +100 -0
  644. package/src/cli/initial-message.ts +43 -0
  645. package/src/cli/list-models.ts +104 -0
  646. package/src/cli/session-picker.ts +52 -0
  647. package/src/cli.ts +16 -0
  648. package/src/config.ts +214 -0
  649. package/src/core/agent-session.ts +3279 -0
  650. package/src/core/auth-storage.ts +488 -0
  651. package/src/core/bash-executor.ts +158 -0
  652. package/src/core/compaction/branch-summarization.ts +355 -0
  653. package/src/core/compaction/compaction.ts +823 -0
  654. package/src/core/compaction/index.ts +7 -0
  655. package/src/core/compaction/utils.ts +170 -0
  656. package/src/core/defaults.ts +3 -0
  657. package/src/core/diagnostics.ts +15 -0
  658. package/src/core/event-bus.ts +33 -0
  659. package/src/core/exec.ts +107 -0
  660. package/src/core/export-html/ansi-to-html.ts +258 -0
  661. package/src/core/export-html/index.ts +314 -0
  662. package/src/core/export-html/template.css +1001 -0
  663. package/src/core/export-html/template.html +55 -0
  664. package/src/core/export-html/template.js +1690 -0
  665. package/src/core/export-html/tool-renderer.ts +156 -0
  666. package/src/core/export-html/vendor/highlight.min.js +1213 -0
  667. package/src/core/export-html/vendor/marked.min.js +6 -0
  668. package/src/core/extensions/index.ts +168 -0
  669. package/src/core/extensions/loader.ts +557 -0
  670. package/src/core/extensions/runner.ts +915 -0
  671. package/src/core/extensions/types.ts +1461 -0
  672. package/src/core/extensions/wrapper.ts +27 -0
  673. package/src/core/footer-data-provider.ts +273 -0
  674. package/src/core/index.ts +61 -0
  675. package/src/core/keybindings.ts +302 -0
  676. package/src/core/messages.ts +195 -0
  677. package/src/core/model-registry.ts +766 -0
  678. package/src/core/model-resolver.ts +606 -0
  679. package/src/core/output-guard.ts +74 -0
  680. package/src/core/package-manager.ts +2222 -0
  681. package/src/core/prompt-templates.ts +294 -0
  682. package/src/core/resolve-config-value.ts +142 -0
  683. package/src/core/resource-loader.ts +886 -0
  684. package/src/core/sdk.ts +360 -0
  685. package/src/core/self-update.ts +57 -0
  686. package/src/core/session-manager.ts +1410 -0
  687. package/src/core/settings-manager.ts +973 -0
  688. package/src/core/skills.ts +508 -0
  689. package/src/core/slash-commands.ts +37 -0
  690. package/src/core/source-info.ts +40 -0
  691. package/src/core/system-prompt.ts +168 -0
  692. package/src/core/timings.ts +31 -0
  693. package/src/core/tools/bash.ts +431 -0
  694. package/src/core/tools/edit-diff.ts +445 -0
  695. package/src/core/tools/edit.ts +307 -0
  696. package/src/core/tools/file-mutation-queue.ts +39 -0
  697. package/src/core/tools/find.ts +314 -0
  698. package/src/core/tools/grep.ts +375 -0
  699. package/src/core/tools/index.ts +193 -0
  700. package/src/core/tools/ls.ts +233 -0
  701. package/src/core/tools/path-utils.ts +94 -0
  702. package/src/core/tools/read.ts +269 -0
  703. package/src/core/tools/render-utils.ts +64 -0
  704. package/src/core/tools/tool-definition-wrapper.ts +43 -0
  705. package/src/core/tools/truncate.ts +265 -0
  706. package/src/core/tools/write.ts +285 -0
  707. package/src/core/version-check.ts +85 -0
  708. package/src/index.ts +348 -0
  709. package/src/main.ts +958 -0
  710. package/src/migrations.ts +290 -0
  711. package/src/modes/index.ts +9 -0
  712. package/src/modes/interactive/components/armin.ts +382 -0
  713. package/src/modes/interactive/components/assistant-message.ts +130 -0
  714. package/src/modes/interactive/components/bash-execution.ts +218 -0
  715. package/src/modes/interactive/components/bordered-loader.ts +66 -0
  716. package/src/modes/interactive/components/branch-summary-message.ts +58 -0
  717. package/src/modes/interactive/components/compaction-summary-message.ts +59 -0
  718. package/src/modes/interactive/components/config-selector.ts +592 -0
  719. package/src/modes/interactive/components/countdown-timer.ts +38 -0
  720. package/src/modes/interactive/components/custom-editor.ts +80 -0
  721. package/src/modes/interactive/components/custom-message.ts +99 -0
  722. package/src/modes/interactive/components/diff.ts +147 -0
  723. package/src/modes/interactive/components/dynamic-border.ts +25 -0
  724. package/src/modes/interactive/components/extension-editor.ts +147 -0
  725. package/src/modes/interactive/components/extension-input.ts +87 -0
  726. package/src/modes/interactive/components/extension-selector.ts +107 -0
  727. package/src/modes/interactive/components/footer.ts +216 -0
  728. package/src/modes/interactive/components/index.ts +31 -0
  729. package/src/modes/interactive/components/keybinding-hints.ts +24 -0
  730. package/src/modes/interactive/components/login-dialog.ts +178 -0
  731. package/src/modes/interactive/components/model-selector.ts +328 -0
  732. package/src/modes/interactive/components/oauth-selector.ts +121 -0
  733. package/src/modes/interactive/components/scoped-models-selector.ts +346 -0
  734. package/src/modes/interactive/components/session-selector-search.ts +194 -0
  735. package/src/modes/interactive/components/session-selector.ts +1010 -0
  736. package/src/modes/interactive/components/settings-selector.ts +432 -0
  737. package/src/modes/interactive/components/show-images-selector.ts +50 -0
  738. package/src/modes/interactive/components/skill-invocation-message.ts +55 -0
  739. package/src/modes/interactive/components/theme-selector.ts +67 -0
  740. package/src/modes/interactive/components/thinking-selector.ts +74 -0
  741. package/src/modes/interactive/components/tool-execution.ts +328 -0
  742. package/src/modes/interactive/components/tree-selector.ts +1197 -0
  743. package/src/modes/interactive/components/user-message-selector.ts +143 -0
  744. package/src/modes/interactive/components/user-message.ts +33 -0
  745. package/src/modes/interactive/components/visual-truncate.ts +50 -0
  746. package/src/modes/interactive/interactive-mode.ts +4501 -0
  747. package/src/modes/interactive/theme/dark.json +85 -0
  748. package/src/modes/interactive/theme/light.json +84 -0
  749. package/src/modes/interactive/theme/theme-schema.json +335 -0
  750. package/src/modes/interactive/theme/theme.ts +1137 -0
  751. package/src/modes/print-mode.ts +131 -0
  752. package/src/modes/rpc/jsonl.ts +58 -0
  753. package/src/modes/rpc/rpc-client.ts +505 -0
  754. package/src/modes/rpc/rpc-mode.ts +654 -0
  755. package/src/modes/rpc/rpc-types.ts +262 -0
  756. package/src/utils/changelog.ts +99 -0
  757. package/src/utils/child-process.ts +86 -0
  758. package/src/utils/clipboard-image.ts +300 -0
  759. package/src/utils/clipboard-native.ts +22 -0
  760. package/src/utils/clipboard.ts +81 -0
  761. package/src/utils/exif-orientation.ts +183 -0
  762. package/src/utils/frontmatter.ts +39 -0
  763. package/src/utils/git.ts +192 -0
  764. package/src/utils/image-convert.ts +41 -0
  765. package/src/utils/image-resize.ts +176 -0
  766. package/src/utils/mime.ts +30 -0
  767. package/src/utils/photon.ts +139 -0
  768. package/src/utils/shell.ts +202 -0
  769. package/src/utils/sleep.ts +18 -0
  770. package/src/utils/tools-manager.ts +287 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skills.js","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACnF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,yBAAyB,EAAmB,MAAM,kBAAkB,CAAC;AAE9E,+BAA+B;AAC/B,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,sCAAsC;AACtC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC,MAAM,iBAAiB,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAIjE,SAAS,WAAW,CAAC,CAAS,EAAU;IACvC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAAA,CAC9B;AAED,SAAS,mBAAmB,CAAC,IAAY,EAAE,MAAc,EAAiB;IACzE,MA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AY,EAAE,CAAC,CAAC;YAC5G,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;YACrF,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QACvE,CAAC;IACF,CAAC;IAED,OAAO;QACN,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrC,WAAW,EAAE,CAAC,GAAG,cAAc,EAAE,GAAG,oBAAoB,CAAC;KACzD,CAAC;AAAA,CACF","sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from \"fs\";\nimport ignore from \"ignore\";\nimport { homedir } from \"os\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../config.js\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\nimport { createSyntheticSourceInfo, type SourceInfo } from \"./source-info.js\";\n\n/** Max name length per spec */\nconst MAX_NAME_LENGTH = 64;\n\n/** Max description length per spec */\nconst MAX_DESCRIPTION_LENGTH = 1024;\n\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\n\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\nfunction toPosixPath(p: string): string {\n\treturn p.split(sep).join(\"/\");\n}\n\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\n\tlet pattern = line;\n\tlet negated = false;\n\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\n\tif (pattern.startsWith(\"/\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\n\nfunction addIgnoreRules(ig: IgnoreMatcher, dir: string, rootDir: string): void {\n\tconst relativeDir = relative(rootDir, dir);\n\tconst prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : \"\";\n\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePath = join(dir, filename);\n\t\tif (!existsSync(ignorePath)) continue;\n\t\ttry {\n\t\t\tconst content = readFileSync(ignorePath, \"utf-8\");\n\t\t\tconst patterns = content\n\t\t\t\t.split(/\\r?\\n/)\n\t\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t\t.filter((line): line is string => Boolean(line));\n\t\t\tif (patterns.length > 0) {\n\t\t\t\tig.add(patterns);\n\t\t\t}\n\t\t} catch {}\n\t}\n}\n\nexport interface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t[key: string]: unknown;\n}\n\nexport interface Skill {\n\tname: string;\n\tdescription: string;\n\tfilePath: string;\n\tbaseDir: string;\n\tsourceInfo: SourceInfo;\n\tdisableModelInvocation: boolean;\n}\n\nexport interface LoadSkillsResult {\n\tskills: Skill[];\n\tdiagnostics: ResourceDiagnostic[];\n}\n\n/**\n * Validate skill name per Agent Skills spec.\n * Returns array of validation error messages (empty if valid).\n */\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\n\tif (name !== parentDirName) {\n\t\terrors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\t}\n\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\terrors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\t}\n\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(`name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)`);\n\t}\n\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) {\n\t\terrors.push(`name must not start or end with a hyphen`);\n\t}\n\n\tif (name.includes(\"--\")) {\n\t\terrors.push(`name must not contain consecutive hyphens`);\n\t}\n\n\treturn errors;\n}\n\n/**\n * Validate description per Agent Skills spec.\n */\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\n\treturn errors;\n}\n\nexport interface LoadSkillsFromDirOptions {\n\t/** Directory to scan for skills */\n\tdir: string;\n\t/** Source identifier for these skills */\n\tsource: string;\n}\n\nfunction createSkillSourceInfo(filePath: string, baseDir: string, source: string): SourceInfo {\n\tswitch (source) {\n\t\tcase \"user\":\n\t\t\treturn createSyntheticSourceInfo(filePath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"user\",\n\t\t\t\tbaseDir,\n\t\t\t});\n\t\tcase \"project\":\n\t\t\treturn createSyntheticSourceInfo(filePath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"project\",\n\t\t\t\tbaseDir,\n\t\t\t});\n\t\tcase \"path\":\n\t\t\treturn createSyntheticSourceInfo(filePath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tbaseDir,\n\t\t\t});\n\t\tdefault:\n\t\t\treturn createSyntheticSourceInfo(filePath, { source, baseDir });\n\t}\n}\n\n/**\n * Load skills from a directory.\n *\n * Discovery rules:\n * - if a directory contains SKILL.md, treat it as a skill root and do not recurse further\n * - otherwise, load direct .md children in the root\n * - recurse into subdirectories to find SKILL.md\n */\nexport function loadSkillsFromDir(options: LoadSkillsFromDirOptions): LoadSkillsResult {\n\tconst { dir, source } = options;\n\treturn loadSkillsFromDirInternal(dir, source, true);\n}\n\nfunction loadSkillsFromDirInternal(\n\tdir: string,\n\tsource: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher?: IgnoreMatcher,\n\trootDir?: string,\n): LoadSkillsResult {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\tif (!existsSync(dir)) {\n\t\treturn { skills, diagnostics };\n\t}\n\n\tconst root = rootDir ?? dir;\n\tconst ig = ignoreMatcher ?? ignore();\n\taddIgnoreRules(ig, dir, root);\n\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name !== \"SKILL.md\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst fullPath = join(dir, entry.name);\n\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tisFile = statSync(fullPath).isFile();\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst relPath = toPosixPath(relative(root, fullPath));\n\t\t\tif (!isFile || ig.ignores(relPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst result = loadSkillFromFile(fullPath, source);\n\t\t\tif (result.skill) {\n\t\t\t\tskills.push(result.skill);\n\t\t\t}\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t\treturn { skills, diagnostics };\n\t\t}\n\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name.startsWith(\".\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Skip node_modules to avoid scanning dependencies\n\t\t\tif (entry.name === \"node_modules\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst fullPath = join(dir, entry.name);\n\n\t\t\t// For symlinks, check if they point to a directory and follow them\n\t\t\tlet isDirectory = entry.isDirectory();\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisDirectory = stats.isDirectory();\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\t// Broken symlink, skip it\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst relPath = toPosixPath(relative(root, fullPath));\n\t\t\tconst ignorePath = isDirectory ? `${relPath}/` : relPath;\n\t\t\tif (ig.ignores(ignorePath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isDirectory) {\n\t\t\t\tconst subResult = loadSkillsFromDirInternal(fullPath, source, false, ig, root);\n\t\t\t\tskills.push(...subResult.skills);\n\t\t\t\tdiagnostics.push(...subResult.diagnostics);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!isFile || !includeRootFiles || !entry.name.endsWith(\".md\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst result = loadSkillFromFile(fullPath, source);\n\t\t\tif (result.skill) {\n\t\t\t\tskills.push(result.skill);\n\t\t\t}\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t} catch {}\n\n\treturn { skills, diagnostics };\n}\n\nfunction loadSkillFromFile(\n\tfilePath: string,\n\tsource: string,\n): { skill: Skill | null; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter } = parseFrontmatter<SkillFrontmatter>(rawContent);\n\t\tconst skillDir = dirname(filePath);\n\t\tconst parentDirName = basename(skillDir);\n\n\t\t// Validate description\n\t\tconst descErrors = validateDescription(frontmatter.description);\n\t\tfor (const error of descErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\t// Use name from frontmatter, or fall back to parent directory name\n\t\tconst name = frontmatter.name || parentDirName;\n\n\t\t// Validate name\n\t\tconst nameErrors = validateName(name, parentDirName);\n\t\tfor (const error of nameErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\t// Still load the skill even with warnings (unless description is completely missing)\n\t\tif (!frontmatter.description || frontmatter.description.trim() === \"\") {\n\t\t\treturn { skill: null, diagnostics };\n\t\t}\n\n\t\treturn {\n\t\t\tskill: {\n\t\t\t\tname,\n\t\t\t\tdescription: frontmatter.description,\n\t\t\t\tfilePath,\n\t\t\t\tbaseDir: skillDir,\n\t\t\t\tsourceInfo: createSkillSourceInfo(filePath, skillDir, source),\n\t\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t\t},\n\t\t\tdiagnostics,\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse skill file\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n}\n\n/**\n * Format skills for inclusion in a system prompt.\n * Uses XML format per Agent Skills standard.\n * See: https://agentskills.io/integrate-skills\n *\n * Skills with disableModelInvocation=true are excluded from the prompt\n * (they can only be invoked explicitly via /skill:name commands).\n */\nexport function formatSkillsForPrompt(skills: Skill[]): string {\n\tconst visibleSkills = skills.filter((s) => !s.disableModelInvocation);\n\n\tif (visibleSkills.length === 0) {\n\t\treturn \"\";\n\t}\n\n\tconst lines = [\n\t\t\"\\n\\nThe following skills provide specialized instructions for specific tasks.\",\n\t\t\"Use the read tool to load a skill's file when the task matches its description.\",\n\t\t\"When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.\",\n\t\t\"\",\n\t\t\"<available_skills>\",\n\t];\n\n\tfor (const skill of visibleSkills) {\n\t\tlines.push(\" <skill>\");\n\t\tlines.push(` <name>${escapeXml(skill.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(skill.description)}</description>`);\n\t\tlines.push(` <location>${escapeXml(skill.filePath)}</location>`);\n\t\tlines.push(\" </skill>\");\n\t}\n\n\tlines.push(\"</available_skills>\");\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction escapeXml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&amp;\")\n\t\t.replace(/</g, \"&lt;\")\n\t\t.replace(/>/g, \"&gt;\")\n\t\t.replace(/\"/g, \"&quot;\")\n\t\t.replace(/'/g, \"&apos;\");\n}\n\nexport interface LoadSkillsOptions {\n\t/** Working directory for project-local skills. Default: process.cwd() */\n\tcwd?: string;\n\t/** Agent config directory for global skills. Default: ~/.pi/agent */\n\tagentDir?: string;\n\t/** Explicit skill paths (files or directories) */\n\tskillPaths?: string[];\n\t/** Include default skills directories. Default: true */\n\tincludeDefaults?: boolean;\n}\n\nfunction normalizePath(input: string): string {\n\tconst trimmed = input.trim();\n\tif (trimmed === \"~\") return homedir();\n\tif (trimmed.startsWith(\"~/\")) return join(homedir(), trimmed.slice(2));\n\tif (trimmed.startsWith(\"~\")) return join(homedir(), trimmed.slice(1));\n\treturn trimmed;\n}\n\nfunction resolveSkillPath(p: string, cwd: string): string {\n\tconst normalized = normalizePath(p);\n\treturn isAbsolute(normalized) ? normalized : resolve(cwd, normalized);\n}\n\n/**\n * Load skills from all configured locations.\n * Returns skills and any validation diagnostics.\n */\nexport function loadSkills(options: LoadSkillsOptions = {}): LoadSkillsResult {\n\tconst { cwd = process.cwd(), agentDir, skillPaths = [], includeDefaults = true } = options;\n\n\t// Resolve agentDir - if not provided, use default from config\n\tconst resolvedAgentDir = agentDir ?? getAgentDir();\n\n\tconst skillMap = new Map<string, Skill>();\n\tconst realPathSet = new Set<string>();\n\tconst allDiagnostics: ResourceDiagnostic[] = [];\n\tconst collisionDiagnostics: ResourceDiagnostic[] = [];\n\n\tfunction addSkills(result: LoadSkillsResult) {\n\t\tallDiagnostics.push(...result.diagnostics);\n\t\tfor (const skill of result.skills) {\n\t\t\t// Resolve symlinks to detect duplicate files\n\t\t\tlet realPath: string;\n\t\t\ttry {\n\t\t\t\trealPath = realpathSync(skill.filePath);\n\t\t\t} catch {\n\t\t\t\trealPath = skill.filePath;\n\t\t\t}\n\n\t\t\t// Skip silently if we've already loaded this exact file (via symlink)\n\t\t\tif (realPathSet.has(realPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst existing = skillMap.get(skill.name);\n\t\t\tif (existing) {\n\t\t\t\tcollisionDiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"${skill.name}\" collision`,\n\t\t\t\t\tpath: skill.filePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"skill\",\n\t\t\t\t\t\tname: skill.name,\n\t\t\t\t\t\twinnerPath: existing.filePath,\n\t\t\t\t\t\tloserPath: skill.filePath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tskillMap.set(skill.name, skill);\n\t\t\t\trealPathSet.add(realPath);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (includeDefaults) {\n\t\taddSkills(loadSkillsFromDirInternal(join(resolvedAgentDir, \"skills\"), \"user\", true));\n\t\taddSkills(loadSkillsFromDirInternal(resolve(cwd, CONFIG_DIR_NAME, \"skills\"), \"project\", true));\n\t}\n\n\tconst userSkillsDir = join(resolvedAgentDir, \"skills\");\n\tconst projectSkillsDir = resolve(cwd, CONFIG_DIR_NAME, \"skills\");\n\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\n\tconst getSource = (resolvedPath: string): \"user\" | \"project\" | \"path\" => {\n\t\tif (!includeDefaults) {\n\t\t\tif (isUnderPath(resolvedPath, userSkillsDir)) return \"user\";\n\t\t\tif (isUnderPath(resolvedPath, projectSkillsDir)) return \"project\";\n\t\t}\n\t\treturn \"path\";\n\t};\n\n\tfor (const rawPath of skillPaths) {\n\t\tconst resolvedPath = resolveSkillPath(rawPath, cwd);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path does not exist\", path: resolvedPath });\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tconst source = getSource(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(resolvedPath, source, true));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst result = loadSkillFromFile(resolvedPath, source);\n\t\t\t\tif (result.skill) {\n\t\t\t\t\taddSkills({ skills: [result.skill], diagnostics: result.diagnostics });\n\t\t\t\t} else {\n\t\t\t\t\tallDiagnostics.push(...result.diagnostics);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path is not a markdown file\", path: resolvedPath });\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read skill path\";\n\t\t\tallDiagnostics.push({ type: \"warning\", message, path: resolvedPath });\n\t\t}\n\t}\n\n\treturn {\n\t\tskills: Array.from(skillMap.values()),\n\t\tdiagnostics: [...allDiagnostics, ...collisionDiagnostics],\n\t};\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { SourceInfo } from "./source-info.js";
2
+ export type SlashCommandSource = "extension" | "prompt" | "skill";
3
+ export interface SlashCommandInfo {
4
+ name: string;
5
+ description?: string;
6
+ source: SlashCommandSource;
7
+ sourceInfo: SourceInfo;
8
+ }
9
+ export interface BuiltinSlashCommand {
10
+ name: string;
11
+ description: string;
12
+ }
13
+ export declare const BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand>;
14
+ //# sourceMappingURL=slash-commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slash-commands.d.ts","sourceRoot":"","sources":["../../src/core/slash-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElE,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,sBAAsB,EAAE,aAAa,CAAC,mBAAmB,CAoBrE,CAAC","sourcesContent":["import type { SourceInfo } from \"./source-info.js\";\n\nexport type SlashCommandSource = \"extension\" | \"prompt\" | \"skill\";\n\nexport interface SlashCommandInfo {\n\tname: string;\n\tdescription?: string;\n\tsource: SlashCommandSource;\n\tsourceInfo: SourceInfo;\n}\n\nexport interface BuiltinSlashCommand {\n\tname: string;\n\tdescription: string;\n}\n\nexport const BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand> = [\n\t{ name: \"settings\", description: \"Open settings menu\" },\n\t{ name: \"model\", description: \"Select model (opens selector UI)\" },\n\t{ name: \"scoped-models\", description: \"Enable/disable models for Ctrl+P cycling\" },\n\t{ name: \"export\", description: \"Export session (HTML default, or specify path: .html/.jsonl)\" },\n\t{ name: \"import\", description: \"Import and resume a session from a JSONL file\" },\n\t{ name: \"copy\", description: \"Copy last agent message to clipboard\" },\n\t{ name: \"name\", description: \"Set session display name\" },\n\t{ name: \"session\", description: \"Show session info and stats\" },\n\t{ name: \"changelog\", description: \"Show changelog entries\" },\n\t{ name: \"hotkeys\", description: \"Show all keyboard shortcuts\" },\n\t{ name: \"fork\", description: \"Create a new fork from a previous message\" },\n\t{ name: \"tree\", description: \"Navigate session tree (switch branches)\" },\n\t{ name: \"login\", description: \"Login with OAuth provider\" },\n\t{ name: \"logout\", description: \"Logout from OAuth provider\" },\n\t{ name: \"new\", description: \"Start a new session\" },\n\t{ name: \"compact\", description: \"Manually compact the session context\" },\n\t{ name: \"resume\", description: \"Resume a different session\" },\n\t{ name: \"reload\", description: \"Reload keybindings, extensions, skills, prompts, and themes\" },\n\t{ name: \"quit\", description: \"Quit pi\" },\n];\n"]}
@@ -0,0 +1,22 @@
1
+ export const BUILTIN_SLASH_COMMANDS = [
2
+ { name: "settings", description: "Open settings menu" },
3
+ { name: "model", description: "Select model (opens selector UI)" },
4
+ { name: "scoped-models", description: "Enable/disable models for Ctrl+P cycling" },
5
+ { name: "export", description: "Export session (HTML default, or specify path: .html/.jsonl)" },
6
+ { name: "import", description: "Import and resume a session from a JSONL file" },
7
+ { name: "copy", description: "Copy last agent message to clipboard" },
8
+ { name: "name", description: "Set session display name" },
9
+ { name: "session", description: "Show session info and stats" },
10
+ { name: "changelog", description: "Show changelog entries" },
11
+ { name: "hotkeys", description: "Show all keyboard shortcuts" },
12
+ { name: "fork", description: "Create a new fork from a previous message" },
13
+ { name: "tree", description: "Navigate session tree (switch branches)" },
14
+ { name: "login", description: "Login with OAuth provider" },
15
+ { name: "logout", description: "Logout from OAuth provider" },
16
+ { name: "new", description: "Start a new session" },
17
+ { name: "compact", description: "Manually compact the session context" },
18
+ { name: "resume", description: "Resume a different session" },
19
+ { name: "reload", description: "Reload keybindings, extensions, skills, prompts, and themes" },
20
+ { name: "quit", description: "Quit pi" },
21
+ ];
22
+ //# sourceMappingURL=slash-commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slash-commands.js","sourceRoot":"","sources":["../../src/core/slash-commands.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,sBAAsB,GAAuC;IACzE,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE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";\n\nexport interface SlashCommandInfo {\n\tname: string;\n\tdescription?: string;\n\tsource: SlashCommandSource;\n\tsourceInfo: SourceInfo;\n}\n\nexport interface BuiltinSlashCommand {\n\tname: string;\n\tdescription: string;\n}\n\nexport const BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand> = [\n\t{ name: \"settings\", description: \"Open settings menu\" },\n\t{ name: \"model\", description: \"Select model (opens selector UI)\" },\n\t{ name: \"scoped-models\", description: \"Enable/disable models for Ctrl+P cycling\" },\n\t{ name: \"export\", description: \"Export session (HTML default, or specify path: .html/.jsonl)\" },\n\t{ name: \"import\", description: \"Import and resume a session from a JSONL file\" },\n\t{ name: \"copy\", description: \"Copy last agent message to clipboard\" },\n\t{ name: \"name\", description: \"Set session display name\" },\n\t{ name: \"session\", description: \"Show session info and stats\" },\n\t{ name: \"changelog\", description: \"Show changelog entries\" },\n\t{ name: \"hotkeys\", description: \"Show all keyboard shortcuts\" },\n\t{ name: \"fork\", description: \"Create a new fork from a previous message\" },\n\t{ name: \"tree\", description: \"Navigate session tree (switch branches)\" },\n\t{ name: \"login\", description: \"Login with OAuth provider\" },\n\t{ name: \"logout\", description: \"Logout from OAuth provider\" },\n\t{ name: \"new\", description: \"Start a new session\" },\n\t{ name: \"compact\", description: \"Manually compact the session context\" },\n\t{ name: \"resume\", description: \"Resume a different session\" },\n\t{ name: \"reload\", description: \"Reload keybindings, extensions, skills, prompts, and themes\" },\n\t{ name: \"quit\", description: \"Quit pi\" },\n];\n"]}
@@ -0,0 +1,18 @@
1
+ import type { PathMetadata } from "./package-manager.js";
2
+ export type SourceScope = "user" | "project" | "temporary";
3
+ export type SourceOrigin = "package" | "top-level";
4
+ export interface SourceInfo {
5
+ path: string;
6
+ source: string;
7
+ scope: SourceScope;
8
+ origin: SourceOrigin;
9
+ baseDir?: string;
10
+ }
11
+ export declare function createSourceInfo(path: string, metadata: PathMetadata): SourceInfo;
12
+ export declare function createSyntheticSourceInfo(path: string, options: {
13
+ source: string;
14
+ scope?: SourceScope;
15
+ origin?: SourceOrigin;
16
+ baseDir?: string;
17
+ }): SourceInfo;
18
+ //# sourceMappingURL=source-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-info.d.ts","sourceRoot":"","sources":["../../src/core/source-info.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,WAAW,CAAC;AAEnD,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,UAAU,CAQjF;AAED,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;IACR,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,GACC,UAAU,CAQZ","sourcesContent":["import type { PathMetadata } from \"./package-manager.js\";\n\nexport type SourceScope = \"user\" | \"project\" | \"temporary\";\nexport type SourceOrigin = \"package\" | \"top-level\";\n\nexport interface SourceInfo {\n\tpath: string;\n\tsource: string;\n\tscope: SourceScope;\n\torigin: SourceOrigin;\n\tbaseDir?: string;\n}\n\nexport function createSourceInfo(path: string, metadata: PathMetadata): SourceInfo {\n\treturn {\n\t\tpath,\n\t\tsource: metadata.source,\n\t\tscope: metadata.scope,\n\t\torigin: metadata.origin,\n\t\tbaseDir: metadata.baseDir,\n\t};\n}\n\nexport function createSyntheticSourceInfo(\n\tpath: string,\n\toptions: {\n\t\tsource: string;\n\t\tscope?: SourceScope;\n\t\torigin?: SourceOrigin;\n\t\tbaseDir?: string;\n\t},\n): SourceInfo {\n\treturn {\n\t\tpath,\n\t\tsource: options.source,\n\t\tscope: options.scope ?? \"temporary\",\n\t\torigin: options.origin ?? \"top-level\",\n\t\tbaseDir: options.baseDir,\n\t};\n}\n"]}
@@ -0,0 +1,19 @@
1
+ export function createSourceInfo(path, metadata) {
2
+ return {
3
+ path,
4
+ source: metadata.source,
5
+ scope: metadata.scope,
6
+ origin: metadata.origin,
7
+ baseDir: metadata.baseDir,
8
+ };
9
+ }
10
+ export function createSyntheticSourceInfo(path, options) {
11
+ return {
12
+ path,
13
+ source: options.source,
14
+ scope: options.scope ?? "temporary",
15
+ origin: options.origin ?? "top-level",
16
+ baseDir: options.baseDir,
17
+ };
18
+ }
19
+ //# sourceMappingURL=source-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-info.js","sourceRoot":"","sources":["../../src/core/source-info.ts"],"names":[],"mappings":"AAaA,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,QAAsB,EAAc;IAClF,OAAO;QACN,IAAI;QACJ,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;KACzB,CAAC;AAAA,CACF;AAED,MAAM,UAAU,yBAAyB,CACxC,IAAY,EACZ,OAKC,EACY;IACb,OAAO;QACN,IAAI;QACJ,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,WAAW;QACnC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,WAAW;QACrC,OAAO,EAAE,OAAO,CAAC,OAAO;KACxB,CAAC;AAAA,CACF","sourcesContent":["import type { PathMetadata } from \"./package-manager.js\";\n\nexport type SourceScope = \"user\" | \"project\" | \"temporary\";\nexport type SourceOrigin = \"package\" | \"top-level\";\n\nexport interface SourceInfo {\n\tpath: string;\n\tsource: string;\n\tscope: SourceScope;\n\torigin: SourceOrigin;\n\tbaseDir?: string;\n}\n\nexport function createSourceInfo(path: string, metadata: PathMetadata): SourceInfo {\n\treturn {\n\t\tpath,\n\t\tsource: metadata.source,\n\t\tscope: metadata.scope,\n\t\torigin: metadata.origin,\n\t\tbaseDir: metadata.baseDir,\n\t};\n}\n\nexport function createSyntheticSourceInfo(\n\tpath: string,\n\toptions: {\n\t\tsource: string;\n\t\tscope?: SourceScope;\n\t\torigin?: SourceOrigin;\n\t\tbaseDir?: string;\n\t},\n): SourceInfo {\n\treturn {\n\t\tpath,\n\t\tsource: options.source,\n\t\tscope: options.scope ?? \"temporary\",\n\t\torigin: options.origin ?? \"top-level\",\n\t\tbaseDir: options.baseDir,\n\t};\n}\n"]}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * System prompt construction and project context loading
3
+ */
4
+ import { type Skill } from "./skills.js";
5
+ export interface BuildSystemPromptOptions {
6
+ /** Custom system prompt (replaces default). */
7
+ customPrompt?: string;
8
+ /** Tools to include in prompt. Default: [read, bash, edit, write] */
9
+ selectedTools?: string[];
10
+ /** Optional one-line tool snippets keyed by tool name. */
11
+ toolSnippets?: Record<string, string>;
12
+ /** Additional guideline bullets appended to the default system prompt guidelines. */
13
+ promptGuidelines?: string[];
14
+ /** Text to append to system prompt. */
15
+ appendSystemPrompt?: string;
16
+ /** Working directory. Default: process.cwd() */
17
+ cwd?: string;
18
+ /** Pre-loaded context files. */
19
+ contextFiles?: Array<{
20
+ path: string;
21
+ content: string;
22
+ }>;
23
+ /** Pre-loaded skills. */
24
+ skills?: Skill[];
25
+ }
26
+ /** Build the system prompt with tools, guidelines, and context */
27
+ export declare function buildSystemPrompt(options?: BuildSystemPromptOptions): string;
28
+ //# sourceMappingURL=system-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,wBAAwB;IACxC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CA4IhF","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst resolvedCwd = cwd ?? process.cwd();\n\tconst promptCwd = resolvedCwd.replace(/\\\\/g, \"/\");\n\n\tconst date = new Date().toISOString().slice(0, 10);\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (only if read tool is available)\n\t\tconst customPromptHasRead = !selectedTools || selectedTools.includes(\"read\");\n\t\tif (customPromptHasRead && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date and working directory last\n\t\tprompt += `\\nCurrent date: ${date}`;\n\t\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// A tool appears in Available tools only when the caller provides a one-line snippet.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst visibleTools = tools.filter((name) => !!toolSnippets?.[name]);\n\tconst toolsList =\n\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets![name]}`).join(\"\\n\") : \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRead = tools.includes(\"read\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs)) {\n\t\taddGuideline(\"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\");\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)\n- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (only if read tool is available)\n\tif (hasRead && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date and working directory last\n\tprompt += `\\nCurrent date: ${date}`;\n\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\treturn prompt;\n}\n"]}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * System prompt construction and project context loading
3
+ */
4
+ import { getDocsPath, getExamplesPath, getReadmePath } from "../config.js";
5
+ import { formatSkillsForPrompt } from "./skills.js";
6
+ /** Build the system prompt with tools, guidelines, and context */
7
+ export function buildSystemPrompt(options = {}) {
8
+ const { customPrompt, selectedTools, toolSnippets, promptGuidelines, appendSystemPrompt, cwd, contextFiles: providedContextFiles, skills: providedSkills, } = options;
9
+ const resolvedCwd = cwd ?? process.cwd();
10
+ const promptCwd = resolvedCwd.replace(/\\/g, "/");
11
+ const date = new Date().toISOString().slice(0, 10);
12
+ const appendSection = appendSystemPrompt ? `\n\n${appendSystemPrompt}` : "";
13
+ const contextFiles = providedContextFiles ?? [];
14
+ const skills = providedSkills ?? [];
15
+ if (customPrompt) {
16
+ let prompt = customPrompt;
17
+ if (appendSection) {
18
+ prompt += appendSection;
19
+ }
20
+ // Append project context files
21
+ if (contextFiles.length > 0) {
22
+ prompt += "\n\n# Project Context\n\n";
23
+ prompt += "Project-specific instructions and guidelines:\n\n";
24
+ for (const { path: filePath, content } of contextFiles) {
25
+ prompt += `## ${filePath}\n\n${content}\n\n`;
26
+ }
27
+ }
28
+ // Append skills section (only if read tool is available)
29
+ const customPromptHasRead = !selectedTools || selectedTools.includes("read");
30
+ if (customPromptHasRead && skills.length > 0) {
31
+ prompt += formatSkillsForPrompt(skills);
32
+ }
33
+ // Add date and working directory last
34
+ prompt += `\nCurrent date: ${date}`;
35
+ prompt += `\nCurrent working directory: ${promptCwd}`;
36
+ return prompt;
37
+ }
38
+ // Get absolute paths to documentation and examples
39
+ const readmePath = getReadmePath();
40
+ const docsPath = getDocsPath();
41
+ const examplesPath = getExamplesPath();
42
+ // Build tools list based on selected tools.
43
+ // A tool appears in Available tools only when the caller provides a one-line snippet.
44
+ const tools = selectedTools || ["read", "bash", "edit", "write"];
45
+ const visibleTools = tools.filter((name) => !!toolSnippets?.[name]);
46
+ const toolsList = visibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets[name]}`).join("\n") : "(none)";
47
+ // Build guidelines based on which tools are actually available
48
+ const guidelinesList = [];
49
+ const guidelinesSet = new Set();
50
+ const addGuideline = (guideline) => {
51
+ if (guidelinesSet.has(guideline)) {
52
+ return;
53
+ }
54
+ guidelinesSet.add(guideline);
55
+ guidelinesList.push(guideline);
56
+ };
57
+ const hasBash = tools.includes("bash");
58
+ const hasGrep = tools.includes("grep");
59
+ const hasFind = tools.includes("find");
60
+ const hasLs = tools.includes("ls");
61
+ const hasRead = tools.includes("read");
62
+ // File exploration guidelines
63
+ if (hasBash && !hasGrep && !hasFind && !hasLs) {
64
+ addGuideline("Use bash for file operations like ls, rg, find");
65
+ }
66
+ else if (hasBash && (hasGrep || hasFind || hasLs)) {
67
+ addGuideline("Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)");
68
+ }
69
+ for (const guideline of promptGuidelines ?? []) {
70
+ const normalized = guideline.trim();
71
+ if (normalized.length > 0) {
72
+ addGuideline(normalized);
73
+ }
74
+ }
75
+ // Always include these
76
+ addGuideline("Be concise in your responses");
77
+ addGuideline("Show file paths clearly when working with files");
78
+ const guidelines = guidelinesList.map((g) => `- ${g}`).join("\n");
79
+ let prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.
80
+
81
+ Available tools:
82
+ ${toolsList}
83
+
84
+ In addition to the tools above, you may have access to other custom tools depending on the project.
85
+
86
+ Guidelines:
87
+ ${guidelines}
88
+
89
+ Pi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):
90
+ - Main documentation: ${readmePath}
91
+ - Additional docs: ${docsPath}
92
+ - Examples: ${examplesPath} (extensions, custom tools, SDK)
93
+ - When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)
94
+ - When working on pi topics, read the docs and examples, and follow .md cross-references before implementing
95
+ - Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;
96
+ if (appendSection) {
97
+ prompt += appendSection;
98
+ }
99
+ // Append project context files
100
+ if (contextFiles.length > 0) {
101
+ prompt += "\n\n# Project Context\n\n";
102
+ prompt += "Project-specific instructions and guidelines:\n\n";
103
+ for (const { path: filePath, content } of contextFiles) {
104
+ prompt += `## ${filePath}\n\n${content}\n\n`;
105
+ }
106
+ }
107
+ // Append skills section (only if read tool is available)
108
+ if (hasRead && skills.length > 0) {
109
+ prompt += formatSkillsForPrompt(skills);
110
+ }
111
+ // Add date and working directory last
112
+ prompt += `\nCurrent date: ${date}`;
113
+ prompt += `\nCurrent working directory: ${promptCwd}`;
114
+ return prompt;
115
+ }
116
+ //# sourceMappingURL=system-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAqBhE,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,OAAO,GAA6B,EAAE,EAAU;IACjF,MAAM,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,GAAG,EACH,YAAY,EAAE,oBAAoB,EAClC,MAAM,EAAE,cAAc,GACtB,GAAG,OAAO,CAAC;IACZ,MAAM,WAAW,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAElD,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEnD,MAAM,aAAa,GAAG,kBAAkB,CAAC,CAAC,CAAC,OAAO,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE5E,MAAM,YAAY,GAAG,oBAAoB,IAAI,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,cAAc,IAAI,EAAE,CAAC;IAEpC,IAAI,YAAY,EAAE,CAAC;QAClB,IAAI,MAAM,GAAG,YAAY,CAAC;QAE1B,IAAI,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,aAAa,CAAC;QACzB,CAAC;QAED,+BAA+B;QAC/B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,2BAA2B,C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,CAAC,CAAC;IAC7C,YAAY,CAAC,iDAAiD,CAAC,CAAC;IAEhE,MAAM,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAElE,IAAI,MAAM,GAAG;;;EAGZ,SAAS;;;;;EAKT,UAAU;;;wBAGY,UAAU;qBACb,QAAQ;cACf,YAAY;;;0GAGgF,CAAC;IAE1G,IAAI,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,aAAa,CAAC;IACzB,CAAC;IAED,+BAA+B;IAC/B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,2BAA2B,CAAC;QACtC,MAAM,IAAI,mDAAmD,CAAC;QAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACxD,MAAM,IAAI,MAAM,QAAQ,OAAO,OAAO,MAAM,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,sCAAsC;IACtC,MAAM,IAAI,mBAAmB,IAAI,EAAE,CAAC;IACpC,MAAM,IAAI,gCAAgC,SAAS,EAAE,CAAC;IAEtD,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst resolvedCwd = cwd ?? process.cwd();\n\tconst promptCwd = resolvedCwd.replace(/\\\\/g, \"/\");\n\n\tconst date = new Date().toISOString().slice(0, 10);\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (only if read tool is available)\n\t\tconst customPromptHasRead = !selectedTools || selectedTools.includes(\"read\");\n\t\tif (customPromptHasRead && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Add date and working directory last\n\t\tprompt += `\\nCurrent date: ${date}`;\n\t\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// A tool appears in Available tools only when the caller provides a one-line snippet.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst visibleTools = tools.filter((name) => !!toolSnippets?.[name]);\n\tconst toolsList =\n\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets![name]}`).join(\"\\n\") : \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = tools.includes(\"bash\");\n\tconst hasGrep = tools.includes(\"grep\");\n\tconst hasFind = tools.includes(\"find\");\n\tconst hasLs = tools.includes(\"ls\");\n\tconst hasRead = tools.includes(\"read\");\n\n\t// File exploration guidelines\n\tif (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Use bash for file operations like ls, rg, find\");\n\t} else if (hasBash && (hasGrep || hasFind || hasLs)) {\n\t\taddGuideline(\"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\");\n\t}\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\t// Always include these\n\taddGuideline(\"Be concise in your responses\");\n\taddGuideline(\"Show file paths clearly when working with files\");\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), pi packages (docs/packages.md)\n- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (only if read tool is available)\n\tif (hasRead && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date and working directory last\n\tprompt += `\\nCurrent date: ${date}`;\n\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\treturn prompt;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Central timing instrumentation for startup profiling.
3
+ * Enable with PI_TIMING=1 environment variable.
4
+ */
5
+ export declare function resetTimings(): void;
6
+ export declare function time(label: string): void;
7
+ export declare function printTimings(): void;
8
+ //# sourceMappingURL=timings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timings.d.ts","sourceRoot":"","sources":["../../src/core/timings.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,wBAAgB,YAAY,IAAI,IAAI,CAInC;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAKxC;AAED,wBAAgB,YAAY,IAAI,IAAI,CAQnC","sourcesContent":["/**\n * Central timing instrumentation for startup profiling.\n * Enable with PI_TIMING=1 environment variable.\n */\n\nconst ENABLED = process.env.PI_TIMING === \"1\";\nconst timings: Array<{ label: string; ms: number }> = [];\nlet lastTime = Date.now();\n\nexport function resetTimings(): void {\n\tif (!ENABLED) return;\n\ttimings.length = 0;\n\tlastTime = Date.now();\n}\n\nexport function time(label: string): void {\n\tif (!ENABLED) return;\n\tconst now = Date.now();\n\ttimings.push({ label, ms: now - lastTime });\n\tlastTime = now;\n}\n\nexport function printTimings(): void {\n\tif (!ENABLED || timings.length === 0) return;\n\tconsole.error(\"\\n--- Startup Timings ---\");\n\tfor (const t of timings) {\n\t\tconsole.error(` ${t.label}: ${t.ms}ms`);\n\t}\n\tconsole.error(` TOTAL: ${timings.reduce((a, b) => a + b.ms, 0)}ms`);\n\tconsole.error(\"------------------------\\n\");\n}\n"]}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Central timing instrumentation for startup profiling.
3
+ * Enable with PI_TIMING=1 environment variable.
4
+ */
5
+ const ENABLED = process.env.PI_TIMING === "1";
6
+ const timings = [];
7
+ let lastTime = Date.now();
8
+ export function resetTimings() {
9
+ if (!ENABLED)
10
+ return;
11
+ timings.length = 0;
12
+ lastTime = Date.now();
13
+ }
14
+ export function time(label) {
15
+ if (!ENABLED)
16
+ return;
17
+ const now = Date.now();
18
+ timings.push({ label, ms: now - lastTime });
19
+ lastTime = now;
20
+ }
21
+ export function printTimings() {
22
+ if (!ENABLED || timings.length === 0)
23
+ return;
24
+ console.error("\n--- Startup Timings ---");
25
+ for (const t of timings) {
26
+ console.error(` ${t.label}: ${t.ms}ms`);
27
+ }
28
+ console.error(` TOTAL: ${timings.reduce((a, b) => a + b.ms, 0)}ms`);
29
+ console.error("------------------------\n");
30
+ }
31
+ //# sourceMappingURL=timings.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AAC,CAAC;AAAA,CAC5C","sourcesContent":["/**\n * Central timing instrumentation for startup profiling.\n * Enable with PI_TIMING=1 environment variable.\n */\n\nconst ENABLED = process.env.PI_TIMING === \"1\";\nconst timings: Array<{ label: string; ms: number }> = [];\nlet lastTime = Date.now();\n\nexport function resetTimings(): void {\n\tif (!ENABLED) return;\n\ttimings.length = 0;\n\tlastTime = Date.now();\n}\n\nexport function time(label: string): void {\n\tif (!ENABLED) return;\n\tconst now = Date.now();\n\ttimings.push({ label, ms: now - lastTime });\n\tlastTime = now;\n}\n\nexport function printTimings(): void {\n\tif (!ENABLED || timings.length === 0) return;\n\tconsole.error(\"\\n--- Startup Timings ---\");\n\tfor (const t of timings) {\n\t\tconsole.error(` ${t.label}: ${t.ms}ms`);\n\t}\n\tconsole.error(` TOTAL: ${timings.reduce((a, b) => a + b.ms, 0)}ms`);\n\tconsole.error(\"------------------------\\n\");\n}\n"]}
@@ -0,0 +1,73 @@
1
+ import type { AgentTool } from "@lenylvt/pi-agent-core";
2
+ import { type Static } from "@sinclair/typebox";
3
+ import type { ToolDefinition } from "../extensions/types.js";
4
+ import { type TruncationResult } from "./truncate.js";
5
+ declare const bashSchema: import("@sinclair/typebox").TObject<{
6
+ command: import("@sinclair/typebox").TString;
7
+ timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
8
+ }>;
9
+ export type BashToolInput = Static<typeof bashSchema>;
10
+ export interface BashToolDetails {
11
+ truncation?: TruncationResult;
12
+ fullOutputPath?: string;
13
+ }
14
+ /**
15
+ * Pluggable operations for the bash tool.
16
+ * Override these to delegate command execution to remote systems (for example SSH).
17
+ */
18
+ export interface BashOperations {
19
+ /**
20
+ * Execute a command and stream output.
21
+ * @param command The command to execute
22
+ * @param cwd Working directory
23
+ * @param options Execution options
24
+ * @returns Promise resolving to exit code (null if killed)
25
+ */
26
+ exec: (command: string, cwd: string, options: {
27
+ onData: (data: Buffer) => void;
28
+ signal?: AbortSignal;
29
+ timeout?: number;
30
+ env?: NodeJS.ProcessEnv;
31
+ }) => Promise<{
32
+ exitCode: number | null;
33
+ }>;
34
+ }
35
+ /**
36
+ * Create bash operations using pi's built-in local shell execution backend.
37
+ *
38
+ * This is useful for extensions that intercept user_bash and still want pi's
39
+ * standard local shell behavior while wrapping or rewriting commands.
40
+ */
41
+ export declare function createLocalBashOperations(): BashOperations;
42
+ export interface BashSpawnContext {
43
+ command: string;
44
+ cwd: string;
45
+ env: NodeJS.ProcessEnv;
46
+ }
47
+ export type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;
48
+ export interface BashToolOptions {
49
+ /** Custom operations for command execution. Default: local shell */
50
+ operations?: BashOperations;
51
+ /** Command prefix prepended to every command (for example shell setup commands) */
52
+ commandPrefix?: string;
53
+ /** Hook to adjust command, cwd, or env before execution */
54
+ spawnHook?: BashSpawnHook;
55
+ }
56
+ type BashRenderState = {
57
+ startedAt: number | undefined;
58
+ endedAt: number | undefined;
59
+ interval: NodeJS.Timeout | undefined;
60
+ };
61
+ export declare function createBashToolDefinition(cwd: string, options?: BashToolOptions): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState>;
62
+ export declare function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema>;
63
+ /** Default bash tool using process.cwd() for backwards compatibility. */
64
+ export declare const bashToolDefinition: ToolDefinition<import("@sinclair/typebox").TObject<{
65
+ command: import("@sinclair/typebox").TString;
66
+ timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
67
+ }>, BashToolDetails | undefined, BashRenderState>;
68
+ export declare const bashTool: AgentTool<import("@sinclair/typebox").TObject<{
69
+ command: import("@sinclair/typebox").TString;
70
+ timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
71
+ }>, any>;
72
+ export {};
73
+ //# sourceMappingURL=bash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"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CAAC,EAAE,MAAM,CAAC;IACvB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,aAAa,CAAC;CAC1B;AAID,KAAK,eAAe,GAAG;IACtB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;CACrC,CAAC;AAwGF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CA8JjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG;AAED,yEAAyE;AACzE,eAAO,MAAM,kBAAkB;;;iDAA0C,CAAC;AAC1E,eAAO,MAAM,QAAQ;;;QAAgC,CAAC","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { createWriteStream, existsSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type { AgentTool } from \"@lenylvt/pi-agent-core\";\nimport { Container, Text, truncateToWidth } from \"@lenylvt/pi-tui\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport { spawn } from \"child_process\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { truncateToVisualLines } from \"../../modes/interactive/components/visual-truncate.js\";\nimport { theme } from \"../../modes/interactive/theme/theme.js\";\nimport { waitForChildProcess } from \"../../utils/child-process.js\";\nimport { getShellConfig, getShellEnv, killProcessTree } from \"../../utils/shell.js\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.js\";\nimport { getTextOutput, invalidArgText, str } from \"./render-utils.js\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateTail } from \"./truncate.js\";\n\n/**\n * Generate a unique temp file path for bash output.\n */\nfunction getTempFilePath(): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(tmpdir(), `pi-bash-${id}.log`);\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (for example SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command The command to execute\n\t * @param cwd Working directory\n\t * @param options Execution options\n\t * @returns Promise resolving to exit code (null if killed)\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\n/**\n * Create bash operations using pi's built-in local shell execution backend.\n *\n * This is useful for extensions that intercept user_bash and still want pi's\n * standard local shell behavior while wrapping or rewriting commands.\n */\nexport function createLocalBashOperations(): BashOperations {\n\treturn {\n\t\texec: (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tconst { shell, args } = getShellConfig();\n\t\t\t\tif (!existsSync(cwd)) {\n\t\t\t\t\treject(new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst child = spawn(shell, [...args, command], {\n\t\t\t\t\tcwd,\n\t\t\t\t\tdetached: true,\n\t\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\t});\n\t\t\t\tlet timedOut = false;\n\t\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\t\t// Set timeout if provided.\n\t\t\t\tif (timeout !== undefined && timeout > 0) {\n\t\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t\t}, timeout * 1000);\n\t\t\t\t}\n\t\t\t\t// Stream stdout and stderr.\n\t\t\t\tchild.stdout?.on(\"data\", onData);\n\t\t\t\tchild.stderr?.on(\"data\", onData);\n\t\t\t\t// Handle abort signal by killing the entire process tree.\n\t\t\t\tconst onAbort = () => {\n\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t};\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\t// Handle shell spawn errors and wait for the process to terminate without hanging\n\t\t\t\t// on inherited stdio handles held by detached descendants.\n\t\t\t\twaitForChildProcess(child)\n\t\t\t\t\t.then((code) => {\n\t\t\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (timedOut) {\n\t\t\t\t\t\t\treject(new Error(`timeout:${timeout}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresolve({ exitCode: code });\n\t\t\t\t\t})\n\t\t\t\t\t.catch((err) => {\n\t\t\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t});\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nfunction resolveSpawnContext(command: string, cwd: string, spawnHook?: BashSpawnHook): BashSpawnContext {\n\tconst baseContext: BashSpawnContext = { command, cwd, env: { ...getShellEnv() } };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nconst BASH_PREVIEW_LINES = 5;\n\ntype BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\n\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n\tcachedSkipped: number | undefined;\n};\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t\tcachedSkipped: undefined,\n\t};\n}\n\nfunction formatDuration(ms: number): string {\n\treturn `${(ms / 1000).toFixed(1)}s`;\n}\n\nfunction formatBashCall(args: { command?: string; timeout?: number } | undefined): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tconst commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\treturn theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix;\n}\n\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\n\tconst output = getTextOutput(result as any, showImages).trim();\n\n\tif (output) {\n\t\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\n\t\tif (options.expanded) {\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tstate.cachedLines = preview.visualLines;\n\t\t\t\t\t\tstate.cachedSkipped = preview.skippedCount;\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\tif (state.cachedSkipped && state.cachedSkipped > 0) {\n\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${state.cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...(state.cachedLines ?? [])];\n\t\t\t\t\t}\n\t\t\t\t\treturn [\"\", ...(state.cachedLines ?? [])];\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t\tstate.cachedSkipped = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tif (truncation?.truncated || fullOutputPath) {\n\t\tconst warnings: string[] = [];\n\t\tif (fullOutputPath) {\n\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t}\n\t\tif (truncation?.truncated) {\n\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t} else {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t}\n\n\tif (startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options?.operations ?? createLocalBashOperations();\n\tconst commandPrefix = options?.commandPrefix;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tpromptSnippet: \"Execute bash commands (ls, grep, find, etc.)\",\n\t\tparameters: bashSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\tconst spawnContext = resolveSpawnContext(resolvedCommand, cwd, spawnHook);\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tlet tempFilePath: string | undefined;\n\t\t\t\tlet tempFileStream: ReturnType<typeof createWriteStream> | undefined;\n\t\t\t\tlet totalBytes = 0;\n\t\t\t\tconst chunks: Buffer[] = [];\n\t\t\t\tlet chunksBytes = 0;\n\t\t\t\tconst maxChunksBytes = DEFAULT_MAX_BYTES * 2;\n\n\t\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\t\ttotalBytes += data.length;\n\t\t\t\t\t// Start writing to a temp file once output exceeds the in-memory threshold.\n\t\t\t\t\tif (totalBytes > DEFAULT_MAX_BYTES && !tempFilePath) {\n\t\t\t\t\t\ttempFilePath = getTempFilePath();\n\t\t\t\t\t\ttempFileStream = createWriteStream(tempFilePath);\n\t\t\t\t\t\t// Write all buffered chunks to the file.\n\t\t\t\t\t\tfor (const chunk of chunks) tempFileStream.write(chunk);\n\t\t\t\t\t}\n\t\t\t\t\t// Write to temp file if we have one.\n\t\t\t\t\tif (tempFileStream) tempFileStream.write(data);\n\t\t\t\t\t// Keep a rolling buffer of recent output for tail truncation.\n\t\t\t\t\tchunks.push(data);\n\t\t\t\t\tchunksBytes += data.length;\n\t\t\t\t\t// Trim old chunks if the rolling buffer grows too large.\n\t\t\t\t\twhile (chunksBytes > maxChunksBytes && chunks.length > 1) {\n\t\t\t\t\t\tconst removed = chunks.shift()!;\n\t\t\t\t\t\tchunksBytes -= removed.length;\n\t\t\t\t\t}\n\t\t\t\t\t// Stream partial output using the rolling tail buffer.\n\t\t\t\t\tif (onUpdate) {\n\t\t\t\t\t\tconst fullBuffer = Buffer.concat(chunks);\n\t\t\t\t\t\tconst fullText = fullBuffer.toString(\"utf-8\");\n\t\t\t\t\t\tconst truncation = truncateTail(fullText);\n\t\t\t\t\t\tonUpdate({\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: truncation.content || \"\" }],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\ttruncation: truncation.truncated ? truncation : undefined,\n\t\t\t\t\t\t\t\tfullOutputPath: tempFilePath,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\tonData: handleData,\n\t\t\t\t\tsignal,\n\t\t\t\t\ttimeout,\n\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t})\n\t\t\t\t\t.then(({ exitCode }) => {\n\t\t\t\t\t\t// Close temp file stream before building the final result.\n\t\t\t\t\t\tif (tempFileStream) tempFileStream.end();\n\t\t\t\t\t\t// Combine the rolling buffer chunks.\n\t\t\t\t\t\tconst fullBuffer = Buffer.concat(chunks);\n\t\t\t\t\t\tconst fullOutput = fullBuffer.toString(\"utf-8\");\n\t\t\t\t\t\t// Apply tail truncation for the final display payload.\n\t\t\t\t\t\tconst truncation = truncateTail(fullOutput);\n\t\t\t\t\t\tlet outputText = truncation.content || \"(no output)\";\n\t\t\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\t\t\t// Build truncation details and an actionable notice.\n\t\t\t\t\t\t\tdetails = { truncation, fullOutputPath: tempFilePath };\n\t\t\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\t\t\t// Edge case: the last line alone is larger than the byte limit.\n\t\t\t\t\t\t\t\tconst lastLineSize = formatSize(Buffer.byteLength(fullOutput.split(\"\\n\").pop() || \"\", \"utf-8\"));\n\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${tempFilePath}]`;\n\t\t\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${tempFilePath}]`;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${tempFilePath}]`;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (exitCode !== 0 && exitCode !== null) {\n\t\t\t\t\t\t\toutputText += `\\n\\nCommand exited with code ${exitCode}`;\n\t\t\t\t\t\t\treject(new Error(outputText));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: outputText }], details });\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\t.catch((err: Error) => {\n\t\t\t\t\t\t// Close temp file stream and include buffered output in the error message.\n\t\t\t\t\t\tif (tempFileStream) tempFileStream.end();\n\t\t\t\t\t\tconst fullBuffer = Buffer.concat(chunks);\n\t\t\t\t\t\tlet output = fullBuffer.toString(\"utf-8\");\n\t\t\t\t\t\tif (err.message === \"aborted\") {\n\t\t\t\t\t\t\tif (output) output += \"\\n\\n\";\n\t\t\t\t\t\t\toutput += \"Command aborted\";\n\t\t\t\t\t\t\treject(new Error(output));\n\t\t\t\t\t\t} else if (err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\t\tif (output) output += \"\\n\\n\";\n\t\t\t\t\t\t\toutput += `Command timed out after ${timeoutSecs} seconds`;\n\t\t\t\t\t\t\treject(new Error(output));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t});\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatBashCall(args));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult as any,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\treturn wrapToolDefinition(createBashToolDefinition(cwd, options));\n}\n\n/** Default bash tool using process.cwd() for backwards compatibility. */\nexport const bashToolDefinition = createBashToolDefinition(process.cwd());\nexport const bashTool = createBashTool(process.cwd());\n"]}