lsd-pi 1.3.2 → 1.3.7

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 (205) hide show
  1. package/dist/cli.js +2 -1
  2. package/dist/lsd-settings-manager.d.ts +2 -0
  3. package/dist/lsd-settings-manager.js +5 -0
  4. package/dist/resource-loader.js +33 -3
  5. package/dist/resources/extensions/browser-tools/tools/codegen.js +5 -5
  6. package/dist/resources/extensions/browser-tools/tools/navigation.js +107 -178
  7. package/dist/resources/extensions/browser-tools/tools/network-mock.js +112 -167
  8. package/dist/resources/extensions/browser-tools/tools/pages.js +182 -234
  9. package/dist/resources/extensions/browser-tools/tools/refs.js +202 -461
  10. package/dist/resources/extensions/browser-tools/tools/session.js +176 -323
  11. package/dist/resources/extensions/browser-tools/tools/state-persistence.js +91 -154
  12. package/dist/resources/extensions/browser-tools/utils.js +1 -1
  13. package/dist/resources/extensions/cache-timer/index.js +3 -2
  14. package/dist/resources/extensions/slash-commands/extension-manifest.json +2 -2
  15. package/dist/resources/extensions/slash-commands/fast.js +73 -0
  16. package/dist/resources/extensions/slash-commands/index.js +2 -0
  17. package/dist/resources/extensions/slash-commands/plan.js +37 -12
  18. package/dist/resources/extensions/subagent/background-job-manager.js +13 -0
  19. package/dist/resources/extensions/subagent/in-process-runner.js +387 -0
  20. package/dist/resources/extensions/subagent/index.js +278 -626
  21. package/dist/resources/extensions/subagent/legacy-runner.js +503 -0
  22. package/dist/resources/extensions/voice/index.js +96 -36
  23. package/dist/resources/extensions/voice/push-to-talk.js +26 -0
  24. package/dist/welcome-screen.js +2 -2
  25. package/package.json +1 -1
  26. package/packages/pi-agent-core/dist/agent.d.ts +19 -0
  27. package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
  28. package/packages/pi-agent-core/dist/agent.js +16 -0
  29. package/packages/pi-agent-core/dist/agent.js.map +1 -1
  30. package/packages/pi-agent-core/src/agent.ts +32 -2
  31. package/packages/pi-ai/dist/providers/openai-codex-responses.d.ts +34 -1
  32. package/packages/pi-ai/dist/providers/openai-codex-responses.d.ts.map +1 -1
  33. package/packages/pi-ai/dist/providers/openai-codex-responses.js +32 -4
  34. package/packages/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
  35. package/packages/pi-ai/dist/providers/openai-codex-responses.test.js +127 -16
  36. package/packages/pi-ai/dist/providers/openai-codex-responses.test.js.map +1 -1
  37. package/packages/pi-ai/dist/providers/openai-responses.d.ts +8 -1
  38. package/packages/pi-ai/dist/providers/openai-responses.d.ts.map +1 -1
  39. package/packages/pi-ai/dist/providers/openai-responses.fast-mode.test.d.ts +2 -0
  40. package/packages/pi-ai/dist/providers/openai-responses.fast-mode.test.d.ts.map +1 -0
  41. package/packages/pi-ai/dist/providers/openai-responses.fast-mode.test.js +67 -0
  42. package/packages/pi-ai/dist/providers/openai-responses.fast-mode.test.js.map +1 -0
  43. package/packages/pi-ai/dist/providers/openai-responses.js +21 -3
  44. package/packages/pi-ai/dist/providers/openai-responses.js.map +1 -1
  45. package/packages/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
  46. package/packages/pi-ai/dist/providers/simple-options.js +2 -0
  47. package/packages/pi-ai/dist/providers/simple-options.js.map +1 -1
  48. package/packages/pi-ai/dist/types.d.ts +5 -0
  49. package/packages/pi-ai/dist/types.d.ts.map +1 -1
  50. package/packages/pi-ai/dist/types.js.map +1 -1
  51. package/packages/pi-ai/src/providers/openai-codex-responses.test.ts +143 -20
  52. package/packages/pi-ai/src/providers/openai-codex-responses.ts +47 -4
  53. package/packages/pi-ai/src/providers/openai-responses.fast-mode.test.ts +73 -0
  54. package/packages/pi-ai/src/providers/openai-responses.ts +26 -3
  55. package/packages/pi-ai/src/providers/simple-options.ts +2 -0
  56. package/packages/pi-ai/src/types.ts +5 -0
  57. package/packages/pi-coding-agent/dist/core/keybindings.d.ts +1 -1
  58. package/packages/pi-coding-agent/dist/core/keybindings.d.ts.map +1 -1
  59. package/packages/pi-coding-agent/dist/core/keybindings.js +2 -0
  60. package/packages/pi-coding-agent/dist/core/keybindings.js.map +1 -1
  61. package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
  62. package/packages/pi-coding-agent/dist/core/sdk.js +4 -2
  63. package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
  64. package/packages/pi-coding-agent/dist/core/settings-manager.collapse-tool-calls.test.d.ts +2 -0
  65. package/packages/pi-coding-agent/dist/core/settings-manager.collapse-tool-calls.test.d.ts.map +1 -0
  66. package/packages/pi-coding-agent/dist/core/settings-manager.collapse-tool-calls.test.js +35 -0
  67. package/packages/pi-coding-agent/dist/core/settings-manager.collapse-tool-calls.test.js.map +1 -0
  68. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +12 -0
  69. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  70. package/packages/pi-coding-agent/dist/core/settings-manager.fast-mode.test.d.ts +2 -0
  71. package/packages/pi-coding-agent/dist/core/settings-manager.fast-mode.test.d.ts.map +1 -0
  72. package/packages/pi-coding-agent/dist/core/settings-manager.fast-mode.test.js +35 -0
  73. package/packages/pi-coding-agent/dist/core/settings-manager.fast-mode.test.js.map +1 -0
  74. package/packages/pi-coding-agent/dist/core/settings-manager.js +24 -0
  75. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  76. package/packages/pi-coding-agent/dist/core/slash-commands.d.ts.map +1 -1
  77. package/packages/pi-coding-agent/dist/core/slash-commands.js +1 -0
  78. package/packages/pi-coding-agent/dist/core/slash-commands.js.map +1 -1
  79. package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
  80. package/packages/pi-coding-agent/dist/core/system-prompt.js +6 -1
  81. package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
  82. package/packages/pi-coding-agent/dist/core/tool-priority.d.ts +4 -0
  83. package/packages/pi-coding-agent/dist/core/tool-priority.d.ts.map +1 -0
  84. package/packages/pi-coding-agent/dist/core/tool-priority.js +18 -0
  85. package/packages/pi-coding-agent/dist/core/tool-priority.js.map +1 -0
  86. package/packages/pi-coding-agent/dist/core/tool-priority.test.d.ts +2 -0
  87. package/packages/pi-coding-agent/dist/core/tool-priority.test.d.ts.map +1 -0
  88. package/packages/pi-coding-agent/dist/core/tool-priority.test.js +27 -0
  89. package/packages/pi-coding-agent/dist/core/tool-priority.test.js.map +1 -0
  90. package/packages/pi-coding-agent/dist/core/tools/edit-diff.d.ts +5 -0
  91. package/packages/pi-coding-agent/dist/core/tools/edit-diff.d.ts.map +1 -1
  92. package/packages/pi-coding-agent/dist/core/tools/edit-diff.js +21 -0
  93. package/packages/pi-coding-agent/dist/core/tools/edit-diff.js.map +1 -1
  94. package/packages/pi-coding-agent/dist/core/tools/edit-diff.test.js +16 -1
  95. package/packages/pi-coding-agent/dist/core/tools/edit-diff.test.js.map +1 -1
  96. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-summary-line.test.d.ts +2 -0
  97. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-summary-line.test.d.ts.map +1 -0
  98. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-summary-line.test.js +34 -0
  99. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-summary-line.test.js.map +1 -0
  100. package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.d.ts +45 -0
  101. package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.d.ts.map +1 -0
  102. package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.js +314 -0
  103. package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.js.map +1 -0
  104. package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.test.d.ts +2 -0
  105. package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.test.d.ts.map +1 -0
  106. package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.test.js +122 -0
  107. package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.test.js.map +1 -0
  108. package/packages/pi-coding-agent/dist/modes/interactive/components/diff.d.ts +7 -5
  109. package/packages/pi-coding-agent/dist/modes/interactive/components/diff.d.ts.map +1 -1
  110. package/packages/pi-coding-agent/dist/modes/interactive/components/diff.js +86 -28
  111. package/packages/pi-coding-agent/dist/modes/interactive/components/diff.js.map +1 -1
  112. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts +4 -0
  113. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts.map +1 -1
  114. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js +23 -10
  115. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js.map +1 -1
  116. package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.d.ts +8 -0
  117. package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  118. package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.js +52 -6
  119. package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.js.map +1 -1
  120. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +19 -0
  121. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  122. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +127 -14
  123. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  124. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-summary-line.d.ts +14 -0
  125. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-summary-line.d.ts.map +1 -0
  126. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-summary-line.js +93 -0
  127. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-summary-line.js.map +1 -0
  128. package/packages/pi-coding-agent/dist/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.d.ts +2 -0
  129. package/packages/pi-coding-agent/dist/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.d.ts.map +1 -0
  130. package/packages/pi-coding-agent/dist/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.js +328 -0
  131. package/packages/pi-coding-agent/dist/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.js.map +1 -0
  132. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  133. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +123 -0
  134. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  135. package/packages/pi-coding-agent/dist/modes/interactive/controllers/extension-ui-controller.js +1 -1
  136. package/packages/pi-coding-agent/dist/modes/interactive/controllers/extension-ui-controller.js.map +1 -1
  137. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.d.ts.map +1 -1
  138. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js +7 -0
  139. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js.map +1 -1
  140. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.d.ts +4 -0
  141. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.d.ts.map +1 -1
  142. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.js.map +1 -1
  143. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +9 -1
  144. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  145. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +103 -23
  146. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  147. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.d.ts.map +1 -1
  148. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js +41 -0
  149. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js.map +1 -1
  150. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js +4 -4
  151. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js.map +1 -1
  152. package/packages/pi-coding-agent/package.json +1 -1
  153. package/packages/pi-coding-agent/src/core/keybindings.ts +4 -1
  154. package/packages/pi-coding-agent/src/core/sdk.ts +4 -2
  155. package/packages/pi-coding-agent/src/core/settings-manager.collapse-tool-calls.test.ts +46 -0
  156. package/packages/pi-coding-agent/src/core/settings-manager.fast-mode.test.ts +46 -0
  157. package/packages/pi-coding-agent/src/core/settings-manager.ts +36 -0
  158. package/packages/pi-coding-agent/src/core/slash-commands.ts +1 -0
  159. package/packages/pi-coding-agent/src/core/system-prompt.ts +6 -1
  160. package/packages/pi-coding-agent/src/core/tool-priority.test.ts +30 -0
  161. package/packages/pi-coding-agent/src/core/tool-priority.ts +17 -0
  162. package/packages/pi-coding-agent/src/core/tools/edit-diff.test.ts +20 -0
  163. package/packages/pi-coding-agent/src/core/tools/edit-diff.ts +26 -0
  164. package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/tool-summary-line.test.ts +41 -0
  165. package/packages/pi-coding-agent/src/modes/interactive/components/btw-overlay.test.ts +172 -0
  166. package/packages/pi-coding-agent/src/modes/interactive/components/btw-overlay.ts +402 -0
  167. package/packages/pi-coding-agent/src/modes/interactive/components/diff.ts +105 -28
  168. package/packages/pi-coding-agent/src/modes/interactive/components/footer.ts +21 -6
  169. package/packages/pi-coding-agent/src/modes/interactive/components/settings-selector.ts +63 -6
  170. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +1262 -1138
  171. package/packages/pi-coding-agent/src/modes/interactive/components/tool-summary-line.ts +120 -0
  172. package/packages/pi-coding-agent/src/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.ts +396 -0
  173. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +530 -398
  174. package/packages/pi-coding-agent/src/modes/interactive/controllers/extension-ui-controller.ts +1 -1
  175. package/packages/pi-coding-agent/src/modes/interactive/controllers/input-controller.ts +7 -0
  176. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode-state.ts +4 -0
  177. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +109 -23
  178. package/packages/pi-coding-agent/src/modes/interactive/slash-command-handlers.ts +60 -1
  179. package/packages/pi-coding-agent/src/modes/interactive/theme/themes.ts +4 -4
  180. package/packages/pi-tui/dist/components/editor.js +3 -3
  181. package/packages/pi-tui/dist/components/editor.js.map +1 -1
  182. package/packages/pi-tui/src/components/editor.ts +3 -3
  183. package/pkg/dist/modes/interactive/theme/themes.js +4 -4
  184. package/pkg/dist/modes/interactive/theme/themes.js.map +1 -1
  185. package/pkg/package.json +1 -1
  186. package/src/resources/extensions/browser-tools/tools/codegen.ts +5 -5
  187. package/src/resources/extensions/browser-tools/tools/navigation.ts +118 -196
  188. package/src/resources/extensions/browser-tools/tools/network-mock.ts +114 -205
  189. package/src/resources/extensions/browser-tools/tools/pages.ts +183 -237
  190. package/src/resources/extensions/browser-tools/tools/refs.ts +193 -507
  191. package/src/resources/extensions/browser-tools/tools/session.ts +182 -321
  192. package/src/resources/extensions/browser-tools/tools/state-persistence.ts +94 -172
  193. package/src/resources/extensions/browser-tools/utils.ts +1 -1
  194. package/src/resources/extensions/cache-timer/index.ts +3 -2
  195. package/src/resources/extensions/slash-commands/extension-manifest.json +2 -2
  196. package/src/resources/extensions/slash-commands/fast.ts +89 -0
  197. package/src/resources/extensions/slash-commands/index.ts +2 -0
  198. package/src/resources/extensions/slash-commands/plan.ts +42 -12
  199. package/src/resources/extensions/subagent/background-job-manager.ts +28 -0
  200. package/src/resources/extensions/subagent/in-process-runner.ts +534 -0
  201. package/src/resources/extensions/subagent/index.ts +489 -799
  202. package/src/resources/extensions/subagent/legacy-runner.ts +607 -0
  203. package/src/resources/extensions/voice/index.ts +308 -238
  204. package/src/resources/extensions/voice/push-to-talk.ts +42 -0
  205. package/src/resources/extensions/voice/tests/push-to-talk.test.ts +109 -0
