mirror of
https://github.com/garrytan/gstack.git
synced 2026-12-01 20:34:25 +01:00
When a code change's first review leads to fixes, the second-model review now reads those fixes and the final review again, instead of being skipped once it had run. A reviewer from the same model family as the author (a Claude reader checking Claude's work) no longer counts as the second model, and the review record names the model family that reviewed. Nothing to do: when the second model can't run (Codex down, rate-limited or refused), that is still recorded and never blocks shipping. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/red-team#1 reader=red-team Review-Finding: s11/outside-voice#1 reader=outside-voice Review-Finding: s11/outside-voice#2 reader=outside-voice Review-Finding: s11/outside-voice#3 reader=outside-voice Review-Finding: s11/outside-voice#4 reader=outside-voice Review-Finding: s11/adversarial-native#1 reader=adversarial-native Review-Finding: s11/adversarial-native#2 reader=adversarial-native Review-Finding: s11/adversarial-native#3 reader=adversarial-native Review-Finding: s11/adversarial-native#5 reader=adversarial-native Review-Finding: s11/adversarial-native#7 reader=adversarial-native
83 lines
6.3 KiB
TypeScript
83 lines
6.3 KiB
TypeScript
/**
|
|
* The outside voice's record (GST-4140): which provider and model read the diff, its family, and whether that read counts as
|
|
* second-model coverage. gstack-review-dispatch collect records it on the outside voice's output event and refuses a
|
|
* same-family read, verify prints it as OUTSIDE_VOICE_RECORD:, and gstack-ship-receipt write binds it as the receipt's
|
|
* outside_voice. A same-family fallback is one voice, never outside coverage; missing coverage is recorded as unavailable or
|
|
* skipped and never blocks.
|
|
*/
|
|
import { familyConflict, modelFamily, type ModelFamily } from './outside-voice-runner';
|
|
|
|
/** The reason verify records a completed outside read whose model family was never recorded: not proven second-model coverage. */
|
|
export const UNPROVEN_FAMILY = 'the outside read recorded no recognizable model family, so it is not proven second-model coverage';
|
|
/** The reason verify records a completed outside read with no recognized native family to compare it to: not proven a second family. */
|
|
export const UNPROVEN_NATIVE = 'the outside read recorded no recognizable native model family (collect --native-model), so it is not proven a second family';
|
|
|
|
export const OUTSIDE_VOICE_STATUSES = ['completed', 'unavailable', 'skipped'] as const;
|
|
export type OutsideVoiceStatus = typeof OUTSIDE_VOICE_STATUSES[number];
|
|
export interface OutsideVoiceRecord { status: OutsideVoiceStatus; provider: string; model: string; family: ModelFamily | string; native_family?: ModelFamily | string; reason?: string }
|
|
/** Who read: recorded on a collected outside voice's output event. */
|
|
export interface OutsideProvenance { provider: string; model: string; family: ModelFamily | string; native_model?: string; native_family?: ModelFamily | string }
|
|
|
|
/**
|
|
* A model id's family: lib/outside-voice-runner.ts's rules on the whole id, then on its last path segment (a router prefix such as
|
|
* `openrouter/anthropic/claude-…` keeps Claude's family); `unknown` otherwise. A bare provider prefix never names a family: a router
|
|
* (`bedrock/anthropic.claude-…`) would read as a second family.
|
|
*/
|
|
export function familyOf(model: string | undefined | null): string {
|
|
const id = (model ?? '').trim().toLowerCase();
|
|
const own = modelFamily(id);
|
|
return own !== 'unknown' ? own : modelFamily(id.split('/').at(-1));
|
|
}
|
|
|
|
/**
|
|
* The reply's closing `OUTSIDE_STATUS: <status> provider=<p> model=<m> …` line (bin/gstack-outside-voice prints it last); undefined
|
|
* when the last non-empty line is anything else, so a status line quoted inside the review text never counts.
|
|
*/
|
|
export function parseOutsideStatus(text: string): { status: string; provider?: string; model?: string } | undefined {
|
|
const line = text.replace(/\r\n/g, '\n').split('\n').map(l => l.trim()).filter(Boolean).at(-1);
|
|
if (!line?.startsWith('OUTSIDE_STATUS: ')) return undefined;
|
|
const [status = '', ...rest] = line.slice('OUTSIDE_STATUS: '.length).split(/\s+/);
|
|
const kv = Object.fromEntries(rest.map(p => p.split('=')).filter(p => p.length === 2 && p[1]) as [string, string][]);
|
|
return { status, provider: kv.provider, model: kv.model && kv.model !== 'unknown' ? kv.model : undefined };
|
|
}
|
|
|
|
/**
|
|
* The provenance collect records, from its flags or else the reply's closing OUTSIDE_STATUS line; undefined when neither is there.
|
|
* The family always comes from the model id (familyOf), never from a printed `family=`; a model that names none is `unknown`.
|
|
*/
|
|
export function outsideProvenance(o: { model?: string; provider?: string; nativeModel?: string; output: string }): OutsideProvenance | undefined {
|
|
const status = parseOutsideStatus(o.output);
|
|
if (!o.model && !o.provider && !status) return undefined;
|
|
const model = o.model ?? status?.model ?? 'unknown';
|
|
const family = familyOf(model);
|
|
const native = o.nativeModel ? familyOf(o.nativeModel) : undefined;
|
|
return { provider: o.provider ?? status?.provider ?? 'unknown', model, family, ...(o.nativeModel ? { native_model: o.nativeModel, native_family: native } : {}) };
|
|
}
|
|
|
|
/** Why a read with this provenance is not outside coverage: the same family as the lane's native model. undefined when it may count. */
|
|
export function sameFamily(p: OutsideProvenance): string | undefined {
|
|
if (!p.native_model || p.family === 'unknown' || !p.native_family || p.native_family === 'unknown') return undefined;
|
|
return p.family === p.native_family ? (familyConflict(p.model, p.native_model) ?? `outside ${p.model} and native ${p.native_model} are both ${p.family}`) : undefined;
|
|
}
|
|
|
|
/**
|
|
* Why a read by `model` is not proven second-model coverage: its family is unrecognized or not the model's own, the native family is
|
|
* missing or unrecognized, or the two are the same. undefined only for a recognized family beside a different recognized native family.
|
|
*/
|
|
export function unprovenCoverage(r: { model: string; family: string; native_family?: string }): string | undefined {
|
|
if (r.family === 'unknown' || familyOf(r.model) !== r.family) return UNPROVEN_FAMILY;
|
|
if (!r.native_family || r.native_family === 'unknown') return UNPROVEN_NATIVE;
|
|
return r.native_family === r.family ? `the outside read by ${r.model} is the ${r.family} family, the same as the lane's native family: a same-family fallback is never outside coverage` : undefined;
|
|
}
|
|
|
|
/** The receipt-side check: a completed record needs a recognized family and a different recognized native_family; every record needs a known status. */
|
|
export function outsideVoiceProblem(r: unknown): string | undefined {
|
|
if (!r || typeof r !== 'object' || Array.isArray(r)) return 'outside_voice must be an object { status, provider, model, family }';
|
|
const v = r as Record<string, unknown>;
|
|
if (!(OUTSIDE_VOICE_STATUSES as readonly unknown[]).includes(v.status)) return `outside_voice.status must be one of ${OUTSIDE_VOICE_STATUSES.join(', ')}, got ${JSON.stringify(v.status)}`;
|
|
for (const k of ['provider', 'model', 'family'] as const) if (typeof v[k] !== 'string' || !v[k]) return `outside_voice.${k} must be a non-empty string`;
|
|
if (v.status !== 'completed') return undefined;
|
|
const why = unprovenCoverage({ model: String(v.model), family: String(v.family), native_family: typeof v.native_family === 'string' ? v.native_family : undefined });
|
|
return why && `outside_voice records a completed read by ${v.model} (family ${v.family}, native_family ${typeof v.native_family === 'string' ? v.native_family : 'none'}), but ${why}; record it as unavailable`;
|
|
}
|