@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,316 @@
1
+ /** Bounded Git and filesystem inventory collection for workspace observation. */
2
+
3
+ import { type Dirent, promises as fs } from "node:fs";
4
+ import * as path from "node:path";
5
+ import type { CodeRequestControl } from "@mrclrchtr/supi-code-runtime/api";
6
+ import { createExclusionMatcher, type ExclusionMatcher } from "./exclusions.ts";
7
+ import { readGitPaths } from "./git.ts";
8
+ import {
9
+ compareObservationPaths,
10
+ errorMessage,
11
+ isWithinRoot,
12
+ joinRelative,
13
+ normalizeInventoryPath,
14
+ } from "./paths.ts";
15
+ import { assertUnlinkedPath } from "./safe-path.ts";
16
+ import type {
17
+ InventoryEntry,
18
+ InventorySource,
19
+ InventoryStopReason,
20
+ WorkspaceObservationError,
21
+ } from "./types.ts";
22
+
23
+ /** Default retained-entry cap for one observation. */
24
+ export const DEFAULT_MAX_INVENTORY_ENTRIES = 10_000;
25
+
26
+ /** Internal inventory result before metadata collection. */
27
+ export interface InventoryCollectionResult {
28
+ readonly source: InventorySource;
29
+ readonly entries: readonly InventoryEntry[];
30
+ readonly stopReason: InventoryStopReason;
31
+ readonly errors: readonly WorkspaceObservationError[];
32
+ }
33
+
34
+ /** Options owned by inventory collection. */
35
+ export interface InventoryOptions {
36
+ readonly exclude: readonly string[];
37
+ readonly includeIgnored: boolean;
38
+ readonly maxEntries: number;
39
+ readonly prioritizedDirectory: string | null;
40
+ readonly control?: CodeRequestControl;
41
+ }
42
+
43
+ /** Collect tracked plus non-ignored untracked paths, or accessible files outside Git. */
44
+ export async function collectInventory(
45
+ root: string,
46
+ options: InventoryOptions,
47
+ ): Promise<InventoryCollectionResult> {
48
+ options.control?.signal?.throwIfAborted();
49
+ const errors: WorkspaceObservationError[] = [];
50
+ const exclusions = createExclusionMatcher(options.exclude, errors);
51
+ const maxEntries = normalizeLimit(options.maxEntries);
52
+ if (deadlineReached(options.control)) {
53
+ return { source: "filesystem", entries: [], stopReason: "deadline", errors };
54
+ }
55
+
56
+ const context: InventoryContext = {
57
+ root,
58
+ exclusions,
59
+ maxEntries,
60
+ prioritizedDirectory: options.prioritizedDirectory,
61
+ control: options.control,
62
+ errors,
63
+ };
64
+ const rootError = await inspectRoot(root);
65
+ if (rootError)
66
+ return {
67
+ source: "filesystem",
68
+ entries: [],
69
+ stopReason: "complete",
70
+ errors: [...errors, rootError],
71
+ };
72
+ const git = await readGitPaths(root, options.includeIgnored, options.control);
73
+ if (git.kind === "git") return classifyGitPaths(context, git.paths);
74
+ if (git.kind === "deadline") {
75
+ return { source: "git", entries: [], stopReason: "deadline", errors };
76
+ }
77
+ if (git.kind === "unavailable") {
78
+ errors.push({
79
+ stage: "inventory",
80
+ path: null,
81
+ reason: `Git inventory unavailable: ${git.reason}`,
82
+ });
83
+ return { source: "git", entries: [], stopReason: "complete", errors };
84
+ }
85
+ if (git.kind === "missing-command")
86
+ errors.push({
87
+ stage: "inventory",
88
+ path: null,
89
+ reason: "Git is unavailable; filesystem inventory cannot apply Git ignore rules.",
90
+ });
91
+ return collectFilesystem(context);
92
+ }
93
+
94
+ interface InventoryContext {
95
+ readonly root: string;
96
+ readonly exclusions: ExclusionMatcher;
97
+ readonly maxEntries: number;
98
+ readonly prioritizedDirectory: string | null;
99
+ readonly control: CodeRequestControl | undefined;
100
+ readonly errors: WorkspaceObservationError[];
101
+ }
102
+
103
+ async function classifyGitPaths(
104
+ context: InventoryContext,
105
+ paths: readonly string[],
106
+ ): Promise<InventoryCollectionResult> {
107
+ const entries: InventoryEntry[] = [];
108
+ let stopReason: InventoryStopReason = "complete";
109
+ for (const rawPath of [...paths].sort((left, right) =>
110
+ compareObservationPaths(left, right, context.prioritizedDirectory),
111
+ )) {
112
+ context.control?.signal?.throwIfAborted();
113
+ if (deadlineReached(context.control)) {
114
+ stopReason = "deadline";
115
+ break;
116
+ }
117
+ const relativePath = normalizeInventoryPath(context.root, rawPath);
118
+ if (!relativePath) {
119
+ context.errors.push({
120
+ stage: "inventory",
121
+ path: rawPath,
122
+ reason: "Git returned a path outside the requested root.",
123
+ });
124
+ continue;
125
+ }
126
+ if (context.exclusions.matches(relativePath, false)) continue;
127
+ const entry = await classifyGitEntry(context, relativePath);
128
+ if (!entry) continue;
129
+ if (entries.length >= context.maxEntries) {
130
+ stopReason = "entry-limit";
131
+ break;
132
+ }
133
+ entries.push(entry);
134
+ }
135
+ return { source: "git", entries: sortEntries(entries), stopReason, errors: context.errors };
136
+ }
137
+
138
+ async function classifyGitEntry(
139
+ context: InventoryContext,
140
+ relativePath: string,
141
+ ): Promise<InventoryEntry | null> {
142
+ const absolutePath = path.join(context.root, ...relativePath.split("/"));
143
+ if (!isWithinRoot(context.root, absolutePath)) return null;
144
+ try {
145
+ await assertUnlinkedPath(context.root, relativePath);
146
+ const stats = await fs.lstat(absolutePath);
147
+ if (stats.isSymbolicLink()) return { path: relativePath, kind: "symlink" };
148
+ if (stats.isFile()) return { path: relativePath, kind: "file" };
149
+ context.errors.push({
150
+ stage: "inventory",
151
+ path: relativePath,
152
+ reason: "Git entry is not a regular file or symbolic link.",
153
+ });
154
+ return null;
155
+ } catch (error) {
156
+ context.errors.push({
157
+ stage: "inventory",
158
+ path: relativePath,
159
+ reason: `Could not inspect Git entry: ${errorMessage(error)}`,
160
+ });
161
+ return null;
162
+ }
163
+ }
164
+
165
+ async function collectFilesystem(context: InventoryContext): Promise<InventoryCollectionResult> {
166
+ const rootCheck = await inspectRoot(context.root);
167
+ if (rootCheck) {
168
+ return {
169
+ source: "filesystem",
170
+ entries: [],
171
+ stopReason: "complete",
172
+ errors: [rootCheck, ...context.errors],
173
+ };
174
+ }
175
+
176
+ const entries: InventoryEntry[] = [];
177
+ const pending: string[] = ["."];
178
+ const priority = context.prioritizedDirectory;
179
+ if (priority && !context.exclusions.matches(priority, true)) pending.push(priority);
180
+ const visited = new Set<string>();
181
+ let stopReason: InventoryStopReason = "complete";
182
+ while (pending.length > 0) {
183
+ context.control?.signal?.throwIfAborted();
184
+ if (deadlineReached(context.control)) {
185
+ stopReason = "deadline";
186
+ break;
187
+ }
188
+ const directory = pending.pop() ?? ".";
189
+ if (visited.has(directory)) continue;
190
+ visited.add(directory);
191
+ let children: Dirent[];
192
+ try {
193
+ await assertUnlinkedPath(context.root, directory, true);
194
+ children = await fs.readdir(resolveRelative(context.root, directory), {
195
+ withFileTypes: true,
196
+ });
197
+ } catch (error) {
198
+ context.errors.push({
199
+ stage: "inventory",
200
+ path: directory,
201
+ reason: `Could not read directory: ${errorMessage(error)}`,
202
+ });
203
+ continue;
204
+ }
205
+ const visit = await visitChildren(context, directory, children, entries);
206
+ pending.push(...visit.directories.reverse());
207
+ if (visit.stopReason !== "complete") {
208
+ stopReason = visit.stopReason;
209
+ break;
210
+ }
211
+ }
212
+ return {
213
+ source: "filesystem",
214
+ entries: sortEntries(entries),
215
+ stopReason,
216
+ errors: context.errors,
217
+ };
218
+ }
219
+
220
+ interface ChildVisitResult {
221
+ readonly directories: string[];
222
+ readonly stopReason: InventoryStopReason;
223
+ }
224
+
225
+ async function visitChildren(
226
+ context: InventoryContext,
227
+ directory: string,
228
+ children: readonly Dirent[],
229
+ entries: InventoryEntry[],
230
+ ): Promise<ChildVisitResult> {
231
+ const directories: string[] = [];
232
+ for (const child of [...children].sort((left, right) => left.name.localeCompare(right.name))) {
233
+ context.control?.signal?.throwIfAborted();
234
+ if (deadlineReached(context.control)) return { directories, stopReason: "deadline" };
235
+ const relativePath = joinRelative(directory, child.name);
236
+ if (child.isDirectory()) {
237
+ if (!context.exclusions.matches(relativePath, true)) directories.push(relativePath);
238
+ continue;
239
+ }
240
+ if (context.exclusions.matches(relativePath, false)) continue;
241
+ const kind = await classifyDirent(context, relativePath, child);
242
+ if (!kind) continue;
243
+ if (entries.length >= context.maxEntries) return { directories, stopReason: "entry-limit" };
244
+ entries.push({ path: relativePath, kind });
245
+ }
246
+ return { directories, stopReason: "complete" };
247
+ }
248
+
249
+ async function classifyDirent(
250
+ context: InventoryContext,
251
+ relativePath: string,
252
+ child: Dirent,
253
+ ): Promise<InventoryEntry["kind"] | null> {
254
+ if (child.isSymbolicLink()) return "symlink";
255
+ if (child.isFile()) return "file";
256
+ try {
257
+ const stats = await fs.lstat(resolveRelative(context.root, relativePath));
258
+ if (stats.isSymbolicLink()) return "symlink";
259
+ if (stats.isFile()) return "file";
260
+ } catch (error) {
261
+ context.errors.push({
262
+ stage: "inventory",
263
+ path: relativePath,
264
+ reason: `Could not inspect entry: ${errorMessage(error)}`,
265
+ });
266
+ return null;
267
+ }
268
+ context.errors.push({
269
+ stage: "inventory",
270
+ path: relativePath,
271
+ reason: "Entry is not a regular file or symbolic link.",
272
+ });
273
+ return null;
274
+ }
275
+
276
+ async function inspectRoot(root: string): Promise<WorkspaceObservationError | null> {
277
+ try {
278
+ const stats = await fs.lstat(root);
279
+ if (stats.isSymbolicLink()) {
280
+ return {
281
+ stage: "inventory",
282
+ path: ".",
283
+ reason: "The observation root is a symbolic link; it is not followed.",
284
+ };
285
+ }
286
+ if (!stats.isDirectory()) {
287
+ return { stage: "inventory", path: ".", reason: "The observation root is not a directory." };
288
+ }
289
+ return null;
290
+ } catch (error) {
291
+ return {
292
+ stage: "inventory",
293
+ path: ".",
294
+ reason: `Could not inspect the observation root: ${errorMessage(error)}`,
295
+ };
296
+ }
297
+ }
298
+
299
+ function resolveRelative(root: string, relativePath: string): string {
300
+ if (relativePath === ".") return root;
301
+ return path.join(root, ...relativePath.split("/"));
302
+ }
303
+
304
+ function normalizeLimit(value: number): number {
305
+ if (!Number.isFinite(value)) return Number.MAX_SAFE_INTEGER;
306
+ return Math.max(0, Math.floor(value));
307
+ }
308
+
309
+ function deadlineReached(control: CodeRequestControl | undefined): boolean {
310
+ const deadline = control?.deadline;
311
+ return typeof deadline === "number" && Number.isFinite(deadline) && Date.now() >= deadline;
312
+ }
313
+
314
+ function sortEntries(entries: readonly InventoryEntry[]): InventoryEntry[] {
315
+ return [...entries].sort((left, right) => left.path.localeCompare(right.path));
316
+ }
@@ -0,0 +1,223 @@
1
+ /** Explicit workspace-membership resolution. Directory adjacency is never used. */
2
+
3
+ import * as path from "node:path";
4
+ import type { WorkspaceConfig } from "./metadata-types.ts";
5
+ import { issue } from "./metadata-utils.ts";
6
+ import { normalizeRelativePath } from "./paths.ts";
7
+ import type { MetadataIssue, ProjectDeclaration, ProjectMembership } from "./types.ts";
8
+
9
+ interface CompiledPattern {
10
+ readonly value: string;
11
+ readonly negative: boolean;
12
+ readonly glob: string;
13
+ }
14
+
15
+ interface CompiledConfig {
16
+ readonly config: WorkspaceConfig;
17
+ readonly patterns: readonly CompiledPattern[];
18
+ readonly excludes: readonly CompiledPattern[];
19
+ }
20
+
21
+ /** Attach explicit memberships to projects without inferring from directory layout. */
22
+ export function applyMemberships(
23
+ projects: readonly ProjectDeclaration[],
24
+ configs: readonly WorkspaceConfig[],
25
+ issues: MetadataIssue[],
26
+ ): ProjectDeclaration[] {
27
+ const compiled = configs.map((config) => compileConfig(config, issues));
28
+ const goMatches = new Map<string, Set<string>>();
29
+ const result = projects.map((project) => ({
30
+ ...project,
31
+ memberships: membershipsForProject(project, compiled, goMatches),
32
+ }));
33
+ reportUnmatchedGoUses(compiled, goMatches, issues);
34
+ return result;
35
+ }
36
+
37
+ function compileConfig(config: WorkspaceConfig, issues: MetadataIssue[]): CompiledConfig {
38
+ return {
39
+ config,
40
+ patterns: compilePatterns(config, config.patterns, issues),
41
+ excludes: compilePatterns(config, config.excludes, issues),
42
+ };
43
+ }
44
+
45
+ function compilePatterns(
46
+ config: WorkspaceConfig,
47
+ values: readonly string[],
48
+ issues: MetadataIssue[],
49
+ ): CompiledPattern[] {
50
+ const patterns: CompiledPattern[] = [];
51
+ for (const value of values) {
52
+ const compiled = compilePattern(config, value, issues);
53
+ if (compiled) patterns.push(compiled);
54
+ }
55
+ return patterns;
56
+ }
57
+
58
+ function compilePattern(
59
+ config: WorkspaceConfig,
60
+ value: string,
61
+ issues: MetadataIssue[],
62
+ ): CompiledPattern | null {
63
+ const negative = config.kind === "node-workspace" && value.startsWith("!");
64
+ const normalized = normalizeRelativePath(negative ? value.slice(1) : value);
65
+ if (
66
+ normalized === null ||
67
+ value.length === 0 ||
68
+ (config.kind !== "go-work" &&
69
+ (value.includes("\\") || /[?*+@!]\(/.test(value) || value.startsWith("!!")))
70
+ ) {
71
+ issues.push(
72
+ issue(
73
+ config.manifestPath,
74
+ config.field,
75
+ "unsupported",
76
+ `Unsupported workspace path pattern: \`${value}\`.`,
77
+ ),
78
+ );
79
+ return null;
80
+ }
81
+ try {
82
+ path.matchesGlob("pattern-check", normalized);
83
+ } catch (error) {
84
+ issues.push(
85
+ issue(
86
+ config.manifestPath,
87
+ config.field,
88
+ "unsupported",
89
+ `Unsupported workspace path pattern \`${value}\`: ${String(error)}`,
90
+ ),
91
+ );
92
+ return null;
93
+ }
94
+ return { value, negative, glob: normalized };
95
+ }
96
+
97
+ function membershipsForProject(
98
+ project: ProjectDeclaration,
99
+ configs: readonly CompiledConfig[],
100
+ goMatches: Map<string, Set<string>>,
101
+ ): ProjectMembership[] {
102
+ const memberships: ProjectMembership[] = [];
103
+ for (const compiled of configs) {
104
+ if (!supportsKind(compiled.config.kind, project.kind)) continue;
105
+ const relative = relativeDirectory(compiled.config.directory, project.directory);
106
+ if (relative === null) continue;
107
+ if (compiled.config.kind === "go-work") {
108
+ const membership = matchGoUse(compiled, project, goMatches);
109
+ if (membership) memberships.push(membership);
110
+ continue;
111
+ }
112
+ if (isExcluded(compiled, relative)) continue;
113
+ const matched = lastMatchingPattern(compiled.patterns, relative);
114
+ if (!matched) continue;
115
+ memberships.push({
116
+ kind: compiled.config.kind,
117
+ manifestPath: compiled.config.manifestPath,
118
+ field: compiled.config.field,
119
+ value: matched.value,
120
+ });
121
+ }
122
+ return dedupeMemberships(memberships);
123
+ }
124
+
125
+ function supportsKind(
126
+ workspaceKind: WorkspaceConfig["kind"],
127
+ projectKind: ProjectDeclaration["kind"],
128
+ ): boolean {
129
+ if (workspaceKind === "node-workspace") return projectKind === "node-package";
130
+ if (workspaceKind === "cargo-workspace") return projectKind === "rust-package";
131
+ return projectKind === "go-module";
132
+ }
133
+
134
+ function relativeDirectory(base: string, directory: string): string | null {
135
+ const relative = path.posix.relative(base, directory);
136
+ if (relative === "") return ".";
137
+ if (relative === ".." || relative.startsWith("../")) return null;
138
+ return relative;
139
+ }
140
+
141
+ function isExcluded(config: CompiledConfig, relative: string): boolean {
142
+ return config.excludes.some((pattern) => patternMatches(pattern, relative));
143
+ }
144
+
145
+ function lastMatchingPattern(
146
+ patterns: readonly CompiledPattern[],
147
+ relative: string,
148
+ ): CompiledPattern | null {
149
+ let matched: CompiledPattern | null = null;
150
+ for (const pattern of patterns) {
151
+ if (!patternMatches(pattern, relative)) continue;
152
+ if (pattern.negative) return null;
153
+ matched = pattern;
154
+ }
155
+ return matched?.negative ? null : matched;
156
+ }
157
+
158
+ function patternMatches(pattern: CompiledPattern, relative: string): boolean {
159
+ try {
160
+ return path.matchesGlob(relative, pattern.glob);
161
+ } catch {
162
+ return false;
163
+ }
164
+ }
165
+
166
+ function matchGoUse(
167
+ config: CompiledConfig,
168
+ project: ProjectDeclaration,
169
+ goMatches: Map<string, Set<string>>,
170
+ ): ProjectMembership | null {
171
+ for (const pattern of config.patterns) {
172
+ const usePath = normalizeRelativePath(path.posix.join(config.config.directory, pattern.glob));
173
+ if (usePath !== project.directory) continue;
174
+ markGoMatch(config.config.manifestPath, pattern.value, goMatches);
175
+ return {
176
+ kind: "go-work",
177
+ manifestPath: config.config.manifestPath,
178
+ field: config.config.field,
179
+ value: pattern.value,
180
+ };
181
+ }
182
+ return null;
183
+ }
184
+
185
+ function markGoMatch(manifestPath: string, value: string, matches: Map<string, Set<string>>): void {
186
+ const values = matches.get(manifestPath) ?? new Set<string>();
187
+ values.add(value);
188
+ matches.set(manifestPath, values);
189
+ }
190
+
191
+ function reportUnmatchedGoUses(
192
+ configs: readonly CompiledConfig[],
193
+ matches: ReadonlyMap<string, Set<string>>,
194
+ issues: MetadataIssue[],
195
+ ): void {
196
+ for (const compiled of configs) {
197
+ if (compiled.config.kind !== "go-work") continue;
198
+ const matched = matches.get(compiled.config.manifestPath) ?? new Set<string>();
199
+ for (const pattern of compiled.patterns) {
200
+ if (matched.has(pattern.value)) continue;
201
+ issues.push(
202
+ issue(
203
+ compiled.config.manifestPath,
204
+ compiled.config.field,
205
+ "unresolved",
206
+ `go.work use path \`${pattern.value}\` has no observed go.mod project.`,
207
+ ),
208
+ );
209
+ }
210
+ }
211
+ }
212
+
213
+ function dedupeMemberships(values: readonly ProjectMembership[]): ProjectMembership[] {
214
+ const seen = new Set<string>();
215
+ const result: ProjectMembership[] = [];
216
+ for (const value of values) {
217
+ const key = `${value.kind}\0${value.manifestPath}\0${value.field}\0${value.value}`;
218
+ if (seen.has(key)) continue;
219
+ seen.add(key);
220
+ result.push(value);
221
+ }
222
+ return result;
223
+ }
@@ -0,0 +1,56 @@
1
+ /** Internal metadata document and workspace-configuration shapes. */
2
+
3
+ import type {
4
+ DeclaredDependency,
5
+ DeclaredPath,
6
+ MetadataDocument,
7
+ MetadataDocumentKind,
8
+ MetadataIssue,
9
+ ProjectDeclaration,
10
+ ProjectKind,
11
+ WorkspaceDeclaration,
12
+ } from "./types.ts";
13
+
14
+ /** One successfully parsed metadata document. */
15
+ export interface ParsedDocument {
16
+ readonly path: string;
17
+ readonly kind: MetadataDocumentKind;
18
+ readonly directory: string;
19
+ readonly data: unknown;
20
+ }
21
+
22
+ /** Metadata documents plus successful parses. */
23
+ export interface MetadataReadResult {
24
+ readonly documents: readonly MetadataDocument[];
25
+ readonly parsed: readonly ParsedDocument[];
26
+ readonly issues: readonly MetadataIssue[];
27
+ readonly deadlineReached: boolean;
28
+ }
29
+
30
+ /** One explicit workspace-membership declaration. */
31
+ export type WorkspaceConfig = WorkspaceDeclaration;
32
+
33
+ /** Facts extracted from one parsed document. */
34
+ export interface DocumentContribution {
35
+ readonly project: ProjectDeclaration | null;
36
+ readonly workspace: WorkspaceConfig | null;
37
+ readonly issues: readonly MetadataIssue[];
38
+ }
39
+
40
+ /** Mutable project assembly data before runtime freezing. */
41
+ export interface ProjectDraft {
42
+ readonly id: string;
43
+ readonly manifestPath: string;
44
+ readonly kind: ProjectKind;
45
+ readonly directory: string;
46
+ readonly name: string | null;
47
+ readonly nameField: string | null;
48
+ readonly description: string | null;
49
+ readonly descriptionField: string | null;
50
+ readonly memberships: ProjectMembershipDraft[];
51
+ readonly declaredPaths: readonly DeclaredPath[];
52
+ readonly dependencies: readonly DeclaredDependency[];
53
+ }
54
+
55
+ /** Mutable membership list used only before the result is frozen. */
56
+ export type ProjectMembershipDraft = import("./types.ts").ProjectMembership;
@@ -0,0 +1,60 @@
1
+ /** Small value helpers shared by metadata readers. */
2
+
3
+ import type { MetadataIssue, MetadataIssueKind, ProjectDeclaration } from "./types.ts";
4
+
5
+ /** Check for a plain parsed object. */
6
+ export function isRecord(value: unknown): value is Record<string, unknown> {
7
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8
+ }
9
+
10
+ /** Read a string value without coercing other types. */
11
+ export function stringValue(value: unknown): string | null {
12
+ return typeof value === "string" ? value : null;
13
+ }
14
+
15
+ /** Read an array of strings, or null when any entry is not a string. */
16
+ export function stringArray(value: unknown): string[] | null {
17
+ if (!Array.isArray(value)) return null;
18
+ return value.every((entry) => typeof entry === "string") ? [...value] : null;
19
+ }
20
+
21
+ /** Create one documented metadata issue. */
22
+ export function issue(
23
+ path: string,
24
+ field: string | null,
25
+ kind: MetadataIssueKind,
26
+ reason: string,
27
+ ): MetadataIssue {
28
+ return { path, field, kind, reason };
29
+ }
30
+
31
+ /** Create an empty project with the stable manifest-path identity. */
32
+ export function baseProject(input: {
33
+ manifestPath: string;
34
+ kind: ProjectDeclaration["kind"];
35
+ directory: string;
36
+ name: string | null;
37
+ nameField: string | null;
38
+ description: string | null;
39
+ descriptionField: string | null;
40
+ }): ProjectDeclaration {
41
+ return {
42
+ id: input.manifestPath,
43
+ manifestPath: input.manifestPath,
44
+ kind: input.kind,
45
+ directory: input.directory,
46
+ name: input.name,
47
+ nameField: input.nameField,
48
+ description: input.description,
49
+ descriptionField: input.descriptionField,
50
+ memberships: [],
51
+ declaredPaths: [],
52
+ dependencies: [],
53
+ };
54
+ }
55
+
56
+ /** Join a parent field and a child key while retaining the exact key text. */
57
+ export function childField(parent: string, key: string): string {
58
+ if (/^[A-Za-z_$][\w$]*$/.test(key)) return `${parent}.${key}`;
59
+ return `${parent}[${JSON.stringify(key)}]`;
60
+ }