handoff-check 0.1.0 → 0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - Detect same-ID rule edits through revision and canonical SHA-256 references.
6
+ - Add v2 manifest/handoff schemas and CHANGED findings with expected/reported data.
7
+ - Add snapshot capture with exclusive new-file output and explicit scope/time.
8
+ - Preserve legacy v1 ID checks; add --require-content for explicit enforcement.
9
+ - Use v2 starters and content-aware agent/CI guidance with a reviewed migration path.
10
+
3
11
  ## 0.1.0
4
12
 
5
13
  - Establish English contributor and coding-agent guidance and project policies.
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.1.0.**
6
+ **Version: 0.2.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
  Once the npm package is published, run in the repository where your agent works:
19
19
 
20
20
  ```sh
21
- npx handoff-check@0.1.0 init --scope staging --agent both --dry-run
22
- npx handoff-check@0.1.0 init --scope staging --agent both
21
+ npx handoff-check@0.2.0 init --scope staging --agent both --dry-run
22
+ npx handoff-check@0.2.0 init --scope staging --agent both
23
23
  ```
24
24
 
25
25
  This creates `.handoff-check.json`, starter `constraints.json` and `handoff.json`,
@@ -27,12 +27,13 @@ installs skills for Codex and Claude Code, and appends managed instruction block
27
27
  to `AGENTS.md` and `CLAUDE.md`. Choose `--agent codex`, `claude`, or `none` to limit
28
28
  integrations. Scope is explicit; choose the intended environment.
29
29
 
30
- Starters intentionally contain zero rules. Add reviewed constraints and update
31
- the handoff's `activeConstraints` before relying on a successful verification.
30
+ Starters intentionally contain zero rules. Add reviewed constraints (v2 rules need
31
+ a positive `revision`), then capture a baseline as described below before relying
32
+ on verification. Revisions and hashes detect edits under an unchanged rule ID.
32
33
  Ask a resuming agent to use the installed skill, or run:
33
34
 
34
35
  ```sh
35
- npx handoff-check@0.1.0 verify --format json
36
+ npx handoff-check@0.2.0 verify --format json --require-content
36
37
  ```
37
38
 
38
39
  The saved config supplies paths and scope. `init --ci` also creates a pinned GitHub
@@ -42,7 +43,53 @@ Neither checks whether the agent obeys a rule's meaning.
42
43
 
43
44
  Until publication, use a local package via the [setup guide](docs/agent-integration.md).
44
45
  Node.js 22+ is required; end users do not need Bun. After publication, global
45
- installation is also available: `npm install --global handoff-check@0.1.0`.
46
+ installation is also available: `npm install --global handoff-check@0.2.0`.
47
+
48
+ ## Catch rule edits between sessions
49
+
50
+ After reviewing rules at handoff creation, capture a new baseline:
51
+
52
+ ```sh
53
+ npx handoff-check@0.2.0 snapshot --task "Resume migration review" --output handoff.next.json
54
+ npx handoff-check@0.2.0 verify --handoff handoff.next.json --require-content --format json
55
+ ```
56
+
57
+ Snapshot creates a new file exclusively. Review it before deliberately replacing
58
+ the configured handoff file with it. On resume, verify the SAVED handoff first;
59
+ never regenerate it just to clear findings.
60
+
61
+ V2 references record each rule's ID, revision and canonical SHA-256 content hash.
62
+ An edit under the same ID is detected even if revision was not incremented.
63
+ Revision changes (including decreases) are compared separately.
64
+
65
+ ```text
66
+ CHANGED C-07 Review changed constraint: ...; handoff revision 1, current revision 1; content hash differs
67
+ ```
68
+
69
+ JSON findings include expected/reported revision and hash. This detects a change;
70
+ it does not show a text diff or authenticate either file. Source reference text is
71
+ hashed, but referenced documents are not fetched or checked.
72
+
73
+ See the [v2 handoff schema](schemas/handoff.v2.schema.json),
74
+ [v2 manifest schema](schemas/constraints.v2.schema.json), and
75
+ [canonicalization contract](docs/decisions/0002-content-aware-handoffs.md).
76
+ The [changed-rule example](examples/changed-rule/handoff.json) captures the original
77
+ manifest; its current manifest edits the description without bumping revision.
78
+
79
+ ## Upgrade from 0.1
80
+
81
+ V1 handoffs remain supported in ID-only mode with unchanged v1 JSON result fields.
82
+ They cannot detect content edits. `--require-content` rejects them instead of
83
+ silently falling back. V2 handoffs work with either v1 manifests (implicit revision `1`)
84
+ or revisioned v2 manifests. Scope must match the v2 handoff's saved scope.
85
+
86
+ Review current rules, capture a new v2 baseline, and deliberately update the saved
87
+ handoff. Existing inputs are preserved by init, not silently upgraded. Review
88
+ installed skills, instruction blocks and CI commands to update their pinned
89
+ version to 0.2.0 and add `--require-content`. Init refuses to overwrite differing
90
+ integrations; compare them with the new packaged templates and update reviewed
91
+ copies explicitly. Never refresh before checking resumed work or reuse capturedAt
92
+ as the clock for real resumed work.
46
93
 
47
94
  ## Configuration and initialization
