Files
gstack/lib/gate-outcomes.ts
T
Garry Tanandcapy-ai[bot] 90a170c941 v1.92.50.0 wave(autoplan): #3781 #3743 #3751 #3762 (#3788)
* fix(eval-plan): per-arm pilot projection and --seat-metered arms (#3653)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): guard tolerates Claude Code's cwd-reset footer and recovers after an unreadable init (#3651)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes (journal reader strips the cwd-reset footer; an init with no text block no longer locks the session)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: journal reader skips a failed or unreadable init, as invocation() does

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* feat(autoplan): --ceo-only runs the CEO review alone with zero questions (GST-537)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(eval-plan): all-seat pilot, single-attempt arm and --seat-metered CLI wiring

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(eval-plan): summed deviation adds arm deviations, matching the summed band (arms share rows)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes (test pins an unpriced seat-metered arm)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes (seat-metered declaration fixed per --out, price row still required, a real charge settles as spent)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test: classify autoplan-ceo-only in the Codex host metadata

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: a seat-metered arm that settles a charge is projected as a priced arm

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: select autoplan-ceo-only on the skills it runs; say it needs Claude Code

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(skills): /eval-plan --seat-metered and per-arm projection

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(eval-plan): skill prose stays under its context budget and carries no $N token

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test: run autoplan-ceo-only in the marathon lane

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(skills): a seat-metered arm leaves the seat set once it settles a charge

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: changelog entry for /autoplan --ceo-only

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(autoplan): init_failed covers unreadable init output and the cwd-reset line (#3651)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test: count the autoplan-ceo-only paid file in the shard inventory

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(autoplan): #3651 tests pass the test-code type ratchet

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(dx): CAP finding titles carry a one-line description (GBRA-223 claim 2)

The DX error contract told both autoplan DX voices to title capped findings
exactly CAP4:<path>:<item>, so gates, tasks and reconcile saw a bare code.
The title is now CAP4:<path>:<item> <what fails>; the grader already parses
that shape.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): reconcile pairs same-file findings that carry no line (GBRA-223 claim 1)

Plan reviews name files, rarely lines, and reconcile associated by location
only when both findings had a line, so findings both voices raised on one
file were filed new and native-only. A same-file pair with a missing line is
now associated as unverified (basis file), never confirmed; a CAP code no
longer counts in title comparison. DRIVER.md names submit --reconcile.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): open Critical and High findings reach the gate as apply items (GBRA-223 claim 3)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): a spend cap binds on every unattended host; --estimate-usd persists; DRIVER names --usage-usd (GBRA-223 claim 4)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): run binds complete api results, names a truncated response, --max-tokens; DRIVER documents run (GBRA-223 claim 6)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* feat(autoplan): carry an item-by-item answer when the later gate asks nothing new (GBRA-223 claim 7)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(dx): trim the compact error contract so plan-devex-review stays under its size pin

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes (p1b applies finding fixes, api attempts reserve no host default, cross-file title pairing, paired severity counted)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: review fixes (priced api reservations, no file-only twins, two-pass pairing, partial replies keep p1-dependent defaults open, outside refusal degrades)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* P7: record whose words answered a gate (--words-by agent:<id>), never carry an agent's own words, import each row under its own answerer (GEVA-2)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: review pass 2 (p1b needs --rec-hash after recommend; api calls send the output limit they reserve for)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* changelog: fragment for the /autoplan field-report wave (GST-672)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: captain record notes --words-by agent attribution

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test: follow finding apply items in approval-class and Captain flow tests; bind run-api limit to DEFAULT_MAX_TOKENS

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* wave autoplan: lower the gemini plan-devex-review pin to its exact size after #3781's DX trim

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): CAP titles on different paths never match by title in reconcile or confirm rounds (wave review)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): a truncated api call settles its cost and a retry is admitted afresh against the cap

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): an applied finding stays open until the revised plan is reviewed; a shared location alone never twins two findings

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(approval): a plan gate answered in an agent's own words is not owner approval

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(gate): a new answer replaces the earlier answer's authorship and words

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): a failed api call with no usage keeps its attempt open; reservations price the bound prompt (wave fix-check)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): a spend cap fails closed: only a call refused before sending keeps its attempt; a sent call with unknown usage settles at its reservation

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(autoplan): the 16384 output default applies to both providers; changelog for the wave's integrator fixes

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(autoplan): how run settles a failed api call; changelog scopes it to the native voice

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(autoplan): a spend cap fails closed on every exit of run; an unpriced model reserves the default once a cap is set

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(autoplan): every sent call settles; an unpriced model under a cap reserves the default

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(autoplan): DRIVER and help say a cap reserves in any session kind and how run settles a sent call

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>
2026-11-02 01:35:47 +00:00

