@mrclrchtr/supi-code-intelligence 11.0.1 → 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.
Files changed (100) hide show
  1. package/README.md +41 -4
  2. package/gradle-helper/README.md +48 -0
  3. package/gradle-helper/build.sh +73 -0
  4. package/gradle-helper/lib/gradle-tooling-api-9.4.0.jar +0 -0
  5. package/gradle-helper/lib/slf4j-api-2.0.17.jar +0 -0
  6. package/gradle-helper/lib/slf4j-simple-2.0.17.jar +0 -0
  7. package/gradle-helper/lib/supi-gradle-observation.jar +0 -0
  8. package/gradle-helper/licenses/DEPENDENCIES.md +11 -0
  9. package/gradle-helper/licenses/LICENSE-gradle-tooling-api.txt +422 -0
  10. package/gradle-helper/licenses/LICENSE-slf4j.txt +21 -0
  11. package/gradle-helper/licenses/NOTICE-gradle.txt +21 -0
  12. package/gradle-helper/src/GradleObservation.java +597 -0
  13. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  14. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  15. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +41 -1
  16. package/node_modules/@mrclrchtr/supi-lsp/README.md +1 -1
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +41 -1
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/README.md +5 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/browser/ril.js +8 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/common/connection.js +7 -2
  23. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/common/ral.d.ts +8 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/main.d.ts +14 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/main.js +6 -4
  26. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/ril.js +5 -1
  27. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/package.json +4 -2
  28. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-protocol/package.json +4 -3
  29. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/lib/esm/main.js +2 -2
  30. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/lib/umd/main.js +2 -2
  31. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/package.json +2 -1
  32. package/node_modules/@mrclrchtr/supi-lsp/package.json +6 -6
  33. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +21 -0
  34. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +1 -1
  35. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -0
  36. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  37. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  38. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +41 -1
  39. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +5 -3
  40. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/LICENSE +21 -0
  41. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +19 -2
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/LICENSE +21 -0
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +19 -2
  46. package/node_modules/ignore/README.md +36 -10
  47. package/node_modules/ignore/index.d.ts +3 -2
  48. package/node_modules/ignore/index.js +57 -53
  49. package/node_modules/ignore/legacy.js +50 -46
  50. package/node_modules/ignore/package.json +1 -1
  51. package/package.json +11 -6
  52. package/src/analysis/gradle/query.ts +273 -0
  53. package/src/analysis/gradle/runtime.ts +173 -0
  54. package/src/analysis/gradle/types.ts +65 -0
  55. package/src/analysis/read-next.ts +1 -4
  56. package/src/analysis/refactor/apply.ts +2 -2
  57. package/src/analysis/refactor/mutation-authority.ts +4 -1
  58. package/src/analysis/search/ast-scan.ts +143 -18
  59. package/src/analysis/workspace/safe-path.ts +14 -2
  60. package/src/analysis/workspace/types.ts +2 -0
  61. package/src/extension.ts +10 -1
  62. package/src/gradle/consent.ts +279 -0
  63. package/src/headless.ts +3 -0
  64. package/src/overview/collect.ts +11 -3
  65. package/src/session/orientation/workspace-context.ts +49 -28
  66. package/src/session/orientation-types.ts +11 -1
  67. package/src/session/orientation-workflow.ts +2 -0
  68. package/src/session/session.ts +8 -0
  69. package/src/tool/code_find/execute.ts +1 -1
  70. package/src/tool/code_find/markdown.ts +24 -17
  71. package/src/tool/code_find/result.ts +18 -5
  72. package/src/tool/code_find/spec.ts +2 -0
  73. package/src/tool/code_find/structured.ts +161 -0
  74. package/src/tool/code_graph/result.ts +32 -15
  75. package/src/tool/code_graph/spec.ts +2 -0
  76. package/src/tool/code_graph/structured.ts +142 -0
  77. package/src/tool/code_health/markdown.ts +5 -15
  78. package/src/tool/code_inspect/markdown.ts +19 -11
  79. package/src/tool/code_inspect/result.ts +1 -0
  80. package/src/tool/code_orientation/directory-navigation.ts +66 -0
  81. package/src/tool/code_orientation/gradle-sections.ts +68 -0
  82. package/src/tool/code_orientation/markdown.ts +19 -8
  83. package/src/tool/code_orientation/result.ts +89 -11
  84. package/src/tool/code_orientation/workspace-format.ts +2 -1
  85. package/src/tool/code_orientation/workspace-output.ts +40 -13
  86. package/src/tool/code_orientation/workspace-projects.ts +170 -50
  87. package/src/tool/code_orientation/workspace-sections.ts +3 -1
  88. package/src/tool/code_resolve/markdown.ts +4 -10
  89. package/src/tool/code_resolve/result.ts +2 -0
  90. package/src/tool/code_resolve/spec.ts +2 -0
  91. package/src/tool/code_resolve/structured.ts +103 -0
  92. package/src/tool/infra/truncate.ts +12 -4
  93. package/src/tool/register.ts +10 -6
  94. package/src/tool/result/display.ts +17 -0
  95. package/src/tool/result/model-budget.ts +195 -0
  96. package/src/tool/result/structured.ts +62 -0
  97. package/src/tool/result/types.ts +10 -2
  98. package/src/tool/specs.ts +2 -0
  99. package/src/types/execution.ts +5 -1
  100. package/src/ui/tui/display.ts +10 -4
