@mrclrchtr/supi-code-intelligence 11.1.0 → 11.2.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/README.md +29 -4
- package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/README.md +42 -5
- 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-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/LICENSE +15 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/README.md +680 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/bin/semver.js +195 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/comparator.js +143 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/index.js +7 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +577 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/semver.js +350 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/clean.js +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/cmp.js +54 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/coerce.js +62 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare-build.js +9 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare-loose.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare.js +7 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/diff.js +60 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/eq.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/gt.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/gte.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/inc.js +21 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/lt.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/lte.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/major.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/minor.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/neq.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/parse.js +18 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/patch.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/prerelease.js +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/rcompare.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/rsort.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/satisfies.js +12 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/sort.js +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/truncate.js +48 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/valid.js +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/index.js +93 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +37 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/debug.js +11 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/identifiers.js +29 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/lrucache.js +42 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/parse-options.js +17 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/re.js +223 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +78 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/preload.js +4 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/range.bnf +17 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/gtr.js +6 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/intersects.js +9 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/ltr.js +6 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/max-satisfying.js +27 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/min-satisfying.js +26 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/min-version.js +63 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/outside.js +82 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/simplify.js +49 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/subset.js +249 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/to-comparators.js +10 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/valid.js +13 -0
- package/node_modules/@mrclrchtr/supi-lsp/package.json +5 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +23 -5
- package/node_modules/@mrclrchtr/supi-lsp/src/config/config.ts +53 -2
- package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +19 -4
- package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +22 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/typescript-launch.ts +276 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-project-info.ts +22 -10
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +52 -19
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +4 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/src/session/scanner.ts +27 -15
- 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-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
- package/package.json +5 -5
- package/src/analysis/capability/capability-warnings.ts +18 -12
- package/src/analysis/health/check.ts +115 -0
- package/src/analysis/health/diagnostics.ts +3 -0
- package/src/analysis/health/file-scope.ts +2 -3
- package/src/analysis/health/semantic-state.ts +38 -0
- package/src/analysis/health/server-status.ts +8 -0
- package/src/analysis/health/signals.ts +2 -0
- package/src/analysis/health/status.ts +82 -0
- package/src/analysis/refactor/apply.ts +17 -8
- package/src/session/health-types.ts +7 -0
- package/src/session/health-workflow.ts +8 -43
- package/src/session/orientation/collect.ts +138 -12
- package/src/session/orientation/context-facts.ts +27 -2
- package/src/session/orientation/context-sections.ts +47 -0
- package/src/session/orientation/facts.ts +124 -0
- package/src/session/orientation/gather.ts +98 -11
- package/src/session/orientation/workspace-context.ts +16 -6
- package/src/session/orientation-types.ts +5 -0
- package/src/session/orientation-workflow.ts +3 -2
- package/src/session/refactor-plans.ts +5 -2
- package/src/session/refactor-workflow.ts +4 -3
- package/src/tool/code_find/guidance.ts +1 -1
- package/src/tool/code_health/markdown.ts +12 -2
- package/src/tool/code_health/result.ts +15 -2
- package/src/tool/code_health/spec.ts +2 -0
- package/src/tool/code_health/structured-schema.ts +250 -0
- package/src/tool/code_health/structured.ts +256 -0
- package/src/tool/code_inspect/result.ts +11 -5
- package/src/tool/code_inspect/spec.ts +2 -0
- package/src/tool/code_inspect/structured.ts +232 -0
- package/src/tool/code_orientation/result.ts +10 -4
- package/src/tool/code_orientation/spec.ts +2 -0
- package/src/tool/code_orientation/structured-schema.ts +607 -0
- package/src/tool/code_orientation/structured-workspace.ts +193 -0
- package/src/tool/code_orientation/structured.ts +195 -0
- package/src/tool/code_orientation/workspace-observations.ts +81 -0
- package/src/tool/code_orientation/workspace-output.ts +5 -0
- package/src/tool/code_orientation/workspace-projects.ts +16 -31
- package/src/tool/code_orientation/workspace-sections.ts +43 -30
- package/src/tool/code_refactor_apply/execute.ts +1 -1
- package/src/tool/code_refactor_apply/result.ts +13 -5
- package/src/tool/code_refactor_apply/spec.ts +2 -0
- package/src/tool/code_refactor_apply/structured.ts +49 -0
- package/src/tool/code_refactor_plan/result.ts +16 -8
- package/src/tool/code_refactor_plan/spec.ts +2 -0
- package/src/tool/code_refactor_plan/structured.ts +128 -0
- package/src/tool/schemas.ts +7 -1
- package/src/ui/status-command.ts +110 -321
- package/src/ui/status-overlay.ts +564 -420
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
} from "../../session/orientation-types.ts";
|
|
11
11
|
import { gradleSections } from "./gradle-sections.ts";
|
|
12
12
|
import { code, plain, sourcePath, tableSection } from "./workspace-format.ts";
|
|
13
|
+
import { workspaceCollectionStatus } from "./workspace-observations.ts";
|
|
13
14
|
import { projectSections } from "./workspace-projects.ts";
|
|
14
15
|
|
|
15
16
|
/** Build output facts from one captured observation, with no filesystem reads. */
|
|
@@ -104,37 +105,25 @@ function collectionStatus(
|
|
|
104
105
|
observation: WorkspaceObservation,
|
|
105
106
|
): OrientationSectionData {
|
|
106
107
|
if (section.key === "workspace.issues" || section.key.startsWith("gradle.")) return section;
|
|
107
|
-
const
|
|
108
|
-
const inventoryPartial =
|
|
109
|
-
collection.stopReason !== "complete" ||
|
|
110
|
-
collection.errors.some((error) => error.stage === "inventory");
|
|
108
|
+
const state = workspaceCollectionStatus(observation.collection);
|
|
111
109
|
const partial = section.provenance.some((source) => source.source === "filesystem")
|
|
112
|
-
? inventoryPartial
|
|
113
|
-
:
|
|
110
|
+
? state.inventoryPartial
|
|
111
|
+
: state.metadataPartial;
|
|
114
112
|
if (!partial) return section;
|
|
115
|
-
const reason =
|
|
116
|
-
collection.stopReason === "entry-limit"
|
|
117
|
-
? "safety-limit"
|
|
118
|
-
: collection.stopReason === "deadline"
|
|
119
|
-
? "timeout"
|
|
120
|
-
: inventoryPartial
|
|
121
|
-
? "filesystem-error"
|
|
122
|
-
: "configuration-error";
|
|
123
113
|
return {
|
|
124
114
|
...section,
|
|
125
115
|
status: "partial",
|
|
126
|
-
reason:
|
|
127
|
-
? "Inventory collection is incomplete"
|
|
128
|
-
: "Metadata collection is incomplete",
|
|
116
|
+
reason: state.reason,
|
|
129
117
|
evidenceLists: section.evidenceLists.map((list) => ({
|
|
130
118
|
...list,
|
|
131
119
|
totalCount: null,
|
|
132
|
-
partialReason:
|
|
120
|
+
partialReason: state.partialReason,
|
|
133
121
|
})),
|
|
134
122
|
};
|
|
135
123
|
}
|
|
136
124
|
|
|
137
|
-
|
|
125
|
+
/** Nearest project declarations containing the focus, established by parsed metadata. */
|
|
126
|
+
export function containingProjects(facts: WorkspaceOrientationFacts, root: string) {
|
|
138
127
|
const candidates = facts.observation.projects.filter((project) =>
|
|
139
128
|
within(path.resolve(facts.observation.root, project.directory), root),
|
|
140
129
|
);
|
|
@@ -166,11 +155,17 @@ function inventoryNote(
|
|
|
166
155
|
return `Inventory: ${files} regular file${files === 1 ? "" : "s"} and ${links} symbolic links. Includes ${policy}; link targets are not followed.${exclusions} Collection ${collection.status}${collection.stopReason !== "complete" ? ` (${collection.stopReason}; more entries may exist)` : ""}.`;
|
|
167
156
|
}
|
|
168
157
|
|
|
169
|
-
|
|
158
|
+
/** Named inventory observations before presentation and per-list selection. */
|
|
159
|
+
export interface WorkspaceInventoryFacts {
|
|
160
|
+
readonly directories: readonly { path: string; entryCount: number }[];
|
|
161
|
+
readonly directFiles: readonly InventoryEntry[];
|
|
162
|
+
readonly extensions: readonly { extension: string; fileCount: number }[];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Derive direct children and extension counts from the already captured inventory. */
|
|
166
|
+
export function collectWorkspaceInventory(
|
|
170
167
|
entries: readonly InventoryEntry[],
|
|
171
|
-
|
|
172
|
-
limit: number,
|
|
173
|
-
): OrientationSectionData[] {
|
|
168
|
+
): WorkspaceInventoryFacts {
|
|
174
169
|
const directories = new Map<string, number>();
|
|
175
170
|
const extensions = new Map<string, number>();
|
|
176
171
|
for (const entry of entries) {
|
|
@@ -181,13 +176,30 @@ function inventorySections(
|
|
|
181
176
|
extensions.set(extension, (extensions.get(extension) ?? 0) + 1);
|
|
182
177
|
}
|
|
183
178
|
}
|
|
184
|
-
|
|
179
|
+
return {
|
|
180
|
+
directories: [...directories]
|
|
181
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
182
|
+
.map(([name, count]) => ({ path: `${name}/`, entryCount: count })),
|
|
183
|
+
directFiles: entries.filter((entry) => !entry.path.includes("/")),
|
|
184
|
+
extensions: [...extensions]
|
|
185
|
+
.sort(([a, an], [b, bn]) => bn - an || a.localeCompare(b))
|
|
186
|
+
.map(([extension, count]) => ({ extension, fileCount: count })),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function inventorySections(
|
|
191
|
+
entries: readonly InventoryEntry[],
|
|
192
|
+
facts: WorkspaceOrientationFacts,
|
|
193
|
+
limit: number,
|
|
194
|
+
): OrientationSectionData[] {
|
|
195
|
+
const { directories, directFiles, extensions } = collectWorkspaceInventory(entries);
|
|
185
196
|
const sections = [
|
|
186
197
|
tableSection("workspace.directories", "Direct directories", {
|
|
187
198
|
headers: ["Path", "Entries at all depths"],
|
|
188
|
-
rows: [
|
|
189
|
-
|
|
190
|
-
|
|
199
|
+
rows: directories.map(({ path: directory, entryCount }) => [
|
|
200
|
+
code(directory),
|
|
201
|
+
String(entryCount),
|
|
202
|
+
]),
|
|
191
203
|
limit,
|
|
192
204
|
detail: "included paths",
|
|
193
205
|
}),
|
|
@@ -204,9 +216,10 @@ function inventorySections(
|
|
|
204
216
|
sections.push(
|
|
205
217
|
tableSection("workspace.extensions", "File extensions (filenames, not language support)", {
|
|
206
218
|
headers: ["Extension", "Regular files"],
|
|
207
|
-
rows: [
|
|
208
|
-
|
|
209
|
-
|
|
219
|
+
rows: extensions.map(({ extension, fileCount }) => [
|
|
220
|
+
extension ? code(extension) : "No extension",
|
|
221
|
+
String(fileCount),
|
|
222
|
+
]),
|
|
210
223
|
limit: facts.overview ? Math.min(5, limit) : limit,
|
|
211
224
|
detail: "included regular files",
|
|
212
225
|
}),
|
|
@@ -13,5 +13,5 @@ export async function executeRefactorApplyTool(
|
|
|
13
13
|
ctx: CodeIntelToolExecCtx,
|
|
14
14
|
): Promise<CodeIntelResult> {
|
|
15
15
|
const outcome = await ctx.session.applyRefactor(params, toWorkflowControl(ctx));
|
|
16
|
-
return finishRefactorApplyResult(outcome);
|
|
16
|
+
return finishRefactorApplyResult(outcome, ctx.cwd);
|
|
17
17
|
}
|
|
@@ -4,22 +4,30 @@ 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 { structuredRefactorApply } from "./structured.ts";
|
|
7
8
|
|
|
8
9
|
type RefactorApplyOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["applyRefactor"]>>;
|
|
9
10
|
|
|
10
11
|
/** Assemble the final model-visible code_refactor_apply result for one workflow outcome. */
|
|
11
|
-
export function finishRefactorApplyResult(
|
|
12
|
+
export function finishRefactorApplyResult(
|
|
13
|
+
outcome: RefactorApplyOutcome,
|
|
14
|
+
cwd: string,
|
|
15
|
+
): CodeIntelResult {
|
|
12
16
|
if (outcome.kind === "unavailable") throw new Error(outcome.reason);
|
|
13
17
|
if (outcome.kind === "invalid-input") {
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
return {
|
|
19
|
+
...searchErrorResult(`**Error:** ${outcome.message}`, {
|
|
20
|
+
nextQueries: ["Generate a fresh plan with code_refactor_plan"],
|
|
21
|
+
message: outcome.message,
|
|
22
|
+
}),
|
|
23
|
+
structuredContent: structuredRefactorApply(outcome, cwd),
|
|
24
|
+
};
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
const assembly = assembleRefactorApplyDetails(outcome.result, outcome.plan);
|
|
21
28
|
return {
|
|
22
29
|
content: renderRefactorApplyResult(assembly),
|
|
30
|
+
structuredContent: structuredRefactorApply(outcome, cwd),
|
|
23
31
|
details: {
|
|
24
32
|
type: "search",
|
|
25
33
|
data: assembly.details,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import type { CodeIntelToolExecCtx } from "../../types/index.ts";
|
|
3
3
|
import { executeRefactorApplyTool } from "./execute.ts";
|
|
4
|
+
import { RefactorApplyOutputSchema } from "./structured.ts";
|
|
4
5
|
import { renderRefactorApplyCall, renderRefactorApplyResult } from "./tui.ts";
|
|
5
6
|
|
|
6
7
|
export const CODE_REFACTOR_APPLY_TOOL_NAME = "code_refactor_apply";
|
|
@@ -19,6 +20,7 @@ export const codeRefactorApplySpec = {
|
|
|
19
20
|
},
|
|
20
21
|
{ additionalProperties: false },
|
|
21
22
|
),
|
|
23
|
+
outputSchema: RefactorApplyOutputSchema,
|
|
22
24
|
run: (params: unknown, ctx: CodeIntelToolExecCtx) =>
|
|
23
25
|
executeRefactorApplyTool(params as Parameters<typeof executeRefactorApplyTool>[0], ctx),
|
|
24
26
|
renderCall: renderRefactorApplyCall,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
import { toDisplayPath } from "../../analysis/search/paths.ts";
|
|
3
|
+
import type { RefactorApplyWorkflowOutcome } from "../../session/refactor-types.ts";
|
|
4
|
+
|
|
5
|
+
/** Native application outcome, separate from recovery's absolute changed-file paths. */
|
|
6
|
+
export const RefactorApplyOutputSchema = Type.Union([
|
|
7
|
+
Type.Object(
|
|
8
|
+
{
|
|
9
|
+
kind: Type.Literal("applied"),
|
|
10
|
+
planId: Type.String(),
|
|
11
|
+
files: Type.Array(
|
|
12
|
+
Type.Object(
|
|
13
|
+
{ file: Type.String(), editCount: Type.Integer({ minimum: 0 }) },
|
|
14
|
+
{ additionalProperties: false },
|
|
15
|
+
),
|
|
16
|
+
),
|
|
17
|
+
fileCount: Type.Integer({ minimum: 0 }),
|
|
18
|
+
editCount: Type.Integer({ minimum: 0 }),
|
|
19
|
+
},
|
|
20
|
+
{ additionalProperties: false },
|
|
21
|
+
),
|
|
22
|
+
Type.Object(
|
|
23
|
+
{ kind: Type.Literal("invalid-input"), message: Type.String(), nextAction: Type.String() },
|
|
24
|
+
{ additionalProperties: false },
|
|
25
|
+
),
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
/** Project applied file counts without exposing the stored plan. */
|
|
29
|
+
export function structuredRefactorApply(
|
|
30
|
+
outcome: Exclude<RefactorApplyWorkflowOutcome, { kind: "unavailable" }>,
|
|
31
|
+
cwd: string,
|
|
32
|
+
): Static<typeof RefactorApplyOutputSchema> {
|
|
33
|
+
if (outcome.kind === "invalid-input")
|
|
34
|
+
return {
|
|
35
|
+
kind: outcome.kind,
|
|
36
|
+
message: outcome.message,
|
|
37
|
+
nextAction: "Generate a fresh plan with code_refactor_plan",
|
|
38
|
+
};
|
|
39
|
+
const counts = new Map<string, number>();
|
|
40
|
+
for (const edit of outcome.plan.edits.edits)
|
|
41
|
+
counts.set(edit.file, (counts.get(edit.file) ?? 0) + 1);
|
|
42
|
+
return {
|
|
43
|
+
kind: "applied",
|
|
44
|
+
planId: outcome.plan.id,
|
|
45
|
+
files: [...counts].map(([file, editCount]) => ({ file: toDisplayPath(cwd, file), editCount })),
|
|
46
|
+
fileCount: outcome.result.filesChanged,
|
|
47
|
+
editCount: outcome.result.totalEdits,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -4,6 +4,7 @@ import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts
|
|
|
4
4
|
import { renderRefactorPlanResult } from "../refactor-markdown.ts";
|
|
5
5
|
import { searchErrorResult } from "../result/errors.ts";
|
|
6
6
|
import { assembleRefactorPlanDetails } from "../result/refactor.ts";
|
|
7
|
+
import { structuredRefactorPlan } from "./structured.ts";
|
|
7
8
|
|
|
8
9
|
type RefactorPlanOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["planRefactor"]>>;
|
|
9
10
|
|
|
@@ -14,10 +15,13 @@ export function finishRefactorPlanResult(
|
|
|
14
15
|
): CodeIntelResult {
|
|
15
16
|
if (outcome.kind === "unavailable") throw new Error(outcome.reason);
|
|
16
17
|
if (outcome.kind === "invalid-input") {
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
return {
|
|
19
|
+
...searchErrorResult(`**Error:** ${outcome.message}`, {
|
|
20
|
+
nextQueries: ["Fix the target or operation and retry"],
|
|
21
|
+
message: outcome.message,
|
|
22
|
+
}),
|
|
23
|
+
structuredContent: structuredRefactorPlan(outcome, cwd),
|
|
24
|
+
};
|
|
21
25
|
}
|
|
22
26
|
if (outcome.kind === "ambiguous") {
|
|
23
27
|
const candidates = outcome.candidates
|
|
@@ -26,15 +30,19 @@ export function finishRefactorPlanResult(
|
|
|
26
30
|
`${index + 1}. ${candidate.description} (${candidate.file}:${candidate.line})`,
|
|
27
31
|
)
|
|
28
32
|
.join("\n");
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
return {
|
|
34
|
+
...searchErrorResult(`**Refactor ambiguous:**\n${candidates}`, {
|
|
35
|
+
nextQueries: ["Use a precise target handle or anchor"],
|
|
36
|
+
message: "The refactor target is ambiguous.",
|
|
37
|
+
}),
|
|
38
|
+
structuredContent: structuredRefactorPlan(outcome, cwd),
|
|
39
|
+
};
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
const assembly = assembleRefactorPlanDetails(outcome.plan, cwd);
|
|
36
43
|
return {
|
|
37
44
|
content: renderRefactorPlanResult(assembly),
|
|
45
|
+
structuredContent: structuredRefactorPlan(outcome, cwd),
|
|
38
46
|
details: {
|
|
39
47
|
type: "search",
|
|
40
48
|
data: assembly.details,
|
|
@@ -2,6 +2,7 @@ import { Type } from "typebox";
|
|
|
2
2
|
import type { CodeIntelToolExecCtx } from "../../types/index.ts";
|
|
3
3
|
import { RefactorOperationParam, RefactorTargetParam } from "../schemas.ts";
|
|
4
4
|
import { executeRefactorPlanTool } from "./execute.ts";
|
|
5
|
+
import { RefactorPlanOutputSchema } from "./structured.ts";
|
|
5
6
|
import { renderRefactorPlanCall, renderRefactorPlanResult } from "./tui.ts";
|
|
6
7
|
|
|
7
8
|
export const CODE_REFACTOR_PLAN_TOOL_NAME = "code_refactor_plan";
|
|
@@ -18,6 +19,7 @@ export const codeRefactorPlanSpec = {
|
|
|
18
19
|
},
|
|
19
20
|
{ additionalProperties: false },
|
|
20
21
|
),
|
|
22
|
+
outputSchema: RefactorPlanOutputSchema,
|
|
21
23
|
run: (params: unknown, ctx: CodeIntelToolExecCtx) =>
|
|
22
24
|
executeRefactorPlanTool(params as Parameters<typeof executeRefactorPlanTool>[0], ctx),
|
|
23
25
|
renderCall: renderRefactorPlanCall,
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
2
|
+
import { type Static, Type } from "typebox";
|
|
3
|
+
import { toDisplayPath } from "../../analysis/search/paths.ts";
|
|
4
|
+
import {
|
|
5
|
+
PUBLIC_REFACTOR_OPERATION_NAMES,
|
|
6
|
+
type RefactorPlanWorkflowOutcome,
|
|
7
|
+
} from "../../session/refactor-types.ts";
|
|
8
|
+
|
|
9
|
+
const Position = Type.Object(
|
|
10
|
+
{ line: Type.Integer({ minimum: 0 }), character: Type.Integer({ minimum: 0 }) },
|
|
11
|
+
{ additionalProperties: false },
|
|
12
|
+
);
|
|
13
|
+
const Edit = Type.Object(
|
|
14
|
+
{
|
|
15
|
+
file: Type.String(),
|
|
16
|
+
range: Type.Object(
|
|
17
|
+
{ start: Position, end: Position },
|
|
18
|
+
{
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
description: "Zero-based UTF-16 positions; end is exclusive.",
|
|
21
|
+
},
|
|
22
|
+
),
|
|
23
|
+
newText: Type.String(),
|
|
24
|
+
},
|
|
25
|
+
{ additionalProperties: false },
|
|
26
|
+
);
|
|
27
|
+
const Candidate = Type.Object(
|
|
28
|
+
{
|
|
29
|
+
description: Type.String(),
|
|
30
|
+
file: Type.Optional(Type.String()),
|
|
31
|
+
line: Type.Optional(Type.Integer()),
|
|
32
|
+
character: Type.Optional(Type.Integer()),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
additionalProperties: false,
|
|
36
|
+
description:
|
|
37
|
+
"Provider-reported candidate location, when available; one-based line and UTF-16 character.",
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
/** Native plan data, including all edits rather than the bounded text preview. */
|
|
42
|
+
export const RefactorPlanOutputSchema = Type.Union([
|
|
43
|
+
Type.Object(
|
|
44
|
+
{
|
|
45
|
+
kind: Type.Literal("completed"),
|
|
46
|
+
planId: Type.String(),
|
|
47
|
+
operation: StringEnum([...PUBLIC_REFACTOR_OPERATION_NAMES]),
|
|
48
|
+
target: Type.Object(
|
|
49
|
+
{ file: Type.String(), line: Type.Integer(), character: Type.Integer() },
|
|
50
|
+
{ additionalProperties: false, description: "One-based line and UTF-16 character." },
|
|
51
|
+
),
|
|
52
|
+
newName: Type.Optional(Type.String()),
|
|
53
|
+
destination: Type.Optional(Type.String()),
|
|
54
|
+
edits: Type.Array(Edit),
|
|
55
|
+
fileCount: Type.Integer({ minimum: 0 }),
|
|
56
|
+
editCount: Type.Integer({ minimum: 0 }),
|
|
57
|
+
provenance: StringEnum(["semantic", "structural"]),
|
|
58
|
+
nextAction: Type.Object(
|
|
59
|
+
{ tool: Type.Literal("code_refactor_apply"), planId: Type.String() },
|
|
60
|
+
{ additionalProperties: false },
|
|
61
|
+
),
|
|
62
|
+
},
|
|
63
|
+
{ additionalProperties: false },
|
|
64
|
+
),
|
|
65
|
+
Type.Object(
|
|
66
|
+
{
|
|
67
|
+
kind: Type.Literal("ambiguous"),
|
|
68
|
+
candidates: Type.Array(Candidate),
|
|
69
|
+
nextAction: Type.String(),
|
|
70
|
+
},
|
|
71
|
+
{ additionalProperties: false },
|
|
72
|
+
),
|
|
73
|
+
Type.Object(
|
|
74
|
+
{ kind: Type.Literal("invalid-input"), message: Type.String(), nextAction: Type.String() },
|
|
75
|
+
{ additionalProperties: false },
|
|
76
|
+
),
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
/** Project public facts without plan authority, fingerprints, or document preconditions. */
|
|
80
|
+
export function structuredRefactorPlan(
|
|
81
|
+
outcome: Exclude<RefactorPlanWorkflowOutcome, { kind: "unavailable" }>,
|
|
82
|
+
cwd: string,
|
|
83
|
+
): Static<typeof RefactorPlanOutputSchema> {
|
|
84
|
+
if (outcome.kind === "invalid-input")
|
|
85
|
+
return {
|
|
86
|
+
kind: outcome.kind,
|
|
87
|
+
message: outcome.message,
|
|
88
|
+
nextAction: "Fix the target or operation and retry",
|
|
89
|
+
};
|
|
90
|
+
if (outcome.kind === "ambiguous")
|
|
91
|
+
return {
|
|
92
|
+
kind: outcome.kind,
|
|
93
|
+
candidates: outcome.candidates.map((candidate) => ({
|
|
94
|
+
description: candidate.description,
|
|
95
|
+
...(candidate.file === undefined ? {} : { file: toDisplayPath(cwd, candidate.file) }),
|
|
96
|
+
...(candidate.line === undefined ? {} : { line: candidate.line }),
|
|
97
|
+
...(candidate.character === undefined ? {} : { character: candidate.character }),
|
|
98
|
+
})),
|
|
99
|
+
nextAction: "Use a precise target handle or anchor",
|
|
100
|
+
};
|
|
101
|
+
const plan = outcome.plan;
|
|
102
|
+
const operation = PUBLIC_REFACTOR_OPERATION_NAMES.find((name) => name === plan.operation);
|
|
103
|
+
if (operation === undefined) throw new Error(`Unsupported refactor operation: ${plan.operation}`);
|
|
104
|
+
return {
|
|
105
|
+
kind: "completed",
|
|
106
|
+
planId: plan.id,
|
|
107
|
+
operation,
|
|
108
|
+
target: {
|
|
109
|
+
file: toDisplayPath(cwd, plan.targetFile),
|
|
110
|
+
line: plan.targetLine,
|
|
111
|
+
character: plan.targetCharacter,
|
|
112
|
+
},
|
|
113
|
+
...(plan.newName === undefined ? {} : { newName: plan.newName }),
|
|
114
|
+
...(plan.destination === undefined ? {} : { destination: plan.destination }),
|
|
115
|
+
edits: plan.edits.edits.map((edit) => ({
|
|
116
|
+
file: toDisplayPath(cwd, edit.file),
|
|
117
|
+
range: {
|
|
118
|
+
start: { line: edit.range.start.line, character: edit.range.start.character },
|
|
119
|
+
end: { line: edit.range.end.line, character: edit.range.end.character },
|
|
120
|
+
},
|
|
121
|
+
newText: edit.newText,
|
|
122
|
+
})),
|
|
123
|
+
fileCount: new Set(plan.edits.edits.map((edit) => edit.file)).size,
|
|
124
|
+
editCount: plan.edits.edits.length,
|
|
125
|
+
provenance: plan.evidenceSource ?? "semantic",
|
|
126
|
+
nextAction: { tool: "code_refactor_apply", planId: plan.id },
|
|
127
|
+
};
|
|
128
|
+
}
|
package/src/tool/schemas.ts
CHANGED
|
@@ -147,7 +147,13 @@ const RefactorOperationProperties = {
|
|
|
147
147
|
{ additionalProperties: false },
|
|
148
148
|
),
|
|
149
149
|
update_imports: Type.Object({}, { additionalProperties: false }),
|
|
150
|
-
delete_dead_code: Type.Object(
|
|
150
|
+
delete_dead_code: Type.Object(
|
|
151
|
+
{},
|
|
152
|
+
{
|
|
153
|
+
additionalProperties: false,
|
|
154
|
+
description: "Remove server-supported unused code; support may be limited to unused imports.",
|
|
155
|
+
},
|
|
156
|
+
),
|
|
151
157
|
} satisfies Record<PublicRefactorOperationName, TSchema>;
|
|
152
158
|
|
|
153
159
|
export const RefactorOperationParam = exactOneSelector(
|