@mrclrchtr/supi-code-intelligence 11.3.0 → 12.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 (132) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +15 -9
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
  5. package/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  6. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
  7. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  8. package/node_modules/@mrclrchtr/supi-lsp/README.md +22 -17
  9. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  10. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
  11. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +2 -2
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +30 -0
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +1 -1
  18. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  19. package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +2 -2
  20. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +13 -3
  21. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +25 -9
  22. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +7 -5
  23. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-edit-capture.ts +258 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +64 -11
  25. package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +8 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +48 -79
  27. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +10 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +118 -0
  29. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +67 -3
  30. package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +87 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +21 -35
  32. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-command-capture.ts +139 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +202 -47
  34. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +22 -17
  35. package/node_modules/@mrclrchtr/supi-lsp/src/session/route-boundary.ts +26 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +106 -16
  37. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +3 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +22 -1
  39. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -1
  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/api.ts +3 -1
  42. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  43. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
  44. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  45. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  46. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
  47. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +5 -1
  48. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
  49. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +5 -1
  50. package/node_modules/@mrclrchtr/supi-tree-sitter/src/coordinates.ts +16 -2
  51. package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +3 -2
  52. package/node_modules/@mrclrchtr/supi-tree-sitter/src/syntax-errors.ts +2 -0
  53. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-range.ts +94 -0
  54. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +26 -6
  55. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +6 -3
  56. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +13 -4
  57. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +1 -9
  58. package/package.json +5 -5
  59. package/src/analysis/health/server-status.ts +41 -12
  60. package/src/analysis/helpers.ts +0 -7
  61. package/src/analysis/relations/implementations.ts +5 -0
  62. package/src/analysis/relations/references.ts +5 -0
  63. package/src/analysis/target/anchored-structural.ts +4 -1
  64. package/src/analysis/target/file-merge.ts +162 -0
  65. package/src/analysis/target/file-outline-omissions.ts +146 -0
  66. package/src/analysis/target/file-refinement.ts +7 -7
  67. package/src/analysis/target/file.ts +44 -156
  68. package/src/analysis/target/symbol.ts +5 -1
  69. package/src/analysis/target/types.ts +32 -6
  70. package/src/api.ts +1 -1
  71. package/src/app/app.ts +9 -3
  72. package/src/session/find-types.ts +8 -4
  73. package/src/session/find-workflow.ts +11 -16
  74. package/src/session/graph/collect.ts +2 -0
  75. package/src/session/graph-types.ts +3 -1
  76. package/src/session/graph-workflow.ts +5 -4
  77. package/src/session/input/health-refactor.ts +48 -34
  78. package/src/session/input/workflows.ts +45 -46
  79. package/src/session/inspect/file-point.ts +2 -2
  80. package/src/session/inspect-types.ts +1 -1
  81. package/src/session/inspect-workflow.ts +3 -3
  82. package/src/session/orientation/workspace-context.ts +3 -0
  83. package/src/session/orientation-workflow.ts +6 -3
  84. package/src/session/refactor-file-actions.ts +122 -0
  85. package/src/session/refactor-plan-pipeline.ts +152 -0
  86. package/src/session/refactor-plans.ts +18 -15
  87. package/src/session/refactor-types.ts +24 -12
  88. package/src/session/refactor-workflow.ts +70 -244
  89. package/src/session/session.ts +87 -12
  90. package/src/session/target-workflow.ts +23 -21
  91. package/src/tool/code_find/execute.ts +6 -7
  92. package/src/tool/code_find/spec.ts +9 -16
  93. package/src/tool/code_find/tui.ts +12 -6
  94. package/src/tool/code_graph/section.ts +4 -0
  95. package/src/tool/code_graph/spec.ts +6 -0
  96. package/src/tool/code_health/spec.ts +6 -0
  97. package/src/tool/code_health/structured-schema.ts +4 -4
  98. package/src/tool/code_health/structured.ts +15 -17
  99. package/src/tool/code_inspect/execute.ts +1 -1
  100. package/src/tool/code_inspect/markdown.ts +33 -6
  101. package/src/tool/code_inspect/result.ts +1 -1
  102. package/src/tool/code_inspect/spec.ts +14 -6
  103. package/src/tool/code_inspect/structured.ts +2 -2
  104. package/src/tool/code_inspect/tui.ts +2 -2
  105. package/src/tool/code_orientation/directory-navigation.ts +20 -31
  106. package/src/tool/code_orientation/spec.ts +8 -0
  107. package/src/tool/code_orientation/workspace-output.ts +40 -13
  108. package/src/tool/code_orientation/workspace-sections.ts +45 -2
  109. package/src/tool/code_refactor_apply/result.ts +2 -1
  110. package/src/tool/code_refactor_apply/spec.ts +7 -0
  111. package/src/tool/code_refactor_plan/execute.ts +0 -2
  112. package/src/tool/code_refactor_plan/result.ts +23 -13
  113. package/src/tool/code_refactor_plan/spec.ts +8 -2
  114. package/src/tool/code_refactor_plan/structured.ts +59 -12
  115. package/src/tool/code_refactor_plan/tui.ts +14 -17
  116. package/src/tool/code_resolve/guidance.ts +1 -1
  117. package/src/tool/code_resolve/markdown.ts +121 -34
  118. package/src/tool/code_resolve/result.ts +18 -15
  119. package/src/tool/code_resolve/spec.ts +6 -0
  120. package/src/tool/code_resolve/structured.ts +43 -10
  121. package/src/tool/namespace.ts +14 -0
  122. package/src/tool/refactor-markdown.ts +55 -15
  123. package/src/tool/register.ts +3 -0
  124. package/src/tool/result/model-budget.ts +2 -2
  125. package/src/tool/result/refactor-preview.ts +118 -0
  126. package/src/tool/result/refactor-unavailable.ts +16 -0
  127. package/src/tool/result/refactor.ts +8 -2
  128. package/src/tool/result/types.ts +13 -10
  129. package/src/tool/schemas.ts +63 -20
  130. package/src/tool/specs.ts +3 -0
  131. package/src/ui/status-overlay.ts +1 -1
  132. package/src/ui/tui/common.ts +10 -10
