Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions browse/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,11 @@ publish cookie values, passwords, profile/account text, or session details.

## Fallback command reference

The table in the Browser fallback section covers what the cookbook covers. Everything
else `$B` can do — extraction, tabs, dialogs, uploads, meta/server commands, and the
full snapshot-flag reference — lives in the generated section below. Read it before
reaching for a `$B` command that is not in the table.
Read the section below before using a `$B` command the table lacks.

- `$B eval <file>` reads only files under the temp dir or the daemon's working dir.
- Each git root gets its own daemon: after a `cd` into another repo (nested too), `$B`
starts a new one without your session. Run `$B` from the project dir.

> **STOP.** Before using any command or snapshot flag beyond the Browser fallback translation table — the full generated reference for every browse command, its argument shape, and every snapshot flag, Read `~/.claude/skills/gstack/browse/sections/command-list.md` and execute it
> in full. Do not work from memory — that section is the source of truth for this step.
9 changes: 5 additions & 4 deletions browse/SKILL.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ publish cookie values, passwords, profile/account text, or session details.

## Fallback command reference

The table in the Browser fallback section covers what the cookbook covers. Everything
else `$B` can do — extraction, tabs, dialogs, uploads, meta/server commands, and the
full snapshot-flag reference — lives in the generated section below. Read it before
reaching for a `$B` command that is not in the table.
Read the section below before using a `$B` command the table lacks.

- `$B eval <file>` reads only files under the temp dir or the daemon's working dir.
- Each git root gets its own daemon: after a `cd` into another repo (nested too), `$B`
starts a new one without your session. Run `$B` from the project dir.

