@mrclrchtr/supi-code-intelligence 5.0.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.
Files changed (139) hide show
  1. package/README.md +2 -2
  2. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  3. package/node_modules/@mrclrchtr/supi-core/package.json +2 -2
  4. package/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
  5. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +0 -3
  6. package/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
  7. package/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
  8. package/node_modules/@mrclrchtr/supi-lsp/README.md +34 -3
  9. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  10. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +2 -2
  11. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +0 -3
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
  15. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  16. package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +12 -1
  17. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-cache.ts +67 -28
  18. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-collection.ts +63 -6
  19. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-evidence.ts +46 -5
  20. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-host.ts +1 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-publication.ts +214 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-refresh.ts +278 -79
  23. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-timing.ts +29 -8
  24. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +101 -19
  25. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-state.ts +19 -1
  26. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +49 -3
  27. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +73 -15
  28. package/node_modules/@mrclrchtr/supi-lsp/src/client/transport.ts +1 -1
  29. package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +2 -2
  30. package/node_modules/@mrclrchtr/supi-lsp/src/config/config.ts +5 -5
  31. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +3 -0
  32. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-extends.ts +68 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-path.ts +8 -0
  34. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +176 -24
  35. package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +4 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/workspace-sentinels.ts +46 -10
  37. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-diagnostics.ts +4 -3
  38. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-recovery.ts +65 -17
  39. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +143 -21
  40. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostic-surface.ts +2 -0
  41. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostics.ts +43 -1
  42. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +31 -0
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +2 -2
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +0 -3
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
  48. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
  49. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  50. package/package.json +5 -5
  51. package/src/analysis/health/diagnostics.ts +58 -126
  52. package/src/analysis/health/file-scope.ts +184 -0
  53. package/src/analysis/health/recovery.ts +8 -1
  54. package/src/analysis/readiness.ts +4 -0
  55. package/src/analysis/search/ast-scan.ts +4 -1
  56. package/src/analysis/search/pattern-analysis.ts +10 -3
  57. package/src/analysis/search/pattern.ts +6 -1
  58. package/src/config.ts +35 -1
  59. package/src/extension.ts +57 -14
  60. package/src/overview/overview-data.ts +9 -2
  61. package/src/overview/overview.ts +49 -30
  62. package/src/overview/types.ts +2 -0
  63. package/src/session/find-types.ts +2 -2
  64. package/src/session/find-workflow.ts +3 -2
  65. package/src/session/health-refresh.ts +76 -49
  66. package/src/session/health-types.ts +7 -1
  67. package/src/session/health-workflow.ts +35 -18
  68. package/src/session/input/workflows.ts +2 -2
  69. package/src/session/inspect-workflow.ts +2 -1
  70. package/src/session/orientation/collect.ts +2 -2
  71. package/src/session/orientation-types.ts +2 -0
  72. package/src/session/orientation-workflow.ts +8 -2
  73. package/src/session/refactor-workflow.ts +2 -1
  74. package/src/session/session.ts +25 -1
  75. package/src/substrate/lsp/maintenance.ts +105 -23
  76. package/src/substrate/lsp/recovery.ts +11 -5
  77. package/src/tool/code_find/execute.ts +23 -0
  78. package/src/tool/code_find/guidance.ts +8 -0
  79. package/src/tool/{find → code_find}/render.ts +1 -1
  80. package/src/tool/{result/find.ts → code_find/result.ts} +36 -11
  81. package/src/tool/code_find/spec.ts +37 -0
  82. package/src/tool/code_graph/execute.ts +24 -0
  83. package/src/tool/code_graph/guidance.ts +6 -0
  84. package/src/tool/{graph → code_graph}/markdown.ts +1 -1
  85. package/src/tool/{result/graph.ts → code_graph/result.ts} +69 -4
  86. package/src/tool/code_graph/spec.ts +39 -0
  87. package/src/tool/{health → code_health}/execute.ts +2 -18
  88. package/src/tool/code_health/guidance.ts +8 -0
  89. package/src/tool/{health → code_health}/markdown.ts +68 -18
  90. package/src/tool/{result/health.ts → code_health/result.ts} +29 -4
  91. package/src/tool/code_health/spec.ts +41 -0
  92. package/src/tool/code_inspect/execute.ts +20 -0
  93. package/src/tool/code_inspect/guidance.ts +6 -0
  94. package/src/tool/{inspect → code_inspect}/markdown.ts +1 -1
  95. package/src/tool/{result/inspect.ts → code_inspect/result.ts} +32 -3
  96. package/src/tool/code_inspect/spec.ts +25 -0
  97. package/src/tool/code_orientation/execute.ts +25 -0
  98. package/src/tool/code_orientation/guidance.ts +9 -0
  99. package/src/tool/{orientation → code_orientation}/markdown.ts +1 -1
  100. package/src/tool/{result/orientation.ts → code_orientation/result.ts} +67 -3
  101. package/src/tool/code_orientation/spec.ts +25 -0
  102. package/src/tool/code_refactor_apply/execute.ts +17 -0
  103. package/src/tool/code_refactor_apply/guidance.ts +5 -0
  104. package/src/tool/{refactor-apply/execute.ts → code_refactor_apply/result.ts} +5 -11
  105. package/src/tool/code_refactor_apply/spec.ts +26 -0
  106. package/src/tool/code_refactor_plan/execute.ts +27 -0
  107. package/src/tool/code_refactor_plan/guidance.ts +8 -0
  108. package/src/tool/{refactor-plan/execute.ts → code_refactor_plan/result.ts} +9 -22
  109. package/src/tool/code_refactor_plan/spec.ts +25 -0
  110. package/src/tool/code_resolve/execute.ts +19 -0
  111. package/src/tool/code_resolve/guidance.ts +8 -0
  112. package/src/tool/{resolve → code_resolve}/markdown.ts +1 -1
  113. package/src/tool/{result/resolve.ts → code_resolve/result.ts} +37 -24
  114. package/src/tool/code_resolve/spec.ts +25 -0
  115. package/src/tool/guidance.ts +71 -52
  116. package/src/tool/infra/truncate.ts +40 -0
  117. package/src/tool/{refactor-plan/markdown.ts → refactor-markdown.ts} +4 -7
  118. package/src/tool/register.ts +9 -97
  119. package/src/tool/result/refactor.ts +1 -4
  120. package/src/tool/schemas.ts +26 -157
  121. package/src/tool/specs.ts +40 -126
  122. package/src/tool/find/execute.ts +0 -43
  123. package/src/tool/graph/execute.ts +0 -82
  124. package/src/tool/inspect/execute.ts +0 -40
  125. package/src/tool/orientation/execute.ts +0 -80
  126. package/src/tool/resolve/execute.ts +0 -53
  127. /package/src/tool/{find → code_find}/ast-kinds.ts +0 -0
  128. /package/src/tool/{find → code_find}/markdown.ts +0 -0
  129. /package/src/tool/{find → code_find}/modes.ts +0 -0
  130. /package/src/tool/{find → code_find}/tui.ts +0 -0
  131. /package/src/tool/{graph → code_graph}/tui.ts +0 -0
  132. /package/src/tool/{health → code_health}/refresh-status.ts +0 -0
  133. /package/src/tool/{health → code_health}/semantic-state.ts +0 -0
  134. /package/src/tool/{health → code_health}/tui.ts +0 -0
  135. /package/src/tool/{inspect → code_inspect}/tui.ts +0 -0
  136. /package/src/tool/{orientation → code_orientation}/tui.ts +0 -0
  137. /package/src/tool/{refactor-apply → code_refactor_apply}/tui.ts +0 -0
  138. /package/src/tool/{refactor-plan → code_refactor_plan}/tui.ts +0 -0
  139. /package/src/tool/{resolve → code_resolve}/tui.ts +0 -0
