pi-agent-ide 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (446) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/assets/banner.png +0 -0
  4. package/docs/architecture.md +100 -0
  5. package/docs/configuration.md +104 -0
  6. package/docs/development.md +102 -0
  7. package/docs/evaluation.md +14 -0
  8. package/docs/extensions.md +298 -0
  9. package/docs/tools.md +104 -0
  10. package/node_modules/pi-agent-filesystem/index.ts +60 -0
  11. package/node_modules/pi-agent-filesystem/package.json +23 -0
  12. package/node_modules/pi-agent-filesystem/src/resolver.ts +175 -0
  13. package/node_modules/pi-agent-filesystem-image/index.ts +14 -0
  14. package/node_modules/pi-agent-filesystem-image/package.json +20 -0
  15. package/node_modules/pi-agent-filesystem-pdf/index.ts +14 -0
  16. package/node_modules/pi-agent-filesystem-pdf/package.json +17 -0
  17. package/node_modules/pi-agent-filesystem-text/index.ts +23 -0
  18. package/node_modules/pi-agent-filesystem-text/package.json +20 -0
  19. package/node_modules/pi-agent-ide-ast/index.ts +1 -0
  20. package/node_modules/pi-agent-ide-ast/package.json +39 -0
  21. package/node_modules/pi-agent-ide-ast/src/api/scope.ts +1 -0
  22. package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
  23. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +374 -0
  24. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +813 -0
  25. package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
  26. package/node_modules/pi-agent-ide-ast/src/extension.ts +85 -0
  27. package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
  28. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +221 -0
  29. package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
  30. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +141 -0
  31. package/node_modules/pi-agent-ide-changes/index.ts +68 -0
  32. package/node_modules/pi-agent-ide-changes/package.json +29 -0
  33. package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +103 -0
  34. package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
  35. package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
  36. package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
  37. package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
  38. package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
  39. package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
  40. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
  41. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
  42. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
  43. package/node_modules/pi-agent-ide-formatter/index.ts +33 -0
  44. package/node_modules/pi-agent-ide-formatter/package.json +14 -0
  45. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +50 -0
  46. package/node_modules/pi-agent-ide-formatter/src/registry.ts +30 -0
  47. package/node_modules/pi-agent-ide-formatter/src/types.ts +10 -0
  48. package/node_modules/pi-agent-ide-lint/index.ts +237 -0
  49. package/node_modules/pi-agent-ide-lint/package.json +19 -0
  50. package/node_modules/pi-agent-ide-lint/src/command-linter.ts +160 -0
  51. package/node_modules/pi-agent-ide-lint/src/command-runner.ts +51 -0
  52. package/node_modules/pi-agent-ide-lint/src/registry.ts +30 -0
  53. package/node_modules/pi-agent-ide-lint/src/types.ts +10 -0
  54. package/node_modules/pi-agent-ide-lsp/index.ts +250 -0
  55. package/node_modules/pi-agent-ide-lsp/package.json +23 -0
  56. package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
  57. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
  58. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
  59. package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
  60. package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
  61. package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
  62. package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
  63. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
  64. package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
  65. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
  66. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
  67. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
  68. package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
  69. package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
  70. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
  71. package/node_modules/pi-agent-image/package.json +18 -0
  72. package/node_modules/pi-agent-image/src/image-converter.ts +318 -0
  73. package/node_modules/pi-agent-image/src/index.ts +6 -0
  74. package/node_modules/pi-agent-pdf/package.json +16 -0
  75. package/node_modules/pi-agent-pdf/src/index.ts +5 -0
  76. package/node_modules/pi-agent-pdf/src/pdf-converter.ts +197 -0
  77. package/node_modules/pi-agent-read/index.ts +1 -0
  78. package/node_modules/pi-agent-read/package.json +41 -0
  79. package/node_modules/pi-agent-read/src/api/connect-plugin.ts +67 -0
  80. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +67 -0
  81. package/node_modules/pi-agent-read/src/api/rendering.ts +11 -0
  82. package/node_modules/pi-agent-read/src/api/tools/read.ts +208 -0
  83. package/node_modules/pi-agent-read/src/core/extension.ts +40 -0
  84. package/node_modules/pi-agent-read/src/core/read-core.ts +390 -0
  85. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
  86. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
  87. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
  88. package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
  89. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +828 -0
  90. package/node_modules/pi-agent-resource/package.json +17 -0
  91. package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +84 -0
  92. package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +49 -0
  93. package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +29 -0
  94. package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +73 -0
  95. package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +152 -0
  96. package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +74 -0
  97. package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +149 -0
  98. package/node_modules/pi-agent-resource/src/content.ts +17 -0
  99. package/node_modules/pi-agent-resource/src/index.ts +65 -0
  100. package/node_modules/pi-agent-resource/src/resolver.ts +23 -0
  101. package/node_modules/pi-agent-resource/src/resource.ts +41 -0
  102. package/node_modules/pi-agent-resource/src/validation.ts +139 -0
  103. package/node_modules/pi-agent-search/index.ts +1 -0
  104. package/node_modules/pi-agent-search/package.json +35 -0
  105. package/node_modules/pi-agent-search/src/api/connect-plugin.ts +61 -0
  106. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +60 -0
  107. package/node_modules/pi-agent-search/src/api/search.ts +91 -0
  108. package/node_modules/pi-agent-search/src/core/extension.ts +126 -0
  109. package/node_modules/pi-agent-search/src/core/search-core.ts +400 -0
  110. package/node_modules/pi-agent-search-semantic/index.ts +105 -0
  111. package/node_modules/pi-agent-search-semantic/package.json +17 -0
  112. package/node_modules/pi-agent-search-text/index.ts +54 -0
  113. package/node_modules/pi-agent-search-text/package.json +33 -0
  114. package/node_modules/pi-agent-search-text/src/file-search.ts +105 -0
  115. package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
  116. package/node_modules/pi-agent-search-text/src/resolvers.ts +192 -0
  117. package/node_modules/pi-agent-search-text/src/search-backend.ts +295 -0
  118. package/node_modules/pi-agent-search-text/src/search-query.ts +139 -0
  119. package/node_modules/pi-agent-search-text/src/search-renderer.ts +420 -0
  120. package/node_modules/pi-agent-search-text/src/search-result.ts +193 -0
  121. package/node_modules/pi-agent-search-text/src/search-session.ts +338 -0
  122. package/node_modules/pi-agent-search-web/index.ts +74 -0
  123. package/node_modules/pi-agent-search-web/package.json +19 -0
  124. package/node_modules/pi-agent-search-web/src/config.ts +499 -0
  125. package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
  126. package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +89 -0
  127. package/node_modules/pi-agent-search-web/src/providers/request.ts +430 -0
  128. package/node_modules/pi-agent-search-web/src/providers/response.ts +402 -0
  129. package/node_modules/pi-agent-search-web/src/search-format.ts +29 -0
  130. package/node_modules/pi-agent-search-web/src/search.ts +434 -0
  131. package/node_modules/pi-agent-search-web/src/types.ts +153 -0
  132. package/node_modules/pi-agent-text/package.json +18 -0
  133. package/node_modules/pi-agent-text/src/index.ts +31 -0
  134. package/node_modules/pi-agent-text/src/presented-text.ts +24 -0
  135. package/node_modules/pi-agent-text/src/source-line.ts +49 -0
  136. package/node_modules/pi-agent-text/src/text-anchor.ts +157 -0
  137. package/node_modules/pi-agent-text/src/text-converter.ts +109 -0
  138. package/node_modules/pi-agent-text/src/text-document.ts +149 -0
  139. package/node_modules/pi-agent-text-anchor-constant/index.ts +30 -0
  140. package/node_modules/pi-agent-text-anchor-constant/package.json +17 -0
  141. package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
  142. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +48 -0
  143. package/node_modules/pi-agent-text-anchor-line-hash/package.json +24 -0
  144. package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
  145. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
  146. package/node_modules/pi-agent-text-editor/index.ts +19 -0
  147. package/node_modules/pi-agent-text-editor/package.json +92 -0
  148. package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
  149. package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
  150. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
  151. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
  152. package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
  153. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
  154. package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
  155. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
  156. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
  157. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
  158. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +147 -0
  159. package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
  160. package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
  161. package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
  162. package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
  163. package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
  164. package/node_modules/pi-agent-text-editor/src/core/extension.ts +150 -0
  165. package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
  166. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
  167. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
  168. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
  169. package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
  170. package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
  171. package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
  172. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
  173. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
  174. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
  175. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
  176. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
  177. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
  178. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
  179. package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
  180. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
  181. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
  182. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
  183. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
  184. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
  185. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
  186. package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +16 -0
  187. package/node_modules/pi-agent-text-editor/src/tools/extension.ts +19 -0
  188. package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
  189. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
  190. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
  191. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
  192. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
  193. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
  194. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
  195. package/node_modules/pi-agent-text-editor-argument-order/index.ts +29 -0
  196. package/node_modules/pi-agent-text-editor-argument-order/package.json +16 -0
  197. package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
  198. package/node_modules/pi-agent-text-editor-overwrite/index.ts +391 -0
  199. package/node_modules/pi-agent-text-editor-overwrite/package.json +16 -0
  200. package/node_modules/pi-agent-text-editor-renderer/index.ts +22 -0
  201. package/node_modules/pi-agent-text-editor-renderer/package.json +21 -0
  202. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
  203. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
  204. package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
  205. package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
  206. package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
  207. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
  208. package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
  209. package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
  210. package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
  211. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
  212. package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
  213. package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +375 -0
  214. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +17 -0
  215. package/node_modules/pi-agent-tool-call-interception/package.json +17 -0
  216. package/node_modules/pi-agent-tool-call-interception/src/index.ts +418 -0
  217. package/node_modules/pi-agent-web/index.ts +37 -0
  218. package/node_modules/pi-agent-web/package.json +24 -0
  219. package/node_modules/pi-agent-web/src/resolver.ts +182 -0
  220. package/node_modules/pi-agent-web-html/index.ts +15 -0
  221. package/node_modules/pi-agent-web-html/package.json +18 -0
  222. package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +101 -0
  223. package/node_modules/pi-agent-web-html/src/html-converter.ts +91 -0
  224. package/node_modules/pi-agent-web-image/index.ts +14 -0
  225. package/node_modules/pi-agent-web-image/package.json +17 -0
  226. package/node_modules/pi-agent-web-pdf/index.ts +14 -0
  227. package/node_modules/pi-agent-web-pdf/package.json +17 -0
  228. package/node_modules/pi-agent-web-text/index.ts +14 -0
  229. package/node_modules/pi-agent-web-text/package.json +17 -0
  230. package/package.json +176 -0
  231. package/src/api/code-view.ts +25 -0
  232. package/src/api/connect-plugin.ts +64 -0
  233. package/src/api/plugin-protocol.ts +63 -0
  234. package/src/api/read.ts +5 -0
  235. package/src/api/resource.ts +2 -0
  236. package/src/api/search.ts +4 -0
  237. package/src/api/text-editor.ts +3 -0
  238. package/src/api/text.ts +2 -0
  239. package/src/api/toolchain.ts +24 -0
  240. package/src/code-view/diagnostic-view.ts +82 -0
  241. package/src/code-view/reference.ts +113 -0
  242. package/src/code-view/source-view.ts +229 -0
  243. package/src/composite/builtin-extensions.ts +68 -0
  244. package/src/composite/config.ts +94 -0
  245. package/src/composite/selection.ts +66 -0
  246. package/src/core/extension.ts +48 -0
  247. package/src/core/ide-core.ts +117 -0
  248. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +60 -0
  249. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +23 -0
  250. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +14 -0
  251. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +20 -0
  252. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +14 -0
  253. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +17 -0
  254. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +23 -0
  255. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +20 -0
  256. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +175 -0
  257. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +37 -0
  258. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +24 -0
  259. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +15 -0
  260. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +18 -0
  261. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +101 -0
  262. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +91 -0
  263. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +14 -0
  264. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +17 -0
  265. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +14 -0
  266. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +17 -0
  267. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +14 -0
  268. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +17 -0
  269. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +182 -0
  270. package/src/extensions/pi-agent-read/index.ts +1 -0
  271. package/src/extensions/pi-agent-read/package.json +41 -0
  272. package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +67 -0
  273. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +67 -0
  274. package/src/extensions/pi-agent-read/src/api/rendering.ts +11 -0
  275. package/src/extensions/pi-agent-read/src/api/tools/read.ts +208 -0
  276. package/src/extensions/pi-agent-read/src/core/extension.ts +40 -0
  277. package/src/extensions/pi-agent-read/src/core/read-core.ts +390 -0
  278. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
  279. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
  280. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
  281. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
  282. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +828 -0
  283. package/src/extensions/pi-agent-search/index.ts +1 -0
  284. package/src/extensions/pi-agent-search/package.json +35 -0
  285. package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +105 -0
  286. package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +17 -0
  287. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +54 -0
  288. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +33 -0
  289. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +105 -0
  290. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
  291. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +192 -0
  292. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +295 -0
  293. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +139 -0
  294. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +420 -0
  295. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +193 -0
  296. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +338 -0
  297. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +74 -0
  298. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +19 -0
  299. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +499 -0
  300. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
  301. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +89 -0
  302. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +430 -0
  303. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +402 -0
  304. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +29 -0
  305. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +434 -0
  306. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +153 -0
  307. package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +61 -0
  308. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +60 -0
  309. package/src/extensions/pi-agent-search/src/api/search.ts +91 -0
  310. package/src/extensions/pi-agent-search/src/core/extension.ts +126 -0
  311. package/src/extensions/pi-agent-search/src/core/search-core.ts +400 -0
  312. package/src/extensions/pi-agent-text-editor/index.ts +19 -0
  313. package/src/extensions/pi-agent-text-editor/package.json +92 -0
  314. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +30 -0
  315. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +17 -0
  316. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
  317. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +48 -0
  318. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +24 -0
  319. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
  320. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
  321. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +29 -0
  322. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +16 -0
  323. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
  324. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +391 -0
  325. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +16 -0
  326. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +22 -0
  327. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +21 -0
  328. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
  329. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
  330. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
  331. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
  332. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
  333. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
  334. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
  335. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
  336. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
  337. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
  338. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
  339. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +375 -0
  340. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +17 -0
  341. package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
  342. package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
  343. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
  344. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
  345. package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
  346. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
  347. package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
  348. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
  349. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
  350. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
  351. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +147 -0
  352. package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
  353. package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
  354. package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
  355. package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
  356. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
  357. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +150 -0
  358. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
  359. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
  360. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
  361. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
  362. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
  363. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
  364. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
  365. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
  366. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
  367. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
  368. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
  369. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
  370. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
  371. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
  372. package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
  373. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
  374. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
  375. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
  376. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
  377. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
  378. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
  379. package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +16 -0
  380. package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +19 -0
  381. package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
  382. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
  383. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
  384. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
  385. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
  386. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
  387. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
  388. package/src/index.ts +1 -0
  389. package/src/pi-agent-ide.ts +17 -0
  390. package/src/plugins/pi-agent-ide-ast/index.ts +1 -0
  391. package/src/plugins/pi-agent-ide-ast/package.json +39 -0
  392. package/src/plugins/pi-agent-ide-ast/src/api/scope.ts +1 -0
  393. package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
  394. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +374 -0
  395. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +813 -0
  396. package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
  397. package/src/plugins/pi-agent-ide-ast/src/extension.ts +85 -0
  398. package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
  399. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +221 -0
  400. package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
  401. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +141 -0
  402. package/src/plugins/pi-agent-ide-changes/index.ts +68 -0
  403. package/src/plugins/pi-agent-ide-changes/package.json +29 -0
  404. package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +103 -0
  405. package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
  406. package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
  407. package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
  408. package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
  409. package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
  410. package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
  411. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
  412. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
  413. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
  414. package/src/plugins/pi-agent-ide-formatter/index.ts +33 -0
  415. package/src/plugins/pi-agent-ide-formatter/package.json +14 -0
  416. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +50 -0
  417. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +30 -0
  418. package/src/plugins/pi-agent-ide-formatter/src/types.ts +10 -0
  419. package/src/plugins/pi-agent-ide-lint/index.ts +237 -0
  420. package/src/plugins/pi-agent-ide-lint/package.json +19 -0
  421. package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +160 -0
  422. package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +51 -0
  423. package/src/plugins/pi-agent-ide-lint/src/registry.ts +30 -0
  424. package/src/plugins/pi-agent-ide-lint/src/types.ts +10 -0
  425. package/src/plugins/pi-agent-ide-lsp/index.ts +250 -0
  426. package/src/plugins/pi-agent-ide-lsp/package.json +23 -0
  427. package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
  428. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
  429. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
  430. package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
  431. package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
  432. package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
  433. package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
  434. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
  435. package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
  436. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
  437. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
  438. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
  439. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
  440. package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
  441. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
  442. package/src/post-edit/gate.ts +153 -0
  443. package/src/toolchain/diagnostic.ts +7 -0
  444. package/src/toolchain/gate.ts +322 -0
  445. package/src/toolchain/registry.ts +223 -0
  446. package/src/toolchain/types.ts +164 -0
