architecture-harness 0.20.1 → 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/dispatch-guard.test.mjs +16 -0
- package/src/cli/dispatch-reminder.mjs +12 -2
- package/src/cli/dispatch-reminder.test.mjs +30 -18
- package/src/cli/dispatch.mjs +41 -11
- package/src/cli/dispatch.test.mjs +46 -4
- 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/package.json
CHANGED
|
@@ -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. */
|
|
@@ -81,7 +91,7 @@ function decideSessionStart(call) {
|
|
|
81
91
|
}
|
|
82
92
|
const explore = exploreLine(cwd);
|
|
83
93
|
if (!dispatch) return explore === "" ? null : context("SessionStart", explore.trim());
|
|
84
|
-
return context("SessionStart", `${REMINDER}${slotsLine(dispatch)}${directLine(cwd)}${explore}`);
|
|
94
|
+
return context("SessionStart", `${REMINDER}${modelsLine(dispatch)}${slotsLine(dispatch)}${directLine(cwd)}${explore}`);
|
|
85
95
|
}
|
|
86
96
|
|
|
87
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,7 +193,7 @@ 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
|
});
|
|
196
199
|
|
|
@@ -236,3 +239,12 @@ test("a local swarm.direct of false turns the direct lane note off, whatever the
|
|
|
236
239
|
writeFileSync(path.join(dir, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {}, direct: false } }));
|
|
237
240
|
assert.doesNotMatch(decide(start(dir, "startup")).hookSpecificOutput.additionalContext, /needs no subagent/);
|
|
238
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
|
+
});
|
|
@@ -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
|