@mrclrchtr/supi-code-intelligence 11.3.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +15 -9
- package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
- package/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/README.md +22 -17
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +30 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +13 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +25 -9
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +7 -5
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-edit-capture.ts +258 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +64 -11
- package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +48 -79
- package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +10 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +118 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +67 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +87 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +21 -35
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-command-capture.ts +139 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +202 -47
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +22 -17
- package/node_modules/@mrclrchtr/supi-lsp/src/session/route-boundary.ts +26 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +106 -16
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +3 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +22 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +5 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +5 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/coordinates.ts +16 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +3 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/syntax-errors.ts +2 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-range.ts +94 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +26 -6
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +6 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +13 -4
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +1 -9
- package/package.json +5 -5
- package/src/analysis/health/server-status.ts +41 -12
- package/src/analysis/helpers.ts +0 -7
- package/src/analysis/relations/implementations.ts +5 -0
- package/src/analysis/relations/references.ts +5 -0
- package/src/analysis/target/anchored-structural.ts +4 -1
- package/src/analysis/target/file-merge.ts +162 -0
- package/src/analysis/target/file-outline-omissions.ts +146 -0
- package/src/analysis/target/file-refinement.ts +7 -7
- package/src/analysis/target/file.ts +44 -156
- package/src/analysis/target/symbol.ts +5 -1
- package/src/analysis/target/types.ts +32 -6
- package/src/api.ts +1 -1
- package/src/app/app.ts +9 -3
- package/src/session/find-types.ts +8 -4
- package/src/session/find-workflow.ts +11 -16
- package/src/session/graph/collect.ts +2 -0
- package/src/session/graph-types.ts +3 -1
- package/src/session/graph-workflow.ts +5 -4
- package/src/session/input/health-refactor.ts +48 -34
- package/src/session/input/workflows.ts +45 -46
- package/src/session/inspect/file-point.ts +2 -2
- package/src/session/inspect-types.ts +1 -1
- package/src/session/inspect-workflow.ts +3 -3
- package/src/session/orientation/workspace-context.ts +3 -0
- package/src/session/orientation-workflow.ts +6 -3
- package/src/session/refactor-file-actions.ts +122 -0
- package/src/session/refactor-plan-pipeline.ts +152 -0
- package/src/session/refactor-plans.ts +18 -15
- package/src/session/refactor-types.ts +24 -12
- package/src/session/refactor-workflow.ts +70 -244
- package/src/session/session.ts +87 -12
- package/src/session/target-workflow.ts +23 -21
- package/src/tool/code_find/execute.ts +6 -7
- package/src/tool/code_find/spec.ts +9 -16
- package/src/tool/code_find/tui.ts +12 -6
- package/src/tool/code_graph/section.ts +4 -0
- package/src/tool/code_graph/spec.ts +6 -0
- package/src/tool/code_health/spec.ts +6 -0
- package/src/tool/code_health/structured-schema.ts +4 -4
- package/src/tool/code_health/structured.ts +15 -17
- package/src/tool/code_inspect/execute.ts +1 -1
- package/src/tool/code_inspect/markdown.ts +33 -6
- package/src/tool/code_inspect/result.ts +1 -1
- package/src/tool/code_inspect/spec.ts +14 -6
- package/src/tool/code_inspect/structured.ts +2 -2
- package/src/tool/code_inspect/tui.ts +2 -2
- package/src/tool/code_orientation/directory-navigation.ts +20 -31
- package/src/tool/code_orientation/spec.ts +8 -0
- package/src/tool/code_orientation/workspace-output.ts +40 -13
- package/src/tool/code_orientation/workspace-sections.ts +45 -2
- package/src/tool/code_refactor_apply/result.ts +2 -1
- package/src/tool/code_refactor_apply/spec.ts +7 -0
- package/src/tool/code_refactor_plan/execute.ts +0 -2
- package/src/tool/code_refactor_plan/result.ts +23 -13
- package/src/tool/code_refactor_plan/spec.ts +8 -2
- package/src/tool/code_refactor_plan/structured.ts +59 -12
- package/src/tool/code_refactor_plan/tui.ts +14 -17
- package/src/tool/code_resolve/guidance.ts +1 -1
- package/src/tool/code_resolve/markdown.ts +121 -34
- package/src/tool/code_resolve/result.ts +18 -15
- package/src/tool/code_resolve/spec.ts +6 -0
- package/src/tool/code_resolve/structured.ts +43 -10
- package/src/tool/namespace.ts +14 -0
- package/src/tool/refactor-markdown.ts +55 -15
- package/src/tool/register.ts +3 -0
- package/src/tool/result/model-budget.ts +2 -2
- package/src/tool/result/refactor-preview.ts +118 -0
- package/src/tool/result/refactor-unavailable.ts +16 -0
- package/src/tool/result/refactor.ts +8 -2
- package/src/tool/result/types.ts +13 -10
- package/src/tool/schemas.ts +63 -20
- package/src/tool/specs.ts +3 -0
- package/src/ui/status-overlay.ts +1 -1
- package/src/ui/tui/common.ts +10 -10
|
@@ -16,11 +16,11 @@ export function renderInspectCall(
|
|
|
16
16
|
_context: ToolRendererContext | undefined,
|
|
17
17
|
): Text {
|
|
18
18
|
const params = (args ?? {}) as {
|
|
19
|
-
|
|
19
|
+
anchor?: { file?: unknown; line?: unknown; character?: unknown };
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
let content = theme.fg("toolTitle", "code_inspect");
|
|
23
|
-
const point = params.
|
|
23
|
+
const point = params.anchor;
|
|
24
24
|
if (point && typeof point === "object") {
|
|
25
25
|
const file = formatCallPath(point.file);
|
|
26
26
|
if (file) content += ` ${theme.fg("accent", file)}`;
|
|
@@ -10,12 +10,16 @@ const INLINE_SECTIONS = new Set([
|
|
|
10
10
|
"workspace.issues",
|
|
11
11
|
]);
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Keep the immediate directory map, manifest-declared entry paths, and all collection problems
|
|
15
|
+
* inline; defer ancillary facts to the captured result and name them in one note.
|
|
16
|
+
*/
|
|
14
17
|
export function selectDirectoryNavigation(data: OrientationResultData): OrientationResultData {
|
|
15
18
|
if (!data.workspace?.focus || data.workspace.overview) return data;
|
|
16
19
|
const workspaceRoot = data.workspace.focus === data.workspace.observation.root;
|
|
17
20
|
const inline = (section: OrientationSectionData): boolean =>
|
|
18
21
|
INLINE_SECTIONS.has(section.key) ||
|
|
22
|
+
section.key.endsWith(".paths") ||
|
|
19
23
|
section.key.startsWith("gradle.") ||
|
|
20
24
|
(workspaceRoot &&
|
|
21
25
|
(section.key === "workspace.projects" || section.key === "workspace.memberships")) ||
|
|
@@ -28,39 +32,24 @@ export function selectDirectoryNavigation(data: OrientationResultData): Orientat
|
|
|
28
32
|
sum + section.evidenceLists.reduce((count, list) => count + (list.totalCount ?? 0), 0),
|
|
29
33
|
0,
|
|
30
34
|
);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
provenance: [],
|
|
39
|
-
evidenceLists: [
|
|
40
|
-
{
|
|
41
|
-
key: "workspace.captured",
|
|
42
|
-
totalCount: total,
|
|
43
|
-
shownCount: 0,
|
|
44
|
-
omittedCount: total,
|
|
45
|
-
partialReason: null,
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
items: [
|
|
49
|
-
{
|
|
50
|
-
kind: "paragraph",
|
|
51
|
-
text: `Ancillary sections are in the captured details: ${deferred.map((section) => section.title).join("; ")}.`,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
});
|
|
55
|
-
}
|
|
35
|
+
const notes =
|
|
36
|
+
total > 0
|
|
37
|
+
? [
|
|
38
|
+
...data.notes,
|
|
39
|
+
`Deferred to captured details: ${deferred.map((section) => section.title).join("; ")}.`,
|
|
40
|
+
]
|
|
41
|
+
: data.notes;
|
|
56
42
|
return {
|
|
57
43
|
...data,
|
|
44
|
+
notes,
|
|
58
45
|
sections,
|
|
59
46
|
renderedSections: sections.map((section) => section.key),
|
|
60
|
-
omittedCount:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
47
|
+
omittedCount:
|
|
48
|
+
total +
|
|
49
|
+
sections.reduce(
|
|
50
|
+
(sum, section) =>
|
|
51
|
+
sum + section.evidenceLists.reduce((count, list) => count + (list.omittedCount ?? 0), 0),
|
|
52
|
+
0,
|
|
53
|
+
),
|
|
65
54
|
};
|
|
66
55
|
}
|
|
@@ -12,6 +12,14 @@ export const CODE_ORIENTATION_TOOL_LABEL = "Code Orientation";
|
|
|
12
12
|
export const codeOrientationSpec = {
|
|
13
13
|
name: CODE_ORIENTATION_TOOL_NAME,
|
|
14
14
|
label: CODE_ORIENTATION_TOOL_LABEL,
|
|
15
|
+
// Read-only by default. Gradle observation runs project build logic only after an explicit
|
|
16
|
+
// per-project allow; that consent covers its effects, so the hints describe the default path.
|
|
17
|
+
annotations: {
|
|
18
|
+
readOnlyHint: true,
|
|
19
|
+
destructiveHint: false,
|
|
20
|
+
idempotentHint: true,
|
|
21
|
+
openWorldHint: true,
|
|
22
|
+
},
|
|
15
23
|
outputSchema: OrientationOutputSchema,
|
|
16
24
|
parameters: Type.Object(
|
|
17
25
|
{
|
|
@@ -40,21 +40,9 @@ export function prepareWorkspaceOutput(input: OrientationResultData): {
|
|
|
40
40
|
true,
|
|
41
41
|
);
|
|
42
42
|
const fullContent = renderOrientationData(full);
|
|
43
|
-
let limit = workspace.overview
|
|
44
|
-
? Math.max(10, workspace.observation.projects.length)
|
|
45
|
-
: workspace.maxResults;
|
|
46
|
-
let descriptions = true;
|
|
47
|
-
let data = selectDirectoryNavigation(workspaceSections(input, limit, descriptions));
|
|
48
|
-
if (navigationText(data).length > budget.warning * 4) {
|
|
49
|
-
descriptions = false;
|
|
50
|
-
data = selectDirectoryNavigation(workspaceSections(input, limit, descriptions));
|
|
51
|
-
}
|
|
52
43
|
// Reserve room for the snapshot path and omission notice before reducing rows.
|
|
53
44
|
const reserved = 1024;
|
|
54
|
-
|
|
55
|
-
limit = Math.floor(limit / 2);
|
|
56
|
-
data = selectDirectoryNavigation(workspaceSections(input, limit, descriptions));
|
|
57
|
-
}
|
|
45
|
+
let { data, descriptions } = selectWithinBudget(input, workspace, budget, reserved);
|
|
58
46
|
const overflow = exceedsNavigationBudget(data, budget.cap * 4 - reserved);
|
|
59
47
|
if (overflow) {
|
|
60
48
|
data = {
|
|
@@ -111,6 +99,45 @@ export function prepareWorkspaceOutput(input: OrientationResultData): {
|
|
|
111
99
|
};
|
|
112
100
|
}
|
|
113
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Shrink one observation's presentation until it fits: drop descriptions, then the uncapped
|
|
104
|
+
* directory file list, then halve every list cap.
|
|
105
|
+
*/
|
|
106
|
+
function selectWithinBudget(
|
|
107
|
+
input: OrientationResultData,
|
|
108
|
+
workspace: WorkspaceOrientationFacts,
|
|
109
|
+
budget: { warning: number; cap: number },
|
|
110
|
+
reserved: number,
|
|
111
|
+
): { data: OrientationResultData; descriptions: boolean } {
|
|
112
|
+
let limit = workspace.overview
|
|
113
|
+
? Math.max(10, workspace.observation.projects.length)
|
|
114
|
+
: workspace.maxResults;
|
|
115
|
+
// Without an explicit cap, directory focus shows every direct file until the budget forces the default.
|
|
116
|
+
let fileLimit =
|
|
117
|
+
workspace.focus && !workspace.overview && !workspace.maxResultsExplicit
|
|
118
|
+
? Number.MAX_SAFE_INTEGER
|
|
119
|
+
: limit;
|
|
120
|
+
let descriptions = true;
|
|
121
|
+
const select = () =>
|
|
122
|
+
selectDirectoryNavigation(workspaceSections(input, limit, descriptions, fileLimit));
|
|
123
|
+
let data = select();
|
|
124
|
+
if (navigationText(data).length > budget.warning * 4) {
|
|
125
|
+
descriptions = false;
|
|
126
|
+
data = select();
|
|
127
|
+
}
|
|
128
|
+
const cap = budget.cap * 4 - reserved;
|
|
129
|
+
if (exceedsNavigationBudget(data, cap) && fileLimit > limit) {
|
|
130
|
+
fileLimit = limit;
|
|
131
|
+
data = select();
|
|
132
|
+
}
|
|
133
|
+
while (exceedsNavigationBudget(data, cap) && limit > 0) {
|
|
134
|
+
limit = Math.floor(limit / 2);
|
|
135
|
+
fileLimit = limit;
|
|
136
|
+
data = select();
|
|
137
|
+
}
|
|
138
|
+
return { data, descriptions };
|
|
139
|
+
}
|
|
140
|
+
|
|
114
141
|
/** Overview links recover omitted navigation; explicit Orientation also retains raw facts. */
|
|
115
142
|
function needsCapturedResult(
|
|
116
143
|
workspace: WorkspaceOrientationFacts,
|
|
@@ -19,6 +19,7 @@ export function workspaceSections(
|
|
|
19
19
|
data: OrientationResultData,
|
|
20
20
|
limit: number,
|
|
21
21
|
descriptions: boolean,
|
|
22
|
+
fileLimit = limit,
|
|
22
23
|
): OrientationResultData {
|
|
23
24
|
const facts = data.workspace;
|
|
24
25
|
if (!facts) return data;
|
|
@@ -54,7 +55,7 @@ export function workspaceSections(
|
|
|
54
55
|
"Declared descriptions are omitted to preserve names and paths. They remain in the captured result.",
|
|
55
56
|
);
|
|
56
57
|
}
|
|
57
|
-
const sections = inventorySections(entries, facts, limit);
|
|
58
|
+
const sections = inventorySections(entries, facts, limit, fileLimit);
|
|
58
59
|
sections.push(...projectSections(facts, limit, descriptions));
|
|
59
60
|
sections.push(...gradleSections(observation.gradle, limit));
|
|
60
61
|
const issues = [
|
|
@@ -192,6 +193,7 @@ function inventorySections(
|
|
|
192
193
|
entries: readonly InventoryEntry[],
|
|
193
194
|
facts: WorkspaceOrientationFacts,
|
|
194
195
|
limit: number,
|
|
196
|
+
fileLimit: number,
|
|
195
197
|
): OrientationSectionData[] {
|
|
196
198
|
const { directories, directFiles, extensions } = collectWorkspaceInventory(entries);
|
|
197
199
|
const sections = [
|
|
@@ -205,7 +207,8 @@ function inventorySections(
|
|
|
205
207
|
detail: "included paths",
|
|
206
208
|
}),
|
|
207
209
|
];
|
|
208
|
-
if (
|
|
210
|
+
if (facts.focus && !facts.overview) sections.push(directFileList(directFiles, fileLimit));
|
|
211
|
+
else if (directFiles.length > 0 || !facts.overview)
|
|
209
212
|
sections.push(
|
|
210
213
|
tableSection("workspace.files", "Direct files", {
|
|
211
214
|
headers: ["Path", "Kind"],
|
|
@@ -228,6 +231,46 @@ function inventorySections(
|
|
|
228
231
|
return sections;
|
|
229
232
|
}
|
|
230
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Directory focus lists direct files as one compact line instead of a per-row table. Its own
|
|
236
|
+
* `fileLimit` lets presentation show all siblings and shrink them first under the text budget.
|
|
237
|
+
*/
|
|
238
|
+
function directFileList(
|
|
239
|
+
directFiles: readonly InventoryEntry[],
|
|
240
|
+
fileLimit: number,
|
|
241
|
+
): OrientationSectionData {
|
|
242
|
+
const names = directFiles
|
|
243
|
+
.slice(0, fileLimit)
|
|
244
|
+
.map((entry) =>
|
|
245
|
+
entry.kind === "symlink" ? `${code(entry.path)} (symlink)` : code(entry.path),
|
|
246
|
+
);
|
|
247
|
+
return {
|
|
248
|
+
key: "workspace.files",
|
|
249
|
+
title: "Direct files",
|
|
250
|
+
status: "complete",
|
|
251
|
+
reason: null,
|
|
252
|
+
confidence: "unavailable",
|
|
253
|
+
provenance: [{ source: "filesystem", detail: "included paths" }],
|
|
254
|
+
evidenceLists: [
|
|
255
|
+
{
|
|
256
|
+
key: "workspace.files",
|
|
257
|
+
totalCount: directFiles.length,
|
|
258
|
+
shownCount: names.length,
|
|
259
|
+
omittedCount: directFiles.length - names.length,
|
|
260
|
+
partialReason: null,
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
items: [
|
|
264
|
+
{
|
|
265
|
+
kind: "paragraph",
|
|
266
|
+
text: directFiles.length
|
|
267
|
+
? names.join(", ") || "No entries shown."
|
|
268
|
+
: "No collected entries.",
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
231
274
|
export function display(cwd: string, target: string): string {
|
|
232
275
|
return toDisplayPath(cwd, target);
|
|
233
276
|
}
|
|
@@ -4,6 +4,7 @@ import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts
|
|
|
4
4
|
import { renderRefactorApplyResult } from "../refactor-markdown.ts";
|
|
5
5
|
import { searchErrorResult } from "../result/errors.ts";
|
|
6
6
|
import { assembleRefactorApplyDetails } from "../result/refactor.ts";
|
|
7
|
+
import { refactorUnavailableReason } from "../result/refactor-unavailable.ts";
|
|
7
8
|
import { structuredRefactorApply } from "./structured.ts";
|
|
8
9
|
|
|
9
10
|
type RefactorApplyOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["applyRefactor"]>>;
|
|
@@ -13,7 +14,7 @@ export function finishRefactorApplyResult(
|
|
|
13
14
|
outcome: RefactorApplyOutcome,
|
|
14
15
|
cwd: string,
|
|
15
16
|
): CodeIntelResult {
|
|
16
|
-
if (outcome.kind === "unavailable") throw new Error(outcome.reason);
|
|
17
|
+
if (outcome.kind === "unavailable") throw new Error(refactorUnavailableReason(outcome.reason));
|
|
17
18
|
if (outcome.kind === "invalid-input") {
|
|
18
19
|
return {
|
|
19
20
|
...searchErrorResult(`**Error:** ${outcome.message}`, {
|
|
@@ -11,6 +11,13 @@ export const CODE_REFACTOR_APPLY_TOOL_LABEL = "Code Refactor Apply";
|
|
|
11
11
|
export const codeRefactorApplySpec = {
|
|
12
12
|
name: CODE_REFACTOR_APPLY_TOOL_NAME,
|
|
13
13
|
label: CODE_REFACTOR_APPLY_TOOL_LABEL,
|
|
14
|
+
// Overwrites workspace files; a repeated planId is rejected because Apply consumes the plan.
|
|
15
|
+
annotations: {
|
|
16
|
+
readOnlyHint: false,
|
|
17
|
+
destructiveHint: true,
|
|
18
|
+
idempotentHint: true,
|
|
19
|
+
openWorldHint: false,
|
|
20
|
+
},
|
|
14
21
|
parameters: Type.Object(
|
|
15
22
|
{
|
|
16
23
|
planId: Type.String({
|
|
@@ -4,13 +4,11 @@ import type {
|
|
|
4
4
|
RefactorOperationInput,
|
|
5
5
|
RefactorPlanWorkflowInput,
|
|
6
6
|
} from "../../session/refactor-types.ts";
|
|
7
|
-
import type { RefactorTargetInput } from "../../session/target-input.ts";
|
|
8
7
|
import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
|
|
9
8
|
import { toWorkflowControl } from "../infra/workflow-control.ts";
|
|
10
9
|
import { finishRefactorPlanResult } from "./result.ts";
|
|
11
10
|
|
|
12
11
|
export interface CodeRefactorPlanToolParams {
|
|
13
|
-
target: RefactorTargetInput;
|
|
14
12
|
operation: RefactorOperationInput;
|
|
15
13
|
}
|
|
16
14
|
|
|
@@ -5,7 +5,8 @@ import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts
|
|
|
5
5
|
import { renderRefactorPlanResult } from "../refactor-markdown.ts";
|
|
6
6
|
import { searchErrorResult } from "../result/errors.ts";
|
|
7
7
|
import { assembleRefactorPlanDetails } from "../result/refactor.ts";
|
|
8
|
-
import {
|
|
8
|
+
import { refactorUnavailableReason } from "../result/refactor-unavailable.ts";
|
|
9
|
+
import { AMBIGUOUS_NEXT_ACTION, structuredRefactorPlan } from "./structured.ts";
|
|
9
10
|
|
|
10
11
|
type RefactorPlanOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["planRefactor"]>>;
|
|
11
12
|
|
|
@@ -14,28 +15,37 @@ export function finishRefactorPlanResult(
|
|
|
14
15
|
outcome: RefactorPlanOutcome,
|
|
15
16
|
cwd: string,
|
|
16
17
|
): CodeIntelResult {
|
|
17
|
-
if (outcome.kind === "unavailable") throw new Error(outcome.reason);
|
|
18
|
+
if (outcome.kind === "unavailable") throw new Error(refactorUnavailableReason(outcome.reason));
|
|
18
19
|
if (outcome.kind === "invalid-input") {
|
|
19
20
|
return {
|
|
20
21
|
...searchErrorResult(`**Error:** ${outcome.message}`, {
|
|
21
|
-
nextQueries: ["Fix the
|
|
22
|
+
nextQueries: ["Fix the operation input and retry"],
|
|
22
23
|
message: outcome.message,
|
|
23
24
|
}),
|
|
24
25
|
structuredContent: structuredRefactorPlan(outcome, cwd),
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
if (outcome.kind === "ambiguous") {
|
|
28
|
-
const candidates = outcome.candidates
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const candidates = outcome.candidates.map((candidate, index) => {
|
|
30
|
+
const label =
|
|
31
|
+
candidate.title === undefined
|
|
32
|
+
? candidate.description
|
|
33
|
+
: `${candidate.kind ? `\`${candidate.kind}\` — ` : ""}${JSON.stringify(candidate.title)}`;
|
|
34
|
+
const location =
|
|
35
|
+
candidate.file === undefined
|
|
36
|
+
? ""
|
|
37
|
+
: ` — first edit ${toDisplayPath(cwd, candidate.file)}:${candidate.line}`;
|
|
38
|
+
return `${index + 1}. ${label}${location}`;
|
|
39
|
+
});
|
|
34
40
|
return {
|
|
35
|
-
...searchErrorResult(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
...searchErrorResult(
|
|
42
|
+
`**Refactor ambiguous:**\n${candidates.join("\n")}\n\n${AMBIGUOUS_NEXT_ACTION}.`,
|
|
43
|
+
{
|
|
44
|
+
status: "disambiguation",
|
|
45
|
+
nextQueries: [AMBIGUOUS_NEXT_ACTION],
|
|
46
|
+
message: "Several matching actions produce different edits.",
|
|
47
|
+
},
|
|
48
|
+
),
|
|
39
49
|
structuredContent: structuredRefactorPlan(outcome, cwd),
|
|
40
50
|
};
|
|
41
51
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import type { CodeIntelToolExecCtx } from "../../types/index.ts";
|
|
3
|
-
import { RefactorOperationParam
|
|
3
|
+
import { RefactorOperationParam } from "../schemas.ts";
|
|
4
4
|
import { executeRefactorPlanTool } from "./execute.ts";
|
|
5
5
|
import { RefactorPlanOutputSchema } from "./structured.ts";
|
|
6
6
|
import { renderRefactorPlanCall, renderRefactorPlanResult } from "./tui.ts";
|
|
@@ -12,9 +12,15 @@ export const CODE_REFACTOR_PLAN_TOOL_LABEL = "Code Refactor Plan";
|
|
|
12
12
|
export const codeRefactorPlanSpec = {
|
|
13
13
|
name: CODE_REFACTOR_PLAN_TOOL_NAME,
|
|
14
14
|
label: CODE_REFACTOR_PLAN_TOOL_LABEL,
|
|
15
|
+
// Previews only: server-pushed edits are captured and refused; no file changes.
|
|
16
|
+
annotations: {
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
destructiveHint: false,
|
|
19
|
+
idempotentHint: true,
|
|
20
|
+
openWorldHint: false,
|
|
21
|
+
},
|
|
15
22
|
parameters: Type.Object(
|
|
16
23
|
{
|
|
17
|
-
target: RefactorTargetParam,
|
|
18
24
|
operation: RefactorOperationParam,
|
|
19
25
|
},
|
|
20
26
|
{ additionalProperties: false },
|
|
@@ -23,9 +23,30 @@ const Edit = Type.Object(
|
|
|
23
23
|
},
|
|
24
24
|
{ additionalProperties: false },
|
|
25
25
|
);
|
|
26
|
+
const OnePosition = Type.Object(
|
|
27
|
+
{ line: Type.Integer({ minimum: 1 }), character: Type.Integer({ minimum: 1 }) },
|
|
28
|
+
{ additionalProperties: false },
|
|
29
|
+
);
|
|
30
|
+
const Action = Type.Object(
|
|
31
|
+
{
|
|
32
|
+
kind: Type.String(),
|
|
33
|
+
title: Type.String(),
|
|
34
|
+
provenance: Type.Optional(
|
|
35
|
+
Type.Union([Type.Literal("edit"), Type.Literal("captured-command")], {
|
|
36
|
+
description:
|
|
37
|
+
"edit: the action's own edit. captured-command: the edit the server pushed while running the action's command; SuPi refused it, so nothing was applied.",
|
|
38
|
+
}),
|
|
39
|
+
),
|
|
40
|
+
},
|
|
41
|
+
{ additionalProperties: false, description: "Server-reported code action kind and title." },
|
|
42
|
+
);
|
|
26
43
|
const Candidate = Type.Object(
|
|
27
44
|
{
|
|
28
45
|
description: Type.String(),
|
|
46
|
+
kind: Type.Optional(Type.String()),
|
|
47
|
+
title: Type.Optional(
|
|
48
|
+
Type.String({ description: "Pass back as the operation `title` to select this action." }),
|
|
49
|
+
),
|
|
29
50
|
file: Type.Optional(Type.String()),
|
|
30
51
|
line: Type.Optional(Type.Integer()),
|
|
31
52
|
character: Type.Optional(Type.Integer()),
|
|
@@ -37,6 +58,10 @@ const Candidate = Type.Object(
|
|
|
37
58
|
},
|
|
38
59
|
);
|
|
39
60
|
|
|
61
|
+
/** Guidance for choosing among matching code actions. */
|
|
62
|
+
export const AMBIGUOUS_NEXT_ACTION =
|
|
63
|
+
"Several matching actions produce different edits; repeat the call with one candidate's exact `title`";
|
|
64
|
+
|
|
40
65
|
/** Native plan data, including all edits rather than the bounded text preview. */
|
|
41
66
|
export const RefactorPlanOutputSchema = Type.Union([
|
|
42
67
|
Type.Object(
|
|
@@ -44,12 +69,27 @@ export const RefactorPlanOutputSchema = Type.Union([
|
|
|
44
69
|
kind: Type.Literal("completed"),
|
|
45
70
|
planId: Type.String(),
|
|
46
71
|
operation: Type.Enum([...PUBLIC_REFACTOR_OPERATION_NAMES], { type: "string" }),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
72
|
+
file: Type.String({ description: "File the operation was requested for." }),
|
|
73
|
+
target: Type.Optional(
|
|
74
|
+
Type.Object(
|
|
75
|
+
{ line: Type.Integer(), character: Type.Integer() },
|
|
76
|
+
{
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
description: "rename_symbol target; one-based line and UTF-16 character.",
|
|
79
|
+
},
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
range: Type.Optional(
|
|
83
|
+
Type.Object(
|
|
84
|
+
{ start: OnePosition, end: OnePosition },
|
|
85
|
+
{
|
|
86
|
+
additionalProperties: false,
|
|
87
|
+
description: "code_action range; one-based positions, end exclusive.",
|
|
88
|
+
},
|
|
89
|
+
),
|
|
50
90
|
),
|
|
51
91
|
newName: Type.Optional(Type.String()),
|
|
52
|
-
|
|
92
|
+
action: Type.Optional(Action),
|
|
53
93
|
edits: Type.Array(Edit),
|
|
54
94
|
fileCount: Type.Integer({ minimum: 0 }),
|
|
55
95
|
editCount: Type.Integer({ minimum: 0 }),
|
|
@@ -84,18 +124,20 @@ export function structuredRefactorPlan(
|
|
|
84
124
|
return {
|
|
85
125
|
kind: outcome.kind,
|
|
86
126
|
message: outcome.message,
|
|
87
|
-
nextAction: "Fix the
|
|
127
|
+
nextAction: "Fix the operation input and retry",
|
|
88
128
|
};
|
|
89
129
|
if (outcome.kind === "ambiguous")
|
|
90
130
|
return {
|
|
91
131
|
kind: outcome.kind,
|
|
92
132
|
candidates: outcome.candidates.map((candidate) => ({
|
|
93
133
|
description: candidate.description,
|
|
134
|
+
...(candidate.kind === undefined ? {} : { kind: candidate.kind }),
|
|
135
|
+
...(candidate.title === undefined ? {} : { title: candidate.title }),
|
|
94
136
|
...(candidate.file === undefined ? {} : { file: toDisplayPath(cwd, candidate.file) }),
|
|
95
137
|
...(candidate.line === undefined ? {} : { line: candidate.line }),
|
|
96
138
|
...(candidate.character === undefined ? {} : { character: candidate.character }),
|
|
97
139
|
})),
|
|
98
|
-
nextAction:
|
|
140
|
+
nextAction: AMBIGUOUS_NEXT_ACTION,
|
|
99
141
|
};
|
|
100
142
|
const plan = outcome.plan;
|
|
101
143
|
const operation = PUBLIC_REFACTOR_OPERATION_NAMES.find((name) => name === plan.operation);
|
|
@@ -104,13 +146,18 @@ export function structuredRefactorPlan(
|
|
|
104
146
|
kind: "completed",
|
|
105
147
|
planId: plan.id,
|
|
106
148
|
operation,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
149
|
+
file: toDisplayPath(cwd, plan.file),
|
|
150
|
+
...(plan.target === undefined ? {} : { target: { ...plan.target } }),
|
|
151
|
+
...(plan.range === undefined
|
|
152
|
+
? {}
|
|
153
|
+
: {
|
|
154
|
+
range: {
|
|
155
|
+
start: { ...plan.range.start },
|
|
156
|
+
end: { ...plan.range.end },
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
112
159
|
...(plan.newName === undefined ? {} : { newName: plan.newName }),
|
|
113
|
-
...(plan.
|
|
160
|
+
...(plan.action === undefined ? {} : { action: { ...plan.action } }),
|
|
114
161
|
edits: plan.edits.edits.map((edit) => ({
|
|
115
162
|
file: toDisplayPath(cwd, edit.file),
|
|
116
163
|
range: {
|
|
@@ -16,28 +16,25 @@ export function renderRefactorPlanCall(
|
|
|
16
16
|
theme: Theme,
|
|
17
17
|
_context: ToolRendererContext | undefined,
|
|
18
18
|
): Text {
|
|
19
|
-
const params = (args ?? {}) as {
|
|
20
|
-
operation?: Record<string, { newName?: unknown } | undefined>;
|
|
21
|
-
target?: { anchor?: { file?: unknown }; handle?: unknown };
|
|
22
|
-
};
|
|
19
|
+
const params = (args ?? {}) as { operation?: Record<string, unknown> };
|
|
23
20
|
|
|
24
21
|
let content = theme.fg("toolTitle", "code_refactor_plan");
|
|
25
22
|
const operation = params.operation ? Object.entries(params.operation)[0] : undefined;
|
|
26
23
|
if (operation) {
|
|
27
24
|
content += ` ${theme.fg("accent", formatCallValue(operation[0], 40) ?? "operation")}`;
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (
|
|
25
|
+
const payload = (operation[1] ?? {}) as {
|
|
26
|
+
newName?: unknown;
|
|
27
|
+
kind?: unknown;
|
|
28
|
+
file?: unknown;
|
|
29
|
+
target?: { anchor?: { file?: unknown }; handle?: unknown };
|
|
30
|
+
};
|
|
31
|
+
const detail = formatCallValue(payload.newName) ?? formatCallValue(payload.kind);
|
|
32
|
+
if (detail) content += ` ${theme.fg("muted", detail)}`;
|
|
33
|
+
const location =
|
|
34
|
+
formatCallPath(payload.file) ??
|
|
35
|
+
formatCallPath(payload.target?.anchor?.file) ??
|
|
36
|
+
formatCallValue(payload.target?.handle);
|
|
37
|
+
if (location) content += ` ${theme.fg("muted", location)}`;
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
return new Text(content, 0, 0);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const toolDescription =
|
|
2
|
-
"Resolve a real symbol anchor or semantic query to target handles for later code tools, or list a file's declarations as a
|
|
2
|
+
"Resolve a real symbol anchor or semantic query to target handles for later code tools, or list a file's declarations as a file outline. This tool does not search file text.";
|
|
3
3
|
|
|
4
4
|
export const promptSnippet = "resolve symbols or file declarations";
|
|
5
5
|
|