mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-18 14:14:37 +01:00
Run each driven /ship phase as one command, count its calls, and stop it at 100 minutes (GST-2984) (#4451)
A driven /ship now runs each ship/DRIVER.md phase as one command, shows how many calls the run made, and stops itself with a printed line at 100 minutes. Why: measured /ship runs made 121 to 308 calls where the driver plans 9 to 12, and 10 of 12 ran past the 100-minute stop while those limits were only prose. Nothing to do: older ship records without `calls=` still validate and print. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#1 reader=outside-voice
This commit is contained in:
1 parent
9c6e0a0f85
commit
0ee5914628
19 files changed
+807
-49
No files matched your search
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
||||
/**
|
||||
* gstack-ship-phase — one ship/DRIVER.md phase as one call (G2).
|
||||
*
|
||||
* gstack-ship-phase run --dir <run dir> --phase <n> [--record <rec>] [--wait-s <s>] -- '<command>' ['<command>' ...]
|
||||
* Runs the phase's commands in order, each in the background (output in <run dir>/phases/<n>/<k>.log), and prints
|
||||
* only result lines: RAN: <k>/<N> exit=<c> with each command's CODE: lines, then PHASE: <n> done. A command still
|
||||
* running after --wait-s (default 200) keeps running and the run prints WAITING: and NEXT: rerun; rerun the same
|
||||
* command to resume. A failed command prints STOP: (exit 3); fix it and rerun the same command: finished commands
|
||||
* stay done (the journal keys each by the sha256 of its text). With --record, a stopped run or one past 100
|
||||
* minutes prints STOP: and runs nothing (exit 3); past 100 minutes it also writes <ledger dir>/stop.json.
|
||||
* gstack-ship-phase program
|
||||
* Prints the checked-in Capy phase program (lib/capy-ship-phase.js): PROGRAM: v<n> sha256=<h> bytes=<n>, then its
|
||||
* text as one JSON string. Load it the way capy/skill/gstack/SKILL.md loads the review pass program.
|
||||
*
|
||||
* Exit: 0 done or waiting · 3 stop · 2 usage. Logic: lib/ship-phase.ts, lib/ship-clock.ts.
|
||||
*/
|
||||
import { createHash } from 'node:crypto';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { runPhase } from '../lib/ship-phase';
|
||||
import { logShipCall } from '../lib/ship-call-log';
|
||||
|
||||
logShipCall('gstack-ship-phase');
|
||||
|
||||
const PROGRAM_VERSION = 1;
|
||||
const [command, ...rest] = process.argv.slice(2);
|
||||
const usage = (why: string) => { process.stderr.write(`gstack-ship-phase: ${why} (usage; see gstack-ship-phase --help)\n`); process.exit(2); };
|
||||
|
||||
if (!command || command === '--help' || command === '-h') {
|
||||
const lines = (await Bun.file(import.meta.path).text()).split('\n');
|
||||
(command ? console.log : console.error)(lines.slice(2, lines.indexOf(' */')).map(l => l.replace(/^ \* ?/, '')).join('\n'));
|
||||
process.exit(command ? 0 : 2);
|
||||
}
|
||||
if (command === 'program') {
|
||||
const text = fs.readFileSync(path.join(import.meta.dir, '..', 'lib', 'capy-ship-phase.js'), 'utf8');
|
||||
const sha = createHash('sha256').update(text).digest('hex');
|
||||
process.stdout.write(`PROGRAM: v${PROGRAM_VERSION} sha256=${sha} bytes=${Buffer.byteLength(text)}\n${JSON.stringify(text)}\n`);
|
||||
process.exit(0);
|
||||
}
|
||||
if (command !== 'run') usage(`unknown command '${command}'`);
|
||||
const sep = rest.indexOf('--');
|
||||
const opts = sep < 0 ? rest : rest.slice(0, sep);
|
||||
const commands = sep < 0 ? [] : rest.slice(sep + 1);
|
||||
const flag = (name: string) => { const i = opts.indexOf(`--${name}`); return i >= 0 ? opts[i + 1] : undefined; };
|
||||
const known = new Set(['--dir', '--phase', '--record', '--wait-s']);
|
||||
for (let i = 0; i < opts.length; i += 2) if (!known.has(opts[i]!) || opts[i + 1] === undefined) usage(`run: unexpected '${opts[i]}'`);
|
||||
const dir = flag('dir'), phase = flag('phase'), waitRaw = flag('wait-s');
|
||||
if (!dir) usage('run needs --dir <run dir>');
|
||||
if (!phase || !/^[A-Za-z0-9._-]+$/.test(phase)) usage('run needs --phase <n> (letters, digits, dot, underscore or dash)');
|
||||
if (!commands.length || commands.some(c => !c.trim())) usage("run needs the phase's commands after --, one argument each");
|
||||
if (waitRaw !== undefined && !/^\d+$/.test(waitRaw)) usage(`--wait-s '${waitRaw}' is not a whole number of seconds`);
|
||||
try {
|
||||
const out = await runPhase({ dir: dir!, phase: phase!, commands, record: flag('record'), waitS: waitRaw === undefined ? undefined : Number(waitRaw), cwd: process.cwd(), env: process.env });
|
||||
if (out.stdout.length) process.stdout.write(out.stdout.join('\n') + '\n');
|
||||
process.exit(out.exit);
|
||||
} catch (e: any) {
|
||||
process.stderr.write(`gstack-ship-phase: ${e?.message ?? e}\n`);
|
||||
process.exit(e?.exit === 3 ? 3 : 2);
|
||||
}
|
||||
+13
-1
@@ -3,7 +3,7 @@
|
||||
* gstack-ship-receipt — the handoff record, identifiers first (plan C5).
|
||||
*
|
||||
* gstack-ship-receipt write [--pr <n>] [--head <sha>] [--base <ref>] [--version <X>] [--gated-tree <sha>]
|
||||
* [--predecessor <sha>] [--gate <json|@file>] [--ci <json|@file>] [--spend-usd <n>]
|
||||
* [--predecessor <sha>] [--gate <json|@file>] [--ci <json|@file>] [--spend-usd <n>] [--calls <n> | --budget-record <rec>]
|
||||
* [--session-kind <k>] [--artifacts-consumed <n>/<m>] [--run <id>] [--thread <id>]
|
||||
* [--receipt <tree-receipt.json>] [--policy <label>] [--preregistration <text>] [--history <text>]
|
||||
* [--pregate <pregate.json>] [--issues <json|@file>] [--approval <line>]... [--approval-run <dir>]...
|
||||
@@ -66,6 +66,7 @@ import { historyLine, placeRunEntry, prReviewHistory, reviewRoute, runStub } fro
|
||||
import { grantAt, readReviewRoundGrants } from '../lib/review-round-grant';
|
||||
import { readMechanicalLines } from '../lib/ship-mechanical';
|
||||
import { isRegistryUnavailable, loadRegistryFromBase } from '../lib/regen';
|
||||
import { runCalls } from '../lib/ship-clock';
|
||||
|
||||
const HELP = `gstack-ship-receipt — the \`\`\`gstack-ship-receipt\`\`\` block (docs/ship-policy.md#ship-receipt)
|
||||
|
||||
@@ -108,6 +109,7 @@ const HELP = `gstack-ship-receipt — the \`\`\`gstack-ship-receipt\`\`\` block
|
||||
instead); any over (or absent) file exits 1 (DOCS_AUDIT_BLOCKED)
|
||||
|
||||
write flags: --pr --head --base --version --gated-tree --predecessor --gate <json|@file> --ci <json|@file> --spend-usd
|
||||
--calls <n> | --budget-record <rec> (calls=: the run's calls from the call log since gstack-ship-budget start; lib/ship-clock.ts)
|
||||
--session-kind --artifacts-consumed <n>/<m> --run --thread --receipt <tree-receipt.json> --policy --preregistration
|
||||
--history --queue-mode --pregate <pregate.json> (C8: refused unless current, green and every requires-remote obligation
|
||||
carries a receipt: PREGATE_STALE / PREGATE_LANE_FAILED / PREGATE_INCOMPLETE / PREGATE_REMOTE_UNCLEARED) --issues <json|@file>
|
||||
@@ -232,6 +234,15 @@ function ciCarried(base: string): ShipReceipt['ci_carried'] {
|
||||
try { const list = JSON.parse(r.stdout); return Array.isArray(list) && list.length ? list : undefined; } catch { return undefined; }
|
||||
}
|
||||
|
||||
/** calls= (G2): --calls <n>, or the run's count from the call log through its budget record; absent when neither is given or the log holds no row. */
|
||||
function callsArg(rest: string[]): number | undefined {
|
||||
const raw = flag(rest, '--calls');
|
||||
if (raw !== undefined) { if (!/^\d+$/.test(raw)) throw new Error(`--calls '${raw}' is not a whole number`); return Number(raw); }
|
||||
const record = flag(rest, '--budget-record');
|
||||
if (record === undefined) return undefined;
|
||||
try { return runCalls(record, process.env) ?? undefined; } catch (e: any) { throw new Error(`--budget-record ${record}: ${e.message}`); }
|
||||
}
|
||||
|
||||
function cmdWrite(rest: string[], json: boolean): number {
|
||||
const repoRoot = git(['rev-parse', '--show-toplevel']) ?? process.cwd();
|
||||
const checkedOut = git(['rev-parse', 'HEAD'], repoRoot);
|
||||
@@ -350,6 +361,7 @@ function cmdWrite(rest: string[], json: boolean): number {
|
||||
tree: tree?.tree, gate_reuse: tree ? `${tree.gate_reuse} (${tree.gate_reuse_reason})` : undefined,
|
||||
gate: jsonArg(flag(rest, '--gate')), ci: jsonArg(flag(rest, '--ci')), ci_carried: carried,
|
||||
spend_usd: flag(rest, '--spend-usd') !== undefined ? (Number.isFinite(Number(flag(rest, '--spend-usd'))) ? Number(flag(rest, '--spend-usd')) : flag(rest, '--spend-usd')) : undefined,
|
||||
calls: callsArg(rest),
|
||||
session_kind: sessionKind, artifacts_consumed: flag(rest, '--artifacts-consumed'), run: flag(rest, '--run'), thread: flag(rest, '--thread'),
|
||||
policy: flag(rest, '--policy') ?? tree?.policy, queue_mode: flag(rest, '--queue-mode'), preregistration: flag(rest, '--preregistration'), history: flag(rest, '--history'),
|
||||
...pregate, issues: issuesFile ? receiptIssuesFrom(issuesFile) : undefined, approval: approval.kind === 'ok' ? approval.approval : undefined,
|
||||
|
||||
Reference in new issue
Block a user