handoff-check 0.6.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0
4
+
5
+ - Add explicit two-snapshot diff with added, removed, changed and unchanged counts.
6
+ - Compare content-aware unbound v2/v3 and bound v4 snapshots with strict scope/project matching.
7
+ - Show typed field differences when both snapshots retain content; preserve hash-only comparison.
8
+ - Add terminal-only guided setup with explicit project/environments and a real global rule.
9
+ - Preview exact new project-bound files and retained baselines before explicit adoption; refuse overwrites.
10
+ - Preserve existing verification, init, profile and lifecycle contracts without automatic migration.
11
+
3
12
  ## 0.6.0
4
13
 
5
14
  - Add opt-in manifest v3/handoff v4 portable project binding with strict matching.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  A deterministic, local CLI that verifies active constraints before a coding agent
4
4
  resumes work.
5
5
 
6
- **Version: 0.6.0.**
6
+ **Version: 0.7.0.**
7
7
 
8
8
  A task summary may preserve the goal while losing an active rule, carrying an
9
9
  expired restriction, or moving a staging-only instruction into production.
@@ -18,8 +18,8 @@ Source references are review metadata and are never fetched.
18
18
  Run in the repository where your agent works:
19
19
 
20
20
  ```sh
21
- npx handoff-check@0.6.0 init --scope staging --agent both --dry-run
22
- npx handoff-check@0.6.0 init --scope staging --agent both
21
+ npx handoff-check@0.7.0 init --scope staging --agent both --dry-run
22
+ npx handoff-check@0.7.0 init --scope staging --agent both
23
23
  ```
24
24
 
25
25
  This creates `.handoff-check.json`, starter `constraints.json` and `handoff.json`,
@@ -33,7 +33,7 @@ on verification. Revisions and hashes detect edits under an unchanged rule ID.
33
33
  Ask a resuming agent to use the installed skill, or run:
34
34
 
35
35
  ```sh
36
- npx handoff-check@0.6.0 verify --format json --require-content
36
+ npx handoff-check@0.7.0 verify --format json --require-content
37
37
  ```
38
38
 
39
39
  The saved config supplies paths and scope. `init --ci` also creates a pinned GitHub
@@ -42,7 +42,7 @@ agent execution; CI enforces the declared-ID comparison when its workflow runs.
42
42
  Neither checks whether the agent obeys a rule's meaning.
43
43
 
44
44
  Node.js 22+ is required; end users do not need Bun. Global installation is also
45
- available: `npm install --global handoff-check@0.6.0`. For contributor builds or
45
+ available: `npm install --global handoff-check@0.7.0`. For contributor builds or
46
46
  offline package testing, see the [setup guide](docs/agent-integration.md).
47
47
 
48
48
  For a complete first-rule walkthrough, including a passing baseline and a detected
@@ -65,7 +65,7 @@ default but are explicitly marked. Unexpected reported IDs still fail.
65
65
  To require actual active rules, opt in:
66
66
 
67
67
  ```sh
68
- npx handoff-check@0.6.0 verify --require-content --require-active --format json
68
+ npx handoff-check@0.7.0 verify --require-content --require-active --format json
69
69
  ```
70
70
 
71
71
  A zero active set produces global NO_ACTIVE_CONSTRAINTS (no fake ID), mismatch
@@ -83,8 +83,8 @@ init and snapshot reject it. See the
83
83
  After reviewing rules at handoff creation, capture a new baseline:
84
84
 
85
85
  ```sh
86
- npx handoff-check@0.6.0 snapshot --task "Resume migration review" --output handoff.next.json
87
- npx handoff-check@0.6.0 verify --handoff handoff.next.json --require-content --format json
86
+ npx handoff-check@0.7.0 snapshot --task "Resume migration review" --output handoff.next.json
87
+ npx handoff-check@0.7.0 verify --handoff handoff.next.json --require-content --format json
88
88
  ```
89
89
 
90
90
  Snapshot creates a new file exclusively. Review it before deliberately replacing
@@ -106,9 +106,9 @@ hashed, but referenced documents are not fetched or checked.
106
106
  ## Explain rules and review field changes
107
107
 
108
108
  ```sh
109
- npx handoff-check@0.6.0 explain --format markdown
110
- npx handoff-check@0.6.0 snapshot --task "Review migration" --include-content --output handoff.reviewed.json
111
- npx handoff-check@0.6.0 verify --handoff handoff.reviewed.json --require-content --format markdown
109
+ npx handoff-check@0.7.0 explain --format markdown
110
+ npx handoff-check@0.7.0 snapshot --task "Review migration" --include-content --output handoff.reviewed.json
111
+ npx handoff-check@0.7.0 verify --handoff handoff.reviewed.json --require-content --format markdown
112
112
  ```
113
113
 
114
114
  `explain` shows every manifest rule's applicability for the selected scope/time,
@@ -133,7 +133,7 @@ cannot read it. No input migration is needed to keep using v1/v2 on 0.4.
133
133
  `verify --format markdown` preserves exit codes 0/1/2 and includes scope, time,
134
134
  active count, tracking mode, requested policies and findings. To save a report,
135
135
  redirect stdout to a separate file; a shell creates/truncates the destination, so
136
- never choose a manifest or handoff path. Markdown is verify/explain-only.
136
+ never choose a manifest or handoff path. Markdown is supported by verify, explain and diff.
137
137
  See [ADR 0004](docs/decisions/0004-explainable-verification.md) and the
138
138
  [retained-content example](examples/retained-content/handoff.json).
139
139
 
@@ -153,19 +153,32 @@ or revisioned v2 manifests. Scope must match the v2 handoff's saved scope.
153
153
  Review current rules, capture a new v2 baseline, and deliberately update the saved
154
154
  handoff. Existing inputs are preserved by init, not silently upgraded. Review
155
155
  installed skills, instruction blocks and CI commands to update their pinned
156
- version to 0.6.0 and add `--require-content`. Init refuses to overwrite differing
156
+ version to 0.7.0 and add `--require-content`. Init refuses to overwrite differing
157
157
  integrations; compare them with the new packaged templates and update reviewed
158
158
  copies explicitly. Never refresh before checking resumed work or reuse capturedAt
159
159
  as the clock for real resumed work.
160
160
 
161
+ ## Snapshot diff and guided setup
162
+
163
+ Run `npx handoff-check@0.7.0 setup` in a terminal to create a new project-bound
164
+ configuration with explicit environments and one real rule you author. Review
165
+ the exact retained baselines before typing `yes`; existing files are never replaced.
166
+ No agent integrations or dependencies are installed. Use `--dry-run` to preview.
167
+
168
+ Compare two saved snapshots with `diff --before saved.json --after next.json`.
169
+ It shows added/removed/changed rules, with field details when both sides retain
170
+ content. Exit 0 means unchanged, 1 differences, 2 invalid. It compares declarations,
171
+ not agent memory or current applicability; continue using verify before resuming.
172
+ See [the guide](docs/snapshot-diff-and-setup.md).
173
+
161
174
  ## Configuration and initialization
162
175
 
163
176
  0.6 adds optional portable project binding, explicit environment profiles and
164
177
  reproducibility metadata. Existing unbound files/default JSON stay compatible.
165
178
 
166
179
  ```sh
167
- npx handoff-check@0.6.0 verify --profile stage --require-content --report --format json
168
- npx handoff-check@0.6.0 doctor --profile stage
180
+ npx handoff-check@0.7.0 verify --profile stage --require-content --report --format json
181
+ npx handoff-check@0.7.0 doctor --profile stage
169
182
  ```
170
183
 
171
184
  These commands require an explicitly authored config v2 profile. Bound manifest
