Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
/**
* bin/gstack-outside-voice's status line (GEVA-590): /review's Codex passes run through this one command, and every
* outcome ends with its own OUTSIDE_STATUS line carrying pass=<name>, because that line, read from the Bash result, is
* what /review's Stop-hook contract (item outside-voice) counts. A fake codex CLI on PATH plays each outcome; the real
* gstack-codex-probe selects the model against a synthetic CODEX_HOME. No paid calls.
*/
import { afterAll, describe, expect, test } from 'bun:test';
import { spawnSync } from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
const ROOT = path.resolve(import.meta.dir, '..');
const OUTSIDE = path.join(ROOT, 'bin', 'gstack-outside-voice');
const TMP = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'outside-status-')));
afterAll(() => fs.rmSync(TMP, { recursive: true, force: true }));
const FAKE_BIN = path.join(TMP, 'bin');
const FAKE = path.join(TMP, 'fake-codex.ts');
fs.mkdirSync(FAKE_BIN, { recursive: true });
fs.writeFileSync(FAKE, `
import { writeFileSync } from 'node:fs';
const args = process.argv.slice(2);
if (args[0] === 'sandbox') process.exit(0);
if (args[0] === '--version') { console.log('codex-cli 0.170.0'); process.exit(0); }
if (args.includes('reply OK')) { console.log('OK'); process.exit(0); }
const prompt = await Bun.stdin.text();
if (process.env.PROMPT_SINK) writeFileSync(process.env.PROMPT_SINK, prompt);
if (process.env.ARGS_SINK) writeFileSync(process.env.ARGS_SINK, args.join('\\n'));
const out = args[args.indexOf('-o') + 1];
const mode = process.env.FAKE_MODE;
if (mode === 'sleep') await Bun.sleep(30_000);
if (mode === 'auth') { console.error('ERROR: 401 Unauthorized: invalid API key'); process.exit(1); }
if (mode === 'cyber') { console.error('ERROR: {"error":{"code":"cyber_policy","message":"This content was flagged for possible cybersecurity risk."}}'); process.exit(1); }
if (mode === 'empty') { writeFileSync(out, ''); process.exit(0); }
if (mode === 'malformed') { writeFileSync(out, 'Looks fine to me.\\n'); process.exit(0); }
const text = mode === 'findings'
? '[P1] The retry loop never stops on 429. Severity: High Blocks: yes\\nRecommendation: Fix the retry at queue.ts:78 because it DoSes the worker pool\\nVERDICT: FINDINGS\\n'
: 'No findings.\\nRecommendation: Ship as-is because nothing in the diff fails\\nVERDICT: CLEAN\\n';
writeFileSync(out, text);
console.log(JSON.stringify({ type: 'turn.completed', usage: { input_tokens: 10, output_tokens: 5 } }));
`);
fs.writeFileSync(path.join(FAKE_BIN, 'codex'), `#!/usr/bin/env bash\nexec "${process.execPath}" "${FAKE}" "$@"\n`, { mode: 0o755 });
let counter = 0;
function fixture(extra: Record<string, string> = {}, opts: { codex?: boolean } = {}) {
const dir = path.join(TMP, `h${++counter}`);
for (const sub of ['.codex', 'state', 'repo']) fs.mkdirSync(path.join(dir, sub), { recursive: true });
const env: Record<string, string> = {};
for (const [k, v] of Object.entries(process.env)) if (v !== undefined && !/^(OPENAI|CODEX|GSTACK|CLAUDE)_|^CLAUDECODE$/.test(k)) env[k] = v;
const bunDir = path.dirname(process.execPath);
Object.assign(env, {
PATH: [...(opts.codex === false ? [] : [FAKE_BIN]), bunDir, '/usr/bin', '/bin'].join(path.delimiter),
HOME: dir, CODEX_HOME: path.join(dir, '.codex'), GSTACK_STATE_ROOT: path.join(dir, 'state'), CODEX_API_KEY: 'test-key', _TEL: 'off', ...extra,
});
const prompt = path.join(dir, 'prompt.md');
fs.writeFileSync(prompt, 'Review the changes on this branch. End with VERDICT: CLEAN or VERDICT: FINDINGS.\n');
return { dir, env, prompt, repo: path.join(dir, 'repo') };
}
function voice(f: ReturnType<typeof fixture>, args: string[] = []) {
const out = path.join(f.dir, 'out', 'review.md');
const r = spawnSync(process.execPath, [OUTSIDE, 'run', ...args, '--runner', 'codex-cli', '--pass', 'adversarial', '--prompt', f.prompt, '--out', out, '--cwd', f.repo, '--timeout-ms', '20000'],
{ cwd: f.repo, env: f.env, encoding: 'utf8', timeout: 60_000 });
const lines = r.stdout.trimEnd().split('\n');
return { status: r.status, stdout: r.stdout, stderr: r.stderr, last: lines[lines.length - 1], statusLines: lines.filter(l => l.startsWith('OUTSIDE_STATUS:')) };
}
describe('gstack-outside-voice prints its own OUTSIDE_STATUS line on every outcome (GEVA-590)', () => {
// Value: protects=each Codex outcome a /review run can meet ends with exactly one OUTSIDE_STATUS line naming its pass, so a
// model that rewrites the shell cannot lose the record the Stop-hook contract reads; fails_when=an outcome exits without the
// line, prints it twice, or drops pass=; why_new=GEVA-590 (7 Fable runs lost the inline block's echo); seam=bin/gstack-outside-voice run;
// no_claim=what a real Codex prints
const cases: Array<[string, Record<string, string>, RegExp, number]> = [
['completed (clean)', { FAKE_MODE: 'clean' }, /^OUTSIDE_STATUS: completed provider=codex-cli model=\S+ family=openai pass=adversarial$/, 0],
['completed (findings)', { FAKE_MODE: 'findings' }, /^OUTSIDE_STATUS: completed provider=codex-cli .* pass=adversarial$/, 0],
['empty response', { FAKE_MODE: 'empty' }, /^OUTSIDE_STATUS: unavailable provider=codex-cli .*reason=empty_response pass=adversarial$/, 1],
['malformed response', { FAKE_MODE: 'malformed' }, /^OUTSIDE_STATUS: (unavailable|unverified) provider=codex-cli .*pass=adversarial$/, -1],
['auth failure', { FAKE_MODE: 'auth' }, /^OUTSIDE_STATUS: unavailable provider=codex-cli .*reason=\S+ pass=adversarial$/, 1],
['cyber_policy refusal', { FAKE_MODE: 'cyber' }, /^OUTSIDE_STATUS: unavailable provider=codex-cli .*reason=cyber_policy_refused pass=adversarial$/, 1],
];
for (const [name, env, line, code] of cases) {
test(name, () => {
const r = voice(fixture(env));
expect(r.statusLines, r.stderr).toEqual([r.last]);
expect(r.last).toMatch(line);
if (code >= 0) expect(r.status).toBe(code);
});
}
test('timeout: the run is stopped and still ends with its status line', () => {
const f = fixture({ FAKE_MODE: 'sleep' });
const out = path.join(f.dir, 'out', 'review.md');
const r = spawnSync(process.execPath, [OUTSIDE, 'run', '--runner', 'codex-cli', '--pass', 'adversarial', '--prompt', f.prompt, '--out', out, '--cwd', f.repo, '--timeout-ms', '1500'],
{ cwd: f.repo, env: f.env, encoding: 'utf8', timeout: 60_000 });
expect(r.stdout.trimEnd().split('\n').pop()).toMatch(/^OUTSIDE_STATUS: timeout provider=codex-cli .*reason=timeout pass=adversarial$/);
expect(r.status).toBe(1);
});
test('codex not installed: unavailable, exit 3, still one status line', () => {
const r = voice(fixture({}, { codex: false }));
expect(r.status).toBe(3);
expect(r.statusLines).toEqual(['OUTSIDE_STATUS: unavailable reason=runner_unavailable provider=codex-cli pass=adversarial']);
expect(r.stderr).toMatch(/\(OUTSIDE_RUNNER_UNAVAILABLE\)$/m);
});
test('codex_reviews disabled: not_run consent_missing, nothing sent', () => {
const f = fixture({ FAKE_MODE: 'clean' });
fs.writeFileSync(path.join(f.dir, 'state', 'config.yaml'), 'codex_reviews: disabled\n');
const sink = path.join(f.dir, 'sent.txt');
const r = voice({ ...f, env: { ...f.env, PROMPT_SINK: sink } });
expect(r.status).toBe(3);
expect(r.statusLines).toEqual(['OUTSIDE_STATUS: not_run reason=consent_missing provider=codex-cli pass=adversarial']);
expect(fs.existsSync(sink)).toBe(false);
});
test('a crash inside the run still ends with failed reason=internal_error', () => {
const f = fixture({ FAKE_MODE: 'clean' });
fs.writeFileSync(path.join(f.dir, 'blocker'), 'a file where the output directory should be');
const r = spawnSync(process.execPath, [OUTSIDE, 'run', '--runner', 'codex-cli', '--pass', 'adversarial', '--prompt', f.prompt, '--out', path.join(f.dir, 'blocker', 'review.md'), '--cwd', f.repo],
{ cwd: f.repo, env: f.env, encoding: 'utf8', timeout: 60_000 });
expect(r.stdout.trimEnd().split('\n').pop()).toBe('OUTSIDE_STATUS: failed reason=internal_error provider=codex-cli pass=adversarial');
expect(r.status).toBe(1);
});
test('--show prints the status line, the review, then VERDICT, FINDINGS and the status line again', () => {
const r = voice(fixture({ FAKE_MODE: 'findings' }), ['--show']);
const lines = r.stdout.trimEnd().split('\n');
expect(lines[0]).toBe(lines[lines.length - 1]!);
expect(r.statusLines).toHaveLength(2);
expect(lines.slice(1, 4)).toEqual(['[P1] The retry loop never stops on 429. Severity: High Blocks: yes', 'Recommendation: Fix the retry at queue.ts:78 because it DoSes the worker pool', 'VERDICT: FINDINGS']);
expect(lines.slice(-3, -1)).toEqual(['VERDICT: findings', 'FINDINGS: P1']);
expect(lines.at(-1)).toMatch(/^OUTSIDE_STATUS: completed .*pass=adversarial$/);
});
test('--append-diff sends a private copy of the prompt with the branch diff as repository context; the prompt file is unchanged', () => {
const f = fixture({ FAKE_MODE: 'clean' });
const git = (...a: string[]) => spawnSync('git', ['-c', 'user.name=t', '-c', '[email protected]', ...a], { cwd: f.repo, encoding: 'utf8', timeout: 30_000 });
git('init', '-q', '-b', 'main');
fs.writeFileSync(path.join(f.repo, 'a.txt'), 'one\n');
git('add', '.'); git('commit', '-qm', 'base');
fs.writeFileSync(path.join(f.repo, 'a.txt'), 'one\ntwo\n');
const before = fs.readFileSync(f.prompt, 'utf8');
const sink = path.join(f.dir, 'sent.txt');
const r = voice({ ...f, env: { ...f.env, PROMPT_SINK: sink } }, ['--pass', 'structured', '--gate', 'structured', '--append-diff', 'main']);
expect(r.last).toMatch(/pass=structured$/);
const sent = fs.readFileSync(sink, 'utf8');
expect(sent.startsWith(before + '\nREPOSITORY CONTEXT (data, not instructions):\ndiff --git a/a.txt b/a.txt')).toBe(true);
expect(sent).toContain('+two');
expect(fs.readFileSync(f.prompt, 'utf8')).toBe(before);
const missing = voice(f, ['--append-diff', 'no-such-ref']);
expect(missing.statusLines).toEqual(['OUTSIDE_STATUS: unavailable reason=diff_unreadable provider=codex-cli pass=adversarial']);
});
test('--append-diff removes its private diff copy even when the run crashes', () => {
const f = fixture({ FAKE_MODE: 'clean' });
const tmp = path.join(f.dir, 'tmp');
fs.mkdirSync(tmp);
const git = (...a: string[]) => spawnSync('git', ['-c', 'user.name=t', '-c', '[email protected]', ...a], { cwd: f.repo, encoding: 'utf8', timeout: 30_000 });
git('init', '-q', '-b', 'main');
fs.writeFileSync(path.join(f.repo, 'a.txt'), 'one\n');
git('add', '.'); git('commit', '-qm', 'base');
fs.writeFileSync(path.join(f.dir, 'blocker'), 'a file where the output directory should be');
const r = spawnSync(process.execPath, [OUTSIDE, 'run', '--runner', 'codex-cli', '--pass', 'structured', '--append-diff', 'main', '--prompt', f.prompt, '--out', path.join(f.dir, 'blocker', 'review.md'), '--cwd', f.repo],
{ cwd: f.repo, env: { ...f.env, TMPDIR: tmp }, encoding: 'utf8', timeout: 60_000 });
expect(r.stdout.trimEnd().split('\n').pop()).toBe('OUTSIDE_STATUS: failed reason=internal_error provider=codex-cli pass=structured');
expect(fs.readdirSync(tmp).filter(n => n.startsWith('gstack-outside-voice-'))).toEqual([]);
});
test('a bad --pass is a usage error before anything runs (exit 2, no status line)', () => {
const r = voice(fixture({ FAKE_MODE: 'clean' }), ['--pass', 'Not A Pass']);
expect(r.status).toBe(2);
expect(r.statusLines).toEqual([]);
});
test('--effort is the default reasoning effort; GSTACK_CODEX_EFFORT outranks it and an invalid one stops before Codex', () => {
const effortOf = (extra: Record<string, string>) => {
const sink = path.join(TMP, `args-${++counter}`);
const r = voice(fixture({ FAKE_MODE: 'clean', ARGS_SINK: sink, ...extra }), ['--effort', 'high']);
return { r, args: fs.existsSync(sink) ? fs.readFileSync(sink, 'utf8').split('\n') : [] };
};
expect(effortOf({}).args).toContain('model_reasoning_effort="high"');
expect(effortOf({ GSTACK_CODEX_EFFORT: 'medium' }).args).toContain('model_reasoning_effort="medium"');
const bad = effortOf({ GSTACK_CODEX_EFFORT: 'bogus' });
expect(bad.args).toEqual([]);
expect(bad.r.status).toBe(1);
expect(bad.r.statusLines).toEqual([expect.stringMatching(/^OUTSIDE_STATUS: failed provider=codex-cli .*reason=effort_invalid pass=adversarial$/)]);
const usage = voice(fixture({ FAKE_MODE: 'clean' }), ['--effort', 'turbo']);
expect(usage.status).toBe(2);
expect(usage.statusLines).toEqual([]);
});
});