@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
@@ -14,9 +14,13 @@ import {
14
14
  assembleToolResult,
15
15
  type ResultSection,
16
16
  type ToolResultAssembly,
17
- } from "./assembly.ts";
18
- import { createToolDisplaySection } from "./display.ts";
19
- import type { ContextDetails, OrientationSectionDetails, ToolDisplaySection } from "./types.ts";
17
+ } from "../result/assembly.ts";
18
+ import { createToolDisplaySection } from "../result/display.ts";
19
+ import type {
20
+ ContextDetails,
21
+ OrientationSectionDetails,
22
+ ToolDisplaySection,
23
+ } from "../result/types.ts";
20
24
 
21
25
  export interface OrientationDetailsInput {
22
26
  readonly confidence: ConfidenceMode;
@@ -182,3 +186,63 @@ function uniqueProvenance(sections: readonly OrientationSectionData[]) {
182
186
  }),
183
187
  );
184
188
  }
189
+
190
+ import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
191
+ import { contextErrorResult } from "../result/errors.ts";
192
+ import { renderOrientationResult } from "./markdown.ts";
193
+
194
+ type OrientationOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["orient"]>>;
195
+
196
+ /** Assemble the final model-visible code_orientation result for one workflow outcome. */
197
+ export function finishOrientationResult(outcome: OrientationOutcome): CodeIntelResult {
198
+ if (outcome.kind === "unavailable") throw new Error(outcome.reason);
199
+ if (outcome.kind === "invalid-input") {
200
+ return contextErrorResult(`**Error:** ${outcome.message}`, {
201
+ nextQueries: ["Choose an existing path, module, or precise target"],
202
+ message: outcome.message,
203
+ });
204
+ }
205
+ if (outcome.kind === "disambiguation" || outcome.kind === "kind-mismatch") {
206
+ const candidates = outcome.candidates ?? [];
207
+ const lines = [
208
+ outcome.kind === "kind-mismatch"
209
+ ? `# No Orientation target matched provider kind \`${outcome.requestedKind}\``
210
+ : "# Multiple Orientation targets",
211
+ "",
212
+ ];
213
+ for (const candidate of candidates) {
214
+ lines.push(
215
+ `${candidate.rank}. **${candidate.name}** (\`${candidate.kind ?? "unknown"}\`) — \`${candidate.file}\`:${candidate.line}:${candidate.character} — \`${candidate.targetId}\``,
216
+ );
217
+ }
218
+ const nextQueries =
219
+ outcome.kind === "kind-mismatch"
220
+ ? ["Retry without symbolKind, use an observed provider kind, or focus one handle"]
221
+ : ["Use one candidate handle as focus.target.handle"];
222
+ const details = assembleOrientationDetails({
223
+ confidence: "semantic",
224
+ omittedCount: outcome.omittedCount,
225
+ candidates,
226
+ nextQueries,
227
+ });
228
+ return {
229
+ content: lines.join("\n"),
230
+ details: {
231
+ type: "context",
232
+ data: details,
233
+ status: "completed",
234
+ displaySections: orientationCandidateDisplaySections(candidates, outcome.omittedCount),
235
+ },
236
+ };
237
+ }
238
+ const assembly = assembleOrientationResult(outcome.data);
239
+ return {
240
+ content: renderOrientationResult(assembly),
241
+ details: {
242
+ type: "context",
243
+ data: assembly.details,
244
+ status: "completed",
245
+ displaySections: assembly.displaySections,
246
+ },
247
+ };
248
+ }
@@ -0,0 +1,25 @@
1
+ import { Type } from "typebox";
2
+ import type { CodeIntelToolExecCtx } from "../../types/index.ts";
3
+ import { MaxResultsParam, OrientationFocusParam } from "../schemas.ts";
4
+ import { executeOrientationTool } from "./execute.ts";
5
+ import { renderOrientationCall, renderOrientationResult } from "./tui.ts";
6
+
7
+ export const CODE_ORIENTATION_TOOL_NAME = "code_orientation";
8
+ export const CODE_ORIENTATION_TOOL_LABEL = "Code Orientation";
9
+
10
+ /** Canonical provider-facing metadata for the code_orientation tool. */
11
+ export const codeOrientationSpec = {
12
+ name: CODE_ORIENTATION_TOOL_NAME,
13
+ label: CODE_ORIENTATION_TOOL_LABEL,
14
+ parameters: Type.Object(
15
+ {
16
+ focus: Type.Optional(OrientationFocusParam),
17
+ maxResults: Type.Optional(MaxResultsParam),
18
+ },
19
+ { additionalProperties: false },
20
+ ),
21
+ run: (params: unknown, ctx: CodeIntelToolExecCtx) =>
22
+ executeOrientationTool(params as Parameters<typeof executeOrientationTool>[0], ctx),
23
+ renderCall: renderOrientationCall,
24
+ renderResult: renderOrientationResult,
25
+ } as const;
@@ -0,0 +1,17 @@
1
+ /** Thin Pi adapter for session-owned refactor application. */
2
+
3
+ import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
4
+ import { toWorkflowControl } from "../infra/workflow-control.ts";
5
+ import { finishRefactorApplyResult } from "./result.ts";
6
+
7
+ export interface CodeRefactorApplyToolParams {
8
+ planId: string;
9
+ }
10
+
11
+ export async function executeRefactorApplyTool(
12
+ params: CodeRefactorApplyToolParams,
13
+ ctx: CodeIntelToolExecCtx,
14
+ ): Promise<CodeIntelResult> {
15
+ const outcome = await ctx.session.applyRefactor(params, toWorkflowControl(ctx));
16
+ return finishRefactorApplyResult(outcome);
17
+ }
@@ -0,0 +1,5 @@
1
+ export const toolDescription = "Apply one stored refactor plan by planId.";
2
+
3
+ export const promptSnippet = "apply a fresh stored refactor plan";
4
+
5
+ export const promptGuidelines: string[] = [];
@@ -1,20 +1,14 @@
1
- /** Thin Pi adapter for session-owned refactor application. */
1
+ /** Result assembly for code_refactor_apply. */
2
2
 
