@mrclrchtr/supi-code-intelligence 1.9.1 → 1.11.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 (84) hide show
  1. package/README.md +15 -7
  2. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/README.md +7 -1
  3. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +7 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
  5. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +112 -6
  6. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config.ts +20 -0
  7. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/llm.ts +211 -0
  8. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +108 -0
  9. package/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +66 -0
  10. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +2 -2
  11. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +4 -0
  12. package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +13 -0
  13. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +45 -0
  14. package/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/context.ts +5 -1
  15. package/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/runtime.ts +14 -3
  16. package/node_modules/@mrclrchtr/supi-core/README.md +7 -1
  17. package/node_modules/@mrclrchtr/supi-core/package.json +7 -1
  18. package/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
  19. package/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +112 -6
  20. package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +20 -0
  21. package/node_modules/@mrclrchtr/supi-core/src/llm.ts +211 -0
  22. package/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +108 -0
  23. package/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +66 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/README.md +7 -1
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/README.md +7 -1
  26. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +7 -1
  27. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +112 -6
  29. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config.ts +20 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/llm.ts +211 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +108 -0
  32. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +66 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +2 -2
  34. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +4 -0
  35. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +13 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +45 -0
  37. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/context.ts +5 -1
  38. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/runtime.ts +14 -3
  39. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/README.md +7 -1
  40. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +7 -1
  41. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
  42. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +112 -6
  43. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config/config.ts +20 -0
  44. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/llm.ts +211 -0
  45. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +108 -0
  46. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +66 -0
  47. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  48. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-semantic-provider.ts +139 -1
  49. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +7 -1
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/README.md +7 -1
  51. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +7 -1
  52. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
  53. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +112 -6
  54. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/config/config.ts +20 -0
  55. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/llm.ts +211 -0
  56. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +108 -0
  57. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +66 -0
  58. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +2 -2
  59. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +4 -0
  60. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +13 -0
  61. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +45 -0
  62. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/context.ts +5 -1
  63. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/workspace/runtime.ts +14 -3
  64. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/README.md +7 -1
  65. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +7 -1
  66. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
  67. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config/config-settings.ts +112 -6
  68. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config/config.ts +20 -0
  69. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/llm.ts +211 -0
  70. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +108 -0
  71. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +66 -0
  72. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  73. package/package.json +5 -5
  74. package/src/intent/types.ts +34 -0
  75. package/src/planner/planner.ts +82 -0
  76. package/src/presentation/markdown/refactor.ts +27 -0
  77. package/src/refactor/apply-workspace-edit.ts +162 -0
  78. package/src/refactor/safety.ts +154 -0
  79. package/src/tool/execute-affected.ts +22 -0
  80. package/src/tool/execute-brief.ts +9 -2
  81. package/src/tool/execute-refactor.ts +101 -0
  82. package/src/tool/execute-relations.ts +21 -3
  83. package/src/tool/guidance.ts +18 -11
  84. package/src/tool/tool-specs.ts +25 -0
