@mrclrchtr/supi-code-intelligence 13.0.0 → 14.0.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 (78) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +3 -3
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +10 -0
  5. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  6. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +59 -13
  7. package/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +41 -9
  8. package/node_modules/@mrclrchtr/supi-core/src/session.ts +2 -0
  9. package/node_modules/@mrclrchtr/supi-core/src/side-run.ts +46 -0
  10. package/node_modules/@mrclrchtr/supi-core/src/spill.ts +2 -2
  11. package/node_modules/@mrclrchtr/supi-lsp/README.md +6 -2
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +10 -0
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +59 -13
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +41 -9
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/session.ts +2 -0
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/side-run.ts +46 -0
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/spill.ts +2 -2
  20. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  21. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-refresh.ts +5 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-request.ts +3 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-timing.ts +14 -1
  24. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-typescript.ts +8 -1
  25. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +4 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-input-admission.ts +7 -1
  27. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +1 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/src/client/transport.ts +24 -8
  29. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +5 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +3 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/src/debug-telemetry.ts +64 -0
  32. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-project-info.ts +3 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +27 -2
  34. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-symbol.ts +16 -112
  35. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +521 -83
  36. package/node_modules/@mrclrchtr/supi-lsp/src/manager/workspace-symbol-collection.ts +163 -0
  37. package/node_modules/@mrclrchtr/supi-lsp/src/manager/workspace-symbol-row-limit.ts +72 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +11 -0
  39. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +36 -7
  40. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  41. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +10 -0
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +59 -13
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +41 -9
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/session.ts +2 -0
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/side-run.ts +46 -0
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/spill.ts +2 -2
  48. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  49. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/sql/tree-sitter-sql.wasm +0 -0
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/sql/tree-sitter-sql.wasm.json +2 -2
  51. package/package.json +5 -5
  52. package/src/analysis/health/server-status.ts +32 -9
  53. package/src/analysis/health/signals.ts +1 -0
  54. package/src/analysis/instruction-files.ts +11 -7
  55. package/src/analysis/search/exclusions.ts +18 -4
  56. package/src/analysis/target/file-outline-omissions.ts +17 -2
  57. package/src/analysis/target/symbol-selection.ts +100 -0
  58. package/src/analysis/target/symbol.ts +48 -8
  59. package/src/analysis/target/types.ts +8 -1
  60. package/src/app/app.ts +37 -21
  61. package/src/extension.ts +1 -2
  62. package/src/headless.ts +4 -2
  63. package/src/session/health-types.ts +2 -0
  64. package/src/session/orientation-types.ts +5 -0
  65. package/src/session/orientation-workflow.ts +13 -3
  66. package/src/session/target-workflow.ts +18 -12
  67. package/src/tool/code_find/render.ts +10 -11
  68. package/src/tool/code_find/result.ts +6 -1
  69. package/src/tool/code_graph/structured.ts +3 -0
  70. package/src/tool/code_health/markdown.ts +3 -1
  71. package/src/tool/code_health/structured-schema.ts +1 -0
  72. package/src/tool/code_health/structured.ts +2 -0
  73. package/src/tool/code_orientation/markdown.ts +6 -1
  74. package/src/tool/code_resolve/result.ts +2 -1
  75. package/src/tool/code_resolve/structured.ts +6 -1
  76. package/src/tool/result/candidate-selection.ts +17 -1
  77. package/src/ui/footer.ts +147 -42
  78. package/src/ui/status-overlay.ts +13 -8
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "source": {
3
3
  "npmPackage": "@derekstride/tree-sitter-sql",
4
- "version": "0.3.11",
4
+ "version": "0.3.13",
5
5
  "repository": "https://github.com/derekstride/tree-sitter-sql"
6
6
  },
7
7
  "generatedWith": {
8
8
  "treeSitterCli": "0.27.2"
9
9
  },