48
95
 
@@ -178,8 +225,8 @@ include global rules even when no scope-specific rules exist.
178
225
  | 1 | Rule mismatch; inspect findings |
179
226
  | 2 | Invalid arguments, invalid input, or unreadable input file |
180
227
 
181
- Findings are `MISSING`, `EXPIRED`, `REVOKED`, `SUPERSEDED`, `OUT_OF_SCOPE`, or
182
- `UNKNOWN`, ordered by ID. A reported ID receives one primary finding according to
228
+ Findings include `MISSING`, `EXPIRED`, `REVOKED`, `SUPERSEDED`, `OUT_OF_SCOPE`,
229
+ `UNKNOWN`, and (for v2) `CHANGED`, ordered by ID. A reported ID receives one primary finding according to
183
230
  the precedence in the lifecycle ADR.
184
231
 
185
232
  `--format json` writes a versioned result with `status`, `scope`, `asOf`,
package/dist/cli.js CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli.ts
4
+ import { open as open2 } from "node:fs/promises";
4
5
  import { resolve as resolve3 } from "node:path";
5
6
  import { parseArgs } from "node:util";
6
7
  // package.json
7
8
  var package_default = {
8
9
  name: "handoff-check",
9
- version: "0.1.0",
10
+ version: "0.2.0",
10
11
  description: "A deterministic, local CLI that verifies active constraints before a coding agent resumes work.",
11
12
  type: "module",
12
13
  packageManager: "bun@1.2.10",
@@ -114,8 +115,13 @@ function timestamp(value, path) {
114
115
  return millis;
115
116
  }
116
117
  function version(value, path) {
117
- if (value.schemaVersion !== 1)
118
- fail(`${path}.schemaVersion: expected 1`);
118
+ if (value.schemaVersion !== 1 && value.schemaVersion !== 2)
119
+ fail(`${path}.schemaVersion: expected 1 or 2`);
120
+ }
121
+ function revision(value, path) {
122
+ if (!Number.isSafeInteger(value) || value < 1)
123
+ fail(`${path}: expected a positive safe integer`);
124
+ return value;
119
125
  }
120
126
  function unique(values, path) {
121
127
  const seen = new Set;
@@ -142,7 +148,8 @@ function parseManifest(input) {
142
148
  "expiresAt",
143
149
  "revokedAt",
144
150
  "replacedBy",
145
- "supersededAt"
151
+ "supersededAt",
152
+ ...root.schemaVersion === 2 ? ["revision"] : []
146
153
  ], path);
147
154
  const parsed = {
148
155
  id: identifier(rule.id, `${path}.id`),
@@ -150,6 +157,8 @@ function parseManifest(input) {
150
157
  description: string(rule.description, `${path}.description`),
151
158
  source: string(rule.source, `${path}.source`)
152
159
  };
160
+ if (root.schemaVersion === 2)
161
+ parsed.revision = revision(rule.revision, `${path}.revision`);
153
162
  for (const field of ["expiresAt", "revokedAt", "supersededAt"]) {
154
163
  if (Object.hasOwn(rule, field)) {
155
164
  timestamp(rule[field], `${path}.${field}`);
@@ -188,15 +197,45 @@ function parseManifest(input) {
188
197
  for (const id of path)
189
198
  completed.add(id);
190
199
  }
191
- return { schemaVersion: 1, constraints };
200
+ return { schemaVersion: root.schemaVersion, constraints };
192
201
  }
193
202
  function parseHandoff(input) {
194
203
  const root = object(input, "handoff");
195
- keys(root, ["schemaVersion", "task", "activeConstraints"], "handoff");
196
204
  version(root, "handoff");
205
+ keys(root, [
206
+ "schemaVersion",
207
+ "task",
208
+ "activeConstraints",
209
+ ...root.schemaVersion === 2 ? ["scope", "capturedAt"] : []
210
+ ], "handoff");
197
211
  const task = string(root.task, "handoff.task");
198
212
  if (!Array.isArray(root.activeConstraints))
199
213
  fail("handoff.activeConstraints: expected an array");
214
+ if (root.schemaVersion === 2) {
215
+ const scope = identifier(root.scope, "handoff.scope");
216
+ timestamp(root.capturedAt, "handoff.capturedAt");
217
+ const activeConstraints2 = root.activeConstraints.map((entry, index) => {
218
+ const path = `handoff.activeConstraints[${index}]`;
219
+ const ref = object(entry, path);
220
+ keys(ref, ["id", "revision", "contentHash"], path);
221
+ const contentHash = string(ref.contentHash, `${path}.contentHash`);
222
+ if (!/^sha256:[a-f0-9]{64}(?![\s\S])/.test(contentHash))
223
+ fail(`${path}.contentHash: expected sha256 followed by 64 lowercase hex digits`);
224
+ return {
225
+ id: identifier(ref.id, `${path}.id`),
226
+ revision: revision(ref.revision, `${path}.revision`),
227
+ contentHash
228
+ };
229
+ });
230
+ unique(activeConstraints2.map((ref) => ref.id), "handoff.activeConstraints");
231
+ return {
232
+ schemaVersion: 2,
233
+ task,
234
+ scope,
235
+ capturedAt: root.capturedAt,
236
+ activeConstraints: activeConstraints2
237
+ };
238
+ }
200
239
  const activeConstraints = root.activeConstraints.map((id, index) => identifier(id, `handoff.activeConstraints[${index}]`));
201
240
  unique(activeConstraints, "handoff.activeConstraints");
202
241
  return { schemaVersion: 1, task, activeConstraints };
@@ -268,7 +307,7 @@ Before resuming a handoff or continuing after a context reset, use the handoff-c
268
307
  skill and run the configured verifier from this repository root:
269
308
 
270
309
  \`\`\`sh
271
- npx --yes handoff-check@${package_default.version} verify --format json
310
+ npx --yes handoff-check@${package_default.version} verify --format json --require-content
272
311
  \`\`\`
273
312
 
274
313
  Use .handoff-check.json for paths and scope. If no scope is configured, request the
@@ -277,6 +316,8 @@ Resolve exit 1 mismatches or exit 2 input errors before resuming the affected ta
277
316
  Do not change the manifest merely to obtain a pass. Empty rules verify no policy;
278
317
  author and review real project constraints before relying on this check. A pass
279
318
  checks declared IDs only and does not grant authorization or interpret summaries.
319
+ Capture a snapshot only at handoff creation or after explicitly reviewing changes;
320
+ never refresh the baseline before verifying it when resuming work.
280
321
  ${end}
281
322
  `;
282
323
  async function inspect(root, path) {
@@ -331,15 +372,17 @@ async function initialize(root, options) {
331
372
  [
332
373
  "constraints",
333
374
  "constraints.json",
334
- { schemaVersion: 1, constraints: [] },
375
+ { schemaVersion: 2, constraints: [] },
335
376
  parseManifest
336
377
  ],
337
378
  [
338
379
  "handoff",
339
380
  "handoff.json",
340
381
  {
341
- schemaVersion: 1,
382
+ schemaVersion: 2,
342
383
  task: "Describe the task being handed off",
384
+ scope,
385
+ capturedAt: new Date().toISOString(),
343
386
  activeConstraints: []
344
387
  },
345
388
  parseHandoff
@@ -405,7 +448,7 @@ jobs:
405
448
  - uses: actions/setup-node@v4
406
449
  with:
407
450
  node-version: 22
408
- - run: npx --yes handoff-check@${package_default.version} verify --format json
451
+ - run: npx --yes handoff-check@${package_default.version} verify --format json --require-content
409
452
  `;
410
453
  const old = await inspect(root, path);
411
454
  if (old !== undefined && old !== content)
@@ -457,7 +500,28 @@ jobs:
457
500
  action: file.action,
458
501
  ...file.action === "preserve" ? {} : { content: file.content }
459
502
  })),
460
- notice: "Starter files may contain zero rules. Add reviewed project constraints and update the handoff before relying on verification."
503
+ notice: "Starter files may contain zero rules. Add reviewed project constraints, then capture a v2 snapshot. Existing v1 handoffs are preserved but cannot satisfy --require-content until explicitly migrated. Never refresh a baseline before verifying it on resume."
504
+ };
505
+ }
506
+
507
+ // src/content.ts
508
+ import { createHash } from "node:crypto";
509
+ function reference(rule) {
510
+ const instant = (value) => value === undefined ? null : new Date(value).toISOString();
511
+ const content = JSON.stringify({
512
+ id: rule.id,
513
+ scope: rule.scope,
514
+ description: rule.description,
515
+ source: rule.source,
516
+ expiresAt: instant(rule.expiresAt),
517
+ revokedAt: instant(rule.revokedAt),
518
+ replacedBy: rule.replacedBy ?? null,
519
+ supersededAt: instant(rule.supersededAt)
520
+ });
521
+ return {
522
+ id: rule.id,
523
+ revision: rule.revision ?? 1,
524
+ contentHash: `sha256:${createHash("sha256").update(content, "utf8").digest("hex")}`
461
525
  };
462
526
  }
463
527
 
@@ -478,10 +542,13 @@ function inactive(rule, scope, time) {
478
542
  }
479
543
  function verify(manifest, handoff, scope, asOf) {
480
544
  identifier(scope, "scope");
545
+ if (handoff.schemaVersion === 2 && handoff.scope !== scope)
546
+ throw new InputError(`Handoff scope '${handoff.scope}' does not match selected scope '${scope}'`);
481
547
  const time = timestamp(asOf, "asOf");
482
548
  const byId = new Map(manifest.constraints.map((rule) => [rule.id, rule]));
483
549
  const expectedConstraints = manifest.constraints.filter((rule) => inactive(rule, scope, time) === undefined).map((rule) => rule.id).sort(compare);
484
- const reportedConstraints = [...handoff.activeConstraints].sort(compare);
550
+ const refs = new Map(handoff.schemaVersion === 2 ? handoff.activeConstraints.map((ref) => [ref.id, ref]) : []);
551
+ const reportedConstraints = (handoff.schemaVersion === 1 ? [...handoff.activeConstraints] : handoff.activeConstraints.map((ref) => ref.id)).sort(compare);
485
552
  const reported = new Set(reportedConstraints);
486
553
  const findings = [];
487
554
  for (const id of expectedConstraints) {
@@ -502,11 +569,30 @@ function verify(manifest, handoff, scope, asOf) {
502
569
  id,
503
570
  message: `Remove ${code.toLowerCase().replaceAll("_", "-")} constraint${detail}${rule ? `: ${rule.description}` : ""}`
504
571
  });
572
+ } else if (rule && handoff.schemaVersion === 2) {
573
+ const current = reference(rule);
574
+ const previous = refs.get(id);
575
+ if (previous && (current.revision !== previous.revision || current.contentHash !== previous.contentHash)) {
576
+ findings.push({
577
+ code: "CHANGED",
578
+ id,
579
+ message: `Review changed constraint: ${rule.description}; handoff revision ${previous.revision}, current revision ${current.revision}${current.contentHash !== previous.contentHash ? "; content hash differs" : ""}`,
580
+ expected: {
581
+ revision: current.revision,
582
+ contentHash: current.contentHash
583
+ },
584
+ reported: {
585
+ revision: previous.revision,
586
+ contentHash: previous.contentHash
587
+ }
588
+ });
589
+ }
505
590
  }
506
591
  }
507
592
  findings.sort((a, b) => compare(a.id, b.id) || compare(a.code, b.code));
508
593
  return {
509
- schemaVersion: 1,
594
+ schemaVersion: handoff.schemaVersion,
595
+ ...handoff.schemaVersion === 2 ? { tracking: "content" } : {},
510
596
  status: findings.length ? "mismatch" : "verified",
511
597
  scope,
512
598
  asOf: new Date(time).toISOString(),
@@ -515,12 +601,26 @@ function verify(manifest, handoff, scope, asOf) {
515
601
  findings
516
602
  };
517
603
  }
604
+ function snapshot(manifest, task, scope, asOf) {
605
+ if (!task.trim())
606
+ throw new InputError("--task: expected a non-empty task");
607
+ const result = verify(manifest, { schemaVersion: 1, task, activeConstraints: [] }, scope, asOf);
608
+ const byId = new Map(manifest.constraints.map((rule) => [rule.id, rule]));
609
+ return {
610
+ schemaVersion: 2,
611
+ task,
612
+ scope,
613
+ capturedAt: result.asOf,
614
+ activeConstraints: result.expectedConstraints.map((id) => reference(byId.get(id)))
615
+ };
616
+ }
518
617
 
519
618
  // src/cli.ts
520
619
  var help = `Handoff Check
521
620
 
522
621
  Usage: handoff-check verify --scope <scope> [options]
523
622
  handoff-check init --scope <scope> [--agent both] [--dry-run] [--ci]
623
+ handoff-check snapshot --task <task> [--output <new-file>] [options]
524
624
 
525
625
  Options:
526
626
  --constraints <path> Manifest file (default: constraints.json)
@@ -528,6 +628,9 @@ Options:
528
628
  --scope <scope> Selected scope, including global constraints
529
629
  --config <path> Project config (default: cwd/.handoff-check.json)
530
630
  --as-of <UTC time> Fixed evaluation time (default: current time)
631
+ --require-content verify: require a v2 content-aware handoff
632
+ --task <task> snapshot: task description (required)
633
+ --output <path> snapshot: create a new baseline file, never overwrite
531
634
  --format text|json Output format (default: text)
532
635
  --agent <agent> init: codex, claude, both (default), or none
533
636
  --dry-run init: preview files and instruction changes without writes
@@ -564,7 +667,10 @@ async function main() {
564
667
  version: { type: "boolean" },
565
668
  agent: { type: "string" },
566
669
  "dry-run": { type: "boolean" },
567
- ci: { type: "boolean" }
670
+ ci: { type: "boolean" },
671
+ "require-content": { type: "boolean" },
672
+ task: { type: "string" },
673
+ output: { type: "string" }
568
674
  }
569
675
  });
570
676
  format = values.format;
@@ -579,13 +685,21 @@ async function main() {
579
685
  `);
580
686
  return 0;
581
687
  }
582
- if (positionals.length !== 1 || !["verify", "init"].includes(positionals[0] ?? ""))
583
- throw new InputError("Expected command: verify or init (use --help for usage)");
688
+ if (positionals.length !== 1 || !["verify", "init", "snapshot"].includes(positionals[0] ?? ""))
689
+ throw new InputError("Expected command: verify, snapshot or init (use --help for usage)");
584
690
  const cwd = process.cwd();
585
691
  if (positionals[0] === "init") {
586
- for (const key of ["constraints", "handoff", "config", "as-of"])
692
+ for (const key of [
693
+ "constraints",
694
+ "handoff",
695
+ "config",
696
+ "as-of",
697
+ "require-content",
698
+ "task",
699
+ "output"
700
+ ])
587
701
  if (values[key] !== undefined)
588
- throw new InputError(`--${key} is only supported by verify`);
702
+ throw new InputError(`--${key} is not supported by init`);
589
703
  const result2 = await initialize(cwd, {
590
704
  ...values.scope === undefined ? {} : { scope: values.scope },
591
705
  agent: values.agent ?? "both",
@@ -625,7 +739,48 @@ ${result2.notice}
625
739
  if (values[key] !== undefined && !values[key].trim())
626
740
  throw new InputError(`--${key}: expected a non-empty path`);
627
741
  const manifest = parseManifest(await readJson(values.constraints !== undefined ? resolve3(cwd, values.constraints) : resolve3(directory, config.constraints ?? "constraints.json")));
742
+ if (positionals[0] === "snapshot") {
743
+ if (values.handoff !== undefined || values["require-content"] !== undefined)
744
+ throw new InputError("--handoff and --require-content are only supported by verify");
745
+ if (values.task === undefined)
746
+ throw new InputError("snapshot requires --task");
747
+ const captured = snapshot(manifest, values.task, scope, asOf);
748
+ const content = `${JSON.stringify(captured, null, 2)}
749
+ `;
750
+ if (values.output === undefined)
751
+ process.stdout.write(content);
752
+ else {
753
+ if (!values.output.trim())
754
+ throw new InputError("--output: expected a non-empty path");
755
+ const path = resolve3(cwd, values.output);
756
+ let handle;
757
+ try {
758
+ handle = await open2(path, "wx", 420);
759
+ } catch {
760
+ throw new InputError(`Cannot create snapshot '${path}'; choose a new file with an existing parent directory`);
761
+ }
762
+ try {
763
+ await handle.writeFile(content, "utf8");
764
+ } finally {
765
+ await handle.close();
766
+ }
767
+ const saved = {
768
+ schemaVersion: 1,
769
+ status: "captured",
770
+ path,
771
+ constraints: captured.activeConstraints.length
772
+ };
773
+ process.stdout.write(format === "json" ? `${JSON.stringify(saved)}
774
+ ` : `CAPTURED ${terminalText(path)}
775
+ `);
776
+ }
777
+ return 0;
778
+ }
779
+ if (values.task !== undefined || values.output !== undefined)
780
+ throw new InputError("--task and --output are only supported by snapshot");
628
781
  const handoff = parseHandoff(await readJson(values.handoff !== undefined ? resolve3(cwd, values.handoff) : resolve3(directory, config.handoff ?? "handoff.json")));
782
+ if (values["require-content"] && handoff.schemaVersion !== 2)
783
+ throw new InputError("Content tracking requires a schemaVersion 2 handoff; review current rules and capture a snapshot before resuming");
629
784
  const result = verify(manifest, handoff, scope, asOf);
630
785
  if (format === "json") {
631
786
  process.stdout.write(`${JSON.stringify(result, null, 2)}
@@ -635,7 +790,7 @@ ${result2.notice}
635
790
  process.stdout.write(`${finding.code.padEnd(12)} ${finding.id} ${terminalText(finding.message)}
636
791
  `);
637
792
  }
638
- process.stdout.write(`${result.status === "verified" ? "PASS" : "FAIL"} ${result.findings.length} findings | scope ${scope} | as of ${result.asOf}
793
+ process.stdout.write(`${result.status === "verified" ? "PASS" : "FAIL"} ${result.findings.length} findings | scope ${scope} | as of ${result.asOf}${handoff.schemaVersion === 1 ? " | IDs only; content changes not checked" : " | content tracked"}
639
794
  `);
640
795
  }
641
796
  return result.status === "verified" ? 0 : 1;
@@ -9,8 +9,8 @@ infers rules from a summary.
9
9
  After the npm release is published, from the consuming repository root:
10
10
 
11
11
  ```sh
12
- npx handoff-check@0.1.0 init --scope staging --agent both --dry-run
13
- npx handoff-check@0.1.0 init --scope staging --agent both
12
+ npx handoff-check@0.2.0 init --scope staging --agent both --dry-run
13
+ npx handoff-check@0.2.0 init --scope staging --agent both
14
14
  ```
15
15
 
16
16
  Choose `codex`, `claude`, `both` (default), or `none`. Generated integrations:
@@ -38,8 +38,8 @@ npm pack
38
38
  From a separate consuming project, substitute the actual absolute tarball path:
39
39
 
40
40
  ```sh
41
- npx --offline --yes --package=/absolute/path/handoff-check-0.1.0.tgz handoff-check init --scope staging --agent both
42
- npx --offline --yes --package=/absolute/path/handoff-check-0.1.0.tgz handoff-check verify --format json
41
+ npx --offline --yes --package=/absolute/path/handoff-check-0.2.0.tgz handoff-check init --scope staging --agent both
42
+ npx --offline --yes --package=/absolute/path/handoff-check-0.2.0.tgz handoff-check verify --format json --require-content
43
43
  ```
44
44
 
45
45
  Bun is not required for these consumer commands. Generated agent commands use the
@@ -58,6 +58,18 @@ The agent checks IDs and reads active rule descriptions. Exit 1 means mismatch;
58
58
  exit 2 means invalid inputs/arguments. Resolve either before resuming affected work.
59
59
  A pass does not authorize an action or interpret the task summary.
60
60
 
61
+ In 0.2, skills and generated instructions require content-aware v2 handoffs.
62
+ At handoff creation, review current rules and run the configured CLI's
63
+ `snapshot --task "Resume the task" --output handoff.next.json`. Review that file
64
+ before explicitly promoting it to the configured handoff. On resume, verify the
65
+ saved baseline first; do not regenerate it to hide a CHANGED finding. Snapshot
66
+ records revisions/hashes, not old text, and capturedAt is not the evaluation clock.
67
+
68
+ Existing v1 inputs are preserved. Review/capture a v2 handoff and explicitly update
69
+ old skill/managed-block/CI pins before relying on content tracking. Existing v1
70
+ manifests use implicit revision 1; v2 manifests make revisions explicit.
71
+ See [upgrade instructions](../README.md#upgrade-from-01).
72
+
61
73
  Skill discovery depends on the host agent. Skills/instructions are guidance, not
62
74
  guaranteed hooks. `init --ci` adds `.github/workflows/handoff-check.yml` pinned to
63
75
  the installed version and using saved config. This checks committed IDs on push/PR,
@@ -0,0 +1,82 @@
1
+ # ADR 0002: Content-aware handoffs
2
+
3
+ Status: accepted for 0.2.0.
4
+
5
+ ## Formats and compatibility
6
+
7
+ Manifest v1 and handoff v1 keep their existing schemas. A v1 handoff still checks
8
+ IDs only against either manifest format. Its JSON result stays schemaVersion 1
9
+ with the existing fields. Text output explicitly identifies ID-only checking.
10
+
11
+ Manifest v2 adds required `revision` to each constraint: a positive safe integer
12
+ (1 through 9007199254740991). Handoff v2 records `task`, `scope`, `capturedAt`, and
13
+ `activeConstraints` objects containing `id`, `revision`, and `contentHash`.
14
+ IDs remain unique. Unknown fields, malformed hashes, and invalid revisions fail
15
+ as invalid input. Both input formats are versioned independently.
16
+
17
+ A v2 handoff works with either manifest. Manifest v1 rules have implicit revision
18
+ 1, so an existing manifest can adopt content tracking without being rewritten.
19
+ A revisioned v2 manifest works with v1 handoffs in ID-only mode. `--require-content`
20
+ rejects a v1 handoff with exit 2 instead of silently falling back. New skills and
21
+ generated CI use this option; old integrations must be upgraded explicitly.
22
+
23
+ ## Canonical content algorithm v1
24
+
25
+ Serialize the following object, in exactly this field order, using ECMAScript
26
+ `JSON.stringify` without indentation, then encode as UTF-8 and compute SHA-256:
27
+
28
+ 1. `id`
29
+ 2. `scope`
30
+ 3. `description`
31
+ 4. `source`
32
+ 5. `expiresAt`
33
+ 6. `revokedAt`
34
+ 7. `replacedBy`
35
+ 8. `supersededAt`
36
+
37
+ Required strings are preserved exactly, with no trimming or Unicode normalization.
38
+ Absent optional fields are represented as JSON null in this canonical object;
39
+ explicit null in input remains invalid. Timestamps normalize through
40
+ `Date.toISOString()` to UTC milliseconds. Revision is excluded from the hash and
41
+ compared separately. The stored syntax is `sha256:` plus 64 lowercase hex digits.
42
+ Reordering JSON properties, formatting JSON, or using equivalent UTC fractional
43
+ representations does not change the hash. Changing any hashed string does.
44
+
45
+ This algorithm is part of the v2 contract. Any incompatible canonicalization
46
+ change requires a new contract version, not silent rehashing. A golden fixture
47
+ independently verifies the hash contract in tests.
48
+
49
+ Only literal source-reference text is hashed. Referenced documents are never
50
+ fetched or hashed. These hashes are change detectors, not signatures or proof of
51
+ authorization; someone who controls both files can replace both values.
52
+
53
+ ## Capture and verification
54
+
55
+ `snapshot --task <text>` reads the manifest and captures the selected/global rules
56
+ that apply at the explicit or once-captured current clock. It does not read the
57
+ existing handoff, rewrite the manifest, or infer constraints from task prose.
58
+ Default stdout is a complete v2 JSON handoff. `--output <new-path>` creates a new
59
+ file exclusively and refuses existing paths; write failures return exit 2 and may
60
+ leave a partial newly created file, which must be inspected before retrying.
61
+
62
+ `capturedAt` is normalized metadata, not the evaluation clock, an activation rule,
63
+ or authenticated history. Verification uses current time unless --as-of is
64
+ explicit. A fixed evaluation time may predate capturedAt; that describes the
65
+ supplied files at the chosen instant, not a reconstructed historical Git version.
66
+ Selected scope must equal the v2 handoff scope or verification returns exit 2.
67
+
68
+ For an active reported ID, a revision OR content-hash difference produces one
69
+ CHANGED finding. Both differences are reported together with expected/reported
70
+ revision and hash. Missing rules remain MISSING. Unknown, out-of-scope, revoked,
71
+ superseded, and expired primary findings retain lifecycle precedence over CHANGED.
72
+ Adding a future lifecycle timestamp is CHANGED immediately while the rule is
73
+ active; once the timestamp takes effect its lifecycle finding wins.
74
+
75
+ V2 results use schemaVersion 2 and `tracking: "content"`; ID lists remain sorted,
76
+ and findings remain ordered by ID then code. Revision decreases are differences
77
+ too; monotonic revision history is not verified. Old text is not stored, so the
78
+ tool does not show a textual diff.
79
+
80
+ Capture at handoff creation or after an explicit review of changed rules. Never
81
+ recapture a baseline automatically before checking a resumed task: that would hide
82
+ the changes the check is intended to find. Verification and CI remain read-only.
package/docs/releasing.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Releasing
2
2
 
3
3
  The npm package name is `handoff-check`; the binary is `handoff-check` and the
4
- initial version is 0.1.0. A registry lookup is not proof that a name can be claimed.
4
+ current version is 0.2.0. A registry lookup is not proof that a name can be claimed.
5
5
  Confirm ownership during the authenticated first publication.
6
6
 
7
- ## First release
7
+ ## Release a reviewed version
8
8
 
9
9
  1. Merge reviewed changes into main and wait for all Linux/macOS/Windows checks,
10
10
  including packed offline npx onboarding, to pass on the merged commit.
@@ -13,14 +13,18 @@ Confirm ownership during the authenticated first publication.
13
13
  built tarball as `npm-package`.
14
14
  3. Download that tarball, inspect its file list and checksum, and test it in a
15
15
  separate consumer directory using offline npx with an absolute tarball path.
16
- 4. Authenticate using `npm login` in the maintainer's own terminal. Never commit or
17
- send credentials. Publish the reviewed artifact with
18
- `npm publish /absolute/path/handoff-check-0.1.0.tgz --ignore-scripts --access public`.
19
- Complete any npm two-factor authentication directly with npm.
16
+ 4. Prefer trusted publishing: dispatch the same main commit/version with
17
+ `publish: true` and the reviewed tarball's SHA256 in the `sha256` input. The
18
+ workflow refuses publication if the rebuilt artifact differs. Download the
19
+ publish-run artifact and compare it before claiming artifact continuity.
20
+ For first-publication bootstrap or an explicitly chosen manual release, use
21
+ `npm login` and publish the reviewed tarball directly with
22
+ `npm publish /absolute/path/handoff-check-0.2.0.tgz --ignore-scripts --access public`.
23
+ Complete interactive two-factor authentication directly with npm.
20
24
  5. Verify registry name, version, binary and integrity, then test
21
- `npx --yes handoff-check@0.1.0 --version` and fresh-project init/verify using a
25
+ `npx --yes handoff-check@0.2.0 --version` and fresh-project init/verify using a
22
26
  new package cache and the public registry, rather than the local tarball.
23
- 6. Create tag `v0.1.0` and a GitHub release on the reviewed main commit, attach the
27
+ 6. Create tag `v0.2.0` and a GitHub release on the reviewed main commit, attach the
24
28
  same tarball, and describe features, requirements and known limits.
25
29
 
26
30
  Publishing is immutable for a given npm name/version. Fix failed candidates on a
package/docs/roadmap.md CHANGED
@@ -30,7 +30,12 @@
30
30
 
31
31
  ## Following releases
32
32
 
33
+ Implemented in 0.2.0: revisioned v2 manifests, content-aware handoff snapshots,
34
+ canonical SHA-256 comparison, CHANGED findings, explicit --require-content,
35
+ legacy compatibility and reviewed migration guidance. No automatic baseline refresh.
36
+
33
37
  - Incorporate feedback from real repositories before expanding the contract.
38
+ - Consider optional old-content storage for textual diffs in a later version.
34
39
  - Consider host-specific enforcement hooks separately from the portable skill;
35
40
  neither skill discovery nor agent instructions guarantee execution.
36
41
 
@@ -0,0 +1,12 @@
1
+ {
2
+ "schemaVersion": 2,
3
+ "constraints": [
4
+ {
5
+ "id": "C-07",
6
+ "revision": 1,
7
+ "scope": "staging",
8
+ "description": "Require two reviewers before applying migrations",
9
+ "source": "decision:review"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "schemaVersion": 2,
3
+ "task": "Resume migration review",
4
+ "scope": "staging",
5
+ "capturedAt": "2026-11-24T10:00:00.000Z",
6
+ "activeConstraints": [
7
+ {
8
+ "id": "C-07",
9
+ "revision": 1,
10
+ "contentHash": "sha256:2e1217c01957cd82f81d2bdc47397e00d7c56399606f38545384bdab07ee1b3d"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "schemaVersion": 2,
3
+ "constraints": [
4
+ {
5
+ "id": "C-07",
6
+ "revision": 1,
7
+ "scope": "staging",
8
+ "description": "Review migrations",
9
+ "source": "decision:review"
10
+ }
11
+ ]
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handoff-check",
3
- "version": "0.1.0",
3
+ "version": "0.2.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,75 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Handoff Check revisioned constraint manifest v2",
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "required": ["schemaVersion", "constraints"],
7
+ "properties": {
8
+ "schemaVersion": {
9
+ "const": 2
10
+ },
11
+ "constraints": {
12
+ "type": "array",
13
+ "items": {
14
+ "$ref": "#/$defs/constraint"
15
+ },
16
+ "description": "IDs must be unique. Replacement references must exist, share scope, and form an acyclic graph; these checks are enforced by the CLI."
17
+ }
18
+ },
19
+ "$defs": {
20
+ "identifier": {
21
+ "type": "string",
22
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*(?![\\s\\S])"
23
+ },
24
+ "text": {
25
+ "type": "string",
26
+ "pattern": "\\S"
27
+ },
28
+ "timestamp": {
29
+ "type": "string",
30
+ "format": "date-time",
31
+ "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,3})?Z$",
32
+ "description": "UTC only; real calendar dates required. The CLI also rejects leap seconds and rollover dates."
33
+ },
34
+ "constraint": {
35
+ "type": "object",
36
+ "additionalProperties": false,
37
+ "required": ["id", "scope", "description", "source", "revision"],
38
+ "dependentRequired": {
39
+ "replacedBy": ["supersededAt"],
40
+ "supersededAt": ["replacedBy"]
41
+ },
42
+ "properties": {
43
+ "id": {
44
+ "$ref": "#/$defs/identifier"
45
+ },
46
+ "scope": {
47
+ "$ref": "#/$defs/identifier"
48
+ },
49
+ "description": {
50
+ "$ref": "#/$defs/text"
51
+ },
52
+ "source": {
53
+ "$ref": "#/$defs/text"
54
+ },
55
+ "expiresAt": {
56
+ "$ref": "#/$defs/timestamp"
57
+ },
58
+ "revokedAt": {
59
+ "$ref": "#/$defs/timestamp"
60
+ },
61
+ "replacedBy": {
62
+ "$ref": "#/$defs/identifier"
63
+ },
64
+ "supersededAt": {
65
+ "$ref": "#/$defs/timestamp"
66
+ },
67
+ "revision": {
68
+ "type": "integer",
69
+ "minimum": 1,
70
+ "maximum": 9007199254740991
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Handoff Check content-aware handoff v2",
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "required": [
7
+ "schemaVersion",
8
+ "task",
9
+ "scope",
10
+ "capturedAt",
11
+ "activeConstraints"
12
+ ],
13
+ "properties": {
14
+ "schemaVersion": { "const": 2 },
15
+ "task": { "type": "string", "pattern": "\\S" },
16
+ "scope": { "$ref": "#/$defs/id" },
17
+ "capturedAt": {
18
+ "type": "string",
19
+ "format": "date-time",
20
+ "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,3})?Z$"
21
+ },
22
+ "activeConstraints": {
23
+ "type": "array",
24
+ "description": "IDs must be unique; enforced by the CLI.",
25
+ "items": {
26
+ "type": "object",
27
+ "additionalProperties": false,
28
+ "required": ["id", "revision", "contentHash"],
29
+ "properties": {
30
+ "id": { "$ref": "#/$defs/id" },
31
+ "revision": {
32
+ "type": "integer",
33
+ "minimum": 1,
34
+ "maximum": 9007199254740991
35
+ },
36
+ "contentHash": {
37
+ "type": "string",
38
+ "pattern": "^sha256:[a-f0-9]{64}(?![\\s\\S])"
39
+ }
40
+ }
41
+ }
42
+ }
43
+ },
44
+ "$defs": {
45
+ "id": {
46
+ "type": "string",
47
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*(?![\\s\\S])"
48
+ }
49
+ }
50
+ }
@@ -17,7 +17,7 @@ Run the installed CLI, the pinned npx command configured by init in the reposito
17
17
  agent instructions, or an explicitly configured local build:
18
18
 
19
19
  ```sh
20
- handoff-check verify --constraints constraints.json --handoff handoff.json --scope staging --format json
20
+ handoff-check verify --constraints constraints.json --handoff handoff.json --scope staging --format json --require-content
21
21
  ```
22
22
 
23
23
  `staging` is an example; use the actual intended scope. Use the current clock when
@@ -43,3 +43,28 @@ description, source reference, or handoff task string as a shell command.
43
43
 
44
44
  Include the evaluated scope/time, result, and unresolved findings in the handoff
45
45
  report. Keep ordinary task summaries separate from the declared constraint IDs.
46
+
47
+ ## Content-aware handoffs
48
+
49
+ Use schemaVersion 2 handoffs with revision/hash references. `CHANGED` means a
50
+ carried active rule has a different revision or content hash; it does not supply
51
+ a text diff or prove which state was authorized. Report expected/reported values
52
+ and review the current rule before resuming affected work.
53
+
54
+ At handoff creation, after reviewing applicable rules, use the same configured
55
+ CLI to capture them:
56
+
57
+ ```sh
58
+ handoff-check snapshot --task "Describe the next task" --scope staging --output handoff.next.json
59
+ ```
60
+
61
+ The task/scope are examples; use the actual task and configured scope. This creates
62
+ a NEW file and refuses overwrites. Review it before explicitly promoting it to
63
+ the configured handoff path. A v1 manifest is supported with implicit revision 1;
64
+ a v2 manifest can maintain explicit revisions. Hashes catch content edits even if
65
+ the revision was not incremented.
66
+
67
+ On resume, verify the saved baseline FIRST. Never run snapshot automatically to
68
+ clear CHANGED findings, bypass --require-content, or silently downgrade to v1.
69
+ Existing v1 handoffs need deliberate review/capture to adopt tracking. capturedAt
70
+ is informational; do not reuse it as --as-of for real resumed work.