233 lines
12 KiB
TypeScript

/**
* INV-1 gate outcome contract: every gate or outside review ends as
* `ran` (with findings or a verdict), `not_run` (gstack chose not to run it) or
* `unavailable` (it tried and could not). Each reason code maps to one state,
* one stable anchor in docs/troubleshooting.md and one fix action; the
* validator prints these lines and test/troubleshooting-anchors.test.ts checks
* every anchor exists. Add a row here before printing a new reason anywhere.
*/
export type GateState = 'ran' | 'not_run' | 'unavailable';
export interface GateOutcome {
state: GateState;
/** Stable `<a id>` in docs/troubleshooting.md. */
anchor: string;
/** What happened, in plain words; `<detail>` adds the real value (exit code, stderr line). */
summary: string;
fix: string;
}
export const GATE_OUTCOMES = {
sandbox_unavailable: {
state: 'unavailable', anchor: 'codex-sandbox-unavailable',
summary: "Codex's sandbox could not start here",
fix: 'enable unprivileged user namespaces for this container, or set GSTACK_CODEX_NO_SANDBOX=1',
},
commands_failed: {
state: 'unavailable', anchor: 'outside-review-commands-failed',
summary: 'the reviewer could not run commands or read the diff',
fix: 'read the reviewer stderr above, repair the environment it names, then re-run the review',
},
execution_failed: {
state: 'unavailable', anchor: 'outside-review-execution-failed',
summary: 'the reviewer process failed',
fix: 'read the provider diagnosis above (auth, model, network), repair it, then re-run the review',
},
timeout: {
state: 'unavailable', anchor: 'outside-review-timeout',
summary: 'the reviewer hit its time limit and was stopped',
fix: 're-run the review with a smaller scope, or check the provider status and network',
},
empty_response: {
state: 'unavailable', anchor: 'outside-review-empty-response',
summary: 'the reviewer returned no response',
fix: 'read the reviewer stderr above, then re-run the review',
},
review_refused: {
state: 'unavailable', anchor: 'outside-review-refused',
summary: 'the reviewer declined to review',
fix: 're-run the review; if it declines again, review the change natively',
},
truncated: {
state: 'unavailable', anchor: 'outside-review-truncated',
summary: 'the reviewer hit its output token limit and the response is cut off',
fix: 're-run with a larger --max-tokens (or a smaller prompt); a cut-off response never counts as a review',
},
missing_markers: {
state: 'unavailable', anchor: 'outside-review-missing-markers',
summary: 'the response lacks the markers this gate requires',
fix: 're-run the review; a response without its required markers never counts as a pass',
},
untagged_review: {
state: 'ran', anchor: 'outside-review-unverified',
summary: 'the review completed without severity tags or an explicit no-findings line',
fix: 'read the output above and decide; it is not a pass',
},
unparsed_severity: {
state: 'ran', anchor: 'outside-review-unparsed-severity',
summary: 'the review labels a finding with a P0-P3 severity in a form the parser cannot read',
fix: 'read the quoted line and the full reply above and decide; it is not a pass. Re-run the review asking for [P0]-[P3] or "P1:" labels, or re-check a corrected reply with bun lib/outside-review-result.ts --verdict <gate> <reply-file> from your gstack checkout (https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#outside-review-unparsed-severity)',
},
model_unusable: {
state: 'unavailable', anchor: 'codex-model-unusable',
summary: 'Codex could not use the selected model',
fix: 'set GSTACK_CODEX_MODEL=<supported-model> or fix model (and base_url for a custom provider) in your Codex config.toml',
},
quota_exhausted: {
state: 'unavailable', anchor: 'codex-quota-exhausted',
summary: "Codex refused the call for this account's usage limit",
fix: "wait for the reset time in Codex's message above, or add credits or a higher plan for that account; the model choice is fine. To re-check before gstack's 15-minute cache expires, set GSTACK_CODEX_PROBE_RETRY=1 (https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#codex-quota-exhausted)",
},
rate_limited: {
state: 'unavailable', anchor: 'codex-rate-limited',
summary: 'Codex rate-limited the review (HTTP 429), so it did not complete',
fix: 're-run the review in a minute; if 429s persist, check the account rate limits on the provider dashboard (https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#codex-rate-limited)',
},
helper_unavailable: {
state: 'unavailable', anchor: 'sourced-helper-location',
summary: 'the gstack Codex helper could not be loaded into this shell',
fix: 'run the skill from bash or zsh, or export GSTACK_ROOT=<install dir>; if the helper file is missing, re-run ./setup (https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#sourced-helper-location)',
},
probe_inconclusive: {
state: 'ran', anchor: 'codex-mode-unverified',
summary: 'the Codex model check timed out or hit a network error, so readiness is unverified',
fix: 'nothing to do now; the review itself is still checked, and a failure there is reported',
},
auth_failed: {
state: 'unavailable', anchor: 'codex-auth-failed',
summary: 'no Codex credentials were found',
fix: 'run codex login, or set the API key your Codex config.toml provider names in env_key',
},
disabled: {
state: 'not_run', anchor: 'outside-review-disabled',
summary: 'outside reviews are turned off (codex_reviews=disabled)',
fix: 'gstack-config set codex_reviews enabled',
},
consent_missing: {
state: 'not_run', anchor: 'outside-review-consent-missing',
summary: 'outside reviews are turned off (codex_reviews=disabled) or the gstack config could not be read, so no repository content was sent',
fix: 'gstack-config set codex_reviews enabled (or make config.yaml readable), then re-run; /codex and /claude-code still run when you ask for them (https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#outside-review-consent-missing)',
},
no_version_source: {
state: 'not_run', anchor: 'ship-no-version-source',
summary: 'no version source is configured, or release automation owns it',
fix: 'create VERSION, or write the version file path (for example package.json) to .gstack/version-path',
},
version_source_broken: {
state: 'unavailable', anchor: 'ship-version-source-broken',
summary: 'the configured version file is missing, empty, unreadable or malformed',
fix: 'fix that file, or correct --version-path / .gstack/version-path',
},
no_plan_bound: {
state: 'not_run', anchor: 'plan-audit-not-run',
summary: 'no plan is bound to this branch and no docs/designs/ file matches',
fix: 'add "Plan: <path>" to the PR body, or run /autoplan',
},
bun_missing: {
state: 'unavailable', anchor: 'learnings-bun-missing',
summary: 'bun not found on PATH, so learnings (or the timeline) could not be read',
fix: 'install Bun (https://bun.sh), then re-run ./setup',
},
learnings_unavailable: {
state: 'unavailable', anchor: 'learnings-unavailable',
summary: 'the learnings search failed, so prior learnings were not loaded',
fix: 'read the reason in parentheses; install Bun if it is missing, then re-run ./setup',
},
tmpdir_unwritable: {
state: 'unavailable', anchor: 'log-tmpdir-unwritable',
summary: 'could not create a temp file in ${TMPDIR:-/tmp}, so the entry was not recorded',
fix: 'point TMPDIR at a writable directory',
},
not_calibrated: {
state: 'not_run', anchor: 'plan-tune-not-calibrated',
summary: 'not calibrated: no recorded signals',
fix: 'answer more registered questions; run gstack-developer-profile --derive to recount',
},
variant_save_failed: {
state: 'unavailable', anchor: 'design-variant-save-failed',
summary: 'the paid image was received but could not be saved to the output path (a recovery copy is in the temp dir)',
fix: 'follow the printed fix (disk space, permissions or a new --output), then copy the recovery file from the printed path',
},
design_unavailable: {
state: 'unavailable', anchor: 'design-not-available',
summary: 'the design binary could not start (it exited, timed out, was killed at launch, or is not installed)',
fix: 'cd <gstack checkout> && ./setup',
},
taste_profile_unavailable: {
state: 'unavailable', anchor: 'design-taste-profile-unavailable',
summary: 'the project slug could not be resolved, so your taste profile was not loaded',
fix: 'run ./setup',
},
no_install_found: {
state: 'unavailable', anchor: 'gstack-no-install-found',
summary: 'no gstack install for this host was found from this shell',
fix: './setup --host <host> from your gstack checkout; ./setup --status shows it',
},
db_unreachable: {
state: 'unavailable', anchor: 'gbrain-db-unreachable',
summary: 'the gbrain database host is unreachable; your gbrain config is unchanged',
fix: 'check network or VPN, then re-run /sync-gbrain',
},
ingest_batch_refused: {
state: 'unavailable', anchor: 'memory-ingest-unattributed-failures',
summary: 'gbrain reported failures it did not attribute to a page, so nothing was marked saved',
fix: 're-run /sync-gbrain; after three refusals gstack finds and sets aside the page that breaks the batch',
},
reconcile_not_run: {
state: 'not_run', anchor: 'memory-reconcile-not-run',
summary: 'the post-upgrade transcript check did not run (gbrain missing, or the brain is remote over HTTP)',
fix: 'run /setup-gbrain, then gstack-memory-ingest --reconcile',
},
ingest_locked: {
state: 'not_run', anchor: 'memory-ingest-locked',
summary: 'another memory ingest is writing the state file',
fix: 'wait for it to finish, then re-run /sync-gbrain',
},
ingest_state_unsaved: {
state: 'unavailable', anchor: 'memory-ingest-state-unsaved',
summary: 'the ingest state file could not be saved',
fix: 'fix permissions or free disk space under your gstack state root, then re-run /sync-gbrain',
},
artifacts_not_indexed: {
state: 'unavailable', anchor: 'gbrain-artifacts-not-indexed',
summary: 'curated artifacts were pushed to git, but gbrain has 0 indexed pages for them',
fix: 'gbrain sync --source <id>, then re-run /sync-gbrain',
},
dream_unscoped: {
state: 'not_run', anchor: 'gbrain-dream-skipped',
summary: 'the installed gbrain cannot run only the call-graph phase, and the full dream cycle takes about 35 minutes',
fix: 'gstack-gbrain-install, then /sync-gbrain --dream',
},
cycle_freshness_unknown: {
state: 'unavailable', anchor: 'gbrain-cycle-freshness-unknown',
summary: 'the installed gbrain does not expose cycle_freshness, so call-graph status is unknown',
fix: 'gstack-gbrain-install',
},
update_incomplete: {
state: 'unavailable', anchor: 'auto-update-incomplete',
summary: 'auto-update pulled gstack, but setup or migrations did not finish',
fix: 'cd <gstack checkout> && ./setup',
},
cso_helper_unbuilt: {
state: 'unavailable', anchor: 'cso-windows-msvc-compile',
summary: 'MSVC is installed but the /cso native helper failed to compile',
fix: 'fix the printed compiler error, then re-run ./setup',
},
chromium_path_failed: {
state: 'unavailable', anchor: 'browse-chromium-path-failed',
summary: 'the Chromium at GSTACK_CHROMIUM_PATH could not launch',
fix: 'point GSTACK_CHROMIUM_PATH at a working Chromium, or unset GSTACK_CHROMIUM_PATH',
},
} as const satisfies Record<string, GateOutcome>;
export type GateReason = keyof typeof GATE_OUTCOMES;
/** One user-facing line for an outcome that is not a clean `ran`. */
export function gateOutcomeLine(gate: string, reason: GateReason, detail?: string): string {
const outcome: GateOutcome = GATE_OUTCOMES[reason];
const what = detail ? `${outcome.summary} (${detail})` : outcome.summary;
if (outcome.state === 'not_run') return `${gate}: not run (${what}). Fix: ${outcome.fix}.`;
if (outcome.state === 'ran') return `${gate}: ran, verdict unverified (${what}). Fix: ${outcome.fix}.`;
return `${gate} unavailable: ${what}. No review ran; this is missing coverage, not a pass. Fix: ${outcome.fix}.`;
}