@punks/cli 5.2.0 → 5.2.2
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.
- package/README.md +2 -2
- package/dist/BASELINE_CHANGELOG.md +46 -1
- package/dist/CHANGELOG.md +37 -0
- package/dist/baseline/scaffold-baseline/baseline.json +15 -5
- package/dist/baseline/scaffold-baseline/data/catalog/packs.json +2 -0
- package/dist/baseline/scaffold-baseline/data/catalog/skills.json +16 -0
- package/dist/baseline/scaffold-baseline/data/hooks/format-edited-file.mjs +459 -318
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.d.ts +1 -0
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.mjs +98 -27
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.test.ts +156 -8
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.d.mts +55 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.mjs +329 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.test.ts +864 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.d.mts +97 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.mjs +658 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.test.ts +614 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/commands.md +8 -9
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +28 -24
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/wiki-structure.md +16 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/SKILL.md +21 -16
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/agents/openai.yaml +1 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +16 -4
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/SKILL.md +65 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/assets/ARCHITECTURE-TEMPLATE.md +119 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-architecture/references/artifact-contract.md +200 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/SKILL.md +11 -3
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/architecture-convergence.md +19 -4
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/plan-schema.md +17 -3
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/SKILL.md +38 -20
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +11 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/readiness.md +40 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +8 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/SKILL.md +4 -2
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/lifecycle.md +23 -10
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/brainstorm/SKILL.md +22 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +3 -2
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +6 -3
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/plan.md +4 -2
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +5 -1
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +15 -9
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/spec.md +13 -26
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/artifact-state.md +39 -1
- package/dist/baseline/scaffold-baseline/skills/phases/requirements-phase/SKILL.md +31 -14
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/prepare-review.md +12 -4
- package/dist/baseline/scaffold-baseline.json +5 -5
- package/dist/baseline/scaffold-baseline.tgz +0 -0
- package/dist/data/hooks/format-edited-file.d.mts +5 -0
- package/dist/data/hooks/format-edited-file.mjs +282 -333
- package/dist/data/scripts/commit-gate-runner.mjs +98 -27
- package/dist/data/scripts/managed-lint-runner.d.mts +55 -0
- package/dist/data/scripts/managed-lint-runner.mjs +329 -0
- package/dist/data/scripts/managed-lint.d.mts +97 -0
- package/dist/data/scripts/managed-lint.mjs +658 -0
- package/dist/index.js +86 -1184
- package/dist/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
- package/dist/skills/agnostic/cli/hi-cli/references/commands.md +8 -9
- package/dist/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
- package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +15 -11
- package/dist/skills/agnostic/cli/hi-cli/references/wiki-structure.md +16 -0
- package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +21 -16
- package/dist/skills/agnostic/docs/docs-onboarding/agents/openai.yaml +1 -1
- package/dist/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +16 -4
- package/dist/skills/agnostic/planning/create-architecture/SKILL.md +65 -0
- package/dist/skills/agnostic/planning/create-architecture/assets/ARCHITECTURE-TEMPLATE.md +119 -0
- package/dist/skills/agnostic/planning/create-architecture/references/artifact-contract.md +200 -0
- package/dist/skills/agnostic/planning/create-plan/SKILL.md +11 -3
- package/dist/skills/agnostic/planning/create-plan/references/architecture-convergence.md +19 -4
- package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +17 -3
- package/dist/skills/agnostic/planning/create-spec/SKILL.md +38 -20
- package/dist/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +11 -0
- package/dist/skills/agnostic/planning/create-spec/references/readiness.md +40 -0
- package/dist/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +8 -0
- package/dist/skills/agnostic/planning/implement-spec/SKILL.md +4 -2
- package/dist/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
- package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +23 -10
- package/dist/skills/agnostic/requirements/brainstorm/SKILL.md +22 -0
- package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
- package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +3 -2
- package/dist/skills/phases/delivery-phase/SKILL.md +6 -3
- package/dist/skills/phases/delivery-phase/phases/plan.md +4 -2
- package/dist/skills/phases/delivery-phase/phases/review.md +5 -1
- package/dist/skills/phases/delivery-phase/phases/router.md +15 -9
- package/dist/skills/phases/delivery-phase/phases/spec.md +13 -26
- package/dist/skills/phases/delivery-phase/references/artifact-state.md +39 -1
- package/dist/skills/phases/requirements-phase/SKILL.md +31 -14
- package/dist/skills/phases/review-phase/phases/prepare-review.md +12 -4
- package/package.json +3 -2
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { access, readFile, readdir, realpath, stat } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
/** @typedef {import('./managed-lint.mjs').ManagedLintRoute} Route */
|
|
6
|
+
/** @typedef {import('./managed-lint.mjs').ManagedLintSelection} Selection */
|
|
7
|
+
/** @typedef {import('./managed-lint.mjs').ManagedLintPolicyInput} PolicyInput */
|
|
8
|
+
/** @typedef {import('./managed-lint.mjs').ManagedLintResolution} Resolution */
|
|
9
|
+
/** @typedef {import('./managed-lint.mjs').ManagedLintCommand} Command */
|
|
10
|
+
/** @typedef {import('./managed-lint.mjs').ResolveManagedLintOptions} ResolveOptions */
|
|
11
|
+
/** @typedef {import('./managed-lint.mjs').BuildManagedLintCommandOptions} CommandOptions */
|
|
12
|
+
/** @typedef {import('./managed-lint.mjs').ManagedQualityPathOptions} PathOptions */
|
|
13
|
+
/** @typedef {import('./managed-lint.mjs').ResolvedManagedLintRoute} ResolvedRoute */
|
|
14
|
+
/** @typedef {Route & {boundaries: string[], files: string[], triggered: boolean}} MutableRoute */
|
|
15
|
+
|
|
16
|
+
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
17
|
+
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18
|
+
/** @param {unknown} value @param {string} key @returns {unknown} */
|
|
19
|
+
const field = (value, key) => (record(value) ? value[key] : undefined);
|
|
20
|
+
/** @param {unknown} value @returns {value is unknown[]} */
|
|
21
|
+
const array = (value) => Array.isArray(value);
|
|
22
|
+
/** @param {unknown} error @returns {string} */
|
|
23
|
+
const errorMessage = (error) => (error instanceof Error ? error.message : String(error));
|
|
24
|
+
|
|
25
|
+
/** @param {string} scope @param {string} file @returns {boolean} */
|
|
26
|
+
const contains = (scope, file) => scope === "." || file === scope || file.startsWith(`${scope}/`);
|
|
27
|
+
/** @param {string} file @returns {boolean} */
|
|
28
|
+
const wiki = (file) => ["wiki", "app/wiki", "apps/wiki"].some((scope) => contains(scope, file));
|
|
29
|
+
/** @param {unknown} value @returns {value is string} */
|
|
30
|
+
const validPath = (value) =>
|
|
31
|
+
typeof value === "string" &&
|
|
32
|
+
value.length > 0 &&
|
|
33
|
+
!value.includes("\\") &&
|
|
34
|
+
!path.posix.isAbsolute(value) &&
|
|
35
|
+
value.split("/").every((part) => part !== ".." && part !== "") &&
|
|
36
|
+
path.posix.normalize(value) === value;
|
|
37
|
+
/** @param {unknown} value @returns {value is string[]} */
|
|
38
|
+
const strings = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
39
|
+
/** @param {string} file @returns {boolean} */
|
|
40
|
+
const blocked = (file) =>
|
|
41
|
+
file.split("/").some((part) => ["node_modules", ".git", ".devpunks"].includes(part));
|
|
42
|
+
/** @param {readonly string[]} a @param {readonly string[]} b @returns {boolean} */
|
|
43
|
+
const same = (a, b) =>
|
|
44
|
+
JSON.stringify([...new Set(a)].toSorted()) === JSON.stringify([...new Set(b)].toSorted());
|
|
45
|
+
/** @param {string} message @returns {import("./managed-lint.mjs").ManagedLintFailure} */
|
|
46
|
+
const conflict = (message) => ({ diagnostics: [message], status: "conflict" });
|
|
47
|
+
/** @param {string} file @returns {Promise<boolean>} */
|
|
48
|
+
const exists = async (file) => {
|
|
49
|
+
try {
|
|
50
|
+
await access(file);
|
|
51
|
+
return true;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (field(error, "code") === "ENOENT") {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** @param {string} root @param {string} scope @param {readonly string[]} scopes @param {readonly string[]} exclude @returns {Promise<string[]>} */
|
|
61
|
+
const boundaries = async (root, scope, scopes, exclude) => {
|
|
62
|
+
/** @param {string} directory @returns {Promise<string[]>} */
|
|
63
|
+
const visit = async (directory) => {
|
|
64
|
+
const entries = await readdir(path.resolve(root, directory), { withFileTypes: true });
|
|
65
|
+
const children = await Promise.all(
|
|
66
|
+
entries.map(async (entry) => {
|
|
67
|
+
const child = path.posix.join(directory, entry.name);
|
|
68
|
+
if (!entry.isDirectory() || isManagedQualityPathExcluded({ exclude, path: child })) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
if (
|
|
72
|
+
!scopes.includes(child) &&
|
|
73
|
+
((await exists(path.resolve(root, child, "package.json"))) ||
|
|
74
|
+
(await exists(path.resolve(root, child, "pyproject.toml"))))
|
|
75
|
+
) {
|
|
76
|
+
return [child];
|
|
77
|
+
}
|
|
78
|
+
return await visit(child);
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
81
|
+
return children.flat();
|
|
82
|
+
};
|
|
83
|
+
return await visit(scope);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** @param {string} root @param {string} scope @param {(file: string) => boolean} excluded @returns {Promise<string[]>} */
|
|
87
|
+
const sourceFiles = async (root, scope, excluded) => {
|
|
88
|
+
/** @param {string} directory @returns {Promise<string[]>} */
|
|
89
|
+
const visit = async (directory) => {
|
|
90
|
+
const entries = await readdir(path.resolve(root, directory), { withFileTypes: true });
|
|
91
|
+
const children = await Promise.all(
|
|
92
|
+
entries.map(async (entry) => {
|
|
93
|
+
const file = path.posix.join(directory, entry.name);
|
|
94
|
+
if (blocked(file) || excluded(file)) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
if (entry.isDirectory()) {
|
|
98
|
+
return await visit(file);
|
|
99
|
+
}
|
|
100
|
+
return entry.isFile() ? [file] : [];
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
return children.flat();
|
|
104
|
+
};
|
|
105
|
+
return await visit(scope);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** @param {ResolveOptions} options @returns {Promise<Resolution>} */
|
|
109
|
+
export const resolveManagedLint = async (options) => {
|
|
110
|
+
try {
|
|
111
|
+
return await resolveRoutes(options);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
return conflict(`Cannot resolve managed lint inputs: ${errorMessage(error)}`);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/** @param {unknown} route @returns {route is Route} */
|
|
117
|
+
const validRoute = (route) =>
|
|
118
|
+
record(route) &&
|
|
119
|
+
validPath(route.scope) &&
|
|
120
|
+
!wiki(route.scope) &&
|
|
121
|
+
!blocked(route.scope) &&
|
|
122
|
+
validPath(route.config) &&
|
|
123
|
+
route.config === path.posix.join(route.scope, "oxlint.config.ts") &&
|
|
124
|
+
record(route.tool) &&
|
|
125
|
+
route.tool.package === "oxlint" &&
|
|
126
|
+
typeof route.tool.version === "string" &&
|
|
127
|
+
validPolicyInputs(route.policyInputs) &&
|
|
128
|
+
strings(route.inputs) &&
|
|
129
|
+
route.inputs.every(validPath) &&
|
|
130
|
+
(route.maxWarnings === null ||
|
|
131
|
+
(typeof route.maxWarnings === "number" &&
|
|
132
|
+
Number.isInteger(route.maxWarnings) &&
|
|
133
|
+
route.maxWarnings >= 0));
|
|
134
|
+
|
|
135
|
+
/** @param {unknown} artifact @param {readonly string[]} scopes @param {readonly string[]} exclude @returns {artifact is Selection} */
|
|
136
|
+
const validSelection = (artifact, scopes, exclude) =>
|
|
137
|
+
record(artifact) &&
|
|
138
|
+
artifact.version === 1 &&
|
|
139
|
+
strings(artifact.scopes) &&
|
|
140
|
+
strings(artifact.exclude) &&
|
|
141
|
+
same(scopes, artifact.scopes) &&
|
|
142
|
+
same(exclude, artifact.exclude) &&
|
|
143
|
+
array(artifact.routes) &&
|
|
144
|
+
artifact.routes.length === new Set(scopes).size &&
|
|
145
|
+
artifact.routes.every(validRoute) &&
|
|
146
|
+
same(
|
|
147
|
+
artifact.routes.map((route) => route.scope),
|
|
148
|
+
scopes,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
/** @param {PathOptions} options @returns {boolean} @throws {TypeError} Invalid repository-relative path. */
|
|
152
|
+
export const isManagedQualityPathExcluded = ({ path: file, exclude }) => {
|
|
153
|
+
if (!validPath(file)) {
|
|
154
|
+
throw new TypeError("Managed quality path must be normalized and repository-relative.");
|
|
155
|
+
}
|
|
156
|
+
return (
|
|
157
|
+
wiki(file) ||
|
|
158
|
+
blocked(file) ||
|
|
159
|
+
exclude.some(
|
|
160
|
+
(pattern) =>
|
|
161
|
+
matchesGlob(file, pattern) || matchesGlob(`${file}/`, pattern) || contains(pattern, file),
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/** @param {string} root @param {Route} route @param {readonly string[]} scopes @param {readonly string[]} exclude @returns {Promise<MutableRoute>} */
|
|
167
|
+
const resolveOwner = async (root, route, scopes, exclude) => {
|
|
168
|
+
if (!(await containedRealPath(root, path.resolve(root, route.scope)))) {
|
|
169
|
+
throw new Error(`Selected owner escapes repository: ${route.scope}`);
|
|
170
|
+
}
|
|
171
|
+
if (!(await exists(path.resolve(root, route.scope, "package.json")))) {
|
|
172
|
+
throw new Error(`Selected owner is missing: ${route.scope}`);
|
|
173
|
+
}
|
|
174
|
+
const canonicalRoot = await realpath(root);
|
|
175
|
+
if (
|
|
176
|
+
(await realpath(path.resolve(root, route.scope))) !== path.resolve(canonicalRoot, route.scope)
|
|
177
|
+
) {
|
|
178
|
+
throw new Error(`Selected owner must not alias another directory: ${route.scope}`);
|
|
179
|
+
}
|
|
180
|
+
await verifyPolicyInputs(root, route);
|
|
181
|
+
return {
|
|
182
|
+
...route,
|
|
183
|
+
boundaries: await boundaries(root, route.scope, scopes, exclude),
|
|
184
|
+
files: [],
|
|
185
|
+
triggered: false,
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/** @param {unknown} value @returns {value is string[]} */
|
|
190
|
+
const validPaths = (value) => strings(value) && value.every(validPath);
|
|
191
|
+
/** @param {unknown} value @returns {value is string[] | undefined} */
|
|
192
|
+
const optionalPaths = (value) => value === undefined || validPaths(value);
|
|
193
|
+
/** @param {unknown} value @returns {boolean} */
|
|
194
|
+
const validSettings = (value) => record(value) && (value.lint === undefined || record(value.lint));
|
|
195
|
+
/** @param {string} file @param {Route} route @returns {boolean} */
|
|
196
|
+
const isRouteDependency = (file, route) =>
|
|
197
|
+
route.inputs.includes(file) || file === route.config || isSelectionInput(file);
|
|
198
|
+
/** @param {string} file @returns {boolean} */
|
|
199
|
+
const isSelectionInput = (file) =>
|
|
200
|
+
file === ".devpunks/settings.json" || file === ".devpunks/specs/lint/selection.json";
|
|
201
|
+
/** @param {readonly string[]} scopes @param {string} file @returns {string | undefined} */
|
|
202
|
+
const ownerScope = (scopes, file) =>
|
|
203
|
+
scopes
|
|
204
|
+
.filter((scope) => contains(scope, file))
|
|
205
|
+
.toSorted((a, b) => (b === "." ? 0 : b.length) - (a === "." ? 0 : a.length))[0];
|
|
206
|
+
|
|
207
|
+
/** @param {unknown} selection @returns {string[] | null} */
|
|
208
|
+
const migrationConflicts = (selection) => {
|
|
209
|
+
const conflicts = field(field(selection, "lintEvidence"), "conflicts");
|
|
210
|
+
if (conflicts === undefined) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
if (!array(conflicts)) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
const locations = conflicts.map((item) => field(item, "path"));
|
|
217
|
+
return strings(locations) ? locations : null;
|
|
218
|
+
};
|
|
219
|
+
/** @param {string} file @param {readonly string[]} locations @returns {boolean} */
|
|
220
|
+
const isMigrationInput = (file, locations) =>
|
|
221
|
+
locations.some(
|
|
222
|
+
(location) =>
|
|
223
|
+
location === file ||
|
|
224
|
+
location.startsWith(`${file}#`) ||
|
|
225
|
+
(location.startsWith(`${file}:`) && /^:\d+$/u.test(location.slice(file.length))),
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
/** Prove no work without validating unrelated adopted policy or tool health.
|
|
229
|
+
* @param {ResolveOptions} options - The explicit path request and available route authority.
|
|
230
|
+
* @param {readonly string[] | undefined} scopes - Saved software owners, when selected.
|
|
231
|
+
* @param {readonly string[]} exclude - Validated project exclusions.
|
|
232
|
+
* @returns {Promise<boolean>} Whether every path is outside source and dependency work.
|
|
233
|
+
*/
|
|
234
|
+
const excludedRequest = async ({ root, selection, paths }, scopes, exclude) => {
|
|
235
|
+
if (paths === undefined || paths.length === 0) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
if (scopes?.some((scope) => wiki(scope) || blocked(scope)) === true) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
const artifact = field(selection, "managedLint");
|
|
242
|
+
const routes = artifact === undefined ? [] : field(artifact, "routes");
|
|
243
|
+
// Stale but readable routes still own dependencies. Malformed routes cannot prove absence.
|
|
244
|
+
if (!array(routes) || !routes.every(validRoute)) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
const conflicts = migrationConflicts(selection);
|
|
248
|
+
if (conflicts === null) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
if (
|
|
252
|
+
paths.some(
|
|
253
|
+
(file) =>
|
|
254
|
+
isSelectionInput(file) ||
|
|
255
|
+
isMigrationInput(file, conflicts) ||
|
|
256
|
+
scopes?.some((scope) => file === path.posix.join(scope, "oxlint.config.ts")) === true ||
|
|
257
|
+
routes.some((route) => isRouteDependency(file, route)),
|
|
258
|
+
)
|
|
259
|
+
) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
const remaining = paths.filter((file) => !isManagedQualityPathExcluded({ exclude, path: file }));
|
|
263
|
+
if (remaining.length === 0) {
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
if (scopes === undefined) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const owned = remaining.flatMap((file) => {
|
|
270
|
+
const owner = ownerScope(scopes, file);
|
|
271
|
+
return owner === undefined ? [] : [{ file, owner }];
|
|
272
|
+
});
|
|
273
|
+
return await outsideBoundaries(root, scopes, exclude, owned);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/** @param {string} root - Repository directory.
|
|
277
|
+
* @param {readonly string[]} scopes - Saved software owners.
|
|
278
|
+
* @param {readonly string[]} exclude - Validated exclusions.
|
|
279
|
+
* @param {readonly {file: string, owner: string}[]} owned - Requests requiring boundary proof.
|
|
280
|
+
* @returns {Promise<boolean>} Whether all requests belong to unselected nested projects.
|
|
281
|
+
*/
|
|
282
|
+
const outsideBoundaries = async (root, scopes, exclude, owned) => {
|
|
283
|
+
/** @type {Map<string, Promise<string[]>>} */
|
|
284
|
+
const observed = new Map();
|
|
285
|
+
/** @param {number} index @returns {Promise<boolean>} */
|
|
286
|
+
const visit = async (index) => {
|
|
287
|
+
const candidate = owned[index];
|
|
288
|
+
if (candidate === undefined) {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
const pending =
|
|
292
|
+
observed.get(candidate.owner) ?? boundaries(root, candidate.owner, scopes, exclude);
|
|
293
|
+
observed.set(candidate.owner, pending);
|
|
294
|
+
const nested = await pending;
|
|
295
|
+
if (!nested.some((boundary) => contains(boundary, candidate.file))) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return await visit(index + 1);
|
|
299
|
+
};
|
|
300
|
+
try {
|
|
301
|
+
return await visit(0);
|
|
302
|
+
} catch {
|
|
303
|
+
// Incomplete boundary evidence defers to normal owner validation and its diagnostics.
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
/** @param {ResolveOptions} options @returns {Promise<Resolution>} */
|
|
309
|
+
const resolveRoutes = async ({ root, settings, selection, paths, scope }) => {
|
|
310
|
+
const lint = field(settings, "lint");
|
|
311
|
+
if (!validSettings(settings)) {
|
|
312
|
+
return conflict("Managed lint settings and lint must be objects.");
|
|
313
|
+
}
|
|
314
|
+
const scopes = field(lint, "scopes");
|
|
315
|
+
if (!optionalPaths(scopes)) {
|
|
316
|
+
return conflict("lint.scopes must contain exact repository-relative package paths.");
|
|
317
|
+
}
|
|
318
|
+
const exclude = field(lint, "exclude") ?? [];
|
|
319
|
+
if (
|
|
320
|
+
!strings(exclude) ||
|
|
321
|
+
!exclude.every((pattern) => validPath(pattern) && !pattern.startsWith("!"))
|
|
322
|
+
) {
|
|
323
|
+
return conflict("lint.exclude must be a list of repository-relative patterns.");
|
|
324
|
+
}
|
|
325
|
+
if (scopes?.length === 0) {
|
|
326
|
+
return { diagnostics: [], status: "disabled" };
|
|
327
|
+
}
|
|
328
|
+
if (!optionalPaths(paths)) {
|
|
329
|
+
return conflict("Lint input paths must be repository-relative and contained.");
|
|
330
|
+
}
|
|
331
|
+
if (scope !== undefined && scopes?.includes(scope) !== true) {
|
|
332
|
+
return conflict(`Scope ${scope} is not a selected software owner.`);
|
|
333
|
+
}
|
|
334
|
+
if (
|
|
335
|
+
await excludedRequest(
|
|
336
|
+
{ root, selection, settings, ...(paths === undefined ? {} : { paths }) },
|
|
337
|
+
scopes,
|
|
338
|
+
exclude,
|
|
339
|
+
)
|
|
340
|
+
) {
|
|
341
|
+
return { excludedPaths: [...new Set(paths)].toSorted(), routes: [], status: "ready" };
|
|
342
|
+
}
|
|
343
|
+
if (scopes === undefined) {
|
|
344
|
+
return {
|
|
345
|
+
diagnostics: ["Select exact software scopes in .devpunks/settings.json lint.scopes."],
|
|
346
|
+
status: "selection-needed",
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
const artifact = field(selection, "managedLint");
|
|
350
|
+
if (!validSelection(artifact, scopes, exclude)) {
|
|
351
|
+
return conflict(
|
|
352
|
+
"Managed lint selection is stale or invalid; run hi scaffold/update after selecting scopes.",
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
const routes = await Promise.all(
|
|
356
|
+
artifact.routes.map(async (route) => await resolveOwner(root, route, scopes, exclude)),
|
|
357
|
+
);
|
|
358
|
+
const enumerated =
|
|
359
|
+
paths === undefined
|
|
360
|
+
? await Promise.all(
|
|
361
|
+
routes.map(
|
|
362
|
+
async (route) =>
|
|
363
|
+
await sourceFiles(
|
|
364
|
+
root,
|
|
365
|
+
route.scope,
|
|
366
|
+
(file) =>
|
|
367
|
+
isManagedQualityPathExcluded({ exclude, path: file }) ||
|
|
368
|
+
route.boundaries.some((boundary) => contains(boundary, file)),
|
|
369
|
+
),
|
|
370
|
+
),
|
|
371
|
+
)
|
|
372
|
+
: [];
|
|
373
|
+
const requested = paths ?? enumerated.flat();
|
|
374
|
+
if (!validPaths(requested)) {
|
|
375
|
+
return conflict("Lint input paths must be repository-relative and contained.");
|
|
376
|
+
}
|
|
377
|
+
/** @type {string[]} */
|
|
378
|
+
const excludedPaths = [];
|
|
379
|
+
await Promise.all(
|
|
380
|
+
[...new Set(requested)].map(async (file) => {
|
|
381
|
+
for (const dependent of routes) {
|
|
382
|
+
if (isRouteDependency(file, dependent)) {
|
|
383
|
+
dependent.triggered = true;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const selectedScope = ownerScope(scopes, file);
|
|
387
|
+
const owner = routes.find((route) => route.scope === selectedScope);
|
|
388
|
+
if (
|
|
389
|
+
owner === undefined ||
|
|
390
|
+
isManagedQualityPathExcluded({ exclude, path: file }) ||
|
|
391
|
+
owner.boundaries.some((boundary) => contains(boundary, file)) ||
|
|
392
|
+
!(await containedRealPath(root, path.resolve(root, file), true))
|
|
393
|
+
) {
|
|
394
|
+
excludedPaths.push(file);
|
|
395
|
+
} else {
|
|
396
|
+
owner.files.push(file);
|
|
397
|
+
}
|
|
398
|
+
}),
|
|
399
|
+
);
|
|
400
|
+
return {
|
|
401
|
+
excludedPaths: excludedPaths.toSorted(),
|
|
402
|
+
routes: routes.map((route) => ({ ...route, files: route.files.toSorted() })),
|
|
403
|
+
status: "ready",
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
/** Describe a check; execution and controlled temporary mirrors belong to adapters.
|
|
408
|
+
* @param {CommandOptions} options @returns {Promise<Command>} */
|
|
409
|
+
export const buildManagedLintCommand = async (options) => {
|
|
410
|
+
try {
|
|
411
|
+
return await buildCommand(options);
|
|
412
|
+
} catch (error) {
|
|
413
|
+
return conflict(`Cannot construct managed lint command: ${errorMessage(error)}`);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
/** @param {string} root @param {string} directory @param {string} version @returns {Promise<{executable: string, version: string}>} */
|
|
417
|
+
const resolveTool = async (root, directory, version) => {
|
|
418
|
+
const manifest = path.join(directory, "node_modules", "oxlint", "package.json");
|
|
419
|
+
if (await exists(manifest)) {
|
|
420
|
+
/** @type {unknown} */
|
|
421
|
+
const value = JSON.parse(await readFile(manifest, "utf-8"));
|
|
422
|
+
if (!record(value) || value.name !== "oxlint" || value.version !== version) {
|
|
423
|
+
throw new Error(
|
|
424
|
+
`Local Oxlint version differs from route at ${manifest}; regenerate managed lint routes.`,
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
const bin = typeof value.bin === "string" ? value.bin : field(value.bin, "oxlint");
|
|
428
|
+
if (!validPath(bin)) {
|
|
429
|
+
throw new Error(`Invalid local Oxlint executable at ${manifest}`);
|
|
430
|
+
}
|
|
431
|
+
const executable = path.resolve(path.dirname(manifest), bin);
|
|
432
|
+
if (!(await exists(executable))) {
|
|
433
|
+
throw new Error(`Local Oxlint executable is missing: ${executable}`);
|
|
434
|
+
}
|
|
435
|
+
return { executable, version: value.version };
|
|
436
|
+
}
|
|
437
|
+
if (directory === path.resolve(root) || !containsPhysical(root, directory)) {
|
|
438
|
+
throw new Error(
|
|
439
|
+
`No repository-local Oxlint installation for ${directory}; install the selected toolchain.`,
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
return await resolveTool(root, path.dirname(directory), version);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
/** @param {string} root @param {ResolvedRoute} route @param {string | undefined} logicalSourcePath @returns {Promise<string[]>} */
|
|
446
|
+
const commandFiles = async (root, route, logicalSourcePath) => {
|
|
447
|
+
if (logicalSourcePath !== undefined && !route.files.includes(logicalSourcePath)) {
|
|
448
|
+
throw new Error("Logical source is not in the resolved eligible file set.");
|
|
449
|
+
}
|
|
450
|
+
const sourcePaths = logicalSourcePath === undefined ? route.files : [logicalSourcePath];
|
|
451
|
+
const files = await Promise.all(
|
|
452
|
+
[...new Set(sourcePaths)].map(async (file) => {
|
|
453
|
+
if (
|
|
454
|
+
!validPath(file) ||
|
|
455
|
+
!contains(route.scope, file) ||
|
|
456
|
+
wiki(file) ||
|
|
457
|
+
blocked(file) ||
|
|
458
|
+
route.boundaries.some((boundary) => contains(boundary, file))
|
|
459
|
+
) {
|
|
460
|
+
throw new Error("Command inputs fall outside the resolved owner.");
|
|
461
|
+
}
|
|
462
|
+
const absolute = path.resolve(root, file);
|
|
463
|
+
if (!(await containedRealPath(root, absolute))) {
|
|
464
|
+
throw new Error(`Lint input escapes repository: ${file}`);
|
|
465
|
+
}
|
|
466
|
+
if (!(await exists(absolute))) {
|
|
467
|
+
return [];
|
|
468
|
+
}
|
|
469
|
+
const info = await stat(absolute);
|
|
470
|
+
if (!info.isFile()) {
|
|
471
|
+
throw new Error(`Lint input must be an explicit file: ${file}`);
|
|
472
|
+
}
|
|
473
|
+
return [path.relative(path.resolve(root, route.scope), absolute)];
|
|
474
|
+
}),
|
|
475
|
+
);
|
|
476
|
+
return files.flat();
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
/** @param {CommandOptions} options @returns {Promise<Command>} */
|
|
480
|
+
const buildCommand = async ({
|
|
481
|
+
root,
|
|
482
|
+
route,
|
|
483
|
+
output = "human",
|
|
484
|
+
logicalSourcePath,
|
|
485
|
+
physicalInputPath,
|
|
486
|
+
}) => {
|
|
487
|
+
if (
|
|
488
|
+
physicalInputPath !== undefined &&
|
|
489
|
+
(logicalSourcePath === undefined ||
|
|
490
|
+
path.resolve(physicalInputPath) !== path.resolve(root, logicalSourcePath))
|
|
491
|
+
) {
|
|
492
|
+
return conflict(
|
|
493
|
+
"Temporary input has no proven logical-path policy parity; use a controlled repository mirror.",
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
if (
|
|
497
|
+
!validRoute(route) ||
|
|
498
|
+
!strings(route.files) ||
|
|
499
|
+
!strings(route.boundaries) ||
|
|
500
|
+
!["human", "json"].includes(output)
|
|
501
|
+
) {
|
|
502
|
+
return conflict("Invalid managed lint command route.");
|
|
503
|
+
}
|
|
504
|
+
await verifyPolicyInputs(root, route);
|
|
505
|
+
const cwd = path.resolve(root, route.scope);
|
|
506
|
+
const config = path.resolve(root, route.config);
|
|
507
|
+
if (!(await containedRealPath(root, cwd)) || !(await containedRealPath(root, config))) {
|
|
508
|
+
return conflict("Managed lint owner or config escapes repository.");
|
|
509
|
+
}
|
|
510
|
+
if (!(await exists(config))) {
|
|
511
|
+
return conflict(`Effective lint config is missing: ${route.config}`);
|
|
512
|
+
}
|
|
513
|
+
const tool = await resolveTool(root, cwd, route.tool.version);
|
|
514
|
+
const files = await commandFiles(root, route, logicalSourcePath);
|
|
515
|
+
if (files.length === 0) {
|
|
516
|
+
return { diagnostics: [], status: "empty" };
|
|
517
|
+
}
|
|
518
|
+
const args = ["--config", config, "--disable-nested-config"];
|
|
519
|
+
if (route.maxWarnings !== null) {
|
|
520
|
+
args.push("--max-warnings", String(route.maxWarnings));
|
|
521
|
+
}
|
|
522
|
+
if (output === "json") {
|
|
523
|
+
args.push("--format", "json");
|
|
524
|
+
}
|
|
525
|
+
args.push("--", ...files);
|
|
526
|
+
return {
|
|
527
|
+
args,
|
|
528
|
+
config,
|
|
529
|
+
cwd,
|
|
530
|
+
executable: tool.executable,
|
|
531
|
+
logicalSourcePath,
|
|
532
|
+
physicalInputPath,
|
|
533
|
+
scope: route.scope,
|
|
534
|
+
status: "ready",
|
|
535
|
+
toolVersion: tool.version,
|
|
536
|
+
};
|
|
537
|
+
};
|
|
538
|
+
/** @param {string} root @param {string} file @returns {boolean} */
|
|
539
|
+
const containsPhysical = (root, file) => {
|
|
540
|
+
const relative = path.relative(path.resolve(root), file);
|
|
541
|
+
return (
|
|
542
|
+
relative === "" ||
|
|
543
|
+
(!relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative))
|
|
544
|
+
);
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
/** @param {string} root @param {string} file @param {boolean} canonical @returns {Promise<boolean>} */
|
|
548
|
+
const containedRealPath = async (root, file, canonical = false) => {
|
|
549
|
+
const actualRoot = await realpath(root);
|
|
550
|
+
/** @param {string} current @returns {Promise<boolean>} */
|
|
551
|
+
const resolveExisting = async (current) => {
|
|
552
|
+
try {
|
|
553
|
+
const actual = await realpath(current);
|
|
554
|
+
return (
|
|
555
|
+
containsPhysical(actualRoot, actual) &&
|
|
556
|
+
(!canonical || actual === path.resolve(actualRoot, path.relative(root, current)))
|
|
557
|
+
);
|
|
558
|
+
} catch (error) {
|
|
559
|
+
if (field(error, "code") !== "ENOENT") {
|
|
560
|
+
throw error;
|
|
561
|
+
}
|
|
562
|
+
if (current === path.dirname(current)) {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
return await resolveExisting(path.dirname(current));
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
return await resolveExisting(file);
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
// Portable glob subset used by saved exclusions: *, **, ?, character classes and brace alternatives.
|
|
572
|
+
// No dependency on Node's newer path.matchesGlob API in consumer hooks.
|
|
573
|
+
/** @param {string} file @param {string} pattern @returns {boolean} */
|
|
574
|
+
const matchesGlob = (file, pattern) => {
|
|
575
|
+
let source = "";
|
|
576
|
+
let braces = 0;
|
|
577
|
+
for (let i = 0; i < pattern.length; i += 1) {
|
|
578
|
+
const char = pattern[i];
|
|
579
|
+
if (char === "*") {
|
|
580
|
+
if (pattern[i + 1] === "*") {
|
|
581
|
+
i += 1;
|
|
582
|
+
if (pattern[i + 1] === "/") {
|
|
583
|
+
i += 1;
|
|
584
|
+
source += "(?:.*/)?";
|
|
585
|
+
} else {
|
|
586
|
+
source += ".*";
|
|
587
|
+
}
|
|
588
|
+
} else {
|
|
589
|
+
source += "[^/]*";
|
|
590
|
+
}
|
|
591
|
+
} else if (char === "?") {
|
|
592
|
+
source += "[^/]";
|
|
593
|
+
} else if (char === "{") {
|
|
594
|
+
source += "(?:";
|
|
595
|
+
braces += 1;
|
|
596
|
+
} else if (char === "}" && braces > 0) {
|
|
597
|
+
source += ")";
|
|
598
|
+
braces -= 1;
|
|
599
|
+
} else if (char === "," && braces > 0) {
|
|
600
|
+
source += "|";
|
|
601
|
+
} else if (char === "[") {
|
|
602
|
+
const end = pattern.indexOf("]", i + 1);
|
|
603
|
+
if (end === -1) {
|
|
604
|
+
throw new Error(`Unclosed exclusion character class: ${pattern}`);
|
|
605
|
+
}
|
|
606
|
+
let group = pattern.slice(i + 1, end);
|
|
607
|
+
if (group.startsWith("!")) {
|
|
608
|
+
group = `^${group.slice(1)}`;
|
|
609
|
+
}
|
|
610
|
+
source += `[${group}]`;
|
|
611
|
+
i = end;
|
|
612
|
+
} else {
|
|
613
|
+
source += char.replaceAll(/[|\\{}()[\]^$+?.]/gu, "\\$&");
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (braces !== 0) {
|
|
617
|
+
throw new Error(`Unclosed exclusion alternatives: ${pattern}`);
|
|
618
|
+
}
|
|
619
|
+
return new RegExp(`^(?:${source})$`, "u").test(file);
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
/** @param {unknown} inputs @returns {inputs is readonly PolicyInput[] | undefined} */
|
|
623
|
+
const validPolicyInputs = (inputs) =>
|
|
624
|
+
inputs === undefined ||
|
|
625
|
+
(array(inputs) &&
|
|
626
|
+
inputs.every(
|
|
627
|
+
(input) =>
|
|
628
|
+
record(input) &&
|
|
629
|
+
validPath(input.path) &&
|
|
630
|
+
typeof input.sha256 === "string" &&
|
|
631
|
+
/^[a-f0-9]{64}$/u.test(input.sha256),
|
|
632
|
+
));
|
|
633
|
+
|
|
634
|
+
/** @param {string} root @param {Route} route @returns {Promise<void>} */
|
|
635
|
+
const verifyPolicyInputs = async (root, route) => {
|
|
636
|
+
await Promise.all(
|
|
637
|
+
(route.policyInputs ?? []).map(async (input) => {
|
|
638
|
+
const absolute = path.resolve(root, input.path);
|
|
639
|
+
const stale = () =>
|
|
640
|
+
new Error(
|
|
641
|
+
`Stale project policy input ${input.path}; run hi scaffold/update to compile current policy.`,
|
|
642
|
+
);
|
|
643
|
+
if (!(await containedRealPath(root, absolute)) || !(await exists(absolute))) {
|
|
644
|
+
throw stale();
|
|
645
|
+
}
|
|
646
|
+
const info = await stat(absolute);
|
|
647
|
+
if (!info.isFile()) {
|
|
648
|
+
throw stale();
|
|
649
|
+
}
|
|
650
|
+
const hash = createHash("sha256")
|
|
651
|
+
.update(await readFile(absolute))
|
|
652
|
+
.digest("hex");
|
|
653
|
+
if (hash !== input.sha256) {
|
|
654
|
+
throw stale();
|
|
655
|
+
}
|
|
656
|
+
}),
|
|
657
|
+
);
|
|
658
|
+
};
|