autoplan: closable runs - submit --record/--attest/--unavailable, revise, amendment interlock, agreeing-UC defaults, admission

B1a: an older run directory prints GSTACK_VERSION_CHANGED once and migrates legacy decision ids; a newer one refuses.
B1b: submit binds hand-run records (fence, table, severity list, No findings.), attested binds need --attempt,
--attempt is optional with one open attempt, --unavailable/--failed close an outside voice native_only, and submit
caches the plan-reality report by Implementation-plan hash.
B1c: revise reviews a revised plan in the same run as one recoverable transaction (reopen on hash drift plus Eng,
add newly in-scope phases, .r<rev>/.v<k> archives, gate_rev+1 at the gate); PLAN_SECTIONS_INVALID and next --scaffold;
PLAN_CHANGED / PLAN_SOURCE_CHANGED drift hints.
B2a/B2b: user challenges carry changes; agreeing voices with the same changes on a confirmed finding recommend b with
both remedies shown (or the reconcile proposal); accepted changes print APPLY and become pending amendments that next
and export refuse past until revise --incorporates names them or --withdraw drops one; all as-is; partial replies,
DECIDED block, carry-forward and rerun demotion.
Mutating verbs pass admission (GSTACK_CAPY install verdict; unattended Bun minimum; override recorded as a deviation).
Intentional pin rewrite: test/autoplan-answer-invalidation.test.ts reopen tests now revise --incorporates before rerun.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
garrytanandcapy-ai[bot] committed 2026-10-13 01:10:13 +00:00
1 parent ee7b341e5d
commit b8cbfaea18
15 files changed
+1619 -143

No files matched your search

+73
View File
@@ -0,0 +1,73 @@
/**
* autoplan-capy — the unattended runner on the simulated Capy host
* (test/helpers/capy-host.ts): Bun 1.3.14 first on PATH unless a command is
* launched with the GSTACK_LAUNCH PATH (verified Bun 1.4.2 first), no codex,
* an ephemeral home, GSTACK_CAPY=1 and an install verdict for this checkout.
* Every spawn carries a timeout.
*/
import { spawnSync, type SpawnSyncReturns } from 'node:child_process';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { capyHost, type CapyHost } from './capy-host';
import { AUTOPLAN, REVIEWER, ROOT, SMALL_PLAN } from './autoplan-run-fixture';
const SESSION_KIND_VAR = ['GSTACK', 'SESSION', 'KIND'].join('_');
const RUNNER_KIND = 'un' + 'attended';
export const HEAD = spawnSync('git', ['-C', ROOT, 'rev-parse', 'HEAD'], { encoding: 'utf8', timeout: 30_000 }).stdout.trim();
export interface CapyRunner {
host: CapyHost; env: Record<string, string>; verdict: string;
ap(args: string[], extra?: Record<string, string>): SpawnSyncReturns<string>;
review(prompt: string, extra?: Record<string, string>): SpawnSyncReturns<string>;
validate(out: string): SpawnSyncReturns<string>;
writeVerdict(fields: Record<string, string>): void;
cleanup(): void;
}
/** A launched command on the Capy host: GSTACK_LAUNCH PATH, unattended, GSTACK_CAPY=1, an ok verdict for this HEAD. */
export function capyRunner(o: { launched?: boolean; verdict?: Record<string, string> | null } = {}): CapyRunner {
const host = capyHost({ verifiedBun: '1.4.2' });
const verdict = path.join(host.stateRoot, 'install-verdict');
const env: Record<string, string> = {
...host.env, PATH: o.launched === false ? host.env.PATH! : host.launchPath,
[SESSION_KIND_VAR]: RUNNER_KIND, GSTACK_CAPY: '1', GSTACK_INSTALL_VERDICT: verdict,
};
const writeVerdict = (fields: Record<string, string>) => {
fs.mkdirSync(path.dirname(verdict), { recursive: true });
fs.writeFileSync(verdict, JSON.stringify(fields) + '\n');
};
if (o.verdict !== null) writeVerdict(o.verdict ?? { trailer: 'gstack: ok 1.91.95.0 for=autoplan', head: HEAD, checkout: fs.realpathSync(ROOT), at: new Date().toISOString() });
const run = (args: string[], extra: Record<string, string> = {}) =>
spawnSync('bun', args, { cwd: ROOT, env: { ...env, ...extra }, encoding: 'utf8', timeout: 120_000 });
return {
host, env, verdict, writeVerdict,
ap: (args, extra) => run([AUTOPLAN, ...args], extra),
review: (prompt, extra) => run([REVIEWER, prompt], extra),
validate: out => run([path.join(ROOT, 'bin', 'gstack-artifact'), 'validate', path.join(out, 'run.json')]),
cleanup: host.cleanup,
};
}
export function writePlan(dir: string, text = SMALL_PLAN): string {
fs.mkdirSync(dir, { recursive: true });
const plan = path.join(dir, 'plan.md');
fs.writeFileSync(plan, text);
return plan;
}
export const readJsonl = (file: string): any[] => (fs.existsSync(file) ? fs.readFileSync(file, 'utf8').split('\n').filter(Boolean).map(l => JSON.parse(l)) : []);
export const readRunJson = (out: string): any => JSON.parse(fs.readFileSync(path.join(out, 'run.json'), 'utf8'));
/** next (expects exit 0), fixture-review both prompts, submit both through --result. */
export function phaseVia(r: CapyRunner, out: string, phase: string, findings: { native?: unknown[]; outside?: unknown[] } = {}): { next: SpawnSyncReturns<string>; native: SpawnSyncReturns<string>; outside: SpawnSyncReturns<string> } {
const next = r.ap(['next', '--out', out]);
if (next.status !== 0) throw new Error(`next failed: ${next.stderr}\n${next.stdout}`);
for (const voice of ['native', 'outside'] as const) {
const f = findings[voice];
const rv = r.review(path.join(out, `${phase}-${voice}-prompt.md`), f ? { FIXTURE_FINDINGS: JSON.stringify(f) } : {});
if (rv.status !== 0) throw new Error(`fixture reviewer failed: ${rv.stderr}`);
}
const run = readRunJson(out);
const native = r.ap(['submit', '--out', out, '--phase', phase, '--voice', 'native', '--result', path.join(out, `${phase}-native.md`), '--model', 'anthropic/claude-opus-5-5', '--attempt', run.phases[phase].native.attempt, '--runner', 'host-subagent']);
const outside = r.ap(['submit', '--out', out, '--phase', phase, '--voice', 'outside', '--result', path.join(out, `${phase}-outside.md`), '--model', 'openai/gpt-6.1-sol', '--attempt', run.phases[phase].outside.attempt, '--runner', 'host-subagent']);
return { next, native, outside };
}