@@ -0,0 +1,146 @@
1
+ /**
2
+ * File outline omissions: which discovered declarations an outline leaves out
3
+ * and how they are counted. Imported names, export-list names, and
4
+ * `export … from` statements bind or forward names the file does not declare;
5
+ * local declarations live inside function bodies.
6
+ */
7
+
8
+ import type {
9
+ CodeRequestControl,
10
+ StructuralProvider as StructuralSubstrate,
11
+ } from "@mrclrchtr/supi-code-runtime/api";
12
+ import { isCodeRequestInterruption } from "@mrclrchtr/supi-code-runtime/api";
13
+ import type { DiscoveredTargetData } from "./file.ts";
14
+ import type { FileOutlineNameSpan, FileOutlineNotListed, ResolvedTargetData } from "./types.ts";
15
+
16
+ interface SourceSpan {
17
+ readonly startLine: number;
18
+ readonly startCharacter: number;
19
+ readonly endLine: number;
20
+ readonly endCharacter: number;
21
+ }
22
+
23
+ /** Statements that bind names the file does not declare itself. */
24
+ interface BindingRanges {
25
+ readonly imports: readonly SourceSpan[];
26
+ /** Specifiers of `export { … }` lists, with or without `from`. */
27
+ readonly exportLists: readonly SourceSpan[];
28
+ /**
29
+ * Specifiers of `export { … } from`, and whole `export * from` or
30
+ * `export * as name from` statements, which have no outline row.
31
+ */
32
+ readonly reExports: readonly SourceSpan[];
33
+ }
34
+
35
+ /** Syntax ranges of import statements and export-list specifiers, or null when unknown. */
36
+ export async function collectBindingRanges(
37
+ file: string,
38
+ structural: StructuralSubstrate | undefined,
39
+ control?: CodeRequestControl,
40
+ ): Promise<BindingRanges | null> {
41
+ if (!structural) return null;
42
+ try {
43
+ const [imports, exports] = await Promise.all([
44
+ structural.imports(file, control),
45
+ structural.exports(file, control),
46
+ ]);
47
+ const exportData = exports.kind === "success" || exports.kind === "partial" ? exports.data : [];
48
+ return {
49
+ imports: imports.kind === "success" || imports.kind === "partial" ? imports.data : [],
50
+ exportLists: exportData.filter(
51
+ (entry) => entry.kind === "export" || entry.kind === "re-export",
52
+ ),
53
+ reExports: exportData.filter((entry) => entry.kind === "re-export"),
54
+ };
55
+ } catch (error) {
56
+ if (isCodeRequestInterruption(error, control)) throw error;
57
+ return null;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Split discovered declarations into the listed outline and counted omissions.
63
+ *
64
+ * Local declarations are omitted by level. A name only the language server
65
+ * reported inside an import statement or an export list is a binding, not a
66
+ * declaration of this file. A syntax-parser export statement that contains a
67
+ * re-export only forwards names; an own `export { … }` list stays listed.
68
+ * Without binding ranges such entries stay listed rather than being guessed.
69
+ */
70
+ export function partitionOutline(
71
+ targets: readonly DiscoveredTargetData[],
72
+ ranges: BindingRanges | null,
73
+ ): { targets: DiscoveredTargetData[]; notListed: FileOutlineNotListed } {
74
+ const listed: DiscoveredTargetData[] = [];
75
+ const lines = { imported: [] as number[], exportList: [] as number[], reExport: [] as number[] };
76
+ const reExportRows: SourceSpan[] = [];
77
+ let localDeclarations = 0;
78
+ for (const target of targets) {
79
+ const omission = classifyOmission(target, ranges);
80
+ if (omission === "local") localDeclarations++;
81
+ else if (omission === null) listed.push(target);
82
+ else {
83
+ lines[omission].push(target.displayLine);
84
+ if (omission === "reExport") reExportRows.push(statementSpan(target));
85
+ }
86
+ }
87
+ // `export *` statements have no outline row; each record is one statement.
88
+ for (const record of ranges?.reExports ?? []) {
89
+ if (!reExportRows.some((row) => containsLines(row, record))) {
90
+ lines.reExport.push(record.startLine);
91
+ }
92
+ }
93
+ return {
94
+ targets: listed,
95
+ notListed: {
96
+ importedNames: nameSpan(lines.imported),
97
+ exportListNames: nameSpan(lines.exportList),
98
+ reExportStatements: nameSpan(lines.reExport),
99
+ localDeclarations,
100
+ },
101
+ };
102
+ }
103
+
104
+ /** Why the outline leaves `target` out, or null when it is listed. */
105
+ function classifyOmission(
106
+ target: DiscoveredTargetData,
107
+ ranges: BindingRanges | null,
108
+ ): "local" | "imported" | "exportList" | "reExport" | null {
109
+ if (target.level === "local") return "local";
110
+ if (!ranges) return null;
111
+ if (isReExportStatement(target, ranges)) return "reExport";
112
+ if (target.provenance.includes("structural")) return null;
113
+ if (ranges.imports.some((range) => containsTarget(range, target))) return "imported";
114
+ if (ranges.exportLists.some((range) => containsTarget(range, target))) return "exportList";
115
+ return null;
116
+ }
117
+
118
+ /** A syntax-parser `export` statement row whose lines hold a re-export. */
119
+ function isReExportStatement(target: DiscoveredTargetData, ranges: BindingRanges): boolean {
120
+ if (target.kind !== "export" || target.provenance.includes("semantic")) return false;
121
+ const row = statementSpan(target);
122
+ return ranges.reExports.some((range) => containsLines(row, range));
123
+ }
124
+
125
+ function statementSpan(target: DiscoveredTargetData): SourceSpan {
126
+ const startLine = target.declarationAnchor.line;
127
+ return { startLine, startCharacter: 1, endLine: target.endLine ?? startLine, endCharacter: 1 };
128
+ }
129
+
130
+ function containsLines(outer: SourceSpan, inner: SourceSpan): boolean {
131
+ return inner.startLine >= outer.startLine && inner.endLine <= outer.endLine;
132
+ }
133
+
134
+ function containsTarget(range: SourceSpan, target: ResolvedTargetData): boolean {
135
+ const { displayLine: line, displayCharacter: character } = target;
136
+ const afterStart =
137
+ line > range.startLine || (line === range.startLine && character >= range.startCharacter);
138
+ const beforeEnd =
139
+ line < range.endLine || (line === range.endLine && character <= range.endCharacter);
140
+ return afterStart && beforeEnd;
141
+ }
142
+
143
+ function nameSpan(lines: readonly number[]): FileOutlineNameSpan | null {
144
+ if (lines.length === 0) return null;
145
+ return { count: lines.length, startLine: Math.min(...lines), endLine: Math.max(...lines) };
146
+ }
@@ -24,11 +24,11 @@ export function refineLatexSectionNameAnchor(
24
24
  };
25
25
  }
26
26
 
27
- /** Prefer known hierarchy, but keep conflicts unknown. */
28
- export function reconcileNesting(
29
- semantic: DiscoveredTargetData["nesting"],
30
- structural: DiscoveredTargetData["nesting"],
31
- ): DiscoveredTargetData["nesting"] {
27
+ /** Prefer a known declaration level, but keep conflicts unknown. */
28
+ export function reconcileLevel(
29
+ semantic: DiscoveredTargetData["level"],
30
+ structural: DiscoveredTargetData["level"],
31
+ ): DiscoveredTargetData["level"] {
32
32
  if (semantic === structural) return semantic;
33
33
  if (semantic === "unknown") return structural;
34
34
  if (structural === "unknown") return semantic;
@@ -41,10 +41,10 @@ export function reconcileContainer(
41
41
  structural: DiscoveredTargetData,
42
42
  ): string | null {
43
43
  if (semantic.container === structural.container) return semantic.container;
44
- if (semantic.nesting === "unknown" && semantic.container === null) {
44
+ if (semantic.level === "unknown" && semantic.container === null) {
45
45
  return structural.container;
46
46
  }
47
- if (structural.nesting === "unknown" && structural.container === null) {
47
+ if (structural.level === "unknown" && structural.container === null) {
48
48
  return semantic.container;
49
49
  }
50
50
  return null;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * File target discovery — collects every evidence-backed declaration in one
2
+ * File outline discovery — collects every evidence-backed declaration in one
3
3
  * file after the Target workflow has established semantic readiness.
4
4
  *
5
5
  * Semantic and structural facts are merged. Semantic facts win duplicate
@@ -11,7 +11,8 @@ import * as fs from "node:fs";
11
11
  import * as path from "node:path";
12
12
  import {
13
13
  type CodeRequestControl,
14
- type DeclarationNesting,
14
+ childDeclarationLevel,
15
+ type DeclarationLevel,
15
16
  type DocumentCodeSymbol,
16
17
  isCodeRequestInterruption,
17
18
  type OutlineData,
@@ -21,19 +22,14 @@ import {
21
22
  import type { AnchorKind } from "../../session/target-store.ts";
22
23
  import { normalizePath } from "../search/paths.ts";
23
24
  import { mergeDiscoveryPartial, type TargetDiscoveryResult } from "./discovery.ts";
24
- import {
25
- reconcileContainer,
26
- reconcileNesting,
27
- refineLatexSectionNameAnchor,
28
- } from "./file-refinement.ts";
25
+ import { mergeDiscoveries } from "./file-merge.ts";
26
+ import { collectBindingRanges, partitionOutline } from "./file-outline-omissions.ts";
29
27
  import {
30
28
  canonicalDeclarationKind,
31
29
  canonicalFileDeclarationKind,
32
- canonicalFileDeclarationName,
33
- declarationOccurrencesFor,
34
30
  refineTypeAliasIdentity,
35
31
  } from "./identity.ts";
36
- import type { ResolvedTargetData, ResolvedTargetGroupData } from "./types.ts";
32
+ import type { FileOutlineData, ResolvedTargetData } from "./types.ts";
37
33
 
38
34
  const BINARY_EXTENSIONS = new Set([
39
35
  ".png",
@@ -65,8 +61,10 @@ const BINARY_EXTENSIONS = new Set([
65
61
  type DiscoveryResult = TargetDiscoveryResult<DiscoveredTargetData>;
66
62
 
67
63
  export interface DiscoveredTargetData extends ResolvedTargetData {
68
- /** Provider-backed hierarchy used only for file-result presentation ranking. */
69
- readonly nesting: DeclarationNesting;
64
+ /** Provider-backed position in the file, used only for outline ranking. */
65
+ readonly level: DeclarationLevel;
66
+ /** 1-based last line of a syntax-parser declaration, used to classify export statements. */
67
+ readonly endLine?: number;
70
68
  }
71
69
 
72
70
  /** Validated file-discovery input with its normalized absolute path. */
@@ -83,8 +81,8 @@ export function validateFileTargetDiscovery(file: string, cwd: string): FileDisc
83
81
  : { kind: "valid", file: resolvedFile };
84
82
  }
85
83
 
86
- /** Discover a Target group for one file without rendering or registering handles. */
87
- export async function resolveFileTargetGroup(
84
+ /** Discover the File outline of one file without rendering or registering handles. */
85
+ export async function resolveFileOutline(
88
86
  file: string,
89
87
  cwd: string,
90
88
  deps: {
@@ -93,7 +91,7 @@ export async function resolveFileTargetGroup(
93
91
  } = {},
94
92
  control?: CodeRequestControl,
95
93
  ): Promise<
96
- | { kind: "resolved"; group: ResolvedTargetGroupData }
94
+ | { kind: "resolved"; outline: FileOutlineData }
97
95
  | { kind: "invalid-input"; message: string }
98
96
  | { kind: "unavailable"; message: string }
99
97
  > {
@@ -101,9 +99,10 @@ export async function resolveFileTargetGroup(
101
99
  if (validation.kind === "invalid-input") return validation;
102
100
  const resolvedFile = validation.file;
103
101
 
104
- const [semantic, structural] = await Promise.all([
102
+ const [semantic, structural, bindingRanges] = await Promise.all([
105
103
  discoverSemantic(resolvedFile, deps.semantic, deps.structural, control),
106
104
  discoverStructural(resolvedFile, deps.structural, control),
105
+ collectBindingRanges(resolvedFile, deps.structural, control),
107
106
  ]);
108
107
  if (!semantic.available && !structural.available) {
109
108
  const displayFile = path.relative(cwd, resolvedFile) || file;
@@ -113,30 +112,34 @@ export async function resolveFileTargetGroup(
113
112
  };
114
113
  }
115
114
 
116
- const targets = mergeDiscoveries(structural.targets, semantic.targets);
117
- const unknownNestingCount = targets.filter((target) => target.nesting === "unknown").length;
115
+ const { targets, notListed } = partitionOutline(
116
+ mergeDiscoveries(structural.targets, semantic.targets),
117
+ bindingRanges,
118
+ );
119
+ const unknownLevelCount = targets.filter((target) => target.level === "unknown").length;
118
120
  const discoveryProvenance = [
119
121
  ...(semantic.available ? (["semantic"] as const) : []),
120
122
  ...(structural.available ? (["structural"] as const) : []),
121
123
  ];
122
124
  return {
123
125
  kind: "resolved",
124
- group: {
126
+ outline: {
125
127
  file: resolvedFile,
126
128
  displayName: path.relative(cwd, resolvedFile) || resolvedFile,
127
129
  targets,
128
130
  discoveryProvenance,
129
- confidence: targetGroupConfidence(targets, discoveryProvenance),
130
- unknownNestingCount,
131
+ confidence: fileOutlineConfidence(targets, discoveryProvenance),
132
+ unknownLevelCount,
131
133
  ...mergeDiscoveryPartial(semantic, structural),
134
+ notListed,
132
135
  },
133
136
  };
134
137
  }
135
138
 
136
- function targetGroupConfidence(
139
+ function fileOutlineConfidence(
137
140
  targets: readonly ResolvedTargetData[],
138
- discoveryProvenance: ResolvedTargetGroupData["discoveryProvenance"],
139
- ): ResolvedTargetGroupData["confidence"] {
141
+ discoveryProvenance: FileOutlineData["discoveryProvenance"],
142
+ ): FileOutlineData["confidence"] {
140
143
  if (targets.length === 0) {
141
144
  return discoveryProvenance.includes("semantic") ? "semantic" : "structural";
142
145
  }
@@ -173,7 +176,7 @@ async function discoverSemantic(
173
176
  result.data.map(async (symbol) => {
174
177
  const target = targetFromSymbol(file, symbol);
175
178
  const refined = await refineTypeAliasIdentity(target, structural, control);
176
- return { ...refined, nesting: target.nesting };
179
+ return { ...refined, level: target.level };
177
180
  }),
178
181
  ),
179
182
  ...(result.kind === "partial" ? { partial: { reason: result.reason, errorRanges: [] } } : {}),
@@ -201,13 +204,15 @@ function targetFromSymbol(file: string, symbol: DocumentCodeSymbol): DiscoveredT
201
204
  provenance: ["semantic"],
202
205
  anchorKind: (symbol.nameAnchor ? "name" : "declaration") as AnchorKind,
203
206
  container: symbol.container ?? null,
204
- nesting: normalizeNesting(symbol.nesting),
207
+ level: normalizeLevel(symbol.level),
205
208
  };
206
209
  }
207
210
 
208
211
  /** Normalize process-global or legacy provider observations at the discovery seam. */
209
- function normalizeNesting(value: unknown): DeclarationNesting {
210
- if (value === "top-level" || value === "nested" || value === "unknown") return value;
212
+ function normalizeLevel(value: unknown): DeclarationLevel {
213
+ if (value === "top-level" || value === "member" || value === "local" || value === "unknown") {
214
+ return value;
215
+ }
211
216
  return "unknown";
212
217
  }
213
218
 
@@ -238,10 +243,14 @@ async function discoverStructural(
238
243
  function flattenOutline(
239
244
  file: string,
240
245
  items: readonly OutlineData[],
241
- container: string | null = null,
242
- nesting: DeclarationNesting = "top-level",
246
+ parent: {
247
+ readonly name: string;
248
+ readonly kind: string;
249
+ readonly level: DeclarationLevel;
250
+ } | null = null,
243
251
  ): DiscoveredTargetData[] {
244
252
  return items.flatMap((item) => {
253
+ const level: DeclarationLevel = parent ? childDeclarationLevel(parent, item.kind) : "top-level";
245
254
  const nameAnchor = item.nameAnchor ?? {
246
255
  line: item.startLine,
247
256
  character: item.startCharacter,
@@ -252,6 +261,7 @@ function flattenOutline(
252
261
  displayLine: nameAnchor.line,
253
262
  displayCharacter: nameAnchor.character,
254
263
  declarationAnchor: { line: item.startLine, character: item.startCharacter },
264
+ endLine: item.endLine,
255
265
  declarationOccurrence: 0,
256
266
  name: item.name,
257
267
  kind: item.kind,
@@ -262,132 +272,10 @@ function flattenOutline(
262
272
  confidence: "structural",
263
273
  provenance: ["structural"],
264
274
  anchorKind: item.nameAnchor ? "name" : "declaration",
265
- container,
266
- nesting,
275
+ container: parent?.name ?? null,
276
+ level,
267
277
  };
268
- return [target, ...flattenOutline(file, item.children ?? [], item.name, "nested")];
269
- });
270
- }
271
-
272
- /**
273
- * Merge duplicate provider observations without collapsing repeated declarations.
274
- * Semantic facts win a matched pair while retaining both provider sources.
275
- */
276
- function mergeDiscoveries(
277
- structural: readonly DiscoveredTargetData[],
278
- semantic: readonly DiscoveredTargetData[],
279
- ): DiscoveredTargetData[] {
280
- const unmatchedSemantic = new Set(semantic.map((_target, index) => index));
281
- const mergedStructural = structural.flatMap((structuralTarget) => {
282
- const semanticIndex = findSemanticMatch(structuralTarget, semantic, unmatchedSemantic);
283
- if (semanticIndex === null) return [structuralTarget];
284
- unmatchedSemantic.delete(semanticIndex);
285
- const semanticTarget = semantic[semanticIndex];
286
- const refinedSemantic = refineLatexSectionNameAnchor(semanticTarget, structuralTarget);
287
- return [
288
- {
289
- ...refinedSemantic,
290
- provenance: ["semantic", "structural"] as const,
291
- nativeKind: structuralTarget.nativeKind ?? semanticTarget.nativeKind,
292
- container: reconcileContainer(semanticTarget, structuralTarget),
293
- nesting: reconcileNesting(semanticTarget.nesting, structuralTarget.nesting),
294
- },
295
- ];
296
- });
297
- const semanticOnly = semantic.filter((_target, index) => unmatchedSemantic.has(index));
298
- const sourceOrdered = [...mergedStructural, ...semanticOnly].sort(compareDeclarations);
299
- const identified = assignDeclarationOccurrences(sourceOrdered);
300
- return identified.sort(compareFileOrientationDeclarations);
301
- }
302
-
303
- function findSemanticMatch(
304
- structural: DiscoveredTargetData,
305
- semantic: readonly DiscoveredTargetData[],
306
- unmatched: ReadonlySet<number>,
307
- ): number | null {
308
- const matches = semantic
309
- .map((target, index) => ({ target, index }))
310
- .filter(({ target, index }) => unmatched.has(index) && sameDeclaration(target, structural))
311
- .sort(
312
- (left, right) =>
313
- Math.abs(left.target.declarationAnchor.character - structural.declarationAnchor.character) -
314
- Math.abs(
315
- right.target.declarationAnchor.character - structural.declarationAnchor.character,
316
- ) ||
317
- left.target.declarationAnchor.character - right.target.declarationAnchor.character ||
318
- compareDeclarations(left.target, right.target) ||
319
- (left.target.container ?? "").localeCompare(right.target.container ?? "") ||
320
- left.target.nesting.localeCompare(right.target.nesting) ||
321
- left.index - right.index,
322
- );
323
- return matches[0]?.index ?? null;
324
- }
325
-
326
- function sameDeclaration(left: DiscoveredTargetData, right: DiscoveredTargetData): boolean {
327
- return (
328
- canonicalFileDeclarationName(left.file, left.kind, left.name) ===
329
- canonicalFileDeclarationName(right.file, right.kind, right.name) &&
330
- compatibleContainerEvidence(left, right) &&
331
- left.declarationAnchor.line === right.declarationAnchor.line &&
332
- declarationIdentityKind(left) === declarationIdentityKind(right)
333
- );
334
- }
335
-
336
- /** Container conflicts match only when both providers report the exact declaration anchor. */
337
- function compatibleContainerEvidence(
338
- left: DiscoveredTargetData,
339
- right: DiscoveredTargetData,
340
- ): boolean {
341
- return (
342
- left.container === right.container ||
343
- left.declarationAnchor.character === right.declarationAnchor.character
344
- );
345
- }
346
-
347
- function assignDeclarationOccurrences(
348
- targets: readonly DiscoveredTargetData[],
349
- ): DiscoveredTargetData[] {
350
- const candidates = targets.map((target) => ({
351
- name: target.name,
352
- identityKind: declarationIdentityKind(target),
353
- declarationAnchor: target.declarationAnchor,
354
- nameAnchor: { line: target.displayLine, character: target.displayCharacter },
355
- container: target.container,
356
- }));
357
- const occurrences = declarationOccurrencesFor(candidates);
358
- return targets.map((target, index) => {
359
- const declarationOccurrence = occurrences[index];
360
- if (declarationOccurrence === undefined) {
361
- throw new Error("The declaration occurrence was not assigned.");
362
- }
363
- return { ...target, declarationOccurrence };
278
+ const childParent = { name: item.name, kind: item.kind, level };
279
+ return [target, ...flattenOutline(file, item.children ?? [], childParent)];
364
280
  });
365
281
  }
366
-
367
- function declarationIdentityKind(target: ResolvedTargetData): string {
368
- return (
369
- target.identityKind ??
370
- canonicalFileDeclarationKind(target.file, target.kind, target.name) ??
371
- canonicalDeclarationKind(target.kind)
372
- );
373
- }
374
-
375
- function compareFileOrientationDeclarations(
376
- left: DiscoveredTargetData,
377
- right: DiscoveredTargetData,
378
- ): number {
379
- return topLevelRank(left) - topLevelRank(right) || compareDeclarations(left, right);
380
- }
381
-
382
- function topLevelRank(target: DiscoveredTargetData): number {
383
- return target.nesting === "top-level" ? 0 : 1;
384
- }
385
-
386
- function compareDeclarations(left: ResolvedTargetData, right: ResolvedTargetData): number {
387
- return (
388
- left.displayLine - right.displayLine ||
389
- left.displayCharacter - right.displayCharacter ||
390
- (left.name ?? "").localeCompare(right.name ?? "") ||
391
- (left.kind ?? "").localeCompare(right.kind ?? "")
392
- );
393
- }
@@ -310,7 +310,11 @@ function emptySymbolOutcome(
310
310
  }
311
311
  return {
312
312
  kind: "error",
313
- message: `Symbol not found: \`${symbol}\`${scope ? ` in path \`${scope}\`` : ""}. Try \`code_resolve\` to search for it, or use an anchor target (file/line/character) if you know the location.`,
313
+ message: [
314
+ `Symbol not found: \`${symbol}\`${scope ? ` in path \`${scope}\`` : ""}.`,
315
+ "Workspace-symbol search covers only files in projects the language server has loaded; files outside them (e.g. excluded by tsconfig or in another toolchain's subtree) are not searched.",
316
+ 'Next: `code_find` with `search.ast` and `kind: "definition"` for a structural search, `code_resolve` with `target.file` if the file is known, or an anchor target (file/line/character) if the location is known.',
317
+ ].join(" "),
314
318
  };
315
319
  }
316
320
 
@@ -101,21 +101,47 @@ export interface ResolvedTargetData {
101
101
  resolution?: import("../../types/index.ts").AnchoredResolutionMetadata;
102
102
  }
103
103
 
104
+ /** Names left out of a File outline that sit on a contiguous span of lines. */
105
+ export interface FileOutlineNameSpan {
106
+ readonly count: number;
107
+ /** 1-based first and last line holding such a name. */
108
+ readonly startLine: number;
109
+ readonly endLine: number;
110
+ }
111
+
112
+ /**
113
+ * Declarations discovered in a file but left out of its File outline, counted
114
+ * so an agent can request them explicitly.
115
+ */
116
+ export interface FileOutlineNotListed {
117
+ /** Names bound by import statements; the file does not declare them. */
118
+ readonly importedNames: FileOutlineNameSpan | null;
119
+ /** Names inside `export { … }` lists, including re-exports `export { … } from`. */
120
+ readonly exportListNames: FileOutlineNameSpan | null;
121
+ /** `export … from` statements; they only forward names declared in other modules. */
122
+ readonly reExportStatements: FileOutlineNameSpan | null;
123
+ /** Declarations inside function, method, or constructor bodies. */
124
+ readonly localDeclarations: number;
125
+ }
126
+
104
127
  /**
105
- * A file-derived Target group with zero or more evidence-backed declarations.
128
+ * The File outline of one file: its top-level declarations and members,
129
+ * without imported names, export-list names, and local declarations.
106
130
  */
107
- export interface ResolvedTargetGroupData {
131
+ export interface FileOutlineData {
108
132
  file: string;
109
133
  displayName: string;
110
134
  targets: ResolvedTargetData[];
111
135
  /** Providers that successfully enumerated the selected file. */
112
136
  discoveryProvenance: readonly TargetProviderProvenance[];
113
- /** Conservative confidence across the complete group, before display capping. */
137
+ /** Conservative confidence across the complete outline, before display capping. */
114
138
  confidence: "semantic" | "structural" | "heuristic" | "unavailable";
115
- /** Complete-group declarations whose provider observations could not establish hierarchy. */
116
- unknownNestingCount: number;
139
+ /** Declarations in the complete outline whose provider reported no enclosing declaration. */
140
+ unknownLevelCount: number;
117
141
  /** Partial provider collection; targets remain usable and exact absence is not claimed. */
118
142
  partial?: { reason: string; errorRanges: readonly SourceRange[] };
143
+ /** Discovered declarations left out of `targets`, with exact counts. */
144
+ notListed: FileOutlineNotListed;
119
145
  }
120
146
 
121
147
  /**
@@ -166,7 +192,7 @@ export type TargetOutcome =
166
192
  /** Request-scoped evidence notes, such as policy exclusions beside a unique match. */
167
193
  notes?: readonly string[];
168
194
  }
169
- | { kind: "group"; group: ResolvedTargetGroupData }
195
+ | { kind: "file-outline"; outline: FileOutlineData }
170
196
  | ({
171
197
  kind: "disambiguation";
172
198
  candidates: DisambiguationCandidateData[];
package/src/api.ts CHANGED
@@ -40,8 +40,8 @@ export type {
40
40
  export type { CodeProvider, CodeProviderState } from "./analysis/provider.ts";
41
41
  // Target resolution types.
42
42
  export type {
43
+ FileOutlineData,
43
44
  ResolvedTargetData,
44
- ResolvedTargetGroupData,
45
45
  TargetOutcome,
46
46
  TargetProviderProvenance,
47
47
  } from "./analysis/target/types.ts";
package/src/app/app.ts CHANGED
@@ -72,8 +72,10 @@ export function createSessionCache(): {
72
72
  * Create the code-intelligence app and wire it to pi lifecycle events.
73
73
  *
74
74
  * Registers:
75
- * - `session_start` — creates a session for the new cwd, checks branch
76
- * for existing overview
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
77
79
  * - `session_shutdown` — releases all sessions and clears per-session stores
78
80
  */
79
81
  export function createCodeIntelligenceApp(pi: ExtensionAPI): CodeIntelligenceApp {
@@ -91,8 +93,12 @@ export function createCodeIntelligenceApp(pi: ExtensionAPI): CodeIntelligenceApp
91
93
  restoreBranchOverviewState(session, ctx.sessionManager.getBranch());
92
94
  });
93
95
 
96
+ pi.on("tool_result", (event, ctx) => {
97
+ sessions.get(ctx.cwd)?.recordToolResult(event);
98
+ });
99
+
94
100
  pi.on("session_compact", (_event, ctx) => {
95
- sessions.get(ctx.cwd)?.resetSurfacedInstructionDirs();
101
+ sessions.get(ctx.cwd)?.resetInstructionDedup();
96
102
  });
97
103
 
98
104
  pi.on("session_shutdown", () => {
@@ -5,11 +5,15 @@ import type { CodeFindMode } from "../tool/code_find/modes.ts";
5
5
 
6
6
  export type FindMode = CodeFindMode;
7
7
 
8
+ /** Exactly one search mode; each branch carries only the fields that mode honors. */
9
+ export type FindSearchInput =
10
+ | { readonly ast: { readonly kind: CodeFindAstKind; readonly query: string } }
11
+ | { readonly semantic: { readonly query: string } };
12
+
13
+ /** Canonical code_find workflow input. */
8
14
  export interface FindWorkflowInput {
9
- readonly query: string;
10
- readonly scope?: readonly string[];
11
- readonly mode: FindMode;
12
- readonly kind?: CodeFindAstKind;
15
+ readonly search: FindSearchInput;
16
+ readonly scopes?: readonly string[];
13
17
  readonly maxResults?: number;
14
18
  }
15
19