{{SECTION:command-list}}
1 change: 1 addition & 0 deletions changelog.d/fix-quarantine-skip-snooze-browse-models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**A quarantined test that the runner skipped now fails the run instead of passing it.** `gstack-flaky` treats a skip on the attempt that decided the run as a quarantined failure, because a quarantined test still has to run; a test skipped first and passing on the retry still passes (#4550, fix found in #4551). Also: "Not now" on the upgrade prompt now sticks for git installs, because the snooze snippet takes the whole `UPGRADE_AVAILABLE` line and keys on the same field the update check reads (#4561); `gstack-models resolve` and `list` read a custom Codex provider's `config.toml` model the way `gstack-codex-probe role-ready` does, instead of always saying no model is set (#4491); and the /browse skill now says that `$B eval` reads files only from the temp directory or the daemon's working directory, and that the daemon belongs to the git root you run `$B` from (#4557, #4558).
4 changes: 3 additions & 1 deletion docs/flaky.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ live quarantined test, and nothing else is wrong with that attempt (no kill, no
failure outside the report, no first-run test missing), the whole command may
run again, up to 3 attempts in total. The run is green only when one of those
attempts is fully green. A quarantined test that fails all 3 is a **hard
break**, and the run is red. A test that is not quarantined keeps its one
break**, and the run is red. A quarantined test skipped on the final attempt
did not run, so it is a quarantined failure and the run is red; it never counts
toward the clean streak. A test that is not quarantined keeps its one
rerun. A red attempt never turns green because its only reported failure is a
quarantined test, because the runner's exit status can come from things the
report does not show (a coverage threshold, a fail-on-flaky policy, a global
Expand Down
7 changes: 4 additions & 3 deletions docs/model-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ because you already route that ID to your endpoint. Any other name there, such
as a smart-tier model or a deployment alias, is refused
(`custom_provider_model_not_tier`): it could be any model, so name it with the
tier setting or the environment override if you want it as your plan reviewer.
`gstack-codex-probe role-ready` and `gstack-outside-voice run --runner codex-cli`
(for the `autoplan` and `spec` gates) share this selection, so the readiness
check and the review never pick different models. A model identifier passing syntax validation
`gstack-codex-probe role-ready`, `gstack-outside-voice run --runner codex-cli`
(for the `autoplan` and `spec` gates), and `gstack-models resolve` and `list`
share this selection, so the readiness check, the review and the listing never
pick different models. A model identifier passing syntax validation
is not proof of account availability. See [provider recovery](troubleshooting.md#model-policy-provider).

Detection is conservative, not a replacement for the CLI's settings engine.
Expand Down
5 changes: 3 additions & 2 deletions gstack-upgrade/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Tell user: "Auto-upgrade enabled. Future updates will install automatically." Th
```bash
GSTACK_STATE_ROOT=$(~/.claude/skills/gstack/bin/gstack-paths --get GSTACK_STATE_ROOT); : "${GSTACK_STATE_ROOT:?gstack-paths failed; reinstall with ./setup or /gstack-upgrade}"
_SNOOZE_FILE="$GSTACK_STATE_ROOT/update-snoozed"
_REMOTE_VER="{new}"
_UPGRADE_LINE="{line}"
_REMOTE_VER=$(printf '%s\n' "$_UPGRADE_LINE" | awk '{print (NF >= 4 ? $(4) : $(3))}')
_CUR_LEVEL=0
if [ -f "$_SNOOZE_FILE" ]; then
_SNOOZED_VER=$(awk '{print $(1)}' "$_SNOOZE_FILE")
Expand All @@ -63,7 +64,7 @@ _NEW_LEVEL=$((_CUR_LEVEL + 1))
[ "$_NEW_LEVEL" -gt 3 ] && _NEW_LEVEL=3
echo "$_REMOTE_VER $_NEW_LEVEL $(date +%s)" > "$_SNOOZE_FILE"
```
Note: `{new}` is the remote version from the `UPGRADE_AVAILABLE` output — substitute it from the update check result. On a four-field line use the SHA (fourth field) as `{new}`, so the snooze ends when main moves.
Note: `{line}` is the whole `UPGRADE_AVAILABLE` line, exactly as printed; the snippet picks the field `gstack-update-check` reads.

Tell user the snooze duration: "Next reminder in 24h" (or 48h or 1 week, depending on level). Tip: "Set `auto_upgrade: true` in `~/.gstack/config.yaml` for automatic upgrades."

Expand Down
5 changes: 3 additions & 2 deletions gstack-upgrade/SKILL.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Tell user: "Auto-upgrade enabled. Future updates will install automatically." Th
```bash
GSTACK_STATE_ROOT=$(~/.claude/skills/gstack/bin/gstack-paths --get GSTACK_STATE_ROOT); : "${GSTACK_STATE_ROOT:?gstack-paths failed; reinstall with ./setup or /gstack-upgrade}"
_SNOOZE_FILE="$GSTACK_STATE_ROOT/update-snoozed"
_REMOTE_VER="{new}"
_UPGRADE_LINE="{line}"
_REMOTE_VER=$(printf '%s\n' "$_UPGRADE_LINE" | awk '{print (NF >= 4 ? $(4) : $(3))}')
_CUR_LEVEL=0
if [ -f "$_SNOOZE_FILE" ]; then
_SNOOZED_VER=$(awk '{print $(1)}' "$_SNOOZE_FILE")
Expand All @@ -69,7 +70,7 @@ _NEW_LEVEL=$((_CUR_LEVEL + 1))
[ "$_NEW_LEVEL" -gt 3 ] && _NEW_LEVEL=3
echo "$_REMOTE_VER $_NEW_LEVEL $(date +%s)" > "$_SNOOZE_FILE"
```
Note: `{new}` is the remote version from the `UPGRADE_AVAILABLE` output — substitute it from the update check result. On a four-field line use the SHA (fourth field) as `{new}`, so the snooze ends when main moves.
Note: `{line}` is the whole `UPGRADE_AVAILABLE` line, exactly as printed; the snippet picks the field `gstack-update-check` reads.

Tell user the snooze duration: "Next reminder in 24h" (or 48h or 1 week, depending on level). Tip: "Set `auto_upgrade: true` in `~/.gstack/config.yaml` for automatic upgrades."

Expand Down
13 changes: 8 additions & 5 deletions lib/flaky-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ function mayRunAgain(again: Ran, first: JunitReport, quarantined: ReadonlySet<st
const history = (t: JunitTest, runs: Ran[]): Attempt[] =>
[...t.attempts, ...runs.flatMap(r => r.report?.tests.find(x => x.id === t.id)?.attempts ?? ['fail' as const])];

/** A quarantined test passes only when it never failed or an attempt with the runner's full verdict cleared it. */
/** A quarantined test passes only when its final attempt ran and passed, and it never failed or an attempt with the runner's full verdict cleared it; a skip is not a run. */
const quarantinedStatus = (attempts: string[], cleared: boolean): 'quarantined-pass' | 'quarantined-fail' | 'hard-break' =>
cleared || !attempts.includes('fail') ? 'quarantined-pass'
: attempts.length >= QUARANTINE_ATTEMPTS && attempts.every(a => a === 'fail') ? 'hard-break' : 'quarantined-fail';
attempts.length >= QUARANTINE_ATTEMPTS && attempts.every(a => a === 'fail') ? 'hard-break'
: attempts.at(-1) === 'pass' && (cleared || !attempts.includes('fail')) ? 'quarantined-pass' : 'quarantined-fail';

export async function runFlaky(opts: RunOptions): Promise<RunResult> {
const cwd = opts.cwd ?? process.cwd();
Expand Down Expand Up @@ -363,7 +363,7 @@ export async function runFlaky(opts: RunOptions): Promise<RunResult> {
if (why) settle(t, t.attempts, why);
else eligible.push(t);
}
const passedQ = report.tests.filter(t => isQ(t) && finalAttempt(t) !== 'fail' && t.attempts.some(a => a !== 'skip'));
const passedQ = report.tests.filter(t => isQ(t) && finalAttempt(t) !== 'fail');
const wholeRerun = !eligible.length ? undefined
: opts.rerunScope !== 'test' ? 'the default; --rerun-scope test reruns the failed test alone'
: incompleteRun(report.runner, first.output, first.exit, opts.command, runnerFlaky.length) ?? undefined;
Expand Down Expand Up @@ -409,7 +409,10 @@ export async function runFlaky(opts: RunOptions): Promise<RunResult> {
if (reruns) fs.writeFileSync(junit, firstXml);
}
const green = runs.length ? fullGreen(runs.at(-1)!, report) : reruns > 0 || first.exit === 0;
for (const t of passedQ) settleQ(t, history(t, runs), green, 'the attempt that decided the run was not a full green run', runs.length ? 'command' : undefined);
for (const t of passedQ) {
const attempts = history(t, runs);
settleQ(t, attempts, green, attempts.at(-1) === 'skip' ? 'quarantined, and skipped on the final attempt instead of running' : 'the attempt that decided the run was not a full green run', runs.length ? 'command' : undefined);
}
const red = !green || outcomes.some(o => !PASSING.has(o.status));
const q = outcomes.filter(o => o.status === 'quarantined-pass' || o.status === 'quarantined-fail' || o.status === 'hard-break').length;
return { exitCode: red ? 1 : 0, tests: report.tests.length, commandExit: first.exit, outcomes, reruns, quarantined: q, ...(wholeRerun && reruns ? { wholeRerun } : {}), ledger };
Expand Down
14 changes: 13 additions & 1 deletion lib/model-policy-cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as path from 'node:path';
import { CODEX_EFFORT_LEVELS, MODEL_CATALOG, MODEL_CATALOG_VERSION, MODEL_PROVIDERS, MODEL_TIERS, modelCatalogSha256, type ModelProvider } from './model-catalog';
import {
CODEX_MODEL_REPAIR,
codexNativeModel,
CUSTOM_PROVIDER_UNSCANNED,
DOCS_PROVIDER,
describeSelection,
MODEL_OVERRIDE_KEYS,
ModelPolicyError,
Expand Down Expand Up @@ -319,13 +322,22 @@ export function modelsMain(args: string[], env: StateRootEnv = process.env, plat
: { code: 1, stdout: '', stderr: errors.map(renderError).join('') };
}

const codexModel = codexNativeModel({ kind: 'exec', env });
const nativeModel = () => {
try {
return codexModel();
} catch (error) {
if (error instanceof ModelPolicyError) throw error;
throw new ModelPolicyError({ reason: 'native_provider_unresolved', problem: 'gstack cannot read the model your Codex config.toml names', cause: (error as Error).message, key: null, source: 'native', repair: [CODEX_MODEL_REPAIR], docs: DOCS_PROVIDER });
}
};
const selections: ModelSelection[] = [];
const errors: CliError[] = [];
const roles: ModelRole[] = command === 'list' ? ['plan-review', 'implementation'] : [role === 'eval-arms' ? 'implementation' : role as ModelRole];
for (const r of roles) {
for (const p of provider ? [provider] : MODEL_PROVIDERS) {
attempt(r, p, () => r === 'plan-review'
? [resolvePlanReviewModel({ provider: p, env, platform, cwd, config })]
? [resolvePlanReviewModel({ provider: p, env, platform, cwd, config, ...(p === 'openai' ? { nativeModel } : {}) })]
: resolveImplementationModels({ provider: p, env, platform, cwd, config }), selections, errors);
}
}
Expand Down
66 changes: 65 additions & 1 deletion lib/model-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const ANTHROPIC_MODEL_ID_PATTERN = /^[A-Za-z0-9._:/@+[\]-]{1,512}$/;

const DOCS = 'https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md';
const DOCS_CONFIG = `${DOCS}#model-policy-config`;
const DOCS_PROVIDER = `${DOCS}#model-policy-provider`;
export const DOCS_PROVIDER = `${DOCS}#model-policy-provider`;
const DOCS_SELECTION = `${DOCS}#model-policy-selection`;

const PROVIDER_LABEL: Record<ModelProvider, string> = { anthropic: 'Anthropic (Claude Code)', openai: 'OpenAI (Codex)' };
Expand Down Expand Up @@ -695,3 +695,67 @@ export function modelPolicyCommands() {
restoreDefault: 'gstack-config unset plan_review_tier',
};
}

export const CODEX_MODEL_REPAIR = 'Choose a model your Codex account can use: name it for this request, set GSTACK_CODEX_MODEL=<model>, or set model in the Codex config.toml.';

const stripControlChars = (value: string): string => value.replace(/[\x00-\x1f\x7f]/g, ' ');

/**
* The model Codex's own config.toml names for this invocation kind
* (`review_model` first for native review, then the legacy active profile's
* model, then `model`). `value` is null when it names none, and `source`
* then says what was missing. Shared by the runtime and plan-review records.
*/
export function codexConfigModel(opts: {
kind: 'exec' | 'review';
env: Record<string, string | undefined>;
codexHome?: string;
home?: string;
}): { value: string | null; source: string } {
const home = opts.home ?? opts.env.HOME ?? os.homedir();
const codexHome = opts.codexHome ?? opts.env.CODEX_HOME ?? path.join(home, '.codex');
if (!path.isAbsolute(codexHome)) {
throw new Error(`CODEX_HOME '${sanitize(codexHome)}' is not an absolute path, so its config.toml model cannot be read. ${CODEX_MODEL_REPAIR}`);
}
const configPath = path.join(codexHome, 'config.toml');
let raw: string;
try {
raw = fs.readFileSync(configPath, 'utf8');
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return { value: null, source: `no ${stripControlChars(configPath)}` };
throw new Error(`Could not read ${sanitize(configPath)}. ${CODEX_MODEL_REPAIR}`);
}
let parsed: Record<string, unknown>;
try {
parsed = Bun.TOML.parse(raw) as Record<string, unknown>;
} catch {
throw new Error(`Could not parse ${sanitize(configPath)}. ${CODEX_MODEL_REPAIR}`);
}
const profileName = typeof parsed.profile === 'string' ? parsed.profile : undefined;
const profiles = parsed.profiles as Record<string, Record<string, unknown> | undefined> | undefined;
const profile = profileName && typeof profiles === 'object' ? profiles?.[profileName] : undefined;
const candidates: Array<[string, unknown]> = [
...(opts.kind === 'review' ? [[`${configPath} review_model`, parsed.review_model] as [string, unknown]] : []),
[`${configPath} [profiles.${profileName}].model`, profile?.model],
[`${configPath} model`, parsed.model],
];
for (const [source, value] of candidates) {
if (value === undefined) continue;
if (typeof value !== 'string') throw new Error(`${sanitize(source)} is not a string. ${CODEX_MODEL_REPAIR}`);
return { value, source };
}
return { value: null, source: `no model in ${stripControlChars(configPath)}` };
}

/** The model Codex's config.toml names, in the shape resolvePlanReviewModel's nativeModel reads, so every plan-review caller sees the same custom-provider model. */
export function codexNativeModel(opts: {
kind: 'exec' | 'review';
env: Record<string, string | undefined>;
codexHome?: string;
home?: string;
}): () => { model: string; label: string } | null {
return () => {
const named = codexConfigModel(opts);
return named.value === null ? null : { model: named.value.trim(), label: stripControlChars(named.source) };
};
}
57 changes: 3 additions & 54 deletions scripts/resolve-codex-generation-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { ALL_MODEL_NAMES, resolveModel, type Model } from './models';
import { ModelPolicyError, resolvePlanReviewModel, selectionRepair, type ModelSelection } from '../lib/model-policy';
import { CODEX_MODEL_REPAIR, codexConfigModel, codexNativeModel, ModelPolicyError, resolvePlanReviewModel, selectionRepair, type ModelSelection } from '../lib/model-policy';
import { emitModelPolicyNotice } from '../lib/model-policy-notice';

export interface CodexGenerationModelResolution {
Expand Down Expand Up @@ -117,7 +117,7 @@ export interface CodexRuntimeModelSelection {
/** Characters a model id may carry before it is interpolated into `-c "model=\"…\""`. */
export const CODEX_RUNTIME_MODEL_PATTERN = /^[A-Za-z0-9._:/-]{1,100}$/;

const REPAIR = 'Choose a model your Codex account can use: name it for this request, set GSTACK_CODEX_MODEL=<model>, or set model in the Codex config.toml.';
const REPAIR = CODEX_MODEL_REPAIR;

/**
* Runtime model for gstack-owned Codex calls (#2914). Unlike the generation
Expand Down Expand Up @@ -150,53 +150,6 @@ export function resolveCodexRuntimeModel(opts: {
return chosen(named.source, named.value);
}

/**
* The model Codex's own config.toml names for this invocation kind
* (`review_model` first for native review, then the legacy active profile's
* model, then `model`). `value` is null when it names none, and `source`
* then says what was missing. Shared by the runtime and plan-review records.
*/
function codexConfigModel(opts: {
kind: CodexInvocationKind;
env: Record<string, string | undefined>;
codexHome?: string;
home?: string;
}): { value: string | null; source: string } {
const home = opts.home ?? opts.env.HOME ?? os.homedir();
const codexHome = opts.codexHome ?? opts.env.CODEX_HOME ?? path.join(home, '.codex');
if (!path.isAbsolute(codexHome)) {
throw new Error(`CODEX_HOME '${sanitize(codexHome)}' is not an absolute path, so its config.toml model cannot be read. ${REPAIR}`);
}
const configPath = path.join(codexHome, 'config.toml');
let raw: string;
try {
raw = fs.readFileSync(configPath, 'utf8');
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return { value: null, source: `no ${stripControl(configPath)}` };
throw new Error(`Could not read ${sanitize(configPath)}. ${REPAIR}`);
}
let parsed: Record<string, unknown>;
try {
parsed = Bun.TOML.parse(raw) as Record<string, unknown>;
} catch {
throw new Error(`Could not parse ${sanitize(configPath)}. ${REPAIR}`);
}
const profileName = typeof parsed.profile === 'string' ? parsed.profile : undefined;
const profiles = parsed.profiles as Record<string, Record<string, unknown> | undefined> | undefined;
const profile = profileName && typeof profiles === 'object' ? profiles?.[profileName] : undefined;
const candidates: Array<[string, unknown]> = [
...(opts.kind === 'review' ? [[`${configPath} review_model`, parsed.review_model] as [string, unknown]] : []),
[`${configPath} [profiles.${profileName}].model`, profile?.model],
[`${configPath} model`, parsed.model],
];
for (const [source, value] of candidates) {
if (value === undefined) continue;
if (typeof value !== 'string') throw new Error(`${sanitize(source)} is not a string. ${REPAIR}`);
return { value, source };
}
return { value: null, source: `no model in ${stripControl(configPath)}` };
}

export interface CodexPlanReviewSelection extends CodexRuntimeModelSelection {
selection: ModelSelection;
/** Source-aware repair for this record, never a lower-priority setting. */
Expand All @@ -218,11 +171,7 @@ export function resolveCodexPlanReviewModel(opts: {
cwd?: string;
}): CodexPlanReviewSelection {
const env = opts.env ?? process.env;
const nativeModel = () => {
const named = codexConfigModel({ ...opts, env });
return named.value === null ? null : { model: named.value.trim(), label: stripControl(named.source) };
};
const selection = resolvePlanReviewModel({ provider: 'openai', requestedModel: opts.explicit || undefined, env, cwd: opts.cwd, nativeModel });
const selection = resolvePlanReviewModel({ provider: 'openai', requestedModel: opts.explicit || undefined, env, cwd: opts.cwd, nativeModel: codexNativeModel({ ...opts, env }) });
const repair = stripControl(selectionRepair(selection).join('; '));
if (selection.status === 'selected') {
const model = selection.requestedModel;
Expand Down
Loading
Loading