mirror of
https://github.com/garrytan/gstack.git
synced 2026-12-01 12:25:53 +01:00
First versions: check a ruled-out line against the one reply it cites (GST-3646) (#4800)
A first version's `ruled out : ""` line now counts only against the one recorded owner reply its date names (record id, time, or day when he sent one reply that day). Any other match asks him instead of hiding the reviewer's finding. Why: the line used to match words from any of his replies, so a ruling could win on words he never tied to it. Nothing to do: the date format plans already use still works when he replied once that day. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=specialist-batched
This commit is contained in:
1 parent
4394a02363
commit
beca1d6f15
9 files changed
+84
-25
No files matched your search
@@ -131,6 +131,9 @@ export function openEarlier(state: RunState, phase: string, current: FindingRow[
|
||||
/** The origin tag of an open Critical/High finding's gate item: only `a` (its fix applied to the plan) settles it. */
|
||||
export const FINDING_ORIGIN = 'finding';
|
||||
|
||||
/** The origin tag of a recorded owner ruling's keep item: its `a` turns the reviewer's fix down, so the build gets no task for it. */
|
||||
export const RULING_ORIGIN = 'ruling';
|
||||
|
||||
/**
|
||||
* Earlier finding id -> the answered decision whose gate item named it. A finding carried into the build stays open,
|
||||
* and `findings: false` also leaves an applied one open, so a confirm round re-raising it is never suppressed.
|
||||
|
||||
@@ -14,6 +14,7 @@ import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { PHASES } from './autoplan-prompts';
|
||||
import type { ConsensusRecord } from './autoplan-reconcile';
|
||||
import { RULING_ORIGIN } from './autoplan-confirm';
|
||||
import { decisionId } from './gate-list';
|
||||
import { readDecisions, readJournal, voiceRows, type DispatchCounts, type RunState, type Voice } from './autoplan-state';
|
||||
import type { FindingRow, TaskRow } from './headless-artifacts';
|
||||
@@ -26,8 +27,9 @@ export function buildTasks(state: RunState, findings: FindingRow[]): TaskRow[] {
|
||||
const covered = new Set<string>();
|
||||
const blockedBy = state.ceo_only ? [] : [decisionId(state.run, state.gate_rev ?? 1, 'p1')];
|
||||
let n = 0;
|
||||
const ruled = new Set(readDecisions(state.out).filter(d => d.chosen === 'a' && d.origin?.endsWith(`|${RULING_ORIGIN}`)).flatMap(d => (d.origin!.split('|')[1] ?? '').split('+')));
|
||||
for (const f of findings as Array<FindingRow & { settled_by?: string }>) {
|
||||
if (f.settled_by || covered.has(f.id)) continue;
|
||||
if (f.settled_by || ruled.has(f.id) || covered.has(f.id)) continue;
|
||||
if (f.disposition === 'deferred') {
|
||||
covered.add(f.id);
|
||||
tasks.push({ schema_version: 2, run: state.run, id: `${state.run}-T${++n}`, title: `deferred from ${f.phase}: ${f.title}`, status: 'pending', depends_on: [], findings: [f.id],
|
||||
|
||||
+24
-12
@@ -41,7 +41,10 @@ export interface OwnerContext { words: OwnerWordsSection; verified: Set<number>;
|
||||
* 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[] {
|
||||
/** One recorded owner reply: its words, and when available its time and record id, which a ruled-out line cites. */
|
||||
export interface OwnerReply { text: string; at?: string; id?: string }
|
||||
|
||||
export function ledgerWords(cwd: string, env: NodeJS.ProcessEnv = process.env): OwnerReply[] {
|
||||
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 [];
|
||||
@@ -52,36 +55,45 @@ export function ledgerWords(cwd: string, env: NodeJS.ProcessEnv = process.env):
|
||||
const name = `${branchKey(branch)}.jsonl`;
|
||||
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[] = [];
|
||||
const words: OwnerReply[] = [];
|
||||
for (const file of files) {
|
||||
let text: string;
|
||||
try { text = fs.readFileSync(file, 'utf8'); } catch { continue; }
|
||||
for (const line of text.split('\n')) {
|
||||
try { const row = JSON.parse(line); if (typeof row?.words === 'string' && !row.words_by) words.push(row.words); } catch { /* a torn line */ }
|
||||
try { const row = JSON.parse(line); if (typeof row?.words === 'string' && !row.words_by) words.push({ text: row.words, at: row.recorded_at, id: row.id }); } catch { /* a torn line */ }
|
||||
}
|
||||
}
|
||||
return words;
|
||||
}
|
||||
|
||||
/** Every owner reply this run recorded, plus the owner's words in the approvals records for the plan's branch. */
|
||||
export function recordedOwnerWords(state: RunState, env: NodeJS.ProcessEnv = process.env): string[] {
|
||||
const out: string[] = [];
|
||||
for (const r of readJournal(state.out)) if (typeof r.owner_reply === 'string') out.push(r.owner_reply);
|
||||
for (const d of readDecisions(state.out)) if (typeof d.owner_reply === 'string') out.push(d.owner_reply);
|
||||
export function recordedOwnerWords(state: RunState, env: NodeJS.ProcessEnv = process.env): OwnerReply[] {
|
||||
const out: OwnerReply[] = [];
|
||||
for (const r of readJournal(state.out)) if (typeof r.owner_reply === 'string') out.push({ text: r.owner_reply, at: r.ts });
|
||||
for (const d of readDecisions(state.out)) if (typeof d.owner_reply === 'string') out.push({ text: d.owner_reply, at: d.answered_at, id: d.id });
|
||||
return [...out, ...ledgerWords(path.dirname(state.plan_input ?? state.plan_source), env)];
|
||||
}
|
||||
|
||||
export function ownerContext(state: RunState, recorded: string[] = recordedOwnerWords(state)): OwnerContext {
|
||||
/** The replies a ruled-out line's citation names: a record id, or a time (`YYYY-MM-DD` or `YYYY-MM-DD HH:MMZ`) its timestamp starts with. One reply is stored on every row it answered, so copies of the same words count once. */
|
||||
export function citedReplies(cite: string, replies: OwnerReply[]): OwnerReply[] {
|
||||
const m = /^(\d{4}-\d{2}-\d{2})(?:[ T](\d{2}:\d{2})Z?)?$/.exec(cite.trim());
|
||||
const stamp = m ? `${m[1]}${m[2] ? `T${m[2]}` : ''}` : undefined;
|
||||
const cited = replies.filter(r => r.id === cite.trim() || (!!stamp && !!r.at && r.at.startsWith(stamp)));
|
||||
return [...new Map(cited.map(r => [r.text.trim(), r])).values()];
|
||||
}
|
||||
|
||||
export function ownerContext(state: RunState, recorded: Array<string | OwnerReply> = recordedOwnerWords(state)): OwnerContext {
|
||||
let text = '';
|
||||
try { text = fs.readFileSync(state.active_plan, 'utf8'); } catch { /* no plan text: nothing is quoted */ }
|
||||
const words = parseOwnerWords(text);
|
||||
const keys = recorded.map(wordKey);
|
||||
const said = (text: string) => keys.some(k => k.includes(wordKey(text)));
|
||||
const verified = new Set(words.quotes.filter(q => said(q.text)).map(q => q.n));
|
||||
const replies = recorded.map(r => (typeof r === 'string' ? { text: r } : r));
|
||||
const keys = replies.map(r => wordKey(r.text));
|
||||
const verified = new Set(words.quotes.filter(q => keys.some(k => k.includes(wordKey(q.text)))).map(q => q.n));
|
||||
const ruledBy = (q: OwnerQuote) => {
|
||||
if (q.line?.kind !== 'ruled_out') return false;
|
||||
const key = wordKey(q.line.ruling);
|
||||
return key.trim().split(/\s+/).length >= 3 && !wordKey(q.text).includes(key) && said(q.line.ruling);
|
||||
const cited = citedReplies(q.line.date, replies);
|
||||
return key.trim().split(/\s+/).length >= 3 && !wordKey(q.text).includes(key) && cited.length === 1 && wordKey(cited[0]!.text).includes(key);
|
||||
};
|
||||
const ruled = new Set(words.quotes.filter(ruledBy).map(q => q.n));
|
||||
return { words, verified, ruled, dayOne: parseDayOne(text), cuts: parseCuts(text), app: !!state.scope?.ui, lean: !!state.lean,
|
||||
|
||||
@@ -26,7 +26,7 @@ import { FILES, RunError, journal as journalRow, now, readDecisions, voiceRows,
|
||||
import { applyCapChoices, pendingDeltas, releaseUndispatched, roundCap, roundOf } from './autoplan-budget';
|
||||
import { evaluateCarry, gateEvidence, voidPendingCheck } from './autoplan-carry';
|
||||
import { buildEli5, capyRelayLine } from './captain-brief';
|
||||
import { FINDING_ORIGIN, openEarlier, previousReview, reviewRows, settledIds } from './autoplan-confirm';
|
||||
import { FINDING_ORIGIN, RULING_ORIGIN, openEarlier, previousReview, reviewRows, settledIds } from './autoplan-confirm';
|
||||
import { lineText } from './autoplan-owner-text';
|
||||
import { blockingProposal, confirmDirectionItem, dayOneItems, directionIsOwners, gateOwnerWords, heaviestChanges, narrowedQuoteOf, ownerContext, ownerQuoteOf, proposalItem, type ChallengeRow, type NewItem } from './autoplan-gate-items';
|
||||
import { phaseClose } from './autoplan-timing';
|
||||
@@ -256,13 +256,13 @@ export function buildGate(state: RunState, gateRev: number): GateList {
|
||||
const twin = twinOf(f.id) ? byId.get(twinOf(f.id)!) as ChallengeRow | undefined : undefined;
|
||||
const narrows = narrowedQuoteOf(owner, f) ?? narrowedQuoteOf(owner, twin);
|
||||
if (narrows) {
|
||||
const rows = [f, ...(twin && !twin.settled_by && !challenged.has(twin.id) ? [twin] : [])];
|
||||
const rows = [f, ...(twin && !twin.settled_by && !challenged.has(twin.id) && (!twin.narrows_quote || twin.narrows_quote === narrows.n) ? [twin] : [])];
|
||||
rows.forEach(r => challenged.add(r.id));
|
||||
if (!(narrows.line?.kind === 'ruled_out' && owner.ruled.has(narrows.n))) { narrowed.push(...rows.map(r => ({ ...r, narrows_quote: narrows.n }))); continue; }
|
||||
const ids = rows.map(r => r.id);
|
||||
push({ id: `d${++d}`, title: `${f.title} [${ids.join(' + ')}]`, kind: 'auto', recommended: 'a', phase, item_class: 'challenge1', ...(heaviestChanges(rows) ? { changes: heaviestChanges(rows) } : {}),
|
||||
why: `${rows.map(r => r.voice).join(' + ')} say${rows.length > 1 ? '' : 's'} the plan does less than your words “${narrows.text}”, but ${lineText({ ...narrows, ruling_verified: true })}`,
|
||||
cost: `b reopens ${phase}${phase === 'eng' ? '' : ' and eng'}`, options: [KEEP('keep your ruling'), { key: 'b', text: 'accept the change', changes_plan: true }] }, ids.join('+'));
|
||||
cost: `b reopens ${phase}${phase === 'eng' ? '' : ' and eng'}`, options: [KEEP('keep your ruling'), { key: 'b', text: 'accept the change', changes_plan: true }] }, ids.join('+'), RULING_ORIGIN);
|
||||
continue;
|
||||
}
|
||||
if (quoted && (f.changes || f.user_challenge) && !ownerQuoteOf(owner, f)) {
|
||||
|
||||
Reference in new issue
Block a user