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:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-24 20:54:18 +00:00
1 parent 4394a02363
commit beca1d6f15
9 files changed
+84 -25

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ The first `next` prints `SCOPE: ui=… (terms; visual; files) dx=… (detected)
TODOS*, docs/** but not docs/*-policy.md, or other markdown outside a skill dir) runs CEO on the native voice only, then Eng. UI needs a rendered file path (including a named non-test `.ts`/`.js` file that holds a tagged `html`, `css` or `svg` template, such as Lit or htm) or a UI term next
to a visual noun in the Implementation plan. To keep flags for later runs on the same plan, add
the `SCOPE_PIN:` marker it prints (`<!-- gstack-autoplan-scope: … -->`) as the plan's first
line yourself; gstack never writes the plan. **First versions** (a `### Day one` section or `--first-version`): the plan quotes the owner under `### Owner's words`, one bullet each, `- <who>, <when>: "<words>" → does it | choice[; size: <n>][; leave out: <reason>] | ruled out <date>: "<ruling>"` (a ruling stands against a reviewer only when a recorded owner reply holds it; otherwise the gate asks him, recommending it); the gate letters each quote this version doesn't fully do and every cut, the five day-one rows cite `owner words <n>`, and the build clears `gstack-first-use` before the owner is asked to try it ([docs/first-use-check.md](../docs/first-use-check.md)). **Kinds (R65), first `next` only.** `--kind fix` reviews nothing: it prints `AUTOPLAN: not needed (bug fix; R65)`, a `PROOF:` line and `GSTACK_RESULT: skill=autoplan status=skipped run=-`, writes nothing and needs no `--out` or `--plan`; the PR still carries the bug's proof, a repro on current main or a failing test written first. `--kind feature`, the default for an unattended run on Capy (`GSTACK_CAPY=1`) that names no kind, is the lean run. Its `phase_order` is `eng` alone with one native reviewer, whose prompt merges the CEO and Eng lenses (Design or DX only when scope detects them), each a short role or brief plus that review skill's checklist, never the skill's own method, always asks "Any outside terms, licences or rights involved?" and shows the draft code. The draft is `git diff` from the merge base with `--base <ref>` (default: `gstack-diff-scope`'s base, never an `origin/HEAD` naming the checked-out branch), untracked files included and the run directory left out, written to the snapshot as `draft.diff` and hashed; with no code yet it says `DRAFT: none (<why>)`. The first `next` prints `LEAN:` and each opened phase `DRAFT:`; the reviewer's line after INPUT must be `DRAFT: <sha256>` or `DRAFT: none`, or submit refuses it (`RESULT_RECEIPT_MISSING`). No outside voice, `--max-rounds 1`, no carry check and one gate revision: `revise --incorporates` applies the accepted changes without re-review and approves. `--full` brings back every phase and both voices: each native reviewer gets a five-question brief and its phase's checklist, each outside reviewer a one-paragraph role, and neither the skill's own method. Off Capy, and in an interactive session, the default stays full.
line yourself; gstack never writes the plan. **First versions** (a `### Day one` section or `--first-version`): the plan quotes the owner under `### Owner's words`, one bullet each, `- <who>, <when>: "<words>" → does it | choice[; size: <n>][; leave out: <reason>] | ruled out <date>: "<ruling>"` (`<date>` cites the one recorded owner reply by its id, its time `YYYY-MM-DD HH:MMZ`, or its day when it was his only reply that day; the ruling stands against a reviewer only when that reply holds it, otherwise the gate asks him, recommending it); the gate letters each quote this version doesn't fully do and every cut, the five day-one rows cite `owner words <n>`, and the build clears `gstack-first-use` before the owner is asked to try it ([docs/first-use-check.md](../docs/first-use-check.md)). **Kinds (R65), first `next` only.** `--kind fix` reviews nothing: it prints `AUTOPLAN: not needed (bug fix; R65)`, a `PROOF:` line and `GSTACK_RESULT: skill=autoplan status=skipped run=-`, writes nothing and needs no `--out` or `--plan`; the PR still carries the bug's proof, a repro on current main or a failing test written first. `--kind feature`, the default for an unattended run on Capy (`GSTACK_CAPY=1`) that names no kind, is the lean run. Its `phase_order` is `eng` alone with one native reviewer, whose prompt merges the CEO and Eng lenses (Design or DX only when scope detects them), each a short role or brief plus that review skill's checklist, never the skill's own method, always asks "Any outside terms, licences or rights involved?" and shows the draft code. The draft is `git diff` from the merge base with `--base <ref>` (default: `gstack-diff-scope`'s base, never an `origin/HEAD` naming the checked-out branch), untracked files included and the run directory left out, written to the snapshot as `draft.diff` and hashed; with no code yet it says `DRAFT: none (<why>)`. The first `next` prints `LEAN:` and each opened phase `DRAFT:`; the reviewer's line after INPUT must be `DRAFT: <sha256>` or `DRAFT: none`, or submit refuses it (`RESULT_RECEIPT_MISSING`). No outside voice, `--max-rounds 1`, no carry check and one gate revision: `revise --incorporates` applies the accepted changes without re-review and approves. `--full` brings back every phase and both voices: each native reviewer gets a five-question brief and its phase's checklist, each outside reviewer a one-paragraph role, and neither the skill's own method. Off Capy, and in an interactive session, the default stays full.
## The loop
+1 -1
View File
@@ -17,7 +17,7 @@ The first `next` prints `SCOPE: ui=… (terms; visual; files) dx=… (detected)
TODOS*, docs/** but not docs/*-policy.md, or other markdown outside a skill dir) runs CEO on the native voice only, then Eng. UI needs a rendered file path (including a named non-test `.ts`/`.js` file that holds a tagged `html`, `css` or `svg` template, such as Lit or htm) or a UI term next
to a visual noun in the Implementation plan. To keep flags for later runs on the same plan, add
the `SCOPE_PIN:` marker it prints (`<!-- gstack-autoplan-scope: … -->`) as the plan's first
line yourself; gstack never writes the plan. **First versions** (a `### Day one` section or `--first-version`): the plan quotes the owner under `### Owner's words`, one bullet each, `- <who>, <when>: "<words>" → does it | choice[; size: <n>][; leave out: <reason>] | ruled out <date>: "<ruling>"` (a ruling stands against a reviewer only when a recorded owner reply holds it; otherwise the gate asks him, recommending it); the gate letters each quote this version doesn't fully do and every cut, the five day-one rows cite `owner words <n>`, and the build clears `gstack-first-use` before the owner is asked to try it ([docs/first-use-check.md](../docs/first-use-check.md)). **Kinds (R65), first `next` only.** `--kind fix` reviews nothing: it prints `AUTOPLAN: not needed (bug fix; R65)`, a `PROOF:` line and `GSTACK_RESULT: skill=autoplan status=skipped run=-`, writes nothing and needs no `--out` or `--plan`; the PR still carries the bug's proof, a repro on current main or a failing test written first. `--kind feature`, the default for an unattended run on Capy (`GSTACK_CAPY=1`) that names no kind, is the lean run. Its `phase_order` is `eng` alone with one native reviewer, whose prompt merges the CEO and Eng lenses (Design or DX only when scope detects them), each a short role or brief plus that review skill's checklist, never the skill's own method, always asks "Any outside terms, licences or rights involved?" and shows the draft code. The draft is `git diff` from the merge base with `--base <ref>` (default: `gstack-diff-scope`'s base, never an `origin/HEAD` naming the checked-out branch), untracked files included and the run directory left out, written to the snapshot as `draft.diff` and hashed; with no code yet it says `DRAFT: none (<why>)`. The first `next` prints `LEAN:` and each opened phase `DRAFT:`; the reviewer's line after INPUT must be `DRAFT: <sha256>` or `DRAFT: none`, or submit refuses it (`RESULT_RECEIPT_MISSING`). No outside voice, `--max-rounds 1`, no carry check and one gate revision: `revise --incorporates` applies the accepted changes without re-review and approves. `--full` brings back every phase and both voices: each native reviewer gets a five-question brief and its phase's checklist, each outside reviewer a one-paragraph role, and neither the skill's own method. Off Capy, and in an interactive session, the default stays full.
line yourself; gstack never writes the plan. **First versions** (a `### Day one` section or `--first-version`): the plan quotes the owner under `### Owner's words`, one bullet each, `- <who>, <when>: "<words>" → does it | choice[; size: <n>][; leave out: <reason>] | ruled out <date>: "<ruling>"` (`<date>` cites the one recorded owner reply by its id, its time `YYYY-MM-DD HH:MMZ`, or its day when it was his only reply that day; the ruling stands against a reviewer only when that reply holds it, otherwise the gate asks him, recommending it); the gate letters each quote this version doesn't fully do and every cut, the five day-one rows cite `owner words <n>`, and the build clears `gstack-first-use` before the owner is asked to try it ([docs/first-use-check.md](../docs/first-use-check.md)). **Kinds (R65), first `next` only.** `--kind fix` reviews nothing: it prints `AUTOPLAN: not needed (bug fix; R65)`, a `PROOF:` line and `GSTACK_RESULT: skill=autoplan status=skipped run=-`, writes nothing and needs no `--out` or `--plan`; the PR still carries the bug's proof, a repro on current main or a failing test written first. `--kind feature`, the default for an unattended run on Capy (`GSTACK_CAPY=1`) that names no kind, is the lean run. Its `phase_order` is `eng` alone with one native reviewer, whose prompt merges the CEO and Eng lenses (Design or DX only when scope detects them), each a short role or brief plus that review skill's checklist, never the skill's own method, always asks "Any outside terms, licences or rights involved?" and shows the draft code. The draft is `git diff` from the merge base with `--base <ref>` (default: `gstack-diff-scope`'s base, never an `origin/HEAD` naming the checked-out branch), untracked files included and the run directory left out, written to the snapshot as `draft.diff` and hashed; with no code yet it says `DRAFT: none (<why>)`. The first `next` prints `LEAN:` and each opened phase `DRAFT:`; the reviewer's line after INPUT must be `DRAFT: <sha256>` or `DRAFT: none`, or submit refuses it (`RESULT_RECEIPT_MISSING`). No outside voice, `--max-rounds 1`, no carry check and one gate revision: `revise --incorporates` applies the accepted changes without re-review and approves. `--full` brings back every phase and both voices: each native reviewer gets a five-question brief and its phase's checklist, each outside reviewer a one-paragraph role, and neither the skill's own method. Off Capy, and in an interactive session, the default stays full.
## The loop
@@ -0,0 +1 @@
**A first version's ruled-out line now counts only against the one reply it cites.** The date in `ruled out <date>: "<ruling>"` names the owner's recorded reply by its record id, its time (`2026-11-18 09:20Z`), or its day when he sent only one reply that day. The ruling beats a reviewer only when that reply holds its words. A citation that names no reply or several, or a reply that doesn't hold the ruling, makes the approval gate ask him instead. Words from some other reply no longer count. Keeping his ruling also leaves the build with no task for the fix he turned down. A second reviewer's finding that names a different quote now stays on its own item instead of joining this one. (GST-3646)
+2 -2
View File
@@ -16,7 +16,7 @@ A plan is a first version when it has a `Day one` section or the run passes `--f
- Ada Example, 2026-11-18 09:12Z: "I keep forgetting which plant needs water" → does it
- Ada Example, 2026-11-18 09:14Z: "and tell my partner when I'm away" → choice; size: two days; leave out: needs a second account
- Ada Example, 2026-11-18 09:20Z: "and maybe post my streak" → ruled out 2026-11-18: "no posting anywhere, ever"
- Ada Example, 2026-11-18 09:20Z: "and maybe post my streak" → ruled out 2026-11-18 09:31Z: "no posting anywhere, ever"
```
Each bullet is who, when, the words in quotes, then an arrow (`→` or `->`) and the line:
@@ -25,7 +25,7 @@ Each bullet is who, when, the words in quotes, then an arrow (`→` or `->`) and
|---|---|---|
| `does it` | this version does what the words ask | a reviewer who finds it does less files a `narrows_quote` finding, and the gate asks |
| `choice` | this version doesn't fully do it yet | one lettered choice quoting the words: a) build it in this version, b) leave it out. It recommends a, unless the line says `leave out: <reason>`, shown on the choice. `size: <n>` is shown as the cost |
| `ruled out <date>: "<ruling>"` | the owner ruled it out himself | when one of his recorded replies holds the ruling, it beats a reviewer: a finding that says the plan falls short of these words becomes one item recommending his ruling, and a cut of them stays a cut. When no recorded reply holds it, the gate asks him once, with the ruling and any finding side by side and the ruling recommended |
| `ruled out <date>: "<ruling>"` | the owner ruled it out himself | `<date>` names the one recorded reply the ruling came from: its record id, its time (`2026-11-18 09:20Z`), or just its day when he sent only one reply that day. When that one reply holds the ruling, it beats a reviewer. A finding that says the plan falls short of these words becomes one item recommending his ruling, a cut of them stays a cut, and keeping the ruling leaves no build task for the fix he turned down. When the citation names no reply or more than one, or the reply it names doesn't hold the ruling, the gate asks him once, with the ruling and any finding side by side and the ruling recommended |
A public export (`gstack-autoplan export --public`) drops the owner's words: every quote and every ruling, however short, wherever it appears in quote marks, and every `leave out:` reason, wherever the gate shows it. A quote of three or more words is also caught where it is repeated without quote marks.
+3
View File
@@ -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.
+3 -1
View File
@@ -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
View File
@@ -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,
+3 -3
View File
@@ -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)) {
+46 -5
View File
@@ -523,7 +523,7 @@ describe('first versions: the owner page quotes the owner and letters what it le
const calendar = (voice: 'native' | 'outside', tagged = true) => row('ceo', voice, { id: `${RUN}-ceo-r2-${voice}-1`, severity: 'High', title: 'Leaving the calendar out does less than the owner asked for', changes: 'scope', resolution: 'add calendar reads', ...(tagged ? { narrows_quote: 3 } : {}) } as Row);
const run = (name: string, o: { said?: boolean; native?: FindingRow[]; outside?: FindingRow[]; cuts?: string }) => {
const state = makeRun(name, { plan: plan(CASE5, o.cuts), round2: { native: o.native ?? [], outside: o.outside ?? [] }, round1: false, ui: false });
if (o.said) fs.writeFileSync(path.join(state.out, 'attempts.jsonl'), JSON.stringify({ owner_reply: `c3: no. ${RULING}` }) + '\n');
if (o.said) fs.writeFileSync(path.join(state.out, 'attempts.jsonl'), JSON.stringify({ ts: '2026-11-12T09:00:12Z', owner_reply: `c3: no. ${RULING}` }) + '\n');
return state;
};
const calendarItems = (list: GateList) => list.items.filter(i => i.title.includes('calendar'));
@@ -537,13 +537,54 @@ describe('first versions: the owner page quotes the owner and letters what it le
test('a ruling dated with a time parses; a short ruling, or one that only repeats the quote, never counts as recorded', () => {
expect(parseOwnerWords("### Owner's words\n\n- The owner, 2026-11-23 10:04Z: \"add dark mode\" → ruled out 2026-11-24 09:12Z: \"not in the first version\"").quotes[0]).toMatchObject({ text: 'add dark mode', line: { kind: 'ruled_out', date: '2026-11-24 09:12Z', ruling: 'not in the first version' } });
const ruledWith = (ruling: string, replies: string[]) => {
const ruledWith = (ruling: string, replies: Array<{ text: string; at?: string }>) => {
const state = makeRun(`ruled-floor-${ruling.replace(/\W+/g, '-')}`, { plan: plan(CASE4 + `\n- The owner, 2026-11-12 09:00Z: "never touch my calendar or my reminders" → ruled out 2026-11-12: "${ruling}"`), round2: { native: [], outside: [] }, round1: false, ui: false });
return ownerContext(state, replies).ruled;
};
expect(ruledWith('no', ['c1: no, keep the dark mode'])).toEqual(new Set());
expect(ruledWith('never touch my calendar', ['never touch my calendar or my reminders'])).toEqual(new Set());
expect(ruledWith('leave my calendar alone', ['never touch my calendar or my reminders. actually leave my calendar alone'])).toEqual(new Set([3]));
const at = '2026-11-12T09:00:00Z';
expect(ruledWith('no', [{ text: 'c1: no, keep the dark mode', at }])).toEqual(new Set());
expect(ruledWith('never touch my calendar', [{ text: 'never touch my calendar or my reminders', at }])).toEqual(new Set());
expect(ruledWith('leave my calendar alone', [{ text: 'never touch my calendar or my reminders. actually leave my calendar alone', at }])).toEqual(new Set([3]));
});
test('a ruling is checked against the one reply its citation names; no reply, two replies or another day means he is asked', () => {
const ruledCiting = (cite: string, replies: Array<{ text: string; at?: string; id?: string }>) => {
const state = makeRun(`ruled-cite-${cite.replace(/\W+/g, '-')}-${replies.length}`, { plan: plan(CASE4 + `\n- The owner, 2026-11-12 09:00Z: "never touch my calendar" → ruled out ${cite}: "${RULING}"`), round2: { native: [], outside: [] }, round1: false, ui: false });
return ownerContext(state, replies).ruled;
};
const said = { text: `c3: no. ${RULING}`, at: '2026-11-12T09:00:12Z', id: 'run-g1-d3' };
const other = { text: 'c1: yes, build the contacts', at: '2026-11-12T16:30:00Z', id: 'run-g1-d1' };
expect(ruledCiting('2026-11-12', [said])).toEqual(new Set([3]));
expect(ruledCiting('2026-11-12', [said, other])).toEqual(new Set());
expect(ruledCiting('2026-11-12 09:00Z', [said, other])).toEqual(new Set([3]));
expect(ruledCiting('run-g1-d3', [said, other])).toEqual(new Set([3]));
expect(ruledCiting('run-g1-d1', [said, other])).toEqual(new Set());
expect(ruledCiting('2026-11-13', [said])).toEqual(new Set());
expect(ruledCiting('2026-11-12', [{ text: said.text }])).toEqual(new Set());
const copies = [{ ...said, id: 'run-g1-p1' }, { ...said, id: 'run-g1-c3' }, { text: said.text, at: '2026-11-12T09:00:12.004Z' }, { text: said.text, at: said.at, id: 'appr-1' }];
expect(ruledCiting('2026-11-12', copies)).toEqual(new Set([3]));
expect(ruledCiting('2026-11-12 09:00Z', copies)).toEqual(new Set([3]));
expect(ruledCiting('2026-11-12', [...copies, other])).toEqual(new Set());
});
test('paired findings that name different quotes each reach their own item', () => {
const onDoesIt = row('ceo', 'outside', { id: `${RUN}-ceo-r2-outside-1`, severity: 'High', title: 'Leaving the calendar out does less than the owner asked for', changes: 'scope', resolution: 'add calendar reads', narrows_quote: 1 } as Row);
const list = buildGate(run('ruled-twin-apart', { said: true, native: [calendar('native')], outside: [onDoesIt] }), 1);
expect(calendarItems(list).filter(i => i.item_class === 'challenge1').map(i => i.origin!.split('|')[1])).toEqual([`${RUN}-ceo-r2-native-1`]);
const twoWay = byClass(list, 'owner_choice').find(i => i.title.includes('two-way'))!;
expect(twoWay.origin!.split('|')[1]!.split('+')).toEqual(['quote:1', `${RUN}-ceo-r2-outside-1`]);
expect(twoWay.recommended).toBe('a');
});
test('keeping a recorded ruling leaves no build task for the fix it turned down; accepting the change keeps the task', () => {
for (const chosen of ['a', 'b'] as const) {
const state = run(`ruled-task-${chosen}`, { said: true, native: [calendar('native')] });
const item = calendarItems(buildGate(state, 1))[0]!;
expect(item.origin!.endsWith('|ruling')).toBe(true);
writeDecisions(state.out, [{ schema_version: 1, run: RUN, id: `${RUN}-g1-${item.id}`, gate_rev: 1, label: item.id.toUpperCase(), title: item.title, status: 'overridden', chosen, origin: item.origin } as any]);
const tasks = buildTasks(state, [calendar('native')]);
expect(tasks.map(t => t.findings), chosen).toEqual(chosen === 'a' ? [] : [[`${RUN}-ceo-r2-native-1`]]);
}
});
test('a recorded ruling beats a High finding: one item recommending the ruling, never a build-it choice or a proposal', () => {