handoff-check 0.7.0 → 0.9.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/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 open3 } from "node:fs/promises";
5
- import { resolve as resolve6 } from "node:path";
4
+ import { open as open5 } from "node:fs/promises";
5
+ import { resolve as resolve8 } 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.7.0",
10
+ version: "0.9.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",
@@ -68,7 +68,8 @@ var package_default = {
68
68
 
69
69
  // src/config.ts
70
70
  import { createHash as createHash2 } from "node:crypto";
71
- import { readFile } from "node:fs/promises";
71
+ import { constants } from "node:fs";
72
+ import { open, readFile } from "node:fs/promises";
72
73
  import { dirname, resolve } from "node:path";
73
74
 
74
75
  // src/content.ts
@@ -315,10 +316,22 @@ function selectProfile(config, profile) {
315
316
  function digest(bytes) {
316
317
  return `sha256:${createHash2("sha256").update(bytes).digest("hex")}`;
317
318
  }
318
- async function readJsonRecord(path) {
319
+ async function readBytes(path, regularOnly) {
320
+ if (!regularOnly)
321
+ return readFile(path);
322
+ const handle = await open(path, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));
323
+ try {
324
+ if (!(await handle.stat()).isFile())
325
+ throw new InputError(`Expected a regular input file: '${path}'`);
326
+ return await handle.readFile();
327
+ } finally {
328
+ await handle.close();
329
+ }
330
+ }
331
+ async function readJsonRecord(path, regularOnly = false) {
319
332
  let bytes;
320
333
  try {
321
- bytes = await readFile(path);
334
+ bytes = await readBytes(path, regularOnly);
322
335
  } catch {
323
336
  throw new InputError(`Cannot read input file '${path}'`);
324
337
  }
@@ -330,8 +343,8 @@ async function readJsonRecord(path) {
330
343
  }
331
344
  return { input, path, sha256: digest(bytes) };
332
345
  }
333
- async function readJson(path) {
334
- return (await readJsonRecord(path)).input;
346
+ async function readJson(path, regularOnly = false) {
347
+ return (await readJsonRecord(path, regularOnly)).input;
335
348
  }
336
349
  function parseConfig(input) {
337
350
  if (!input || typeof input !== "object" || Array.isArray(input))
@@ -384,11 +397,11 @@ function parseConfig(input) {
384
397
  }
385
398
  return config;
386
399
  }
387
- async function loadConfig(cwd, explicit) {
400
+ async function loadConfig(cwd, explicit, regularOnly = false) {
388
401
  const path = resolve(cwd, explicit ?? ".handoff-check.json");
389
402
  let input;
390
403
  try {
391
- input = await readFile(path);
404
+ input = await readBytes(path, regularOnly);
392
405
  } catch (error) {
393
406
  if (explicit === undefined && error.code === "ENOENT")
394
407
  return { config: { schemaVersion: 1 }, directory: cwd };
@@ -1117,8 +1130,8 @@ async function doctor(cwd, options) {
1117
1130
  }
1118
1131
 
1119
1132
  // src/initialize.ts
1120
- import { constants } from "node:fs";
1121
- import { lstat as lstat2, mkdir, open, readFile as readFile3 } from "node:fs/promises";
1133
+ import { constants as constants2 } from "node:fs";
1134
+ import { lstat as lstat2, mkdir, open as open2, readFile as readFile3 } from "node:fs/promises";
1122
1135
  import { dirname as dirname3, isAbsolute as isAbsolute2, relative as relative2, resolve as resolve4, sep as sep2 } from "node:path";
1123
1136
  var begin = "<!-- handoff-check:begin -->";
1124
1137
  var end = "<!-- handoff-check:end -->";
@@ -1297,8 +1310,8 @@ jobs:
1297
1310
  throw new InputError("Target changed after planning");
1298
1311
  await mkdir(dirname3(file.path), { recursive: true });
1299
1312
  await inspect(root, file.path);
1300
- const flags = file.action === "create" ? constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL : constants.O_WRONLY | constants.O_APPEND | (constants.O_NOFOLLOW ?? 0);
1301
- const handle = await open(file.path, flags, 420);
1313
+ const flags = file.action === "create" ? constants2.O_WRONLY | constants2.O_CREAT | constants2.O_EXCL : constants2.O_WRONLY | constants2.O_APPEND | (constants2.O_NOFOLLOW ?? 0);
1314
+ const handle = await open2(file.path, flags, 420);
1302
1315
  try {
1303
1316
  await handle.writeFile(file.content, "utf8");
1304
1317
  } finally {
@@ -1376,9 +1389,343 @@ function reportMarkdown(report) {
1376
1389
  `);
1377
1390
  }
1378
1391
 
1379
- // src/setup.ts
1380
- import { lstat as lstat3, open as open2, readdir } from "node:fs/promises";
1392
+ // src/review-cli.ts
1393
+ import { open as open3 } from "node:fs/promises";
1381
1394
  import { resolve as resolve5 } from "node:path";
1395
+
1396
+ // src/review.ts
1397
+ function object2(input, allowed, path) {
1398
+ if (!input || typeof input !== "object" || Array.isArray(input))
1399
+ throw new InputError(`${path}: expected an object`);
1400
+ const value = input;
1401
+ for (const key of Object.keys(value).sort())
1402
+ if (!allowed.includes(key))
1403
+ throw new InputError(`${path}: unknown field '${key}'`);
1404
+ return value;
1405
+ }
1406
+ function text(input, path) {
1407
+ if (typeof input !== "string" || !input.trim())
1408
+ throw new InputError(`${path}: expected a non-empty string`);
1409
+ return input;
1410
+ }
1411
+ function parseReviewRegistry(input) {
1412
+ const root = object2(input, ["schemaVersion", "projectId", "rules"], "review registry");
1413
+ if (root.schemaVersion !== 1)
1414
+ throw new InputError("review registry.schemaVersion: expected 1");
1415
+ const projectId = Object.hasOwn(root, "projectId") ? identifier(root.projectId, "review registry.projectId") : undefined;
1416
+ if (!Array.isArray(root.rules))
1417
+ throw new InputError("review registry.rules: expected an array");
1418
+ const seen = new Set;
1419
+ const rules = root.rules.map((input2, index) => {
1420
+ const path = `review registry.rules[${index}]`;
1421
+ const entry = object2(input2, ["id", "revision", "contentHash", "owner", "reviewedAt", "reviewBy"], path);
1422
+ const id = identifier(entry.id, `${path}.id`);
1423
+ if (seen.has(id))
1424
+ throw new InputError(`${path}: duplicate ID '${id}'`);
1425
+ seen.add(id);
1426
+ if (!Number.isSafeInteger(entry.revision) || entry.revision < 1)
1427
+ throw new InputError(`${path}.revision: expected a positive safe integer`);
1428
+ const contentHash = text(entry.contentHash, `${path}.contentHash`);
1429
+ if (!/^sha256:[a-f0-9]{64}(?![\s\S])/.test(contentHash))
1430
+ throw new InputError(`${path}.contentHash: expected canonical sha256 reference`);
1431
+ const reviewedAt = timestamp(entry.reviewedAt, `${path}.reviewedAt`);
1432
+ const reviewBy = timestamp(entry.reviewBy, `${path}.reviewBy`);
1433
+ if (reviewBy <= reviewedAt)
1434
+ throw new InputError(`${path}: reviewBy must be later than reviewedAt`);
1435
+ return {
1436
+ id,
1437
+ revision: entry.revision,
1438
+ contentHash,
1439
+ owner: text(entry.owner, `${path}.owner`),
1440
+ reviewedAt: new Date(reviewedAt).toISOString(),
1441
+ reviewBy: new Date(reviewBy).toISOString()
1442
+ };
1443
+ });
1444
+ return {
1445
+ schemaVersion: 1,
1446
+ ...projectId === undefined ? {} : { projectId },
1447
+ rules
1448
+ };
1449
+ }
1450
+ function recordReview(manifest, scope, asOf, owner, reviewBy) {
1451
+ text(owner, "--owner");
1452
+ const explanation = explain(manifest, scope, asOf);
1453
+ const active = new Set(explanation.rules.filter((r) => r.decision === "ACTIVE").map((r) => r.id));
1454
+ if (!active.size)
1455
+ throw new InputError("review-record requires at least one active constraint; no review record created");
1456
+ return parseReviewRegistry({
1457
+ schemaVersion: 1,
1458
+ ...manifest.projectId === undefined ? {} : { projectId: manifest.projectId },
1459
+ rules: manifest.constraints.filter((r) => active.has(r.id)).sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0).map((rule) => ({
1460
+ ...reference(rule),
1461
+ owner,
1462
+ reviewedAt: explanation.asOf,
1463
+ reviewBy
1464
+ }))
1465
+ });
1466
+ }
1467
+ function reviewRules(manifest, registry, scope, asOf) {
1468
+ const projectId = checkProject(manifest);
1469
+ if (projectId !== registry.projectId)
1470
+ throw new InputError("Review registry and manifest must have matching project binding (both bound or both unbound)");
1471
+ const explanation = explain(manifest, scope, asOf);
1472
+ const time = timestamp(explanation.asOf, "asOf");
1473
+ const active = new Set(explanation.rules.filter((r) => r.decision === "ACTIVE").map((r) => r.id));
1474
+ const known = new Set(manifest.constraints.map((r) => r.id));
1475
+ const entries = new Map(registry.rules.map((r) => [r.id, r]));
1476
+ const rules = manifest.constraints.filter((r) => active.has(r.id)).sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0).map((rule) => {
1477
+ const expected = reference(rule);
1478
+ const entry = entries.get(rule.id);
1479
+ let status;
1480
+ if (!entry)
1481
+ status = "MISSING_REVIEW";
1482
+ else if (entry.revision !== expected.revision || entry.contentHash !== expected.contentHash)
1483
+ status = "STALE_REVIEW";
1484
+ else if (timestamp(entry.reviewedAt, "reviewedAt") > time)
1485
+ status = "FUTURE_REVIEW";
1486
+ else if (timestamp(entry.reviewBy, "reviewBy") <= time)
1487
+ status = "OVERDUE_REVIEW";
1488
+ else
1489
+ status = "CURRENT";
1490
+ return {
1491
+ id: rule.id,
1492
+ status,
1493
+ expected,
1494
+ ...entry ? {
1495
+ recorded: {
1496
+ id: entry.id,
1497
+ revision: entry.revision,
1498
+ contentHash: entry.contentHash
1499
+ },
1500
+ owner: entry.owner,
1501
+ reviewedAt: entry.reviewedAt,
1502
+ reviewBy: entry.reviewBy
1503
+ } : {}
1504
+ };
1505
+ });
1506
+ const findings = [];
1507
+ if (!active.size)
1508
+ findings.push({ code: "NO_ACTIVE_CONSTRAINTS" });
1509
+ for (const rule of rules)
1510
+ if (rule.status !== "CURRENT")
1511
+ findings.push({ code: rule.status, id: rule.id });
1512
+ for (const entry of registry.rules)
1513
+ if (!known.has(entry.id))
1514
+ findings.push({ code: "UNKNOWN_RULE", id: entry.id });
1515
+ findings.sort((a, b) => (a.id ?? "") < (b.id ?? "") ? -1 : (a.id ?? "") > (b.id ?? "") ? 1 : 0);
1516
+ return {
1517
+ schemaVersion: 1,
1518
+ kind: "rule-review",
1519
+ status: findings.length ? "attention" : "current",
1520
+ ...projectId === undefined ? {} : { projectId },
1521
+ scope,
1522
+ asOf: explanation.asOf,
1523
+ activeConstraintCount: active.size,
1524
+ currentReviewCount: rules.filter((r) => r.status === "CURRENT").length,
1525
+ registryEntryCount: registry.rules.length,
1526
+ ignoredEntryCount: registry.rules.filter((r) => known.has(r.id) && !active.has(r.id)).length,
1527
+ rules,
1528
+ findings,
1529
+ notice: "Local maintenance record, not authenticated review or permission. Review deadlines never deactivate constraints or change verify/run results. Known inactive rules are ignored; orphan registry IDs require attention. Record only after reviewing the current rules; never refresh merely to clear findings."
1530
+ };
1531
+ }
1532
+ function reviewText(result, markdown) {
1533
+ const safe = markdown ? markdownText : terminalText;
1534
+ const lines = [
1535
+ markdown ? `# Handoff Check rule review
1536
+ ` : "RULE REVIEW",
1537
+ `${result.status.toUpperCase()} | ${result.currentReviewCount}/${result.activeConstraintCount} active rules have current review | scope ${safe(result.scope)} | as of ${safe(result.asOf)}${result.projectId ? ` | project ${safe(result.projectId)}` : ""}`,
1538
+ `${result.registryEntryCount} registry entries | ${result.ignoredEntryCount} known inactive entries ignored`
1539
+ ];
1540
+ for (const rule of result.rules) {
1541
+ lines.push(`${rule.status} ${safe(rule.id)}${rule.owner === undefined ? "" : ` | owner ${safe(rule.owner)} | reviewed ${safe(rule.reviewedAt ?? "")} | review by ${safe(rule.reviewBy ?? "")}`}`);
1542
+ if (rule.status === "MISSING_REVIEW" || rule.status === "STALE_REVIEW")
1543
+ lines.push(` Current reference: revision ${rule.expected.revision} ${rule.expected.contentHash}`);
1544
+ }
1545
+ for (const finding of result.findings)
1546
+ if (!finding.id || finding.code === "UNKNOWN_RULE")
1547
+ lines.push(`${finding.code}${finding.id ? ` ${safe(finding.id)}` : ""}`);
1548
+ lines.push(safe(result.notice));
1549
+ return `${lines.join(markdown ? `
1550
+
1551
+ ` : `
1552
+ `)}
1553
+ `;
1554
+ }
1555
+
1556
+ // src/review-cli.ts
1557
+ async function reviewCommand(cwd, command, options) {
1558
+ if (options.profile !== undefined && [options.scope, options.constraints].some((v) => v !== undefined))
1559
+ throw new InputError("--profile cannot be combined with --scope or --constraints");
1560
+ for (const key of ["config", "constraints", "registry", "output"])
1561
+ if (options[key] !== undefined && !options[key].trim())
1562
+ throw new InputError(`--${key}: expected a non-empty path`);
1563
+ if (command === "review" && options.registry === undefined)
1564
+ throw new InputError("review requires --registry <review-file>; no review file is discovered implicitly");
1565
+ if (command === "review-record" && (options.owner === undefined || options["review-by"] === undefined))
1566
+ throw new InputError("review-record requires --owner and --review-by after reviewing the current rules");
1567
+ if (command === "review-record" && options.format === "markdown")
1568
+ throw new InputError("review-record supports text or json acknowledgement; its record is always JSON");
1569
+ const loaded = await loadConfig(cwd, options.config, true);
1570
+ const config = selectProfile(loaded.config, options.profile);
1571
+ const scope = identifier(options.scope ?? config.scope, "--scope (or config.scope)");
1572
+ const manifest = parseManifest(await readJson(options.constraints !== undefined ? resolve5(cwd, options.constraints) : resolve5(loaded.directory, config.constraints ?? "constraints.json"), true));
1573
+ checkProject(manifest, undefined, config.projectId);
1574
+ if (command === "review") {
1575
+ const registry = parseReviewRegistry(await readJson(resolve5(cwd, options.registry), true));
1576
+ const asOf2 = options["as-of"] ?? new Date().toISOString();
1577
+ timestamp(asOf2, "--as-of");
1578
+ const result = reviewRules(manifest, registry, scope, asOf2);
1579
+ process.stdout.write(options.format === "json" ? `${JSON.stringify(result, null, 2)}
1580
+ ` : reviewText(result, options.format === "markdown"));
1581
+ return result.status === "current" ? 0 : 1;
1582
+ }
1583
+ const asOf = options["as-of"] ?? new Date().toISOString();
1584
+ timestamp(asOf, "--as-of");
1585
+ const record = recordReview(manifest, scope, asOf, options.owner, options["review-by"]);
1586
+ const content = `${JSON.stringify(record, null, 2)}
1587
+ `;
1588
+ if (options.output === undefined)
1589
+ process.stdout.write(content);
1590
+ else {
1591
+ const path = resolve5(cwd, options.output);
1592
+ let handle;
1593
+ try {
1594
+ handle = await open3(path, "wx", 420);
1595
+ } catch {
1596
+ throw new InputError(`Cannot create review record '${path}'; choose a new file with an existing parent directory`);
1597
+ }
1598
+ try {
1599
+ await handle.writeFile(content, "utf8");
1600
+ } catch {
1601
+ throw new InputError(`Cannot finish review record '${path}'; the new file may be partial. Inspect it before retrying.`);
1602
+ } finally {
1603
+ await handle.close();
1604
+ }
1605
+ process.stdout.write(options.format === "json" ? `${JSON.stringify({ schemaVersion: 1, status: "recorded", path, entries: record.rules.length })}
1606
+ ` : `RECORDED ${terminalText(path)} | ${record.rules.length} reviewed rule references
1607
+ `);
1608
+ }
1609
+ return 0;
1610
+ }
1611
+
1612
+ // src/run.ts
1613
+ import { spawn } from "node:child_process";
1614
+ import { constants as constants3 } from "node:os";
1615
+ import { resolve as resolve6 } from "node:path";
1616
+ async function runVerified(cwd, options, argv) {
1617
+ const executable = argv[0];
1618
+ if (!executable?.trim())
1619
+ throw new InputError("run requires -- <executable> [arguments...]");
1620
+ if (options.profile !== undefined && [options.scope, options.constraints, options.handoff].some((v) => v !== undefined))
1621
+ throw new InputError("--profile cannot be combined with --scope, --constraints or --handoff");
1622
+ for (const key of ["config", "constraints", "handoff"])
1623
+ if (options[key] !== undefined && !options[key].trim())
1624
+ throw new InputError(`--${key}: expected a non-empty path`);
1625
+ let child;
1626
+ const signalCode = (signal) => 128 + (constants3.signals[signal] ?? 1);
1627
+ const forward = (signal) => {
1628
+ if (!child) {
1629
+ process.stderr.write(`RUN CANCELLED before command launch
1630
+ `);
1631
+ process.exit(signalCode(signal));
1632
+ }
1633
+ if (child && child.exitCode === null && child.signalCode === null) {
1634
+ process.stderr.write(`RUN SIGNAL ${signal}: forwarding to direct child
1635
+ `);
1636
+ try {
1637
+ child.kill(signal);
1638
+ } catch {
1639
+ process.stderr.write(`RUN SIGNAL ${signal}: direct-child forwarding failed
1640
+ `);
1641
+ }
1642
+ }
1643
+ };
1644
+ const interrupt = () => forward("SIGINT");
1645
+ const terminate = () => forward("SIGTERM");
1646
+ process.on("SIGINT", interrupt);
1647
+ process.on("SIGTERM", terminate);
1648
+ const deadline = setTimeout(() => {
1649
+ process.stderr.write(`RUN INVALID: preflight exceeded 5 seconds; command not started
1650
+ `);
1651
+ process.exit(2);
1652
+ }, 5000);
1653
+ process.stderr.write(`RUN CHECKING: current-clock content/nonempty preflight
1654
+ `);
1655
+ try {
1656
+ const loaded = await loadConfig(cwd, options.config, true);
1657
+ const config = selectProfile(loaded.config, options.profile);
1658
+ const scope = identifier(options.scope ?? config.scope, "--scope (or config.scope)");
1659
+ const manifest = parseManifest(await readJson(options.constraints !== undefined ? resolve6(cwd, options.constraints) : resolve6(loaded.directory, config.constraints ?? "constraints.json"), true));
1660
+ const handoff = parseHandoff(await readJson(options.handoff !== undefined ? resolve6(cwd, options.handoff) : resolve6(loaded.directory, config.handoff ?? "handoff.json"), true));
1661
+ if (handoff.schemaVersion === 1)
1662
+ throw new InputError("run requires a content-aware v2/v3/v4 handoff; review and capture a baseline explicitly");
1663
+ const result = verify(manifest, handoff, scope, new Date().toISOString(), {
1664
+ requireActive: true,
1665
+ ...config.projectId === undefined ? {} : { projectId: config.projectId }
1666
+ });
1667
+ clearTimeout(deadline);
1668
+ if (result.status !== "verified") {
1669
+ for (const finding of result.findings)
1670
+ process.stderr.write(`RUN BLOCKED ${finding.code}${finding.id ? ` ${finding.id}` : ""}
1671
+ `);
1672
+ process.stderr.write(`RUN BLOCKED: command not started | ${result.expectedConstraints.length} active constraints | scope ${scope} | as of ${result.asOf}${result.projectId ? ` | project ${result.projectId}` : ""}${options.profile ? ` | profile ${options.profile}` : ""}
1673
+ `);
1674
+ return 1;
1675
+ }
1676
+ process.stderr.write(`RUN VERIFIED: ${result.expectedConstraints.length} active constraints | content tracked | scope ${scope} | as of ${result.asOf}${result.projectId ? ` | project ${result.projectId}` : ""}${options.profile ? ` | profile ${options.profile}` : ""}
1677
+ `);
1678
+ return await new Promise((done) => {
1679
+ let launchFailed = false;
1680
+ let started = false;
1681
+ try {
1682
+ child = spawn(executable, argv.slice(1), {
1683
+ cwd,
1684
+ env: process.env,
1685
+ shell: false,
1686
+ stdio: "inherit"
1687
+ });
1688
+ } catch {
1689
+ process.stderr.write(`RUN LAUNCH ERROR: command could not be started
1690
+ `);
1691
+ done(2);
1692
+ return;
1693
+ }
1694
+ child.on("error", (error) => {
1695
+ if (started) {
1696
+ process.stderr.write(`RUN PROCESS ERROR: ${terminalText(error.code ?? "UNKNOWN")} | waiting for direct child
1697
+ `);
1698
+ return;
1699
+ }
1700
+ launchFailed = true;
1701
+ process.stderr.write(`RUN LAUNCH ERROR: ${terminalText(error.code ?? "UNKNOWN")} | command could not be started
1702
+ `);
1703
+ done(2);
1704
+ });
1705
+ child.once("spawn", () => {
1706
+ started = true;
1707
+ process.stderr.write(`RUN STARTED: verification passed; waiting for command
1708
+ `);
1709
+ });
1710
+ child.once("close", (code, signal) => {
1711
+ if (launchFailed)
1712
+ return;
1713
+ const exitCode = code ?? (signal ? signalCode(signal) : 2);
1714
+ process.stderr.write(`RUN EXIT: ${exitCode}${signal ? ` | signal ${signal}` : ""}
1715
+ `);
1716
+ done(exitCode);
1717
+ });
1718
+ });
1719
+ } finally {
1720
+ clearTimeout(deadline);
1721
+ process.removeListener("SIGINT", interrupt);
1722
+ process.removeListener("SIGTERM", terminate);
1723
+ }
1724
+ }
1725
+
1726
+ // src/setup.ts
1727
+ import { lstat as lstat3, open as open4, readdir } from "node:fs/promises";
1728
+ import { resolve as resolve7 } from "node:path";
1382
1729
  import { createInterface } from "node:readline/promises";
1383
1730
  function setupPlan(answers, asOf) {
1384
1731
  const projectId = identifier(answers.projectId, "Project ID");
@@ -1425,7 +1772,7 @@ async function assertSetupTargets(root, files) {
1425
1772
  if (existing.has(file.path.normalize("NFC").toLowerCase()))
1426
1773
  throw new InputError(`Setup requires new files; target already exists: '${file.path}'.`);
1427
1774
  try {
1428
- await lstat3(resolve5(root, file.path));
1775
+ await lstat3(resolve7(root, file.path));
1429
1776
  } catch (error) {
1430
1777
  if (error.code === "ENOENT")
1431
1778
  continue;
@@ -1439,7 +1786,7 @@ async function writeSetup(root, files) {
1439
1786
  const written = [];
1440
1787
  for (const file of files) {
1441
1788
  try {
1442
- const handle = await open2(resolve5(root, file.path), "wx", 420);
1789
+ const handle = await open4(resolve7(root, file.path), "wx", 420);
1443
1790
  try {
1444
1791
  await handle.writeFile(file.content, "utf8");
1445
1792
  } finally {
@@ -1521,6 +1868,9 @@ Edit and review constraints before relying on them. Never refresh a baseline bef
1521
1868
  var help = `Handoff Check
1522
1869
 
1523
1870
  Usage: handoff-check verify --scope <scope> [options]
1871
+ handoff-check review --registry <review-file> [--profile <name>] [--format text|json|markdown]
1872
+ handoff-check review-record --owner <owner> --review-by <UTC time> [--output <new-file>] [options]
1873
+ handoff-check run [--profile <name> | --scope <scope>] [--config <path>] -- <executable> [args...]
1524
1874
  handoff-check diff --before <snapshot> --after <snapshot> [--format text|json|markdown]
1525
1875
  handoff-check setup [--dry-run]
1526
1876
  handoff-check init --scope <scope> [--agent both] [--dry-run] [--ci]
@@ -1531,6 +1881,9 @@ Usage: handoff-check verify --scope <scope> [options]
1531
1881
  handoff-check hook --host claude --config <absolute-path> [--require-active]
1532
1882
 
1533
1883
  Options:
1884
+ --registry <path> review: explicit review registry (resolved from cwd)
1885
+ --owner <owner> review-record: owner of explicitly reviewed active rules
1886
+ --review-by <UTC> review-record: review deadline, later than capture time
1534
1887
  --before <path> diff: saved snapshot before the change
1535
1888
  --after <path> diff: saved snapshot after the change
1536
1889
  --constraints <path> Manifest file (default: constraints.json)
@@ -1544,9 +1897,9 @@ Options:
1544
1897
  --require-content verify: require a v2/v3/v4 content-aware handoff
1545
1898
  --require-active verify: fail if empty; hook/hook-config: opt-in nonempty policy
1546
1899
  --task <task> snapshot: task description (required)
1547
- --output <path> snapshot: create a new baseline file, never overwrite
1900
+ --output <path> snapshot/review-record: create a new file, never overwrite
1548
1901
  --include-content snapshot: retain old rule text in unbound v3/bound v4 (opt-in)
1549
- --format text|json|markdown Markdown is verify/explain/diff-only (default: text)
1902
+ --format text|json|markdown Markdown is verify/explain/diff/review-only (default: text)
1550
1903
  --agent <agent> init: codex, claude, both (default), or none
1551
1904
  --host <host> doctor: integration target; hook/hook-config: claude
1552
1905
  --dry-run init/setup: preview proposed files without writes
@@ -1555,14 +1908,21 @@ Options:
1555
1908
  --help Show this help
1556
1909
 
1557
1910
  Exit codes: verify 0 verified / 1 mismatch; diff 0 unchanged / 1 different; doctor 0 healthy / 1 attention.
1911
+ Review: 0 current maintenance / 1 attention (including zero active); never changes verify/run policy.
1912
+ Run: mandatory content/nonempty/current-clock preflight; 1 blocked / 2 invalid or launch error.
1913
+ After launch run returns the child exit code (or 128 + signal); diagnostics use stderr.
1558
1914
  Hook 0 means advisory response delivered (may report FAIL/INVALID), not verified.
1559
1915
  Invalid invocation/input returns 2; explain/init/snapshot/hook-config succeed with 0.
1560
1916
  `;
1561
1917
  async function main() {
1562
1918
  let format = "text";
1563
1919
  try {
1920
+ const rawArgs = process.argv.slice(2);
1921
+ const runCommand = rawArgs[0] === "run";
1922
+ const separator = rawArgs.indexOf("--");
1923
+ const wrapperArgs = runCommand && separator >= 0 ? rawArgs.slice(0, separator) : rawArgs;
1564
1924
  const { values, positionals } = parseArgs({
1565
- args: process.argv.slice(2),
1925
+ args: wrapperArgs,
1566
1926
  allowPositionals: true,
1567
1927
  strict: true,
1568
1928
  options: {
@@ -1587,7 +1947,10 @@ async function main() {
1587
1947
  task: { type: "string" },
1588
1948
  output: { type: "string" },
1589
1949
  before: { type: "string" },
1590
- after: { type: "string" }
1950
+ after: { type: "string" },
1951
+ registry: { type: "string" },
1952
+ owner: { type: "string" },
1953
+ "review-by": { type: "string" }
1591
1954
  }
1592
1955
  });
1593
1956
  format = values.format;
@@ -1611,11 +1974,43 @@ async function main() {
1611
1974
  "hook",
1612
1975
  "hook-config",
1613
1976
  "diff",
1614
- "setup"
1977
+ "setup",
1978
+ "run",
1979
+ "review",
1980
+ "review-record"
1615
1981
  ].includes(positionals[0] ?? ""))
1616
- throw new InputError("Expected command: verify, snapshot, explain, init, setup, diff, doctor, hook or hook-config (use --help for usage)");
1982
+ throw new InputError("Expected command: verify, snapshot, explain, init, setup, diff, run, review, review-record, doctor, hook or hook-config (use --help for usage)");
1617
1983
  const cwd = process.cwd();
1618
1984
  const command = positionals[0];
1985
+ if (command === "review" || command === "review-record") {
1986
+ const allowed = [
1987
+ "config",
1988
+ "profile",
1989
+ "scope",
1990
+ "constraints",
1991
+ "as-of",
1992
+ "format",
1993
+ ...command === "review" ? ["registry"] : ["owner", "review-by", "output"]
1994
+ ];
1995
+ for (const key of Object.keys(values))
1996
+ if (!allowed.includes(key))
1997
+ throw new InputError(`--${key} is not supported by ${command}`);
1998
+ return await reviewCommand(cwd, command, values);
1999
+ }
2000
+ if (values.registry !== undefined || values.owner !== undefined || values["review-by"] !== undefined)
2001
+ throw new InputError("--registry, --owner and --review-by are review/review-record-only");
2002
+ if (command === "run") {
2003
+ if (!runCommand || separator < 0)
2004
+ throw new InputError("Use run as the first argument and include -- <executable> [arguments...]");
2005
+ const allowed = ["config", "profile", "scope", "constraints", "handoff"];
2006
+ for (const key of Object.keys(values)) {
2007
+ if (key === "format" && !wrapperArgs.some((arg) => arg === "--format" || arg.startsWith("--format=")))
2008
+ continue;
2009
+ if (!allowed.includes(key))
2010
+ throw new InputError(`--${key} is not supported by run; content/nonempty checks and the current clock are mandatory`);
2011
+ }
2012
+ return await runVerified(cwd, values, rawArgs.slice(separator + 1));
2013
+ }
1619
2014
  if (command === "diff" || command === "setup") {
1620
2015
  const allowed = command === "diff" ? ["before", "after", "format"] : ["dry-run"];
1621
2016
  for (const key of Object.keys(values)) {
@@ -1630,8 +2025,8 @@ async function main() {
1630
2025
  }
1631
2026
  if (!values.before?.trim() || !values.after?.trim())
1632
2027
  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);
2028
+ const before = parseHandoff((await readJsonRecord(resolve8(cwd, values.before))).input);
2029
+ const after = parseHandoff((await readJsonRecord(resolve8(cwd, values.after))).input);
1635
2030
  const result2 = diffSnapshots(before, after);
1636
2031
  process.stdout.write(format === "json" ? `${JSON.stringify(result2, null, 2)}
1637
2032
  ` : diffText(result2, format === "markdown"));
@@ -1782,7 +2177,7 @@ ${result2.notice}
1782
2177
  for (const key of ["constraints", "handoff", "config"])
1783
2178
  if (values[key] !== undefined && !values[key].trim())
1784
2179
  throw new InputError(`--${key}: expected a non-empty path`);
1785
- const manifestRecord = await readJsonRecord(values.constraints !== undefined ? resolve6(cwd, values.constraints) : resolve6(directory, config.constraints ?? "constraints.json"));
2180
+ const manifestRecord = await readJsonRecord(values.constraints !== undefined ? resolve8(cwd, values.constraints) : resolve8(directory, config.constraints ?? "constraints.json"));
1786
2181
  const manifest = parseManifest(manifestRecord.input);
1787
2182
  checkProject(manifest, undefined, config.projectId);
1788
2183
  if (command === "explain") {
@@ -1807,10 +2202,10 @@ ${result2.notice}
1807
2202
  else {
1808
2203
  if (!values.output.trim())
1809
2204
  throw new InputError("--output: expected a non-empty path");
1810
- const path = resolve6(cwd, values.output);
2205
+ const path = resolve8(cwd, values.output);
1811
2206
  let handle;
1812
2207
  try {
1813
- handle = await open3(path, "wx", 420);
2208
+ handle = await open5(path, "wx", 420);
1814
2209
  } catch {
1815
2210
  throw new InputError(`Cannot create snapshot '${path}'; choose a new file with an existing parent directory`);
1816
2211
  }
@@ -1833,7 +2228,7 @@ ${result2.notice}
1833
2228
  }
1834
2229
  if (values.task !== undefined || values.output !== undefined)
1835
2230
  throw new InputError("--task and --output are only supported by snapshot");
1836
- const handoffRecord = await readJsonRecord(values.handoff !== undefined ? resolve6(cwd, values.handoff) : resolve6(directory, config.handoff ?? "handoff.json"));
2231
+ const handoffRecord = await readJsonRecord(values.handoff !== undefined ? resolve8(cwd, values.handoff) : resolve8(directory, config.handoff ?? "handoff.json"));
1837
2232
  const handoff = parseHandoff(handoffRecord.input);
1838
2233
  if (values["require-content"] && handoff.schemaVersion === 1)
1839
2234
  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.7.0 init --scope staging --agent both --dry-run
13
- npx handoff-check@0.7.0 init --scope staging --agent both
12
+ npx handoff-check@0.9.0 init --scope staging --agent both --dry-run
13
+ npx handoff-check@0.9.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.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
42
+ npx --offline --yes --package=/absolute/path/handoff-check-0.9.0.tgz handoff-check init --scope staging --agent both
43
+ npx --offline --yes --package=/absolute/path/handoff-check-0.9.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
@@ -35,6 +35,19 @@ lifecycle inference. Setup authors new bound files from explicit answers using
35
35
  the existing parsers and snapshot core, previews exact bytes, and creates files
36
36
  exclusively only after adoption. Existing init remains stable. See ADR 0007.
37
37
 
38
+ Run is an opt-in CLI process adapter: it reads regular local inputs through the
39
+ same selectors/parsers, requires current-clock content/nonempty verification,
40
+ then spawns explicit argv with shell false only on success. Child stdio/cwd/env
41
+ are inherited and exit codes preserved. It never expands the pure verifier into
42
+ an execution engine. See ADR 0008 for cancellation, time-of-check/time-of-use and
43
+ platform limits; the supplied program's side effects are outside verification.
44
+
45
+ Review maintenance is independent of verification. A strict separate registry
46
+ binds ownership/deadlines to existing rule references; review reuses explain's
47
+ active selection and never modifies applicability. Review-record explicitly
48
+ captures selected active references without merging or refreshing handoffs.
49
+ Neither verify/run nor lifecycle/doctor load the registry. See ADR 0009.
50
+
38
51
  Exit codes: 0 for verified IDs, 1 for rule mismatches, 2 for invalid input or an
39
52
  unreadable input file. JSON output is intended for agent adapters and automation.
40
53