jig-plan 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +75 -10
- package/agents/jig-reviewer.md +79 -15
- package/cli/jig.mjs +34 -3
- package/cli/lib/hooks.mjs +228 -19
- package/cli/lib/lint.mjs +2 -1
- package/cli/lib/review.mjs +403 -0
- package/cli/lib/verify.mjs +15 -6
- package/package.json +1 -1
- package/skills/build/SKILL.md +3 -2
- package/skills/review/SKILL.md +108 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
// jig review: the brief a reviewer starts from. Deterministic, and it runs
|
|
2
|
+
// only git (hardened, through git.mjs) and, for --pr, gh. It never runs a
|
|
3
|
+
// repo's own commands: the gate is the review skill's job.
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
import { readFileSync, lstatSync, appendFileSync } from 'node:fs';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { join, relative } from 'node:path';
|
|
8
|
+
import { git, isCommit, stateDir } from './git.mjs';
|
|
9
|
+
import { activePlans, doingSlice, plansDir } from './status.mjs';
|
|
10
|
+
import { lastEvidence, workTree, readJsonl } from './verify.mjs';
|
|
11
|
+
import { loadChecks } from './checks.mjs';
|
|
12
|
+
import { section } from './plan.mjs';
|
|
13
|
+
import { diagnose } from './doctor.mjs';
|
|
14
|
+
import { pathMatches } from './hooks.mjs';
|
|
15
|
+
|
|
16
|
+
const lines = (s) => (s ?? '').split('\n').filter(Boolean);
|
|
17
|
+
const full = (root, ref) => git(root, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`])?.trim() || null;
|
|
18
|
+
|
|
19
|
+
// ---------- base ----------
|
|
20
|
+
|
|
21
|
+
function defaultBranch(root) {
|
|
22
|
+
const remote = git(root, ['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD'])?.trim();
|
|
23
|
+
if (remote) return remote;
|
|
24
|
+
// A CI checkout has neither origin/HEAD nor a local main.
|
|
25
|
+
for (const b of ['refs/heads/main', 'refs/heads/master', 'refs/remotes/origin/main', 'refs/remotes/origin/master']) if (full(root, b)) return b.replace(/^refs\/(heads|remotes)\//, '');
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The newest commit since Baseline whose Verified: trailer names another
|
|
30
|
+
// slice; else Baseline. Build step 5 writes that trailer on every slice commit.
|
|
31
|
+
export function sliceStart(root, baseline, sliceId) {
|
|
32
|
+
const start = full(root, baseline);
|
|
33
|
+
if (!start) return null;
|
|
34
|
+
const log = git(root, ['log', '--format=%H%x00%B%x1e', `${start}..HEAD`]) ?? '';
|
|
35
|
+
for (const rec of log.split('\x1e')) {
|
|
36
|
+
const [sha, body = ''] = rec.trim().split('\0');
|
|
37
|
+
if (!sha) continue;
|
|
38
|
+
const named = [...body.matchAll(/^Verified:\s+(S\d+)\b/gm)].map((m) => m[1]);
|
|
39
|
+
if (named.some((s) => s !== sliceId)) return sha;
|
|
40
|
+
}
|
|
41
|
+
return start;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function fromPr(root, pr) {
|
|
45
|
+
if (!/^\d+$/.test(String(pr))) return { error: `--pr needs a PR number, got "${pr}"` };
|
|
46
|
+
let j;
|
|
47
|
+
try {
|
|
48
|
+
j = JSON.parse(execFileSync('gh', ['pr', 'view', String(pr), '--json', 'baseRefOid,baseRefName,headRefOid,author,number'], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 20000 }));
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return { error: `gh pr view ${pr} failed (${e.code === 'ENOENT' ? 'gh is not installed' : String(e.stderr || e.message).trim().split('\n')[0]})` };
|
|
51
|
+
}
|
|
52
|
+
if (typeof j?.headRefOid !== 'string' || typeof j?.baseRefOid !== 'string') return { error: `gh pr view ${pr} gave no base or head commit` };
|
|
53
|
+
if (!isCommit(root, j.headRefOid)) return { error: `PR ${pr}'s head ${j.headRefOid.slice(0, 7)} isn't in this clone; run \`gh pr checkout ${pr}\` first` };
|
|
54
|
+
if (!isCommit(root, j.baseRefOid)) return { error: `PR ${pr}'s base ${j.baseRefOid.slice(0, 7)} isn't in this clone; run \`git fetch origin ${j.baseRefName ?? '<base branch>'}\` first` };
|
|
55
|
+
const base = git(root, ['merge-base', j.baseRefOid, j.headRefOid])?.trim();
|
|
56
|
+
if (!base) return { error: `no merge-base between PR ${pr}'s base and head (a shallow clone? run \`git fetch --unshallow\`)` };
|
|
57
|
+
return { base, head: j.headRefOid, how: 'pr', pr: { number: j.number, author: j.author?.login ?? null } };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function resolveBase(root, { base = null, pr = null } = {}) {
|
|
61
|
+
if (pr) return fromPr(root, pr);
|
|
62
|
+
if (base) {
|
|
63
|
+
const b = full(root, base);
|
|
64
|
+
return b ? { base: b, how: 'flag' } : { error: `--base ${base} is not a commit here` };
|
|
65
|
+
}
|
|
66
|
+
// Each step that was tried and skipped is named, so a brief that ends at
|
|
67
|
+
// HEAD says why rather than quietly showing a small diff.
|
|
68
|
+
const fallback = [];
|
|
69
|
+
for (const { path, plan } of activePlans(root)) {
|
|
70
|
+
const slice = doingSlice(plan);
|
|
71
|
+
const baseline = plan.header?.baseline;
|
|
72
|
+
if (!slice || !baseline) continue;
|
|
73
|
+
const b = sliceStart(root, baseline, slice.id);
|
|
74
|
+
if (b) return { base: b, how: 'slice', plan: relative(root, path), slice: slice.id };
|
|
75
|
+
fallback.push(`${relative(root, path)} Baseline ${baseline} is not a commit here`);
|
|
76
|
+
}
|
|
77
|
+
const head = full(root, 'HEAD');
|
|
78
|
+
if (!head) return { error: 'no commits yet' };
|
|
79
|
+
const def = defaultBranch(root);
|
|
80
|
+
if (!def) fallback.push('no default branch (origin/HEAD, main or master)');
|
|
81
|
+
const mb = def ? git(root, ['merge-base', 'HEAD', def])?.trim() : null;
|
|
82
|
+
if (def && !mb) fallback.push(`no merge-base with ${def}`);
|
|
83
|
+
if (mb && mb !== head) return { base: mb, how: 'merge-base', branch: def, fallback };
|
|
84
|
+
if (git(root, ['rev-parse', '--is-shallow-repository'])?.trim() === 'true') fallback.push('shallow clone');
|
|
85
|
+
return { base: head, how: 'head', fallback };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ---------- diff ----------
|
|
89
|
+
|
|
90
|
+
// Files changed from base to head (a commit), or to the working tree when
|
|
91
|
+
// head is null, with added and removed lines. Untracked files count as added.
|
|
92
|
+
// Throws when git fails, so a bad range is never an empty diff.
|
|
93
|
+
// Not for hooks: a working-tree diff runs any clean filter .git/config
|
|
94
|
+
// defines (as a plain `git diff` would), and hooks run outside the sandbox.
|
|
95
|
+
// textconv and external diff drivers are off.
|
|
96
|
+
const MAX_UNTRACKED = 2 * 1024 * 1024;
|
|
97
|
+
export function diffFiles(root, base, head = null) {
|
|
98
|
+
const range = head ? [base, head] : [base];
|
|
99
|
+
const q = ['-c', 'core.quotePath=false'];
|
|
100
|
+
const stat = git(root, [...q, 'diff', '--no-renames', '--no-textconv', '--no-ext-diff', '--numstat', '-z', ...range, '--']);
|
|
101
|
+
// Prefixes pinned: the user's diff.noprefix or diff.mnemonicPrefix would
|
|
102
|
+
// otherwise change the header paths this parser reads.
|
|
103
|
+
const patch = git(root, [...q, 'diff', '--no-renames', '--no-textconv', '--no-ext-diff', '--src-prefix=a/', '--dst-prefix=b/', '-U0', '--no-color', ...range, '--']);
|
|
104
|
+
if (stat === null || patch === null) throw new Error(`git diff ${range.join(' ')} failed`);
|
|
105
|
+
const files = new Map();
|
|
106
|
+
for (const rec of stat.split('\0').filter(Boolean)) {
|
|
107
|
+
const [a, d, ...p] = rec.split('\t');
|
|
108
|
+
files.set(p.join('\t'), { path: p.join('\t'), adds: a === '-' ? 0 : Number(a), dels: d === '-' ? 0 : Number(d), binary: a === '-', added: [], removed: [] });
|
|
109
|
+
}
|
|
110
|
+
// Headers name the file on each side; /dev/null on one side is an add or a
|
|
111
|
+
// delete. Content lines are read only inside hunks.
|
|
112
|
+
let cur = null; let from = null; let inHunk = false;
|
|
113
|
+
for (const l of patch.split('\n')) {
|
|
114
|
+
if (l.startsWith('diff --git ')) { cur = null; from = null; inHunk = false; continue; }
|
|
115
|
+
// git ends a header with a tab when the path has a space.
|
|
116
|
+
if (!inHunk && l.startsWith('--- ')) { from = l === '--- /dev/null' ? null : l.replace(/^--- a\//, '').replace(/\t$/, ''); continue; }
|
|
117
|
+
if (!inHunk && l.startsWith('+++ ')) { cur = files.get(l === '+++ /dev/null' ? from : l.replace(/^\+\+\+ b\//, '').replace(/\t$/, '')) ?? null; continue; }
|
|
118
|
+
if (l.startsWith('@@')) { inHunk = true; continue; }
|
|
119
|
+
if (!inHunk || !cur) continue;
|
|
120
|
+
if (l.startsWith('+')) cur.added.push(l.slice(1));
|
|
121
|
+
else if (l.startsWith('-')) cur.removed.push(l.slice(1));
|
|
122
|
+
}
|
|
123
|
+
if (!head) {
|
|
124
|
+
for (const p of lines(git(root, [...q, 'ls-files', '--others', '--exclude-standard']))) {
|
|
125
|
+
// Regular files only, and not huge ones: a symlink, FIFO or device is
|
|
126
|
+
// never opened, the same rule treeId follows.
|
|
127
|
+
let text = '';
|
|
128
|
+
try {
|
|
129
|
+
const st = lstatSync(join(root, p));
|
|
130
|
+
if (st.isFile() && st.size <= MAX_UNTRACKED) text = readFileSync(join(root, p), 'utf8');
|
|
131
|
+
} catch { /* unreadable: list it with no lines */ }
|
|
132
|
+
const added = text.split('\n'); if (added[added.length - 1] === '') added.pop();
|
|
133
|
+
files.set(p, { path: p, adds: added.length, dels: 0, binary: false, added, removed: [], untracked: true });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return [...files.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ---------- triggers ----------
|
|
140
|
+
|
|
141
|
+
const ext = (p) => (p.match(/\.([^./]+)$/)?.[1] ?? '').toLowerCase();
|
|
142
|
+
// No .txt: requirements.txt and CMakeLists.txt are code, not prose.
|
|
143
|
+
const DOC_EXT = new Set(['md', 'mdx', 'rst', 'adoc']);
|
|
144
|
+
const isDoc = (p) => DOC_EXT.has(ext(p));
|
|
145
|
+
// Images, fonts and other media: their names say nothing about what code does.
|
|
146
|
+
const MEDIA = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'ico', 'avif', 'bmp', 'mp4', 'webm', 'mov', 'mp3', 'wav', 'woff', 'woff2', 'ttf', 'otf', 'pdf']);
|
|
147
|
+
const isMedia = (f) => f.binary || MEDIA.has(ext(f.path));
|
|
148
|
+
const isTest = (p) => /(^|\/)(test|tests|__tests__|spec|e2e)\//i.test(p) || /\.(test|spec)\.[cm]?[jt]sx?$/i.test(p) || /_test\.(go|py|rb)$/.test(p) || /(^|\/)test_[^/]*\.py$/.test(p);
|
|
149
|
+
// Line-content rules read source code only: a test's fixture strings would
|
|
150
|
+
// trigger them for every test that mentions what it tests.
|
|
151
|
+
const code = (f) => !isDoc(f.path) && !f.binary && !isTest(f.path);
|
|
152
|
+
const PEOPLE = /^(readme|changelog|contributing|security|code_of_conduct)(\.[a-z]+)?$/i;
|
|
153
|
+
|
|
154
|
+
// One table: id, the partner skill that reviews those files (or null), and
|
|
155
|
+
// the rule. Rules read paths, plus added or removed lines of code files.
|
|
156
|
+
export const TRIGGERS = [
|
|
157
|
+
{ id: 'ui', partner: 'loupe', match: (f) => !isTest(f.path) && (['tsx', 'jsx', 'vue', 'svelte', 'astro', 'css', 'scss', 'sass', 'less', 'html'].includes(ext(f.path)) || /\.swift$/.test(f.path) && /(view|screen)/i.test(f.path)) },
|
|
158
|
+
{ id: 'prose', partner: 'humanizing-writing', match: (f, o) => isDoc(f.path) && !isTest(f.path) && !f.path.startsWith(`${o.plansDir}/`) && !f.path.startsWith('docs/plans/') },
|
|
159
|
+
{
|
|
160
|
+
id: 'security', partner: 'owasp-security',
|
|
161
|
+
// `token` under a lexer or parser is a lexical token, not a credential.
|
|
162
|
+
match: (f) => !isDoc(f.path) && !isMedia(f) && (
|
|
163
|
+
!(/(^|\/)(lexer|lexers|parser|parsers|tokeniz\w*)\//i.test(f.path) && /(^|\/)tokens?\.\w+$/i.test(f.path)) && /(^|[/_.-])(auth|authn|authz|authenticat\w*|authoriz\w*|login|logout|session|sessions|token|tokens|oauth|jwt|password|passwd|secret|secrets|crypto|permission|permissions|acl|rbac|admin|payment|payments|billing|invoice|invoices|money|wallet|checkout)([/_.-]|$)/i.test(f.path)
|
|
164
|
+
|| code(f) && (f.added.some((l) => SECURITY_LINE.test(l)) || f.removed.some((l) => AUTH_CHECK.test(l)))),
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: 'invariants', partner: null,
|
|
168
|
+
match: (f) => code(f) && (/(^|\/)(parser|parsers|parse|serializ\w*|codec|reducer|reducers|state-machine|fsm|queue|queues|cache|caches|lock|locks|scheduler)([/._-]|$)/i.test(f.path)
|
|
169
|
+
|| f.added.some((l) => /\b(transaction|mutex|semaphore|atomic|compareAndSwap|Promise\.all|Promise\.race|idempoten\w*|invalidate|BEGIN TRANSACTION|SELECT .* FOR UPDATE|setInterval)\b|\bnew Worker\(/i.test(l))),
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
id: 'tests-or-checks', partner: null,
|
|
173
|
+
match: (f, o) => isTest(f.path) || /^\.github\/workflows\//.test(f.path) || /(^|\/)(\.gitlab-ci\.yml|\.circleci\/|Jenkinsfile|azure-pipelines\.yml)/.test(f.path)
|
|
174
|
+
|| (f.path.startsWith(`${o.plansDir}/`) || f.path.startsWith('docs/plans/')) && f.path.endsWith('/checks.json')
|
|
175
|
+
|| /(^|\/)(jest|vitest|playwright|cypress|karma|mocha|ava|tap)\.config\.[cm]?[jt]s$|(^|\/)(\.mocharc[^/]*|pytest\.ini|tox\.ini|conftest\.py|\.nycrc[^/]*|codecov\.yml)$/.test(f.path)
|
|
176
|
+
|| /(^|\/)package\.json$/.test(f.path) && [...f.added, ...f.removed].some((l) => /^\s*"(test|tests|lint|typecheck|verify|check|e2e|ci)(:[\w:-]+)?"\s*:/.test(l)),
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: 'migration', partner: null,
|
|
180
|
+
match: (f) => !isDoc(f.path) && (/(^|\/)(migrations?|migrate|alembic|flyway|liquibase)\//i.test(f.path) || /(^|\/)db\/migrate\//.test(f.path) || /\.prisma$/.test(f.path) || /\.sql$/.test(f.path) && /(schema|migrat|V\d+__)/i.test(f.path)
|
|
181
|
+
|| code(f) && f.added.some((l) => /\b(ALTER TABLE|DROP TABLE|CREATE TABLE|DROP COLUMN|ADD COLUMN|RENAME COLUMN|addColumn|dropColumn|renameColumn|createTable|dropTable)\b/i.test(l))),
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
// Shell, query building, deserialisation, user-controlled paths, weak crypto.
|
|
186
|
+
const SECURITY_LINE = new RegExp([
|
|
187
|
+
// Not after a dot: RegExp.prototype.exec and obj.system( are everywhere.
|
|
188
|
+
String.raw`(?<![.\w])(exec|execSync|execFile|execFileSync|spawn|spawnSync|popen|system)\s*\(|\b(cp|child_process|os|subprocess)\.(exec|execSync|spawn|spawnSync|system|popen|run|call|check_output)\w*\s*\(`,
|
|
189
|
+
String.raw`child_process|subprocess\.|os\.system|shell\s*=\s*True`,
|
|
190
|
+
String.raw`\b(eval|new Function)\s*\(`,
|
|
191
|
+
String.raw`\b(SELECT|INSERT INTO|UPDATE|DELETE FROM)\b.*(\$\{|\{\w+\}|["'\x60]\s*\+|%s|\.format\()`,
|
|
192
|
+
String.raw`pickle\.loads?|yaml\.load\(|unserialize\(|Marshal\.load|ObjectInputStream|deserializ`,
|
|
193
|
+
String.raw`\b(path\.(join|resolve)|os\.path\.join|open)\(.*\b(req|request|params|query|body|input|argv|args)\b`,
|
|
194
|
+
String.raw`createHash\(\s*['"](md5|sha1)['"]|createCipher\(|Math\.random\(\).*\b(token|secret|id|nonce|salt)\b|crypto\.subtle|jwt\.(sign|verify|decode)`,
|
|
195
|
+
String.raw`dangerouslySetInnerHTML|innerHTML\s*=`,
|
|
196
|
+
].join('|'), 'i');
|
|
197
|
+
|
|
198
|
+
// A removed line that checked who may do something: deleting an auth check
|
|
199
|
+
// is a security change even when nothing security-shaped is added.
|
|
200
|
+
const AUTH_CHECK = /\b(isAdmin|isOwner|isAuthenticated|requireAuth\w*|authoriz\w*|authenticat\w*|checkPermission\w*|hasPermission\w*|hasRole|can\(|forbidden|unauthori[sz]ed|csrf|verifyToken|jwt\.verify)/i;
|
|
201
|
+
|
|
202
|
+
// Small, docs-only, and nothing else matched.
|
|
203
|
+
const TRIVIAL_LINES = 20;
|
|
204
|
+
const TRIVIAL_FILES = 3;
|
|
205
|
+
|
|
206
|
+
export function triggersFor(files, { plansDir: pd = 'docs/plans' } = {}) {
|
|
207
|
+
const o = { plansDir: pd };
|
|
208
|
+
const out = [];
|
|
209
|
+
for (const t of TRIGGERS) {
|
|
210
|
+
const hit = files.filter((f) => t.match(f, o)).map((f) => f.path);
|
|
211
|
+
if (!hit.length) continue;
|
|
212
|
+
const row = { id: t.id, partner: t.partner, files: hit };
|
|
213
|
+
// People-facing docs get the owner's voice; skills, agents and references don't.
|
|
214
|
+
if (t.id === 'prose') row.voice = hit.filter((p) => PEOPLE.test(p.split('/').pop()) || /^docs\//.test(p));
|
|
215
|
+
out.push(row);
|
|
216
|
+
}
|
|
217
|
+
const lines = files.reduce((n, f) => n + f.adds + f.dels, 0);
|
|
218
|
+
const docsOnly = files.length && files.every((f) => isDoc(f.path));
|
|
219
|
+
if (docsOnly && lines <= TRIVIAL_LINES && files.length <= TRIVIAL_FILES && out.every((t) => t.id === 'prose')) out.push({ id: 'trivial', partner: null, files: files.map((f) => f.path) });
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ---------- REVIEW.md from the base ----------
|
|
224
|
+
|
|
225
|
+
// Entries look like "- When: <trigger> · Check: <what> · Source: <where>".
|
|
226
|
+
// An entry matches when a path or code token in its When (backticks, or a
|
|
227
|
+
// word with a slash or a dot) appears in a changed path or an added line.
|
|
228
|
+
// Entries with no such token go to `judge`: the reviewer decides them.
|
|
229
|
+
export function reviewMdEntries(text, files) {
|
|
230
|
+
const matched = []; const judge = [];
|
|
231
|
+
for (const l of (text ?? '').split('\n')) {
|
|
232
|
+
const m = l.match(/^\s*-\s*When:\s*(.+?)\s*·\s*Check:\s*(.+?)\s*·\s*Source:\s*(.+?)\s*$/);
|
|
233
|
+
if (!m) continue;
|
|
234
|
+
const e = { when: m[1], check: m[2], source: m[3] };
|
|
235
|
+
const toks = [...m[1].matchAll(/`([^`]+)`/g)].map((x) => x[1]);
|
|
236
|
+
if (!toks.length) toks.push(...(m[1].match(/[\w.-]*\/[\w./*-]*|\b[\w-]+\.[a-z]{1,5}\b/g) ?? []));
|
|
237
|
+
if (!toks.length) { judge.push(e); continue; }
|
|
238
|
+
const hit = files.filter((f) => toks.some((t) => (/[*?]/.test(t) ? pathMatches(f.path, t) : f.path.includes(t) || f.added.some((a) => a.includes(t)))));
|
|
239
|
+
if (hit.length) matched.push({ ...e, files: hit.map((f) => f.path) });
|
|
240
|
+
}
|
|
241
|
+
return { matched, judge };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ---------- records ----------
|
|
245
|
+
|
|
246
|
+
export const reviews = (root) => readJsonl(root, 'reviews.jsonl');
|
|
247
|
+
|
|
248
|
+
// A review the skill hands over as JSON. Validated before anything is
|
|
249
|
+
// written; the record is tied to the working tree it reviewed, like evidence.
|
|
250
|
+
export const VERDICTS = ['ready', 'fix first', 'rethink'];
|
|
251
|
+
export const SEVERITIES = ['Important', 'Nit', 'Pre-existing'];
|
|
252
|
+
export const CONFIDENCES = ['Confirmed', 'Likely', 'Needs verification'];
|
|
253
|
+
export const OUTCOMES = ['fixed', 'wrong', 'intentional', 'didnt-matter'];
|
|
254
|
+
const hash8 = (s) => createHash('sha256').update(s).digest('hex').slice(0, 8);
|
|
255
|
+
|
|
256
|
+
// Stable across reviews: class, file and title (lower case, spaces collapsed),
|
|
257
|
+
// never the line, which moves as the file changes.
|
|
258
|
+
export function findingId(f) {
|
|
259
|
+
return hash8([f.class, f.file, String(f.title ?? '').toLowerCase().replace(/\s+/g, ' ').trim()].join('\0'));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function invalid(input) {
|
|
263
|
+
if (!input || typeof input !== 'object') return 'input is not a JSON object';
|
|
264
|
+
if (!VERDICTS.includes(input.verdict)) return `verdict must be one of ${VERDICTS.join(', ')}`;
|
|
265
|
+
if (!Array.isArray(input.findings)) return 'findings must be a list (empty for "Findings: none")';
|
|
266
|
+
for (const [i, f] of input.findings.entries()) {
|
|
267
|
+
const at = `findings[${i}]`;
|
|
268
|
+
if (!SEVERITIES.includes(f.severity)) return `${at}: severity must be one of ${SEVERITIES.join(', ')}`;
|
|
269
|
+
if (f.confidence !== undefined && !CONFIDENCES.includes(f.confidence)) return `${at}: confidence must be one of ${CONFIDENCES.join(', ')}`;
|
|
270
|
+
if (f.severity === 'Important' && f.confidence === undefined) return `${at}: an Important finding needs a confidence`;
|
|
271
|
+
if (typeof f.file !== 'string' || !f.file) return `${at}: file is required`;
|
|
272
|
+
if (f.line !== undefined && f.line !== null && !Number.isInteger(f.line)) return `${at}: line must be an integer`;
|
|
273
|
+
if (typeof f.class !== 'string' || !f.class) return `${at}: class is required (e.g. swallowed-error)`;
|
|
274
|
+
if (typeof f.title !== 'string' || !f.title) return `${at}: title is required`;
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// The input names the base, head and tree from the brief the review started
|
|
280
|
+
// from, so a record can't certify a tree nobody reviewed: if the working
|
|
281
|
+
// tree moved since the brief, the record is refused. A null tree is a PR
|
|
282
|
+
// head that wasn't checked out.
|
|
283
|
+
export function recordReview(root, input) {
|
|
284
|
+
const why = invalid(input);
|
|
285
|
+
if (why) return { error: why };
|
|
286
|
+
for (const k of ['base', 'head', 'tree']) if (!(k in input)) return { error: `${k} is required: copy base, head and tree from \`jig review --json\`` };
|
|
287
|
+
const base = full(root, input.base);
|
|
288
|
+
const head = full(root, input.head);
|
|
289
|
+
if (!base) return { error: `base ${input.base} is not a commit here` };
|
|
290
|
+
if (!head) return { error: `head ${input.head} is not a commit here` };
|
|
291
|
+
let tree = null;
|
|
292
|
+
if (input.tree !== null) {
|
|
293
|
+
tree = workTree(root);
|
|
294
|
+
if (tree !== input.tree || head !== full(root, 'HEAD')) return { error: `the tree reviewed (${String(input.tree).slice(0, 7)}) changed since the brief (now ${String(tree).slice(0, 7)}${head !== full(root, 'HEAD') ? ', and HEAD moved' : ''}); review the new tree` };
|
|
295
|
+
}
|
|
296
|
+
const t = Date.now();
|
|
297
|
+
const findings = input.findings.map((f) => ({ id: findingId(f), severity: f.severity, ...(f.confidence ? { confidence: f.confidence } : {}), file: f.file, line: f.line ?? null, class: f.class, title: f.title }));
|
|
298
|
+
const dup = findings.find((f, i) => findings.findIndex((g) => g.id === f.id) !== i);
|
|
299
|
+
if (dup) return { error: `two findings have the same id ${dup.id} (${dup.class} in ${dup.file}): give them titles that say how they differ, or report them as one finding with both lines` };
|
|
300
|
+
const rec = { v: 1, t, id: hash8(`${t}\0${tree}\0${head}`), head, base, tree, verdict: input.verdict, findings, ...(Number.isInteger(input.dropped) ? { dropped: input.dropped } : {}) };
|
|
301
|
+
appendFileSync(join(stateDir(root), 'reviews.jsonl'), JSON.stringify(rec) + '\n');
|
|
302
|
+
return { record: rec, trailer: `Reviewed: ${rec.verdict}, ${findings.length} findings (tree ${tree ? tree.slice(0, 7) : 'none'})` };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function recordOutcome(root, id, outcome) {
|
|
306
|
+
if (!OUTCOMES.includes(outcome)) return { error: `outcome must be one of ${OUTCOMES.join(', ')}` };
|
|
307
|
+
if (!reviews(root).some((r) => (r.findings ?? []).some((f) => f.id === id))) return { error: `no finding ${id} in reviews.jsonl` };
|
|
308
|
+
const rec = { v: 1, t: Date.now(), kind: 'outcome', finding: id, outcome };
|
|
309
|
+
appendFileSync(join(stateDir(root), 'reviews.jsonl'), JSON.stringify(rec) + '\n');
|
|
310
|
+
return { record: rec };
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// The owner-approved intent for a blind first pass: Outcome (with Done
|
|
314
|
+
// when), Decisions the owner decided, Out of scope, and the slice's Goal,
|
|
315
|
+
// Touch and Checks. Never the Log or the Now line, which are the builder's
|
|
316
|
+
// account of the work.
|
|
317
|
+
export function planIntent(plan, sliceId) {
|
|
318
|
+
const body = (name) => (section(plan, name)?.body ?? []).map((l) => l.trimEnd()).filter((l) => l.trim());
|
|
319
|
+
const s = plan.slices.find((x) => x.id === sliceId) ?? null;
|
|
320
|
+
return {
|
|
321
|
+
outcome: body('Outcome'),
|
|
322
|
+
decisions: body('Decisions').filter((l) => /Decided:\s*owner\b/i.test(l)),
|
|
323
|
+
outOfScope: body('Out of scope'),
|
|
324
|
+
slice: s ? { id: s.id, title: s.title, goal: s.fields.goal?.value ?? null, touch: s.fields.touch?.value ?? null, checks: s.fields.checks?.value ?? null } : null,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ---------- the brief ----------
|
|
329
|
+
|
|
330
|
+
export function reviewBrief(root, opts = {}) {
|
|
331
|
+
const b = resolveBase(root, opts);
|
|
332
|
+
if (b.error) return b;
|
|
333
|
+
const head = b.head ?? full(root, 'HEAD');
|
|
334
|
+
let files;
|
|
335
|
+
try { files = diffFiles(root, b.base, b.head ?? null); } catch (e) { return { error: e.message }; }
|
|
336
|
+
if (!files.length && b.how === 'head') return { error: `nothing to review: no changes against HEAD${b.fallback.length ? ` (${b.fallback.join('; ')})` : ''}. Pass --base <ref>.` };
|
|
337
|
+
const pd = plansDir(root);
|
|
338
|
+
// The fingerprint is of the working tree, so it is the PR's only when the
|
|
339
|
+
// PR head is what's checked out.
|
|
340
|
+
const tree = b.head && b.head !== full(root, 'HEAD') ? null : workTree(root);
|
|
341
|
+
const ev = lastEvidence(root);
|
|
342
|
+
const all = reviews(root).filter((r) => !r.kind && r.findings);
|
|
343
|
+
const rv = all[all.length - 1] ?? null;
|
|
344
|
+
// Rounds of review on this base: a later round reviews only the diff since
|
|
345
|
+
// the last reviewed head, with the earlier findings.
|
|
346
|
+
const round = all.filter((r) => r.base === b.base).length + 1;
|
|
347
|
+
const active = activePlans(root);
|
|
348
|
+
// The plan whose intent the blind pass reads: the one the base came from,
|
|
349
|
+
// or with --base or --pr, the single plan with a doing slice.
|
|
350
|
+
const doingPlans = active.filter(({ plan }) => doingSlice(plan));
|
|
351
|
+
const mine = b.plan ? active.find(({ path }) => relative(root, path) === b.plan) : doingPlans.length === 1 ? doingPlans[0] : null;
|
|
352
|
+
const checks = active.some(({ path }) => loadChecks(path).exists);
|
|
353
|
+
const reviewText = git(root, ['show', `${b.base}:REVIEW.md`]);
|
|
354
|
+
// What the review skill's gate runs when there is no checks.json (doctor D1, D7).
|
|
355
|
+
const diag = diagnose(root);
|
|
356
|
+
const pick = (d) => (d ? { level: d.level, msg: d.msg, ...(d.id === 'D1' && d.level === 'ok' ? { commands: d.msg.replace(/^verify command found:\s*/, '').split(', ') } : {}) } : null);
|
|
357
|
+
const gate = { D1: pick(diag.find((d) => d.id === 'D1' && d.level !== 'info')), D7: pick(diag.find((d) => d.id === 'D7')) };
|
|
358
|
+
const brief = {
|
|
359
|
+
v: 1,
|
|
360
|
+
base: b.base, head, how: b.how,
|
|
361
|
+
...(b.plan ? { plan: b.plan, slice: b.slice } : {}),
|
|
362
|
+
intent: mine ? planIntent(mine.plan, b.slice ?? doingSlice(mine.plan)?.id) : null,
|
|
363
|
+
...(b.branch ? { branch: b.branch } : {}),
|
|
364
|
+
...(b.pr ? { pr: b.pr } : {}),
|
|
365
|
+
...(b.fallback?.length ? { fallback: b.fallback } : {}),
|
|
366
|
+
uncommitted: !b.head && Boolean(git(root, ['status', '--porcelain'])?.trim()),
|
|
367
|
+
tree,
|
|
368
|
+
stats: { files: files.length, adds: files.reduce((n, f) => n + f.adds, 0), dels: files.reduce((n, f) => n + f.dels, 0) },
|
|
369
|
+
files: files.map(({ path, adds, dels, binary, untracked }) => ({ path, adds, dels, ...(binary ? { binary } : {}), ...(untracked ? { untracked } : {}) })),
|
|
370
|
+
triggers: triggersFor(files, { plansDir: pd }),
|
|
371
|
+
reviewMd: reviewText === null ? null : reviewMdEntries(reviewText, files),
|
|
372
|
+
checks,
|
|
373
|
+
gate,
|
|
374
|
+
round,
|
|
375
|
+
evidence: ev ? { t: ev.t, plan: ev.plan, slice: ev.slice, tree: ev.tree, pass: (ev.results ?? []).length > 0 && ev.results.every((r) => r.pass), current: Boolean(tree && ev.tree === tree) } : null,
|
|
376
|
+
review: rv ? { t: rv.t, id: rv.id, verdict: rv.verdict, base: rv.base, head: rv.head, tree: rv.tree, current: Boolean(tree && rv.tree === tree), findings: rv.findings } : null,
|
|
377
|
+
};
|
|
378
|
+
// --blind: what a first, blind pass may see. The earlier verdict and the
|
|
379
|
+
// evidence record are opinions and claims, so they wait for Phase 2.
|
|
380
|
+
if (opts.blind) { delete brief.review; delete brief.evidence; }
|
|
381
|
+
return brief;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const short = (s) => (s ? s.slice(0, 7) : '-');
|
|
385
|
+
|
|
386
|
+
// The text brief: base and tree first, then what to look at.
|
|
387
|
+
export function formatBrief(b) {
|
|
388
|
+
const out = [];
|
|
389
|
+
out.push(`Base ${short(b.base)} (${b.how}${b.plan ? `: ${b.plan} ${b.slice}` : ''}${b.branch ? `: ${b.branch}` : ''}${b.pr ? `: PR #${b.pr.number} by ${b.pr.author}` : ''}) · head ${short(b.head)}${b.uncommitted ? ' + uncommitted' : ''} · tree ${short(b.tree)}`);
|
|
390
|
+
if (b.fallback?.length) out.push(`Fell back: ${b.fallback.join('; ')}`);
|
|
391
|
+
if (b.tree === null) out.push('Tree: none (the PR head is not checked out, so evidence and review records cannot match it)');
|
|
392
|
+
out.push(`Diff: ${b.stats.files} files, +${b.stats.adds} -${b.stats.dels}`);
|
|
393
|
+
if (b.triggers.length) for (const t of b.triggers) out.push(`Trigger ${t.id}${t.partner ? ` (${t.partner})` : ''}: ${t.files.slice(0, 5).join(', ')}${t.files.length > 5 ? ` and ${t.files.length - 5} more` : ''}`);
|
|
394
|
+
else out.push('Triggers: none');
|
|
395
|
+
if (b.reviewMd) {
|
|
396
|
+
for (const e of b.reviewMd.matched) out.push(`REVIEW.md: ${e.check} (Source: ${e.source}) on ${e.files.join(', ')}`);
|
|
397
|
+
if (b.reviewMd.judge.length) out.push(`REVIEW.md: ${b.reviewMd.judge.length} entr${b.reviewMd.judge.length === 1 ? 'y' : 'ies'} with no path trigger, for the reviewer to judge`);
|
|
398
|
+
}
|
|
399
|
+
out.push(`Gate: ${b.checks ? 'jig verify (checks.json)' : b.gate.D1?.level === 'ok' ? b.gate.D1.msg : 'no checks.json and no one-command verify'}${b.gate.D7?.level === 'ok' ? `; ${b.gate.D7.msg}` : ''}`);
|
|
400
|
+
out.push(`Evidence: ${b.evidence ? `${b.evidence.pass ? 'pass' : 'FAIL'} at tree ${short(b.evidence.tree)} (${b.evidence.current ? 'current' : 'stale'})` : 'none'}`);
|
|
401
|
+
out.push(`Review: ${b.review ? `${b.review.verdict} at tree ${short(b.review.tree)} (${b.review.current ? 'current' : 'stale'})` : 'none'}`);
|
|
402
|
+
return out.join('\n');
|
|
403
|
+
}
|
package/cli/lib/verify.mjs
CHANGED
|
@@ -7,9 +7,15 @@ import { stateDir, showHead, treeId, headSha } from './git.mjs';
|
|
|
7
7
|
import { plansDir } from './status.mjs';
|
|
8
8
|
import { today } from './scaffold.mjs';
|
|
9
9
|
|
|
10
|
+
// The last line that says something. Skips what an error object or stack
|
|
11
|
+
// trace ends with (node --test ends on `}`): brace-only lines, `at ...`
|
|
12
|
+
// frames, indented `key: value,` properties and node's closing `Node.js vNN`
|
|
13
|
+
// line. Falls back to the last line.
|
|
14
|
+
const NOISE = /^\s*[{}[\](),]*\s*$|^\s+at\s|^\s+[\w$]+: .*,?$|^Node\.js v\d/;
|
|
10
15
|
function lastLine(s) {
|
|
11
|
-
const lines = (s ?? '').split('\n').
|
|
12
|
-
|
|
16
|
+
const lines = (s ?? '').split('\n').filter((l) => l.trim());
|
|
17
|
+
const pick = lines.findLast((l) => !NOISE.test(l)) ?? lines[lines.length - 1] ?? '';
|
|
18
|
+
return pick.trim().slice(0, 200);
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
export function runCheck(root, c) {
|
|
@@ -43,7 +49,7 @@ export function verifyPlan(root, planPath, opts = {}) {
|
|
|
43
49
|
const logged = Boolean(opts.record && results.length);
|
|
44
50
|
// After the checks: output they write must not make this record stale.
|
|
45
51
|
const tree = workTree(root);
|
|
46
|
-
const record = { t: Date.now(), plan, slice: opts.slice ?? null, fast: Boolean(opts.fast), logged, head: headSha(root, { short: false }), tree, checks, results: results.map(({ id, pass, exit, ms, why }) => ({ id, pass, exit, ms, ...(pass ? {} : { why: why.slice(0, 200) }) })) };
|
|
52
|
+
const record = { v: 1, t: Date.now(), plan, slice: opts.slice ?? null, fast: Boolean(opts.fast), logged, head: headSha(root, { short: false }), tree, checks, results: results.map(({ id, pass, exit, ms, why }) => ({ id, pass, exit, ms, ...(pass ? {} : { why: why.slice(0, 200) }) })) };
|
|
47
53
|
appendFileSync(join(stateDir(root), 'evidence.jsonl'), JSON.stringify(record) + '\n');
|
|
48
54
|
if (logged) appendLog(planPath, logLine(results, opts.slice, changes));
|
|
49
55
|
return { results, ...changes, tree };
|
|
@@ -104,13 +110,16 @@ export function appendLog(planPath, line) {
|
|
|
104
110
|
writeFileSync(planPath, lines.join('\n').replace(/\n*$/, '\n'));
|
|
105
111
|
}
|
|
106
112
|
|
|
107
|
-
// Every readable
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
// Every readable record in a .git/jig/*.jsonl file, oldest first. A corrupt
|
|
114
|
+
// line is skipped.
|
|
115
|
+
export function readJsonl(root, name) {
|
|
116
|
+
const p = join(stateDir(root), name);
|
|
110
117
|
if (!existsSync(p)) return [];
|
|
111
118
|
return readFileSync(p, 'utf8').split('\n').filter(Boolean).flatMap((l) => { try { return [JSON.parse(l)]; } catch { return []; } });
|
|
112
119
|
}
|
|
113
120
|
|
|
121
|
+
export const evidence = (root) => readJsonl(root, 'evidence.jsonl');
|
|
122
|
+
|
|
114
123
|
// The last readable record, parsed from the end: the Stop hook calls this on
|
|
115
124
|
// every turn, and records grow with the number of checks.
|
|
116
125
|
export function lastEvidence(root) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jig-plan",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Plan, verify and guard work done by coding agents: short reviewable plans, executable acceptance checks, and hooks that stop false completion claims.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/skills/build/SKILL.md
CHANGED
|
@@ -43,8 +43,9 @@ Run `jig verify --record` for the slice. It runs the slice's checks, prints one
|
|
|
43
43
|
- **A check fails:** fix the code, not the check, and verify again. You get three rounds on the same check. If it still fails on the third `jig verify`, stop: don't try a fourth fix. Report to the owner what you changed in each round and the current error, and let them decide. The Stop hook counts the rounds from `evidence.jsonl` and says when you've reached three.
|
|
44
44
|
- **A check is flaky** (passes and fails on the same code): don't add retries, sleeps or a skip, and don't rerun it until it passes. Find the cause. If you can't, delete the test, log why, and tell the owner (deleting a protected test asks first). `jig lint` warns on a check command that retries or sleeps [J22], and rejects one that can't fail, such as `|| true` [J23].
|
|
45
45
|
- **A check can't run here** (missing service, credentials, hardware): say so in the Log and to the owner. Don't count it as passing.
|
|
46
|
+
- **The slice can't be done as specified** (the spec and a test conflict, a check can't pass in this environment, a service is missing): append a `Blocked: <reason>` line to the Log, for example `- 2026-11-26: Blocked: C3 needs a Postgres this sandbox doesn't have`, tell the owner, and stop. That's an accepted end state: the Stop hook, the rounds count and the commit gate let it through. Use it instead of a fourth fix or a weakened check. A model given an explicit way out cheats on impossible tasks far less, and more retries make it cheat more.
|
|
46
47
|
|
|
47
|
-
At the full tier,
|
|
48
|
+
At the full tier, run the `jig:review` skill on the slice. It runs the gate, the reviewer in two phases and the validator, and records a review tied to this tree. Fix the Important findings, or log why one doesn't apply. Nits are your call, and Pre-existing findings go to the owner rather than into this slice. Answer a finding only with evidence (a run, or a file:line). If you think one is wrong and can't show it, tell the owner rather than arguing with the reviewer. After fixing, run `jig:review` again with the earlier findings, so it reviews only the new diff. If it returns `rethink` (it does so in round 3 when Important findings are still open), stop and take the approach to the owner.
|
|
48
49
|
|
|
49
50
|
When the slice changes UI and the loupe skill is available, run it on the affected screens if the slice's done-when calls for it.
|
|
50
51
|
|
|
@@ -53,7 +54,7 @@ When the slice changes UI and the loupe skill is available, run it on the affect
|
|
|
53
54
|
1. Mark the slice `[done]` and update `Now:` to the next slice.
|
|
54
55
|
2. Append a Log line saying, in two or three sentences, what changed and why. This is for whoever reads the code next, including the owner checking they still understand their system.
|
|
55
56
|
3. Run `jig lint` on the plan.
|
|
56
|
-
4. Commit the slice with a message that says what it does. End the message with the `Verified:` line that `jig verify --record` printed, for example `Verified: S2 C1 pass, C2 pass (tree 3f2a91c)`. If nothing was verified, write `Verified: none (<reason>)` instead, so the commit can be found later.
|
|
57
|
+
4. Commit the slice with a message that says what it does. End the message with the `Verified:` line that `jig verify --record` printed, for example `Verified: S2 C1 pass, C2 pass (tree 3f2a91c)`. If nothing was verified, write `Verified: none (<reason>)` instead, so the commit can be found later. When the slice was reviewed, add the `Reviewed:` line that `jig review --record` printed on the next line.
|
|
57
58
|
|
|
58
59
|
Then stop and report to the owner:
|
|
59
60
|
- the slice
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: review
|
|
3
|
+
description: Reviews a change after it is built, with or without a jig plan. It gets the brief from `jig review`, gates on `jig verify` or the repo's verify command, reviews blind against the owner's intent and then against the builder's claims, validates each Important finding, sends UI, prose and security files to their partner skills, and records a review tied to the working tree. Use after building with jig, when a jig plan's slice is done, or to review a jig plan's diff, slice or branch. Not for a generic "review this PR" with no jig context, which the built-in /code-review covers.
|
|
4
|
+
allowed-tools: Read Glob Grep Bash(jig review:*) Bash(jig status:*) Bash(gh pr view:*) Bash(git diff:*) Bash(git log:*) Bash(git show:*) Bash(git status:*)
|
|
5
|
+
argument-hint: --base <ref>, --pr <number>, or nothing (the doing slice)
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Review
|
|
9
|
+
|
|
10
|
+
Deterministic checks decide, and a model's review advises. A model checking its own work without outside feedback doesn't reliably catch its errors, so the gate runs first and a red gate ends the review. The reviewer reads the change before it reads the builder's account of it, because a persuasive description gets bad changes approved.
|
|
11
|
+
|
|
12
|
+
## 1. Brief
|
|
13
|
+
|
|
14
|
+
Run `jig review --json`, adding `--base <ref>` or `--pr <number>` if you were given one. Read:
|
|
15
|
+
- `base`, `head`, `how` and `fallback`: what is being compared, and any step that was skipped to get there
|
|
16
|
+
- `files`, `stats` and `triggers`: what changed, and which partners apply
|
|
17
|
+
- `intent`: the owner-approved part of the plan, when there is one
|
|
18
|
+
- `reviewMd`: REVIEW.md entries from the base that match, and those left for the reviewer to judge
|
|
19
|
+
- `checks`, `gate`, `evidence`: what the gate runs, and whether the last `jig verify` covers this tree
|
|
20
|
+
- `round` and `review`: the round number on this base, and the last review's head and findings
|
|
21
|
+
|
|
22
|
+
If it prints an error, report it and stop.
|
|
23
|
+
|
|
24
|
+
**Someone else's code:** with `--pr`, or when the commits aren't the builder's in this session, ask the owner before step 2 runs anything. Running a PR's tests runs its author's code on this machine.
|
|
25
|
+
|
|
26
|
+
## 2. Gate
|
|
27
|
+
|
|
28
|
+
- **With checks.json:** if `evidence.current` and `evidence.pass` are true and `evidence.slice` is the brief's `slice`, the gate already passed for this tree. Say so. Otherwise run `jig verify` (with `--slice <id>` when the brief names a slice).
|
|
29
|
+
- **Without:** when `gate.D1.level` is `ok`, run the first command in `gate.D1.commands`. Also run the runner `gate.D7` names when its level is `ok`.
|
|
30
|
+
- **No gate at all:** put "Not checked: no gate (no checks.json and no one-command verify)" in the report. The verdict can't be `ready` with nothing run.
|
|
31
|
+
|
|
32
|
+
**A red gate ends the review.** Report the failing check and its deciding line, and stop. Don't model-review code that fails its own checks.
|
|
33
|
+
|
|
34
|
+
**Light path:** when `triggers` has `trivial` (a small docs-only diff), run the gate and one reviewer pass (step 3, phase 1 only), then go to step 6. Put the skipped partners under Not checked, with "light path" as the reason.
|
|
35
|
+
|
|
36
|
+
## 3. Review in two phases
|
|
37
|
+
|
|
38
|
+
**Phase 1.** Run `jig review --json --blind`, which leaves out the earlier verdict and the evidence record. Start the `jig-reviewer` agent in diff mode, and tell it "Phase 1 only". Give it:
|
|
39
|
+
- with a plan: the plan path and slice ID
|
|
40
|
+
- without one: the base and head from the brief, and the owner's request or the linked issue as the spec
|
|
41
|
+
- the blind brief's JSON
|
|
42
|
+
- the brief's `round`. On round 2 or later, also the earlier findings (`review.findings`) and the last reviewed commit (`review.head`)
|
|
43
|
+
|
|
44
|
+
Don't give it the plan's Log, commit messages, the PR description or your own summary of the work. It returns its Phase 1 findings and stops.
|
|
45
|
+
|
|
46
|
+
**Phase 2.** Use SendMessage to send the same agent (its ID from the Phase 1 call) the builder's claims: the PR title and body (`gh pr view <n> --json title,body` for a PR), the `evidence` from the full brief, and your summary of what was done and verified. If you can't reach it, start a new `jig-reviewer` with the Phase 1 findings quoted verbatim, then the claims. It checks each claim against the diff and the evidence, and can add findings but not remove them. Because the claims arrive only after the Phase 1 findings exist, the blind pass is blind by construction.
|
|
47
|
+
|
|
48
|
+
## 4. Validate the Important findings
|
|
49
|
+
|
|
50
|
+
For each Important finding, start a fresh `jig-reviewer` in validate mode. Give it only the claim, `file:line: <the defect>`, never the finder's evidence or reasoning. Run these in parallel.
|
|
51
|
+
- `confirmed`: keep the finding, with the validator's evidence.
|
|
52
|
+
- `dropped`: remove it, and count it in the report.
|
|
53
|
+
|
|
54
|
+
Don't validate Nits or Pre-existing findings. Don't retry a dropped finding, and don't count a second run of the same model as a second vote.
|
|
55
|
+
|
|
56
|
+
**The verdict after validation:** `rethink` if the reviewer returned it. Otherwise `fix first` while a confirmed Important finding remains, else `ready`. Don't let the gate's absence give `ready` (step 2).
|
|
57
|
+
|
|
58
|
+
## 5. Partners
|
|
59
|
+
|
|
60
|
+
Each partner reviews only the files its trigger matched, so none of them becomes a second reviewer of the code.
|
|
61
|
+
|
|
62
|
+
| Trigger | Partner | Files | Notes |
|
|
63
|
+
|---|---|---|---|
|
|
64
|
+
| `ui` | loupe | the trigger's files | the screens those files render |
|
|
65
|
+
| `prose` | humanizing-writing | prose an agent wrote in this change | the files in `voice` are people-facing docs (README, CHANGELOG, docs/, SECURITY, CONTRIBUTING) and use the owner's voice profile when humanizing-writing has one. In jig's own repo that's `voices/ashwin-sathian.md`. Skills, agents and references get the plain rules and no voice. |
|
|
66
|
+
| `security` | owasp-security | the trigger's files | its Important findings are validated like the reviewer's (step 4) |
|
|
67
|
+
|
|
68
|
+
humanizing-writing excludes proofreading a person's own writing, so run it only on prose an agent wrote in this change, and say that in the report. Prose a person wrote, such as most of a PR you didn't build, goes under Not checked with that reason.
|
|
69
|
+
|
|
70
|
+
A partner that isn't installed goes under "Not checked", with the reason. Never skip one silently. loupe and humanizing-writing findings are listed under the partner's name and don't change the verdict.
|
|
71
|
+
|
|
72
|
+
## 6. Record
|
|
73
|
+
|
|
74
|
+
Write the findings JSON to a scratch file outside the repo:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{ "base": "<from the brief>", "head": "<from the brief>", "tree": "<from the brief>", "verdict": "fix first",
|
|
78
|
+
"findings": [{ "severity": "Important", "confidence": "Confirmed", "file": "src/a.js", "line": 12, "class": "swallowed-error", "title": "catch drops the parse error" }],
|
|
79
|
+
"dropped": 1 }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Record only the findings that are kept: the reviewer's, after validation, and owasp-security's confirmed ones. `dropped` is the count from step 4. Each finding's `title` is the reviewer's one-line finding, word for word. For a finding still open from an earlier round, reuse its earlier `title` and `class`, so it keeps its id.
|
|
83
|
+
|
|
84
|
+
Then run `jig review --record <file>`. It prints the `Reviewed:` trailer. If jig refuses because the tree changed, files moved during the review: run the brief again and review the new diff, rather than recording the old review against the new tree.
|
|
85
|
+
|
|
86
|
+
## 7. Report
|
|
87
|
+
|
|
88
|
+
Keep it short. Long review comments get acted on less, and AI review can slow a change down.
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
Verdict: <ready | fix first | rethink> · Gate: <the jig verify line, or the command and its result> · Validator: <n> confirmed, <m> dropped
|
|
92
|
+
1. [Important] [Confirmed] <class>: <finding>. <file:line>. Fix: <inline fix>.
|
|
93
|
+
... at most five shown, Important first, then Confirmed before Likely
|
|
94
|
+
<k> more: <one line each, folded>
|
|
95
|
+
Partners: <which ran, on which files>
|
|
96
|
+
Not checked: <each with its reason>
|
|
97
|
+
Declined to judge: <from the reviewer>
|
|
98
|
+
Would miss: <one line on what these checks would miss here>
|
|
99
|
+
Reviewed: <verdict>, <n> findings (tree <short>)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The owner's attention is the audit budget, so the top five carry the report. `ready` with no findings is a normal result.
|
|
103
|
+
|
|
104
|
+
## Replies, rounds and outcomes
|
|
105
|
+
|
|
106
|
+
- **The builder answers a finding only with evidence:** a run, or a file:line. A prose rebuttal goes to the owner, never back to the reviewer, because models flip correct answers when asked whether they're sure.
|
|
107
|
+
- **Three rounds, then the owner.** On round 3 with Important findings still open, the reviewer returns `rethink`. Stop and take the approach to the owner.
|
|
108
|
+
- **Outcomes:** when a finding is settled, record it with `jig review --outcome <id> fixed|wrong|intentional|didnt-matter`. The finding ids are in the record. These outcomes are how jig learns which findings were worth raising.
|