mirror of
https://github.com/garrytan/gstack.git
synced 2026-10-31 14:06:50 +01:00
* security: isolate every gstack Bun entry point from the audited checkout's .env and bunfig.toml Bun auto-loads .env, .env.local and .env.<NODE_ENV> from its cwd and runs a cwd bunfig.toml preload before the program starts. gstack runs inside the repo it audits, so a committed .env could steer state roots, the claude binary or spend caps, and a bunfig preload ran arbitrary code in every bin and hook. Every bun shebang, shell and skill caller, TypeScript spawn and compiled build now disables both (--no-env-file --config=/dev/null, bunIsolationArgs(), --no-compile-autoload-dotenv/bunfig), with a ratchet and hostile-fixture regressions. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: name the directly executed scripts in the isolation ratchet Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: follow the isolation flags in touchfiles, copy lists, recipe assertions and the harness pin Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix: keep browse/src/bun-child-config.ts unchanged so the native cookie qualification still binds Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(windows): the empty bunfig outlives its process so the timeline hook's detached repair child can read it Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * v1.91.159.0 security: gstack's Bun entry points ignore the audited repo's .env and bunfig.toml (S1) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: plan-mode render pattern accepts the isolation flags Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
66 lines
3.8 KiB
TypeScript
Executable File
66 lines
3.8 KiB
TypeScript
Executable File
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
/**
|
|
* gstack-contributor-mode — contributor-PR mode detection for /review (plan E3, decision D10).
|
|
*
|
|
* gstack-contributor-mode detect [--author <login>] [--pr <n>] [--contributor] [--base <ref>] [--policy-from base|head] [--json]
|
|
* gstack-contributor-mode instructions
|
|
*
|
|
* Prints `CONTRIBUTOR_MODE: on|off author=<login> source=flag|policy|collaborators|off`
|
|
* then, when on, the evidence-first instructions /review follows (the table and the
|
|
* credit-line rule). Maintainers come from .gstack/ship-policy.json on the base
|
|
* branch; without a list, repository push permission through the collaborators API;
|
|
* without either, off with the source recorded (CONTRIBUTOR_SOURCE_UNAVAILABLE on
|
|
* stderr). CODEOWNERS is never read. Exit 0 always for a completed detection.
|
|
* Logic: lib/contributor-mode.ts.
|
|
*/
|
|
import { spawnSync } from 'node:child_process';
|
|
import { CONTRIBUTOR_INSTRUCTIONS, detectContributorMode, renderDetection } from '../lib/contributor-mode';
|
|
import { EXIT, exitTableHelp } from '../lib/headless-artifacts';
|
|
import { resultLine } from '../lib/result-codes';
|
|
import { isUnavailable, loadPolicyFromBase, loadPolicyFromHead, resolveBaseBranch } from '../lib/ship-policy';
|
|
|
|
const HELP = `gstack-contributor-mode — is the PR author outside the maintainer set? (docs/ship-policy.md#contributor-mode)
|
|
|
|
detect [--author <login>] [--pr <n>] [--contributor] [--base <ref>] [--policy-from base|head] [--json]
|
|
--contributor forces the mode on (source=flag); --author skips the gh lookup
|
|
instructions print the evidence-first review instructions without detecting
|
|
|
|
${exitTableHelp()}`;
|
|
|
|
function flag(args: string[], name: string): string | undefined {
|
|
const i = args.indexOf(name);
|
|
return i >= 0 ? args[i + 1] : undefined;
|
|
}
|
|
|
|
function main(argv: string[]): number {
|
|
if (argv.includes('--help') || argv.includes('-h')) { process.stdout.write(HELP + '\n'); return EXIT.ok; }
|
|
const [cmd, ...rest] = argv;
|
|
if (cmd === 'instructions') { process.stdout.write(CONTRIBUTOR_INSTRUCTIONS + '\n'); return EXIT.ok; }
|
|
if (cmd !== 'detect') { process.stderr.write(`gstack-contributor-mode: unknown command ${cmd ?? ''}\n${HELP}\n`); return EXIT.usage; }
|
|
const root = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8', timeout: 15_000 });
|
|
if (root.status !== 0) { process.stderr.write('gstack-contributor-mode: not inside a git repository\n'); return EXIT.usage; }
|
|
const cwd = root.stdout.trim();
|
|
const prText = flag(rest, '--pr');
|
|
const pr = prText !== undefined ? Number(prText) : undefined;
|
|
if (pr !== undefined && (!Number.isInteger(pr) || pr <= 0)) { process.stderr.write('gstack-contributor-mode: --pr needs a positive number\n'); return EXIT.usage; }
|
|
|
|
let maintainers: string[] = []; let policySource = 'no ship policy';
|
|
if ((flag(rest, '--policy-from') ?? 'base') === 'head') { const l = loadPolicyFromHead(cwd); maintainers = l.policy.maintainers; policySource = l.source.label; }
|
|
else {
|
|
const base = resolveBaseBranch(cwd, flag(rest, '--base'));
|
|
const l = loadPolicyFromBase(cwd, base);
|
|
if (!isUnavailable(l)) { maintainers = l.policy.maintainers; policySource = l.source.label; }
|
|
else policySource = `policy source unavailable (${l.detail})`;
|
|
}
|
|
const d = detectContributorMode({ cwd, author: flag(rest, '--author'), pr, force: rest.includes('--contributor'), maintainers, policySource });
|
|
if (rest.includes('--json')) process.stdout.write(JSON.stringify(d) + '\n');
|
|
else {
|
|
process.stdout.write(renderDetection(d) + '\n');
|
|
if (d.mode === 'on') process.stdout.write('\n' + CONTRIBUTOR_INSTRUCTIONS + '\n');
|
|
}
|
|
if (d.error) process.stderr.write(resultLine('gstack-contributor-mode', d.error.code, d.error.message) + '\n');
|
|
return EXIT.ok;
|
|
}
|
|
|
|
process.exitCode = main(process.argv.slice(2));
|