Approval page re-reviews two-reviewer scope changes and checks quotes only against this repository (#4441)

/autoplan's approval page now re-reviews a scope change both reviewers
raise, asks a plan with no Owner's words to confirm its direction, and
checks owner quotes only against this repository's approvals record.

This keeps the rule that only the owner's own words set a plan's
direction, and there is nothing for the reader to do.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/specialist-batched#1 reader=specialist-batched
Review-Finding: p1/specialist-batched#2 reader=specialist-batched
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-17 13:22:10 +00:00
1 parent c53b15c48d
commit 169eb9c8a5
10 files changed
+124 -39

No files matched your search

+20 -9
View File
@@ -15,6 +15,7 @@ import * as fs from 'node:fs';
import * as path from 'node:path';
import { spawnSync } from 'node:child_process';
import { branchKey, captainApprovalsDir } from './approval-record';
import { readVersionedSlugCache, sanitizeSlug } from './bin-context';
import { cutDrops, parseCuts, parseDayOne, parseOwnerWords, wordKey, type DayOneTable, type OwnerQuote, type OwnerWordsSection } from './autoplan-owner-text';
import { SETTLEABLE_CHANGES } from './autoplan-reconcile';
import { readDecisions, readJournal, type RunState } from './autoplan-state';
@@ -28,19 +29,24 @@ export interface GateOwnerWords { status: OwnerWordsSection['status']; quotes: A
export interface OwnerContext { words: OwnerWordsSection; verified: Set<number>; dayOne: DayOneTable; cuts: string[]; app: boolean; lean: boolean }
/**
* The owner's words in every approvals record already on disk for the branch checked out at `cwd` (lib/approval-record.ts
* layout: <state root>/projects/<slug>/approvals/<branch key>.jsonl and its mirrors). Read-only: the slug is not resolved,
* because resolving it writes the slug cache, and building a gate must not write outside the run.
* The owner's words in this repository's approvals record for the branch checked out at `cwd` (lib/approval-record.ts
* layout: <state root>/projects/<slug>/approvals/<branch key>.jsonl and <mirror>/<slug>/<branch key>.jsonl). Read-only:
* the slug comes from GSTACK_PROJECT_SLUG or the repository's slug cache entry gstack-slug already wrote (repository
* scope, which ignores project markers, as the writer resolves it), never a fresh resolution (that
* writes the cache, and building a gate must not write outside the run). No known slug reads no record, so a quote stays
* unverified rather than matching another repository's branch of the same name.
*/
export function ledgerWords(cwd: string, env: NodeJS.ProcessEnv = process.env): string[] {
const head = spawnSync('git', ['symbolic-ref', '--short', '-q', 'HEAD'], { cwd, encoding: 'utf8', timeout: 10_000 });
const branch = head.status === 0 ? head.stdout.trim() : '';
if (!branch) return [];
const stateRoot = resolveStateRoot(env);
const pinned = sanitizeSlug((env.GSTACK_PROJECT_SLUG ?? '').trim());
const slug = pinned && pinned !== '.' && pinned !== '..' ? pinned : readVersionedSlugCache(stateRoot, cwd, { scope: 'repository' });
if (!slug) return [];
const name = `${branchKey(branch)}.jsonl`;
const files: string[] = [];
const under = (root: string, sub: string[]) => { try { for (const d of fs.readdirSync(root)) files.push(path.join(root, d, ...sub, name)); } catch { /* no such root */ } };
under(path.join(resolveStateRoot(env), 'projects'), ['approvals']);
for (const root of [env.GSTACK_APPROVALS_DIR, captainApprovalsDir(env)]) if (root) under(root, []);
const files = [path.join(stateRoot, 'projects', slug, 'approvals', name),
...[env.GSTACK_APPROVALS_DIR, captainApprovalsDir(env)].flatMap(root => (root ? [path.join(root, slug, name)] : []))];
const words: string[] = [];
for (const file of files) {
let text: string;
@@ -92,13 +98,18 @@ export function proposalCost(ctx: OwnerContext, phase: string, changes: string):
/** A proposal behind a Critical or High row keeps the finding path's b: the draft stands and the finding becomes a blocking build task. */
export const blockingProposal = (rows: ChallengeRow[]): boolean => rows.some(r => r.severity === 'Critical' || r.severity === 'High');
/** The heaviest `changes` any row names: scope, cost or direction before packaging or ordering, so a pair never settles a scope change. */
export function heaviestChanges(rows: Array<{ changes?: string } | undefined>): string | undefined {
const named = rows.flatMap(r => (r?.changes ? [r.changes] : []));
return ['scope', 'cost', 'direction'].find(c => named.includes(c)) ?? named[0];
}
/**
* One proposal from one or both voices (a paired twin) against agent-written plan text: a takes the change, b keeps the draft.
* Its `changes` is the heaviest any row names (scope, cost, direction, then packaging or ordering), so a pair never settles a scope change.
*/
export function proposalItem(ctx: OwnerContext, phase: string, rows: ChallengeRow[], o: { carried?: boolean } = {}): NewItem {
const named: string[] = rows.flatMap(r => (r.changes ? [r.changes] : []));
const changes = ['scope', 'cost', 'direction'].find(c => named.includes(c)) ?? named[0] ?? 'direction';
const changes = heaviestChanges(rows) ?? 'direction';
const keep = blockingProposal(rows) ? "keep the plan's draft; carry it into the build as a blocking task (no plan change)" : "keep the plan's draft";
const fixes = [...new Set(rows.map(r => r.resolution).filter((r): r is string => !!r))];
const voices = rows.map(r => r.voice).join(' + ');
+3 -2
View File
@@ -27,7 +27,7 @@ import { applyCapChoices, pendingDeltas, releaseUndispatched, roundCap, roundOf
import { evaluateCarry, gateEvidence, voidPendingCheck } from './autoplan-carry';
import { buildEli5, capyRelayLine } from './captain-brief';
import { FINDING_ORIGIN, openEarlier, previousReview, reviewRows, settledIds } from './autoplan-confirm';
import { blockingProposal, confirmDirectionItem, dayOneItems, directionIsOwners, gateOwnerWords, ownerContext, ownerQuoteOf, proposalItem, type ChallengeRow, type NewItem } from './autoplan-gate-items';
import { blockingProposal, confirmDirectionItem, dayOneItems, directionIsOwners, gateOwnerWords, heaviestChanges, ownerContext, ownerQuoteOf, proposalItem, type ChallengeRow, type NewItem } from './autoplan-gate-items';
import { phaseClose } from './autoplan-timing';
import { agentWords, ANSWERED_BY_RE, applyReply, autoDefault, decisionId, decisionRows, keepDirection, legacyRecHash, parseReply, pendingHint, recHash, replyShape, validateGateList, type GateChoice, type GateItem, type GateList, type GateOption, type ParsedReply } from './gate-list';
import type { DecisionRow, FindingRow } from './headless-artifacts';
@@ -235,7 +235,8 @@ export function buildGate(state: RunState, gateRev: number): GateList {
const title = `${n.title} [${row.native_id} + ${row.outside_id}]`;
if (reran && !n.changes && !o.changes) { push(agentDecision(`d${++d}`, title, phase, 'both voices recommend changing your stated direction'), ids); continue; }
const def = challengeDefault(row, n, o);
push({ id: `uc${++uc}`, title, kind: 'approval', recommended: def.recommended, recommended_basis: def.basis, phase, item_class: 'challenge2', ...(n.changes ?? o.changes ? { changes: n.changes ?? o.changes } : {}),
if (!quoted && def.recommended === 'a') { kept.push(`uc${uc + 1}`); keptIds.push(n.id, o.id); }
push({ id: `uc${++uc}`, title, kind: 'approval', recommended: def.recommended, recommended_basis: def.basis, phase, item_class: 'challenge2', ...(heaviestChanges([n, o]) ? { changes: heaviestChanges([n, o]) } : {}),
why: `both voices recommend changing your stated direction; blind spot: ${o.title}; cost if wrong: ${o.resolution ?? n.resolution ?? 'unstated'}`,
options: [KEEP('keep your direction (the plan as reviewed)'), { key: 'b', text: def.text, changes_plan: true }] }, ids);
continue;
+6 -4
View File
@@ -12,7 +12,7 @@ import { resolveStateRoot } from "./state-root";
import { legacyRemoteSlug, remoteSlug } from "./remote-identity";
/** Keep the slug inside the [a-zA-Z0-9._-] alphabet gstack-slug promises (`tr -cd`). */
function sanitizeSlug(s: string): string {
export function sanitizeSlug(s: string): string {
return s.replace(/[^a-zA-Z0-9._-]/g, "");
}
@@ -386,10 +386,12 @@ function markerSlug(stateRoot: string, cwd: string, root: string): string {
* no entry, the entry predates the versioned format, or its value is unusable
* (empty, "." or ".." after sanitizing). Never spawns git: hot-path readers
* (the AskUserQuestion preference hook) rely on gstack-slug, which every skill
* preamble runs, having already written the entry.
* preamble runs, having already written the entry. Scope "repository" skips the
* project marker's entry, as slugFromEnvironment's does, so approvals readers and
* writers agree on the slug.
*/
export function readVersionedSlugCache(stateRoot: string, cwd: string): string | undefined {
const marker = projectMarkerRoot(cwd);
export function readVersionedSlugCache(stateRoot: string, cwd: string, opts: { scope?: "memory" | "repository" } = {}): string | undefined {
const marker = opts.scope === "repository" ? "" : projectMarkerRoot(cwd);
const file = marker ? markerCacheFile(stateRoot, marker) : slugCacheReadOrder(stateRoot, cwd).find((f) => existsSync(f));
if (!file) return undefined;
let raw: string;