10
- "sha256": "e03fb5079e88cfe0807056c284fd2b0589cee35df9bbb3d07e72f2f4178de8de",
10
+ "sha256": "3c7acad1cda9d565e6884e1d058a5b141c7b6b2983a3b2e4fb0f2ea2efe36ad8",
11
11
  "trust": {
12
12
  "note": "The @derekstride/tree-sitter-sql npm package is a devDependency only. It is never resolved at runtime; the vendored WASM above is the sole runtime artifact. This workspace explicitly disables the package's npx-based install script via pnpm allowBuilds. The WASM was built locally from the installed package source. See scripts/generate-sql-wasm.mjs for the rebuild procedure.",
13
13
  "alternativesConsidered": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-code-intelligence",
3
- "version": "13.0.0",
3
+ "version": "14.0.0",
4
4
  "description": "LSP and AST navigation, search, diagnostics, and refactoring",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -44,10 +44,10 @@
44
44
  "ignore": "7.0.14",
45
45
  "smol-toml": "1.9.1",
46
46
  "yaml": "2.9.1",
47
- "@mrclrchtr/supi-code-runtime": "13.0.0",
48
- "@mrclrchtr/supi-lsp": "13.0.0",
49
- "@mrclrchtr/supi-tree-sitter": "13.0.0",
50
- "@mrclrchtr/supi-core": "13.0.0"
47
+ "@mrclrchtr/supi-code-runtime": "14.0.0",
48
+ "@mrclrchtr/supi-core": "14.0.0",
49
+ "@mrclrchtr/supi-lsp": "14.0.0",
50
+ "@mrclrchtr/supi-tree-sitter": "14.0.0"
51
51
  },
52
52
  "bundledDependencies": [
53
53
  "@mrclrchtr/supi-code-runtime",
@@ -5,6 +5,31 @@ import type {
5
5
  ServerOperationSupportMap,
6
6
  } from "@mrclrchtr/supi-lsp/api";
7
7
 
8
+ /**
9
+ * Display state of one LSP route.
10
+ *
11
+ * `loading` means the route answers queries while the background warm-up still
12
+ * loads its projects; symbol queries wait for that pass.
13
+ */
14
+ export type ProjectServerRouteState =
15
+ | "ready"
16
+ | "starting"
17
+ | "loading"
18
+ | "recovering"
19
+ | "error"
20
+ | "unavailable";
21
+
22
+ /** Classify one route for status surfaces without changing semantic readiness. */
23
+ export function classifyProjectServerRoute(
24
+ server: Pick<ProjectServerInfo, "status" | "statusReason" | "ready" | "loadingProjects">,
25
+ ): ProjectServerRouteState {
26
+ if (server.statusReason === "process-crash-recovery-pending") return "recovering";
27
+ if (server.status === "error") return "error";
28
+ if (server.status === "unavailable") return "unavailable";
29
+ if (!server.ready) return "starting";
30
+ return server.loadingProjects ? "loading" : "ready";
31
+ }
32
+
8
33
  /** Workspace-wide counts for non-running LSP routes. */
9
34
  export interface ProjectServerRouteStatusCounts {
10
35
  recovering: number;
@@ -16,15 +41,13 @@ export interface ProjectServerRouteStatusCounts {
16
41
  export function countProjectServerRouteStatuses(
17
42
  servers: readonly Pick<ProjectServerInfo, "status" | "statusReason">[],
18
43
  ): ProjectServerRouteStatusCounts {
19
- return {
20
- recovering: servers.filter((server) => server.statusReason === "process-crash-recovery-pending")
21
- .length,
22
- error: servers.filter(
23
- (server) =>
24
- server.status === "error" && server.statusReason !== "process-crash-recovery-pending",
25
- ).length,
26
- unavailable: servers.filter((server) => server.status === "unavailable").length,
27
- };
44
+ const counts = { recovering: 0, error: 0, unavailable: 0 };
45
+ for (const server of servers) {
46
+ // `ready` does not affect these three states.
47
+ const state = classifyProjectServerRoute({ ...server, ready: false });
48
+ if (state === "recovering" || state === "error" || state === "unavailable") counts[state]++;
49
+ }
50
+ return counts;
28
51
  }
29
52
 
30
53
  /** Render nonzero workspace route counts for an aggregate status surface. */
@@ -19,6 +19,7 @@ export function collectServers(
19
19
  ...(server.typescript ? { typescript: server.typescript } : {}),
20
20
  ...(server.failureMessage ? { failureMessage: server.failureMessage } : {}),
21
21
  ready: server.ready,
22
+ ...(server.loadingProjects ? { loadingProjects: true as const } : {}),
22
23
  ...(server.operationSupport ? { operationSupport: server.operationSupport } : {}),
23
24
  }));
24
25
  }
