@mrclrchtr/supi-code-intelligence 11.2.0 → 11.4.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 (145) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +19 -9
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +2 -1
  5. package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +3 -1
  6. package/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  7. package/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +9 -0
  8. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -5
  9. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  10. package/node_modules/@mrclrchtr/supi-core/src/child-web-tools.ts +110 -0
  11. package/node_modules/@mrclrchtr/supi-core/src/session.ts +11 -0
  12. package/node_modules/@mrclrchtr/supi-lsp/README.md +40 -3
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +2 -1
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +3 -1
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +9 -0
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -5
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/child-web-tools.ts +110 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/session.ts +11 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +2 -2
  23. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +30 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +1 -1
  26. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  27. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-collection.ts +11 -4
  28. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +77 -6
  29. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-input-admission.ts +149 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-typescript-project.ts +40 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +151 -44
  32. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +10 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +2 -2
  34. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +118 -0
  35. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-symbol.ts +157 -23
  36. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +318 -58
  37. package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +87 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +22 -17
  39. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +68 -6
  40. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +1 -0
  41. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +5 -1
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +2 -2
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +2 -1
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +3 -1
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +9 -0
  48. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -5
  49. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/child-web-tools.ts +110 -0
  51. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/session.ts +11 -0
  52. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  53. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
  54. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +9 -1
  55. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
  56. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +9 -1
  57. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +40 -25
  58. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +2 -0
  59. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/call-context.ts +44 -0
  60. package/package.json +6 -5
  61. package/src/analysis/health/server-status.ts +6 -2
  62. package/src/analysis/helpers.ts +0 -7
  63. package/src/analysis/relations/implementations.ts +5 -0
  64. package/src/analysis/relations/references.ts +5 -0
  65. package/src/analysis/search/exclusions.ts +47 -0
  66. package/src/analysis/search/paths.ts +32 -9
  67. package/src/analysis/target/anchored-structural.ts +3 -8
  68. package/src/analysis/target/anchored.ts +4 -20
  69. package/src/analysis/target/file-merge.ts +162 -0
  70. package/src/analysis/target/file-outline-omissions.ts +146 -0
  71. package/src/analysis/target/file-refinement.ts +7 -7
  72. package/src/analysis/target/file.ts +44 -156
  73. package/src/analysis/target/identity.ts +1 -1
  74. package/src/analysis/target/latex-label-container.ts +6 -6
  75. package/src/analysis/target/latex-section-anchor.ts +6 -6
  76. package/src/analysis/target/resolution.ts +18 -0
  77. package/src/analysis/target/symbol.ts +44 -12
  78. package/src/analysis/target/types.ts +38 -7
  79. package/src/api.ts +1 -1
  80. package/src/app/app.ts +9 -3
  81. package/src/extension.ts +17 -11
  82. package/src/session/graph/collect.ts +3 -10
  83. package/src/session/graph-types.ts +5 -1
  84. package/src/session/graph-workflow.ts +6 -4
  85. package/src/session/inspect/collect.ts +8 -2
  86. package/src/session/inspect/file-point.ts +2 -3
  87. package/src/session/inspect-workflow.ts +1 -1
  88. package/src/session/orientation/collect.ts +54 -16
  89. package/src/session/orientation/context-sections.ts +2 -3
  90. package/src/session/orientation/facts.ts +9 -1
  91. package/src/session/orientation/workspace-context.ts +3 -0
  92. package/src/session/orientation-types.ts +3 -0
  93. package/src/session/orientation-workflow.ts +24 -8
  94. package/src/session/refactor-identity.ts +76 -0
  95. package/src/session/refactor-workflow.ts +14 -16
  96. package/src/session/session.ts +87 -12
  97. package/src/session/target-store.ts +3 -18
  98. package/src/session/target-workflow.ts +56 -37
  99. package/src/substrate/lsp/recovery.ts +5 -5
  100. package/src/tool/code_find/render.ts +8 -4
  101. package/src/tool/code_find/result.ts +78 -6
  102. package/src/tool/code_find/spec.ts +4 -3
  103. package/src/tool/code_find/structured.ts +25 -9
  104. package/src/tool/code_graph/details.ts +1 -0
  105. package/src/tool/code_graph/display.ts +1 -1
  106. package/src/tool/code_graph/guidance.ts +1 -1
  107. package/src/tool/code_graph/markdown.ts +11 -6
  108. package/src/tool/code_graph/read-next.ts +38 -9
  109. package/src/tool/code_graph/reference-selection.ts +30 -0
  110. package/src/tool/code_graph/result.ts +25 -118
  111. package/src/tool/code_graph/section.ts +137 -0
  112. package/src/tool/code_graph/spec.ts +3 -3
  113. package/src/tool/code_graph/structured.ts +17 -6
  114. package/src/tool/code_health/display-paths.ts +92 -0
  115. package/src/tool/code_health/file-scope-markdown.ts +3 -2
  116. package/src/tool/code_health/result.ts +4 -2
  117. package/src/tool/code_health/spec.ts +3 -3
  118. package/src/tool/code_health/structured-schema.ts +44 -44
  119. package/src/tool/code_inspect/spec.ts +5 -1
  120. package/src/tool/code_inspect/structured.ts +1 -2
  121. package/src/tool/code_orientation/directory-navigation.ts +20 -31
  122. package/src/tool/code_orientation/execute.ts +1 -1
  123. package/src/tool/code_orientation/result.ts +22 -5
  124. package/src/tool/code_orientation/structured-schema.ts +46 -36
  125. package/src/tool/code_orientation/structured-workspace.ts +2 -1
  126. package/src/tool/code_orientation/structured.ts +6 -12
  127. package/src/tool/code_orientation/workspace-format.ts +2 -5
  128. package/src/tool/code_orientation/workspace-output.ts +40 -13
  129. package/src/tool/code_orientation/workspace-sections.ts +48 -4
  130. package/src/tool/code_refactor_apply/result.ts +1 -1
  131. package/src/tool/code_refactor_plan/result.ts +2 -1
  132. package/src/tool/code_refactor_plan/structured.ts +2 -3
  133. package/src/tool/code_resolve/guidance.ts +1 -1
  134. package/src/tool/code_resolve/markdown.ts +127 -64
  135. package/src/tool/code_resolve/result.ts +41 -25
  136. package/src/tool/code_resolve/structured.ts +49 -18
  137. package/src/tool/result/model-budget.ts +2 -2
  138. package/src/tool/result/refactor.ts +8 -5
  139. package/src/tool/result/structured.ts +8 -5
  140. package/src/tool/result/types.ts +31 -24
  141. package/src/tool/schemas.ts +5 -5
  142. package/src/ui/status-command.ts +37 -1
  143. package/src/ui/status-overlay.ts +70 -51
  144. package/src/ui/status-presentation.ts +108 -0
  145. package/src/ui/tui/common.ts +10 -10
