@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.
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 +95 -14
  47. package/node_modules/ignore/index.d.ts +56 -20
  48. package/node_modules/ignore/index.js +150 -120
  49. package/node_modules/ignore/legacy.js +159 -131
  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,142 @@
1
+ import { StringEnum } from "@earendil-works/pi-ai";
2
+ import { type Static, Type } from "typebox";
3
+ import type { EvidenceListMetadata } from "../../analysis/evidence.ts";
4
+ import { toDisplayPath } from "../../analysis/search/paths.ts";
5
+ import type { GraphWorkflowOutcome } from "../../session/graph-types.ts";
6
+ import {
7
+ EvidenceListSchema,
8
+ NavigationTargetSchema,
9
+ ReadNextSchema,
10
+ RecoveryRangeSchema,
11
+ } from "../result/structured.ts";
12
+ import type { GraphResultAssembly } from "./result.ts";
13
+
14
+ /** Codemode relation evidence; callees describe written expressions, not resolved identities. */
15
+ export const GraphOutputSchema = Type.Object(
16
+ {
17
+ kind: StringEnum(["completed", "invalid-input", "disambiguation", "kind-mismatch"]),
18
+ target: Type.Optional(Type.Object({ name: Type.String(), file: Type.String() })),
19
+ sections: Type.Array(
20
+ Type.Object(
21
+ {
22
+ relation: StringEnum(["references", "callees", "implements"]),
23
+ source: StringEnum(["semantic", "structural"]),
24
+ status: StringEnum(["complete", "partial", "unavailable"]),
25
+ message: Type.Union([Type.String(), Type.Null()]),
26
+ items: Type.Array(
27
+ Type.Object(
28
+ {
29
+ name: Type.Union([Type.String(), Type.Null()]),
30
+ file: Type.String(),
31
+ line: Type.Integer(),
32
+ character: Type.Integer(),
33
+ },
34
+ { additionalProperties: false },
35
+ ),
36
+ ),
37
+ evidence: Type.Optional(EvidenceListSchema),
38
+ externalCount: Type.Integer(),
39
+ depth: Type.Union([StringEnum(["direct", "deep"]), Type.Null()]),
40
+ enclosingScope: Type.Union([
41
+ Type.Object({
42
+ name: Type.String(),
43
+ file: Type.String(),
44
+ startLine: Type.Integer(),
45
+ endLine: Type.Integer(),
46
+ }),
47
+ Type.Null(),
48
+ ]),
49
+ recovery: Type.Union([
50
+ Type.Object({
51
+ file: Type.String(),
52
+ reason: Type.String(),
53
+ errorRanges: Type.Array(RecoveryRangeSchema),
54
+ }),
55
+ Type.Null(),
56
+ ]),
57
+ },
58
+ { additionalProperties: false },
59
+ ),
60
+ ),
61
+ targets: Type.Optional(Type.Array(NavigationTargetSchema)),
62
+ evidenceLists: Type.Array(EvidenceListSchema),
63
+ readNext: Type.Array(ReadNextSchema),
64
+ message: Type.Optional(Type.String()),
65
+ requestedKind: Type.Optional(Type.String()),
66
+ nextQueries: Type.Array(Type.String()),
67
+ },
68
+ { additionalProperties: false },
69
+ );
70
+
71
+ /** Project the already-bounded assembly without exposing provider objects or UI previews. */
72
+ export function structuredGraphResult(
73
+ assembly: GraphResultAssembly,
74
+ ): Static<typeof GraphOutputSchema> {
75
+ return {
76
+ kind: "completed",
77
+ target: { name: assembly.displayName, file: assembly.resolvedDisplayFile },
78
+ sections: assembly.sections.map((section, index) => {
79
+ const info = assembly.details.sections[index];
80
+ return {
81
+ relation: section.rel,
82
+ source: info.source,
83
+ status: info.status,
84
+ message: info.message,
85
+ items:
86
+ section.kind === "unavailable"
87
+ ? []
88
+ : section.evidence.items.map((item) => ({
89
+ name: item.name,
90
+ file: toDisplayPath(assembly.cwd, item.file),
91
+ line: item.line,
92
+ character: item.character,
93
+ })),
94
+ ...(section.kind === "ok" ? { evidence: { ...section.evidence.metadata } } : {}),
95
+ externalCount: info.externalCount,
96
+ depth: info.depth,
97
+ enclosingScope: info.enclosingScope ? { ...info.enclosingScope } : null,
98
+ recovery: info.recovery
99
+ ? {
100
+ file: toDisplayPath(assembly.cwd, info.recovery.file),
101
+ reason: info.recovery.reason,
102
+ errorRanges: info.recovery.errorRanges.map((range) => ({
103
+ start: { ...range.start },
104
+ end: { ...range.end },
105
+ })),
106
+ }
107
+ : null,
108
+ };
109
+ }),
110
+ evidenceLists: assembly.assembled.evidenceLists.map((evidence) => ({ ...evidence })),
111
+ readNext: assembly.details.readNext.map((item) => ({ ...item })),
112
+ nextQueries: [],
113
+ };
114
+ }
115
+
116
+ /** Keep recoverable candidate selection machine-readable without parsing Markdown. */
117
+ export function structuredGraphCandidates(
118
+ outcome: Extract<GraphWorkflowOutcome, { kind: "disambiguation" | "kind-mismatch" }>,
119
+ evidence: EvidenceListMetadata,
120
+ actions: { message: string; nextQueries: string[] },
121
+ ): Static<typeof GraphOutputSchema> {
122
+ const { message, nextQueries } = actions;
123
+ return {
124
+ kind: outcome.kind,
125
+ message,
126
+ sections: [],
127
+ targets: outcome.candidates.map((candidate) => ({
128
+ handle: candidate.targetId,
129
+ name: candidate.name,
130
+ kind: candidate.kind,
131
+ file: candidate.file,
132
+ line: candidate.line,
133
+ character: candidate.character,
134
+ anchorKind: candidate.anchorKind,
135
+ container: candidate.container,
136
+ })),
137
+ evidenceLists: [{ ...evidence }],
138
+ readNext: [],
139
+ nextQueries,
140
+ ...(outcome.kind === "kind-mismatch" ? { requestedKind: outcome.requestedKind } : {}),
141
+ };
142
+ }
@@ -69,9 +69,7 @@ function renderRefreshStatus(
69
69
  if (data.refresh.lastAttempt) {
70
70
  renderRetainedAttempt(lines, data.refresh.lastAttempt, cwd);
71
71
  } else {
72
- lines.push(
73
- "**Diagnostic refresh attempt**: not requested this session. Use `refresh: true` to try one.",
74
- );
72
+ lines.push("Refresh: not requested (`refresh: true` to attempt).");
75
73
  }
76
74
  lines.push("");
77
75
  }
