@mrclrchtr/supi-code-intelligence 9.1.1 → 10.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 (94) hide show
  1. package/README.md +24 -8
  2. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  3. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  5. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  6. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  7. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-symbol.ts +29 -0
  8. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +25 -22
  9. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  10. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  11. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  12. package/node_modules/ignore/LICENSE-MIT +21 -0
  13. package/node_modules/ignore/README.md +501 -0
  14. package/node_modules/ignore/index.d.ts +81 -0
  15. package/node_modules/ignore/index.js +1566 -0
  16. package/node_modules/ignore/legacy.js +1346 -0
  17. package/node_modules/ignore/package.json +93 -0
  18. package/node_modules/smol-toml/LICENSE +24 -0
  19. package/node_modules/smol-toml/README.md +605 -0
  20. package/node_modules/smol-toml/dist/date.d.ts +41 -0
  21. package/node_modules/smol-toml/dist/date.js +156 -0
  22. package/node_modules/smol-toml/dist/error.d.ts +37 -0
  23. package/node_modules/smol-toml/dist/error.js +67 -0
  24. package/node_modules/smol-toml/dist/extract.js +293 -0
  25. package/node_modules/smol-toml/dist/index.cjs +771 -0
  26. package/node_modules/smol-toml/dist/index.d.ts +44 -0
  27. package/node_modules/smol-toml/dist/index.js +34 -0
  28. package/node_modules/smol-toml/dist/parse.d.ts +73 -0
  29. package/node_modules/smol-toml/dist/parse.js +164 -0
  30. package/node_modules/smol-toml/dist/primitive.js +151 -0
  31. package/node_modules/smol-toml/dist/stringify.d.ts +32 -0
  32. package/node_modules/smol-toml/dist/stringify.js +219 -0
  33. package/node_modules/smol-toml/dist/struct.js +156 -0
  34. package/node_modules/smol-toml/dist/util.d.ts +43 -0
  35. package/node_modules/smol-toml/dist/util.js +57 -0
  36. package/node_modules/smol-toml/package.json +68 -0
  37. package/package.json +9 -5
  38. package/src/analysis/evidence.ts +2 -0
  39. package/src/analysis/target/symbol.ts +19 -8
  40. package/src/analysis/target/types.ts +2 -0
  41. package/src/analysis/workspace/exclusions.ts +35 -0
  42. package/src/analysis/workspace/git.ts +130 -0
  43. package/src/analysis/workspace/go-parser.ts +330 -0
  44. package/src/analysis/workspace/go.ts +154 -0
  45. package/src/analysis/workspace/index.ts +28 -0
  46. package/src/analysis/workspace/inventory.ts +316 -0
  47. package/src/analysis/workspace/membership.ts +223 -0
  48. package/src/analysis/workspace/metadata-types.ts +56 -0
  49. package/src/analysis/workspace/metadata-utils.ts +60 -0
  50. package/src/analysis/workspace/metadata.ts +148 -0
  51. package/src/analysis/workspace/node.ts +214 -0
  52. package/src/analysis/workspace/observe.ts +161 -0
  53. package/src/analysis/workspace/paths.ts +65 -0
  54. package/src/analysis/workspace/python.ts +158 -0
  55. package/src/analysis/workspace/relationships.ts +87 -0
  56. package/src/analysis/workspace/rust.ts +238 -0
  57. package/src/analysis/workspace/safe-path.ts +20 -0
  58. package/src/analysis/workspace/types.ts +245 -0
  59. package/src/app/app.ts +1 -0
  60. package/src/config.ts +4 -4
  61. package/src/extension.ts +16 -49
  62. package/src/overview/budget.ts +23 -0
  63. package/src/overview/collect.ts +22 -0
  64. package/src/session/orientation/workspace-context.ts +166 -0
  65. package/src/session/orientation-types.ts +8 -1
  66. package/src/session/orientation-workflow.ts +16 -3
  67. package/src/session/session.ts +2 -3
  68. package/src/session/target-workflow.ts +2 -0
  69. package/src/tool/code_find/execute.ts +1 -1
  70. package/src/tool/code_find/result.ts +10 -3
  71. package/src/tool/code_graph/result.ts +7 -2
  72. package/src/tool/code_orientation/execute.ts +8 -1
  73. package/src/tool/code_orientation/markdown.ts +58 -8
  74. package/src/tool/code_orientation/result.ts +17 -5
  75. package/src/tool/code_orientation/workspace-format.ts +74 -0
  76. package/src/tool/code_orientation/workspace-instructions.ts +105 -0
  77. package/src/tool/code_orientation/workspace-output.ts +118 -0
  78. package/src/tool/code_orientation/workspace-projects.ts +177 -0
  79. package/src/tool/code_orientation/workspace-sections.ts +217 -0
  80. package/src/tool/code_resolve/execute.ts +1 -1
  81. package/src/tool/code_resolve/markdown.ts +4 -1
  82. package/src/tool/code_resolve/result.ts +14 -2
  83. package/src/tool/register.ts +2 -0
  84. package/src/tool/result/candidate-row.ts +22 -0
  85. package/src/tool/result/display.ts +6 -0
  86. package/src/tool/result/errors.ts +12 -0
  87. package/src/tool/result/types.ts +2 -0
  88. package/src/types/execution.ts +2 -0
  89. package/src/ui/tui/candidate-disclosure.ts +43 -0
  90. package/src/ui/tui/candidate-selection.ts +24 -5
  91. package/src/ui/tui/common.ts +3 -0
  92. package/src/overview/overview-data.ts +0 -154
  93. package/src/overview/overview.ts +0 -91
  94. package/src/overview/types.ts +0 -23
