architecture-harness 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +20 -5
- package/src/cli/bash-command-guard.mjs +44 -5
- package/src/cli/bash-command-guard.test.mjs +35 -1
- package/src/cli/budget-guard.mjs +1 -0
- package/src/cli/budget-guard.test.mjs +7 -1
- package/src/cli/budget.mjs +3 -4
- package/src/cli/budget.test.mjs +5 -5
- package/src/cli/check-commands.mjs +82 -0
- package/src/cli/check-commands.test.mjs +190 -0
- package/src/cli/check.mjs +34 -13
- package/src/cli/ci-template.test.mjs +17 -15
- package/src/cli/cli.test.mjs +33 -2
- package/src/cli/commit-msg.mjs +12 -12
- package/src/cli/commit-msg.test.mjs +22 -7
- package/src/cli/generated-file-guard.mjs +11 -2
- package/src/cli/generated-file-guard.test.mjs +14 -2
- package/src/cli/init.mjs +70 -25
- package/src/cli/lint-changed.mjs +157 -0
- package/src/cli/lint-changed.test.mjs +102 -0
- package/src/cli/plugin-agents.test.mjs +1 -1
- package/src/cli/post-edit-gate.test.mjs +12 -3
- package/src/cli/pr-check.mjs +15 -2
- package/src/cli/pr-check.test.mjs +19 -9
- package/src/cli/qc.mjs +38 -7
- package/src/cli/scaffold.mjs +23 -2
- package/src/cli/scaffold.test.mjs +51 -0
- package/src/cli/shell-command.mjs +3 -1
- package/src/cli/stop-gate.test.mjs +49 -128
- package/src/cli/typecheck.mjs +46 -0
- package/src/cli/typecheck.test.mjs +43 -0
- package/src/cli/user-config-package.mjs +16 -0
- package/src/cli/user-config-toml.mjs +144 -0
- package/src/cli/user-config.mjs +155 -0
- package/src/cli/user-config.test.mjs +274 -0
- package/src/cli/work-order-guard.mjs +2 -2
- package/src/cli/worktree-gate.mjs +11 -12
- package/src/cli/worktree-gate.test.mjs +28 -29
- package/src/cli/worktree-isolation.mjs +3 -3
- package/src/cli/worktree-isolation.test.mjs +1 -1
- package/src/cli/worktree.mjs +9 -1
- package/src/cli/worktree.test.mjs +16 -1
- package/src/config.mjs +28 -11
- package/src/config.test.mjs +33 -1
- package/src/eslint/preset.mjs +8 -3
- package/src/eslint/preset.test.mjs +15 -8
- package/src/eslint/rules/no-raw-fetch.mjs +42 -2
- package/src/eslint/rules.test.mjs +15 -0
- package/src/gates/audit-append-only.mjs +18 -4
- package/src/gates/audit-append-only.test.mjs +19 -0
- package/src/gates/tenant-predicate.mjs +147 -7
- package/src/gates/tenant-predicate.test.mjs +55 -0
- package/src/gates/tenant-tables.mjs +5 -2
- package/src/gates/tenant-tables.test.mjs +8 -0
- package/src/gates/threshold-ratchet.mjs +12 -9
- package/src/gates/threshold-ratchet.test.mjs +16 -0
- package/src/plugin.test.mjs +28 -0
- package/src/screens/auth-run.test.mjs +20 -17
- package/src/screens/capture-idle.test.mjs +2 -1
- package/src/screens/catalog.test.mjs +3 -3
- package/src/screens/chrome.mjs +21 -0
- package/src/vale-style.test.mjs +5 -5
- package/templates/CLAUDE.md +2 -2
- package/templates/githooks/pre-commit +7 -10
- package/templates/github/workflows/ci.yml +25 -84
- package/templates/github/workflows/pr-policy.yml +36 -0
- package/user-config/claude/settings.shared.json +74 -0
- package/user-config/claude/statusline.js +323 -0
- package/user-config/codex/config.shared.toml +19 -0
- package/src/cli/edit-batch-guard.mjs +0 -77
- package/src/cli/edit-batch-guard.test.mjs +0 -131
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, readdirSync, rmSync, symlinkSync } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
|
+
import vm from "node:vm";
|
|
9
|
+
import { packageUserConfig } from "./user-config-package.mjs";
|
|
10
|
+
import { mergeClaudeSettings, mergeCodexConfig, captureCodexConfig, configPaths, assertSafePath, kitUserConfigDir, runUserConfig } from "./user-config.mjs";
|
|
11
|
+
|
|
12
|
+
function fixture(t) {
|
|
13
|
+
const root = mkdtempSync(path.join(os.tmpdir(), "qc-user-config-"));
|
|
14
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
15
|
+
const kitDir = path.join(root, "kit");
|
|
16
|
+
for (const dir of ["claude", "codex"]) mkdirSync(path.join(kitDir, dir), { recursive: true });
|
|
17
|
+
writeFileSync(path.join(kitDir, "claude/settings.shared.json"), '{"model":"opus","enabledPlugins":{"kit@remote":true}}\n');
|
|
18
|
+
writeFileSync(path.join(kitDir, "claude/statusline.js"), "console.log('status');\n");
|
|
19
|
+
writeFileSync(path.join(kitDir, "codex/config.shared.toml"), 'model = "shared"\n[plugins."kit@remote"]\nenabled = true\n');
|
|
20
|
+
const lines = [];
|
|
21
|
+
return { root, kitDir, home: path.join(root, "home"), env: {}, log: (line) => lines.push(line), lines, now: new Date(2026, 0, 2, 3, 4, 5) };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
test("JSON merges listed plugin and marketplace keys, preserving local keys and omitted shared keys", () => {
|
|
25
|
+
const local = { model: "old", effortLevel: "high", local: 7, enabledPlugins: { local: true, kit: false }, extraKnownMarketplaces: { local: {} } };
|
|
26
|
+
const shared = { model: "opus", local: 9, enabledPlugins: { kit: true }, extraKnownMarketplaces: { remote: { source: { source: "github", repo: "a/b" } } } };
|
|
27
|
+
const result = mergeClaudeSettings(JSON.stringify(local), JSON.stringify(shared));
|
|
28
|
+
assert.deepEqual(JSON.parse(result.text), { ...local, model: "opus", enabledPlugins: { local: true, kit: true }, extraKnownMarketplaces: { ...local.extraKnownMarketplaces, ...shared.extraKnownMarketplaces } });
|
|
29
|
+
assert.deepEqual(result.changed, ["model", "enabledPlugins.kit", "extraKnownMarketplaces.remote"]);
|
|
30
|
+
assert.deepEqual(mergeClaudeSettings(result.text, JSON.stringify(shared)).changed, []);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("TOML merges top-level keys and plugin fields while preserving comments and unrelated lines", () => {
|
|
34
|
+
const local = '# keep\r\nmodel = "old" # model comment\r\nnotify = ["local"]\r\n\r\n[desktop]\r\nmodel = "desktop"\r\n[plugins."kit@remote"] # plugin comment\r\nenabled = false # enabled comment\r\nlocal = 42\r\n[plugins."local@private"]\r\nenabled = true\r\n';
|
|
35
|
+
const shared = 'model = "new"\nservice_tier = "default"\nnotify = ["wrong"]\n[desktop]\nmodel = "wrong"\n[plugins."kit@remote"]\nenabled = true\n[plugins."new@remote"]\nenabled = false\n';
|
|
36
|
+
const result = mergeCodexConfig(local, shared);
|
|
37
|
+
assert.ok(result.text.includes('model = "new" # model comment\r\n'));
|
|
38
|
+
assert.ok(result.text.includes('notify = ["local"]\r\n'));
|
|
39
|
+
assert.ok(result.text.includes('[desktop]\r\nmodel = "desktop"\r\n'));
|
|
40
|
+
assert.ok(result.text.includes('[plugins."kit@remote"] # plugin comment\r\nenabled = true # enabled comment\r\nlocal = 42'));
|
|
41
|
+
assert.ok(result.text.includes('[plugins."local@private"]\r\nenabled = true'));
|
|
42
|
+
assert.ok(result.text.includes('service_tier = "default"\r\n'));
|
|
43
|
+
assert.ok(result.text.includes('[plugins."new@remote"]\r\nenabled = false'));
|
|
44
|
+
assert.deepEqual(mergeCodexConfig(result.text, shared).changed, []);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("TOML preserves multiline local values and ignores fake headers inside strings", () => {
|
|
48
|
+
const local = 'notify = [\n "keep",\n]\nmodel = "old"\n[desktop]\ntext = """\n[plugins."fake@local"]\nenabled = false\n"""\n';
|
|
49
|
+
const result = mergeCodexConfig(local, 'model = "new"\n');
|
|
50
|
+
assert.equal(result.text, local.replace('model = "old"', 'model = "new"'));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("TOML consumes multiline values of bare and quoted dotted keys", () => {
|
|
54
|
+
for (const key of ["x.y", '"x" . \'y\'', '\'x\' . "y" . z']) {
|
|
55
|
+
for (const quote of ['"""', "'''"]) {
|
|
56
|
+
const local = `${key} = ${quote}\nmodel = "inner"\n[plugins."fake@r"]\nenabled = false\n${quote}\n`;
|
|
57
|
+
assert.equal(mergeCodexConfig(local, 'model = "new"\n').text, `${local}model = "new"\n`);
|
|
58
|
+
assert.equal(captureCodexConfig(local), "");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("TOML handles a final value without a newline and compares string values", () => {
|
|
64
|
+
assert.equal(mergeCodexConfig('model = "old"', 'model = "new"').text, 'model = "new"');
|
|
65
|
+
const local = "model = 'same' # keep quotes\n";
|
|
66
|
+
assert.equal(mergeCodexConfig(local, 'model = "same"\n').text, local);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("a shared plugin field keeps local fields and adds the missing enabled field", () => {
|
|
70
|
+
const local = '[plugins."kit@remote"]\nlocal = true';
|
|
71
|
+
const merged = mergeCodexConfig(local, '[plugins."kit@remote"]\nenabled = true\n');
|
|
72
|
+
assert.equal(merged.text, `${local}\nenabled = true\n`);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("TOML fills existing plugin sections before appending new tables", () => {
|
|
76
|
+
const shared = '[plugins."A@r"]\nenabled = true\n[plugins."B@r"]\nenabled = true\n';
|
|
77
|
+
for (const eol of ["\n", "\r\n"]) {
|
|
78
|
+
for (const suffix of ["", eol]) {
|
|
79
|
+
const local = `# keep${eol}[plugins."B@r"]${suffix}`;
|
|
80
|
+
const expected = '# keep\n[plugins."B@r"]\nenabled = true\n\n[plugins."A@r"]\nenabled = true\n'.replaceAll("\n", eol);
|
|
81
|
+
assert.equal(mergeCodexConfig(local, shared).text, expected);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("TOML refuses inline plugin tables before adding a plugin section", () => {
|
|
87
|
+
for (const key of ["plugins", '"plugins"', "'plugins'"]) {
|
|
88
|
+
const local = `${key} = { "A@r" = { enabled = false } }\n`;
|
|
89
|
+
assert.throws(() => mergeCodexConfig(local, '[plugins."A@r"]\nenabled = true\n'), /inline.*plugins.*table/i);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("malformed shared configuration fails before any target changes", async (t) => {
|
|
94
|
+
const f = fixture(t);
|
|
95
|
+
writeFileSync(path.join(f.kitDir, "codex/config.shared.toml"), 'model = "unterminated');
|
|
96
|
+
assert.equal(await runUserConfig(["apply"], f), 2);
|
|
97
|
+
assert.deepEqual(readdirSync(f.root), ["kit"]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("backup collisions fail without overwriting the backup or original file", async (t) => {
|
|
101
|
+
const f = fixture(t);
|
|
102
|
+
const paths = configPaths(f.home, f.env);
|
|
103
|
+
mkdirSync(path.dirname(paths.claude), { recursive: true });
|
|
104
|
+
writeFileSync(paths.claude, '{"model":"local"}');
|
|
105
|
+
const backup = `${paths.claude}.bak-20260102-030405`;
|
|
106
|
+
writeFileSync(backup, "keep backup");
|
|
107
|
+
assert.equal(await runUserConfig(["apply"], f), 2);
|
|
108
|
+
assert.equal(readFileSync(backup, "utf8"), "keep backup");
|
|
109
|
+
assert.equal(readFileSync(paths.claude, "utf8"), '{"model":"local"}');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("a later backup collision stops all target writes", async (t) => {
|
|
113
|
+
const f = fixture(t);
|
|
114
|
+
const paths = configPaths(f.home, f.env);
|
|
115
|
+
mkdirSync(path.dirname(paths.claude), { recursive: true });
|
|
116
|
+
mkdirSync(path.dirname(paths.codex), { recursive: true });
|
|
117
|
+
const originals = new Map([
|
|
118
|
+
[paths.claude, '{"model":"local"}\n'],
|
|
119
|
+
[paths.codex, 'model = "local"\n'],
|
|
120
|
+
[paths.statusline, "local status\n"],
|
|
121
|
+
]);
|
|
122
|
+
for (const [file, text] of originals) writeFileSync(file, text);
|
|
123
|
+
const backup = `${paths.codex}.bak-20260102-030405`;
|
|
124
|
+
writeFileSync(backup, "keep backup");
|
|
125
|
+
assert.equal(await runUserConfig(["apply"], f), 2);
|
|
126
|
+
assert.match(f.lines.at(-1), /EEXIST/);
|
|
127
|
+
for (const [file, text] of originals) assert.equal(readFileSync(file, "utf8"), text);
|
|
128
|
+
assert.equal(readFileSync(backup, "utf8"), "keep backup");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("capture excludes local marketplaces, their plugins, notify, and desktop settings", () => {
|
|
132
|
+
const source = 'model = "shared"\nnotify = ["private"]\n[marketplaces.local]\nsource_type = "local"\nsource = "C:/private"\n[marketplaces.remote]\nsource_type = "git"\nsource = "https://example.com/kit.git"\n[plugins."keep@remote"]\nenabled = true\n[plugins."skip@local"]\nenabled = true\n[desktop]\nsecret = "private"\n';
|
|
133
|
+
assert.equal(captureCodexConfig(source), 'model = "shared"\n\n[plugins."keep@remote"]\nenabled = true\n');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("apply backs up changed files, lists keys, and leaves matching files untouched", async (t) => {
|
|
137
|
+
const f = fixture(t);
|
|
138
|
+
const paths = configPaths(f.home, f.env);
|
|
139
|
+
mkdirSync(path.dirname(paths.claude), { recursive: true });
|
|
140
|
+
writeFileSync(paths.claude, '{"model":"local","outside":true}\n');
|
|
141
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
142
|
+
assert.equal(readFileSync(`${paths.claude}.bak-20260102-030405`, "utf8"), '{"model":"local","outside":true}\n');
|
|
143
|
+
assert.equal(JSON.parse(readFileSync(paths.claude)).outside, true);
|
|
144
|
+
assert.ok(f.lines.some((line) => line.includes("model")));
|
|
145
|
+
const before = readdirSync(path.dirname(paths.claude));
|
|
146
|
+
assert.equal(await runUserConfig(["apply"], f), 0);
|
|
147
|
+
assert.deepEqual(readdirSync(path.dirname(paths.claude)), before);
|
|
148
|
+
assert.equal(await runUserConfig(["check"], f), 0);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("check returns one for drift and dry-run changes no files", async (t) => {
|
|
152
|
+
const f = fixture(t);
|
|
153
|
+
assert.equal(await runUserConfig(["check"], f), 1);
|
|
154
|
+
assert.equal(await runUserConfig(["apply", "--dry-run"], f), 0);
|
|
155
|
+
assert.deepEqual(readdirSync(f.root).sort(), ["kit"]);
|
|
156
|
+
assert.ok(f.lines.some((line) => line.includes("statusline.js")));
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("capture writes shared data only and supports dry-run", async (t) => {
|
|
160
|
+
const f = fixture(t);
|
|
161
|
+
const paths = configPaths(f.home, f.env);
|
|
162
|
+
mkdirSync(path.dirname(paths.claude), { recursive: true });
|
|
163
|
+
mkdirSync(path.dirname(paths.codex), { recursive: true });
|
|
164
|
+
writeFileSync(paths.claude, '{"model":"local","outside":"private","env":{"TOKEN":"private","CLAUDE_CODE_DISABLE_MOUSE":"1"}}');
|
|
165
|
+
writeFileSync(paths.codex, 'model = "local"\nnotify = ["private"]\n');
|
|
166
|
+
writeFileSync(paths.statusline, "status source\n");
|
|
167
|
+
assert.equal(await runUserConfig(["capture", "--dry-run"], f), 0);
|
|
168
|
+
assert.equal(JSON.parse(readFileSync(path.join(f.kitDir, "claude/settings.shared.json"))).model, "opus");
|
|
169
|
+
assert.equal(await runUserConfig(["capture"], f), 0);
|
|
170
|
+
const captured = JSON.parse(readFileSync(path.join(f.kitDir, "claude/settings.shared.json")));
|
|
171
|
+
assert.deepEqual(captured, { model: "local", env: { CLAUDE_CODE_DISABLE_MOUSE: "1" } });
|
|
172
|
+
assert.equal(readFileSync(path.join(f.kitDir, "claude/statusline.js"), "utf8"), "status source\n");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
for (const filename of [".claude.json", ".credentials.json", "auth.json", "api-token.json", "service-secret.toml", "my-credential.txt", "oauth-cache.json"]) {
|
|
176
|
+
test(`refuses credential filename ${filename} on Windows and POSIX paths`, async (t) => {
|
|
177
|
+
const f = fixture(t);
|
|
178
|
+
for (const name of [`/home/a/${filename}`, `C:\\Users\\a\\${filename.toUpperCase()}`]) {
|
|
179
|
+
assert.throws(() => assertSafePath(name), /credential/i);
|
|
180
|
+
for (const verb of ["apply", "capture"]) {
|
|
181
|
+
f.lines.length = 0;
|
|
182
|
+
assert.equal(await runUserConfig([verb, "--dry-run", "--codex-dir", name], f), 2);
|
|
183
|
+
assert.match(f.lines.at(-1), /Refusing credential file:/);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
assert.deepEqual(readdirSync(f.root), ["kit"]);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
test("refuses credential symlinks before changing another file", async (t) => {
|
|
191
|
+
const f = fixture(t);
|
|
192
|
+
const paths = configPaths(f.home, f.env);
|
|
193
|
+
mkdirSync(path.dirname(paths.codex), { recursive: true });
|
|
194
|
+
const secret = path.join(f.root, "auth.json");
|
|
195
|
+
writeFileSync(secret, "credential sentinel");
|
|
196
|
+
try { symlinkSync(secret, paths.codex); } catch (error) {
|
|
197
|
+
if (error.code === "EPERM") return t.skip("Windows requires symlink privileges");
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
assert.equal(await runUserConfig(["apply"], f), 2);
|
|
201
|
+
assert.deepEqual(readdirSync(f.home), [".codex"]);
|
|
202
|
+
assert.equal(readFileSync(secret, "utf8"), "credential sentinel");
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("home paths use the host path style and respect config environment overrides", () => {
|
|
206
|
+
assert.equal(configPaths("/home/person", {}).claude, "/home/person/.claude/settings.json");
|
|
207
|
+
assert.equal(configPaths("C:\\Users\\person", {}).codex, "C:\\Users\\person\\.codex\\config.toml");
|
|
208
|
+
assert.equal(configPaths("/home/person", { CLAUDE_CONFIG_DIR: "/config/claude", CODEX_HOME: "/config/codex" }).statusline, "/config/claude/statusline.js");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("CLI dispatch runs outside a repository and returns usage errors", () => {
|
|
212
|
+
const cli = fileURLToPath(new URL("./qc.mjs", import.meta.url));
|
|
213
|
+
const result = spawnSync(process.execPath, [cli, "user-config", "invalid"], { cwd: os.tmpdir(), encoding: "utf8" });
|
|
214
|
+
assert.equal(result.status, 2);
|
|
215
|
+
assert.match(result.stderr, /user-config/);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("CLI check returns drift, matching, and error exit codes", (t) => {
|
|
219
|
+
const f = fixture(t);
|
|
220
|
+
const paths = configPaths(f.home, f.env);
|
|
221
|
+
const cli = fileURLToPath(new URL("./qc.mjs", import.meta.url));
|
|
222
|
+
const args = [cli, "user-config", "check", "--kit-dir", f.kitDir, "--claude-dir", path.dirname(paths.claude), "--codex-dir", path.dirname(paths.codex)];
|
|
223
|
+
const run = () => spawnSync(process.execPath, args, { cwd: os.tmpdir(), encoding: "utf8" });
|
|
224
|
+
assert.equal(run().status, 1);
|
|
225
|
+
mkdirSync(path.dirname(paths.claude), { recursive: true });
|
|
226
|
+
mkdirSync(path.dirname(paths.codex), { recursive: true });
|
|
227
|
+
writeFileSync(paths.claude, readFileSync(path.join(f.kitDir, "claude/settings.shared.json")));
|
|
228
|
+
writeFileSync(paths.codex, readFileSync(path.join(f.kitDir, "codex/config.shared.toml")));
|
|
229
|
+
writeFileSync(paths.statusline, readFileSync(path.join(f.kitDir, "claude/statusline.js")));
|
|
230
|
+
assert.equal(run().status, 0);
|
|
231
|
+
writeFileSync(paths.claude, "invalid JSON");
|
|
232
|
+
assert.equal(run().status, 2);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("package staging includes all three shared files and resolves them outside the checkout", async (t) => {
|
|
236
|
+
const f = fixture(t);
|
|
237
|
+
const target = path.join(f.root, "node_modules/architecture-harness/user-config");
|
|
238
|
+
packageUserConfig(f.kitDir, target);
|
|
239
|
+
assert.equal(readFileSync(path.join(target, "claude/statusline.js"), "utf8"), "console.log('status');\n");
|
|
240
|
+
assert.equal(readFileSync(path.join(target, "codex/config.shared.toml"), "utf8"), readFileSync(path.join(f.kitDir, "codex/config.shared.toml"), "utf8"));
|
|
241
|
+
assert.equal(readFileSync(path.join(target, "claude/settings.shared.json"), "utf8"), readFileSync(path.join(f.kitDir, "claude/settings.shared.json"), "utf8"));
|
|
242
|
+
mkdirSync(path.join(f.root, "user-config"));
|
|
243
|
+
const moduleUrl = pathToFileURL(path.join(f.root, "node_modules/architecture-harness/src/cli/user-config.mjs"));
|
|
244
|
+
assert.equal(kitUserConfigDir(moduleUrl), `${target}${path.sep}`);
|
|
245
|
+
mkdirSync(path.join(f.root, ".claude-plugin"));
|
|
246
|
+
writeFileSync(path.join(f.root, ".claude-plugin/plugin.json"), "{}");
|
|
247
|
+
assert.equal(kitUserConfigDir(moduleUrl), `${path.join(f.root, "user-config")}${path.sep}`);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
for (const home of ["/home/person", "C:\\Users\\person"]) {
|
|
251
|
+
test(`seeded status line keeps its three rows with home ${home}`, () => {
|
|
252
|
+
const source = readFileSync(new URL("../../../../user-config/claude/statusline.js", import.meta.url), "utf8");
|
|
253
|
+
let input;
|
|
254
|
+
let output = "";
|
|
255
|
+
const fakeFs = { readFileSync: () => { throw new Error("No cache or account"); }, readdirSync: () => [], writeFileSync: () => {} };
|
|
256
|
+
const fakeProcess = {
|
|
257
|
+
env: { CLAUDE_CONFIG_DIR: `${home}/custom-claude` }, cwd: () => `${home}/project`,
|
|
258
|
+
stdin: { on: (event, fn) => { if (event === "data") input = fn; return { on: (_event, end) => { input(JSON.stringify({ model: { display_name: "Test model" }, context_window: { used_percentage: 20, context_window_size: 1000000 }, rate_limits: { five_hour: { used_percentage: 10, resets_at: 9999999999 }, seven_day: { used_percentage: 20, resets_at: 9999999999 } } })); end(); } }; } },
|
|
259
|
+
stdout: { write: (value) => { output += value; } },
|
|
260
|
+
};
|
|
261
|
+
vm.runInNewContext(source, { process: fakeProcess, Buffer, require: (name) => {
|
|
262
|
+
if (name === "fs" || name === "node:fs") return fakeFs;
|
|
263
|
+
if (name === "os" || name === "node:os") return { homedir: () => home };
|
|
264
|
+
if (name === "path" || name === "node:path") return home.startsWith("C:") ? path.win32 : path.posix;
|
|
265
|
+
if (name === "child_process" || name === "node:child_process") return { execFileSync: () => { throw new Error("No repository"); } };
|
|
266
|
+
throw new Error(`Unexpected module ${name}`);
|
|
267
|
+
} });
|
|
268
|
+
assert.equal(output.split("\n").length, 3);
|
|
269
|
+
assert.match(output, /~\/project/);
|
|
270
|
+
assert.match(output, /Test model/);
|
|
271
|
+
assert.match(output, /custom-claude/);
|
|
272
|
+
assert.match(output, /weekly 20%/);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
@@ -175,9 +175,9 @@ export async function run(root) {
|
|
|
175
175
|
return decide(call, root);
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
/** The verdict on one Write or
|
|
178
|
+
/** The verdict on one Write, Edit, MultiEdit or NotebookEdit call. @returns a deny payload, or null to allow it. */
|
|
179
179
|
export async function decide(call, root) {
|
|
180
|
-
const file = call.tool_input?.file_path;
|
|
180
|
+
const file = call.tool_input?.file_path ?? call.tool_input?.notebook_path;
|
|
181
181
|
if (!file) return null;
|
|
182
182
|
const absolute = path.resolve(root, file);
|
|
183
183
|
const rel = path.relative(root, absolute).split(path.sep).join("/");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// The Stop trigger of QC-015:
|
|
3
|
-
// head. It
|
|
2
|
+
// The Stop trigger of QC-015: it names the worktree, local branch, or remote branch that a PR this session merged
|
|
3
|
+
// leaves on its head. It advises and never blocks, since a developer can keep a merged branch on purpose. It reads
|
|
4
|
+
// the merge records of the ledger, and runs git only for a merge of this session.
|
|
4
5
|
|
|
5
6
|
import { spawnSync } from "node:child_process";
|
|
6
7
|
import { createHash } from "node:crypto";
|
|
@@ -52,7 +53,7 @@ function cleanupOf(merge, { main, folder }) {
|
|
|
52
53
|
const memoryOf = (tmp, session) => path.join(tmp, "qc-worktree-gate", `${fileSafe(session)}.last`);
|
|
53
54
|
const hashOf = (text) => createHash("sha256").update(text).digest("hex");
|
|
54
55
|
|
|
55
|
-
function
|
|
56
|
+
function lastNote(file) {
|
|
56
57
|
try {
|
|
57
58
|
return readFileSync(file, "utf8");
|
|
58
59
|
} catch {
|
|
@@ -60,7 +61,7 @@ function lastBlock(file) {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
/** The
|
|
64
|
+
/** The note on one Stop. @returns the hook output, or null to let the turn end with no message. */
|
|
64
65
|
export function decide(call, { tmp = os.tmpdir(), projectDir = process.env.CLAUDE_PROJECT_DIR } = {}) {
|
|
65
66
|
if (call.hook_event_name !== "Stop") return null;
|
|
66
67
|
const rule = worktreeRuleAt(call.cwd ?? process.cwd()) ?? (projectDir ? worktreeRuleAt(projectDir) : null);
|
|
@@ -81,21 +82,19 @@ export function decide(call, { tmp = os.tmpdir(), projectDir = process.env.CLAUD
|
|
|
81
82
|
rmSync(memory, { force: true });
|
|
82
83
|
return null;
|
|
83
84
|
}
|
|
84
|
-
const
|
|
85
|
+
const message = [
|
|
85
86
|
`Worktree check: a PR this session merged leaves its worktree or its branch. From the main checkout (${rule.main}), run:`,
|
|
86
87
|
...lines,
|
|
87
88
|
].join("\n");
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
if (call.stop_hook_active === true && lastBlock(memory) === hashOf(reason)) return note;
|
|
89
|
+
// The note names one set of leftovers once, so a branch kept on purpose costs one line.
|
|
90
|
+
if (lastNote(memory) === hashOf(message)) return null;
|
|
91
91
|
try {
|
|
92
92
|
mkdirSync(path.dirname(memory), { recursive: true });
|
|
93
|
-
writeFileSync(memory, hashOf(
|
|
93
|
+
writeFileSync(memory, hashOf(message));
|
|
94
94
|
} catch {
|
|
95
|
-
// With no memory,
|
|
96
|
-
if (call.stop_hook_active === true) return note;
|
|
95
|
+
// With no memory, the note repeats at each stop.
|
|
97
96
|
}
|
|
98
|
-
return {
|
|
97
|
+
return { systemMessage: message };
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
async function readStdin() {
|
|
@@ -38,41 +38,41 @@ function workspace(t, config = {}) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const merge = (extra = {}) => ({ type: "merge", session: "s", pr: 60, repo: "o/r", sha: "abc1234", branch: BRANCH, base: "main", mergedAt: null, issues: [], ...extra });
|
|
41
|
-
const stopCall = (cwd
|
|
42
|
-
const gate = (ws, cwd = ws.main,
|
|
41
|
+
const stopCall = (cwd) => ({ session_id: "s", cwd, hook_event_name: "Stop" });
|
|
42
|
+
const gate = (ws, cwd = ws.main, projectDir = undefined) => decide(stopCall(cwd), { tmp: ws.tmp, projectDir });
|
|
43
43
|
const dropWorktree = (ws) => git(ws.main, "worktree", "remove", "--force", ws.worktree);
|
|
44
44
|
const dropBranch = (ws) => git(ws.main, "branch", "-D", BRANCH);
|
|
45
45
|
const dropRemote = (ws) => git(ws.main, "push", "-q", "origin", "--delete", BRANCH);
|
|
46
46
|
|
|
47
|
-
test("a merged PR whose worktree remains
|
|
47
|
+
test("a merged PR whose worktree remains gets a note that names qc worktree remove", (t) => {
|
|
48
48
|
const ws = workspace(t);
|
|
49
49
|
appendRecord(ws.ledger, merge());
|
|
50
50
|
const output = gate(ws);
|
|
51
|
-
assert.equal(output?.decision,
|
|
52
|
-
assert.match(output.
|
|
53
|
-
assert.match(output.
|
|
51
|
+
assert.equal(output?.decision, undefined);
|
|
52
|
+
assert.match(output.systemMessage, /o\/r#60 \(feat\/62-x\): `npx qc worktree remove kit-62`/);
|
|
53
|
+
assert.match(output.systemMessage, /from the main checkout/i);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
test("a merged PR whose local branch remains
|
|
56
|
+
test("a merged PR whose local branch remains gets a note that names git branch -D", (t) => {
|
|
57
57
|
const ws = workspace(t);
|
|
58
58
|
appendRecord(ws.ledger, merge());
|
|
59
59
|
dropWorktree(ws);
|
|
60
60
|
dropRemote(ws);
|
|
61
61
|
const output = gate(ws);
|
|
62
|
-
assert.equal(output?.decision,
|
|
63
|
-
assert.match(output.
|
|
64
|
-
assert.doesNotMatch(output.
|
|
62
|
+
assert.equal(output?.decision, undefined);
|
|
63
|
+
assert.match(output.systemMessage, /`git branch -D feat\/62-x`/);
|
|
64
|
+
assert.doesNotMatch(output.systemMessage, /qc worktree remove|push origin --delete/);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
test("a merged PR whose remote branch remains
|
|
67
|
+
test("a merged PR whose remote branch remains gets a note that names git push origin --delete", (t) => {
|
|
68
68
|
const ws = workspace(t);
|
|
69
69
|
appendRecord(ws.ledger, merge());
|
|
70
70
|
dropWorktree(ws);
|
|
71
71
|
dropBranch(ws);
|
|
72
72
|
const output = gate(ws);
|
|
73
|
-
assert.equal(output?.decision,
|
|
74
|
-
assert.match(output.
|
|
75
|
-
assert.doesNotMatch(output.
|
|
73
|
+
assert.equal(output?.decision, undefined);
|
|
74
|
+
assert.match(output.systemMessage, /`git push origin --delete feat\/62-x`/);
|
|
75
|
+
assert.doesNotMatch(output.systemMessage, /branch -D/);
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
test("a merged PR with its worktree, its branch, and its remote branch gone passes", (t) => {
|
|
@@ -106,35 +106,34 @@ test("the main checkout on the merged branch is told to switch to the base first
|
|
|
106
106
|
dropRemote(ws);
|
|
107
107
|
git(ws.main, "switch", "-q", BRANCH);
|
|
108
108
|
const output = gate(ws);
|
|
109
|
-
assert.match(output.
|
|
109
|
+
assert.match(output.systemMessage, /`git switch main`, then `git branch -D feat\/62-x`/);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
test("a repeat stop with the same leftovers
|
|
112
|
+
test("a repeat stop with the same leftovers is silent, and a changed set gets a note again", (t) => {
|
|
113
113
|
const ws = workspace(t);
|
|
114
114
|
appendRecord(ws.ledger, merge());
|
|
115
|
-
assert.
|
|
116
|
-
|
|
117
|
-
assert.equal(repeat?.decision, undefined);
|
|
118
|
-
assert.match(repeat.systemMessage, /same.*kit-62/s);
|
|
115
|
+
assert.match(gate(ws)?.systemMessage, /kit-62/);
|
|
116
|
+
assert.equal(gate(ws), null);
|
|
119
117
|
dropWorktree(ws);
|
|
120
118
|
dropRemote(ws);
|
|
121
|
-
assert.
|
|
119
|
+
assert.match(gate(ws)?.systemMessage, /branch -D/, "a changed set gets a note again");
|
|
122
120
|
dropBranch(ws);
|
|
123
|
-
assert.equal(gate(ws
|
|
124
|
-
assert.deepEqual(readdirSync(path.join(ws.tmp, "qc-worktree-gate")), [], "a clean stop forgets the last
|
|
121
|
+
assert.equal(gate(ws), null);
|
|
122
|
+
assert.deepEqual(readdirSync(path.join(ws.tmp, "qc-worktree-gate")), [], "a clean stop forgets the last note");
|
|
125
123
|
});
|
|
126
124
|
|
|
127
125
|
test("a stop whose cwd is a removed worktree judges its main checkout, and one outside every checkout reads the project dir", (t) => {
|
|
128
126
|
const ws = workspace(t);
|
|
129
127
|
appendRecord(ws.ledger, merge());
|
|
130
128
|
const gone = path.join(ws.main, ".worktree", "kit-61");
|
|
131
|
-
assert.
|
|
129
|
+
assert.match(gate(ws, gone)?.systemMessage, /kit-62/);
|
|
130
|
+
rmSync(path.join(ws.tmp, "qc-worktree-gate"), { recursive: true, force: true });
|
|
132
131
|
const outside = path.join(ws.top, "tmp");
|
|
133
132
|
assert.equal(gate(ws, outside), null);
|
|
134
|
-
assert.
|
|
133
|
+
assert.match(gate(ws, outside, ws.main)?.systemMessage, /kit-62/);
|
|
135
134
|
});
|
|
136
135
|
|
|
137
|
-
test("the hook process is silent in a checkout with no merge, and prints the
|
|
136
|
+
test("the hook process is silent in a checkout with no merge, and prints the note after one", (t) => {
|
|
138
137
|
const ws = workspace(t);
|
|
139
138
|
const run = () => spawnSync(process.execPath, [HOOK], {
|
|
140
139
|
input: JSON.stringify(stopCall(ws.main)),
|
|
@@ -145,8 +144,8 @@ test("the hook process is silent in a checkout with no merge, and prints the blo
|
|
|
145
144
|
assert.equal(quiet.status, 0, quiet.stderr);
|
|
146
145
|
assert.equal(quiet.stdout, "");
|
|
147
146
|
appendRecord(ws.ledger, merge());
|
|
148
|
-
const
|
|
149
|
-
assert.equal(
|
|
150
|
-
assert.
|
|
147
|
+
const noted = run();
|
|
148
|
+
assert.equal(noted.status, 0, noted.stderr);
|
|
149
|
+
assert.match(JSON.parse(noted.stdout).systemMessage, /kit-62/);
|
|
151
150
|
assert.ok(existsSync(ws.worktree));
|
|
152
151
|
});
|
|
@@ -81,7 +81,7 @@ function heldRefusal(held, { branch, now, leaseFile, root, qc }) {
|
|
|
81
81
|
return (
|
|
82
82
|
`Another agent (session ${held.holder}) is already working in this worktree on ` +
|
|
83
83
|
`"${held.branch ?? branch}". Two agents on one branch lose each other's edits. ` +
|
|
84
|
-
`Take your own: \`
|
|
84
|
+
`Take your own: \`npx qc worktree add <slug> <branch>\`. ` +
|
|
85
85
|
`The lease is ${leaseFile}, written ${duration(held.age)} ago; it lapses at ` +
|
|
86
86
|
`${timestamp(held.lapsesAt)}, in ${duration(held.lapsesAt - now)}. See it: \`${qc} lease status ${at}\`. ` +
|
|
87
87
|
`Its holder releases it: \`${qc} lease release ${at} --session <id>\`. ` +
|
|
@@ -106,13 +106,13 @@ export function isolationRefusal(state) {
|
|
|
106
106
|
if (settings.protectedBranches.includes(branch)) {
|
|
107
107
|
return (
|
|
108
108
|
`"${branch}" is a protected branch and an agent does not generate code on it. ` +
|
|
109
|
-
`Create a work order's own branch first: \`
|
|
109
|
+
`Create a work order's own branch first: \`npx qc worktree add <slug> <branch>\`.`
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
if (settings.require === WORKTREE && kind === "primary") {
|
|
113
113
|
return (
|
|
114
114
|
`This is the primary worktree, shared by every session that opens the repository. ` +
|
|
115
|
-
`Give this work order its own: \`
|
|
115
|
+
`Give this work order its own: \`npx qc worktree add <slug> ${branch}\`.`
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
const held = leaseHeldByAnother(lease, sessionId, now, settings.leaseHours);
|
|
@@ -54,7 +54,7 @@ test("an ignored path is still refused on a detached HEAD", () => {
|
|
|
54
54
|
test("generating code on a protected branch is refused and names the branch", () => {
|
|
55
55
|
const reason = isolationRefusal(base({ branch: "main" }));
|
|
56
56
|
assert.match(reason, /"main" is a protected branch/);
|
|
57
|
-
assert.match(reason, /
|
|
57
|
+
assert.match(reason, /qc worktree add/);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
test("the protected branch list is configurable", () => {
|
package/src/cli/worktree.mjs
CHANGED
|
@@ -16,6 +16,14 @@ export const USAGE = `qc worktree — a linked worktree under .worktree/ in the
|
|
|
16
16
|
The default is worktree.base in qc.config.json. The install is worktree.install.
|
|
17
17
|
The folder is worktree.dir. remove also finds a worktree at ../<name>, beside the main checkout.`;
|
|
18
18
|
|
|
19
|
+
/** The install of the package manager whose lockfile `root` holds, or null for a folder with no package.json. */
|
|
20
|
+
export function installCommand(root) {
|
|
21
|
+
if (existsSync(path.join(root, "pnpm-lock.yaml"))) return "pnpm install --frozen-lockfile";
|
|
22
|
+
if (existsSync(path.join(root, "yarn.lock"))) return "yarn install --frozen-lockfile";
|
|
23
|
+
if (existsSync(path.join(root, "package-lock.json"))) return "npm ci";
|
|
24
|
+
return existsSync(path.join(root, "package.json")) ? "npm install" : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
function git(cwd, ...args) {
|
|
20
28
|
const result = spawnSync("git", args, { cwd, encoding: "utf8" });
|
|
21
29
|
return { ok: result.status === 0, out: (result.stdout ?? "").trim(), err: (result.stderr ?? "").trim() };
|
|
@@ -85,7 +93,7 @@ async function add(config, main, target, branch, from) {
|
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
95
|
// Every add runs the install, so a second add finishes what a failed install left.
|
|
88
|
-
const install = config.worktree?.install;
|
|
96
|
+
const install = config.worktree?.install ?? installCommand(target);
|
|
89
97
|
if (install) {
|
|
90
98
|
const ran = spawnSync(install, { cwd: target, shell: true, stdio: "inherit" });
|
|
91
99
|
if (ran.status !== 0) {
|
|
@@ -6,7 +6,7 @@ import { tmpdir } from "node:os";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { load } from "../config.mjs";
|
|
9
|
-
import { runWorktree } from "./worktree.mjs";
|
|
9
|
+
import { installCommand, runWorktree } from "./worktree.mjs";
|
|
10
10
|
|
|
11
11
|
const QC = fileURLToPath(new URL("./qc.mjs", import.meta.url));
|
|
12
12
|
const git = (cwd, ...args) => execFileSync("git", args, { cwd, stdio: "pipe", encoding: "utf8" }).trim();
|
|
@@ -55,6 +55,21 @@ function added(main, name, branch) {
|
|
|
55
55
|
return lastLine(result.stdout);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
test("with no install configured, the lockfile picks the install, and a folder with no package.json installs nothing", () => {
|
|
59
|
+
const dir = realpathSync.native(mkdtempSync(path.join(tmpdir(), "qc-install-")));
|
|
60
|
+
try {
|
|
61
|
+
assert.equal(installCommand(dir), null);
|
|
62
|
+
writeFileSync(path.join(dir, "package.json"), "{}");
|
|
63
|
+
assert.equal(installCommand(dir), "npm install");
|
|
64
|
+
for (const [lockfile, command] of [["package-lock.json", "npm ci"], ["yarn.lock", "yarn install --frozen-lockfile"], ["pnpm-lock.yaml", "pnpm install --frozen-lockfile"]]) {
|
|
65
|
+
writeFileSync(path.join(dir, lockfile), "");
|
|
66
|
+
assert.equal(installCommand(dir), command);
|
|
67
|
+
}
|
|
68
|
+
} finally {
|
|
69
|
+
rmSync(dir, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
58
73
|
test("add makes a worktree under .worktree/ in the main checkout and installs it; remove deletes it and its merged branch", () => {
|
|
59
74
|
const { top, main } = fixture();
|
|
60
75
|
const where = added(main, "wt-a", "feat/a");
|
package/src/config.mjs
CHANGED
|
@@ -247,8 +247,9 @@ export const defaults = {
|
|
|
247
247
|
// restricted. `require`: off | branch (refuse the trunk) | worktree (also refuse the primary).
|
|
248
248
|
swarm: {
|
|
249
249
|
isolation: { require: "off", protectedBranches: ["main", "master"], leaseHours: 8, allow: [] },
|
|
250
|
-
// Tool calls per subagent
|
|
251
|
-
|
|
250
|
+
// Tool calls per subagent: off by default. A whole number turns the budget on: the hook reminds at seventy
|
|
251
|
+
// percent and denies all but the hand-off at the budget.
|
|
252
|
+
toolCallBudget: null,
|
|
252
253
|
// Off until a repository writes the section. `{}` turns it on, and `dispatchDefaults` fills each key it omits.
|
|
253
254
|
dispatch: null,
|
|
254
255
|
// Read only while `dispatch` is on. `reviewDefaults` fills each key it omits.
|
|
@@ -257,13 +258,13 @@ export const defaults = {
|
|
|
257
258
|
direct: null,
|
|
258
259
|
},
|
|
259
260
|
|
|
260
|
-
// Files a generator writes. The generated-file hook refuses a hand edit of one and names `command
|
|
261
|
-
generated: { globs: ["**/*.generated.*"], command:
|
|
261
|
+
// Files a generator writes. The generated-file hook refuses a hand edit of one and names `command`, when set.
|
|
262
|
+
generated: { globs: ["**/*.generated.*"], command: null },
|
|
262
263
|
|
|
263
|
-
// `qc worktree`. `install` runs in each new worktree. `base` is the default `--from`: the ref a
|
|
264
|
+
// `qc worktree`. `install` runs in each new worktree; null picks it from the lockfile. `base` is the default `--from`: the ref a
|
|
264
265
|
// branch starts at, and the ref `remove` checks a merge against.
|
|
265
266
|
// `dir` holds each worktree, inside the main checkout. `enforce: false` turns off the QC-015 hooks.
|
|
266
|
-
worktree: { install:
|
|
267
|
+
worktree: { install: null, base: "origin/main", dir: ".worktree", enforce: true },
|
|
267
268
|
|
|
268
269
|
// Names that must be registered scoped, never singleton.
|
|
269
270
|
scopedSuffixes: ["Repository", "Saga", "UnitOfWork", "UnitOfWorkFactory"],
|
|
@@ -283,6 +284,15 @@ export const defaults = {
|
|
|
283
284
|
required: { "pre-commit": ["qc work-order-check"], "commit-msg": ["qc commit-msg"], "pre-push": ["qc check"] },
|
|
284
285
|
},
|
|
285
286
|
|
|
287
|
+
check: {
|
|
288
|
+
// The kit appends changed paths; for example, "pnpm exec vitest related --run". Null keeps this off.
|
|
289
|
+
related: null,
|
|
290
|
+
// Commands receive no extra arguments; for example, ["node script/check-comments.mjs --base origin/dev"].
|
|
291
|
+
commands: [],
|
|
292
|
+
// The merge base with this ref selects committed and staged changes.
|
|
293
|
+
base: "origin/main",
|
|
294
|
+
},
|
|
295
|
+
|
|
286
296
|
// `conventional` runs commitlint's conventional rules, an optional peer dependency the repository
|
|
287
297
|
// installs. `attribution` requires a Co-Authored-By trailer. The English rule always runs.
|
|
288
298
|
commitMessage: { conventional: true, attribution: false },
|
|
@@ -423,20 +433,21 @@ export const defaults = {
|
|
|
423
433
|
rules: {
|
|
424
434
|
"no-comment-paragraph": true,
|
|
425
435
|
"name-the-pattern": false,
|
|
426
|
-
|
|
436
|
+
// Opt-in: a style or a domain policy of the reference stack, not a defect in any repository.
|
|
437
|
+
"no-promise-then": false,
|
|
427
438
|
"no-number-in-comment": true,
|
|
428
439
|
"no-cross-feature-internals": true,
|
|
429
|
-
"no-offset-pagination":
|
|
440
|
+
"no-offset-pagination": false,
|
|
430
441
|
"no-orchestration-in-trigger": true,
|
|
431
|
-
"no-status-literal":
|
|
442
|
+
"no-status-literal": false,
|
|
432
443
|
"scoped-repository": true,
|
|
433
444
|
"storage-only-in-resource": true,
|
|
434
445
|
"external-service-only-in-adapter": true,
|
|
435
446
|
"tenant-scoped-table": true,
|
|
436
|
-
"signal-last-param":
|
|
447
|
+
"signal-last-param": false,
|
|
437
448
|
"no-raw-fetch": true,
|
|
438
449
|
"no-sql-raw": true,
|
|
439
|
-
"ime-safe-key":
|
|
450
|
+
"ime-safe-key": false,
|
|
440
451
|
// A policy rule: a repository turns it on once its controls carry the pending prop.
|
|
441
452
|
"mutation-control-pending": false,
|
|
442
453
|
"registry-literal": true,
|
|
@@ -631,6 +642,12 @@ export function load(root = process.cwd()) {
|
|
|
631
642
|
const file = path.join(root, CONFIG_FILE);
|
|
632
643
|
const user = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
|
|
633
644
|
const config = merge(defaults, user);
|
|
645
|
+
if (!isPlainObject(config.check)) throw new TypeError("check must be an object");
|
|
646
|
+
const { related, commands, base } = config.check;
|
|
647
|
+
const command = (value) => typeof value === "string" && value.trim().length > 0;
|
|
648
|
+
if (related !== null && !command(related)) throw new TypeError("check.related must be a non-empty string or null");
|
|
649
|
+
if (!Array.isArray(commands) || !commands.every(command)) throw new TypeError("check.commands must be an array of non-empty strings");
|
|
650
|
+
if (!command(base)) throw new TypeError("check.base must be a non-empty string");
|
|
634
651
|
config.root = root;
|
|
635
652
|
return config;
|
|
636
653
|
}
|