architecture-harness 0.20.0 → 0.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli/controller-guard.mjs +4 -4
- package/src/cli/controller-guard.test.mjs +23 -1
- package/src/cli/direct-lane.mjs +75 -15
- package/src/cli/direct-lane.test.mjs +120 -27
- package/src/cli/dispatch-guard.test.mjs +16 -0
- package/src/cli/dispatch-reminder.mjs +20 -3
- package/src/cli/dispatch-reminder.test.mjs +73 -18
- package/src/cli/dispatch.mjs +41 -11
- package/src/cli/dispatch.test.mjs +46 -4
- package/src/cli/merge-guard.mjs +14 -12
- package/src/cli/merge-guard.test.mjs +100 -11
- package/src/cli/plugin-agents.test.mjs +10 -10
- package/src/cli/task-gate.test.mjs +3 -0
- package/src/config.mjs +21 -13
- package/templates/docs/enforcement.md +2 -2
package/package.json
CHANGED
|
@@ -45,12 +45,12 @@ export function decide(call, platform = process.platform) {
|
|
|
45
45
|
const rel = path.relative(fileRoot, file).replaceAll("\\", "/");
|
|
46
46
|
const { controllerPaths } = workflow.review;
|
|
47
47
|
if (isControllerPath(rel, controllerPaths, platform)) return null;
|
|
48
|
-
|
|
49
|
-
const lane = direct
|
|
50
|
-
? editLane({ root: fileRoot, base: workflow.base,
|
|
48
|
+
// The checkout's `swarm.direct` only turns the lane off; `editLane` reads the limits from the base.
|
|
49
|
+
const lane = workflow.direct
|
|
50
|
+
? editLane({ root: fileRoot, base: workflow.base, protectedBranches: workflow.protectedBranches, rel, toolName: call.tool_name, input })
|
|
51
51
|
: workflow.directProblem && { problem: workflow.directProblem };
|
|
52
52
|
if (lane && lane.problem === null) {
|
|
53
|
-
return context(`Direct lane: with this edit the branch changes ${sizeLine(lane.size, direct)}, so the fix needs no implementer. Merge it with \`--match-head-commit <sha>\`.`);
|
|
53
|
+
return context(`Direct lane: with this edit the branch changes ${sizeLine(lane.size, lane.direct)}, so the fix needs no implementer. Merge it with \`--match-head-commit <sha>\`.`);
|
|
54
54
|
}
|
|
55
55
|
const laneNote = lane ? ` The direct lane of swarm.direct does not apply: ${lane.problem}.` : "";
|
|
56
56
|
return deny(
|
|
@@ -22,9 +22,9 @@ function workspace(t, dispatchConfig = { swarm: { dispatch: {} } }) {
|
|
|
22
22
|
git(main, "config", key, value);
|
|
23
23
|
}
|
|
24
24
|
writeFileSync(path.join(main, "a.txt"), "a\n");
|
|
25
|
+
if (dispatchConfig !== null) writeFileSync(path.join(main, "qc.config.json"), JSON.stringify(dispatchConfig));
|
|
25
26
|
git(main, "add", ".");
|
|
26
27
|
git(main, "commit", "-q", "-m", "init");
|
|
27
|
-
writeFileSync(path.join(main, "qc.config.json"), JSON.stringify(dispatchConfig));
|
|
28
28
|
const linked = path.join(base, "linked");
|
|
29
29
|
git(main, "worktree", "add", "-q", "-b", "feat/1-x", linked);
|
|
30
30
|
const scratch = path.join(base, "scratch");
|
|
@@ -161,3 +161,25 @@ test("a wrong swarm.direct closes the lane and keeps the guard on", (t) => {
|
|
|
161
161
|
assert.match(reason, /^Controller guard: while swarm.dispatch is on/);
|
|
162
162
|
assert.match(reason, /does not apply: swarm.direct.maxLines in qc.config.json must be a positive whole number/);
|
|
163
163
|
});
|
|
164
|
+
|
|
165
|
+
test("the lane reads its limits from the base, and names a base that holds no config", (t) => {
|
|
166
|
+
const ws = laneWorkspace(t, { swarm: { dispatch: {}, direct: { maxLines: 5 } } });
|
|
167
|
+
const linked = path.join(ws.linked, "src", "a.ts");
|
|
168
|
+
writeFileSync(path.join(ws.main, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, direct: { maxLines: 500 } } }));
|
|
169
|
+
const output = decide(edit(ws.main, linked, "Edit", { tool_input: { file_path: linked, ...small } }));
|
|
170
|
+
assert.match(output?.hookSpecificOutput?.additionalContext ?? "", /the branch changes 2 of 5 lines in 1 of 2 files/);
|
|
171
|
+
writeFileSync(path.join(ws.linked, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, direct: { maxLines: 500 } } }));
|
|
172
|
+
const loosened = decide(edit(ws.main, linked, "Edit", { tool_input: { file_path: linked, ...small } }));
|
|
173
|
+
assert.match(denied(loosened) ?? "", /does not apply: qc\.config\.json changes on the branch, so it runs the subagent workflow/);
|
|
174
|
+
const bare = laneWorkspace(t, null);
|
|
175
|
+
writeFileSync(path.join(bare.main, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {} } }));
|
|
176
|
+
const closed = decide(edit(bare.main, path.join(bare.linked, "src", "a.ts"), "Edit", { tool_input: { file_path: path.join(bare.linked, "src", "a.ts"), ...small } }));
|
|
177
|
+
assert.match(denied(closed) ?? "", /does not apply: git cannot read qc\.config\.json at origin\/main/);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("a pending edit of qc.config.json leaves the lane when the controller does not own the file", (t) => {
|
|
181
|
+
const ws = laneWorkspace(t, { swarm: { dispatch: {}, review: { controllerPaths: ["docs/**"] } } });
|
|
182
|
+
const config = path.join(ws.linked, "qc.config.json");
|
|
183
|
+
const reason = denied(decide(edit(ws.main, config, "Edit", { tool_input: { file_path: config, ...small } }))) ?? "";
|
|
184
|
+
assert.match(reason, /does not apply: qc\.config\.json changes on the branch, so it runs the subagent workflow/);
|
|
185
|
+
});
|
package/src/cli/direct-lane.mjs
CHANGED
|
@@ -15,6 +15,9 @@ const KINDS = ["task", "branch"];
|
|
|
15
15
|
const GITLINK_MODE = "160000";
|
|
16
16
|
const SNIFF_BYTES = 8_000;
|
|
17
17
|
const MAX_TEXT_BYTES = 1_000_000;
|
|
18
|
+
const OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;
|
|
19
|
+
const PR_BASE = "the PR base";
|
|
20
|
+
const NOTE_READ_MS = 2_000;
|
|
18
21
|
// Under the 10 s timeout of a PreToolUse hook, for all git and gh reads of one call: a hook that times out lets its call run.
|
|
19
22
|
export const LANE_BUDGET_MS = 6_000;
|
|
20
23
|
|
|
@@ -37,11 +40,24 @@ export function directSettings(swarm = {}) {
|
|
|
37
40
|
return settings;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
/**
|
|
41
|
-
|
|
43
|
+
/**
|
|
44
|
+
* @returns the lane's limits for the checkout that holds `cwd`, or null when it has no config or the lane is off. The
|
|
45
|
+
* checkout's `swarm.direct` can turn the lane off. The limits are the ones at `worktree.base` when one git read gets
|
|
46
|
+
* them, as the lane judges, and the checkout's own when it does not. The read waits `readMs` at most.
|
|
47
|
+
*/
|
|
48
|
+
export function directSettingsAt(cwd, { readMs = NOTE_READ_MS } = {}) {
|
|
42
49
|
const root = checkoutRootOf(cwd);
|
|
43
50
|
if (!root || !existsSync(path.join(root, CONFIG_FILE))) return null;
|
|
44
|
-
|
|
51
|
+
const config = load(root);
|
|
52
|
+
const local = directSettings(config.swarm);
|
|
53
|
+
if (!local) return null;
|
|
54
|
+
const text = gitOutWithin(readMs, root, "show", `${config.worktree?.base ?? "origin/main"}:${CONFIG_FILE}`);
|
|
55
|
+
if (text === null) return local;
|
|
56
|
+
try {
|
|
57
|
+
return directSettings(JSON.parse(text).swarm);
|
|
58
|
+
} catch {
|
|
59
|
+
return local;
|
|
60
|
+
}
|
|
45
61
|
}
|
|
46
62
|
|
|
47
63
|
/** The lines of a text as git counts them: a last line with no newline still counts. */
|
|
@@ -72,6 +88,32 @@ function gitBy(budgetMs) {
|
|
|
72
88
|
|
|
73
89
|
const gitFailed = (git, what) => (git.late?.() ? `git ran past the ${LANE_BUDGET_MS} ms budget of the lane` : what);
|
|
74
90
|
|
|
91
|
+
/**
|
|
92
|
+
* The limits of `swarm.direct` in `qc.config.json` at the commit `base`, read through `git`. A branch cannot loosen its own
|
|
93
|
+
* limits, so the lane never reads the checkout's file. `label` names the base in a problem.
|
|
94
|
+
* @returns `{ direct }`, or `{ problem }` naming why the lane is closed.
|
|
95
|
+
*/
|
|
96
|
+
function directAtBase(root, base, git, label = base) {
|
|
97
|
+
const text = git(root, "show", `${base}:${CONFIG_FILE}`);
|
|
98
|
+
if (text === null) return { problem: gitFailed(git, `git cannot read ${CONFIG_FILE} at ${label}`) };
|
|
99
|
+
try {
|
|
100
|
+
const config = JSON.parse(text);
|
|
101
|
+
if (config === null || typeof config !== "object" || Array.isArray(config)) return { problem: `${CONFIG_FILE} at ${label} is not a JSON object` };
|
|
102
|
+
const { swarm } = config;
|
|
103
|
+
if (swarm !== undefined && (swarm === null || typeof swarm !== "object" || Array.isArray(swarm))) {
|
|
104
|
+
return { problem: `swarm in ${CONFIG_FILE} at ${label} must be an object, got ${JSON.stringify(swarm)}` };
|
|
105
|
+
}
|
|
106
|
+
const direct = directSettings(swarm);
|
|
107
|
+
return direct ? { direct } : { problem: `${KEY} is false at ${label}` };
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return { problem: error instanceof SyntaxError ? `${CONFIG_FILE} at ${label} is not JSON` : error.message };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The checkout also sets `worktree.base` and `swarm.isolation.protectedBranches`, so a branch that edits the file could point `base` at looser settings.
|
|
114
|
+
const touchesConfig = (changes) => [...changes.keys()].some((file) => file.toLowerCase() === CONFIG_FILE);
|
|
115
|
+
const CONFIG_PROBLEM = `${CONFIG_FILE} changes on the branch, so it runs the subagent workflow`;
|
|
116
|
+
|
|
75
117
|
function startsWithNul(file) {
|
|
76
118
|
const fd = openSync(file, "r");
|
|
77
119
|
try {
|
|
@@ -152,40 +194,57 @@ export function sizeProblem(changes, direct) {
|
|
|
152
194
|
|
|
153
195
|
/**
|
|
154
196
|
* Judges one main-session edit of `rel` in the checkout at `root`. The branch diff and the pending edit together
|
|
155
|
-
* must fit
|
|
197
|
+
* must fit the limits at `base`, on a branch that is not protected, and neither may touch `qc.config.json`.
|
|
198
|
+
* @returns `{ problem }`, or `{ problem: null, size, direct }` when it fits.
|
|
156
199
|
*/
|
|
157
|
-
export function editLane({ root, base,
|
|
200
|
+
export function editLane({ root, base, protectedBranches, rel, toolName, input, budgetMs = LANE_BUDGET_MS }) {
|
|
158
201
|
const git = gitBy(budgetMs);
|
|
159
202
|
const branch = git(root, "branch", "--show-current");
|
|
160
203
|
if (branch === null) return { problem: gitFailed(git, "git cannot name the checked-out branch") };
|
|
161
204
|
if (branch === "") return { problem: "the checkout has a detached head" };
|
|
162
205
|
if (protectedBranches.includes(branch)) return { problem: `${branch} is a protected branch, so start a branch for the fix` };
|
|
163
206
|
const fork = git(root, "merge-base", base, "HEAD");
|
|
164
|
-
|
|
207
|
+
if (!fork) return { problem: gitFailed(git, `git cannot diff the branch against ${base}`) };
|
|
208
|
+
const settings = directAtBase(root, base, git);
|
|
209
|
+
if (!settings.direct) return settings;
|
|
210
|
+
const { direct } = settings;
|
|
211
|
+
const changes = changesSince(root, fork, { maxFiles: direct.maxFiles, git });
|
|
165
212
|
if (!changes) return { problem: gitFailed(git, `git cannot diff the branch against ${base}`) };
|
|
166
213
|
const old = toolName === "Write" || toolName === "NotebookEdit" ? fileLines(root, rel) : undefined;
|
|
167
214
|
const replaced = old === undefined ? 0 : old;
|
|
168
215
|
const before = changes.has(rel) ? changes.get(rel) : 0;
|
|
169
216
|
changes.set(rel, before === null || replaced === null ? null : before + replaced + pendingLines(toolName, input));
|
|
217
|
+
if (touchesConfig(changes)) return { problem: CONFIG_PROBLEM };
|
|
170
218
|
const problem = sizeProblem(changes, direct);
|
|
171
|
-
return problem ? { problem } : { problem: null, size: sizeOf(changes) };
|
|
219
|
+
return problem ? { problem } : { problem: null, size: sizeOf(changes), direct };
|
|
172
220
|
}
|
|
173
221
|
|
|
174
222
|
/**
|
|
175
223
|
* Judges the merge of head `sha` with no review of the merge kind. A record belongs to the branch when it names
|
|
176
224
|
* a commit of the branch, or the name of a local branch at `sha`, so an amend or a rebase cannot drop it.
|
|
177
225
|
* The newest review on the branch must not ask for changes, and no implementer may have worked on it.
|
|
178
|
-
*
|
|
226
|
+
* `baseOid` is the commit the PR merges into, as GitHub names it: the lane reads the limits at that commit and
|
|
227
|
+
* measures the branch from its merge base with it, so no local ref decides. A change to `qc.config.json` closes the lane.
|
|
228
|
+
* @returns `{ problem }`, or `{ problem: null, size, direct, review }` when the merge fits. `review` is the
|
|
229
|
+
* APPROVED verdict that a path of `reviewPaths` needed, or null.
|
|
179
230
|
*/
|
|
180
|
-
export function mergeLane({ root,
|
|
231
|
+
export function mergeLane({ root, baseOid, protectedBranches = [], sha, records, budgetMs = LANE_BUDGET_MS }) {
|
|
232
|
+
if (typeof baseOid !== "string" || !OBJECT_ID.test(baseOid)) return { problem: "gh returned no base commit for the PR, so the lane cannot tell what the PR merges into" };
|
|
181
233
|
const git = gitBy(budgetMs);
|
|
182
|
-
|
|
183
|
-
|
|
234
|
+
if (git(root, "cat-file", "-e", `${baseOid}^{commit}`) === null) {
|
|
235
|
+
return { problem: gitFailed(git, `the PR base commit ${baseOid.slice(0, 12)} is not in this repository, so run \`git fetch\``) };
|
|
236
|
+
}
|
|
237
|
+
const fork = git(root, "merge-base", baseOid, sha);
|
|
238
|
+
if (!fork) return { problem: gitFailed(git, `git cannot find the merge base of ${PR_BASE} and ${sha}`) };
|
|
239
|
+
const settings = directAtBase(root, baseOid, git, PR_BASE);
|
|
240
|
+
if (!settings.direct) return settings;
|
|
241
|
+
const { direct } = settings;
|
|
184
242
|
const history = git(root, "rev-list", `${fork}..${sha}`);
|
|
185
243
|
const changes = history === null ? null : changesSince(root, fork, { head: sha, git });
|
|
186
|
-
if (!changes) return { problem: gitFailed(git, `git cannot diff ${sha} against ${
|
|
244
|
+
if (!changes) return { problem: gitFailed(git, `git cannot diff ${sha} against ${PR_BASE}`) };
|
|
245
|
+
if (touchesConfig(changes)) return { problem: CONFIG_PROBLEM };
|
|
187
246
|
const shas = history.split(/\r?\n/).filter(Boolean);
|
|
188
|
-
if (shas.length === 0) return { problem: `${sha} has no commit past ${
|
|
247
|
+
if (shas.length === 0) return { problem: `${sha} has no commit past ${PR_BASE}, so the lane cannot measure what the PR merges` };
|
|
189
248
|
const branches = branchesAt(root, sha, git);
|
|
190
249
|
if (branches.length === 0) return { problem: gitFailed(git, `no local branch points at ${sha}, so the ledger cannot be tied to its branch`) };
|
|
191
250
|
const guarded = branches.find((branch) => protectedBranches.includes(branch));
|
|
@@ -202,8 +261,9 @@ export function mergeLane({ root, base, direct, protectedBranches = [], sha, rec
|
|
|
202
261
|
if (problem) return { problem };
|
|
203
262
|
const reviewed = pathMatcher(direct.reviewPaths);
|
|
204
263
|
const needsReview = [...changes.keys()].find((file) => reviewed(file));
|
|
205
|
-
|
|
264
|
+
const approval = needsReview === undefined ? null : latestVerdictFor(records, sha, KINDS);
|
|
265
|
+
if (needsReview !== undefined && approval?.verdict !== "APPROVED") {
|
|
206
266
|
return { problem: `${needsReview} matches ${KEY}.reviewPaths, so dispatch the task reviewer (sdd-reviewer) on ${sha}` };
|
|
207
267
|
}
|
|
208
|
-
return { problem: null, size: sizeOf(changes) };
|
|
268
|
+
return { problem: null, size: sizeOf(changes), direct, review: approval };
|
|
209
269
|
}
|
|
@@ -11,13 +11,14 @@ const git = (cwd, ...args) => execFileSync("git", args, { cwd, stdio: "pipe", en
|
|
|
11
11
|
const BASE = "origin/main";
|
|
12
12
|
const lines = (n) => Array.from({ length: n }, (_, i) => `line ${i}`).join("\n") + "\n";
|
|
13
13
|
|
|
14
|
-
/** A repository with `origin/main` at its first commit and a branch `feat/1-x` checked out. */
|
|
15
|
-
function repo(t) {
|
|
14
|
+
/** A repository with `origin/main` at its first commit, which holds a `qc.config.json` with `swarm`, and a branch `feat/1-x` checked out. */
|
|
15
|
+
function repo(t, swarm = { dispatch: {} }, config = JSON.stringify({ swarm })) {
|
|
16
16
|
const root = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-direct-")));
|
|
17
17
|
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
18
18
|
git(root, "init", "-q", "-b", "main");
|
|
19
19
|
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"]]) git(root, "config", key, value);
|
|
20
20
|
mkdirSync(path.join(root, "src"));
|
|
21
|
+
if (config !== null) writeFileSync(path.join(root, "qc.config.json"), config);
|
|
21
22
|
writeFileSync(path.join(root, "src", "a.ts"), lines(10));
|
|
22
23
|
git(root, "add", ".");
|
|
23
24
|
git(root, "commit", "-q", "-m", "init");
|
|
@@ -34,8 +35,11 @@ const commit = (root, file, text) => {
|
|
|
34
35
|
return git(root, "rev-parse", "HEAD");
|
|
35
36
|
};
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
/** The commit `origin/main` names: the base commit a PR merges into. */
|
|
39
|
+
const oidOf = (root) => git(root, "rev-parse", BASE);
|
|
40
|
+
|
|
41
|
+
const edit = (root, rel, input) =>
|
|
42
|
+
editLane({ root, base: BASE, protectedBranches: ["main"], rel, toolName: "Edit", input });
|
|
39
43
|
|
|
40
44
|
test("the settings fill their defaults, accept false, and name a wrong key", () => {
|
|
41
45
|
assert.deepEqual(directSettings({}), directDefaults);
|
|
@@ -98,7 +102,7 @@ test("a protected branch, a detached head, or a missing base ref leaves the lane
|
|
|
98
102
|
test("a small head with no review merges through the lane", (t) => {
|
|
99
103
|
const root = repo(t);
|
|
100
104
|
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
101
|
-
const fit = mergeLane({ root,
|
|
105
|
+
const fit = mergeLane({ root, baseOid: oidOf(root), sha, records: [] });
|
|
102
106
|
assert.equal(fit.problem, null);
|
|
103
107
|
assert.deepEqual(fit.size, { files: 1, lines: 2 });
|
|
104
108
|
});
|
|
@@ -107,21 +111,20 @@ test("a review that is not APPROVED, an implementer commit, or a large head keep
|
|
|
107
111
|
const root = repo(t);
|
|
108
112
|
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
109
113
|
const changes = [{ type: "verdict", kind: "task", verdict: "CHANGES_REQUIRED", sha }];
|
|
110
|
-
assert.match(mergeLane({ root,
|
|
114
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: changes }).problem, /latest review on the branch, of .*, is CHANGES_REQUIRED/);
|
|
111
115
|
const stop = [{ type: "stop", role: "implementer", head: sha, branch: "feat/1-x" }];
|
|
112
|
-
assert.match(mergeLane({ root,
|
|
116
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: stop }).problem, /an implementer worked on the branch/);
|
|
113
117
|
const big = commit(root, "src/b.ts", lines(30));
|
|
114
|
-
assert.match(mergeLane({ root,
|
|
115
|
-
assert.match(mergeLane({ root,
|
|
118
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha: big, records: [] }).problem, /32 of 20 lines/);
|
|
119
|
+
assert.match(mergeLane({ root, baseOid: "1".repeat(40), sha, records: [] }).problem, /is not in this repository, so run `git fetch`/);
|
|
116
120
|
});
|
|
117
121
|
|
|
118
122
|
test("a head that touches a review path needs one APPROVED review of either kind", (t) => {
|
|
119
|
-
const root = repo(t);
|
|
123
|
+
const root = repo(t, { dispatch: {}, direct: { reviewPaths: ["src/**"] } });
|
|
120
124
|
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
121
|
-
|
|
122
|
-
assert.match(mergeLane({ root, base: BASE, direct, sha, records: [] }).problem, /src\/a\.ts matches swarm\.direct\.reviewPaths/);
|
|
125
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, /src\/a\.ts matches swarm\.direct\.reviewPaths/);
|
|
123
126
|
const approved = [{ type: "verdict", kind: "task", verdict: "APPROVED", sha }];
|
|
124
|
-
assert.equal(mergeLane({ root,
|
|
127
|
+
assert.equal(mergeLane({ root, baseOid: oidOf(root), sha, records: approved }).problem, null);
|
|
125
128
|
});
|
|
126
129
|
|
|
127
130
|
test("a commit after a review that asked for changes stays out of the lane until a review approves it", (t) => {
|
|
@@ -129,9 +132,9 @@ test("a commit after a review that asked for changes stays out of the lane until
|
|
|
129
132
|
const first = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
130
133
|
const records = [{ type: "verdict", kind: "task", verdict: "CHANGES_REQUIRED", sha: first }];
|
|
131
134
|
const second = commit(root, "src/a.ts", lines(10).replace("line 3", "line 3!"));
|
|
132
|
-
assert.match(mergeLane({ root,
|
|
135
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha: second, records }).problem, /CHANGES_REQUIRED/);
|
|
133
136
|
records.push({ type: "verdict", kind: "task", verdict: "APPROVED", sha: second });
|
|
134
|
-
assert.equal(mergeLane({ root,
|
|
137
|
+
assert.equal(mergeLane({ root, baseOid: oidOf(root), sha: second, records }).problem, null);
|
|
135
138
|
});
|
|
136
139
|
|
|
137
140
|
test("an amend after a review that asked for changes, or after an implementer commit, stays out of the lane", (t) => {
|
|
@@ -142,15 +145,15 @@ test("an amend after a review that asked for changes, or after an implementer co
|
|
|
142
145
|
writeFileSync(path.join(root, "src", "a.ts"), lines(10).replace("line 3", "line 3!"));
|
|
143
146
|
git(root, "commit", "-q", "--amend", "-am", "amended");
|
|
144
147
|
const amended = git(root, "rev-parse", "HEAD");
|
|
145
|
-
assert.match(mergeLane({ root,
|
|
146
|
-
assert.match(mergeLane({ root,
|
|
148
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha: amended, records: verdicts }).problem, /CHANGES_REQUIRED/);
|
|
149
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha: amended, records: stops }).problem, /an implementer worked/);
|
|
147
150
|
});
|
|
148
151
|
|
|
149
152
|
test("a head that no local branch points at stays out of the lane", (t) => {
|
|
150
153
|
const root = repo(t);
|
|
151
154
|
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
152
155
|
git(root, "reset", "-q", "--hard", "HEAD~1");
|
|
153
|
-
assert.match(mergeLane({ root,
|
|
156
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, /no local branch points at/);
|
|
154
157
|
});
|
|
155
158
|
|
|
156
159
|
test("a binary file, a submodule, or an untracked binary has no size the lane can judge", (t) => {
|
|
@@ -158,39 +161,129 @@ test("a binary file, a submodule, or an untracked binary has no size the lane ca
|
|
|
158
161
|
writeFileSync(path.join(root, "src", "lib.dll"), Buffer.from([0, 1, 2, 3]));
|
|
159
162
|
assert.match(edit(root, "src/a.ts", { old_string: "a", new_string: "b" }).problem, /src\/lib\.dll is a binary file/);
|
|
160
163
|
const binary = commit(root, "src/lib.dll", Buffer.from([0, 1, 2, 3]));
|
|
161
|
-
assert.match(mergeLane({ root,
|
|
164
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha: binary, records: [] }).problem, /src\/lib\.dll is a binary file/);
|
|
162
165
|
git(root, "reset", "-q", "--hard", "HEAD~1");
|
|
163
166
|
git(root, "update-index", "--add", "--cacheinfo", `160000,${git(root, "rev-parse", "HEAD")},vendor/sub`);
|
|
164
167
|
git(root, "commit", "-q", "-m", "submodule");
|
|
165
|
-
assert.match(mergeLane({ root,
|
|
168
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha: git(root, "rev-parse", "HEAD"), records: [] }).problem, /vendor\/sub is a binary file, a large file, or a submodule/);
|
|
166
169
|
});
|
|
167
170
|
|
|
168
171
|
test("a lane that runs out of time closes", (t) => {
|
|
169
172
|
const root = repo(t);
|
|
170
173
|
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
171
|
-
assert.match(editLane({ root, base: BASE,
|
|
172
|
-
assert.match(mergeLane({ root,
|
|
174
|
+
assert.match(editLane({ root, base: BASE, protectedBranches: [], rel: "src/a.ts", toolName: "Edit", input: {}, budgetMs: 0 }).problem, /budget of the lane/);
|
|
175
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: [], budgetMs: 0 }).problem, /budget of the lane/);
|
|
173
176
|
});
|
|
174
177
|
|
|
175
178
|
test("a Write over a file counts the lines it replaces", (t) => {
|
|
176
179
|
const root = repo(t);
|
|
177
|
-
const write = editLane({ root, base: BASE,
|
|
180
|
+
const write = editLane({ root, base: BASE, protectedBranches: [], rel: "src/a.ts", toolName: "Write", input: { content: lines(11) } });
|
|
178
181
|
assert.match(write.problem, /21 of 20 lines/);
|
|
179
182
|
});
|
|
180
183
|
|
|
181
184
|
test("a head with no commit past the base, the head of a protected branch, or a branch an implementer was sent to stays out of the lane", (t) => {
|
|
182
185
|
const root = repo(t);
|
|
183
186
|
const fork = git(root, "rev-parse", "HEAD");
|
|
184
|
-
assert.match(mergeLane({ root,
|
|
187
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha: fork, records: [] }).problem, /has no commit past the PR base/);
|
|
185
188
|
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
186
|
-
assert.match(mergeLane({ root,
|
|
189
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), protectedBranches: ["feat/1-x"], sha, records: [] }).problem, /head of the protected branch feat\/1-x/);
|
|
187
190
|
const sent = [{ type: "dispatch", task: true, branch: "feat/1-x", head: fork }];
|
|
188
|
-
assert.match(mergeLane({ root,
|
|
191
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: sent }).problem, /an implementer worked on the branch/);
|
|
189
192
|
});
|
|
190
193
|
|
|
191
194
|
test("a Write over a tracked binary has no size the lane can judge", (t) => {
|
|
192
195
|
const root = repo(t);
|
|
193
196
|
commit(root, "src/lib.dll", Buffer.from([0, 1, 2, 3]));
|
|
194
|
-
const write = editLane({ root, base: BASE,
|
|
197
|
+
const write = editLane({ root, base: BASE, protectedBranches: [], rel: "src/lib.dll", toolName: "Write", input: { content: "x" } });
|
|
195
198
|
assert.match(write.problem, /src\/lib\.dll is a binary file/);
|
|
196
199
|
});
|
|
200
|
+
|
|
201
|
+
const withDirect = (direct) => ({ dispatch: {}, direct });
|
|
202
|
+
|
|
203
|
+
test("the lane judges with the limits of the base, not the limits of the checkout", (t) => {
|
|
204
|
+
const root = repo(t, withDirect({ maxLines: 5 }));
|
|
205
|
+
const big = { old_string: "a\n".repeat(3), new_string: "b\n".repeat(3) };
|
|
206
|
+
const fit = edit(root, "src/a.ts", big);
|
|
207
|
+
assert.match(fit.problem, /changes 6 of 5 lines in 1 of 2 files/);
|
|
208
|
+
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "x\n".repeat(5)));
|
|
209
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, /changes 7 of 5 lines/);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("a base that sets reviewPaths holds a merge to its review, though the checkout drops the setting", (t) => {
|
|
213
|
+
const root = repo(t, withDirect({ reviewPaths: ["**"] }));
|
|
214
|
+
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
215
|
+
writeFileSync(path.join(root, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {} } }));
|
|
216
|
+
const loose = mergeLane({ root, baseOid: oidOf(root), sha, records: [] });
|
|
217
|
+
assert.match(loose.problem, /src\/a\.ts matches swarm\.direct\.reviewPaths/);
|
|
218
|
+
const approved = [{ type: "verdict", kind: "task", verdict: "APPROVED", sha }];
|
|
219
|
+
const fit = mergeLane({ root, baseOid: oidOf(root), sha, records: approved });
|
|
220
|
+
assert.equal(fit.problem, null);
|
|
221
|
+
assert.equal(fit.review.kind, "task");
|
|
222
|
+
assert.equal(fit.review.sha, sha);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("a base with no qc.config.json closes the lane", (t) => {
|
|
226
|
+
const root = repo(t, undefined, null);
|
|
227
|
+
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
228
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, /git cannot read qc\.config\.json at the PR base/);
|
|
229
|
+
assert.match(edit(root, "src/a.ts", { old_string: "a", new_string: "b" }).problem, /git cannot read qc\.config\.json at origin\/main/);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("a base config that is not JSON, or holds a wrong swarm or swarm.direct, closes the lane and names the cause", (t) => {
|
|
233
|
+
for (const [config, cause] of [
|
|
234
|
+
["{ not json", /qc\.config\.json at (?:origin\/main|the PR base) is not JSON/],
|
|
235
|
+
["null", /qc\.config\.json at (?:origin\/main|the PR base) is not a JSON object/],
|
|
236
|
+
[JSON.stringify({ swarm: null }), /swarm in qc\.config\.json at (?:origin\/main|the PR base) must be an object, got null/],
|
|
237
|
+
[JSON.stringify({ swarm: [] }), /swarm in qc\.config\.json at (?:origin\/main|the PR base) must be an object, got \[\]/],
|
|
238
|
+
[JSON.stringify({ swarm: { direct: { maxLines: 0 } } }), /swarm\.direct\.maxLines in qc\.config\.json must be a positive whole number/],
|
|
239
|
+
]) {
|
|
240
|
+
const root = repo(t, undefined, config);
|
|
241
|
+
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
242
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, cause);
|
|
243
|
+
assert.match(edit(root, "src/a.ts", { old_string: "a", new_string: "b" }).problem, cause);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("a base that sets swarm.direct to false closes the lane", (t) => {
|
|
248
|
+
const root = repo(t, withDirect(false));
|
|
249
|
+
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
250
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, /swarm\.direct is false at the PR base/);
|
|
251
|
+
assert.match(edit(root, "src/a.ts", { old_string: "a", new_string: "b" }).problem, /swarm\.direct is false at origin\/main/);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("a branch that changes qc.config.json leaves the lane, and so does a pending edit of it", (t) => {
|
|
255
|
+
const root = repo(t);
|
|
256
|
+
const sha = commit(root, "qc.config.json", JSON.stringify({ swarm: { dispatch: {}, direct: { maxLines: 500 } } }));
|
|
257
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, /qc\.config\.json changes on the branch, so it runs the subagent workflow/);
|
|
258
|
+
assert.match(edit(root, "src/a.ts", { old_string: "a", new_string: "b" }).problem, /qc\.config\.json changes on the branch, so it runs the subagent workflow/);
|
|
259
|
+
const clean = repo(t);
|
|
260
|
+
assert.match(edit(clean, "qc.config.json", { old_string: "{", new_string: "{ " }).problem, /qc\.config\.json changes on the branch/);
|
|
261
|
+
assert.match(editLane({ root: clean, base: BASE, protectedBranches: [], rel: "qc.config.json", toolName: "Write", input: { content: "{}" } }).problem, /qc\.config\.json changes on the branch/);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("a config change in a folder below the root does not close the lane", (t) => {
|
|
265
|
+
const root = repo(t);
|
|
266
|
+
const sha = commit(root, "pkg/qc.config.json", "{}\n");
|
|
267
|
+
assert.equal(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, null);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("a merge with no base commit, or a base commit the repository lacks, closes the lane", (t) => {
|
|
271
|
+
const root = repo(t);
|
|
272
|
+
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
273
|
+
assert.match(mergeLane({ root, baseOid: undefined, sha, records: [] }).problem, /no base commit/);
|
|
274
|
+
assert.match(mergeLane({ root, baseOid: "origin/main", sha, records: [] }).problem, /no base commit/);
|
|
275
|
+
assert.match(mergeLane({ root, baseOid: "1".repeat(40), sha, records: [] }).problem, /the PR base commit 111111111111 is not in this repository, so run `git fetch`/);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test("the lane measures the merge from the base commit it is given, not from a local ref", (t) => {
|
|
279
|
+
const root = repo(t, withDirect({ reviewPaths: ["**"] }));
|
|
280
|
+
git(root, "switch", "-q", "-c", "tip", BASE);
|
|
281
|
+
writeFileSync(path.join(root, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {} } }));
|
|
282
|
+
git(root, "commit", "-q", "-am", "loosen");
|
|
283
|
+
git(root, "update-ref", "refs/remotes/origin/main", "HEAD");
|
|
284
|
+
const sha = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
285
|
+
const loose = mergeLane({ root, baseOid: git(root, "rev-parse", BASE), sha, records: [] });
|
|
286
|
+
assert.equal(loose.problem, null, "the local ref is the base here");
|
|
287
|
+
const strict = mergeLane({ root, baseOid: git(root, "rev-parse", `${BASE}~1`), sha, records: [] });
|
|
288
|
+
assert.match(strict.problem, /qc\.config\.json changes on the branch/);
|
|
289
|
+
});
|
|
@@ -11,6 +11,9 @@ const GUARD = fileURLToPath(new URL("./dispatch-guard.mjs", import.meta.url));
|
|
|
11
11
|
const HOOKS = fileURLToPath(new URL("../../../../hooks/hooks.json", import.meta.url));
|
|
12
12
|
|
|
13
13
|
/** A checkout that turns the guard on, one whose swarm section has no dispatch key, one with no config, and a temp folder. */
|
|
14
|
+
// The guard process below runs under Codex, whatever runtime runs the test.
|
|
15
|
+
process.env.QC_RUNTIME = "codex";
|
|
16
|
+
|
|
14
17
|
function workspace(t, dispatch = { maxPromptChars: 80 }) {
|
|
15
18
|
const base = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-dispatch-")));
|
|
16
19
|
t.after(() => rmSync(base, { recursive: true, force: true }));
|
|
@@ -178,6 +181,19 @@ test("the hook runs as its own process and prints its refusal as JSON", (t) => {
|
|
|
178
181
|
assert.match(reasonOf(JSON.parse(result.stdout)) ?? "", /names no model/);
|
|
179
182
|
});
|
|
180
183
|
|
|
184
|
+
test("a hook process under Claude Code sees only CLAUDE_PROJECT_DIR, and still refuses a role dispatch with no model", (t) => {
|
|
185
|
+
const ws = workspace(t);
|
|
186
|
+
const { QC_RUNTIME, CLAUDECODE, ...inherited } = process.env;
|
|
187
|
+
const env = Object.fromEntries(Object.entries(inherited).filter(([key]) => !key.startsWith("CODEX_")));
|
|
188
|
+
const result = spawnSync(process.execPath, [GUARD], {
|
|
189
|
+
input: JSON.stringify(agentCall(ws.on, implementer)),
|
|
190
|
+
env: { ...env, CLAUDE_PROJECT_DIR: ws.on, TEMP: ws.tmp, TMP: ws.tmp, TMPDIR: ws.tmp },
|
|
191
|
+
encoding: "utf8",
|
|
192
|
+
});
|
|
193
|
+
assert.equal(result.status, 0, result.stderr);
|
|
194
|
+
assert.match(reasonOf(JSON.parse(result.stdout)) ?? "", /inherits the session's model.*Pass `model` with sonnet/);
|
|
195
|
+
});
|
|
196
|
+
|
|
181
197
|
test("hooks.json runs the guard on Agent, SubagentStart and SubagentStop", () => {
|
|
182
198
|
const { hooks } = JSON.parse(readFileSync(HOOKS, "utf8"));
|
|
183
199
|
const matchersOf = (entries) =>
|
|
@@ -10,11 +10,21 @@ export const REMINDER =
|
|
|
10
10
|
"Subagent workflow (swarm.dispatch in qc.config.json): run a plan with superpowers:subagent-driven-development. " +
|
|
11
11
|
"Dispatch architecture:sdd-planner to write a plan, architecture:sdd-implementer for one task, and " +
|
|
12
12
|
"architecture:sdd-reviewer to review it; before merge, dispatch architecture:sdd-branch-reviewer to review the " +
|
|
13
|
-
"whole branch.
|
|
13
|
+
"whole branch. " +
|
|
14
14
|
"Run one implementer at a time: a hook refuses a second while one runs. Name a model on any other dispatch, and " +
|
|
15
15
|
"pass each brief as a file path. Name the worktree on a prompt line `Worktree: <path>`. A reviewer starts with " +
|
|
16
16
|
"`VERDICT: <APPROVED|CHANGES_REQUIRED> <sha>`, and a merge passes `--match-head-commit <sha>`.";
|
|
17
17
|
|
|
18
|
+
const ROLES = ["sdd-planner", "sdd-implementer", "sdd-reviewer", "sdd-branch-reviewer"];
|
|
19
|
+
|
|
20
|
+
/** One added line naming each role's models for the session's runtime, so a dispatch names the right one. */
|
|
21
|
+
export function modelsLine({ models, runtime }) {
|
|
22
|
+
const roles = ROLES.map((role) => `${role} ${(models[`architecture:${role}`] ?? models[role] ?? models["*"] ?? ["the session's model"]).join(" or ")}`);
|
|
23
|
+
const how = runtime === "claude" ? "Name that model on each dispatch: the guard refuses a role dispatch with no model." : "A role with no named model inherits the session's.";
|
|
24
|
+
const where = runtime ? `the ${runtime} runtime` : "an unknown runtime (set QC_RUNTIME to claude or codex)";
|
|
25
|
+
return ` Models for ${where}: ${roles.join(", ")}. ${how}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
18
28
|
const context = (eventName, text) => ({ hookSpecificOutput: { hookEventName: eventName, additionalContext: text } });
|
|
19
29
|
|
|
20
30
|
/** One added line for a limit above 1, which overrides the one-at-a-time rule of the note. */
|
|
@@ -33,10 +43,17 @@ function directLine(cwd) {
|
|
|
33
43
|
}
|
|
34
44
|
return direct
|
|
35
45
|
? ` A fix of at most ${direct.maxLines} changed lines in ${direct.maxFiles} ${direct.maxFiles === 1 ? "file" : "files"} needs no subagent: edit it in the main session on a branch, ` +
|
|
36
|
-
|
|
46
|
+
`and merge it with \`--match-head-commit <sha>\`${reviewClause(direct.reviewPaths)} The guards measure the branch against its base (swarm.direct).`
|
|
37
47
|
: "";
|
|
38
48
|
}
|
|
39
49
|
|
|
50
|
+
/** The end of the merge sentence: no review, or the one APPROVED review that `swarm.direct.reviewPaths` asks for. */
|
|
51
|
+
function reviewClause(reviewPaths) {
|
|
52
|
+
if (reviewPaths.length === 0) return " and no review.";
|
|
53
|
+
if (reviewPaths.includes("**")) return ". Every direct merge needs one APPROVED review of the head (sdd-reviewer).";
|
|
54
|
+
return ". A merge needs one APPROVED review of the head (sdd-reviewer) when a changed path matches swarm.direct.reviewPaths.";
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
/** The explore tools, or null when the section is off, names none, or does not parse. */
|
|
41
58
|
function exploreToolsAt(cwd) {
|
|
42
59
|
let settings;
|
|
@@ -74,7 +91,7 @@ function decideSessionStart(call) {
|
|
|
74
91
|
}
|
|
75
92
|
const explore = exploreLine(cwd);
|
|
76
93
|
if (!dispatch) return explore === "" ? null : context("SessionStart", explore.trim());
|
|
77
|
-
return context("SessionStart", `${REMINDER}${slotsLine(dispatch)}${directLine(cwd)}${explore}`);
|
|
94
|
+
return context("SessionStart", `${REMINDER}${modelsLine(dispatch)}${slotsLine(dispatch)}${directLine(cwd)}${explore}`);
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
/** @returns the hook output, or null when there is nothing to add for this event. */
|
|
@@ -5,7 +5,12 @@ import os from "node:os";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { test } from "node:test";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
-
import {
|
|
8
|
+
import { runtimeModels } from "../config.mjs";
|
|
9
|
+
import { REMINDER, decide, modelsLine } from "./dispatch-reminder.mjs";
|
|
10
|
+
|
|
11
|
+
// The checkouts below run under Codex, whatever runtime runs the test.
|
|
12
|
+
process.env.QC_RUNTIME = "codex";
|
|
13
|
+
const BASE = `${REMINDER}${modelsLine({ models: runtimeModels.codex, runtime: "codex" })}`;
|
|
9
14
|
|
|
10
15
|
const NOTE = fileURLToPath(new URL("./dispatch-reminder.mjs", import.meta.url));
|
|
11
16
|
const HOOKS = fileURLToPath(new URL("../../../../hooks/hooks.json", import.meta.url));
|
|
@@ -37,11 +42,11 @@ test("with the section on, every start adds the note, a compaction included", (t
|
|
|
37
42
|
for (const source of ["startup", "resume", "clear", "compact", "fork"]) {
|
|
38
43
|
const output = decide(start(on, source));
|
|
39
44
|
assert.equal(output.hookSpecificOutput.hookEventName, "SessionStart", source);
|
|
40
|
-
assert.equal(output.hookSpecificOutput.additionalContext,
|
|
45
|
+
assert.equal(output.hookSpecificOutput.additionalContext, BASE, source);
|
|
41
46
|
}
|
|
42
47
|
});
|
|
43
48
|
|
|
44
|
-
test("the note names the workflow, the four types,
|
|
49
|
+
test("the note names the workflow, the four types, and the one-implementer rule, in a short text", () => {
|
|
45
50
|
for (const word of [
|
|
46
51
|
"superpowers:subagent-driven-development",
|
|
47
52
|
"architecture:sdd-planner",
|
|
@@ -49,8 +54,6 @@ test("the note names the workflow, the four types, the model tiers, and the one-
|
|
|
49
54
|
"architecture:sdd-reviewer",
|
|
50
55
|
"architecture:sdd-branch-reviewer",
|
|
51
56
|
"one implementer at a time",
|
|
52
|
-
"gpt-6.1-sol",
|
|
53
|
-
"high reasoning effort",
|
|
54
57
|
"Worktree: <path>",
|
|
55
58
|
"VERDICT: <APPROVED|CHANGES_REQUIRED> <sha>",
|
|
56
59
|
"--match-head-commit <sha>",
|
|
@@ -65,18 +68,18 @@ test("with swarm.explore also on, the note names its tools", (t) => {
|
|
|
65
68
|
{ swarm: { dispatch: {}, explore: { tools: [{ name: "CocoIndex", use: "u", how: "h" }, { name: "GitNexus", use: "u", how: "h" }] } } },
|
|
66
69
|
]);
|
|
67
70
|
const text = decide(start(on, "startup")).hookSpecificOutput.additionalContext;
|
|
68
|
-
assert.ok(text.startsWith(
|
|
71
|
+
assert.ok(text.startsWith(BASE));
|
|
69
72
|
assert.match(text, /CocoIndex, GitNexus/);
|
|
70
73
|
assert.match(text, /optional/i);
|
|
71
74
|
});
|
|
72
75
|
|
|
73
|
-
test("with swarm.explore off, or naming no tools, the note is exactly
|
|
76
|
+
test("with swarm.explore off, or naming no tools, the note is exactly the base note", (t) => {
|
|
74
77
|
const [off, empty] = checkouts(t, [
|
|
75
78
|
{ swarm: { direct: false, dispatch: {} } },
|
|
76
79
|
{ swarm: { direct: false, dispatch: {}, explore: { tools: [] } } },
|
|
77
80
|
]);
|
|
78
|
-
assert.equal(decide(start(off, "startup")).hookSpecificOutput.additionalContext,
|
|
79
|
-
assert.equal(decide(start(empty, "startup")).hookSpecificOutput.additionalContext,
|
|
81
|
+
assert.equal(decide(start(off, "startup")).hookSpecificOutput.additionalContext, BASE);
|
|
82
|
+
assert.equal(decide(start(empty, "startup")).hookSpecificOutput.additionalContext, BASE);
|
|
80
83
|
});
|
|
81
84
|
|
|
82
85
|
test("with swarm.explore on and swarm.dispatch off, the SessionStart note still names the tools", (t) => {
|
|
@@ -113,7 +116,7 @@ test("the hook runs as its own process and prints the note as JSON, or nothing w
|
|
|
113
116
|
const run = (cwd) => spawnSync(process.execPath, [NOTE], { input: JSON.stringify(start(cwd, "startup")), encoding: "utf8" });
|
|
114
117
|
const noted = run(on);
|
|
115
118
|
assert.equal(noted.status, 0, noted.stderr);
|
|
116
|
-
assert.equal(JSON.parse(noted.stdout).hookSpecificOutput.additionalContext,
|
|
119
|
+
assert.equal(JSON.parse(noted.stdout).hookSpecificOutput.additionalContext, BASE);
|
|
117
120
|
const silent = run(plain);
|
|
118
121
|
assert.equal(silent.status, 0, silent.stderr);
|
|
119
122
|
assert.equal(silent.stdout, "");
|
|
@@ -138,15 +141,15 @@ test("hooks.json also runs the note on SubagentStart, all matchers, beside the e
|
|
|
138
141
|
);
|
|
139
142
|
});
|
|
140
143
|
|
|
141
|
-
test("a limit above 1 adds one line stating it, and a limit of 1 leaves the note as
|
|
144
|
+
test("a limit above 1 adds one line stating it, and a limit of 1 leaves the note as the base note", (t) => {
|
|
142
145
|
const [three, one] = checkouts(t, [
|
|
143
146
|
{ swarm: { dispatch: { implementerSlots: 3 } } },
|
|
144
147
|
{ swarm: { direct: false, dispatch: { implementerSlots: 1 } } },
|
|
145
148
|
]);
|
|
146
149
|
const text = decide(start(three, "startup")).hookSpecificOutput.additionalContext;
|
|
147
|
-
assert.ok(text.startsWith(
|
|
150
|
+
assert.ok(text.startsWith(BASE));
|
|
148
151
|
assert.match(text, /up to 3 implementers at once/);
|
|
149
|
-
assert.equal(decide(start(one, "startup")).hookSpecificOutput.additionalContext,
|
|
152
|
+
assert.equal(decide(start(one, "startup")).hookSpecificOutput.additionalContext, BASE);
|
|
150
153
|
});
|
|
151
154
|
|
|
152
155
|
test("SubagentStart gives each tool's use and command, in config order, since a plugin agent carries no MCP tool", (t) => {
|
|
@@ -172,16 +175,16 @@ test("SubagentStart gives each tool's use and command, in config order, since a
|
|
|
172
175
|
);
|
|
173
176
|
});
|
|
174
177
|
|
|
175
|
-
test("a swarm.explore section that does not parse leaves SubagentStart silent and the session note as
|
|
178
|
+
test("a swarm.explore section that does not parse leaves SubagentStart silent and the session note as the base note", (t) => {
|
|
176
179
|
const [bad] = checkouts(t, [{ swarm: { direct: false, dispatch: {}, explore: { tools: "CocoIndex" } } }]);
|
|
177
180
|
assert.equal(decide(subagentStart(bad)), null);
|
|
178
|
-
assert.equal(decide(start(bad, "startup")).hookSpecificOutput.additionalContext,
|
|
181
|
+
assert.equal(decide(start(bad, "startup")).hookSpecificOutput.additionalContext, BASE);
|
|
179
182
|
});
|
|
180
183
|
|
|
181
|
-
test("with the direct lane on by default, the note names its limits after
|
|
184
|
+
test("with the direct lane on by default, the note names its limits after the base note", (t) => {
|
|
182
185
|
const [lane, custom] = checkouts(t, [{ swarm: { dispatch: {} } }, { swarm: { dispatch: {}, direct: { maxLines: 5, maxFiles: 1 } } }]);
|
|
183
186
|
const text = decide(start(lane, "startup")).hookSpecificOutput.additionalContext;
|
|
184
|
-
assert.ok(text.startsWith(
|
|
187
|
+
assert.ok(text.startsWith(BASE));
|
|
185
188
|
assert.match(text, /at most 20 changed lines in 2 files needs no subagent/);
|
|
186
189
|
assert.match(text, /--match-head-commit <sha>/);
|
|
187
190
|
assert.match(decide(start(custom, "startup")).hookSpecificOutput.additionalContext, /at most 5 changed lines in 1 file needs/);
|
|
@@ -190,6 +193,58 @@ test("with the direct lane on by default, the note names its limits after REMIND
|
|
|
190
193
|
test("a swarm.direct section that does not parse names the key and leaves the rest of the note", (t) => {
|
|
191
194
|
const [bad] = checkouts(t, [{ swarm: { dispatch: {}, direct: { maxLines: 0 } } }]);
|
|
192
195
|
const text = decide(start(bad, "startup")).hookSpecificOutput.additionalContext;
|
|
193
|
-
assert.ok(text.startsWith(
|
|
196
|
+
assert.ok(text.startsWith(BASE));
|
|
194
197
|
assert.match(text, /Direct lane is off: swarm\.direct\.maxLines/);
|
|
195
198
|
});
|
|
199
|
+
|
|
200
|
+
test("the direct lane note says when a merge needs a review", (t) => {
|
|
201
|
+
const [none, some, every] = checkouts(t, [
|
|
202
|
+
{ swarm: { dispatch: {} } },
|
|
203
|
+
{ swarm: { dispatch: {}, direct: { reviewPaths: ["src/**", "api/**"] } } },
|
|
204
|
+
{ swarm: { dispatch: {}, direct: { reviewPaths: ["**"] } } },
|
|
205
|
+
]);
|
|
206
|
+
const noteOf = (dir) => decide(start(dir, "startup")).hookSpecificOutput.additionalContext;
|
|
207
|
+
assert.match(noteOf(none), /--match-head-commit <sha>` and no review\./);
|
|
208
|
+
const partial = noteOf(some);
|
|
209
|
+
assert.match(partial, /--match-head-commit <sha>`\. A merge needs one APPROVED review of the head \(sdd-reviewer\) when a changed path matches swarm\.direct\.reviewPaths\./);
|
|
210
|
+
assert.doesNotMatch(partial, /no review/);
|
|
211
|
+
const all = noteOf(every);
|
|
212
|
+
assert.match(all, /--match-head-commit <sha>`\. Every direct merge needs one APPROVED review of the head \(sdd-reviewer\)\./);
|
|
213
|
+
assert.doesNotMatch(all, /no review/);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("the direct lane note reads the limits at worktree.base, and the checkout's when that read fails", (t) => {
|
|
217
|
+
const [dir] = checkouts(t, [{ swarm: { dispatch: {}, direct: { maxLines: 5, reviewPaths: ["**"] } } }]);
|
|
218
|
+
const git = (...args) => execFileSync("git", args, { cwd: dir, stdio: "pipe" });
|
|
219
|
+
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"]]) git("config", key, value);
|
|
220
|
+
git("add", ".");
|
|
221
|
+
git("commit", "-q", "-m", "init");
|
|
222
|
+
git("update-ref", "refs/remotes/origin/main", "HEAD");
|
|
223
|
+
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, direct: { maxLines: 500 } } }));
|
|
224
|
+
const noteOf = () => decide(start(dir, "startup")).hookSpecificOutput.additionalContext;
|
|
225
|
+
const text = noteOf();
|
|
226
|
+
assert.match(text, /at most 5 changed lines in 2 files needs no subagent/);
|
|
227
|
+
assert.match(text, /Every direct merge needs one APPROVED review/);
|
|
228
|
+
git("update-ref", "-d", "refs/remotes/origin/main");
|
|
229
|
+
assert.match(noteOf(), /at most 500 changed lines in 2 files needs no subagent/);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("a local swarm.direct of false turns the direct lane note off, whatever the base says", (t) => {
|
|
233
|
+
const [dir] = checkouts(t, [{ swarm: { dispatch: {} } }]);
|
|
234
|
+
const git = (...args) => execFileSync("git", args, { cwd: dir, stdio: "pipe" });
|
|
235
|
+
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"]]) git("config", key, value);
|
|
236
|
+
git("add", ".");
|
|
237
|
+
git("commit", "-q", "-m", "init");
|
|
238
|
+
git("update-ref", "refs/remotes/origin/main", "HEAD");
|
|
239
|
+
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, direct: false } }));
|
|
240
|
+
assert.doesNotMatch(decide(start(dir, "startup")).hookSpecificOutput.additionalContext, /needs no subagent/);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test("the models line names each role's models for the runtime, and how to dispatch it", () => {
|
|
244
|
+
const claude = modelsLine({ models: runtimeModels.claude, runtime: "claude" });
|
|
245
|
+
assert.match(claude, /the claude runtime: sdd-planner opus, sdd-implementer sonnet, sdd-reviewer sonnet, sdd-branch-reviewer opus\./);
|
|
246
|
+
assert.match(claude, /Name that model on each dispatch/);
|
|
247
|
+
const codex = modelsLine({ models: runtimeModels.codex, runtime: "codex" });
|
|
248
|
+
assert.match(codex, /the codex runtime: sdd-planner gpt-6\.1-sol, sdd-implementer gpt-6\.1-sol/);
|
|
249
|
+
assert.match(modelsLine({ models: {}, runtime: null }), /unknown runtime \(set QC_RUNTIME to claude or codex\): sdd-planner the session's model/);
|
|
250
|
+
});
|
package/src/cli/dispatch.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { CONFIG_FILE, MODEL_FAMILIES, dispatchDefaults, exploreDefaults, load, merge } from "../config.mjs";
|
|
6
|
+
import { CONFIG_FILE, MODEL_FAMILIES, dispatchDefaults, exploreDefaults, load, merge, runtimeModels } from "../config.mjs";
|
|
7
7
|
import { checkoutRootOf } from "./checkout-root.mjs";
|
|
8
8
|
|
|
9
9
|
const KEY = "swarm.dispatch";
|
|
@@ -34,17 +34,31 @@ export function familyOf(model) {
|
|
|
34
34
|
return MODEL_FAMILIES.find((family) => !family.startsWith("gpt-") && lower.includes(family)) ?? null;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/** The SDD role types, whose definitions say `model: inherit`. */
|
|
38
|
+
const ROLE_TYPES = Object.keys(runtimeModels.claude).filter((type) => type !== WILDCARD_TYPE);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The runtime that runs this session, from a positive signal: `QC_RUNTIME`, then Claude Code's `CLAUDECODE`
|
|
42
|
+
* or `CLAUDE_PROJECT_DIR`, then any `CODEX_` variable. Null when none is set, or when `QC_RUNTIME` names no
|
|
43
|
+
* runtime the kit knows. Claude Code sets `CLAUDECODE` in its shells, but a hook process gets only
|
|
44
|
+
* `CLAUDE_PROJECT_DIR`.
|
|
45
|
+
*/
|
|
46
|
+
export function runtimeOf(env = process.env) {
|
|
47
|
+
const named = typeof env.QC_RUNTIME === "string" ? env.QC_RUNTIME.trim().toLowerCase() : "";
|
|
48
|
+
if (named !== "") return Object.hasOwn(runtimeModels, named) ? named : null;
|
|
49
|
+
if (env.CLAUDECODE === "1" || (env.CLAUDE_PROJECT_DIR ?? "") !== "") return "claude";
|
|
50
|
+
return Object.keys(env).some((key) => key.startsWith("CODEX_")) ? "codex" : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
37
53
|
/** @returns the dispatch settings, or null when the section is absent; throws naming the key a repository got wrong. */
|
|
38
|
-
export function dispatchSettings(swarm = {}) {
|
|
54
|
+
export function dispatchSettings(swarm = {}, runtime = runtimeOf()) {
|
|
39
55
|
const raw = swarm.dispatch;
|
|
40
56
|
if (raw === undefined || raw === null || raw === false) return null;
|
|
41
57
|
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
42
58
|
throw new Error(`${KEY} in qc.config.json must be an object, got ${JSON.stringify(raw)}`);
|
|
43
59
|
}
|
|
44
|
-
const {
|
|
45
|
-
|
|
46
|
-
raw,
|
|
47
|
-
);
|
|
60
|
+
const defaults = { ...dispatchDefaults, models: (runtime && runtimeModels[runtime]) ?? {} };
|
|
61
|
+
const { allowedTypes, implementerTypes, maxPromptChars, slotMinutes, implementerSlots, models } = merge(defaults, raw);
|
|
48
62
|
if (!isNameList(allowedTypes)) throw wrong("allowedTypes", allowedTypes, "a list of agent types");
|
|
49
63
|
if (!isNameList(implementerTypes)) throw wrong("implementerTypes", implementerTypes, "a list of agent types");
|
|
50
64
|
if (!Number.isInteger(maxPromptChars) || maxPromptChars < 1) {
|
|
@@ -55,14 +69,14 @@ export function dispatchSettings(swarm = {}) {
|
|
|
55
69
|
throw wrong("implementerSlots", implementerSlots, "a positive whole number");
|
|
56
70
|
}
|
|
57
71
|
checkModels(models);
|
|
58
|
-
return { allowedTypes, implementerTypes, maxPromptChars, slotMinutes, implementerSlots, models };
|
|
72
|
+
return { allowedTypes, implementerTypes, maxPromptChars, slotMinutes, implementerSlots, models, runtime };
|
|
59
73
|
}
|
|
60
74
|
|
|
61
75
|
/** @returns the settings of the checkout that holds `cwd`, or null when it has no config or no section. */
|
|
62
|
-
export function dispatchSettingsAt(cwd) {
|
|
76
|
+
export function dispatchSettingsAt(cwd, runtime = runtimeOf()) {
|
|
63
77
|
const root = checkoutRootOf(cwd);
|
|
64
78
|
if (!root || !existsSync(path.join(root, CONFIG_FILE))) return null;
|
|
65
|
-
return dispatchSettings(load(root).swarm);
|
|
79
|
+
return dispatchSettings(load(root).swarm, runtime);
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
const isToolEntry = (entry) =>
|
|
@@ -143,9 +157,22 @@ function tierRefusal(type, model, families) {
|
|
|
143
157
|
);
|
|
144
158
|
}
|
|
145
159
|
|
|
160
|
+
const runtimeRefusal = (type) =>
|
|
161
|
+
`Dispatch guard: the session's runtime is unknown, so ${KEY}.models lists no model for ${type}. ` +
|
|
162
|
+
"Set QC_RUNTIME to claude or codex, or list the type in swarm.dispatch.models in qc.config.json.";
|
|
163
|
+
|
|
164
|
+
/** Under Claude Code a role's definition inherits the session's model, so the dispatch names the role's tier. */
|
|
165
|
+
function inheritRefusal(type, families) {
|
|
166
|
+
return (
|
|
167
|
+
`Dispatch guard: ${type} inherits the session's model unless the dispatch names one. ` +
|
|
168
|
+
`Pass \`model\` with ${families.join(" or ")}, the tier of this role.`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
146
172
|
/** @returns the reason a named model breaks its type's tier, or null when it fits. */
|
|
147
173
|
function tierRefusalFor(type, model, settings) {
|
|
148
174
|
const families = settings.models[type] ?? settings.models[WILDCARD_TYPE];
|
|
175
|
+
if (!families) return runtimeRefusal(type);
|
|
149
176
|
const family = familyOf(model);
|
|
150
177
|
if (family && families.includes(family)) return null;
|
|
151
178
|
return tierRefusal(type, model, families);
|
|
@@ -157,6 +184,9 @@ export function dispatchRefusal(input, settings) {
|
|
|
157
184
|
const model = typeof input.model === "string" ? input.model.trim() : "";
|
|
158
185
|
const allowed = settings.allowedTypes.includes(type);
|
|
159
186
|
if (!allowed && (type === FORK || model === "")) return modelRefusal(type, settings);
|
|
187
|
+
if (model === "" && settings.runtime === "claude" && ROLE_TYPES.includes(type) && Object.hasOwn(settings.models, type)) {
|
|
188
|
+
return inheritRefusal(type, settings.models[type]);
|
|
189
|
+
}
|
|
160
190
|
if (model !== "" && type !== FORK) {
|
|
161
191
|
const refusal = tierRefusalFor(type, model, settings);
|
|
162
192
|
if (refusal) return refusal;
|
|
@@ -174,8 +204,8 @@ export function dispatchNote(input, settings) {
|
|
|
174
204
|
if (MODEL_FAMILIES.includes(model.toLowerCase())) return null;
|
|
175
205
|
return (
|
|
176
206
|
`Dispatch note: ${type} sets its own model, and "${model}" is a full model id. Requests to different models share no prompt cache, ` +
|
|
177
|
-
`so this dispatch pays the type's shared first-call prefix again when
|
|
178
|
-
"
|
|
207
|
+
`so this dispatch pays the type's shared first-call prefix again when other dispatches of the type use another id. ` +
|
|
208
|
+
"Name the bare family, such as `sonnet`, to share one cache with them."
|
|
179
209
|
);
|
|
180
210
|
}
|
|
181
211
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { strict as assert } from "node:assert";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
-
import { defaults, dispatchDefaults, merge } from "../config.mjs";
|
|
4
|
-
import { dispatchNote, dispatchRefusal, dispatchSettings, exploreSettings, exploreToolLines, familyOf, isImplementer, slotRefusal, typeOf } from "./dispatch.mjs";
|
|
3
|
+
import { defaults, dispatchDefaults, merge, runtimeModels } from "../config.mjs";
|
|
4
|
+
import { dispatchNote, dispatchRefusal, dispatchSettings, exploreSettings, exploreToolLines, familyOf, isImplementer, runtimeOf, slotRefusal, typeOf } from "./dispatch.mjs";
|
|
5
|
+
|
|
6
|
+
// The settings below default to Codex, whatever runtime runs the test.
|
|
7
|
+
process.env.QC_RUNTIME = "codex";
|
|
5
8
|
|
|
6
9
|
test("a swarm section with no dispatch key keeps the guard off", () => {
|
|
7
10
|
assert.equal(dispatchSettings({}), null);
|
|
@@ -11,7 +14,8 @@ test("a swarm section with no dispatch key keeps the guard off", () => {
|
|
|
11
14
|
});
|
|
12
15
|
|
|
13
16
|
test("an empty dispatch section turns the guard on with every default", () => {
|
|
14
|
-
|
|
17
|
+
const expected = { ...dispatchDefaults, models: runtimeModels.codex, runtime: "codex" };
|
|
18
|
+
assert.deepEqual(dispatchSettings(merge(defaults, { swarm: { dispatch: {} } }).swarm), expected);
|
|
15
19
|
});
|
|
16
20
|
|
|
17
21
|
test("a list in the section replaces its default rather than extending it", () => {
|
|
@@ -45,7 +49,7 @@ test("a wrong value names its key", () => {
|
|
|
45
49
|
test("a repository's models merges key by key with the defaults", () => {
|
|
46
50
|
const settings = dispatchSettings({ dispatch: { models: { "architecture:sdd-planner": ["sonnet"] } } });
|
|
47
51
|
assert.deepEqual(settings.models["architecture:sdd-planner"], ["sonnet"]);
|
|
48
|
-
assert.deepEqual(settings.models["architecture:sdd-implementer"],
|
|
52
|
+
assert.deepEqual(settings.models["architecture:sdd-implementer"], runtimeModels.codex["architecture:sdd-implementer"]);
|
|
49
53
|
});
|
|
50
54
|
|
|
51
55
|
test("familyOf finds the first known family a model string contains, lower-cased", () => {
|
|
@@ -238,3 +242,41 @@ test("an excerptChars the repository sets must be smaller than maxOutputChars",
|
|
|
238
242
|
assert.throws(() => exploreSettings({ explore: { maxOutputChars: 20, excerptChars } }), /swarm\.explore\.excerptChars .*smaller than maxOutputChars \(20\)/);
|
|
239
243
|
}
|
|
240
244
|
});
|
|
245
|
+
|
|
246
|
+
test("the runtime comes from QC_RUNTIME, then CLAUDECODE or CLAUDE_PROJECT_DIR, then a CODEX_ variable, and is null with no signal", () => {
|
|
247
|
+
assert.equal(runtimeOf({ QC_RUNTIME: "Codex", CLAUDECODE: "1" }), "codex");
|
|
248
|
+
assert.equal(runtimeOf({ QC_RUNTIME: "other", CLAUDECODE: "1" }), null);
|
|
249
|
+
assert.equal(runtimeOf({ CLAUDECODE: "1", CODEX_HOME: "x" }), "claude");
|
|
250
|
+
assert.equal(runtimeOf({ CLAUDE_PROJECT_DIR: "/repo", CODEX_HOME: "x" }), "claude");
|
|
251
|
+
assert.equal(runtimeOf({ CLAUDE_PROJECT_DIR: "", CODEX_HOME: "x" }), "codex");
|
|
252
|
+
assert.equal(runtimeOf({ CODEX_HOME: "x" }), "codex");
|
|
253
|
+
assert.equal(runtimeOf({}), null);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("under Claude Code the no-model refusal covers only the four roles, not another type a repository lists", () => {
|
|
257
|
+
const settings = dispatchSettings({ dispatch: { allowedTypes: [...dispatchDefaults.allowedTypes, "Explore"], models: { Explore: ["haiku"] } } }, "claude");
|
|
258
|
+
assert.equal(dispatchRefusal({ subagent_type: "Explore", prompt: "p" }, settings), null);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("under Claude Code each role takes its Claude tier, and a role dispatch must name it", () => {
|
|
262
|
+
const settings = dispatchSettings({ dispatch: {} }, "claude");
|
|
263
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "sonnet", prompt: "p" }, settings), null);
|
|
264
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-branch-reviewer", model: "opus", prompt: "p" }, settings), null);
|
|
265
|
+
assert.match(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "gpt-6.1-sol" }, settings) ?? "", /may run only on sonnet/);
|
|
266
|
+
assert.match(dispatchRefusal({ subagent_type: "architecture:sdd-planner", prompt: "p" }, settings) ?? "", /inherits the session's model.*Pass `model` with opus/);
|
|
267
|
+
assert.equal(dispatchRefusal({ subagent_type: "Explore", model: "haiku", prompt: "p" }, settings), null);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("under Codex a role dispatch with no model inherits the session's GPT model", () => {
|
|
271
|
+
const settings = dispatchSettings({ dispatch: {} }, "codex");
|
|
272
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", prompt: "p" }, settings), null);
|
|
273
|
+
assert.match(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "sonnet" }, settings) ?? "", /may run only on gpt-6\.1-sol/);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test("an unknown runtime refuses a named model with no listed families, and a repository's models still apply", () => {
|
|
277
|
+
const unknown = dispatchSettings({ dispatch: {} }, null);
|
|
278
|
+
assert.match(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "sonnet" }, unknown) ?? "", /runtime is unknown.*QC_RUNTIME/);
|
|
279
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", prompt: "p" }, unknown), null);
|
|
280
|
+
const listed = dispatchSettings({ dispatch: { models: { "architecture:sdd-implementer": ["sonnet"] } } }, null);
|
|
281
|
+
assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "sonnet", prompt: "p" }, listed), null);
|
|
282
|
+
});
|
package/src/cli/merge-guard.mjs
CHANGED
|
@@ -60,33 +60,35 @@ export function mergeVerdict(merges, records, kind, lane = null) {
|
|
|
60
60
|
/** @returns the reason the first of `merges` may not run, or null when each pins an approved head. */
|
|
61
61
|
export const mergeRefusal = (merges, records, kind, lane = null) => mergeVerdict(merges, records, kind, lane).refusal;
|
|
62
62
|
|
|
63
|
-
/** The base
|
|
63
|
+
/** The base the PR of `merge` merges into, as gh reads it before the merge: `{ name, oid }`, or null. `oid` is null when gh names none. */
|
|
64
64
|
function prBaseOf(merge, cwd, gh, timeoutMs) {
|
|
65
|
-
const args = ["pr", "view", ...(merge.selector ? [merge.selector] : []), ...(merge.repo ? ["-R", merge.repo] : []), "--json", "baseRefName"];
|
|
65
|
+
const args = ["pr", "view", ...(merge.selector ? [merge.selector] : []), ...(merge.repo ? ["-R", merge.repo] : []), "--json", "baseRefName,baseRefOid"];
|
|
66
66
|
try {
|
|
67
|
-
|
|
67
|
+
const pr = JSON.parse(gh(args, { cwd, env: merge.env, timeoutMs }) ?? "null");
|
|
68
|
+
return typeof pr?.baseRefName === "string" ? { name: pr.baseRefName, oid: pr.baseRefOid ?? null } : null;
|
|
68
69
|
} catch {
|
|
69
70
|
return null;
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
/**
|
|
74
|
-
* The direct lane of one workflow, as `mergeVerdict` asks it. Null while `swarm.direct` is false; a wrong
|
|
75
|
-
* names itself. The lane
|
|
76
|
-
* The merges of one call share one time budget.
|
|
75
|
+
* The direct lane of one workflow, as `mergeVerdict` asks it. Null while the checkout's `swarm.direct` is false; a wrong
|
|
76
|
+
* value names itself. The lane judges against the base commit that gh names for the PR, so no local ref decides.
|
|
77
|
+
* A PR into a branch other than `worktree.base` stays out of it. The merges of one call share one time budget.
|
|
77
78
|
*/
|
|
78
79
|
function laneOf(workflow, records, cwd, gh) {
|
|
79
80
|
const { direct, directProblem, base } = workflow;
|
|
80
81
|
if (!direct) return directProblem ? () => ({ problem: directProblem }) : null;
|
|
81
82
|
const deadline = Date.now() + LANE_BUDGET_MS;
|
|
82
83
|
return (merge) => {
|
|
83
|
-
const fit = mergeLane({ root: workflow.root, base, direct, protectedBranches: workflow.protectedBranches, sha: merge.sha, records, budgetMs: deadline - Date.now() });
|
|
84
|
-
if (fit.problem !== null) return fit;
|
|
85
84
|
const left = deadline - Date.now();
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
if (
|
|
89
|
-
|
|
85
|
+
const pr = left > 0 ? prBaseOf(merge, cwd, gh, left) : null;
|
|
86
|
+
if (pr === null) return { problem: "gh cannot read the base branch of the PR within the time budget of the lane" };
|
|
87
|
+
if (pr.name !== base && `origin/${pr.name}` !== base) return { problem: `the PR merges into ${pr.name}, and the lane measures against ${base}` };
|
|
88
|
+
const fit = mergeLane({ root: workflow.root, baseOid: pr.oid, protectedBranches: workflow.protectedBranches, sha: merge.sha, records, budgetMs: deadline - Date.now() });
|
|
89
|
+
if (fit.problem !== null) return fit;
|
|
90
|
+
const reviewed = fit.review ? `the APPROVED ${fit.review.kind} review of ${fit.review.sha}` : "no review";
|
|
91
|
+
return { problem: null, note: `Merge guard: ${merge.sha} merges through the direct lane, with ${sizeLine(fit.size, fit.direct)} and ${reviewed}.` };
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -346,38 +346,42 @@ test("with swarm.dispatch off, a merge whose command failed after GitHub merged
|
|
|
346
346
|
assert.deepEqual(readLedger(ws.ledgerOf(ws.off)).map(({ type, pr }) => ({ type, pr })), [{ type: "merge", pr: 60 }]);
|
|
347
347
|
});
|
|
348
348
|
|
|
349
|
-
/** A checkout with the checks on, `origin/main` at its first commit, and a small fix on `feat/1-x`. */
|
|
350
|
-
function laneRepo(t, config = { swarm: { dispatch: {} } }) {
|
|
349
|
+
/** A checkout with the checks on, `origin/main` at its first commit, and a small fix on `feat/1-x`. `tracked: false` keeps the config out of that commit. */
|
|
350
|
+
function laneRepo(t, config = { swarm: { dispatch: {} } }, { tracked = true } = {}) {
|
|
351
351
|
const dir = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-merge-lane-")));
|
|
352
352
|
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
353
353
|
const git = (...args) => execFileSync("git", args, { cwd: dir, stdio: "pipe", encoding: "utf8" }).trim();
|
|
354
354
|
git("init", "-q", "-b", "main");
|
|
355
355
|
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"]]) git("config", key, value);
|
|
356
|
-
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify(config));
|
|
356
|
+
if (tracked) writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify(config));
|
|
357
357
|
writeFileSync(path.join(dir, "a.ts"), "one\ntwo\n");
|
|
358
358
|
git("add", ".");
|
|
359
359
|
git("commit", "-q", "-m", "init");
|
|
360
|
+
if (!tracked) writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify(config));
|
|
360
361
|
git("update-ref", "refs/remotes/origin/main", "HEAD");
|
|
361
362
|
git("switch", "-q", "-c", "feat/1-x");
|
|
362
363
|
writeFileSync(path.join(dir, "a.ts"), "one\n2\n");
|
|
363
364
|
git("commit", "-q", "-am", "fix");
|
|
364
|
-
return { dir, head: git("rev-parse", "HEAD"), ledger: path.join(dir, ".git", "qc", "ledger.jsonl") };
|
|
365
|
+
return { dir, head: git("rev-parse", "HEAD"), base: git("rev-parse", "origin/main"), ledger: path.join(dir, ".git", "qc", "ledger.jsonl") };
|
|
365
366
|
}
|
|
366
367
|
|
|
368
|
+
/** What `gh pr view --json baseRefName,baseRefOid` answers for a PR into `main` whose base commit is `oid`. */
|
|
369
|
+
const prView = (oid, name = "main") => JSON.stringify({ baseRefName: name, baseRefOid: oid });
|
|
370
|
+
|
|
367
371
|
test("a small head with no review merges through the direct lane, with a note", (t) => {
|
|
368
|
-
const { dir, head } = laneRepo(t);
|
|
369
|
-
const { gh, calls } = fakeGh(
|
|
372
|
+
const { dir, head, base } = laneRepo(t);
|
|
373
|
+
const { gh, calls } = fakeGh(prView(base));
|
|
370
374
|
const output = decide(shell(dir, `gh pr merge 7 --squash --match-head-commit ${head}`), { gh });
|
|
371
375
|
assert.equal(denied(output), null);
|
|
372
|
-
assert.deepEqual(calls[0].args, ["pr", "view", "7", "--json", "baseRefName"]);
|
|
376
|
+
assert.deepEqual(calls[0].args, ["pr", "view", "7", "--json", "baseRefName,baseRefOid"]);
|
|
373
377
|
assert.match(output?.hookSpecificOutput?.additionalContext ?? "", /merges through the direct lane, with 2 of 20 lines in 1 of 2 files and no review/);
|
|
374
378
|
assert.match(denied(decide(shell(dir, "gh pr merge 7 --squash"))) ?? "", /--match-head-commit <sha>/);
|
|
375
379
|
});
|
|
376
380
|
|
|
377
381
|
test("a review that asked for changes keeps a small head out of the direct lane", (t) => {
|
|
378
|
-
const { dir, head, ledger } = laneRepo(t);
|
|
382
|
+
const { dir, head, base, ledger } = laneRepo(t);
|
|
379
383
|
appendRecord(ledger, verdict("task", "CHANGES_REQUIRED", head));
|
|
380
|
-
const reason = denied(decide(shell(dir, `gh pr merge 7 --squash --match-head-commit ${head}`))) ?? "";
|
|
384
|
+
const reason = denied(decide(shell(dir, `gh pr merge 7 --squash --match-head-commit ${head}`), { gh: fakeGh(prView(base)).gh })) ?? "";
|
|
381
385
|
assert.match(reason, /no APPROVED branch review/);
|
|
382
386
|
assert.match(reason, /The direct lane of swarm\.direct does not apply: the latest review on the branch, of .*, is CHANGES_REQUIRED/);
|
|
383
387
|
});
|
|
@@ -397,8 +401,93 @@ test("a wrong swarm.direct closes the lane and keeps the merge guard on", (t) =>
|
|
|
397
401
|
});
|
|
398
402
|
|
|
399
403
|
test("a PR into another base, or a PR whose base gh cannot read, stays out of the direct lane", (t) => {
|
|
400
|
-
const { dir, head } = laneRepo(t);
|
|
404
|
+
const { dir, head, base } = laneRepo(t);
|
|
401
405
|
const merge = shell(dir, `gh pr merge 7 --squash --match-head-commit ${head}`);
|
|
402
|
-
assert.match(denied(decide(merge, { gh: fakeGh(
|
|
406
|
+
assert.match(denied(decide(merge, { gh: fakeGh(prView(base, "release/2.0")).gh })) ?? "", /the PR merges into release\/2\.0, and the lane measures against origin\/main/);
|
|
403
407
|
assert.match(denied(decide(merge, { gh: fakeGh(null).gh })) ?? "", /gh cannot read the base branch of the PR/);
|
|
404
408
|
});
|
|
409
|
+
|
|
410
|
+
test("a head that a review path covers merges through the lane after an APPROVED review, and the note names that review", (t) => {
|
|
411
|
+
const { dir, head, base, ledger } = laneRepo(t, { swarm: { dispatch: {}, direct: { reviewPaths: ["**"] } } });
|
|
412
|
+
const merge = shell(dir, `gh pr merge 7 --squash --match-head-commit ${head}`);
|
|
413
|
+
const gh = fakeGh(prView(base)).gh;
|
|
414
|
+
assert.match(denied(decide(merge, { gh })) ?? "", /a\.ts matches swarm\.direct\.reviewPaths/);
|
|
415
|
+
appendRecord(ledger, verdict("task", "APPROVED", head));
|
|
416
|
+
const output = decide(merge, { gh });
|
|
417
|
+
assert.equal(denied(output), null);
|
|
418
|
+
const note = output?.hookSpecificOutput?.additionalContext ?? "";
|
|
419
|
+
assert.match(note, new RegExp(`merges through the direct lane, with 2 of 20 lines in 1 of 2 files and the APPROVED task review of ${head}\.`));
|
|
420
|
+
assert.doesNotMatch(note, /no review/);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test("the merge guard judges with the limits of the base, so a loosened checkout does not open the lane", (t) => {
|
|
424
|
+
const { dir, head, base } = laneRepo(t, { swarm: { dispatch: {}, direct: { reviewPaths: ["**"] } } });
|
|
425
|
+
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {} } }));
|
|
426
|
+
const reason = denied(decide(shell(dir, `gh pr merge 7 --squash --match-head-commit ${head}`), { gh: fakeGh(prView(base)).gh })) ?? "";
|
|
427
|
+
assert.match(reason, /does not apply: a\.ts matches swarm\.direct\.reviewPaths/);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test("a head that changes qc.config.json stays out of the direct lane", (t) => {
|
|
431
|
+
const { dir, base } = laneRepo(t);
|
|
432
|
+
const git = (...args) => execFileSync("git", args, { cwd: dir, stdio: "pipe", encoding: "utf8" }).trim();
|
|
433
|
+
git("switch", "-q", "-c", "feat/2-y", "origin/main");
|
|
434
|
+
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, direct: { maxLines: 500 } } }));
|
|
435
|
+
git("commit", "-q", "-am", "loosen");
|
|
436
|
+
const merge = shell(dir, `gh pr merge 7 --squash --match-head-commit ${git("rev-parse", "HEAD")}`);
|
|
437
|
+
const reason = denied(decide(merge, { gh: fakeGh(prView(base)).gh })) ?? "";
|
|
438
|
+
assert.match(reason, /does not apply: qc\.config\.json changes on the branch, so it runs the subagent workflow/);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test("a base that holds no qc.config.json keeps the head out of the direct lane", (t) => {
|
|
442
|
+
const { dir, head, base } = laneRepo(t, { swarm: { dispatch: {} } }, { tracked: false });
|
|
443
|
+
const reason = denied(decide(shell(dir, `gh pr merge 7 --squash --match-head-commit ${head}`), { gh: fakeGh(prView(base)).gh })) ?? "";
|
|
444
|
+
assert.match(reason, /does not apply: git cannot read qc\.config\.json at the PR base/);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
test("the note states the size against the limits of the base, not the checkout", (t) => {
|
|
448
|
+
const { dir, head, base } = laneRepo(t, { swarm: { dispatch: {}, direct: { maxLines: 5 } } });
|
|
449
|
+
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, direct: { maxLines: 500 } } }));
|
|
450
|
+
const output = decide(shell(dir, `gh pr merge 7 --squash --match-head-commit ${head}`), { gh: fakeGh(prView(base)).gh });
|
|
451
|
+
assert.match(output?.hookSpecificOutput?.additionalContext ?? "", /with 2 of 5 lines in 1 of 2 files and no review/);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const gitIn = (dir, ...args) => execFileSync("git", args, { cwd: dir, stdio: "pipe", encoding: "utf8" }).trim();
|
|
455
|
+
const merge7 = (dir, head) => shell(dir, `gh pr merge 7 --squash --match-head-commit ${head}`);
|
|
456
|
+
|
|
457
|
+
test("a loosening commit on the local base ref, absent from the PR base commit, does not open the lane", (t) => {
|
|
458
|
+
const strict = { swarm: { dispatch: {}, direct: { reviewPaths: ["**"] } }, worktree: { base: "main" } };
|
|
459
|
+
const { dir, base } = laneRepo(t, strict);
|
|
460
|
+
gitIn(dir, "switch", "-q", "main");
|
|
461
|
+
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {} }, worktree: { base: "main" } }));
|
|
462
|
+
gitIn(dir, "commit", "-q", "-am", "loosen");
|
|
463
|
+
gitIn(dir, "switch", "-q", "-c", "fix/2-y");
|
|
464
|
+
writeFileSync(path.join(dir, "a.ts"), "one\nthree\n");
|
|
465
|
+
gitIn(dir, "commit", "-q", "-am", "one-line fix");
|
|
466
|
+
const reason = denied(decide(merge7(dir, gitIn(dir, "rev-parse", "HEAD")), { gh: fakeGh(prView(base)).gh })) ?? "";
|
|
467
|
+
assert.match(reason, /does not apply: qc\.config\.json changes on the branch, so it runs the subagent workflow/);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
test("a stale local base ref does not hide the review paths that the PR base commit sets", (t) => {
|
|
471
|
+
const { dir } = laneRepo(t);
|
|
472
|
+
gitIn(dir, "switch", "-q", "-c", "newbase", "origin/main");
|
|
473
|
+
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, direct: { reviewPaths: ["**"] } } }));
|
|
474
|
+
gitIn(dir, "commit", "-q", "-am", "require reviews");
|
|
475
|
+
const newBase = gitIn(dir, "rev-parse", "HEAD");
|
|
476
|
+
gitIn(dir, "switch", "-q", "feat/1-x");
|
|
477
|
+
gitIn(dir, "rebase", "-q", newBase);
|
|
478
|
+
const head = gitIn(dir, "rev-parse", "HEAD");
|
|
479
|
+
const reason = denied(decide(merge7(dir, head), { gh: fakeGh(prView(newBase)).gh })) ?? "";
|
|
480
|
+
assert.match(reason, /does not apply: a\.ts matches swarm\.direct\.reviewPaths/);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
test("a PR base commit that the local repository lacks closes the lane and says to fetch", (t) => {
|
|
484
|
+
const { dir, head } = laneRepo(t);
|
|
485
|
+
const reason = denied(decide(merge7(dir, head), { gh: fakeGh(prView("1234567890123456789012345678901234567890")).gh })) ?? "";
|
|
486
|
+
assert.match(reason, /does not apply: the PR base commit 1234567890\w* is not in this repository, so run `git fetch`/);
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
test("a gh answer with no base commit closes the lane", (t) => {
|
|
490
|
+
const { dir, head } = laneRepo(t);
|
|
491
|
+
const reason = denied(decide(merge7(dir, head), { gh: fakeGh(JSON.stringify({ baseRefName: "main" })).gh })) ?? "";
|
|
492
|
+
assert.match(reason, /does not apply: gh returned no base commit for the PR/);
|
|
493
|
+
});
|
|
@@ -3,8 +3,7 @@ import { readFileSync, readdirSync } from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { test } from "node:test";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { dispatchDefaults } from "../config.mjs";
|
|
7
|
-
import { familyOf } from "./dispatch.mjs";
|
|
6
|
+
import { dispatchDefaults, runtimeModels } from "../config.mjs";
|
|
8
7
|
import { REMINDER } from "./dispatch-reminder.mjs";
|
|
9
8
|
|
|
10
9
|
const AGENTS = fileURLToPath(new URL("../../../../agents/", import.meta.url));
|
|
@@ -41,10 +40,10 @@ const ALWAYS_PRESENT = ["Read", "Bash"];
|
|
|
41
40
|
const READ_TOOLS = ["Read", "Grep", "Glob", "Bash", "PowerShell"];
|
|
42
41
|
const EDIT_TOOLS = [...READ_TOOLS, "Skill", "Edit", "Write"];
|
|
43
42
|
const EXPECTED = {
|
|
44
|
-
"sdd-implementer": { model: "
|
|
45
|
-
"sdd-planner": { model: "
|
|
46
|
-
"sdd-reviewer": { model: "
|
|
47
|
-
"sdd-branch-reviewer": { model: "
|
|
43
|
+
"sdd-implementer": { model: "inherit", effort: "high", tools: EDIT_TOOLS },
|
|
44
|
+
"sdd-planner": { model: "inherit", effort: "high", tools: EDIT_TOOLS },
|
|
45
|
+
"sdd-reviewer": { model: "inherit", effort: "high", tools: READ_TOOLS },
|
|
46
|
+
"sdd-branch-reviewer": { model: "inherit", effort: "high", tools: READ_TOOLS },
|
|
48
47
|
};
|
|
49
48
|
// Fields Claude Code ignores on a plugin agent, and the one that drops a repository's CLAUDE.md and rules.
|
|
50
49
|
const FORBIDDEN_FIELDS = ["disallowedTools", "hooks", "mcpServers", "permissionMode", "omitClaudeMd"];
|
|
@@ -81,7 +80,7 @@ function readmeToolsOf(markdown) {
|
|
|
81
80
|
|
|
82
81
|
const frontOf = (name) => frontmatterOf(path.join(AGENTS, `${name}.md`));
|
|
83
82
|
|
|
84
|
-
test("each subagent type
|
|
83
|
+
test("each subagent type inherits the session model, has a model in every runtime, and keeps its effort and tool list", () => {
|
|
85
84
|
assert.deepEqual(
|
|
86
85
|
readdirSync(AGENTS).sort(),
|
|
87
86
|
Object.keys(EXPECTED).map((name) => `${name}.md`).sort(),
|
|
@@ -94,9 +93,10 @@ test("each subagent type runs on its model tier at its effort, with its own tool
|
|
|
94
93
|
assert.equal(front.effort, want.effort, name);
|
|
95
94
|
assert.ok(front.description.length > 0, name);
|
|
96
95
|
assert.deepEqual(listOf(front.tools), want.tools, name);
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
for (const models of Object.values(runtimeModels)) {
|
|
97
|
+
assert.ok(models[name]?.length > 0, name);
|
|
98
|
+
assert.deepEqual(models[`${PLUGIN}:${name}`], models[name], name);
|
|
99
|
+
}
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
|
|
@@ -10,6 +10,9 @@ import { gitOut } from "./git-read.mjs";
|
|
|
10
10
|
import { continuedStop, gateRefusal, judgeTask, noResumeReason, recordDispatch, worktreeNamed } from "./task-gate.mjs";
|
|
11
11
|
import { sessionDirOf } from "./workflow-settings.mjs";
|
|
12
12
|
|
|
13
|
+
// The guard processes below run under Codex, whatever runtime runs the test.
|
|
14
|
+
process.env.QC_RUNTIME = "codex";
|
|
15
|
+
|
|
13
16
|
const git = (cwd, ...args) => execFileSync("git", args, { cwd, stdio: "pipe", encoding: "utf8" }).trim();
|
|
14
17
|
|
|
15
18
|
/** A checkout with the checks on and a linked worktree on feat/1-x, one without the checks, and a temp folder. */
|
package/src/config.mjs
CHANGED
|
@@ -493,21 +493,29 @@ export const dispatchDefaults = {
|
|
|
493
493
|
slotMinutes: 60,
|
|
494
494
|
// How many implementers run at once in a session. Each needs paths of its own, and a worktree.
|
|
495
495
|
implementerSlots: 1,
|
|
496
|
-
// The model families each type's named `model` may carry
|
|
497
|
-
models: {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
496
|
+
// The model families each type's named `model` may carry, over the runtime's own in `runtimeModels`.
|
|
497
|
+
models: {},
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
const roleModels = (planning, working, other) => ({
|
|
501
|
+
"sdd-planner": planning,
|
|
502
|
+
"architecture:sdd-planner": planning,
|
|
503
|
+
"sdd-branch-reviewer": planning,
|
|
504
|
+
"architecture:sdd-branch-reviewer": planning,
|
|
505
|
+
"sdd-implementer": working,
|
|
506
|
+
"architecture:sdd-implementer": working,
|
|
507
|
+
"sdd-reviewer": working,
|
|
508
|
+
"architecture:sdd-reviewer": working,
|
|
509
|
+
"*": other,
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
// The default `swarm.dispatch.models` of each runtime that can run a session. A runtime calls only its own models.
|
|
513
|
+
export const runtimeModels = {
|
|
514
|
+
claude: roleModels(["opus"], ["sonnet"], ["sonnet", "haiku"]),
|
|
515
|
+
codex: roleModels(["gpt-6.1-sol"], ["gpt-6.1-sol"], ["gpt-6.1-sol"]),
|
|
508
516
|
};
|
|
509
517
|
|
|
510
|
-
// GPT uses an exact model id; Claude
|
|
518
|
+
// GPT uses an exact model id; a Claude family matches any model id that contains it.
|
|
511
519
|
export const MODEL_FAMILIES = ["gpt-6.1-sol", "opus", "sonnet", "haiku", "fable"];
|
|
512
520
|
|
|
513
521
|
// What each key of `swarm.explore` means when a repository omits it. The kit names no tool; a
|
|
@@ -67,9 +67,9 @@ recorded.
|
|
|
67
67
|
| An implementer reports the failing test before the passing one | `report-stop.mjs` |
|
|
68
68
|
| A task is reviewed before the next implementer starts on its branch | `dispatch-guard.mjs`, through `task-gate.mjs` |
|
|
69
69
|
| A fix round goes back to the implementer that wrote the task | `dispatch-guard.mjs`, through `task-gate.mjs` |
|
|
70
|
-
| A merge pins the head that an APPROVED review named, or a head inside the direct lane | `merge-guard.mjs`, through `direct-lane.mjs` |
|
|
70
|
+
| A merge pins the head that an APPROVED review named, or a head inside the direct lane, whose limits come from the commit the PR merges into | `merge-guard.mjs`, through `direct-lane.mjs` |
|
|
71
71
|
| An issue that a merge names is closed, or has a comment after the merge | `issue-gate.mjs`, on `Stop` |
|
|
72
|
-
| The controller edits only its own paths, or a small fix inside the direct lane | `controller-guard.mjs`, through `direct-lane.mjs` |
|
|
72
|
+
| The controller edits only its own paths, or a small fix inside the direct lane, whose limits come from the base | `controller-guard.mjs`, through `direct-lane.mjs` |
|
|
73
73
|
| A plan task names its files, a test step, and a commit step, within the budget | `qc plan-check`, and `plan-stop.mjs` |
|
|
74
74
|
|
|
75
75
|
## Worktrees — QC-015
|