@inixiative/config 0.5.260 → 0.5.261
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 +18 -0
- package/dist/cli.js +545 -175
- package/package.json +3 -1
- package/skills/cleanup-scan/SKILL.md +89 -0
- package/skills/code-walkthrough/SKILL.md +29 -0
- package/skills/experiment/SKILL.md +79 -0
- package/skills/experiment/design.md +44 -0
- package/skills/experiment/finding.json +16 -0
- package/skills/experiment/review.md +33 -0
- package/skills/labeling/SKILL.md +40 -0
- package/skills/no-slop-writing/SKILL.md +69 -0
- package/skills/no-slop-writing/references/register-anchors.md +64 -0
- package/skills/no-slop-writing/references/slop-quarantine.md +97 -0
- package/skills/permissions-syntax-first/SKILL.md +142 -0
- package/skills/probe/SKILL.md +74 -0
- package/skills/probe/record.json +24 -0
- package/skills/reflecting-without-flinching/SKILL.md +32 -0
- package/skills/review-adversarial/SKILL.md +39 -0
- package/skills/review-dedupe/SKILL.md +38 -0
- package/skills/review-naming/SKILL.md +35 -0
- package/skills/review-plan/SKILL.md +38 -0
- package/skills/review-subtractor/SKILL.md +48 -0
- package/skills/worktrees/SKILL.md +57 -0
- package/standards/CODE_STYLE.md +83 -0
- package/standards/ENGINEERING_DOCTRINE.md +84 -0
- package/standards/GREAT_PROGRAMMER.md +128 -0
- package/standards/NAMING_VOCABULARY.md +72 -0
- package/standards/SKILL_AUTHORING.md +55 -0
- package/versions.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -1,41 +1,335 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
import { spawnSync as
|
|
4
|
+
import { spawnSync as spawnSync5 } from "child_process";
|
|
5
5
|
import {
|
|
6
6
|
existsSync as existsSync3,
|
|
7
|
-
mkdirSync as
|
|
7
|
+
mkdirSync as mkdirSync5,
|
|
8
8
|
mkdtempSync,
|
|
9
|
-
readdirSync as
|
|
10
|
-
readFileSync as
|
|
11
|
-
rmSync as
|
|
12
|
-
writeFileSync as
|
|
9
|
+
readdirSync as readdirSync4,
|
|
10
|
+
readFileSync as readFileSync4,
|
|
11
|
+
rmSync as rmSync4,
|
|
12
|
+
writeFileSync as writeFileSync4
|
|
13
13
|
} from "fs";
|
|
14
14
|
import { hostname as hostname2, tmpdir } from "os";
|
|
15
|
-
import { basename as basename2, dirname as
|
|
15
|
+
import { basename as basename2, dirname as dirname5, join as join5, resolve as resolve2 } from "path";
|
|
16
16
|
|
|
17
17
|
// src/args.ts
|
|
18
18
|
import { parseArgs } from "util";
|
|
19
19
|
|
|
20
20
|
// src/lib.ts
|
|
21
|
-
import { spawnSync } from "child_process";
|
|
21
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
22
22
|
import { randomUUID } from "crypto";
|
|
23
23
|
import {
|
|
24
24
|
existsSync,
|
|
25
25
|
globSync,
|
|
26
26
|
linkSync,
|
|
27
|
+
mkdirSync as mkdirSync2,
|
|
28
|
+
readdirSync as readdirSync2,
|
|
29
|
+
readFileSync as readFileSync2,
|
|
30
|
+
realpathSync as realpathSync2,
|
|
31
|
+
rmSync as rmSync2,
|
|
32
|
+
statSync,
|
|
33
|
+
writeFileSync as writeFileSync2
|
|
34
|
+
} from "fs";
|
|
35
|
+
import { homedir, hostname } from "os";
|
|
36
|
+
import { dirname as dirname2, join as join2, resolve, sep as sep2 } from "path";
|
|
37
|
+
import { fileURLToPath } from "url";
|
|
38
|
+
|
|
39
|
+
// src/standards.ts
|
|
40
|
+
import { spawnSync } from "child_process";
|
|
41
|
+
import {
|
|
42
|
+
lstatSync,
|
|
27
43
|
mkdirSync,
|
|
28
44
|
readdirSync,
|
|
29
45
|
readFileSync,
|
|
30
46
|
realpathSync,
|
|
31
47
|
rmSync,
|
|
32
|
-
statSync,
|
|
33
48
|
writeFileSync
|
|
34
49
|
} from "fs";
|
|
35
|
-
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var
|
|
50
|
+
import { dirname, join, sep } from "path";
|
|
51
|
+
var STANDARDS_PROFILES = ["app", "agentic"];
|
|
52
|
+
var STANDARDS_DIR = "docs/standards";
|
|
53
|
+
var SKILLS_DIR = ".claude/skills";
|
|
54
|
+
var SKILL_PREFIX = "inixiative-";
|
|
55
|
+
var STANDARDS_GITIGNORE_RULES = [
|
|
56
|
+
{
|
|
57
|
+
rule: "/docs/standards/",
|
|
58
|
+
probe: "docs/standards/GREAT_PROGRAMMER.md",
|
|
59
|
+
label: "docs/standards/"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
rule: "/.claude/skills/inixiative-*/",
|
|
63
|
+
probe: ".claude/skills/inixiative-cleanup-scan/SKILL.md",
|
|
64
|
+
label: ".claude/skills/inixiative-*/"
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
var STANDARDS_PREPARE = "if git rev-parse --git-dir >/dev/null 2>&1 && [ -x node_modules/.bin/inixiative-config ]; then bun ./node_modules/.bin/inixiative-config standards; fi";
|
|
68
|
+
var STANDARD_DOCS = [
|
|
69
|
+
"CODE_STYLE.md",
|
|
70
|
+
"ENGINEERING_DOCTRINE.md",
|
|
71
|
+
"GREAT_PROGRAMMER.md",
|
|
72
|
+
"NAMING_VOCABULARY.md",
|
|
73
|
+
"SKILL_AUTHORING.md"
|
|
74
|
+
];
|
|
75
|
+
var UNIVERSAL_SKILLS = [
|
|
76
|
+
"cleanup-scan",
|
|
77
|
+
"code-walkthrough",
|
|
78
|
+
"labeling",
|
|
79
|
+
"no-slop-writing",
|
|
80
|
+
"reflecting-without-flinching",
|
|
81
|
+
"review-adversarial",
|
|
82
|
+
"review-dedupe",
|
|
83
|
+
"review-naming",
|
|
84
|
+
"review-plan",
|
|
85
|
+
"review-subtractor",
|
|
86
|
+
"worktrees"
|
|
87
|
+
];
|
|
88
|
+
var PROFILE_SKILLS = {
|
|
89
|
+
app: ["permissions-syntax-first"],
|
|
90
|
+
agentic: ["experiment", "probe"]
|
|
91
|
+
};
|
|
92
|
+
var SHARED_ANCESTORS = ["docs", ".claude", SKILLS_DIR];
|
|
93
|
+
var lstatOrNull = (path) => {
|
|
94
|
+
try {
|
|
95
|
+
return lstatSync(path);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
const code = error.code;
|
|
98
|
+
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var appendGitignoreLine = (dir2, line) => {
|
|
103
|
+
const gitignorePath = join(dir2, ".gitignore");
|
|
104
|
+
const current = lstatOrNull(gitignorePath) ? readFileSync(gitignorePath, "utf8") : "";
|
|
105
|
+
const separator = current === "" || current.endsWith("\n") ? "" : "\n";
|
|
106
|
+
writeFileSync(gitignorePath, `${current}${separator}${line}
|
|
107
|
+
`);
|
|
108
|
+
};
|
|
109
|
+
var isStandardsProfile = (value) => typeof value === "string" && STANDARDS_PROFILES.includes(value);
|
|
110
|
+
var resolveStandardsProfiles = (pkg) => {
|
|
111
|
+
const raw = pkg.inixiative?.profiles;
|
|
112
|
+
if (raw === void 0) return { profiles: [] };
|
|
113
|
+
if (!Array.isArray(raw)) {
|
|
114
|
+
return {
|
|
115
|
+
profiles: [],
|
|
116
|
+
error: `package.json inixiative.profiles must be an array of ${STANDARDS_PROFILES.join(" | ")}`
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const invalid = raw.filter((item) => !isStandardsProfile(item));
|
|
120
|
+
if (invalid.length > 0) {
|
|
121
|
+
return {
|
|
122
|
+
profiles: [],
|
|
123
|
+
error: `package.json inixiative.profiles contains unknown profile(s): ${invalid.map(String).join(", ")} (valid: ${STANDARDS_PROFILES.join(", ")})`
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return { profiles: [...new Set(raw)] };
|
|
127
|
+
};
|
|
128
|
+
var resolvedSkillNames = (profiles) => {
|
|
129
|
+
const names = new Set(UNIVERSAL_SKILLS);
|
|
130
|
+
for (const profile of profiles) {
|
|
131
|
+
for (const skill of PROFILE_SKILLS[profile]) names.add(skill);
|
|
132
|
+
}
|
|
133
|
+
return [...names].sort();
|
|
134
|
+
};
|
|
135
|
+
var walkFiles = (rootDir, prefix = "") => {
|
|
136
|
+
const results = [];
|
|
137
|
+
for (const entry of readdirSync(rootDir, { withFileTypes: true })) {
|
|
138
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
139
|
+
const abs = join(rootDir, entry.name);
|
|
140
|
+
if (entry.isDirectory()) {
|
|
141
|
+
results.push(...walkFiles(abs, rel));
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (entry.isFile()) results.push(rel);
|
|
145
|
+
}
|
|
146
|
+
return results.sort();
|
|
147
|
+
};
|
|
148
|
+
var fetchExpectedStandardsFiles = (configRoot, profiles) => {
|
|
149
|
+
const files = /* @__PURE__ */ new Map();
|
|
150
|
+
for (const doc of STANDARD_DOCS) {
|
|
151
|
+
files.set(`${STANDARDS_DIR}/${doc}`, join(configRoot, "standards", doc));
|
|
152
|
+
}
|
|
153
|
+
for (const skill of resolvedSkillNames(profiles)) {
|
|
154
|
+
const skillRoot = join(configRoot, "skills", skill);
|
|
155
|
+
for (const rel of walkFiles(skillRoot)) {
|
|
156
|
+
files.set(`${SKILLS_DIR}/${SKILL_PREFIX}${skill}/${rel}`, join(skillRoot, rel));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return files;
|
|
160
|
+
};
|
|
161
|
+
var ancestorProblems = (dir2) => {
|
|
162
|
+
const problems = [];
|
|
163
|
+
const rootReal = realpathSync(dir2);
|
|
164
|
+
for (const rel of SHARED_ANCESTORS) {
|
|
165
|
+
const abs = join(dir2, rel);
|
|
166
|
+
const stat = lstatOrNull(abs);
|
|
167
|
+
if (!stat) continue;
|
|
168
|
+
if (stat.isSymbolicLink()) {
|
|
169
|
+
problems.push(`${rel} is a symlink \u2014 refusing to traverse outside the repository`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (!stat.isDirectory()) {
|
|
173
|
+
problems.push(`${rel} is not a directory`);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const resolved = realpathSync(abs);
|
|
177
|
+
if (resolved !== rootReal && !resolved.startsWith(`${rootReal}${sep}`)) {
|
|
178
|
+
problems.push(`${rel} resolves outside the repository`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return problems;
|
|
182
|
+
};
|
|
183
|
+
var expectedDirectoriesOf = (expected) => {
|
|
184
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
185
|
+
for (const rel of expected.keys()) {
|
|
186
|
+
let cur = dirname(rel);
|
|
187
|
+
while (cur !== "." && cur !== "") {
|
|
188
|
+
dirs.add(cur);
|
|
189
|
+
cur = dirname(cur);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return dirs;
|
|
193
|
+
};
|
|
194
|
+
var staleStandardsPaths = (dir2, expected, activeSkillDirs) => {
|
|
195
|
+
const expectedDirs = expectedDirectoriesOf(expected);
|
|
196
|
+
const stale = [];
|
|
197
|
+
const scanManagedRoot = (relRoot) => {
|
|
198
|
+
const absRoot = join(dir2, relRoot);
|
|
199
|
+
const stat = lstatOrNull(absRoot);
|
|
200
|
+
if (!stat) return;
|
|
201
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
202
|
+
stale.push(relRoot);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
for (const entry of readdirSync(absRoot)) {
|
|
206
|
+
const rel = `${relRoot}/${entry}`;
|
|
207
|
+
const childStat = lstatOrNull(join(dir2, rel));
|
|
208
|
+
if (!childStat) continue;
|
|
209
|
+
if (childStat.isSymbolicLink()) {
|
|
210
|
+
stale.push(rel);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (childStat.isDirectory()) {
|
|
214
|
+
if (!expectedDirs.has(rel)) {
|
|
215
|
+
stale.push(rel);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
scanManagedRoot(rel);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (!expected.has(rel)) stale.push(rel);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
scanManagedRoot(STANDARDS_DIR);
|
|
225
|
+
const skillsAbs = join(dir2, SKILLS_DIR);
|
|
226
|
+
const skillsStat = lstatOrNull(skillsAbs);
|
|
227
|
+
if (skillsStat && !skillsStat.isSymbolicLink() && skillsStat.isDirectory()) {
|
|
228
|
+
for (const entry of readdirSync(skillsAbs)) {
|
|
229
|
+
if (!entry.startsWith(SKILL_PREFIX)) continue;
|
|
230
|
+
const rel = `${SKILLS_DIR}/${entry}`;
|
|
231
|
+
const stat = lstatOrNull(join(dir2, rel));
|
|
232
|
+
if (!stat) continue;
|
|
233
|
+
if (stat.isSymbolicLink() || !stat.isDirectory() || !activeSkillDirs.has(entry)) {
|
|
234
|
+
stale.push(rel);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
scanManagedRoot(rel);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return stale.sort();
|
|
241
|
+
};
|
|
242
|
+
var syncStandards = (dir2, configRoot, profiles) => {
|
|
243
|
+
const problems = ancestorProblems(dir2);
|
|
244
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
245
|
+
const expected = fetchExpectedStandardsFiles(configRoot, profiles);
|
|
246
|
+
const activeSkillDirs = new Set(resolvedSkillNames(profiles).map((s) => `${SKILL_PREFIX}${s}`));
|
|
247
|
+
const removed = staleStandardsPaths(dir2, expected, activeSkillDirs);
|
|
248
|
+
for (const rel of removed) {
|
|
249
|
+
rmSync(join(dir2, rel), { recursive: true, force: true });
|
|
250
|
+
}
|
|
251
|
+
const written = [];
|
|
252
|
+
for (const [rel, srcAbs] of expected) {
|
|
253
|
+
const destAbs = join(dir2, rel);
|
|
254
|
+
const srcBytes = readFileSync(srcAbs);
|
|
255
|
+
const stat = lstatOrNull(destAbs);
|
|
256
|
+
if (stat) {
|
|
257
|
+
if (stat.isFile() && !stat.isSymbolicLink() && readFileSync(destAbs).equals(srcBytes)) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
rmSync(destAbs, { recursive: true, force: true });
|
|
261
|
+
}
|
|
262
|
+
mkdirSync(dirname(destAbs), { recursive: true });
|
|
263
|
+
writeFileSync(destAbs, srcBytes);
|
|
264
|
+
written.push(rel);
|
|
265
|
+
}
|
|
266
|
+
return { written, removed };
|
|
267
|
+
};
|
|
268
|
+
var inspectStandards = (dir2, pkg, configRoot, options = {}) => {
|
|
269
|
+
if (pkg.name === "@inixiative/config") return [];
|
|
270
|
+
const findings = [];
|
|
271
|
+
const { profiles, error } = resolveStandardsProfiles(pkg);
|
|
272
|
+
if (error) {
|
|
273
|
+
findings.push({ level: "error", message: error });
|
|
274
|
+
return findings;
|
|
275
|
+
}
|
|
276
|
+
const problems = ancestorProblems(dir2);
|
|
277
|
+
if (problems.length > 0) {
|
|
278
|
+
for (const message of problems) findings.push({ level: "error", message });
|
|
279
|
+
return findings;
|
|
280
|
+
}
|
|
281
|
+
if (options.gitRepo) {
|
|
282
|
+
for (const { rule, probe, label } of STANDARDS_GITIGNORE_RULES) {
|
|
283
|
+
const ignored = spawnSync("git", ["check-ignore", "-q", probe], { cwd: dir2 }).status === 0;
|
|
284
|
+
if (ignored) continue;
|
|
285
|
+
findings.push({
|
|
286
|
+
level: "error",
|
|
287
|
+
message: `${label} is not gitignored \u2192 adding ${rule} to .gitignore`,
|
|
288
|
+
fix: () => appendGitignoreLine(dir2, rule)
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const expected = fetchExpectedStandardsFiles(configRoot, profiles);
|
|
293
|
+
const activeSkillDirs = new Set(resolvedSkillNames(profiles).map((s) => `${SKILL_PREFIX}${s}`));
|
|
294
|
+
const missing = [];
|
|
295
|
+
const drifted = /* @__PURE__ */ new Set();
|
|
296
|
+
for (const [rel, srcAbs] of expected) {
|
|
297
|
+
const destAbs = join(dir2, rel);
|
|
298
|
+
const stat = lstatOrNull(destAbs);
|
|
299
|
+
if (!stat) {
|
|
300
|
+
missing.push(rel);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
304
|
+
drifted.add(rel);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (!readFileSync(destAbs).equals(readFileSync(srcAbs))) {
|
|
308
|
+
drifted.add(rel);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const stale = staleStandardsPaths(dir2, expected, activeSkillDirs).filter(
|
|
312
|
+
(rel) => !drifted.has(rel)
|
|
313
|
+
);
|
|
314
|
+
if (missing.length > 0 || drifted.size > 0 || stale.length > 0) {
|
|
315
|
+
const summary = [
|
|
316
|
+
missing.length > 0 ? `${missing.length} missing` : null,
|
|
317
|
+
drifted.size > 0 ? `${drifted.size} drifted` : null,
|
|
318
|
+
stale.length > 0 ? `${stale.length} unused (${stale.slice(0, 3).join(", ")})` : null
|
|
319
|
+
].filter(Boolean).join(", ");
|
|
320
|
+
findings.push({
|
|
321
|
+
level: "error",
|
|
322
|
+
message: `shared standards/skills out of sync (${summary}) \u2192 run inixiative-config standards`,
|
|
323
|
+
fix: () => {
|
|
324
|
+
syncStandards(dir2, configRoot, profiles);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return findings;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// src/lib.ts
|
|
332
|
+
var packageRoot = join2(dirname2(fileURLToPath(import.meta.url)), "..");
|
|
39
333
|
var LANES = ["primitives", "agentic"];
|
|
40
334
|
var isLane = (value) => LANES.includes(value);
|
|
41
335
|
var lanePackages = (manifest2, lane2) => {
|
|
@@ -121,8 +415,8 @@ var boundedCheckWithLimits = /^(inixiative-config|bun src\/cli\.ts) bounded( --[
|
|
|
121
415
|
var DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies"];
|
|
122
416
|
var LEFTHOOK_PREPARE = 'if git rev-parse --git-dir >/dev/null 2>&1; then root="$(dirname "$(git rev-parse --path-format=absolute --git-common-dir)")"; if [ -x "$root/node_modules/.bin/lefthook" ]; then (cd "$root" && ./node_modules/.bin/lefthook install); fi; fi';
|
|
123
417
|
var lefthookInstallInPrepare = /if [^;]*; then lefthook install; fi|lefthook install/;
|
|
124
|
-
var loadManifest = () => JSON.parse(
|
|
125
|
-
var ownVersion = () => JSON.parse(
|
|
418
|
+
var loadManifest = () => JSON.parse(readFileSync2(join2(packageRoot, "versions.json"), "utf8"));
|
|
419
|
+
var ownVersion = () => JSON.parse(readFileSync2(join2(packageRoot, "package.json"), "utf8")).version;
|
|
126
420
|
var stripJsonc = (text) => {
|
|
127
421
|
let out = "";
|
|
128
422
|
let inString = false;
|
|
@@ -249,26 +543,26 @@ var npmAlias = (spec) => {
|
|
|
249
543
|
};
|
|
250
544
|
var readJson = (path) => {
|
|
251
545
|
try {
|
|
252
|
-
return tryParseJsonc(
|
|
546
|
+
return tryParseJsonc(readFileSync2(path, "utf8"));
|
|
253
547
|
} catch {
|
|
254
548
|
return null;
|
|
255
549
|
}
|
|
256
550
|
};
|
|
257
551
|
var originRepo = (dir2) => {
|
|
258
|
-
const url =
|
|
552
|
+
const url = spawnSync2("git", ["remote", "get-url", "origin"], { cwd: dir2, encoding: "utf8" });
|
|
259
553
|
if (url.status !== 0) return null;
|
|
260
554
|
const match = url.stdout.trim().match(/github\.com[:/]([^/]+\/[^/]+?)(?:\.git)?\/?$/);
|
|
261
555
|
return match ? match[1] : null;
|
|
262
556
|
};
|
|
263
557
|
var isLinkedWorktree = (dir2) => {
|
|
264
|
-
const dotGit =
|
|
558
|
+
const dotGit = join2(dir2, ".git");
|
|
265
559
|
return existsSync(dotGit) && !statSync(dotGit).isDirectory();
|
|
266
560
|
};
|
|
267
|
-
var childDirs = (dir2) =>
|
|
561
|
+
var childDirs = (dir2) => readdirSync2(dir2, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).filter((entry) => entry.name !== "node_modules").map((entry) => join2(dir2, entry.name));
|
|
268
562
|
var candidateDirs = (root) => {
|
|
269
563
|
const dirs = [];
|
|
270
564
|
for (const child of childDirs(root)) {
|
|
271
|
-
const nested = existsSync(
|
|
565
|
+
const nested = existsSync(join2(child, "package.json")) ? [child] : childDirs(child).filter((dir2) => existsSync(join2(dir2, "package.json")));
|
|
272
566
|
dirs.push(...nested.filter((dir2) => !isLinkedWorktree(dir2)));
|
|
273
567
|
}
|
|
274
568
|
return dirs;
|
|
@@ -282,13 +576,13 @@ var discover = (root, manifest2, lanes2 = LANES) => {
|
|
|
282
576
|
const claims = /* @__PURE__ */ new Map();
|
|
283
577
|
const claim = (key, checkout) => claims.set(key, [...claims.get(key) ?? [], checkout]);
|
|
284
578
|
for (const dir2 of candidateDirs(root)) {
|
|
285
|
-
const pkg = readJson(
|
|
579
|
+
const pkg = readJson(join2(dir2, "package.json"));
|
|
286
580
|
if (!pkg) continue;
|
|
287
581
|
const name = typeof pkg.name === "string" ? pkg.name : dir2;
|
|
288
582
|
const provided = [
|
|
289
583
|
{ name: pkg.name, path: "package.json" },
|
|
290
584
|
...workspacePackagePaths(dir2, pkg).map((path) => ({
|
|
291
|
-
name: readJson(
|
|
585
|
+
name: readJson(join2(dir2, path))?.name,
|
|
292
586
|
path
|
|
293
587
|
}))
|
|
294
588
|
].filter(
|
|
@@ -305,7 +599,7 @@ var discover = (root, manifest2, lanes2 = LANES) => {
|
|
|
305
599
|
for (const entry of provided) claim(entry.name, checkout);
|
|
306
600
|
continue;
|
|
307
601
|
}
|
|
308
|
-
if (consumerRepos.size === 0 || !existsSync(
|
|
602
|
+
if (consumerRepos.size === 0 || !existsSync(join2(dir2, ".git"))) continue;
|
|
309
603
|
const repo = originRepo(dir2);
|
|
310
604
|
if (repo && consumerRepos.has(repo)) {
|
|
311
605
|
const consumer = manifest2.consumers[repo];
|
|
@@ -316,7 +610,7 @@ var discover = (root, manifest2, lanes2 = LANES) => {
|
|
|
316
610
|
const ambiguous = [];
|
|
317
611
|
for (const [key, candidates] of claims) {
|
|
318
612
|
let pool = candidates.length > 1 ? candidates.filter((candidate) => originRepo(candidate.dir)) : candidates;
|
|
319
|
-
const direct = pool.filter((candidate) =>
|
|
613
|
+
const direct = pool.filter((candidate) => dirname2(candidate.dir) === resolve(root));
|
|
320
614
|
if (pool.length > 1 && direct.length === 1) pool = direct;
|
|
321
615
|
if (pool.length === 1) chosen.set(pool[0].dir, pool[0]);
|
|
322
616
|
else ambiguous.push({ key, dirs: candidates.map((candidate) => candidate.dir).sort() });
|
|
@@ -328,7 +622,7 @@ var discover = (root, manifest2, lanes2 = LANES) => {
|
|
|
328
622
|
var dependencyNames = (dir2, paths) => {
|
|
329
623
|
const names = /* @__PURE__ */ new Set();
|
|
330
624
|
for (const path of paths) {
|
|
331
|
-
const pkg = readJson(
|
|
625
|
+
const pkg = readJson(join2(dir2, path));
|
|
332
626
|
for (const field of DEP_FIELDS) {
|
|
333
627
|
for (const [key, spec] of Object.entries(pkg?.[field] ?? {})) {
|
|
334
628
|
names.add(key);
|
|
@@ -353,7 +647,7 @@ var orderBy = (items, key, deps) => {
|
|
|
353
647
|
return order;
|
|
354
648
|
};
|
|
355
649
|
var declaredDependencies = (dir2) => {
|
|
356
|
-
const pkg = readJson(
|
|
650
|
+
const pkg = readJson(join2(dir2, "package.json"));
|
|
357
651
|
return pkg ? dependencyNames(dir2, ["package.json", ...workspacePackagePaths(dir2, pkg)]) : /* @__PURE__ */ new Set();
|
|
358
652
|
};
|
|
359
653
|
var publishOrder = (checkout) => {
|
|
@@ -415,7 +709,7 @@ var trainPlan = (root, manifest2, lanes2 = LANES) => {
|
|
|
415
709
|
ambiguousConsumers: ambiguous.filter((entry) => consumerOrder.includes(entry.key))
|
|
416
710
|
};
|
|
417
711
|
};
|
|
418
|
-
var writeManifest = (manifest2) =>
|
|
712
|
+
var writeManifest = (manifest2) => writeFileSync2(join2(packageRoot, "versions.json"), `${JSON.stringify(manifest2, null, 2)}
|
|
419
713
|
`);
|
|
420
714
|
var workspacePackagePaths = (dir2, pkg) => {
|
|
421
715
|
const raw = pkg.workspaces;
|
|
@@ -424,7 +718,7 @@ var workspacePackagePaths = (dir2, pkg) => {
|
|
|
424
718
|
const paths = /* @__PURE__ */ new Set();
|
|
425
719
|
for (const pattern of globs) {
|
|
426
720
|
for (const match of globSync(`${pattern}/package.json`, { cwd: dir2 })) {
|
|
427
|
-
paths.add(match.split(
|
|
721
|
+
paths.add(match.split(sep2).join("/"));
|
|
428
722
|
}
|
|
429
723
|
}
|
|
430
724
|
return [...paths].sort();
|
|
@@ -433,7 +727,7 @@ var staleUpdates = (dir2, findings) => {
|
|
|
433
727
|
const groups = /* @__PURE__ */ new Map();
|
|
434
728
|
for (const finding of findings) {
|
|
435
729
|
if (finding.kind !== "stale-lock" || !finding.name) continue;
|
|
436
|
-
const cwd =
|
|
730
|
+
const cwd = join2(dir2, dirname2(finding.path ?? "package.json"));
|
|
437
731
|
groups.set(cwd, (groups.get(cwd) ?? /* @__PURE__ */ new Set()).add(finding.name));
|
|
438
732
|
}
|
|
439
733
|
return [...groups].map(([cwd, names]) => ({ cwd, names: [...names] }));
|
|
@@ -445,7 +739,7 @@ var detectPreset = (pkg, override) => {
|
|
|
445
739
|
};
|
|
446
740
|
function inspect(dir2, manifest2, presetOverride) {
|
|
447
741
|
const findings = [];
|
|
448
|
-
const pkgPath =
|
|
742
|
+
const pkgPath = join2(dir2, "package.json");
|
|
449
743
|
if (!existsSync(pkgPath)) {
|
|
450
744
|
return {
|
|
451
745
|
findings: [{ level: "error", message: `no package.json in ${dir2}` }],
|
|
@@ -453,17 +747,17 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
453
747
|
packagePaths: []
|
|
454
748
|
};
|
|
455
749
|
}
|
|
456
|
-
const pkg = JSON.parse(
|
|
750
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf8"));
|
|
457
751
|
let pkgDirty = false;
|
|
458
752
|
const touch = () => {
|
|
459
753
|
pkgDirty = true;
|
|
460
754
|
};
|
|
461
755
|
const members = workspacePackagePaths(dir2, pkg).map((rel) => {
|
|
462
|
-
const abs =
|
|
756
|
+
const abs = join2(dir2, rel);
|
|
463
757
|
return {
|
|
464
758
|
rel,
|
|
465
759
|
abs,
|
|
466
|
-
pkg: JSON.parse(
|
|
760
|
+
pkg: JSON.parse(readFileSync2(abs, "utf8")),
|
|
467
761
|
dirty: false
|
|
468
762
|
};
|
|
469
763
|
});
|
|
@@ -575,39 +869,33 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
575
869
|
}
|
|
576
870
|
});
|
|
577
871
|
}
|
|
578
|
-
const bunVersionPath =
|
|
579
|
-
const bunVersion = existsSync(bunVersionPath) ?
|
|
872
|
+
const bunVersionPath = join2(dir2, ".bun-version");
|
|
873
|
+
const bunVersion = existsSync(bunVersionPath) ? readFileSync2(bunVersionPath, "utf8").trim() : null;
|
|
580
874
|
if (bunVersion !== manifest2.bun) {
|
|
581
875
|
findings.push({
|
|
582
876
|
level: "error",
|
|
583
877
|
message: `.bun-version ${bunVersion ?? "(missing)"} \u2192 ${manifest2.bun}`,
|
|
584
|
-
fix: () =>
|
|
878
|
+
fix: () => writeFileSync2(bunVersionPath, `${manifest2.bun}
|
|
585
879
|
`)
|
|
586
880
|
});
|
|
587
881
|
}
|
|
588
|
-
const lockbPath =
|
|
882
|
+
const lockbPath = join2(dir2, "bun.lockb");
|
|
589
883
|
if (existsSync(lockbPath)) {
|
|
590
884
|
findings.push({
|
|
591
885
|
level: "error",
|
|
592
886
|
message: "legacy binary bun.lockb \u2192 delete and re-lock as bun.lock",
|
|
593
|
-
fix: () =>
|
|
887
|
+
fix: () => rmSync2(lockbPath)
|
|
594
888
|
});
|
|
595
889
|
}
|
|
596
|
-
const lockPath =
|
|
597
|
-
const lockText = existsSync(lockPath) ?
|
|
598
|
-
if (existsSync(
|
|
599
|
-
const tmpIgnored =
|
|
890
|
+
const lockPath = join2(dir2, "bun.lock");
|
|
891
|
+
const lockText = existsSync(lockPath) ? readFileSync2(lockPath, "utf8") : null;
|
|
892
|
+
if (existsSync(join2(dir2, ".git"))) {
|
|
893
|
+
const tmpIgnored = spawnSync2("git", ["check-ignore", "-q", "tmp/scratch"], { cwd: dir2 }).status === 0;
|
|
600
894
|
if (!tmpIgnored) {
|
|
601
895
|
findings.push({
|
|
602
896
|
level: "error",
|
|
603
897
|
message: "tmp/ is not gitignored \u2192 adding /tmp/* to .gitignore",
|
|
604
|
-
fix: () =>
|
|
605
|
-
const gitignorePath = join(dir2, ".gitignore");
|
|
606
|
-
const current = existsSync(gitignorePath) ? readFileSync(gitignorePath, "utf8") : "";
|
|
607
|
-
const separator = current === "" || current.endsWith("\n") ? "" : "\n";
|
|
608
|
-
writeFileSync(gitignorePath, `${current}${separator}/tmp/*
|
|
609
|
-
`);
|
|
610
|
-
}
|
|
898
|
+
fix: () => appendGitignoreLine(dir2, "/tmp/*")
|
|
611
899
|
});
|
|
612
900
|
}
|
|
613
901
|
if (!lockText) {
|
|
@@ -616,7 +904,7 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
616
904
|
message: "bun.lock missing \u2192 run bun install and commit the lockfile"
|
|
617
905
|
});
|
|
618
906
|
} else {
|
|
619
|
-
const ignoreStatus =
|
|
907
|
+
const ignoreStatus = spawnSync2("git", ["check-ignore", "-q", "bun.lock"], {
|
|
620
908
|
cwd: dir2
|
|
621
909
|
}).status;
|
|
622
910
|
if (ignoreStatus === 0) {
|
|
@@ -624,14 +912,14 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
624
912
|
level: "error",
|
|
625
913
|
message: "bun.lock is gitignored \u2192 removing the ignore rule; commit the lockfile",
|
|
626
914
|
fix: () => {
|
|
627
|
-
const gitignorePath =
|
|
915
|
+
const gitignorePath = join2(dir2, ".gitignore");
|
|
628
916
|
if (!existsSync(gitignorePath)) return;
|
|
629
|
-
const kept =
|
|
630
|
-
|
|
917
|
+
const kept = readFileSync2(gitignorePath, "utf8").split("\n").filter((line) => !/^\s*bun\.lockb?\s*$/.test(line));
|
|
918
|
+
writeFileSync2(gitignorePath, kept.join("\n"));
|
|
631
919
|
}
|
|
632
920
|
});
|
|
633
921
|
} else if (ignoreStatus === 1) {
|
|
634
|
-
const trackedStatus =
|
|
922
|
+
const trackedStatus = spawnSync2("git", ["ls-files", "--error-unmatch", "bun.lock"], {
|
|
635
923
|
cwd: dir2
|
|
636
924
|
}).status;
|
|
637
925
|
if (trackedStatus === 1) {
|
|
@@ -639,7 +927,7 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
639
927
|
level: "error",
|
|
640
928
|
message: "bun.lock untracked \u2192 staging it; commit the lockfile",
|
|
641
929
|
fix: () => {
|
|
642
|
-
|
|
930
|
+
spawnSync2("git", ["add", "bun.lock"], { cwd: dir2 });
|
|
643
931
|
}
|
|
644
932
|
});
|
|
645
933
|
} else if (trackedStatus !== 0) {
|
|
@@ -667,29 +955,30 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
667
955
|
}
|
|
668
956
|
});
|
|
669
957
|
}
|
|
670
|
-
const lefthookPath =
|
|
958
|
+
const lefthookPath = join2(dir2, "lefthook.yml");
|
|
671
959
|
const lefthookStub = "extends:\n - node_modules/@inixiative/config/lefthook/base.yml\n";
|
|
672
960
|
if (!existsSync(lefthookPath)) {
|
|
673
961
|
findings.push({
|
|
674
962
|
level: "error",
|
|
675
963
|
message: "lefthook.yml missing \u2192 stub extending @inixiative/config/lefthook/base.yml",
|
|
676
|
-
fix: () =>
|
|
964
|
+
fix: () => writeFileSync2(lefthookPath, lefthookStub)
|
|
677
965
|
});
|
|
678
|
-
} else if (!
|
|
966
|
+
} else if (!readFileSync2(lefthookPath, "utf8").includes("lefthook/base.yml")) {
|
|
679
967
|
findings.push({
|
|
680
968
|
level: "error",
|
|
681
969
|
message: "lefthook.yml does not extend the shared hooks \u2192 replaced with extends stub (local hooks overwritten \u2014 review the diff)",
|
|
682
|
-
fix: () =>
|
|
970
|
+
fix: () => writeFileSync2(lefthookPath, lefthookStub)
|
|
683
971
|
});
|
|
684
972
|
}
|
|
685
973
|
const prepare = pkg.scripts?.prepare;
|
|
974
|
+
const expectedPrepare = pkg.name === "@inixiative/config" ? LEFTHOOK_PREPARE : `${LEFTHOOK_PREPARE} && ${STANDARDS_PREPARE}`;
|
|
686
975
|
if (!prepare) {
|
|
687
976
|
findings.push({
|
|
688
977
|
level: "error",
|
|
689
|
-
message: `scripts.prepare missing \u2192 "${
|
|
978
|
+
message: `scripts.prepare missing \u2192 "${expectedPrepare}"`,
|
|
690
979
|
fix: () => {
|
|
691
980
|
pkg.scripts ??= {};
|
|
692
|
-
pkg.scripts.prepare =
|
|
981
|
+
pkg.scripts.prepare = expectedPrepare;
|
|
693
982
|
touch();
|
|
694
983
|
}
|
|
695
984
|
});
|
|
@@ -709,6 +998,27 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
709
998
|
message: "scripts.prepare does not run lefthook install \u2014 hooks will not auto-install"
|
|
710
999
|
});
|
|
711
1000
|
}
|
|
1001
|
+
if (pkg.name !== "@inixiative/config" && prepare && !prepare.includes(STANDARDS_PREPARE)) {
|
|
1002
|
+
findings.push({
|
|
1003
|
+
level: "error",
|
|
1004
|
+
message: `scripts.prepare does not sync shared standards/skills \u2192 "${STANDARDS_PREPARE}"`,
|
|
1005
|
+
fix: () => {
|
|
1006
|
+
pkg.scripts ??= {};
|
|
1007
|
+
const current = pkg.scripts.prepare;
|
|
1008
|
+
if (!current) {
|
|
1009
|
+
pkg.scripts.prepare = expectedPrepare;
|
|
1010
|
+
} else if (current.includes("inixiative-config standards")) {
|
|
1011
|
+
pkg.scripts.prepare = current.replace(
|
|
1012
|
+
/if [^;]*; then [^;]*inixiative-config standards; fi|(?:(?:bun|bunx)\s+)?(?:\.\/node_modules\/\.bin\/)?inixiative-config standards/,
|
|
1013
|
+
STANDARDS_PREPARE
|
|
1014
|
+
);
|
|
1015
|
+
} else {
|
|
1016
|
+
pkg.scripts.prepare = `${current} && ${STANDARDS_PREPARE}`;
|
|
1017
|
+
}
|
|
1018
|
+
touch();
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
712
1022
|
}
|
|
713
1023
|
const rangeTargets = [
|
|
714
1024
|
{ label: "", path: "package.json", pkg, mark: touch },
|
|
@@ -861,19 +1171,19 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
861
1171
|
}
|
|
862
1172
|
const preset2 = detectPreset(pkg, presetOverride);
|
|
863
1173
|
const tsconfigTarget = `@inixiative/config/tsconfig/${preset2}.json`;
|
|
864
|
-
const tsconfigPath =
|
|
1174
|
+
const tsconfigPath = join2(dir2, "tsconfig.json");
|
|
865
1175
|
if (!existsSync(tsconfigPath)) {
|
|
866
1176
|
findings.push({
|
|
867
1177
|
level: "error",
|
|
868
1178
|
message: `tsconfig.json missing \u2192 stub extending ${tsconfigTarget}`,
|
|
869
|
-
fix: () =>
|
|
1179
|
+
fix: () => writeFileSync2(
|
|
870
1180
|
tsconfigPath,
|
|
871
1181
|
`${JSON.stringify({ extends: tsconfigTarget, exclude: ["dist"] }, null, 2)}
|
|
872
1182
|
`
|
|
873
1183
|
)
|
|
874
1184
|
});
|
|
875
1185
|
} else {
|
|
876
|
-
const tsconfig = tryParseJsonc(
|
|
1186
|
+
const tsconfig = tryParseJsonc(readFileSync2(tsconfigPath, "utf8")) ?? {};
|
|
877
1187
|
const extendsValue = tsconfig.extends;
|
|
878
1188
|
if (typeof extendsValue !== "string" || !extendsValue.startsWith("@inixiative/config/tsconfig/")) {
|
|
879
1189
|
findings.push({
|
|
@@ -882,23 +1192,23 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
882
1192
|
fix: () => {
|
|
883
1193
|
const { extends: _replaced, ...rest } = tsconfig;
|
|
884
1194
|
const next = { extends: tsconfigTarget, ...rest };
|
|
885
|
-
|
|
1195
|
+
writeFileSync2(tsconfigPath, `${JSON.stringify(next, null, 2)}
|
|
886
1196
|
`);
|
|
887
1197
|
}
|
|
888
1198
|
});
|
|
889
1199
|
}
|
|
890
1200
|
}
|
|
891
1201
|
const biomeTargets = preset2 === "react" ? ["@inixiative/config/biome/base.json", "@inixiative/config/biome/react.json"] : ["@inixiative/config/biome/base.json"];
|
|
892
|
-
const biomePath =
|
|
1202
|
+
const biomePath = join2(dir2, "biome.json");
|
|
893
1203
|
if (!existsSync(biomePath)) {
|
|
894
1204
|
findings.push({
|
|
895
1205
|
level: "error",
|
|
896
1206
|
message: `biome.json missing \u2192 stub extending ${biomeTargets.join(" + ")}`,
|
|
897
|
-
fix: () =>
|
|
1207
|
+
fix: () => writeFileSync2(biomePath, `${JSON.stringify({ extends: biomeTargets }, null, 2)}
|
|
898
1208
|
`)
|
|
899
1209
|
});
|
|
900
1210
|
} else {
|
|
901
|
-
const biome = tryParseJsonc(
|
|
1211
|
+
const biome = tryParseJsonc(readFileSync2(biomePath, "utf8")) ?? {};
|
|
902
1212
|
const extendsValue = Array.isArray(biome.extends) ? biome.extends : [];
|
|
903
1213
|
const missing = biomeTargets.filter((target) => !extendsValue.includes(target));
|
|
904
1214
|
if (missing.length > 0) {
|
|
@@ -907,7 +1217,7 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
907
1217
|
message: `biome.json missing extends ${missing.join(", ")}; local rules retained as overrides, review them`,
|
|
908
1218
|
fix: () => {
|
|
909
1219
|
const next = { ...biome, extends: biomeTargets };
|
|
910
|
-
|
|
1220
|
+
writeFileSync2(biomePath, `${JSON.stringify(next, null, 2)}
|
|
911
1221
|
`);
|
|
912
1222
|
}
|
|
913
1223
|
});
|
|
@@ -919,13 +1229,13 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
919
1229
|
flush: () => {
|
|
920
1230
|
let wrote = false;
|
|
921
1231
|
if (pkgDirty) {
|
|
922
|
-
|
|
1232
|
+
writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
923
1233
|
`);
|
|
924
1234
|
wrote = true;
|
|
925
1235
|
}
|
|
926
1236
|
for (const member of members) {
|
|
927
1237
|
if (!member.dirty) continue;
|
|
928
|
-
|
|
1238
|
+
writeFileSync2(member.abs, `${JSON.stringify(member.pkg, null, 2)}
|
|
929
1239
|
`);
|
|
930
1240
|
wrote = true;
|
|
931
1241
|
}
|
|
@@ -933,7 +1243,7 @@ function inspect(dir2, manifest2, presetOverride) {
|
|
|
933
1243
|
}
|
|
934
1244
|
};
|
|
935
1245
|
}
|
|
936
|
-
var trainLockPath = () =>
|
|
1246
|
+
var trainLockPath = () => join2(homedir(), ".inixiative", "train.lock");
|
|
937
1247
|
var isAlive = (pid) => {
|
|
938
1248
|
try {
|
|
939
1249
|
process.kill(pid, 0);
|
|
@@ -943,7 +1253,7 @@ var isAlive = (pid) => {
|
|
|
943
1253
|
}
|
|
944
1254
|
};
|
|
945
1255
|
var processStart = (pid) => {
|
|
946
|
-
const ps =
|
|
1256
|
+
const ps = spawnSync2("ps", ["-o", "lstart=", "-p", String(pid)], { encoding: "utf8" });
|
|
947
1257
|
const start = ps.status === 0 ? ps.stdout.trim() : "";
|
|
948
1258
|
return start === "" ? null : start;
|
|
949
1259
|
};
|
|
@@ -967,7 +1277,7 @@ var staleness = (contents, lock) => {
|
|
|
967
1277
|
};
|
|
968
1278
|
var readOrNull = (path) => {
|
|
969
1279
|
try {
|
|
970
|
-
return
|
|
1280
|
+
return readFileSync2(path, "utf8");
|
|
971
1281
|
} catch (error) {
|
|
972
1282
|
if (error.code === "ENOENT") return null;
|
|
973
1283
|
throw error;
|
|
@@ -975,7 +1285,7 @@ var readOrNull = (path) => {
|
|
|
975
1285
|
};
|
|
976
1286
|
var createExclusive = (path, contents) => {
|
|
977
1287
|
const draft = `${path}.${process.pid}.${randomUUID()}`;
|
|
978
|
-
|
|
1288
|
+
writeFileSync2(draft, contents, { flag: "wx" });
|
|
979
1289
|
try {
|
|
980
1290
|
linkSync(draft, path);
|
|
981
1291
|
return true;
|
|
@@ -983,7 +1293,7 @@ var createExclusive = (path, contents) => {
|
|
|
983
1293
|
if (error.code === "EEXIST") return false;
|
|
984
1294
|
throw error;
|
|
985
1295
|
} finally {
|
|
986
|
-
|
|
1296
|
+
rmSync2(draft, { force: true });
|
|
987
1297
|
}
|
|
988
1298
|
};
|
|
989
1299
|
var TAKEOVER_TIMEOUT_MS = 1e4;
|
|
@@ -993,27 +1303,27 @@ var removeStale = (path, stale) => {
|
|
|
993
1303
|
`)) {
|
|
994
1304
|
try {
|
|
995
1305
|
if (Date.now() - statSync(mutex).mtimeMs > TAKEOVER_TIMEOUT_MS)
|
|
996
|
-
|
|
1306
|
+
rmSync2(mutex, { force: true });
|
|
997
1307
|
} catch {
|
|
998
1308
|
}
|
|
999
1309
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
1000
1310
|
return;
|
|
1001
1311
|
}
|
|
1002
1312
|
try {
|
|
1003
|
-
if (readOrNull(path) === stale)
|
|
1313
|
+
if (readOrNull(path) === stale) rmSync2(path, { force: true });
|
|
1004
1314
|
} finally {
|
|
1005
|
-
|
|
1315
|
+
rmSync2(mutex, { force: true });
|
|
1006
1316
|
}
|
|
1007
1317
|
};
|
|
1008
1318
|
var acquireTrainLock = (path, holder) => {
|
|
1009
|
-
|
|
1319
|
+
mkdirSync2(dirname2(path), { recursive: true });
|
|
1010
1320
|
const mine = `${JSON.stringify(holder, null, 2)}
|
|
1011
1321
|
`;
|
|
1012
1322
|
let reclaimed;
|
|
1013
1323
|
for (; ; ) {
|
|
1014
1324
|
if (createExclusive(path, mine)) {
|
|
1015
1325
|
const release = () => {
|
|
1016
|
-
if (readOrNull(path) === mine)
|
|
1326
|
+
if (readOrNull(path) === mine) rmSync2(path, { force: true });
|
|
1017
1327
|
};
|
|
1018
1328
|
return reclaimed ? { ok: true, release, reclaimed } : { ok: true, release };
|
|
1019
1329
|
}
|
|
@@ -1038,13 +1348,22 @@ var holdTrainLock = (release) => {
|
|
|
1038
1348
|
}
|
|
1039
1349
|
};
|
|
1040
1350
|
var isConfigCheckout = (dir2) => {
|
|
1041
|
-
const top =
|
|
1351
|
+
const top = spawnSync2("git", ["rev-parse", "--show-toplevel"], { cwd: dir2, encoding: "utf8" });
|
|
1042
1352
|
if (top.status !== 0) return false;
|
|
1043
|
-
return
|
|
1353
|
+
return realpathSync2(top.stdout.trim()) === realpathSync2(dir2) && originRepo(dir2) === "inixiative/config";
|
|
1044
1354
|
};
|
|
1045
1355
|
|
|
1046
1356
|
// src/args.ts
|
|
1047
|
-
var COMMANDS = [
|
|
1357
|
+
var COMMANDS = [
|
|
1358
|
+
"check",
|
|
1359
|
+
"sync",
|
|
1360
|
+
"standards",
|
|
1361
|
+
"scan",
|
|
1362
|
+
"train",
|
|
1363
|
+
"ports",
|
|
1364
|
+
"terms",
|
|
1365
|
+
"bounded"
|
|
1366
|
+
];
|
|
1048
1367
|
var PRESETS = ["base", "node", "react"];
|
|
1049
1368
|
var preset = { type: "string" };
|
|
1050
1369
|
var lane = { type: "string" };
|
|
@@ -1052,6 +1371,7 @@ var flag = { type: "boolean", default: false };
|
|
|
1052
1371
|
var OPTIONS = {
|
|
1053
1372
|
check: { preset },
|
|
1054
1373
|
sync: { preset, force: flag, "no-install": flag },
|
|
1374
|
+
standards: { check: flag },
|
|
1055
1375
|
scan: { lane },
|
|
1056
1376
|
train: { lane, push: flag, "dry-run": flag, "adopt-check-timeout": { type: "string" } },
|
|
1057
1377
|
ports: {},
|
|
@@ -1130,6 +1450,7 @@ var parseCommandLine = (argv) => {
|
|
|
1130
1450
|
noInstall: values["no-install"] === true,
|
|
1131
1451
|
push: values.push === true,
|
|
1132
1452
|
dryRun: values["dry-run"] === true,
|
|
1453
|
+
checkOnly: values.check === true,
|
|
1133
1454
|
adoptCheckTimeout: adoptCheckTimeout2,
|
|
1134
1455
|
writeBaseline: values["write-baseline"] === true,
|
|
1135
1456
|
bounds
|
|
@@ -1137,10 +1458,10 @@ var parseCommandLine = (argv) => {
|
|
|
1137
1458
|
};
|
|
1138
1459
|
|
|
1139
1460
|
// src/bounded.ts
|
|
1140
|
-
import { spawn, spawnSync as
|
|
1141
|
-
import { mkdirSync as
|
|
1461
|
+
import { spawn, spawnSync as spawnSync3 } from "child_process";
|
|
1462
|
+
import { mkdirSync as mkdirSync3 } from "fs";
|
|
1142
1463
|
import { constants, cpus, homedir as homedir2, totalmem } from "os";
|
|
1143
|
-
import { basename, dirname as
|
|
1464
|
+
import { basename, dirname as dirname3, join as join3 } from "path";
|
|
1144
1465
|
var DEFAULT_BOUNDS = {
|
|
1145
1466
|
seconds: 40 * 60,
|
|
1146
1467
|
memoryBytes: 12 * 2 ** 30,
|
|
@@ -1148,7 +1469,7 @@ var DEFAULT_BOUNDS = {
|
|
|
1148
1469
|
};
|
|
1149
1470
|
var INSIDE_BOUNDED = "INIXIATIVE_BOUNDED";
|
|
1150
1471
|
var TIME_LIMIT_EXIT_CODE = 124;
|
|
1151
|
-
var checkLockPath = () =>
|
|
1472
|
+
var checkLockPath = () => join3(homedir2(), ".foundry", "check.lock");
|
|
1152
1473
|
var LOCK_WAIT_EXIT_CODE = 75;
|
|
1153
1474
|
var MAX_CHECK_SLOTS = 8;
|
|
1154
1475
|
var defaultCheckSlots = (cpuCount = cpus().length, totalMemoryBytes = totalmem(), envValue = process.env.INIXIATIVE_CHECK_SLOTS) => {
|
|
@@ -1162,11 +1483,11 @@ var defaultCheckSlots = (cpuCount = cpus().length, totalMemoryBytes = totalmem()
|
|
|
1162
1483
|
};
|
|
1163
1484
|
var checkSlotPaths = (basePath = checkLockPath(), slots = defaultCheckSlots()) => {
|
|
1164
1485
|
const count = Math.max(1, Math.min(Math.floor(slots), MAX_CHECK_SLOTS));
|
|
1165
|
-
const dir2 =
|
|
1486
|
+
const dir2 = dirname3(basePath);
|
|
1166
1487
|
const name = basename(basePath);
|
|
1167
1488
|
const paths = [basePath];
|
|
1168
1489
|
for (let i = 1; i < count; i++) {
|
|
1169
|
-
paths.push(name === "check.lock" ?
|
|
1490
|
+
paths.push(name === "check.lock" ? join3(dir2, `check-slot-${i}.lock`) : `${basePath}.${i}`);
|
|
1170
1491
|
}
|
|
1171
1492
|
return paths;
|
|
1172
1493
|
};
|
|
@@ -1174,7 +1495,7 @@ var underLock = (path, seconds, command2) => process.platform === "linux" ? seco
|
|
|
1174
1495
|
var lockWrapperAbove = (path, from = process.ppid) => {
|
|
1175
1496
|
let pid = from;
|
|
1176
1497
|
for (let depth = 0; depth < 40 && pid > 1; depth++) {
|
|
1177
|
-
const ps =
|
|
1498
|
+
const ps = spawnSync3("ps", ["-o", "ppid=,command=", "-p", String(pid)], { encoding: "utf8" });
|
|
1178
1499
|
const match = /^\s*(\d+)\s+(.*)$/.exec((ps.stdout ?? "").trim());
|
|
1179
1500
|
if (!match) return null;
|
|
1180
1501
|
const command2 = match[2] ?? "";
|
|
@@ -1207,13 +1528,13 @@ var groupProcessesInPs = (output, pgid) => output.split("\n").flatMap((line) =>
|
|
|
1207
1528
|
});
|
|
1208
1529
|
var fetchGroupMemory = (pgid) => {
|
|
1209
1530
|
if (process.platform === "darwin") {
|
|
1210
|
-
const top =
|
|
1531
|
+
const top = spawnSync3("top", ["-l", "1", "-n", "5000", "-stats", "pid,pgrp,mem,command"], {
|
|
1211
1532
|
encoding: "utf8",
|
|
1212
1533
|
timeout: 3e4
|
|
1213
1534
|
});
|
|
1214
1535
|
if (top.status === 0) return groupProcessesInTop(top.stdout, pgid);
|
|
1215
1536
|
}
|
|
1216
|
-
const ps =
|
|
1537
|
+
const ps = spawnSync3("ps", ["-eo", "pid=,pgid=,rss=,comm="], {
|
|
1217
1538
|
encoding: "utf8",
|
|
1218
1539
|
timeout: 3e4
|
|
1219
1540
|
});
|
|
@@ -1258,7 +1579,7 @@ var runBounded = async (command2, options = {}) => {
|
|
|
1258
1579
|
const slotPaths = checkSlotPaths(basePath, slots);
|
|
1259
1580
|
const cwd = options.cwd ?? process.cwd();
|
|
1260
1581
|
const sampleMs = options.sampleMs ?? 1e4;
|
|
1261
|
-
|
|
1582
|
+
mkdirSync3(dirname3(basePath), { recursive: true });
|
|
1262
1583
|
const holding = ["sh", "-c", HOLDING_THE_LOCK, "sh", ...command2];
|
|
1263
1584
|
let activePgid;
|
|
1264
1585
|
let signalled = null;
|
|
@@ -1333,7 +1654,7 @@ var runBounded = async (command2, options = {}) => {
|
|
|
1333
1654
|
if (!announced && Date.now() - waitStart >= announceMs) {
|
|
1334
1655
|
announced = true;
|
|
1335
1656
|
say(
|
|
1336
|
-
`bounded: waiting for a free check slot (${slotPaths.length} busy under ${
|
|
1657
|
+
`bounded: waiting for a free check slot (${slotPaths.length} busy under ${dirname3(basePath)})`
|
|
1337
1658
|
);
|
|
1338
1659
|
}
|
|
1339
1660
|
await sleep(Math.min(250, remainingMs));
|
|
@@ -1392,7 +1713,7 @@ var holdCheckLock = async (options = {}) => {
|
|
|
1392
1713
|
const slotPaths = checkSlotPaths(basePath, slots);
|
|
1393
1714
|
const waitSeconds = options.waitSeconds ?? DEFAULT_BOUNDS.waitSeconds;
|
|
1394
1715
|
const say = options.say ?? ((line) => console.error(line));
|
|
1395
|
-
|
|
1716
|
+
mkdirSync3(dirname3(basePath), { recursive: true });
|
|
1396
1717
|
let holder = null;
|
|
1397
1718
|
if (slotPaths.length === 1) {
|
|
1398
1719
|
holder = await tryHoldOneSlot(
|
|
@@ -1415,7 +1736,7 @@ var holdCheckLock = async (options = {}) => {
|
|
|
1415
1736
|
if (!announced && Date.now() - waitStart >= 5e3) {
|
|
1416
1737
|
announced = true;
|
|
1417
1738
|
say(
|
|
1418
|
-
`train: waiting for a free check slot (${slotPaths.length} busy under ${
|
|
1739
|
+
`train: waiting for a free check slot (${slotPaths.length} busy under ${dirname3(basePath)})`
|
|
1419
1740
|
);
|
|
1420
1741
|
}
|
|
1421
1742
|
await sleep(Math.min(250, remainingMs));
|
|
@@ -1484,17 +1805,17 @@ function portsFor(project) {
|
|
|
1484
1805
|
}
|
|
1485
1806
|
|
|
1486
1807
|
// src/retiredTerms.ts
|
|
1487
|
-
import { spawnSync as
|
|
1808
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
1488
1809
|
import {
|
|
1489
1810
|
existsSync as existsSync2,
|
|
1490
|
-
lstatSync,
|
|
1491
|
-
mkdirSync as
|
|
1492
|
-
readdirSync as
|
|
1493
|
-
readFileSync as
|
|
1494
|
-
rmSync as
|
|
1495
|
-
writeFileSync as
|
|
1811
|
+
lstatSync as lstatSync2,
|
|
1812
|
+
mkdirSync as mkdirSync4,
|
|
1813
|
+
readdirSync as readdirSync3,
|
|
1814
|
+
readFileSync as readFileSync3,
|
|
1815
|
+
rmSync as rmSync3,
|
|
1816
|
+
writeFileSync as writeFileSync3
|
|
1496
1817
|
} from "fs";
|
|
1497
|
-
import { dirname as
|
|
1818
|
+
import { dirname as dirname4, join as join4 } from "path";
|
|
1498
1819
|
var RETIRED_TERMS = [
|
|
1499
1820
|
{
|
|
1500
1821
|
id: "kastle",
|
|
@@ -1546,7 +1867,7 @@ var TEXT_FILE = /\.(md|mdx|html|astro)$/i;
|
|
|
1546
1867
|
var PUBLIC_FILE = /(^|\/)README[^/]*\.md$|\.(html|astro|mdx)$/i;
|
|
1547
1868
|
var SKIPPED = /(^|\/)(node_modules|\.git|\.worktrees|fixtures|rule-violations)\/|^(dist|build|coverage|tmp)\/|^\.foundry\/regions\/|(^|\/)CHANGELOG[^/]*\.md$/i;
|
|
1548
1869
|
var walk = (root, dir2 = "", out = []) => {
|
|
1549
|
-
for (const entry of
|
|
1870
|
+
for (const entry of readdirSync3(join4(root, dir2), { withFileTypes: true })) {
|
|
1550
1871
|
const rel = dir2 ? `${dir2}/${entry.name}` : entry.name;
|
|
1551
1872
|
if (entry.isDirectory() && !SKIPPED.test(`${rel}/`)) walk(root, rel, out);
|
|
1552
1873
|
else if (entry.isFile()) out.push(rel);
|
|
@@ -1555,14 +1876,14 @@ var walk = (root, dir2 = "", out = []) => {
|
|
|
1555
1876
|
};
|
|
1556
1877
|
var readText = (abs) => {
|
|
1557
1878
|
try {
|
|
1558
|
-
return
|
|
1879
|
+
return lstatSync2(abs).isFile() ? readFileSync3(abs, "utf8") : null;
|
|
1559
1880
|
} catch {
|
|
1560
1881
|
return null;
|
|
1561
1882
|
}
|
|
1562
1883
|
};
|
|
1563
1884
|
var listFiles = (root) => {
|
|
1564
|
-
if (existsSync2(
|
|
1565
|
-
const listed =
|
|
1885
|
+
if (existsSync2(join4(root, ".git"))) {
|
|
1886
|
+
const listed = spawnSync4(
|
|
1566
1887
|
"git",
|
|
1567
1888
|
["ls-files", "-z", "--cached", "--others", "--exclude-standard"],
|
|
1568
1889
|
{
|
|
@@ -1581,7 +1902,7 @@ var scanRetiredTerms = (root) => {
|
|
|
1581
1902
|
if (SKIPPED.test(path) || path.startsWith(`${RETIRED_TERMS_DIR}/`)) continue;
|
|
1582
1903
|
const isManifest = /(^|\/)package\.json$/.test(path);
|
|
1583
1904
|
if (!isManifest && !TEXT_FILE.test(path)) continue;
|
|
1584
|
-
const raw = readText(
|
|
1905
|
+
const raw = readText(join4(root, path));
|
|
1585
1906
|
if (raw === null) continue;
|
|
1586
1907
|
let text = raw;
|
|
1587
1908
|
if (isManifest) {
|
|
@@ -1609,9 +1930,9 @@ var scanRetiredTerms = (root) => {
|
|
|
1609
1930
|
return hits;
|
|
1610
1931
|
};
|
|
1611
1932
|
var readList = (root, file) => {
|
|
1612
|
-
const abs =
|
|
1933
|
+
const abs = join4(root, file);
|
|
1613
1934
|
if (!existsSync2(abs)) return [];
|
|
1614
|
-
return
|
|
1935
|
+
return readFileSync3(abs, "utf8").split("\n").map((line) => line.trimEnd()).filter((line) => line.trim() !== "" && !line.trimStart().startsWith("#"));
|
|
1615
1936
|
};
|
|
1616
1937
|
var allowedBy = (lines) => {
|
|
1617
1938
|
const rules = lines.map((line) => {
|
|
@@ -1685,7 +2006,7 @@ var checkRetiredTerms = (root) => {
|
|
|
1685
2006
|
var writeRetiredTermsBaseline = (root) => {
|
|
1686
2007
|
const allowed = allowedBy(readList(root, ALLOW_FILE));
|
|
1687
2008
|
const counts = countByKey(scanRetiredTerms(root).filter((hit) => !allowed(hit)));
|
|
1688
|
-
const path =
|
|
2009
|
+
const path = join4(root, BASELINE_FILE);
|
|
1689
2010
|
if (existsSync2(path)) {
|
|
1690
2011
|
const { counts: baseline } = readBaseline(root);
|
|
1691
2012
|
const refused = [...counts].filter(([key, count]) => count > (baseline.get(key) ?? 0)).map(
|
|
@@ -1700,11 +2021,11 @@ var writeRetiredTermsBaseline = (root) => {
|
|
|
1700
2021
|
];
|
|
1701
2022
|
const lines = [...counts].sort(([a], [b]) => a.localeCompare(b)).map(([key, n]) => `${key} ${n}`);
|
|
1702
2023
|
if (lines.length === 0) {
|
|
1703
|
-
|
|
2024
|
+
rmSync3(path, { force: true });
|
|
1704
2025
|
return { written: 0, refused: [] };
|
|
1705
2026
|
}
|
|
1706
|
-
|
|
1707
|
-
|
|
2027
|
+
mkdirSync4(dirname4(path), { recursive: true });
|
|
2028
|
+
writeFileSync3(path, `${[...header, ...lines].join("\n")}
|
|
1708
2029
|
`);
|
|
1709
2030
|
return { written: lines.length, refused: [] };
|
|
1710
2031
|
};
|
|
@@ -1717,7 +2038,7 @@ try {
|
|
|
1717
2038
|
if (!(error instanceof UsageError)) throw error;
|
|
1718
2039
|
console.error(`\u2717 ${error.message}`);
|
|
1719
2040
|
console.error(
|
|
1720
|
-
"Usage: inixiative-config check [dir] [--preset=base|node|react]\n inixiative-config sync [dir] [--preset=base|node|react] [--force] [--no-install]\n inixiative-config scan [root] [--lane=primitives|agentic]\n inixiative-config train [root] [--lane=primitives|agentic] [--push] [--dry-run]\n inixiative-config ports [project]\n inixiative-config terms [dir] [--write-baseline]\n inixiative-config bounded [--minutes=40] [--memory-gb=12] [--wait-minutes=240] -- <command\u2026>"
|
|
2041
|
+
"Usage: inixiative-config check [dir] [--preset=base|node|react]\n inixiative-config sync [dir] [--preset=base|node|react] [--force] [--no-install]\n inixiative-config standards [dir] [--check]\n inixiative-config scan [root] [--lane=primitives|agentic]\n inixiative-config train [root] [--lane=primitives|agentic] [--push] [--dry-run]\n inixiative-config ports [project]\n inixiative-config terms [dir] [--write-baseline]\n inixiative-config bounded [--minutes=40] [--memory-gb=12] [--wait-minutes=240] -- <command\u2026>"
|
|
1721
2042
|
);
|
|
1722
2043
|
process.exit(2);
|
|
1723
2044
|
}
|
|
@@ -1726,7 +2047,7 @@ var dir = resolve2(command === "bounded" ? "." : positionals[0] ?? ".");
|
|
|
1726
2047
|
if (command === "bounded") {
|
|
1727
2048
|
if (process.env.CI) {
|
|
1728
2049
|
const [file, ...args] = positionals;
|
|
1729
|
-
const ran =
|
|
2050
|
+
const ran = spawnSync5(file ?? "", args, { stdio: "inherit" });
|
|
1730
2051
|
if (ran.error) {
|
|
1731
2052
|
console.error(`\u2717 bounded: the command did not start: ${ran.error.message}`);
|
|
1732
2053
|
process.exit(127);
|
|
@@ -1778,7 +2099,7 @@ var report = (findings) => {
|
|
|
1778
2099
|
if (process.versions.bun && process.versions.bun !== manifest.bun) {
|
|
1779
2100
|
console.log(`\u26A0 running bun ${process.versions.bun}, blessed is ${manifest.bun} (bun upgrade)`);
|
|
1780
2101
|
}
|
|
1781
|
-
var git = (cwd, ...gitArgs) =>
|
|
2102
|
+
var git = (cwd, ...gitArgs) => spawnSync5("git", gitArgs, { cwd, encoding: "utf8" });
|
|
1782
2103
|
var behindOrigin = (cwd) => {
|
|
1783
2104
|
const behind = git(cwd, "rev-list", "--count", "HEAD..@{upstream}");
|
|
1784
2105
|
return behind.status === 0 ? Number(behind.stdout.trim()) : 0;
|
|
@@ -1814,9 +2135,56 @@ var offDefaultBranch = (cwd) => {
|
|
|
1814
2135
|
const current = branch.stdout.trim();
|
|
1815
2136
|
return current === main ? null : { branch: current, main };
|
|
1816
2137
|
};
|
|
2138
|
+
var standardsFindingsFor = (targetDir) => {
|
|
2139
|
+
const pkgPath = join5(targetDir, "package.json");
|
|
2140
|
+
if (!existsSync3(pkgPath) || !existsSync3(join5(targetDir, ".git"))) return [];
|
|
2141
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf8"));
|
|
2142
|
+
return inspectStandards(targetDir, pkg, packageRoot, { gitRepo: true });
|
|
2143
|
+
};
|
|
1817
2144
|
if (command === "check") {
|
|
1818
2145
|
const { findings } = inspect(dir, manifest, presetFlag);
|
|
1819
|
-
process.exit(
|
|
2146
|
+
process.exit(
|
|
2147
|
+
report([...findings, ...standardsFindingsFor(dir), ...checkRetiredTerms(dir).findings]) > 0 ? 1 : 0
|
|
2148
|
+
);
|
|
2149
|
+
}
|
|
2150
|
+
if (command === "standards") {
|
|
2151
|
+
const pkgPath = join5(dir, "package.json");
|
|
2152
|
+
if (!existsSync3(pkgPath)) {
|
|
2153
|
+
console.error(`\u2717 no package.json in ${dir}`);
|
|
2154
|
+
process.exit(1);
|
|
2155
|
+
}
|
|
2156
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf8"));
|
|
2157
|
+
if (pkg.name === "@inixiative/config") {
|
|
2158
|
+
console.log("\u2713 @inixiative/config owns standards/ and skills/ directly");
|
|
2159
|
+
process.exit(0);
|
|
2160
|
+
}
|
|
2161
|
+
if (commandLine.checkOnly) {
|
|
2162
|
+
const findings = inspectStandards(dir, pkg, packageRoot, {
|
|
2163
|
+
gitRepo: existsSync3(join5(dir, ".git"))
|
|
2164
|
+
});
|
|
2165
|
+
process.exit(report(findings) > 0 ? 1 : 0);
|
|
2166
|
+
}
|
|
2167
|
+
const { profiles, error } = resolveStandardsProfiles(pkg);
|
|
2168
|
+
if (error) {
|
|
2169
|
+
console.error(`\u2717 ${error}`);
|
|
2170
|
+
process.exit(1);
|
|
2171
|
+
}
|
|
2172
|
+
try {
|
|
2173
|
+
const { written, removed } = syncStandards(dir, packageRoot, profiles);
|
|
2174
|
+
if (written.length === 0 && removed.length === 0) {
|
|
2175
|
+
console.log("\u2713 standards in sync");
|
|
2176
|
+
} else {
|
|
2177
|
+
const parts = [
|
|
2178
|
+
written.length > 0 ? `${written.length} updated` : null,
|
|
2179
|
+
removed.length > 0 ? `${removed.length} unused removed` : null
|
|
2180
|
+
].filter(Boolean);
|
|
2181
|
+
console.log(`\u2713 standards synced (${parts.join(", ")})`);
|
|
2182
|
+
}
|
|
2183
|
+
} catch (err) {
|
|
2184
|
+
console.error(`\u2717 ${err instanceof Error ? err.message : String(err)}`);
|
|
2185
|
+
process.exit(1);
|
|
2186
|
+
}
|
|
2187
|
+
process.exit(0);
|
|
1820
2188
|
}
|
|
1821
2189
|
if (command === "terms") {
|
|
1822
2190
|
if (commandLine.writeBaseline) {
|
|
@@ -1958,13 +2326,13 @@ if (command === "train") {
|
|
|
1958
2326
|
const worktrees = [];
|
|
1959
2327
|
const removeWorktree = ({ repo, path, tooling }) => {
|
|
1960
2328
|
if (tooling) {
|
|
1961
|
-
|
|
2329
|
+
spawnSync5("bun", ["run", "worktree:destroy", basename2(path), "--force"], {
|
|
1962
2330
|
cwd: repo,
|
|
1963
2331
|
stdio: "inherit"
|
|
1964
2332
|
});
|
|
1965
2333
|
} else {
|
|
1966
2334
|
git(repo, "worktree", "remove", "--force", path);
|
|
1967
|
-
|
|
2335
|
+
rmSync4(dirname5(path), { recursive: true, force: true });
|
|
1968
2336
|
}
|
|
1969
2337
|
};
|
|
1970
2338
|
process.on("exit", () => {
|
|
@@ -2010,7 +2378,7 @@ if (command === "train") {
|
|
|
2010
2378
|
}
|
|
2011
2379
|
if (!dryRun) {
|
|
2012
2380
|
console.log(`\u2193 fast-forwarded to origin (+${behind})`);
|
|
2013
|
-
checkout.pkg = JSON.parse(
|
|
2381
|
+
checkout.pkg = JSON.parse(readFileSync4(join5(checkout.dir, "package.json"), "utf8"));
|
|
2014
2382
|
}
|
|
2015
2383
|
}
|
|
2016
2384
|
return true;
|
|
@@ -2036,8 +2404,8 @@ if (command === "train") {
|
|
|
2036
2404
|
};
|
|
2037
2405
|
};
|
|
2038
2406
|
const runRepoCheck = (cwd, seconds = 2 * 60 * 60) => {
|
|
2039
|
-
const { scripts } = JSON.parse(
|
|
2040
|
-
return
|
|
2407
|
+
const { scripts } = JSON.parse(readFileSync4(join5(cwd, "package.json"), "utf8"));
|
|
2408
|
+
return spawnSync5(
|
|
2041
2409
|
process.execPath,
|
|
2042
2410
|
[
|
|
2043
2411
|
process.argv[1] ?? "",
|
|
@@ -2053,7 +2421,7 @@ if (command === "train") {
|
|
|
2053
2421
|
).status;
|
|
2054
2422
|
};
|
|
2055
2423
|
const relockAndCheck = (checkout, check = true) => effect(`re-lock ${checkout.name}${check ? " and run its check" : ""}`, void 0, () => {
|
|
2056
|
-
const install = (...flags) =>
|
|
2424
|
+
const install = (...flags) => spawnSync5("bun", ["install", ...flags], { cwd: checkout.dir, stdio: "inherit" }).status === 0;
|
|
2057
2425
|
if (!install() && !install("--no-cache")) {
|
|
2058
2426
|
throw new Abort(`bun install failed in ${checkout.name}`);
|
|
2059
2427
|
}
|
|
@@ -2061,7 +2429,7 @@ if (command === "train") {
|
|
|
2061
2429
|
checkout.dir,
|
|
2062
2430
|
inspect(checkout.dir, target()).findings
|
|
2063
2431
|
)) {
|
|
2064
|
-
|
|
2432
|
+
spawnSync5("bun", ["update", ...names], { cwd, stdio: "inherit" });
|
|
2065
2433
|
}
|
|
2066
2434
|
if (check && runRepoCheck(checkout.dir) !== 0) {
|
|
2067
2435
|
throw new CheckFailed(`check failed in ${checkout.name}`);
|
|
@@ -2072,7 +2440,7 @@ if (command === "train") {
|
|
|
2072
2440
|
if (git(checkout.dir, "status", "--porcelain").stdout.trim() === "") return;
|
|
2073
2441
|
git(checkout.dir, "reset", "--quiet", "--hard", "HEAD");
|
|
2074
2442
|
git(checkout.dir, "clean", "--quiet", "-fd");
|
|
2075
|
-
|
|
2443
|
+
spawnSync5("bun", ["install", "--frozen-lockfile"], { cwd: checkout.dir, stdio: "inherit" });
|
|
2076
2444
|
});
|
|
2077
2445
|
const movesOf = (checkout) => {
|
|
2078
2446
|
const candidates2 = activeCandidates(manifest);
|
|
@@ -2136,8 +2504,8 @@ if (command === "train") {
|
|
|
2136
2504
|
};
|
|
2137
2505
|
const worktree = (checkout, branch) => {
|
|
2138
2506
|
const tooling = !!checkout.pkg.scripts?.["worktree:create"];
|
|
2139
|
-
const path = tooling ?
|
|
2140
|
-
const created = tooling ?
|
|
2507
|
+
const path = tooling ? join5(checkout.dir, ".worktrees", branch.replaceAll("/", "-")) : join5(mkdtempSync(join5(tmpdir(), "inixiative-train-")), basename2(checkout.dir));
|
|
2508
|
+
const created = tooling ? spawnSync5("bun", ["run", "worktree:create", defaultBranch(checkout.dir), branch], {
|
|
2141
2509
|
cwd: checkout.dir,
|
|
2142
2510
|
stdio: "inherit"
|
|
2143
2511
|
}).status === 0 && existsSync3(path) : git(checkout.dir, "worktree", "add", "--quiet", "-b", branch, path, "HEAD").status === 0;
|
|
@@ -2155,9 +2523,9 @@ if (command === "train") {
|
|
|
2155
2523
|
(file) => /(^|\/)\.env[^/]*$/.test(file) && !/(^|\/)(node_modules|\.worktrees)\//.test(file)
|
|
2156
2524
|
);
|
|
2157
2525
|
for (const file of envFiles) {
|
|
2158
|
-
if (existsSync3(
|
|
2159
|
-
|
|
2160
|
-
|
|
2526
|
+
if (existsSync3(join5(path, file))) continue;
|
|
2527
|
+
mkdirSync5(dirname5(join5(path, file)), { recursive: true });
|
|
2528
|
+
writeFileSync4(join5(path, file), readFileSync4(join5(checkout.dir, file)));
|
|
2161
2529
|
}
|
|
2162
2530
|
return { ...checkout, dir: path };
|
|
2163
2531
|
};
|
|
@@ -2178,11 +2546,11 @@ if (command === "train") {
|
|
|
2178
2546
|
...git(cwd, "ls-files", "--others", "--exclude-standard", "-z").stdout.split("\0")
|
|
2179
2547
|
].filter(Boolean);
|
|
2180
2548
|
if (changed.length === 0) return null;
|
|
2181
|
-
const scratch = mkdtempSync(
|
|
2549
|
+
const scratch = mkdtempSync(join5(tmpdir(), "inixiative-train-"));
|
|
2182
2550
|
try {
|
|
2183
|
-
const env = { ...process.env, GIT_INDEX_FILE:
|
|
2551
|
+
const env = { ...process.env, GIT_INDEX_FILE: join5(scratch, "index") };
|
|
2184
2552
|
const step = (...args) => {
|
|
2185
|
-
const result =
|
|
2553
|
+
const result = spawnSync5("git", args, { cwd, env, encoding: "utf8" });
|
|
2186
2554
|
if (result.status !== 0) {
|
|
2187
2555
|
throw new Abort(`git ${args[0]} failed capturing train:adopt's output`);
|
|
2188
2556
|
}
|
|
@@ -2192,7 +2560,7 @@ if (command === "train") {
|
|
|
2192
2560
|
step("add", "-A", "--", ...changed);
|
|
2193
2561
|
return step("write-tree");
|
|
2194
2562
|
} finally {
|
|
2195
|
-
|
|
2563
|
+
rmSync4(scratch, { recursive: true, force: true });
|
|
2196
2564
|
}
|
|
2197
2565
|
};
|
|
2198
2566
|
const adoptionPlan = (script, output) => script ? `re-lock, run train:adopt, then the check \u2014 complete if both pass, else incomplete with the re-lock only and train:adopt's output saved on ${output}` : "re-lock and commit";
|
|
@@ -2220,14 +2588,14 @@ if (command === "train") {
|
|
|
2220
2588
|
const { inspection } = bumpRanges(branchCheckout);
|
|
2221
2589
|
relockAndCheck(branchCheckout, false);
|
|
2222
2590
|
const owned = [...inspection.packagePaths, "bun.lock"].filter(
|
|
2223
|
-
(path) => existsSync3(
|
|
2591
|
+
(path) => existsSync3(join5(branchCheckout.dir, path))
|
|
2224
2592
|
);
|
|
2225
2593
|
if (git(branchCheckout.dir, "add", "--", ...owned).status !== 0) {
|
|
2226
2594
|
throw new Abort(`git add failed on ${branch} in ${checkout.name}`);
|
|
2227
2595
|
}
|
|
2228
2596
|
let produced = null;
|
|
2229
2597
|
if (script) {
|
|
2230
|
-
const adopted =
|
|
2598
|
+
const adopted = spawnSync5("bun", ["run", "train:adopt"], {
|
|
2231
2599
|
cwd: branchCheckout.dir,
|
|
2232
2600
|
stdio: "inherit"
|
|
2233
2601
|
}).status === 0;
|
|
@@ -2253,7 +2621,7 @@ if (command === "train") {
|
|
|
2253
2621
|
"-m",
|
|
2254
2622
|
`Train-Adopt: incomplete (${reason})`
|
|
2255
2623
|
] : ["-m", `chore: adopt ${label}`];
|
|
2256
|
-
const commit =
|
|
2624
|
+
const commit = spawnSync5("git", ["commit", ...message], {
|
|
2257
2625
|
cwd: branchCheckout.dir,
|
|
2258
2626
|
stdio: "inherit"
|
|
2259
2627
|
});
|
|
@@ -2263,7 +2631,7 @@ if (command === "train") {
|
|
|
2263
2631
|
);
|
|
2264
2632
|
}
|
|
2265
2633
|
if (reason && produced) {
|
|
2266
|
-
const saving =
|
|
2634
|
+
const saving = spawnSync5(
|
|
2267
2635
|
"git",
|
|
2268
2636
|
[
|
|
2269
2637
|
"commit-tree",
|
|
@@ -2311,14 +2679,14 @@ if (command === "train") {
|
|
|
2311
2679
|
if (dryRun && !changes) return false;
|
|
2312
2680
|
return effect(`commit its package.json files + bun.lock in ${checkout.name}`, true, () => {
|
|
2313
2681
|
const tracked = [...packagePaths, "bun.lock"].filter(
|
|
2314
|
-
(path) => existsSync3(
|
|
2682
|
+
(path) => existsSync3(join5(checkout.dir, path))
|
|
2315
2683
|
);
|
|
2316
2684
|
const mutated = git(checkout.dir, "status", "--porcelain", "--", ...tracked);
|
|
2317
2685
|
if (mutated.status !== 0 || mutated.stdout.trim().length === 0) return false;
|
|
2318
2686
|
if (git(checkout.dir, "add", "--", ...tracked).status !== 0) {
|
|
2319
2687
|
throw new Abort(`git add failed in ${checkout.name} \u2014 is bun.lock ignored?`);
|
|
2320
2688
|
}
|
|
2321
|
-
const commit =
|
|
2689
|
+
const commit = spawnSync5("git", ["commit", "-m", message], {
|
|
2322
2690
|
cwd: checkout.dir,
|
|
2323
2691
|
stdio: "inherit"
|
|
2324
2692
|
});
|
|
@@ -2336,24 +2704,24 @@ if (command === "train") {
|
|
|
2336
2704
|
});
|
|
2337
2705
|
const publishToNpm = (checkout, entry) => {
|
|
2338
2706
|
if (entry.path === "package.json") {
|
|
2339
|
-
return
|
|
2707
|
+
return spawnSync5("npm", ["publish"], { cwd: checkout.dir, stdio: "inherit" }).status === 0;
|
|
2340
2708
|
}
|
|
2341
|
-
const memberDir =
|
|
2342
|
-
const out = mkdtempSync(
|
|
2709
|
+
const memberDir = join5(checkout.dir, dirname5(entry.path));
|
|
2710
|
+
const out = mkdtempSync(join5(tmpdir(), "inixiative-train-"));
|
|
2343
2711
|
try {
|
|
2344
|
-
const pack =
|
|
2712
|
+
const pack = spawnSync5("bun", ["pm", "pack", "--destination", out], {
|
|
2345
2713
|
cwd: memberDir,
|
|
2346
2714
|
stdio: "inherit"
|
|
2347
2715
|
});
|
|
2348
|
-
const tarball =
|
|
2716
|
+
const tarball = readdirSync4(out).find((name) => name.endsWith(".tgz"));
|
|
2349
2717
|
if (pack.status !== 0 || !tarball) return false;
|
|
2350
|
-
return
|
|
2718
|
+
return spawnSync5("npm", ["publish", join5(out, tarball)], { cwd: memberDir, stdio: "inherit" }).status === 0;
|
|
2351
2719
|
} finally {
|
|
2352
|
-
|
|
2720
|
+
rmSync4(out, { recursive: true, force: true });
|
|
2353
2721
|
}
|
|
2354
2722
|
};
|
|
2355
2723
|
const npmLatest = (name) => {
|
|
2356
|
-
const remote =
|
|
2724
|
+
const remote = spawnSync5("npm", ["view", `${name}@latest`, "version"], { encoding: "utf8" });
|
|
2357
2725
|
return remote.status === 0 ? remote.stdout.trim() : null;
|
|
2358
2726
|
};
|
|
2359
2727
|
for (const { lane: lane2, checkouts, missing, ambiguous } of plan.lanes) {
|
|
@@ -2382,7 +2750,7 @@ if (command === "train") {
|
|
|
2382
2750
|
continue;
|
|
2383
2751
|
}
|
|
2384
2752
|
const releases = checkout.packages.map((entry) => {
|
|
2385
|
-
const local = JSON.parse(
|
|
2753
|
+
const local = JSON.parse(readFileSync4(join5(checkout.dir, entry.path), "utf8")).version ?? "0.0.0";
|
|
2386
2754
|
const remote = npmLatest(entry.name);
|
|
2387
2755
|
return { entry, local, remote, ahead: remote === null || compare(local, remote) > 0 };
|
|
2388
2756
|
});
|
|
@@ -2579,10 +2947,10 @@ blessed: ${promoted.length === 0 ? "nothing" : promoted.join(", ")}`);
|
|
|
2579
2947
|
version = bumpPatch(remoteVersion);
|
|
2580
2948
|
const bumped = version;
|
|
2581
2949
|
effect(`bump @inixiative/config to ${bumped} in package.json`, void 0, () => {
|
|
2582
|
-
const pkgPath =
|
|
2583
|
-
const pkg = JSON.parse(
|
|
2950
|
+
const pkgPath = join5(packageRoot, "package.json");
|
|
2951
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf8"));
|
|
2584
2952
|
pkg.version = bumped;
|
|
2585
|
-
|
|
2953
|
+
writeFileSync4(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
2586
2954
|
`);
|
|
2587
2955
|
});
|
|
2588
2956
|
}
|
|
@@ -2611,12 +2979,12 @@ blessed: ${promoted.length === 0 ? "nothing" : promoted.join(", ")}`);
|
|
|
2611
2979
|
recorded.length > 0 ? `candidate ${recorded.join(", ")}` : ""
|
|
2612
2980
|
].filter(Boolean).join("; ") || "release"} \u2014 ${version}`;
|
|
2613
2981
|
effect(`commit "${message}" in @inixiative/config`, void 0, () => {
|
|
2614
|
-
|
|
2982
|
+
spawnSync5("git", ["add", "--", "package.json", "versions.json", "test/fixtures"], {
|
|
2615
2983
|
cwd: packageRoot
|
|
2616
2984
|
});
|
|
2617
|
-
if (
|
|
2985
|
+
if (spawnSync5("git", ["diff", "--cached", "--quiet"], { cwd: packageRoot }).status === 0)
|
|
2618
2986
|
return;
|
|
2619
|
-
const commit =
|
|
2987
|
+
const commit = spawnSync5("git", ["commit", "-m", message], {
|
|
2620
2988
|
cwd: packageRoot,
|
|
2621
2989
|
stdio: "inherit"
|
|
2622
2990
|
});
|
|
@@ -2626,7 +2994,7 @@ blessed: ${promoted.length === 0 ? "nothing" : promoted.join(", ")}`);
|
|
|
2626
2994
|
}
|
|
2627
2995
|
});
|
|
2628
2996
|
effect(`publish @inixiative/config@${version} to npm`, void 0, () => {
|
|
2629
|
-
const publish2 =
|
|
2997
|
+
const publish2 = spawnSync5("npm", ["publish"], { cwd: packageRoot, stdio: "inherit" });
|
|
2630
2998
|
if (publish2.status !== 0 || !servedByRegistry("@inixiative/config", version)) {
|
|
2631
2999
|
console.error("\u2717 publish failed for @inixiative/config");
|
|
2632
3000
|
process.exit(1);
|
|
@@ -2671,14 +3039,14 @@ dry run complete \u2014 a real train would commit in ${committed.size} repo(s) a
|
|
|
2671
3039
|
console.log(` ${repoDir} (${branch})`);
|
|
2672
3040
|
} else if (commandLine.push) {
|
|
2673
3041
|
for (const repoDir of committed) {
|
|
2674
|
-
if (
|
|
3042
|
+
if (spawnSync5("git", ["push"], { cwd: repoDir, stdio: "inherit" }).status !== 0) {
|
|
2675
3043
|
console.error(`\u2717 push failed in ${repoDir}`);
|
|
2676
3044
|
process.exit(1);
|
|
2677
3045
|
}
|
|
2678
3046
|
}
|
|
2679
3047
|
for (const { dir: repoDir, branch, output } of adoptionBranches) {
|
|
2680
3048
|
for (const ref of output ? [branch, output] : [branch]) {
|
|
2681
|
-
const push =
|
|
3049
|
+
const push = spawnSync5("git", ["push", "-u", "origin", ref], {
|
|
2682
3050
|
cwd: repoDir,
|
|
2683
3051
|
stdio: "inherit"
|
|
2684
3052
|
});
|
|
@@ -2723,7 +3091,7 @@ function currentBranch(cwd) {
|
|
|
2723
3091
|
function servedByRegistry(name, version) {
|
|
2724
3092
|
const deadline = Date.now() + 15 * 6e4;
|
|
2725
3093
|
while (true) {
|
|
2726
|
-
const view =
|
|
3094
|
+
const view = spawnSync5("npm", ["view", `${name}@${version}`, "version", "--prefer-online"], {
|
|
2727
3095
|
encoding: "utf8"
|
|
2728
3096
|
});
|
|
2729
3097
|
if (view.status === 0 && view.stdout.trim() === version) return true;
|
|
@@ -2736,33 +3104,34 @@ function bumpPatch(version) {
|
|
|
2736
3104
|
return `${major}.${minor}.${(patch ?? 0) + 1}`;
|
|
2737
3105
|
}
|
|
2738
3106
|
function fixtureDirs() {
|
|
2739
|
-
const root =
|
|
3107
|
+
const root = join5(packageRoot, "test", "fixtures");
|
|
2740
3108
|
if (!existsSync3(root)) return [];
|
|
2741
|
-
return
|
|
3109
|
+
return readdirSync4(root).map((name) => join5(root, name)).filter((dir2) => existsSync3(join5(dir2, "package.json")));
|
|
2742
3110
|
}
|
|
2743
|
-
if (existsSync3(
|
|
2744
|
-
const status =
|
|
3111
|
+
if (existsSync3(join5(dir, ".git")) && !commandLine.force) {
|
|
3112
|
+
const status = spawnSync5("git", ["status", "--porcelain"], { cwd: dir, encoding: "utf8" });
|
|
2745
3113
|
if (status.status === 0 && status.stdout.trim().length > 0) {
|
|
2746
3114
|
console.error("\u2717 working tree dirty \u2014 commit first or pass --force");
|
|
2747
3115
|
process.exit(1);
|
|
2748
3116
|
}
|
|
2749
3117
|
}
|
|
2750
3118
|
var first = inspect(dir, manifest, presetFlag);
|
|
2751
|
-
|
|
3119
|
+
var firstStandards = standardsFindingsFor(dir);
|
|
3120
|
+
for (const finding of [...first.findings, ...firstStandards]) finding.fix?.();
|
|
2752
3121
|
first.flush();
|
|
2753
|
-
var fixed = first.findings.filter((finding) => finding.fix).length;
|
|
3122
|
+
var fixed = [...first.findings, ...firstStandards].filter((finding) => finding.fix).length;
|
|
2754
3123
|
if (fixed > 0) console.log(`applied ${fixed} fix${fixed === 1 ? "" : "es"}`);
|
|
2755
3124
|
if (!commandLine.noInstall) {
|
|
2756
3125
|
const relinked = new Set(
|
|
2757
3126
|
first.findings.flatMap(
|
|
2758
|
-
(finding) => finding.kind === "member-toolchain" && finding.path ? [
|
|
3127
|
+
(finding) => finding.kind === "member-toolchain" && finding.path ? [dirname5(finding.path)] : []
|
|
2759
3128
|
)
|
|
2760
3129
|
);
|
|
2761
3130
|
for (const member of relinked) {
|
|
2762
|
-
|
|
3131
|
+
rmSync4(join5(dir, member, "node_modules"), { recursive: true, force: true });
|
|
2763
3132
|
}
|
|
2764
3133
|
const install = (...extra) => {
|
|
2765
|
-
if (
|
|
3134
|
+
if (spawnSync5("bun", ["install", ...extra], { cwd: dir, stdio: "inherit" }).status !== 0) {
|
|
2766
3135
|
console.error("\u2717 bun install failed");
|
|
2767
3136
|
process.exit(1);
|
|
2768
3137
|
}
|
|
@@ -2774,15 +3143,16 @@ if (!commandLine.noInstall) {
|
|
|
2774
3143
|
installed = inspect(dir, manifest, presetFlag);
|
|
2775
3144
|
}
|
|
2776
3145
|
for (const { cwd, names } of staleUpdates(dir, installed.findings)) {
|
|
2777
|
-
if (
|
|
3146
|
+
if (spawnSync5("bun", ["update", ...names], { cwd, stdio: "inherit" }).status !== 0) {
|
|
2778
3147
|
console.error(`\u2717 bun update failed in ${cwd}`);
|
|
2779
3148
|
process.exit(1);
|
|
2780
3149
|
}
|
|
2781
3150
|
}
|
|
2782
3151
|
}
|
|
2783
3152
|
var final = inspect(dir, manifest, presetFlag);
|
|
2784
|
-
var
|
|
3153
|
+
var finalStandards = standardsFindingsFor(dir);
|
|
3154
|
+
var remaining = [...final.findings, ...finalStandards].filter((finding) => finding.fix);
|
|
2785
3155
|
for (const finding of remaining) finding.fix?.();
|
|
2786
3156
|
final.flush();
|
|
2787
|
-
var settled = remaining.length > 0 ? inspect(dir, manifest, presetFlag) : final;
|
|
2788
|
-
process.exit(report(settled
|
|
3157
|
+
var settled = remaining.length > 0 ? [...inspect(dir, manifest, presetFlag).findings, ...standardsFindingsFor(dir)] : [...final.findings, ...finalStandards];
|
|
3158
|
+
process.exit(report(settled) > 0 ? 1 : 0);
|