@@ -1 +1 @@
1
- {"version":3,"file":"slash-commands.js","sourceRoot":"","sources":["../../src/core/slash-commands.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAA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AAI,EAAE,QAAQ,EAAE,WAAW,EAAE,4BAA4B,EAAE;IAC7D,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE;IACnD,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,sCAAsC,EAAE;IACxE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,4BAA4B,EAAE;IAC7D,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gDAAgD,EAAE;IACjF,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,gDAAgD,EAAE;IACnF,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,sCAAsC,EAAE;IAC1E,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,gEAAgE,EAAE;IACnG,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE;CACxC,CAAC","sourcesContent":["export type SlashCommandSource = \"extension\" | \"prompt\" | \"skill\";\n\nexport type SlashCommandLocation = \"user\" | \"project\" | \"path\";\n\nexport interface SlashCommandInfo {\n\tname: string;\n\tdescription?: string;\n\tsource: SlashCommandSource;\n\tlocation?: SlashCommandLocation;\n\tpath?: string;\n}\n\nexport interface BuiltinSlashCommand {\n\tname: string;\n\tdescription: string;\n}\n\nexport const BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand> = [\n\t{ name: \"help\", description: \"Show available slash commands and command details\" },\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 to HTML file\" },\n\t{ name: \"share\", description: \"Share session as a secret GitHub gist\" },\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: \"provider\", description: \"Manage provider configuration\" },\n\t{ name: \"config\", description: \"Re-run the setup wizard\" },\n\t{ name: \"setup\", description: \"Re-run the setup wizard\" },\n\t{ name: \"permission\", description: \"Cycle permission mode (danger-full-access/accept-on-edit/auto/plan)\" },\n\t{ name: \"sandbox\", description: \"Show or toggle sandbox settings\" },\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 extensions, skills, prompts, and themes\" },\n\t{ name: \"thinking\", description: \"Set thinking level (off/low/medium/high/xhigh)\" },\n\t{ name: \"edit-mode\", description: \"Toggle edit mode (standard/hashline)\" },\n\t{ name: \"terminal\", description: \"Run a shell command directly (e.g. /terminal ping -c3 1.1.1.1)\" },\n\t{ name: \"quit\", description: \"Quit pi\" },\n];\n"]}
1
+ {"version":3,"file":"slash-commands.js","sourceRoot":"","sources":["../../src/core/slash-commands.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,sBAAsB,GAAuC;IACzE,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,mDAAmD,EAAE;IAClF,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE;IACvD,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,kCAAkC,EAAE;IAClE,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,0CAA0C,EAAE;IAClF,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,6BAA6B,EAAE;IAC9D,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EA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E,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,gDAAgD,EAAE;IACnF,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,sCAAsC,EAAE;IAC1E,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,gEAAgE,EAAE;IACnG,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE;CACxC,CAAC","sourcesContent":["export type SlashCommandSource = \"extension\" | \"prompt\" | \"skill\";\n\nexport type SlashCommandLocation = \"user\" | \"project\" | \"path\";\n\nexport interface SlashCommandInfo {\n\tname: string;\n\tdescription?: string;\n\tsource: SlashCommandSource;\n\tlocation?: SlashCommandLocation;\n\tpath?: string;\n}\n\nexport interface BuiltinSlashCommand {\n\tname: string;\n\tdescription: string;\n}\n\nexport const BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand> = [\n\t{ name: \"help\", description: \"Show available slash commands and command details\" },\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 to HTML file\" },\n\t{ name: \"share\", description: \"Share session as a secret GitHub gist\" },\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: \"btw\", description: \"Ask a side question without interrupting the current task\" },\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: \"provider\", description: \"Manage provider configuration\" },\n\t{ name: \"config\", description: \"Re-run the setup wizard\" },\n\t{ name: \"setup\", description: \"Re-run the setup wizard\" },\n\t{ name: \"permission\", description: \"Cycle permission mode (danger-full-access/accept-on-edit/auto/plan)\" },\n\t{ name: \"sandbox\", description: \"Show or toggle sandbox settings\" },\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 extensions, skills, prompts, and themes\" },\n\t{ name: \"thinking\", description: \"Set thinking level (off/low/medium/high/xhigh)\" },\n\t{ name: \"edit-mode\", description: \"Toggle edit mode (standard/hashline)\" },\n\t{ name: \"terminal\", description: \"Run a shell command directly (e.g. /terminal ping -c3 1.1.1.1)\" },\n\t{ name: \"quit\", description: \"Quit pi\" },\n];\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAchE,MAAM,WAAW,wBAAwB;IACxC;;;;;OAKG;IACH,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,CAgOhF"}
1
+ {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAchE,MAAM,WAAW,wBAAwB;IACxC;;;;;OAKG;IACH,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,CAqOhF"}
@@ -97,7 +97,12 @@ export function buildSystemPrompt(options = {}) {
97
97
  const hasRead = tools.includes("read");
98
98
  const hasLsp = tools.includes("lsp");
99
99
  // Priority-ordered compact guidelines
100
- addGuideline("Be concise. Prefer short, direct answers over preamble.");
100
+ addGuideline("Terse output. All technical substance stays. Only fluff dies.");
101
+ addGuideline("Drop: articles (a/an/the), filler (just/really/basically/actually/simply), pleasantries (sure/certainly/of course/happy to), hedging (might be worth/could consider).");
102
+ addGuideline("Fragments OK. Short synonyms (big not extensive, fix not implement a solution for). Pattern: [thing] [action] [reason]. [next step].");
103
+ addGuideline("Never announce what you're about to do — just do it. Never summarize what you just did unless the user asks.");
104
+ addGuideline("Code blocks, error messages, file paths, and technical terms stay exact. Only compress prose.");
105
+ addGuideline("For security warnings, irreversible actions, or multi-step sequences where fragments risk misread — use full clear sentences. Resume terse after.");
101
106
  addGuideline("For conceptual, product, or UX questions, answer first; inspect code only if implementation detail is needed.");
102
107
  const hasSubagent = tools.includes("subagent");
103
108
  if (hasLsp) {
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,0CAA0C;AAC1C,MAAM,gBAAgB,GAA2B;IAChD,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,8CAA8C;IACpD,IAAI,EAAE,4DAA4D;IAClE,KAAK,EAAE,2BAA2B;IAClC,IAAI,EAAE,6IAA6I;IACnJ,IAAI,EAAE,kDAAkD;IACxD,EAAE,EAAE,yBAAyB;IAC7B,GAAG,EAAE,oHAAoH;CACzH,CAAC;AA0BF,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,UAAoC,EAAE;IACvE,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,WAAW,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEtD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,M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K,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,6DAA6D;IAC7D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2CAA2C;IAC3C,MAAM,IAAI,4BAA4B,QAAQ,EAAE,CAAC;IACjD,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { existsSync } from \"node:fs\";\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore). For symbol definitions, references, type info, or callers in code, use lsp instead\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/**\n\t * Custom system prompt that replaces the default role header, tool list,\n\t * and guidelines entirely. You are responsible for providing your own\n\t * tool-usage guidance. Project context, skills, extension promptGuidelines,\n\t * date/cwd, and appendSystemPrompt are still applied on top.\n\t */\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 = toPosixPath(cwd ?? process.cwd());\n\n\tconst now = new Date();\n\tconst dateTime = now.toLocaleString(\"en-US\", {\n\t\tweekday: \"long\",\n\t\tyear: \"numeric\",\n\t\tmonth: \"long\",\n\t\tday: \"numeric\",\n\t\thour: \"2-digit\",\n\t\tminute: \"2-digit\",\n\t\tsecond: \"2-digit\",\n\t\ttimeZoneName: \"short\",\n\t});\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 (if read or Skill tool is available)\n\t\tconst customPromptHasSkillAccess = !selectedTools || selectedTools.includes(\"read\") || selectedTools.includes(\"Skill\");\n\t\tif (customPromptHasSkillAccess && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Append promptGuidelines from extension-registered tools.\n\t\t// Without this, tools registered via pi.registerTool() with promptGuidelines\n\t\t// have their definitions reach the API but the model has no guidance on when\n\t\t// to use them (#1184).\n\t\tif (promptGuidelines && promptGuidelines.length > 0) {\n\t\t\tprompt += \"\\n\\n\";\n\t\t\tfor (const guideline of promptGuidelines) {\n\t\t\t\tprompt += guideline + \"\\n\";\n\t\t\t}\n\t\t}\n\n\t\t// Add date/time and working directory last\n\t\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\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// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(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 hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// Priority-ordered compact guidelines\n\taddGuideline(\"Be concise. Prefer short, direct answers over preamble.\");\n\taddGuideline(\"For conceptual, product, or UX questions, answer first; inspect code only if implementation detail is needed.\");\n\n\tconst hasSubagent = tools.includes(\"subagent\");\n\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t\"Code navigation in typed codebases: use lsp first for symbols (definition, references, implementation, type info, hover, callers, diagnostics, rename, format). Do not use grep/find as a substitute for symbol navigation when LSP is available. Use grep/find/ls for raw text patterns, filenames, and non-code files. If LSP is unavailable or failing, say so briefly and then fall back to grep/read.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Before choosing a code navigation tool, classify intent: symbol lookup (definition/reference/implementation/type/caller/rename) → lsp; raw text or filename search → grep/find.\",\n\t\t);\n\t} else {\n\t\taddGuideline(\"Use grep/find/ls for code search and file exploration (faster than bash, respects .gitignore)\");\n\t}\n\n\tif (hasSubagent) {\n\t\taddGuideline(\n\t\t\t\"Recon planning policy: use 0 scouts for narrow known-file work, 1 scout for one broad unfamiliar subsystem, and 2-4 parallel scouts only when the work spans multiple loosely-coupled subsystems.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For broad or unfamiliar codebase exploration, delegate reconnaissance to the scout subagent before reading many files yourself. After scout returns, use lsp and targeted reads for the narrowed file set.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Call the subagent tool directly. For one scout use { agent, task }. For several scouts use parallel mode with { tasks: [{ agent, task }, ...] }.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"When the user names a subagent such as scout, worker, reviewer, or planner, invoke the subagent tool directly rather than the Skill tool or ad-hoc search.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Scout is for mapping and reconnaissance only — not for final review, audit, or ranked issue lists. Use it to identify relevant files, subsystems, and likely hotspots for later evaluation.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"If reconnaissance spans multiple loosely-coupled areas, prefer multiple scout subagents in parallel, each covering one subsystem, instead of one model exploring everything itself.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For broad review or audit requests, use scout only as a prep step to map architecture and hotspots; the parent model or a reviewer should make the final judgments.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Skip scout only when the task is clearly narrow, the relevant file is already known, or the user explicitly asked for direct inspection of a specific file.\",\n\t\t);\n\t}\n\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Read files before editing them. Never use cat or sed to inspect or modify files.\");\n\t}\n\n\tif (hasEdit) {\n\t\taddGuideline(\"edit requires exact text match; write is for new files or full rewrites.\");\n\t}\n\n\tif (hasWrite && !hasEdit) {\n\t\taddGuideline(\"write is for new files or full rewrites.\");\n\t}\n\n\tif (hasLsp && hasEdit) {\n\t\taddGuideline(\"Run lsp diagnostics after edits to catch type errors.\");\n\t}\n\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\"Output plain text directly when summarizing your work — do not cat or echo to display what you did.\");\n\t}\n\n\taddGuideline(\"Show file paths clearly when referencing files.\");\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\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\tconst lspDecisionTable = hasLsp\n\t\t? `\\n\\nTool selection — code navigation quick map:\\n\\n| Intent | Use | Avoid |\\n| --- | --- | --- |\\n| Find where a symbol is defined | \\`lsp definition\\` | \\`grep\\` |\\n| Find all usages of a symbol | \\`lsp references\\` | \\`grep\\` |\\n| Find implementations of an interface/type | \\`lsp implementation\\` | \\`grep\\` |\\n| Get type info/docs for a symbol | \\`lsp hover\\` | raw text search |\\n| Find callers of a function | \\`lsp incoming_calls\\` | \\`grep\\` |\\n| Search literal text patterns (TODO, logs, strings) | \\`grep\\` | \\`lsp\\` |\\n| Search filenames/paths | \\`find\\` / \\`ls\\` | \\`lsp\\` |\\n| Rename a symbol across codebase | \\`lsp rename\\` | find-and-replace |\\n| Check type errors after edits | \\`lsp diagnostics\\` | ad-hoc grep |\\n| Format a file | \\`lsp format\\` | external formatter guesswork |`\n\t\t: \"\";\n\n\tconst piDocsBlock = existsSync(readmePath)\n\t\t? `\\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 working on pi topics, read the docs and follow .md cross-references before implementing`\n\t\t: \"\";\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness.\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}${lspDecisionTable}${piDocsBlock}`;\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 (if read or Skill tool is available)\n\tconst hasSkill = tools.includes(\"Skill\");\n\tif ((hasRead || hasSkill) && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time and working directory last\n\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
1
+ {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,e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OAAO,IAAI,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2CAA2C;IAC3C,MAAM,IAAI,4BAA4B,QAAQ,EAAE,CAAC;IACjD,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { existsSync } from \"node:fs\";\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore). For symbol definitions, references, type info, or callers in code, use lsp instead\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/**\n\t * Custom system prompt that replaces the default role header, tool list,\n\t * and guidelines entirely. You are responsible for providing your own\n\t * tool-usage guidance. Project context, skills, extension promptGuidelines,\n\t * date/cwd, and appendSystemPrompt are still applied on top.\n\t */\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 = toPosixPath(cwd ?? process.cwd());\n\n\tconst now = new Date();\n\tconst dateTime = now.toLocaleString(\"en-US\", {\n\t\tweekday: \"long\",\n\t\tyear: \"numeric\",\n\t\tmonth: \"long\",\n\t\tday: \"numeric\",\n\t\thour: \"2-digit\",\n\t\tminute: \"2-digit\",\n\t\tsecond: \"2-digit\",\n\t\ttimeZoneName: \"short\",\n\t});\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 (if read or Skill tool is available)\n\t\tconst customPromptHasSkillAccess = !selectedTools || selectedTools.includes(\"read\") || selectedTools.includes(\"Skill\");\n\t\tif (customPromptHasSkillAccess && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Append promptGuidelines from extension-registered tools.\n\t\t// Without this, tools registered via pi.registerTool() with promptGuidelines\n\t\t// have their definitions reach the API but the model has no guidance on when\n\t\t// to use them (#1184).\n\t\tif (promptGuidelines && promptGuidelines.length > 0) {\n\t\t\tprompt += \"\\n\\n\";\n\t\t\tfor (const guideline of promptGuidelines) {\n\t\t\t\tprompt += guideline + \"\\n\";\n\t\t\t}\n\t\t}\n\n\t\t// Add date/time and working directory last\n\t\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\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// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(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 hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// Priority-ordered compact guidelines\n\taddGuideline(\"Terse output. All technical substance stays. Only fluff dies.\");\n\taddGuideline(\"Drop: articles (a/an/the), filler (just/really/basically/actually/simply), pleasantries (sure/certainly/of course/happy to), hedging (might be worth/could consider).\");\n\taddGuideline(\"Fragments OK. Short synonyms (big not extensive, fix not implement a solution for). Pattern: [thing] [action] [reason]. [next step].\");\n\taddGuideline(\"Never announce what you're about to do — just do it. Never summarize what you just did unless the user asks.\");\n\taddGuideline(\"Code blocks, error messages, file paths, and technical terms stay exact. Only compress prose.\");\n\taddGuideline(\"For security warnings, irreversible actions, or multi-step sequences where fragments risk misread — use full clear sentences. Resume terse after.\");\n\taddGuideline(\"For conceptual, product, or UX questions, answer first; inspect code only if implementation detail is needed.\");\n\n\tconst hasSubagent = tools.includes(\"subagent\");\n\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t\"Code navigation in typed codebases: use lsp first for symbols (definition, references, implementation, type info, hover, callers, diagnostics, rename, format). Do not use grep/find as a substitute for symbol navigation when LSP is available. Use grep/find/ls for raw text patterns, filenames, and non-code files. If LSP is unavailable or failing, say so briefly and then fall back to grep/read.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Before choosing a code navigation tool, classify intent: symbol lookup (definition/reference/implementation/type/caller/rename) → lsp; raw text or filename search → grep/find.\",\n\t\t);\n\t} else {\n\t\taddGuideline(\"Use grep/find/ls for code search and file exploration (faster than bash, respects .gitignore)\");\n\t}\n\n\tif (hasSubagent) {\n\t\taddGuideline(\n\t\t\t\"Recon planning policy: use 0 scouts for narrow known-file work, 1 scout for one broad unfamiliar subsystem, and 2-4 parallel scouts only when the work spans multiple loosely-coupled subsystems.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For broad or unfamiliar codebase exploration, delegate reconnaissance to the scout subagent before reading many files yourself. After scout returns, use lsp and targeted reads for the narrowed file set.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Call the subagent tool directly. For one scout use { agent, task }. For several scouts use parallel mode with { tasks: [{ agent, task }, ...] }.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"When the user names a subagent such as scout, worker, reviewer, or planner, invoke the subagent tool directly rather than the Skill tool or ad-hoc search.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Scout is for mapping and reconnaissance only — not for final review, audit, or ranked issue lists. Use it to identify relevant files, subsystems, and likely hotspots for later evaluation.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"If reconnaissance spans multiple loosely-coupled areas, prefer multiple scout subagents in parallel, each covering one subsystem, instead of one model exploring everything itself.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For broad review or audit requests, use scout only as a prep step to map architecture and hotspots; the parent model or a reviewer should make the final judgments.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Skip scout only when the task is clearly narrow, the relevant file is already known, or the user explicitly asked for direct inspection of a specific file.\",\n\t\t);\n\t}\n\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Read files before editing them. Never use cat or sed to inspect or modify files.\");\n\t}\n\n\tif (hasEdit) {\n\t\taddGuideline(\"edit requires exact text match; write is for new files or full rewrites.\");\n\t}\n\n\tif (hasWrite && !hasEdit) {\n\t\taddGuideline(\"write is for new files or full rewrites.\");\n\t}\n\n\tif (hasLsp && hasEdit) {\n\t\taddGuideline(\"Run lsp diagnostics after edits to catch type errors.\");\n\t}\n\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\"Output plain text directly when summarizing your work — do not cat or echo to display what you did.\");\n\t}\n\n\taddGuideline(\"Show file paths clearly when referencing files.\");\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\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\tconst lspDecisionTable = hasLsp\n\t\t? `\\n\\nTool selection — code navigation quick map:\\n\\n| Intent | Use | Avoid |\\n| --- | --- | --- |\\n| Find where a symbol is defined | \\`lsp definition\\` | \\`grep\\` |\\n| Find all usages of a symbol | \\`lsp references\\` | \\`grep\\` |\\n| Find implementations of an interface/type | \\`lsp implementation\\` | \\`grep\\` |\\n| Get type info/docs for a symbol | \\`lsp hover\\` | raw text search |\\n| Find callers of a function | \\`lsp incoming_calls\\` | \\`grep\\` |\\n| Search literal text patterns (TODO, logs, strings) | \\`grep\\` | \\`lsp\\` |\\n| Search filenames/paths | \\`find\\` / \\`ls\\` | \\`lsp\\` |\\n| Rename a symbol across codebase | \\`lsp rename\\` | find-and-replace |\\n| Check type errors after edits | \\`lsp diagnostics\\` | ad-hoc grep |\\n| Format a file | \\`lsp format\\` | external formatter guesswork |`\n\t\t: \"\";\n\n\tconst piDocsBlock = existsSync(readmePath)\n\t\t? `\\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 working on pi topics, read the docs and follow .md cross-references before implementing`\n\t\t: \"\";\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness.\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}${lspDecisionTable}${piDocsBlock}`;\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 (if read or Skill tool is available)\n\tconst hasSkill = tools.includes(\"Skill\");\n\tif ((hasRead || hasSkill) && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time and working directory last\n\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export type ToolPriority = "always" | "on-error" | "collapse";
2
+ export declare function getToolPriority(toolName: string): ToolPriority;
3
+ export declare function shouldCollapse(toolName: string, isError: boolean): boolean;
4
+ //# sourceMappingURL=tool-priority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-priority.d.ts","sourceRoot":"","sources":["../../src/core/tool-priority.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;AAK9D,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAI9D;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAK1E"}
@@ -0,0 +1,18 @@
1
+ const ALWAYS_VISIBLE = new Set(["edit", "write"]);
2
+ const ON_ERROR = new Set(["bash", "bg_shell"]);
3
+ export function getToolPriority(toolName) {
4
+ if (ALWAYS_VISIBLE.has(toolName))
5
+ return "always";
6
+ if (ON_ERROR.has(toolName))
7
+ return "on-error";
8
+ return "collapse";
9
+ }
10
+ export function shouldCollapse(toolName, isError) {
11
+ const priority = getToolPriority(toolName);
12
+ if (priority === "always")
13
+ return false;
14
+ if (priority === "on-error")
15
+ return !isError;
16
+ return true;
17
+ }
18
+ //# sourceMappingURL=tool-priority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-priority.js","sourceRoot":"","sources":["../../src/core/tool-priority.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAClD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AAE/C,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC/C,IAAI,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAClD,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAE,OAAO,UAAU,CAAC;IAC9C,OAAO,UAAU,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,OAAgB;IAChE,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,QAAQ,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,QAAQ,KAAK,UAAU;QAAE,OAAO,CAAC,OAAO,CAAC;IAC7C,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["export type ToolPriority = \"always\" | \"on-error\" | \"collapse\";\n\nconst ALWAYS_VISIBLE = new Set([\"edit\", \"write\"]);\nconst ON_ERROR = new Set([\"bash\", \"bg_shell\"]);\n\nexport function getToolPriority(toolName: string): ToolPriority {\n\tif (ALWAYS_VISIBLE.has(toolName)) return \"always\";\n\tif (ON_ERROR.has(toolName)) return \"on-error\";\n\treturn \"collapse\";\n}\n\nexport function shouldCollapse(toolName: string, isError: boolean): boolean {\n\tconst priority = getToolPriority(toolName);\n\tif (priority === \"always\") return false;\n\tif (priority === \"on-error\") return !isError;\n\treturn true;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tool-priority.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-priority.test.d.ts","sourceRoot":"","sources":["../../src/core/tool-priority.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { getToolPriority, shouldCollapse } from "./tool-priority.js";
4
+ describe("tool priority", () => {
5
+ it("keeps edit and write always visible", () => {
6
+ assert.equal(getToolPriority("edit"), "always");
7
+ assert.equal(getToolPriority("write"), "always");
8
+ assert.equal(shouldCollapse("edit", false), false);
9
+ assert.equal(shouldCollapse("write", true), false);
10
+ });
11
+ it("collapses bash and bg_shell only on success", () => {
12
+ assert.equal(getToolPriority("bash"), "on-error");
13
+ assert.equal(getToolPriority("bg_shell"), "on-error");
14
+ assert.equal(shouldCollapse("bash", false), true);
15
+ assert.equal(shouldCollapse("bash", true), false);
16
+ assert.equal(shouldCollapse("bg_shell", false), true);
17
+ assert.equal(shouldCollapse("bg_shell", true), false);
18
+ });
19
+ it("collapses read, grep, and unknown tools", () => {
20
+ assert.equal(getToolPriority("read"), "collapse");
21
+ assert.equal(getToolPriority("grep"), "collapse");
22
+ assert.equal(getToolPriority("unknown-tool"), "collapse");
23
+ assert.equal(shouldCollapse("read", false), true);
24
+ assert.equal(shouldCollapse("unknown-tool", true), true);
25
+ });
26
+ });
27
+ //# sourceMappingURL=tool-priority.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-priority.test.js","sourceRoot":"","sources":["../../src/core/tool-priority.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAErE,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC9C,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;QACjD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QACnD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;QACtD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;QACtD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QAClD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,CAAC;QAC1D,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { describe, it } from \"node:test\";\n\nimport { getToolPriority, shouldCollapse } from \"./tool-priority.js\";\n\ndescribe(\"tool priority\", () => {\n\tit(\"keeps edit and write always visible\", () => {\n\t\tassert.equal(getToolPriority(\"edit\"), \"always\");\n\t\tassert.equal(getToolPriority(\"write\"), \"always\");\n\t\tassert.equal(shouldCollapse(\"edit\", false), false);\n\t\tassert.equal(shouldCollapse(\"write\", true), false);\n\t});\n\n\tit(\"collapses bash and bg_shell only on success\", () => {\n\t\tassert.equal(getToolPriority(\"bash\"), \"on-error\");\n\t\tassert.equal(getToolPriority(\"bg_shell\"), \"on-error\");\n\t\tassert.equal(shouldCollapse(\"bash\", false), true);\n\t\tassert.equal(shouldCollapse(\"bash\", true), false);\n\t\tassert.equal(shouldCollapse(\"bg_shell\", false), true);\n\t\tassert.equal(shouldCollapse(\"bg_shell\", true), false);\n\t});\n\n\tit(\"collapses read, grep, and unknown tools\", () => {\n\t\tassert.equal(getToolPriority(\"read\"), \"collapse\");\n\t\tassert.equal(getToolPriority(\"grep\"), \"collapse\");\n\t\tassert.equal(getToolPriority(\"unknown-tool\"), \"collapse\");\n\t\tassert.equal(shouldCollapse(\"read\", false), true);\n\t\tassert.equal(shouldCollapse(\"unknown-tool\", true), true);\n\t});\n});\n"]}
@@ -61,6 +61,11 @@ export interface EditDiffResult {
61
61
  export interface EditDiffError {
62
62
  error: string;
63
63
  }
64
+ /**
65
+ * Compute the diff for a write operation without applying it.
66
+ * Used for preview rendering in the TUI before the tool executes.
67
+ */
68
+ export declare function computeWriteDiff(path: string, newContent: string, cwd: string): Promise<EditDiffResult | EditDiffError>;
64
69
  /**
65
70
  * Compute the diff for an edit operation without applying it.
66
71
  * Used for preview rendering in the TUI before the tool executes.
@@ -1 +1 @@
1
- {"version":3,"file":"edit-diff.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM/D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAE9E;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,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OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CAgBzC;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CA6DzC"}
@@ -257,6 +257,27 @@ function buildLineDiffLinear(oldLines, newLines) {
257
257
  }
258
258
  return ops;
259
259
  }
260
+ /**
261
+ * Compute the diff for a write operation without applying it.
262
+ * Used for preview rendering in the TUI before the tool executes.
263
+ */
264
+ export async function computeWriteDiff(path, newContent, cwd) {
265
+ const absolutePath = resolveToCwd(path, cwd);
266
+ try {
267
+ let oldContent = "";
268
+ try {
269
+ await access(absolutePath, constants.R_OK);
270
+ oldContent = await readFile(absolutePath, "utf-8");
271
+ }
272
+ catch {
273
+ oldContent = "";
274
+ }
275
+ return generateDiffString(normalizeToLF(stripBom(oldContent).text), normalizeToLF(newContent));
276
+ }
277
+ catch (err) {
278
+ return { error: err instanceof Error ? err.message : String(err) };
279
+ }
280
+ }
260
281
  /**
261
282
  * Compute the diff for an edit operation without applying it.
262
283
  * Used for preview rendering in the TUI before the tool executes.
@@ -1 +1 @@
1
- {"version":3,"file":"edit-diff.js","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,K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AA0E;aACzH,CAAC;QACH,CAAC;QAED,mEAAmE;QACnE,MAAM,YAAY,GAAG,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;QAC/D,MAAM,YAAY,GAAG,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;QAC/D,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAEhE,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;YACrB,OAAO;gBACN,KAAK,EAAE,SAAS,WAAW,+BAA+B,IAAI,2EAA2E;aACzI,CAAC;QACH,CAAC;QAED,qDAAqD;QACrD,gFAAgF;QAChF,MAAM,WAAW,GAAG,WAAW,CAAC,qBAAqB,CAAC;QACtD,MAAM,UAAU,GACf,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC;YAC3C,iBAAiB;YACjB,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;QAEpE,6CAA6C;QAC7C,IAAI,WAAW,KAAK,UAAU,EAAE,CAAC;YAChC,OAAO;gBACN,KAAK,EAAE,+BAA+B,IAAI,+CAA+C;aACzF,CAAC;QACH,CAAC;QAED,oBAAoB;QACpB,OAAO,kBAAkB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;AACF,CAAC","sourcesContent":["/**\n * Shared diff computation utilities for the edit tool.\n * Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).\n *\n * These helpers intentionally stay in JavaScript. Issue #453 showed that\n * post-tool preview paths must not depend on the native addon because a native\n * hang there can wedge the entire interactive session after a successful tool run.\n */\n\nimport { constants } from \"fs\";\nimport { access, readFile } from \"fs/promises\";\nimport { resolveToCwd, UNICODE_SPACES } from \"./path-utils.js\";\n\nexport function detectLineEnding(content: string): \"\\r\\n\" | \"\\n\" {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: \"\\r\\n\" | \"\\n\"): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching.\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn text\n\t\t.replace(/\\r\\n/g, \"\\n\")\n\t\t.replace(/\\r/g, \"\\n\")\n\t\t.replace(/[“”]/g, '\"')\n\t\t.replace(/[‘’]/g, \"'\")\n\t\t.replace(/[‐‑‒–—−]/g, \"-\")\n\t\t.replace(UNICODE_SPACES, \" \")\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.replace(/[ \\t]+$/g, \"\"))\n\t\t.join(\"\\n\");\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/**\n\t * The content to use for replacement operations.\n\t * When exact match: original content. When fuzzy match: normalized content.\n\t */\n\tcontentForReplacement: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n *\n * When fuzzy matching is used, the returned contentForReplacement is the\n * fuzzy-normalized version of the content.\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\tconst normalizedContent = normalizeForFuzzyMatch(content);\n\tconst normalizedOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = normalizedContent.indexOf(normalizedOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: normalizedOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: normalizedContent,\n\t};\n}\n\n/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */\nexport function stripBom(content: string): { bom: string; text: string } {\n\treturn content.startsWith(\"\\uFEFF\") ? { bom: \"\\uFEFF\", text: content.slice(1) } : { bom: \"\", text: content };\n}\n\n/**\n * Generate a unified diff string with line numbers and context.\n *\n * Returns both the diff string and the first changed line number (in the new file).\n * Only lines within `contextLines` of a change are included (like unified diff).\n */\nexport function generateDiffString(\n\toldContent: string,\n\tnewContent: string,\n\tcontextLines = 4,\n): { diff: string; firstChangedLine: number | undefined } {\n\tconst ops = buildLineDiff(oldContent, newContent);\n\tlet firstChangedLine: number | undefined;\n\n\t// First pass: assign line numbers and find changed indices\n\tconst annotated: { op: LineDiffOp; oldLine: number; newLine: number }[] = [];\n\tlet oldLine = 1;\n\tlet newLine = 1;\n\tconst changedIndices: number[] = [];\n\n\tfor (let idx = 0; idx < ops.length; idx++) {\n\t\tconst op = ops[idx];\n\t\tannotated.push({ op, oldLine, newLine });\n\n\t\tif (op.type !== \"context\") {\n\t\t\tchangedIndices.push(idx);\n\t\t\tif (firstChangedLine === undefined) {\n\t\t\t\tfirstChangedLine = newLine;\n\t\t\t}\n\t\t}\n\n\t\tif (op.type === \"remove\") {\n\t\t\toldLine += 1;\n\t\t} else if (op.type === \"add\") {\n\t\t\tnewLine += 1;\n\t\t} else {\n\t\t\toldLine += 1;\n\t\t\tnewLine += 1;\n\t\t}\n\t}\n\n\t// Build set of indices to include (changes + surrounding context)\n\tconst includeSet = new Set<number>();\n\tfor (const ci of changedIndices) {\n\t\tfor (let k = Math.max(0, ci - contextLines); k <= Math.min(ops.length - 1, ci + contextLines); k++) {\n\t\t\tincludeSet.add(k);\n\t\t}\n\t}\n\n\tconst maxLine = Math.max(oldLine - 1, newLine - 1, 1);\n\tconst lineNumberWidth = String(maxLine).length;\n\tconst rendered: string[] = [];\n\tlet lastIncluded = -1;\n\n\tfor (let idx = 0; idx < annotated.length; idx++) {\n\t\tif (!includeSet.has(idx)) continue;\n\n\t\t// Insert separator when there's a gap between included regions\n\t\tif (lastIncluded !== -1 && idx > lastIncluded + 1) {\n\t\t\trendered.push(\"...\");\n\t\t}\n\t\tlastIncluded = idx;\n\n\t\tconst { op, oldLine: ol, newLine: nl } = annotated[idx];\n\t\tif (op.type === \"context\") {\n\t\t\trendered.push(` ${String(nl).padStart(lineNumberWidth, \" \")} ${op.line}`);\n\t\t} else if (op.type === \"remove\") {\n\t\t\trendered.push(`-${String(ol).padStart(lineNumberWidth, \" \")} ${op.line}`);\n\t\t} else {\n\t\t\trendered.push(`+${String(nl).padStart(lineNumberWidth, \" \")} ${op.line}`);\n\t\t}\n\t}\n\n\treturn {\n\t\tdiff: rendered.join(\"\\n\"),\n\t\tfirstChangedLine,\n\t};\n}\n\nexport interface EditDiffResult {\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nexport interface EditDiffError {\n\terror: string;\n}\n\ntype LineDiffOp =\n\t| { type: \"context\"; line: string }\n\t| { type: \"remove\"; line: string }\n\t| { type: \"add\"; line: string };\n\nfunction splitLines(text: string): string[] {\n\tconst lines = text.split(\"\\n\");\n\tif (lines.length > 0 && lines.at(-1) === \"\") {\n\t\tlines.pop();\n\t}\n\treturn lines;\n}\n\n/**\n * Maximum number of cells (oldLines * newLines) before we switch from the\n * full LCS DP algorithm to a simpler linear-scan diff. This prevents OOM\n * on large files (e.g. 10k lines would need a 100M-cell matrix).\n */\nconst MAX_DP_CELLS = 4_000_000; // ~32 MB for 64-bit numbers\n\nfunction buildLineDiff(oldContent: string, newContent: string): LineDiffOp[] {\n\tconst oldLines = splitLines(oldContent);\n\tconst newLines = splitLines(newContent);\n\n\tconst cells = (oldLines.length + 1) * (newLines.length + 1);\n\tif (cells > MAX_DP_CELLS) {\n\t\treturn buildLineDiffLinear(oldLines, newLines);\n\t}\n\n\treturn buildLineDiffLCS(oldLines, newLines);\n}\n\n/**\n * Full LCS-based diff using O(n*m) DP table. Produces optimal diffs but\n * is only safe for files where n*m <= MAX_DP_CELLS.\n */\nfunction buildLineDiffLCS(oldLines: string[], newLines: string[]): LineDiffOp[] {\n\tconst dp: number[][] = Array.from({ length: oldLines.length + 1 }, () =>\n\t\tArray<number>(newLines.length + 1).fill(0),\n\t);\n\n\tfor (let i = oldLines.length - 1; i >= 0; i--) {\n\t\tfor (let j = newLines.length - 1; j >= 0; j--) {\n\t\t\tif (oldLines[i] === newLines[j]) {\n\t\t\t\tdp[i][j] = dp[i + 1][j + 1] + 1;\n\t\t\t} else {\n\t\t\t\tdp[i][j] = Math.max(dp[i + 1][j], dp[i][j + 1]);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst ops: LineDiffOp[] = [];\n\tlet i = 0;\n\tlet j = 0;\n\n\twhile (i < oldLines.length && j < newLines.length) {\n\t\tif (oldLines[i] === newLines[j]) {\n\t\t\tops.push({ type: \"context\", line: oldLines[i] });\n\t\t\ti += 1;\n\t\t\tj += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (dp[i + 1][j] >= dp[i][j + 1]) {\n\t\t\tops.push({ type: \"remove\", line: oldLines[i] });\n\t\t\ti += 1;\n\t\t} else {\n\t\t\tops.push({ type: \"add\", line: newLines[j] });\n\t\t\tj += 1;\n\t\t}\n\t}\n\n\twhile (i < oldLines.length) {\n\t\tops.push({ type: \"remove\", line: oldLines[i] });\n\t\ti += 1;\n\t}\n\n\twhile (j < newLines.length) {\n\t\tops.push({ type: \"add\", line: newLines[j] });\n\t\tj += 1;\n\t}\n\n\treturn ops;\n}\n\n/**\n * Linear-time fallback diff for large files. Matches common prefix/suffix,\n * then treats the remaining middle as a bulk remove+add. Not optimal but\n * O(n+m) in both time and space.\n */\nfunction buildLineDiffLinear(oldLines: string[], newLines: string[]): LineDiffOp[] {\n\tconst ops: LineDiffOp[] = [];\n\n\t// Match common prefix\n\tlet prefixLen = 0;\n\tconst minLen = Math.min(oldLines.length, newLines.length);\n\twhile (prefixLen < minLen && oldLines[prefixLen] === newLines[prefixLen]) {\n\t\tprefixLen++;\n\t}\n\n\t// Match common suffix (not overlapping with prefix)\n\tlet suffixLen = 0;\n\twhile (\n\t\tsuffixLen < minLen - prefixLen &&\n\t\toldLines[oldLines.length - 1 - suffixLen] === newLines[newLines.length - 1 - suffixLen]\n\t) {\n\t\tsuffixLen++;\n\t}\n\n\t// Emit prefix context\n\tfor (let i = 0; i < prefixLen; i++) {\n\t\tops.push({ type: \"context\", line: oldLines[i] });\n\t}\n\n\t// Emit removed lines from the middle\n\tfor (let i = prefixLen; i < oldLines.length - suffixLen; i++) {\n\t\tops.push({ type: \"remove\", line: oldLines[i] });\n\t}\n\n\t// Emit added lines from the middle\n\tfor (let j = prefixLen; j < newLines.length - suffixLen; j++) {\n\t\tops.push({ type: \"add\", line: newLines[j] });\n\t}\n\n\t// Emit suffix context\n\tfor (let i = oldLines.length - suffixLen; i < oldLines.length; i++) {\n\t\tops.push({ type: \"context\", line: oldLines[i] });\n\t}\n\n\treturn ops;\n}\n\n/**\n * Compute the diff for an edit operation without applying it.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeEditDiff(\n\tpath: string,\n\toldText: string,\n\tnewText: string,\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, cwd);\n\n\ttry {\n\t\t// Check if file exists and is readable\n\t\ttry {\n\t\t\tawait access(absolutePath, constants.R_OK);\n\t\t} catch {\n\t\t\treturn { error: `File not found: ${path}` };\n\t\t}\n\n\t\t// Read the file\n\t\tconst rawContent = await readFile(absolutePath, \"utf-8\");\n\n\t\t// Strip BOM before matching (LLM won't include invisible BOM in oldText)\n\t\tconst { text: content } = stripBom(rawContent);\n\n\t\tconst normalizedContent = normalizeToLF(content);\n\t\tconst normalizedOldText = normalizeToLF(oldText);\n\t\tconst normalizedNewText = normalizeToLF(newText);\n\n\t\t// Find the old text using fuzzy matching (tries exact match first, then fuzzy)\n\t\tconst matchResult = fuzzyFindText(normalizedContent, normalizedOldText);\n\n\t\tif (!matchResult.found) {\n\t\t\treturn {\n\t\t\t\terror: `Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,\n\t\t\t};\n\t\t}\n\n\t\t// Count occurrences using fuzzy-normalized content for consistency\n\t\tconst fuzzyContent = normalizeForFuzzyMatch(normalizedContent);\n\t\tconst fuzzyOldText = normalizeForFuzzyMatch(normalizedOldText);\n\t\tconst occurrences = fuzzyContent.split(fuzzyOldText).length - 1;\n\n\t\tif (occurrences > 1) {\n\t\t\treturn {\n\t\t\t\terror: `Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t\t};\n\t\t}\n\n\t\t// Compute the new content using the matched position\n\t\t// When fuzzy matching was used, contentForReplacement is the normalized version\n\t\tconst baseContent = matchResult.contentForReplacement;\n\t\tconst newContent =\n\t\t\tbaseContent.substring(0, matchResult.index) +\n\t\t\tnormalizedNewText +\n\t\t\tbaseContent.substring(matchResult.index + matchResult.matchLength);\n\n\t\t// Check if it would actually change anything\n\t\tif (baseContent === newContent) {\n\t\t\treturn {\n\t\t\t\terror: `No changes would be made to ${path}. The replacement produces identical content.`,\n\t\t\t};\n\t\t}\n\n\t\t// Generate the diff\n\t\treturn generateDiffString(baseContent, newContent);\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n"]}
1
+ {"version":3,"file":"edit-diff.js","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,OAAO,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,MAAqB;IACrE,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,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CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;AACF,CAAC","sourcesContent":["/**\n * Shared diff computation utilities for the edit tool.\n * Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).\n *\n * These helpers intentionally stay in JavaScript. Issue #453 showed that\n * post-tool preview paths must not depend on the native addon because a native\n * hang there can wedge the entire interactive session after a successful tool run.\n */\n\nimport { constants } from \"fs\";\nimport { access, readFile } from \"fs/promises\";\nimport { resolveToCwd, UNICODE_SPACES } from \"./path-utils.js\";\n\nexport function detectLineEnding(content: string): \"\\r\\n\" | \"\\n\" {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: \"\\r\\n\" | \"\\n\"): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching.\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn text\n\t\t.replace(/\\r\\n/g, \"\\n\")\n\t\t.replace(/\\r/g, \"\\n\")\n\t\t.replace(/[“”]/g, '\"')\n\t\t.replace(/[‘’]/g, \"'\")\n\t\t.replace(/[‐‑‒–—−]/g, \"-\")\n\t\t.replace(UNICODE_SPACES, \" \")\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.replace(/[ \\t]+$/g, \"\"))\n\t\t.join(\"\\n\");\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/**\n\t * The content to use for replacement operations.\n\t * When exact match: original content. When fuzzy match: normalized content.\n\t */\n\tcontentForReplacement: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n *\n * When fuzzy matching is used, the returned contentForReplacement is the\n * fuzzy-normalized version of the content.\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\tconst normalizedContent = normalizeForFuzzyMatch(content);\n\tconst normalizedOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = normalizedContent.indexOf(normalizedOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: normalizedOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: normalizedContent,\n\t};\n}\n\n/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */\nexport function stripBom(content: string): { bom: string; text: string } {\n\treturn content.startsWith(\"\\uFEFF\") ? { bom: \"\\uFEFF\", text: content.slice(1) } : { bom: \"\", text: content };\n}\n\n/**\n * Generate a unified diff string with line numbers and context.\n *\n * Returns both the diff string and the first changed line number (in the new file).\n * Only lines within `contextLines` of a change are included (like unified diff).\n */\nexport function generateDiffString(\n\toldContent: string,\n\tnewContent: string,\n\tcontextLines = 4,\n): { diff: string; firstChangedLine: number | undefined } {\n\tconst ops = buildLineDiff(oldContent, newContent);\n\tlet firstChangedLine: number | undefined;\n\n\t// First pass: assign line numbers and find changed indices\n\tconst annotated: { op: LineDiffOp; oldLine: number; newLine: number }[] = [];\n\tlet oldLine = 1;\n\tlet newLine = 1;\n\tconst changedIndices: number[] = [];\n\n\tfor (let idx = 0; idx < ops.length; idx++) {\n\t\tconst op = ops[idx];\n\t\tannotated.push({ op, oldLine, newLine });\n\n\t\tif (op.type !== \"context\") {\n\t\t\tchangedIndices.push(idx);\n\t\t\tif (firstChangedLine === undefined) {\n\t\t\t\tfirstChangedLine = newLine;\n\t\t\t}\n\t\t}\n\n\t\tif (op.type === \"remove\") {\n\t\t\toldLine += 1;\n\t\t} else if (op.type === \"add\") {\n\t\t\tnewLine += 1;\n\t\t} else {\n\t\t\toldLine += 1;\n\t\t\tnewLine += 1;\n\t\t}\n\t}\n\n\t// Build set of indices to include (changes + surrounding context)\n\tconst includeSet = new Set<number>();\n\tfor (const ci of changedIndices) {\n\t\tfor (let k = Math.max(0, ci - contextLines); k <= Math.min(ops.length - 1, ci + contextLines); k++) {\n\t\t\tincludeSet.add(k);\n\t\t}\n\t}\n\n\tconst maxLine = Math.max(oldLine - 1, newLine - 1, 1);\n\tconst lineNumberWidth = String(maxLine).length;\n\tconst rendered: string[] = [];\n\tlet lastIncluded = -1;\n\n\tfor (let idx = 0; idx < annotated.length; idx++) {\n\t\tif (!includeSet.has(idx)) continue;\n\n\t\t// Insert separator when there's a gap between included regions\n\t\tif (lastIncluded !== -1 && idx > lastIncluded + 1) {\n\t\t\trendered.push(\"...\");\n\t\t}\n\t\tlastIncluded = idx;\n\n\t\tconst { op, oldLine: ol, newLine: nl } = annotated[idx];\n\t\tif (op.type === \"context\") {\n\t\t\trendered.push(` ${String(nl).padStart(lineNumberWidth, \" \")} ${op.line}`);\n\t\t} else if (op.type === \"remove\") {\n\t\t\trendered.push(`-${String(ol).padStart(lineNumberWidth, \" \")} ${op.line}`);\n\t\t} else {\n\t\t\trendered.push(`+${String(nl).padStart(lineNumberWidth, \" \")} ${op.line}`);\n\t\t}\n\t}\n\n\treturn {\n\t\tdiff: rendered.join(\"\\n\"),\n\t\tfirstChangedLine,\n\t};\n}\n\nexport interface EditDiffResult {\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nexport interface EditDiffError {\n\terror: string;\n}\n\ntype LineDiffOp =\n\t| { type: \"context\"; line: string }\n\t| { type: \"remove\"; line: string }\n\t| { type: \"add\"; line: string };\n\nfunction splitLines(text: string): string[] {\n\tconst lines = text.split(\"\\n\");\n\tif (lines.length > 0 && lines.at(-1) === \"\") {\n\t\tlines.pop();\n\t}\n\treturn lines;\n}\n\n/**\n * Maximum number of cells (oldLines * newLines) before we switch from the\n * full LCS DP algorithm to a simpler linear-scan diff. This prevents OOM\n * on large files (e.g. 10k lines would need a 100M-cell matrix).\n */\nconst MAX_DP_CELLS = 4_000_000; // ~32 MB for 64-bit numbers\n\nfunction buildLineDiff(oldContent: string, newContent: string): LineDiffOp[] {\n\tconst oldLines = splitLines(oldContent);\n\tconst newLines = splitLines(newContent);\n\n\tconst cells = (oldLines.length + 1) * (newLines.length + 1);\n\tif (cells > MAX_DP_CELLS) {\n\t\treturn buildLineDiffLinear(oldLines, newLines);\n\t}\n\n\treturn buildLineDiffLCS(oldLines, newLines);\n}\n\n/**\n * Full LCS-based diff using O(n*m) DP table. Produces optimal diffs but\n * is only safe for files where n*m <= MAX_DP_CELLS.\n */\nfunction buildLineDiffLCS(oldLines: string[], newLines: string[]): LineDiffOp[] {\n\tconst dp: number[][] = Array.from({ length: oldLines.length + 1 }, () =>\n\t\tArray<number>(newLines.length + 1).fill(0),\n\t);\n\n\tfor (let i = oldLines.length - 1; i >= 0; i--) {\n\t\tfor (let j = newLines.length - 1; j >= 0; j--) {\n\t\t\tif (oldLines[i] === newLines[j]) {\n\t\t\t\tdp[i][j] = dp[i + 1][j + 1] + 1;\n\t\t\t} else {\n\t\t\t\tdp[i][j] = Math.max(dp[i + 1][j], dp[i][j + 1]);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst ops: LineDiffOp[] = [];\n\tlet i = 0;\n\tlet j = 0;\n\n\twhile (i < oldLines.length && j < newLines.length) {\n\t\tif (oldLines[i] === newLines[j]) {\n\t\t\tops.push({ type: \"context\", line: oldLines[i] });\n\t\t\ti += 1;\n\t\t\tj += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (dp[i + 1][j] >= dp[i][j + 1]) {\n\t\t\tops.push({ type: \"remove\", line: oldLines[i] });\n\t\t\ti += 1;\n\t\t} else {\n\t\t\tops.push({ type: \"add\", line: newLines[j] });\n\t\t\tj += 1;\n\t\t}\n\t}\n\n\twhile (i < oldLines.length) {\n\t\tops.push({ type: \"remove\", line: oldLines[i] });\n\t\ti += 1;\n\t}\n\n\twhile (j < newLines.length) {\n\t\tops.push({ type: \"add\", line: newLines[j] });\n\t\tj += 1;\n\t}\n\n\treturn ops;\n}\n\n/**\n * Linear-time fallback diff for large files. Matches common prefix/suffix,\n * then treats the remaining middle as a bulk remove+add. Not optimal but\n * O(n+m) in both time and space.\n */\nfunction buildLineDiffLinear(oldLines: string[], newLines: string[]): LineDiffOp[] {\n\tconst ops: LineDiffOp[] = [];\n\n\t// Match common prefix\n\tlet prefixLen = 0;\n\tconst minLen = Math.min(oldLines.length, newLines.length);\n\twhile (prefixLen < minLen && oldLines[prefixLen] === newLines[prefixLen]) {\n\t\tprefixLen++;\n\t}\n\n\t// Match common suffix (not overlapping with prefix)\n\tlet suffixLen = 0;\n\twhile (\n\t\tsuffixLen < minLen - prefixLen &&\n\t\toldLines[oldLines.length - 1 - suffixLen] === newLines[newLines.length - 1 - suffixLen]\n\t) {\n\t\tsuffixLen++;\n\t}\n\n\t// Emit prefix context\n\tfor (let i = 0; i < prefixLen; i++) {\n\t\tops.push({ type: \"context\", line: oldLines[i] });\n\t}\n\n\t// Emit removed lines from the middle\n\tfor (let i = prefixLen; i < oldLines.length - suffixLen; i++) {\n\t\tops.push({ type: \"remove\", line: oldLines[i] });\n\t}\n\n\t// Emit added lines from the middle\n\tfor (let j = prefixLen; j < newLines.length - suffixLen; j++) {\n\t\tops.push({ type: \"add\", line: newLines[j] });\n\t}\n\n\t// Emit suffix context\n\tfor (let i = oldLines.length - suffixLen; i < oldLines.length; i++) {\n\t\tops.push({ type: \"context\", line: oldLines[i] });\n\t}\n\n\treturn ops;\n}\n\n/**\n * Compute the diff for a write operation without applying it.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeWriteDiff(\n\tpath: string,\n\tnewContent: string,\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, cwd);\n\n\ttry {\n\t\tlet oldContent = \"\";\n\t\ttry {\n\t\t\tawait access(absolutePath, constants.R_OK);\n\t\t\toldContent = await readFile(absolutePath, \"utf-8\");\n\t\t} catch {\n\t\t\toldContent = \"\";\n\t\t}\n\n\t\treturn generateDiffString(normalizeToLF(stripBom(oldContent).text), normalizeToLF(newContent));\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n\n/**\n * Compute the diff for an edit operation without applying it.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeEditDiff(\n\tpath: string,\n\toldText: string,\n\tnewText: string,\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, cwd);\n\n\ttry {\n\t\t// Check if file exists and is readable\n\t\ttry {\n\t\t\tawait access(absolutePath, constants.R_OK);\n\t\t} catch {\n\t\t\treturn { error: `File not found: ${path}` };\n\t\t}\n\n\t\t// Read the file\n\t\tconst rawContent = await readFile(absolutePath, \"utf-8\");\n\n\t\t// Strip BOM before matching (LLM won't include invisible BOM in oldText)\n\t\tconst { text: content } = stripBom(rawContent);\n\n\t\tconst normalizedContent = normalizeToLF(content);\n\t\tconst normalizedOldText = normalizeToLF(oldText);\n\t\tconst normalizedNewText = normalizeToLF(newText);\n\n\t\t// Find the old text using fuzzy matching (tries exact match first, then fuzzy)\n\t\tconst matchResult = fuzzyFindText(normalizedContent, normalizedOldText);\n\n\t\tif (!matchResult.found) {\n\t\t\treturn {\n\t\t\t\terror: `Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,\n\t\t\t};\n\t\t}\n\n\t\t// Count occurrences using fuzzy-normalized content for consistency\n\t\tconst fuzzyContent = normalizeForFuzzyMatch(normalizedContent);\n\t\tconst fuzzyOldText = normalizeForFuzzyMatch(normalizedOldText);\n\t\tconst occurrences = fuzzyContent.split(fuzzyOldText).length - 1;\n\n\t\tif (occurrences > 1) {\n\t\t\treturn {\n\t\t\t\terror: `Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t\t};\n\t\t}\n\n\t\t// Compute the new content using the matched position\n\t\t// When fuzzy matching was used, contentForReplacement is the normalized version\n\t\tconst baseContent = matchResult.contentForReplacement;\n\t\tconst newContent =\n\t\t\tbaseContent.substring(0, matchResult.index) +\n\t\t\tnormalizedNewText +\n\t\t\tbaseContent.substring(matchResult.index + matchResult.matchLength);\n\n\t\t// Check if it would actually change anything\n\t\tif (baseContent === newContent) {\n\t\t\treturn {\n\t\t\t\terror: `No changes would be made to ${path}. The replacement produces identical content.`,\n\t\t\t};\n\t\t}\n\n\t\t// Generate the diff\n\t\treturn generateDiffString(baseContent, newContent);\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n"]}
@@ -3,7 +3,7 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { describe, it } from "node:test";
6
- import { computeEditDiff, fuzzyFindText, generateDiffString, normalizeForFuzzyMatch, } from "./edit-diff.js";
6
+ import { computeEditDiff, computeWriteDiff, fuzzyFindText, generateDiffString, normalizeForFuzzyMatch, } from "./edit-diff.js";
7
7
  describe("edit-diff", () => {
8
8
  it("normalizes quotes, dashes, spaces, and trailing whitespace", () => {
9
9
  const input = "“hello”\u00A0world — test \nnext\t\t\n";
@@ -47,6 +47,21 @@ describe("edit-diff", () => {
47
47
  assert.ok(result.firstChangedLine !== undefined);
48
48
  assert.match(result.diff, /CHANGED/);
49
49
  });
50
+ it("computes diffs for write preview against existing files", async (t) => {
51
+ const dir = mkdtempSync(join(tmpdir(), "write-diff-test-"));
52
+ t.after(() => {
53
+ rmSync(dir, { recursive: true, force: true });
54
+ });
55
+ const file = join(dir, "sample.ts");
56
+ writeFileSync(file, "const title = \"Hello\";\n", "utf-8");
57
+ const result = await computeWriteDiff(file, "const title = \"Hi\";\n", dir);
58
+ assert.ok(!("error" in result), "expected a diff result");
59
+ if (!("error" in result)) {
60
+ assert.equal(result.firstChangedLine, 1);
61
+ assert.match(result.diff, /-1 const title = "Hello";/);
62
+ assert.match(result.diff, /\+1 const title = "Hi";/);
63
+ }
64
+ });
50
65
  it("computes diffs for preview without native helpers", async (t) => {
51
66
  const dir = mkdtempSync(join(tmpdir(), "edit-diff-test-"));
52
67
  t.after(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"edit-diff.test.js","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EACN,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AAExB,QAAQ,CAAC,WAAW,EAAE,GAAG,EA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CAAC,MAAM,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC;QACjD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACnE,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC;QAC3D,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACZ,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QACpC,aAAa,CAAC,IAAI,EAAE,0BAA0B,EAAE,OAAO,CAAC,CAAC;QAEzD,MAAM,MAAM,GAAG,MAAM,eAAe,CACnC,IAAI,EACJ,4BAA4B,EAC5B,yBAAyB,EACzB,GAAG,CACH,CAAC;QAEF,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,EAAE,wBAAwB,CAAC,CAAC;QAC1D,IAAI,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,EAAE,CAAC;YAC1B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;YACzC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;QACtD,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { describe, it } from \"node:test\";\n\nimport {\n\tcomputeEditDiff,\n\tfuzzyFindText,\n\tgenerateDiffString,\n\tnormalizeForFuzzyMatch,\n} from \"./edit-diff.js\";\n\ndescribe(\"edit-diff\", () => {\n\tit(\"normalizes quotes, dashes, spaces, and trailing whitespace\", () => {\n\t\tconst input = \"“hello”\\u00A0world — test \\nnext\\t\\t\\n\";\n\t\tassert.equal(normalizeForFuzzyMatch(input), \"\\\"hello\\\" world - test\\nnext\\n\");\n\t});\n\n\tit(\"falls back to fuzzy matching when unicode punctuation differs\", () => {\n\t\tconst result = fuzzyFindText(\"const title = “Hello”;\\n\", \"const title = \\\"Hello\\\";\\n\");\n\t\tassert.equal(result.found, true);\n\t\tassert.equal(result.usedFuzzyMatch, true);\n\t\tassert.equal(result.contentForReplacement, \"const title = \\\"Hello\\\";\\n\");\n\t});\n\n\tit(\"renders numbered diffs with the first changed line\", () => {\n\t\tconst result = generateDiffString(\"line 1\\nline 2\\nline 3\\n\", \"line 1\\nline two\\nline 3\\n\");\n\t\tassert.equal(result.firstChangedLine, 2);\n\t\tassert.match(result.diff, /-2 line 2/);\n\t\tassert.match(result.diff, /\\+2 line two/);\n\t});\n\n\tit(\"respects contextLines and inserts separators for distant changes\", () => {\n\t\tconst lines = Array.from({ length: 20 }, (_, i) => `line ${i + 1}`);\n\t\tconst oldContent = lines.join(\"\\n\") + \"\\n\";\n\t\tconst modified = [...lines];\n\t\tmodified[1] = \"changed 2\"; // line 2\n\t\tmodified[17] = \"changed 18\"; // line 18\n\t\tconst newContent = modified.join(\"\\n\") + \"\\n\";\n\n\t\tconst result = generateDiffString(oldContent, newContent, 2);\n\t\t// Should contain separator between the two distant change regions\n\t\tassert.match(result.diff, /\\.\\.\\./);\n\t\t// Should NOT contain lines far from changes (e.g. line 10)\n\t\tassert.doesNotMatch(result.diff, /line 10/);\n\t\t// Should contain the changed lines\n\t\tassert.match(result.diff, /changed 2/);\n\t\tassert.match(result.diff, /changed 18/);\n\t});\n\n\tit(\"handles large files without OOM by falling back to linear diff\", () => {\n\t\t// Create files large enough to exceed the DP threshold\n\t\tconst lineCount = 3000;\n\t\tconst oldLines = Array.from({ length: lineCount }, (_, i) => `line ${i}`);\n\t\tconst newLines = [...oldLines];\n\t\tnewLines[1500] = \"CHANGED\";\n\t\tconst result = generateDiffString(oldLines.join(\"\\n\") + \"\\n\", newLines.join(\"\\n\") + \"\\n\");\n\t\tassert.ok(result.firstChangedLine !== undefined);\n\t\tassert.match(result.diff, /CHANGED/);\n\t});\n\n\tit(\"computes diffs for preview without native helpers\", async (t) => {\n\t\tconst dir = mkdtempSync(join(tmpdir(), \"edit-diff-test-\"));\n\t\tt.after(() => {\n\t\t\trmSync(dir, { recursive: true, force: true });\n\t\t});\n\n\t\tconst file = join(dir, \"sample.ts\");\n\t\twriteFileSync(file, \"const title = “Hello”;\\n\", \"utf-8\");\n\n\t\tconst result = await computeEditDiff(\n\t\t\tfile,\n\t\t\t\"const title = \\\"Hello\\\";\\n\",\n\t\t\t\"const title = \\\"Hi\\\";\\n\",\n\t\t\tdir,\n\t\t);\n\n\t\tassert.ok(!(\"error\" in result), \"expected a diff result\");\n\t\tif (!(\"error\" in result)) {\n\t\t\tassert.equal(result.firstChangedLine, 1);\n\t\t\tassert.match(result.diff, /\\+1 const title = \"Hi\";/);\n\t\t}\n\t});\n});\n"]}
1
+ {"version":3,"file":"edit-diff.test.js","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EACN,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,gBAAgB,CA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AAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC;QAC3D,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACZ,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QACpC,aAAa,CAAC,IAAI,EAAE,0BAA0B,EAAE,OAAO,CAAC,CAAC;QAEzD,MAAM,MAAM,GAAG,MAAM,eAAe,CACnC,IAAI,EACJ,4BAA4B,EAC5B,yBAAyB,EACzB,GAAG,CACH,CAAC;QAEF,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,EAAE,wBAAwB,CAAC,CAAC;QAC1D,IAAI,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,EAAE,CAAC;YAC1B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;YACzC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;QACtD,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { describe, it } from \"node:test\";\n\nimport {\n\tcomputeEditDiff,\n\tcomputeWriteDiff,\n\tfuzzyFindText,\n\tgenerateDiffString,\n\tnormalizeForFuzzyMatch,\n} from \"./edit-diff.js\";\n\ndescribe(\"edit-diff\", () => {\n\tit(\"normalizes quotes, dashes, spaces, and trailing whitespace\", () => {\n\t\tconst input = \"“hello”\\u00A0world — test \\nnext\\t\\t\\n\";\n\t\tassert.equal(normalizeForFuzzyMatch(input), \"\\\"hello\\\" world - test\\nnext\\n\");\n\t});\n\n\tit(\"falls back to fuzzy matching when unicode punctuation differs\", () => {\n\t\tconst result = fuzzyFindText(\"const title = “Hello”;\\n\", \"const title = \\\"Hello\\\";\\n\");\n\t\tassert.equal(result.found, true);\n\t\tassert.equal(result.usedFuzzyMatch, true);\n\t\tassert.equal(result.contentForReplacement, \"const title = \\\"Hello\\\";\\n\");\n\t});\n\n\tit(\"renders numbered diffs with the first changed line\", () => {\n\t\tconst result = generateDiffString(\"line 1\\nline 2\\nline 3\\n\", \"line 1\\nline two\\nline 3\\n\");\n\t\tassert.equal(result.firstChangedLine, 2);\n\t\tassert.match(result.diff, /-2 line 2/);\n\t\tassert.match(result.diff, /\\+2 line two/);\n\t});\n\n\tit(\"respects contextLines and inserts separators for distant changes\", () => {\n\t\tconst lines = Array.from({ length: 20 }, (_, i) => `line ${i + 1}`);\n\t\tconst oldContent = lines.join(\"\\n\") + \"\\n\";\n\t\tconst modified = [...lines];\n\t\tmodified[1] = \"changed 2\"; // line 2\n\t\tmodified[17] = \"changed 18\"; // line 18\n\t\tconst newContent = modified.join(\"\\n\") + \"\\n\";\n\n\t\tconst result = generateDiffString(oldContent, newContent, 2);\n\t\t// Should contain separator between the two distant change regions\n\t\tassert.match(result.diff, /\\.\\.\\./);\n\t\t// Should NOT contain lines far from changes (e.g. line 10)\n\t\tassert.doesNotMatch(result.diff, /line 10/);\n\t\t// Should contain the changed lines\n\t\tassert.match(result.diff, /changed 2/);\n\t\tassert.match(result.diff, /changed 18/);\n\t});\n\n\tit(\"handles large files without OOM by falling back to linear diff\", () => {\n\t\t// Create files large enough to exceed the DP threshold\n\t\tconst lineCount = 3000;\n\t\tconst oldLines = Array.from({ length: lineCount }, (_, i) => `line ${i}`);\n\t\tconst newLines = [...oldLines];\n\t\tnewLines[1500] = \"CHANGED\";\n\t\tconst result = generateDiffString(oldLines.join(\"\\n\") + \"\\n\", newLines.join(\"\\n\") + \"\\n\");\n\t\tassert.ok(result.firstChangedLine !== undefined);\n\t\tassert.match(result.diff, /CHANGED/);\n\t});\n\n\tit(\"computes diffs for write preview against existing files\", async (t) => {\n\t\tconst dir = mkdtempSync(join(tmpdir(), \"write-diff-test-\"));\n\t\tt.after(() => {\n\t\t\trmSync(dir, { recursive: true, force: true });\n\t\t});\n\n\t\tconst file = join(dir, \"sample.ts\");\n\t\twriteFileSync(file, \"const title = \\\"Hello\\\";\\n\", \"utf-8\");\n\n\t\tconst result = await computeWriteDiff(file, \"const title = \\\"Hi\\\";\\n\", dir);\n\n\t\tassert.ok(!(\"error\" in result), \"expected a diff result\");\n\t\tif (!(\"error\" in result)) {\n\t\t\tassert.equal(result.firstChangedLine, 1);\n\t\t\tassert.match(result.diff, /-1 const title = \"Hello\";/);\n\t\t\tassert.match(result.diff, /\\+1 const title = \"Hi\";/);\n\t\t}\n\t});\n\n\tit(\"computes diffs for preview without native helpers\", async (t) => {\n\t\tconst dir = mkdtempSync(join(tmpdir(), \"edit-diff-test-\"));\n\t\tt.after(() => {\n\t\t\trmSync(dir, { recursive: true, force: true });\n\t\t});\n\n\t\tconst file = join(dir, \"sample.ts\");\n\t\twriteFileSync(file, \"const title = “Hello”;\\n\", \"utf-8\");\n\n\t\tconst result = await computeEditDiff(\n\t\t\tfile,\n\t\t\t\"const title = \\\"Hello\\\";\\n\",\n\t\t\t\"const title = \\\"Hi\\\";\\n\",\n\t\t\tdir,\n\t\t);\n\n\t\tassert.ok(!(\"error\" in result), \"expected a diff result\");\n\t\tif (!(\"error\" in result)) {\n\t\t\tassert.equal(result.firstChangedLine, 1);\n\t\t\tassert.match(result.diff, /\\+1 const title = \"Hi\";/);\n\t\t}\n\t});\n});\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tool-summary-line.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-summary-line.test.d.ts","sourceRoot":"","sources":["../../../../../src/modes/interactive/components/__tests__/tool-summary-line.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import stripAnsi from "strip-ansi";
4
+ import { ToolSummaryLine } from "../tool-summary-line.js";
5
+ import { initTheme } from "../../theme/theme.js";
6
+ initTheme("dark");
7
+ describe("ToolSummaryLine", () => {
8
+ it("renders action-based summaries for grouped identical tools", () => {
9
+ const summary = new ToolSummaryLine();
10
+ summary.addTool("read", 600);
11
+ summary.addTool("read", 150);
12
+ const rendered = stripAnsi(summary.render(160).join("\n"));
13
+ assert.match(rendered, /^ ● /);
14
+ assert.ok(rendered.includes("reading 2 files · 0.8s"));
15
+ assert.equal(summary.canGroupWith("read"), true);
16
+ assert.equal(summary.canGroupWith("find"), false);
17
+ assert.equal(rendered.includes("collapsed tools"), false);
18
+ assert.equal(rendered.includes("⎯"), false);
19
+ });
20
+ it("keeps fallback format for unknown tools", () => {
21
+ const summary = new ToolSummaryLine();
22
+ summary.addTool("custom_tool", 100);
23
+ const rendered = stripAnsi(summary.render(160).join("\n"));
24
+ assert.ok(rendered.includes("custom_tool · 0.1s"));
25
+ });
26
+ it("renders nothing when empty or hidden", () => {
27
+ const summary = new ToolSummaryLine();
28
+ assert.deepEqual(summary.render(80), []);
29
+ summary.addTool("grep", 100);
30
+ summary.setHidden(true);
31
+ assert.deepEqual(summary.render(80), []);
32
+ });
33
+ });
34
+ //# sourceMappingURL=tool-summary-line.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-summary-line.test.js","sourceRoot":"","sources":["../../../../../src/modes/interactive/components/__tests__/tool-summary-line.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB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QAC3D,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC/C,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;QACtC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAEzC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7B,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it } from \"node:test\";\nimport assert from \"node:assert/strict\";\nimport stripAnsi from \"strip-ansi\";\n\nimport { ToolSummaryLine } from \"../tool-summary-line.js\";\nimport { initTheme } from \"../../theme/theme.js\";\n\ninitTheme(\"dark\");\n\ndescribe(\"ToolSummaryLine\", () => {\n\tit(\"renders action-based summaries for grouped identical tools\", () => {\n\t\tconst summary = new ToolSummaryLine();\n\t\tsummary.addTool(\"read\", 600);\n\t\tsummary.addTool(\"read\", 150);\n\n\t\tconst rendered = stripAnsi(summary.render(160).join(\"\\n\"));\n\t\tassert.match(rendered, /^ ● /);\n\t\tassert.ok(rendered.includes(\"reading 2 files · 0.8s\"));\n\t\tassert.equal(summary.canGroupWith(\"read\"), true);\n\t\tassert.equal(summary.canGroupWith(\"find\"), false);\n\t\tassert.equal(rendered.includes(\"collapsed tools\"), false);\n\t\tassert.equal(rendered.includes(\"⎯\"), false);\n\t});\n\n\tit(\"keeps fallback format for unknown tools\", () => {\n\t\tconst summary = new ToolSummaryLine();\n\t\tsummary.addTool(\"custom_tool\", 100);\n\n\t\tconst rendered = stripAnsi(summary.render(160).join(\"\\n\"));\n\t\tassert.ok(rendered.includes(\"custom_tool · 0.1s\"));\n\t});\n\n\tit(\"renders nothing when empty or hidden\", () => {\n\t\tconst summary = new ToolSummaryLine();\n\t\tassert.deepEqual(summary.render(80), []);\n\n\t\tsummary.addTool(\"grep\", 100);\n\t\tsummary.setHidden(true);\n\t\tassert.deepEqual(summary.render(80), []);\n\t});\n});\n"]}
@@ -0,0 +1,45 @@
1
+ import type { Message, Model, SimpleStreamOptions } from "@gsd/pi-ai";
2
+ import { streamSimple } from "@gsd/pi-ai";
3
+ import { type MarkdownTheme, type Component, type Focusable, type TUI } from "@gsd/pi-tui";
4
+ export declare class BtwOverlayComponent implements Component, Focusable {
5
+ private _focused;
6
+ private readonly markdownTheme;
7
+ private readonly model;
8
+ private readonly systemPrompt;
9
+ private readonly baseMessages;
10
+ private readonly ui;
11
+ private readonly input;
12
+ private readonly onDismiss;
13
+ private readonly requestRender;
14
+ private readonly streamFn;
15
+ private readonly streamOptions;
16
+ private readonly btwHistory;
17
+ private readonly turns;
18
+ private currentAbortController;
19
+ private disposed;
20
+ private isStreaming;
21
+ private scrollOffset;
22
+ private followTail;
23
+ private lastWidth;
24
+ get focused(): boolean;
25
+ set focused(value: boolean);
26
+ constructor(question: string, model: Model<any>, systemPrompt: string | undefined, messages: Message[], markdownTheme: MarkdownTheme, ui: TUI, onDismiss: () => void, requestRender: () => void, streamer?: typeof streamSimple, streamOptions?: Pick<SimpleStreamOptions, "apiKey" | "sessionId">);
27
+ handleInput(data: string): void;
28
+ invalidate(): void;
29
+ dispose(): void;
30
+ render(width: number): string[];
31
+ private dismiss;
32
+ private submitTurn;
33
+ private finishAssistantTurn;
34
+ private createUserMessage;
35
+ private getTotalHeight;
36
+ private getBodyHeight;
37
+ private scrollBy;
38
+ private getBodyLines;
39
+ private renderTurnContent;
40
+ private renderTopBorder;
41
+ private renderBottomBorder;
42
+ private renderBodyLine;
43
+ private renderFooterLine;
44
+ }
45
+ //# sourceMappingURL=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