Review and ship tools: read Codex numbered severities, check Remote Control sessions, see every worktree (#4681)

Five fixes from outside reports. The too-large-diff fix line now
suggests only folders the policy can exclude, Codex findings written as
`### 1. High` keep their severity, /autoplan's report check runs in
Remote Control sessions, /ship's version picker sees all worktrees, and
PR before/after images use the real base.

Why: each reproduced on main with a failing test and gave a wrong
answer.

Nothing to do after merge.

Co-authored-by: larsonthune <195244869+larsonthune@users.noreply.github.com>
Co-authored-by: vilano93 <244097767+vilano93@users.noreply.github.com>
Co-authored-by: szsunyuan <3579304+szsunyuan@users.noreply.github.com>
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
This commit is contained in:
authored and GitHub committed 2026-11-22 12:38:59 +00:00
1 parent 4bd15f8a3d
commit b3323f47b8
13 files changed
+250 -39

No files matched your search

+6 -2
View File
@@ -230,6 +230,8 @@ export interface RecordMeta {
message: boolean;
role?: string;
sessionStart: boolean;
/** Remote Control's status record, written as the conversation root when it is active before the first prompt. */
bridgeRoot: boolean;
timestampValid: boolean;
cwd?: string;
type?: string;
@@ -285,7 +287,9 @@ export function recordMeta(r: Record<string, any>, index: number): RecordMeta {
agent: r.agentId != null, sidechain: r.isSidechain !== false,
conversation: r.agentId == null && message && (r.message.role === 'user' || r.message.role === 'assistant'),
message, role: message && typeof r.message.role === 'string' ? r.message.role : undefined,
sessionStart: sessionStartRecord(r), timestampValid, cwd,
sessionStart: sessionStartRecord(r),
bridgeRoot: r.type === 'system' && r.subtype === 'bridge_status' && r.parentUuid === null && r.message == null,
timestampValid, cwd,
type: typeof r.type === 'string' ? r.type : undefined, subtype: typeof r.subtype === 'string' ? r.subtype : undefined,
attachmentType: object(r.attachment) && typeof r.attachment.type === 'string' ? r.attachment.type : undefined,
version: indexedVersion(r),
@@ -384,7 +388,7 @@ export function ownedCausalOrder(metas: readonly RecordMeta[], cwd: string): Own
for (const node of genesis ? [root] : top.slice(0, turn + 1)) if (!sameNativePath(node.cwd, cwd))
return { reason: sameRealPath(node.cwd, cwd) ? 'unrecognized_shape:cwd_spelling' : 'foreign_cwd', shape: shape() };
if (!genesis) {
const preamble = top.slice(0, turn).find(n => !n.sessionStart);
const preamble = top.slice(0, turn).find(n => !n.sessionStart && !n.bridgeRoot);
const odd = !root.parentNull ? `root_parent:${shapeOf(root)}`
: preamble ? `preamble:${shapeOf(preamble)}`
: top[turn]!.role !== 'user' ? `first_turn:${shapeOf(top[turn]!)}` : undefined;
+3 -3
View File
@@ -166,7 +166,7 @@ const AUTOPLAN_LEVEL: Record<string, Severity | undefined> = { Critical: 'P0', H
const WORD = '(critical|high|medium|low)';
const SEVERITY_LABELS = [
new RegExp(`\\b(?:severity|priority)\\b[\\t ]*[:=][\\t ]*(?:\\*\\*|__|\\[|\`)*${WORD}\\b`, 'gim'),
new RegExp(`^[\\t ]*(?:>[\\t ]*)?(?:#{1,6}[\\t ]+|[-+*][\\t ]+|\\(?\\d{1,3}[.)][\\t ]+)?(?:\\*\\*|__)?\\[?${WORD}\\]?(?:\\*\\*|__)?[\\t ]*(?::|\u2014|\u2013|-[\\t ]|\\]|\\(|\\*\\*[\\t ]*(?:\u2014|\u2013|-[\\t ]))`, 'gim'),
new RegExp(`^[\\t ]*(?:>[\\t ]*)?(?:#{1,6}[\\t ]+)?(?:[-+*][\\t ]+|\\(?\\d{1,3}[.)][\\t ]+)?(?:\\*\\*|__)?\\[?${WORD}\\]?(?:\\*\\*|__)?[\\t ]*(?::|\u2014|\u2013|-[\\t ]|\\]|\\(|\\*\\*[\\t ]*(?:\u2014|\u2013|-[\\t ]))`, 'gim'),
new RegExp(`(?:\\*\\*|__)\\[?${WORD}\\]?:?(?:\\*\\*|__)`, 'gi'),
new RegExp(`\\|[\\t ]*(?:\\*\\*)?${WORD}(?:\\*\\*)?[\\t ]*(?=\\|)`, 'gi'),
new RegExp(`[\\t ](?:\u2014|\u2013|-)[\\t ]+(?:\\*\\*|__)?${WORD}(?:\\*\\*|__)?[\\t ]*[.;]?[\\t ]*$`, 'gim'),
@@ -216,7 +216,7 @@ function recommendationHeading(text: string): string {
* or `Verdict: not ready`, while the evidence for clean keeps it blanked. One pass:
* an opener closes only when a later marker of its kind is at least as long.
*/
const CODE_LABEL_BEFORE = /^[\t ]*(?:>[\t ]*)?(?:#{1,6}[\t ]+|[-+*][\t ]+|\(?\d{1,3}[.)][\t ]+)?(?:\*\*|__)?$|\b(?:severity|priority)[\t ]*[:=][\t ]*(?:\*\*|__)?$|\|[\t ]*(?:\*\*)?$/i;
const CODE_LABEL_BEFORE = /^[\t ]*(?:>[\t ]*)?(?:#{1,6}[\t ]+)?(?:[-+*][\t ]+|\(?\d{1,3}[.)][\t ]+)?(?:\*\*|__)?$|\b(?:severity|priority)[\t ]*[:=][\t ]*(?:\*\*|__)?$|\|[\t ]*(?:\*\*)?$/i;
function withoutCode(text: string, readUnclosed = false): string {
const lines = text.split(/\r?\n/);
const markers = lines.map(line => /^[\t ]*(`{3,}|~{3,})/.exec(line)?.[1]);
@@ -248,7 +248,7 @@ function withoutCode(text: string, readUnclosed = false): string {
* bullet, number or bold, as `[P1]`, `P1:`, `P1 —`, `**P1 — x**`, `**P1** — x`,
* `P1 (x)` or a bare `P1` ending the line; or a table cell `| P1 |`.
*/
const LABEL_START = '^[\\t ]*(?:>[\\t ]*)?(?:#{1,6}[\\t ]+|[-+*][\\t ]+|\\(?\\d{1,3}[.)][\\t ]+)?(?:\\*\\*|__)?';
const LABEL_START = '^[\\t ]*(?:>[\\t ]*)?(?:#{1,6}[\\t ]+)?(?:[-+*][\\t ]+|\\(?\\d{1,3}[.)][\\t ]+)?(?:\\*\\*|__)?';
const LABELED_P = new RegExp(`${LABEL_START}(?:\\[(P[0-3])\\]|(P[0-3])(?:\\*\\*|__)?[\\t ]*(?::|\u2014|\u2013|-[\\t ]|\\(|$|(?:\\*\\*|__)[\\t ]*(?::|\u2014|\u2013|-[\\t ]|$)))`, 'gm');
const TABLE_P = /\|[\t ]*(?:\*\*)?\[?(P[0-3])\]?(?:\*\*)?[\t ]*(?=\|)/g;
const LABEL_P = new RegExp(`${LABEL_START}\\[?P[0-3]\\b`);
+13 -6
View File
@@ -17,7 +17,8 @@
import { spawnSync } from './spawn-sync';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { resolveBase } from './gate-diff/git';
import { defaultBase as defaultBaseRef, mergeBase, resolveBase } from './gate-diff/git';
import { noDefaultBaseLine } from './default-base';
import { findSection } from './markdown-sections';
import { scan } from './redact-engine';
import type { ResultCodeName } from './result-codes';
@@ -65,13 +66,19 @@ export function resolveCommit(cwd: string, ref: string): string | ShotError {
return r.status === 0 ? r.stdout.trim() : { code: 'PR_SHOTS_INPUT_NOT_FOUND', message: `base ref ${ref}` };
}
/** The default base: where this branch left origin's default branch. */
/**
* The default base: where this branch left its base branch, chosen by the shared default-base rules (a remote HEAD naming
* this branch is skipped, #3733). A stale remote HEAD falls back to main, then master.
*/
export function defaultBase(cwd: string): string | ShotError {
for (const ref of ['origin/HEAD', 'origin/main', 'main']) {
const r = git(cwd, ['merge-base', 'HEAD', ref]);
if (r.status === 0 && r.stdout.trim()) return r.stdout.trim();
const found = defaultBaseRef(cwd);
if ('skipped' in found) return { code: 'PR_SHOTS_INPUT_NOT_FOUND', message: noDefaultBaseLine(found.skipped) };
for (const ref of [found.ref, 'main', 'master']) {
const base = resolveBase(ref, cwd, 'HEAD');
const fork = base && mergeBase('HEAD', base.sha, cwd);
if (fork) return fork;
}
return { code: 'PR_SHOTS_INPUT_NOT_FOUND', message: 'no merge base with origin/HEAD, origin/main or main; pass --base <ref>' };
return { code: 'PR_SHOTS_INPUT_NOT_FOUND', message: `no merge base with ${found.ref}, main or master; pass --base <ref>` };
}
/** Both sides of a tracked file (or one heading's section of it) at `base` and in the working tree. */
+23 -6
View File
@@ -664,17 +664,33 @@ function policyJson(patterns: readonly string[], floor?: string | null): string
return JSON.stringify({ review_exclude_paths: patterns, min_gstack_version: min });
}
/** Folders to suggest: the largest top directories, until what is left would fit. */
function suggest(byDir: ReadonlyArray<[string, number]>, bytes: number): string[] {
/** By path alone, whether review_exclude_paths could exclude a file: content (data, logs, docs, binary assets), never code or tests. */
const excludableByPath = (p: string) => !SOURCE.test(p) && (DATA_PATH.test(p) || /\.log$/i.test(p) || BINARY_CONTENT_EXT.test(p) || classifyPath(p) === 'docs');
/**
* Folders to suggest: the top directories holding the most bytes the policy could exclude (whole folders when only folder
* sizes are known), until what is left would fit; none when they cannot get the reader under the ceiling (#4369).
*/
function suggest(d: { bytes: number; byDir: ReadonlyArray<[string, number]>; byFile?: ReadonlyArray<[string, number]> }): string[] {
let byDir = d.byDir;
if (d.byFile?.length) {
const excludable = new Map<string, number>();
for (const [file, n] of d.byFile) {
if (!excludableByPath(file)) continue;
const dir = file.includes('/') ? file.split('/')[0]! : '(root)';
excludable.set(dir, (excludable.get(dir) ?? 0) + n);
}
byDir = [...excludable].sort((a, b) => b[1] - a[1]);
}
const out: string[] = [];
let left = bytes;
let left = d.bytes;
for (const [dir, n] of byDir) {
if (left <= REVIEW_DIFF_MAX_BYTES || out.length >= 3) break;
if (dir === '(root)') continue;
out.push(`${dir}/**`);
left -= n;
}
return out;
return left <= REVIEW_DIFF_MAX_BYTES ? out : [];
}
/** The REVIEW_DIFF_TOO_LARGE line and object: the reader's bytes, the largest folders and files, and a fix chosen by where the policy stands. */
@@ -684,9 +700,10 @@ export function tooLargeLine(context: string, reader: string, d: { bytes: number
const largest = (d.byFile ?? []).slice(0, 5);
const split = largest.length ? `split the PR (largest files: ${largest.map(([f, n]) => `${named(f)} (${n} bytes)`).join(', ')})` : 'split the PR';
const land = (patterns: readonly string[]) => `ask the repo owner to land ${policyJson(patterns, c.floor)} in ${SHIP_POLICY_PATH} on ${c.base} as its own PR (docs/ship-policy.md#review-exclude-paths), then bring ${c.base} into this branch and rerun once; if it is still over, ${split}`;
const dirs = suggest(d.byDir, d.bytes);
const dirs = suggest(d);
const fresh = dirs.filter(p => !c.record?.patterns.includes(p));
const fix = c.state === 'head-only' ? `this branch declares review_exclude_paths, but only the copy on ${c.base} applies: ${land(c.headPatterns ?? [])}`
: c.state === 'active' ? `still over after excluding ${c.record?.excluded ?? 0} files; ${dirs.length ? land([...(c.record?.patterns ?? []), ...dirs.filter(p => !c.record?.patterns.includes(p))]) : split}`
: c.state === 'active' ? `still over after excluding ${c.record?.excluded ?? 0} files; ${fresh.length ? land([...(c.record?.patterns ?? []), ...fresh]) : split}`
: dirs.length ? land(dirs) : split;
const files = largest.length ? ` files=${largest.map(([f, n]) => `${/[\s,:"]/.test(f) ? JSON.stringify(f) : f}:${n}`).join(',')}` : '';
const line = `${context}: the reader's diff is over the review ceiling (reader=${reader} bytes=${d.bytes} max=${REVIEW_DIFF_MAX_BYTES} top=${top}${files} policy=${c.source}); fix: ${fix}; nothing was written (REVIEW_DIFF_TOO_LARGE)`;