@mrclrchtr/supi-code-intelligence 11.0.0 → 11.1.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 +41 -4
- package/gradle-helper/README.md +48 -0
- package/gradle-helper/build.sh +73 -0
- package/gradle-helper/lib/gradle-tooling-api-9.4.0.jar +0 -0
- package/gradle-helper/lib/slf4j-api-2.0.17.jar +0 -0
- package/gradle-helper/lib/slf4j-simple-2.0.17.jar +0 -0
- package/gradle-helper/lib/supi-gradle-observation.jar +0 -0
- package/gradle-helper/licenses/DEPENDENCIES.md +11 -0
- package/gradle-helper/licenses/LICENSE-gradle-tooling-api.txt +422 -0
- package/gradle-helper/licenses/LICENSE-slf4j.txt +21 -0
- package/gradle-helper/licenses/NOTICE-gradle.txt +21 -0
- package/gradle-helper/src/GradleObservation.java +597 -0
- 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-core/src/debug-registry.ts +41 -1
- package/node_modules/@mrclrchtr/supi-lsp/README.md +1 -1
- 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/@mrclrchtr/supi-core/src/debug-registry.ts +41 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/README.md +5 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/browser/ril.js +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/common/connection.js +7 -2
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/common/ral.d.ts +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/main.d.ts +14 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/main.js +6 -4
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/ril.js +5 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/package.json +4 -2
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-protocol/package.json +4 -3
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/lib/esm/main.js +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/lib/umd/main.js +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/package.json +2 -1
- package/node_modules/@mrclrchtr/supi-lsp/package.json +6 -6
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +21 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -0
- 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/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +41 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +5 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/LICENSE +21 -0
- 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 +19 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/LICENSE +21 -0
- 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 +19 -2
- package/node_modules/ignore/README.md +95 -14
- package/node_modules/ignore/index.d.ts +56 -20
- package/node_modules/ignore/index.js +150 -120
- package/node_modules/ignore/legacy.js +159 -131
- package/node_modules/ignore/package.json +1 -1
- package/package.json +11 -6
- package/src/analysis/gradle/query.ts +273 -0
- package/src/analysis/gradle/runtime.ts +173 -0
- package/src/analysis/gradle/types.ts +65 -0
- package/src/analysis/read-next.ts +1 -4
- package/src/analysis/refactor/apply.ts +2 -2
- package/src/analysis/refactor/mutation-authority.ts +4 -1
- package/src/analysis/search/ast-scan.ts +143 -18
- package/src/analysis/workspace/safe-path.ts +14 -2
- package/src/analysis/workspace/types.ts +2 -0
- package/src/extension.ts +10 -1
- package/src/gradle/consent.ts +279 -0
- package/src/headless.ts +3 -0
- package/src/overview/collect.ts +11 -3
- package/src/session/orientation/workspace-context.ts +49 -28
- package/src/session/orientation-types.ts +11 -1
- package/src/session/orientation-workflow.ts +2 -0
- package/src/session/session.ts +8 -0
- package/src/tool/code_find/execute.ts +1 -1
- package/src/tool/code_find/markdown.ts +24 -17
- package/src/tool/code_find/result.ts +18 -5
- package/src/tool/code_find/spec.ts +2 -0
- package/src/tool/code_find/structured.ts +161 -0
- package/src/tool/code_graph/result.ts +32 -15
- package/src/tool/code_graph/spec.ts +2 -0
- package/src/tool/code_graph/structured.ts +142 -0
- package/src/tool/code_health/markdown.ts +5 -15
- package/src/tool/code_inspect/markdown.ts +19 -11
- package/src/tool/code_inspect/result.ts +1 -0
- package/src/tool/code_orientation/directory-navigation.ts +66 -0
- package/src/tool/code_orientation/gradle-sections.ts +68 -0
- package/src/tool/code_orientation/markdown.ts +19 -8
- package/src/tool/code_orientation/result.ts +89 -11
- package/src/tool/code_orientation/workspace-format.ts +2 -1
- package/src/tool/code_orientation/workspace-output.ts +40 -13
- package/src/tool/code_orientation/workspace-projects.ts +170 -50
- package/src/tool/code_orientation/workspace-sections.ts +3 -1
- package/src/tool/code_resolve/markdown.ts +4 -10
- package/src/tool/code_resolve/result.ts +2 -0
- package/src/tool/code_resolve/spec.ts +2 -0
- package/src/tool/code_resolve/structured.ts +103 -0
- package/src/tool/infra/truncate.ts +12 -4
- package/src/tool/register.ts +10 -6
- package/src/tool/result/display.ts +17 -0
- package/src/tool/result/model-budget.ts +195 -0
- package/src/tool/result/structured.ts +62 -0
- package/src/tool/result/types.ts +10 -2
- package/src/tool/specs.ts +2 -0
- package/src/types/execution.ts +5 -1
- package/src/ui/tui/display.ts +10 -4
package/src/overview/collect.ts
CHANGED
|
@@ -5,17 +5,25 @@ import { workspaceOrientationData } from "../session/orientation/workspace-conte
|
|
|
5
5
|
import { prepareWorkspaceOutput } from "../tool/code_orientation/workspace-output.ts";
|
|
6
6
|
|
|
7
7
|
/** Capture a first-turn map without requiring any project metadata or provider. */
|
|
8
|
-
export async function collectOverview(
|
|
8
|
+
export async function collectOverview(
|
|
9
|
+
cwd: string,
|
|
10
|
+
projectTrusted: boolean,
|
|
11
|
+
homeDir?: string,
|
|
12
|
+
gradleObserver?: import("../analysis/gradle/types.ts").GradleObserver,
|
|
13
|
+
) {
|
|
9
14
|
try {
|
|
10
15
|
if (!statSync(cwd).isDirectory()) return null;
|
|
11
16
|
} catch {
|
|
12
17
|
return null;
|
|
13
18
|
}
|
|
14
19
|
const exclude = loadAutomaticExclusionPatterns(cwd, { projectTrusted, homeDir });
|
|
15
|
-
const
|
|
20
|
+
const control = { deadline: Date.now() + 10_000 };
|
|
21
|
+
let observation = await observeWorkspace(cwd, {
|
|
16
22
|
exclude,
|
|
17
|
-
control
|
|
23
|
+
control,
|
|
18
24
|
});
|
|
25
|
+
const gradle = await gradleObserver?.observe(cwd, control);
|
|
26
|
+
if (gradle) observation = { ...observation, gradle };
|
|
19
27
|
return prepareWorkspaceOutput(
|
|
20
28
|
workspaceOrientationData({ observation, cwd, focus: null, maxResults: 10, overview: true }),
|
|
21
29
|
);
|
|
@@ -4,9 +4,13 @@ import { loadAutomaticExclusionPatterns } from "@mrclrchtr/supi-core/config";
|
|
|
4
4
|
import ignore from "ignore";
|
|
5
5
|
import { isGitIgnoredDirectory } from "../../analysis/workspace/git.ts";
|
|
6
6
|
import { observeWorkspace } from "../../analysis/workspace/observe.ts";
|
|
7
|
-
import { assertUnlinkedPath } from "../../analysis/workspace/safe-path.ts";
|
|
7
|
+
import { assertUnlinkedPath, WorkspaceSymlinkError } from "../../analysis/workspace/safe-path.ts";
|
|
8
8
|
import type { WorkspaceObservation } from "../../analysis/workspace/types.ts";
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
OrientationResultData,
|
|
11
|
+
OrientationWorkflowInput,
|
|
12
|
+
OrientationWorkflowOutcome,
|
|
13
|
+
} from "../orientation-types.ts";
|
|
10
14
|
import type { WorkflowControl } from "../workflow-control.ts";
|
|
11
15
|
|
|
12
16
|
/** Captured facts for workspace and directory presentation; no provider or live state. */
|
|
@@ -22,35 +26,53 @@ export interface WorkspaceOrientationFacts {
|
|
|
22
26
|
/** Select the new navigation path without changing file or symbol-focused workflows. */
|
|
23
27
|
export async function orientWorkspaceContext(
|
|
24
28
|
request: OrientationWorkflowInput,
|
|
25
|
-
options: {
|
|
29
|
+
options: {
|
|
30
|
+
cwd: string;
|
|
31
|
+
homeDir?: string;
|
|
32
|
+
projectTrusted: boolean;
|
|
33
|
+
gradleObserver?: import("../../analysis/gradle/types.ts").GradleObserver;
|
|
34
|
+
},
|
|
26
35
|
control?: WorkflowControl,
|
|
27
36
|
): Promise<
|
|
28
37
|
| { kind: "completed"; data: OrientationResultData; directory: string | null }
|
|
29
|
-
| { kind: "invalid-input"
|
|
38
|
+
| Extract<OrientationWorkflowOutcome, { kind: "invalid-input" }>
|
|
30
39
|
| null
|
|
31
40
|
> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
try {
|
|
42
|
+
const selected = directoryFocus(request, options.cwd);
|
|
43
|
+
if (!selected) return null;
|
|
44
|
+
let focus = selected.path;
|
|
45
|
+
const exclude = loadAutomaticExclusionPatterns(options.cwd, options);
|
|
46
|
+
if (focus) await assertFocusPath(options.cwd, focus);
|
|
47
|
+
let observation = await initialObservation(options.cwd, focus, exclude, control);
|
|
48
|
+
if (request.focus && "module" in request.focus) {
|
|
49
|
+
const selected = resolveModule(observation, request.focus.module);
|
|
50
|
+
if (selected.kind === "invalid-input") return selected;
|
|
51
|
+
focus = selected.path;
|
|
52
|
+
}
|
|
53
|
+
if (focus) observation = await focusObservation(observation, focus, exclude, control);
|
|
54
|
+
const selectedRoot =
|
|
55
|
+
request.focus && "path" in request.focus ? (focus ?? options.cwd) : options.cwd;
|
|
56
|
+
const gradle = await options.gradleObserver?.observe(selectedRoot, control);
|
|
57
|
+
if (gradle) observation = { ...observation, gradle };
|
|
58
|
+
return {
|
|
59
|
+
kind: "completed",
|
|
60
|
+
directory: focus,
|
|
61
|
+
data: workspaceOrientationData({
|
|
62
|
+
observation,
|
|
63
|
+
cwd: options.cwd,
|
|
64
|
+
focus,
|
|
65
|
+
maxResults: request.maxResults ?? 10,
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (!(error instanceof WorkspaceSymlinkError)) throw error;
|
|
70
|
+
return {
|
|
71
|
+
kind: "invalid-input",
|
|
72
|
+
message: error.message,
|
|
73
|
+
symlinkRejection: { requestedPath: error.requestedPath, blockedPath: error.blockedPath },
|
|
74
|
+
};
|
|
42
75
|
}
|
|
43
|
-
if (focus) observation = await focusObservation(observation, focus, exclude, control);
|
|
44
|
-
return {
|
|
45
|
-
kind: "completed",
|
|
46
|
-
directory: focus,
|
|
47
|
-
data: workspaceOrientationData({
|
|
48
|
-
observation,
|
|
49
|
-
cwd: options.cwd,
|
|
50
|
-
focus,
|
|
51
|
-
maxResults: request.maxResults ?? 10,
|
|
52
|
-
}),
|
|
53
|
-
};
|
|
54
76
|
}
|
|
55
77
|
|
|
56
78
|
async function initialObservation(
|
|
@@ -107,13 +129,12 @@ async function assertFocusPath(cwd: string, focus: string): Promise<void> {
|
|
|
107
129
|
function directoryFocus(
|
|
108
130
|
request: OrientationWorkflowInput,
|
|
109
131
|
cwd: string,
|
|
110
|
-
): { kind: "directory"; path: string | null } |
|
|
132
|
+
): { kind: "directory"; path: string | null } | null {
|
|
111
133
|
if (!request.focus || "module" in request.focus) return { kind: "directory", path: null };
|
|
112
134
|
if ("target" in request.focus) return null;
|
|
113
135
|
const focus = path.resolve(cwd, request.focus.path.replace(/^@/, ""));
|
|
114
136
|
if (!existsSync(focus) || !statSync(focus).isDirectory()) return null;
|
|
115
|
-
if (lstatSync(focus).isSymbolicLink())
|
|
116
|
-
return { kind: "invalid-input", message: "Symbolic-link directory focus is not followed." };
|
|
137
|
+
if (lstatSync(focus).isSymbolicLink()) throw new WorkspaceSymlinkError(focus, focus);
|
|
117
138
|
return { kind: "directory", path: focus };
|
|
118
139
|
}
|
|
119
140
|
|
|
@@ -94,6 +94,8 @@ export interface OrientationSectionData {
|
|
|
94
94
|
readonly confidence: ConfidenceMode;
|
|
95
95
|
readonly provenance: readonly OrientationProvenance[];
|
|
96
96
|
readonly evidenceLists: readonly EvidenceListMetadata[];
|
|
97
|
+
/** Evidence list counted by table rows, including when only empty-result framing remains. */
|
|
98
|
+
readonly tableEvidenceKey?: string;
|
|
97
99
|
/** Content atoms for this section; the adapter frames them under the title + note. */
|
|
98
100
|
readonly items: readonly OrientationItem[];
|
|
99
101
|
}
|
|
@@ -141,5 +143,13 @@ export type OrientationWorkflowOutcome =
|
|
|
141
143
|
readonly requestedKind: TargetSymbolKind;
|
|
142
144
|
readonly candidates: readonly OrientationCandidate[];
|
|
143
145
|
} & TargetCandidateCompleteness)
|
|
144
|
-
| {
|
|
146
|
+
| {
|
|
147
|
+
readonly kind: "invalid-input";
|
|
148
|
+
readonly message: string;
|
|
149
|
+
/** No-follow facts for actionable explicit-focus guidance; never a resolved retry path. */
|
|
150
|
+
readonly symlinkRejection?: {
|
|
151
|
+
readonly requestedPath: string;
|
|
152
|
+
readonly blockedPath: string;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
145
155
|
| { readonly kind: "unavailable"; readonly reason: string };
|
|
@@ -36,6 +36,8 @@ export interface OrientationWorkflowDeps extends TargetWorkflowDeps {
|
|
|
36
36
|
readonly projectTrusted: boolean;
|
|
37
37
|
/** Global config home for hermetic config reads; undefined uses os.homedir(). */
|
|
38
38
|
readonly homeDir?: string;
|
|
39
|
+
/** Separately authorized runtime model collection; absent in profiles that do not own it. */
|
|
40
|
+
readonly gradleObserver?: import("../analysis/gradle/types.ts").GradleObserver;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/** Resolve the Orientation focus and collect immutable facts for presentation adapters. */
|
package/src/session/session.ts
CHANGED
|
@@ -178,6 +178,7 @@ export class WorkspaceCodeIntelligenceSession {
|
|
|
178
178
|
|
|
179
179
|
/** Global config home for hermetic config reads; undefined uses os.homedir(). */
|
|
180
180
|
#homeDir: string | undefined;
|
|
181
|
+
#gradleObserver: import("../analysis/gradle/types.ts").GradleObserver | undefined;
|
|
181
182
|
|
|
182
183
|
/** One automatic exclusion snapshot shared by this session's broad searches. */
|
|
183
184
|
#automaticPathPolicy: AutomaticLspPathPolicy | null = null;
|
|
@@ -332,6 +333,11 @@ export class WorkspaceCodeIntelligenceSession {
|
|
|
332
333
|
);
|
|
333
334
|
}
|
|
334
335
|
|
|
336
|
+
/** Attach this profile's separately authorized Gradle observation boundary. */
|
|
337
|
+
setGradleObserver(observer: import("../analysis/gradle/types.ts").GradleObserver): void {
|
|
338
|
+
this.#gradleObserver = observer;
|
|
339
|
+
}
|
|
340
|
+
|
|
335
341
|
/** Orient around the workspace or one exact focus. */
|
|
336
342
|
async orient(
|
|
337
343
|
input: OrientationWorkflowInput,
|
|
@@ -343,6 +349,7 @@ export class WorkspaceCodeIntelligenceSession {
|
|
|
343
349
|
...this.targetWorkflowDeps(),
|
|
344
350
|
nativeInstructionPaths: this.#nativeInstructionPaths,
|
|
345
351
|
surfacedInstructionDirs: this.#surfacedInstructionDirs,
|
|
352
|
+
gradleObserver: this.#gradleObserver,
|
|
346
353
|
projectTrusted: this.#projectTrusted,
|
|
347
354
|
homeDir: this.#homeDir,
|
|
348
355
|
},
|
|
@@ -470,6 +477,7 @@ export class WorkspaceCodeIntelligenceSession {
|
|
|
470
477
|
this.#lspController = null;
|
|
471
478
|
this.#automaticPathPolicy = null;
|
|
472
479
|
this.#projectTrusted = false;
|
|
480
|
+
this.#gradleObserver = undefined;
|
|
473
481
|
}
|
|
474
482
|
}
|
|
475
483
|
|
|
@@ -19,5 +19,5 @@ export async function executeFindTool(
|
|
|
19
19
|
ctx: CodeIntelToolExecCtx,
|
|
20
20
|
): Promise<CodeIntelResult> {
|
|
21
21
|
const outcome = await ctx.session.find(params as FindWorkflowInput, toWorkflowControl(ctx));
|
|
22
|
-
return finishFindResult(outcome, params.scope, params.mode);
|
|
22
|
+
return finishFindResult(outcome, ctx.cwd, params.scope, params.mode);
|
|
23
23
|
}
|
|
@@ -59,32 +59,39 @@ function renderScanLimitations(limitations: readonly StructuredScanLimitation[])
|
|
|
59
59
|
limitation.pathCount === null
|
|
60
60
|
? "unknown paths"
|
|
61
61
|
: `${limitation.pathCount} path${limitation.pathCount === 1 ? "" : "s"}`;
|
|
62
|
-
|
|
62
|
+
const examples =
|
|
63
|
+
limitation.reason === "unreadable-path" && limitation.examples.length > 0
|
|
64
|
+
? ` (examples: ${limitation.examples.map((file) => `\`${file}\``).join(", ")})`
|
|
65
|
+
: "";
|
|
66
|
+
return `${limitation.reason}: ${count}${examples}`;
|
|
63
67
|
});
|
|
64
68
|
return `_AST Scan incomplete — ${descriptions.join("; ")}. Match total is unknown._`;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
function appendScanAndFailures(lines: string[], result: StructuredPatternResult): void {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
for (const [reason, source] of [
|
|
73
|
+
["configured-exclusion", "`code-intelligence.exclude`"],
|
|
74
|
+
["gitignore", "`.gitignore`"],
|
|
75
|
+
] as const) {
|
|
76
|
+
for (const excluded of result.scan.exclusions.filter(
|
|
77
|
+
(exclusion) => exclusion.reason === reason,
|
|
78
|
+
)) {
|
|
79
|
+
const examples = excluded.examples.length
|
|
80
|
+
? ` Examples: ${excluded.examples.map((file) => `\`${file}\``).join(", ")}.`
|
|
81
|
+
: "";
|
|
82
|
+
lines.push(
|
|
83
|
+
"",
|
|
84
|
+
`_While scanning \`${excluded.scopeRoot}\`, skipped ${excluded.pathCount} path${excluded.pathCount === 1 ? "" : "s"} by ${source}. Other explicit scopes may include these paths.${examples}_`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
79
87
|
}
|
|
80
|
-
const
|
|
88
|
+
for (const excluded of result.scan.exclusions.filter(
|
|
81
89
|
(exclusion) => exclusion.reason === "unsupported-operation",
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
const count = operationExclusion.pathCount;
|
|
90
|
+
)) {
|
|
91
|
+
const count = excluded.pathCount;
|
|
85
92
|
lines.push(
|
|
86
93
|
"",
|
|
87
|
-
`
|
|
94
|
+
`_While scanning \`${excluded.scopeRoot}\`, skipped ${count} file${count === 1 ? "" : "s"} because ${result.scan.policy.operation} analysis is not supported for their language._`,
|
|
88
95
|
);
|
|
89
96
|
}
|
|
90
97
|
const scanWarning = renderScanLimitations(result.scan.limitations);
|
|
@@ -171,12 +171,14 @@ function findProvenance(
|
|
|
171
171
|
import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
|
|
172
172
|
import { scopedSymbolFailureMessage, searchErrorResult } from "../result/errors.ts";
|
|
173
173
|
import { renderFindResult } from "./render.ts";
|
|
174
|
+
import { structuredFindResult } from "./structured.ts";
|
|
174
175
|
|
|
175
176
|
type FindOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["find"]>>;
|
|
176
177
|
|
|
177
178
|
/** Assemble the final model-visible code_find result for one workflow outcome. */
|
|
178
179
|
export function finishFindResult(
|
|
179
180
|
outcome: FindOutcome,
|
|
181
|
+
cwd: string,
|
|
180
182
|
scope: readonly string[] | undefined,
|
|
181
183
|
mode?: FindMode,
|
|
182
184
|
): CodeIntelResult {
|
|
@@ -188,16 +190,27 @@ export function finishFindResult(
|
|
|
188
190
|
throw new Error(reason);
|
|
189
191
|
}
|
|
190
192
|
if (outcome.kind === "invalid-input") {
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
return {
|
|
194
|
+
...searchErrorResult(`**Error:** ${outcome.message}`, {
|
|
195
|
+
scope: Array.isArray(scope) ? scope.join(", ") : null,
|
|
196
|
+
nextQueries: ["Fix the search input and retry"],
|
|
197
|
+
message: outcome.message,
|
|
198
|
+
}),
|
|
199
|
+
structuredContent: {
|
|
200
|
+
kind: "invalid-input",
|
|
201
|
+
confidence: "unavailable",
|
|
202
|
+
matches: [],
|
|
203
|
+
evidenceLists: [],
|
|
204
|
+
nextQueries: ["Fix the search input and retry"],
|
|
205
|
+
message: outcome.message,
|
|
206
|
+
},
|
|
207
|
+
};
|
|
196
208
|
}
|
|
197
209
|
|
|
198
210
|
const assembly = assembleFindWorkflowResult(outcome);
|
|
199
211
|
return {
|
|
200
212
|
content: renderFindResult(assembly),
|
|
213
|
+
structuredContent: structuredFindResult(assembly, cwd),
|
|
201
214
|
details: {
|
|
202
215
|
type: "search",
|
|
203
216
|
data: assembly.details,
|
|
@@ -5,6 +5,7 @@ import { FindQueryParam, FindScopeParam, MaxResultsParam } from "../schemas.ts";
|
|
|
5
5
|
import { CODE_FIND_AST_KINDS } from "./ast-kinds.ts";
|
|
6
6
|
import { executeFindTool } from "./execute.ts";
|
|
7
7
|
import { CODE_FIND_MODES } from "./modes.ts";
|
|
8
|
+
import { FindOutputSchema } from "./structured.ts";
|
|
8
9
|
import { renderFindCall, renderFindResult } from "./tui.ts";
|
|
9
10
|
|
|
10
11
|
export const CODE_FIND_TOOL_NAME = "code_find";
|
|
@@ -14,6 +15,7 @@ export const CODE_FIND_TOOL_LABEL = "Code Find";
|
|
|
14
15
|
export const codeFindSpec = {
|
|
15
16
|
name: CODE_FIND_TOOL_NAME,
|
|
16
17
|
label: CODE_FIND_TOOL_LABEL,
|
|
18
|
+
outputSchema: FindOutputSchema,
|
|
17
19
|
parameters: Type.Object(
|
|
18
20
|
{
|
|
19
21
|
query: FindQueryParam,
|
|
@@ -0,0 +1,161 @@
|
|
|
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 { ConfidenceSchema, EvidenceListSchema, RecoveryRangeSchema } from "../result/structured.ts";
|
|
5
|
+
import type { FindResultAssembly } from "./result.ts";
|
|
6
|
+
|
|
7
|
+
const ScanPathSummary = Type.Object({
|
|
8
|
+
reason: Type.String(),
|
|
9
|
+
pathCount: Type.Union([Type.Integer(), Type.Null()]),
|
|
10
|
+
examples: Type.Array(Type.String()),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/** Codemode search evidence, including scan-universe limits independently of match counts. */
|
|
14
|
+
export const FindOutputSchema = Type.Object(
|
|
15
|
+
{
|
|
16
|
+
kind: StringEnum(["completed", "invalid-input"]),
|
|
17
|
+
mode: Type.Optional(StringEnum(["semantic", "ast"])),
|
|
18
|
+
confidence: ConfidenceSchema,
|
|
19
|
+
matches: Type.Array(
|
|
20
|
+
Type.Object(
|
|
21
|
+
{
|
|
22
|
+
name: Type.String(),
|
|
23
|
+
kind: Type.String(),
|
|
24
|
+
file: Type.String(),
|
|
25
|
+
line: Type.Integer(),
|
|
26
|
+
character: Type.Integer(),
|
|
27
|
+
endLine: Type.Optional(Type.Integer()),
|
|
28
|
+
endCharacter: Type.Optional(Type.Integer()),
|
|
29
|
+
anchorKind: Type.Optional(StringEnum(["name", "declaration"])),
|
|
30
|
+
container: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
31
|
+
},
|
|
32
|
+
{ additionalProperties: false },
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
evidenceLists: Type.Array(EvidenceListSchema),
|
|
36
|
+
nextQueries: Type.Array(Type.String()),
|
|
37
|
+
message: Type.Optional(Type.String()),
|
|
38
|
+
partialReason: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
39
|
+
automaticPathExclusion: Type.Optional(
|
|
40
|
+
Type.Object({ excludedCount: Type.Integer(), examples: Type.Array(Type.String()) }),
|
|
41
|
+
),
|
|
42
|
+
scan: Type.Optional(
|
|
43
|
+
Type.Object({
|
|
44
|
+
universe: Type.String(),
|
|
45
|
+
roots: Type.Array(Type.String()),
|
|
46
|
+
eligibleFileCount: Type.Union([Type.Integer(), Type.Null()]),
|
|
47
|
+
analyzedFileCount: Type.Integer(),
|
|
48
|
+
complete: Type.Boolean(),
|
|
49
|
+
exclusions: Type.Array(
|
|
50
|
+
Type.Object({ ...ScanPathSummary.properties, scopeRoot: Type.String() }),
|
|
51
|
+
),
|
|
52
|
+
limitations: Type.Array(ScanPathSummary),
|
|
53
|
+
policy: Type.Object({
|
|
54
|
+
operation: Type.String(),
|
|
55
|
+
supportedExtensions: Type.Array(Type.String()),
|
|
56
|
+
excludedDirectories: Type.Array(Type.String()),
|
|
57
|
+
configuredExclusions: Type.Array(Type.String()),
|
|
58
|
+
hiddenEntries: Type.String(),
|
|
59
|
+
ignoreFiles: Type.Boolean(),
|
|
60
|
+
symlinks: Type.String(),
|
|
61
|
+
maxFiles: Type.Integer(),
|
|
62
|
+
timeoutMs: Type.Number(),
|
|
63
|
+
}),
|
|
64
|
+
}),
|
|
65
|
+
),
|
|
66
|
+
failures: Type.Optional(
|
|
67
|
+
Type.Array(
|
|
68
|
+
Type.Object({
|
|
69
|
+
file: Type.String(),
|
|
70
|
+
kind: Type.String(),
|
|
71
|
+
reason: Type.String(),
|
|
72
|
+
errorRanges: Type.Optional(Type.Array(RecoveryRangeSchema)),
|
|
73
|
+
}),
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
},
|
|
77
|
+
{ additionalProperties: false },
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
/** Serialize only the visible matches while preserving complete collection metadata. */
|
|
81
|
+
export function structuredFindResult(
|
|
82
|
+
assembly: FindResultAssembly,
|
|
83
|
+
cwd: string,
|
|
84
|
+
): Static<typeof FindOutputSchema> {
|
|
85
|
+
const { data } = assembly.outcome;
|
|
86
|
+
const evidence = assembly.assembled.evidenceLists;
|
|
87
|
+
const shown = evidence[0]?.shownCount ?? 0;
|
|
88
|
+
const base = {
|
|
89
|
+
kind: "completed" as const,
|
|
90
|
+
mode: data.kind,
|
|
91
|
+
confidence: assembly.assembled.confidence,
|
|
92
|
+
evidenceLists: evidence.map((entry) => ({ ...entry })),
|
|
93
|
+
nextQueries: assembly.details.nextQueries,
|
|
94
|
+
};
|
|
95
|
+
if (data.kind === "semantic") {
|
|
96
|
+
const exclusion = data.partialMetadata?.automaticPathExclusion;
|
|
97
|
+
return {
|
|
98
|
+
...base,
|
|
99
|
+
matches: data.symbols.slice(0, shown).map((symbol) => {
|
|
100
|
+
const anchor = symbol.nameAnchor ?? symbol.declarationAnchor;
|
|
101
|
+
return {
|
|
102
|
+
name: symbol.name,
|
|
103
|
+
kind: symbol.kind,
|
|
104
|
+
file: toDisplayPath(cwd, symbol.file),
|
|
105
|
+
line: anchor.line,
|
|
106
|
+
character: anchor.character,
|
|
107
|
+
anchorKind: symbol.nameAnchor ? ("name" as const) : ("declaration" as const),
|
|
108
|
+
container: symbol.container ?? null,
|
|
109
|
+
};
|
|
110
|
+
}),
|
|
111
|
+
partialReason: data.partialReason,
|
|
112
|
+
...(exclusion
|
|
113
|
+
? {
|
|
114
|
+
automaticPathExclusion: {
|
|
115
|
+
excludedCount: exclusion.excludedCount,
|
|
116
|
+
examples: [...exclusion.examples],
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
: {}),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const { scan } = data.result;
|
|
123
|
+
return {
|
|
124
|
+
...base,
|
|
125
|
+
matches: data.result.matches.slice(0, shown).map((match) => ({
|
|
126
|
+
name: match.name,
|
|
127
|
+
kind: match.kind,
|
|
128
|
+
file: match.file,
|
|
129
|
+
line: match.line,
|
|
130
|
+
character: match.startCharacter,
|
|
131
|
+
endLine: match.endLine,
|
|
132
|
+
endCharacter: match.endCharacter,
|
|
133
|
+
})),
|
|
134
|
+
partialReason: data.result.partialReason,
|
|
135
|
+
scan: {
|
|
136
|
+
...scan,
|
|
137
|
+
roots: [...scan.roots],
|
|
138
|
+
policy: {
|
|
139
|
+
...scan.policy,
|
|
140
|
+
supportedExtensions: [...scan.policy.supportedExtensions],
|
|
141
|
+
excludedDirectories: [...scan.policy.excludedDirectories],
|
|
142
|
+
configuredExclusions: [...scan.policy.configuredExclusions],
|
|
143
|
+
},
|
|
144
|
+
exclusions: scan.exclusions.map((entry) => ({ ...entry, examples: [...entry.examples] })),
|
|
145
|
+
limitations: scan.limitations.map((entry) => ({ ...entry, examples: [...entry.examples] })),
|
|
146
|
+
},
|
|
147
|
+
failures: data.result.failures.map((failure) => ({
|
|
148
|
+
file: failure.file,
|
|
149
|
+
kind: failure.kind,
|
|
150
|
+
reason: failure.reason,
|
|
151
|
+
...(failure.errorRanges
|
|
152
|
+
? {
|
|
153
|
+
errorRanges: failure.errorRanges.map((range) => ({
|
|
154
|
+
start: { ...range.start },
|
|
155
|
+
end: { ...range.end },
|
|
156
|
+
})),
|
|
157
|
+
}
|
|
158
|
+
: {}),
|
|
159
|
+
})),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -26,6 +26,7 @@ import type { GraphDetails, GraphFileGroup, GraphSectionDetails } from "./detail
|
|
|
26
26
|
import { graphDisplaySection } from "./display.ts";
|
|
27
27
|
import { formatGraphEvidence } from "./format.ts";
|
|
28
28
|
import { graphReadNext } from "./read-next.ts";
|
|
29
|
+
import { structuredGraphCandidates, structuredGraphResult } from "./structured.ts";
|
|
29
30
|
|
|
30
31
|
export type { GraphRelationKind, GraphSection } from "../../session/graph-types.ts";
|
|
31
32
|
|
|
@@ -265,7 +266,17 @@ type GraphOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["graph"]>
|
|
|
265
266
|
export function finishGraphResult(outcome: GraphOutcome, cwd: string): CodeIntelResult {
|
|
266
267
|
if (outcome.kind === "unavailable") throw new Error(outcome.reason);
|
|
267
268
|
if (outcome.kind === "invalid-input") {
|
|
268
|
-
return
|
|
269
|
+
return {
|
|
270
|
+
...searchErrorResult(`**Error:** ${outcome.message}`, { message: outcome.message }),
|
|
271
|
+
structuredContent: {
|
|
272
|
+
kind: "invalid-input",
|
|
273
|
+
message: outcome.message,
|
|
274
|
+
sections: [],
|
|
275
|
+
evidenceLists: [],
|
|
276
|
+
readNext: [],
|
|
277
|
+
nextQueries: [],
|
|
278
|
+
},
|
|
279
|
+
};
|
|
269
280
|
}
|
|
270
281
|
if (outcome.kind === "disambiguation" || outcome.kind === "kind-mismatch") {
|
|
271
282
|
return finishGraphCandidates(outcome);
|
|
@@ -281,6 +292,7 @@ export function finishGraphResult(outcome: GraphOutcome, cwd: string): CodeIntel
|
|
|
281
292
|
const displayTruncated = hasHiddenDisplayEvidence(assembly);
|
|
282
293
|
return {
|
|
283
294
|
content: renderGraphResult(assembly),
|
|
295
|
+
structuredContent: structuredGraphResult(assembly),
|
|
284
296
|
details: {
|
|
285
297
|
type: "graph",
|
|
286
298
|
data: assembly.details,
|
|
@@ -328,20 +340,25 @@ function finishGraphCandidates(
|
|
|
328
340
|
format: (candidate) => formatCandidateRow(candidate, "handle-first"),
|
|
329
341
|
}),
|
|
330
342
|
];
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
343
|
+
const nextQueries =
|
|
344
|
+
outcome.kind === "kind-mismatch"
|
|
345
|
+
? ["Retry without symbolKind, use an observed provider kind, or choose a near-match handle"]
|
|
346
|
+
: ["Choose one candidate handle, or narrow the symbol selector with scope or symbolKind"];
|
|
347
|
+
const message =
|
|
348
|
+
outcome.kind === "kind-mismatch"
|
|
349
|
+
? `No target matched provider kind ${outcome.requestedKind}.`
|
|
350
|
+
: "The target is ambiguous.";
|
|
351
|
+
return {
|
|
352
|
+
...searchErrorResult(lines.join("\n"), {
|
|
353
|
+
confidence: "semantic",
|
|
354
|
+
evidenceLists: [evidence],
|
|
355
|
+
nextQueries,
|
|
356
|
+
status: outcome.kind === "disambiguation" ? "disambiguation" : "invalid-input",
|
|
357
|
+
message,
|
|
358
|
+
displaySections,
|
|
359
|
+
}),
|
|
360
|
+
structuredContent: structuredGraphCandidates(outcome, evidence, { message, nextQueries }),
|
|
361
|
+
};
|
|
345
362
|
}
|
|
346
363
|
|
|
347
364
|
function graphCandidateEvidence(
|
|
@@ -3,6 +3,7 @@ import { Type } from "typebox";
|
|
|
3
3
|
import type { CodeIntelToolExecCtx } from "../../types/index.ts";
|
|
4
4
|
import { GraphTargetParam, MaxResultsParam } from "../schemas.ts";
|
|
5
5
|
import { executeGraphTool } from "./execute.ts";
|
|
6
|
+
import { GraphOutputSchema } from "./structured.ts";
|
|
6
7
|
import { renderGraphCall, renderGraphResult } from "./tui.ts";
|
|
7
8
|
|
|
8
9
|
export const CODE_GRAPH_TOOL_NAME = "code_graph";
|
|
@@ -12,6 +13,7 @@ export const CODE_GRAPH_TOOL_LABEL = "Code Graph";
|
|
|
12
13
|
export const codeGraphSpec = {
|
|
13
14
|
name: CODE_GRAPH_TOOL_NAME,
|
|
14
15
|
label: CODE_GRAPH_TOOL_LABEL,
|
|
16
|
+
outputSchema: GraphOutputSchema,
|
|
15
17
|
parameters: Type.Object(
|
|
16
18
|
{
|
|
17
19
|
target: GraphTargetParam,
|