jig-plan 2.0.1 → 2.2.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 +12 -9
- package/agents/jig-reviewer.md +17 -6
- package/cli/jig.mjs +5 -2
- package/cli/lib/checks.mjs +46 -1
- package/cli/lib/doctor.mjs +23 -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/fundamentals.md +10 -0
- package/references/mechanisms.md +1 -0
- package/references/plan-format.md +2 -2
- package/references/team.md +1 -0
- package/skills/build/SKILL.md +4 -3
- package/skills/guard/SKILL.md +22 -0
- package/skills/plan/SKILL.md +2 -0
|
@@ -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.0
|
|
11
|
+
"version": "2.2.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.0
|
|
5
|
+
"version": "2.2.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
|
@@ -45,7 +45,7 @@ Then work the way you already do, e.g. *"add CSV export to the reports page"*. A
|
|
|
45
45
|
5. **Build.** The `build` skill takes one slice per session. It writes the acceptance checks from the spec first, implements, runs `jig verify --record`, logs what changed and commits. If a test and the spec disagree, it stops and tells you rather than editing the test.
|
|
46
46
|
6. **Guard.** The second time the same mistake turns up, the `guard` skill turns it into a test, lint rule, deny rule or hook, not another line of prose.
|
|
47
47
|
|
|
48
|
-
A `jig-reviewer` agent reviews plans, and each slice's diff, in a fresh context and backs every finding with a file and line or a command.
|
|
48
|
+
A `jig-reviewer` agent reviews plans, and each slice's diff, in a fresh context and backs every finding with a file and line or a command. It tags each finding Important, Nit or Pre-existing, so nobody gets held to a bug they didn't write. On a second pass it only looks at what changed and doesn't repeat itself. If Important findings are still open after three rounds, it says to rethink the approach. If your repo has a `REVIEW.md` of `When: · Check: · Source:` entries, it applies the ones that match the diff, reading the file from the plan's baseline commit so the slice can't edit its own checklist.
|
|
49
49
|
|
|
50
50
|
## What a plan looks like
|
|
51
51
|
|
|
@@ -91,11 +91,11 @@ Why no estimates? Agents miss their own runtimes by a typical factor of 2.9 (Age
|
|
|
91
91
|
| Hook | What it does | What it never does |
|
|
92
92
|
|---|---|---|
|
|
93
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 |
|
|
94
|
-
| 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 |
|
|
95
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`) |
|
|
96
|
-
| 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 |
|
|
97
97
|
|
|
98
|
-
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.
|
|
99
99
|
|
|
100
100
|
## The CLI
|
|
101
101
|
|
|
@@ -103,9 +103,10 @@ Turn hooks off with `JIG_HOOKS_OFF=pre-bash,stop` (or `all`), and the session nu
|
|
|
103
103
|
|
|
104
104
|
```
|
|
105
105
|
jig new <slug> --tier brief|full|program --title "..." start a plan with the baseline commit filled in
|
|
106
|
-
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)
|
|
107
107
|
jig status active plans, their Now line, the current slice
|
|
108
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
|
|
109
110
|
jig doctor [--ack] report harness gaps; --ack marks the repo's agent config as read
|
|
110
111
|
```
|
|
111
112
|
|
|
@@ -117,15 +118,16 @@ GAP D2 no ESLint or Biome config, so nothing flags empty catch blocks
|
|
|
117
118
|
GAP D3 secret-looking files the agent can read: .env
|
|
118
119
|
Suggested deny rules for .claude/settings.json (review before adding): {"permissions":{"deny":["Read(./.env)", ...]}}
|
|
119
120
|
ok D4 no repo-level hooks, MCP servers or risky settings
|
|
120
|
-
GAP D5 no CI configuration found
|
|
121
|
+
GAP D5 no CI configuration or git hooks found
|
|
121
122
|
GAP D6 package.json has dependencies but no lockfile
|
|
123
|
+
note D7 no e2e runner or verify skill; fine for a CLI or library if a check runs the real command
|
|
122
124
|
|
|
123
125
|
5 item(s) to look at. jig doctor changed nothing.
|
|
124
126
|
```
|
|
125
127
|
|
|
126
128
|
Plans go in your repo's existing plans folder (`docs/plans/` or `docs/plan/`), or wherever `.jig.json` says with `{"plansDir": "..."}`.
|
|
127
129
|
|
|
128
|
-
D4 flags repo settings that can run code or redirect API traffic before you've read them: hooks, `ANTHROPIC_BASE_URL`, `bypassPermissions`, and auto-enabled MCP servers. Those are the settings behind CVE-2025-59536, CVE-2026-21852 and CVE-2026-33068. Once you've read them, `jig doctor --ack` keeps D4 quiet until one of those files changes. Doctor never runs repo code, so where a lint preset or CI status can't be read from the files, it says so rather than guessing.
|
|
130
|
+
D4 flags repo settings that can run code or redirect API traffic before you've read them: hooks, `ANTHROPIC_BASE_URL`, `bypassPermissions`, and auto-enabled MCP servers. Those are the settings behind CVE-2025-59536, CVE-2026-21852 and CVE-2026-33068. Once you've read them, `jig doctor --ack` keeps D4 quiet until one of those files changes. Doctor never runs repo code, so where a lint preset or CI status can't be read from the files, it says so rather than guessing. D7 asks whether there's a way to run the change, not just test it: a `.claude/skills/verify*` skill, an e2e or HTTP test runner, or an e2e script. It's only a gap for an app (a UI or server framework in its dependencies). A CLI or library gets a note.
|
|
129
131
|
|
|
130
132
|
## Evidence
|
|
131
133
|
|
|
@@ -156,13 +158,14 @@ jig's two wins were the tasks where the right move was to stop. It asked what "M
|
|
|
156
158
|
|
|
157
159
|
**Triggering.** With the SessionStart nudge, all 10 trigger prompts behaved as expected, with or without superpowers installed. Without it, direct requests like "Build a CSV export endpoint" skipped the skill altogether (0 of 3).
|
|
158
160
|
|
|
159
|
-
**Plans and review.** All three multi-slice plans jig wrote in the eval passed `jig lint`. The reviewer found 5 of 5 seeded plan defects in both runs, against 4 and 5 for a plain review in a fresh context. That's too close to call.
|
|
161
|
+
**Plans and review.** All three multi-slice plans jig wrote in the eval passed `jig lint`. The reviewer found 5 of 5 seeded plan defects in both runs, against 4 and 5 for a plain review in a fresh context. That's too close to call. `evals/reviewer/` now keeps a held-out test case apart from the one we tune on, adds a clean plan as a control, and has a same-session self-review arm. In that run (Sonnet 5.5, 3 runs per cell), plain, fresh and self-review all found 15 of 15 held-out defects, and none flagged the clean plan. The one difference: only the fresh reviewer called an unflagged schema change a one-way door that needs your decision (3 of 3, against 0 of 3 each). So jig's case for a separate reviewer rests on its rubric more than on the fresh context. The details, including what went wrong in the first run, are in [the report](evals/results/REPORT.md).
|
|
160
162
|
|
|
161
163
|
Re-run any of it (it spends money on your account, about $0.05 to $0.15 a run):
|
|
162
164
|
|
|
163
165
|
```bash
|
|
164
166
|
node evals/run.mjs --arms none,jig,planmode,superpowers --runs 3 -j 6
|
|
165
167
|
node evals/triggers/run.mjs --arms jig,jig+superpowers --runs 3
|
|
168
|
+
node evals/reviewer/run.mjs --dry # one review, prints the cost estimate
|
|
166
169
|
node evals/reviewer/run.mjs --runs 3
|
|
167
170
|
```
|
|
168
171
|
|
|
@@ -200,7 +203,7 @@ claude plugin uninstall jig@jig # remove
|
|
|
200
203
|
|
|
201
204
|
- **jig never fires:** check `claude plugin details jig` lists the hooks, and that `JIG_NUDGE` isn't `off`.
|
|
202
205
|
- **An install keeps asking:** that's the pre-bash hook. Approve it once the package checks out, or set `JIG_HOOKS_OFF=pre-bash`.
|
|
203
|
-
- **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.
|
|
206
|
+
- **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.
|
|
204
207
|
- **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.
|
|
205
208
|
- **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).
|
|
206
209
|
|
package/agents/jig-reviewer.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: jig-reviewer
|
|
3
|
-
description: Fresh-context reviewer for jig plans and slice diffs. Give it a plan path and the original request (plan mode), or a plan path and a slice ID (diff mode). Returns evidence-backed findings, at most ten. It reads only, and never edits.
|
|
3
|
+
description: Fresh-context reviewer for jig plans and slice diffs. Give it a plan path and the original request (plan mode), or a plan path and a slice ID (diff mode). On a later round, also give it the earlier findings and the last reviewed commit. Returns evidence-backed findings, at most ten. It reads only, and never edits.
|
|
4
4
|
tools: Read, Grep, Glob, Bash
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -10,12 +10,21 @@ Only report findings you can back with evidence: a file and line, a command and
|
|
|
10
10
|
|
|
11
11
|
Don't edit files. Use Bash only to read: `git diff`, `git log`, `git show`, `jig lint`, `jig status`, and package manager queries such as `npm view`. Don't run the project's tests or check commands; the builder runs those with `jig verify`.
|
|
12
12
|
|
|
13
|
+
## Rounds
|
|
14
|
+
|
|
15
|
+
The builder may send the same slice back after fixing your findings. Then the input also has your earlier findings and the last commit you reviewed.
|
|
16
|
+
|
|
17
|
+
- **Round 1:** review the whole slice.
|
|
18
|
+
- **Round 2 and later:** review only `git diff <last reviewed commit>`, plus whether each earlier finding was fixed. Don't repeat a finding. If an earlier one isn't fixed, say "still open: <number>" once.
|
|
19
|
+
- **Name the class of a bug, not one instance.** When you find a swallowed error, a missing auth check or an unescaped query, search the slice for every other place it occurs and report them as one finding, with each location.
|
|
20
|
+
- **After round 3**, if Important findings are still open, return `Verdict: rethink`. Say what keeps going wrong, so the builder rethinks the approach with the owner instead of patching again.
|
|
21
|
+
|
|
13
22
|
## Plan mode
|
|
14
23
|
|
|
15
24
|
Input: a plan path and the original request. Run `jig lint <path>` first; don't repeat what lint reports. Then check what lint can't:
|
|
16
25
|
|
|
17
26
|
1. **Does the outcome match the request?** Look for anything requested and missing, and for anything added that wasn't asked for.
|
|
18
|
-
2. **Would the checks fail if the feature were missing or wrong?** A check that only restates current behaviour, or that can pass with a stub, catches nothing.
|
|
27
|
+
2. **Would the checks fail if the feature were missing or wrong?** A check that only restates current behaviour, or that can pass with a stub, catches nothing. When a slice changes behaviour a user sees, ask for at least one check that runs the real system (kind `e2e`: start the app, CLI or service and drive the changed flow), not only unit tests.
|
|
19
28
|
3. **Reuse.** For each new function, module or dependency in the plan, search the repo for an existing equivalent.
|
|
20
29
|
4. **Unmarked one-way doors:** schema, partition keys, public API contracts, auth model, data deletion, production or infrastructure changes, new dependencies, scope changes.
|
|
21
30
|
5. **Fundamentals the plan skips for what it touches.** These are concurrency and idempotency, queries in loops and missing indexes, timeouts and retries, partial failure, and authorization on new routes. Read `${CLAUDE_PLUGIN_ROOT}/references/fundamentals.md` and `security.md` for the areas involved.
|
|
@@ -35,18 +44,20 @@ Input: a plan path and a slice ID. Diff the slice against its starting commit (f
|
|
|
35
44
|
6. **Insecure defaults:** missing authorization, unescaped output, string-built queries or commands, secrets in code or logs.
|
|
36
45
|
7. **Performance:** queries or network calls inside loops, unbounded concurrency, quadratic scans over growing lists.
|
|
37
46
|
8. **Claims against evidence.** Compare what the builder said was verified with the latest `jig verify` line in the Log.
|
|
47
|
+
9. **The repo's checklist.** If the repo has a REVIEW.md, read it from the plan's Baseline commit with `git show <Baseline>:REVIEW.md`, never the working-tree copy, so the slice under review can't change its own checklist. Each entry has the form `When: <trigger readable from a diff> · Check: <what to verify> · Source: <incident or PR>`. Apply only the entries whose trigger matches this diff, and cite the entry's Source in the finding.
|
|
38
48
|
|
|
39
49
|
## Output
|
|
40
50
|
|
|
41
51
|
```
|
|
42
52
|
Verdict: ready | fix first | rethink
|
|
43
53
|
Findings:
|
|
44
|
-
1. [
|
|
54
|
+
1. [Important|Nit|Pre-existing] <one-line finding>. Evidence: <file:line, plan line, or command + output>. Fix: <specific change>.
|
|
45
55
|
...
|
|
56
|
+
Earlier findings: <fixed / still open, by number; round 2 and later only>
|
|
46
57
|
Not checked: <anything you couldn't check, and why>
|
|
47
58
|
```
|
|
48
59
|
|
|
49
60
|
Each severity has a bar:
|
|
50
|
-
- **
|
|
51
|
-
- **
|
|
52
|
-
- **
|
|
61
|
+
- **Important:** a defect this change adds or makes worse: wrong behaviour, data loss, a security hole, a check that can't fail, or something likely to cause rework. The builder fixes these before the slice closes.
|
|
62
|
+
- **Nit:** worth fixing, but doesn't block.
|
|
63
|
+
- **Pre-existing:** a defect that was there before this change. Report it so the owner knows, but the builder isn't on the hook for it in this slice.
|
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.0
|
|
11
|
+
const VERSION = '2.2.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,7 +1,8 @@
|
|
|
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
|
-
export const KINDS = ['acceptance', 'regression', 'property', 'mutation', 'perf', 'security'];
|
|
5
|
+
export const KINDS = ['acceptance', 'regression', 'property', 'mutation', 'perf', 'security', 'e2e', 'differential'];
|
|
5
6
|
const ID_RE = /^[A-Za-z][\w.-]*$/;
|
|
6
7
|
|
|
7
8
|
export function checksPathFor(planPath) {
|
|
@@ -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/doctor.mjs
CHANGED
|
@@ -157,6 +157,29 @@ export function diagnose(root) {
|
|
|
157
157
|
else add('D6', 'ok', 'lockfile matches package.json');
|
|
158
158
|
} else if (locks.length) add('D6', 'ok', `lockfile present (${locks.join(', ')})`);
|
|
159
159
|
}
|
|
160
|
+
// D7: a way to run the change, not only test it. Conservative: a gap only
|
|
161
|
+
// for a clear app (a UI or server framework in runtime dependencies of a
|
|
162
|
+
// package with no `bin`) with no sign of e2e; everything else is a note.
|
|
163
|
+
const projectFile = pkg || isPy || has('go.mod') || has('Cargo.toml');
|
|
164
|
+
const skillsDir = join(root, '.claude', 'skills');
|
|
165
|
+
let skill = null;
|
|
166
|
+
try { skill = readdirSync(skillsDir).find((n) => /^verify/.test(n) && existsSync(join(skillsDir, n, 'SKILL.md'))); } catch { /* no .claude/skills */ }
|
|
167
|
+
const SKIP = /(^|\/)(examples?|fixtures?|test|tests|__tests__|docs)\//;
|
|
168
|
+
const pkgs = walk(root, 4, (n, r) => n === 'package.json' && !SKIP.test(r)).map((r) => json(join(root, r))).filter(Boolean);
|
|
169
|
+
if (projectFile || skill || pkgs.length) {
|
|
170
|
+
const allDeps = new Set(pkgs.flatMap((p) => Object.keys({ ...(p.dependencies ?? {}), ...(p.devDependencies ?? {}) })));
|
|
171
|
+
const RUNNERS = ['@playwright/test', 'cypress', 'detox', 'webdriverio', '@wdio/cli', 'supertest', 'pactum'];
|
|
172
|
+
const runner = RUNNERS.find((r) => allDeps.has(r));
|
|
173
|
+
const script = pkgs.flatMap((p) => Object.entries(p.scripts ?? {})).find(([k, v]) => /(^|:)(e2e|integration)\b/.test(k) || /\b(playwright test|cypress run|detox test|maestro test)\b/.test(v));
|
|
174
|
+
const config = walk(root, 4, (n, r) => !SKIP.test(r) && /^(playwright|cypress)\.config\.[cm]?[jt]s$|^\.detoxrc|^detox\.config\.|^wdio\.conf\./.test(n))[0] ?? (has('.maestro') ? '.maestro/' : null);
|
|
175
|
+
const py = isPy ? (read(join(root, 'pyproject.toml')) ?? '') + (read(join(root, 'requirements.txt')) ?? '') : '';
|
|
176
|
+
const APPS = /^(react|react-dom|next|vue|nuxt|svelte|@sveltejs\/kit|@angular\/core|solid-js|astro|electron|react-native|expo|express|fastify|koa|hono|@nestjs\/core|@remix-run\/node)$/;
|
|
177
|
+
const isApp = pkgs.some((p) => !p.bin && Object.keys(p.dependencies ?? {}).some((d) => APPS.test(d))) || /\b(django|fastapi|flask)\b/i.test(py);
|
|
178
|
+
const found = [skill && `.claude/skills/${skill}`, runner && `${runner} installed`, script && `script "${script[0]}"`, config].filter(Boolean);
|
|
179
|
+
if (found.length) add('D7', 'ok', `a way to run the change end to end: ${found.join(', ')}`);
|
|
180
|
+
else if (isApp) add('D7', 'gap', 'no way to run the app end to end: no .claude/skills/verify*/SKILL.md, no e2e or HTTP test runner, no e2e script or runner config', 'Add a verify skill that starts the app and drives the changed flow, or an e2e runner. Tests alone miss what running the change shows.');
|
|
181
|
+
else add('D7', 'info', 'no e2e runner or verify skill; fine for a CLI or library if a check runs the real command', 'Give user-visible slices one check that runs the built CLI or public API, not only unit tests.');
|
|
182
|
+
}
|
|
160
183
|
return F;
|
|
161
184
|
}
|
|
162
185
|
|
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.0
|
|
3
|
+
"version": "2.2.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 |
|
|
@@ -34,6 +34,16 @@ Read only the sections for areas the slice touches. Each question either has an
|
|
|
34
34
|
- Can a retry storm happen: clients retrying in lockstep, or retries multiplying through layers?
|
|
35
35
|
- Is ordering assumed anywhere it isn't guaranteed?
|
|
36
36
|
|
|
37
|
+
## Testing and verification
|
|
38
|
+
- Does a check run the change for real? When a slice changes what a user sees, one `e2e` check starts the app, CLI or service and drives the changed flow. Running the change catches what tests of its parts miss.
|
|
39
|
+
- Does a rule have a property, not only examples? The four shapes that cover most rules:
|
|
40
|
+
- **round-trip:** `decode(encode(x)) == x` (serializers, parsers, migrations up then down)
|
|
41
|
+
- **invariant:** something that holds after every operation (a balance never negative, a list stays sorted, counts add up)
|
|
42
|
+
- **idempotency:** doing it twice equals doing it once (retries, webhooks, `PUT`, migrations)
|
|
43
|
+
- **equivalence:** the new code gives the same result as a simpler or older one (an optimisation, a rewrite)
|
|
44
|
+
- Is this a rewrite or a migration that must keep behaviour? Use a `differential` check: run old and new on the same inputs and compare. Normalise the noise first (timestamps, ids, ordering, whitespace), and keep a checked-in list of approved differences, so a new difference fails and an approved one doesn't.
|
|
45
|
+
- Is a test flaky? Find the cause (shared state, time, ordering, a race). Don't retry, sleep or skip it. If you can't find the cause, delete the test and log why.
|
|
46
|
+
|
|
37
47
|
## Software design
|
|
38
48
|
- Does the change deepen an existing module or add a shallow one: a wrapper that passes calls through, or an interface with one implementation?
|
|
39
49
|
- Agents optimize locally. Does the change respect the boundaries and invariants the repo already has? Look for ADRs and module owners.
|
package/references/mechanisms.md
CHANGED
|
@@ -7,6 +7,7 @@ Prose instructions are advisory, and models follow them less as they pile up (IF
|
|
|
7
7
|
| A rule that must always hold ("never edit migrations", "no prod credentials") | Permission deny rule, or a PreToolUse hook | Deterministic: it runs whether or not the model remembers it |
|
|
8
8
|
| A behaviour that must be true of the code | A test, type or lint rule, run in CI | Fails the build instead of relying on review |
|
|
9
9
|
| A convention or non-obvious fact (build command, a trap in this repo) | One line in CLAUDE.md or AGENTS.md | Advisory and cheap. Only write what isn't already in the repo; generated context files raised cost 20–23% with no significant gain (Gloaguen et al., arXiv 2602.11988) |
|
|
10
|
+
| A review rule that only shows in a diff (no test can decide it) | A `When: · Check: · Source:` entry in REVIEW.md, applied by the diff reviewer from the base commit | Read only when the trigger matches, and a slice can't edit the copy that judges it |
|
|
10
11
|
| A procedure used now and then | A skill | Loaded only when needed, so it costs nothing the rest of the time |
|
|
11
12
|
| Investigation, or parallel work | A subagent, or one agent per git worktree split along module boundaries | Keeps searches and logs out of the main context and avoids merge conflicts |
|
|
12
13
|
| Access to an outside system | An MCP server, pinned, with a read-only token where possible | Each server widens what an injected instruction can reach |
|
|
@@ -135,7 +135,7 @@ The Log is append-only and dated: `- 2026-11-25: ...` or `- 2026-11-25 14:02: ..
|
|
|
135
135
|
|---|---|
|
|
136
136
|
| `id` | Letters, digits, `.`, `-` or `_`, starting with a letter. Unique |
|
|
137
137
|
| `slice` | A slice ID from the plan |
|
|
138
|
-
| `kind` | `acceptance`, `regression`, `property`, `mutation`, `perf` or `
|
|
138
|
+
| `kind` | `acceptance`, `regression`, `property`, `mutation`, `perf`, `security`, `e2e` (starts the real app, CLI or service and drives the changed flow) or `differential` (compares old and new output on the same inputs) |
|
|
139
139
|
| `cmd` | Shell command, run from the repo root |
|
|
140
140
|
| `expect.exit` | Expected exit code (default 0) |
|
|
141
141
|
| `expect.stdout` | Optional JavaScript regex the output must match |
|
|
@@ -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,10 +40,11 @@ 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
|
-
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.
|
|
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 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. After fixing, send it back with the earlier findings and the commit it last reviewed, so it reviews only the new diff. If it returns `rethink` after three rounds, stop and take the approach to the owner.
|
|
47
48
|
|
|
48
49
|
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.
|
|
49
50
|
|
|
@@ -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
|
package/skills/guard/SKILL.md
CHANGED
|
@@ -37,6 +37,27 @@ Show the owner the mechanism, the exact change, and how you tested that it catch
|
|
|
37
37
|
|
|
38
38
|
Add a Log line to the active plan naming the failure and the guard.
|
|
39
39
|
|
|
40
|
+
## Review checklist entries
|
|
41
|
+
|
|
42
|
+
Some failures can't be caught by a test or lint rule, but a reviewer reading the diff would spot them. Those can become an entry in the repo's REVIEW.md, which the jig-reviewer applies in diff mode:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
- When: <a trigger readable from a diff, e.g. "a new route under src/api/"> · Check: <what to verify> · Source: <incident, PR or plan Log line>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Propose an entry only when all three hold:
|
|
49
|
+
- it has happened twice (find both occurrences)
|
|
50
|
+
- its trigger can be seen in a diff, without running anything
|
|
51
|
+
- it survived one attempt to disprove it: look for a past diff where the trigger matched and the problem wasn't there, and narrow the trigger if you find one
|
|
52
|
+
|
|
53
|
+
Show the owner the exact entry and let them commit REVIEW.md. Rule files are the owner's, and the reviewer reads REVIEW.md from the plan's Baseline commit, so an agent editing it mid-slice changes nothing anyway.
|
|
54
|
+
|
|
55
|
+
Prune the list when you add to it: drop entries whose Source no longer applies (the code is gone, or a test now catches it) and merge entries with the same trigger. A long checklist gets skimmed.
|
|
56
|
+
|
|
57
|
+
## Start a new gate in observe mode
|
|
58
|
+
|
|
59
|
+
A new hook or gate can misfire, and a gate that asks too often gets switched off. Ship it observing first. jig's own gates support `JIG_GATES=observe` (or `JIG_GATES=observe:<gate>,...`), which logs each decision to `.git/jig/observe.jsonl` instead of asking. For a hook you write, log what it would have blocked in the same way. After a few sessions, read the log with the owner, count the false positives, and only then let it enforce.
|
|
60
|
+
|
|
40
61
|
## Doctor
|
|
41
62
|
|
|
42
63
|
`jig doctor` reports gaps in a repo's harness and changes nothing. It checks:
|
|
@@ -46,6 +67,7 @@ Add a Log line to the active plan naming the failure and the guard.
|
|
|
46
67
|
- whether `.claude/settings.json` and `.mcp.json` need reading before you trust the repo
|
|
47
68
|
- for a secret scanner in CI
|
|
48
69
|
- for lockfile drift
|
|
70
|
+
- for a way to run the change end to end: a `.claude/skills/verify*/SKILL.md`, an e2e runner or an e2e script (D7; a gap for apps, a note for a CLI or library)
|
|
49
71
|
|
|
50
72
|
Run it, then turn each gap the owner cares about into a slice or a guard. Treat a repo you didn't write as untrusted: read its `.claude/` and `.mcp.json` before running an agent in it.
|
|
51
73
|
|
package/skills/plan/SKILL.md
CHANGED
|
@@ -66,6 +66,8 @@ What matters most, and why:
|
|
|
66
66
|
- `mutation` on core logic at the full tier
|
|
67
67
|
- `perf` with a threshold on hot paths
|
|
68
68
|
- `security` on auth and input
|
|
69
|
+
- `e2e` when the slice changes behaviour a user sees: one check that starts the real app, CLI or service and drives the changed flow, because tests alone miss what running it shows
|
|
70
|
+
- `differential` when a rewrite must keep behaviour: old and new on the same inputs (see `references/fundamentals.md`)
|
|
69
71
|
- **Risks** say how you'd notice each one and what you'd do instead. Don't score them.
|
|
70
72
|
- **No time estimates.** They are unreliable, and they turn into deadlines. Scope (slices, files, checks) is the measure.
|
|
71
73
|
|