pi-agent-ide 0.6.4 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (431) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +2 -2
  3. package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
  4. package/dist/chunk-2TRHFMCZ.js +11 -0
  5. package/dist/{chunk-WJTHY6AG.js → chunk-4GCWGE2C.js} +1 -1
  6. package/dist/chunk-4XMY4H4V.js +1 -0
  7. package/dist/{chunk-BSICWXMH.js → chunk-64M3SQPG.js} +1 -1
  8. package/dist/{chunk-QEJGED4V.js → chunk-76ZK5ODR.js} +2 -2
  9. package/dist/{chunk-3BBJZSMS.js → chunk-7LD2OQH3.js} +1 -1
  10. package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
  11. package/dist/chunk-CWD4O5PM.js +3 -0
  12. package/dist/chunk-D3WTDA6V.js +2 -0
  13. package/dist/chunk-EAZGN5ND.js +7 -0
  14. package/dist/chunk-GXEGY7GV.js +1 -0
  15. package/dist/chunk-HZEY4GT4.js +2 -0
  16. package/dist/chunk-LEEQIQ7D.js +28 -0
  17. package/dist/chunk-NRZO5KJT.js +9 -0
  18. package/dist/chunk-OMVRLWMX.js +5 -0
  19. package/dist/{chunk-VBICI5YA.js → chunk-PGIVHICI.js} +1 -1
  20. package/dist/{chunk-FBOW7XOV.js → chunk-PKKDDIWW.js} +1 -1
  21. package/dist/chunk-PNU3E7IO.js +3 -0
  22. package/dist/chunk-PS2B6THP.js +3 -0
  23. package/dist/{chunk-FUG2TEKI.js → chunk-QFTBY67N.js} +2 -2
  24. package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
  25. package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
  26. package/dist/chunk-VMTR74FF.js +2 -0
  27. package/dist/{chunk-HPUAIWIH.js → chunk-WMO6RNE2.js} +1 -1
  28. package/dist/chunk-WU6ZK6YD.js +1 -0
  29. package/dist/{chunk-GIRAEVUJ.js → chunk-XH5WN5XA.js} +1 -1
  30. package/dist/chunk-XYS4FSCC.js +12 -0
  31. package/dist/chunk-YP46DVVP.js +2 -0
  32. package/dist/entry-11.js +1 -1
  33. package/dist/entry-13.js +1 -1
  34. package/dist/entry-14.js +1 -1
  35. package/dist/entry-15.js +1 -1
  36. package/dist/entry-17.js +1 -1
  37. package/dist/entry-25.js +2 -2
  38. package/dist/entry-26.js +1 -1
  39. package/dist/entry-27.js +2 -2
  40. package/dist/entry-28.js +1 -1
  41. package/dist/entry-29.js +1 -1
  42. package/dist/entry-30.js +1 -1
  43. package/dist/entry-31.js +12 -9
  44. package/dist/entry-33.js +1 -1
  45. package/dist/entry-37.js +6 -6
  46. package/dist/entry-41.js +1 -1
  47. package/dist/entry-42.js +1 -1
  48. package/dist/entry-43.js +1 -1
  49. package/dist/entry-44.js +1 -1
  50. package/dist/entry-45.js +13 -14
  51. package/dist/entry-46.js +1 -1
  52. package/dist/entry-49.js +1 -1
  53. package/dist/entry-50.js +3 -6
  54. package/dist/entry-51.js +11 -9
  55. package/dist/entry-52.js +1 -1
  56. package/dist/entry-53.js +1 -1
  57. package/dist/entry-54.js +1 -1
  58. package/dist/entry-56.js +1 -1
  59. package/dist/entry-57.js +1 -1
  60. package/dist/entry-58.js +1 -1
  61. package/dist/entry-60.js +1 -1
  62. package/dist/entry-61.js +0 -1
  63. package/dist/entry-62.js +1 -0
  64. package/dist/entry-63.js +0 -1
  65. package/dist/entry-64.js +1 -0
  66. package/dist/entry-65.js +1 -1
  67. package/dist/entry-66.js +1 -1
  68. package/dist/entry-67.js +1 -1
  69. package/dist/entry-68.js +1 -1
  70. package/dist/entry-69.js +1 -1
  71. package/dist/entry-70.js +1 -1
  72. package/dist/entry-71.js +0 -1
  73. package/dist/entry-72.js +1 -0
  74. package/dist/entry-73.js +0 -1
  75. package/dist/entry-74.js +1 -0
  76. package/dist/entry-75.js +1 -1
  77. package/dist/entry-76.js +1 -1
  78. package/dist/entry-77.js +66 -1
  79. package/dist/entry-78.js +14 -325
  80. package/dist/entry-79.js +2 -18
  81. package/dist/entry-80.js +1 -2
  82. package/dist/entry-81.js +1 -1
  83. package/dist/entry-82.js +5 -1
  84. package/dist/entry-83.js +3 -5
  85. package/dist/entry-84.js +1 -3
  86. package/dist/entry-85.js +1 -1
  87. package/dist/entry-86.js +1 -1
  88. package/dist/pi-agent-ide.js +14 -9
  89. package/docs/agent-guides/editing.md +38 -33
  90. package/docs/agent-guides/git-changes.md +1 -1
  91. package/docs/agent-guides/read-resources.md +8 -4
  92. package/docs/agent-guides/search-code.md +34 -2
  93. package/docs/agent-guides/select-code.md +115 -0
  94. package/docs/configuration.md +12 -17
  95. package/docs/development.md +2 -1
  96. package/docs/releases.md +1 -1
  97. package/docs/research/apply-native-capability-matrix.md +174 -0
  98. package/docs/research/apply-read-latency.md +2 -0
  99. package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
  100. package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
  101. package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
  102. package/docs/research/native-codemode-batch-decision.md +2 -0
  103. package/docs/research/native-codemode-batching.md +1 -1
  104. package/docs/structured-results.md +30 -38
  105. package/docs/tools.md +11 -11
  106. package/docs/user-hooks.md +1 -1
  107. package/node_modules/pi-agent-doctor/package.json +1 -1
  108. package/node_modules/pi-agent-documentation/package.json +1 -1
  109. package/node_modules/pi-agent-filesystem/index.ts +7 -6
  110. package/node_modules/pi-agent-filesystem/package.json +7 -7
  111. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  112. package/node_modules/pi-agent-filesystem-jq/index.ts +4 -3
  113. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  114. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  115. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  116. package/node_modules/pi-agent-ide-ast/package.json +15 -10
  117. package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  118. package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  119. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  120. package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  121. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  122. package/node_modules/pi-agent-ide-ast/src/extension.ts +10 -5
  123. package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  124. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +142 -27
  125. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  126. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
  127. package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
  128. package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
  129. package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
  130. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +268 -0
  131. package/node_modules/pi-agent-ide-changes/index.ts +6 -21
  132. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  133. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  134. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  135. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  136. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  137. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  138. package/node_modules/pi-agent-ide-lsp/index.ts +5 -5
  139. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  140. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  141. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  142. package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  143. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  144. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  145. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
  146. package/node_modules/pi-agent-image/package.json +2 -2
  147. package/node_modules/pi-agent-invariant/package.json +1 -1
  148. package/node_modules/pi-agent-pdf/package.json +2 -2
  149. package/node_modules/pi-agent-read/package.json +7 -7
  150. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  151. package/node_modules/pi-agent-read/src/api/read-parameters.ts +40 -3
  152. package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -1
  153. package/node_modules/pi-agent-read/src/core/extension.ts +18 -1
  154. package/node_modules/pi-agent-read/src/core/read-core.ts +50 -35
  155. package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  156. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
  157. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +17 -3
  158. package/node_modules/pi-agent-resource/package.json +1 -1
  159. package/node_modules/pi-agent-resource/src/index.ts +10 -0
  160. package/node_modules/pi-agent-resource/src/result-targets.ts +407 -0
  161. package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
  162. package/node_modules/pi-agent-search/package.json +5 -5
  163. package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
  164. package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
  165. package/node_modules/pi-agent-search/src/api/search-parameters.ts +9 -3
  166. package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
  167. package/node_modules/pi-agent-search/src/api/search.ts +28 -0
  168. package/node_modules/pi-agent-search/src/api/structured-result.ts +69 -14
  169. package/node_modules/pi-agent-search/src/core/extension.ts +56 -16
  170. package/node_modules/pi-agent-search/src/core/search-core.ts +9 -1
  171. package/node_modules/pi-agent-search-text/index.ts +3 -1
  172. package/node_modules/pi-agent-search-text/package.json +7 -6
  173. package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  174. package/node_modules/pi-agent-search-text/src/resolvers.ts +161 -30
  175. package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
  176. package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -17
  177. package/node_modules/pi-agent-search-text/src/search-renderer.ts +89 -292
  178. package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
  179. package/node_modules/pi-agent-search-text/src/search-session.ts +96 -11
  180. package/node_modules/pi-agent-text/package.json +2 -2
  181. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  182. package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
  183. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  184. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  185. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
  186. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  187. package/node_modules/pi-agent-text-editor/index.ts +0 -5
  188. package/node_modules/pi-agent-text-editor/package.json +26 -31
  189. package/node_modules/pi-agent-text-editor/runtime/entry-77.js +1 -0
  190. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  191. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  192. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  193. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  194. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  195. package/node_modules/pi-agent-text-editor/src/core/extension.ts +22 -5
  196. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  197. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -14
  198. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  199. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  200. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  201. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
  202. package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
  203. package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  204. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  205. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +86 -154
  206. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  207. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  208. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
  209. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  210. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
  211. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  212. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  213. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  214. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  215. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  216. package/node_modules/pi-agent-text-editor-renderer/index.ts +1 -72
  217. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  218. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  219. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  220. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  221. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  222. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
  223. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  224. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  225. package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
  226. package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
  227. package/node_modules/pi-agent-web/index.ts +7 -3
  228. package/node_modules/pi-agent-web/package.json +8 -8
  229. package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
  230. package/node_modules/pi-agent-web/src/search.ts +111 -2
  231. package/node_modules/pi-agent-web-html/package.json +3 -3
  232. package/node_modules/pi-agent-web-image/package.json +4 -4
  233. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  234. package/node_modules/pi-agent-web-text/package.json +4 -4
  235. package/package.json +35 -36
  236. package/src/composite/module-labels.ts +1 -1
  237. package/src/composite/preferences.ts +0 -5
  238. package/src/composite/text-results.ts +221 -0
  239. package/src/documentation/extension.ts +11 -9
  240. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
  241. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  242. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  243. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +4 -3
  244. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  245. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  246. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  247. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +7 -3
  248. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
  249. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  250. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +2 -0
  251. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  252. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  253. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  254. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +2 -0
  255. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +111 -2
  256. package/src/extensions/pi-agent-read/package.json +7 -7
  257. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  258. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +40 -3
  259. package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -1
  260. package/src/extensions/pi-agent-read/src/core/extension.ts +18 -1
  261. package/src/extensions/pi-agent-read/src/core/read-core.ts +50 -35
  262. package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  263. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
  264. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +17 -3
  265. package/src/extensions/pi-agent-search/package.json +5 -5
  266. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -1
  267. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
  268. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  269. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +161 -30
  270. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
  271. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -17
  272. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +89 -292
  273. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
  274. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +96 -11
  275. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
  276. package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
  277. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +9 -3
  278. package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
  279. package/src/extensions/pi-agent-search/src/api/search.ts +28 -0
  280. package/src/extensions/pi-agent-search/src/api/structured-result.ts +69 -14
  281. package/src/extensions/pi-agent-search/src/core/extension.ts +56 -16
  282. package/src/extensions/pi-agent-search/src/core/search-core.ts +9 -1
  283. package/src/extensions/pi-agent-text-editor/index.ts +0 -5
  284. package/src/extensions/pi-agent-text-editor/package.json +26 -31
  285. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  286. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
  287. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  288. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  289. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
  290. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  291. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +1 -72
  292. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  293. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +2 -0
  294. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  295. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  296. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  297. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +1 -0
  298. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  299. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  300. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  301. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  302. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  303. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +22 -5
  304. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  305. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -14
  306. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  307. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  308. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  309. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
  310. package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
  311. package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  312. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  313. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +86 -154
  314. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  315. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  316. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
  317. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  318. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
  319. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  320. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  321. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  322. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  323. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  324. package/src/pi-agent-ide.ts +4 -7
  325. package/src/plugins/pi-agent-ide-ast/package.json +15 -10
  326. package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  327. package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  328. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  329. package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  330. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  331. package/src/plugins/pi-agent-ide-ast/src/extension.ts +10 -5
  332. package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  333. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +142 -27
  334. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  335. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
  336. package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
  337. package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
  338. package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
  339. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +268 -0
  340. package/src/plugins/pi-agent-ide-changes/index.ts +6 -21
  341. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  342. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  343. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  344. package/src/plugins/pi-agent-ide-debugger/index.ts +5 -3
  345. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +5 -3
  346. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  347. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  348. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  349. package/src/plugins/pi-agent-ide-lsp/index.ts +5 -5
  350. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  351. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  352. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  353. package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  354. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  355. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  356. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
  357. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
  358. package/src/plugins/pi-agent-ide-terminal/src/search.ts +10 -36
  359. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +1 -1
  360. package/src/plugins/pi-agent-ide-vision/index.ts +31 -4
  361. package/dist/chunk-2P2OGO3G.js +0 -2
  362. package/dist/chunk-5J43L2RL.js +0 -11
  363. package/dist/chunk-6EYWFBNG.js +0 -0
  364. package/dist/chunk-7AVXUV4A.js +0 -7
  365. package/dist/chunk-7WCZOO5I.js +0 -1
  366. package/dist/chunk-BAYETTZZ.js +0 -16
  367. package/dist/chunk-BVK5A7ED.js +0 -28
  368. package/dist/chunk-F7NVAC4Q.js +0 -0
  369. package/dist/chunk-FZBCKIJJ.js +0 -1
  370. package/dist/chunk-I5JLCFUX.js +0 -1
  371. package/dist/chunk-KUPHNMUK.js +0 -2
  372. package/dist/chunk-MIZAFRDR.js +0 -1
  373. package/dist/chunk-PJPA5EEE.js +0 -2
  374. package/dist/chunk-PXWDDBBC.js +0 -0
  375. package/dist/chunk-SILJ3OL4.js +0 -9
  376. package/dist/chunk-TQZBVOTT.js +0 -5
  377. package/dist/chunk-VWW3RLUX.js +0 -12
  378. package/dist/chunk-YHUTTZC6.js +0 -2
  379. package/dist/chunk-ZODCBFBL.js +0 -2
  380. package/dist/entry-87.js +0 -1
  381. package/docs/agent-guides/apply.md +0 -333
  382. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  383. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  384. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  385. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  386. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  387. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  388. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  389. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  390. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  391. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  392. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  393. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  394. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  395. package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  396. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  397. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  398. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  399. package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +0 -1
  400. package/node_modules/pi-agent-web-text/runtime/entry-87.js +0 -2
  401. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +0 -2
  402. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +0 -2
  403. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  404. package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +0 -2
  405. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  406. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  407. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  408. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  409. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  410. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  411. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  412. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  413. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  414. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  415. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  416. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  417. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  418. package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  419. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  420. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  421. /package/node_modules/{pi-agent-text-editor → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
  422. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
  423. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-81.js +0 -0
  424. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-83.js +0 -0
  425. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  426. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  427. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  428. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  429. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  430. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  431. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
@@ -43,6 +43,7 @@ export async function searchText(
43
43
  request: TextSearchRequest,
44
44
  cwd: string,
45
45
  signal?: AbortSignal,
46
+ budget?: SearchCaptureBudget,
46
47
  ): Promise<TextSearchBackendResult> {
47
48
  if (request.query.length === 0) {
48
49
  throw new Error("Search query must not be empty.");
@@ -53,42 +54,106 @@ export async function searchText(
53
54
  }
54
55
 
55
56
  if (request.condition !== undefined) return searchBoolean(request, cwd, signal);
56
- return searchPattern(request, cwd, signal);
57
+ return searchPattern(request, cwd, signal, undefined, budget);
57
58
  }
58
59
 
60
+ /** Reuse ordinary text-search scope, ignores, and glob parsing for the extra scan. */
61
+ export async function ripgrepScope(request: TextSearchRequest, cwd: string) {
62
+ const target = path.resolve(cwd, stripFilePrefix(request.path ?? "."));
63
+ const directory = (await stat(target)).isDirectory();
64
+ return {
65
+ cwd: directory ? target : path.dirname(target),
66
+ target: directory ? "." : path.basename(target),
67
+ arguments: [
68
+ "--no-config",
69
+ "--no-ignore-parent",
70
+ "--color=never",
71
+ ...splitGlobList(request.include).flatMap((glob) => ["--glob", glob]),
72
+ ...splitGlobList(request.exclude).flatMap((glob) => ["--glob", `!${glob}`]),
73
+ ],
74
+ };
75
+ }
76
+ /** Internal capture bounds for candidate verification; ordinary Search keeps its full capture. */
77
+ export interface SearchCaptureBudget {
78
+ readonly matches: number;
79
+ readonly bytes: number;
80
+ }
59
81
  type MatchingLine = (source: string, lineNumber: number) => void;
60
82
 
83
+ /** Search exactly the supplied source text with the same ripgrep engine as file searches. */
84
+ export async function searchTextContent(
85
+ request: TextSearchRequest,
86
+ content: string,
87
+ cwd: string,
88
+ signal?: AbortSignal,
89
+ ): Promise<TextSearchBackendResult> {
90
+ if (request.condition !== undefined)
91
+ throw new Error("Boolean scoped search is not available yet.");
92
+ if (/\r|\n/u.test(request.query)) throw new Error("Search supports one-line patterns only.");
93
+ const result = await runRipgrep(
94
+ [
95
+ "--json",
96
+ "--no-config",
97
+ "--color=never",
98
+ "--with-filename",
99
+ "--line-number",
100
+ ...(request.regex === true ? ["--engine", "auto"] : ["--fixed-strings"]),
101
+ request.caseSensitive === true ? "--case-sensitive" : "--ignore-case",
102
+ ...(request.wholeWord === true ? ["--word-regexp"] : []),
103
+ "--",
104
+ request.query,
105
+ "-",
106
+ ],
107
+ cwd,
108
+ signal,
109
+ undefined,
110
+ undefined,
111
+ // An empty source still has one position. Ripgrep excludes the record delimiter from matches.
112
+ content.length === 0 ? "\n" : content,
113
+ );
114
+ return content.length === 0
115
+ ? {
116
+ ...result,
117
+ matches: result.matches.filter(
118
+ (match) => match.lineNumber === 1 && match.startColumn === 0 && match.endColumn === 0,
119
+ ),
120
+ }
121
+ : result;
122
+ }
123
+
61
124
  async function searchPattern(
62
125
  request: TextSearchRequest,
63
126
  cwd: string,
64
127
  signal?: AbortSignal,
65
128
  onLine?: MatchingLine,
129
+ budget?: SearchCaptureBudget,
66
130
  ): Promise<TextSearchBackendResult> {
67
- const target = path.resolve(cwd, stripFilePrefix(request.path ?? "."));
68
- const directory = (await stat(target)).isDirectory();
69
- const searchCwd = directory ? target : path.dirname(target);
131
+ const scope = await ripgrepScope(request, cwd);
132
+ const searchCwd = scope.cwd;
70
133
  const commonArguments = [
71
134
  "--json",
72
- "--no-config",
73
- "--no-ignore-parent",
74
- "--color=never",
75
135
  "--with-filename",
76
136
  "--line-number",
77
137
  request.caseSensitive === true ? "--case-sensitive" : "--ignore-case",
78
138
  ...(request.wholeWord === true ? ["--word-regexp"] : []),
79
- ...splitGlobList(request.include).flatMap((glob) => ["--glob", glob]),
80
- ...splitGlobList(request.exclude).flatMap((glob) => ["--glob", `!${glob}`]),
139
+ ...scope.arguments,
81
140
  "--",
82
141
  request.query,
83
- directory ? "." : path.basename(target),
142
+ scope.target,
84
143
  ];
85
144
 
86
145
  if (request.regex !== true) {
87
- return runRipgrep(["--fixed-strings", ...commonArguments], searchCwd, signal, onLine);
146
+ return runRipgrep(["--fixed-strings", ...commonArguments], searchCwd, signal, onLine, budget);
88
147
  }
89
148
 
90
149
  try {
91
- return await runRipgrep(["--engine", "auto", ...commonArguments], searchCwd, signal, onLine);
150
+ return await runRipgrep(
151
+ ["--engine", "auto", ...commonArguments],
152
+ searchCwd,
153
+ signal,
154
+ onLine,
155
+ budget,
156
+ );
92
157
  } catch (error) {
93
158
  if (!isPcre2MatchLimitError(error)) {
94
159
  if (
@@ -108,6 +173,7 @@ async function searchPattern(
108
173
  searchCwd,
109
174
  signal,
110
175
  onLine,
176
+ budget,
111
177
  );
112
178
  } catch (fallbackError) {
113
179
  if (signal?.aborted) throw fallbackError;
@@ -171,13 +237,29 @@ function runRipgrep(
171
237
  cwd: string,
172
238
  signal?: AbortSignal,
173
239
  onLine?: MatchingLine,
240
+ budget?: SearchCaptureBudget,
241
+ input?: string,
174
242
  ): Promise<TextSearchBackendResult> {
175
243
  return new Promise((resolve, reject) => {
176
244
  const child = spawn(resolveRipgrepExecutable(), arguments_, {
177
- stdio: ["ignore", "pipe", "pipe"],
245
+ stdio: ["pipe", "pipe", "pipe"],
178
246
  cwd,
179
247
  });
248
+ let bytes = 0;
249
+ let limited = false;
250
+ if (budget !== undefined)
251
+ child.stdout.on("data", (chunk: Buffer) => {
252
+ bytes += chunk.length;
253
+ if (bytes > budget.bytes) {
254
+ limited = true;
255
+ child.kill();
256
+ }
257
+ });
180
258
  const output = createInterface({ input: child.stdout });
259
+ child.stdin.on("error", () => {
260
+ /* The process close/error event reports failed searches. */
261
+ });
262
+ child.stdin.end(input);
181
263
  const matches: TextSearchMatch[] = [];
182
264
  let stderr = "";
183
265
  let parseError: unknown;
@@ -195,7 +277,7 @@ function runRipgrep(
195
277
  stderr += chunk;
196
278
  });
197
279
  output.on("line", (line) => {
198
- if (parseError !== undefined || line.length === 0) {
280
+ if (limited || parseError !== undefined || line.length === 0) {
199
281
  return;
200
282
  }
201
283
 
@@ -214,6 +296,11 @@ function runRipgrep(
214
296
  return;
215
297
  }
216
298
  for (const match of matchesFromEvent(event as RipgrepMatchEvent, cwd)) {
299
+ if (budget !== undefined && matches.length === budget.matches) {
300
+ limited = true;
301
+ child.kill();
302
+ break;
303
+ }
217
304
  matches.push(match);
218
305
  }
219
306
  } catch (error) {
@@ -240,13 +327,13 @@ function runRipgrep(
240
327
  return;
241
328
  }
242
329
 
243
- if (code !== 0 && code !== 1) {
330
+ if (!limited && code !== 0 && code !== 1) {
244
331
  reject(new Error(stderr.trim() || `ripgrep exited with code ${String(code)}.`));
245
332
  return;
246
333
  }
247
334
 
248
335
  matches.sort(compareMatches);
249
- resolve({ matches, complete: true });
336
+ resolve({ matches, complete: !limited });
250
337
  });
251
338
 
252
339
  signal?.addEventListener("abort", abort, { once: true });
@@ -280,7 +367,7 @@ function matchesFromEvent(event: RipgrepMatchEvent, cwd: string): TextSearchMatc
280
367
  const matches: TextSearchMatch[] = [];
281
368
 
282
369
  for (const submatch of event.data.submatches) {
283
- if (submatch.start < 0 || submatch.end <= submatch.start || submatch.end > lineBuffer.length) {
370
+ if (submatch.start < 0 || submatch.end < submatch.start || submatch.end > lineBuffer.length) {
284
371
  continue;
285
372
  }
286
373
 
@@ -1,6 +1,3 @@
1
- import { requiredValue } from "pi-agent-invariant";
2
- import path from "node:path";
3
-
4
1
  import {
5
2
  type AgentToolResult,
6
3
  keyText,
@@ -8,41 +5,15 @@ import {
8
5
  type ThemeColor,
9
6
  type ToolRenderResultOptions,
10
7
  } from "@earendil-works/pi-coding-agent";
11
- import {
12
- type Component,
13
- Text,
14
- truncateToWidth,
15
- visibleWidth,
16
- wrapTextWithAnsi,
17
- } from "@earendil-works/pi-tui";
18
-
8
+ import { type Component, Text } from "@earendil-works/pi-tui";
9
+ import { ResultPanel, type ResultPanelRow } from "pi-agent-tool-ui";
19
10
  import { isSearchToolDetails } from "#src/search-result.js";
20
-
21
11
  import { restoreSearchDetails } from "#src/persisted-result.js";
22
-
23
12
  const restoredDetails = new WeakMap<object, SearchToolDetails>();
24
13
 
25
14
  import type { SearchResultFile, SearchResultLine, SearchToolDetails } from "#src/search-result.js";
26
15
 
27
16
  const COMPACT_SEARCH_ROWS = 12;
28
- const FULL_LINE_CHARACTERS = 2048;
29
- const PREVIEW_CHARACTERS = 256;
30
-
31
- const FILE_BADGES: Readonly<
32
- Record<string, { readonly label: string; readonly color: ThemeColor }>
33
- > = {
34
- ".ts": { label: "TS", color: "accent" },
35
- ".tsx": { label: "TX", color: "accent" },
36
- ".js": { label: "JS", color: "warning" },
37
- ".jsx": { label: "JX", color: "warning" },
38
- ".json": { label: "{}", color: "warning" },
39
- ".md": { label: "MD", color: "mdHeading" },
40
- ".py": { label: "PY", color: "accent" },
41
- ".rs": { label: "RS", color: "accent" },
42
- ".go": { label: "GO", color: "accent" },
43
- ".css": { label: "CS", color: "accent" },
44
- ".html": { label: "<>", color: "accent" },
45
- };
46
17
 
47
18
  interface SearchRenderContext {
48
19
  readonly lastComponent: Component | undefined;
@@ -50,6 +21,7 @@ interface SearchRenderContext {
50
21
  }
51
22
 
52
23
  type SearchPanelRow =
24
+ | { readonly kind: "candidate"; readonly identifier: string }
53
25
  | { readonly kind: "file"; readonly file: SearchResultFile }
54
26
  | { readonly kind: "line"; readonly file: SearchResultFile; readonly line: SearchResultLine }
55
27
  | { readonly kind: "summary"; readonly text: string }
@@ -83,65 +55,47 @@ export function renderSearchResult(
83
55
  const previous =
84
56
  context.lastComponent instanceof SearchResultPanel ? context.lastComponent : undefined;
85
57
  const panel = previous ?? new SearchResultPanel(result.details, theme, options.expanded);
86
- panel.update(result.details, theme, options.expanded);
58
+ panel.updateSearch(result.details, theme, options.expanded);
87
59
  return panel;
88
60
  }
89
61
 
90
- export class SearchResultPanel implements Component {
91
- private cached: { readonly width: number; readonly lines: string[] } | undefined;
92
-
93
- public constructor(
94
- private details: SearchToolDetails,
95
- private theme: Theme,
96
- private expanded: boolean,
97
- ) {}
98
-
99
- public update(details: SearchToolDetails, theme: Theme, expanded: boolean): void {
100
- if (this.details === details && this.theme === theme && this.expanded === expanded) {
101
- return;
102
- }
103
-
104
- this.details = details;
105
- this.theme = theme;
106
- this.expanded = expanded;
107
- this.invalidate();
108
- }
109
-
110
- public render(width: number): string[] {
111
- if (this.cached?.width === width) {
112
- return this.cached.lines;
113
- }
114
-
115
- if (width < 4) {
116
- const lines = [truncateToWidth(searchSummary(this.details), Math.max(1, width))];
117
- this.cached = { width, lines };
118
- return lines;
119
- }
120
-
121
- const innerWidth = width - 2;
122
- const rows = searchViewport(this.details, this.expanded);
123
- const gutterWidth = maximumLineNumberWidth(this.details.files);
124
- const renderedRows = rows.flatMap((row) =>
125
- renderPanelRow(row, innerWidth, gutterWidth, this.theme),
126
- );
127
- const visibleRows = compactRenderedRows(renderedRows, this.expanded, innerWidth, this.theme);
128
- const lines = [renderTopBorder(this.details, innerWidth, this.theme), ...visibleRows];
129
-
130
- lines.push(this.theme.fg("borderMuted", `╰${"─".repeat(innerWidth)}╯`));
131
- const clipped = lines.map((line) => truncateToWidth(line, width));
132
- this.cached = { width, lines: clipped };
133
- return clipped;
134
- }
135
-
136
- public invalidate(): void {
137
- this.cached = undefined;
138
- }
62
+ /** Adapt Search counts and compacted groups to the shared result frame. */
63
+ export class SearchResultPanel extends ResultPanel {
64
+ public constructor(details: SearchToolDetails, theme: Theme, expanded: boolean) {
65
+ super(searchModel(details, expanded), theme, expanded);
66
+ }
67
+ public updateSearch(details: SearchToolDetails, theme: Theme, expanded: boolean): void {
68
+ super.update(searchModel(details, expanded), theme, expanded);
69
+ }
70
+ }
71
+ function searchModel(details: SearchToolDetails, expanded: boolean) {
72
+ const rows = searchViewport(details, expanded).map((row): ResultPanelRow => {
73
+ if (row.kind === "file")
74
+ return {
75
+ kind: "source",
76
+ label: row.file.path,
77
+ link: row.file.link,
78
+ count: row.file.matchCount,
79
+ };
80
+ if (row.kind === "line") return { kind: "line", ...row.line };
81
+ if (row.kind === "candidate") return { kind: "note", text: row.identifier };
82
+ if (row.kind === "summary") return { kind: "note", text: row.text };
83
+ if (row.kind === "omitted")
84
+ return {
85
+ kind: "note",
86
+ text: `… ${row.matches} more ${plural(row.matches, "match", "matches")} · ${keyText("app.tools.expand")} to expand`,
87
+ };
88
+ return { kind: "note", text: "No matches found" };
89
+ });
90
+ return { summary: searchSummary(details), rows };
139
91
  }
140
-
141
92
  function searchViewport(details: SearchToolDetails, expanded: boolean): readonly SearchPanelRow[] {
142
- const rows =
93
+ const hasCandidates = details.fuzzy?.status === "ready" && details.fuzzy.candidates.length > 0;
94
+ const rows: SearchPanelRow[] =
143
95
  details.files.length === 0
144
- ? [{ kind: "empty" } satisfies SearchPanelRow]
96
+ ? hasCandidates
97
+ ? []
98
+ : [{ kind: "empty" } satisfies SearchPanelRow]
145
99
  : details.files.flatMap((file): SearchPanelRow[] => [
146
100
  { kind: "file", file },
147
101
  ...(file.uniqueLineCount === undefined
@@ -158,7 +112,41 @@ function searchViewport(details: SearchToolDetails, expanded: boolean): readonly
158
112
  ]),
159
113
  ]);
160
114
 
161
- if (expanded || rows.length <= COMPACT_SEARCH_ROWS) {
115
+ if (details.fuzzy !== undefined) {
116
+ if (details.fuzzy.status === "skipped")
117
+ rows.push({
118
+ kind: "summary",
119
+ text: "Fuzzy search unavailable",
120
+ });
121
+ else if (details.fuzzy.candidates.length > 0) {
122
+ rows.push(
123
+ ...details.fuzzy.candidates.flatMap((candidate): SearchPanelRow[] => {
124
+ const files =
125
+ details.fuzzyPresentation?.groups.find(
126
+ (group) => group.identifier === candidate.identifier,
127
+ )?.files ?? [];
128
+ const previewCount = files.reduce((count, file) => count + file.matchCount, 0);
129
+ return [
130
+ { kind: "candidate", identifier: candidate.identifier },
131
+ ...(files.length === 0
132
+ ? []
133
+ : [
134
+ {
135
+ kind: "summary",
136
+ text: `Shown ${String(previewCount)} of ${String(candidate.matchCount)}${candidate.selection.complete ? "" : "+"}`,
137
+ } as const,
138
+ ...files.flatMap((file): SearchPanelRow[] => [
139
+ { kind: "file", file },
140
+ ...file.lines.map((line): SearchPanelRow => ({ kind: "line", file, line })),
141
+ ]),
142
+ ]),
143
+ ];
144
+ }),
145
+ );
146
+ }
147
+ }
148
+
149
+ if (details.fuzzy !== undefined || expanded || rows.length <= COMPACT_SEARCH_ROWS) {
162
150
  return rows;
163
151
  }
164
152
 
@@ -181,147 +169,25 @@ function searchViewport(details: SearchToolDetails, expanded: boolean): readonly
181
169
  ];
182
170
  }
183
171
 
184
- function compactRenderedRows(
185
- rows: readonly string[],
186
- expanded: boolean,
187
- width: number,
188
- theme: Theme,
189
- ): readonly string[] {
190
- if (expanded || rows.length <= COMPACT_SEARCH_ROWS) {
191
- return rows;
192
- }
193
-
194
- const hint = `${keyText("app.tools.expand")} to expand`;
195
- const notice = framed(theme.fg("dim", ` … output truncated · ${hint}`), width, theme);
196
- return [...rows.slice(0, COMPACT_SEARCH_ROWS - 1), notice];
197
- }
198
-
199
- function renderPanelRow(
200
- row: SearchPanelRow,
201
- width: number,
202
- gutterWidth: number,
203
- theme: Theme,
204
- ): readonly string[] {
205
- if (row.kind === "file") {
206
- return [framed(renderFileHeader(row.file, width, theme), width, theme, true)];
207
- }
208
-
209
- if (row.kind === "line") {
210
- return renderMatchLine(row.line, width, gutterWidth, theme);
211
- }
212
-
213
- if (row.kind === "summary") {
214
- return [
215
- framed(
216
- theme.fg(
217
- "dim",
218
- ` ${safeText(row.text.length > FULL_LINE_CHARACTERS ? `${row.text.slice(0, PREVIEW_CHARACTERS)}…` : row.text)}`,
219
- ),
220
- width,
221
- theme,
222
- ),
223
- ];
224
- }
225
-
226
- if (row.kind === "omitted") {
227
- const hint = `${keyText("app.tools.expand")} to expand`;
228
- return [
229
- framed(
230
- theme.fg(
231
- "dim",
232
- ` … ${String(row.matches)} more ${plural(row.matches, "match", "matches")} · ${hint}`,
233
- ),
234
- width,
235
- theme,
236
- ),
237
- ];
238
- }
239
-
240
- return [framed(theme.fg("dim", " No matches found"), width, theme)];
241
- }
242
-
243
- function renderFileHeader(file: SearchResultFile, width: number, theme: Theme): string {
244
- const badge = fileBadge(file.path, theme);
245
- const count = theme.fg("accent", theme.bold(String(file.matchCount)));
246
- const fixedWidth = visibleWidth(badge) + visibleWidth(count) + 4;
247
- const pathWidth = Math.max(1, width - fixedWidth);
248
- const displayedPath = truncatePath(file.path, pathWidth);
249
- const linkedPath = fileLink(displayedPath, file.link, theme);
250
- const left = ` ${badge} ${linkedPath}`;
251
- const gap = " ".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(count) - 1));
252
- return truncateToWidth(`${left}${gap}${count} `, width);
253
- }
254
-
255
- function renderMatchLine(
256
- line: SearchResultLine,
257
- width: number,
258
- gutterWidth: number,
259
- theme: Theme,
260
- ): readonly string[] {
261
- const number = String(line.lineNumber).padStart(gutterWidth);
262
- const gutter = ` ${theme.fg("dim", number)} ${theme.fg("borderMuted", "│")} `;
263
- const contentWidth = Math.max(1, width - visibleWidth(gutter) - 1);
264
- const preview = previewMatchLine(line);
265
- const wrapped = wrapTextWithAnsi(renderHighlightedLine(preview, theme), contentWidth);
266
- const continuationGutter = " ".repeat(visibleWidth(gutter));
267
-
268
- const rows = wrapped.map((content, index) =>
269
- framed(`${index === 0 ? gutter : continuationGutter}${content}`, width, theme),
270
- );
271
- if (preview !== line)
272
- rows.push(
273
- framed(theme.fg("dim", " … line shortened · read file for full text"), width, theme),
172
+ function searchSummary(details: SearchToolDetails): string {
173
+ if (
174
+ details.matchCount === 0 &&
175
+ details.fuzzy?.status === "ready" &&
176
+ details.fuzzy.candidates.length > 0 &&
177
+ details.fuzzyPresentation !== undefined
178
+ ) {
179
+ const count = details.fuzzy.candidates.reduce(
180
+ (total, candidate) => total + candidate.matchCount,
181
+ 0,
274
182
  );
275
- return rows;
276
- }
277
-
278
- // Crop before styling or wrapping so giant source lines never enter terminal layout.
279
- function previewMatchLine(line: SearchResultLine): SearchResultLine {
280
- if (line.text.length <= FULL_LINE_CHARACTERS) return line;
281
- const start = Math.max(0, (line.ranges[0]?.from ?? 0) - 64);
282
- const end = Math.min(line.text.length, start + PREVIEW_CHARACTERS);
283
- const prefix = start > 0 ? "…" : "";
284
- return {
285
- ...line,
286
- text: `${prefix}${line.text.slice(start, end)}${end < line.text.length ? "…" : ""}`,
287
- ranges: line.ranges
288
- .filter((range) => range.from < end && range.to > start)
289
- .map((range) => ({
290
- from: Math.max(range.from, start) - start + prefix.length,
291
- to: Math.min(range.to, end) - start + prefix.length,
292
- })),
293
- };
294
- }
295
- function renderHighlightedLine(line: SearchResultLine, theme: Theme): string {
296
- let result = "";
297
- let offset = 0;
298
-
299
- for (const range of line.ranges) {
300
- if (range.from > offset) {
301
- result += theme.fg("toolOutput", safeText(line.text.slice(offset, range.from)));
302
- }
303
-
304
- const match = safeText(line.text.slice(range.from, range.to));
305
- result += theme.bg("selectedBg", theme.fg("accent", theme.bold(match)));
306
- offset = range.to;
183
+ const suffix = details.fuzzy.candidates.every((candidate) => candidate.selection.complete)
184
+ ? ""
185
+ : "+";
186
+ const files = details.fuzzyPresentation.fileCount;
187
+ return `0 exact · ${String(count)}${suffix} fuzzy ${plural(count, "match", "matches")} · ${String(files)}${suffix} ${plural(files, "file", "files")}`;
307
188
  }
308
-
309
- if (offset < line.text.length) {
310
- result += theme.fg("toolOutput", safeText(line.text.slice(offset)));
311
- }
312
-
313
- return result;
314
- }
315
- function renderTopBorder(details: SearchToolDetails, width: number, theme: Theme): string {
316
- const frame = (text: string): string => theme.fg("borderMuted", text);
317
- const title = truncateToWidth(` ${searchSummary(details)} `, Math.max(0, width - 1), "");
318
- const fill = "─".repeat(Math.max(0, width - visibleWidth(title) - 1));
319
- return `${frame("╭─")}${theme.fg("accent", title)}${frame(`${fill}╮`)}`;
320
- }
321
-
322
- function searchSummary(details: SearchToolDetails): string {
323
189
  if (details.matchCount === 0) {
324
- return "No matches";
190
+ return details.complete ? "No matches" : "No matches · incomplete";
325
191
  }
326
192
 
327
193
  const count = `${String(details.matchCount)}${details.complete ? "" : "+"}`;
@@ -332,75 +198,6 @@ function searchSummary(details: SearchToolDetails): string {
332
198
  )}`;
333
199
  }
334
200
 
335
- function framed(content: string, width: number, theme: Theme, highlighted = false): string {
336
- const clipped = truncateToWidth(content, width);
337
- const body = `${clipped}${" ".repeat(Math.max(0, width - visibleWidth(clipped)))}`;
338
- const renderedBody = highlighted ? theme.bg("selectedBg", body) : body;
339
- const border = theme.fg("borderMuted", "│");
340
- return `${border}${renderedBody}${border}`;
341
- }
342
-
343
- function fileBadge(filePath: string, theme: Theme): string {
344
- const extension = path.extname(filePath).toLowerCase();
345
- const badge =
346
- FILE_BADGES[extension] ??
347
- ({
348
- label: "◇ ",
349
- color: extension.length === 0 ? "muted" : "accent",
350
- } satisfies { readonly label: string; readonly color: ThemeColor });
351
- return theme.fg(badge.color, theme.bold(badge.label));
352
- }
353
-
354
- function fileLink(displayedPath: string, link: string, theme: Theme): string {
355
- const separator = Math.max(displayedPath.lastIndexOf("/"), displayedPath.lastIndexOf("\\"));
356
- const directory = separator === -1 ? "" : displayedPath.slice(0, separator + 1);
357
- const basename = separator === -1 ? displayedPath : displayedPath.slice(separator + 1);
358
- const label = theme.fg("muted", directory) + theme.underline(theme.fg("accent", basename));
359
- return link.includes("\u{7}") || link.includes("\u{1B}")
360
- ? label
361
- : `\u{1B}]8;;${link}\u{7}${label}\u{1B}]8;;\u{7}`;
362
- }
363
-
364
- function truncatePath(filePath: string, width: number): string {
365
- if (visibleWidth(filePath) <= width) {
366
- return filePath;
367
- }
368
-
369
- if (width <= 1) {
370
- return "…";
371
- }
372
-
373
- return `…${filePath.slice(-(width - 1))}`;
374
- }
375
-
376
- function safeText(value: string): string {
377
- let result = "";
378
-
379
- for (const character of value) {
380
- if (character === "\t") {
381
- result += " ".repeat(4);
382
- continue;
383
- }
384
-
385
- const code = requiredValue(character.codePointAt(0));
386
- result += code < 0x20 || code === 0x7f ? "�" : character;
387
- }
388
-
389
- return result;
390
- }
391
-
392
- function maximumLineNumberWidth(files: readonly SearchResultFile[]): number {
393
- let maximum = 1;
394
-
395
- for (const file of files) {
396
- for (const line of file.lines) {
397
- maximum = Math.max(maximum, line.lineNumber);
398
- }
399
- }
400
-
401
- return Math.max(3, String(maximum).length);
402
- }
403
-
404
201
  function plural(count: number, singular: string, pluralForm: string): string {
405
202
  return count === 1 ? singular : pluralForm;
406
203
  }