@@ -57,6 +57,9 @@ export function isValidInstructionFileName(name: unknown): name is string {
57
57
  * When the project is not trusted, all project-configured instruction files
58
58
  * are rejected so a repository-authored path cannot cause reads outside the
59
59
  * workspace root.
60
+ *
61
+ * `known` lists files the session already has (loaded natively, read in full, or
62
+ * delivered by an earlier orientation), so callers can say why they are not repeated.
60
63
  */
61
64
  export function findInstructionFilesForDirectory(options: {
62
65
  directory: string;
@@ -66,7 +69,7 @@ export function findInstructionFilesForDirectory(options: {
66
69
  surfacedDirectories: Set<string>;
67
70
  /** Whether project-local configuration is trusted. */
68
71
  projectTrusted: boolean;
69
- }): InstructionFileMatch[] {
72
+ }): { matches: InstructionFileMatch[]; known: InstructionFileMatch[] } {
70
73
  const cwd = path.resolve(options.cwd);
71
74
  const directory = path.resolve(options.directory);
72
75
 
@@ -74,21 +77,22 @@ export function findInstructionFilesForDirectory(options: {
74
77
  options.projectTrusted && Array.isArray(options.fileNames)
75
78
  ? options.fileNames.filter(isValidInstructionFileName)
76
79
  : [];
77
- if (validNames.length === 0) return [];
78
- if (!isDirectoryWithinCwd(directory, cwd)) return [];
80
+ if (validNames.length === 0) return { matches: [], known: [] };
81
+ if (!isDirectoryWithinCwd(directory, cwd)) return { matches: [], known: [] };
79
82
 
80
83
  const dirs = collectDirsShallowestFirst(directory, cwd);
81
84
  const matches: InstructionFileMatch[] = [];
85
+ const known: InstructionFileMatch[] = [];
82
86
 
83
87
  for (const dir of dirs) {
84
- if (options.surfacedDirectories.has(dir)) continue;
85
88
  const match = findFirstInstructionFile(dir, cwd, validNames);
86
89
  if (!match) continue;
87
- if (options.nativeContextPaths.has(match.absolutePath)) continue;
88
- matches.push(match);
90
+ const seen =
91
+ options.surfacedDirectories.has(dir) || options.nativeContextPaths.has(match.absolutePath);
92
+ (seen ? known : matches).push(match);
89
93
  }
90
94
 
91
- return matches;
95
+ return { matches, known };
92
96
  }
93
97
 
94
98
  function isDirectoryWithinCwd(directory: string, cwd: string): boolean {
@@ -28,11 +28,26 @@ export function displayAutomaticPathExclusion(
28
28
  : undefined;
29
29
  }
30
30
 
31
- /** Explain which observed path was excluded even when a matching canonical source was retained. */
31
+ /** Examples named in prose; structured output keeps every collected example. */
32
+ const MAX_PROSE_EXAMPLES = 2;
33
+
34
+ /**
35
+ * Explain which observed path was excluded even when a matching canonical source was retained.
36
+ * A path that is already canonical is named once.
37
+ */
32
38
  export function describeExcludedPath(
33
39
  example: AutomaticPathExclusionDisplay["examples"][number],
34
40
  ): string {
35
- return `observed \`${example.observedPath}\` → canonical \`${example.canonicalPath}\``;
41
+ return example.observedPath === example.canonicalPath
42
+ ? `\`${example.canonicalPath}\``
43
+ : `observed \`${example.observedPath}\` → canonical \`${example.canonicalPath}\``;
44
+ }
45
+
46
+ /** Render the bounded ` Excluded path examples: …` suffix, or an empty string without examples. */
47
+ export function describeExcludedPathExamples(exclusion: AutomaticPathExclusionDisplay): string {
48
+ if (exclusion.examples.length === 0) return "";
49
+ const shown = exclusion.examples.slice(0, MAX_PROSE_EXAMPLES).map(describeExcludedPath);
50
+ return ` Excluded path examples: ${shown.join(", ")}.`;
36
51
  }
37
52
 
38
53
  /** Preserve provider failure reasons and append path explanations from typed metadata only. */
@@ -42,6 +57,5 @@ export function describePartialQuery(
42
57
  cwd: string,
43
58
  ): string {
44
59
  const exclusion = displayAutomaticPathExclusion(metadata?.automaticPathExclusion, cwd);
45
- if (!exclusion?.examples.length) return reason;
46
- return `${reason} Excluded path examples: ${exclusion.examples.map(describeExcludedPath).join(", ")}.`;
60
+ return exclusion ? `${reason}${describeExcludedPathExamples(exclusion)}` : reason;
47
61
  }
@@ -21,7 +21,7 @@ interface SourceSpan {
21
21
  }
22
22
 
23
23
  /** Statements that bind names the file does not declare itself. */
24
- interface BindingRanges {
24
+ export interface BindingRanges {
25
25
  readonly imports: readonly SourceSpan[];
26
26
  /** Specifiers of `export { … }` lists, with or without `from`. */
27
27
  readonly exportLists: readonly SourceSpan[];
@@ -58,6 +58,18 @@ export async function collectBindingRanges(
58
58
  }
59
59
  }
60
60
 
61
+ /**
62
+ * Whether a 1-based position lies in an import statement or an export list, where a name is
63
+ * bound or forwarded but not declared.
64
+ */
65
+ export function isBindingPosition(
66
+ ranges: BindingRanges,
67
+ position: { line: number; character: number },
68
+ ): boolean {
69
+ const target = { displayLine: position.line, displayCharacter: position.character };
70
+ return [...ranges.imports, ...ranges.exportLists].some((range) => containsTarget(range, target));
71
+ }
72
+
61
73
  /**
62
74
  * Split discovered declarations into the listed outline and counted omissions.
63
75
  *
@@ -131,7 +143,10 @@ function containsLines(outer: SourceSpan, inner: SourceSpan): boolean {
131
143
  return inner.startLine >= outer.startLine && inner.endLine <= outer.endLine;
132
144
  }
133
145
 
134
- function containsTarget(range: SourceSpan, target: ResolvedTargetData): boolean {
146
+ function containsTarget(
147
+ range: SourceSpan,
148
+ target: Pick<ResolvedTargetData, "displayLine" | "displayCharacter">,
149
+ ): boolean {
135
150
  const { displayLine: line, displayCharacter: character } = target;
136
151
  const afterStart =
137
152
  line > range.startLine || (line === range.startLine && character >= range.startCharacter);
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Automatic selection among exact-name symbol matches: which matches declare the name, and how
3
+ * the unselected ones are disclosed.
4
+ */
5
+
6
+ import * as path from "node:path";
7
+ import type {
8
+ CodeRequestControl,
9
+ CodeSymbol,
10
+ StructuralProvider as StructuralSubstrate,
11
+ } from "@mrclrchtr/supi-code-runtime/api";
12
+ import { collectBindingRanges, isBindingPosition } from "./file-outline-omissions.ts";
13
+
14
+ /** Exact-name matches checked for import/export-list bindings; each costs a syntax query. */
15
+ const MAX_BINDING_CHECKS = 8;
16
+ const MAX_NOTE_NAMES = 3;
17
+
18
+ /**
19
+ * Drop exact-name matches that only import or re-export the name, such as the `alias` symbol
20
+ * tsserver reports for `export { foo } from "./foo"`. Keeps every match when the syntax
21
+ * provider is absent, when a file cannot be classified, or when no declaration would remain.
22
+ */
23
+ export async function declarationsAmong(
24
+ exact: readonly CodeSymbol[],
25
+ structural: StructuralSubstrate | undefined,
26
+ control?: CodeRequestControl,
27
+ ): Promise<readonly CodeSymbol[]> {
28
+ if (!structural || exact.length > MAX_BINDING_CHECKS) return exact;
29
+ const files = [...new Set(exact.map((candidate) => candidate.file))];
30
+ const ranges = new Map(
31
+ await Promise.all(
32
+ files.map(
33
+ async (file) => [file, await collectBindingRanges(file, structural, control)] as const,
34
+ ),
35
+ ),
36
+ );
37
+ const declared = exact.filter((candidate) => {
38
+ const fileRanges = ranges.get(candidate.file);
39
+ return (
40
+ !fileRanges ||
41
+ !isBindingPosition(fileRanges, candidate.nameAnchor ?? candidate.declarationAnchor)
42
+ );
43
+ });
44
+ return declared.length > 0 ? declared : exact;
45
+ }
46
+
47
+ /** Name what was passed over for the selected match: bindings of its name and partial names. */
48
+ export function unselectedNote(
49
+ candidates: readonly CodeSymbol[],
50
+ selected: CodeSymbol,
51
+ symbol: string,
52
+ ): string | undefined {
53
+ const others = candidates.filter((candidate) => candidate !== selected);
54
+ const parts = describeOthers(others, symbol);
55
+ if (!parts) return undefined;
56
+ const subject = others.some((candidate) => candidate.name === symbol)
57
+ ? "declaration of that name"
58
+ : "exact-name match";
59
+ return `Selected the only ${subject}; ${parts} ${others.length === 1 ? "was" : "were"} not selected.`;
60
+ }
61
+
62
+ /** Name the matches left out of a candidate list that holds only declarations of the name. */
63
+ export function unlistedNote(
64
+ candidates: readonly CodeSymbol[],
65
+ listed: readonly CodeSymbol[],
66
+ symbol: string,
67
+ ): string | undefined {
68
+ const others = candidates.filter((candidate) => !listed.includes(candidate));
69
+ const parts = describeOthers(others, symbol);
70
+ if (!parts) return undefined;
71
+ // No count: the candidate disclosure already states it.
72
+ return `Listing declarations named \`${symbol}\`; ${parts} ${others.length === 1 ? "is" : "are"} not listed.`;
73
+ }
74
+
75
+ function describeOthers(others: readonly CodeSymbol[], symbol: string): string | undefined {
76
+ const bindings = others.filter((candidate) => candidate.name === symbol);
77
+ const partial = others.filter((candidate) => candidate.name !== symbol);
78
+ const parts: string[] = [];
79
+ if (bindings.length > 0) {
80
+ const files = [...new Set(bindings.map((candidate) => path.basename(candidate.file)))];
81
+ parts.push(
82
+ `${count(bindings.length, "import or export-list binding")} of that name (${listed(files)})`,
83
+ );
84
+ }
85
+ if (partial.length > 0) {
86
+ const names = [...new Set(partial.map((candidate) => candidate.name))];
87
+ parts.push(`${count(partial.length, "partial-name match", "es")} (${listed(names)})`);
88
+ }
89
+ return parts.length > 0 ? parts.join(" and ") : undefined;
90
+ }
91
+
92
+ function count(n: number, noun: string, plural = "s"): string {
93
+ return `${n} ${noun}${n === 1 ? "" : plural}`;
94
+ }
95
+
96
+ function listed(values: readonly string[]): string {
97
+ const shown = values.slice(0, MAX_NOTE_NAMES).map((value) => `\`${value}\``);
98
+ if (values.length > MAX_NOTE_NAMES) shown.push(`${values.length - MAX_NOTE_NAMES} more`);
99
+ return shown.join(", ");
100
+ }
@@ -13,6 +13,7 @@ import {
13
13
  type CodeSymbol,
14
14
  isCodeRequestInterruption,
15
15
  type SemanticProvider as SemanticSubstrate,
16
+ type StructuralProvider as StructuralSubstrate,
16
17
  } from "@mrclrchtr/supi-code-runtime/api";
17
18
  import { isWithinOrEqual } from "@mrclrchtr/supi-core/project";
18
19
  import type { TargetSymbolKind } from "../../session/target-input.ts";
@@ -20,6 +21,7 @@ import type { AnchorKind } from "../../session/target-store.ts";
20
21
  import { createEvidenceList, createPartialEvidenceList } from "../evidence.ts";
21
22
  import { describePartialQuery } from "../search/exclusions.ts";
22
23
  import { normalizePath } from "../search/paths.ts";
24
+ import { declarationsAmong, unlistedNote, unselectedNote } from "./symbol-selection.ts";
23
25
  import type { DisambiguationCandidateData, TargetOutcome } from "./types.ts";
24
26
 
25
27
  const MAX_CANDIDATES = 8; // default fallback when maxResults is not provided
@@ -115,6 +117,8 @@ export async function resolveSymbolTarget(
115
117
  exportedOnly?: boolean;
116
118
  maxResults?: number;
117
119
  control?: CodeRequestControl;
120
+ /** Syntax provider used to tell declarations from import and export-list bindings. */
121
+ structural?: StructuralSubstrate;
118
122
  },
119
123
  ): Promise<TargetOutcome> {
120
124
  const scopePath = options?.path ? normalizePath(options.path, cwd) : null;
@@ -157,6 +161,7 @@ export async function resolveSymbolTarget(
157
161
  });
158
162
  }
159
163
  return resolveCandidates({
164
+ symbol,
160
165
  candidates: exactKind,
161
166
  discovery: candidateDiscovery(result, cwd),
162
167
  exclusionNote: exclusionOnlyNote(result, cwd),
@@ -164,10 +169,12 @@ export async function resolveSymbolTarget(
164
169
  cwd,
165
170
  maxResults: options.maxResults,
166
171
  control: options.control,
172
+ structural: options.structural,
167
173
  });
168
174
  }
169
175
 
170
176
  return resolveCandidates({
177
+ symbol,
171
178
  candidates: eligible,
172
179
  discovery: candidateDiscovery(result, cwd),
173
180
  exclusionNote: exclusionOnlyNote(result, cwd),
@@ -175,6 +182,7 @@ export async function resolveSymbolTarget(
175
182
  cwd,
176
183
  maxResults: options?.maxResults,
177
184
  control: options?.control,
185
+ structural: options?.structural,
178
186
  });
179
187
  }
180
188
 
@@ -188,6 +196,8 @@ function normalizeProviderKind(kind: string): string {
188
196
 
189
197
  async function resolveCandidates(
190
198
  options: CandidateOutcomeBase & {
199
+ /** The queried name; one case-sensitive exact match wins over partial-name matches. */
200
+ symbol: string;
191
201
  discovery: CandidateDiscovery;
192
202
  /** Disclosure for a unique match beside policy-excluded rows. */
193
203
  exclusionNote?: string;
@@ -198,20 +208,43 @@ async function resolveCandidates(
198
208
  (candidate) =>
199
209
  candidate.declarationAnchor.line > 0 || candidate.declarationAnchor.character > 0,
200
210
  );
201
- if (ranged.length === 1 && discovery.partialMessage === null) {
202
- const resolved = resolvedTarget(await refineResolvedSymbolAnchor(ranged[0], semantic, control));
203
- // Exclusion-only evidence resolves, but the excluded rows stay disclosed.
204
- return exclusionNote ? { ...resolved, notes: [exclusionNote] } : resolved;
211
+ // Workspace-symbol providers match substrings, so a query for `foo` also returns `fooBar`.
212
+ const exact = ranged.filter((candidate) => candidate.name === options.symbol);
213
+ const complete = discovery.partialMessage === null;
214
+ // A row-limited answer may lack partial-name matches but holds every exact name.
215
+ const exactComplete = complete || discovery.exactNamesComplete;
216
+ const declared =
217
+ exactComplete && exact.length > 1
218
+ ? await declarationsAmong(exact, options.structural, control)
219
+ : exact;
220
+ const selected =
221
+ complete && ranged.length === 1
222
+ ? ranged[0]
223
+ : exactComplete && declared.length === 1
224
+ ? declared[0]
225
+ : undefined;
226
+ if (selected) {
227
+ const resolved = resolvedTarget(await refineResolvedSymbolAnchor(selected, semantic, control));
228
+ // Unselected rows stay disclosed: bindings, partial-name matches, policy exclusions, and the row limit.
229
+ const notes = [
230
+ unselectedNote(candidates, selected, options.symbol),
231
+ exclusionNote ?? discovery.partialMessage ?? undefined,
232
+ ].filter((note): note is string => note !== undefined);
233
+ return notes.length > 0 ? { ...resolved, notes } : resolved;
205
234
  }
206
- return buildCandidateOutcome({
235
+ // Several declarations of the queried name: partial-name matches cannot be meant.
236
+ const listed = exactComplete && declared.length > 1 ? declared : candidates;
237
+ const outcome = await buildCandidateOutcome({
207
238
  kind: "disambiguation",
208
- candidates,
239
+ candidates: listed,
209
240
  semantic,
210
241
  cwd,
211
242
  maxResults,
212
243
  discovery,
213
244
  control,
214
245
  });
246
+ const note = unlistedNote(candidates, listed, options.symbol);
247
+ return note ? { ...outcome, candidateNotes: [note] } : outcome;
215
248
  }
216
249
 
217
250
  function resolvedTarget(candidate: CodeSymbol): Extract<TargetOutcome, { kind: "resolved" }> {
@@ -241,6 +274,7 @@ interface CandidateOutcomeBase {
241
274
  cwd: string;
242
275
  maxResults?: number;
243
276
  control?: CodeRequestControl;
277
+ structural?: StructuralSubstrate;
244
278
  }
245
279
 
246
280
  /**
@@ -249,6 +283,8 @@ interface CandidateOutcomeBase {
249
283
  */
250
284
  interface CandidateDiscovery {
251
285
  readonly partialMessage: string | null;
286
+ /** Every exact-name declaration is present although the result is partial. */
287
+ readonly exactNamesComplete: boolean;
252
288
  }
253
289
 
254
290
  function candidateDiscovery(
@@ -259,8 +295,11 @@ function candidateDiscovery(
259
295
  // automatic scope; the retained in-policy rows are complete. Failures and
260
296
  // coverage gaps keep the total unknown.
261
297
  return result.kind === "partial" && result.metadata?.exclusionOnly !== true
262
- ? { partialMessage: describePartialQuery(result.reason, result.metadata, cwd) }
263
- : { partialMessage: null };
298
+ ? {
299
+ partialMessage: describePartialQuery(result.reason, result.metadata, cwd),
300
+ exactNamesComplete: result.metadata?.rowLimit?.exactNamesComplete === true,
301
+ }
302
+ : { partialMessage: null, exactNamesComplete: false };
264
303
  }
265
304
 
266
305
  /** Describe exclusion-only evidence so a resolved target still discloses dropped rows. */
@@ -292,6 +331,7 @@ function emptySymbolOutcome(
292
331
  return {
293
332
  kind: "unavailable",
294
333
  reason: `Symbol discovery for \`${symbol}\` is incomplete: ${describePartialQuery(result.reason, result.metadata, cwd)}`,
334
+ ...(result.metadata?.rowLimit ? { rowLimited: true as const } : {}),
295
335
  };
296
336
  }
297
337
  return {
@@ -172,6 +172,8 @@ export interface DisambiguationCandidateData {
172
172
  export interface TargetCandidateCompleteness {
173
173
  /** Candidate Evidence list metadata; consumers re-key it, never rebuild it. */
174
174
  candidateEvidence: EvidenceListMetadata;
175
+ /** Matches left out of `candidates` on purpose, such as partial names beside exact ones. */
176
+ candidateNotes?: readonly string[];
175
177
  }
176
178
 
177
179
  /**
@@ -197,5 +199,10 @@ export type TargetOutcome =
197
199
  requestedKind: TargetSymbolKind;
198
200
  candidates: DisambiguationCandidateData[];
199
201
  } & TargetCandidateCompleteness)
200
- | { kind: "unavailable"; reason: string }
202
+ | {
203
+ kind: "unavailable";
204
+ reason: string;
205
+ /** A provider row limit, not readiness, left the result incomplete; the reason names the next step. */
206
+ rowLimited?: true;
207
+ }
201
208
  | { kind: "error"; message: string };
package/src/app/app.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * feature wiring.
7
7
  */
8
8
 
9
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
9
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
10
10
  import { WorkspaceCodeIntelligenceSession } from "../session/session.ts";
11
11
 
12
12
  /**
@@ -68,14 +68,44 @@ export function createSessionCache(): {
68
68
  };
69
69
  }
70
70
 
71
+ /**
72
+ * Keep a session informed about the instruction files its model already has, so directory
73
+ * `code_orientation` does not deliver them again. Shared by the full extension and the
74
+ * headless profile; without it every instruction file counts as unseen.
75
+ *
76
+ * Registers:
77
+ * - `session_start` / `session_tree` — rebuild surfaced directories and full reads from the branch
78
+ * - `before_agent_start` — record the context files Pi loaded into the system prompt
79
+ * - `tool_result` — record full `read` results
80
+ * - `session_compact` — reset, so instructions are delivered again
81
+ */
82
+ export function registerInstructionDedup(
83
+ pi: ExtensionAPI,
84
+ getSession: (cwd: string) => WorkspaceCodeIntelligenceSession,
85
+ ): void {
86
+ const restore = (_event: unknown, ctx: ExtensionContext): void => {
87
+ getSession(ctx.cwd).reconstructInstructionState(ctx.sessionManager.getBranch());
88
+ };
89
+ pi.on("session_start", restore);
90
+ pi.on("session_tree", restore);
91
+ pi.on("before_agent_start", (event, ctx) => {
92
+ getSession(ctx.cwd).captureNativeInstructionPaths(event.systemPromptOptions.contextFiles ?? []);
93
+ });
94
+ pi.on("tool_result", (event, ctx) => {
95
+ getSession(ctx.cwd).recordToolResult(event);
96
+ });
97
+ pi.on("session_compact", (_event, ctx) => {
98
+ getSession(ctx.cwd).resetInstructionDedup();
99
+ });
100
+ }
101
+
71
102
  /**
72
103
  * Create the code-intelligence app and wire it to pi lifecycle events.
73
104
  *
74
105
  * Registers:
75
- * - `session_start` / `session_tree` — create or restore the session for the
76
- * cwd from the active branch (overview and instruction dedup state)
77
- * - `tool_result` — records full `read` results for instruction dedup
78
- * - `session_compact` — resets instruction dedup state
106
+ * - instruction deduplication, see {@link registerInstructionDedup}
107
+ * - `session_start` / `session_tree` — create the session for the cwd and
108
+ * restore overview state from the active branch
79
109
  * - `session_shutdown` — releases all sessions and clears per-session stores
80
110
  */
81
111
  export function createCodeIntelligenceApp(pi: ExtensionAPI): CodeIntelligenceApp {
@@ -93,13 +123,7 @@ export function createCodeIntelligenceApp(pi: ExtensionAPI): CodeIntelligenceApp
93
123
  restoreBranchOverviewState(session, ctx.sessionManager.getBranch());
94
124
  });
95
125
 
96
- pi.on("tool_result", (event, ctx) => {
97
- sessions.get(ctx.cwd)?.recordToolResult(event);
98
- });
99
-
100
- pi.on("session_compact", (_event, ctx) => {
101
- sessions.get(ctx.cwd)?.resetInstructionDedup();
102
- });
126
+ registerInstructionDedup(pi, (cwd) => getOrCreateSession(sessions, cwd));
103
127
 
104
128
  pi.on("session_shutdown", () => {
105
129
  for (const session of sessions.values()) {
@@ -108,19 +132,11 @@ export function createCodeIntelligenceApp(pi: ExtensionAPI): CodeIntelligenceApp
108
132
  sessions.clear();
109
133
  });
110
134
 
111
- /**
112
- * Restore overview injection state from a branch.
113
- *
114
- * Reconstructs instruction-file state and checks whether this branch
115
- * already contains a code-intelligence-overview custom message.
116
- */
135
+ /** Check whether this branch already contains a code-intelligence-overview custom message. */
117
136
  function restoreBranchOverviewState(
118
137
  session: WorkspaceCodeIntelligenceSession,
119
138
  branch: unknown[],
120
139
  ): void {
121
- session.reconstructInstructionState(
122
- branch as Parameters<typeof session.reconstructInstructionState>[0],
123
- );
124
140
  session.restoreOverviewInjection(false);
125
141
  for (const entry of branch as Array<{ type?: string; customType?: string }>) {
126
142
  if (entry.type === "custom_message" && entry.customType === OVERVIEW_CUSTOM_TYPE) {
package/src/extension.ts CHANGED
@@ -85,9 +85,8 @@ export default function codeIntelligenceExtension(
85
85
  ?.setOverviewEnabledOnce(resolveOverviewEnabled(ctx.cwd, ctx.isProjectTrusted(), homeDir));
86
86
  });
87
87
 
88
- pi.on("before_agent_start", (event, ctx) => {
88
+ pi.on("before_agent_start", (_event, ctx) => {
89
89
  const session = app.getSession(ctx.cwd) ?? app.createSession(ctx.cwd);
90
- session.captureNativeInstructionPaths(event.systemPromptOptions.contextFiles ?? []);
91
90
  session.setHomeDir(homeDir);
92
91
  session.setGradleObserver(gradle.forContext(ctx));
93
92
  if (!session.hasPinnedOverview()) {
package/src/headless.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { createSessionCache } from "./app/app.ts";
2
+ import { createSessionCache, registerInstructionDedup } from "./app/app.ts";
3
3
  import { registerGradleObservations } from "./gradle/consent.ts";
4
4
  import { registerLspSessionLifecycle } from "./substrate/lsp/lifecycle.ts";
5
5
  import { createLspAdapterState } from "./substrate/lsp/state.ts";
@@ -20,7 +20,8 @@ const inspectionToolNames = new Set<string>(HEADLESS_INSPECTION_TOOL_NAMES);
20
20
 
21
21
  /**
22
22
  * Register the managed-child profile: six inspection tools backed by the shared
23
- * Workspace provider host, without refactors, settings, UI, or overview state.
23
+ * Workspace provider host and instruction deduplication, without refactors, settings, UI, or
24
+ * overview state.
24
25
  */
25
26
  export default function headlessInspectionProfile(pi: ExtensionAPI): void {
26
27
  const sessions = createSessionCache();
@@ -34,6 +35,7 @@ export default function headlessInspectionProfile(pi: ExtensionAPI): void {
34
35
  session.setGradleObserver(gradle.forContext(ctx));
35
36
  session.setAutomaticPathPolicy(lspState.providerLease?.automaticPathPolicy ?? null);
36
37
  });
38
+ registerInstructionDedup(pi, sessions.getOrCreate);
37
39
  pi.on("session_shutdown", () => sessions.clear());
38
40
 
39
41
  registerCodeIntelligenceTools(
@@ -41,6 +41,8 @@ export interface HealthServerInfo {
41
41
  /** Actionable launch failure, distinct from process recovery status. */
42
42
  readonly failureMessage?: string;
43
43
  readonly ready: boolean;
44
+ /** Present while the background warm-up loads the route's projects; a symbol query waits for it. */
45
+ readonly loadingProjects?: true;
44
46
  /** Negotiated operation support and SuPi planning limitations. */
45
47
  readonly operationSupport?: ServerOperationSupportMap;
46
48
  }
@@ -133,6 +133,11 @@ export interface OrientationResultData {
133
133
  readonly instructions?: InstructionFilesMetadata;
134
134
  /** Collected instruction snippets; separate from mutable session deduplication state. */
135
135
  readonly instructionFiles?: readonly import("../analysis/instruction-files.ts").RenderedInstructionFile[];
136
+ /**
137
+ * Instruction files for the focused directory that the session already has, so they are not
138
+ * repeated. Rendered as one line so an absent section does not read as a discovery failure.
139
+ */
140
+ readonly knownInstructionPaths?: readonly string[];
136
141
  /** Captured generic workspace facts; absent for the unchanged file and symbol paths. */
137
142
  readonly workspace?: import("./orientation/workspace-context.ts").WorkspaceOrientationFacts;
138
143
  readonly target?: Readonly<TargetStoreEntry>;