@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,158 @@
1
+ /** pyproject.toml [project] declaration reader. */
2
+
3
+ import type { DocumentContribution, ParsedDocument } from "./metadata-types.ts";
4
+ import { baseProject, isRecord, issue, stringArray, stringValue } from "./metadata-utils.ts";
5
+ import type { DeclaredDependency, MetadataIssue } from "./types.ts";
6
+
7
+ const REQUIREMENT_NAME = /^\s*([A-Za-z0-9][A-Za-z0-9._-]*)/;
8
+ const DYNAMIC_FIELDS = new Set(["name", "description", "dependencies", "optional-dependencies"]);
9
+
10
+ /** Read only explicitly declared `[project]` facts from one pyproject.toml. */
11
+ export function readPythonDocument(document: ParsedDocument): DocumentContribution {
12
+ if (!isRecord(document.data)) {
13
+ return {
14
+ project: null,
15
+ workspace: null,
16
+ issues: [
17
+ issue(document.path, null, "malformed", "pyproject.toml must contain a TOML table."),
18
+ ],
19
+ };
20
+ }
21
+ if (!Object.hasOwn(document.data, "project")) {
22
+ return { project: null, workspace: null, issues: [] };
23
+ }
24
+ const project = document.data.project;
25
+ if (!isRecord(project)) {
26
+ return {
27
+ project: null,
28
+ workspace: null,
29
+ issues: [
30
+ issue(document.path, "project", "malformed", "pyproject.toml#project must be a table."),
31
+ ],
32
+ };
33
+ }
34
+ const issues: MetadataIssue[] = [];
35
+ const context = { path: document.path, issues };
36
+ const name = readStringField(context, project, "name", "project.name");
37
+ const description = readStringField(context, project, "description", "project.description");
38
+ recordDynamicFields(document.path, project, issues);
39
+ return {
40
+ project: {
41
+ ...baseProject({
42
+ manifestPath: document.path,
43
+ kind: "python-project",
44
+ directory: document.directory,
45
+ name,
46
+ nameField: name === null ? null : "project.name",
47
+ description,
48
+ descriptionField: description === null ? null : "project.description",
49
+ }),
50
+ dependencies: collectPythonDependencies(document.path, project, issues),
51
+ },
52
+ workspace: null,
53
+ issues,
54
+ };
55
+ }
56
+
57
+ interface PythonContext {
58
+ readonly path: string;
59
+ readonly issues: MetadataIssue[];
60
+ }
61
+
62
+ function readStringField(
63
+ context: PythonContext,
64
+ project: Record<string, unknown>,
65
+ key: string,
66
+ field: string,
67
+ ): string | null {
68
+ if (!Object.hasOwn(project, key)) return null;
69
+ const value = stringValue(project[key]);
70
+ if (value === null) {
71
+ context.issues.push(issue(context.path, field, "unsupported", `${field} must be a string.`));
72
+ }
73
+ return value;
74
+ }
75
+
76
+ function recordDynamicFields(
77
+ path: string,
78
+ project: Record<string, unknown>,
79
+ issues: MetadataIssue[],
80
+ ): void {
81
+ if (!Object.hasOwn(project, "dynamic")) return;
82
+ const dynamic = stringArray(project.dynamic);
83
+ if (!dynamic) {
84
+ issues.push(
85
+ issue(path, "project.dynamic", "unsupported", "project.dynamic must be a string array."),
86
+ );
87
+ return;
88
+ }
89
+ for (const field of dynamic) {
90
+ if (!DYNAMIC_FIELDS.has(field)) continue;
91
+ issues.push(
92
+ issue(
93
+ path,
94
+ "project.dynamic",
95
+ "dynamic",
96
+ `project.${field} is dynamic and is not resolved from static metadata.`,
97
+ ),
98
+ );
99
+ }
100
+ }
101
+
102
+ function collectPythonDependencies(
103
+ path: string,
104
+ project: Record<string, unknown>,
105
+ issues: MetadataIssue[],
106
+ ): DeclaredDependency[] {
107
+ const dependencies: DeclaredDependency[] = [];
108
+ const sink = { path, dependencies, issues };
109
+ appendRequirementList(project, "dependencies", "project.dependencies", sink);
110
+ if (!Object.hasOwn(project, "optional-dependencies")) return dependencies;
111
+ const optional = project["optional-dependencies"];
112
+ if (!isRecord(optional)) {
113
+ issues.push(
114
+ issue(
115
+ path,
116
+ "project.optional-dependencies",
117
+ "unsupported",
118
+ "project.optional-dependencies must be a table of requirement arrays.",
119
+ ),
120
+ );
121
+ return dependencies;
122
+ }
123
+ for (const group of Object.keys(optional).sort((left, right) => left.localeCompare(right))) {
124
+ appendRequirementList(optional, group, `project.optional-dependencies.${group}`, sink);
125
+ }
126
+ return dependencies;
127
+ }
128
+
129
+ interface DependencySink extends PythonContext {
130
+ readonly dependencies: DeclaredDependency[];
131
+ }
132
+
133
+ function appendRequirementList(
134
+ owner: Record<string, unknown>,
135
+ key: string,
136
+ field: string,
137
+ sink: DependencySink,
138
+ ): void {
139
+ if (!Object.hasOwn(owner, key)) return;
140
+ const values = owner[key];
141
+ if (!Array.isArray(values)) {
142
+ sink.issues.push(
143
+ issue(sink.path, field, "unsupported", `${field} must be a requirement array.`),
144
+ );
145
+ return;
146
+ }
147
+ for (const value of values) {
148
+ const requirement = stringValue(value);
149
+ const name = requirement === null ? null : (REQUIREMENT_NAME.exec(requirement)?.[1] ?? null);
150
+ if (requirement === null || name === null) {
151
+ sink.issues.push(
152
+ issue(sink.path, field, "unsupported", "Unreadable dependency requirement entry."),
153
+ );
154
+ continue;
155
+ }
156
+ sink.dependencies.push({ field, name, value: requirement });
157
+ }
158
+ }
@@ -0,0 +1,87 @@
1
+ /** Declared local project relationships from uniquely identified native project names. */
2
+
3
+ import { isRecord, stringValue } from "./metadata-utils.ts";
4
+ import type {
5
+ DeclaredDependency,
6
+ ProjectDeclaration,
7
+ ProjectKind,
8
+ ProjectRelationship,
9
+ } from "./types.ts";
10
+
11
+ type ProjectIndex = Map<ProjectKind, Map<string, ProjectDeclaration[]>>;
12
+
13
+ /** Build declarations only for targets with exactly one established project identity. */
14
+ export function buildRelationships(projects: readonly ProjectDeclaration[]): ProjectRelationship[] {
15
+ const index = indexProjects(projects);
16
+ const relationships: ProjectRelationship[] = [];
17
+ for (const project of projects) {
18
+ for (const dependency of project.dependencies) {
19
+ const target = resolveTarget(project, dependency, index);
20
+ if (!target) continue;
21
+ relationships.push({
22
+ from: project.id,
23
+ to: target.id,
24
+ manifestPath: project.manifestPath,
25
+ field: dependency.field,
26
+ value: dependency.value,
27
+ });
28
+ }
29
+ }
30
+ return sortRelationships(relationships);
31
+ }
32
+
33
+ function indexProjects(projects: readonly ProjectDeclaration[]): ProjectIndex {
34
+ const index: ProjectIndex = new Map();
35
+ for (const project of projects) {
36
+ const key = identityKey(project);
37
+ if (key === null) continue;
38
+ const byKind = index.get(project.kind) ?? new Map<string, ProjectDeclaration[]>();
39
+ const entries = byKind.get(key) ?? [];
40
+ entries.push(project);
41
+ byKind.set(key, entries);
42
+ index.set(project.kind, byKind);
43
+ }
44
+ return index;
45
+ }
46
+
47
+ function identityKey(project: ProjectDeclaration): string | null {
48
+ if (project.name === null) return null;
49
+ return project.kind === "python-project" ? normalizePythonName(project.name) : project.name;
50
+ }
51
+
52
+ function resolveTarget(
53
+ project: ProjectDeclaration,
54
+ dependency: DeclaredDependency,
55
+ index: ProjectIndex,
56
+ ): ProjectDeclaration | null {
57
+ const key = dependencyKey(project.kind, dependency);
58
+ if (key === null) return null;
59
+ const entries = index.get(project.kind)?.get(key) ?? [];
60
+ return entries.length === 1 ? (entries[0] ?? null) : null;
61
+ }
62
+
63
+ function dependencyKey(kind: ProjectKind, dependency: DeclaredDependency): string | null {
64
+ if (kind === "python-project") return normalizePythonName(dependency.name);
65
+ if (kind === "rust-package") return rustDependencyKey(dependency);
66
+ return dependency.name;
67
+ }
68
+
69
+ function rustDependencyKey(dependency: DeclaredDependency): string | null {
70
+ if (!isRecord(dependency.value)) return dependency.name;
71
+ if (dependency.value.workspace === true) return null;
72
+ return stringValue(dependency.value.package) ?? dependency.name;
73
+ }
74
+
75
+ /** Normalize only the match key; the declared name remains unchanged. */
76
+ function normalizePythonName(value: string): string {
77
+ return value.toLowerCase().replaceAll(/[-_.]+/g, "-");
78
+ }
79
+
80
+ function sortRelationships(values: readonly ProjectRelationship[]): ProjectRelationship[] {
81
+ return [...values].sort(
82
+ (left, right) =>
83
+ left.from.localeCompare(right.from) ||
84
+ left.field.localeCompare(right.field) ||
85
+ left.to.localeCompare(right.to),
86
+ );
87
+ }
@@ -0,0 +1,238 @@
1
+ /** Cargo.toml package, workspace, path, and dependency declaration reader. */
2
+
3
+ import type { DocumentContribution, ParsedDocument, WorkspaceConfig } from "./metadata-types.ts";
4
+ import {
5
+ baseProject,
6
+ childField,
7
+ isRecord,
8
+ issue,
9
+ stringArray,
10
+ stringValue,
11
+ } from "./metadata-utils.ts";
12
+ import type { DeclaredDependency, DeclaredPath, MetadataIssue } from "./types.ts";
13
+
14
+ const DEPENDENCY_FIELDS = ["dependencies", "dev-dependencies", "build-dependencies"] as const;
15
+
16
+ /** Read one Cargo.toml without resolving inherited or build-time behavior. */
17
+ export function readRustDocument(document: ParsedDocument): DocumentContribution {
18
+ if (!isRecord(document.data)) {
19
+ return {
20
+ project: null,
21
+ workspace: null,
22
+ issues: [issue(document.path, null, "malformed", "Cargo.toml must contain a TOML table.")],
23
+ };
24
+ }
25
+ const issues: MetadataIssue[] = [];
26
+ const project = readRustProject(document, issues);
27
+ return {
28
+ project,
29
+ workspace: readCargoWorkspace(document, issues),
30
+ issues,
31
+ };
32
+ }
33
+
34
+ function readRustProject(
35
+ document: ParsedDocument,
36
+ issues: MetadataIssue[],
37
+ ): DocumentContribution["project"] {
38
+ if (!isRecord(document.data) || !Object.hasOwn(document.data, "package")) return null;
39
+ const pkg = document.data.package;
40
+ if (!isRecord(pkg)) {
41
+ issues.push(
42
+ issue(document.path, "package", "malformed", "Cargo.toml#package must be a table."),
43
+ );
44
+ return null;
45
+ }
46
+ const name = readString(packageValue(document.path, pkg, "name", issues));
47
+ const description = readString(packageValue(document.path, pkg, "description", issues));
48
+ if (Object.hasOwn(pkg, "workspace")) {
49
+ issues.push(
50
+ issue(
51
+ document.path,
52
+ "package.workspace",
53
+ "unresolved",
54
+ "Explicit package.workspace reference is retained as a limitation; workspace-reference resolution is not supported.",
55
+ ),
56
+ );
57
+ }
58
+ const base = baseProject({
59
+ manifestPath: document.path,
60
+ kind: "rust-package",
61
+ directory: document.directory,
62
+ name,
63
+ nameField: name === null ? null : "package.name",
64
+ description,
65
+ descriptionField: description === null ? null : "package.description",
66
+ });
67
+ return {
68
+ ...base,
69
+ declaredPaths: collectCargoPaths(document.data, document.path, issues),
70
+ dependencies: collectCargoDependencies(document.data, document.path, issues),
71
+ };
72
+ }
73
+
74
+ function packageValue(
75
+ path: string,
76
+ pkg: Record<string, unknown>,
77
+ key: string,
78
+ issues: MetadataIssue[],
79
+ ): unknown {
80
+ if (!Object.hasOwn(pkg, key)) return undefined;
81
+ const value = pkg[key];
82
+ if (typeof value !== "string") {
83
+ issues.push(issue(path, `package.${key}`, "unsupported", `package.${key} must be a string.`));
84
+ return undefined;
85
+ }
86
+ return value;
87
+ }
88
+
89
+ function readString(value: unknown): string | null {
90
+ return typeof value === "string" ? value : null;
91
+ }
92
+
93
+ function readCargoWorkspace(
94
+ document: ParsedDocument,
95
+ issues: MetadataIssue[],
96
+ ): WorkspaceConfig | null {
97
+ if (!isRecord(document.data) || !Object.hasOwn(document.data, "workspace")) return null;
98
+ const workspace = document.data.workspace;
99
+ if (!isRecord(workspace)) {
100
+ issues.push(
101
+ issue(document.path, "workspace", "malformed", "Cargo.toml#workspace must be a table."),
102
+ );
103
+ return null;
104
+ }
105
+ const members = workspace.members === undefined ? [] : stringArray(workspace.members);
106
+ const excludes = workspace.exclude === undefined ? [] : stringArray(workspace.exclude);
107
+ if (!members) {
108
+ issues.push(
109
+ issue(
110
+ document.path,
111
+ "workspace.members",
112
+ "unsupported",
113
+ "workspace.members must be strings.",
114
+ ),
115
+ );
116
+ }
117
+ if (!excludes) {
118
+ issues.push(
119
+ issue(
120
+ document.path,
121
+ "workspace.exclude",
122
+ "unsupported",
123
+ "workspace.exclude must be strings.",
124
+ ),
125
+ );
126
+ }
127
+ if (!members || !excludes) return null;
128
+ return {
129
+ kind: "cargo-workspace",
130
+ manifestPath: document.path,
131
+ directory: document.directory,
132
+ field: "workspace.members",
133
+ patterns: members,
134
+ excludeField: workspace.exclude === undefined ? null : "workspace.exclude",
135
+ excludes,
136
+ };
137
+ }
138
+
139
+ function collectCargoDependencies(
140
+ manifest: Record<string, unknown>,
141
+ manifestPath: string,
142
+ issues: MetadataIssue[],
143
+ ): DeclaredDependency[] {
144
+ const dependencies: DeclaredDependency[] = [];
145
+ const sink = { manifestPath, dependencies, issues };
146
+ for (const field of DEPENDENCY_FIELDS) {
147
+ appendDependencyTable(manifest, field, field, sink);
148
+ }
149
+ appendTargetDependencies(manifest, sink);
150
+ if (isRecord(manifest.workspace)) {
151
+ appendDependencyTable(manifest.workspace, "dependencies", "workspace.dependencies", sink);
152
+ }
153
+ return dependencies;
154
+ }
155
+
156
+ interface CargoDependencySink {
157
+ readonly manifestPath: string;
158
+ readonly dependencies: DeclaredDependency[];
159
+ readonly issues: MetadataIssue[];
160
+ }
161
+
162
+ function appendTargetDependencies(
163
+ manifest: Record<string, unknown>,
164
+ sink: CargoDependencySink,
165
+ ): void {
166
+ if (!isRecord(manifest.target)) return;
167
+ for (const target of Object.keys(manifest.target).sort((left, right) =>
168
+ left.localeCompare(right),
169
+ )) {
170
+ const value = manifest.target[target];
171
+ if (!isRecord(value)) continue;
172
+ for (const field of DEPENDENCY_FIELDS) {
173
+ appendDependencyTable(value, field, `${childField("target", target)}.${field}`, sink);
174
+ }
175
+ }
176
+ }
177
+
178
+ function appendDependencyTable(
179
+ owner: Record<string, unknown>,
180
+ key: string,
181
+ field: string,
182
+ sink: CargoDependencySink,
183
+ ): void {
184
+ if (!Object.hasOwn(owner, key)) return;
185
+ const table = owner[key];
186
+ if (!isRecord(table)) {
187
+ sink.issues.push(
188
+ issue(sink.manifestPath, field, "unsupported", `${field} must be a dependency table.`),
189
+ );
190
+ return;
191
+ }
192
+ for (const name of Object.keys(table).sort((left, right) => left.localeCompare(right))) {
193
+ const value = table[name];
194
+ sink.dependencies.push({ field, name, value });
195
+ if (isRecord(value) && value.workspace === true) {
196
+ sink.issues.push(
197
+ issue(
198
+ sink.manifestPath,
199
+ childField(field, name),
200
+ "inherited",
201
+ "Workspace-inherited dependency values are not resolved.",
202
+ ),
203
+ );
204
+ }
205
+ }
206
+ }
207
+
208
+ function collectCargoPaths(
209
+ manifest: Record<string, unknown>,
210
+ manifestPath: string,
211
+ issues: MetadataIssue[],
212
+ ): DeclaredPath[] {
213
+ const paths: DeclaredPath[] = [];
214
+ const sink = { manifestPath, paths, issues };
215
+ appendPath(manifest.lib, "lib.path", "path", sink);
216
+ appendPath(manifest.package, "package.build", "build", sink);
217
+ if (!Array.isArray(manifest.bin)) return paths;
218
+ for (const [index, bin] of manifest.bin.entries()) {
219
+ appendPath(bin, `bin[${index}].path`, "path", sink);
220
+ }
221
+ return paths;
222
+ }
223
+
224
+ interface CargoPathSink {
225
+ readonly manifestPath: string;
226
+ readonly paths: DeclaredPath[];
227
+ readonly issues: MetadataIssue[];
228
+ }
229
+
230
+ function appendPath(owner: unknown, field: string, key: string, sink: CargoPathSink): void {
231
+ if (!isRecord(owner) || !Object.hasOwn(owner, key)) return;
232
+ const value = stringValue(owner[key]);
233
+ if (value === null) {
234
+ sink.issues.push(issue(sink.manifestPath, field, "unsupported", `${field} must be a string.`));
235
+ return;
236
+ }
237
+ sink.paths.push({ field, path: value });
238
+ }
@@ -0,0 +1,20 @@
1
+ import { promises as fs } from "node:fs";
2
+ import * as path from "node:path";
3
+
4
+ /** Reject link traversal below the selected root, including a replaced root itself. */
5
+ export async function assertUnlinkedPath(
6
+ root: string,
7
+ relativePath: string,
8
+ includeLeaf = false,
9
+ ): Promise<void> {
10
+ const parts = relativePath.split("/").filter((part) => part !== "." && part.length > 0);
11
+ if (!includeLeaf) parts.pop();
12
+ let current = root;
13
+ if ((await fs.lstat(current)).isSymbolicLink())
14
+ throw new Error("Symbolic-link root is not followed.");
15
+ for (const part of parts) {
16
+ current = path.join(current, part);
17
+ if ((await fs.lstat(current)).isSymbolicLink())
18
+ throw new Error(`Symbolic-link ancestor is not followed: ${relativePath}`);
19
+ }
20
+ }