@@ -236,8 +234,9 @@ function renderStatusLine(lines: string[], data: HealthData, semanticRequested:
236
234
  if (!semanticRequested) return;
237
235
 
238
236
  const routeSummary = formatProjectServerRouteSummary(data.servers);
239
- lines.push(`**LSP**: ${displaySemanticStatus(data)}${routeSummary ? ` — ${routeSummary}` : ""}`);
240
- if (data.structuralStatus) lines.push(`**Structural**: ${data.structuralStatus}`);
237
+ lines.push(
238
+ `**LSP**: ${displaySemanticStatus(data)}${routeSummary ? ` — ${routeSummary}` : ""}${data.structuralStatus ? `; **Structural**: ${data.structuralStatus}` : ""}`,
239
+ );
241
240
  lines.push("");
242
241
  }
243
242
 
@@ -297,7 +296,7 @@ function renderDiagnosticObservation(lines: string[], data: HealthData, cwd: str
297
296
  return;
298
297
  }
299
298
  if (observation.entries.length === 0) {
300
- lines.push(emptyDiagnosticText(observation.scope, cwd));
299
+ lines.push("No errors or warnings reported in this scope.");
301
300
  return;
302
301
  }
303
302
  renderDiagnosticEntries(lines, data, cwd);
@@ -311,15 +310,6 @@ function asSentence(text: string): string {
311
310
  return /[.!?]$/.test(text) ? text : `${text}.`;
312
311
  }
