architecture-harness 0.29.5 → 0.30.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 +1 -1
- package/src/cli/codex-loop.mjs +115 -0
- package/src/cli/codex-loop.test.mjs +114 -0
- package/src/cli/fleet-dispatch.mjs +123 -0
- package/src/cli/fleet-dispatch.test.mjs +98 -0
- package/src/cli/fleet-github.mjs +7 -0
- package/src/cli/fleet-jobs.mjs +195 -0
- package/src/cli/fleet-jobs.test.mjs +188 -0
- package/src/cli/fleet-message.mjs +1 -1
- package/src/cli/fleet-message.test.mjs +1 -1
- package/src/cli/fleet-node.mjs +14 -8
- package/src/cli/fleet-node.test.mjs +48 -11
- package/src/cli/fleet-state.mjs +1 -1
- package/src/cli/fleet.mjs +9 -5
- package/src/cli/fleet.test.mjs +19 -1
- package/src/cli/pr-guard.mjs +2 -0
- package/src/cli/pr-guard.test.mjs +11 -3
- package/src/cli/qc.mjs +6 -0
- package/src/cli/watch.mjs +1 -1
- package/src/config.mjs +3 -1
|
@@ -54,6 +54,7 @@ test("HTTP routes, JSON, signature refusal, replay, byte limit and durable queue
|
|
|
54
54
|
}
|
|
55
55
|
const post = body => fetch(`${base}/message`, { method: "POST", body });
|
|
56
56
|
assert.equal((await post("{")).status, 400);
|
|
57
|
+
assert.equal((await post("null" + " ".repeat(65536))).status, 413);
|
|
57
58
|
const invalid = await post(JSON.stringify({ ...message(), sig: "00".repeat(32) }));
|
|
58
59
|
assert.equal(invalid.status, 400);
|
|
59
60
|
assert.deepEqual(await invalid.json(), { ok: false, reason: "bad-signature" });
|
|
@@ -128,13 +129,13 @@ test("heartbeat targets only other active addressed nodes and records receipt ti
|
|
|
128
129
|
assert.equal(received[0].url, "http://127.0.0.1:8081/message");
|
|
129
130
|
assert.equal(received[0].message.kind, "heartbeat");
|
|
130
131
|
assert.equal(received[0].message.body.os, process.platform === "win32" ? "windows" : process.platform);
|
|
131
|
-
assert.deepEqual(received[0].message.body, { load: initialLoad, kit: "commit", os: process.platform === "win32" ? "windows" : process.platform, term: 1, leader: true, work: [], assigned: [] });
|
|
132
|
+
assert.deepEqual(received[0].message.body, { load: initialLoad, kit: "commit", os: process.platform === "win32" ? "windows" : process.platform, term: 1, leader: true, work: [], jobs: { max: 0, live: 0, limitedUntil: 0, steps: [] }, assigned: [] });
|
|
132
133
|
const server = await createNodeServer({ root, fleet, clock: () => now, listen: { port: 0 } });
|
|
133
134
|
t.after(() => new Promise(resolve => server.close(resolve)));
|
|
134
135
|
const post = body => fetch(`http://127.0.0.1:${server.address().port}/message`, { method: "POST", body: JSON.stringify(body) });
|
|
135
136
|
const beat = message({ kind: "heartbeat", body: { kit: null, term: 1, leader: false } });
|
|
136
137
|
assert.equal((await post(beat)).status, 202);
|
|
137
|
-
assert.deepEqual(readState(root, "peers"), { a: { load: { ...initialLoad, rtt: 0 }, time: now, os: host, kit: "commit", term: 1, leader: true, work: [], assigned: [] }, b: { time: now, messageTime: beat.time, kit: null, term: 1, leader: false } });
|
|
138
|
+
assert.deepEqual(readState(root, "peers"), { a: { load: { ...initialLoad, rtt: 0 }, time: now, os: host, kit: "commit", term: 1, leader: true, work: [], jobs: { max: 0, live: 0, limitedUntil: 0, steps: [] }, assigned: [] }, b: { time: now, messageTime: beat.time, kit: null, term: 1, leader: false } });
|
|
138
139
|
assert.equal((await post(message({ kind: "heartbeat", body: { leader: "yes" } }))).status, 400);
|
|
139
140
|
assert.deepEqual(readState(root, "queue"), []);
|
|
140
141
|
});
|
|
@@ -147,7 +148,7 @@ test("heartbeat ordering saves signed time and ignores older or equal snapshots
|
|
|
147
148
|
t.after(() => new Promise(resolve => server.close(resolve)));
|
|
148
149
|
const post = (sent, body) => fetch(`http://127.0.0.1:${server.address().port}/message`, { method: "POST",
|
|
149
150
|
body: JSON.stringify(message({ kind: "heartbeat", time: new Date(sent).toISOString(), body })) });
|
|
150
|
-
const body = { kit: "new", term: 1, leader: true, work: [], assigned: [] };
|
|
151
|
+
const body = { kit: "new", term: 1, leader: true, work: [], jobs: { max: 0, live: 0, limitedUntil: 0, steps: [] }, assigned: [] };
|
|
151
152
|
assert.equal((await post(now, body)).status, 202);
|
|
152
153
|
const saved = readState(root, "peers");
|
|
153
154
|
assert.equal(saved.b.messageTime, new Date(now).toISOString());
|
|
@@ -294,7 +295,7 @@ test("start detaches with a log, start twice is idempotent, stop keeps state and
|
|
|
294
295
|
writeState(root, "peers", { b: { time: now, leader: true, term: 1, kit: null, assigned: [{ repo: "o/r", issue: 7, epoch: 1 }] } });
|
|
295
296
|
const p = processDeps(root);
|
|
296
297
|
assert.deepEqual(await startNode({ ...p.deps, leader: true }), { running: true, already: false });
|
|
297
|
-
assert.deepEqual(readState(root, "node"), { pid: 12345, leader: true, instance: p.spawned[0].options.env.QC_FLEET_INSTANCE });
|
|
298
|
+
assert.deepEqual(readState(root, "node"), { pid: 12345, leader: true, instance: p.spawned[0].options.env.QC_FLEET_INSTANCE, jobs: { max: 0 } });
|
|
298
299
|
assert.equal(p.spawned.length, 1);
|
|
299
300
|
const spawned = p.spawned[0];
|
|
300
301
|
assert.equal(spawned.command, process.execPath);
|
|
@@ -328,7 +329,7 @@ test("start names missing secret/address, times out and cleans up; stale records
|
|
|
328
329
|
await assert.rejects(startNode(p.deps), /health.*5 s/);
|
|
329
330
|
assert.equal(p.time() - now, 5000);
|
|
330
331
|
assert.equal(existsSync(path.join(stateDir(root), "node.json")), false);
|
|
331
|
-
writeState(root, "node", { pid: 12345, leader: true, instance: p.spawned[0].options.env.QC_FLEET_INSTANCE });
|
|
332
|
+
writeState(root, "node", { pid: 12345, leader: true, instance: p.spawned[0].options.env.QC_FLEET_INSTANCE, jobs: { max: 0 } });
|
|
332
333
|
p.setLive(false);
|
|
333
334
|
p.setReady(true);
|
|
334
335
|
assert.deepEqual(await stopNode(p.deps), { stopped: true, already: true });
|
|
@@ -408,7 +409,7 @@ test("serve schedules heartbeats every 30 seconds, retries every second and clos
|
|
|
408
409
|
time += 1000;
|
|
409
410
|
await timers[0].fn();
|
|
410
411
|
assert.equal(sent.length, 1);
|
|
411
|
-
assert.deepEqual(sent[0].body, { load: initialLoad, os: host, kit: null, term: 1, leader: true, work: [], assigned: [] });
|
|
412
|
+
assert.deepEqual(sent[0].body, { load: initialLoad, os: host, kit: null, term: 1, leader: true, work: [], jobs: { max: 0, live: 0, limitedUntil: 0, steps: [] }, assigned: [] });
|
|
412
413
|
assert.equal(readState(root, "node").leader, true);
|
|
413
414
|
const closed = new Promise(resolve => server.once("close", resolve));
|
|
414
415
|
signals.get("SIGTERM")();
|
|
@@ -418,6 +419,27 @@ test("serve schedules heartbeats every 30 seconds, retries every second and clos
|
|
|
418
419
|
assert.equal(existsSync(path.join(stateDir(root), "node.json")), false);
|
|
419
420
|
});
|
|
420
421
|
|
|
422
|
+
test("serve passes checkout repository to the worker job tick", async t => {
|
|
423
|
+
const root = fixture(t), sent = [];
|
|
424
|
+
let tick;
|
|
425
|
+
const server = await serveNode({ root, fleet, repo: "o/r", clock: () => now,
|
|
426
|
+
gh: apiResponse, listen: { port: 0 }, timer: fn => { tick = fn; }, clearTimer: () => {},
|
|
427
|
+
onSignal: () => {}, offSignal: () => {},
|
|
428
|
+
fetch: async (_url, options) => { sent.push(JSON.parse(options.body)); return { status: 202 }; } });
|
|
429
|
+
t.after(() => new Promise(resolve => server.close(resolve)));
|
|
430
|
+
writeState(root, "peers", { b: { leader: true, term: 1, time: now } });
|
|
431
|
+
for (const repo of ["other/repo", "o/r"]) {
|
|
432
|
+
writeState(root, "queue", [message({ repo, kind: "codex-job", body: {
|
|
433
|
+
id: "job-1", branch: "feat/job", base: "main", brief: "brief", rounds: 1,
|
|
434
|
+
} })]);
|
|
435
|
+
await tick();
|
|
436
|
+
for (let n = 0; n < 12; n++) await new Promise(resolve => setImmediate(resolve));
|
|
437
|
+
const result = sent.filter(row => row.kind === "codex-result").at(-1);
|
|
438
|
+
assert.equal(result.body.state, "refused");
|
|
439
|
+
assert.equal(result.body.reason, repo === "o/r" ? "no free job slots" : "repository does not match worker checkout");
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
|
|
421
443
|
test("serve advertises a hostname as its bound IPv4 to a receiver, refreshes the same fleet for HTTP, heartbeats and expiry, and closes discovery on shutdown", async t => {
|
|
422
444
|
const { createBeacon, readDiscovered, startDiscovery } = await import("./fleet-discover.mjs");
|
|
423
445
|
const order = getDefaultResultOrder();
|
|
@@ -824,19 +846,19 @@ test("heartbeats carry own work, per-recipient Leader assignments, and replace p
|
|
|
824
846
|
const fetcher = async (_url, options) => { received.push(JSON.parse(options.body)); return { status: 202 }; };
|
|
825
847
|
await heartbeat({ root, fleet: nodes, repo: "o/r", leader: true, clock: () => now, fetch: fetcher });
|
|
826
848
|
assert.deepEqual(received.map(row => row.body), [
|
|
827
|
-
{ load: initialLoad, os: host, kit: null, term: 1, leader: true, work: [work], assigned: [{ repo: "o/r", issue: 2, epoch: 1 }] },
|
|
828
|
-
{ load: initialLoad, os: host, kit: null, term: 1, leader: true, work: [work], assigned: [{ repo: "o/r", issue: 3, epoch: 1 }] },
|
|
849
|
+
{ load: initialLoad, os: host, kit: null, term: 1, leader: true, work: [work], jobs: { max: 0, live: 0, limitedUntil: 0, steps: [] }, assigned: [{ repo: "o/r", issue: 2, epoch: 1 }] },
|
|
850
|
+
{ load: initialLoad, os: host, kit: null, term: 1, leader: true, work: [work], jobs: { max: 0, live: 0, limitedUntil: 0, steps: [] }, assigned: [{ repo: "o/r", issue: 3, epoch: 1 }] },
|
|
829
851
|
]);
|
|
830
852
|
received.length = 0;
|
|
831
853
|
writeState(root, "assignments", { "o/r#1": held(1, "a", 2) });
|
|
832
854
|
await heartbeat({ root, fleet: nodes, repo: "o/r", clock: () => now, fetch: fetcher });
|
|
833
|
-
assert.deepEqual(received[0].body, { load: { ...initialLoad, rtt: 0 }, os: host, kit: null, term: 1, leader: false, work: [{ repo: "o/r", issue: 1, epoch: 2, step: null, branch: null, head: null }] });
|
|
855
|
+
assert.deepEqual(received[0].body, { load: { ...initialLoad, rtt: 0 }, os: host, kit: null, term: 1, leader: false, work: [{ repo: "o/r", issue: 1, epoch: 2, step: null, branch: null, head: null }], jobs: { max: 0, live: 0, limitedUntil: 0, steps: [] } });
|
|
834
856
|
const server = await createNodeServer({ root, fleet: nodes, clock: () => now, listen: { port: 0 } });
|
|
835
857
|
t.after(() => new Promise(resolve => server.close(resolve)));
|
|
836
858
|
let sentTime = now;
|
|
837
859
|
const post = body => fetch(`http://127.0.0.1:${server.address().port}/message`, { method: "POST",
|
|
838
860
|
body: JSON.stringify(message({ kind: "heartbeat", body, time: new Date(sentTime++).toISOString() })) });
|
|
839
|
-
const body = { os: host, kit: null, term: 1, leader: true, work: [work], assigned: [{ repo: "o/r", issue: 1, epoch: 2 }] };
|
|
861
|
+
const body = { os: host, kit: null, term: 1, leader: true, work: [work], jobs: { max: 0, live: 0, limitedUntil: 0, steps: [] }, assigned: [{ repo: "o/r", issue: 1, epoch: 2 }] };
|
|
840
862
|
assert.equal((await post(body)).status, 202);
|
|
841
863
|
assert.deepEqual(readState(root, "peers").b, { time: now, messageTime: new Date(now).toISOString(), ...body });
|
|
842
864
|
assert.equal((await post({ ...body, work: [], assigned: [] })).status, 202);
|
|
@@ -1142,7 +1164,7 @@ test("promotion during the heartbeat send to A gives C the rebuilt assignment at
|
|
|
1142
1164
|
} });
|
|
1143
1165
|
assert.equal(sent.length, 2);
|
|
1144
1166
|
assert.equal(sent[1].url, "http://127.0.0.1:18082/message");
|
|
1145
|
-
assert.deepEqual(sent[1].body, { load: initialLoad, os: host, kit: null, leader: true, term: 2, work: [],
|
|
1167
|
+
assert.deepEqual(sent[1].body, { load: initialLoad, os: host, kit: null, leader: true, term: 2, work: [], jobs: { max: 0, live: 0, limitedUntil: 0, steps: [] },
|
|
1146
1168
|
assigned: [{ repo: "o/r", issue: 7, epoch: 3 }] });
|
|
1147
1169
|
});
|
|
1148
1170
|
|
|
@@ -1516,3 +1538,18 @@ test("serve rereads the fleet file and leaves join mode on a tick without restar
|
|
|
1516
1538
|
assert.ok(githubReads > 0);
|
|
1517
1539
|
assert.equal((await fetch(`${base}/message`, { method: "POST", body: "{}" })).status, 400);
|
|
1518
1540
|
});
|
|
1541
|
+
|
|
1542
|
+
test("HTTP carries a full 64 KiB job brief and checks job heartbeat fields", async t => {
|
|
1543
|
+
const root = fixture(t), server = await createNodeServer({ root, fleet, clock: () => now, listen: { port: 0 } });
|
|
1544
|
+
t.after(() => new Promise(resolve => server.close(resolve)));
|
|
1545
|
+
const post = body => fetch(`http://127.0.0.1:${server.address().port}/message`, { method: "POST", body: JSON.stringify(body) });
|
|
1546
|
+
const body = { id: "job", branch: "feat/job", base: "main", brief: "\n".repeat(65536), rounds: 3 };
|
|
1547
|
+
assert.equal((await post(message({ kind: "codex-job", body }))).status, 202);
|
|
1548
|
+
assert.equal(readState(root, "queue")[0].body.brief.length, 65536);
|
|
1549
|
+
const jobs = { max: 6, live: 1, limitedUntil: 0, steps: [{ id: "job", step: "implement exit 0" }] };
|
|
1550
|
+
assert.equal((await post(message({ kind: "heartbeat", body: { kit: null, term: 1, leader: false, jobs } }))).status, 202);
|
|
1551
|
+
assert.deepEqual(readState(root, "peers").b.jobs, jobs);
|
|
1552
|
+
for (const change of [{ max: -1 }, { live: 1.5 }, { limitedUntil: "no" }, { steps: [{ id: "../bad", step: "x" }] }, { steps: [{ id: "job", step: "x".repeat(121) }] }]) {
|
|
1553
|
+
assert.equal((await post(message({ kind: "heartbeat", body: { kit: null, term: 1, leader: false, jobs: { ...jobs, ...change } } }))).status, 400);
|
|
1554
|
+
}
|
|
1555
|
+
});
|
package/src/cli/fleet-state.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { commonDirOf } from "./ledger.mjs";
|
|
5
5
|
|
|
6
|
-
const FILES = ["election", "proposal", "work", "assignments", "questions", "seen", "queue", "outbox", "dead", "peers", "node", "plans", "answers", "said", "inbox", "watched", "github"];
|
|
6
|
+
const FILES = ["election", "proposal", "work", "assignments", "questions", "seen", "queue", "outbox", "dead", "peers", "node", "plans", "answers", "said", "inbox", "watched", "github", "jobs", "jobs-local"];
|
|
7
7
|
|
|
8
8
|
/** State is private to git's shared directory, outside every worktree's tracked files. */
|
|
9
9
|
export function stateDir(root = process.cwd()) {
|
package/src/cli/fleet.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { checkoutRootOf } from "./checkout-root.mjs";
|
|
|
10
10
|
import { runGh } from "./gh-run.mjs";
|
|
11
11
|
import { gitOut, originOf } from "./git-read.mjs";
|
|
12
12
|
import { sendPushed, validPlatformBranch } from "./fleet-platform.mjs";
|
|
13
|
+
import { DISPATCH_VERBS, parseDispatchArgs, runDispatch } from "./fleet-dispatch.mjs";
|
|
13
14
|
import { TALK_VERBS, parseTalkArgs, runTalk } from "./fleet-talk.mjs";
|
|
14
15
|
import { highestTerm, latestLeader, readState, writeState } from "./fleet-state.mjs";
|
|
15
16
|
import { confirmLeader, nodeStatus, serveNode, startNode, stopNode } from "./fleet-node.mjs";
|
|
@@ -17,7 +18,7 @@ import { createKey, validateKey, pairingDecision, readPairing } from "./fleet-pa
|
|
|
17
18
|
import { effectiveFleet, readDiscovered } from "./fleet-discover.mjs";
|
|
18
19
|
|
|
19
20
|
const SIZES = ["S", "M", "L"];
|
|
20
|
-
const USAGE = "usage: qc fleet init [--self <id>] [--nodes <id:weight:size,...>] [--port <port>] [--secret <hex>] [--addresses <id@host:port,...>] [--force] | next [--repo <o/r>] [--all] | status [--repo <o/r>] | plan <issue> --file <path> | ask <issue> --file <path> | say <node-id|leader> --file <path> | approve <message-id> [--changes] [--file <path>] | answer <message-id> --file <path> | show <message-id> | start [--leader] | serve [--leader] | stop | allow <code> | deny <code> | accept <code> | confirm-leader | progress <issue> --step plan|code|review|merge [--branch <b>] [--head <sha40>] | owns <issue> | pushed <issue> --branch <b> --head <sha40>";
|
|
21
|
+
const USAGE = "usage: qc fleet init [--self <id>] [--nodes <id:weight:size,...>] [--port <port>] [--secret <hex>] [--addresses <id@host:port,...>] [--force] | next [--repo <o/r>] [--all] | status [--repo <o/r>] | plan <issue> --file <path> | ask <issue> --file <path> | say <node-id|leader> --file <path> | approve <message-id> [--changes] [--file <path>] | answer <message-id> --file <path> | show <message-id> | start [--leader] [--jobs <n>] | job --brief <file> --branch <b> --base <ref> [--rounds 3] [--node <id>] [--id <id>] | jobs | cancel <id> | worker [--jobs <n>] | serve [--leader] [--jobs <n>] | stop | allow <code> | deny <code> | accept <code> | confirm-leader | progress <issue> --step plan|code|review|merge [--branch <b>] [--head <sha40>] | owns <issue> | pushed <issue> --branch <b> --head <sha40>";
|
|
21
22
|
|
|
22
23
|
function validAddress(address) {
|
|
23
24
|
if (typeof address !== "string" || !address || address.trim() !== address || address === "0.0.0.0") return false;
|
|
@@ -144,10 +145,11 @@ function parseArgs(argv) {
|
|
|
144
145
|
if (args.length !== 1 || !/^\d{6}$/.test(args[0])) throw new Error(`${verb} needs a 6-digit code`);
|
|
145
146
|
return { verb, code: args[0] };
|
|
146
147
|
}
|
|
148
|
+
if (DISPATCH_VERBS.includes(verb)) return parseDispatchArgs(verb, args);
|
|
147
149
|
if (TALK_VERBS.includes(verb)) return parseTalkArgs(verb, args);
|
|
148
150
|
const hasIssue = ["progress", "owns", "pushed"].includes(verb);
|
|
149
151
|
const rest = hasIssue ? args.slice(1) : args;
|
|
150
|
-
const allowed = verb === "init" ? ["--self", "--nodes", "--port", "--secret", "--addresses", "--force"] : verb === "next" ? ["--repo", "--all"] : verb === "status" ? ["--repo"] : ["start", "serve"].includes(verb) ? ["--leader"] : verb === "pushed" ? ["--branch", "--head"] : verb === "progress" ? ["--step", "--branch", "--head"] : ["stop", "owns", "confirm-leader"].includes(verb) ? [] : null;
|
|
152
|
+
const allowed = verb === "init" ? ["--self", "--nodes", "--port", "--secret", "--addresses", "--force"] : verb === "next" ? ["--repo", "--all"] : verb === "status" ? ["--repo"] : ["start", "serve", "worker"].includes(verb) ? ["--leader", "--jobs"] : verb === "pushed" ? ["--branch", "--head"] : verb === "progress" ? ["--step", "--branch", "--head"] : ["stop", "owns", "confirm-leader"].includes(verb) ? [] : null;
|
|
151
153
|
if (!allowed) throw new Error(USAGE);
|
|
152
154
|
const options = { verb };
|
|
153
155
|
if (hasIssue) {
|
|
@@ -172,6 +174,7 @@ function parseArgs(argv) {
|
|
|
172
174
|
const branch = options["--branch"];
|
|
173
175
|
if (branch !== undefined && (!branch || /[\s~^:?*\[\\\x00-\x1f\x7f]/.test(branch) || /(^[-/.]|[/.]$|\.\.|@\{|\/\/|\.lock(?:\/|$)|\/\.)/.test(branch) || branch === "@")) throw new Error("--branch needs a valid branch name");
|
|
174
176
|
}
|
|
177
|
+
if (options["--jobs"] !== undefined && (!/^\d+$/.test(options["--jobs"]) || !Number.isSafeInteger(Number(options["--jobs"])))) throw new Error("--jobs needs a nonnegative integer");
|
|
175
178
|
return options;
|
|
176
179
|
}
|
|
177
180
|
|
|
@@ -272,7 +275,7 @@ export function runFleet(argv, { cwd = process.cwd(), env = process.env, gh = ru
|
|
|
272
275
|
}
|
|
273
276
|
if ((fleet.discover && !fleet.secret) || (!origin(cwd) && !options["--repo"])) return 0;
|
|
274
277
|
}
|
|
275
|
-
if (["start", "stop", "serve"].includes(options.verb)) {
|
|
278
|
+
if (["start", "stop", "serve", "worker"].includes(options.verb)) {
|
|
276
279
|
return runNodeVerb(options, { root: cwd, fleet, configuredFleet, env, gh, git, origin, say, warn, node }).catch(error => { warn(error.message); return 1; });
|
|
277
280
|
}
|
|
278
281
|
if (options.verb === "confirm-leader") {
|
|
@@ -283,6 +286,7 @@ export function runFleet(argv, { cwd = process.cwd(), env = process.env, gh = ru
|
|
|
283
286
|
const localRepo = origin(cwd);
|
|
284
287
|
const repo = (options["--repo"] ?? localRepo)?.toLowerCase();
|
|
285
288
|
if (!repo) throw new Error("--repo is required when origin has no repository");
|
|
289
|
+
if (DISPATCH_VERBS.includes(options.verb)) return runDispatch(options, { root: cwd, fleet, repo, say, ...node }).catch(error => { warn(error.message); return 1; });
|
|
286
290
|
if (TALK_VERBS.includes(options.verb)) {
|
|
287
291
|
return runTalk(options, { root: cwd, fleet, repo, gh, say, node }).catch(error => { warn(error.message); return 1; });
|
|
288
292
|
}
|
|
@@ -346,7 +350,7 @@ export function runFleet(argv, { cwd = process.cwd(), env = process.env, gh = ru
|
|
|
346
350
|
}
|
|
347
351
|
|
|
348
352
|
async function runNodeVerb(options, { root, fleet, configuredFleet, env, gh, git, origin, say, warn, node }) {
|
|
349
|
-
const deps = { gh, git, ...node, root, fleet, configuredFleet, env, fleetFile: fleetPath(env), leader: options["--leader"] === true };
|
|
353
|
+
const deps = { gh, git, ...node, root, fleet, configuredFleet, env, fleetFile: fleetPath(env), leader: options["--leader"] === true, jobs: Number(options["--jobs"] ?? (options.verb === "worker" ? 6 : 0)) };
|
|
350
354
|
if (options.verb === "serve") {
|
|
351
355
|
const kitRoot = fileURLToPath(new URL("../../../../", import.meta.url));
|
|
352
356
|
const kit = gitOut(kitRoot, "rev-parse", "HEAD")?.trim() || null;
|
|
@@ -354,7 +358,7 @@ async function runNodeVerb(options, { root, fleet, configuredFleet, env, gh, git
|
|
|
354
358
|
const server = await serveNode({ ...deps, holdLabel, repo: origin(root) ?? "qc/fleet", kit, warn });
|
|
355
359
|
return new Promise(resolve => server.once("close", () => resolve(0)));
|
|
356
360
|
}
|
|
357
|
-
if (options.verb
|
|
361
|
+
if (["start", "worker"].includes(options.verb)) {
|
|
358
362
|
const result = await startNode(deps);
|
|
359
363
|
say(`fleet node ${result.already ? "already running" : "started"}: ${fleet.self}`);
|
|
360
364
|
} else {
|
package/src/cli/fleet.test.mjs
CHANGED
|
@@ -316,7 +316,11 @@ test("next prints the oldest five or all, exits 3 when empty, and status adds th
|
|
|
316
316
|
|
|
317
317
|
test("init routes through qc from an empty folder, creates mode 0600 and refuses replacement", t => {
|
|
318
318
|
const guide = readFileSync(new URL("../../../../docs/fleet.md", import.meta.url), "utf8");
|
|
319
|
-
|
|
319
|
+
const worker = guide.split("## Codex worker\n")[1]?.split("## Pair the PCs\n")[0];
|
|
320
|
+
const pairing = guide.split("## Pair the PCs\n")[1];
|
|
321
|
+
assert.ok(worker && worker.trim().split("\n").length <= 40);
|
|
322
|
+
assert.ok(pairing && pairing.trim().split("\n").length <= 40);
|
|
323
|
+
for (const verb of ["worker", "job", "jobs", "cancel"]) assert.ok(worker.includes(`qc fleet ${verb}`));
|
|
320
324
|
assert.match(guide, /QC_FLEET_FILE/);
|
|
321
325
|
assert.match(guide, /active.*false/);
|
|
322
326
|
const reference = readFileSync(new URL("../../../../docs/reference.md", import.meta.url), "utf8");
|
|
@@ -645,3 +649,17 @@ test("start migrates keys, leader creates secret, and pairing CLI and status sha
|
|
|
645
649
|
assert.equal(f.run(["allow", "123"], { node: { clock: () => now } }).code, 1);
|
|
646
650
|
assert.equal(f.run(["accept", code], { node: { clock: () => now } }).code, 1);
|
|
647
651
|
});
|
|
652
|
+
|
|
653
|
+
for (const [verb, count] of [["worker", 6], ["worker", 2], ["start", 3]]) test(`CLI ${verb} starts ${count} job slots`, async t => {
|
|
654
|
+
const f = fixture(t);
|
|
655
|
+
f.run(["init", "--self", "a1", "--nodes", "a1:1:L", "--addresses", "a1@127.0.0.1:8080", "--secret", "ab".repeat(32)]);
|
|
656
|
+
let instance, args;
|
|
657
|
+
const result = await f.run([verb, ...(count === 6 ? [] : ["--jobs", String(count)])], { node: {
|
|
658
|
+
spawn: (_command, argv, opts) => { args = argv; instance = opts.env.QC_FLEET_INSTANCE; return { pid: 456, once() {}, unref() {} }; },
|
|
659
|
+
kill: () => {}, clock: () => 1000, fetch: async () => ({ status: 200, json: async () => ({ ok: true, instance }) }),
|
|
660
|
+
} });
|
|
661
|
+
assert.equal(result.code, 0, result.errors.join("\n"));
|
|
662
|
+
assert.equal(readState(f.cwd, "node").jobs.max, count);
|
|
663
|
+
assert.deepEqual(args.slice(-2), ["--jobs", String(count)]);
|
|
664
|
+
for (const bad of ["-1", "1.5", "no", "9007199254740992"]) assert.equal((await f.run([verb, "--jobs", bad])).code, 1);
|
|
665
|
+
});
|
package/src/cli/pr-guard.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { checkoutRootOf } from "./checkout-root.mjs";
|
|
|
8
8
|
import { branchAt, originOf, repoOfSpelling } from "./git-read.mjs";
|
|
9
9
|
import { runGh } from "./gh-run.mjs";
|
|
10
10
|
import { readyProblems } from "./legs.mjs";
|
|
11
|
+
import { load } from "../config.mjs";
|
|
11
12
|
import { cdTarget, commandEnv, commandWords, segmentsOf } from "./shell-command.mjs";
|
|
12
13
|
|
|
13
14
|
const deny = (reason) => ({ hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: reason } });
|
|
@@ -106,6 +107,7 @@ export function decidePr(call, { gh = runGh, problems = readyProblems } = {}) {
|
|
|
106
107
|
const options = { ...optionsOf(words.filter((_, i) => i !== group && i !== verbAt)), verb: words[verbAt] };
|
|
107
108
|
const root = checkoutRootOf(cwd);
|
|
108
109
|
if (!root || !existsSync(path.join(root, "qc.config.json"))) continue;
|
|
110
|
+
if (!load(root).ready.enforce) continue;
|
|
109
111
|
const origin = originOf(root);
|
|
110
112
|
if (!origin) continue;
|
|
111
113
|
const ghEnv = { ...settings(process.env), ...env, ...settings(commandEnv(segment)) };
|
|
@@ -15,7 +15,7 @@ function workspace(t) {
|
|
|
15
15
|
git("init", "-q");
|
|
16
16
|
git("checkout", "-qb", "feat/206-pr-guard");
|
|
17
17
|
git("remote", "add", "origin", "https://github.com/o/r.git");
|
|
18
|
-
writeFileSync(path.join(cwd, "qc.config.json"),
|
|
18
|
+
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ ready: { enforce: true } }));
|
|
19
19
|
return cwd;
|
|
20
20
|
}
|
|
21
21
|
const call = (cwd, command, extra = {}) => ({ cwd, tool_name: "Bash", hook_event_name: "PreToolUse", tool_input: { command }, ...extra });
|
|
@@ -29,6 +29,14 @@ test("create requires the controller and a draft", (t) => {
|
|
|
29
29
|
assert.equal(decidePr(call(cwd, "gh pr create --draft"), { gh: emptyGh }), null);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
test("the guard is off unless the repository sets ready.enforce", (t) => {
|
|
33
|
+
const cwd = workspace(t);
|
|
34
|
+
writeFileSync(path.join(cwd, "qc.config.json"), "{}");
|
|
35
|
+
for (const command of ["gh pr create", "gh pr ready 7"]) {
|
|
36
|
+
assert.equal(decidePr(call(cwd, command), { gh: () => assert.fail("no gh call when the guard is off") }), null);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
32
40
|
test("only Bash PreToolUse in a configured origin checkout is guarded", (t) => {
|
|
33
41
|
const cwd = workspace(t);
|
|
34
42
|
for (const command of ["echo 'gh pr create'", "gh pr view", "gh pr create -R other/repo", "GH_REPO=other/repo gh pr create"]) {
|
|
@@ -102,13 +110,13 @@ test("ready uses the ledger for the PR head even when the checkout head differs"
|
|
|
102
110
|
git("add", ".");
|
|
103
111
|
git("commit", "-qm", "base");
|
|
104
112
|
git("branch", "base");
|
|
105
|
-
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ check: { base: "base" }, ready: { platforms: ["linux", "windows"] } }));
|
|
113
|
+
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ check: { base: "base" }, ready: { enforce: true, platforms: ["linux", "windows"] } }));
|
|
106
114
|
writeFileSync(path.join(cwd, "risk.mjs"), "process.platform;\n");
|
|
107
115
|
git("add", ".");
|
|
108
116
|
git("commit", "-qm", "risk");
|
|
109
117
|
const head = git("rev-parse", "HEAD");
|
|
110
118
|
git("checkout", "-q", "base");
|
|
111
|
-
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ check: { base: "base" }, ready: { platforms: ["linux", "windows"] } }));
|
|
119
|
+
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ check: { base: "base" }, ready: { enforce: true, platforms: ["linux", "windows"] } }));
|
|
112
120
|
const gh = () => JSON.stringify({ headRefOid: head });
|
|
113
121
|
assert.match(reason(decidePr(call(cwd, "gh pr ready 12"), { gh })), /linux, windows/);
|
|
114
122
|
appendLeg(cwd, { head, os: "linux", source: "local" });
|
package/src/cli/qc.mjs
CHANGED
|
@@ -49,6 +49,7 @@ const USAGE = `qc — architecture gates
|
|
|
49
49
|
record a failed run, or rerun the open test files before a push
|
|
50
50
|
qc ask --issue <n> "<question>" label the issue needs-user and post the question
|
|
51
51
|
qc budget report each role's end context, peaks at handoffAt, and advice on its limit
|
|
52
|
+
qc codex-loop --dir <run dir> --brief <name> [--rounds <n>] [--from-review <report>] [--skip-implement] [--base <ref>]
|
|
52
53
|
qc codex-implement --brief <file> --worktree <path> --progress <file> [--log <file>] [--max-runs <n>] [--role <scout|tests|implement|review>] [--review] [--report <file>] [--resume <id>] [--effort <low|medium|high>] [--wait-reset] [--max-hours <n>] [--poll-minutes <n>]
|
|
53
54
|
run a brief through codex exec as an implementer; done means the last non-empty progress line equals ALL TASKS DONE after trimming whitespace
|
|
54
55
|
the runner supplies the marker; write it as the last line, alone, only when the exit criteria hold; never quote it elsewhere or wait for it; exit 2 on a Codex limit
|
|
@@ -154,6 +155,11 @@ async function main() {
|
|
|
154
155
|
process.exit(await runLease(rest));
|
|
155
156
|
}
|
|
156
157
|
// The runner reads no configuration, so it runs from any folder.
|
|
158
|
+
if (command === "codex-loop") {
|
|
159
|
+
const { runCodexLoop } = await import("./codex-loop.mjs");
|
|
160
|
+
process.exitCode = await runCodexLoop(rest);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
157
163
|
if (command === "codex-implement") {
|
|
158
164
|
const { runCodexImplement } = await import("./codex-implement.mjs");
|
|
159
165
|
process.exitCode = await runCodexImplement(rest);
|
package/src/cli/watch.mjs
CHANGED
|
@@ -253,7 +253,7 @@ export async function runWatch(argv, { gh = readGh, say = console.log, warn = co
|
|
|
253
253
|
const leader = readState(cwd, "node").leader === true;
|
|
254
254
|
const messages = leader
|
|
255
255
|
? [...readState(cwd, "queue").filter(message => ["plan", "question"].includes(message.kind)),
|
|
256
|
-
...readState(cwd, "inbox").filter(message => message.kind
|
|
256
|
+
...readState(cwd, "inbox").filter(message => ["say", "codex-result"].includes(message.kind))]
|
|
257
257
|
: readState(cwd, "inbox");
|
|
258
258
|
messages.push(...pairingMessages(cwd, leader, now()));
|
|
259
259
|
const proposal = readState(cwd, "proposal");
|
package/src/config.mjs
CHANGED
|
@@ -11,7 +11,8 @@ export const CONFIG_FILE = "qc.config.json";
|
|
|
11
11
|
export const defaults = {
|
|
12
12
|
commentWatch: true,
|
|
13
13
|
github: { configDirs: { shawrylk: "~/.config/gh-personal" } },
|
|
14
|
-
ready
|
|
14
|
+
// The PR guard (draft on create, platform legs before ready) runs only when a repository sets enforce.
|
|
15
|
+
ready: { enforce: false, platforms: ["linux"] },
|
|
15
16
|
checkpoint: { maxAgeMinutes: 30 },
|
|
16
17
|
post: { aiLabel: true },
|
|
17
18
|
ci: { requiredChecks: [] },
|
|
@@ -801,6 +802,7 @@ export function load(root = process.cwd()) {
|
|
|
801
802
|
config.ready.platforms.some((os) => !["linux", "windows", "darwin"].includes(os)) || new Set(config.ready.platforms).size !== config.ready.platforms.length) {
|
|
802
803
|
throw new TypeError("ready.platforms must be a non-empty array of distinct linux, windows and darwin platforms");
|
|
803
804
|
}
|
|
805
|
+
if (typeof config.ready.enforce !== "boolean") throw new TypeError("ready.enforce must be a boolean");
|
|
804
806
|
if (!isPlainObject(config.check)) throw new TypeError("check must be an object");
|
|
805
807
|
const { related, sincePush, e2e, commands, base } = config.check;
|
|
806
808
|
const command = (value) => typeof value === "string" && value.trim().length > 0;
|