@@ -40,21 +40,9 @@ export function prepareWorkspaceOutput(input: OrientationResultData): {
40
40
  true,
41
41
  );
42
42
  const fullContent = renderOrientationData(full);
43
- let limit = workspace.overview
44
- ? Math.max(10, workspace.observation.projects.length)
45
- : workspace.maxResults;
46
- let descriptions = true;
47
- let data = selectDirectoryNavigation(workspaceSections(input, limit, descriptions));
48
- if (navigationText(data).length > budget.warning * 4) {
49
- descriptions = false;
50
- data = selectDirectoryNavigation(workspaceSections(input, limit, descriptions));
51
- }
52
43
  // Reserve room for the snapshot path and omission notice before reducing rows.
53
44
  const reserved = 1024;
54
- while (exceedsNavigationBudget(data, budget.cap * 4 - reserved) && limit > 0) {
55
- limit = Math.floor(limit / 2);
56
- data = selectDirectoryNavigation(workspaceSections(input, limit, descriptions));
57
- }
45
+ let { data, descriptions } = selectWithinBudget(input, workspace, budget, reserved);
58
46
  const overflow = exceedsNavigationBudget(data, budget.cap * 4 - reserved);
59
47
  if (overflow) {
60
48
  data = {
@@ -111,6 +99,45 @@ export function prepareWorkspaceOutput(input: OrientationResultData): {
111
99
  };
112
100
  }
113
101
 
102
+ /**
103
+ * Shrink one observation's presentation until it fits: drop descriptions, then the uncapped
104
+ * directory file list, then halve every list cap.
105
+ */
106
+ function selectWithinBudget(
107
+ input: OrientationResultData,
108
+ workspace: WorkspaceOrientationFacts,
109
+ budget: { warning: number; cap: number },
110
+ reserved: number,
111
+ ): { data: OrientationResultData; descriptions: boolean } {
112
+ let limit = workspace.overview
113
+ ? Math.max(10, workspace.observation.projects.length)
114
+ : workspace.maxResults;
115
+ // Without an explicit cap, directory focus shows every direct file until the budget forces the default.
116
+ let fileLimit =
117
+ workspace.focus && !workspace.overview && !workspace.maxResultsExplicit
118
+ ? Number.MAX_SAFE_INTEGER
119
+ : limit;
120
+ let descriptions = true;
121
+ const select = () =>
122
+ selectDirectoryNavigation(workspaceSections(input, limit, descriptions, fileLimit));
123
+ let data = select();
124
+ if (navigationText(data).length > budget.warning * 4) {
125
+ descriptions = false;
126
+ data = select();
127
+ }
128
+ const cap = budget.cap * 4 - reserved;
129
+ if (exceedsNavigationBudget(data, cap) && fileLimit > limit) {
130
+ fileLimit = limit;
131
+ data = select();
132
+ }
133
+ while (exceedsNavigationBudget(data, cap) && limit > 0) {
134
+ limit = Math.floor(limit / 2);
135
+ fileLimit = limit;
136
+ data = select();
137
+ }
138
+ return { data, descriptions };
139
+ }
140
+
114
141
  /** Overview links recover omitted navigation; explicit Orientation also retains raw facts. */
115
142
  function needsCapturedResult(
116
143
  workspace: WorkspaceOrientationFacts,
@@ -1,4 +1,5 @@
1
1
  import * as path from "node:path";
2
+ import { toDisplayPath } from "../../analysis/search/paths.ts";
2
3
  import type { InventoryEntry, WorkspaceObservation } from "../../analysis/workspace/types.ts";
3
4
  import {
4
5
  type WorkspaceOrientationFacts,
@@ -13,11 +14,12 @@ import { code, plain, sourcePath, tableSection } from "./workspace-format.ts";
13
14
  import { workspaceCollectionStatus } from "./workspace-observations.ts";
14
15
  import { projectSections } from "./workspace-projects.ts";
15
16
 
16
- /** Build output facts from one captured observation, with no filesystem reads. */
17
+ /** Project one captured observation without collecting new workspace facts. */
17
18
  export function workspaceSections(
18
19
  data: OrientationResultData,
19
20
  limit: number,
20
21
  descriptions: boolean,
22
+ fileLimit = limit,
21
23
  ): OrientationResultData {
22
24
  const facts = data.workspace;
23
25
  if (!facts) return data;
@@ -53,7 +55,7 @@ export function workspaceSections(
53
55
  "Declared descriptions are omitted to preserve names and paths. They remain in the captured result.",
54
56
  );
55
57
  }
56
- const sections = inventorySections(entries, facts, limit);
58
+ const sections = inventorySections(entries, facts, limit, fileLimit);
57
59
  sections.push(...projectSections(facts, limit, descriptions));
58
60
  sections.push(...gradleSections(observation.gradle, limit));
59
61
  const issues = [
@@ -191,6 +193,7 @@ function inventorySections(
191
193
  entries: readonly InventoryEntry[],
192
194
  facts: WorkspaceOrientationFacts,
193
195
  limit: number,
196
+ fileLimit: number,
194
197
  ): OrientationSectionData[] {
195
198
  const { directories, directFiles, extensions } = collectWorkspaceInventory(entries);
196
199
  const sections = [
@@ -204,7 +207,8 @@ function inventorySections(
204
207
  detail: "included paths",
205
208
  }),
206
209
  ];
207
- if (directFiles.length > 0 || !facts.overview)
210
+ if (facts.focus && !facts.overview) sections.push(directFileList(directFiles, fileLimit));
211
+ else if (directFiles.length > 0 || !facts.overview)
208
212
  sections.push(
209
213
  tableSection("workspace.files", "Direct files", {
210
214
  headers: ["Path", "Kind"],
@@ -227,6 +231,46 @@ function inventorySections(
227
231
  return sections;
228
232
  }
229
233
 
234
+ /**
235
+ * Directory focus lists direct files as one compact line instead of a per-row table. Its own
236
+ * `fileLimit` lets presentation show all siblings and shrink them first under the text budget.
237
+ */
238
+ function directFileList(
239
+ directFiles: readonly InventoryEntry[],
240
+ fileLimit: number,
241
+ ): OrientationSectionData {
242
+ const names = directFiles
243
+ .slice(0, fileLimit)
244
+ .map((entry) =>
245
+ entry.kind === "symlink" ? `${code(entry.path)} (symlink)` : code(entry.path),
246
+ );
247
+ return {
248
+ key: "workspace.files",
249
+ title: "Direct files",
250
+ status: "complete",
251
+ reason: null,
252
+ confidence: "unavailable",
253
+ provenance: [{ source: "filesystem", detail: "included paths" }],
254
+ evidenceLists: [
255
+ {
256
+ key: "workspace.files",
257
+ totalCount: directFiles.length,
258
+ shownCount: names.length,
259
+ omittedCount: directFiles.length - names.length,
260
+ partialReason: null,
261
+ },
262
+ ],
263
+ items: [
264
+ {
265
+ kind: "paragraph",
266
+ text: directFiles.length
267
+ ? names.join(", ") || "No entries shown."
268
+ : "No collected entries.",
269
+ },
270
+ ],
271
+ };
272
+ }
273
+
230
274
  export function display(cwd: string, target: string): string {
231
- return path.relative(cwd, target).replaceAll(path.sep, "/") || ".";
275
+ return toDisplayPath(cwd, target);
232
276
  }
@@ -24,7 +24,7 @@ export function finishRefactorApplyResult(
24
24
  };
25
25
  }
26
26
 
27
- const assembly = assembleRefactorApplyDetails(outcome.result, outcome.plan);
27
+ const assembly = assembleRefactorApplyDetails(outcome.result, outcome.plan, cwd);
28
28
  return {
29
29
  content: renderRefactorApplyResult(assembly),
30
30
  structuredContent: structuredRefactorApply(outcome, cwd),
@@ -1,5 +1,6 @@
1
1
  /** Result assembly for code_refactor_plan. */
2
2
 
3
+ import { toDisplayPath } from "../../analysis/search/paths.ts";
3
4
  import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
4
5
  import { renderRefactorPlanResult } from "../refactor-markdown.ts";
5
6
  import { searchErrorResult } from "../result/errors.ts";
@@ -27,7 +28,7 @@ export function finishRefactorPlanResult(
27
28
  const candidates = outcome.candidates
28
29
  .map(
29
30
  (candidate, index) =>
30
- `${index + 1}. ${candidate.description} (${candidate.file}:${candidate.line})`,
31
+ `${index + 1}. ${candidate.description} (${candidate.file === undefined ? candidate.file : toDisplayPath(cwd, candidate.file)}:${candidate.line})`,
31
32
  )
32
33
  .join("\n");
33
34
  return {
@@ -1,4 +1,3 @@
1
- import { StringEnum } from "@earendil-works/pi-ai";
2
1
  import { type Static, Type } from "typebox";
3
2
  import { toDisplayPath } from "../../analysis/search/paths.ts";
4
3
  import {
@@ -44,7 +43,7 @@ export const RefactorPlanOutputSchema = Type.Union([
44
43
  {
45
44
  kind: Type.Literal("completed"),
46
45
  planId: Type.String(),
47
- operation: StringEnum([...PUBLIC_REFACTOR_OPERATION_NAMES]),
46
+ operation: Type.Enum([...PUBLIC_REFACTOR_OPERATION_NAMES], { type: "string" }),
48
47
  target: Type.Object(
49
48
  { file: Type.String(), line: Type.Integer(), character: Type.Integer() },
50
49
  { additionalProperties: false, description: "One-based line and UTF-16 character." },
@@ -54,7 +53,7 @@ export const RefactorPlanOutputSchema = Type.Union([
54
53
  edits: Type.Array(Edit),
55
54
  fileCount: Type.Integer({ minimum: 0 }),
56
55
  editCount: Type.Integer({ minimum: 0 }),
57
- provenance: StringEnum(["semantic", "structural"]),
56
+ provenance: Type.Enum(["semantic", "structural"], { type: "string" }),
58
57
  nextAction: Type.Object(
59
58
  { tool: Type.Literal("code_refactor_apply"), planId: Type.String() },
60
59
  { additionalProperties: false },
@@ -1,5 +1,5 @@
1
1
  export const toolDescription =
2
- "Resolve a real symbol anchor or semantic query to target handles for later code tools, or list a file's declarations as a target group. This tool does not search file text.";
2
+ "Resolve a real symbol anchor or semantic query to target handles for later code tools, or list a file's declarations as a file outline. This tool does not search file text.";
3
3
 
4
4
  export const promptSnippet = "resolve symbols or file declarations";
5
5
 
@@ -1,8 +1,9 @@
1
1
  /** Markdown adapter for assembled code_resolve outcomes. */
2
2
 
3
- import { relative } from "node:path";
4
3
  import { renderEvidenceListMetadataDisclosure } from "../../analysis/evidence.ts";
5
- import type { TargetStoreEntry } from "../../session/target-store.ts";
4
+ import { toDisplayPath } from "../../analysis/search/paths.ts";
5
+ import type { TargetProviderProvenance } from "../../session/target-store.ts";
6
+ import type { TargetWorkflowOutcome } from "../../session/target-workflow.ts";
6
7
  import { formatPartialCandidateDisclosure } from "../result/candidate-row.ts";
7
8
  import type { ResolveDetails } from "../result/types.ts";
8
9
  import type { ResolveResultAssembly } from "./result.ts";
@@ -12,9 +13,9 @@ export function renderResolveResult(assembly: ResolveResultAssembly): string {
12
13
  const { outcome, cwd } = assembly;
13
14
  switch (outcome.kind) {
14
15
  case "resolved":
15
- return renderResolved(outcome.entry, outcome.notes, cwd);
16
- case "target-group":
17
- return renderTargetGroup(assembly.details);
16
+ return renderResolved(outcome, cwd);
17
+ case "file-outline":
18
+ return renderFileOutline(assembly.details);
18
19
  case "disambiguation":
19
20
  return renderDisambiguation(assembly.details);
20
21
  case "kind-mismatch":
@@ -27,11 +28,11 @@ export function renderResolveResult(assembly: ResolveResultAssembly): string {
27
28
  }
28
29
 
29
30
  function renderResolved(
30
- target: Readonly<TargetStoreEntry>,
31
- notes: readonly string[],
31
+ outcome: Extract<TargetWorkflowOutcome, { kind: "resolved" }>,
32
32
  cwd: string,
33
33
  ): string {
34
- const relFile = relative(cwd, target.file) || target.file;
34
+ const { entry: target, notes } = outcome;
35
+ const relFile = toDisplayPath(cwd, target.file);
35
36
  const displayKind = target.nativeKind ?? target.kind;
36
37
  const kind = displayKind ? ` \`${displayKind}\`` : "";
37
38
  const name = target.name ? ` **${target.name}**${kind}` : "";
@@ -41,93 +42,155 @@ function renderResolved(
41
42
  `confidence: ${target.confidence}; provenance: ${target.provenance.join("+")}`,
42
43
  ];
43
44
 
44
- const resolutionNote = renderAnchoredResolutionNote(target);
45
- if (resolutionNote) lines.push("", resolutionNote);
46
45
  for (const note of notes) {
47
- if (resolutionNote && isResolutionMetadataNote(note)) continue;
48
46
  lines.push("", `_Note: ${note}_`);
49
47
  }
50
48
  return lines.join("\n");
51
49
  }
52
50
 
53
- function isResolutionMetadataNote(note: string): boolean {
54
- return (
55
- note.startsWith("Resolved from a declaration header and snapped to the identifier") ||
56
- note === "Resolved from provider-backed structural identifier evidence."
57
- );
58
- }
59
-
60
- function renderTargetGroup(details: ResolveDetails): string {
61
- const discovery = details.groupDiscoveryProvenance?.join("+") || "unavailable";
62
- const lines = [
63
- `# Targets in \`${details.groupFile ?? "file"}\``,
64
- "",
65
- `- Group confidence: \`${details.confidence}\``,
66
- `- Discovery provenance: \`${discovery}\``,
67
- ];
68
- appendUnknownHierarchyDisclosure(lines, details.groupUnknownNestingCount ?? 0);
69
- appendGroupRecoveryDisclosure(lines, details);
51
+ function renderFileOutline(details: ResolveDetails): string {
52
+ const lines = [`# File outline of \`${details.outlineFile ?? "file"}\``, ""];
53
+ lines.push(`- Sources: ${outlineSources(details.outlineDiscoveryProvenance ?? [])}`);
54
+ appendUnknownLevelDisclosure(lines, details.outlineUnknownLevelCount ?? 0);
55
+ appendOutlineRecoveryDisclosure(lines, details);
70
56
  lines.push("");
71
- appendTargetGroupItems(lines, details);
57
+ appendFileOutlineItems(lines, details);
72
58
  appendDisclosure(lines, details);
59
+ appendNotListed(lines, details);
73
60
  return lines.join("\n");
74
61
  }
75
62
 
76
- function appendTargetGroupItems(lines: string[], details: ResolveDetails): void {
63
+ const SOURCE_NAMES: Record<TargetProviderProvenance, string> = {
64
+ semantic: "language server",
65
+ structural: "syntax parser",
66
+ };
67
+
68
+ function outlineSources(provenance: readonly TargetProviderProvenance[]): string {
69
+ return provenance.length
70
+ ? provenance.map((source) => SOURCE_NAMES[source]).join(" and ")
71
+ : "none";
72
+ }
73
+
74
+ function appendFileOutlineItems(lines: string[], details: ResolveDetails): void {
77
75
  if (details.targets.length === 0) {
78
76
  lines.push(
79
- details.groupPartialReason
77
+ details.outlinePartialReason
80
78
  ? "No declarations were collected before structural recovery limited discovery."
81
79
  : "No declarations were reported for this file.",
82
80
  );
83
81
  return;
84
82
  }
85
- lines.push(declarationCountHeading(details.targetCount), "");
86
- for (const target of details.targets) {
87
- const displayKind = target.nativeKind ?? target.kind;
88
- const kind = displayKind ? ` (\`${displayKind}\`)` : "";
89
- const container = target.container ? ` in \`${target.container}\`` : "";
90
- lines.push(
91
- `- \`${target.targetId}\` **${target.name ?? "anonymous"}**${kind}${container} — \`${target.displayLine}:${target.displayCharacter}\` (${target.anchorKind} anchor, ${target.confidence}, provenance: ${target.provenance.join("+")})`,
92
- );
83
+ const count = details.targetCount;
84
+ lines.push(
85
+ `${count} declaration${count === 1 ? "" : "s"}: top-level declarations in source order, members indented below their container. Pass a handle as target.handle to code_graph, code_inspect, or code_refactor_plan.`,
86
+ "",
87
+ );
88
+ appendGroupedRows(lines, details.targets);
89
+ }
90
+
91
+ type OutlineRowTarget = ResolveDetails["targets"][number];
92
+
93
+ /**
94
+ * Render each visible member directly below its visible container, so the
95
+ * container name is not repeated per row. Members whose container is not a
96
+ * uniquely named visible row keep an explicit `in` suffix.
97
+ */
98
+ function appendGroupedRows(lines: string[], targets: readonly OutlineRowTarget[]): void {
99
+ const containerCounts = new Map<string, number>();
100
+ for (const target of targets) {
101
+ if (target.name) containerCounts.set(target.name, (containerCounts.get(target.name) ?? 0) + 1);
93
102
  }
103
+ const children = new Map<string, OutlineRowTarget[]>();
104
+ const roots: OutlineRowTarget[] = [];
105
+ for (const target of targets) {
106
+ const container = target.container;
107
+ if (container && container !== target.name && containerCounts.get(container) === 1) {
108
+ children.set(container, [...(children.get(container) ?? []), target]);
109
+ } else {
110
+ roots.push(target);
111
+ }
112
+ }
113
+ const emit = (target: OutlineRowTarget, depth: number): void => {
114
+ lines.push(outlineRow(target, depth));
115
+ const own = target.name ? children.get(target.name) : undefined;
116
+ if (!own) return;
117
+ children.delete(target.name ?? "");
118
+ for (const child of own) emit(child, depth + 1);
119
+ };
120
+ for (const root of roots) emit(root, 0);
121
+ // Containers that are themselves grouped under a hidden row fall back to suffixes.
122
+ for (const orphans of children.values()) for (const orphan of orphans) emit(orphan, 0);
123
+ }
124
+
125
+ /** One compact row; evidence notes appear only when they differ from the usual case. */
126
+ function outlineRow(target: OutlineRowTarget, depth: number): string {
127
+ const displayKind = outlineKind(target.nativeKind ?? target.kind);
128
+ const kind = displayKind ? `${displayKind} ` : "";
129
+ const container = depth === 0 && target.container ? ` in \`${target.container}\`` : "";
130
+ const indent = " ".repeat(depth);
131
+ const suffix = target.provenance.includes("semantic") ? "" : " (syntax parser only)";
132
+ const name = (target.name ?? "anonymous").replace(/\s+/g, " ");
133
+ return `${indent}- \`${target.targetId}\` ${kind}\`${name}\`${container} — L${target.displayLine}:${target.displayCharacter}${suffix}`;
134
+ }
135
+
136
+ /** Lower-case words for both providers' kinds, e.g. `EnumMember` -> `enum member`. */
137
+ function outlineKind(kind: string | null | undefined): string {
138
+ return (kind ?? "").replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase();
139
+ }
140
+
141
+ function appendNotListed(lines: string[], details: ResolveDetails): void {
142
+ const notListed = details.outlineNotListed;
143
+ if (!notListed) return;
144
+ const span = (value: { startLine: number; endLine: number }) =>
145
+ value.startLine === value.endLine
146
+ ? `L${value.startLine}`
147
+ : `L${value.startLine}–L${value.endLine}`;
148
+ const rows = [
149
+ ...(notListed.importedNames
150
+ ? [
151
+ `- ${plural(notListed.importedNames.count, "imported name")} (${span(notListed.importedNames)}). Read those lines, or resolve a name with code_resolve target.symbol.`,
152
+ ]
153
+ : []),
154
+ ...(notListed.reExportStatements
155
+ ? [
156
+ `- ${plural(notListed.reExportStatements.count, "`export … from` statement")} (${span(notListed.reExportStatements)}); they forward names declared in other modules.`,
157
+ ]
158
+ : []),
159
+ ...(notListed.exportListNames
160
+ ? [
161
+ `- ${plural(notListed.exportListNames.count, "name")} in export lists (${span(notListed.exportListNames)}). Read those lines, or find them with code_find mode "ast", kind "export", a name fragment as query, and scope set to this file.`,
162
+ ]
163
+ : []),
164
+ ...(notListed.localDeclarations > 0
165
+ ? [
166
+ `- ${plural(notListed.localDeclarations, "declaration")} inside function, method, or constructor bodies. Resolve one with code_resolve target.symbol and scope set to this file.`,
167
+ ]
168
+ : []),
169
+ ];
170
+ if (rows.length) lines.push("", "Not listed:", ...rows);
94
171
  }
95
172
 
96
- function appendGroupRecoveryDisclosure(lines: string[], details: ResolveDetails): void {
97
- if (!details.groupPartialReason) return;
98
- const locations = (details.groupErrorRanges ?? []).map(
173
+ function plural(count: number, noun: string): string {
174
+ return `${count} ${noun}${count === 1 ? "" : "s"}`;
175
+ }
176
+
177
+ function appendOutlineRecoveryDisclosure(lines: string[], details: ResolveDetails): void {
178
+ if (!details.outlinePartialReason) return;
179
+ const locations = (details.outlineErrorRanges ?? []).map(
99
180
  (range) => `L${range.start.line + 1}:${range.start.character + 1}`,
100
181
  );
101
182
  const errors = locations.length ? ` Error locations: ${locations.join(", ")}.` : "";
102
- lines.push(`- Partial discovery: ${details.groupPartialReason}${errors}`);
103
- }
104
-
105
- function declarationCountHeading(count: number): string {
106
- return `**${count} declaration${count === 1 ? "" : "s"} discovered**`;
183
+ lines.push(`- Partial discovery: ${details.outlinePartialReason}${errors}`);
107
184
  }
108
185
 
109
- function appendUnknownHierarchyDisclosure(lines: string[], count: number): void {
186
+ function appendUnknownLevelDisclosure(lines: string[], count: number): void {
110
187
  if (count <= 0) return;
111
- const declaration = count === 1 ? "declaration has" : "declarations have";
188
+ const declarations = count === 1 ? "declaration has" : "declarations have";
112
189
  lines.push(
113
- `- Hierarchy: ${count} ${declaration} unknown hierarchy; only provider-proven top-level declarations were prioritized.`,
190
+ `- Position unknown: ${count} ${declarations} no enclosing declaration reported by the language server, so ${count === 1 ? "it is" : "they are"} listed after the top-level declarations.`,
114
191
  );
115
192
  }
116
193
 
117
- function renderAnchoredResolutionNote(target: Readonly<TargetStoreEntry>): string | null {
118
- const resolution = target.resolution;
119
- if (!resolution) return null;
120
- const degraded = resolution.source !== "semantic";
121
- if (!resolution.snapped && !degraded) return null;
122
-
123
- const requested = `${resolution.requested.line}:${resolution.requested.character}`;
124
- const resolved = `${resolution.resolved.line}:${resolution.resolved.character}`;
125
- if (resolution.snapped) {
126
- return `_Note: snapped from requested coordinate ${requested} to name anchor ${resolved} (evidence: ${resolution.source})._`;
127
- }
128
- return `_Note: resolved from ${resolution.source} evidence; use code_inspect for point-level facts._`;
129
- }
130
-
131
194
  function renderDisambiguation(details: ResolveDetails): string {
132
195
  const lines = [
133
196
  "# Multiple matches found",
@@ -1,7 +1,7 @@
1
- import { relative } from "node:path";
2
1
  import type { ConfidenceMode } from "@mrclrchtr/supi-code-runtime/api";
3
2
  import type { EvidenceListMetadata } from "../../analysis/evidence.ts";
4
3
  import { createEvidenceList } from "../../analysis/evidence.ts";
4
+ import { toDisplayPath } from "../../analysis/search/paths.ts";
5
5
  import type { ResolveTargetInput } from "../../session/target-input.ts";
6
6
  import type { TargetStoreEntry } from "../../session/target-store.ts";
7
7
  import type { TargetWorkflowOutcome } from "../../session/target-workflow.ts";
@@ -14,7 +14,11 @@ import {
14
14
  import { formatCandidateRow } from "../result/candidate-row.ts";
15
15
  import { createToolDisplaySection } from "../result/display.ts";
16
16
  import { scopedSymbolFailureMessage } from "../result/errors.ts";
17
- import type { ResolveDetails, ToolDisplaySection } from "../result/types.ts";
17
+ import type {
18
+ AnchoredResolutionMetadata,
19
+ ResolveDetails,
20
+ ToolDisplaySection,
21
+ } from "../result/types.ts";
18
22
 
19
23
  /** Presentation-neutral assembled code_resolve result. */
20
24
  export interface ResolveResultAssembly {
@@ -80,19 +84,23 @@ export function assembleResolveResult(
80
84
  function projectResolveOutcome(outcome: TargetWorkflowOutcome, cwd: string): ResolveProjection {
81
85
  switch (outcome.kind) {
82
86
  case "resolved":
83
- return projectResolved(outcome.entry, cwd);
84
- case "target-group":
85
- return projectTargetGroup(outcome, cwd);
87
+ return projectResolved(outcome, cwd);
88
+ case "file-outline":
89
+ return projectFileOutline(outcome, cwd);
86
90
  case "disambiguation":
87
91
  case "kind-mismatch":
88
- return projectCandidateOutcome(outcome);
92
+ return projectCandidateOutcome(outcome, cwd);
89
93
  case "invalid-input":
90
94
  case "unavailable":
91
95
  return projectFailure(outcome);
92
96
  }
93
97
  }
94
98
 
95
- function projectResolved(target: Readonly<TargetStoreEntry>, cwd: string): ResolveProjection {
99
+ function projectResolved(
100
+ outcome: Extract<TargetWorkflowOutcome, { kind: "resolved" }>,
101
+ cwd: string,
102
+ ): ResolveProjection {
103
+ const { entry: target, resolution } = outcome;
96
104
  const evidence = createEvidenceList({ key: "resolve.targets", items: [target] }).metadata;
97
105
  return {
98
106
  key: "resolve.targets",
@@ -107,14 +115,14 @@ function projectResolved(target: Readonly<TargetStoreEntry>, cwd: string): Resol
107
115
  targetCount: 1,
108
116
  omittedCount: 0,
109
117
  evidenceLists: [evidence],
110
- targets: [toTargetDetails(target, cwd)],
118
+ targets: [toTargetDetails(target, cwd, resolution)],
111
119
  nextQueries: [],
112
120
  },
113
121
  };
114
122
  }
115
123
 
116
- function projectTargetGroup(
117
- outcome: Extract<TargetWorkflowOutcome, { kind: "target-group" }>,
124
+ function projectFileOutline(
125
+ outcome: Extract<TargetWorkflowOutcome, { kind: "file-outline" }>,
118
126
  cwd: string,
119
127
  ): ResolveProjection {
120
128
  const evidence = {
@@ -130,19 +138,20 @@ function projectTargetGroup(
130
138
  },
131
139
  };
132
140
  return {
133
- key: "resolve.target-group",
134
- title: "Target group",
141
+ key: "resolve.file-outline",
142
+ title: "File outline",
135
143
  status: outcome.partial ? "partial" : "complete",
136
144
  items: evidence.items,
137
145
  confidence: outcome.confidence,
138
146
  evidence: evidence.metadata,
139
147
  details: {
140
- resultKind: "target-group",
141
- groupFile: relative(cwd, outcome.file) || outcome.file,
142
- groupDiscoveryProvenance: [...outcome.discoveryProvenance],
143
- groupUnknownNestingCount: outcome.unknownNestingCount,
144
- groupPartialReason: outcome.partial?.reason ?? null,
145
- groupErrorRanges: outcome.partial?.errorRanges,
148
+ resultKind: "file-outline",
149
+ outlineFile: toDisplayPath(cwd, outcome.file),
150
+ outlineDiscoveryProvenance: [...outcome.discoveryProvenance],
151
+ outlineUnknownLevelCount: outcome.unknownLevelCount,
152
+ outlinePartialReason: outcome.partial?.reason ?? null,
153
+ outlineErrorRanges: outcome.partial?.errorRanges,
154
+ outlineNotListed: outcome.notListed,
146
155
  confidence: outcome.confidence,
147
156
  targetCount: outcome.totalCount,
148
157
  omittedCount: evidence.metadata.omittedCount,
@@ -150,7 +159,9 @@ function projectTargetGroup(
150
159
  targets: evidence.items.map((target) => toTargetDetails(target, cwd)),
151
160
  nextQueries:
152
161
  outcome.totalCount > 0
153
- ? ["Choose one Target group member handle for precise graph or refactor work"]
162
+ ? [
163
+ "Pass one declaration handle from the file outline as target.handle to code_graph, code_inspect, or code_refactor_plan",
164
+ ]
154
165
  : ["Use code_inspect for point facts or code_find for explicit source evidence"],
155
166
  },
156
167
  };
@@ -158,6 +169,7 @@ function projectTargetGroup(
158
169
 
159
170
  function projectCandidateOutcome(
160
171
  outcome: Extract<TargetWorkflowOutcome, { kind: "disambiguation" | "kind-mismatch" }>,
172
+ cwd: string,
161
173
  ): ResolveProjection {
162
174
  const evidence: EvidenceListMetadata = {
163
175
  key: "resolve.candidates",
@@ -189,7 +201,7 @@ function projectCandidateOutcome(
189
201
  name: candidate.name,
190
202
  kind: candidate.kind,
191
203
  container: candidate.container,
192
- file: candidate.file,
204
+ file: toDisplayPath(cwd, candidate.file),
193
205
  line: candidate.line,
194
206
  character: candidate.character,
195
207
  rank: candidate.rank,
@@ -228,11 +240,15 @@ function projectFailure(
228
240
  };
229
241
  }
230
242
 
231
- function toTargetDetails(target: Readonly<TargetStoreEntry>, cwd: string) {
243
+ function toTargetDetails(
244
+ target: Readonly<TargetStoreEntry>,
245
+ cwd: string,
246
+ resolution?: AnchoredResolutionMetadata,
247
+ ) {
232
248
  return {
233
249
  targetId: target.targetId,
234
250
  spanId: target.spanId,
235
- file: relative(cwd, target.file) || target.file,
251
+ file: toDisplayPath(cwd, target.file),
236
252
  displayLine: target.displayLine,
237
253
  displayCharacter: target.displayCharacter,
238
254
  name: target.name,
@@ -242,7 +258,7 @@ function toTargetDetails(target: Readonly<TargetStoreEntry>, cwd: string) {
242
258
  anchorKind: target.anchorKind,
243
259
  confidence: target.confidence,
244
260
  provenance: [...target.provenance],
245
- resolution: target.resolution,
261
+ ...(resolution ? { resolution } : {}),
246
262
  };
247
263
  }
248
264
 
@@ -285,7 +301,7 @@ function resolveProvenance(outcome: TargetWorkflowOutcome): ResultProvenance[] {
285
301
  const sources = new Set<"semantic" | "structural">();
286
302
  if (outcome.kind === "resolved") {
287
303
  for (const source of outcome.entry.provenance) sources.add(source);
288
- } else if (outcome.kind === "target-group") {
304
+ } else if (outcome.kind === "file-outline") {
289
305
  for (const source of outcome.discoveryProvenance) sources.add(source);
290
306
  } else if (outcome.kind === "disambiguation" || outcome.kind === "kind-mismatch") {
291
307
  sources.add("semantic");
@@ -330,7 +346,7 @@ export function finishResolveResult(
330
346
  type: "resolve",
331
347
  data: assembly.details,
332
348
  status:
333
- outcome.kind === "resolved" || outcome.kind === "target-group"
349
+ outcome.kind === "resolved" || outcome.kind === "file-outline"
334
350
  ? "completed"
335
351
  : outcome.kind === "disambiguation" || outcome.kind === "kind-mismatch"
336
352
  ? "disambiguation"