@@ -0,0 +1,101 @@
1
+ /**
2
+ * code_refactor tool execution.
3
+ *
4
+ * Routes through the planner to get the refactor-capable semantic provider,
5
+ * calls rename/codeActions, validates the returned edit, applies it,
6
+ * and returns the result.
7
+ */
8
+
9
+ import { getDefaultWorkspaceRuntime } from "@mrclrchtr/supi-code-runtime/api";
10
+ import { toLspPosition } from "@mrclrchtr/supi-lsp/api";
11
+ import { routeFor } from "../planner/planner.ts";
12
+ import { renderRefactorResult } from "../presentation/markdown/refactor.ts";
13
+ import { applyWorkspaceEdit } from "../refactor/apply-workspace-edit.ts";
14
+ import { validateEdit } from "../refactor/safety.ts";
15
+ import { normalizePath } from "../search-helpers.ts";
16
+ import type { CodeIntelResult } from "../types.ts";
17
+
18
+ export interface CodeRefactorToolParams {
19
+ operation: "rename";
20
+ file: string;
21
+ line: number;
22
+ character: number;
23
+ newName: string;
24
+ // Future: "code-action" operation could be added here
25
+ }
26
+
27
+ /**
28
+ * Execute the code_refactor tool.
29
+ */
30
+ export async function executeRefactorTool(
31
+ params: CodeRefactorToolParams,
32
+ ctx: { cwd: string },
33
+ ): Promise<CodeIntelResult> {
34
+ const route = routeFor(ctx.cwd, "code_refactor");
35
+ if (route.preferred === "unavailable") {
36
+ return {
37
+ content:
38
+ "**Error:** No refactor-capable provider is available for this workspace. Ensure an LSP server is configured and running.",
39
+ details: undefined,
40
+ };
41
+ }
42
+
43
+ const runtime = getDefaultWorkspaceRuntime();
44
+ const ws = runtime.getWorkspace(ctx.cwd);
45
+ const provider = ws.semantic.provider;
46
+
47
+ if (!provider?.rename) {
48
+ return {
49
+ content: "**Error:** The active semantic provider does not support rename operations.",
50
+ details: undefined,
51
+ };
52
+ }
53
+
54
+ const resolvedFile = normalizePath(params.file, ctx.cwd);
55
+
56
+ // Execute the rename operation with 0-based LSP coordinates
57
+ const refactorResult = await provider.rename(
58
+ resolvedFile,
59
+ toLspPosition(params.line, params.character),
60
+ params.newName,
61
+ );
62
+
63
+ if (refactorResult.kind === "unavailable") {
64
+ return {
65
+ content: `**Refactor unavailable:** ${refactorResult.reason}`,
66
+ details: undefined,
67
+ };
68
+ }
69
+
70
+ if (refactorResult.kind === "ambiguous") {
71
+ const candidates = refactorResult.candidates
72
+ .map((c, i) => {
73
+ const location = c.file ? `${c.file}${c.line != null ? `:${c.line}` : ""}` : "";
74
+ return `${i + 1}. ${c.description}${location ? ` (${location})` : ""}`;
75
+ })
76
+ .join("\n");
77
+ return {
78
+ content: `**Refactor ambiguous:** Multiple matching targets found. Please disambiguate:\n${candidates}`,
79
+ details: undefined,
80
+ };
81
+ }
82
+
83
+ // Validate the edit
84
+ const validation = validateEdit(refactorResult.edits);
85
+ if (!validation.safe) {
86
+ return {
87
+ content: `**Refactor safety check failed:** ${validation.reason}`,
88
+ details: undefined,
89
+ };
90
+ }
91
+
92
+ // Apply the edit
93
+ const applyResult = applyWorkspaceEdit(refactorResult.edits);
94
+ const content = renderRefactorResult({
95
+ result: applyResult,
96
+ operation: `rename "${params.newName}"`,
97
+ targetDescription: `${resolvedFile}:${params.line}:${params.character}`,
98
+ });
99
+
100
+ return { content, details: undefined };
101
+ }
@@ -1,3 +1,4 @@
1
+ import { routeFor } from "../planner/planner.ts";
1
2
  import type { CodeIntelResult } from "../types.ts";
2
3
  import type { RelationsInput } from "../use-case/generate-relations.ts";
3
4
  import { executeRelations } from "../use-case/generate-relations.ts";
@@ -16,7 +17,7 @@ export interface CodeRelationsToolParams {
16
17
  maxResults?: number;
17
18
  }
18
19
 