@@ -0,0 +1,177 @@
1
+ import * as path from "node:path";
2
+ import type { ProjectDeclaration, ProjectRelationship } from "../../analysis/workspace/types.ts";
3
+ import {
4
+ type WorkspaceOrientationFacts,
5
+ within,
6
+ } from "../../session/orientation/workspace-context.ts";
7
+ import type { OrientationSectionData } from "../../session/orientation-types.ts";
8
+ import { code, plain, sourcePath, tableSection } from "./workspace-format.ts";
9
+
10
+ /** Project identities and native declarations, without inferred roles or source roots. */
11
+ export function projectSections(
12
+ facts: WorkspaceOrientationFacts,
13
+ limit: number,
14
+ descriptions: boolean,
15
+ ): OrientationSectionData[] {
16
+ const { observation, focus } = facts;
17
+ const projects = observation.projects.filter(
18
+ (project) => !focus || within(focus, path.resolve(observation.root, project.directory)),
19
+ );
20
+ const nested = projects.filter(
21
+ (project) => path.resolve(observation.root, project.directory) !== (focus ?? observation.root),
22
+ );
23
+ const header = [
24
+ "Kind",
25
+ "Name",
26
+ "Path",
27
+ "Identity source",
28
+ ...(descriptions ? ["Declared description"] : []),
29
+ ];
30
+ const result = [
31
+ tableSection("workspace.projects", "Project declarations", {
32
+ headers: header,
33
+ rows: nested.map((project) => [
34
+ project.kind,
35
+ code(project.name ?? "Unnamed declaration"),
36
+ code(sourcePath(facts, project.directory)),
37
+ code(
38
+ `${sourcePath(facts, project.manifestPath)}${project.nameField ? `#${project.nameField}` : ""}`,
39
+ ),
40
+ ...(descriptions
41
+ ? [
42
+ project.description
43
+ ? `${plain(project.description)} (${code(`${sourcePath(facts, project.manifestPath)}#${project.descriptionField}`)})`
44
+ : "—",
45
+ ]
46
+ : []),
47
+ ]),
48
+ limit,
49
+ detail: "parsed project metadata",
50
+ source: "manifest",
51
+ }),
52
+ ];
53
+ const memberships = projects.flatMap((project) =>
54
+ project.memberships.map((membership) => [
55
+ code(sourcePath(facts, project.directory)),
56
+ membership.kind,
57
+ code(`${sourcePath(facts, membership.manifestPath)}#${membership.field}`),
58
+ code(membership.value),
59
+ ]),
60
+ );
61
+ if (memberships.length > 0 && !facts.overview)
62
+ result.push(
63
+ tableSection("workspace.memberships", "Declared memberships", {
64
+ headers: ["Project", "Kind", "Source", "Value"],
65
+ rows: memberships,
66
+ limit,
67
+ detail: "workspace configuration",
68
+ source: "manifest",
69
+ }),
70
+ );
71
+ if (!focus) return result;
72
+ for (const project of projects.filter(
73
+ (project) => path.resolve(observation.root, project.directory) === focus,
74
+ )) {
75
+ result.push(declaredPaths(project, limit, facts));
76
+ const edges = observation.relationships.filter(
77
+ (edge) => edge.from === project.id || edge.to === project.id,
78
+ );
79
+ result.push(relationshipSection(project, edges, facts, limit));
80
+ const unmatched =
81
+ project.dependencies.length - edges.filter((edge) => edge.from === project.id).length;
82
+ result.push({
83
+ key: `${project.id}.other`,
84
+ title: "Other declarations",
85
+ status: "complete",
86
+ reason: null,
87
+ confidence: "unavailable",
88
+ provenance: [{ source: "manifest", detail: project.manifestPath }],
89
+ evidenceLists: [],
90
+ items: [
91
+ {
92
+ kind: "paragraph",
93
+ text: `${unmatched} dependency declarations do not match a unique observed project identity. Read ${code(sourcePath(facts, project.manifestPath))} for those declarations and other manifest fields. Name matches do not establish installed dependency resolution.`,
94
+ },
95
+ ],
96
+ });
97
+ }
98
+ return result;
99
+ }
100
+
101
+ function declaredPaths(
102
+ project: ProjectDeclaration,
103
+ limit: number,
104
+ facts: WorkspaceOrientationFacts,
105
+ ): OrientationSectionData {
106
+ const byPath = new Map<string, string[]>();
107
+ for (const entry of project.declaredPaths) {
108
+ const fields = byPath.get(entry.path) ?? [];
109
+ fields.push(entry.field);
110
+ byPath.set(entry.path, fields);
111
+ }
112
+ return tableSection(`${project.id}.paths`, "Declared paths (project-relative)", {
113
+ headers: ["Path", "Fields"],
114
+ rows: [...byPath]
115
+ .sort(([a], [b]) => a.localeCompare(b))
116
+ .map(([value, fields]) => [code(value), fields.map(code).join(", ")]),
117
+ limit,
118
+ detail: sourcePath(facts, project.manifestPath),
119
+ source: "manifest",
120
+ });
121
+ }
122
+
123
+ function relationshipSection(
124
+ project: ProjectDeclaration,
125
+ edges: readonly ProjectRelationship[],
126
+ facts: WorkspaceOrientationFacts,
127
+ limit: number,
128
+ ): OrientationSectionData {
129
+ const selected = edges.slice(0, limit);
130
+ const ids = [...new Set(selected.flatMap((edge) => [edge.from, edge.to]))].sort();
131
+ const labels = new Map(facts.observation.projects.map((entry) => [entry.id, entry]));
132
+ const lines = ["flowchart LR"];
133
+ for (const [index, id] of ids.entries()) {
134
+ const entry = labels.get(id);
135
+ lines.push(
136
+ ` n${index}["${mermaid(entry?.name ?? id)}<br/>${mermaid(entry ? sourcePath(facts, entry.directory) : id)}"]`,
137
+ );
138
+ }
139
+ for (const edge of selected) {
140
+ lines.push(
141
+ ` n${ids.indexOf(edge.from)} -->|"${mermaid(`${edge.field}: ${typeof edge.value === "string" ? edge.value : JSON.stringify(edge.value)}`)}"| n${ids.indexOf(edge.to)}`,
142
+ );
143
+ }
144
+ return {
145
+ key: `${project.id}.relationships`,
146
+ title: "Declared project relationships",
147
+ status: "complete",
148
+ reason: null,
149
+ confidence: "unavailable",
150
+ provenance: [
151
+ { source: "manifest", detail: "dependency fields in each source node's manifest" },
152
+ ],
153
+ evidenceLists: [
154
+ {
155
+ key: `${project.id}.relationships`,
156
+ totalCount: edges.length,
157
+ shownCount: selected.length,
158
+ omittedCount: edges.length - selected.length,
159
+ partialReason: null,
160
+ },
161
+ ],
162
+ items: [
163
+ {
164
+ kind: "paragraph",
165
+ text: "Each edge retains its source field and value. These are declarations, not a runtime graph or proof of installed dependency resolution.",
166
+ },
167
+ ...(selected.length ? [{ kind: "code" as const, language: "mermaid", lines }] : []),
168
+ ],
169
+ };
170
+ }
171
+
172
+ /** Mermaid entity escapes prevent repository names from creating diagram syntax. */
173
+ function mermaid(value: string): string {
174
+ return value
175
+ .replace(/\s+/g, " ")
176
+ .replace(/[#"<>`&|\\\p{Cc}\p{Cf}]/gu, (character) => `#${character.codePointAt(0) ?? 0};`);
177
+ }
@@ -0,0 +1,217 @@
1
+ import * as path from "node:path";
2
+ import type { InventoryEntry, WorkspaceObservation } from "../../analysis/workspace/types.ts";
3
+ import {
4
+ type WorkspaceOrientationFacts,
5
+ within,
6
+ } from "../../session/orientation/workspace-context.ts";
7
+ import type {
8
+ OrientationResultData,
9
+ OrientationSectionData,
10
+ } from "../../session/orientation-types.ts";
11
+ import { code, plain, sourcePath, tableSection } from "./workspace-format.ts";
12
+ import { projectSections } from "./workspace-projects.ts";
13
+
14
+ /** Build output facts from one captured observation, with no filesystem reads. */
15
+ export function workspaceSections(
16
+ data: OrientationResultData,
17
+ limit: number,
18
+ descriptions: boolean,
19
+ ): OrientationResultData {
20
+ const facts = data.workspace;
21
+ if (!facts) return data;
22
+ const { observation, focus, overview } = facts;
23
+ const root = focus ?? observation.root;
24
+ const entries = observation.inventory.entries
25
+ .filter((entry) => within(root, path.resolve(observation.root, entry.path)))
26
+ .map((entry) => ({
27
+ ...entry,
28
+ path: path
29
+ .relative(root, path.resolve(observation.root, entry.path))
30
+ .replaceAll(path.sep, "/"),
31
+ }));
32
+ const projects = containingProjects(facts, root);
33
+ const title = focus
34
+ ? `Directory Orientation: ${code(display(facts.cwd, focus))}`
35
+ : `${overview ? "Workspace Overview" : "Workspace Orientation"}: ${projects.map((project) => plain(project.name ?? project.manifestPath)).join(" / ") || plain(display(facts.cwd, root))}`;
36
+ const notes = [
37
+ `Root: ${code(display(facts.cwd, observation.root))}${focus ? "" : " (session working directory)"}.`,
38
+ ];
39
+ for (const project of projects) {
40
+ notes.push(
41
+ `Project: ${code(project.name ?? "Unnamed declaration")} (${project.kind}); source: ${code(sourcePath(facts, project.manifestPath))}.`,
42
+ );
43
+ if (project.description && descriptions)
44
+ notes.push(
45
+ `Declared description (${code(`${sourcePath(facts, project.manifestPath)}#${project.descriptionField}`)}): ${plain(project.description)}`,
46
+ );
47
+ }
48
+ notes.push(inventoryNote(entries, facts));
49
+ if (!descriptions && observation.projects.some((project) => project.description)) {
50
+ notes.push(
51
+ "Declared descriptions are omitted to preserve names and paths. They remain in the captured result.",
52
+ );
53
+ }
54
+ const sections = inventorySections(entries, facts, limit);
55
+ sections.push(...projectSections(facts, limit, descriptions));
56
+ const issues = [
57
+ ...observation.collection.errors
58
+ .filter(
59
+ (error) =>
60
+ error.stage !== "metadata" ||
61
+ !observation.metadata.issues.some(
62
+ (issue) => issue.path === error.path && issue.reason === error.reason,
63
+ ),
64
+ )
65
+ .map((error) => `${error.stage}: ${sourcePath(facts, error.path ?? ".")}: ${error.reason}`),
66
+ ...observation.metadata.issues.map(
67
+ (issue) =>
68
+ `${sourcePath(facts, issue.path)}${issue.field ? `#${issue.field}` : ""}: ${issue.kind}: ${issue.reason}`,
69
+ ),
70
+ ];
71
+ if (issues.length > 0)
72
+ sections.push(
73
+ tableSection("workspace.issues", "Collection limits", {
74
+ headers: ["Observation"],
75
+ rows: [...new Set(issues)].map((issue) => [plain(issue)]),
76
+ limit,
77
+ detail: "captured collection",
78
+ }),
79
+ );
80
+ // Instruction text is independent of the navigation budget and list cap.
81
+ const instructions = data.sections.filter((section) => section.key === "instructions");
82
+ const resultSections = [
83
+ ...instructions,
84
+ ...sections.map((section) => collectionStatus(section, observation)),
85
+ ];
86
+ return {
87
+ ...data,
88
+ title,
89
+ notes,
90
+ sections: resultSections,
91
+ renderedSections: resultSections.map((section) => section.key),
92
+ omittedCount: sections.reduce(
93
+ (sum, section) =>
94
+ sum + section.evidenceLists.reduce((total, list) => total + (list.omittedCount ?? 0), 0),
95
+ 0,
96
+ ),
97
+ };
98
+ }
99
+
100
+ function collectionStatus(
101
+ section: OrientationSectionData,
102
+ observation: WorkspaceObservation,
103
+ ): OrientationSectionData {
104
+ if (section.key === "workspace.issues") return section;
105
+ const { collection } = observation;
106
+ const inventoryPartial =
107
+ collection.stopReason !== "complete" ||
108
+ collection.errors.some((error) => error.stage === "inventory");
109
+ const partial = section.provenance.some((source) => source.source === "filesystem")
110
+ ? inventoryPartial
111
+ : collection.status === "partial";
112
+ if (!partial) return section;
113
+ const reason =
114
+ collection.stopReason === "entry-limit"
115
+ ? "safety-limit"
116
+ : collection.stopReason === "deadline"
117
+ ? "timeout"
118
+ : inventoryPartial
119
+ ? "filesystem-error"
120
+ : "configuration-error";
121
+ return {
122
+ ...section,
123
+ status: "partial",
124
+ reason: inventoryPartial
125
+ ? "Inventory collection is incomplete"
126
+ : "Metadata collection is incomplete",
127
+ evidenceLists: section.evidenceLists.map((list) => ({
128
+ ...list,
129
+ totalCount: null,
130
+ partialReason: reason,
131
+ })),
132
+ };
133
+ }
134
+
135
+ function containingProjects(facts: WorkspaceOrientationFacts, root: string) {
136
+ const candidates = facts.observation.projects.filter((project) =>
137
+ within(path.resolve(facts.observation.root, project.directory), root),
138
+ );
139
+ const depth = Math.max(
140
+ -1,
141
+ ...candidates.map((project) => path.resolve(facts.observation.root, project.directory).length),
142
+ );
143
+ return candidates.filter(
144
+ (project) => path.resolve(facts.observation.root, project.directory).length === depth,
145
+ );
146
+ }
147
+
148
+ function inventoryNote(
149
+ entries: readonly InventoryEntry[],
150
+ facts: WorkspaceOrientationFacts,
151
+ ): string {
152
+ const files = entries.filter((entry) => entry.kind === "file").length;
153
+ const links = entries.length - files;
154
+ const { inclusion, collection } = facts.observation;
155
+ const policy =
156
+ inclusion.source === "git"
157
+ ? inclusion.includeIgnored
158
+ ? "Git-tracked and untracked paths, including ignored paths for this explicit focus"
159
+ : "Git-tracked and non-ignored untracked paths"
160
+ : "accessible filesystem paths";
161
+ const exclusions = inclusion.exclude.length
162
+ ? ` Explicit exclusions: ${inclusion.exclude.map(code).join(", ")}.`
163
+ : "";
164
+ return `Inventory: ${files} regular file${files === 1 ? "" : "s"} and ${links} symbolic links. Includes ${policy}; link targets are not followed.${exclusions} Collection ${collection.status}${collection.stopReason !== "complete" ? ` (${collection.stopReason}; more entries may exist)` : ""}.`;
165
+ }
166
+
167
+ function inventorySections(
168
+ entries: readonly InventoryEntry[],
169
+ facts: WorkspaceOrientationFacts,
170
+ limit: number,
171
+ ): OrientationSectionData[] {
172
+ const directories = new Map<string, number>();
173
+ const extensions = new Map<string, number>();
174
+ for (const entry of entries) {
175
+ const parts = entry.path.split("/");
176
+ if (parts.length > 1) directories.set(parts[0], (directories.get(parts[0]) ?? 0) + 1);
177
+ if (entry.kind === "file") {
178
+ const extension = path.posix.extname(entry.path);
179
+ extensions.set(extension, (extensions.get(extension) ?? 0) + 1);
180
+ }
181
+ }
182
+ const directFiles = entries.filter((entry) => !entry.path.includes("/"));
183
+ const sections = [
184
+ tableSection("workspace.directories", "Direct directories", {
185
+ headers: ["Path", "Entries at all depths"],
186
+ rows: [...directories]
187
+ .sort(([a], [b]) => a.localeCompare(b))
188
+ .map(([name, count]) => [code(`${name}/`), String(count)]),
189
+ limit,
190
+ detail: "included paths",
191
+ }),
192
+ ];
193
+ if (directFiles.length > 0 || !facts.overview)
194
+ sections.push(
195
+ tableSection("workspace.files", "Direct files", {
196
+ headers: ["Path", "Kind"],
197
+ rows: directFiles.map((entry) => [code(entry.path), entry.kind]),
198
+ limit: facts.overview ? Math.min(5, limit) : limit,
199
+ detail: "included paths",
200
+ }),
201
+ );
202
+ sections.push(
203
+ tableSection("workspace.extensions", "File extensions (filenames, not language support)", {
204
+ headers: ["Extension", "Regular files"],
205
+ rows: [...extensions]
206
+ .sort(([a, an], [b, bn]) => bn - an || a.localeCompare(b))
207
+ .map(([extension, count]) => [extension ? code(extension) : "No extension", String(count)]),
208
+ limit: facts.overview ? Math.min(5, limit) : limit,
209
+ detail: "included regular files",
210
+ }),
211
+ );
212
+ return sections;
213
+ }
214
+
215
+ export function display(cwd: string, target: string): string {
216
+ return path.relative(cwd, target).replaceAll(path.sep, "/") || ".";
217
+ }
@@ -15,5 +15,5 @@ export async function executeResolveTool(
15
15
  ctx: CodeIntelToolExecCtx,
16
16
  ): Promise<CodeIntelResult> {
17
17
  const outcome = await ctx.session.resolve(params, toWorkflowControl(ctx));
18
- return finishResolveResult(outcome, ctx.cwd);
18
+ return finishResolveResult(outcome, ctx.cwd, params.target);
19
19
  }
@@ -3,6 +3,7 @@
3
3
  import { relative } from "node:path";
4
4
  import { renderEvidenceListMetadataDisclosure } from "../../analysis/evidence.ts";
5
5
  import type { TargetStoreEntry } from "../../session/target-store.ts";
6
+ import { formatPartialCandidateDisclosure } from "../result/candidate-row.ts";
6
7
  import type { ResolveDetails } from "../result/types.ts";
7
8
  import type { ResolveResultAssembly } from "./result.ts";
8
9
 
@@ -155,6 +156,8 @@ function appendCandidates(lines: string[], details: ResolveDetails): void {
155
156
 
156
157
  function appendDisclosure(lines: string[], details: ResolveDetails): void {
157
158
  const evidence = details.evidenceLists?.[0];
158
- const disclosure = evidence ? renderEvidenceListMetadataDisclosure(evidence) : null;
159
+ const disclosure = evidence
160
+ ? (formatPartialCandidateDisclosure(evidence) ?? renderEvidenceListMetadataDisclosure(evidence))
161
+ : null;
159
162
  if (disclosure) lines.push("", disclosure);
160
163
  }
@@ -2,6 +2,7 @@ import { relative } from "node:path";
2
2
  import type { ConfidenceMode } from "@mrclrchtr/supi-code-runtime/api";
3
3
  import type { EvidenceListMetadata } from "../../analysis/evidence.ts";
4
4
  import { createEvidenceList } from "../../analysis/evidence.ts";
5
+ import type { ResolveTargetInput } from "../../session/target-input.ts";
5
6
  import type { TargetStoreEntry } from "../../session/target-store.ts";
6
7
  import type { TargetWorkflowOutcome } from "../../session/target-workflow.ts";
7
8
  import {
@@ -12,6 +13,7 @@ import {
12
13
  } from "../result/assembly.ts";
13
14
  import { formatCandidateRow } from "../result/candidate-row.ts";
14
15
  import { createToolDisplaySection } from "../result/display.ts";
16
+ import { scopedSymbolFailureMessage } from "../result/errors.ts";
15
17
  import type { ResolveDetails, ToolDisplaySection } from "../result/types.ts";
16
18
 
17
19
  /** Presentation-neutral assembled code_resolve result. */
@@ -160,6 +162,7 @@ function projectCandidateOutcome(
160
162
  shownCount: outcome.candidates.length,
161
163
  omittedCount: outcome.omittedCount,
162
164
  partialReason: outcome.partialReason,
165
+ partialMessage: outcome.partialMessage,
163
166
  };
164
167
  const collectedCount = evidence.shownCount + (evidence.omittedCount ?? 0);
165
168
  const mismatch = outcome.kind === "kind-mismatch";
@@ -265,6 +268,7 @@ function resolveDisplaySections(details: ResolveDetails): ToolDisplaySection[] {
265
268
  totalCount: evidence.totalCount,
266
269
  omittedCount: evidence.omittedCount,
267
270
  partialReason: evidence.partialReason,
271
+ partialMessage: evidence.partialMessage,
268
272
  format: (candidate) => formatCandidateRow(candidate, "rank-first"),
269
273
  }),
270
274
  ];
@@ -298,9 +302,17 @@ import { renderResolveResult } from "./markdown.ts";
298
302
  type ResolveOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["resolve"]>>;
299
303
 
300
304
  /** Assemble the final model-visible code_resolve result for one workflow outcome. */
301
- export function finishResolveResult(outcome: ResolveOutcome, cwd: string): CodeIntelResult {
305
+ export function finishResolveResult(
306
+ outcome: ResolveOutcome,
307
+ cwd: string,
308
+ target?: ResolveTargetInput,
309
+ ): CodeIntelResult {
302
310
  if (outcome.kind === "unavailable") {
303
- throw new Error(outcome.reason);
311
+ const reason =
312
+ target && "symbol" in target && target.symbol.scope
313
+ ? scopedSymbolFailureMessage(outcome.reason)
314
+ : outcome.reason;
315
+ throw new Error(reason);
304
316
  }
305
317
 
306
318
  const assembly = assembleResolveResult(outcome, cwd);
@@ -5,6 +5,7 @@ import {
5
5
  startDebugTimer,
6
6
  truncateDebugIdentity as truncateIdentity,
7
7
  } from "@mrclrchtr/supi-core/debug";
8
+ import { reportWorkspaceBudget } from "../overview/budget.ts";
8
9
  import type { WorkspaceCodeIntelligenceSession } from "../session/session.ts";
9
10
  import {
10
11
  CODE_INTELLIGENCE_TOOL_PROMPT_SURFACES,
@@ -129,6 +130,7 @@ export function registerCodeIntelligenceTools(
129
130
  cwd: ctx.cwd,
130
131
  outcome: "completed",
131
132
  });
133
+ reportWorkspaceBudget(ctx, details?.budgetWarning, operationId);
132
134
  return boundCodeToolResult(content, details, {
133
135
  toolName: spec.name,
134
136
  maxLines: spec.maxLines,
@@ -1,3 +1,5 @@
1
+ import type { EvidenceListMetadata } from "../../analysis/evidence.ts";
2
+
1
3
  /** Candidate fields used by the three target-selection row formats. */
2
4
  export interface CandidateRowData {
3
5
  readonly targetId: string;
@@ -25,3 +27,23 @@ export function formatCandidateRow(
25
27
  const rank = candidate.rank && candidate.rank > 0 ? candidate.rank : fallbackRank;
26
28
  return `${rank}. ${candidate.name} (${kind}) — ${candidate.file}:${candidate.line}:${candidate.character} [${candidate.targetId}]`;
27
29
  }
30
+
31
+ /** Separate display omissions from incomplete provider collection in candidate output. */
32
+ export function formatPartialCandidateDisclosure(
33
+ evidence: Pick<
34
+ EvidenceListMetadata,
35
+ "shownCount" | "totalCount" | "omittedCount" | "partialMessage"
36
+ >,
37
+ ): string | null {
38
+ if (evidence.totalCount !== null || !evidence.partialMessage) return null;
39
+ const { shownCount, omittedCount, partialMessage } = evidence;
40
+ const collectedCount = shownCount + (omittedCount ?? 0);
41
+ const noun = collectedCount === 1 ? "candidate" : "candidates";
42
+ const count =
43
+ omittedCount === null
44
+ ? `${shownCount} collected ${noun}.`
45
+ : omittedCount === 0
46
+ ? `all ${shownCount} collected ${noun}.`
47
+ : `${shownCount} of ${collectedCount} collected ${noun}; ${omittedCount} omitted.`;
48
+ return `Showing ${count}\nSearch completeness is unknown: ${partialMessage}`;
49
+ }
@@ -15,6 +15,8 @@ export interface ToolDisplaySectionInput<T> {
15
15
  totalCount?: number | null;
16
16
  omittedCount?: number | null;
17
17
  partialReason?: string | null;
18
+ /** Provider explanation for incomplete collection, when available. */
19
+ partialMessage?: string;
18
20
  maxItems?: number;
19
21
  }
20
22
 
@@ -42,6 +44,7 @@ export function createToolDisplaySection<T>(input: ToolDisplaySectionInput<T>):
42
44
  totalCount,
43
45
  omittedCount,
44
46
  partialReason: input.partialReason ?? null,
47
+ ...(input.partialMessage === undefined ? {} : { partialMessage: input.partialMessage }),
45
48
  };
46
49
  }
47
50
 
@@ -89,6 +92,9 @@ export function readToolDisplaySections(value: unknown): ToolDisplaySection[] {
89
92
  totalCount: record.totalCount,
90
93
  omittedCount: record.omittedCount,
91
94
  partialReason: record.partialReason,
95
+ ...(typeof record.partialMessage === "string"
96
+ ? { partialMessage: record.partialMessage }
97
+ : {}),
92
98
  },
93
99
  ];
94
100
  });
@@ -3,6 +3,18 @@ import type { EvidenceListMetadata } from "../../analysis/evidence.ts";
3
3
  import type { CodeIntelResult, ToolDisplaySection } from "../../types/index.ts";
4
4
  import { assembledNextQueries, assembleToolResult } from "./assembly.ts";
5
5
 
6
+ /** Keep the failure reason and suggest same-session recovery for a scoped symbol query. */
7
+ export function scopedSymbolFailureMessage(reason: string): string {
8
+ return [
9
+ reason,
10
+ "",
11
+ "Next steps:",
12
+ "- If a source file in this scope is known, use `code_resolve` with `target.file`. This can start a missing LSP route and return declaration handles.",
13
+ "- If the file is unknown, use `bash` to locate a source file in the requested scope first.",
14
+ "- Use a returned handle directly, or retry the scoped symbol query. Opening one file does not confirm that the full workspace index is ready.",
15
+ ].join("\n");
16
+ }
17
+
6
18
  /** Full failure or candidate-selection result for search-family tools. */
7
19
  export function searchErrorResult(
8
20
  content: string,
@@ -41,6 +41,8 @@ export interface ToolDisplaySection {
41
41
  totalCount: number | null;
42
42
  omittedCount: number | null;
43
43
  partialReason: string | null;
44
+ /** Provider explanation for incomplete collection, when available. */
45
+ partialMessage?: string;
44
46
  }
45
47
 
46
48
  // ── Anchored coordinate resolution metadata ───────────────────────────
@@ -51,6 +51,8 @@ export interface CodeIntelResultDetails {
51
51
  message?: string;
52
52
  displaySections?: readonly ToolDisplaySection[];
53
53
  truncation?: ToolOutputTruncationDetails;
54
+ /** UI/debug-only soft-budget warning; never part of model content. */
55
+ budgetWarning?: import("../tool/code_orientation/workspace-output.ts").WorkspaceBudgetWarning;
54
56
  }
55
57
 
56
58
  /** Tool result shape returned by executeAction. */
@@ -0,0 +1,43 @@
1
+ import { stripVTControlCharacters } from "node:util";
2
+ import type { Theme } from "@earendil-works/pi-coding-agent";
3
+ import { type Component, Text } from "@earendil-works/pi-tui";
4
+
5
+ const MAX_DISCLOSURE_CHARACTERS = 4096;
6
+ const MAX_COLLAPSED_ROWS = 3;
7
+ const MAX_EXPANDED_ROWS = 10;
8
+
9
+ /** Limit candidate disclosure text without changing the full saved provider reason. */
10
+ export class BoundedCandidateDisclosure implements Component {
11
+ private readonly text: string;
12
+ private readonly sourceLimited: boolean;
13
+
14
+ constructor(
15
+ text: string,
16
+ private readonly expanded: boolean,
17
+ private readonly theme: Theme,
18
+ ) {
19
+ const plain = stripVTControlCharacters(text)
20
+ .replace(/\r\n?/g, "\n")
21
+ .replace(/\t/g, " ")
22
+ .replace(/[\p{Cc}\p{Bidi_Control}]/gu, (character) => (character === "\n" ? character : ""));
23
+ this.text = plain.slice(0, MAX_DISCLOSURE_CHARACTERS);
24
+ this.sourceLimited = plain.length > MAX_DISCLOSURE_CHARACTERS;
25
+ }
26
+
27
+ render(width: number): string[] {
28
+ const safeWidth = Math.max(1, width);
29
+ const rows = new Text(this.theme.fg("muted", this.text), 0, 0).render(safeWidth);
30
+ const maxRows = this.expanded ? MAX_EXPANDED_ROWS : MAX_COLLAPSED_ROWS;
31
+ if (!this.sourceLimited && rows.length <= maxRows) return rows;
32
+ const notice = this.expanded
33
+ ? "Provider reason limited for display."
34
+ : "Provider reason limited; expand for more.";
35
+ return [
36
+ ...rows.slice(0, maxRows),
37
+ ...new Text(this.theme.fg("dim", notice), 0, 0).render(safeWidth),
38
+ ];
39
+ }
40
+
41
+ /** Text and theme formatting are rebuilt for each render. */
42
+ invalidate(): void {}
43
+ }