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.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/assets/banner.png +0 -0
- package/docs/architecture.md +100 -0
- package/docs/configuration.md +104 -0
- package/docs/development.md +102 -0
- package/docs/evaluation.md +14 -0
- package/docs/extensions.md +298 -0
- package/docs/tools.md +104 -0
- package/node_modules/pi-agent-filesystem/index.ts +60 -0
- package/node_modules/pi-agent-filesystem/package.json +23 -0
- package/node_modules/pi-agent-filesystem/src/resolver.ts +175 -0
- package/node_modules/pi-agent-filesystem-image/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-image/package.json +20 -0
- package/node_modules/pi-agent-filesystem-pdf/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-pdf/package.json +17 -0
- package/node_modules/pi-agent-filesystem-text/index.ts +23 -0
- package/node_modules/pi-agent-filesystem-text/package.json +20 -0
- package/node_modules/pi-agent-ide-ast/index.ts +1 -0
- package/node_modules/pi-agent-ide-ast/package.json +39 -0
- package/node_modules/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +85 -0
- package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/node_modules/pi-agent-ide-changes/index.ts +68 -0
- package/node_modules/pi-agent-ide-changes/package.json +29 -0
- package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/node_modules/pi-agent-ide-formatter/index.ts +33 -0
- package/node_modules/pi-agent-ide-formatter/package.json +14 -0
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-formatter/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lint/index.ts +237 -0
- package/node_modules/pi-agent-ide-lint/package.json +19 -0
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/node_modules/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/node_modules/pi-agent-ide-lint/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-lint/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lsp/index.ts +250 -0
- package/node_modules/pi-agent-ide-lsp/package.json +23 -0
- package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/node_modules/pi-agent-image/package.json +18 -0
- package/node_modules/pi-agent-image/src/image-converter.ts +318 -0
- package/node_modules/pi-agent-image/src/index.ts +6 -0
- package/node_modules/pi-agent-pdf/package.json +16 -0
- package/node_modules/pi-agent-pdf/src/index.ts +5 -0
- package/node_modules/pi-agent-pdf/src/pdf-converter.ts +197 -0
- package/node_modules/pi-agent-read/index.ts +1 -0
- package/node_modules/pi-agent-read/package.json +41 -0
- package/node_modules/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/node_modules/pi-agent-read/src/api/rendering.ts +11 -0
- package/node_modules/pi-agent-read/src/api/tools/read.ts +208 -0
- package/node_modules/pi-agent-read/src/core/extension.ts +40 -0
- package/node_modules/pi-agent-read/src/core/read-core.ts +390 -0
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/node_modules/pi-agent-resource/package.json +17 -0
- package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +84 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +49 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +29 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +73 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +152 -0
- package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +74 -0
- package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +149 -0
- package/node_modules/pi-agent-resource/src/content.ts +17 -0
- package/node_modules/pi-agent-resource/src/index.ts +65 -0
- package/node_modules/pi-agent-resource/src/resolver.ts +23 -0
- package/node_modules/pi-agent-resource/src/resource.ts +41 -0
- package/node_modules/pi-agent-resource/src/validation.ts +139 -0
- package/node_modules/pi-agent-search/index.ts +1 -0
- package/node_modules/pi-agent-search/package.json +35 -0
- package/node_modules/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/node_modules/pi-agent-search/src/api/search.ts +91 -0
- package/node_modules/pi-agent-search/src/core/extension.ts +126 -0
- package/node_modules/pi-agent-search/src/core/search-core.ts +400 -0
- package/node_modules/pi-agent-search-semantic/index.ts +105 -0
- package/node_modules/pi-agent-search-semantic/package.json +17 -0
- package/node_modules/pi-agent-search-text/index.ts +54 -0
- package/node_modules/pi-agent-search-text/package.json +33 -0
- package/node_modules/pi-agent-search-text/src/file-search.ts +105 -0
- package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +192 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +295 -0
- package/node_modules/pi-agent-search-text/src/search-query.ts +139 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/node_modules/pi-agent-search-text/src/search-result.ts +193 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +338 -0
- package/node_modules/pi-agent-search-web/index.ts +74 -0
- package/node_modules/pi-agent-search-web/package.json +19 -0
- package/node_modules/pi-agent-search-web/src/config.ts +499 -0
- package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/node_modules/pi-agent-search-web/src/providers/request.ts +430 -0
- package/node_modules/pi-agent-search-web/src/providers/response.ts +402 -0
- package/node_modules/pi-agent-search-web/src/search-format.ts +29 -0
- package/node_modules/pi-agent-search-web/src/search.ts +434 -0
- package/node_modules/pi-agent-search-web/src/types.ts +153 -0
- package/node_modules/pi-agent-text/package.json +18 -0
- package/node_modules/pi-agent-text/src/index.ts +31 -0
- package/node_modules/pi-agent-text/src/presented-text.ts +24 -0
- package/node_modules/pi-agent-text/src/source-line.ts +49 -0
- package/node_modules/pi-agent-text/src/text-anchor.ts +157 -0
- package/node_modules/pi-agent-text/src/text-converter.ts +109 -0
- package/node_modules/pi-agent-text/src/text-document.ts +149 -0
- package/node_modules/pi-agent-text-anchor-constant/index.ts +30 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +17 -0
- package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/node_modules/pi-agent-text-editor/index.ts +19 -0
- package/node_modules/pi-agent-text-editor/package.json +92 -0
- package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/node_modules/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/node_modules/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/node_modules/pi-agent-text-editor-argument-order/package.json +16 -0
- package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/node_modules/pi-agent-text-editor-overwrite/package.json +16 -0
- package/node_modules/pi-agent-text-editor-renderer/index.ts +22 -0
- package/node_modules/pi-agent-text-editor-renderer/package.json +21 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +418 -0
- package/node_modules/pi-agent-web/index.ts +37 -0
- package/node_modules/pi-agent-web/package.json +24 -0
- package/node_modules/pi-agent-web/src/resolver.ts +182 -0
- package/node_modules/pi-agent-web-html/index.ts +15 -0
- package/node_modules/pi-agent-web-html/package.json +18 -0
- package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/node_modules/pi-agent-web-html/src/html-converter.ts +91 -0
- package/node_modules/pi-agent-web-image/index.ts +14 -0
- package/node_modules/pi-agent-web-image/package.json +17 -0
- package/node_modules/pi-agent-web-pdf/index.ts +14 -0
- package/node_modules/pi-agent-web-pdf/package.json +17 -0
- package/node_modules/pi-agent-web-text/index.ts +14 -0
- package/node_modules/pi-agent-web-text/package.json +17 -0
- package/package.json +176 -0
- package/src/api/code-view.ts +25 -0
- package/src/api/connect-plugin.ts +64 -0
- package/src/api/plugin-protocol.ts +63 -0
- package/src/api/read.ts +5 -0
- package/src/api/resource.ts +2 -0
- package/src/api/search.ts +4 -0
- package/src/api/text-editor.ts +3 -0
- package/src/api/text.ts +2 -0
- package/src/api/toolchain.ts +24 -0
- package/src/code-view/diagnostic-view.ts +82 -0
- package/src/code-view/reference.ts +113 -0
- package/src/code-view/source-view.ts +229 -0
- package/src/composite/builtin-extensions.ts +68 -0
- package/src/composite/config.ts +94 -0
- package/src/composite/selection.ts +66 -0
- package/src/core/extension.ts +48 -0
- package/src/core/ide-core.ts +117 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +60 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +175 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +37 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +24 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +15 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +18 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +91 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +182 -0
- package/src/extensions/pi-agent-read/index.ts +1 -0
- package/src/extensions/pi-agent-read/package.json +41 -0
- package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/rendering.ts +11 -0
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +208 -0
- package/src/extensions/pi-agent-read/src/core/extension.ts +40 -0
- package/src/extensions/pi-agent-read/src/core/read-core.ts +390 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/src/extensions/pi-agent-search/index.ts +1 -0
- package/src/extensions/pi-agent-search/package.json +35 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +17 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +54 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +33 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +192 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +295 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +139 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +193 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +338 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +74 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +19 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +499 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +430 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +402 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +29 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +434 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +153 -0
- package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +91 -0
- package/src/extensions/pi-agent-search/src/core/extension.ts +126 -0
- package/src/extensions/pi-agent-search/src/core/search-core.ts +400 -0
- package/src/extensions/pi-agent-text-editor/index.ts +19 -0
- package/src/extensions/pi-agent-text-editor/package.json +92 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +30 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +22 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +21 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/src/index.ts +1 -0
- package/src/pi-agent-ide.ts +17 -0
- package/src/plugins/pi-agent-ide-ast/index.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/package.json +39 -0
- package/src/plugins/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +85 -0
- package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +68 -0
- package/src/plugins/pi-agent-ide-changes/package.json +29 -0
- package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/src/plugins/pi-agent-ide-formatter/index.ts +33 -0
- package/src/plugins/pi-agent-ide-formatter/package.json +14 -0
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-formatter/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lint/index.ts +237 -0
- package/src/plugins/pi-agent-ide-lint/package.json +19 -0
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-lint/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lsp/index.ts +250 -0
- package/src/plugins/pi-agent-ide-lsp/package.json +23 -0
- package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/src/post-edit/gate.ts +153 -0
- package/src/toolchain/diagnostic.ts +7 -0
- package/src/toolchain/gate.ts +322 -0
- package/src/toolchain/registry.ts +223 -0
- package/src/toolchain/types.ts +164 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_MAX_BYTES,
|
|
3
|
+
DEFAULT_MAX_LINES,
|
|
4
|
+
formatSize,
|
|
5
|
+
truncateHead,
|
|
6
|
+
type TruncationResult,
|
|
7
|
+
} from "@earendil-works/pi-coding-agent";
|
|
8
|
+
|
|
9
|
+
import type { ReadRequest, ReadResultDetails, ReadToolResult } from "#src/api/tools/read.js";
|
|
10
|
+
|
|
11
|
+
export const READ_OUTPUT_MAX_BYTES = DEFAULT_MAX_BYTES;
|
|
12
|
+
|
|
13
|
+
export const READ_OUTPUT_MAX_LINES = DEFAULT_MAX_LINES;
|
|
14
|
+
|
|
15
|
+
export async function limitReadOutput(
|
|
16
|
+
result: ReadToolResult,
|
|
17
|
+
request: ReadRequest,
|
|
18
|
+
saveFullOutput?: (text: string) => Promise<string>,
|
|
19
|
+
): Promise<ReadToolResult>
|
|
20
|
+
{
|
|
21
|
+
const block = result.content.length === 1 ? result.content[0] : undefined;
|
|
22
|
+
|
|
23
|
+
if (block?.type !== "text")
|
|
24
|
+
{
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const truncation = truncateHead(block.text, {
|
|
29
|
+
maxBytes: READ_OUTPUT_MAX_BYTES,
|
|
30
|
+
maxLines: READ_OUTPUT_MAX_LINES,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (truncation.truncated)
|
|
34
|
+
{
|
|
35
|
+
const temporarySource = saveFullOutput === undefined ? undefined : await saveFullOutput(block.text);
|
|
36
|
+
const baseNotice = truncation.firstLineExceedsLimit
|
|
37
|
+
? oversizedFirstLineNotice(block.text, result.details, request)
|
|
38
|
+
: truncatedOutputNotice(truncation, result.details, request);
|
|
39
|
+
const notice = temporarySource === undefined
|
|
40
|
+
? baseNotice
|
|
41
|
+
: appendTemporarySource(baseNotice, temporarySource);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
...result,
|
|
45
|
+
content: [{ ...block, text: appendNotice(truncation.content, notice) }],
|
|
46
|
+
details: {
|
|
47
|
+
...truncatedDetails(result.details, truncation),
|
|
48
|
+
...(temporarySource === undefined ? {} : { temporarySource }),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const notice = explicitLimitNotice(result.details, request);
|
|
54
|
+
|
|
55
|
+
if (notice === undefined)
|
|
56
|
+
{
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
...result,
|
|
62
|
+
content: [{ ...block, text: appendNotice(block.text, notice) }],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function appendTemporarySource(notice: string, source: string): string
|
|
67
|
+
{
|
|
68
|
+
return `${notice.slice(0, -1)} Full output: ${source}. Expires after 5 minutes of inactivity.]`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function oversizedFirstLineNotice(text: string, details: ReadResultDetails, request: ReadRequest): string
|
|
72
|
+
{
|
|
73
|
+
const firstLine = text.split(/\r\n|\r|\n/u, 1)[0] ?? "";
|
|
74
|
+
const lineSize = formatSize(Buffer.byteLength(firstLine, "utf8"));
|
|
75
|
+
const sourceLine = sourceStartLine(details, request);
|
|
76
|
+
const lineLabel = sourceLine === undefined ? "First output line" : `Line ${sourceLine}`;
|
|
77
|
+
|
|
78
|
+
return `[${lineLabel} is ${lineSize}, exceeds ${formatSize(READ_OUTPUT_MAX_BYTES)} limit. `
|
|
79
|
+
+ "Use a source-specific tool to read this line in smaller byte ranges.]";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function truncatedOutputNotice(
|
|
83
|
+
truncation: TruncationResult,
|
|
84
|
+
details: ReadResultDetails,
|
|
85
|
+
request: ReadRequest,
|
|
86
|
+
): string
|
|
87
|
+
{
|
|
88
|
+
const sourceRange = shownSourceRange(truncation, details, request);
|
|
89
|
+
|
|
90
|
+
if (sourceRange !== undefined && sourceRange.endLine < sourceRange.totalLines)
|
|
91
|
+
{
|
|
92
|
+
const byteLimit = truncation.truncatedBy === "bytes"
|
|
93
|
+
? ` (${formatSize(truncation.maxBytes)} limit)`
|
|
94
|
+
: "";
|
|
95
|
+
|
|
96
|
+
return `[Showing lines ${sourceRange.startLine}-${sourceRange.endLine} of ${sourceRange.totalLines}${byteLimit}. Use offset=${
|
|
97
|
+
sourceRange.endLine + 1
|
|
98
|
+
} to continue.]`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const limit = truncation.truncatedBy === "lines"
|
|
102
|
+
? `${truncation.maxLines} line limit`
|
|
103
|
+
: `${formatSize(truncation.maxBytes)} limit`;
|
|
104
|
+
|
|
105
|
+
return `[Output truncated: showing ${truncation.outputLines} of ${truncation.totalLines} rendered lines (${limit}). `
|
|
106
|
+
+ "Use a smaller line range to read this source.]";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function shownSourceRange(
|
|
110
|
+
truncation: TruncationResult,
|
|
111
|
+
details: ReadResultDetails,
|
|
112
|
+
request: ReadRequest,
|
|
113
|
+
): { readonly startLine: number; readonly endLine: number; readonly totalLines: number; } | undefined
|
|
114
|
+
{
|
|
115
|
+
const totalLines = details.totalLines;
|
|
116
|
+
const startLine = sourceStartLine(details, request);
|
|
117
|
+
|
|
118
|
+
if (totalLines === undefined || totalLines === 0 || startLine === undefined || truncation.outputLines === 0)
|
|
119
|
+
{
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const projectedEndLine = details.endLine === undefined || details.endLine < startLine
|
|
124
|
+
? totalLines
|
|
125
|
+
: details.endLine;
|
|
126
|
+
const projectedLines = projectedEndLine - startLine + 1;
|
|
127
|
+
const shownLines = Math.min(truncation.outputLines, projectedLines);
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
startLine,
|
|
131
|
+
endLine: startLine + shownLines - 1,
|
|
132
|
+
totalLines,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function explicitLimitNotice(details: ReadResultDetails, request: ReadRequest): string | undefined
|
|
137
|
+
{
|
|
138
|
+
if (request.limit === undefined || details.totalLines === undefined || details.totalLines === 0)
|
|
139
|
+
{
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const startLine = sourceStartLine(details, request);
|
|
144
|
+
|
|
145
|
+
if (startLine === undefined)
|
|
146
|
+
{
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const nextOffset = details.endLine === undefined || details.endLine < startLine
|
|
151
|
+
? startLine
|
|
152
|
+
: details.endLine + 1;
|
|
153
|
+
|
|
154
|
+
if (nextOffset > details.totalLines)
|
|
155
|
+
{
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const remaining = details.totalLines - nextOffset + 1;
|
|
160
|
+
return `[${remaining} more lines in source. Use offset=${nextOffset} to continue.]`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function sourceStartLine(details: ReadResultDetails, request: ReadRequest): number | undefined
|
|
164
|
+
{
|
|
165
|
+
if (details.startLine !== undefined && details.startLine > 0)
|
|
166
|
+
{
|
|
167
|
+
return details.startLine;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (details.totalLines === undefined || details.totalLines === 0)
|
|
171
|
+
{
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const offset = request.offset === undefined ? 1 : Math.trunc(request.offset);
|
|
176
|
+
return offset < 0
|
|
177
|
+
? Math.max(1, details.totalLines + offset + 1)
|
|
178
|
+
: Math.max(1, offset);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function truncatedDetails(details: ReadResultDetails, truncation: TruncationResult): ReadResultDetails
|
|
182
|
+
{
|
|
183
|
+
return {
|
|
184
|
+
...details,
|
|
185
|
+
...(details.lines === undefined ? {} : { lines: details.lines.slice(0, truncation.outputLines) }),
|
|
186
|
+
truncation,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function appendNotice(text: string, notice: string): string
|
|
191
|
+
{
|
|
192
|
+
return text.length === 0 ? notice : `${text}\n\n${notice}`;
|
|
193
|
+
}
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AgentToolResult,
|
|
3
|
+
getLanguageFromPath,
|
|
4
|
+
getMarkdownTheme,
|
|
5
|
+
highlightCode,
|
|
6
|
+
keyHint,
|
|
7
|
+
type Theme,
|
|
8
|
+
} from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { type Component, Container, Markdown, Text, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
10
|
+
import { getTextSourceLine } from "pi-agent-text";
|
|
11
|
+
|
|
12
|
+
import type { ReadResultRendererOptions } from "#src/api/rendering.js";
|
|
13
|
+
import type { ReadResultDetails, ReadResultRenderer, ReadTextLine } from "#src/api/tools/read.js";
|
|
14
|
+
|
|
15
|
+
export const COMPACT_READ_ROWS = 12;
|
|
16
|
+
|
|
17
|
+
interface ReadPanelState
|
|
18
|
+
{
|
|
19
|
+
readonly result: AgentToolResult<unknown>;
|
|
20
|
+
readonly details: ReadResultDetails;
|
|
21
|
+
readonly options: ReadResultRendererOptions;
|
|
22
|
+
readonly expanded: boolean;
|
|
23
|
+
readonly theme: Theme;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createReadResultRenderer(options: ReadResultRendererOptions): ReadResultRenderer
|
|
27
|
+
{
|
|
28
|
+
return (result, renderOptions, theme, context): Component =>
|
|
29
|
+
{
|
|
30
|
+
if (renderOptions.isPartial || context.isError)
|
|
31
|
+
{
|
|
32
|
+
const text = textBlocks(result);
|
|
33
|
+
const color = context.isError ? "error" : "dim";
|
|
34
|
+
return new Text(theme.fg(color, text), 0, 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!hasTextContent(result))
|
|
38
|
+
{
|
|
39
|
+
return context.lastComponent instanceof Container ? context.lastComponent : new Container();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const details = readDetails(result.details);
|
|
43
|
+
const previous = context.lastComponent instanceof ReadResultPanel ? context.lastComponent : undefined;
|
|
44
|
+
const panel = previous ?? new ReadResultPanel({
|
|
45
|
+
result,
|
|
46
|
+
details,
|
|
47
|
+
options,
|
|
48
|
+
expanded: renderOptions.expanded,
|
|
49
|
+
theme,
|
|
50
|
+
});
|
|
51
|
+
panel.update({ result, details, options, expanded: renderOptions.expanded, theme });
|
|
52
|
+
return panel;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class ReadResultPanel implements Component
|
|
57
|
+
{
|
|
58
|
+
private cached: { readonly width: number; readonly lines: string[]; } | undefined;
|
|
59
|
+
|
|
60
|
+
public constructor(private state: ReadPanelState)
|
|
61
|
+
{}
|
|
62
|
+
|
|
63
|
+
public update(state: ReadPanelState): void
|
|
64
|
+
{
|
|
65
|
+
if (
|
|
66
|
+
this.state.result !== state.result
|
|
67
|
+
|| this.state.details !== state.details
|
|
68
|
+
|| this.state.options !== state.options
|
|
69
|
+
|| this.state.expanded !== state.expanded
|
|
70
|
+
|| this.state.theme !== state.theme
|
|
71
|
+
)
|
|
72
|
+
{
|
|
73
|
+
this.state = state;
|
|
74
|
+
this.invalidate();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public render(width: number): string[]
|
|
79
|
+
{
|
|
80
|
+
if (this.cached?.width === width)
|
|
81
|
+
{
|
|
82
|
+
return this.cached.lines;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (width < 8)
|
|
86
|
+
{
|
|
87
|
+
const lines = [truncateToWidth(readTitle(this.state, width), Math.max(1, width))];
|
|
88
|
+
this.cached = { width, lines };
|
|
89
|
+
return lines;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const innerWidth = width - 2;
|
|
93
|
+
const contentWidth = Math.max(1, innerWidth - 2);
|
|
94
|
+
const renderedRows = renderContentRows(this.state, contentWidth);
|
|
95
|
+
const rows = compactRows(renderedRows, this.state.expanded, this.state.theme);
|
|
96
|
+
const lines = [renderTopBorder(this.state, innerWidth, this.state.theme)];
|
|
97
|
+
|
|
98
|
+
for (const row of rows)
|
|
99
|
+
{
|
|
100
|
+
lines.push(framed(row, innerWidth, this.state.theme));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const status = readStatus(this.state.details, this.state.theme);
|
|
104
|
+
|
|
105
|
+
if (status !== undefined)
|
|
106
|
+
{
|
|
107
|
+
lines.push(framed(status, innerWidth, this.state.theme));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
lines.push(this.state.theme.fg("borderMuted", `╰${"─".repeat(innerWidth)}╯`));
|
|
111
|
+
const clipped = lines.map((line) => truncateToWidth(line, width));
|
|
112
|
+
this.cached = { width, lines: clipped };
|
|
113
|
+
return clipped;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public invalidate(): void
|
|
117
|
+
{
|
|
118
|
+
this.cached = undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function renderContentRows(state: ReadPanelState, width: number): string[]
|
|
123
|
+
{
|
|
124
|
+
const lines = readLines(state.details);
|
|
125
|
+
const text = cleanText(state.result, lines, state.details);
|
|
126
|
+
|
|
127
|
+
if (state.options.kind === "markdown" || isMarkdownSource(state.details, lines, state.options.kind))
|
|
128
|
+
{
|
|
129
|
+
const markdown = new Markdown(text, 0, 0, getMarkdownTheme());
|
|
130
|
+
return nonEmptyRows(markdown.render(width), state.theme);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (state.options.kind === "code-view")
|
|
134
|
+
{
|
|
135
|
+
const rows = lines === undefined
|
|
136
|
+
? text.split(/\r\n|\r|\n/u).map((line) => renderCodeViewLabel(line, state.theme))
|
|
137
|
+
: renderCodeViewLines(lines, state.theme);
|
|
138
|
+
return nonEmptyRows(rows, state.theme);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const sourceLines = lines?.map(({ content }) => normalizeText(content))
|
|
142
|
+
?? text.split(/\r\n|\r|\n/u).map(normalizeText);
|
|
143
|
+
const language = languageFor(state.details, lines);
|
|
144
|
+
const rows = language === undefined
|
|
145
|
+
? sourceLines.map((line) => state.theme.fg("toolOutput", line))
|
|
146
|
+
: highlightCode(sourceLines.join("\n"), language);
|
|
147
|
+
return nonEmptyRows(rows, state.theme);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function renderCodeViewLines(lines: readonly ReadTextLine[], theme: Theme): string[]
|
|
151
|
+
{
|
|
152
|
+
return lines.map((line) =>
|
|
153
|
+
{
|
|
154
|
+
const sourceLine = getTextSourceLine(line);
|
|
155
|
+
|
|
156
|
+
if (sourceLine === undefined)
|
|
157
|
+
{
|
|
158
|
+
return renderCodeViewLabel(line.content, theme);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const language = getLanguageFromPath(sourceLine.source);
|
|
162
|
+
const content = normalizeText(stripScopeMarkers(line.content));
|
|
163
|
+
return language === undefined
|
|
164
|
+
? theme.fg("toolOutput", content)
|
|
165
|
+
: highlightCode(content, language)[0] ?? theme.fg("toolOutput", content);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function stripScopeMarkers(value: string): string
|
|
170
|
+
{
|
|
171
|
+
return value.replace(/(?:[ \t]{2,}<!--[ \t]+scope-(?:begin|end)-[^\s>]+[ \t]+-->)+[ \t]*$/u, "");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function renderCodeViewLabel(value: string, theme: Theme): string
|
|
175
|
+
{
|
|
176
|
+
const line = normalizeText(stripScopeMarkers(value));
|
|
177
|
+
|
|
178
|
+
if (/^#{2,3}\s/u.test(line))
|
|
179
|
+
{
|
|
180
|
+
return theme.fg("mdHeading", theme.bold(line.replace(/^#{2,3}\s+/u, "")));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (/^(?:Lines|Reason|Recovery):/u.test(line))
|
|
184
|
+
{
|
|
185
|
+
return theme.fg("dim", line);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (/^[\p{L}][^:]*:$/u.test(line))
|
|
189
|
+
{
|
|
190
|
+
return theme.fg("accent", theme.bold(line));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (/^\s*[-*]\s/u.test(line))
|
|
194
|
+
{
|
|
195
|
+
return theme.fg("mdListBullet", line);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return theme.fg("toolOutput", line);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function compactRows(rows: readonly string[], expanded: boolean, theme: Theme): readonly string[]
|
|
202
|
+
{
|
|
203
|
+
if (expanded || rows.length <= COMPACT_READ_ROWS)
|
|
204
|
+
{
|
|
205
|
+
return rows;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const shown = rows.slice(0, COMPACT_READ_ROWS - 1);
|
|
209
|
+
const omitted = rows.length - shown.length;
|
|
210
|
+
return [
|
|
211
|
+
...shown,
|
|
212
|
+
`${theme.fg("dim", `… ${String(omitted)} more ${omitted === 1 ? "row" : "rows"} · `)}${
|
|
213
|
+
keyHint("app.tools.expand", "to expand")
|
|
214
|
+
}`,
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function renderTopBorder(state: ReadPanelState, width: number, theme: Theme): string
|
|
219
|
+
{
|
|
220
|
+
const frame = (text: string): string => theme.fg("borderMuted", text);
|
|
221
|
+
const title = truncateToWidth(` ${readTitle(state, Math.max(1, width - 1))} `, Math.max(0, width - 1), "");
|
|
222
|
+
const fill = "─".repeat(Math.max(0, width - visibleWidth(title) - 1));
|
|
223
|
+
return `${frame("╭─")}${title}${frame(`${fill}╮`)}`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function readTitle(state: ReadPanelState, width: number): string
|
|
227
|
+
{
|
|
228
|
+
const label = state.options.label ?? languageLabel(languageFor(state.details, readLines(state.details)));
|
|
229
|
+
const source = state.details.source ?? "read result";
|
|
230
|
+
const range = sourceRange(state.details);
|
|
231
|
+
const prefix = state.theme.fg("accent", state.theme.bold(label));
|
|
232
|
+
const suffix = range === undefined ? "" : state.theme.fg("dim", ` · ${range}`);
|
|
233
|
+
const available = Math.max(1, width - visibleWidth(prefix) - visibleWidth(suffix) - 2);
|
|
234
|
+
const renderedSource = truncateFromStart(source, available);
|
|
235
|
+
return `${prefix} ${state.theme.fg("muted", renderedSource)}${suffix}`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function sourceRange(details: ReadResultDetails): string | undefined
|
|
239
|
+
{
|
|
240
|
+
if (
|
|
241
|
+
details.startLine === undefined
|
|
242
|
+
|| details.endLine === undefined
|
|
243
|
+
|| details.totalLines === undefined
|
|
244
|
+
|| details.totalLines <= 0
|
|
245
|
+
)
|
|
246
|
+
{
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return `${String(details.startLine)}–${String(details.endLine)} / ${String(details.totalLines)}`;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function readStatus(details: ReadResultDetails, theme: Theme): string | undefined
|
|
254
|
+
{
|
|
255
|
+
const truncation = details.truncation;
|
|
256
|
+
|
|
257
|
+
if (truncation?.firstLineExceedsLimit === true)
|
|
258
|
+
{
|
|
259
|
+
return theme.fg("warning", "First source line is larger than the saved read limit");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (truncation?.truncated === true)
|
|
263
|
+
{
|
|
264
|
+
return theme.fg(
|
|
265
|
+
"warning",
|
|
266
|
+
`Saved result contains ${String(truncation.outputLines)} of ${String(truncation.totalLines)} rendered rows`,
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function framed(content: string, width: number, theme: Theme): string
|
|
274
|
+
{
|
|
275
|
+
const contentWidth = Math.max(0, width - 2);
|
|
276
|
+
const clipped = truncateToWidth(content, contentWidth);
|
|
277
|
+
const body = ` ${clipped}${" ".repeat(Math.max(0, contentWidth - visibleWidth(clipped)))} `;
|
|
278
|
+
const border = theme.fg("borderMuted", "│");
|
|
279
|
+
return `${border}${body}${border}`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function cleanText(
|
|
283
|
+
result: AgentToolResult<unknown>,
|
|
284
|
+
lines: readonly ReadTextLine[] | undefined,
|
|
285
|
+
details: ReadResultDetails,
|
|
286
|
+
): string
|
|
287
|
+
{
|
|
288
|
+
if (lines !== undefined)
|
|
289
|
+
{
|
|
290
|
+
return lines.map((line) => `${line.content}${line.lineEnding}`).join("");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const text = textBlocks(result);
|
|
294
|
+
|
|
295
|
+
if (
|
|
296
|
+
details.truncation === undefined
|
|
297
|
+
&& !(details.totalLines !== undefined && details.endLine !== undefined && details.endLine < details.totalLines)
|
|
298
|
+
)
|
|
299
|
+
{
|
|
300
|
+
return text;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return text.replace(/\n\n\[(?:Showing lines|Output truncated|\d+ more lines in source)[\s\S]*\]$/u, "");
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function textBlocks(result: AgentToolResult<unknown>): string
|
|
307
|
+
{
|
|
308
|
+
return result.content.flatMap((block) => block.type === "text" ? [block.text] : []).join("\n");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function readLines(details: ReadResultDetails): readonly ReadTextLine[] | undefined
|
|
312
|
+
{
|
|
313
|
+
return details.lines;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function readDetails(value: unknown): ReadResultDetails
|
|
317
|
+
{
|
|
318
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function hasTextContent(result: AgentToolResult<unknown>): boolean
|
|
322
|
+
{
|
|
323
|
+
return result.content.some((block) => block.type === "text");
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function languageFor(details: ReadResultDetails, lines: readonly ReadTextLine[] | undefined): string | undefined
|
|
327
|
+
{
|
|
328
|
+
const mappedSource = lines?.map(getTextSourceLine).find((line) => line !== undefined)?.source;
|
|
329
|
+
const source = mappedSource ?? details.source;
|
|
330
|
+
return source === undefined ? undefined : getLanguageFromPath(normalizeSourcePath(source));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function isMarkdownSource(
|
|
334
|
+
details: ReadResultDetails,
|
|
335
|
+
lines: readonly ReadTextLine[] | undefined,
|
|
336
|
+
kind: ReadResultRendererOptions["kind"],
|
|
337
|
+
): boolean
|
|
338
|
+
{
|
|
339
|
+
return kind === "source" && languageFor(details, lines) === "markdown";
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function normalizeSourcePath(source: string): string
|
|
343
|
+
{
|
|
344
|
+
try
|
|
345
|
+
{
|
|
346
|
+
const url = new URL(source);
|
|
347
|
+
return url.protocol === "file:" ? url.pathname : `${url.pathname}${url.search}`;
|
|
348
|
+
}
|
|
349
|
+
catch
|
|
350
|
+
{
|
|
351
|
+
const withoutSelector = source.replace(/#[^/\\]*$/u, "");
|
|
352
|
+
return withoutSelector.replace(/^[A-Za-z][A-Za-z\d+.-]*:(?=[/\\])/u, "");
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function normalizeText(value: string): string
|
|
357
|
+
{
|
|
358
|
+
let output = "";
|
|
359
|
+
|
|
360
|
+
for (const character of value.replaceAll("\t", " "))
|
|
361
|
+
{
|
|
362
|
+
const code = character.codePointAt(0)!;
|
|
363
|
+
output += code < 0x20 || code === 0x7F ? "�" : character;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return output;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function languageLabel(language: string | undefined): string
|
|
370
|
+
{
|
|
371
|
+
const labels: Readonly<Record<string, string>> = {
|
|
372
|
+
javascript: "JS",
|
|
373
|
+
json: "JSON",
|
|
374
|
+
markdown: "MD",
|
|
375
|
+
python: "PY",
|
|
376
|
+
rust: "RS",
|
|
377
|
+
typescript: "TS",
|
|
378
|
+
};
|
|
379
|
+
return language === undefined ? "TEXT" : labels[language] ?? language.slice(0, 4).toUpperCase();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function nonEmptyRows(rows: readonly string[], theme: Theme): string[]
|
|
383
|
+
{
|
|
384
|
+
return rows.length === 0 ? [theme.fg("dim", "Empty content")] : [...rows];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function truncateFromStart(value: string, width: number): string
|
|
388
|
+
{
|
|
389
|
+
if (visibleWidth(value) <= width)
|
|
390
|
+
{
|
|
391
|
+
return value;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (width <= 1)
|
|
395
|
+
{
|
|
396
|
+
return "…";
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return `…${value.slice(-(width - 1))}`;
|
|
400
|
+
}
|