19
- /** Execute the public code_relations tool through the relations use-case. */
20
+ /** Execute the public code_relations tool through the planner-backed routing. */
20
21
  export async function executeRelationsTool(
21
22
  params: CodeRelationsToolParams,
22
23
  ctx: { cwd: string },
@@ -26,11 +27,11 @@ export async function executeRelationsTool(
26
27
  return { content: error, details: undefined };
27
28
  }
28
29
 
29
- // Semantic actions (callers, callees, implementations) require file or symbol
30
+ // Semantic actions (callers, implementations) or structural (callees) require file or symbol
30
31
  if (!params.file && !params.symbol) {
31
32
  return {
32
33
  content:
33
- "**Error:** Semantic actions require either anchored coordinates (`file`, `line`, `character`) or a `symbol` for discovery.",
34
+ "**Error:** Relations require either anchored coordinates (`file`, `line`, `character`) or a `symbol` for discovery.",
34
35
  details: {
35
36
  type: "search" as const,
36
37
  data: {
@@ -44,6 +45,23 @@ export async function executeRelationsTool(
44
45
  };
45
46
  }
46
47
 
48
+ const route = routeFor(ctx.cwd, "code_relations", params.kind);
49
+ if (route.preferred === "unavailable") {
50
+ return {
51
+ content: `**Error:** No ${params.kind === "callees" ? "structural" : "semantic"} analysis provider is available for this workspace. Use tree_sitter_callees or lsp_* tools directly if needed.`,
52
+ details: {
53
+ type: "search" as const,
54
+ data: {
55
+ confidence: "unavailable" as const,
56
+ scope: null,
57
+ candidateCount: 0,
58
+ omittedCount: 0,
59
+ nextQueries: ["Check LSP and tree-sitter configuration"],
60
+ },
61
+ },
62
+ };
63
+ }
64
+
47
65
  const input: RelationsInput = {
48
66
  kind: params.kind,
49
67
  path: params.path,
@@ -17,26 +17,33 @@ export type CodeIntelligenceToolPromptSurfaceMap = Record<
17
17
  CodeIntelligenceToolPromptSurface
18
18
  >;
19
19
 
20
- // ── Cross-family orchestration guidelines ──────────────────────────────
20
+ // ── Intent-first orchestration guidelines ─────────────────────────────
21
21
  //
22
- // These are appended to the appropriate code_* tools so the model sees a
23
- // coherent strategy for choosing between code_*, lsp_*, and tree_sitter_*
24
- // tools. They do not re-own substrate metadata — each of the other packages
25
- // describes and documents its own tools independently.
22
+ // These steer the model toward choosing tools by user intent rather than
23
+ // by implementation family. Substrate tools (lsp_*, tree_sitter_*) are
24
+ // described as expert follow-up surfaces, not the primary choice.
26
25
 
27
- const ORCHESTRATION_GUIDELINES: Record<CodeIntelligenceToolName, string[]> = {
26
+ const INTENT_GUIDELINES: Record<CodeIntelligenceToolName, string[]> = {
28
27
  code_brief: [
29
- "After code_brief, use lsp_hover/lsp_definition/lsp_references for semantic detail or tree_sitter_* for quick structure.",
28
+ "Use code_brief for prioritized orientation on a project, package, file, or symbol.",
29
+ "The planner selects the best provider (semantic or structural) automatically.",
30
+ "After code_brief, use lsp_hover/lsp_definition/lsp_references for deeper semantic detail or tree_sitter_* for quick structural context.",
30
31
  ],
31
32
  code_map: ["Use code_brief instead when you need prioritized guidance."],
32
33
  code_relations: [
33
- "Follow caller results with lsp_references/lsp_definition; use tree_sitter_callees for structural outgoing calls.",
34
+ "The planner routes callers/implementations to semantic (LSP) analysis and callees to structural (tree-sitter) analysis.",
35
+ "Follow caller results with lsp_references/lsp_definition for additional context; use tree_sitter_callees for structural outgoing calls as a debug surface.",
34
36
  ],
35
37
  code_affected: [
36
- "Use lsp_references instead when you need a plain reference list, not impact analysis.",
38
+ "Uses semantic evidence for blast-radius assessment. Does not fall back to heuristic text search.",
39
+ "Use lsp_references when you only need a plain reference list without impact analysis.",
37
40
  ],
38
41
  code_pattern: [
39
- "Use tree_sitter_query or lsp_hover/lsp_definition when you need structure or semantic precision.",
42
+ "The only code_* tool that uses heuristic/text search behavior. For structured or semantic precision, use tree_sitter_query or lsp_hover/lsp_definition instead.",
43
+ ],
44
+ code_refactor: [
45
+ "Uses semantic provider for precise rename/code-action operations with safety checks.",
46
+ "Does not fall back to heuristic text replacement — if the provider cannot produce precise edits, the tool reports unavailable.",
40
47
  ],
41
48
  };
42
49
 
@@ -49,7 +56,7 @@ export function buildCodeIntelligenceToolPromptSurfaces(): CodeIntelligenceToolP
49
56
  {
50
57
  description: spec.description,
51
58
  promptSnippet: spec.promptSnippet,
52
- promptGuidelines: [...spec.basePromptGuidelines, ...ORCHESTRATION_GUIDELINES[spec.name]],
59
+ promptGuidelines: [...spec.basePromptGuidelines, ...INTENT_GUIDELINES[spec.name]],
53
60
  } satisfies CodeIntelligenceToolPromptSurface,
54
61
  ]),
55
62
  ) as CodeIntelligenceToolPromptSurfaceMap;
@@ -5,6 +5,7 @@ import { executeAffectedTool } from "./execute-affected.ts";
5
5
  import { executeBriefTool } from "./execute-brief.ts";
6
6
  import { executeMapTool } from "./execute-map.ts";
7
7
  import { executePatternTool } from "./execute-pattern.ts";
8
+ import { executeRefactorTool } from "./execute-refactor.ts";
8
9
  import { executeRelationsTool } from "./execute-relations.ts";
9
10
 
10
11
  const PathParam = Type.String({ description: "Scope path" });
@@ -28,6 +29,7 @@ export const CODE_INTELLIGENCE_TOOL_NAMES = [
28
29
  "code_relations",
29
30
  "code_affected",
30
31
  "code_pattern",
32
+ "code_refactor",
31
33
  ] as const;
32
34
  export type CodeIntelligenceToolName = (typeof CODE_INTELLIGENCE_TOOL_NAMES)[number];
33
35
 
@@ -94,6 +96,17 @@ const CodePatternParameters = Type.Object(
94
96
  { additionalProperties: false },
95
97
  );
96
98
 
99
+ const CodeRefactorParameters = Type.Object(
100
+ {
101
+ operation: Type.String({ description: "Refactor operation: rename" }),
102
+ file: FileParam,
103
+ line: LineParam,
104
+ character: CharacterParam,
105
+ newName: Type.String({ description: "New name for rename operation" }),
106
+ },
107
+ { additionalProperties: false },
108
+ );
109
+
97
110
  export interface CodeIntelligenceToolDefinitionSpec {
98
111
  name: CodeIntelligenceToolName;
99
112
  label: string;
@@ -162,4 +175,16 @@ export const CODE_INTELLIGENCE_TOOL_SPECS = [
162
175
  run: (params, ctx) =>
163
176
  executePatternTool(params as Parameters<typeof executePatternTool>[0], ctx),
164
177
  },
178
+ {
179
+ name: "code_refactor",
180
+ label: "Code Refactor",
181
+ description: "Apply a precise semantic refactor (rename) with direct-apply safety checks.",
182
+ promptSnippet: "code_refactor — semantic refactor with direct apply",
183
+ basePromptGuidelines: [
184
+ "Use code_refactor for safe semantic rename operations with precise workspace edits.",
185
+ ],
186
+ parameters: CodeRefactorParameters,
187
+ run: (params, ctx) =>
188
+ executeRefactorTool(params as Parameters<typeof executeRefactorTool>[0], ctx),
189
+ },
165
190
  ] as const satisfies readonly CodeIntelligenceToolDefinitionSpec[];