architecture-harness 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -22
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/branch-sync.mjs +126 -0
- package/src/cli/branch-sync.test.mjs +428 -0
- package/src/cli/budget-guard.mjs +74 -5
- package/src/cli/budget-guard.test.mjs +185 -2
- package/src/cli/budget-report.mjs +85 -0
- package/src/cli/budget-report.test.mjs +173 -0
- package/src/cli/budget.mjs +8 -5
- package/src/cli/check-commands.mjs +123 -11
- package/src/cli/check-commands.test.mjs +360 -6
- package/src/cli/check-feature-switches.test.mjs +110 -0
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check-verdict.mjs +46 -0
- package/src/cli/check-verdict.test.mjs +32 -0
- package/src/cli/check.mjs +137 -4
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/checkpoint.mjs +143 -0
- package/src/cli/checkpoint.test.mjs +146 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +304 -0
- package/src/cli/ci-failures.test.mjs +615 -0
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +25 -29
- package/src/cli/ci-state.test.mjs +174 -2
- package/src/cli/ci-template.test.mjs +86 -0
- package/src/cli/claude-core.test.mjs +37 -0
- package/src/cli/codex-implement.mjs +580 -47
- package/src/cli/codex-implement.test.mjs +1946 -29
- package/src/cli/codex-limit.mjs +85 -0
- package/src/cli/codex-limit.test.mjs +179 -0
- package/src/cli/codex-reset.mjs +78 -0
- package/src/cli/codex-reset.test.mjs +192 -0
- package/src/cli/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +219 -0
- package/src/cli/commit-guard.test.mjs +809 -0
- package/src/cli/context-budgets.mjs +47 -0
- package/src/cli/context-budgets.test.mjs +96 -0
- package/src/cli/context-watch.mjs +116 -0
- package/src/cli/context-watch.test.mjs +395 -0
- package/src/cli/contract-history.mjs +1 -1
- package/src/cli/controller-guard.mjs +38 -0
- package/src/cli/controller-guard.test.mjs +66 -2
- package/src/cli/cost-stop.mjs +5 -1
- package/src/cli/cost-stop.test.mjs +26 -0
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/direct-lane.mjs +32 -19
- package/src/cli/direct-lane.test.mjs +21 -3
- package/src/cli/dispatch-guard.mjs +11 -0
- package/src/cli/dispatch-guard.test.mjs +145 -10
- package/src/cli/dispatch-reminder.mjs +23 -10
- package/src/cli/dispatch-reminder.test.mjs +63 -11
- package/src/cli/dispatch-route.mjs +54 -0
- package/src/cli/dispatch-route.test.mjs +101 -0
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/e2e-affected.mjs +15 -0
- package/src/cli/e2e-affected.test.mjs +73 -0
- package/src/cli/fleet.mjs +180 -0
- package/src/cli/fleet.test.mjs +213 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +96 -31
- package/src/cli/gh-merge-command.test.mjs +74 -0
- package/src/cli/gh-run.mjs +64 -3
- package/src/cli/gh-run.test.mjs +66 -1
- package/src/cli/git-hooks.test.mjs +25 -3
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +143 -40
- package/src/cli/integrate.test.mjs +347 -1
- package/src/cli/integration-lane.mjs +62 -0
- package/src/cli/integration-lane.test.mjs +213 -0
- package/src/cli/ledger.mjs +4 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +70 -0
- package/src/cli/lint-changed.mjs +59 -10
- package/src/cli/lint-changed.test.mjs +112 -1
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +234 -62
- package/src/cli/merge-guard.test.mjs +768 -39
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/output-redaction.mjs +26 -0
- package/src/cli/output-redaction.test.mjs +117 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/pause.mjs +93 -0
- package/src/cli/pause.test.mjs +109 -0
- package/src/cli/plan-check.mjs +84 -12
- package/src/cli/plan-check.test.mjs +152 -2
- package/src/cli/plan-stop.mjs +7 -4
- package/src/cli/plan-stop.test.mjs +87 -0
- package/src/cli/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/plugin-skills.test.mjs +25 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/promotion-branch.mjs +2 -0
- package/src/cli/qc.mjs +160 -27
- package/src/cli/qc.test.mjs +93 -0
- package/src/cli/report-stop.mjs +5 -0
- package/src/cli/report-stop.test.mjs +23 -1
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/review-gate.mjs +24 -6
- package/src/cli/review-gate.test.mjs +116 -0
- package/src/cli/review-promotion.mjs +107 -0
- package/src/cli/review-promotion.test.mjs +251 -0
- package/src/cli/role-budget.mjs +50 -0
- package/src/cli/role-budget.test.mjs +91 -0
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/secret-patterns.mjs +16 -0
- package/src/cli/secret-patterns.test.mjs +73 -0
- package/src/cli/setup-block.mjs +24 -0
- package/src/cli/setup-block.test.mjs +96 -0
- package/src/cli/setup-checks.mjs +65 -0
- package/src/cli/setup-checks.test.mjs +158 -0
- package/src/cli/setup-compaction.mjs +55 -0
- package/src/cli/setup-compaction.test.mjs +115 -0
- package/src/cli/setup-skills.mjs +65 -0
- package/src/cli/setup-skills.test.mjs +171 -0
- package/src/cli/setup.mjs +107 -0
- package/src/cli/setup.test.mjs +275 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/spawn-command.mjs +47 -0
- package/src/cli/spawn-command.test.mjs +64 -0
- package/src/cli/task-gate-review.test.mjs +21 -2
- package/src/cli/task-gate.mjs +25 -12
- package/src/cli/task-gate.test.mjs +43 -5
- package/src/cli/tokens.mjs +46 -3
- package/src/cli/tokens.test.mjs +103 -3
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/transcript-usage.mjs +27 -0
- package/src/cli/transcript-usage.test.mjs +34 -0
- package/src/cli/user-config-package.mjs +1 -1
- package/src/cli/user-config-toml.mjs +63 -7
- package/src/cli/user-config.mjs +39 -7
- package/src/cli/user-config.test.mjs +238 -5
- package/src/cli/watch-arm.mjs +39 -0
- package/src/cli/watch-arm.test.mjs +87 -0
- package/src/cli/watch.mjs +80 -35
- package/src/cli/watch.test.mjs +233 -27
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +18 -4
- package/src/cli/workflow-settings.mjs +44 -8
- package/src/cli/workflow-settings.test.mjs +124 -1
- package/src/cli/worktree.mjs +14 -1
- package/src/cli/worktree.test.mjs +20 -1
- package/src/config.mjs +174 -7
- package/src/config.test.mjs +327 -5
- package/src/consumer-package.mjs +31 -0
- package/src/consumer-package.test.mjs +54 -0
- package/src/descriptions.mjs +2 -0
- package/src/eslint/index.mjs +12 -0
- package/src/eslint/jsx.mjs +20 -0
- package/src/eslint/preset.mjs +26 -2
- package/src/eslint/preset.test.mjs +104 -2
- package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
- package/src/eslint/rules/no-literal-color.mjs +94 -0
- package/src/eslint/rules/no-static-inline-style.mjs +41 -0
- package/src/eslint/rules/one-component-per-file.mjs +70 -0
- package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +189 -0
- package/src/eslint/ui-regressions.test.mjs +39 -0
- package/src/gates/contract-operations.mjs +3 -3
- package/src/gates/contract-operations.test.mjs +28 -0
- package/src/gates/feature-switches.mjs +19 -0
- package/src/gates/feature-switches.test.mjs +55 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/gates/runtime-imports.test.mjs +114 -0
- package/src/gates/saga-key.test.mjs +1 -1
- package/src/global-skills.mjs +9 -0
- package/src/global-skills.test.mjs +53 -0
- package/src/plugin.test.mjs +3 -2
- package/src/ui/class-sites.mjs +38 -6
- package/src/ui/codemod.mjs +4 -1
- package/src/ui/codemod.test.mjs +52 -0
- package/src/ui/components.mjs +5 -3
- package/src/ui/components.test.mjs +8 -0
- package/src/ui/dupes.test.mjs +18 -0
- package/templates/docs/enforcement.md +12 -2
- package/templates/docs/ui.md +33 -0
- package/templates/githooks/pre-commit +1 -0
- package/templates/githooks/pre-push +11 -2
- package/templates/github/workflows/ci.yml +57 -3
- package/user-config/claude/CLAUDE.core.md +28 -0
- package/user-config/claude/settings.shared.json +41 -1
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -84
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -127
- package/src/cli/throwaway-db.test.mjs +0 -83
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -175
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -40
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -137
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -78
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -106
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -40
- package/src/stack/supervisor.mjs +0 -30
package/src/cli/direct-lane.mjs
CHANGED
|
@@ -10,7 +10,8 @@ import { branchesAt, gitOut, gitOutWithin } from "./git-read.mjs";
|
|
|
10
10
|
import { latestVerdictFor, shaMatches } from "./ledger.mjs";
|
|
11
11
|
|
|
12
12
|
const KEY = "swarm.direct";
|
|
13
|
-
const
|
|
13
|
+
const DEFAULTS = { ...directDefaults, reviewPaths: [".mcp.json", "**/.claude/**", ".github/workflows/**", "hooks/**"] };
|
|
14
|
+
const DIRECT_KEYS = Object.keys(DEFAULTS);
|
|
14
15
|
const KINDS = ["task", "branch"];
|
|
15
16
|
const GITLINK_MODE = "160000";
|
|
16
17
|
const SNIFF_BYTES = 8_000;
|
|
@@ -34,7 +35,7 @@ export function directSettings(swarm = {}) {
|
|
|
34
35
|
}
|
|
35
36
|
const unknown = Object.keys(raw).find((key) => !DIRECT_KEYS.includes(key));
|
|
36
37
|
if (unknown !== undefined) throw new Error(`${KEY}.${unknown} in qc.config.json is not a direct lane setting; the keys are ${DIRECT_KEYS.join(", ")}`);
|
|
37
|
-
const settings = merge(
|
|
38
|
+
const settings = merge(DEFAULTS, raw);
|
|
38
39
|
for (const key of ["maxLines", "maxFiles"]) if (!isCount(settings[key])) throw wrong(key, settings[key], "a positive whole number");
|
|
39
40
|
for (const key of ["excludes", "reviewPaths"]) if (!isGlobList(settings[key])) throw wrong(key, settings[key], "a list of globs");
|
|
40
41
|
return settings;
|
|
@@ -76,7 +77,7 @@ export function pendingLines(toolName, input = {}) {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
/** A `gitOut` that shares one deadline, so the whole lane ends inside the hook's timeout. `late()` says it ran out. */
|
|
79
|
-
function gitBy(budgetMs) {
|
|
80
|
+
export function gitBy(budgetMs) {
|
|
80
81
|
const deadline = Date.now() + budgetMs;
|
|
81
82
|
const read = (cwd, ...args) => {
|
|
82
83
|
const left = deadline - Date.now();
|
|
@@ -86,16 +87,21 @@ function gitBy(budgetMs) {
|
|
|
86
87
|
return read;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
const gitFailed = (git, what) => (git.late?.() ? `git ran past the ${LANE_BUDGET_MS} ms budget of the lane` : what);
|
|
90
|
+
export const gitFailed = (git, what) => (git.late?.() ? `git ran past the ${LANE_BUDGET_MS} ms budget of the lane` : what);
|
|
90
91
|
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
/** The config resource at `base`, read through `git`; returns `{ config }`, with null for an absent file, or `{ problem }`. */
|
|
93
|
+
export function configAtBase(root, base, git, label = base) {
|
|
94
|
+
if (label === PR_BASE) {
|
|
95
|
+
if (typeof base !== "string" || !OBJECT_ID.test(base)) return { problem: "gh returned no base commit for the PR, so the lane cannot tell what the PR merges into" };
|
|
96
|
+
if (git(root, "cat-file", "-e", `${base}^{commit}`) === null) {
|
|
97
|
+
return { problem: gitFailed(git, `the PR base commit ${base.slice(0, 12)} is not in this repository, so run \`git fetch\``) };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const entry = git(root, "ls-tree", base, "--", CONFIG_FILE);
|
|
101
|
+
if (entry === null || git.late?.()) return { problem: gitFailed(git, `git cannot read ${CONFIG_FILE} at ${label}`) };
|
|
102
|
+
if (entry === "") return { config: null };
|
|
97
103
|
const text = git(root, "show", `${base}:${CONFIG_FILE}`);
|
|
98
|
-
if (text === null) return { problem: gitFailed(git, `git cannot read ${CONFIG_FILE} at ${label}`) };
|
|
104
|
+
if (text === null || git.late?.()) return { problem: gitFailed(git, `git cannot read ${CONFIG_FILE} at ${label}`) };
|
|
99
105
|
try {
|
|
100
106
|
const config = JSON.parse(text);
|
|
101
107
|
if (config === null || typeof config !== "object" || Array.isArray(config)) return { problem: `${CONFIG_FILE} at ${label} is not a JSON object` };
|
|
@@ -103,13 +109,24 @@ function directAtBase(root, base, git, label = base) {
|
|
|
103
109
|
if (swarm !== undefined && (swarm === null || typeof swarm !== "object" || Array.isArray(swarm))) {
|
|
104
110
|
return { problem: `swarm in ${CONFIG_FILE} at ${label} must be an object, got ${JSON.stringify(swarm)}` };
|
|
105
111
|
}
|
|
106
|
-
|
|
107
|
-
return direct ? { direct } : { problem: `${KEY} is false at ${label}` };
|
|
112
|
+
return { config };
|
|
108
113
|
} catch (error) {
|
|
109
114
|
return { problem: error instanceof SyntaxError ? `${CONFIG_FILE} at ${label} is not JSON` : error.message };
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
|
|
118
|
+
function directAtBase(root, base, git, label = base) {
|
|
119
|
+
const settings = configAtBase(root, base, git, label);
|
|
120
|
+
if (settings.problem) return settings;
|
|
121
|
+
if (settings.config === null) return { problem: `${CONFIG_FILE} is absent at ${label}` };
|
|
122
|
+
try {
|
|
123
|
+
const direct = directSettings(settings.config.swarm);
|
|
124
|
+
return direct ? { direct } : { problem: `${KEY} is false at ${label}` };
|
|
125
|
+
} catch (error) {
|
|
126
|
+
return { problem: error.message };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
113
130
|
// The checkout also sets `worktree.base` and `swarm.isolation.protectedBranches`, so a branch that edits the file could point `base` at looser settings.
|
|
114
131
|
const touchesConfig = (changes) => [...changes.keys()].some((file) => file.toLowerCase() === CONFIG_FILE);
|
|
115
132
|
const CONFIG_PROBLEM = `${CONFIG_FILE} changes on the branch, so it runs the subagent workflow`;
|
|
@@ -229,16 +246,12 @@ export function editLane({ root, base, protectedBranches, rel, toolName, input,
|
|
|
229
246
|
* APPROVED verdict that a path of `reviewPaths` needed, or null.
|
|
230
247
|
*/
|
|
231
248
|
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" };
|
|
233
249
|
const git = gitBy(budgetMs);
|
|
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
250
|
const settings = directAtBase(root, baseOid, git, PR_BASE);
|
|
240
251
|
if (!settings.direct) return settings;
|
|
241
252
|
const { direct } = settings;
|
|
253
|
+
const fork = git(root, "merge-base", baseOid, sha);
|
|
254
|
+
if (!fork) return { problem: gitFailed(git, `git cannot find the merge base of ${PR_BASE} and ${sha}`) };
|
|
242
255
|
const history = git(root, "rev-list", `${fork}..${sha}`);
|
|
243
256
|
const changes = history === null ? null : changesSince(root, fork, { head: sha, git });
|
|
244
257
|
if (!changes) return { problem: gitFailed(git, `git cannot diff ${sha} against ${PR_BASE}`) };
|
|
@@ -42,7 +42,7 @@ const edit = (root, rel, input) =>
|
|
|
42
42
|
editLane({ root, base: BASE, protectedBranches: ["main"], rel, toolName: "Edit", input });
|
|
43
43
|
|
|
44
44
|
test("the settings fill their defaults, accept false, and name a wrong key", () => {
|
|
45
|
-
assert.deepEqual(directSettings({}), directDefaults);
|
|
45
|
+
assert.deepEqual(directSettings({}), { ...directDefaults, reviewPaths: [".mcp.json", "**/.claude/**", ".github/workflows/**", "hooks/**"] });
|
|
46
46
|
assert.equal(directSettings({ direct: false }), null);
|
|
47
47
|
assert.equal(directSettings({ direct: { maxLines: 5 } }).maxLines, 5);
|
|
48
48
|
assert.throws(() => directSettings({ direct: { maxLines: 0 } }), /swarm\.direct\.maxLines/);
|
|
@@ -127,6 +127,23 @@ test("a head that touches a review path needs one APPROVED review of either kind
|
|
|
127
127
|
assert.equal(mergeLane({ root, baseOid: oidOf(root), sha, records: approved }).problem, null);
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
+
for (const file of [".mcp.json", ".claude/settings.json", "nested/.claude/agents/a.md", ".github/workflows/ci.yml", "hooks/check.mjs"]) {
|
|
131
|
+
test(`the default review paths require approval for ${file}`, (t) => {
|
|
132
|
+
const root = repo(t);
|
|
133
|
+
const sha = commit(root, file, "trust config\n");
|
|
134
|
+
const input = { root, baseOid: oidOf(root), sha };
|
|
135
|
+
assert.match(mergeLane({ ...input, records: [] }).problem, /matches swarm\.direct\.reviewPaths/);
|
|
136
|
+
assert.equal(mergeLane({ ...input, records: [{ type: "verdict", kind: "branch", verdict: "APPROVED", sha }] }).problem, null);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
test("repository review paths replace the defaults, including an empty list", (t) => {
|
|
141
|
+
assert.deepEqual(directSettings({ direct: { reviewPaths: ["src/**"] } }).reviewPaths, ["src/**"]);
|
|
142
|
+
const root = repo(t, { dispatch: {}, direct: { reviewPaths: [] } });
|
|
143
|
+
const sha = commit(root, ".mcp.json", "{}\n");
|
|
144
|
+
assert.equal(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, null);
|
|
145
|
+
});
|
|
146
|
+
|
|
130
147
|
test("a commit after a review that asked for changes stays out of the lane until a review approves it", (t) => {
|
|
131
148
|
const root = repo(t);
|
|
132
149
|
const first = commit(root, "src/a.ts", lines(10).replace("line 3", "line three"));
|
|
@@ -194,6 +211,7 @@ test("a head with no commit past the base, the head of a protected branch, or a
|
|
|
194
211
|
test("a Write over a tracked binary has no size the lane can judge", (t) => {
|
|
195
212
|
const root = repo(t);
|
|
196
213
|
commit(root, "src/lib.dll", Buffer.from([0, 1, 2, 3]));
|
|
214
|
+
git(root, "update-ref", "refs/remotes/origin/main", "HEAD");
|
|
197
215
|
const write = editLane({ root, base: BASE, protectedBranches: [], rel: "src/lib.dll", toolName: "Write", input: { content: "x" } });
|
|
198
216
|
assert.match(write.problem, /src\/lib\.dll is a binary file/);
|
|
199
217
|
});
|
|
@@ -225,8 +243,8 @@ test("a base that sets reviewPaths holds a merge to its review, though the check
|
|
|
225
243
|
test("a base with no qc.config.json closes the lane", (t) => {
|
|
226
244
|
const root = repo(t, undefined, null);
|
|
227
245
|
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, /
|
|
229
|
-
assert.match(edit(root, "src/a.ts", { old_string: "a", new_string: "b" }).problem, /
|
|
246
|
+
assert.match(mergeLane({ root, baseOid: oidOf(root), sha, records: [] }).problem, /qc\.config\.json is absent at the PR base/);
|
|
247
|
+
assert.match(edit(root, "src/a.ts", { old_string: "a", new_string: "b" }).problem, /qc\.config\.json is absent at origin\/main/);
|
|
230
248
|
});
|
|
231
249
|
|
|
232
250
|
test("a base config that is not JSON, or holds a wrong swarm or swarm.direct, closes the lane and names the cause", (t) => {
|
|
@@ -6,8 +6,11 @@ import { existsSync } from "node:fs";
|
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { dispatchNote, dispatchRefusal, dispatchSettingsAt, isImplementer, slotRefusal, typeOf } from "./dispatch.mjs";
|
|
9
|
+
import { codexModelOf, routeRefusal, tagRefusal } from "./dispatch-route.mjs";
|
|
10
|
+
import { limitFileOf, readLimit } from "./codex-limit.mjs";
|
|
9
11
|
import { claimSlot, clearSlots, reclaimSlot, releaseHolder, releaseSlot, slotDirOf } from "./dispatch-slot.mjs";
|
|
10
12
|
import { judgeTask, recordDispatch } from "./task-gate.mjs";
|
|
13
|
+
import { checkpointRefusal } from "./checkpoint.mjs";
|
|
11
14
|
|
|
12
15
|
const output = (fields) => ({ hookSpecificOutput: { hookEventName: "PreToolUse", ...fields } });
|
|
13
16
|
const deny = (reason) => output({ permissionDecision: "deny", permissionDecisionReason: reason });
|
|
@@ -63,6 +66,8 @@ export function decide(call, tmp = os.tmpdir(), now = Date.now(), reads = {}) {
|
|
|
63
66
|
|
|
64
67
|
let settings;
|
|
65
68
|
try {
|
|
69
|
+
const checkpoint = checkpointRefusal(call, now);
|
|
70
|
+
if (checkpoint) return deny(checkpoint);
|
|
66
71
|
settings = dispatchSettingsAt(call.cwd ?? process.cwd());
|
|
67
72
|
} catch (error) {
|
|
68
73
|
// A config typo must not stop every dispatch; the session sees the error and reports it.
|
|
@@ -73,6 +78,12 @@ export function decide(call, tmp = os.tmpdir(), now = Date.now(), reads = {}) {
|
|
|
73
78
|
const input = call.tool_input ?? {};
|
|
74
79
|
const refusal = dispatchRefusal(input, settings);
|
|
75
80
|
if (refusal) return deny(refusal);
|
|
81
|
+
const codexModel = "codexModel" in reads ? reads.codexModel : codexModelOf(process.env);
|
|
82
|
+
const tag = tagRefusal(input, { codexModel });
|
|
83
|
+
if (tag) return deny(tag);
|
|
84
|
+
const limit = readLimit(limitFileOf(process.env, tmp), now);
|
|
85
|
+
const route = routeRefusal(input, settings, limit);
|
|
86
|
+
if (route) return deny(route);
|
|
76
87
|
// The task gate judges before the slot is claimed, so a refused task holds no slot.
|
|
77
88
|
const task = judgeTask(call, tmp, reads);
|
|
78
89
|
if (task.refusal) return deny(task.refusal);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { strict as assert } from "node:assert";
|
|
2
2
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
3
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, utimesSync, writeFileSync } from "node:fs";
|
|
4
4
|
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
8
|
import { decide } from "./dispatch-guard.mjs";
|
|
9
|
+
import { limitFileOf, writeLimit } from "./codex-limit.mjs";
|
|
10
|
+
import { runtimeTagOf } from "./dispatch-route.mjs";
|
|
11
|
+
import { checkpointPathOf } from "./checkpoint.mjs";
|
|
9
12
|
|
|
10
13
|
const GUARD = fileURLToPath(new URL("./dispatch-guard.mjs", import.meta.url));
|
|
11
14
|
const HOOKS = fileURLToPath(new URL("../../../../hooks/hooks.json", import.meta.url));
|
|
@@ -32,10 +35,15 @@ function workspace(t, dispatch = { maxPromptChars: 300 }) {
|
|
|
32
35
|
const identity = ["-c", "user.name=qc", "-c", "user.email=qc@example.com", "-c", "commit.gpgsign=false"];
|
|
33
36
|
execFileSync("git", [...identity, "commit", "-q", "--allow-empty", "-m", "init"], { cwd: on, stdio: "pipe" });
|
|
34
37
|
writeFileSync(path.join(off, "qc.config.json"), JSON.stringify({ swarm: { toolCallBudget: 50 } }));
|
|
38
|
+
for (const root of [on, off]) {
|
|
39
|
+
const file = checkpointPathOf(root, "session-aaaa");
|
|
40
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
41
|
+
writeFileSync(file, "## Goal\n## Rules\n## Tasks\n## Next\n");
|
|
42
|
+
}
|
|
35
43
|
return { on, off, plain, tmp, slots: path.join(tmp, "architecture-kit", "dispatch") };
|
|
36
44
|
}
|
|
37
45
|
|
|
38
|
-
const
|
|
46
|
+
const untaggedCall = (cwd, tool_input, extra = {}) => ({
|
|
39
47
|
session_id: "session-aaaa",
|
|
40
48
|
cwd,
|
|
41
49
|
hook_event_name: "PreToolUse",
|
|
@@ -43,6 +51,10 @@ const agentCall = (cwd, tool_input, extra = {}) => ({
|
|
|
43
51
|
tool_input,
|
|
44
52
|
...extra,
|
|
45
53
|
});
|
|
54
|
+
const agentCall = (cwd, input, extra = {}) => untaggedCall(cwd, {
|
|
55
|
+
...input,
|
|
56
|
+
description: runtimeTagOf(input, { codexModel: null }) + (input.description ?? "work"),
|
|
57
|
+
}, extra);
|
|
46
58
|
const subagentEvent = (cwd, agent_type, hook_event_name = "SubagentStop") => ({
|
|
47
59
|
session_id: "session-aaaa",
|
|
48
60
|
cwd,
|
|
@@ -55,11 +67,65 @@ const reasonOf = (output) =>
|
|
|
55
67
|
const implementer = {
|
|
56
68
|
subagent_type: "architecture:sdd-implementer",
|
|
57
69
|
description: "Task 1",
|
|
58
|
-
prompt: "Brief: brief.md",
|
|
70
|
+
prompt: "Brief: brief.md\nRuntime: claude test",
|
|
59
71
|
};
|
|
60
72
|
/** A reviewer prompt that names the checkout, so the task gate can read its branch and head. */
|
|
61
73
|
const reviewerOf = (ws, subagent_type) => ({ subagent_type, prompt: `Worktree: ${ws.on}` });
|
|
62
74
|
|
|
75
|
+
test("a dispatch with no runtime tag is refused and the refusal quotes the tag", (t) => {
|
|
76
|
+
const ws = workspace(t);
|
|
77
|
+
const tag = runtimeTagOf(implementer, { codexModel: null });
|
|
78
|
+
const reason = reasonOf(decide(untaggedCall(ws.on, implementer), ws.tmp));
|
|
79
|
+
assert.ok(reason?.includes(`"${tag}"`), reason);
|
|
80
|
+
assert.equal(existsSync(ws.slots), false);
|
|
81
|
+
assert.equal(decide(agentCall(ws.on, implementer), ws.tmp), null);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("a codex dispatch whose description says Claude is refused", (t) => {
|
|
85
|
+
const ws = workspace(t);
|
|
86
|
+
const input = { subagent_type: "architecture:codex", model: "gpt-6.1-sol", description: "Claude default \u00b7 work", prompt: "p" };
|
|
87
|
+
const reason = reasonOf(decide(untaggedCall(ws.on, input), ws.tmp, Date.now(), { codexModel: null }));
|
|
88
|
+
assert.ok(reason?.includes('"Codex default \u00b7 "'), reason);
|
|
89
|
+
assert.equal(existsSync(ws.slots), false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("a tagged dispatch passes", (t) => {
|
|
93
|
+
const ws = workspace(t);
|
|
94
|
+
assert.equal(decide(agentCall(ws.on, { model: "gpt-6.1-sol", prompt: "p" }), ws.tmp), null);
|
|
95
|
+
const input = { subagent_type: "codex", model: "gpt-6.1-sol", description: "Codex gpt-6.1-sol \u00b7 work", prompt: "p" };
|
|
96
|
+
assert.equal(decide(untaggedCall(ws.on, input), ws.tmp, Date.now(), { codexModel: "gpt-6.1-sol" }), null);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("a codex dispatch while Codex is limited is refused and names the sonnet implementer", (t) => {
|
|
100
|
+
const ws = workspace(t);
|
|
101
|
+
writeLimit(limitFileOf({}, ws.tmp), { until: Date.now() + 3_600_000, source: "codex" });
|
|
102
|
+
const input = { subagent_type: "codex", model: "gpt-6.1-sol", prompt: "Brief: brief.md" };
|
|
103
|
+
const reason = reasonOf(decide(agentCall(ws.on, input), ws.tmp, Date.now(), { codexModel: null })) ?? "";
|
|
104
|
+
for (const text of ["qc codex status", "architecture:sdd-implementer", "sonnet", "Brief: brief.md"]) {
|
|
105
|
+
assert.ok(reason.includes(text), text);
|
|
106
|
+
}
|
|
107
|
+
assert.equal(existsSync(ws.slots), false);
|
|
108
|
+
assert.equal(decide(agentCall(ws.on, { ...implementer, prompt: "Brief: brief.md" }), ws.tmp), null);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("a limit that has passed counts as free", (t) => {
|
|
112
|
+
const ws = workspace(t);
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
writeLimit(limitFileOf({}, ws.tmp), { until: now, source: "codex" });
|
|
115
|
+
const input = { subagent_type: "codex", model: "gpt-6.1-sol", prompt: "Brief: brief.md" };
|
|
116
|
+
assert.equal(decide(agentCall(ws.on, input), ws.tmp, now, { codexModel: null }), null);
|
|
117
|
+
const reason = reasonOf(decide(agentCall(ws.on, { ...implementer, prompt: "Brief: brief.md" }), ws.tmp, now)) ?? "";
|
|
118
|
+
assert.ok(reason.includes("Runtime: claude <reason>"), reason);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("an implementer dispatch while Codex is free needs a Runtime line", (t) => {
|
|
122
|
+
const ws = workspace(t);
|
|
123
|
+
const reason = reasonOf(decide(agentCall(ws.on, { ...implementer, prompt: "Brief: brief.md" }), ws.tmp)) ?? "";
|
|
124
|
+
assert.ok(reason.includes("Runtime: claude <reason>"), reason);
|
|
125
|
+
assert.equal(existsSync(ws.slots), false);
|
|
126
|
+
assert.equal(decide(agentCall(ws.on, implementer), ws.tmp), null);
|
|
127
|
+
});
|
|
128
|
+
|
|
63
129
|
test("a checkout with no config, or a swarm section with no dispatch key, sees no change", (t) => {
|
|
64
130
|
const ws = workspace(t);
|
|
65
131
|
for (const cwd of [ws.off, ws.plain]) {
|
|
@@ -99,7 +165,7 @@ test("a prompt over the limit is refused, and the refusal claims no slot", (t) =
|
|
|
99
165
|
});
|
|
100
166
|
|
|
101
167
|
test("a second implementer is refused until the first one stops, and the refusal names the slot file", (t) => {
|
|
102
|
-
const ws = workspace(t);
|
|
168
|
+
const ws = workspace(t, { implementerSlots: 1 });
|
|
103
169
|
assert.equal(decide(agentCall(ws.on, implementer), ws.tmp), null);
|
|
104
170
|
const second = reasonOf(decide(agentCall(ws.on, { ...implementer, subagent_type: "sdd-implementer" }), ws.tmp)) ?? "";
|
|
105
171
|
assert.match(second, /holds the one implementer slot/);
|
|
@@ -157,14 +223,83 @@ test("a repository's models override replaces one type's families and leaves the
|
|
|
157
223
|
});
|
|
158
224
|
|
|
159
225
|
test("a slot with no stop expires after slotMinutes", (t) => {
|
|
160
|
-
const ws = workspace(t);
|
|
226
|
+
const ws = workspace(t, { implementerSlots: 1 });
|
|
161
227
|
decide(agentCall(ws.on, implementer), ws.tmp);
|
|
162
228
|
assert.notEqual(reasonOf(decide(agentCall(ws.on, implementer), ws.tmp)), null);
|
|
229
|
+
const future = new Date(Date.now() + 61 * 60_000);
|
|
230
|
+
utimesSync(checkpointPathOf(ws.on, "session-aaaa"), future, future);
|
|
163
231
|
assert.equal(decide(agentCall(ws.on, implementer), ws.tmp, Date.now() + 61 * 60_000), null);
|
|
164
232
|
});
|
|
165
233
|
|
|
166
|
-
test("a
|
|
234
|
+
test("a valid checkpoint passes silently through the dispatch CLI", (t) => {
|
|
167
235
|
const ws = workspace(t);
|
|
236
|
+
const result = spawnSync(process.execPath, [GUARD], {
|
|
237
|
+
input: JSON.stringify(agentCall(ws.off, { model: "gpt-6.1-sol", prompt: "p" })),
|
|
238
|
+
encoding: "utf8",
|
|
239
|
+
});
|
|
240
|
+
assert.equal(result.status, 0, result.stderr);
|
|
241
|
+
assert.equal(result.stdout, "");
|
|
242
|
+
assert.equal(result.stderr, "");
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("checkpoint refusal applies with dispatch on or off and names the path, problem, and headings", (t) => {
|
|
246
|
+
const ws = workspace(t);
|
|
247
|
+
for (const root of [ws.on, ws.off]) {
|
|
248
|
+
const file = checkpointPathOf(root, "session-aaaa");
|
|
249
|
+
rmSync(file);
|
|
250
|
+
const call = agentCall(root, { model: "gpt-6.1-sol", prompt: "p" });
|
|
251
|
+
const reason = reasonOf(decide(call, ws.tmp));
|
|
252
|
+
assert.ok(reason?.includes(file), reason);
|
|
253
|
+
assert.match(reason, /missing/);
|
|
254
|
+
assert.ok(reason.split("\n").length <= 4);
|
|
255
|
+
for (const heading of ["## Goal", "## Rules", "## Tasks", "## Next"]) assert.ok(reason.includes(heading));
|
|
256
|
+
assert.equal(decide({ ...call, agent_id: "worker" }, ws.tmp), null);
|
|
257
|
+
writeFileSync(file, "## Goal\n");
|
|
258
|
+
assert.match(reasonOf(decide(call, ws.tmp)), /heading/);
|
|
259
|
+
writeFileSync(file, "## Goal\n## Rules\n## Tasks\n## Next\n" + "task\n".repeat(57));
|
|
260
|
+
assert.match(reasonOf(decide(call, ws.tmp)), /60/);
|
|
261
|
+
writeFileSync(file, "## Goal\n## Rules\n## Tasks\n## Next\n");
|
|
262
|
+
const old = new Date(Date.now() - 31 * 60_000);
|
|
263
|
+
utimesSync(file, old, old);
|
|
264
|
+
assert.match(reasonOf(decide(call, ws.tmp)), /older than 30/);
|
|
265
|
+
writeFileSync(path.join(root, "qc.config.json"), JSON.stringify({ checkpoint: { maxAgeMinutes: 0 } }));
|
|
266
|
+
assert.equal(decide(call, ws.tmp), null);
|
|
267
|
+
rmSync(file);
|
|
268
|
+
assert.match(reasonOf(decide(call, ws.tmp)), /missing/);
|
|
269
|
+
}
|
|
270
|
+
assert.equal(existsSync(ws.slots), false);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("an invalid Git pointer keeps the checkpoint guard on", (t) => {
|
|
274
|
+
const ws = workspace(t);
|
|
275
|
+
const root = path.join(ws.tmp, "broken");
|
|
276
|
+
mkdirSync(root);
|
|
277
|
+
writeFileSync(path.join(root, ".git"), "invalid pointer");
|
|
278
|
+
writeFileSync(path.join(root, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {} } }));
|
|
279
|
+
const output = decide(agentCall(root, { prompt: "p" }), ws.tmp);
|
|
280
|
+
assert.match(reasonOf(output), /the session checkpoint/);
|
|
281
|
+
assert.match(reasonOf(output), /cannot resolve/);
|
|
282
|
+
assert.doesNotMatch(JSON.stringify(output), /guard is off/);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("agents in one assistant message share the first dispatch age check", (t) => {
|
|
286
|
+
const ws = workspace(t);
|
|
287
|
+
const transcript = path.join(ws.tmp, "main.jsonl");
|
|
288
|
+
const message = (id, tools) => JSON.stringify({ type: "assistant", message: { id, content: tools.map((id) => ({ type: "tool_use", id })) } }) + "\n";
|
|
289
|
+
writeFileSync(transcript, message("batch-1", ["a", "b"]));
|
|
290
|
+
const file = checkpointPathOf(ws.off, "session-aaaa");
|
|
291
|
+
const now = Date.now();
|
|
292
|
+
const old = new Date(now - 29 * 60_000);
|
|
293
|
+
utimesSync(file, old, old);
|
|
294
|
+
const call = agentCall(ws.off, { prompt: "p" }, { transcript_path: transcript });
|
|
295
|
+
assert.equal(decide({ ...call, tool_use_id: "a" }, ws.tmp, now), null);
|
|
296
|
+
assert.equal(decide({ ...call, tool_use_id: "b" }, ws.tmp, now + 2 * 60_000), null);
|
|
297
|
+
writeFileSync(transcript, message("batch-2", ["c"]));
|
|
298
|
+
assert.match(reasonOf(decide({ ...call, tool_use_id: "c" }, ws.tmp, now + 2 * 60_000)), /older/);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test("a resumed implementer holds the slot again", (t) => {
|
|
302
|
+
const ws = workspace(t, { implementerSlots: 1 });
|
|
168
303
|
decide(agentCall(ws.on, implementer), ws.tmp);
|
|
169
304
|
decide(subagentEvent(ws.on, "architecture:sdd-implementer"), ws.tmp);
|
|
170
305
|
decide(subagentEvent(ws.on, "architecture:sdd-implementer", "SubagentStart"), ws.tmp);
|
|
@@ -219,8 +354,8 @@ const agentEvent = (cwd, agentId, hook_event_name) => ({
|
|
|
219
354
|
agent_id: agentId,
|
|
220
355
|
});
|
|
221
356
|
|
|
222
|
-
test("
|
|
223
|
-
const ws = workspace(t
|
|
357
|
+
test("the default limit lets three implementers run, refuses the fourth with the holders and the limit, and a stop frees one", (t) => {
|
|
358
|
+
const ws = workspace(t);
|
|
224
359
|
for (const id of ["a", "b", "c"]) {
|
|
225
360
|
assert.equal(decide(slotCall(ws.on, `use-${id}`), ws.tmp), null);
|
|
226
361
|
decide(agentEvent(ws.on, `agent-${id}`, "SubagentStart"), ws.tmp);
|
|
@@ -259,7 +394,7 @@ const taskStop = (cwd, taskId) => ({
|
|
|
259
394
|
});
|
|
260
395
|
|
|
261
396
|
test("a TaskStop frees the slot of the agent it stopped, and a TaskStop of another task frees nothing", (t) => {
|
|
262
|
-
const ws = workspace(t);
|
|
397
|
+
const ws = workspace(t, { implementerSlots: 1 });
|
|
263
398
|
assert.equal(decide(slotCall(ws.on, "use-a"), ws.tmp), null);
|
|
264
399
|
decide(agentEvent(ws.on, "agent-a", "SubagentStart"), ws.tmp);
|
|
265
400
|
assert.equal(decide(taskStop(ws.on, "shell-9"), ws.tmp), null);
|
|
@@ -269,7 +404,7 @@ test("a TaskStop frees the slot of the agent it stopped, and a TaskStop of anoth
|
|
|
269
404
|
});
|
|
270
405
|
|
|
271
406
|
test("a session startup or resume frees every slot of the session, and a compaction frees none", (t) => {
|
|
272
|
-
const ws = workspace(t);
|
|
407
|
+
const ws = workspace(t, { implementerSlots: 1 });
|
|
273
408
|
assert.equal(decide(slotCall(ws.on, "use-a"), ws.tmp), null);
|
|
274
409
|
const start = (source) => ({ session_id: "session-aaaa", cwd: ws.on, hook_event_name: "SessionStart", source });
|
|
275
410
|
assert.equal(decide(start("compact"), ws.tmp), null);
|
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
// and fork, because a rule held only in the conversation is lost to a compaction.
|
|
4
4
|
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { dispatchDefaults } from "../config.mjs";
|
|
6
7
|
import { directSettingsAt } from "./direct-lane.mjs";
|
|
7
8
|
import { dispatchSettingsAt, exploreSettingsAt, exploreToolLines } from "./dispatch.mjs";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
const reminder = (implementerSlots) =>
|
|
10
11
|
"Subagent workflow (swarm.dispatch in qc.config.json): run a plan with superpowers:subagent-driven-development. " +
|
|
11
12
|
"Dispatch architecture:sdd-planner to write a plan, architecture:sdd-implementer for one task, and " +
|
|
12
13
|
"architecture:sdd-reviewer to review it; before merge, dispatch architecture:sdd-branch-reviewer to review the " +
|
|
13
14
|
"whole branch. " +
|
|
14
|
-
|
|
15
|
+
slotsRule(implementerSlots) + " Name a model on any other dispatch, and " +
|
|
15
16
|
"write each brief to a file and name its path on a prompt line `Brief: <path>`; a dispatch with no such line, or a missing file, is refused. " +
|
|
16
17
|
"Name the worktree on a prompt line `Worktree: <path>`; a reviewer whose worktree, branch, or head the gate cannot read is refused. A reviewer starts with " +
|
|
17
18
|
"`VERDICT: <APPROVED|CHANGES_REQUIRED> <sha>`, and a merge passes `--match-head-commit <sha>`. " +
|
|
@@ -19,11 +20,20 @@ export const REMINDER =
|
|
|
19
20
|
"Review a head only once CI on it is green, with the base merged in: fix a CI failure first, and merge `origin/<base>` at Step 0 of a fix round. " +
|
|
20
21
|
"A PR gets one branch review. After it, review each fix round once, by its increment: add `Reviewed: <sha>`, the last head a branch review named.";
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
export const REMINDER = reminder(dispatchDefaults.implementerSlots);
|
|
24
|
+
|
|
25
|
+
/** The reminder names Codex first, its controller skill, and the runtime routing rules. */
|
|
23
26
|
export const CODEX_LINE =
|
|
24
27
|
" Implementer work runs on Codex first through `qc codex-implement --brief <file> --worktree <path> --progress <file>`; " +
|
|
25
28
|
"load the `architecture:codex` skill before the first dispatch. " +
|
|
26
|
-
"
|
|
29
|
+
"Use --role scout for read-only research, --role tests for tests, and --role review (or --review) for review. " +
|
|
30
|
+
"When codex.requireApproval is true, an implement brief needs ## Design and Approved: <scout report>; the orchestrator enables it. " +
|
|
31
|
+
"Every implement/tests run checks Paths, Design dependency names, and codex.maxDiffLines (default 400); split larger issues. " +
|
|
32
|
+
"Forward --resume <session id> only when requested; each run logs its actual session id. " +
|
|
33
|
+
"On exit 2 (a Codex limit), dispatch the same brief to an architecture:sdd-implementer (sonnet). " +
|
|
34
|
+
"Start each Agent description with `Codex <model> · ` for a codex type or `Claude <model> · ` for any other; " +
|
|
35
|
+
"the guard refuses a codex dispatch while `qc codex status` shows a limit and requires `Runtime: claude <reason>` for an implementer dispatch while Codex is free. " +
|
|
36
|
+
"Update the session checkpoint named by SessionStart before each dispatch and compaction; it is the source of truth for open work.";
|
|
27
37
|
|
|
28
38
|
/** The note a Codex implementer gets in place of the controller note, with `QC_ROLE=implementer`. */
|
|
29
39
|
export const WORKER_NOTE =
|
|
@@ -50,11 +60,12 @@ export function modelsLine({ models, runtime }) {
|
|
|
50
60
|
|
|
51
61
|
const context = (eventName, text) => ({ hookSpecificOutput: { hookEventName: eventName, additionalContext: text } });
|
|
52
62
|
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
implementerSlots > 1
|
|
56
|
-
? `
|
|
57
|
-
: "";
|
|
63
|
+
/** State the configured limit directly, retaining the original rule for a single slot. */
|
|
64
|
+
function slotsRule(implementerSlots) {
|
|
65
|
+
return implementerSlots > 1
|
|
66
|
+
? `Run up to ${implementerSlots} implementers at once, each in its own worktree with disjoint paths; each extra implementer needs more than 4 GB of free memory. A hook refuses one over the limit.`
|
|
67
|
+
: "Run one implementer at a time: a hook refuses a second.";
|
|
68
|
+
}
|
|
58
69
|
|
|
59
70
|
/** One added line for the direct lane of `swarm.direct`, or "" when it is off. */
|
|
60
71
|
function directLine(cwd) {
|
|
@@ -114,8 +125,10 @@ function decideSessionStart(call, env) {
|
|
|
114
125
|
}
|
|
115
126
|
const explore = exploreLine(cwd);
|
|
116
127
|
if (!dispatch) return explore === "" ? null : context("SessionStart", explore.trim());
|
|
128
|
+
if (env.QC_ROLE === "scout") return context("SessionStart", `scout worker mode: Work inline. Do not edit, stage, or commit worktree files. Write only the external report and progress; include Gap:, Plan:, Check:, Risks:, Questions:, Breaking: yes|no.${explore}`);
|
|
129
|
+
if (["tests", "review"].includes(env.QC_ROLE)) return context("SessionStart", `${env.QC_ROLE} worker mode: Work inline. Follow the brief's role and exit criteria. Start no helper agents.${explore}`);
|
|
117
130
|
if (env.QC_ROLE === "implementer") return context("SessionStart", `${WORKER_NOTE}${explore}`);
|
|
118
|
-
return context("SessionStart", `${
|
|
131
|
+
return context("SessionStart", `${reminder(dispatch.implementerSlots)}${modelsLine(dispatch)}${CODEX_LINE}${directLine(cwd)}${explore}`);
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
/** @returns the hook output, or null when there is nothing to add for this event. */
|
|
@@ -13,6 +13,19 @@ process.env.QC_RUNTIME = "codex";
|
|
|
13
13
|
delete process.env.QC_ROLE;
|
|
14
14
|
const BASE = `${REMINDER}${modelsLine({ models: runtimeModels.codex, runtime: "codex" })}${CODEX_LINE}`;
|
|
15
15
|
|
|
16
|
+
test("CODEX_LINE names the runtime tags, Runtime line, and qc codex status", () => {
|
|
17
|
+
for (const phrase of [/--role scout/, /codex.requireApproval/, /Approved:/, /## Design/, /codex.maxDiffLines/, /--resume/]) assert.match(CODEX_LINE, phrase);
|
|
18
|
+
for (const text of ["Codex <model> · ", "Claude <model> · ", "Runtime: claude <reason>", "qc codex status"]) {
|
|
19
|
+
assert.ok(CODEX_LINE.includes(text), text);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("the orchestrator note requires the SessionStart checkpoint before dispatch and compaction", () => {
|
|
24
|
+
assert.match(CODEX_LINE, /checkpoint named by SessionStart/);
|
|
25
|
+
assert.match(CODEX_LINE, /before each dispatch and compaction/);
|
|
26
|
+
assert.match(CODEX_LINE, /source of truth for open work/);
|
|
27
|
+
});
|
|
28
|
+
|
|
16
29
|
const NOTE = fileURLToPath(new URL("./dispatch-reminder.mjs", import.meta.url));
|
|
17
30
|
const HOOKS = fileURLToPath(new URL("../../../../hooks/hooks.json", import.meta.url));
|
|
18
31
|
|
|
@@ -47,21 +60,23 @@ test("with the section on, every start adds the note, a compaction included", (t
|
|
|
47
60
|
}
|
|
48
61
|
});
|
|
49
62
|
|
|
50
|
-
test("the note names the workflow, the four types, and the
|
|
63
|
+
test("the note names the workflow, the four types, and the parallel rule, in a short text", () => {
|
|
51
64
|
for (const word of [
|
|
52
65
|
"superpowers:subagent-driven-development",
|
|
53
66
|
"architecture:sdd-planner",
|
|
54
67
|
"architecture:sdd-implementer",
|
|
55
68
|
"architecture:sdd-reviewer",
|
|
56
69
|
"architecture:sdd-branch-reviewer",
|
|
57
|
-
"
|
|
70
|
+
"up to 3 implementers at once",
|
|
71
|
+
"disjoint paths",
|
|
72
|
+
"more than 4 GB of free memory",
|
|
58
73
|
"Worktree: <path>",
|
|
59
74
|
"VERDICT: <APPROVED|CHANGES_REQUIRED> <sha>",
|
|
60
75
|
"--match-head-commit <sha>",
|
|
61
76
|
]) {
|
|
62
77
|
assert.ok(REMINDER.includes(word), word);
|
|
63
78
|
}
|
|
64
|
-
assert.ok(REMINDER.length <
|
|
79
|
+
assert.ok(REMINDER.length < 1500, `${REMINDER.length} characters`);
|
|
65
80
|
});
|
|
66
81
|
|
|
67
82
|
test("the note says to review a green head only, to fix CI first, and to review a fix round by its increment", () => {
|
|
@@ -157,15 +172,39 @@ test("hooks.json also runs the note on SubagentStart, all matchers, beside the e
|
|
|
157
172
|
);
|
|
158
173
|
});
|
|
159
174
|
|
|
160
|
-
test("
|
|
161
|
-
const [
|
|
162
|
-
{ swarm: {
|
|
175
|
+
test("the default and custom parallel limits state the rule directly; one keeps the original rule", (t) => {
|
|
176
|
+
const [defaults, five, one] = checkouts(t, [
|
|
177
|
+
{ swarm: { direct: false, dispatch: {} } },
|
|
178
|
+
{ swarm: { direct: false, dispatch: { implementerSlots: 5 } } },
|
|
163
179
|
{ swarm: { direct: false, dispatch: { implementerSlots: 1 } } },
|
|
164
180
|
]);
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
181
|
+
for (const [cwd, limit] of [[defaults, 3], [five, 5]]) {
|
|
182
|
+
const text = decide(start(cwd, "startup")).hookSpecificOutput.additionalContext;
|
|
183
|
+
assert.ok(text.includes(`up to ${limit} implementers at once`));
|
|
184
|
+
assert.match(text, /each in its own worktree/);
|
|
185
|
+
assert.match(text, /disjoint paths/);
|
|
186
|
+
assert.match(text, /more than 4 GB of free memory/);
|
|
187
|
+
assert.match(text, /A hook refuses one over the limit/);
|
|
188
|
+
assert.doesNotMatch(text, /one implementer at a time|one-at-a-time/);
|
|
189
|
+
}
|
|
190
|
+
assert.equal(decide(start(defaults, "startup")).hookSpecificOutput.additionalContext, BASE);
|
|
191
|
+
const serial = decide(start(one, "startup")).hookSpecificOutput.additionalContext;
|
|
192
|
+
assert.equal(
|
|
193
|
+
serial,
|
|
194
|
+
"Subagent workflow (swarm.dispatch in qc.config.json): run a plan with superpowers:subagent-driven-development. " +
|
|
195
|
+
"Dispatch architecture:sdd-planner to write a plan, architecture:sdd-implementer for one task, and " +
|
|
196
|
+
"architecture:sdd-reviewer to review it; before merge, dispatch architecture:sdd-branch-reviewer to review the " +
|
|
197
|
+
"whole branch. " +
|
|
198
|
+
"Run one implementer at a time: a hook refuses a second. Name a model on any other dispatch, and " +
|
|
199
|
+
"write each brief to a file and name its path on a prompt line `Brief: <path>`; a dispatch with no such line, or a missing file, is refused. " +
|
|
200
|
+
"Name the worktree on a prompt line `Worktree: <path>`; a reviewer whose worktree, branch, or head the gate cannot read is refused. A reviewer starts with " +
|
|
201
|
+
"`VERDICT: <APPROVED|CHANGES_REQUIRED> <sha>`, and a merge passes `--match-head-commit <sha>`. " +
|
|
202
|
+
"Ask the user the product questions first, in one question, and record the answers under `## Product decisions` in each brief. " +
|
|
203
|
+
"Review a head only once CI on it is green, with the base merged in: fix a CI failure first, and merge `origin/<base>` at Step 0 of a fix round. " +
|
|
204
|
+
"A PR gets one branch review. After it, review each fix round once, by its increment: add `Reviewed: <sha>`, the last head a branch review named." +
|
|
205
|
+
modelsLine({ models: runtimeModels.codex, runtime: "codex" }) + CODEX_LINE,
|
|
206
|
+
);
|
|
207
|
+
assert.doesNotMatch(serial, /implementers at once|one over the limit/);
|
|
169
208
|
});
|
|
170
209
|
|
|
171
210
|
test("SubagentStart gives each tool's use and command, in config order, since a plugin agent carries no MCP tool", (t) => {
|
|
@@ -214,12 +253,16 @@ test("a swarm.direct section that does not parse names the key and leaves the re
|
|
|
214
253
|
});
|
|
215
254
|
|
|
216
255
|
test("the direct lane note says when a merge needs a review", (t) => {
|
|
217
|
-
const [none, some, every] = checkouts(t, [
|
|
256
|
+
const [defaults, none, some, every] = checkouts(t, [
|
|
218
257
|
{ swarm: { dispatch: {} } },
|
|
258
|
+
{ swarm: { dispatch: {}, direct: { reviewPaths: [] } } },
|
|
219
259
|
{ swarm: { dispatch: {}, direct: { reviewPaths: ["src/**", "api/**"] } } },
|
|
220
260
|
{ swarm: { dispatch: {}, direct: { reviewPaths: ["**"] } } },
|
|
221
261
|
]);
|
|
222
262
|
const noteOf = (dir) => decide(start(dir, "startup")).hookSpecificOutput.additionalContext;
|
|
263
|
+
const defaultNote = noteOf(defaults);
|
|
264
|
+
assert.match(defaultNote, /--match-head-commit <sha>`\. A merge needs one APPROVED review of the head \(sdd-reviewer\) when a changed path matches swarm\.direct\.reviewPaths\./);
|
|
265
|
+
assert.doesNotMatch(defaultNote, /no review/);
|
|
223
266
|
assert.match(noteOf(none), /--match-head-commit <sha>` and no review\./);
|
|
224
267
|
const partial = noteOf(some);
|
|
225
268
|
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\./);
|
|
@@ -280,6 +323,15 @@ test("the controller note makes Codex the first choice, names its skill, and fal
|
|
|
280
323
|
});
|
|
281
324
|
|
|
282
325
|
test("QC_ROLE=implementer replaces the controller note with the worker note", (t) => {
|
|
326
|
+
for (const role of ["scout", "tests", "review"]) {
|
|
327
|
+
const [on] = checkouts(t, [{ swarm: { dispatch: {} } }]);
|
|
328
|
+
const text = decide(start(on, "startup"), { QC_ROLE: role }).hookSpecificOutput.additionalContext;
|
|
329
|
+
assert.match(text, /Work inline/);
|
|
330
|
+
assert.ok(text.includes(role));
|
|
331
|
+
assert.doesNotMatch(text, /run a plan with superpowers|make one commit|push once/);
|
|
332
|
+
if (role === "scout") assert.match(text, /Do not edit, stage, or commit/);
|
|
333
|
+
}
|
|
334
|
+
|
|
283
335
|
const [on] = checkouts(t, [{ swarm: { dispatch: {} } }]);
|
|
284
336
|
const text = decide(start(on, "startup"), { QC_ROLE: "implementer" }).hookSpecificOutput.additionalContext;
|
|
285
337
|
assert.equal(text, WORKER_NOTE);
|