@@ -1,10 +1,7 @@
1
- import { renderEvidenceListDisclosure } from "../../analysis/evidence.ts";
2
- import { toDisplayPath } from "../../analysis/search/paths.ts";
3
- import { assembledNextQueries } from "../result/assembly.ts";
4
- import type {
5
- RefactorApplyResultAssembly,
6
- RefactorPlanResultAssembly,
7
- } from "../result/refactor.ts";
1
+ import { renderEvidenceListDisclosure } from "../analysis/evidence.ts";
2
+ import { toDisplayPath } from "../analysis/search/paths.ts";
3
+ import { assembledNextQueries } from "./result/assembly.ts";
4
+ import type { RefactorApplyResultAssembly, RefactorPlanResultAssembly } from "./result/refactor.ts";
8
5
 
9
6
  /** Render a refactor plan from its canonical assembled evidence. */
10
7
  export function renderRefactorPlanResult(assembly: RefactorPlanResultAssembly): string {
@@ -1,77 +1,15 @@
1
1
  import { createHmac, randomBytes } from "node:crypto";
2
- import { mkdtempSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
2
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
6
- import type { Component } from "@earendil-works/pi-tui";
7
3
  import { recordDebugEvent, startDebugTimer } from "@mrclrchtr/supi-core/debug";
8
4
  import { truncateIdentity } from "@mrclrchtr/supi-lsp/debug-telemetry";
9
5
  import type { WorkspaceCodeIntelligenceSession } from "../session/session.ts";
10
- import type { CodeIntelResult, ToolOutputTruncationDetails } from "../types/index.ts";
11
- import { renderFindCall, renderFindResult } from "./find/tui.ts";
12
- import { renderGraphCall, renderGraphResult } from "./graph/tui.ts";
13
6
  import {
14
7
  CODE_INTELLIGENCE_TOOL_PROMPT_SURFACES,
15
8
  type CodeIntelligenceToolPromptSurfaceMap,
16
9
  } from "./guidance.ts";
17
- import { renderHealthCall, renderHealthResult } from "./health/tui.ts";
18
- import { truncateToolContent } from "./infra/truncate.ts";
19
- import { renderInspectCall, renderInspectResult } from "./inspect/tui.ts";
20
- import { renderOrientationCall, renderOrientationResult } from "./orientation/tui.ts";
21
- import { renderRefactorApplyCall, renderRefactorApplyResult } from "./refactor-apply/tui.ts";
22
- import { renderRefactorPlanCall, renderRefactorPlanResult } from "./refactor-plan/tui.ts";
23
- import { renderResolveCall, renderResolveResult } from "./resolve/tui.ts";
10
+ import { boundCodeToolResult } from "./infra/truncate.ts";
24
11
  import { CODE_INTELLIGENCE_TOOL_SPECS, type CodeIntelligenceToolDefinitionSpec } from "./specs.ts";
25
12
 
26
- const TOOL_OUTPUT_CONTRACT =
27
- " Output over 2000 lines or 50KB is truncated, with full Markdown saved to a temporary file.";
28
-
29
- interface ToolRenderer {
30
- // biome-ignore lint/suspicious/noExplicitAny: pi render call/result signatures vary per tool; spread into pi.registerTool where concrete typing handles variance
31
- renderCall?: (...args: any[]) => Component;
32
- // biome-ignore lint/suspicious/noExplicitAny: same variance reason as renderCall
33
- renderResult?: (...args: any[]) => Component;
34
- renderShell?: "self";
35
- }
36
-
37
- function getToolRenderer(name: string): ToolRenderer {
38
- switch (name) {
39
- case "code_graph":
40
- return {
41
- renderCall: renderGraphCall,
42
- renderResult: renderGraphResult,
43
- };
44
- case "code_health":
45
- return {
46
- renderCall: renderHealthCall,
47
- renderResult: renderHealthResult,
48
- };
49
- case "code_orientation":
50
- return {
51
- renderCall: renderOrientationCall,
52
- renderResult: renderOrientationResult,
53
- };
54
- case "code_resolve":
55
- return { renderCall: renderResolveCall, renderResult: renderResolveResult };
56
- case "code_inspect":
57
- return { renderCall: renderInspectCall, renderResult: renderInspectResult };
58
- case "code_find":
59
- return { renderCall: renderFindCall, renderResult: renderFindResult };
60
- case "code_refactor_plan":
61
- return {
62
- renderCall: renderRefactorPlanCall,
63
- renderResult: renderRefactorPlanResult,
64
- };
65
- case "code_refactor_apply":
66
- return {
67
- renderCall: renderRefactorApplyCall,
68
- renderResult: renderRefactorApplyResult,
69
- };
70
- default:
71
- return {};
72
- }
73
- }
74
-
75
13
  /**
76
14
  * Register the focused code-intelligence tool surface from shared specs.
77
15
  *
@@ -125,13 +63,6 @@ function recordCodeWorkflowTiming(
125
63
  );
126
64
  }
127
65
 
128
- function withTruncationDetails(
129
- details: CodeIntelResult["details"],
130
- truncation: ToolOutputTruncationDetails,
131
- ): CodeIntelResult["details"] {
132
- return details ? { ...details, truncation } : details;
133
- }
134
-
135
66
  function terminalCodeOperationOutcome(
136
67
  error: unknown,
137
68
  signal: AbortSignal | undefined,
@@ -166,7 +97,7 @@ export function registerCodeIntelligenceTools(
166
97
  pi.registerTool({
167
98
  name: spec.name,
168
99
  label: spec.label,
169
- description: surface.description + TOOL_OUTPUT_CONTRACT,
100
+ description: surface.description,
170
101
  promptSnippet: surface.promptSnippet,
171
102
  promptGuidelines: surface.promptGuidelines,
172
103
  parameters: spec.parameters,
@@ -191,35 +122,15 @@ export function registerCodeIntelligenceTools(
191
122
  cwd: ctx.cwd,
192
123
  outcome: "completed",
193
124
  });
194
- const { text, truncated } = truncateToolContent(content, {
195
- maxLines: spec.maxLines,
196
- maxBytes: spec.maxBytes,
197
- });
198
- if (truncated && content.length > 0) {
199
- const dir = mkdtempSync(join(tmpdir(), "supi-ci-"));
200
- const spillPath = join(dir, `${spec.name}-output.md`);
201
- writeFileSync(spillPath, content, "utf-8");
202
- const notice = `\n_Full output saved to: \`${spillPath}\`_`;
203
- recordCodeOperationBoundary("code-operation.finish", operationId, spec.name, {
204
- cwd: ctx.cwd,
205
- outcome: "completed",
206
- });
207
- return {
208
- content: [{ type: "text" as const, text: text + notice }],
209
- details: withTruncationDetails(details, {
210
- truncated: true,
211
- fullOutputPath: spillPath,
212
- }),
213
- };
214
- }
215
125
  recordCodeOperationBoundary("code-operation.finish", operationId, spec.name, {
216
126
  cwd: ctx.cwd,
217
127
  outcome: "completed",
218
128
  });
219
- return {
220
- content: [{ type: "text" as const, text }],
221
- details: withTruncationDetails(details, { truncated: false }),
222
- };
129
+ return boundCodeToolResult(content, details, {
130
+ toolName: spec.name,
131
+ maxLines: spec.maxLines,
132
+ maxBytes: spec.maxBytes,
133
+ });
223
134
  } catch (error) {
224
135
  const outcome = terminalCodeOperationOutcome(error, signal);
225
136
  recordCodeWorkflowTiming(workflowTimer, operationId, spec.name, {
@@ -233,7 +144,8 @@ export function registerCodeIntelligenceTools(
233
144
  throw error;
234
145
  }
235
146
  },
236
- ...getToolRenderer(spec.name),
147
+ renderCall: spec.renderCall,
148
+ renderResult: spec.renderResult,
237
149
  });
238
150
  }
239
151
  }
@@ -109,10 +109,7 @@ export function assembleRefactorApplyDetails(
109
109
  provenance,
110
110
  },
111
111
  ],
112
- nextQueries:
113
- applyResult.kind === "applied"
114
- ? ["Use code_health to check for new issues after the refactor"]
115
- : [],
112
+ nextQueries: [],
116
113
  candidateCount,
117
114
  confidence: applyResult.kind === "applied" ? "semantic" : "unavailable",
118
115
  provenance,
@@ -1,22 +1,19 @@
1
1
  import { StringEnum } from "@earendil-works/pi-ai";
2
2
  import { type TSchema, Type } from "typebox";
3
3
  import { TARGET_SYMBOL_KINDS } from "../session/target-input.ts";
4
- import type { CodeIntelligenceToolName } from "../types/index.ts";
5
- import { CODE_FIND_AST_KINDS } from "./find/ast-kinds.ts";
6
- import { CODE_FIND_MODES } from "./find/modes.ts";
7
4
 
8
- const ScopeParam = Type.String({
5
+ export const ScopeParam = Type.String({
9
6
  description: "Workspace-relative file or directory scope.",
10
7
  });
11
- const FindScopeParam = Type.Array(
8
+ export const FindScopeParam = Type.Array(
12
9
  Type.String({ description: "Workspace-relative search scope." }),
13
10
  {
14
11
  description: "One or more workspace-relative search scopes.",
15
12
  minItems: 1,
16
13
  },
17
14
  );
18
- const FileParam = Type.String({ description: "Target file path." });
19
- const QueryParam = Type.String({
15
+ const FileParam = Type.String({ description: "File path." });
16
+ export const QueryParam = Type.String({
20
17
  description: "Human or code reference to resolve or search for.",
21
18
  minLength: 1,
22
19
  });
@@ -25,14 +22,14 @@ const CharacterParam = Type.Integer({
25
22
  description: "1-based UTF-16 column.",
26
23
  minimum: 1,
27
24
  });
28
- const MaxResultsParam = Type.Integer({
25
+ export const MaxResultsParam = Type.Integer({
29
26
  description: "Maximum displayed results.",
30
27
  minimum: 1,
31
28
  });
32
29
 
33
- const SourcePointParam = Type.Object(
30
+ export const SourcePointParam = Type.Object(
34
31
  { file: FileParam, line: LineParam, character: CharacterParam },
35
- { description: "A precise 1-based source point.", additionalProperties: false },
32
+ { additionalProperties: false },
36
33
  );
37
34
 
38
35
  const SymbolTargetParam = Type.Object(
@@ -41,12 +38,12 @@ const SymbolTargetParam = Type.Object(
41
38
  scope: Type.Optional(ScopeParam),
42
39
  symbolKind: Type.Optional(
43
40
  StringEnum(TARGET_SYMBOL_KINDS, {
44
- description: "Exact provider-reported LSP SymbolKind filter; omit when uncertain.",
41
+ description: "LSP SymbolKind filter; omit when uncertain.",
45
42
  }),
46
43
  ),
47
44
  },
48
45
  {
49
- description: "Semantic symbol query and optional workspace-relative scope.",
46
+ description: "Semantic symbol query.",
50
47
  additionalProperties: false,
51
48
  },
52
49
  );
@@ -68,22 +65,22 @@ function exactOneSelector(properties: Record<string, TSchema>, description: stri
68
65
  });
69
66
  }
70
67
 
71
- const ResolveTargetParam = exactOneSelector(
68
+ export const ResolveTargetParam = exactOneSelector(
72
69
  {
73
70
  anchor: SourcePointParam,
74
71
  symbol: SymbolTargetParam,
75
72
  file: FileParam,
76
73
  },
77
- "Exactly one target source: provider-backed anchor, semantic symbol query, or file declaration group.",
74
+ "Exactly one: anchor, symbol query, or file declaration group.",
78
75
  );
79
76
 
80
- const GraphTargetParam = exactOneSelector(
77
+ export const GraphTargetParam = exactOneSelector(
81
78
  {
82
79
  handle: Type.String({ description: "Target handle returned by code_resolve." }),
83
80
  anchor: SourcePointParam,
84
81
  symbol: SymbolTargetParam,
85
82
  },
86
- "Exactly one graph target: handle, provider-backed anchor, or semantic symbol query.",
83
+ "Exactly one graph target.",
87
84
  );
88
85
 
89
86
  const OrientationTargetParam = exactOneSelector(
@@ -92,10 +89,10 @@ const OrientationTargetParam = exactOneSelector(
92
89
  anchor: SourcePointParam,
93
90
  symbol: SymbolTargetParam,
94
91
  },
95
- "Exactly one precise Orientation target: handle, provider-backed anchor, or semantic symbol query.",
92
+ "Exactly one Orientation target.",
96
93
  );
97
94
 
98
- const OrientationFocusParam = exactOneSelector(
95
+ export const OrientationFocusParam = exactOneSelector(
99
96
  {
100
97
  path: Type.String({
101
98
  description: "Workspace-relative project, package, directory, or file path.",
@@ -103,15 +100,15 @@ const OrientationFocusParam = exactOneSelector(
103
100
  module: Type.String({ description: "Discovered module name." }),
104
101
  target: OrientationTargetParam,
105
102
  },
106
- "Exactly one Orientation focus: path, discovered module, or precise target.",
103
+ "Exactly one Orientation focus.",
107
104
  );
108
105
 
109
- const RefactorTargetParam = exactOneSelector(
106
+ export const RefactorTargetParam = exactOneSelector(
110
107
  {
111
108
  handle: Type.String({ description: "Target handle returned by code_resolve." }),
112
109
  anchor: SourcePointParam,
113
110
  },
114
- "Exactly one refactor target: handle or provider-backed anchor.",
111
+ "Exactly one refactor target.",
115
112
  );
116
113
 
117
114
  const RangeParam = Type.Object(
@@ -125,153 +122,25 @@ const RangeParam = Type.Object(
125
122
  { additionalProperties: false },
126
123
  ),
127
124
  },
128
- { description: "1-based selected source range.", additionalProperties: false },
125
+ { additionalProperties: false },
129
126
  );
130
127
 
131
128
  const NewNameParam = Type.String({ description: "New symbol name.", minLength: 1 });
132
129
 
133
- const RefactorOperationParam = exactOneSelector(
130
+ export const RefactorOperationParam = exactOneSelector(
134
131
  {
135
- rename_symbol: Type.Object(
136
- { newName: NewNameParam },
137
- { description: "Rename a semantic symbol.", additionalProperties: false },
138
- ),
132
+ rename_symbol: Type.Object({ newName: NewNameParam }, { additionalProperties: false }),
139
133
  extract_function: Type.Object(
140
134
  { newName: NewNameParam, range: RangeParam },
141
- { description: "Extract the selected range into a function.", additionalProperties: false },
135
+ { additionalProperties: false },
142
136
  ),
143
137
  extract_variable: Type.Object(
144
138
  { newName: NewNameParam, range: RangeParam },
145
- { description: "Extract the selected range into a variable.", additionalProperties: false },
146
- ),
147
- },
148
- "Exactly one precise refactor operation.",
149
- );
150
-
151
- /** Resolve one target or enumerate a file declaration group as session-scoped handles. */
152
- export const CodeResolveParameters = Type.Object(
153
- {
154
- target: ResolveTargetParam,
155
- maxResults: Type.Optional(MaxResultsParam),
156
- },
157
- { additionalProperties: false },
158
- );
159
-
160
- /** Inspect one precise point. */
161
- export const CodeInspectParameters = Type.Object(
162
- {
163
- point: SourcePointParam,
164
- maxResults: Type.Optional(MaxResultsParam),
165
- },
166
- { additionalProperties: false },
167
- );
168
-
169
- /** Orient around the workspace or one exact focus. */
170
- export const CodeOrientationParameters = Type.Object(
171
- {
172
- focus: Type.Optional(OrientationFocusParam),
173
- maxResults: Type.Optional(MaxResultsParam),
174
- },
175
- { additionalProperties: false },
176
- );
177
-
178
- /** Unified structural and semantic code search. */
179
- export const CodeFindParameters = Type.Object(
180
- {
181
- query: QueryParam,
182
- scope: Type.Optional(FindScopeParam),
183
- mode: StringEnum(CODE_FIND_MODES, {
184
- description: 'Required code-aware search mode. mode:"ast" requires `kind`.',
185
- }),
186
- kind: Type.Optional(
187
- StringEnum(CODE_FIND_AST_KINDS, {
188
- description: 'AST kind; only valid with mode:"ast".',
189
- }),
190
- ),
191
- maxResults: Type.Optional(MaxResultsParam),
192
- },
193
- { additionalProperties: false },
194
- );
195
-
196
- /** Provider-backed and explicitly structural relations for one target. */
197
- export const CodeGraphParameters = Type.Object(
198
- {
199
- target: GraphTargetParam,
200
- relations: Type.Optional(
201
- Type.Array(StringEnum(["all", "references", "callees", "implements"]), {
202
- description:
203
- 'Requested relations; defaults to ["references"]. "all" must be the only item.',
204
- minItems: 1,
205
- uniqueItems: true,
206
- }),
207
- ),
208
- maxResults: Type.Optional(MaxResultsParam),
209
- calleeDepth: Type.Optional(
210
- StringEnum(["direct", "deep"], {
211
- description: '`"direct"` excludes nested scopes; `"deep"` includes them.',
212
- }),
213
- ),
214
- },
215
- { additionalProperties: false },
216
- );
217
-
218
- /** Preview one precise semantic refactor without mutating files. */
219
- export const CodeRefactorParameters = Type.Object(
220
- {
221
- target: RefactorTargetParam,
222
- operation: RefactorOperationParam,
223
- },
224
- { additionalProperties: false },
225
- );
226
-
227
- /** Apply a stored plan after freshness and fingerprint validation. */
228
- export const CodeApplyParameters = Type.Object(
229
- {
230
- planId: Type.String({
231
- description: "Stored plan identifier returned by code_refactor_plan.",
232
- minLength: 1,
233
- }),
234
- },
235
- { additionalProperties: false },
236
- );
237
-
238
- /** Report evidence-backed workspace health signals. */
239
- export const CodeHealthParameters = Type.Object(
240
- {
241
- scope: Type.Optional(ScopeParam),
242
- refresh: Type.Optional(
243
- Type.Boolean({
244
- description:
245
- "Attempt workspace-runtime diagnostic recovery before collecting health data; the result reports the established attempt outcome.",
246
- }),
247
- ),
248
- include: Type.Optional(
249
- Type.Array(
250
- StringEnum(["diagnostics", "servers"], {
251
- description: "Live health signals to include.",
252
- }),
253
- { description: "Requested health-signal sections.", uniqueItems: true },
254
- ),
255
- ),
256
- level: Type.Optional(
257
- StringEnum(["summary", "detailed"], {
258
- description: "Detail level for the health report.",
259
- }),
139
+ { additionalProperties: false },
260
140
  ),
261
141
  },
262
- { additionalProperties: false },
142
+ "Exactly one refactor operation.",
263
143
  );
264
144
 
265
- export type WorkflowCodeToolSchemaKey = CodeIntelligenceToolName;
266
-
267
- /** Code intelligence tool schemas keyed by public tool name. */
268
- export const CODE_INTELLIGENCE_TOOL_SCHEMAS = {
269
- code_resolve: CodeResolveParameters,
270
- code_inspect: CodeInspectParameters,
271
- code_orientation: CodeOrientationParameters,
272
- code_find: CodeFindParameters,
273
- code_graph: CodeGraphParameters,
274
- code_refactor_plan: CodeRefactorParameters,
275
- code_refactor_apply: CodeApplyParameters,
276
- code_health: CodeHealthParameters,
277
- } as const satisfies Record<CodeIntelligenceToolName, TSchema>;
145
+ // Per-tool parameter objects live in each tool's spec.ts; this module keeps the
146
+ // shared parameter vocabulary for the eight-tool family.
package/src/tool/specs.ts CHANGED
@@ -1,36 +1,29 @@
1
+ import type { Component } from "@earendil-works/pi-tui";
1
2
  import type { TSchema } from "typebox";
2
- import {
3
- DEFAULT_AST_SCAN_MAX_FILES,
4
- DEFAULT_AST_SCAN_TIMEOUT_MS,
5
- } from "../analysis/search/ast-scan.ts";
6
3
  import type {
7
4
  CodeIntelligenceToolName,
8
5
  CodeIntelResult,
9
6
  CodeIntelToolExecCtx,
10
7
  } from "../types/index.ts";
11
- import { executeFindTool } from "./find/execute.ts";
12
- import { executeGraphTool } from "./graph/execute.ts";
13
- import { executeHealthTool } from "./health/execute.ts";
14
- import { executeInspectTool } from "./inspect/execute.ts";
15
- import { executeOrientationTool } from "./orientation/execute.ts";
16
- import { executeRefactorApplyTool } from "./refactor-apply/execute.ts";
17
- import { executeRefactorPlanTool } from "./refactor-plan/execute.ts";
18
- import { executeResolveTool } from "./resolve/execute.ts";
19
- import {
20
- CodeApplyParameters,
21
- CodeFindParameters,
22
- CodeGraphParameters,
23
- CodeHealthParameters,
24
- CodeInspectParameters,
25
- CodeOrientationParameters,
26
- CodeRefactorParameters,
27
- CodeResolveParameters,
28
- } from "./schemas.ts";
8
+ import { codeFindSpec } from "./code_find/spec.ts";
9
+ import { codeGraphSpec } from "./code_graph/spec.ts";
10
+ import { codeHealthSpec } from "./code_health/spec.ts";
11
+ import { codeInspectSpec } from "./code_inspect/spec.ts";
12
+ import { codeOrientationSpec } from "./code_orientation/spec.ts";
13
+ import { codeRefactorApplySpec } from "./code_refactor_apply/spec.ts";
14
+ import { codeRefactorPlanSpec } from "./code_refactor_plan/spec.ts";
15
+ import { codeResolveSpec } from "./code_resolve/spec.ts";
29
16
 
30
- /** Substrate families that power a tool's implementation. */
31
- export type ToolSubstrate = "semantic" | "structural" | "search" | "diagnostics";
17
+ /**
18
+ * Canonical registration spec for one public code-intelligence tool.
19
+ *
20
+ * Model-facing prose is not part of the spec: descriptions, snippets, and
21
+ * guidelines live in each tool's `guidance.ts`, parameter mechanics live in
22
+ * each tool's `spec.ts` over the shared vocabulary in `schemas.ts`.
23
+ */
24
+ // biome-ignore lint/suspicious/noExplicitAny: pi render call/result signatures vary per tool
25
+ export type CodeToolRendererFn = (...args: any[]) => Component;
32
26
 
33
- /** Canonical registration spec for one public code-intelligence tool. */
34
27
  export interface CodeIntelligenceToolDefinitionSpec {
35
28
  name: CodeIntelligenceToolName;
36
29
  label: string;
@@ -38,109 +31,30 @@ export interface CodeIntelligenceToolDefinitionSpec {
38
31
  maxLines?: number;
39
32
  maxBytes?: number;
40
33
  run: (params: unknown, ctx: CodeIntelToolExecCtx) => Promise<CodeIntelResult> | CodeIntelResult;
41
- purpose: string;
42
- schemaDocs: string;
43
- substrates: ToolSubstrate[];
44
- nonGoals: string[];
34
+ renderCall?: CodeToolRendererFn;
35
+ renderResult?: CodeToolRendererFn;
45
36
  }
46
37
 
47
38
  /** Single source of truth for the surviving eight-tool family. */
48
39
  export const CODE_INTELLIGENCE_TOOL_SPECS = [
49
- {
50
- name: "code_resolve",
51
- label: "Code Resolve",
52
- parameters: CodeResolveParameters,
53
- run: (params, ctx) =>
54
- executeResolveTool(params as Parameters<typeof executeResolveTool>[0], ctx),
55
- purpose:
56
- "Resolve an anchor/symbol into handles or enumerate a file's declarations as a Target group.",
57
- schemaDocs: "Requires one exact target selector: anchor, symbol, or file.",
58
- substrates: ["semantic", "structural"],
59
- nonGoals: [
60
- "Handles do not persist across sessions.",
61
- "No text-search or structural-only target creation fallback.",
62
- ],
63
- },
64
- {
65
- name: "code_inspect",
66
- label: "Code Inspect",
67
- parameters: CodeInspectParameters,
68
- run: (params, ctx) =>
69
- executeInspectTool(params as Parameters<typeof executeInspectTool>[0], ctx),
70
- purpose: "Inspect one exact source point with semantic, structural, and diagnostic facts.",
71
- schemaDocs: "Requires point.file, point.line, and point.character.",
72
- substrates: ["semantic", "structural", "diagnostics"],
73
- nonGoals: ["Does not apply code actions."],
74
- },
75
- {
76
- name: "code_orientation",
77
- label: "Code Orientation",
78
- parameters: CodeOrientationParameters,
79
- run: (params, ctx) =>
80
- executeOrientationTool(params as Parameters<typeof executeOrientationTool>[0], ctx),
81
- purpose: "Orient around the workspace or one exact path, module, or target focus.",
82
- schemaDocs: "Omitted focus means workspace; otherwise focus is an exact-one selector.",
83
- substrates: ["semantic", "structural", "diagnostics"],
84
- nonGoals: ["Relation evidence belongs to code_graph.", "Health belongs to code_health."],
85
- },
86
- {
87
- name: "code_graph",
88
- label: "Code Graph",
89
- parameters: CodeGraphParameters,
90
- run: (params, ctx) => executeGraphTool(params as Parameters<typeof executeGraphTool>[0], ctx),
91
- purpose: "Collect references, structural callees, and implementations for one exact target.",
92
- schemaDocs:
93
- "Target is handle, anchor, or symbol; all expands to the three surviving relations.",
94
- substrates: ["semantic", "structural"],
95
- nonGoals: ["No inferred tests.", "No file-level import/export inventories."],
96
- },
97
- {
98
- name: "code_find",
99
- label: "Code Find",
100
- parameters: CodeFindParameters,
101
- run: (params, ctx) => executeFindTool(params as Parameters<typeof executeFindTool>[0], ctx),
102
- purpose: "Search structural source shape or semantic workspace symbols explicitly.",
103
- schemaDocs: `Requires query and ast/semantic mode; scope is optional and AST mode requires kind. AST enumeration uses a shared ${DEFAULT_AST_SCAN_TIMEOUT_MS / 1_000}-second deadline, a ${DEFAULT_AST_SCAN_MAX_FILES}-file cap, and canonical scope deduplication.`,
104
- substrates: ["semantic", "structural"],
105
- nonGoals: [
106
- "No literal or regex text search; use PI grep when active.",
107
- "No natural-language retrieval.",
108
- "No silent mode fallback.",
109
- ],
110
- },
111
- {
112
- name: "code_health",
113
- label: "Code Health",
114
- parameters: CodeHealthParameters,
115
- run: (params, ctx) => executeHealthTool(params as Parameters<typeof executeHealthTool>[0], ctx),
116
- purpose: "Report live diagnostic, runtime, and structural health observations.",
117
- schemaDocs: "Optional scope, refresh, include, and level; diagnostics and servers are default.",
118
- substrates: ["semantic", "structural", "diagnostics"],
119
- nonGoals: [
120
- "Does not run tests or verification commands.",
121
- "Does not load precomputed coverage or unused-code reports.",
122
- ],
123
- },
124
- {
125
- name: "code_refactor_plan",
126
- label: "Code Refactor Plan",
127
- parameters: CodeRefactorParameters,
128
- run: (params, ctx) =>
129
- executeRefactorPlanTool(params as Parameters<typeof executeRefactorPlanTool>[0], ctx),
130
- purpose: "Create a precise, non-mutating semantic refactor plan.",
131
- schemaDocs: "Requires one handle/anchor target and one exact operation payload.",
132
- substrates: ["semantic"],
133
- nonGoals: ["Never mutates files.", "No heuristic text edits."],
134
- },
135
- {
136
- name: "code_refactor_apply",
137
- label: "Code Refactor Apply",
138
- parameters: CodeApplyParameters,
139
- run: (params, ctx) =>
140
- executeRefactorApplyTool(params as Parameters<typeof executeRefactorApplyTool>[0], ctx),
141
- purpose: "Apply one stored, fingerprint-checked refactor plan.",
142
- schemaDocs: "Requires the planId returned by code_refactor_plan.",
143
- substrates: ["structural"],
144
- nonGoals: ["Does not compose plans.", "Does not bypass freshness checks."],
145
- },
40
+ codeResolveSpec,
41
+ codeInspectSpec,
42
+ codeOrientationSpec,
43
+ codeGraphSpec,
44
+ codeFindSpec,
45
+ codeHealthSpec,
46
+ codeRefactorPlanSpec,
47
+ codeRefactorApplySpec,
146
48
  ] as const satisfies readonly CodeIntelligenceToolDefinitionSpec[];
49
+
50
+ /** Code intelligence tool schemas keyed by public tool name. */
51
+ export const CODE_INTELLIGENCE_TOOL_SCHEMAS = {
52
+ code_resolve: codeResolveSpec.parameters,
53
+ code_inspect: codeInspectSpec.parameters,
54
+ code_orientation: codeOrientationSpec.parameters,
55
+ code_find: codeFindSpec.parameters,
56
+ code_graph: codeGraphSpec.parameters,
57
+ code_refactor_plan: codeRefactorPlanSpec.parameters,
58
+ code_refactor_apply: codeRefactorApplySpec.parameters,
59
+ code_health: codeHealthSpec.parameters,
60
+ } as const satisfies Record<CodeIntelligenceToolName, TSchema>;