jig-plan 2.0.0 → 2.1.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 +16 -7
- package/cli/jig.mjs +5 -2
- package/cli/lib/checks.mjs +45 -0
- package/cli/lib/git.mjs +36 -3
- package/cli/lib/hooks.mjs +199 -37
- package/cli/lib/lint.mjs +17 -0
- package/cli/lib/verify.mjs +64 -9
- package/package.json +1 -1
- package/references/failure-modes.md +1 -0
- package/references/plan-format.md +1 -1
- package/references/team.md +1 -0
- package/skills/build/SKILL.md +3 -2
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"name": "jig",
|
|
9
9
|
"source": "./",
|
|
10
10
|
"description": "Planning and build harness for coding agents. Sizes the plan to the task, writes executable acceptance checks before code, reviews plans and diffs in a fresh context, and uses hooks to stop test tampering, unvetted installs and unverified 'done' claims.",
|
|
11
|
-
"version": "2.
|
|
11
|
+
"version": "2.1.0",
|
|
12
12
|
"author": { "name": "Ashwin Sathian", "url": "https://ashwinsathian.com/" },
|
|
13
13
|
"repository": "https://github.com/AshwinSathian/jig",
|
|
14
14
|
"license": "MIT",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
|
|
3
3
|
"name": "jig",
|
|
4
4
|
"displayName": "jig",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.1.0",
|
|
6
6
|
"description": "Planning and build harness for coding agents. Sizes the plan to the task, writes executable acceptance checks before code, reviews plans and diffs in a fresh context, and uses hooks to stop test tampering, unvetted installs and unverified 'done' claims.",
|
|
7
7
|
"author": { "name": "Ashwin Sathian", "url": "https://ashwinsathian.com/" },
|
|
8
8
|
"repository": "https://github.com/AshwinSathian/jig",
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# jig
|
|
2
2
|
|
|
3
|
-
[](https://github.com/AshwinSathian/jig/actions/workflows/ci.yml) [](LICENSE)
|
|
3
|
+
[](https://github.com/AshwinSathian/jig/actions/workflows/ci.yml) [](https://www.npmjs.com/package/jig-plan) [](https://github.com/AshwinSathian/jig/releases) [](LICENSE)
|
|
4
4
|
|
|
5
5
|
A planning and build harness for Claude Code. jig plans the work at the size it needs, writes the acceptance checks before the code, and uses hooks to catch the ways agent work usually goes wrong: a test edited until it passes, a package that doesn't exist, edits that wander outside the task, and "done" with nothing run.
|
|
6
6
|
|
|
@@ -9,6 +9,12 @@ claude plugin marketplace add AshwinSathian/jig
|
|
|
9
9
|
claude plugin install jig@jig
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
Only want the CLI, say for CI or a repo where you don't run Claude Code? It's on npm as `jig-plan`, with no dependencies:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx jig-plan doctor # or: npm install -g jig-plan, then `jig doctor`
|
|
16
|
+
```
|
|
17
|
+
|
|
12
18
|
Then work the way you already do, e.g. *"add CSV export to the reports page"*. A one-line fix gets a four-line plan in chat and carries on. A feature gets a short plan you approve, and then it's built one slice at a time, with the evidence written into the plan. Run `jig doctor` in a repo to see what it'd want fixed first.
|
|
13
19
|
|
|
14
20
|
**Contents:** [How it works](#how-it-works) · [What a plan looks like](#what-a-plan-looks-like) · [Hooks](#hooks) · [The CLI](#the-cli) · [Evidence](#evidence) · [Limits](#limits) · [How it compares](#how-it-compares) · [Updating and troubleshooting](#updating-and-troubleshooting)
|
|
@@ -85,11 +91,11 @@ Why no estimates? Agents miss their own runtimes by a typical factor of 2.9 (Age
|
|
|
85
91
|
| Hook | What it does | What it never does |
|
|
86
92
|
|---|---|---|
|
|
87
93
|
| SessionStart | One paragraph telling the model to plan code changes with jig, plus the state of any active plan | Run anything from the repo |
|
|
88
|
-
| Before an edit | **Asks** before a file a check protects (an acceptance test) is edited, and also when `checks.json` is invalid. Notes once per file when an edit falls outside the current slice | Return `allow`, so your own permission prompts still apply |
|
|
94
|
+
| Before an edit | **Asks** before a file a check protects (an acceptance test) is edited, and also when `checks.json` is invalid. Once a plan is approved, also asks when an edit would loosen `checks.json` (drop a check, change its command or expectation, unprotect a file) or move the plan out of approved or building. New checks and new protected files go through without a prompt. Notes once per file when an edit falls outside the current slice | Return `allow`, so your own permission prompts still apply |
|
|
89
95
|
| Before a Bash call | **Asks** before `npm i`, `pip install`, `cargo add` and the like when they name a package | Get in the way of lockfile installs (`npm ci`, `pip install -r`) |
|
|
90
|
-
| Stop | If
|
|
96
|
+
| Stop | If the working tree changed since the session started and doesn't match the last `jig verify`, asks the agent to run it and report the result. That catches changes made through Bash too. Each new failing run blocks once, and on the third failure of the same check it tells the agent to stop and bring you what it tried | Run the checks itself, because `checks.json` comes from the repo and a repo can be hostile |
|
|
91
97
|
|
|
92
|
-
Turn hooks off with `JIG_HOOKS_OFF=pre-bash,stop` (or `all`), and the session nudge with `JIG_NUDGE=off`. They're guardrails, not a sandbox: a shell command can still change a file without going through the Edit tool. [SECURITY.md](SECURITY.md) says exactly what runs where.
|
|
98
|
+
Turn hooks off with `JIG_HOOKS_OFF=pre-bash,stop` (or `all`), and the session nudge with `JIG_NUDGE=off`. To try a gate before trusting it, `JIG_GATES=observe` (or `observe:freeze,tree,rounds`) makes the gates write what they'd have asked or blocked to `.git/jig/observe.jsonl` and stay quiet. The gates are `protects` (protected files, and an invalid `checks.json`), `freeze` (loosening checks, or changing an approved plan's status), `install`, `tree` and `rounds`. A sixth, `rules`, only logs for now: it notes edits to `CLAUDE.md`, `REVIEW.md`, `.claude/` and `.github/workflows/`, so you can decide from real data whether it should ask. An edit to one of those files that mentions `JIG_GATES` or `JIG_HOOKS_OFF` always asks, observe mode or not. They're guardrails, not a sandbox: a shell command can still change a file without going through the Edit tool. [SECURITY.md](SECURITY.md) says exactly what runs where.
|
|
93
99
|
|
|
94
100
|
## The CLI
|
|
95
101
|
|
|
@@ -97,9 +103,10 @@ Turn hooks off with `JIG_HOOKS_OFF=pre-bash,stop` (or `all`), and the session nu
|
|
|
97
103
|
|
|
98
104
|
```
|
|
99
105
|
jig new <slug> --tier brief|full|program --title "..." start a plan with the baseline commit filled in
|
|
100
|
-
jig lint [path ...] [--no-paths] check plans against the format (rules J01 to
|
|
106
|
+
jig lint [path ...] [--no-paths] check plans against the format (rules J01 to J24)
|
|
101
107
|
jig status active plans, their Now line, the current slice
|
|
102
108
|
jig verify [--slice S2] [--fast] [--record] run checks.json; --record writes the result to the Log
|
|
109
|
+
and prints a Verified: line for the commit
|
|
103
110
|
jig doctor [--ack] report harness gaps; --ack marks the repo's agent config as read
|
|
104
111
|
```
|
|
105
112
|
|
|
@@ -186,14 +193,16 @@ jig works alongside [loupe](https://github.com/AshwinSathian/loupe) and [humaniz
|
|
|
186
193
|
## Updating and troubleshooting
|
|
187
194
|
|
|
188
195
|
```bash
|
|
189
|
-
claude plugin marketplace update jig && claude plugin update jig@jig # update
|
|
196
|
+
claude plugin marketplace update jig && claude plugin update jig@jig # update the plugin
|
|
197
|
+
npm install -g jig-plan@latest # update the standalone CLI, if you use it
|
|
190
198
|
claude plugin details jig # what's installed and its token cost
|
|
191
199
|
claude plugin uninstall jig@jig # remove
|
|
192
200
|
```
|
|
193
201
|
|
|
194
202
|
- **jig never fires:** check `claude plugin details jig` lists the hooks, and that `JIG_NUDGE` isn't `off`.
|
|
195
203
|
- **An install keeps asking:** that's the pre-bash hook. Approve it once the package checks out, or set `JIG_HOOKS_OFF=pre-bash`.
|
|
196
|
-
- **The agent won't finish:** the Stop hook wants `jig verify` evidence. Run `jig verify --fast --record`, or tell it plainly which check can't run, and why.
|
|
204
|
+
- **The agent won't finish:** the Stop hook wants `jig verify` evidence for the files as they are now. Run `jig verify --fast --record`, or tell it plainly which check can't run, and why. If a check has failed three times running, the hook asks the agent to stop and report, and the call on what happens next is yours.
|
|
205
|
+
- **Two planning workflows at once:** superpowers' skills also trigger on planning requests. In our trigger eval jig fired first on every planning prompt with both installed, but if you'd rather have one, `claude plugin disable superpowers@claude-plugins-official` turns superpowers off.
|
|
197
206
|
- **A plan fails lint:** `jig lint <path>` prints each rule ID and line. The rules are in [references/plan-format.md](references/plan-format.md).
|
|
198
207
|
|
|
199
208
|
## Contributing
|
package/cli/jig.mjs
CHANGED
|
@@ -5,10 +5,10 @@ import { statSync, readdirSync, existsSync } from 'node:fs';
|
|
|
5
5
|
import { lintFile } from './lib/lint.mjs';
|
|
6
6
|
import { newPlan } from './lib/scaffold.mjs';
|
|
7
7
|
import { statusSummary, findPlans, activePlans, doingSlice, plansDir } from './lib/status.mjs';
|
|
8
|
-
import { verifyPlan } from './lib/verify.mjs';
|
|
8
|
+
import { verifyPlan, changedNote, trailer } from './lib/verify.mjs';
|
|
9
9
|
import { repoRoot } from './lib/git.mjs';
|
|
10
10
|
|
|
11
|
-
const VERSION = '2.
|
|
11
|
+
const VERSION = '2.1.0';
|
|
12
12
|
const HELP = `jig ${VERSION}
|
|
13
13
|
|
|
14
14
|
Usage:
|
|
@@ -112,10 +112,13 @@ async function main() {
|
|
|
112
112
|
}
|
|
113
113
|
const res = verifyPlan(root, planPath, { slice, fast: flags.fast === 'true', record: flags.record === 'true', ids: flags.check ? String(flags.check).split(',') : null });
|
|
114
114
|
if (res.error) { console.error(`jig verify: ${res.error}`); return 2; }
|
|
115
|
+
const note = changedNote(res);
|
|
116
|
+
if (note) console.log(`jig verify: ${note}`);
|
|
115
117
|
if (!res.results.length) { console.log('jig verify: no checks matched'); return 0; }
|
|
116
118
|
for (const r of res.results) console.log(`${r.pass ? 'PASS' : 'FAIL'} ${r.id} (${(r.ms / 1000).toFixed(1)}s) ${r.cmd}${r.pass ? '' : `\n ${r.why}`}`);
|
|
117
119
|
const failed = res.results.filter((r) => !r.pass).length;
|
|
118
120
|
console.log(`${res.results.length - failed}/${res.results.length} passed${flags.record === 'true' ? ' · recorded in the plan Log' : ''}`);
|
|
121
|
+
if (flags.record === 'true') console.log(`\nFor the slice commit:\n${trailer(res.results, slice, res.tree)}`);
|
|
119
122
|
return failed ? 1 : 0;
|
|
120
123
|
}
|
|
121
124
|
|
package/cli/lib/checks.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
3
4
|
|
|
4
5
|
export const KINDS = ['acceptance', 'regression', 'property', 'mutation', 'perf', 'security'];
|
|
5
6
|
const ID_RE = /^[A-Za-z][\w.-]*$/;
|
|
@@ -54,3 +55,47 @@ export function validateChecks(data, sliceIds = null) {
|
|
|
54
55
|
});
|
|
55
56
|
return errs;
|
|
56
57
|
}
|
|
58
|
+
|
|
59
|
+
// The freeze. Once a plan is approved, a check's frozen fields and its
|
|
60
|
+
// protects list may only grow: changing a field, dropping a check or dropping
|
|
61
|
+
// a protected path needs a person. A snapshot holds a short hash per frozen
|
|
62
|
+
// field, so evidence records can be compared without storing commands.
|
|
63
|
+
export const FROZEN = ['cmd', 'expect', 'kind', 'timeout_s', 'fast', 'slice'];
|
|
64
|
+
|
|
65
|
+
const canon = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? Object.fromEntries(Object.keys(v).sort().map((k) => [k, canon(v[k])])) : v);
|
|
66
|
+
const short = (v) => createHash('sha256').update(JSON.stringify(canon(v) ?? null)).digest('hex').slice(0, 12);
|
|
67
|
+
|
|
68
|
+
export function snapshot(checks) {
|
|
69
|
+
const out = Object.create(null);
|
|
70
|
+
for (const c of checks ?? []) {
|
|
71
|
+
if (!c || typeof c.id !== 'string') continue;
|
|
72
|
+
out[c.id] = { f: Object.fromEntries(FROZEN.map((k) => [k, short(c[k])])), protects: [...(c.protects ?? [])].sort() };
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// What got looser from `before` to `after` (both snapshots): [{ id, why }].
|
|
78
|
+
export function loosened(before, after) {
|
|
79
|
+
const out = [];
|
|
80
|
+
for (const [id, b] of Object.entries(before ?? {})) {
|
|
81
|
+
const a = Object.hasOwn(after, id) ? after[id] : null;
|
|
82
|
+
if (!a) { out.push({ id, why: 'removed' }); continue; }
|
|
83
|
+
const why = FROZEN.filter((k) => b.f?.[k] !== a.f?.[k]);
|
|
84
|
+
for (const p of b.protects ?? []) if (!(a.protects ?? []).includes(p)) why.push(`protects -${p}`);
|
|
85
|
+
if (why.length) out.push({ id, why: why.join(', ') });
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The file text a Write, Edit or MultiEdit would leave. null when the edit
|
|
91
|
+
// can't apply (the tool then fails on its own).
|
|
92
|
+
export function applyEdit(text, toolName, input) {
|
|
93
|
+
if (toolName === 'Write' || typeof input.content === 'string') return input.content ?? null;
|
|
94
|
+
const edits = Array.isArray(input.edits) ? input.edits : [input];
|
|
95
|
+
let t = text;
|
|
96
|
+
for (const e of edits) {
|
|
97
|
+
if (typeof e.old_string !== 'string' || typeof e.new_string !== 'string' || !t.includes(e.old_string)) return null;
|
|
98
|
+
t = e.replace_all ? t.split(e.old_string).join(e.new_string) : t.replace(e.old_string, () => e.new_string);
|
|
99
|
+
}
|
|
100
|
+
return t;
|
|
101
|
+
}
|
package/cli/lib/git.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import { existsSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { existsSync, mkdirSync, lstatSync, readlinkSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
3
4
|
import { join } from 'node:path';
|
|
4
5
|
|
|
5
6
|
// Hardened git: hooks scripts run outside the Bash sandbox, so don't let a
|
|
@@ -26,8 +27,8 @@ export function repoRoot(cwd) {
|
|
|
26
27
|
return out ? out.trim() : null;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
export function headSha(cwd) {
|
|
30
|
-
const out = git(cwd, ['rev-parse', '--short', 'HEAD']);
|
|
30
|
+
export function headSha(cwd, { short = true } = {}) {
|
|
31
|
+
const out = git(cwd, ['rev-parse', ...(short ? ['--short'] : []), 'HEAD']);
|
|
31
32
|
return out ? out.trim() : null;
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -46,3 +47,35 @@ export function stateDir(root) {
|
|
|
46
47
|
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
47
48
|
return dir;
|
|
48
49
|
}
|
|
50
|
+
|
|
51
|
+
// A fingerprint of the working state: every tracked and untracked file
|
|
52
|
+
// (honouring .gitignore) that `keep` accepts, by path, type and raw bytes.
|
|
53
|
+
// Hashed here rather than with `git add`/`write-tree`, because those run the
|
|
54
|
+
// repo's clean filters, and a filter in .git/config is a command this hook
|
|
55
|
+
// would run outside the sandbox. ls-files runs none, writes no objects and
|
|
56
|
+
// takes no index lock. null when this isn't a repo or git fails.
|
|
57
|
+
export function treeId(root, keep = () => true) {
|
|
58
|
+
const out = git(root, ['ls-files', '-z', '--cached', '--others', '--exclude-standard']);
|
|
59
|
+
if (out === null) return null;
|
|
60
|
+
const h = createHash('sha256');
|
|
61
|
+
for (const rel of [...new Set(out.split('\0').filter(Boolean))].sort()) {
|
|
62
|
+
if (!keep(rel)) continue;
|
|
63
|
+
const abs = join(root, rel);
|
|
64
|
+
let st;
|
|
65
|
+
try { st = lstatSync(abs); } catch { continue; } // deleted: its absence changes the hash
|
|
66
|
+
h.update(rel).update('\0');
|
|
67
|
+
// Never let one file stop the hash: an unreadable file is hashed by its
|
|
68
|
+
// size and mtime, and a FIFO, socket or device is never opened (reading
|
|
69
|
+
// one can block the hook).
|
|
70
|
+
try {
|
|
71
|
+
if (st.isSymbolicLink()) h.update('l').update(readlinkSync(abs));
|
|
72
|
+
else if (st.isDirectory()) h.update('d'); // a submodule
|
|
73
|
+
else if (st.isFile()) h.update(st.mode & 0o111 ? 'x' : 'f').update(readFileSync(abs));
|
|
74
|
+
else h.update('o');
|
|
75
|
+
} catch (e) {
|
|
76
|
+
h.update(`e:${e.code}:${st.size}:${st.mtimeMs}`);
|
|
77
|
+
}
|
|
78
|
+
h.update('\0');
|
|
79
|
+
}
|
|
80
|
+
return h.digest('hex').slice(0, 40);
|
|
81
|
+
}
|
package/cli/lib/hooks.mjs
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
// - never return permissionDecision "allow": that would skip the user's prompts
|
|
4
4
|
// - never run repo-defined commands: checks.json is untrusted input
|
|
5
5
|
// - append short context, and don't repeat it
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync, appendFileSync } from 'node:fs';
|
|
7
7
|
import { join, relative, isAbsolute } from 'node:path';
|
|
8
8
|
import { repoRoot, stateDir } from './git.mjs';
|
|
9
9
|
import { activePlans, doingSlice, sliceTouch, statusSummary, plansDir } from './status.mjs';
|
|
10
|
-
import { loadChecks, validateChecks } from './checks.mjs';
|
|
11
|
-
import {
|
|
10
|
+
import { loadChecks, validateChecks, snapshot, loosened, applyEdit } from './checks.mjs';
|
|
11
|
+
import { evidence, workTree } from './verify.mjs';
|
|
12
|
+
import { parsePlan } from './plan.mjs';
|
|
12
13
|
|
|
13
14
|
const off = (name) => {
|
|
14
15
|
const v = (process.env.JIG_HOOKS_OFF ?? '').split(',').map((s) => s.trim());
|
|
@@ -47,10 +48,21 @@ export function pathMatches(rel, pattern) {
|
|
|
47
48
|
return re.test(rel);
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
// The tree before this session changed anything, kept once: SessionStart also
|
|
52
|
+
// fires on resume and compact, and overwriting it would forget earlier changes.
|
|
53
|
+
// The PreToolUse hooks call this too (before their tool runs), for a session
|
|
54
|
+
// that started before any plan was active.
|
|
55
|
+
function keepStartTree(root, st) {
|
|
56
|
+
if (st.data.startTree) return;
|
|
57
|
+
const tree = workTree(root);
|
|
58
|
+
if (tree) { st.data.startTree = tree; st.save(); }
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
export const NUDGE = 'jig: for any request to change code in this repo, invoke the jig:plan skill first, before reading or editing files. For a one-line fix it is a four-line plan in chat and adds little; for anything ambiguous or risky it catches what a direct start misses. Skip it only for questions, explanations, reviews, and debugging an error whose cause is unknown.';
|
|
51
62
|
|
|
52
63
|
export function sessionStart(input) {
|
|
53
64
|
const root = rootOf(input);
|
|
65
|
+
if (activePlans(root).length) keepStartTree(root, sessionState(root, input));
|
|
54
66
|
const parts = [];
|
|
55
67
|
if (process.env.JIG_NUDGE !== 'off') parts.push(NUDGE);
|
|
56
68
|
const status = statusSummary(root, { max: 2 });
|
|
@@ -59,11 +71,83 @@ export function sessionStart(input) {
|
|
|
59
71
|
return { hookSpecificOutput: { hookEventName: 'SessionStart', additionalContext: parts.join('\n\n') } };
|
|
60
72
|
}
|
|
61
73
|
|
|
74
|
+
// An ask, tagged with the gate that raised it (see observe mode in runHook).
|
|
75
|
+
const ask = (gate, reason) => ({ gate, hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'ask', permissionDecisionReason: reason } });
|
|
76
|
+
const block = (gate, reason) => ({ gate, decision: 'block', reason });
|
|
77
|
+
|
|
78
|
+
// Why an edit to an active plan's checks.json needs a person, or null.
|
|
79
|
+
// Fails closed: a result that doesn't parse or validate asks.
|
|
80
|
+
function frozenChange(checks, input) {
|
|
81
|
+
const after = applyEdit(readFileSync(checks.path, 'utf8'), input.tool_name, input.tool_input ?? {});
|
|
82
|
+
if (after === null) return 'is an edit jig could not apply to the current file, so it cannot tell what changes';
|
|
83
|
+
let data;
|
|
84
|
+
try { data = JSON.parse(after); } catch (e) { return `would leave invalid JSON (${e.message})`; }
|
|
85
|
+
const problems = validateChecks(data);
|
|
86
|
+
if (problems.length) return `would leave an invalid checks.json (${problems[0]})`;
|
|
87
|
+
const loose = loosened(snapshot(checks.data.checks), snapshot(data.checks));
|
|
88
|
+
return loose.length ? `loosens ${loose.map((l) => `${l.id} (${l.why})`).join('; ')}` : null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The same file, even when the path is spelled in another case (macOS and
|
|
92
|
+
// Windows filesystems ignore case) or reached through a symlink.
|
|
93
|
+
function sameFile(a, b) {
|
|
94
|
+
try {
|
|
95
|
+
const x = statSync(a); const y = statSync(b);
|
|
96
|
+
return x.ino === y.ino && x.dev === y.dev;
|
|
97
|
+
} catch { return a === b; } // a file that doesn't exist yet: compare paths
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Rule files: what the agent and the reviewers are told. The Claude Code
|
|
101
|
+
// code-review post treats them, and CI workflows, as paths a person reads.
|
|
102
|
+
// Claude Code also reads CLAUDE.md and .claude/ below the root. Compared in
|
|
103
|
+
// lower case: on macOS and Windows `.CLAUDE/` is the same directory.
|
|
104
|
+
const isRuleFile = (rel) => {
|
|
105
|
+
const parts = rel.toLowerCase().split(/[\\/]/);
|
|
106
|
+
return ['claude.md', 'review.md'].includes(parts[parts.length - 1]) || parts.slice(0, -1).includes('.claude') || parts.slice(0, 2).join('/') === '.github/workflows';
|
|
107
|
+
};
|
|
108
|
+
// Any case (Windows env names ignore it), or JIG followed by an escape.
|
|
109
|
+
const SWITCHES = /\bjig_(gates|hooks_off)\b|\bjig\\[xuU_]/i;
|
|
110
|
+
|
|
111
|
+
// The first switch in a file's text, decoding JSON so an escape can't hide one.
|
|
112
|
+
function switchesIn(text) {
|
|
113
|
+
let s = text;
|
|
114
|
+
try { s = JSON.stringify(JSON.parse(text)); } catch { /* not JSON: match the raw text */ }
|
|
115
|
+
return s.match(SWITCHES)?.[0] ?? null;
|
|
116
|
+
}
|
|
117
|
+
|
|
62
118
|
export function preEdit(input) {
|
|
119
|
+
const file = input.tool_input?.file_path ?? input.tool_input?.notebook_path;
|
|
120
|
+
const root = rootOf(input);
|
|
121
|
+
const abs = file ? (isAbsolute(file) ? file : join(root, file)) : null;
|
|
122
|
+
const rel = abs ? relative(root, abs) : null;
|
|
123
|
+
// Turning jig's gates off from a rule file always asks, and has no gate
|
|
124
|
+
// name, so observe mode can't silence it. Judged on the whole file after
|
|
125
|
+
// the edit: any change to a rule file that mentions a switch asks, so a
|
|
126
|
+
// switch can't be assembled from existing text or have its value changed.
|
|
127
|
+
if (rel && isRuleFile(rel)) {
|
|
128
|
+
const before = existsSync(abs) ? readFileSync(abs, 'utf8') : '';
|
|
129
|
+
const after = applyEdit(before, input.tool_name, input.tool_input ?? {});
|
|
130
|
+
const added = after === null || after === before ? null : switchesIn(after);
|
|
131
|
+
if (after === null || added) {
|
|
132
|
+
return ask(undefined, after === null
|
|
133
|
+
? `jig: this edit to ${rel} can't be applied to the current file, so jig can't tell whether it turns jig's gates off. Re-read the file and retry, or approve if the edit is right.`
|
|
134
|
+
: `jig: this edit to ${rel} mentions ${added}, which switches jig's gates off or into observe mode. That's the owner's call.`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const out = guardEdit(input);
|
|
138
|
+
if (out?.gate || !rel || !isRuleFile(rel)) return out;
|
|
139
|
+
// Observe-only until the owner decides from the log, so log here and keep
|
|
140
|
+
// any scope warning.
|
|
141
|
+
observe(input, 'pre-edit', 'rules', ask('rules', `jig: ${rel} is a rule file (it tells agents or reviewers what to do). A person should read changes to it.`));
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function guardEdit(input) {
|
|
63
146
|
const file = input.tool_input?.file_path ?? input.tool_input?.notebook_path;
|
|
64
147
|
if (!file) return null;
|
|
65
148
|
const root = rootOf(input);
|
|
66
|
-
const
|
|
149
|
+
const abs = isAbsolute(file) ? file : join(root, file);
|
|
150
|
+
const rel = relative(root, abs);
|
|
67
151
|
if (rel.startsWith('..')) return null;
|
|
68
152
|
const st = sessionState(root, input);
|
|
69
153
|
st.data.editedAt = Date.now();
|
|
@@ -77,26 +161,31 @@ export function preEdit(input) {
|
|
|
77
161
|
// be read or validated, we can't tell whether this file is protected.
|
|
78
162
|
const problems = checks.exists ? (checks.error ? [checks.error] : validateChecks(checks.data)) : [];
|
|
79
163
|
if (problems.length) {
|
|
80
|
-
return {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
164
|
+
return ask('protects', `jig: ${relative(root, checks.path)} is invalid (${problems[0]}), so jig can't tell whether ${rel} is a protected acceptance test. Fix checks.json with \`jig lint\`.`);
|
|
165
|
+
}
|
|
166
|
+
if (sameFile(abs, path)) {
|
|
167
|
+
const after = applyEdit(readFileSync(path, 'utf8'), input.tool_name, input.tool_input ?? {});
|
|
168
|
+
const to = after === null ? null : parsePlan(after).header?.status?.toLowerCase();
|
|
169
|
+
if (after === null || !['approved', 'building'].includes(to)) {
|
|
170
|
+
return ask('freeze', after === null
|
|
171
|
+
? `jig: this edit to ${rel} can't be applied to the current file, so jig can't tell whether it changes the plan's status. Re-read the file and retry, or approve if the edit is right.`
|
|
172
|
+
: `jig: this edit sets ${rel} to Status: ${to ?? '(none)'}, which takes it out of the checks freeze and the slice hooks. Changing a plan's status is the owner's call.`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (checks.exists && sameFile(abs, checks.path)) {
|
|
176
|
+
const why = frozenChange(checks, input);
|
|
177
|
+
if (why) {
|
|
178
|
+
return ask('freeze', `jig: this edit to ${rel} ${why}. The plan is approved, so its checks are frozen: add checks or protected paths freely, but loosening one needs the owner's yes and a Log line.`);
|
|
179
|
+
}
|
|
87
180
|
}
|
|
88
181
|
for (const c of checks.data?.checks ?? []) {
|
|
89
182
|
if ((c.protects ?? []).some((p) => pathMatches(rel, p))) {
|
|
90
|
-
return {
|
|
91
|
-
hookSpecificOutput: {
|
|
92
|
-
hookEventName: 'PreToolUse',
|
|
93
|
-
permissionDecision: 'ask',
|
|
94
|
-
permissionDecisionReason: `jig: ${rel} is protected by check ${c.id} in ${relative(root, path)}. Acceptance tests come from the spec; edit one only when the spec changed, and log the decision in the plan.`,
|
|
95
|
-
},
|
|
96
|
-
};
|
|
183
|
+
return ask('protects', `jig: ${rel} is protected by check ${c.id} in ${relative(root, path)}. Acceptance tests come from the spec; edit one only when the spec changed, and log the decision in the plan.`);
|
|
97
184
|
}
|
|
98
185
|
}
|
|
99
186
|
}
|
|
187
|
+
// After the protection checks, so a problem here can't skip them.
|
|
188
|
+
keepStartTree(root, st);
|
|
100
189
|
if (rel.startsWith(`${plansDir(root)}/`) || rel.startsWith('docs/plans/')) return null;
|
|
101
190
|
const doing = plans.map(({ path, plan }) => ({ path, slice: doingSlice(plan) })).find((x) => x.slice);
|
|
102
191
|
if (!doing) return null;
|
|
@@ -146,16 +235,12 @@ export function installedPackages(command) {
|
|
|
146
235
|
|
|
147
236
|
export function preBash(input) {
|
|
148
237
|
const cmd = input.tool_input?.command ?? '';
|
|
238
|
+
const root = rootOf(input);
|
|
239
|
+
if (activePlans(root).length) keepStartTree(root, sessionState(root, input));
|
|
149
240
|
const pkgs = installedPackages(cmd);
|
|
150
241
|
if (!pkgs.length) return null;
|
|
151
242
|
const names = pkgs.map((p) => `${p.name} (${p.eco})`).join(', ');
|
|
152
|
-
return {
|
|
153
|
-
hookSpecificOutput: {
|
|
154
|
-
hookEventName: 'PreToolUse',
|
|
155
|
-
permissionDecision: 'ask',
|
|
156
|
-
permissionDecisionReason: `jig: this adds ${names}. A new dependency is a one-way door: check that the name is the real package (hallucinated names get registered by attackers), its age and downloads, and record it in the plan's Decisions.`,
|
|
157
|
-
},
|
|
158
|
-
};
|
|
243
|
+
return ask('install', `jig: this adds ${names}. A new dependency is a one-way door: check that the name is the real package (hallucinated names get registered by attackers), its age and downloads, and record it in the plan's Decisions.`);
|
|
159
244
|
}
|
|
160
245
|
|
|
161
246
|
export function stop(input) {
|
|
@@ -163,7 +248,6 @@ export function stop(input) {
|
|
|
163
248
|
if ((input.background_tasks ?? []).length) return null;
|
|
164
249
|
const root = rootOf(input);
|
|
165
250
|
const st = sessionState(root, input);
|
|
166
|
-
if (!st.data.editedAt) return null;
|
|
167
251
|
const plans = activePlans(root).filter(({ plan }) => doingSlice(plan));
|
|
168
252
|
if (!plans.length) return null;
|
|
169
253
|
// Only when a checks.json exists; brief plans state checks as commands.
|
|
@@ -171,29 +255,107 @@ export function stop(input) {
|
|
|
171
255
|
if (!withChecks.length) return null;
|
|
172
256
|
const sliceChecks = withChecks.flatMap((x) => x.checks.data.checks.filter((c) => c.slice === x.slice.id));
|
|
173
257
|
const cmd = sliceChecks.some((c) => c.fast === true) ? 'jig verify --fast --record' : 'jig verify --record';
|
|
174
|
-
|
|
258
|
+
// In git, compare working trees, which also sees changes made through Bash.
|
|
259
|
+
// Outside git, or if git fails, fall back to the Edit hook's timestamp.
|
|
260
|
+
const tree = workTree(root);
|
|
261
|
+
// An Edit-hook call counts as a change too, as it did before tree ids.
|
|
262
|
+
const changed = Boolean(st.data.editedAt) || Boolean(tree && st.data.startTree && tree !== st.data.startTree);
|
|
263
|
+
if (!changed) return null;
|
|
264
|
+
// This plan's records only: another plan's failures aren't this slice's rounds.
|
|
265
|
+
const rels = new Set(withChecks.map((x) => relative(root, x.path)));
|
|
266
|
+
// ponytail: parses all of evidence.jsonl (about 6 KB a record for a 36-check plan); trim old records or keep a running count if Stop gets slow.
|
|
267
|
+
const mine = evidence(root).filter((r) => rels.has(r.plan));
|
|
268
|
+
const ev = mine[mine.length - 1] ?? null;
|
|
269
|
+
const run = `Run \`${cmd}\` for the slice in progress and report its result before finishing. If a check cannot run here, say which one and why.`;
|
|
175
270
|
// Evidence that ran no checks proves nothing.
|
|
176
|
-
if (!ev ||
|
|
177
|
-
|
|
271
|
+
if (!ev || !(ev.results ?? []).length) return block('tree', `jig: files changed and no \`jig verify\` has run a check. ${run}`);
|
|
272
|
+
if (tree && !ev.tree) return block('tree', `jig: the last \`jig verify\` has no tree id (it was recorded before jig 2.1), so it can't show which files it checked. ${run}`);
|
|
273
|
+
if (tree ? ev.tree !== tree : ev.t < st.data.editedAt) {
|
|
274
|
+
return block('tree', `jig: files changed since the last \`jig verify\` that ran a check. ${run}`);
|
|
178
275
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
276
|
+
// Rounds per plan, from each plan's own last record when it covers this
|
|
277
|
+
// tree. Each failing record blocks once; the next block needs a new verify.
|
|
278
|
+
const blocked = new Set(st.data.blockedRecords ?? []);
|
|
279
|
+
const reasons = [];
|
|
280
|
+
for (const rel of rels) {
|
|
281
|
+
const recs = mine.filter((r) => r.plan === rel);
|
|
282
|
+
const last = recs[recs.length - 1];
|
|
283
|
+
if (!last || blocked.has(last.t) || (tree ? last.tree !== tree : last.t < st.data.editedAt)) continue;
|
|
284
|
+
const failing = (last.results ?? []).filter((r) => !r.pass);
|
|
285
|
+
if (!failing.length) continue;
|
|
286
|
+
blocked.add(last.t);
|
|
287
|
+
reasons.push(roundsReason(rel, failing.map((f) => ({ id: f.id, why: f.why, n: failedRounds(recs, f.id) }))));
|
|
184
288
|
}
|
|
185
|
-
return null;
|
|
289
|
+
if (!reasons.length) return null;
|
|
290
|
+
st.data.blockedRecords = [...blocked].slice(-50);
|
|
291
|
+
st.save();
|
|
292
|
+
return block('rounds', reasons.join(' '));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function roundsReason(plan, rounds) {
|
|
296
|
+
const out = rounds.filter((r) => r.n >= ROUNDS);
|
|
297
|
+
const still = rounds.filter((r) => r.n < ROUNDS);
|
|
298
|
+
const list = still.map((r) => `${r.id} (round ${r.n} of ${ROUNDS})`).join(', ');
|
|
299
|
+
if (out.length) {
|
|
300
|
+
return `jig (${plan}): ${out.map((r) => `${r.id} has failed ${r.n} verify rounds in a row`).join('; ')}. Stop, and don't try again unless the owner has told you to continue. Report to the owner what you changed in each round and the current error (${out.map((r) => `${r.id}: ${r.why || 'see jig verify'}`).join('; ')}), and let them decide.${list ? ` Also failing: ${list}.` : ''}`;
|
|
301
|
+
}
|
|
302
|
+
return `jig (${plan}): the last \`jig verify\` had failing checks (${still.map((r) => r.id).join(', ')}). Rounds so far: ${list}. Fix the code, not the check, and verify again, or tell the user plainly they are failing; don't describe the slice as done.`;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// After three failed rounds on one check, a person decides (the Claude Code
|
|
306
|
+
// team's rule; /ship stops after three pushes per issue).
|
|
307
|
+
const ROUNDS = 3;
|
|
308
|
+
|
|
309
|
+
// Consecutive failing records for one check, counted back to its last pass.
|
|
310
|
+
export function failedRounds(records, id) {
|
|
311
|
+
let n = 0;
|
|
312
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
313
|
+
const r = (records[i].results ?? []).find((x) => x.id === id);
|
|
314
|
+
if (!r) continue;
|
|
315
|
+
if (r.pass) break;
|
|
316
|
+
n++;
|
|
317
|
+
}
|
|
318
|
+
return n;
|
|
186
319
|
}
|
|
187
320
|
|
|
188
321
|
const HANDLERS = { 'session-start': sessionStart, 'pre-edit': preEdit, 'pre-bash': preBash, stop };
|
|
189
322
|
|
|
323
|
+
// JIG_GATES=observe logs every ask and block to .git/jig/observe.jsonl and
|
|
324
|
+
// prints nothing; observe:<gate>,<gate> does that for the named gates only.
|
|
325
|
+
// Use it to count false positives before a gate enforces. Gates: protects,
|
|
326
|
+
// freeze, install, tree, rounds, and rules (observe-only for now).
|
|
327
|
+
function observed(gate) {
|
|
328
|
+
const v = (process.env.JIG_GATES ?? '').trim();
|
|
329
|
+
if (v === 'observe') return true;
|
|
330
|
+
const m = v.match(/^observe:(.*)$/);
|
|
331
|
+
return Boolean(m && m[1].split(',').map((s) => s.trim()).includes(gate));
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function observe(input, hook, gate, out) {
|
|
335
|
+
const root = rootOf(input);
|
|
336
|
+
const file = input.tool_input?.file_path;
|
|
337
|
+
const entry = {
|
|
338
|
+
t: Date.now(), hook, gate, session: sid(input),
|
|
339
|
+
decision: out.decision ?? out.hookSpecificOutput?.permissionDecision,
|
|
340
|
+
reason: out.reason ?? out.hookSpecificOutput?.permissionDecisionReason,
|
|
341
|
+
...(file ? { file: relative(root, isAbsolute(file) ? file : join(root, file)) } : {}),
|
|
342
|
+
...(input.tool_input?.command ? { command: String(input.tool_input.command).slice(0, 200) } : {}),
|
|
343
|
+
};
|
|
344
|
+
appendFileSync(join(stateDir(root), 'observe.jsonl'), JSON.stringify(entry) + '\n');
|
|
345
|
+
}
|
|
346
|
+
|
|
190
347
|
export function runHook(name) {
|
|
191
348
|
const fn = HANDLERS[name];
|
|
192
349
|
if (!fn) { console.error(`jig hook: unknown hook "${name}" (${Object.keys(HANDLERS).join(', ')})`); return 2; }
|
|
193
350
|
if (off(name)) return 0;
|
|
194
351
|
try {
|
|
195
|
-
const
|
|
196
|
-
|
|
352
|
+
const input = readStdin();
|
|
353
|
+
const out = fn(input);
|
|
354
|
+
if (out) {
|
|
355
|
+
const { gate, ...rest } = out;
|
|
356
|
+
if (gate && observed(gate)) observe(input, name, gate, rest);
|
|
357
|
+
else emit(rest);
|
|
358
|
+
}
|
|
197
359
|
} catch (e) {
|
|
198
360
|
// Guardrails, not a security boundary (Bash can edit files without Edit):
|
|
199
361
|
// an unexpected error must not block all work. The protected-file check
|
package/cli/lib/lint.mjs
CHANGED
|
@@ -113,6 +113,20 @@ export function lintText(text, { root = null, rel = null, checks = null, paths =
|
|
|
113
113
|
warn('J21', 0, `acceptance check ${c.id} runs \`${c.cmd}\` with no filter for its own tests, so it can pass before the behaviour exists; point it at the new test file or name`);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
+
// J22: a check that retries or sleeps hides a flaky test instead of fixing
|
|
117
|
+
// it. J23: a check that can't fail checks nothing.
|
|
118
|
+
// Only shell syntax counts: a test named "retry backoff" is fine. A cleanup
|
|
119
|
+
// step such as `pkill x || true; npm test` can still fail, so J23 looks only
|
|
120
|
+
// at how the command ends.
|
|
121
|
+
const RETRY = /--retr(y|ies)\b|--reruns?\b|\bretries=\d|(^|[;&|]\s*)(npx\s+)?retry\b|\bsleep\s+\d|\b(until|while)\b.*;\s*do\b|\bfor\b.*;\s*do\b.*\bbreak\b/;
|
|
122
|
+
const CANT_FAIL = /(\|\|\s*(true|:|\/bin\/true|exit\s+0|echo\b[^;&|]*)|;\s*(true|:|exit\s+0)|\|\s*(tail|head|tee)\b[^;&|]*)\s*$/;
|
|
123
|
+
const ending = (cmd) => cmd.replace(/\s+#[^'"]*$/, '');
|
|
124
|
+
for (const c of checksData?.checks ?? []) {
|
|
125
|
+
if (typeof c.cmd !== 'string') continue;
|
|
126
|
+
if (RETRY.test(c.cmd)) warn('J22', 0, `check ${c.id} retries or sleeps (\`${c.cmd}\`); find the flaky test's cause, or delete the test and log why`);
|
|
127
|
+
if (CANT_FAIL.test(ending(c.cmd)) && !(/\|\s*(tail|head|tee)\b[^;&|]*$/.test(ending(c.cmd)) && /pipefail/.test(c.cmd))) err('J23', 0, `check ${c.id} can't fail (\`${c.cmd}\`); its exit status comes from \`|| true\`, \`|| echo\`, \`; exit 0\` or a pipe into \`tail\`/\`head\`/\`tee\`; remove it, or use \`set -o pipefail\``);
|
|
128
|
+
}
|
|
129
|
+
const checkSlice = new Map((checksData?.checks ?? []).map((c) => [c.id, c.slice]));
|
|
116
130
|
const slicesSec = section(plan, 'Slices');
|
|
117
131
|
if (slicesSec && !plan.slices.length) err('J08', slicesSec.start, 'Slices section has no "### S<n>: <title> [state]" headings');
|
|
118
132
|
const doing = [];
|
|
@@ -142,6 +156,9 @@ export function lintText(text, { root = null, rel = null, checks = null, paths =
|
|
|
142
156
|
if (!ids.length && !hasCmd) err('J09', s.fields.checks.line, `slice ${s.id} Checks: names no check IDs or commands`);
|
|
143
157
|
if (checksData) {
|
|
144
158
|
for (const id of ids) if (!knownIds.has(id)) err('J10', s.fields.checks.line, `check ${id} is not in checks.json`);
|
|
159
|
+
// jig verify runs a slice's checks by their `slice` field, so a check
|
|
160
|
+
// listed here but owned by another slice never runs for this one.
|
|
161
|
+
for (const id of ids) if (knownIds.has(id) && checkSlice.get(id) !== s.id) warn('J24', s.fields.checks.line, `check ${id} belongs to ${checkSlice.get(id)}, so \`jig verify\` won't run it for ${s.id}; give ${s.id} its own check`);
|
|
145
162
|
} else if (ids.length && checks) {
|
|
146
163
|
err('J10', s.fields.checks.line, `slice ${s.id} names check IDs but there is no checks.json (a brief plan may give commands in backticks instead)`);
|
|
147
164
|
}
|
package/cli/lib/verify.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
2
|
import { appendFileSync, readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
3
3
|
import { join, relative } from 'node:path';
|
|
4
|
-
import { loadChecks } from './checks.mjs';
|
|
4
|
+
import { loadChecks, snapshot, loosened } from './checks.mjs';
|
|
5
5
|
import { parsePlan, section } from './plan.mjs';
|
|
6
|
-
import { stateDir } from './git.mjs';
|
|
6
|
+
import { stateDir, showHead, treeId, headSha } from './git.mjs';
|
|
7
|
+
import { plansDir } from './status.mjs';
|
|
7
8
|
import { today } from './scaffold.mjs';
|
|
8
9
|
|
|
9
10
|
function lastLine(s) {
|
|
@@ -36,17 +37,58 @@ export function verifyPlan(root, planPath, opts = {}) {
|
|
|
36
37
|
if (loaded.error) return { error: `checks.json: ${loaded.error}` };
|
|
37
38
|
const chosen = selectChecks(loaded.data.checks ?? [], opts);
|
|
38
39
|
const results = chosen.map((c) => runCheck(root, c));
|
|
39
|
-
const
|
|
40
|
+
const plan = relative(root, planPath);
|
|
41
|
+
const checks = snapshot(loaded.data.checks);
|
|
42
|
+
const changes = changedChecks(root, plan, relative(root, loaded.path), checks);
|
|
43
|
+
const logged = Boolean(opts.record && results.length);
|
|
44
|
+
// After the checks: output they write must not make this record stale.
|
|
45
|
+
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) }) })) };
|
|
40
47
|
appendFileSync(join(stateDir(root), 'evidence.jsonl'), JSON.stringify(record) + '\n');
|
|
41
|
-
if (
|
|
42
|
-
return { results };
|
|
48
|
+
if (logged) appendLog(planPath, logLine(results, opts.slice, changes));
|
|
49
|
+
return { results, ...changes, tree };
|
|
43
50
|
}
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
// The working tree jig compares evidence against. Plan files are left out,
|
|
53
|
+
// because `jig verify --record` writes the Log after the tree is taken; the
|
|
54
|
+
// checks.json beside them stays in, so a Bash edit to it makes evidence stale.
|
|
55
|
+
export function workTree(root) {
|
|
56
|
+
const dirs = [...new Set([plansDir(root), 'docs/plans', 'docs/plan'])];
|
|
57
|
+
return treeId(root, (rel) => rel !== 'docs/PLAN.md' && !dirs.some((d) => rel.startsWith(`${d}/`) && rel.endsWith('/PLAN.md') && rel.split('/').length === d.split('/').length + 2));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Checks.json edits made outside the edit hook (Bash, an editor) show up here:
|
|
61
|
+
// compare with this plan's last record that wrote a Log line (a plain verify
|
|
62
|
+
// must not absorb a change before a person sees it), or with the committed
|
|
63
|
+
// file when there is none.
|
|
64
|
+
export function changedChecks(root, plan, checksRel, now) {
|
|
65
|
+
const prev = evidence(root).filter((r) => r.plan === plan && r.checks && r.logged).pop();
|
|
66
|
+
if (prev) return { changed: loosened(prev.checks, now), changedSince: 'the last record' };
|
|
67
|
+
const head = showHead(root, checksRel);
|
|
68
|
+
if (head === null) return { changed: [], changedSince: null };
|
|
69
|
+
let data;
|
|
70
|
+
try { data = JSON.parse(head); } catch (e) { return { changed: [], changedSince: null, unreadable: `HEAD ${checksRel} is not valid JSON (${e.message}), so changed checks can't be named` }; }
|
|
71
|
+
return { changed: loosened(snapshot(data.checks), now), changedSince: 'HEAD' };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// The line a slice commit carries, so `git log --grep 'Verified: none'`
|
|
75
|
+
// finds the commits nothing verified.
|
|
76
|
+
export function trailer(results, slice, tree) {
|
|
77
|
+
const parts = results.map((r) => `${r.id} ${r.pass ? 'pass' : 'FAIL'}`).join(', ');
|
|
78
|
+
return `Verified: ${slice ? `${slice} ` : ''}${parts}${tree ? ` (tree ${tree.slice(0, 7)})` : ''}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function changedNote({ changed, changedSince, unreadable } = {}) {
|
|
82
|
+
if (unreadable) return unreadable;
|
|
83
|
+
return changed?.length ? `checks changed since ${changedSince}: ${changed.map((c) => `${c.id} (${c.why})`).join(', ')}` : '';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function logLine(results, slice, changes) {
|
|
46
87
|
const now = new Date();
|
|
47
88
|
const hm = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
|
|
48
89
|
const parts = results.map((r) => (r.pass ? `${r.id} pass` : `${r.id} FAIL (${r.why})`));
|
|
49
|
-
|
|
90
|
+
const note = changedNote(changes);
|
|
91
|
+
return `- ${today()} ${hm}: jig verify${slice ? ` ${slice}` : ''}: ${parts.join('; ')}${note ? `. ${note}` : ''}`;
|
|
50
92
|
}
|
|
51
93
|
|
|
52
94
|
// Append under ## Log (which is the last section by the format rules).
|
|
@@ -62,9 +104,22 @@ export function appendLog(planPath, line) {
|
|
|
62
104
|
writeFileSync(planPath, lines.join('\n').replace(/\n*$/, '\n'));
|
|
63
105
|
}
|
|
64
106
|
|
|
107
|
+
// Every readable evidence record, oldest first. A corrupt line is skipped.
|
|
108
|
+
export function evidence(root) {
|
|
109
|
+
const p = join(stateDir(root), 'evidence.jsonl');
|
|
110
|
+
if (!existsSync(p)) return [];
|
|
111
|
+
return readFileSync(p, 'utf8').split('\n').filter(Boolean).flatMap((l) => { try { return [JSON.parse(l)]; } catch { return []; } });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The last readable record, parsed from the end: the Stop hook calls this on
|
|
115
|
+
// every turn, and records grow with the number of checks.
|
|
65
116
|
export function lastEvidence(root) {
|
|
66
117
|
const p = join(stateDir(root), 'evidence.jsonl');
|
|
67
118
|
if (!existsSync(p)) return null;
|
|
68
|
-
const lines = readFileSync(p, 'utf8').
|
|
69
|
-
|
|
119
|
+
const lines = readFileSync(p, 'utf8').split('\n');
|
|
120
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
121
|
+
if (!lines[i]) continue;
|
|
122
|
+
try { return JSON.parse(lines[i]); } catch { /* corrupt line: try the one before */ }
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
70
125
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jig-plan",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.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": {
|
|
@@ -13,6 +13,7 @@ Use this list when choosing checks for a slice. Pick only the rows that apply, a
|
|
|
13
13
|
| Insecure defaults | XSS, weak password handling, missing authorization on a new route | Read `security.md` when a slice touches auth, input, secrets or dependencies. Add a `security` check (a test that the route rejects an unauthenticated call). Flag auth paths for a human to read |
|
|
14
14
|
| Performance blind spots | Queries in loops, excessive I/O (CodeRabbit: about 8x more common in AI PRs), quadratic scans | Agents don't measure unless a check makes them. Add a `perf` check with a threshold when a slice touches a hot path or a list that grows |
|
|
15
15
|
| Scope creep | Extra abstractions, edits to unrelated files | `Touch:` per slice. Each slice stays reviewable in one sitting |
|
|
16
|
+
| Flaky tests hidden by retries | A check passes after a retry, a sleep or a skip, so the race or ordering bug is still there. The Claude Code team's rule: no retries or sleeps; find the cause, or delete the test and write down why | No retry, sleep or skip in a check. `jig lint` warns on `retry`, `--retries`, `--rerun`, `sleep` and `until … do` in a check's `cmd` [J22], and errors on a `cmd` that can't fail (`|| true`, `|| :`, `; exit 0`) [J23] |
|
|
16
17
|
| False completion claims | "Tests pass" without running them. Replit's agent told its user rollback was impossible; it wasn't | Completion is the `jig verify --record` line in the Log, not a sentence. The Stop hook asks for evidence when files changed after the last verify |
|
|
17
18
|
| Context rot | Quality drops late in long sessions | One slice per session. The plan's `Now:` line and Log are the memory, and subagents do investigation |
|
|
18
19
|
| Destructive action in the wrong environment | Replit deleted a production database during a freeze it had been told about | Production and data changes are one-way doors. A freeze is enforced by permissions and credentials; the plan never claims a prompt enforces it |
|
|
@@ -143,4 +143,4 @@ The Log is append-only and dated: `- 2026-11-25: ...` or `- 2026-11-25 14:02: ..
|
|
|
143
143
|
| `fast` | True for checks that finish within 120 s. The build skill runs these before every stop |
|
|
144
144
|
| `protects` | Paths the agent may not edit without a logged decision. The edit hook asks first |
|
|
145
145
|
|
|
146
|
-
Write acceptance checks from the spec, before the code they check. They state what the code should do, not what it already does. Point each one at its own tests (a file path, `--grep`, `--testPathPattern`, `-t`): a whole-suite command passes before the behaviour exists, and `jig lint` warns about it [J21].
|
|
146
|
+
Write acceptance checks from the spec, before the code they check. They state what the code should do, not what it already does. Point each one at its own tests (a file path, `--grep`, `--testPathPattern`, `-t`): a whole-suite command passes before the behaviour exists, and `jig lint` warns about it [J21]. A `cmd` that retries or sleeps hides a flaky test [J22, warning], and one that can't fail (`|| true`, `|| :`, `; exit 0`) checks nothing [J23]. `jig verify` runs a slice's checks by their `slice` field, so a slice's `Checks:` line should name only its own checks [J24, warning]. Other lint errors here are [J17].
|
package/references/team.md
CHANGED
|
@@ -20,3 +20,4 @@ Use this when `git shortlog -sn --since=90.days` shows more than one active auth
|
|
|
20
20
|
|
|
21
21
|
- **One reviewer per slice**, with their depth set by risk: auth paths, migrations and public contracts get a line-by-line human read; the rest get the jig-reviewer diff pass plus a skim.
|
|
22
22
|
- **The PR description explains the change** in two or three sentences, links the plan and slice, and gives the evidence line from the Log. Required explanations, and a named owner for each module, keep the team's understanding of the code level with the code itself.
|
|
23
|
+
- **Every slice commit says how it was verified.** The build skill ends the message with the `Verified:` line from `jig verify --record`, or `Verified: none (<reason>)`. `git log --grep 'Verified: none'` lists the commits nothing verified, which is where a reviewer should read first. The `tree` value is jig's own fingerprint (a sha256 over the files `git ls-files` lists, without plan Markdown), not a git tree id, so `git show` won't find it. It matches the `tree` in `.git/jig/evidence.jsonl`.
|
package/skills/build/SKILL.md
CHANGED
|
@@ -40,7 +40,8 @@ List each acceptance test file under `protects` in `checks.json`. From then on,
|
|
|
40
40
|
Run `jig verify --record` for the slice. It runs the slice's checks, prints one line per check, and appends the result to the Log. That Log line is the evidence the slice is done. A sentence saying the tests pass is not evidence.
|
|
41
41
|
|
|
42
42
|
- **All green:** go to step 5.
|
|
43
|
-
- **A check fails:** fix the code, not the check, and verify again.
|
|
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
|
+
- **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].
|
|
44
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.
|
|
45
46
|
|
|
46
47
|
At the full tier, hand the slice to the `jig-reviewer` agent in diff mode, with the plan path and slice ID. Fix the findings, or log why one doesn't apply.
|
|
@@ -52,7 +53,7 @@ When the slice changes UI and the loupe skill is available, run it on the affect
|
|
|
52
53
|
1. Mark the slice `[done]` and update `Now:` to the next slice.
|
|
53
54
|
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.
|
|
54
55
|
3. Run `jig lint` on the plan.
|
|
55
|
-
4. Commit the slice with a message that says what it does.
|
|
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.
|
|
56
57
|
|
|
57
58
|
Then stop and report to the owner:
|
|
58
59
|
- the slice
|