313
312
 
314
- function emptyDiagnosticText(scope: HealthDiagnosticScope, cwd: string): string {
315
- if (scope.kind === "file") {
316
- return `No errors or warnings found for \`${makeRelative(cwd, scope.path)}\`.`;
317
- }
318
- return scope.filter
319
- ? `No errors or warnings are reported by the tracked-file diagnostic snapshot under \`${makeRelative(cwd, scope.filter)}\`.`
320
- : "No errors or warnings are reported by the tracked-file diagnostic snapshot.";
321
- }
322
-
323
313
  function renderDiagnosticEntries(lines: string[], data: HealthData, cwd: string): void {
324
314
  const entries = data.diagnostics.entries;
325
315
  if (data.level === "summary") {
@@ -1,5 +1,5 @@
1
1
  import { renderEvidenceListDisclosure } from "../../analysis/evidence.ts";
2
- import type { InspectObservation } from "../../session/inspect-types.ts";
2
+ import type { InspectDefinition, InspectObservation } from "../../session/inspect-types.ts";
3
3
  import type { InspectResultAssembly } from "./result.ts";
4
4
 
5
5
  export function renderInspectResult(assembly: InspectResultAssembly): string {
@@ -11,7 +11,7 @@ export function renderInspectResult(assembly: InspectResultAssembly): string {
11
11
  "",
12
12
  ];
13
13
 
14
- renderNode(lines, input, input.sections.node);
14
+ renderNode(lines, input.sections.node);
15
15
  renderEnclosingSymbol(lines, input.sections.enclosingSymbol);
16
16
  renderHover(lines, input.sections.hover);
17
17
  renderDefinitions(lines, assembly);
@@ -21,7 +21,6 @@ export function renderInspectResult(assembly: InspectResultAssembly): string {
21
21
 
22
22
  function renderNode(
23
23
  lines: string[],
24
- input: InspectResultAssembly["data"],
25
24
  observation: InspectResultAssembly["data"]["sections"]["node"],
26
25
  ): void {
27
26
  lines.push("## Syntax node");
@@ -37,16 +36,13 @@ function renderNode(
37
36
  return;
38
37
  }
39
38
  lines.push(
40
- `- Type: \`${node.type}\` at ${input.relPath}:${node.startLine}:${node.startCharacter}–${node.endLine}:${node.endCharacter}`,
39
+ `- \`${node.type}\` L${node.startLine}:${node.startCharacter}–L${node.endLine}:${node.endCharacter}`,
41
40
  );
42
41
  if (node.text) lines.push("```text", node.text, "```");
43
42
  if (node.ancestry.length > 0) {
44
- lines.push("", "### Ancestry");
45
- for (const ancestor of node.ancestry) {
46
- lines.push(
47
- `- \`${ancestor.type} L${ancestor.startLine}:${ancestor.startCharacter}–L${ancestor.endLine}:${ancestor.endCharacter}\``,
48
- );
49
- }
43
+ lines.push(
44
+ `Ancestry: ${node.ancestry.map((ancestor) => `\`${ancestor.type} L${ancestor.startLine}:${ancestor.startCharacter}–L${ancestor.endLine}:${ancestor.endCharacter}\``).join(" > ")}`,
45
+ );
50
46
  }
51
47
  lines.push("");
52
48
  }
@@ -95,7 +91,7 @@ function renderDefinitions(lines: string[], assembly: InspectResultAssembly): vo
95
91
  lines.push("_No definition result at this point._");
96
92
  } else {
97
93
  for (const definition of assembly.displayedDefinitions) {
98
- lines.push(`- \`${definition.file}:${definition.line}:${definition.character}\``);
94
+ lines.push(`- ${formatDefinition(definition, assembly.data)}`);
99
95
  }
100
96
  }
101
97
  const disclosure = assembly.definitionEvidence
@@ -105,6 +101,18 @@ function renderDefinitions(lines: string[], assembly: InspectResultAssembly): vo
105
101
  lines.push("");
106
102
  }
107
103
 
104
+ function formatDefinition(
105
+ definition: InspectDefinition,
106
+ focus: InspectResultAssembly["data"],
107
+ ): string {
108
+ if (definition.file !== focus.relPath) {
109
+ return `\`${definition.file}:${definition.line}:${definition.character}\``;
110
+ }
111
+ if (definition.line === focus.line && definition.character === focus.character)
112
+ return "Same point";
113
+ return `L${definition.line}:${definition.character}`;
114
+ }
115
+
108
116
  function renderDiagnostics(lines: string[], assembly: InspectResultAssembly): void {
109
117
  const observation = assembly.data.sections.diagnostics;
110
118
  const window = assembly.data.diagnosticWindow;
@@ -84,6 +84,7 @@ export function assembleInspectResult(
84
84
  confidence: data.confidence,
85
85
  focusTarget: `${data.relPath}:${data.line}:${data.character}`,
86
86
  diagnosticWindow: { ...data.diagnosticWindow },
87
+ diagnostics: (diagnosticEvidence?.items ?? []).map((diagnostic) => ({ ...diagnostic })),
87
88
  sections: inspectSectionDetails(data),
88
89
  evidenceLists: [...assembled.evidenceLists],
89
90
  nextQueries: assembledNextQueries(assembled),
@@ -0,0 +1,66 @@
1
+ import type {
2
+ OrientationResultData,
3
+ OrientationSectionData,
4
+ } from "../../session/orientation-types.ts";
5
+
6
+ const INLINE_SECTIONS = new Set([
7
+ "instructions",
8
+ "workspace.directories",
9
+ "workspace.files",
10
+ "workspace.issues",
11
+ ]);
12
+
13
+ /** Keep the immediate directory map and all collection problems inline; defer ancillary facts. */
14
+ export function selectDirectoryNavigation(data: OrientationResultData): OrientationResultData {
15
+ if (!data.workspace?.focus || data.workspace.overview) return data;
16
+ const workspaceRoot = data.workspace.focus === data.workspace.observation.root;
17
+ const inline = (section: OrientationSectionData): boolean =>
18
+ INLINE_SECTIONS.has(section.key) ||
19
+ section.key.startsWith("gradle.") ||
20
+ (workspaceRoot &&
21
+ (section.key === "workspace.projects" || section.key === "workspace.memberships")) ||
22
+ section.status !== "complete" ||
23
+ section.evidenceLists.some((list) => list.totalCount === null || list.partialReason !== null);
24
+ const sections = data.sections.filter(inline);
25
+ const deferred = data.sections.filter((section) => !inline(section));
26
+ const total = deferred.reduce(
27
+ (sum, section) =>
28
+ sum + section.evidenceLists.reduce((count, list) => count + (list.totalCount ?? 0), 0),
29
+ 0,
30
+ );
31
+ if (total > 0) {
32
+ sections.push({
33
+ key: "workspace.captured",
34
+ title: "Captured navigation",
35
+ status: "complete",
36
+ reason: null,
37
+ confidence: "unavailable",
38
+ provenance: [],
39
+ evidenceLists: [
40
+ {
41
+ key: "workspace.captured",
42
+ totalCount: total,
43
+ shownCount: 0,
44
+ omittedCount: total,
45
+ partialReason: null,
46
+ },
47
+ ],
48
+ items: [
49
+ {
50
+ kind: "paragraph",
51
+ text: `Ancillary sections are in the captured details: ${deferred.map((section) => section.title).join("; ")}.`,
52
+ },
53
+ ],
54
+ });
55
+ }
56
+ return {
57
+ ...data,
58
+ sections,
59
+ renderedSections: sections.map((section) => section.key),
60
+ omittedCount: sections.reduce(
61
+ (sum, section) =>
62
+ sum + section.evidenceLists.reduce((count, list) => count + (list.omittedCount ?? 0), 0),
63
+ 0,
64
+ ),
65
+ };
66
+ }
@@ -0,0 +1,68 @@
1
+ import type { GradleObservation } from "../../analysis/gradle/types.ts";
2
+ import type { OrientationSectionData } from "../../session/orientation-types.ts";
3
+ import { code, tableSection } from "./workspace-format.ts";
4
+
5
+ /** Project identities and runtime provenance stay separate from parsed Project declarations. */
6
+ export function gradleSections(
7
+ observation: GradleObservation | undefined,
8
+ limit: number,
9
+ ): OrientationSectionData[] {
10
+ if (!observation) return [];
11
+ const attempted = observation.status === "complete" || observation.stage === "query";
12
+ const uncertain = observation.status !== "complete" && observation.stage === "unknown";
13
+ let queryStatement = "Model query was not run";
14
+ if (attempted) queryStatement = "Model query was attempted";
15
+ if (uncertain) queryStatement = "Model query execution is unknown";
16
+ const detail = `Selected build ${observation.selectedRoot}; requested model ${observation.query}; ${queryStatement}${observation.gradleVersion ? `; Gradle ${observation.gradleVersion}` : ""}${observation.runtime ? `; ${observation.runtime.kind} from ${observation.runtime.source}` : ""}`;
17
+ const source = attempted || uncertain ? "runtime" : "configuration";
18
+ const capability = uncertain ? "Gradle collection" : observation.query;
19
+ const provenance = [{ source, capability, detail }] as const;
20
+ const common: OrientationSectionData = {
21
+ key: "gradle.observation",
22
+ title: "Gradle model observation",
23
+ status: observation.status === "complete" ? "complete" : "unavailable",
24
+ reason:
25
+ observation.status === "complete" ? null : `${observation.status}: ${observation.reason}`,
26
+ confidence: "unavailable",
27
+ provenance,
28
+ evidenceLists: [],
29
+ items: [
30
+ {
31
+ kind: "paragraph",
32
+ text: `Selected build: ${code(observation.selectedRoot)}. Requested model: ${code(observation.query)}. ${observation.gradleVersion ? `Gradle ${code(observation.gradleVersion)}. ` : ""}${observation.status === "complete" ? "Runtime-reported facts, not parsed Project declarations. Included-build trees are not expanded. Directories do not establish source ownership, dependency resolution, or runtime architecture." : `${queryStatement}. This does not establish that the build has no projects.`}`,
33
+ },
34
+ ],
35
+ };
36
+ if (observation.status !== "complete") return [common];
37
+ const projects = tableSection("gradle.projects", "Gradle-reported projects", {
38
+ headers: [
39
+ "Build identity (root directory)",
40
+ "Logical project path",
41
+ "Name",
42
+ "Parent path",
43
+ "Actual project directory",
44
+ ],
45
+ rows: observation.projects.map((project) => [
46
+ code(project.buildRoot),
47
+ code(project.path),
48
+ code(project.name),
49
+ project.parentPath === null ? "—" : code(project.parentPath),
50
+ code(project.directory),
51
+ ]),
52
+ limit,
53
+ source: "runtime",
54
+ detail,
55
+ });
56
+ const included = tableSection(
57
+ "gradle.included-builds",
58
+ "Gradle included-build references (not expanded)",
59
+ {
60
+ headers: ["Build identity (root directory)"],
61
+ rows: observation.includedBuilds.map((build) => [code(build.buildRoot)]),
62
+ limit,
63
+ source: "runtime",
64
+ detail,
65
+ },
66
+ );
67
+ return [common, { ...projects, provenance }, { ...included, provenance }];
68
+ }
@@ -7,6 +7,7 @@ import type {
7
7
  } from "../../session/orientation-types.ts";
8
8
  import { assembledReadNext } from "../result/assembly.ts";
9
9
  import type { OrientationResultAssembly } from "./result.ts";
10
+ import { code } from "./workspace-format.ts";
10
11
 
11
12
  /**
12
13
  * Sole model-facing markdown adapter for Orientation.
@@ -93,29 +94,39 @@ function renderItems(
93
94
  }
94
95
  }
95
96
 
96
- /** Keep source-written fences inside the enclosing code block. */
97
- function codeFence(lines: readonly string[]): string {
98
- let size = 3;
97
+ /** Choose delimiters longer than any source-written backtick run. */
98
+ function codeFence(lines: readonly string[], minimum = 3): string {
99
+ let size = minimum;
99
100
  for (const line of lines)
100
101
  for (const match of line.matchAll(/`+/g)) size = Math.max(size, match[0].length + 1);
101
102
  return "`".repeat(size);
102
103
  }
103
104
 
105
+ function literalReason(reason: string): string {
106
+ const text = reason
107
+ .replace(/[\p{Cc}\p{Cf}\p{Z}]/gu, " ")
108
+ .replace(/\s+/gu, " ")
109
+ .trim();
110
+ const delimiter = codeFence([text], 1);
111
+ return `${delimiter} ${text} ${delimiter}`;
112
+ }
113
+
104
114
  function compactSectionNote(section: OrientationSectionData): string {
115
+ const facts = section.evidenceLists.map(evidenceSummary).join("; ");
105
116
  return [
106
- section.evidenceLists.map(evidenceSummary).join("; "),
107
- section.reason,
117
+ facts ? `${facts}${/[.!?…]$/.test(facts) ? "" : "."}` : null,
118
+ section.reason ? literalReason(section.reason) : null,
108
119
  section.provenance.map(formatProvenance).join(", "),
109
120
  ]
110
121
  .filter(Boolean)
111
- .join(". ");
122
+ .join(" ");
112
123
  }
113
124
 
114
125
  /** Render the same section status/provenance metadata stored in result details. */
115
126
  function formatSectionNote(section: OrientationSectionData): string {
116
127
  const facts = section.evidenceLists.map(evidenceSummary).join("; ");
117
128
  const provenance = section.provenance.map(formatProvenance).join(", ");
118
- return `_(status: ${section.status}; provenance: ${provenance || "none"}${section.reason ? `; ${section.reason}` : ""}${facts ? `; ${facts}` : ""})_`;
129
+ return `_(status: ${section.status}; provenance: ${provenance || "none"}${section.reason ? `; ${literalReason(section.reason)}` : ""}${facts ? `; ${facts}` : ""})_`;
119
130
  }
120
131
 
121
132
  function evidenceSummary(metadata: EvidenceListMetadata): string {
@@ -130,6 +141,6 @@ function evidenceSummary(metadata: EvidenceListMetadata): string {
130
141
  }
131
142
 
132
143
  function formatProvenance(provenance: OrientationProvenance): string {
133
- const detail = provenance.detail ? ` \`${provenance.detail}\`` : "";
144
+ const detail = provenance.detail ? ` ${code(provenance.detail)}` : "";
134
145
  return `${provenance.source}${provenance.capability ? ` (${provenance.capability})` : ""}${detail}`;
135
146
  }
@@ -19,7 +19,11 @@ import {
19
19
  type ToolResultAssembly,
20
20
  } from "../result/assembly.ts";
21
21
  import { formatCandidateRow, formatPartialCandidateDisclosure } from "../result/candidate-row.ts";
22
- import { createToolDisplaySection } from "../result/display.ts";
22
+ import {
23
+ createToolDisplaySection,
24
+ MAX_TUI_DISPLAY_ITEMS,
25
+ truncateDisplayText,
26
+ } from "../result/display.ts";
23
27
  import type {
24
28
  ContextDetails,
25
29
  OrientationSectionDetails,
@@ -131,17 +135,81 @@ export function assembleOrientationDetails(input: OrientationDetailsInput): Cont
131
135
 
132
136
  function orientationDisplaySection(section: OrientationSectionData): ToolDisplaySection {
133
137
  const items = section.items.filter((item) => item.kind !== "blank");
134
- return createToolDisplaySection({
138
+ const input = {
135
139
  key: `orientation.${section.key}`,
136
140
  title: section.title,
137
- items,
138
- totalCount: items.length,
139
- omittedCount: 0,
140
141
  partialReason:
141
142
  section.evidenceLists.find((evidence) => evidence.partialReason)?.partialReason ??
142
143
  (section.reason ? "provider-limited" : null),
143
144
  ...(section.reason ? { partialMessage: section.reason } : {}),
145
+ };
146
+ const evidence = section.evidenceLists.find((list) => list.key === section.tableEvidenceKey);
147
+ if (evidence) {
148
+ const rows = orientationTableRows(items);
149
+ const display = createToolDisplaySection({
150
+ ...input,
151
+ items: rows,
152
+ totalCount: evidence.totalCount,
153
+ omittedCount: evidence.omittedCount,
154
+ partialReason: evidence.partialReason ?? input.partialReason,
155
+ partialMessage: evidence.partialMessage ?? input.partialMessage,
156
+ format: (row) => row,
157
+ });
158
+ return rows.length
159
+ ? display
160
+ : {
161
+ ...display,
162
+ lines: items
163
+ .slice(0, MAX_TUI_DISPLAY_ITEMS)
164
+ .map((item) => truncateDisplayText(formatOrientationItem(item))),
165
+ };
166
+ }
167
+ const grouped = section.key === "workspace.memberships";
168
+ const summaries = section.evidenceLists.map((list) => {
169
+ const prefix = section.evidenceLists.length > 1 ? `${list.key}: ` : "";
170
+ return `${prefix}${orientationEvidenceSelection(list, grouped ? "memberships" : undefined)}`;
171
+ });
172
+ return createToolDisplaySection({
173
+ ...input,
174
+ items,
175
+ totalCount: items.length,
176
+ omittedCount: 0,
144
177
  format: formatOrientationItem,
178
+ preview: {
179
+ unit: grouped ? "group" : "block",
180
+ ...(summaries.length ? { evidenceSummary: summaries.join("; ") } : {}),
181
+ },
182
+ });
183
+ }
184
+
185
+ /** Describe canonical selection separately: a capped group preview need not show every atom. */
186
+ function orientationEvidenceSelection(list: EvidenceListMetadata, noun?: string): string {
187
+ const label = noun ? ` ${noun}` : "";
188
+ const explanation = list.partialMessage ? `; ${list.partialMessage}` : "";
189
+ if (list.totalCount === null) {
190
+ const omitted = list.omittedCount ? `; ${list.omittedCount} collected omitted` : "";
191
+ return `${list.shownCount}${label} selected${omitted}; more may exist — ${list.partialReason ?? "partial"}${explanation}`;
192
+ }
193
+ const partial = list.partialReason ? `; partial — ${list.partialReason}` : "";
194
+ if (list.omittedCount) {
195
+ return `${list.shownCount} of ${list.totalCount}${label} selected; ${list.omittedCount} omitted${partial}${explanation}`;
196
+ }
197
+ return `${list.totalCount}${label || " observed"}${partial}${explanation}`;
198
+ }
199
+
200
+ /** Keep table headers and group context with the first evidence row, outside its count. */
201
+ function orientationTableRows(items: readonly OrientationItem[]): string[] {
202
+ let framing: string[] = [];
203
+ return items.flatMap((item) => {
204
+ if (item.kind !== "table") {
205
+ framing.push(formatOrientationItem(item));
206
+ return [];
207
+ }
208
+ const rows = item.rows.map((row, index) =>
209
+ [...(index === 0 ? [...framing, item.headers.join(" | ")] : []), row.join(" | ")].join("\n"),
210
+ );
211
+ framing = [];
212
+ return rows;
145
213
  });
146
214
  }
147
215
 
@@ -206,12 +274,7 @@ type OrientationOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["or
206
274
  /** Assemble the final model-visible code_orientation result for one workflow outcome. */
207
275
  export function finishOrientationResult(outcome: OrientationOutcome): CodeIntelResult {
208
276
  if (outcome.kind === "unavailable") throw new Error(outcome.reason);
209
- if (outcome.kind === "invalid-input") {
210
- return contextErrorResult(`**Error:** ${outcome.message}`, {
211
- nextQueries: ["Choose an existing path, module, or precise target"],
212
- message: outcome.message,
213
- });
214
- }
277
+ if (outcome.kind === "invalid-input") return invalidOrientationResult(outcome);
215
278
  if (outcome.kind === "disambiguation" || outcome.kind === "kind-mismatch") {
216
279
  const candidates = outcome.candidates;
217
280
  const lines = [
@@ -261,6 +324,20 @@ export function finishOrientationResult(outcome: OrientationOutcome): CodeIntelR
261
324
  return finishCompletedOrientation(outcome.data);
262
325
  }
263
326
 
327
+ function invalidOrientationResult(
328
+ outcome: Extract<OrientationOutcome, { kind: "invalid-input" }>,
329
+ ): CodeIntelResult {
330
+ const rejection = outcome.symlinkRejection;
331
+ const recovery = "Resolve the requested path explicitly and retry with its canonical path.";
332
+ const message = rejection
333
+ ? `Requested focus ${JSON.stringify(rejection.requestedPath)} traverses a symbolic link: ${JSON.stringify(rejection.blockedPath)}. Orientation does not follow symbolic links.\n\n${recovery}`
334
+ : outcome.message;
335
+ return contextErrorResult(`**Error:** ${message}`, {
336
+ nextQueries: rejection ? [recovery] : ["Choose an existing path, module, or precise target"],
337
+ message,
338
+ });
339
+ }
340
+
264
341
  function finishCompletedOrientation(data: OrientationResultData): CodeIntelResult {
265
342
  const navigation = data.workspace ? prepareWorkspaceOutput(data) : null;
266
343
  const assembly = assembleOrientationResult(navigation?.data ?? data);
@@ -270,6 +347,7 @@ function finishCompletedOrientation(data: OrientationResultData): CodeIntelResul
270
347
  type: "context",
271
348
  data: assembly.details,
272
349
  budgetWarning: navigation?.warning,
350
+ ...(navigation ? { modelBudgetManaged: true } : {}),
273
351
  status: "completed",
274
352
  displaySections: assembly.displaySections,
275
353
  },
@@ -45,7 +45,7 @@ export function tableSection(
45
45
  rows: string[][];
46
46
  limit: number;
47
47
  detail: string;
48
- source?: "filesystem" | "manifest";
48
+ source?: "filesystem" | "manifest" | "runtime";
49
49
  },
50
50
  ): OrientationSectionData {
51
51
  const { headers, rows, limit, detail, source = "filesystem" } = options;
@@ -66,6 +66,7 @@ export function tableSection(
66
66
  partialReason: null,
67
67
  },
68
68
  ],
69
+ tableEvidenceKey: key,
69
70
  items:
70
71
  rows.length === 0
71
72
  ? [{ kind: "paragraph", text: "No collected entries." }]