@mrclrchtr/supi-code-intelligence 11.4.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 +22 -0
- package/README.md +13 -7
- package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +1 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +51 -23
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/README.md +21 -16
- 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 +1 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +51 -23
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/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/manager/manager.ts +3 -1
- 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/session/route-boundary.ts +26 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +57 -12
- 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/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 +1 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +51 -23
- 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/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/target/anchored-structural.ts +4 -1
- package/src/analysis/target/symbol.ts +1 -1
- package/src/session/find-types.ts +8 -4
- package/src/session/find-workflow.ts +11 -16
- 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/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 +68 -243
- 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/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/spec.ts +8 -0
- 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/markdown.ts +1 -1
- package/src/tool/code_resolve/spec.ts +6 -0
- 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/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/schemas.ts +63 -20
- package/src/tool/specs.ts +3 -0
- package/src/ui/status-overlay.ts +1 -1
|
@@ -1,57 +1,38 @@
|
|
|
1
1
|
/** Session-owned refactor planning and apply workflows. */
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
RefactorOperation,
|
|
5
|
-
RefactorResult,
|
|
6
|
-
SemanticProvider,
|
|
7
|
-
SourceRange,
|
|
8
|
-
} from "@mrclrchtr/supi-code-runtime/api";
|
|
9
3
|
import { toLspPosition } from "@mrclrchtr/supi-lsp/api";
|
|
10
|
-
import { SEMANTIC_READINESS_TIMEOUT_REASON } from "../analysis/readiness.ts";
|
|
11
4
|
import { applyWorkspaceEdit } from "../analysis/refactor/apply.ts";
|
|
12
5
|
import {
|
|
13
6
|
isLatexSectionTarget,
|
|
14
7
|
refineLatexSectionRenameResult,
|
|
15
8
|
} from "../analysis/refactor/latex-section-rename.ts";
|
|
16
|
-
import {
|
|
17
|
-
establishMutationAuthority,
|
|
18
|
-
revalidateMutationAuthority,
|
|
19
|
-
} from "../analysis/refactor/mutation-authority.ts";
|
|
9
|
+
import { revalidateMutationAuthority } from "../analysis/refactor/mutation-authority.ts";
|
|
20
10
|
import { validateEdit } from "../analysis/refactor/safety.ts";
|
|
21
11
|
import { normalizePath } from "../analysis/search/paths.ts";
|
|
22
|
-
import type { CapabilityAdapter } from "./capability-adapter.ts";
|
|
23
12
|
import {
|
|
24
13
|
parseRefactorApplyWorkflowInput,
|
|
25
14
|
parseRefactorPlanWorkflowInput,
|
|
26
15
|
} from "./input/health-refactor.ts";
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
computeFileFingerprint,
|
|
30
|
-
generatePlanId,
|
|
31
|
-
isPlanFresh,
|
|
32
|
-
type RefactorPlan,
|
|
33
|
-
validateSynchronizedContentFingerprints,
|
|
34
|
-
} from "./refactor-plans.ts";
|
|
16
|
+
import { planFileAction } from "./refactor-file-actions.ts";
|
|
35
17
|
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
type
|
|
41
|
-
|
|
42
|
-
|
|
18
|
+
ensureFileReadiness,
|
|
19
|
+
finishProviderPlan,
|
|
20
|
+
immutablePlan,
|
|
21
|
+
planWithProvider,
|
|
22
|
+
type RefactorWorkflowDeps,
|
|
23
|
+
} from "./refactor-plan-pipeline.ts";
|
|
24
|
+
import { computeFileFingerprint, isPlanFresh } from "./refactor-plans.ts";
|
|
25
|
+
import type {
|
|
26
|
+
RefactorApplyWorkflowInput,
|
|
27
|
+
RefactorApplyWorkflowOutcome,
|
|
28
|
+
RefactorOperationInput,
|
|
29
|
+
RefactorPlanWorkflowInput,
|
|
30
|
+
RefactorPlanWorkflowOutcome,
|
|
43
31
|
} from "./refactor-types.ts";
|
|
44
32
|
import type { TargetStoreEntry } from "./target-store.ts";
|
|
45
|
-
import { resolveTargetWorkflow
|
|
33
|
+
import { resolveTargetWorkflow } from "./target-workflow.ts";
|
|
46
34
|
import { reportProgress, throwIfAborted, type WorkflowControl } from "./workflow-control.ts";
|
|
47
35
|
|
|
48
|
-
export interface RefactorWorkflowDeps extends TargetWorkflowDeps {
|
|
49
|
-
readonly capability: CapabilityAdapter;
|
|
50
|
-
readonly storePlan: (plan: RefactorPlan) => string;
|
|
51
|
-
readonly getPlan: (id: string) => RefactorPlan | undefined;
|
|
52
|
-
readonly removePlan: (id: string) => void;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
36
|
/** Plan one precise refactor without mutating files. */
|
|
56
37
|
export async function runRefactorPlanWorkflow(
|
|
57
38
|
input: RefactorPlanWorkflowInput,
|
|
@@ -60,24 +41,27 @@ export async function runRefactorPlanWorkflow(
|
|
|
60
41
|
): Promise<RefactorPlanWorkflowOutcome> {
|
|
61
42
|
const validatedInput = parseRefactorPlanWorkflowInput(input);
|
|
62
43
|
if (validatedInput.kind === "invalid-input") return validatedInput;
|
|
63
|
-
const
|
|
64
|
-
const parsed = parseOperation(request.operation);
|
|
65
|
-
if (parsed.kind === "invalid-input") return parsed;
|
|
66
|
-
const rangeError = parsed.range ? validateRange(parsed.range) : null;
|
|
67
|
-
if (rangeError) return { kind: "invalid-input", message: rangeError };
|
|
68
|
-
|
|
44
|
+
const { operation } = validatedInput.value;
|
|
69
45
|
throwIfAborted(control);
|
|
46
|
+
if ("rename_symbol" in operation) {
|
|
47
|
+
return planRename(operation.rename_symbol, deps, control);
|
|
48
|
+
}
|
|
49
|
+
return planFileAction(operation, deps, control);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function planRename(
|
|
53
|
+
input: Extract<RefactorOperationInput, { rename_symbol: unknown }>["rename_symbol"],
|
|
54
|
+
deps: RefactorWorkflowDeps,
|
|
55
|
+
control?: WorkflowControl,
|
|
56
|
+
): Promise<RefactorPlanWorkflowOutcome> {
|
|
70
57
|
reportProgress(control, {
|
|
71
58
|
intent: "refactor-plan",
|
|
72
59
|
phase: "target",
|
|
73
60
|
message: "Resolving refactor target",
|
|
74
61
|
});
|
|
75
62
|
const target = await resolveTargetWorkflow(
|
|
76
|
-
|
|
77
|
-
{
|
|
78
|
-
fileLevelAllowed: false,
|
|
79
|
-
nameAnchorRequired: parsed.operation === "rename_symbol",
|
|
80
|
-
},
|
|
63
|
+
input.target,
|
|
64
|
+
{ fileLevelAllowed: false, nameAnchorRequired: true },
|
|
81
65
|
deps,
|
|
82
66
|
control,
|
|
83
67
|
);
|
|
@@ -86,28 +70,48 @@ export async function runRefactorPlanWorkflow(
|
|
|
86
70
|
return {
|
|
87
71
|
kind: "invalid-input",
|
|
88
72
|
message:
|
|
89
|
-
"
|
|
73
|
+
"Rename requires one declaration, not a whole file. Pass one handle from the file outline as target.handle.",
|
|
90
74
|
};
|
|
91
75
|
}
|
|
92
76
|
if (target.kind === "disambiguation" || target.kind === "kind-mismatch") {
|
|
93
77
|
return {
|
|
94
78
|
kind: "invalid-input",
|
|
95
|
-
message: "
|
|
79
|
+
message: "Rename requires one precise target handle or anchor.",
|
|
96
80
|
};
|
|
97
81
|
}
|
|
98
82
|
if (target.kind !== "resolved") return target;
|
|
99
83
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
84
|
+
const file = normalizePath(target.entry.file, deps.cwd);
|
|
85
|
+
const readiness = await ensureFileReadiness(file, deps, control);
|
|
86
|
+
if (readiness) return readiness;
|
|
87
|
+
const sectionRename = await planWithLatexSafety({
|
|
88
|
+
newName: input.newName,
|
|
89
|
+
target: target.entry,
|
|
90
|
+
file,
|
|
91
|
+
deps,
|
|
103
92
|
control,
|
|
104
|
-
);
|
|
105
|
-
if (
|
|
106
|
-
|
|
93
|
+
});
|
|
94
|
+
if (
|
|
95
|
+
sectionRename.result.kind === "precise" &&
|
|
96
|
+
sectionRename.sourceFingerprint &&
|
|
97
|
+
computeFileFingerprint(file) !== sectionRename.sourceFingerprint
|
|
98
|
+
) {
|
|
99
|
+
return {
|
|
100
|
+
kind: "unavailable",
|
|
101
|
+
reason: "The LaTeX source changed before the title rename plan was stored.",
|
|
102
|
+
};
|
|
107
103
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
return finishProviderPlan(sectionRename.result, deps, {
|
|
105
|
+
operation: "rename_symbol",
|
|
106
|
+
file,
|
|
107
|
+
discriminator: `${target.entry.displayLine}:${target.entry.displayCharacter}:${input.newName}`,
|
|
108
|
+
fields: {
|
|
109
|
+
newName: input.newName,
|
|
110
|
+
target: { line: target.entry.displayLine, character: target.entry.displayCharacter },
|
|
111
|
+
},
|
|
112
|
+
evidenceSource: sectionRename.evidenceSource,
|
|
113
|
+
sourceFingerprint: sectionRename.sourceFingerprint,
|
|
114
|
+
});
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
/** Revalidate and apply one stored plan through the per-file mutation queue. */
|
|
@@ -157,94 +161,17 @@ export async function runRefactorApplyWorkflow(
|
|
|
157
161
|
return { kind: "completed", plan: immutablePlan(plan), result };
|
|
158
162
|
}
|
|
159
163
|
|
|
160
|
-
type ParsedRefactorOperation = Extract<ReturnType<typeof parseOperation>, { kind: "ok" }>;
|
|
161
164
|
type RefinedRefactorResult = Awaited<ReturnType<typeof refineLatexSectionRenameResult>>;
|
|
162
165
|
|
|
163
|
-
async function planResolvedRefactor(
|
|
164
|
-
parsed: ParsedRefactorOperation,
|
|
165
|
-
target: Readonly<TargetStoreEntry>,
|
|
166
|
-
deps: RefactorWorkflowDeps,
|
|
167
|
-
control?: WorkflowControl,
|
|
168
|
-
): Promise<RefactorPlanWorkflowOutcome> {
|
|
169
|
-
const file = normalizePath(target.file, deps.cwd);
|
|
170
|
-
const sectionRename = await planWithLatexSafety({ parsed, target, file, deps, control });
|
|
171
|
-
const result = sectionRename.result;
|
|
172
|
-
if (result.kind === "unavailable") return result;
|
|
173
|
-
if (result.kind === "ambiguous") {
|
|
174
|
-
return { kind: "ambiguous", candidates: result.candidates };
|
|
175
|
-
}
|
|
176
|
-
if (
|
|
177
|
-
sectionRename.sourceFingerprint &&
|
|
178
|
-
computeFileFingerprint(file) !== sectionRename.sourceFingerprint
|
|
179
|
-
) {
|
|
180
|
-
return {
|
|
181
|
-
kind: "unavailable",
|
|
182
|
-
reason: "The LaTeX source changed before the title rename plan was stored.",
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const validation = validateEdit(result.edits);
|
|
187
|
-
if (!validation.safe) {
|
|
188
|
-
return { kind: "invalid-input", message: `Refactor safety check failed: ${validation.reason}` };
|
|
189
|
-
}
|
|
190
|
-
const authority = establishMutationAuthority(
|
|
191
|
-
result.edits.edits.map((edit) => edit.file),
|
|
192
|
-
result.authorizedMutationRoots,
|
|
193
|
-
);
|
|
194
|
-
if (authority.kind === "unavailable") return authority;
|
|
195
|
-
const fileFingerprints = collectFileFingerprints(
|
|
196
|
-
result.edits.edits,
|
|
197
|
-
sectionRename.sourceFingerprint
|
|
198
|
-
? { file, fingerprint: sectionRename.sourceFingerprint }
|
|
199
|
-
: undefined,
|
|
200
|
-
);
|
|
201
|
-
const snapshotError = validateSynchronizedContentFingerprints(
|
|
202
|
-
result.edits.documentPreconditions,
|
|
203
|
-
fileFingerprints,
|
|
204
|
-
deps.cwd,
|
|
205
|
-
);
|
|
206
|
-
if (snapshotError) return { kind: "unavailable", reason: snapshotError };
|
|
207
|
-
const changed = dropIdentityEdits(result.edits, fileFingerprints);
|
|
208
|
-
if (changed.kind === "unavailable") return changed;
|
|
209
|
-
if (changed.edits.edits.length === 0) {
|
|
210
|
-
return {
|
|
211
|
-
kind: "invalid-input",
|
|
212
|
-
message: `The ${parsed.operation} refactor produces no changes; every planned edit matches the current text.`,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const plan: RefactorPlan = {
|
|
217
|
-
id: generatePlanId(
|
|
218
|
-
parsed.operation,
|
|
219
|
-
file,
|
|
220
|
-
target.displayLine,
|
|
221
|
-
target.displayCharacter,
|
|
222
|
-
parsed.newName,
|
|
223
|
-
),
|
|
224
|
-
operation: parsed.operation,
|
|
225
|
-
newName: parsed.newName,
|
|
226
|
-
targetFile: file,
|
|
227
|
-
targetLine: target.displayLine,
|
|
228
|
-
targetCharacter: target.displayCharacter,
|
|
229
|
-
edits: changed.edits,
|
|
230
|
-
evidenceSource: sectionRename.evidenceSource,
|
|
231
|
-
authorizedMutationRoots: authority.canonicalRoots,
|
|
232
|
-
fileFingerprints: changed.fileFingerprints,
|
|
233
|
-
createdAt: Date.now(),
|
|
234
|
-
};
|
|
235
|
-
deps.storePlan(plan);
|
|
236
|
-
return { kind: "completed", plan: immutablePlan(plan) };
|
|
237
|
-
}
|
|
238
|
-
|
|
239
166
|
async function planWithLatexSafety(input: {
|
|
240
|
-
readonly
|
|
167
|
+
readonly newName: string;
|
|
241
168
|
readonly target: Readonly<TargetStoreEntry>;
|
|
242
169
|
readonly file: string;
|
|
243
170
|
readonly deps: RefactorWorkflowDeps;
|
|
244
171
|
readonly control?: WorkflowControl;
|
|
245
172
|
}): Promise<RefinedRefactorResult> {
|
|
246
|
-
const {
|
|
247
|
-
const isLatexRename =
|
|
173
|
+
const { newName, target, file, deps, control } = input;
|
|
174
|
+
const isLatexRename = isLatexSectionTarget(target);
|
|
248
175
|
if (isLatexRename && computeFileFingerprint(file) !== target.fileFingerprint) {
|
|
249
176
|
return {
|
|
250
177
|
result: {
|
|
@@ -258,11 +185,10 @@ async function planWithLatexSafety(input: {
|
|
|
258
185
|
const result = await planWithProvider(
|
|
259
186
|
deps.capability.getSemanticProvider(deps.cwd),
|
|
260
187
|
{
|
|
261
|
-
operation:
|
|
188
|
+
operation: "rename_symbol",
|
|
262
189
|
file,
|
|
263
190
|
position: toLspPosition(target.displayLine, target.displayCharacter),
|
|
264
|
-
|
|
265
|
-
newName: parsed.newName,
|
|
191
|
+
newName,
|
|
266
192
|
},
|
|
267
193
|
control,
|
|
268
194
|
);
|
|
@@ -276,11 +202,11 @@ async function planWithLatexSafety(input: {
|
|
|
276
202
|
};
|
|
277
203
|
}
|
|
278
204
|
return refineLatexSectionRenameResult({
|
|
279
|
-
operation:
|
|
205
|
+
operation: "rename_symbol",
|
|
280
206
|
result,
|
|
281
207
|
target,
|
|
282
208
|
file,
|
|
283
|
-
newName
|
|
209
|
+
newName,
|
|
284
210
|
structural: deps.capability.getStructuralProvider(deps.cwd),
|
|
285
211
|
documentVersionReader: getDocumentVersionReader(deps),
|
|
286
212
|
control,
|
|
@@ -295,104 +221,3 @@ function getDocumentVersionReader(
|
|
|
295
221
|
if (typeof state.runtime.getOpenDocumentVersion !== "function") return undefined;
|
|
296
222
|
return (file) => state.runtime.getOpenDocumentVersion(file);
|
|
297
223
|
}
|
|
298
|
-
|
|
299
|
-
function parseOperation(input: RefactorOperationInput):
|
|
300
|
-
| {
|
|
301
|
-
kind: "ok";
|
|
302
|
-
operation: RefactorOperation;
|
|
303
|
-
newName?: string;
|
|
304
|
-
range?: PublicSourceRange;
|
|
305
|
-
}
|
|
306
|
-
| { kind: "invalid-input"; message: string } {
|
|
307
|
-
const keys = PUBLIC_REFACTOR_OPERATION_NAMES.filter((key) => key in input);
|
|
308
|
-
if (keys.length !== 1) {
|
|
309
|
-
return { kind: "invalid-input", message: "Select exactly one refactor operation." };
|
|
310
|
-
}
|
|
311
|
-
if ("rename_symbol" in input) {
|
|
312
|
-
return {
|
|
313
|
-
kind: "ok",
|
|
314
|
-
operation: "rename_symbol",
|
|
315
|
-
newName: input.rename_symbol.newName,
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
if ("extract_function" in input) {
|
|
319
|
-
return {
|
|
320
|
-
kind: "ok",
|
|
321
|
-
operation: "extract_function",
|
|
322
|
-
newName: input.extract_function.newName,
|
|
323
|
-
range: input.extract_function.range,
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
if ("extract_variable" in input) {
|
|
327
|
-
return {
|
|
328
|
-
kind: "ok",
|
|
329
|
-
operation: "extract_variable",
|
|
330
|
-
newName: input.extract_variable.newName,
|
|
331
|
-
range: input.extract_variable.range,
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
return {
|
|
335
|
-
kind: "ok",
|
|
336
|
-
operation: "update_imports" in input ? "update_imports" : "delete_dead_code",
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function validateRange(range: PublicSourceRange): string | null {
|
|
341
|
-
if (
|
|
342
|
-
range.end.line < range.start.line ||
|
|
343
|
-
(range.end.line === range.start.line && range.end.character <= range.start.character)
|
|
344
|
-
) {
|
|
345
|
-
return "range.end must be after range.start.";
|
|
346
|
-
}
|
|
347
|
-
return null;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function toLspRange(range: PublicSourceRange): SourceRange {
|
|
351
|
-
return {
|
|
352
|
-
start: toLspPosition(range.start.line, range.start.character),
|
|
353
|
-
end: toLspPosition(range.end.line, range.end.character),
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
async function planWithProvider(
|
|
358
|
-
provider: SemanticProvider | null,
|
|
359
|
-
request: {
|
|
360
|
-
operation: RefactorOperation;
|
|
361
|
-
file: string;
|
|
362
|
-
position: { line: number; character: number };
|
|
363
|
-
range?: SourceRange;
|
|
364
|
-
newName?: string;
|
|
365
|
-
},
|
|
366
|
-
control?: WorkflowControl,
|
|
367
|
-
): Promise<RefactorResult> {
|
|
368
|
-
if (!provider) return { kind: "unavailable", reason: "No semantic provider is active." };
|
|
369
|
-
if (provider.refactor) return provider.refactor(request, control);
|
|
370
|
-
if (request.operation === "rename_symbol" && request.newName !== undefined && provider.rename) {
|
|
371
|
-
return provider.rename(request.file, request.position, request.newName, control);
|
|
372
|
-
}
|
|
373
|
-
return {
|
|
374
|
-
kind: "unavailable",
|
|
375
|
-
reason: `The semantic provider cannot plan ${request.operation}.`,
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function immutablePlan(plan: RefactorPlan): Readonly<RefactorPlan> {
|
|
380
|
-
return Object.freeze({
|
|
381
|
-
...plan,
|
|
382
|
-
edits: Object.freeze({
|
|
383
|
-
...plan.edits,
|
|
384
|
-
edits: Object.freeze(plan.edits.edits.map((edit) => Object.freeze({ ...edit }))),
|
|
385
|
-
documentPreconditions: plan.edits.documentPreconditions
|
|
386
|
-
? Object.freeze(
|
|
387
|
-
plan.edits.documentPreconditions.map((precondition) =>
|
|
388
|
-
Object.freeze({ ...precondition }),
|
|
389
|
-
),
|
|
390
|
-
)
|
|
391
|
-
: undefined,
|
|
392
|
-
}),
|
|
393
|
-
authorizedMutationRoots: Object.freeze([...plan.authorizedMutationRoots]),
|
|
394
|
-
fileFingerprints: Object.freeze(
|
|
395
|
-
plan.fileFingerprints.map((fingerprint) => Object.freeze({ ...fingerprint })),
|
|
396
|
-
),
|
|
397
|
-
}) as Readonly<RefactorPlan>;
|
|
398
|
-
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
/** Thin Pi adapter for the session-owned code_find workflow. */
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { FindSearchInput, FindWorkflowInput } from "../../session/find-types.ts";
|
|
4
4
|
import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
|
|
5
5
|
import { toWorkflowControl } from "../infra/workflow-control.ts";
|
|
6
|
-
import type { CodeFindAstKind } from "./ast-kinds.ts";
|
|
7
6
|
import { finishFindResult } from "./result.ts";
|
|
8
7
|
|
|
9
8
|
export interface CodeFindToolParams {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
mode: FindMode;
|
|
13
|
-
kind?: CodeFindAstKind;
|
|
9
|
+
search: FindSearchInput;
|
|
10
|
+
scopes?: string[];
|
|
14
11
|
maxResults?: number;
|
|
15
12
|
}
|
|
16
13
|
|
|
@@ -19,5 +16,7 @@ export async function executeFindTool(
|
|
|
19
16
|
ctx: CodeIntelToolExecCtx,
|
|
20
17
|
): Promise<CodeIntelResult> {
|
|
21
18
|
const outcome = await ctx.session.find(params as FindWorkflowInput, toWorkflowControl(ctx));
|
|
22
|
-
|
|
19
|
+
const semantic =
|
|
20
|
+
typeof params.search === "object" && params.search !== null && "semantic" in params.search;
|
|
21
|
+
return finishFindResult(outcome, ctx.cwd, params.scopes, semantic ? "semantic" : "ast");
|
|
23
22
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import type { CodeIntelToolExecCtx } from "../../types/index.ts";
|
|
3
|
-
import {
|
|
4
|
-
import { CODE_FIND_AST_KINDS } from "./ast-kinds.ts";
|
|
3
|
+
import { FindScopesParam, FindSearchParam, MaxResultsParam } from "../schemas.ts";
|
|
5
4
|
import { executeFindTool } from "./execute.ts";
|
|
6
|
-
import { CODE_FIND_MODES } from "./modes.ts";
|
|
7
5
|
import { FindOutputSchema } from "./structured.ts";
|
|
8
6
|
import { renderFindCall, renderFindResult } from "./tui.ts";
|
|
9
7
|
|
|
@@ -14,22 +12,17 @@ export const CODE_FIND_TOOL_LABEL = "Code Find";
|
|
|
14
12
|
export const codeFindSpec = {
|
|
15
13
|
name: CODE_FIND_TOOL_NAME,
|
|
16
14
|
label: CODE_FIND_TOOL_LABEL,
|
|
15
|
+
annotations: {
|
|
16
|
+
readOnlyHint: true,
|
|
17
|
+
destructiveHint: false,
|
|
18
|
+
idempotentHint: true,
|
|
19
|
+
openWorldHint: false,
|
|
20
|
+
},
|
|
17
21
|
outputSchema: FindOutputSchema,
|
|
18
22
|
parameters: Type.Object(
|
|
19
23
|
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
mode: Type.Enum(CODE_FIND_MODES, {
|
|
23
|
-
type: "string",
|
|
24
|
-
description:
|
|
25
|
-
"Required code-aware search mode. AST mode requires `kind`; semantic mode rejects `kind`.",
|
|
26
|
-
}),
|
|
27
|
-
kind: Type.Optional(
|
|
28
|
-
Type.Enum(CODE_FIND_AST_KINDS, {
|
|
29
|
-
type: "string",
|
|
30
|
-
description: 'AST structure kind; required only for mode:"ast".',
|
|
31
|
-
}),
|
|
32
|
-
),
|
|
24
|
+
search: FindSearchParam,
|
|
25
|
+
scopes: Type.Optional(FindScopesParam),
|
|
33
26
|
maxResults: Type.Optional(MaxResultsParam),
|
|
34
27
|
},
|
|
35
28
|
{ additionalProperties: false },
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type ToolRendererContext,
|
|
9
9
|
type ToolResult,
|
|
10
10
|
} from "../../ui/tui/common.ts";
|
|
11
|
-
import
|
|
11
|
+
import { CODE_FIND_MODES } from "./modes.ts";
|
|
12
12
|
|
|
13
13
|
/** Render the compact code_find call header. */
|
|
14
14
|
export function renderFindCall(
|
|
@@ -16,15 +16,21 @@ export function renderFindCall(
|
|
|
16
16
|
theme: Theme,
|
|
17
17
|
_context: ToolRendererContext | undefined,
|
|
18
18
|
): Text {
|
|
19
|
-
|
|
20
|
-
const
|
|
19
|
+
// Streaming calls arrive partial, so every level is read defensively.
|
|
20
|
+
const search = ((args ?? {}) as { search?: unknown }).search;
|
|
21
|
+
const branches = (search && typeof search === "object" ? search : {}) as Record<
|
|
22
|
+
string,
|
|
23
|
+
{ query?: unknown; kind?: unknown } | undefined
|
|
24
|
+
>;
|
|
25
|
+
const mode = CODE_FIND_MODES.find((candidate) => branches[candidate] !== undefined);
|
|
26
|
+
const branch = (mode ? branches[mode] : undefined) ?? {};
|
|
21
27
|
|
|
22
28
|
let content = theme.fg("toolTitle", "code_find");
|
|
23
|
-
const query = formatCallValue(
|
|
29
|
+
const query = formatCallValue(branch.query);
|
|
24
30
|
if (query) content += ` ${theme.fg("accent", JSON.stringify(query))}`;
|
|
25
|
-
content += ` ${theme.fg("muted", mode)}`;
|
|
31
|
+
content += ` ${theme.fg("muted", mode ?? "mode?")}`;
|
|
26
32
|
|
|
27
|
-
const kind = formatCallValue(
|
|
33
|
+
const kind = formatCallValue(branch.kind, 30);
|
|
28
34
|
if (kind) content += theme.fg("dim", ` [${kind}]`);
|
|
29
35
|
|
|
30
36
|
return new Text(content, 0, 0);
|
|
@@ -12,6 +12,12 @@ export const CODE_GRAPH_TOOL_LABEL = "Code Graph";
|
|
|
12
12
|
export const codeGraphSpec = {
|
|
13
13
|
name: CODE_GRAPH_TOOL_NAME,
|
|
14
14
|
label: CODE_GRAPH_TOOL_LABEL,
|
|
15
|
+
annotations: {
|
|
16
|
+
readOnlyHint: true,
|
|
17
|
+
destructiveHint: false,
|
|
18
|
+
idempotentHint: true,
|
|
19
|
+
openWorldHint: false,
|
|
20
|
+
},
|
|
15
21
|
outputSchema: GraphOutputSchema,
|
|
16
22
|
parameters: Type.Object(
|
|
17
23
|
{
|
|
@@ -12,6 +12,12 @@ export const CODE_HEALTH_TOOL_LABEL = "Code Health";
|
|
|
12
12
|
export const codeHealthSpec = {
|
|
13
13
|
name: CODE_HEALTH_TOOL_NAME,
|
|
14
14
|
label: CODE_HEALTH_TOOL_LABEL,
|
|
15
|
+
annotations: {
|
|
16
|
+
readOnlyHint: true,
|
|
17
|
+
destructiveHint: false,
|
|
18
|
+
idempotentHint: true,
|
|
19
|
+
openWorldHint: false,
|
|
20
|
+
},
|
|
15
21
|
parameters: Type.Object(
|
|
16
22
|
{
|
|
17
23
|
scope: Type.Optional(ScopeParam),
|
|
@@ -77,14 +77,14 @@ const operation = object({
|
|
|
77
77
|
server: Type.Enum(["advertised", "not-advertised", "unknown"], { type: "string" }),
|
|
78
78
|
supi: Type.Enum(["supported", "limited", "unsupported"], { type: "string" }),
|
|
79
79
|
reason: Type.Optional(Type.String()),
|
|
80
|
+
kinds: Type.Optional(Type.Array(Type.String())),
|
|
81
|
+
anyKind: Type.Optional(Type.Boolean()),
|
|
80
82
|
});
|
|
81
83
|
const support = object({
|
|
82
84
|
rename_symbol: Type.Optional(operation),
|
|
83
85
|
prepare_rename: Type.Optional(operation),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
update_imports: Type.Optional(operation),
|
|
87
|
-
delete_dead_code: Type.Optional(operation),
|
|
86
|
+
code_action: Type.Optional(operation),
|
|
87
|
+
source_action: Type.Optional(operation),
|
|
88
88
|
code_action_resolve: Type.Optional(operation),
|
|
89
89
|
});
|
|
90
90
|
const server = object({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DiagnosticEvidenceSummary } from "@mrclrchtr/supi-lsp/api";
|
|
1
|
+
import type { DiagnosticEvidenceSummary, ServerOperationSupport } from "@mrclrchtr/supi-lsp/api";
|
|
2
2
|
import type { Static } from "typebox";
|
|
3
3
|
import type {
|
|
4
4
|
HealthData,
|
|
@@ -166,10 +166,8 @@ export function structuredHealthResult(data: HealthData): Output {
|
|
|
166
166
|
const operations = [
|
|
167
167
|
"rename_symbol",
|
|
168
168
|
"prepare_rename",
|
|
169
|
-
"
|
|
170
|
-
"
|
|
171
|
-
"update_imports",
|
|
172
|
-
"delete_dead_code",
|
|
169
|
+
"code_action",
|
|
170
|
+
"source_action",
|
|
173
171
|
"code_action_resolve",
|
|
174
172
|
] as const;
|
|
175
173
|
const servers = data.servers.map(
|
|
@@ -197,18 +195,7 @@ export function structuredHealthResult(data: HealthData): Output {
|
|
|
197
195
|
operationSupport: Object.fromEntries(
|
|
198
196
|
operations.flatMap((key) => {
|
|
199
197
|
const item = operationSupport[key];
|
|
200
|
-
return item
|
|
201
|
-
? [
|
|
202
|
-
[
|
|
203
|
-
key,
|
|
204
|
-
{
|
|
205
|
-
server: item.server,
|
|
206
|
-
supi: item.supi,
|
|
207
|
-
...(item.reason === undefined ? {} : { reason: item.reason }),
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
]
|
|
211
|
-
: [];
|
|
198
|
+
return item ? [[key, structuredOperationSupport(item)]] : [];
|
|
212
199
|
}),
|
|
213
200
|
),
|
|
214
201
|
}
|
|
@@ -254,3 +241,14 @@ export function structuredHealthResult(data: HealthData): Output {
|
|
|
254
241
|
: {}),
|
|
255
242
|
} as Output;
|
|
256
243
|
}
|
|
244
|
+
|
|
245
|
+
/** Copy one operation-support entry, omitting absent optional fields. */
|
|
246
|
+
function structuredOperationSupport(item: ServerOperationSupport) {
|
|
247
|
+
return {
|
|
248
|
+
server: item.server,
|
|
249
|
+
supi: item.supi,
|
|
250
|
+
...(item.reason === undefined ? {} : { reason: item.reason }),
|
|
251
|
+
...(item.kinds === undefined ? {} : { kinds: [...item.kinds] }),
|
|
252
|
+
...(item.anyKind ? { anyKind: true } : {}),
|
|
253
|
+
};
|
|
254
|
+
}
|