3
3
  import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
4
- import { toWorkflowControl } from "../infra/workflow-control.ts";
5
- import { renderRefactorApplyResult } from "../refactor-plan/markdown.ts";
4
+ import { renderRefactorApplyResult } from "../refactor-markdown.ts";
6
5
  import { searchErrorResult } from "../result/errors.ts";
7
6
  import { assembleRefactorApplyDetails } from "../result/refactor.ts";
8
7
 
9
- export interface CodeRefactorApplyToolParams {
10
- planId: string;
11
- }
8
+ type RefactorApplyOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["applyRefactor"]>>;
12
9
 
13
- export async function executeRefactorApplyTool(
14
- params: CodeRefactorApplyToolParams,
15
- ctx: CodeIntelToolExecCtx,
16
- ): Promise<CodeIntelResult> {
17
- const outcome = await ctx.session.applyRefactor(params, toWorkflowControl(ctx));
10
+ /** Assemble the final model-visible code_refactor_apply result for one workflow outcome. */
11
+ export function finishRefactorApplyResult(outcome: RefactorApplyOutcome): CodeIntelResult {
18
12
  if (outcome.kind === "unavailable") throw new Error(outcome.reason);
19
13
  if (outcome.kind === "invalid-input") {
20
14
  return searchErrorResult(`**Error:** ${outcome.message}`, {
@@ -0,0 +1,26 @@
1
+ import { Type } from "typebox";
2
+ import type { CodeIntelToolExecCtx } from "../../types/index.ts";
3
+ import { executeRefactorApplyTool } from "./execute.ts";
4
+ import { renderRefactorApplyCall, renderRefactorApplyResult } from "./tui.ts";
5
+
6
+ export const CODE_REFACTOR_APPLY_TOOL_NAME = "code_refactor_apply";
7
+ export const CODE_REFACTOR_APPLY_TOOL_LABEL = "Code Refactor Apply";
8
+
9
+ /** Canonical provider-facing metadata for the code_refactor_apply tool. */
10
+ export const codeRefactorApplySpec = {
11
+ name: CODE_REFACTOR_APPLY_TOOL_NAME,
12
+ label: CODE_REFACTOR_APPLY_TOOL_LABEL,
13
+ parameters: Type.Object(
14
+ {
15
+ planId: Type.String({
16
+ description: "planId returned by code_refactor_plan.",
17
+ minLength: 1,
18
+ }),
19
+ },
20
+ { additionalProperties: false },
21
+ ),
22
+ run: (params: unknown, ctx: CodeIntelToolExecCtx) =>
23
+ executeRefactorApplyTool(params as Parameters<typeof executeRefactorApplyTool>[0], ctx),
24
+ renderCall: renderRefactorApplyCall,
25
+ renderResult: renderRefactorApplyResult,
26
+ } as const;
@@ -0,0 +1,27 @@
1
+ /** Thin Pi adapter for session-owned refactor planning. */
2
+
3
+ import type {
4
+ RefactorOperationInput,
5
+ RefactorPlanWorkflowInput,
6
+ } from "../../session/refactor-types.ts";
7
+ import type { RefactorTargetInput } from "../../session/target-input.ts";
8
+ import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
9
+ import { toWorkflowControl } from "../infra/workflow-control.ts";
10
+ import { finishRefactorPlanResult } from "./result.ts";
11
+
12
+ export interface CodeRefactorPlanToolParams {
13
+ target: RefactorTargetInput;
14
+ operation: RefactorOperationInput;
15
+ }
16
+
17
+ export async function executeRefactorPlanTool(
18
+ params: CodeRefactorPlanToolParams,
19
+ ctx: CodeIntelToolExecCtx,
20
+ _invokedAs: "code_refactor_plan" = "code_refactor_plan",
21
+ ): Promise<CodeIntelResult> {
22
+ const outcome = await ctx.session.planRefactor(
23
+ params as RefactorPlanWorkflowInput,
24
+ toWorkflowControl(ctx),
25
+ );
26
+ return finishRefactorPlanResult(outcome, ctx.cwd);
27
+ }
@@ -0,0 +1,8 @@
1
+ export const toolDescription =
2
+ "Preview one semantic rename or extraction and return a planId without mutating files.";
3
+
4
+ export const promptSnippet = "preview a precise semantic refactor";
5
+
6
+ export const promptGuidelines = [
7
+ "Use code_refactor_plan for preview only, then call code_refactor_apply with its planId.",
8
+ ];
@@ -1,30 +1,17 @@
1
- /** Thin Pi adapter for session-owned refactor planning. */
1
+ /** Result assembly for code_refactor_plan. */
2
2
 
3
- import type {
4
- RefactorOperationInput,
5
- RefactorPlanWorkflowInput,
6
- } from "../../session/refactor-types.ts";
7
- import type { RefactorTargetInput } from "../../session/target-input.ts";
8
3
  import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
9
- import { toWorkflowControl } from "../infra/workflow-control.ts";
4
+ import { renderRefactorPlanResult } from "../refactor-markdown.ts";
10
5
  import { searchErrorResult } from "../result/errors.ts";
11
6
  import { assembleRefactorPlanDetails } from "../result/refactor.ts";
12
- import { renderRefactorPlanResult } from "./markdown.ts";
13
7
 
14
- export interface CodeRefactorPlanToolParams {
15
- target: RefactorTargetInput;
16
- operation: RefactorOperationInput;
17
- }
8
+ type RefactorPlanOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["planRefactor"]>>;
18
9
 
19
- export async function executeRefactorPlanTool(
20
- params: CodeRefactorPlanToolParams,
21
- ctx: CodeIntelToolExecCtx,
22
- _invokedAs: "code_refactor_plan" = "code_refactor_plan",
23
- ): Promise<CodeIntelResult> {
24
- const outcome = await ctx.session.planRefactor(
25
- params as RefactorPlanWorkflowInput,
26
- toWorkflowControl(ctx),
27
- );
10
+ /** Assemble the final model-visible code_refactor_plan result for one workflow outcome. */
11
+ export function finishRefactorPlanResult(
12
+ outcome: RefactorPlanOutcome,
13
+ cwd: string,
14
+ ): CodeIntelResult {
28
15
  if (outcome.kind === "unavailable") throw new Error(outcome.reason);
29
16
  if (outcome.kind === "invalid-input") {
30
17
  return searchErrorResult(`**Error:** ${outcome.message}`, {
@@ -45,7 +32,7 @@ export async function executeRefactorPlanTool(
45
32
  });
46
33
  }
47
34
 
48
- const assembly = assembleRefactorPlanDetails(outcome.plan, ctx.cwd);
35
+ const assembly = assembleRefactorPlanDetails(outcome.plan, cwd);
49
36
  return {
50
37
  content: renderRefactorPlanResult(assembly),
51
38
  details: {
@@ -0,0 +1,25 @@
1
+ import { Type } from "typebox";
2
+ import type { CodeIntelToolExecCtx } from "../../types/index.ts";
3
+ import { RefactorOperationParam, RefactorTargetParam } from "../schemas.ts";
4
+ import { executeRefactorPlanTool } from "./execute.ts";
5
+ import { renderRefactorPlanCall, renderRefactorPlanResult } from "./tui.ts";
6
+
7
+ export const CODE_REFACTOR_PLAN_TOOL_NAME = "code_refactor_plan";
8
+ export const CODE_REFACTOR_PLAN_TOOL_LABEL = "Code Refactor Plan";
9
+
10
+ /** Canonical provider-facing metadata for the code_refactor_plan tool. */
11
+ export const codeRefactorPlanSpec = {
12
+ name: CODE_REFACTOR_PLAN_TOOL_NAME,
13
+ label: CODE_REFACTOR_PLAN_TOOL_LABEL,
14
+ parameters: Type.Object(
15
+ {
16
+ target: RefactorTargetParam,
17
+ operation: RefactorOperationParam,
18
+ },
19
+ { additionalProperties: false },
20
+ ),
21
+ run: (params: unknown, ctx: CodeIntelToolExecCtx) =>
22
+ executeRefactorPlanTool(params as Parameters<typeof executeRefactorPlanTool>[0], ctx),
23
+ renderCall: renderRefactorPlanCall,
24
+ renderResult: renderRefactorPlanResult,
25
+ } as const;
@@ -0,0 +1,19 @@
1
+ /** Thin Pi adapter for code_resolve. */
2
+
3
+ import type { ResolveTargetInput } from "../../session/target-input.ts";
4
+ import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
5
+ import { toWorkflowControl } from "../infra/workflow-control.ts";
6
+ import { finishResolveResult } from "./result.ts";
7
+
8
+ export interface CodeResolveToolParams {
9
+ target: ResolveTargetInput;
10
+ maxResults?: number;
11
+ }
12
+
13
+ export async function executeResolveTool(
14
+ params: CodeResolveToolParams,
15
+ ctx: CodeIntelToolExecCtx,
16
+ ): Promise<CodeIntelResult> {
17
+ const outcome = await ctx.session.resolve(params, toWorkflowControl(ctx));
18
+ return finishResolveResult(outcome, ctx.cwd);
19
+ }
@@ -0,0 +1,8 @@
1
+ export const toolDescription =
2
+ "Resolve one provider-backed anchor or semantic symbol query to session handles, or enumerate a file's declarations as a bounded Target group. Anchors must identify real symbols";
3
+
4
+ export const promptSnippet = "resolve a precise target or enumerate a file’s target group";
5
+
6
+ export const promptGuidelines = [
7
+ "Use code_resolve when a symbol query may be ambiguous, when later calls should share a stable target handle, or when a known file’s declarations should be enumerated.",
8
+ ];
@@ -3,8 +3,8 @@
3
3
  import { relative } from "node:path";
4
4
  import { renderEvidenceListMetadataDisclosure } from "../../analysis/evidence.ts";
5
5
  import type { TargetStoreEntry } from "../../session/target-store.ts";
6
- import type { ResolveResultAssembly } from "../result/resolve.ts";
7
6
  import type { ResolveDetails } from "../result/types.ts";
7
+ import type { ResolveResultAssembly } from "./result.ts";
8
8
 
9
9
  /** Render an assembled resolve result into markdown. */
10
10
  export function renderResolveResult(assembly: ResolveResultAssembly): string {
@@ -9,9 +9,9 @@ import {
9
9
  assembleToolResult,
10
10
  type ResultProvenance,
11
11
  type ToolResultAssembly,
12
- } from "./assembly.ts";
13
- import { createToolDisplaySection } from "./display.ts";
14
- import type { ResolveDetails, ToolDisplaySection } from "./types.ts";
12
+ } from "../result/assembly.ts";
13
+ import { createToolDisplaySection } from "../result/display.ts";
14
+ import type { ResolveDetails, ToolDisplaySection } from "../result/types.ts";
15
15
 
16
16
  /** Presentation-neutral assembled code_resolve result. */
17
17
  export interface ResolveResultAssembly {
@@ -105,7 +105,7 @@ function projectResolved(target: Readonly<TargetStoreEntry>, cwd: string): Resol
105
105
  omittedCount: 0,
106
106
  evidenceLists: [evidence],
107
107
  targets: [toTargetDetails(target, cwd)],
108
- nextQueries: buildResolveNextQueries(target.targetId, target.kind),
108
+ nextQueries: [],
109
109
  },
110
110
  };
111
111
  }
@@ -289,26 +289,39 @@ function resolveProvenance(outcome: TargetWorkflowOutcome): ResultProvenance[] {
289
289
  ];
290
290
  }
291
291
 
292
- /** Suggested surviving graph relations for a resolved symbol kind. */
293
- export function suggestedResolveRelations(kind: string | undefined | null): string[] {
294
- switch (kind?.toLowerCase()) {
295
- case "function":
296
- case "method":
297
- case "constructor":
298
- return ["references", "callees"];
299
- case "class":
300
- case "interface":
301
- case "type":
302
- case "enum":
303
- return ["references", "implements"];
304
- default:
305
- return ["references"];
292
+ import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
293
+ import { renderResolveResult } from "./markdown.ts";
294
+
295
+ type ResolveOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["resolve"]>>;
296
+
297
+ /** Assemble the final model-visible code_resolve result for one workflow outcome. */
298
+ export function finishResolveResult(outcome: ResolveOutcome, cwd: string): CodeIntelResult {
299
+ if (outcome.kind === "unavailable") {
300
+ throw new Error(outcome.reason);
306
301
  }
307
- }
308
302
 
309
- function buildResolveNextQueries(targetId: string, kind: string | null): string[] {
310
- const relations = suggestedResolveRelations(kind);
311
- return [
312
- `Use code_graph with target.handle "${targetId}" and relations ${JSON.stringify(relations)}`,
313
- ];
303
+ const assembly = assembleResolveResult(outcome, cwd);
304
+ const content = renderResolveResult(assembly);
305
+
306
+ return {
307
+ content,
308
+ details: {
309
+ type: "resolve",
310
+ data: assembly.details,
311
+ status:
312
+ outcome.kind === "resolved" || outcome.kind === "target-group"
313
+ ? "completed"
314
+ : outcome.kind === "disambiguation" || outcome.kind === "kind-mismatch"
315
+ ? "disambiguation"
316
+ : "invalid-input",
317
+ ...(outcome.kind === "invalid-input"
318
+ ? { message: outcome.message }
319
+ : outcome.kind === "disambiguation"
320
+ ? { message: "Multiple target matches require one candidate." }
321
+ : outcome.kind === "kind-mismatch"
322
+ ? { message: `No target matched provider kind ${outcome.requestedKind}.` }
323
+ : {}),
324
+ displaySections: assembly.displaySections,
325
+ },
326
+ };
314
327
  }
@@ -0,0 +1,25 @@
1
+ import { Type } from "typebox";
2
+ import type { CodeIntelToolExecCtx } from "../../types/index.ts";
3
+ import { MaxResultsParam, ResolveTargetParam } from "../schemas.ts";
4
+ import { executeResolveTool } from "./execute.ts";
5
+ import { renderResolveCall, renderResolveResult } from "./tui.ts";
6
+
7
+ export const CODE_RESOLVE_TOOL_NAME = "code_resolve";
8
+ export const CODE_RESOLVE_TOOL_LABEL = "Code Resolve";
9
+
10
+ /** Canonical provider-facing metadata for the code_resolve tool. */
11
+ export const codeResolveSpec = {
12
+ name: CODE_RESOLVE_TOOL_NAME,
13
+ label: CODE_RESOLVE_TOOL_LABEL,
14
+ parameters: Type.Object(
15
+ {
16
+ target: ResolveTargetParam,
17
+ maxResults: Type.Optional(MaxResultsParam),
18
+ },
19
+ { additionalProperties: false },
20
+ ),
21
+ run: (params: unknown, ctx: CodeIntelToolExecCtx) =>
22
+ executeResolveTool(params as Parameters<typeof executeResolveTool>[0], ctx),
23
+ renderCall: renderResolveCall,
24
+ renderResult: renderResolveResult,
25
+ } as const;
@@ -1,12 +1,52 @@
1
- // Model-facing descriptions and concise sibling-selection guidance.
1
+ // Model-facing prompt surfaces for the eight public code-intelligence tools.
2
+ //
3
+ // Ownership map (docs/pi/tool-guidance.md): each model-facing fact lives in
4
+ // exactly one home — the per-tool guidance module. This aggregator assembles
5
+ // the canonical surface map consumed by registration.
6
+ // Parameter mechanics (formats, enum semantics, cross-field rules) live in
7
+ // schemas.ts / per-tool spec.ts and are not repeated here.
2
8
 
3
- import {
4
- DEFAULT_AST_SCAN_MAX_FILES,
5
- DEFAULT_AST_SCAN_TIMEOUT_MS,
6
- } from "../analysis/search/ast-scan.ts";
7
9
  import type { CodeIntelligenceToolName } from "../types/index.ts";
8
-
9
- const AST_SCAN_TIMEOUT_SECONDS = DEFAULT_AST_SCAN_TIMEOUT_MS / 1_000;
10
+ import {
11
+ toolDescription as findDescription,
12
+ promptGuidelines as findGuidelines,
13
+ promptSnippet as findSnippet,
14
+ } from "./code_find/guidance.ts";
15
+ import {
16
+ toolDescription as graphDescription,
17
+ promptGuidelines as graphGuidelines,
18
+ promptSnippet as graphSnippet,
19
+ } from "./code_graph/guidance.ts";
20
+ import {
21
+ toolDescription as healthDescription,
22
+ promptGuidelines as healthGuidelines,
23
+ promptSnippet as healthSnippet,
24
+ } from "./code_health/guidance.ts";
25
+ import {
26
+ toolDescription as inspectDescription,
27
+ promptGuidelines as inspectGuidelines,
28
+ promptSnippet as inspectSnippet,
29
+ } from "./code_inspect/guidance.ts";
30
+ import {
31
+ toolDescription as orientationDescription,
32
+ promptGuidelines as orientationGuidelines,
33
+ promptSnippet as orientationSnippet,
34
+ } from "./code_orientation/guidance.ts";
35
+ import {
36
+ toolDescription as applyDescription,
37
+ promptGuidelines as applyGuidelines,
38
+ promptSnippet as applySnippet,
39
+ } from "./code_refactor_apply/guidance.ts";
40
+ import {
41
+ toolDescription as planDescription,
42
+ promptGuidelines as planGuidelines,
43
+ promptSnippet as planSnippet,
44
+ } from "./code_refactor_plan/guidance.ts";
45
+ import {
46
+ toolDescription as resolveDescription,
47
+ promptGuidelines as resolveGuidelines,
48
+ promptSnippet as resolveSnippet,
49
+ } from "./code_resolve/guidance.ts";
10
50
 
11
51
  export interface CodeIntelligenceToolPromptSurface {
12
52
  description: string;
@@ -21,64 +61,43 @@ export type CodeIntelligenceToolPromptSurfaceMap = Record<
21
61
 
22
62
  export const CODE_INTELLIGENCE_TOOL_PROMPT_SURFACES: CodeIntelligenceToolPromptSurfaceMap = {
23
63
  code_resolve: {
24
- description:
25
- "Resolve one provider-backed anchor or semantic symbol query to session handles, or enumerate a file's declarations as a bounded Target group. Requires a concrete ready LSP client; anchors must identify real symbols, and symbol lookup never falls back to text search. symbolKind is an exact provider-reported LSP kind filter. File groups keep overloads distinct and disclose omissions and provenance.",
26
- promptSnippet: "code_resolve — resolve a precise target or enumerate a file’s target group",
27
- promptGuidelines: [
28
- "Use code_resolve when a symbol query may be ambiguous, when later calls should share a stable target handle, or when a known file’s declarations should be enumerated.",
29
- ],
64
+ description: resolveDescription,
65
+ promptSnippet: resolveSnippet,
66
+ promptGuidelines: resolveGuidelines,
30
67
  },
31
68
  code_inspect: {
32
- description:
33
- "Inspect one exact point for syntax, the narrowest enclosing declaration, hover, definition, and diagnostics intersecting the nearby line window. Use for point facts, not broad Orientation. Completed-empty, partial, and unavailable sections are disclosed independently; no action is applied.",
34
- promptSnippet: "code_inspect — factual point inspection",
35
- promptGuidelines: [],
69
+ description: inspectDescription,
70
+ promptSnippet: inspectSnippet,
71
+ promptGuidelines: inspectGuidelines,
36
72
  },
37
73
  code_orientation: {
38
- description:
39
- "Orient around the workspace or one path, module, or target focus before surgical work. Omit focus for workspace Orientation. Directory focus may surface local instruction files. Use code_graph for relations and code_health for health.",
40
- promptSnippet: "code_orientation — workspace/path/module/symbol Orientation",
41
- promptGuidelines: [
42
- "Use code_orientation before broad file reading when you need direct workspace, package, directory, file, or symbol facts.",
43
- "Use focus.path for a known workspace path, focus.module for a discovered module name, and focus.target for a precise symbol.",
44
- "Use code_graph for relationships and code_health for provider or diagnostic state.",
45
- ],
74
+ description: orientationDescription,
75
+ promptSnippet: orientationSnippet,
76
+ promptGuidelines: orientationGuidelines,
46
77
  },
47
78
  code_graph: {
48
- description:
49
- 'Collect references, structural callees, and implementations for one target. Defaults to references; "all" selects all three. Callees match source shape, not symbol identity; calleeDepth:"deep" includes nested scopes. Per-relation failures are disclosed; no edges are invented.',
50
- promptSnippet: "code_graph — provider-backed and structural relation evidence",
51
- promptGuidelines: [],
79
+ description: graphDescription,
80
+ promptSnippet: graphSnippet,
81
+ promptGuidelines: graphGuidelines,
52
82
  },
53
83
  code_find: {
54
- description: `Search source shape with mode:"ast" or LSP workspace symbols with mode:"semantic"; AST requires kind. Use PI grep for literal/regex source search. Modes never silently fall back. Definition/type/interface/class/method/enum use outline support; import/export use their matching extractors; call uses registered call-site queries. Unscoped AST scans visible regular files supported by the selected kind's structural operation, excluding hidden entries and common generated/dependency directories without reading ignore files or following descendant symlinks. Explicit roots are honored; operation-ineligible files are disclosed, and exact ineligible scopes fail rather than widening. A ${AST_SCAN_TIMEOUT_SECONDS}-second deadline and ${DEFAULT_AST_SCAN_MAX_FILES}-file cap cover enumeration and analysis. Incomplete scans disclose limitations and unknown match totals.`,
55
- promptSnippet: "code_find — explicit structural or semantic code search",
56
- promptGuidelines: [
57
- "Use code_find for structural or semantic search evidence; use PI grep for literal/regex source search and code_graph references for symbol-identity relationships.",
58
- ],
84
+ description: findDescription,
85
+ promptSnippet: findSnippet,
86
+ promptGuidelines: findGuidelines,
59
87
  },
60
88
  code_health: {
61
- description:
62
- "Report live diagnostics as observations, language-server status, and final semantic health state. Use refresh:true to report a diagnostic-recovery attempt before finalizing semantic state. Tracked-file snapshots do not prove workspace completeness; server inventory is workspace-wide. Capability Warnings supplement diagnostic/server results.",
63
- promptSnippet: "code_health — live workspace health observations",
64
- promptGuidelines: [
65
- "Use code_health with refresh:true before relying on potentially stale diagnostics.",
66
- ],
89
+ description: healthDescription,
90
+ promptSnippet: healthSnippet,
91
+ promptGuidelines: healthGuidelines,
67
92
  },
68
93
  code_refactor_plan: {
69
- description:
70
- "Preview a precise semantic rename or extraction and return a planId without mutating files. Requires one handle/anchor target and one operation; unavailable precise edits never fall back to text edits. Apply separately with code_refactor_apply.",
71
- promptSnippet: "code_refactor_plan — preview a precise semantic refactor",
72
- promptGuidelines: [
73
- "Use code_refactor_plan for preview only, then explicitly call code_refactor_apply with its planId.",
74
- ],
94
+ description: planDescription,
95
+ promptSnippet: planSnippet,
96
+ promptGuidelines: planGuidelines,
75
97
  },
76
98
  code_refactor_apply: {
77
- description:
78
- "Apply one stored refactor plan by planId. Revalidates freshness, file fingerprints, ranges, and edit overlap before mutation; never composes or regenerates plans.",
79
- promptSnippet: "code_refactor_apply — apply a fresh stored refactor plan",
80
- promptGuidelines: [
81
- "Use code_refactor_apply only with a planId returned by code_refactor_plan.",
82
- ],
99
+ description: applyDescription,
100
+ promptSnippet: applySnippet,
101
+ promptGuidelines: applyGuidelines,
83
102
  },
84
103
  };
@@ -47,3 +47,43 @@ export function truncateToolContent(
47
47
  const notice = `\n[truncated: kept ${result.outputLines} of ${result.totalLines} lines (${formatSize(result.outputBytes)} of ${formatSize(result.totalBytes)})]\n`;
48
48
  return { text: `${result.content}${notice}`, truncated: true };
49
49
  }
50
+
51
+ import { mkdtempSync, writeFileSync } from "node:fs";
52
+ import { tmpdir } from "node:os";
53
+ import { join } from "node:path";
54
+ import type { CodeIntelResult } from "../../types/index.ts";
55
+ import type { ToolOutputTruncationDetails } from "../result/types.ts";
56
+
57
+ /**
58
+ * Apply the canonical output bound to one assembled code-tool result:
59
+ * truncate at PI limits, spill the full content to a temp file when it
60
+ * overflowed, and record truncation details.
61
+ */
62
+ export function boundCodeToolResult(
63
+ content: string,
64
+ details: CodeIntelResult["details"],
65
+ options: { toolName: string; maxLines?: number; maxBytes?: number },
66
+ ): { content: Array<{ type: "text"; text: string }>; details: CodeIntelResult["details"] } {
67
+ const withTruncation = (truncation: ToolOutputTruncationDetails) =>
68
+ details ? { ...details, truncation } : details;
69
+
70
+ const { text, truncated } = truncateToolContent(content, {
71
+ maxLines: options.maxLines,
72
+ maxBytes: options.maxBytes,
73
+ });
74
+ if (truncated && content.length > 0) {
75
+ const dir = mkdtempSync(join(tmpdir(), "supi-ci-"));
76
+ const spillPath = join(dir, `${options.toolName}-output.md`);
77
+ writeFileSync(spillPath, content, "utf-8");
78
+ return {
79
+ content: [
80
+ { type: "text" as const, text: `${text}\n_Full output saved to: \`${spillPath}\`_` },
81
+ ],
82
+ details: withTruncation({ truncated: true, fullOutputPath: spillPath }),
83
+ };
84
+ }
85
+ return {
86
+ content: [{ type: "text" as const, text }],
87
+ details: withTruncation({ truncated: false }),
88
+ };
89
+ }