@@ -175,12 +188,12 @@ record the exact input/config bytes parsed, package version and policies; Git is
175
188
  read only with separate --git-context. They are not signed attestations or proof
176
189
  of compliance. See [setup, migration and examples](docs/project-context.md).
177
190
 
178
- For read-only installation diagnostics, run `npx handoff-check@0.6.0 doctor`.
191
+ For read-only installation diagnostics, run `npx handoff-check@0.7.0 doctor`.
179
192
  `doctor --format json` reports paths, supported input versions and managed
180
193
  integration pins. Its exit codes are 0 healthy, 1 attention and 2 invalid invocation;
181
194
  it does not verify a handoff or prove a host ran the integration.
182
195
 
183
- `npx handoff-check@0.6.0 hook-config --host claude` emits an opt-in advisory
196
+ `npx handoff-check@0.7.0 hook-config --host claude` emits an opt-in advisory
184
197
  SessionStart snippet to merge manually into existing settings. It never overwrites
185
198
  settings, and requires a pinned project-local package. The local adapter uses the
186
199
  same verifier without network/model calls; startup/resume/clear/compact checks
@@ -318,6 +331,11 @@ handoff-check explain
318
331
  [--config <path>] [--constraints <path>] [--scope <scope>]
319
332
  [--as-of <UTC time>] [--format text|json|markdown]
320
333
 
334
+ handoff-check diff --before <snapshot> --after <snapshot>
335
+ [--format text|json|markdown]
336
+
337
+ handoff-check setup [--dry-run]
338
+
321
339
  handoff-check init --scope <scope>
322
340
  [--agent codex|claude|both|none] [--dry-run] [--ci] [--format text|json]
323
341
 
package/dist/cli.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli.ts
4
- import { open as open2 } from "node:fs/promises";
5
- import { resolve as resolve5 } from "node:path";
4
+ import { open as open3 } from "node:fs/promises";
5
+ import { resolve as resolve6 } from "node:path";
6
6
  import { parseArgs } from "node:util";
7
7
  // package.json
8
8
  var package_default = {
9
9
  name: "handoff-check",
10
- version: "0.6.0",
10
+ version: "0.7.0",
11
11
  description: "A deterministic, local CLI that verifies active constraints before a coding agent resumes work.",
12
12
  type: "module",
13
13
  packageManager: "bun@1.2.10",
@@ -407,13 +407,80 @@ async function loadConfig(cwd, explicit) {
407
407
  };
408
408
  }
409
409
 
