@mrclrchtr/supi-code-intelligence 4.10.0 → 6.0.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/README.md +4 -3
- package/node_modules/@mrclrchtr/supi-code-runtime/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +9 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +53 -13
- package/node_modules/@mrclrchtr/supi-code-runtime/src/request-control.ts +47 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -1
- package/node_modules/@mrclrchtr/supi-core/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +31 -0
- package/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +19 -6
- package/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +3 -0
- package/node_modules/@mrclrchtr/supi-lsp/README.md +111 -5
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +9 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +53 -13
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/request-control.ts +47 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config/config.ts +31 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +19 -6
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +3 -0
- package/node_modules/@mrclrchtr/supi-lsp/package.json +7 -6
- package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +22 -1
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-cache.ts +245 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +78 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-collection.ts +171 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-evidence.ts +413 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-host.ts +15 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-publication.ts +214 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-pull.ts +62 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-refresh.ts +690 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-request.ts +9 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-timing.ts +97 -16
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-waiters.ts +206 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +448 -298
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-state.ts +70 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +231 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-file-state.ts +25 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +529 -119
- package/node_modules/@mrclrchtr/supi-lsp/src/client/transport.ts +161 -33
- package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +12 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/config/config.ts +5 -5
- package/node_modules/@mrclrchtr/supi-lsp/src/config/defaults.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +3 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-extends.ts +68 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-path.ts +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +176 -24
- package/node_modules/@mrclrchtr/supi-lsp/src/debug-telemetry.ts +45 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +42 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/workspace-sentinels.ts +46 -10
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-client-state.ts +79 -9
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-diagnostics.ts +17 -7
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-recovery.ts +350 -26
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-symbol.ts +5 -2
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +586 -96
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +130 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-semantic-provider.ts +45 -329
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +57 -120
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-edit-normalizer.ts +320 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +207 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/readiness.ts +72 -2
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +151 -26
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostic-surface.ts +42 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostics.ts +92 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +165 -118
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-transition-debug.ts +49 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +102 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +17 -7
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +9 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +53 -13
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/request-control.ts +47 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config/config.ts +31 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +19 -6
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +3 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/LICENSE +21 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/README.md +258 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/dist/babel.cjs +257 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/dist/jiti.cjs +1 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-cli.mjs +34 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-hooks.mjs +124 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-native.mjs +121 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-register.d.mts +1 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-register.mjs +4 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-static.mjs +23 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.cjs +30 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.d.cts +8 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.d.mts +8 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.mjs +29 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/types.d.ts +420 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/package.json +146 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +6 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/api.ts +0 -9
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/index.ts +0 -8
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/provider/tree-sitter-provider.ts +16 -12
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/runtime-controller.ts +65 -87
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/session.ts +47 -95
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-timing.ts +147 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client-lifecycle.ts +39 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +561 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-message-size.ts +24 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-protocol.ts +452 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +4 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +12 -4
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +4 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/imports.ts +4 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/node-at.ts +5 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/types.ts +33 -12
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/blocking-test-bootstrap.mjs +34 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/bootstrap.mjs +8 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/parsed-file-store-helpers.ts +23 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/parsed-file-store.ts +400 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/request-control.ts +48 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime-parser-helpers.ts +24 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime-query-helpers.ts +43 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +421 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/service.ts +116 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/worker-main.ts +201 -0
- package/package.json +5 -5
- package/src/analysis/health/diagnostics.ts +221 -77
- package/src/analysis/health/file-scope.ts +184 -0
- package/src/analysis/health/recovery.ts +14 -3
- package/src/analysis/provider.ts +58 -0
- package/src/analysis/readiness.ts +34 -9
- package/src/analysis/refactor/apply.ts +45 -1
- package/src/analysis/refactor/mutation-authority.ts +143 -0
- package/src/analysis/relations/callees.ts +9 -1
- package/src/analysis/relations/types.ts +5 -2
- package/src/analysis/search/ast-scan-timing.ts +9 -2
- package/src/analysis/search/ast-scan.ts +5 -2
- package/src/analysis/search/deadline.ts +2 -2
- package/src/analysis/search/pattern-analysis.ts +54 -33
- package/src/analysis/search/pattern.ts +18 -3
- package/src/analysis/target/anchored.ts +20 -11
- package/src/analysis/target/file.ts +18 -11
- package/src/analysis/target/identity.ts +19 -3
- package/src/analysis/target/symbol.ts +36 -15
- package/src/api.ts +4 -0
- package/src/config.ts +35 -1
- package/src/diagnostics/evidence.ts +51 -0
- package/src/extension.ts +57 -14
- package/src/overview/overview-data.ts +9 -2
- package/src/overview/overview.ts +49 -30
- package/src/overview/types.ts +2 -0
- package/src/session/capability-adapter.ts +12 -3
- package/src/session/find-types.ts +2 -2
- package/src/session/find-workflow.ts +20 -9
- package/src/session/graph/collect.ts +18 -2
- package/src/session/graph-workflow.ts +19 -12
- package/src/session/health-refresh.ts +175 -0
- package/src/session/health-types.ts +43 -15
- package/src/session/health-workflow.ts +69 -54
- package/src/session/input/workflows.ts +2 -2
- package/src/session/inspect/collect.ts +20 -3
- package/src/session/inspect-workflow.ts +12 -6
- package/src/session/orientation/collect.ts +12 -3
- package/src/session/orientation/context-facts.ts +3 -1
- package/src/session/orientation/context-sections.ts +20 -7
- package/src/session/orientation/gather.ts +17 -11
- package/src/session/orientation-types.ts +4 -1
- package/src/session/orientation-workflow.ts +23 -10
- package/src/session/refactor-plans.ts +2 -0
- package/src/session/refactor-workflow.ts +61 -15
- package/src/session/session.ts +29 -2
- package/src/session/target-workflow.ts +54 -23
- package/src/session/workflow-control.ts +7 -3
- package/src/substrate/lsp/lifecycle.ts +26 -46
- package/src/substrate/lsp/maintenance.ts +284 -28
- package/src/substrate/lsp/recovery.ts +11 -5
- package/src/substrate/lsp/state.ts +2 -2
- package/src/substrate/workspace-provider-host.ts +25 -3
- package/src/tool/{find → code_find}/execute.ts +2 -16
- package/src/tool/code_find/guidance.ts +8 -0
- package/src/tool/{find → code_find}/render.ts +21 -4
- package/src/tool/{result/find.ts → code_find/result.ts} +78 -9
- package/src/tool/code_find/spec.ts +37 -0
- package/src/tool/code_find/tui.ts +41 -0
- package/src/tool/code_graph/execute.ts +24 -0
- package/src/tool/code_graph/guidance.ts +6 -0
- package/src/tool/{graph → code_graph}/markdown.ts +1 -1
- package/src/tool/{result/graph.ts → code_graph/result.ts} +111 -3
- package/src/tool/code_graph/spec.ts +39 -0
- package/src/tool/code_graph/tui.ts +117 -0
- package/src/tool/{health → code_health}/execute.ts +2 -13
- package/src/tool/code_health/guidance.ts +8 -0
- package/src/tool/{health → code_health}/markdown.ts +119 -27
- package/src/tool/code_health/refresh-status.ts +105 -0
- package/src/tool/{result/health.ts → code_health/result.ts} +80 -3
- package/src/tool/code_health/spec.ts +41 -0
- package/src/tool/{health → code_health}/tui.ts +95 -98
- package/src/tool/{inspect → code_inspect}/execute.ts +2 -16
- package/src/tool/code_inspect/guidance.ts +6 -0
- package/src/tool/{inspect → code_inspect}/markdown.ts +1 -1
- package/src/tool/{result/inspect.ts → code_inspect/result.ts} +143 -2
- package/src/tool/code_inspect/spec.ts +25 -0
- package/src/tool/code_inspect/tui.ts +44 -0
- package/src/tool/code_orientation/execute.ts +25 -0
- package/src/tool/code_orientation/guidance.ts +9 -0
- package/src/tool/{orientation → code_orientation}/markdown.ts +1 -1
- package/src/tool/code_orientation/result.ts +248 -0
- package/src/tool/code_orientation/spec.ts +25 -0
- package/src/tool/{orientation → code_orientation}/tui.ts +51 -35
- package/src/tool/code_refactor_apply/execute.ts +17 -0
- package/src/tool/code_refactor_apply/guidance.ts +5 -0
- package/src/tool/{refactor-apply/execute.ts → code_refactor_apply/result.ts} +8 -11
- package/src/tool/code_refactor_apply/spec.ts +26 -0
- package/src/tool/code_refactor_apply/tui.ts +73 -0
- package/src/tool/code_refactor_plan/execute.ts +27 -0
- package/src/tool/code_refactor_plan/guidance.ts +8 -0
- package/src/tool/{refactor-plan/execute.ts → code_refactor_plan/result.ts} +13 -22
- package/src/tool/code_refactor_plan/spec.ts +25 -0
- package/src/tool/code_refactor_plan/tui.ts +54 -0
- package/src/tool/code_resolve/execute.ts +19 -0
- package/src/tool/code_resolve/guidance.ts +8 -0
- package/src/tool/{resolve → code_resolve}/markdown.ts +1 -1
- package/src/tool/{result/resolve.ts → code_resolve/result.ts} +79 -29
- package/src/tool/code_resolve/spec.ts +25 -0
- package/src/tool/code_resolve/tui.ts +60 -0
- package/src/tool/guidance.ts +71 -52
- package/src/tool/infra/truncate.ts +40 -0
- package/src/tool/infra/workflow-control.ts +8 -0
- package/src/tool/{refactor-plan/markdown.ts → refactor-markdown.ts} +4 -7
- package/src/tool/register.ts +105 -88
- package/src/tool/result/display.ts +107 -0
- package/src/tool/result/errors.ts +20 -17
- package/src/tool/result/refactor.ts +37 -8
- package/src/tool/result/types.ts +20 -0
- package/src/tool/schemas.ts +26 -157
- package/src/tool/specs.ts +40 -126
- package/src/types/execution.ts +18 -5
- package/src/types/index.ts +8 -1
- package/src/ui/status-command.ts +5 -3
- package/src/ui/status-overlay.ts +4 -0
- package/src/ui/tui/common.ts +108 -10
- package/src/ui/tui/display.ts +48 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/runtime.ts +0 -351
- package/src/tool/find/tui.ts +0 -39
- package/src/tool/graph/execute.ts +0 -62
- package/src/tool/graph/tui.ts +0 -104
- package/src/tool/inspect/tui.ts +0 -36
- package/src/tool/orientation/execute.ts +0 -62
- package/src/tool/refactor-apply/tui.ts +0 -55
- package/src/tool/refactor-plan/tui.ts +0 -41
- package/src/tool/resolve/execute.ts +0 -36
- package/src/tool/resolve/tui.ts +0 -42
- package/src/tool/result/orientation.ts +0 -132
- /package/src/tool/{find → code_find}/ast-kinds.ts +0 -0
- /package/src/tool/{find → code_find}/markdown.ts +0 -0
- /package/src/tool/{find → code_find}/modes.ts +0 -0
- /package/src/tool/{health → code_health}/semantic-state.ts +0 -0
package/src/ui/tui/common.ts
CHANGED
|
@@ -6,19 +6,47 @@
|
|
|
6
6
|
* partial/error guards, and the shared simple-result pattern.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getMarkdownTheme,
|
|
11
|
+
type Theme,
|
|
12
|
+
type ToolRenderResultOptions,
|
|
13
|
+
} from "@earendil-works/pi-coding-agent";
|
|
10
14
|
import { Container, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
|
|
11
15
|
import { formatEvidenceBadge } from "@mrclrchtr/supi-core/evidence-badge";
|
|
16
|
+
import { truncateDisplayText } from "../../tool/result/display.ts";
|
|
17
|
+
import { renderToolDisplaySections } from "./display.ts";
|
|
18
|
+
|
|
19
|
+
export { formatCallPath, formatCallValue, renderToolDisplaySections } from "./display.ts";
|
|
20
|
+
|
|
21
|
+
import type {
|
|
22
|
+
ToolDisplaySection,
|
|
23
|
+
ToolOutputTruncationDetails,
|
|
24
|
+
ToolResultStatus,
|
|
25
|
+
} from "../../tool/result/types.ts";
|
|
12
26
|
|
|
13
27
|
// ── Result type ──────────────────────────────────────────────────
|
|
14
28
|
|
|
15
29
|
/** Shape of a pi tool result consumed by renderResult functions. */
|
|
16
30
|
export interface ToolResult {
|
|
17
31
|
content: Array<{ type: string; text?: string }>;
|
|
18
|
-
details?: {
|
|
19
|
-
|
|
32
|
+
details?: {
|
|
33
|
+
type: string;
|
|
34
|
+
data: Record<string, unknown>;
|
|
35
|
+
status?: ToolResultStatus;
|
|
36
|
+
message?: string;
|
|
37
|
+
displaySections?: readonly ToolDisplaySection[];
|
|
38
|
+
truncation?: ToolOutputTruncationDetails;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** PI render context used by Code Intelligence result renderers. */
|
|
43
|
+
export interface ToolRendererContext {
|
|
44
|
+
isError: boolean;
|
|
20
45
|
}
|
|
21
46
|
|
|
47
|
+
/** PI render options used by Code Intelligence result renderers. */
|
|
48
|
+
export type ResultOptios = ToolRenderResultOptions;
|
|
49
|
+
|
|
22
50
|
// ── Evidence key labels ──────────────────────────────────────────
|
|
23
51
|
|
|
24
52
|
export const EVIDENCE_KEY_LABELS: Record<string, string> = {
|
|
@@ -142,7 +170,7 @@ export function renderMarkdownDetail(
|
|
|
142
170
|
const markdownText = source.content?.find((c) => c.type === "text")?.text ?? "";
|
|
143
171
|
if (!markdownText) return;
|
|
144
172
|
container.addChild(new Spacer(1));
|
|
145
|
-
const divider = `${theme.fg("border", "────")} ${theme.fg("dim", "raw markdown")} ${theme.fg("border", "
|
|
173
|
+
const divider = `${theme.fg("border", "────")} ${theme.fg("dim", "raw markdown")} ${theme.fg("border", "────")}`;
|
|
146
174
|
container.addChild(new Text(divider, 0, 0));
|
|
147
175
|
container.addChild(new Markdown(markdownText, 0, 0, getMarkdownTheme()));
|
|
148
176
|
}
|
|
@@ -157,13 +185,62 @@ export function renderError(label: string, theme: Theme): Text {
|
|
|
157
185
|
return new Text(theme.fg("error", label), 0, 0);
|
|
158
186
|
}
|
|
159
187
|
|
|
160
|
-
|
|
188
|
+
/** Render an execution failure from PI's renderer context. */
|
|
189
|
+
export function renderExecutionError(
|
|
190
|
+
context: ToolRendererContext | undefined,
|
|
191
|
+
label: string,
|
|
192
|
+
theme: Theme,
|
|
193
|
+
): Text | null {
|
|
194
|
+
return context?.isError ? renderError(label, theme) : null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Render a domain error encoded in structured result details. */
|
|
198
|
+
export function renderDomainError(result: ToolResult, theme: Theme): Text | null {
|
|
199
|
+
const status = result.details?.status;
|
|
200
|
+
if (status !== "invalid-input" && status !== "disambiguation" && status !== "unavailable") {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const label =
|
|
205
|
+
status === "invalid-input"
|
|
206
|
+
? "Invalid input"
|
|
207
|
+
: status === "disambiguation"
|
|
208
|
+
? "Choose a target"
|
|
209
|
+
: "Unavailable";
|
|
210
|
+
const message = result.details?.message
|
|
211
|
+
? `: ${truncateDisplayText(result.details.message, 160)}`
|
|
212
|
+
: "";
|
|
213
|
+
return renderError(`${label}${message}`, theme);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Render an invalid-input or unavailable result with its structured body. */
|
|
217
|
+
export function renderDomainResult(
|
|
218
|
+
result: ToolResult,
|
|
219
|
+
options: ResultOptios,
|
|
220
|
+
theme: Theme,
|
|
221
|
+
error: Text,
|
|
222
|
+
): Container | Text {
|
|
223
|
+
if (!options.expanded) return error;
|
|
224
|
+
const container = new Container();
|
|
225
|
+
container.addChild(error);
|
|
226
|
+
renderToolDisplaySections(container, result.details?.displaySections, theme);
|
|
227
|
+
renderMarkdownDetail(container, result, theme);
|
|
228
|
+
return container;
|
|
229
|
+
}
|
|
161
230
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
231
|
+
/** Render the structured output-truncation disclosure. */
|
|
232
|
+
export function renderTruncationDisclosure(result: ToolResult, theme: Theme): Text | null {
|
|
233
|
+
const truncation = result.details?.truncation;
|
|
234
|
+
if (!truncation?.truncated) return null;
|
|
235
|
+
|
|
236
|
+
const path = truncation.fullOutputPath
|
|
237
|
+
? `; full output: ${truncateDisplayText(truncation.fullOutputPath, 160)}`
|
|
238
|
+
: "";
|
|
239
|
+
return new Text(theme.fg("warning", `Output truncated${path}`), 0, 0);
|
|
165
240
|
}
|
|
166
241
|
|
|
242
|
+
// ── Result options ───────────────────────────────────────────────
|
|
243
|
+
|
|
167
244
|
// ── Shared simple-result renderer ─────────────────────────────────
|
|
168
245
|
|
|
169
246
|
/**
|
|
@@ -172,19 +249,34 @@ export interface ResultOptios {
|
|
|
172
249
|
*
|
|
173
250
|
* Handles partial, error, compact, and expanded states uniformly.
|
|
174
251
|
*/
|
|
252
|
+
// biome-ignore lint/complexity/useMaxParams: renderer signature keeps the shared helper convenient for each tool
|
|
175
253
|
export function renderSimpleResult(
|
|
176
254
|
result: ToolResult,
|
|
177
255
|
options: ResultOptios,
|
|
178
256
|
theme: Theme,
|
|
179
257
|
partialLabel: string,
|
|
258
|
+
context?: ToolRendererContext,
|
|
180
259
|
): Container | Text {
|
|
181
260
|
if (options.isPartial) return renderPartial(partialLabel, theme);
|
|
182
|
-
|
|
261
|
+
|
|
262
|
+
const executionError = renderExecutionError(context, "Tool failed", theme);
|
|
263
|
+
if (executionError) return executionError;
|
|
264
|
+
|
|
265
|
+
const domainError = renderDomainError(result, theme);
|
|
266
|
+
if (domainError) return renderDomainResult(result, options, theme, domainError);
|
|
183
267
|
|
|
184
268
|
const data = result.details?.data as Record<string, unknown> | undefined;
|
|
185
269
|
if (options.expanded) return buildExpandedView(result, data, theme);
|
|
186
270
|
|
|
187
|
-
|
|
271
|
+
const compact = buildSimpleCompact(data, theme);
|
|
272
|
+
const truncation = renderTruncationDisclosure(result, theme);
|
|
273
|
+
if (!truncation) return compact;
|
|
274
|
+
|
|
275
|
+
const container = new Container();
|
|
276
|
+
container.addChild(compact);
|
|
277
|
+
container.addChild(new Spacer(1));
|
|
278
|
+
container.addChild(truncation);
|
|
279
|
+
return container;
|
|
188
280
|
}
|
|
189
281
|
|
|
190
282
|
function buildExpandedView(
|
|
@@ -197,7 +289,13 @@ function buildExpandedView(
|
|
|
197
289
|
const header = buildSimpleHeader(data, theme);
|
|
198
290
|
if (header) container.addChild(header);
|
|
199
291
|
|
|
292
|
+
renderToolDisplaySections(container, result.details?.displaySections, theme);
|
|
200
293
|
renderStructuredDetailBody(container, data, theme);
|
|
294
|
+
const truncation = renderTruncationDisclosure(result, theme);
|
|
295
|
+
if (truncation) {
|
|
296
|
+
container.addChild(new Spacer(1));
|
|
297
|
+
container.addChild(truncation);
|
|
298
|
+
}
|
|
201
299
|
renderMarkdownDetail(container, result, theme);
|
|
202
300
|
|
|
203
301
|
return container;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type Container, Text } from "@earendil-works/pi-tui";
|
|
3
|
+
import { readToolDisplaySections, truncateDisplayText } from "../../tool/result/display.ts";
|
|
4
|
+
import type { ToolDisplaySection } from "../../tool/result/types.ts";
|
|
5
|
+
|
|
6
|
+
/** Render bounded structured rows for an expanded TUI body. */
|
|
7
|
+
export function renderToolDisplaySections(
|
|
8
|
+
container: Container,
|
|
9
|
+
value: unknown,
|
|
10
|
+
theme: Theme,
|
|
11
|
+
): void {
|
|
12
|
+
for (const section of readToolDisplaySections(value)) {
|
|
13
|
+
container.addChild(
|
|
14
|
+
new Text(theme.fg("dim", `${section.title}${formatDisplayBounds(section)}`), 0, 0),
|
|
15
|
+
);
|
|
16
|
+
for (const line of section.lines) {
|
|
17
|
+
container.addChild(new Text(theme.fg("muted", line), 0, 0));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatDisplayBounds(section: ToolDisplaySection): string {
|
|
23
|
+
if (section.totalCount === null) {
|
|
24
|
+
const omitted = section.omittedCount ? `; ${section.omittedCount} collected omitted` : "";
|
|
25
|
+
const reason = section.partialReason
|
|
26
|
+
? `; more may exist — ${section.partialReason}`
|
|
27
|
+
: "; partial";
|
|
28
|
+
return ` (${section.shownCount}${omitted}${reason})`;
|
|
29
|
+
}
|
|
30
|
+
if (section.omittedCount && section.omittedCount > 0) {
|
|
31
|
+
return ` (${section.shownCount} of ${section.totalCount}; ${section.omittedCount} omitted)`;
|
|
32
|
+
}
|
|
33
|
+
return ` (${section.totalCount})`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Format one call argument for a compact human transcript row. */
|
|
37
|
+
export function formatCallValue(value: unknown, maxLength = 60): string | null {
|
|
38
|
+
if (typeof value !== "string" || value.length === 0) return null;
|
|
39
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
40
|
+
return truncateDisplayText(normalized, maxLength);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Show the final path segment while accepting both POSIX and Windows paths. */
|
|
44
|
+
export function formatCallPath(value: unknown, maxLength = 60): string | null {
|
|
45
|
+
const formatted = formatCallValue(value, Number.MAX_SAFE_INTEGER);
|
|
46
|
+
if (!formatted) return null;
|
|
47
|
+
return formatCallValue(formatted.split(/[\\/]/).pop() ?? formatted, maxLength);
|
|
48
|
+
}
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
// Tree-sitter runtime — parser management, parse, and query services.
|
|
2
|
-
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
import * as fs from "node:fs";
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
import { startDebugTimer } from "@mrclrchtr/supi-core/debug";
|
|
7
|
-
import { resolveToolPath } from "@mrclrchtr/supi-core/path";
|
|
8
|
-
import type { Language, Parser, Tree } from "web-tree-sitter";
|
|
9
|
-
import { nodeToRange } from "../coordinates.ts";
|
|
10
|
-
import { detectGrammar, resolveGrammarWasmPath } from "../language.ts";
|
|
11
|
-
import type { GrammarId, QueryCapture, TreeSitterResult } from "../types.ts";
|
|
12
|
-
|
|
13
|
-
interface ParserEntry {
|
|
14
|
-
parser: Parser;
|
|
15
|
-
language: Language;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Session-scoped Tree-sitter runtime.
|
|
20
|
-
*
|
|
21
|
-
* A runtime owns the expensive `web-tree-sitter` initialization and parser
|
|
22
|
-
* instances for one pi working directory. Call `dispose()` when the session is
|
|
23
|
-
* torn down so WASM parser resources are released.
|
|
24
|
-
*/
|
|
25
|
-
export class TreeSitterRuntime {
|
|
26
|
-
private parserModule: typeof import("web-tree-sitter") | undefined;
|
|
27
|
-
private parsers = new Map<GrammarId, ParserEntry>();
|
|
28
|
-
private parserPromises = new Map<GrammarId, Promise<ParserEntry>>();
|
|
29
|
-
private initPromise: Promise<typeof import("web-tree-sitter")> | undefined;
|
|
30
|
-
private initializing = false;
|
|
31
|
-
private disposed = false;
|
|
32
|
-
|
|
33
|
-
/** Create a runtime that resolves relative file paths from `cwd`. */
|
|
34
|
-
constructor(private cwd: string) {}
|
|
35
|
-
|
|
36
|
-
/** Ensure web-tree-sitter Parser is initialized. */
|
|
37
|
-
private async ensureParserInit(): Promise<typeof import("web-tree-sitter")> {
|
|
38
|
-
this.assertActive();
|
|
39
|
-
if (this.parserModule) return this.parserModule;
|
|
40
|
-
if (this.initializing && this.initPromise) return this.initPromise;
|
|
41
|
-
|
|
42
|
-
this.initializing = true;
|
|
43
|
-
this.initPromise = (async () => {
|
|
44
|
-
const mod = await import("web-tree-sitter");
|
|
45
|
-
await mod.Parser.init();
|
|
46
|
-
this.assertActive();
|
|
47
|
-
this.parserModule = mod;
|
|
48
|
-
return mod;
|
|
49
|
-
})();
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
return await this.initPromise;
|
|
53
|
-
} catch (err: unknown) {
|
|
54
|
-
// Allow retry on next call
|
|
55
|
-
this.initPromise = undefined;
|
|
56
|
-
this.initializing = false;
|
|
57
|
-
throw new Error("Failed to initialize web-tree-sitter", { cause: err });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get or create a parser entry for a grammar.
|
|
63
|
-
*
|
|
64
|
-
* Concurrent first-use calls for the same grammar share one initialization
|
|
65
|
-
* promise. Failed initialization is not cached, so a later request can retry.
|
|
66
|
-
*/
|
|
67
|
-
async ensureGrammarParser(grammarId: GrammarId): Promise<ParserEntry> {
|
|
68
|
-
this.assertActive();
|
|
69
|
-
const existing = this.parsers.get(grammarId);
|
|
70
|
-
if (existing) return existing;
|
|
71
|
-
|
|
72
|
-
const pending = this.parserPromises.get(grammarId);
|
|
73
|
-
if (pending) return pending;
|
|
74
|
-
|
|
75
|
-
const promise = this.createGrammarParser(grammarId);
|
|
76
|
-
this.parserPromises.set(grammarId, promise);
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
return await promise;
|
|
80
|
-
} finally {
|
|
81
|
-
if (this.parserPromises.get(grammarId) === promise) {
|
|
82
|
-
this.parserPromises.delete(grammarId);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private async createGrammarParser(grammarId: GrammarId): Promise<ParserEntry> {
|
|
88
|
-
const mod = await this.ensureParserInit();
|
|
89
|
-
const wasmPath = resolveGrammarWasmPath(grammarId);
|
|
90
|
-
|
|
91
|
-
const language = await mod.Language.load(wasmPath);
|
|
92
|
-
const parser = new mod.Parser();
|
|
93
|
-
try {
|
|
94
|
-
parser.setLanguage(language);
|
|
95
|
-
} catch (err) {
|
|
96
|
-
parser.delete();
|
|
97
|
-
throw err;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (this.disposed) {
|
|
101
|
-
parser.delete();
|
|
102
|
-
throw new Error("Tree-sitter runtime has been disposed");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const entry = { parser, language };
|
|
106
|
-
this.parsers.set(grammarId, entry);
|
|
107
|
-
return entry;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** Read and parse a file. Returns structured result. */
|
|
111
|
-
async parseFile(filePath: string): Promise<
|
|
112
|
-
TreeSitterResult<{
|
|
113
|
-
tree: Tree;
|
|
114
|
-
source: string;
|
|
115
|
-
resolvedPath: string;
|
|
116
|
-
grammarId: GrammarId;
|
|
117
|
-
}>
|
|
118
|
-
> {
|
|
119
|
-
const resolvedPath = resolveToolPath(this.cwd, filePath);
|
|
120
|
-
|
|
121
|
-
// Check language support first
|
|
122
|
-
const grammarId = detectGrammar(filePath);
|
|
123
|
-
if (!grammarId) {
|
|
124
|
-
return {
|
|
125
|
-
kind: "unsupported-language",
|
|
126
|
-
file: filePath,
|
|
127
|
-
message: `No Tree-sitter grammar configured for ${path.extname(filePath) || "this file type"}`,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const timer = startDebugTimer();
|
|
132
|
-
const parserState = this.parsers.has(grammarId)
|
|
133
|
-
? "reused"
|
|
134
|
-
: this.parserPromises.has(grammarId)
|
|
135
|
-
? "initializing"
|
|
136
|
-
: "cold";
|
|
137
|
-
|
|
138
|
-
// Read the file
|
|
139
|
-
let source: string;
|
|
140
|
-
try {
|
|
141
|
-
source = fs.readFileSync(resolvedPath, "utf-8");
|
|
142
|
-
} catch (err: unknown) {
|
|
143
|
-
finishStructuralTiming(timer, {
|
|
144
|
-
operation: "parse",
|
|
145
|
-
grammar: grammarId,
|
|
146
|
-
parserState,
|
|
147
|
-
outcome: "file-access-error",
|
|
148
|
-
finalPhase: "file-read",
|
|
149
|
-
});
|
|
150
|
-
const message = err instanceof Error ? err.message : "File could not be read";
|
|
151
|
-
return {
|
|
152
|
-
kind: "file-access-error",
|
|
153
|
-
file: filePath,
|
|
154
|
-
message,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
timer.mark("file-read");
|
|
158
|
-
|
|
159
|
-
if (timer.enabled) {
|
|
160
|
-
try {
|
|
161
|
-
createHash("sha256").update(source).digest();
|
|
162
|
-
} catch {
|
|
163
|
-
// Timing-only hashing must not change structural behavior.
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
timer.mark("content-hash");
|
|
167
|
-
|
|
168
|
-
let parserReady = false;
|
|
169
|
-
try {
|
|
170
|
-
const entry = await this.ensureGrammarParser(grammarId);
|
|
171
|
-
timer.mark("parser-setup");
|
|
172
|
-
parserReady = true;
|
|
173
|
-
const tree = entry.parser.parse(source);
|
|
174
|
-
finishStructuralTiming(timer, {
|
|
175
|
-
operation: "parse",
|
|
176
|
-
grammar: grammarId,
|
|
177
|
-
parserState,
|
|
178
|
-
outcome: "completed",
|
|
179
|
-
finalPhase: "parse",
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
kind: "success",
|
|
183
|
-
data: { tree: tree as Tree, source, resolvedPath, grammarId },
|
|
184
|
-
};
|
|
185
|
-
} catch (err: unknown) {
|
|
186
|
-
finishStructuralTiming(timer, {
|
|
187
|
-
operation: "parse",
|
|
188
|
-
grammar: grammarId,
|
|
189
|
-
parserState,
|
|
190
|
-
outcome: "runtime-error",
|
|
191
|
-
finalPhase: parserReady ? "parse" : "parser-setup",
|
|
192
|
-
});
|
|
193
|
-
return { kind: "runtime-error", message: formatError(err, "Parser initialization failed") };
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** Execute a Tree-sitter query against a file. */
|
|
198
|
-
async queryFile(
|
|
199
|
-
filePath: string,
|
|
200
|
-
queryString: string,
|
|
201
|
-
): Promise<TreeSitterResult<QueryCapture[]>> {
|
|
202
|
-
if (!queryString || queryString.trim().length === 0) {
|
|
203
|
-
return { kind: "validation-error", message: "query is required and must be non-empty" };
|
|
204
|
-
}
|
|
205
|
-
if (queryString.length > MAX_QUERY_LENGTH) {
|
|
206
|
-
return {
|
|
207
|
-
kind: "validation-error",
|
|
208
|
-
message: `query exceeds maximum length of ${MAX_QUERY_LENGTH} characters`,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const parseResult = await this.parseFile(filePath);
|
|
213
|
-
if (parseResult.kind !== "success") return parseResult;
|
|
214
|
-
|
|
215
|
-
const { grammarId, tree, source } = parseResult.data;
|
|
216
|
-
const timer = startDebugTimer();
|
|
217
|
-
let compiled = false;
|
|
218
|
-
|
|
219
|
-
try {
|
|
220
|
-
const entry = await this.ensureGrammarParser(grammarId);
|
|
221
|
-
const mod = await this.ensureParserInit();
|
|
222
|
-
let query: InstanceType<typeof mod.Query>;
|
|
223
|
-
|
|
224
|
-
try {
|
|
225
|
-
query = new mod.Query(entry.language, queryString);
|
|
226
|
-
compiled = true;
|
|
227
|
-
timer.mark("query-compilation");
|
|
228
|
-
} catch (err: unknown) {
|
|
229
|
-
finishStructuralTiming(timer, {
|
|
230
|
-
operation: "query",
|
|
231
|
-
grammar: grammarId,
|
|
232
|
-
outcome: "validation-error",
|
|
233
|
-
captureCount: 0,
|
|
234
|
-
finalPhase: "query-compilation",
|
|
235
|
-
});
|
|
236
|
-
return { kind: "validation-error", message: `Invalid query: ${formatError(err)}` };
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
const matches = query.matches(tree.rootNode);
|
|
241
|
-
const captures: QueryCapture[] = [];
|
|
242
|
-
for (const match of matches) {
|
|
243
|
-
for (const { name, node } of match.captures) {
|
|
244
|
-
captures.push({
|
|
245
|
-
name,
|
|
246
|
-
nodeType: node.type,
|
|
247
|
-
range: nodeToRange(node, source),
|
|
248
|
-
text: node.text,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
finishStructuralTiming(timer, {
|
|
253
|
-
operation: "query",
|
|
254
|
-
grammar: grammarId,
|
|
255
|
-
outcome: "completed",
|
|
256
|
-
captureCount: captures.length,
|
|
257
|
-
finalPhase: "query-execution",
|
|
258
|
-
});
|
|
259
|
-
return { kind: "success", data: captures };
|
|
260
|
-
} finally {
|
|
261
|
-
query.delete();
|
|
262
|
-
}
|
|
263
|
-
} catch (err: unknown) {
|
|
264
|
-
finishStructuralTiming(timer, {
|
|
265
|
-
operation: "query",
|
|
266
|
-
grammar: grammarId,
|
|
267
|
-
outcome: "runtime-error",
|
|
268
|
-
captureCount: 0,
|
|
269
|
-
finalPhase: compiled ? "query-execution" : "query-compilation",
|
|
270
|
-
});
|
|
271
|
-
return { kind: "runtime-error", message: formatError(err, "Query execution failed") };
|
|
272
|
-
} finally {
|
|
273
|
-
tree.delete();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/** Get the grammar ID for a file, or undefined if unsupported. */
|
|
278
|
-
getGrammarId(filePath: string): GrammarId | undefined {
|
|
279
|
-
return detectGrammar(filePath);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/** Resolve a file path from cwd. */
|
|
283
|
-
resolvePath(filePath: string): string {
|
|
284
|
-
return resolveToolPath(this.cwd, filePath);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** Dispose all held parser resources. */
|
|
288
|
-
dispose(): void {
|
|
289
|
-
this.disposed = true;
|
|
290
|
-
for (const [, entry] of this.parsers) {
|
|
291
|
-
entry.parser.delete();
|
|
292
|
-
}
|
|
293
|
-
this.parsers.clear();
|
|
294
|
-
this.parserPromises.clear();
|
|
295
|
-
this.parserModule = undefined;
|
|
296
|
-
this.initPromise = undefined;
|
|
297
|
-
this.initializing = false;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
private assertActive(): void {
|
|
301
|
-
if (this.disposed) {
|
|
302
|
-
throw new Error("Tree-sitter runtime has been disposed");
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/** Max query string length to prevent ReDoS via overly complex Tree-sitter patterns. */
|
|
308
|
-
const MAX_QUERY_LENGTH = 10_000;
|
|
309
|
-
|
|
310
|
-
type StructuralTimer = ReturnType<typeof startDebugTimer>;
|
|
311
|
-
type ParserState = "cold" | "initializing" | "reused";
|
|
312
|
-
|
|
313
|
-
type StructuralTimingObservation =
|
|
314
|
-
| {
|
|
315
|
-
readonly operation: "parse";
|
|
316
|
-
readonly grammar: GrammarId;
|
|
317
|
-
readonly parserState: ParserState;
|
|
318
|
-
readonly outcome: "completed" | "file-access-error" | "runtime-error";
|
|
319
|
-
readonly finalPhase: "file-read" | "parse" | "parser-setup";
|
|
320
|
-
}
|
|
321
|
-
| {
|
|
322
|
-
readonly operation: "query";
|
|
323
|
-
readonly grammar: GrammarId;
|
|
324
|
-
readonly outcome: "completed" | "runtime-error" | "validation-error";
|
|
325
|
-
readonly captureCount: number;
|
|
326
|
-
readonly finalPhase: "query-compilation" | "query-execution";
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
function finishStructuralTiming(
|
|
330
|
-
timer: StructuralTimer,
|
|
331
|
-
observation: StructuralTimingObservation,
|
|
332
|
-
): void {
|
|
333
|
-
const { finalPhase, ...data } = observation;
|
|
334
|
-
timer.finish(
|
|
335
|
-
() => ({
|
|
336
|
-
source: "tree-sitter",
|
|
337
|
-
level: "debug",
|
|
338
|
-
category: `structural.${data.operation}.timing`,
|
|
339
|
-
message: `Tree-sitter ${data.operation} ${data.outcome}`,
|
|
340
|
-
data: { ...data },
|
|
341
|
-
}),
|
|
342
|
-
finalPhase,
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/** Format errors with their cause chain's first message for user-facing tool output. */
|
|
347
|
-
function formatError(err: unknown, fallback = "Operation failed"): string {
|
|
348
|
-
if (!(err instanceof Error)) return String(err || fallback);
|
|
349
|
-
if (err.cause instanceof Error) return `${err.message}: ${err.cause.message}`;
|
|
350
|
-
return err.message || fallback;
|
|
351
|
-
}
|
package/src/tool/find/tui.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TUI renderer for code_find — renderCall + renderResult.
|
|
3
|
-
*/
|
|
4
|
-
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { Text } from "@earendil-works/pi-tui";
|
|
6
|
-
import { type ResultOptios, renderSimpleResult, type ToolResult } from "../../ui/tui/common.ts";
|
|
7
|
-
import type { CodeFindToolParams } from "./execute.ts";
|
|
8
|
-
|
|
9
|
-
/** ── renderCall ────────────────────────────────────────────────── */
|
|
10
|
-
|
|
11
|
-
export function renderFindCall(args: unknown, theme: Theme, _context: unknown): Text {
|
|
12
|
-
const params = (args ?? {}) as CodeFindToolParams;
|
|
13
|
-
const mode = params.mode ?? "mode?";
|
|
14
|
-
|
|
15
|
-
let content = theme.fg("toolTitle", "code_find");
|
|
16
|
-
|
|
17
|
-
if (params.query) {
|
|
18
|
-
content += ` ${theme.fg("accent", JSON.stringify(params.query))}`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
content += ` ${theme.fg("muted", mode)}`;
|
|
22
|
-
|
|
23
|
-
if (params.kind) {
|
|
24
|
-
content += theme.fg("dim", ` [${params.kind}]`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return new Text(content, 0, 0);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** ── renderResult ──────────────────────────────────────────────── */
|
|
31
|
-
|
|
32
|
-
export function renderFindResult(
|
|
33
|
-
result: ToolResult,
|
|
34
|
-
options: ResultOptios,
|
|
35
|
-
theme: Theme,
|
|
36
|
-
_context: unknown,
|
|
37
|
-
): ReturnType<typeof renderSimpleResult> {
|
|
38
|
-
return renderSimpleResult(result, options, theme, "Searching…");
|
|
39
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/** Thin Pi adapter for the session-owned code_graph workflow. */
|
|
2
|
-
|
|
3
|
-
import type { GraphWorkflowInput, RequestedGraphRelation } from "../../session/graph-types.ts";
|
|
4
|
-
import type { GraphTargetInput } from "../../session/target-input.ts";
|
|
5
|
-
import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
|
|
6
|
-
import { toWorkflowControl } from "../infra/workflow-control.ts";
|
|
7
|
-
import { searchErrorResult } from "../result/errors.ts";
|
|
8
|
-
import { assembleGraphResult } from "../result/graph.ts";
|
|
9
|
-
import { renderGraphResult } from "./markdown.ts";
|
|
10
|
-
|
|
11
|
-
export type GraphRelation = RequestedGraphRelation;
|
|
12
|
-
|
|
13
|
-
export interface CodeGraphToolParams {
|
|
14
|
-
target: GraphTargetInput;
|
|
15
|
-
relations?: GraphRelation[];
|
|
16
|
-
calleeDepth?: "direct" | "deep";
|
|
17
|
-
maxResults?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function executeGraphTool(
|
|
21
|
-
params: CodeGraphToolParams,
|
|
22
|
-
ctx: CodeIntelToolExecCtx,
|
|
23
|
-
): Promise<CodeIntelResult> {
|
|
24
|
-
const outcome = await ctx.session.graph(params as GraphWorkflowInput, toWorkflowControl(ctx));
|
|
25
|
-
|
|
26
|
-
if (outcome.kind === "unavailable") throw new Error(outcome.reason);
|
|
27
|
-
if (outcome.kind === "invalid-input") {
|
|
28
|
-
return searchErrorResult(`**Error:** ${outcome.message}`);
|
|
29
|
-
}
|
|
30
|
-
if (outcome.kind === "disambiguation" || outcome.kind === "kind-mismatch") {
|
|
31
|
-
const lines = [
|
|
32
|
-
outcome.kind === "kind-mismatch"
|
|
33
|
-
? `**No target matched provider kind \`${outcome.requestedKind}\`. Near matches:**`
|
|
34
|
-
: "**Target is ambiguous. Choose one candidate handle:**",
|
|
35
|
-
"",
|
|
36
|
-
];
|
|
37
|
-
for (const candidate of outcome.candidates) {
|
|
38
|
-
lines.push(
|
|
39
|
-
`- \`${candidate.targetId}\` — ${candidate.name} (\`${candidate.kind ?? "unknown"}\`) at ${candidate.file}:${candidate.line}:${candidate.character}`,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (outcome.kind === "kind-mismatch") {
|
|
43
|
-
lines.push(
|
|
44
|
-
"",
|
|
45
|
-
"Retry without `symbolKind`, use an observed provider kind, or choose a handle.",
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return searchErrorResult(lines.join("\n"));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const assembly = assembleGraphResult({
|
|
52
|
-
displayName: outcome.displayName,
|
|
53
|
-
sections: outcome.sections,
|
|
54
|
-
resolvedDisplayFile: outcome.resolvedDisplayFile,
|
|
55
|
-
maxResults: outcome.maxResults,
|
|
56
|
-
cwd: ctx.cwd,
|
|
57
|
-
});
|
|
58
|
-
return {
|
|
59
|
-
content: renderGraphResult(assembly),
|
|
60
|
-
details: { type: "search", data: assembly.details },
|
|
61
|
-
};
|
|
62
|
-
}
|