@@ -0,0 +1,30 @@
1
+ import { readFile } from "node:fs/promises";
2
+
3
+ const MAX_SOURCE_BYTES = 256 * 1024;
4
+
5
+ export interface TextFileSnapshot
6
+ {
7
+ readonly lines: string[];
8
+ readonly content: string;
9
+ }
10
+
11
+ export async function readTextFile(filePath: string): Promise<TextFileSnapshot>
12
+ {
13
+ const buffer = await readFile(filePath);
14
+
15
+ if (buffer.byteLength > MAX_SOURCE_BYTES)
16
+ {
17
+ throw new Error(`File exceeds the ${MAX_SOURCE_BYTES}-byte AST outline limit: ${filePath}`);
18
+ }
19
+
20
+ if (buffer.includes(0))
21
+ {
22
+ throw new Error(`File appears to be binary and cannot be read as text: ${filePath}`);
23
+ }
24
+
25
+ const content = buffer.toString("utf8").replaceAll("\r\n", "\n");
26
+ const withoutFinalNewline = content.endsWith("\n") ? content.slice(0, -1) : content;
27
+ const lines = withoutFinalNewline.length === 0 ? [] : withoutFinalNewline.split("\n");
28
+
29
+ return { content, lines };
30
+ }
@@ -0,0 +1,85 @@
1
+ import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { createSourceMappedTextReadHandler } from "pi-agent-ide/api/code-view";
3
+ import { connectReadPlugin } from "pi-agent-read/api/connect-plugin";
4
+ import { READ_API_VERSION, READ_PROTOCOL, type ReadPlugin } from "pi-agent-read/api/plugin-protocol";
5
+ import { createReadResultRenderer } from "pi-agent-read/api/rendering";
6
+ import { connectSearchPlugin } from "pi-agent-search/api/connect-plugin";
7
+ import { SEARCH_API_VERSION, SEARCH_PROTOCOL } from "pi-agent-search/api/plugin-protocol";
8
+ import { connectTextEditorPlugin } from "pi-agent-text-editor/api/connect-plugin";
9
+ import {
10
+ TEXT_EDITOR_API_VERSION,
11
+ TEXT_EDITOR_PROTOCOL,
12
+ TEXT_POSITION_ANCHOR_KIND,
13
+ type TextEditorPlugin,
14
+ } from "pi-agent-text-editor/api/plugin-protocol";
15
+
16
+ import { AstScopeManager } from "./ast/manager.js";
17
+ import { createAstOutlineResolver } from "./outline-resolver.js";
18
+ import { createAstScopePostReadHandler, createAstScopePresenter } from "./scope-handler.js";
19
+ import { createAstScopeAnchorResolver } from "./scope-resolver.js";
20
+ import { createAstSearchResolver } from "./search-resolver.js";
21
+
22
+ const renderReadResult = createReadResultRenderer({ kind: "code-view", label: "AST" });
23
+
24
+ export default async function registerAst(pi: ExtensionAPI): Promise<void>
25
+ {
26
+ const manager = new AstScopeManager();
27
+ const presenter = createAstScopePresenter(manager);
28
+
29
+ const readPlugin = {
30
+ protocol: READ_PROTOCOL,
31
+ apiVersion: READ_API_VERSION,
32
+ id: "ast",
33
+ setup(api)
34
+ {
35
+ api.addResolver({ resolver: createAstOutlineResolver(), renderResult: renderReadResult });
36
+ api.addHandler({
37
+ stage: "read",
38
+ when: { resolvedBy: "ast", contentKind: "text" },
39
+ handler: createSourceMappedTextReadHandler(),
40
+ });
41
+ api.addTextPresenter({ presenter });
42
+ api.addHandler({
43
+ stage: "post-read",
44
+ handler: createAstScopePostReadHandler(),
45
+ });
46
+ api.describe(
47
+ [
48
+ "For large or unfamiliar supported code and configuration files, prefer `ast:<path>` for the first read so you can inspect their structure without loading the full text.",
49
+ "Use normal reads afterward for the ranges or scopes you need; they also include AST scope markers.",
50
+ ].join("\n"),
51
+ );
52
+ },
53
+ } satisfies ReadPlugin;
54
+ const editorPlugin = {
55
+ protocol: TEXT_EDITOR_PROTOCOL,
56
+ apiVersion: TEXT_EDITOR_API_VERSION,
57
+ id: "ast",
58
+ setup(api)
59
+ {
60
+ api.addAnchorResolver({
61
+ resolver: createAstScopeAnchorResolver(manager),
62
+ kind: TEXT_POSITION_ANCHOR_KIND,
63
+ type: "auxiliary",
64
+ });
65
+ api.addTextPresenter({ presenter });
66
+ },
67
+ } satisfies TextEditorPlugin;
68
+
69
+ await Promise.all([
70
+ connectReadPlugin(pi, readPlugin),
71
+ connectTextEditorPlugin(pi, editorPlugin),
72
+ connectSearchPlugin(pi, {
73
+ protocol: SEARCH_PROTOCOL,
74
+ apiVersion: SEARCH_API_VERSION,
75
+ id: "ast-search",
76
+ setup(api): void
77
+ {
78
+ api.addResolver({ resolver: createAstSearchResolver() });
79
+ api.describe(
80
+ "Use `ast:<pattern>` for structural code search through ast-grep. Optional path and glob fields limit the workspace scope.",
81
+ );
82
+ },
83
+ }),
84
+ ]);
85
+ }
@@ -0,0 +1,69 @@
1
+ import { formatCodeViewReference, parseCodeViewReference, resolveCodeViewPath } from "pi-agent-ide/api/code-view";
2
+
3
+ import type * as AstOutline from "./ast/outline.js";
4
+ import type { ResourceResolutionAttempt, ResourceResolver, ResourceResolverContext } from "pi-agent-resource";
5
+
6
+ let defaultManager: AstOutline.AstOutlineManager | undefined;
7
+ let astOutlineModule: Promise<typeof AstOutline> | undefined;
8
+
9
+ export function createAstOutlineResolver(manager?: AstOutline.AstOutlineManager): ResourceResolver
10
+ {
11
+ return {
12
+ id: "ast",
13
+ tryResolve(source, context)
14
+ {
15
+ return Promise.resolve(resolveAstOutlineSource(source, context, manager));
16
+ },
17
+ };
18
+ }
19
+
20
+ function resolveAstOutlineSource(
21
+ source: string,
22
+ context: ResourceResolverContext,
23
+ manager: AstOutline.AstOutlineManager | undefined,
24
+ ): ResourceResolutionAttempt
25
+ {
26
+ let reference;
27
+
28
+ try
29
+ {
30
+ reference = parseCodeViewReference(source, "ast");
31
+ }
32
+ catch (error)
33
+ {
34
+ return { kind: "failed", error };
35
+ }
36
+
37
+ if (reference === undefined)
38
+ {
39
+ return { kind: "not-handled" };
40
+ }
41
+
42
+ let filePath: string;
43
+
44
+ try
45
+ {
46
+ filePath = resolveCodeViewPath(reference.path, context.cwd);
47
+ }
48
+ catch (error)
49
+ {
50
+ return { kind: "failed", error };
51
+ }
52
+
53
+ const canonicalSource = formatCodeViewReference("ast", filePath);
54
+ return {
55
+ kind: "resolved",
56
+ resource: {
57
+ source: canonicalSource,
58
+ async read({ signal })
59
+ {
60
+ signal?.throwIfAborted();
61
+ const astOutline = await (astOutlineModule ??= import("./ast/outline.js"));
62
+ const outlineManager = manager ?? (defaultManager ??= new astOutline.AstOutlineManager());
63
+ const outline = await outlineManager.readFileOutline(filePath, context.cwd);
64
+ signal?.throwIfAborted();
65
+ return [astOutline.formatAstOutline(outline)];
66
+ },
67
+ },
68
+ };
69
+ }
@@ -0,0 +1,221 @@
1
+ import type { AstScopeManager, ScopeEntry } from "./ast/manager.js";
2
+ import type { ReadPostReadHandler, ReadTextLine, ReadToolResult } from "pi-agent-read/api/tools/read";
3
+ import type { TextLinePresenter } from "pi-agent-text";
4
+
5
+ const AST_SCOPE_METADATA = "pi-agent-ast";
6
+
7
+ interface AstScopeBoundary
8
+ {
9
+ readonly endLine: number;
10
+ }
11
+
12
+ interface AstScopeLineMetadata
13
+ {
14
+ readonly boundaries?: readonly AstScopeBoundary[];
15
+ }
16
+
17
+ export function createAstScopePresenter(manager: AstScopeManager): TextLinePresenter
18
+ {
19
+ return {
20
+ id: "ast-scopes",
21
+ async present(document, context)
22
+ {
23
+ if (context.resolvedBy !== "filesystem")
24
+ {
25
+ return document;
26
+ }
27
+
28
+ try
29
+ {
30
+ const scopes = await manager.getDocumentScopes(
31
+ document.source,
32
+ context.cwd,
33
+ document.lines.map((line) => line.content),
34
+ );
35
+ const lines = addScopeMarkers(document.lines, scopes);
36
+ return lines === document.lines ? document : { ...document, lines };
37
+ }
38
+ catch
39
+ {
40
+ return document;
41
+ }
42
+ },
43
+ };
44
+ }
45
+
46
+ export function createAstScopePostReadHandler(): ReadPostReadHandler
47
+ {
48
+ return (context) =>
49
+ {
50
+ const state = context.state;
51
+ const result = context.result;
52
+
53
+ if (state?.contentKind !== "text" || result === undefined)
54
+ {
55
+ return { kind: "continue", context };
56
+ }
57
+
58
+ const renderedLines = result.details.lines;
59
+
60
+ if (renderedLines === undefined)
61
+ {
62
+ return { kind: "continue", context };
63
+ }
64
+
65
+ const fullLineByNumber = new Map(state.text.lines.map((line) => [line.lineNumber, line]));
66
+ const renderedLineNumbers = new Set(renderedLines.map((line) => line.lineNumber));
67
+ const contextLines = new Map<number, ReadTextLine>();
68
+
69
+ for (const renderedLine of renderedLines)
70
+ {
71
+ const sourceLine = fullLineByNumber.get(renderedLine.lineNumber);
72
+ const metadata = getAstScopeMetadata(sourceLine);
73
+
74
+ for (const boundary of metadata?.boundaries ?? [])
75
+ {
76
+ if (!renderedLineNumbers.has(boundary.endLine))
77
+ {
78
+ const endLine = fullLineByNumber.get(boundary.endLine);
79
+
80
+ if (endLine !== undefined)
81
+ {
82
+ contextLines.set(boundary.endLine, endLine);
83
+ }
84
+ }
85
+ }
86
+ }
87
+
88
+ if (contextLines.size === 0)
89
+ {
90
+ return { kind: "continue", context };
91
+ }
92
+
93
+ const appendedLines = [...contextLines.values()].sort((left, right) => left.lineNumber - right.lineNumber);
94
+ const lines = [...renderedLines, ...appendedLines];
95
+ const updatedResult = appendTextLines(result, lines, renderedLines.at(-1));
96
+
97
+ return { kind: "continue", context: { ...context, result: updatedResult } };
98
+ };
99
+ }
100
+
101
+ function addScopeMarkers(
102
+ lines: readonly ReadTextLine[],
103
+ scopes: readonly ScopeEntry[],
104
+ ): readonly ReadTextLine[]
105
+ {
106
+ if (scopes.length === 0)
107
+ {
108
+ return lines;
109
+ }
110
+
111
+ const markersByLine = new Map<number, string[]>();
112
+ const boundariesByLine = new Map<number, AstScopeBoundary[]>();
113
+
114
+ for (const scope of scopes)
115
+ {
116
+ const begin = markersByLine.get(scope.startLine) ?? [];
117
+ begin.push(scope.beginAnchor.value);
118
+ markersByLine.set(scope.startLine, begin);
119
+
120
+ const boundaries = boundariesByLine.get(scope.startLine) ?? [];
121
+ boundaries.push({ endLine: scope.endLine });
122
+ boundariesByLine.set(scope.startLine, boundaries);
123
+
124
+ const end = markersByLine.get(scope.endLine) ?? [];
125
+ end.push(scope.endScopeAnchor.value);
126
+ markersByLine.set(scope.endLine, end);
127
+ }
128
+
129
+ return lines.map((line) =>
130
+ {
131
+ const markers = markersByLine.get(line.lineNumber);
132
+ const boundaries = boundariesByLine.get(line.lineNumber);
133
+
134
+ if (markers === undefined && boundaries === undefined)
135
+ {
136
+ return line;
137
+ }
138
+
139
+ return {
140
+ ...line,
141
+ ...(markers === undefined
142
+ ? {}
143
+ : {
144
+ presentation: {
145
+ ...line.presentation,
146
+ suffix: `${line.presentation?.suffix ?? ""}${
147
+ markers.map((marker) => ` <!-- ${marker} -->`).join("")
148
+ }`,
149
+ },
150
+ }),
151
+ metadata: {
152
+ ...line.metadata,
153
+ [AST_SCOPE_METADATA]: {
154
+ ...getAstScopeMetadata(line),
155
+ ...(boundaries === undefined ? {} : { boundaries }),
156
+ } satisfies AstScopeLineMetadata,
157
+ },
158
+ };
159
+ });
160
+ }
161
+
162
+ function getAstScopeMetadata(line: ReadTextLine | undefined): AstScopeLineMetadata | undefined
163
+ {
164
+ const value = line?.metadata?.[AST_SCOPE_METADATA];
165
+
166
+ if (typeof value !== "object" || value === null)
167
+ {
168
+ return undefined;
169
+ }
170
+
171
+ return value;
172
+ }
173
+
174
+ function appendTextLines(
175
+ result: ReadToolResult,
176
+ lines: readonly ReadTextLine[],
177
+ lastRenderedLine: ReadTextLine | undefined,
178
+ ): ReadToolResult
179
+ {
180
+ const block = result.content.length === 1 ? result.content[0] : undefined;
181
+
182
+ if (block?.type !== "text" || result.details.lines === undefined)
183
+ {
184
+ return result;
185
+ }
186
+
187
+ const appendedLines = lines.slice(result.details.lines.length);
188
+
189
+ if (appendedLines.length === 0)
190
+ {
191
+ return result;
192
+ }
193
+
194
+ const separator = lastRenderedLine?.lineEnding !== undefined && lastRenderedLine.lineEnding.length > 0
195
+ ? lastRenderedLine.lineEnding
196
+ : appendedLines[0]?.lineEnding !== undefined && appendedLines[0].lineEnding.length > 0
197
+ ? appendedLines[0].lineEnding
198
+ : "\n";
199
+ const appendedText = appendedLines.map((line, index) =>
200
+ {
201
+ const isLast = index === appendedLines.length - 1;
202
+ const lineEnding = isLast ? line.lineEnding : line.lineEnding || separator;
203
+ const prefix = line.presentation?.prefix ?? "";
204
+ const suffix = line.presentation?.suffix ?? "";
205
+ return `${prefix}${line.content}${suffix}${lineEnding}`;
206
+ }).join("");
207
+ const separatorBeforeContext = /(?:\r\n|\r|\n)$/.test(block.text) ? "" : separator;
208
+ const text = `${block.text}${separatorBeforeContext}${appendedText}`;
209
+
210
+ return {
211
+ ...result,
212
+ content: [{
213
+ ...block,
214
+ text,
215
+ }],
216
+ details: {
217
+ ...result.details,
218
+ lines,
219
+ },
220
+ };
221
+ }
@@ -0,0 +1,45 @@
1
+ import type { AstScopeManager } from "./ast/manager.js";
2
+ import type { TextAnchorResolver } from "pi-agent-text";
3
+
4
+ const scopeAnchorPattern = /^scope-(begin|end)-[A-Z0-9]{3,4}(?:-[1-9]\d*)?$/;
5
+
6
+ export function createAstScopeAnchorResolver(manager: AstScopeManager): TextAnchorResolver
7
+ {
8
+ return {
9
+ id: "ast-scope",
10
+ description:
11
+ "Use `scope-begin-HASH` or `scope-end-HASH` as shown beside source lines; a numeric suffix may distinguish repeated scopes.",
12
+ async tryResolve(value, context)
13
+ {
14
+ if (!scopeAnchorPattern.test(value))
15
+ {
16
+ return { kind: "not-handled" };
17
+ }
18
+
19
+ try
20
+ {
21
+ const scopes = await manager.getDocumentScopes(context.source, context.cwd, context.lines);
22
+ const scope = scopes.find((candidate) =>
23
+ candidate.beginAnchor.value === value || candidate.endScopeAnchor.value === value
24
+ );
25
+
26
+ if (scope === undefined)
27
+ {
28
+ return {
29
+ kind: "rejected",
30
+ rejection: { code: "stale", reason: `AST scope anchor ${value} is stale` },
31
+ };
32
+ }
33
+
34
+ return {
35
+ kind: "resolved",
36
+ anchor: scope.beginAnchor.value === value ? scope.beginAnchor : scope.endScopeAnchor,
37
+ };
38
+ }
39
+ catch (error)
40
+ {
41
+ return { kind: "failed", error };
42
+ }
43
+ },
44
+ };
45
+ }
@@ -0,0 +1,141 @@
1
+ import { spawn } from "node:child_process";
2
+
3
+ import type { SearchRequest, SearchResolver } from "pi-agent-search/api/search";
4
+
5
+ interface AstGrepMatch
6
+ {
7
+ readonly text: string;
8
+ readonly file: string;
9
+ readonly lines: string;
10
+ readonly language: string;
11
+ readonly range: {
12
+ readonly start: { readonly line: number; readonly column: number; };
13
+ readonly end: { readonly line: number; readonly column: number; };
14
+ };
15
+ readonly metaVariables?: unknown;
16
+ }
17
+
18
+ export function createAstSearchResolver(): SearchResolver
19
+ {
20
+ return {
21
+ id: "ast",
22
+ async tryResolve(request, context)
23
+ {
24
+ if (!request.query.startsWith("ast:"))
25
+ {
26
+ return { kind: "not-handled" };
27
+ }
28
+
29
+ const pattern = request.query.slice("ast:".length).trim();
30
+
31
+ if (pattern.length === 0)
32
+ {
33
+ return { kind: "failed", error: new Error("ast: pattern must not be empty") };
34
+ }
35
+
36
+ const matches = await runAstGrep(pattern, request, context.cwd, context.signal);
37
+ const limit = request.limit ?? 100;
38
+ return {
39
+ kind: "resolved",
40
+ payload: { pattern, matches: matches.slice(0, limit), complete: matches.length <= limit },
41
+ };
42
+ },
43
+ format(payload)
44
+ {
45
+ const result = payload as {
46
+ readonly pattern: string;
47
+ readonly matches: readonly AstGrepMatch[];
48
+ readonly complete: boolean;
49
+ };
50
+
51
+ if (result.matches.length === 0)
52
+ {
53
+ return { content: [{ type: "text", text: "No AST matches found." }], details: result };
54
+ }
55
+
56
+ const lines = result.matches.flatMap((match, index) => [
57
+ `${String(index + 1)}. ${match.file}:${String(match.range.start.line + 1)}:${
58
+ String(match.range.start.column + 1)
59
+ } ${match.language}`,
60
+ ` ${match.lines.trim()}`,
61
+ ]);
62
+
63
+ if (!result.complete)
64
+ {
65
+ lines.push("Result limit reached.");
66
+ }
67
+
68
+ return { content: [{ type: "text", text: lines.join("\n") }], details: result };
69
+ },
70
+ };
71
+ }
72
+
73
+ function runAstGrep(pattern: string, request: SearchRequest, cwd: string, signal?: AbortSignal): Promise<AstGrepMatch[]>
74
+ {
75
+ const args = ["run", "--pattern", pattern, "--json=compact", "--no-ignore", "parent"];
76
+
77
+ for (const include of splitGlobs(request.include))
78
+ {
79
+ args.push("--globs", include);
80
+ }
81
+
82
+ for (const exclude of splitGlobs(request.exclude))
83
+ {
84
+ args.push("--globs", `!${exclude}`);
85
+ }
86
+
87
+ args.push(request.path ?? ".");
88
+ return new Promise((resolve, reject) =>
89
+ {
90
+ const child = spawn("ast-grep", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
91
+ let stdout = "";
92
+ let stderr = "";
93
+ child.stdout.setEncoding("utf8");
94
+ child.stderr.setEncoding("utf8");
95
+ child.stdout.on("data", (chunk: string) => stdout += chunk);
96
+ child.stderr.on("data", (chunk: string) => stderr += chunk);
97
+ const abort = (): void =>
98
+ {
99
+ child.kill("SIGTERM");
100
+ };
101
+ signal?.addEventListener("abort", abort, { once: true });
102
+ child.once("error", reject);
103
+ child.once("close", (code) =>
104
+ {
105
+ signal?.removeEventListener("abort", abort);
106
+
107
+ if (signal?.aborted === true)
108
+ {
109
+ reject(signal.reason instanceof Error ? signal.reason : new Error("AST search aborted"));
110
+ return;
111
+ }
112
+
113
+ if (code !== 0 && code !== 1)
114
+ {
115
+ reject(new Error(stderr.trim() || `ast-grep exited with code ${String(code)}`));
116
+ return;
117
+ }
118
+
119
+ try
120
+ {
121
+ const value: unknown = JSON.parse(stdout.length === 0 ? "[]" : stdout);
122
+
123
+ if (!Array.isArray(value))
124
+ {
125
+ throw new TypeError("ast-grep returned non-array JSON");
126
+ }
127
+
128
+ resolve(value as AstGrepMatch[]);
129
+ }
130
+ catch (error)
131
+ {
132
+ reject(error instanceof Error ? error : new Error(String(error)));
133
+ }
134
+ });
135
+ });
136
+ }
137
+
138
+ function splitGlobs(value: string | undefined): string[]
139
+ {
140
+ return value?.split(",").map((item) => item.trim()).filter(Boolean) ?? [];
141
+ }
@@ -0,0 +1,68 @@
1
+ import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { connectReadPlugin } from "pi-agent-read/api/connect-plugin";
3
+ import { READ_API_VERSION, READ_PROTOCOL, type ReadPlugin } from "pi-agent-read/api/plugin-protocol";
4
+ import { connectTextEditorPlugin } from "pi-agent-text-editor/api/connect-plugin";
5
+ import {
6
+ TEXT_EDITOR_API_VERSION,
7
+ TEXT_EDITOR_PROTOCOL,
8
+ type TextEditorPlugin,
9
+ } from "pi-agent-text-editor/api/plugin-protocol";
10
+
11
+ import { CHANGE_ANCHOR_KIND, createChangeAnchorRegistration } from "#src/change-anchor.js";
12
+ import { extensionGitExecutor } from "#src/changes/git-changes-backend.js";
13
+ import { createCurrentChangePresenter } from "#src/current-change-presenter.js";
14
+ import { IndexMutationQueue } from "#src/index-mutation-queue.js";
15
+ import { LastTextTransactionStore } from "#src/last-text-transaction-store.js";
16
+ import { registerIndexChangeTools } from "#src/tool-index-change.js";
17
+ import { createUndoMutationTool } from "#src/tool-text-undo.js";
18
+
19
+ export default async function registerGitChanges(pi: ExtensionAPI): Promise<void>
20
+ {
21
+ if (process.argv.includes("--old-tools"))
22
+ {
23
+ return;
24
+ }
25
+
26
+ const executor = extensionGitExecutor(pi);
27
+ const transactions = new LastTextTransactionStore();
28
+ const indexQueue = new IndexMutationQueue();
29
+ const presenter = createCurrentChangePresenter(executor);
30
+ const anchorRegistration = createChangeAnchorRegistration(executor);
31
+ const readPlugin = {
32
+ protocol: READ_PROTOCOL,
33
+ apiVersion: READ_API_VERSION,
34
+ id: "current-git-changes",
35
+ setup(api)
36
+ {
37
+ api.addTextPresenter({ presenter });
38
+ api.describe(
39
+ "Adds CHANGE anchors and Git index state to current changes in tracked text files. Use these anchors with undo, stage, and unstage.",
40
+ );
41
+ },
42
+ } satisfies ReadPlugin;
43
+ const editorPlugin = {
44
+ protocol: TEXT_EDITOR_PROTOCOL,
45
+ apiVersion: TEXT_EDITOR_API_VERSION,
46
+ id: "current-git-changes",
47
+ setup(api)
48
+ {
49
+ api.addAnchorResolver({
50
+ ...anchorRegistration,
51
+ kind: CHANGE_ANCHOR_KIND,
52
+ type: "auxiliary",
53
+ });
54
+ api.onDidEdit((completion) =>
55
+ {
56
+ transactions.observe(completion);
57
+ });
58
+ api.addMutationTool(createUndoMutationTool(executor, transactions, indexQueue));
59
+ api.addTextPresenter({ presenter });
60
+ },
61
+ } satisfies TextEditorPlugin;
62
+
63
+ await Promise.all([
64
+ connectReadPlugin(pi, readPlugin),
65
+ connectTextEditorPlugin(pi, editorPlugin),
66
+ ]);
67
+ registerIndexChangeTools(pi, executor, indexQueue);
68
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "pi-agent-ide-changes",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "pi": {
6
+ "extensions": [
7
+ "./index.ts"
8
+ ]
9
+ },
10
+ "exports": {
11
+ "./changes/change-groups": {
12
+ "types": "./src/changes/change-groups.ts",
13
+ "default": "./src/changes/change-groups.ts"
14
+ }
15
+ },
16
+ "imports": {
17
+ "#src/*": "./src/*"
18
+ },
19
+ "dependencies": {
20
+ "diff": "^9.0.0",
21
+ "pi-agent-read": "0.1.0",
22
+ "pi-agent-text": "0.1.0",
23
+ "pi-agent-text-editor": "0.1.0"
24
+ },
25
+ "peerDependencies": {
26
+ "@earendil-works/pi-coding-agent": "*",
27
+ "typebox": "*"
28
+ }
29
+ }