410
- // src/doctor.ts
411
- import { lstat, readFile as readFile2, stat as stat2 } from "node:fs/promises";
412
- import { resolve as resolve3 } from "node:path";
413
-
414
- // src/lifecycle.ts
415
- import { realpath, stat } from "node:fs/promises";
416
- import { dirname as dirname2, isAbsolute, relative, resolve as resolve2, sep } from "node:path";
410
+ // src/render.ts
411
+ function terminalText(value) {
412
+ return Array.from(value, (character) => {
413
+ const code = character.codePointAt(0) ?? 0;
414
+ return /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(character) ? `\\u${code.toString(16).padStart(4, "0")}` : character;
415
+ }).join("");
416
+ }
417
+ function markdownText(value) {
418
+ return terminalText(value).replace(/[&<>\\`*_{}[\]()#+.!|~:/@-]/g, (character) => `&#${character.charCodeAt(0)};`);
419
+ }
420
+ function verificationMarkdown(result, handoff, requireActive, requireContent) {
421
+ const label = result.status === "verified" ? result.expectedConstraints.length ? "PASS" : "PASS (EMPTY)" : "FAIL";
422
+ const lines = [
423
+ "# Handoff Check verification",
424
+ "",
425
+ `- Result: ${label}`,
426
+ `- Scope: ${markdownText(result.scope)}`,
427
+ ...result.projectId === undefined ? [] : [`- Project: ${markdownText(result.projectId)}`],
428
+ `- Evaluated at: ${markdownText(result.asOf)}`,
429
+ `- Active constraints checked: ${result.expectedConstraints.length}`,
430
+ `- Tracking: ${handoff.schemaVersion === 1 ? "IDs only; content changes not checked" : handoff.schemaVersion === 3 || handoff.schemaVersion === 4 && handoff.contentMode === "retained" ? "Content hashes with retained old content" : "Content hashes; old content not retained"}`,
431
+ `- Require content-aware handoff: ${requireContent}`,
432
+ `- Require active constraints: ${requireActive}`,
433
+ ""
434
+ ];
435
+ if (!result.expectedConstraints.length)
436
+ lines.push("No active constraints apply to this scope and time.", "");
437
+ lines.push("## Findings", "");
438
+ if (!result.findings.length)
439
+ lines.push("No findings.", "");
440
+ for (const finding of result.findings) {
441
+ lines.push(`### ${finding.code}${finding.id === undefined ? "" : ` ${markdownText(finding.id)}`}`, "", markdownText(finding.message), "");
442
+ if (finding.code === "CHANGED") {
443
+ if (finding.changes) {
444
+ lines.push("| Field | Before (saved) | After (current) |", "| --- | --- | --- |");
445
+ for (const change of finding.changes)
446
+ lines.push(`| ${change.field} | ${markdownText(JSON.stringify(change.before))} | ${markdownText(JSON.stringify(change.after))} |`);
447
+ lines.push("", "Null means an absent optional field.", "");
448
+ } else
449
+ lines.push("Previous content unavailable: this baseline stores hashes only. No textual diff can be reconstructed.", "");
450
+ }
451
+ }
452
+ lines.push("A pass checks declared constraints, not agent behavior or action authorization.");
453
+ return `${lines.join(`
454
+ `)}
455
+ `;
456
+ }
457
+ function explanationText(result, markdown) {
458
+ if (markdown) {
459
+ return [
460
+ "# Handoff Check explanation",
461
+ "",
462
+ `- Scope: ${markdownText(result.scope)}`,
463
+ ...result.projectId === undefined ? [] : [`- Project: ${markdownText(result.projectId)}`],
464
+ `- Evaluated at: ${markdownText(result.asOf)}`,
465
+ `- Active constraints: ${result.activeConstraintCount}`,
466
+ "",
467
+ "| ID | Rule scope | Decision | Reason | Description | Source |",
468
+ "| --- | --- | --- | --- | --- | --- |",
469
+ ...result.rules.map((rule) => `| ${[rule.id, rule.scope, rule.decision, rule.reason, rule.description, rule.source].map(markdownText).join(" | ")} |`),
470
+ "",
471
+ "Explains manifest applicability only; no handoff was compared.",
472
+ ""
473
+ ].join(`
474
+ `);
475
+ }
476
+ return [
477
+ ...result.rules.map((rule) => `${rule.decision.padEnd(12)} ${rule.id} ${terminalText(rule.reason)}; ${terminalText(rule.description)}; source ${terminalText(rule.source)}`),
478
+ `EXPLAIN ${result.activeConstraintCount} active constraints | ${result.rules.length} manifest rules | scope ${result.scope} | as of ${result.asOf}${result.projectId === undefined ? "" : ` | project ${result.projectId}`}`,
479
+ "No handoff was compared.",
480
+ ""
481
+ ].join(`
482
+ `);
483
+ }
417
484
 
418
485
  // src/verifier.ts
419
486
  function compare(a, b) {
@@ -624,7 +691,88 @@ function explain(manifest, scope, asOf) {
624
691
  };
625
692
  }
626
693
 
694
+ // src/diff.ts
695
+ function diffSnapshots(before, after) {
696
+ if (before.schemaVersion === 1 || after.schemaVersion === 1)
697
+ throw new InputError("diff requires content-aware v2/v3/v4 snapshots");
698
+ if (before.scope !== after.scope)
699
+ throw new InputError("diff requires snapshots with the same scope");
700
+ const project = before.schemaVersion === 4 ? before.projectId : undefined;
701
+ if (project !== (after.schemaVersion === 4 ? after.projectId : undefined))
702
+ throw new InputError("diff requires matching project binding on both snapshots");
703
+ const previous = new Map(before.activeConstraints.map((r) => [r.id, r]));
704
+ const current = new Map(after.activeConstraints.map((r) => [r.id, r]));
705
+ const ref = (r) => ({
706
+ id: r.id,
707
+ revision: r.revision,
708
+ contentHash: r.contentHash
709
+ });
710
+ const changes = [];
711
+ let unchangedCount = 0;
712
+ for (const id of [
713
+ ...new Set([...previous.keys(), ...current.keys()])
714
+ ].sort()) {
715
+ const a = previous.get(id);
716
+ const b = current.get(id);
717
+ if (a && b && a.revision === b.revision && a.contentHash === b.contentHash) {
718
+ unchangedCount++;
719
+ continue;
720
+ }
721
+ const retained = (r) => ("content" in r);
722
+ changes.push({
723
+ id,
724
+ kind: !a ? "ADDED" : !b ? "REMOVED" : "CHANGED",
725
+ before: a ? ref(a) : null,
726
+ after: b ? ref(b) : null,
727
+ ...a && b && retained(a) && retained(b) ? { fields: fieldChanges(a.content, b.content) } : {}
728
+ });
729
+ }
730
+ return {
731
+ schemaVersion: 1,
732
+ status: changes.length ? "different" : "unchanged",
733
+ scope: before.scope,
734
+ ...project === undefined ? {} : { projectId: project },
735
+ beforeCount: previous.size,
736
+ afterCount: current.size,
737
+ unchangedCount,
738
+ changes,
739
+ notice: "Compares declared rules, not agent behavior or current applicability. Task and capture time are metadata and are not compared. Field details require retained content on both sides; additions/removals do not imply why a rule became active or inactive."
740
+ };
741
+ }
742
+ function diffText(result, markdown) {
743
+ const safe = markdown ? markdownText : terminalText;
744
+ const lines = [
745
+ markdown ? `# Handoff Check snapshot diff
746
+ ` : "SNAPSHOT DIFF",
747
+ `${result.status.toUpperCase()} | scope ${safe(result.scope)}${result.projectId ? ` | project ${safe(result.projectId)}` : ""}`,
748
+ `${result.beforeCount} before | ${result.afterCount} after | ${result.unchangedCount} unchanged`
749
+ ];
750
+ for (const change of result.changes) {
751
+ lines.push(`${change.kind} ${safe(change.id)}`);
752
+ if (change.kind === "CHANGED") {
753
+ if (change.fields) {
754
+ for (const field of change.fields)
755
+ lines.push(` ${field.field}: ${safe(JSON.stringify(field.before))} -> ${safe(JSON.stringify(field.after))}`);
756
+ } else
757
+ lines.push(" Field details unavailable: both snapshots must retain content");
758
+ lines.push(` Before: revision ${change.before?.revision}, ${change.before?.contentHash}`, ` After: revision ${change.after?.revision}, ${change.after?.contentHash}`);
759
+ }
760
+ }
761
+ lines.push(safe(result.notice));
762
+ return `${lines.join(markdown ? `
763
+
764
+ ` : `
765
+ `)}
766
+ `;
767
+ }
768
+
769
+ // src/doctor.ts
770
+ import { lstat, readFile as readFile2, stat as stat2 } from "node:fs/promises";
771
+ import { resolve as resolve3 } from "node:path";
772
+
627
773
  // src/lifecycle.ts
774
+ import { realpath, stat } from "node:fs/promises";
775
+ import { dirname as dirname2, isAbsolute, relative, resolve as resolve2, sep } from "node:path";
628
776
  var lifecycleCommand = "node";
629
777
  var projectPlaceholder = "$" + "{CLAUDE_PROJECT_DIR}";
630
778
  var lifecycleArgs = [
@@ -1176,81 +1324,6 @@ jobs:
1176
1324
  };
1177
1325
  }
1178
1326
 
1179
- // src/render.ts
1180
- function terminalText(value) {
1181
- return Array.from(value, (character) => {
1182
- const code = character.codePointAt(0) ?? 0;
1183
- return /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(character) ? `\\u${code.toString(16).padStart(4, "0")}` : character;
1184
- }).join("");
1185
- }
1186
- function markdownText(value) {
1187
- return terminalText(value).replace(/[&<>\\`*_{}[\]()#+.!|~:/@-]/g, (character) => `&#${character.charCodeAt(0)};`);
1188
- }
1189
- function verificationMarkdown(result, handoff, requireActive, requireContent) {
1190
- const label = result.status === "verified" ? result.expectedConstraints.length ? "PASS" : "PASS (EMPTY)" : "FAIL";
1191
- const lines = [
1192
- "# Handoff Check verification",
1193
- "",
1194
- `- Result: ${label}`,
1195
- `- Scope: ${markdownText(result.scope)}`,
1196
- ...result.projectId === undefined ? [] : [`- Project: ${markdownText(result.projectId)}`],
1197
- `- Evaluated at: ${markdownText(result.asOf)}`,
1198
- `- Active constraints checked: ${result.expectedConstraints.length}`,
1199
- `- Tracking: ${handoff.schemaVersion === 1 ? "IDs only; content changes not checked" : handoff.schemaVersion === 3 || handoff.schemaVersion === 4 && handoff.contentMode === "retained" ? "Content hashes with retained old content" : "Content hashes; old content not retained"}`,
1200
- `- Require content-aware handoff: ${requireContent}`,
1201
- `- Require active constraints: ${requireActive}`,
1202
- ""
1203
- ];
1204
- if (!result.expectedConstraints.length)
1205
- lines.push("No active constraints apply to this scope and time.", "");
1206
- lines.push("## Findings", "");
1207
- if (!result.findings.length)
1208
- lines.push("No findings.", "");
1209
- for (const finding of result.findings) {
1210
- lines.push(`### ${finding.code}${finding.id === undefined ? "" : ` ${markdownText(finding.id)}`}`, "", markdownText(finding.message), "");
1211
- if (finding.code === "CHANGED") {
1212
- if (finding.changes) {
1213
- lines.push("| Field | Before (saved) | After (current) |", "| --- | --- | --- |");
1214
- for (const change of finding.changes)
1215
- lines.push(`| ${change.field} | ${markdownText(JSON.stringify(change.before))} | ${markdownText(JSON.stringify(change.after))} |`);
1216
- lines.push("", "Null means an absent optional field.", "");
1217
- } else
1218
- lines.push("Previous content unavailable: this baseline stores hashes only. No textual diff can be reconstructed.", "");
1219
- }
1220
- }
1221
- lines.push("A pass checks declared constraints, not agent behavior or action authorization.");
1222
- return `${lines.join(`
1223
- `)}
1224
- `;
1225
- }
1226
- function explanationText(result, markdown) {
1227
- if (markdown) {
1228
- return [
1229
- "# Handoff Check explanation",
1230
- "",
1231
- `- Scope: ${markdownText(result.scope)}`,
1232
- ...result.projectId === undefined ? [] : [`- Project: ${markdownText(result.projectId)}`],
1233
- `- Evaluated at: ${markdownText(result.asOf)}`,
1234
- `- Active constraints: ${result.activeConstraintCount}`,
1235
- "",
1236
- "| ID | Rule scope | Decision | Reason | Description | Source |",
1237
- "| --- | --- | --- | --- | --- | --- |",
1238
- ...result.rules.map((rule) => `| ${[rule.id, rule.scope, rule.decision, rule.reason, rule.description, rule.source].map(markdownText).join(" | ")} |`),
1239
- "",
1240
- "Explains manifest applicability only; no handoff was compared.",
1241
- ""
1242
- ].join(`
1243
- `);
1244
- }
1245
- return [
1246
- ...result.rules.map((rule) => `${rule.decision.padEnd(12)} ${rule.id} ${terminalText(rule.reason)}; ${terminalText(rule.description)}; source ${terminalText(rule.source)}`),
1247
- `EXPLAIN ${result.activeConstraintCount} active constraints | ${result.rules.length} manifest rules | scope ${result.scope} | as of ${result.asOf}${result.projectId === undefined ? "" : ` | project ${result.projectId}`}`,
1248
- "No handoff was compared.",
1249
- ""
1250
- ].join(`
1251
- `);
1252
- }
1253
-
1254
1327
  // src/report.ts
1255
1328
  import { execFile } from "node:child_process";
1256
1329
  import { promisify } from "node:util";
@@ -1303,10 +1376,153 @@ function reportMarkdown(report) {
1303
1376
  `);
1304
1377
  }
1305
1378
 
1379
+ // src/setup.ts
1380
+ import { lstat as lstat3, open as open2, readdir } from "node:fs/promises";
1381
+ import { resolve as resolve5 } from "node:path";
1382
+ import { createInterface } from "node:readline/promises";
1383
+ function setupPlan(answers, asOf) {
1384
+ const projectId = identifier(answers.projectId, "Project ID");
1385
+ const scopes = answers.scopes.map((scope) => identifier(scope, "Environment"));
1386
+ if (!scopes.length || scopes.length > 20 || new Set(scopes).size !== scopes.length || new Set(scopes.map((s) => s.toLowerCase())).size !== scopes.length)
1387
+ throw new InputError("Enter 1 to 20 unique environments (case-insensitive filenames)");
1388
+ const manifest = parseManifest({
1389
+ schemaVersion: 3,
1390
+ projectId,
1391
+ constraints: [
1392
+ {
1393
+ id: identifier(answers.ruleId, "Rule ID"),
1394
+ revision: 1,
1395
+ scope: "global",
1396
+ description: answers.description,
1397
+ source: answers.source
1398
+ }
1399
+ ]
1400
+ });
1401
+ const profiles = Object.fromEntries(scopes.map((scope) => [scope, { scope, handoff: `handoff-${scope}.json` }]));
1402
+ const config = parseConfig({
1403
+ schemaVersion: 2,
1404
+ projectId,
1405
+ constraints: "constraints.json",
1406
+ profiles
1407
+ });
1408
+ const json = (value) => `${JSON.stringify(value, null, 2)}
1409
+ `;
1410
+ return [
1411
+ { path: ".handoff-check.json", content: json(config) },
1412
+ { path: "constraints.json", content: json(manifest) },
1413
+ ...scopes.map((scope) => ({
1414
+ path: `handoff-${scope}.json`,
1415
+ content: json(snapshot(manifest, answers.task, scope, asOf, {
1416
+ includeContent: true,
1417
+ projectId
1418
+ }))
1419
+ }))
1420
+ ];
1421
+ }
1422
+ async function assertSetupTargets(root, files) {
1423
+ const existing = new Set((await readdir(root)).map((name) => name.normalize("NFC").toLowerCase()));
1424
+ for (const file of files) {
1425
+ if (existing.has(file.path.normalize("NFC").toLowerCase()))
1426
+ throw new InputError(`Setup requires new files; target already exists: '${file.path}'.`);
1427
+ try {
1428
+ await lstat3(resolve5(root, file.path));
1429
+ } catch (error) {
1430
+ if (error.code === "ENOENT")
1431
+ continue;
1432
+ throw error;
1433
+ }
1434
+ throw new InputError(`Setup requires new files; target already exists: '${file.path}'. Use init or edit existing configuration explicitly.`);
1435
+ }
1436
+ }
1437
+ async function writeSetup(root, files) {
1438
+ await assertSetupTargets(root, files);
1439
+ const written = [];
1440
+ for (const file of files) {
1441
+ try {
1442
+ const handle = await open2(resolve5(root, file.path), "wx", 420);
1443
+ try {
1444
+ await handle.writeFile(file.content, "utf8");
1445
+ } finally {
1446
+ await handle.close();
1447
+ }
1448
+ written.push(file.path);
1449
+ } catch {
1450
+ throw new InputError(`Setup stopped at '${file.path}'. Written files: ${written.join(", ") || "none"}. Filesystem writes are not transactional; inspect before retrying.`);
1451
+ }
1452
+ }
1453
+ }
1454
+ async function guidedSetup(root, dryRun) {
1455
+ if (!process.stdin.isTTY || !process.stdout.isTTY)
1456
+ throw new InputError("setup requires an interactive terminal; use init --scope <scope> for automation");
1457
+ await assertSetupTargets(root, [
1458
+ { path: ".handoff-check.json" },
1459
+ { path: "constraints.json" }
1460
+ ]);
1461
+ const reader = createInterface({
1462
+ input: process.stdin,
1463
+ output: process.stdout
1464
+ });
1465
+ const abort = new AbortController;
1466
+ reader.on("SIGINT", () => {
1467
+ abort.abort();
1468
+ reader.close();
1469
+ });
1470
+ reader.on("close", () => abort.abort());
1471
+ const ask = async (prompt) => {
1472
+ try {
1473
+ return (await reader.question(prompt, { signal: abort.signal })).trim();
1474
+ } catch {
1475
+ throw new InputError("Setup cancelled before approval; no files written");
1476
+ }
1477
+ };
1478
+ try {
1479
+ process.stdout.write(`Create a project-bound starter with one real rule applying to every environment.
1480
+ No agent settings, hooks, CI, or dependencies will be installed.
1481
+ `);
1482
+ const projectId = await ask("Project ID: ");
1483
+ const scopes = (await ask("Environments (comma-separated, e.g. staging,production): ")).split(",").map((s) => s.trim());
1484
+ const ruleId = await ask("First rule ID: ");
1485
+ const description = await ask("Rule applying to ALL environments: ");
1486
+ const source = await ask("Rule source reference (stored as text, never fetched): ");
1487
+ const task = await ask("Initial handoff task: ");
1488
+ const files = setupPlan({ projectId, scopes, ruleId, description, source, task }, new Date().toISOString());
1489
+ await assertSetupTargets(root, files);
1490
+ process.stdout.write(`
1491
+ Review the exact proposed files and retained rule content:
1492
+ `);
1493
+ for (const file of files)
1494
+ process.stdout.write(`
1495
+ --- ${file.path} ---
1496
+ ${file.content.split(`
1497
+ `).map(terminalText).join(`
1498
+ `)}
1499
+ `);
1500
+ if (dryRun) {
1501
+ process.stdout.write(`PREVIEW ONLY: no files written.
1502
+ `);
1503
+ return;
1504
+ }
1505
+ if (await ask("Adopt these reviewed rules and create these new baselines? Type yes: ") !== "yes") {
1506
+ process.stdout.write(`CANCELLED: no files written.
1507
+ `);
1508
+ return;
1509
+ }
1510
+ await writeSetup(root, files);
1511
+ process.stdout.write(`CREATED ${files.length} files.
1512
+ Next: handoff-check verify --profile ${scopes[0]} --require-content --require-active
1513
+ Edit and review constraints before relying on them. Never refresh a baseline before verifying it on resume.
1514
+ `);
1515
+ } finally {
1516
+ reader.close();
1517
+ }
1518
+ }
1519
+
1306
1520
  // src/cli.ts
1307
1521
  var help = `Handoff Check
1308
1522
 
1309
1523
  Usage: handoff-check verify --scope <scope> [options]
1524
+ handoff-check diff --before <snapshot> --after <snapshot> [--format text|json|markdown]
1525
+ handoff-check setup [--dry-run]
1310
1526
  handoff-check init --scope <scope> [--agent both] [--dry-run] [--ci]
1311
1527
  handoff-check snapshot --task <task> [--output <new-file>] [options]
1312
1528
  handoff-check explain --scope <scope> [options]
@@ -1315,6 +1531,8 @@ Usage: handoff-check verify --scope <scope> [options]
1315
1531
  handoff-check hook --host claude --config <absolute-path> [--require-active]
1316
1532
 
1317
1533
  Options:
1534
+ --before <path> diff: saved snapshot before the change
1535
+ --after <path> diff: saved snapshot after the change
1318
1536
  --constraints <path> Manifest file (default: constraints.json)
1319
1537
  --handoff <path> Handoff file (default: handoff.json)
1320
1538
  --scope <scope> Selected scope, including global constraints
@@ -1328,15 +1546,15 @@ Options:
1328
1546
  --task <task> snapshot: task description (required)
1329
1547
  --output <path> snapshot: create a new baseline file, never overwrite
1330
1548
  --include-content snapshot: retain old rule text in unbound v3/bound v4 (opt-in)
1331
- --format text|json|markdown Markdown is verify/explain-only (default: text)
1549
+ --format text|json|markdown Markdown is verify/explain/diff-only (default: text)
1332
1550
  --agent <agent> init: codex, claude, both (default), or none
1333
1551
  --host <host> doctor: integration target; hook/hook-config: claude
1334
- --dry-run init: preview files and instruction changes without writes
1552
+ --dry-run init/setup: preview proposed files without writes
1335
1553
  --ci init: also create a pinned GitHub Actions check
1336
1554
  --version Show package version
1337
1555
  --help Show this help
1338
1556
 
1339
- Exit codes: verify 0 verified / 1 mismatch; doctor 0 healthy / 1 attention.
1557
+ Exit codes: verify 0 verified / 1 mismatch; diff 0 unchanged / 1 different; doctor 0 healthy / 1 attention.
1340
1558
  Hook 0 means advisory response delivered (may report FAIL/INVALID), not verified.
1341
1559
  Invalid invocation/input returns 2; explain/init/snapshot/hook-config succeed with 0.
1342
1560
  `;
@@ -1367,7 +1585,9 @@ async function main() {
1367
1585
  report: { type: "boolean" },
1368
1586
  "git-context": { type: "boolean" },
1369
1587
  task: { type: "string" },
1370
- output: { type: "string" }
1588
+ output: { type: "string" },
1589
+ before: { type: "string" },
1590
+ after: { type: "string" }
1371
1591
  }
1372
1592
  });
1373
1593
  format = values.format;
@@ -1389,11 +1609,36 @@ async function main() {
1389
1609
  "explain",
1390
1610
  "doctor",
1391
1611
  "hook",
1392
- "hook-config"
1612
+ "hook-config",
1613
+ "diff",
1614
+ "setup"
1393
1615
  ].includes(positionals[0] ?? ""))
1394
- throw new InputError("Expected command: verify, snapshot, explain, init, doctor, hook or hook-config (use --help for usage)");
1616
+ throw new InputError("Expected command: verify, snapshot, explain, init, setup, diff, doctor, hook or hook-config (use --help for usage)");
1395
1617
  const cwd = process.cwd();
1396
1618
  const command = positionals[0];
1619
+ if (command === "diff" || command === "setup") {
1620
+ const allowed = command === "diff" ? ["before", "after", "format"] : ["dry-run"];
1621
+ for (const key of Object.keys(values)) {
1622
+ if (key === "format" && values.format === "text" && !process.argv.slice(2).some((arg) => arg === "--format" || arg.startsWith("--format=")))
1623
+ continue;
1624
+ if (!allowed.includes(key))
1625
+ throw new InputError(`--${key} is not supported by ${command}`);
1626
+ }
1627
+ if (command === "setup") {
1628
+ await guidedSetup(cwd, values["dry-run"] ?? false);
1629
+ return 0;
1630
+ }
1631
+ if (!values.before?.trim() || !values.after?.trim())
1632
+ throw new InputError("diff requires --before <snapshot> and --after <snapshot>");
1633
+ const before = parseHandoff((await readJsonRecord(resolve6(cwd, values.before))).input);
1634
+ const after = parseHandoff((await readJsonRecord(resolve6(cwd, values.after))).input);
1635
+ const result2 = diffSnapshots(before, after);
1636
+ process.stdout.write(format === "json" ? `${JSON.stringify(result2, null, 2)}
1637
+ ` : diffText(result2, format === "markdown"));
1638
+ return result2.status === "unchanged" ? 0 : 1;
1639
+ }
1640
+ if (values.before !== undefined || values.after !== undefined)
1641
+ throw new InputError("--before and --after are diff-only");
1397
1642
  if (values.profile !== undefined) {
1398
1643
  identifier(values.profile, "--profile");
1399
1644
  if (command === "init")
@@ -1537,7 +1782,7 @@ ${result2.notice}
1537
1782
  for (const key of ["constraints", "handoff", "config"])
1538
1783
  if (values[key] !== undefined && !values[key].trim())
1539
1784
  throw new InputError(`--${key}: expected a non-empty path`);
1540
- const manifestRecord = await readJsonRecord(values.constraints !== undefined ? resolve5(cwd, values.constraints) : resolve5(directory, config.constraints ?? "constraints.json"));
1785
+ const manifestRecord = await readJsonRecord(values.constraints !== undefined ? resolve6(cwd, values.constraints) : resolve6(directory, config.constraints ?? "constraints.json"));
1541
1786
  const manifest = parseManifest(manifestRecord.input);
1542
1787
  checkProject(manifest, undefined, config.projectId);
1543
1788
  if (command === "explain") {
@@ -1562,10 +1807,10 @@ ${result2.notice}
1562
1807
  else {
1563
1808
  if (!values.output.trim())
1564
1809
  throw new InputError("--output: expected a non-empty path");
1565
- const path = resolve5(cwd, values.output);
1810
+ const path = resolve6(cwd, values.output);
1566
1811
  let handle;
1567
1812
  try {
1568
- handle = await open2(path, "wx", 420);
1813
+ handle = await open3(path, "wx", 420);
1569
1814
  } catch {
1570
1815
  throw new InputError(`Cannot create snapshot '${path}'; choose a new file with an existing parent directory`);
1571
1816
  }
@@ -1588,7 +1833,7 @@ ${result2.notice}
1588
1833
  }
1589
1834
  if (values.task !== undefined || values.output !== undefined)
1590
1835
  throw new InputError("--task and --output are only supported by snapshot");
1591
- const handoffRecord = await readJsonRecord(values.handoff !== undefined ? resolve5(cwd, values.handoff) : resolve5(directory, config.handoff ?? "handoff.json"));
1836
+ const handoffRecord = await readJsonRecord(values.handoff !== undefined ? resolve6(cwd, values.handoff) : resolve6(directory, config.handoff ?? "handoff.json"));
1592
1837
  const handoff = parseHandoff(handoffRecord.input);
1593
1838
  if (values["require-content"] && handoff.schemaVersion === 1)
1594
1839
  throw new InputError("Content tracking requires a schemaVersion 2, 3 or 4 handoff; review current rules and capture a snapshot before resuming");
@@ -9,8 +9,8 @@ infers rules from a summary.
9
9
  From the consuming repository root:
10
10
 
11
11
  ```sh
12
- npx handoff-check@0.6.0 init --scope staging --agent both --dry-run
13
- npx handoff-check@0.6.0 init --scope staging --agent both
12
+ npx handoff-check@0.7.0 init --scope staging --agent both --dry-run
13
+ npx handoff-check@0.7.0 init --scope staging --agent both
14
14
  ```
15
15
 
16
16
  Choose `codex`, `claude`, `both` (default), or `none`. Generated integrations:
@@ -39,8 +39,8 @@ npm pack
39
39
  From a separate consuming project, substitute the actual absolute tarball path:
40
40
 
41
41
  ```sh
42
- npx --offline --yes --package=/absolute/path/handoff-check-0.6.0.tgz handoff-check init --scope staging --agent both
43
- npx --offline --yes --package=/absolute/path/handoff-check-0.6.0.tgz handoff-check verify --format json --require-content
42
+ npx --offline --yes --package=/absolute/path/handoff-check-0.7.0.tgz handoff-check init --scope staging --agent both
43
+ npx --offline --yes --package=/absolute/path/handoff-check-0.7.0.tgz handoff-check verify --format json --require-content
44
44
  ```
45
45
 
46
46
  Bun is not required for these consumer commands. Generated agent commands use the
@@ -30,6 +30,11 @@ then calls the same verifier. Hook-config prints a mergeable snippet, never writ
30
30
  host settings. Advisory host transport success is distinct from verification.
31
31
  See decisions/0005-local-diagnostics-and-lifecycle.md.
32
32
 
33
+ Diff compares two validated saved handoffs without config, manifest, clock or
34
+ lifecycle inference. Setup authors new bound files from explicit answers using
35
+ the existing parsers and snapshot core, previews exact bytes, and creates files
36
+ exclusively only after adoption. Existing init remains stable. See ADR 0007.
37
+
33
38
  Exit codes: 0 for verified IDs, 1 for rule mismatches, 2 for invalid input or an
34
39
  unreadable input file. JSON output is intended for agent adapters and automation.
35
40
 
@@ -0,0 +1,26 @@
1
+ # ADR 0007: explicit snapshot diff and new-project guided setup
2
+
3
+ Status: accepted for 0.7.0.
4
+
5
+ Compare two validated content-aware handoffs, rather than inventing a manifest
6
+ history or reading agent transcripts. Require identical scope and project binding;
7
+ permit unbound v2/v3 interoperability and same-project v4 mode interoperability.
8
+ Compare revision/hash references with existing canonical semantics. Only two-sided
9
+ retention enables field details through the shared field comparator. Metadata and
10
+ retention-only changes are ignored. No lifecycle inference, chronology assertion,
11
+ source authentication or baseline adoption follows from diff. JSON is independently
12
+ versioned; exits 0/1/2 mean unchanged/different/invalid.
13
+
14
+ Keep old init stable. A separate terminal-only setup builds new config2/manifest3/
15
+ retained-handoff4 files with explicit identity, environment profiles and one real
16
+ user-authored global rule. It reuses strict parsers and the pure snapshot core.
17
+ The preview is exactly the approved bytes. Only affirmative yes writes; all target
18
+ conflicts are preflighted and exclusive creation prevents overwrites. No nested
19
+ paths or instruction append operations are offered, so existing init integration
20
+ planning remains separate. Writes are explicitly nontransactional with a written
21
+ path list on failure. No migrations, automatic baseline refresh, package installs,
22
+ host setting edits, skills or CI installs are implicit.
23
+
24
+ The bounded onboarding scope trades a general configuration editor for a short
25
+ reviewable first meaningful check. New owner/review metadata, source file watching,
26
+ critical-command wrappers and other host adapters remain separate future proposals.
@@ -127,6 +127,14 @@ Acceptance:
127
127
  - Reports are described as local records, not authenticated attestations or proof
128
128
  of agent compliance. Revalidate changed inputs rather than trusting old reports.
129
129
 
130
+ ## 0.7: visible changes and first meaningful check (implemented)
131
+
132
+ Implemented under [ADR 0007](decisions/0007-snapshot-diff-and-guided-setup.md):
133
+ explicit two-snapshot diff with strict scope/project matching, hash-based changes
134
+ and optional retained field details; terminal-only new-project setup with exact
135
+ preview and affirmative adoption of one real global rule. Existing init/verify
136
+ contracts stay unchanged. See [usage](snapshot-diff-and-setup.md).
137
+
130
138
  ## Later: rule maintenance, gated by pilot demand
131
139
 
132
140
  Priority: medium. Keep source inspection separate from normal verify semantics.
@@ -6,8 +6,8 @@ No service, model call or API key is needed.
6
6
  ## Understand the active set
7
7
 
8
8
  ```sh
9
- npx handoff-check@0.6.0 explain --format json
10
- npx handoff-check@0.6.0 explain --scope production --format markdown
9
+ npx handoff-check@0.7.0 explain --format json
10
+ npx handoff-check@0.7.0 explain --scope production --format markdown
11
11
  ```
12
12
 
13
13
  Explain reads the manifest but not the handoff. Every rule has an applicability
@@ -20,8 +20,8 @@ exits 0 even with zero active rules: use verify to compare a handoff.
20
20
  At a reviewed handoff creation, after upgrading all consumers to 0.4+:
21
21
 
22
22
  ```sh
23
- npx handoff-check@0.6.0 snapshot --task "Review staging migrations" --include-content --output handoff.reviewed.json
24
- npx handoff-check@0.6.0 verify --handoff handoff.reviewed.json --require-content --require-active --format markdown
23
+ npx handoff-check@0.7.0 snapshot --task "Review staging migrations" --include-content --output handoff.reviewed.json
24
+ npx handoff-check@0.7.0 verify --handoff handoff.reviewed.json --require-content --require-active --format markdown
25
25
  ```
26
26
 
27
27
  Review the new file before explicitly adopting it in config. Snapshot never
@@ -8,8 +8,8 @@ Bun, API keys, and GitHub Actions are not required. All rules below are syntheti
8
8
  ```sh
9
9
  mkdir handoff-check-demo
10
10
  cd handoff-check-demo
11
- npx handoff-check@0.6.0 init --scope staging --agent none
12
- npx handoff-check@0.6.0 verify --require-content
11
+ npx handoff-check@0.7.0 init --scope staging --agent none
12
+ npx handoff-check@0.7.0 verify --require-content
13
13
  ```
14
14
 
15
15
  The starter passes with `PASS (EMPTY)` and `0 active constraints checked`.
@@ -41,7 +41,7 @@ does not fetch it or check the contents of a referenced document.
41
41
  Before capturing a baseline, run:
42
42
 
43
43
  ```sh
44
- npx handoff-check@0.6.0 verify --require-content --require-active
44
+ npx handoff-check@0.7.0 verify --require-content --require-active
45
45
  ```
46
46
 
47
47
  Expect `MISSING MIGRATION-REVIEW`, one active constraint, and exit 1. The old
@@ -50,8 +50,8 @@ starter handoff does not include the new rule yet.
50
50
  ## Capture and verify a reviewed baseline
51
51
 
52
52
  ```sh
53
- npx handoff-check@0.6.0 snapshot --task "Review staging migration" --output handoff.reviewed.json
54
- npx handoff-check@0.6.0 verify --handoff handoff.reviewed.json --require-content --require-active
53
+ npx handoff-check@0.7.0 snapshot --task "Review staging migration" --output handoff.reviewed.json
54
+ npx handoff-check@0.7.0 verify --handoff handoff.reviewed.json --require-content --require-active
55
55
  ```
56
56
 
57
57
  Review the generated file before relying on it. The verification command should
@@ -70,7 +70,7 @@ In `constraints.json`, change the description to
70
70
  handoff unchanged, then run:
71
71
 
72
72
  ```sh
73
- npx handoff-check@0.6.0 verify --handoff handoff.reviewed.json --require-content --require-active --format json
73
+ npx handoff-check@0.7.0 verify --handoff handoff.reviewed.json --require-content --require-active --format json
74
74
  ```
75
75
 
76
76
  Expect `status: "mismatch"`, `activeConstraintCount: 1`, a `CHANGED` finding, and
package/docs/lifecycle.md CHANGED
@@ -6,8 +6,8 @@ calls, source fetches, API keys or transcript access.
6
6
  ## Diagnose the intended repository/worktree root
7
7
 
8
8
  ```sh
9
- npx handoff-check@0.6.0 doctor --format json
10
- npx handoff-check@0.6.0 doctor --host claude
9
+ npx handoff-check@0.7.0 doctor --format json
10
+ npx handoff-check@0.7.0 doctor --host claude
11
11
  ```
12
12
 
13
13
  Doctor reports resolved input paths/versions, managed integrations/pins and
@@ -22,10 +22,10 @@ host settings and effective trust are not comprehensively inspected.
22
22
 
23
23
  1. Initialize/review inputs and deliberately adopt a content-aware baseline.
24
24
  2. Install the exact package in the consuming project. For npm:
25
- `npm install --save-dev --save-exact handoff-check@0.6.0`. Installation uses
25
+ `npm install --save-dev --save-exact handoff-check@0.7.0`. Installation uses
26
26
  the registry; the hook later uses only this local package. Temporary npx caches
27
27
  and global installs do not meet that prerequisite.
28
- 3. Run `npx handoff-check@0.6.0 hook-config --host claude` and inspect the JSON.
28
+ 3. Run `npx handoff-check@0.7.0 hook-config --host claude` and inspect the JSON.
29
29
  4. In an editor, merge the returned SessionStart entries into the existing
30
30
  `.claude/settings.json` hooks object. Preserve other events, handlers,
31
31
  permissions and settings. Do not replace the whole file or blindly redirect
@@ -56,10 +56,10 @@ Author `.handoff-check.json` as config v2:
56
56
  ```
57
57
 
58
58
  ```sh
59
- npx handoff-check@0.6.0 explain --profile stage
60
- npx handoff-check@0.6.0 snapshot --profile stage --task "Review staging work" --output handoffs/staging.reviewed.json
61
- npx handoff-check@0.6.0 verify --profile stage --require-content
62
- npx handoff-check@0.6.0 doctor --profile stage
59
+ npx handoff-check@0.7.0 explain --profile stage
60
+ npx handoff-check@0.7.0 snapshot --profile stage --task "Review staging work" --output handoffs/staging.reviewed.json
61
+ npx handoff-check@0.7.0 verify --profile stage --require-content
62
+ npx handoff-check@0.7.0 doctor --profile stage
63
63
  ```
64
64
 
65
65
  These assume you deliberately adopted a baseline at the configured handoff path;
@@ -83,8 +83,8 @@ bindings produce NOT VERIFIED context; hook transport success is not a pass.
83
83
  ## Record exactly what was checked
84
84
 
85
85
  ```sh
86
- npx handoff-check@0.6.0 verify --profile stage --require-content --report --format json
87
- npx handoff-check@0.6.0 verify --profile stage --require-content --report --git-context --format markdown
86
+ npx handoff-check@0.7.0 verify --profile stage --require-content --report --format json
87
+ npx handoff-check@0.7.0 verify --profile stage --require-content --report --git-context --format markdown
88
88
  ```
89
89
 
90
90
  --report is optional and verify-only. It adds package version, requested policies,
package/docs/releasing.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Releasing
2
2
 
3
3
  The npm package name is `handoff-check`; the binary is `handoff-check` and the
4
- current version is 0.6.0. The package is already published; subsequent releases
4
+ current version is 0.7.0. The package is already published; subsequent releases
5
5
  use the configured trusted publisher and the reviewed-artifact process below.
6
6
 
7
7
  ## Release a reviewed version
@@ -19,12 +19,12 @@ use the configured trusted publisher and the reviewed-artifact process below.
19
19
  publish-run artifact and compare it before claiming artifact continuity.
20
20
  For first-publication bootstrap or an explicitly chosen manual release, use
21
21
  `npm login` and publish the reviewed tarball directly with
22
- `npm publish /absolute/path/handoff-check-0.6.0.tgz --ignore-scripts --access public`.
22
+ `npm publish /absolute/path/handoff-check-0.7.0.tgz --ignore-scripts --access public`.
23
23
  Complete interactive two-factor authentication directly with npm.
24
24
  5. Verify registry name, version, binary and integrity, then test
25
- `npx --yes handoff-check@0.6.0 --version` and fresh-project init/verify using a
25
+ `npx --yes handoff-check@0.7.0 --version` and fresh-project init/verify using a
26
26
  new package cache and the public registry, rather than the local tarball.
27
- 6. Create tag `v0.6.0` and a GitHub release on the reviewed main commit, attach the
27
+ 6. Create tag `v0.7.0` and a GitHub release on the reviewed main commit, attach the
28
28
  same tarball, and describe features, requirements and known limits.
29
29
 
30
30
  Publishing is immutable for a given npm name/version. Fix failed candidates on a
package/docs/roadmap.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Roadmap
2
2
 
3
+ Implemented in 0.7.0: explicit saved-snapshot diff and guided new-project setup.
4
+ See [snapshot diff and setup](snapshot-diff-and-setup.md).
5
+
3
6
  Implemented in 0.6.0: opt-in portable project IDs, explicit environment profiles,
4
7
  and verification metadata reports with separately requested Git context.
5
8
  See [project/profile/report guide](project-context.md).
@@ -0,0 +1,74 @@
1
+ # Snapshot comparison and guided setup
2
+
3
+ ## Start a new project interactively
4
+
5
+ With Node.js 22 or newer, run in the intended project root:
6
+
7
+ ```sh
8
+ npx handoff-check@0.7.0 setup
9
+ ```
10
+
11
+ Enter a portable project ID, comma-separated environments, a rule ID, a real rule
12
+ that applies to **all** those environments, its source reference, and a task.
13
+ Source references are stored as text and never fetched. Setup prints the exact
14
+ config v2, bound manifest v3, and retained v4 baseline for each environment. Full
15
+ rule descriptions and sources are retained: review sensitive content before
16
+ committing or sharing the files. Type `yes` only after reviewing and adopting them.
17
+ Any other answer cancels without writes. Ctrl-C/EOF before approval fails with
18
+ exit 2 and no writes. `setup --dry-run` asks the same questions and previews without
19
+ asking for adoption or writing files. Captured time is fixed once for that plan;
20
+ it is informational, not an evaluation time to reuse on resume.
21
+
22
+ Setup requires an interactive stdin/stdout terminal. It never installs packages,
23
+ agent skills, hooks, CI or host settings. Existing config, manifest or generated
24
+ handoff paths (including symlinks) cause refusal before writes. It is deliberately
25
+ new-project-only; rerunning refuses existing files rather than refreshing them.
26
+ Writes use exclusive creation and are not transactional: an I/O failure lists
27
+ already written paths. Inspect those files before retrying.
28
+
29
+ For environments `staging,production`, setup creates `.handoff-check.json`,
30
+ `constraints.json`, `handoff-staging.json`, and `handoff-production.json`. There
31
+ is no default profile. Choose the intended environment explicitly:
32
+
33
+ ```sh
34
+ npx handoff-check@0.7.0 verify --profile staging --require-content --require-active
35
+ ```
36
+
37
+ Add environment-specific rules later through deliberate review and capture;
38
+ the first global rule is authored by you, never inferred. For automation use
39
+ `init --scope <scope> --agent none` instead; it retains its existing unbound,
40
+ zero-rule starter behavior. For existing bound/profile projects, edit and review
41
+ integration files explicitly using [lifecycle setup](lifecycle.md) and the shipped
42
+ portable skill. Do not use setup as a migration or baseline-repair command.
43
+
44
+ ## Compare two saved snapshots
45
+
46
+ ```sh
47
+ npx handoff-check@0.7.0 diff --before handoff.saved.json --after handoff.next.json
48
+ npx handoff-check@0.7.0 diff --before handoff.saved.json --after handoff.next.json --format json
49
+ npx handoff-check@0.7.0 diff --before handoff.saved.json --after handoff.next.json --format markdown
50
+ ```
51
+
52
+ Both operands are strictly validated handoff files. Unbound v2/v3 can be compared
53
+ to each other; bound v4 can compare hashes/retained modes within the same project.
54
+ Legacy v1, mixed bound/unbound, different projects and different scopes fail with
55
+ exit 2. The command accepts only `--before`, `--after`, and `--format`; it reads
56
+ neither config nor manifest, uses no clock, and accesses no Git/network/agent data.
57
+
58
+ IDs present only after are ADDED; only before are REMOVED. Same-ID differences in
59
+ revision or canonical content hash are CHANGED, even without a revision bump.
60
+ Remaining IDs count as unchanged. Output sorts IDs and uses the existing fixed
61
+ field order. Hashes are always shown for changed rules. Field details appear only
62
+ when both snapshots retain content; a missing optional field is represented as
63
+ null. No text is reconstructed from hashes. Reordering, task, capture-time and
64
+ retention-mode-only differences do not count as rule changes. The operands set
65
+ direction even if their capture times are reversed.
66
+
67
+ Exit codes: **0** unchanged declarations; **1** rule differences; **2** invalid
68
+ arguments/input or unreadable files. JSON uses its own schemaVersion 1 contract
69
+ ([schema](../schemas/diff.v1.schema.json)), independent of verification results.
70
+ `beforeCount`/`afterCount` count declared references, not current active rules.
71
+ Removed does not mean revoked, expired, authorized removal, or dropped from agent
72
+ memory. This is a comparison of saved declarations. Run verify against the current
73
+ reviewed manifest before resuming work; diff is not authorization or compliance proof.
74
+ Both commands leave existing inputs intact. Never redirect diff output onto inputs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handoff-check",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A deterministic, local CLI that verifies active constraints before a coding agent resumes work.",
5
5
  "type": "module",
6
6
  "packageManager": "bun@1.2.10",
@@ -0,0 +1,121 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/Larusajs/Handoff-Check/schemas/diff.v1.schema.json",
4
+ "title": "Handoff Check snapshot diff v1",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "schemaVersion",
9
+ "status",
10
+ "scope",
11
+ "beforeCount",
12
+ "afterCount",
13
+ "unchangedCount",
14
+ "changes",
15
+ "notice"
16
+ ],
17
+ "properties": {
18
+ "schemaVersion": { "const": 1 },
19
+ "status": { "enum": ["unchanged", "different"] },
20
+ "scope": { "$ref": "#/$defs/identifier" },
21
+ "projectId": { "$ref": "#/$defs/identifier" },
22
+ "beforeCount": { "type": "integer", "minimum": 0 },
23
+ "afterCount": { "type": "integer", "minimum": 0 },
24
+ "unchangedCount": { "type": "integer", "minimum": 0 },
25
+ "notice": { "type": "string" },
26
+ "changes": {
27
+ "type": "array",
28
+ "items": {
29
+ "type": "object",
30
+ "additionalProperties": false,
31
+ "required": ["id", "kind", "before", "after"],
32
+ "properties": {
33
+ "id": { "$ref": "#/$defs/identifier" },
34
+ "kind": { "enum": ["ADDED", "REMOVED", "CHANGED"] },
35
+ "before": {
36
+ "oneOf": [{ "$ref": "#/$defs/reference" }, { "type": "null" }]
37
+ },
38
+ "after": {
39
+ "oneOf": [{ "$ref": "#/$defs/reference" }, { "type": "null" }]
40
+ },
41
+ "fields": {
42
+ "type": "array",
43
+ "items": {
44
+ "type": "object",
45
+ "additionalProperties": false,
46
+ "required": ["field", "before", "after"],
47
+ "properties": {
48
+ "field": {
49
+ "enum": [
50
+ "id",
51
+ "scope",
52
+ "description",
53
+ "source",
54
+ "expiresAt",
55
+ "revokedAt",
56
+ "replacedBy",
57
+ "supersededAt",
58
+ "revision"
59
+ ]
60
+ },
61
+ "before": { "type": ["string", "number", "null"] },
62
+ "after": { "type": ["string", "number", "null"] }
63
+ }
64
+ }
65
+ }
66
+ },
67
+ "allOf": [
68
+ {
69
+ "if": { "properties": { "kind": { "const": "ADDED" } } },
70
+ "then": {
71
+ "properties": {
72
+ "before": { "type": "null" },
73
+ "after": { "$ref": "#/$defs/reference" }
74
+ },
75
+ "not": { "required": ["fields"] }
76
+ }
77
+ },
78
+ {
79
+ "if": { "properties": { "kind": { "const": "REMOVED" } } },
80
+ "then": {
81
+ "properties": {
82
+ "before": { "$ref": "#/$defs/reference" },
83
+ "after": { "type": "null" }
84
+ },
85
+ "not": { "required": ["fields"] }
86
+ }
87
+ },
88
+ {
89
+ "if": { "properties": { "kind": { "const": "CHANGED" } } },
90
+ "then": {
91
+ "properties": {
92
+ "before": { "$ref": "#/$defs/reference" },
93
+ "after": { "$ref": "#/$defs/reference" }
94
+ }
95
+ }
96
+ }
97
+ ]
98
+ }
99
+ }
100
+ },
101
+ "$defs": {
102
+ "identifier": {
103
+ "type": "string",
104
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*(?![\\s\\S])"
105
+ },
106
+ "reference": {
107
+ "type": "object",
108
+ "additionalProperties": false,
109
+ "required": ["id", "revision", "contentHash"],
110
+ "properties": {
111
+ "id": { "$ref": "#/$defs/identifier" },
112
+ "revision": {
113
+ "type": "integer",
114
+ "minimum": 1,
115
+ "maximum": 9007199254740991
116
+ },
117
+ "contentHash": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
118
+ }
119
+ }
120
+ }
121
+ }
@@ -119,3 +119,18 @@ is requested. It wraps the result with package/policy/profile/input digests;
119
119
  --git-context separately opts into Git reads. A report is not authenticated proof
120
120
  of compliance or authorization. Never redirect reports onto input/config files.
121
121
  Doctor and the advisory Claude hook support the same explicit profile selection.
122
+
123
+ ## Saved snapshot comparison and first setup
124
+
125
+ Use `diff --before <saved.json> --after <next.json> --format json` only to compare
126
+ two explicitly selected content-aware snapshots of the same scope/project.
127
+ Exit 0 means unchanged declarations, 1 means differences, 2 means invalid inputs.
128
+ Field details require retained content on both sides. Diff does not evaluate
129
+ current applicability, inspect agent memory, or replace verify on resume. Never
130
+ capture a new baseline merely to clear a diff or assume the later operand is newer.
131
+
132
+ `setup` is an interactive human onboarding flow for new projects. It previews
133
+ project/profile files and one user-authored global rule with retained baselines,
134
+ then requires explicit adoption. It installs no skills/hooks/settings. Do not
135
+ drive it to invent policy or refresh existing baselines; use noninteractive init
136
+ for automation and deliberate review/migration for existing projects.