@@ -0,0 +1,279 @@
1
+ import { isAbsolute, join, relative, sep } from "node:path";
2
+ import {
3
+ type ExtensionAPI,
4
+ type ExtensionContext,
5
+ getAgentDir,
6
+ hasTrustRequiringProjectResources,
7
+ ProjectTrustStore,
8
+ } from "@earendil-works/pi-coding-agent";
9
+ import type { CodeRequestControl } from "@mrclrchtr/supi-code-runtime/api";
10
+ import {
11
+ loadSupiConfigSectionForScope,
12
+ removeSupiConfigKey,
13
+ writeSupiConfig,
14
+ } from "@mrclrchtr/supi-core/config";
15
+ import { registerSettings } from "@mrclrchtr/supi-core/settings";
16
+ import { queryGradleModel } from "../analysis/gradle/query.ts";
17
+ import {
18
+ GradlePrerequisiteError,
19
+ hasGradleSettings,
20
+ selectGradleRuntime,
21
+ } from "../analysis/gradle/runtime.ts";
22
+ import type {
23
+ GradleFailureStage,
24
+ GradleModelQuery,
25
+ GradleObservation,
26
+ GradleObserver,
27
+ } from "../analysis/gradle/types.ts";
28
+
29
+ const section = "code-intelligence";
30
+ const key = "gradleObservation";
31
+ const explanation =
32
+ "Gradle model collection executes settings and plugins; it may download distributions or dependencies, write caches, and access files or services outside the reporting root. Reporting bounds are not a sandbox.";
33
+
34
+ function permission(cwd: string): "allow" | "deny" | undefined {
35
+ const value = loadSupiConfigSectionForScope(section, cwd, { scope: "project" })?.[key];
36
+ return value === "allow" || value === "deny" ? value : undefined;
37
+ }
38
+
39
+ function collectionFailure(
40
+ root: string,
41
+ stage: GradleFailureStage,
42
+ error: unknown,
43
+ ): GradleObservation {
44
+ return {
45
+ selectedRoot: root,
46
+ query: "GradleBuild/BasicGradleProject",
47
+ stage,
48
+ status:
49
+ error instanceof GradlePrerequisiteError
50
+ ? error.status
51
+ : stage === "query" || stage === "unknown"
52
+ ? "failed"
53
+ : "unavailable",
54
+ reason: error instanceof Error ? error.message.slice(0, 500) : "Gradle collection failed.",
55
+ };
56
+ }
57
+
58
+ /** Owned, live-authorized Gradle requests for one Pi session working directory. */
59
+ class SessionGradleObserver implements GradleObserver {
60
+ readonly active = new Set<AbortController>();
61
+ constructor(
62
+ readonly cwd: string,
63
+ readonly trusted: (root: string) => boolean,
64
+ readonly query: GradleModelQuery,
65
+ ) {}
66
+ cancel(): void {
67
+ for (const controller of this.active) controller.abort();
68
+ }
69
+ async observe(
70
+ root: string,
71
+ control?: CodeRequestControl,
72
+ ): Promise<GradleObservation | undefined> {
73
+ const base = { selectedRoot: root, query: "GradleBuild/BasicGradleProject" as const };
74
+ let stage: GradleFailureStage = "prerequisites";
75
+ try {
76
+ if (!(await hasGradleSettings(root))) return undefined;
77
+ stage = "authorization";
78
+ if (!this.trusted(root))
79
+ return {
80
+ ...base,
81
+ status: "blocked",
82
+ stage: "authorization",
83
+ reason:
84
+ "Gradle execution requires an actual Pi project-trust gate. Use /trust and reload; a bare SuPi config is insufficient.",
85
+ };
86
+ const decision = permission(this.cwd);
87
+ if (decision !== "allow")
88
+ return {
89
+ ...base,
90
+ status: "blocked",
91
+ stage: "authorization",
92
+ reason:
93
+ decision === "deny"
94
+ ? "Gradle model collection was denied in project settings."
95
+ : "Gradle model permission is unset; no execution occurred.",
96
+ };
97
+ return await this.collect(root, control);
98
+ } catch (error) {
99
+ return collectionFailure(root, stage, error);
100
+ }
101
+ }
102
+
103
+ private async collect(root: string, control?: CodeRequestControl): Promise<GradleObservation> {
104
+ const base = { selectedRoot: root, query: "GradleBuild/BasicGradleProject" as const };
105
+ const controller = new AbortController();
106
+ this.active.add(controller);
107
+ let stage: GradleFailureStage = "prerequisites";
108
+ try {
109
+ const signal = control?.signal
110
+ ? AbortSignal.any([control.signal, controller.signal])
111
+ : controller.signal;
112
+ if (signal.aborted)
113
+ return {
114
+ ...base,
115
+ status: "interrupted",
116
+ stage,
117
+ reason: "Gradle model collection was cancelled.",
118
+ };
119
+ if (control?.deadline !== undefined && Date.now() >= control.deadline)
120
+ return {
121
+ ...base,
122
+ status: "timeout",
123
+ stage,
124
+ reason: "Gradle observation deadline expired before runtime selection.",
125
+ };
126
+ const runtime = await selectGradleRuntime(root);
127
+ if (!this.trusted(root) || permission(this.cwd) !== "allow" || signal.aborted)
128
+ return {
129
+ ...base,
130
+ status: "interrupted",
131
+ stage: "authorization",
132
+ reason: "Gradle authorization was revoked; no new query was started.",
133
+ };
134
+ stage = "unknown";
135
+ const result = await this.query(root, runtime, { ...control, signal });
136
+ if (signal.aborted || !this.trusted(root) || permission(this.cwd) !== "allow")
137
+ return {
138
+ ...base,
139
+ runtime,
140
+ status: "interrupted",
141
+ stage: result.status === "complete" ? "query" : result.stage,
142
+ gradleVersion: result.gradleVersion,
143
+ reason:
144
+ "Gradle authorization changed or collection was cancelled; prior side effects may remain.",
145
+ };
146
+ return { ...result, runtime };
147
+ } catch (error) {
148
+ return collectionFailure(root, stage, error);
149
+ } finally {
150
+ this.active.delete(controller);
151
+ }
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Register project-only consent, startup prompting, and owned-request cancellation.
157
+ * Pi's effective trust boolean alone is insufficient in a directory containing only
158
+ * .pi/supi/config.json: Pi implicitly trusts directories without protected resources.
159
+ * Snapshot the protected-resource gate at session_start, or require Pi's user-owned
160
+ * saved trust decision. Explicit external focuses require their own saved trust.
161
+ */
162
+ export function registerGradleObservations(
163
+ pi: ExtensionAPI,
164
+ options: {
165
+ homeDir?: string;
166
+ query?: GradleModelQuery;
167
+ interactive?: boolean;
168
+ } = {},
169
+ ): {
170
+ forContext(ctx: ExtensionContext): GradleObserver;
171
+ } {
172
+ const { homeDir, query = queryGradleModel, interactive = true } = options;
173
+ const sessions = new Map<string, SessionGradleObserver>();
174
+ const contexts = new Map<string, ExtensionContext>();
175
+ const gatedRoots = new Set<string>();
176
+ const trustStore = new ProjectTrustStore(homeDir ? join(homeDir, ".pi/agent") : getAgentDir());
177
+ const savedTrust = (root: string) => {
178
+ try {
179
+ return trustStore.get(root) === true;
180
+ } catch {
181
+ return false;
182
+ }
183
+ };
184
+ const forContext = (ctx: ExtensionContext): SessionGradleObserver => {
185
+ contexts.set(ctx.cwd, ctx);
186
+ let observer = sessions.get(ctx.cwd);
187
+ if (!observer) {
188
+ observer = new SessionGradleObserver(
189
+ ctx.cwd,
190
+ (root) => {
191
+ if (!contexts.get(ctx.cwd)?.isProjectTrusted()) return false;
192
+ const local = relative(ctx.cwd, root);
193
+ const inside =
194
+ local === "" || (local !== ".." && !local.startsWith(`..${sep}`) && !isAbsolute(local));
195
+ return inside ? gatedRoots.has(ctx.cwd) || savedTrust(ctx.cwd) : savedTrust(root);
196
+ },
197
+ query,
198
+ );
199
+ sessions.set(ctx.cwd, observer);
200
+ }
201
+ return observer;
202
+ };
203
+ if (interactive)
204
+ registerSettings(pi, {
205
+ id: "code-intelligence-gradle",
206
+ label: "Code Intelligence",
207
+ subsection: "Gradle observations",
208
+ async read(context) {
209
+ if (context.scope !== "project") return { rows: [] };
210
+ const value = permission(context.cwd);
211
+ return {
212
+ rows: [
213
+ {
214
+ field: {
215
+ kind: "enum",
216
+ key,
217
+ label: "Gradle Model Permission",
218
+ values: ["allow", "deny"],
219
+ description: `${explanation} Project only. Reset asks at the next eligible startup. Changes affect the next query; Deny cancels owned work where possible, not side effects or unrelated daemons.`,
220
+ },
221
+ displayValue: value ? (value === "allow" ? "Allow" : "Deny") : "Unset",
222
+ editValue: value ?? "",
223
+ source: value ? "project" : "default",
224
+ inheritanceSource: "default",
225
+ },
226
+ ],
227
+ };
228
+ },
229
+ async apply(request) {
230
+ if (request.scope !== "project" || request.fieldKey !== key)
231
+ throw new Error("Gradle consent is project-only.");
232
+ if (request.action.kind === "unset")
233
+ removeSupiConfigKey({ section, cwd: request.cwd, scope: "project" }, key);
234
+ else {
235
+ if (!["allow", "deny"].includes(request.action.value))
236
+ throw new Error("Expected Allow or Deny.");
237
+ writeSupiConfig(
238
+ { section, cwd: request.cwd, scope: "project" },
239
+ { [key]: request.action.value },
240
+ );
241
+ }
242
+ if (permission(request.cwd) !== "allow") sessions.get(request.cwd)?.cancel();
243
+ return {
244
+ notice: {
245
+ level: "info",
246
+ message:
247
+ "Gradle permission saved. Applies to the next query; cancellation cannot undo side effects or stop unrelated daemons.",
248
+ },
249
+ };
250
+ },
251
+ });
252
+ pi.on("session_start", async (_event, ctx) => {
253
+ if (ctx.isProjectTrusted() && hasTrustRequiringProjectResources(ctx.cwd))
254
+ gatedRoots.add(ctx.cwd);
255
+ const observer = forContext(ctx);
256
+ if (
257
+ !interactive ||
258
+ !ctx.hasUI ||
259
+ !observer.trusted(ctx.cwd) ||
260
+ permission(ctx.cwd) !== undefined ||
261
+ !(await hasGradleSettings(ctx.cwd).catch(() => false))
262
+ )
263
+ return;
264
+ const answer = await ctx.ui.select(`Allow Gradle model collection? ${explanation}`, [
265
+ "Allow",
266
+ "Deny",
267
+ "Cancel",
268
+ ]);
269
+ if (answer === "Allow" || answer === "Deny")
270
+ writeSupiConfig({ section, cwd: ctx.cwd, scope: "project" }, { [key]: answer.toLowerCase() });
271
+ });
272
+ pi.on("session_shutdown", () => {
273
+ for (const observer of sessions.values()) observer.cancel();
274
+ sessions.clear();
275
+ contexts.clear();
276
+ gatedRoots.clear();
277
+ });
278
+ return { forContext };
279
+ }
package/src/headless.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { createSessionCache } from "./app/app.ts";
3
+ import { registerGradleObservations } from "./gradle/consent.ts";
3
4
  import { registerLspSessionLifecycle } from "./substrate/lsp/lifecycle.ts";
4
5
  import { createLspAdapterState } from "./substrate/lsp/state.ts";
5
6
  import { registerCodeIntelligenceTools } from "./tool/register.ts";
@@ -24,11 +25,13 @@ const inspectionToolNames = new Set<string>(HEADLESS_INSPECTION_TOOL_NAMES);
24
25
  export default function headlessInspectionProfile(pi: ExtensionAPI): void {
25
26
  const sessions = createSessionCache();
26
27
  const lspState = createLspAdapterState();
28
+ const gradle = registerGradleObservations(pi, { interactive: false });
27
29
  registerLspSessionLifecycle(pi, lspState, (ctx) => {
28
30
  const session = sessions.getOrCreate(ctx.cwd);
29
31
  session.attachLspController(lspState.controller);
30
32
  session.seedSentinelSnapshot(lspState.sentinelSnapshot);
31
33
  session.setProjectTrusted(ctx.isProjectTrusted());
34
+ session.setGradleObserver(gradle.forContext(ctx));
32
35
  session.setAutomaticPathPolicy(lspState.providerLease?.automaticPathPolicy ?? null);
33
36
  });
34
37
  pi.on("session_shutdown", () => sessions.clear());
@@ -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(cwd: string, projectTrusted: boolean, homeDir?: string) {
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 observation = await observeWorkspace(cwd, {
20
+ const control = { deadline: Date.now() + 10_000 };
21
+ let observation = await observeWorkspace(cwd, {
16
22
  exclude,
17
- control: { deadline: Date.now() + 10_000 },
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 { OrientationResultData, OrientationWorkflowInput } from "../orientation-types.ts";
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: { cwd: string; homeDir?: string; projectTrusted: boolean },
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"; message: string }
38
+ | Extract<OrientationWorkflowOutcome, { kind: "invalid-input" }>
30
39
  | null
31
40
  > {
32
- const selected = directoryFocus(request, options.cwd);
33
- if (!selected || selected.kind === "invalid-input") return selected;
34
- let focus = selected.path;
35
- const exclude = loadAutomaticExclusionPatterns(options.cwd, options);
36
- if (focus) await assertFocusPath(options.cwd, focus);
37
- let observation = await initialObservation(options.cwd, focus, exclude, control);
38
- if (request.focus && "module" in request.focus) {
39
- const selected = resolveModule(observation, request.focus.module);
40
- if (selected.kind === "invalid-input") return selected;
41
- focus = selected.path;
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 } | { kind: "invalid-input"; message: 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
- | { readonly kind: "invalid-input"; readonly message: string }
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. */
@@ -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
- return `${limitation.reason}: ${count}`;
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 configuredExclusion = result.scan.exclusions.find(
69
- (exclusion) => exclusion.reason === "configured-exclusion",
70
- );
71
- if (configuredExclusion) {
72
- const examples = configuredExclusion.examples.length
73
- ? ` Examples: ${configuredExclusion.examples.map((file) => `\`${file}\``).join(", ")}.`
74
- : "";
75
- lines.push(
76
- "",
77
- `_AST Scan excluded ${configuredExclusion.pathCount} configured path${configuredExclusion.pathCount === 1 ? "" : "s"} by \`code-intelligence.exclude\`. Explicit scopes remain available.${examples}`,
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 operationExclusion = result.scan.exclusions.find(
88
+ for (const excluded of result.scan.exclusions.filter(
81
89
  (exclusion) => exclusion.reason === "unsupported-operation",
82
- );
83
- if (operationExclusion) {
84
- const count = operationExclusion.pathCount;
90
+ )) {
91
+ const count = excluded.pathCount;
85
92
  lines.push(
86
93
  "",
87
- `_AST Scan policy excluded ${count} file${count === 1 ? "" : "s"} because ${result.scan.policy.operation} analysis is not supported for their language._`,
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 searchErrorResult(`**Error:** ${outcome.message}`, {
192
- scope: Array.isArray(scope) ? scope.join(", ") : null,
193
- nextQueries: ["Fix the search input and retry"],
194
- message: outcome.message,
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,