@hexagen-monaco/sync 0.13.0 → 0.14.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.
Files changed (34) hide show
  1. package/README.md +316 -16
  2. package/dist/cli.js +2039 -769
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/contract/evaluate.d.ts +54 -0
  5. package/dist/commands/contract/evaluate.d.ts.map +1 -1
  6. package/dist/commands/contract/growth.d.ts +22 -0
  7. package/dist/commands/contract/growth.d.ts.map +1 -0
  8. package/dist/commands/contract/index.d.ts +11 -3
  9. package/dist/commands/contract/index.d.ts.map +1 -1
  10. package/dist/commands/evidence/check.d.ts +2 -0
  11. package/dist/commands/evidence/check.d.ts.map +1 -1
  12. package/dist/commands/evidence/index.d.ts.map +1 -1
  13. package/dist/commands/evidence/pack.d.ts.map +1 -1
  14. package/dist/commands/evidence/verify.d.ts +83 -0
  15. package/dist/commands/evidence/verify.d.ts.map +1 -0
  16. package/dist/commands/grant/issue.d.ts.map +1 -1
  17. package/dist/commands/grant/list.d.ts +72 -0
  18. package/dist/commands/grant/list.d.ts.map +1 -0
  19. package/dist/commands/grant/verify.d.ts +7 -1
  20. package/dist/commands/grant/verify.d.ts.map +1 -1
  21. package/dist/commands/report/exec-git.d.ts.map +1 -1
  22. package/dist/commands/shared/brownfield-sidecar.d.ts +30 -0
  23. package/dist/commands/shared/brownfield-sidecar.d.ts.map +1 -1
  24. package/dist/commands/shared/grant-enumerator.d.ts +32 -0
  25. package/dist/commands/shared/grant-enumerator.d.ts.map +1 -0
  26. package/dist/commands/workbook/export.d.ts.map +1 -1
  27. package/dist/generators/root-file-templates.d.ts +2 -2
  28. package/dist/generators/root-file-templates.d.ts.map +1 -1
  29. package/dist/generators/root-files.d.ts.map +1 -1
  30. package/dist/index.js +22 -7
  31. package/dist/index.js.map +1 -1
  32. package/dist/types/manifest/monorepo.d.ts +1 -0
  33. package/dist/types/manifest/monorepo.d.ts.map +1 -1
  34. package/package.json +1 -1
package/README.md CHANGED
@@ -142,9 +142,11 @@ manifest exists: a grant that names no context at all (no manifest to
142
142
  derive contexts from, and no `--contexts` given) is paths-only in the
143
143
  literal sense, but since every manifest-mutation tool's enforcement
144
144
  requires a context match, such a grant cannot authorize any of those seven
145
- tools — it is scoped only for a future, generic Field Kit adapter that
146
- doesn't check `contexts`, not for `hexagen_accept_transaction` as it exists
147
- today. Prints the grant JSON to stdout, or to `--out <file>` if given.
145
+ tools. It is scoped for `hexagen_propose_patch`, the Field Kit adapter that
146
+ exists today: that tool is propose-only, and its enforcement checks `tools`,
147
+ `paths`, `max_files` and the slice, never `contexts`. It is not scoped for
148
+ `hexagen_accept_transaction`, which requires a context match on every
149
+ mutation. Prints the grant JSON to stdout, or to `--out <file>` if given.
148
150
 
149
151
  ### `hexagen grant show` and `hexagen grant check`
150
152
 
@@ -196,6 +198,66 @@ print the workspace root, the key path and its fingerprint, never the key.
196
198
  auto-broken), and `--key-file`/`--engagement` pointing at a key other than the
197
199
  server default produces a warning naming both keys.
198
200
 
201
+ ### `hexagen grant list`
202
+
203
+ ```bash
204
+ npx hexagen grant list # every grant under .hexagen/grants/, as a table
205
+ npx hexagen grant list --status live # only the live rows
206
+ npx hexagen grant list --json # the same rows as a JSON array on stdout
207
+ ```
208
+
209
+ A read-only listing of every `*.json` under `.hexagen/grants/` — there is no
210
+ `--dir` and no other directory — so you can see what is live, expired or revoked
211
+ without opening JSON by hand. Two lines come first, the directory it read and the
212
+ time the window was judged at, then the resolved key by path and fingerprint
213
+ (never the key), then the table and its summary:
214
+
215
+ ```text
216
+ file status id principal agent mode expires_at revoked_at signature
217
+ grants/g-live.json live g-live martin lane-1 propose 2026-10-01T18:00:00Z - verified
218
+ grants/g-revoked.json revoked g-revoked martin lane-1 propose 2026-10-01T18:00:00Z 2026-10-01T10:00:00Z verified
219
+ grants/g-expired.json expired g-expired martin lane-1 propose 2026-10-01T11:00:00Z - verified
220
+ 3 entries: 1 live, 1 expired, 1 revoked, 0 invalid
221
+ ```
222
+
223
+ The columns are file, status, id, principal, agent, mode, `expires_at`,
224
+ `revoked_at` and the signature verdict; rows are sorted by `expires_at`
225
+ descending, then id. The status is the shared `checkGrantWindow` answer, never a
226
+ second implementation of the window, and it is computed at call time and printed
227
+ with that time. The verification key is resolved once for the whole listing and
228
+ named exactly as `grant issue`, `show` and `check` resolve it. It works in a repo
229
+ with a manifest too, reading the in-repo key.
230
+
231
+ - Every entry in the directory becomes a row, including every refusal and every
232
+ error one raises: a symlink is `invalid: symlink` and is never read, and so are
233
+ an off-allow-list name, a name the key/env pattern forbids, unparseable JSON, a
234
+ JSON value that is not a grant, a file over the 32 MiB per-file cap, and an
235
+ entry that vanishes mid-read (`invalid: vanished before it could be read`). One
236
+ unreadable grant never hides the others — the deliberate difference from
237
+ `workbook export`, which fails the whole call instead. The reads go through the
238
+ same sidecar guards the export uses, so `.hexagen/grants/` has one enumerator,
239
+ not three.
240
+ - Exit 0 only if at least one grant was read, every grant read verifies and no
241
+ row is invalid. Exit 1 if no grant was read, any row is invalid, or any grant
242
+ read fails its signature — including one `--status` filtered out of the printed
243
+ rows. Exit 2 for bad input (an unknown `--status`, an unresolvable workspace
244
+ root, an unreadable directory) or a missing `.hexagen/` or `.hexagen/grants/`.
245
+ A fresh checkout has no `grants/` directory at all, so stage the grant files
246
+ first with `hexagen workbook export --stage .hexagen/grants/<id>.json --yes`.
247
+ - `--status live|expired|revoked|invalid|all` (default `all`) filters the printed
248
+ rows and nothing else. The summary always totals the whole directory, so an
249
+ invalid entry, or a signature failure the filter dropped, is still on screen
250
+ next to the exit code it caused — with `--status live` over a directory that
251
+ also holds one invalid entry, one row is printed and the summary reads:
252
+ `1 shown (--status live); all 4 entries: 1 live, 1 expired, 1 revoked, 1 invalid`.
253
+ `--json` prints the array of rows on stdout, with the key line, the summary and
254
+ the note on stderr.
255
+ - A `revoked_at` edited by hand breaks the signature, so the row reads `revoked`
256
+ and `not verified` — the same split `grant check` reports. `live` is the window
257
+ alone, at the timestamp printed beside it: read the signature column before
258
+ trusting a row. A listing is a snapshot, and a grant can be revoked a second
259
+ later.
260
+
199
261
  ### `hexagen observe`
200
262
 
201
263
  A read-only scan of a repo you do not control. It reports what is already
@@ -344,9 +406,13 @@ npx hexagen observe --out .hexagen/observed.json --yes
344
406
  npx hexagen slice init --path src/billing/ --exclude src/billing/generated/ --yes
345
407
  npx hexagen slice check # drift report
346
408
  npx hexagen contract propose # candidate rules; writes nothing
409
+ npx hexagen contract propose --closed # one candidate `closed` rule instead
347
410
  npx hexagen contract add-rule --kind forbid --from src/billing/ --to src/auth/ --yes
411
+ npx hexagen contract add-rule --kind closed --except src/auth/ --yes # close the slice, except one crossing
348
412
  npx hexagen contract check # gate; exit 1 on a new violation
349
413
  npx hexagen contract check --baseline --yes # record today's violations
414
+ npx hexagen contract check --base <base-sha> # pinned PR base; exit 1 on growth
415
+ npx hexagen contract check --base <base-sha> --allow-growth --reason "<why>"
350
416
  ```
351
417
 
352
418
  **`slice`** writes `.hexagen/slice.json`.
@@ -371,15 +437,56 @@ npx hexagen contract check --baseline --yes # record today's violations
371
437
  **`contract`** writes `.hexagen/contract.json`, whose `sliceId` comes from
372
438
  `slice.json`.
373
439
 
374
- - `contract propose` prints each pair of slice `paths` entries joined by an
375
- in-slice edge (both ends inside the slice, different entries) as a candidate
376
- `forbid` rule. It writes nothing.
440
+ - `contract propose [--closed]` prints each pair of slice `paths` entries joined by
441
+ an in-slice edge (both ends inside the slice, different entries) as a candidate
442
+ `forbid` rule. With `--closed` it prints one candidate `closed` rule instead,
443
+ whose `except` list names every crossing `observed.json` already makes, each
444
+ target emitted exactly as `slice check` prints it: the file path for a file
445
+ target, the package root for a package root, deduplicated, never widened to a
446
+ bare directory name (an `except` entry without a trailing `/` is an exact file,
447
+ so `lib` excepts nothing). Delete the entries you do not accept, and widen a
448
+ file to its directory by hand. A crossing no `except` can accept — a
449
+ root-package target (`.`), a target an `excludes` entry denies, or a target
450
+ spelled as a directory — is reported as `not proposed:` with the advice that
451
+ would accept it, because a rule naming one would still fail, or would accept
452
+ far more than the crossing observed. Both printed `add-rule` lines — the
453
+ cross-prefix one and the `--closed` one — are quoted for a POSIX shell, so
454
+ `sh`, `bash` or `zsh` can run either as it stands; `cmd.exe` does not read
455
+ those quotes, so do not paste one there. The cross-prefix line names the
456
+ slice's own prefixes in `--from`/`--to`, and a prefix is a repo path, so a
457
+ space or a `;` in one would otherwise split the command or run what follows.
458
+ With `--closed`, an
459
+ `observed.json` whose edges were not collected refuses (exit 2) and prints no
460
+ command at all: nothing is known about the crossings, so "no edge leaves the
461
+ slice" would be a claim the report cannot make. An incomplete edge list is a
462
+ `note:` line, not a refusal. It writes nothing and takes no write flag.
377
463
  - `contract add-rule --kind forbid|allow-only --from <prefix> --to <prefix>
378
- [--severity error|warn] [--id <id>]` appends a rule (`error` by default). The
379
- built-in id `unresolved-import` and duplicate ids are refused.
380
- - `contract show` prints the contract.
381
- - `contract check [--baseline]` evaluates the rules against the observed edges
382
- whose `from` is inside the slice. A `forbid` rule fails on an edge from its
464
+ [--severity error|warn] [--id <id>]` appends a rule (`error` by default). A
465
+ `closed` rule takes `--except <prefix>…` and neither `--from` nor `--to`: the
466
+ slice is the `from` side and `except[]` is the only escape hatch, so several
467
+ accepted crossings out of one source are one rule. `--except` may be given with
468
+ no prefixes at all, which accepts no crossing. Each kind refuses the other
469
+ kinds' flags by name, and every `--from`, `--to` and `--except` entry must
470
+ pass the slice-path rules, so a bare directory name (`libs/shared`) is an exact
471
+ path and excepts nothing — write `libs/shared/`. The built-in id
472
+ `unresolved-import`, an id outside `A-Za-z0-9._-` (1-64 chars, no `..`), a
473
+ duplicate id, and a missing `--kind` are refused, the last as exit 2 like every
474
+ other usage error.
475
+ - `contract show` prints the contract, and warns when **one** `closed` rule's
476
+ `except` list covers every observed package root outside the slice: that rule
477
+ then accepts every crossing it could have refused, so the slice is not closed.
478
+ Rules are not pooled — two rules that between them cover the whole repo leave
479
+ each edge one rule still to fail, which is what a closed slice wants. Coverage
480
+ is asked per package root, so `--except apps/` covers `apps/web` and
481
+ `apps/admin`, while `--except apps/web/ui/` covers neither the rest of its own
482
+ package nor any sibling; a bare `apps` covers nothing. A package the slice
483
+ occupies and one an `excludes` entry denies are not units to cover, and the
484
+ root package (`.`) never is. A contract with no `closed` rule reads no scan at
485
+ all, and a missing `slice.json`/`observed.json` is a `note:` line, not a
486
+ refusal.
487
+ - `contract check [--baseline] [--base <ref>] [--allow-growth --reason <text>]`
488
+ evaluates the rules against the observed edges whose `from` is inside the slice.
489
+ A `forbid` rule fails on an edge from its
383
490
  `from` prefix to its `to` prefix. An `allow-only` rule fails on an edge from
384
491
  its `from` prefix to anywhere that is neither its `to` prefix nor its own
385
492
  `from` prefix. A `warn` rule is printed but does not fail the check. The
@@ -397,6 +504,67 @@ npx hexagen contract check --baseline --yes # record today's violations
397
504
  of that UTC day) no longer hides its violation. A root-package target (`.`)
398
505
  is never inside a `to` prefix, so it always violates an `allow-only` rule.
399
506
 
507
+ A `closed` rule fails on any edge from inside the slice to a target that is
508
+ neither inside the slice nor under one of its `except` prefixes, so one rule
509
+ holds every accepted crossing out of the slice: the prefix kinds admit exactly
510
+ one. A package root is judged under both spellings, so
511
+ `--except libs/shared/` covers `libs/shared` and `libs/shared/x.ts`, and an
512
+ entry with no trailing `/` is an exact path. A root-package target (`.`) is
513
+ never inside an `except` prefix, so it always violates a `closed` rule, exactly
514
+ as it always violates an `allow-only` one. An edge whose source is inside an
515
+ `excludes` entry is not judged at all, and under a `closed` rule an `excludes`
516
+ entry creates violations instead of suppressing them: an except cannot re-open
517
+ an excluded target, so an edge into one still fails even under an `except` that
518
+ covers it. `--except src/` accepts every crossing out of `src/`, so read the
519
+ list before you commit it.
520
+
521
+ **The `--base` ratchet.** `contract check --base <ref>` also reads
522
+ `.hexagen/contract.json` and `.hexagen/slice.json` **at** `<ref>` with `git show`,
523
+ and fails when the working tree has made the slice's gate weaker than the
524
+ contract there. It is a detection, not a write-time refusal: the change is already
525
+ committed, and each finding is printed as `growth: …` with the hash the base was
526
+ read at. Growth is:
527
+
528
+ - a `knownViolations` entry the base never had for that rule + file + specifier;
529
+ an edit to the `file` or `specifier` of an entry the base did have;
530
+ - an `expires` pushed later from another `expires`, or dropped;
531
+ - a rule gone from the tree; a rule's `kind`, `from` or `to` changed, in either
532
+ direction; a `closed` rule's `except` prefix added or widened; a rule's
533
+ `severity` moved `error` → `warn`;
534
+ - a `slice.json` `excludes` entry the base did not have; a `paths` entry removed;
535
+ a `paths` entry replaced by a strictly longer prefix.
536
+
537
+ **Not** growth: an entry removed, an `expires` shortened, an `expires` added where
538
+ the base had none, a `reason` added, a rule added, an exclude removed, a `paths`
539
+ entry added or widened, a duplicate baseline entry, two rules that share an id
540
+ swapped, an `except` prefix removed or narrowed, and a `severity` raised from
541
+ `warn` to `error`. Rules are matched by value, so two rules sharing an id are
542
+ compared as a multiset, and entries are matched on rule + file + specifier,
543
+ strongest cover first, so a duplicate that already carries no `expires` is not
544
+ reported as a dropped date.
545
+
546
+ `--allow-growth --reason <text>` accepts the growth, prints the reason beside the
547
+ finding and into the log, and the check then continues — so its exit code is
548
+ still the plain check's, not automatically 0. `--reason` on its own does nothing.
549
+
550
+ Both files must be staged for a base to exist: every writer of `.hexagen/` adds
551
+ it to the exclude file, so `git show` cannot tell "never staged" from "the commit
552
+ that first added it", and the command reports the absence instead of passing.
553
+ Stage them with `hexagen workbook export --stage` on
554
+ `.hexagen/slice.json` and `.hexagen/contract.json`, plus `--yes` (or plain
555
+ `git add -f`). Pass the pinned PR base, never a
556
+ PR-supplied ref: `--base` is client-supplied, so a workflow that lets a PR pick
557
+ its own base compares the head with itself and passes. The one PR that first
558
+ stages the sidecars has a base that predates them — that is the bootstrap case,
559
+ judged on violations alone, and the
560
+ [CI recipe](../../docs/ci/brownfield-gate-recipe.md) runs the plain check for it.
561
+ The guard runs after the slice-id and contract parse and **before**
562
+ `observed.json` is loaded, so growth is still reported when `observed.json` is
563
+ missing or stale. One gap it cannot close: `contract check --baseline --yes`
564
+ rewrites `knownViolations` with no base in sight, so it can drop an `expires` the
565
+ guard would otherwise have reported — `--base` and `--baseline` are refused
566
+ together.
567
+
400
568
  **Concurrent edits.** `add-rule` and `check --baseline` (with `--yes`) hold
401
569
  `.hexagen/contract.json.lock`, created exclusively with the process id inside,
402
570
  while they read and rewrite `contract.json`, and remove it when they finish. If
@@ -419,11 +587,11 @@ than `HEAD` the commands warn, and with `--strict` fail.
419
587
 
420
588
  **Exit codes** (`slice check`, `contract check`, `contract propose`):
421
589
 
422
- | Code | Meaning |
423
- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
424
- | 0 | Clean (`slice check`, `contract check`), or the command succeeded |
425
- | 1 | Drift (`slice check`) or a violation not in the baseline, or incomplete edges (`contract check`) |
426
- | 2 | Bad input or refused: a missing or invalid file, a bad path or id, a refused overwrite, no `--yes`, a slice commit not in the repository, a stale `observed.json`, `--strict` and a different HEAD |
590
+ | Code | Meaning |
591
+ | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
592
+ | 0 | Clean (`slice check`, `contract check`), or growth accepted with `--allow-growth` **and** the plain check clean, or the command succeeded |
593
+ | 1 | Drift (`slice check`), or a violation not in the baseline, or incomplete edges, or growth against `--base` (`contract check`) |
594
+ | 2 | Bad input or refused: a missing or invalid file, a bad path or id, a refused overwrite, no `--yes`, a slice commit not in the repository, a stale `observed.json`, `--strict` and a different HEAD, an unresolvable `--base` (a shallow clone that never fetched it), a `.hexagen/` file absent at `--base` because it was never staged, a `.hexagen/` file at `--base` that exists but cannot be read, a base file that is not valid JSON or does not match its schema, an inconsistent base (the contract at `--base` names another slice than the slice there), `--allow-growth` without `--reason`, `--allow-growth` without `--base`, `--base` with `--baseline` |
427
595
 
428
596
  `init`, `add-rule`, `show` and `--baseline` return 0 on success and 2 otherwise.
429
597
 
@@ -483,6 +651,137 @@ path outside `.hexagen/`, a symlink) refuses the whole call and stages nothing.
483
651
 
484
652
  ---
485
653
 
654
+ ### `hexagen evidence verify`
655
+
656
+ ```text
657
+ hexagen evidence verify --since <git-ref> [--until <git-ref>]
658
+ --grant <file>... [--root <dir>]
659
+ [--key-file <path>] [--engagement <id>]
660
+ [--allow-empty]
661
+ ```
662
+
663
+ A synopsis, not a runnable line: `[…]` marks an optional flag and `<…>` a value you
664
+ supply.
665
+
666
+ Names every changed file the kit governs — inside the slice (minus its excludes)
667
+ or inside any `--grant`'s `paths` — that no trace line appended after `--since`
668
+ covers. It is found after the fact, not refused: it reads only, never writes
669
+ `.hexagen/`, and never stops a write.
670
+
671
+ It reads the range `<since>..<until>` (default `HEAD`) with `git diff`, taking
672
+ the slice at **`<since>`** and the trace, the tip and the proposals at
673
+ **`<until>`**, so a range cannot widen its own scope or its own evidence.
674
+ `<since>` must be an ancestor of `<until>`. It then verifies the trace exactly as
675
+ `evidence pack` does — chain, line shape, the four Rules of
676
+ `docs/kernel/TRACE.md`, and the anchored tip — and joins each changed file to the
677
+ line that claims it. `tip.json` is **required** here, and only a line at or below
678
+ `tip.seq` covers anything: the chain binds each line to the one above it, but only
679
+ a key-holder's `pack` binds the head to the engagement key. A change that a line
680
+ would have covered on paper alone is still reported unaccounted, naming the seq to
681
+ pack. Every grant the trace cites must be supplied as a `--grant`, and the
682
+ engagement key comes from `--key-file`, then `HEXAGEN_GRANT_KEY_FILE`, then the
683
+ engagement — in CI that is a secret written outside the checkout, never a key in
684
+ the tree.
685
+
686
+ No Trace field carries the paths: the join reads them back from
687
+ `.hexagen/proposals/<id>.json` by its `traceSeq` and `grantId`, and recomputes
688
+ `result_digest` over `JSON.stringify({halt_reason, proposal_id, paths})`, so a
689
+ `paths` entry edited after the line was written breaks the digest instead of being
690
+ believed. Only a line whose `seq` is above the last `seq` in the trace as of
691
+ `<since>` can cover anything, read with `git show`; a checkout where the trace was
692
+ not tracked at `<since>`, or where that line is not the one the trace held there,
693
+ exits 2 rather than trusting a clock.
694
+
695
+ It prints the unaccounted paths on stdout and, on stderr, each one with the
696
+ nearest candidate line plus how many changes it skipped as outside the slice and
697
+ every grant. Exit 0 when nothing is unaccounted, 1 when something is, 2 for bad
698
+ input or bad state: an unresolvable `--since` or `--until` (a shallow clone that
699
+ never fetched it says so), a `--since` that is not an ancestor of `--until`, a
700
+ missing or unreadable slice at `<since>`, a missing or empty trace at `<until>`, a
701
+ missing or unverified `tip.json`, an unsound trace, a proposal that does not
702
+ reproduce its line's `result_digest`, a grant that does not verify, a trace not
703
+ tracked at `<since>`, a `--root` that is not the repo top level, and an empty
704
+ diff without `--allow-empty`.
705
+
706
+ Two limits worth stating: it proves an authorized line covering a path exists, not
707
+ that the line is true; and until Trace carries paths itself, a change applied
708
+ through `hexagen_accept_transaction` is unaccounted here, because that writer
709
+ leaves no path list behind. Coverage needs the `.hexagen/` evidence committed, so
710
+ stage it first — and in CI, pack before verify:
711
+
712
+ ```bash
713
+ hexagen workbook export --stage .hexagen/slice.json \
714
+ .hexagen/evidence/trace.jsonl \
715
+ .hexagen/evidence/tip.json \
716
+ .hexagen/grants/<id>.json \
717
+ .hexagen/proposals/<id>.json \
718
+ --yes
719
+ ```
720
+
721
+ ---
722
+
723
+ ### The brownfield CI gate
724
+
725
+ A client repo holds only `.hexagen/` and no manifest, so the generated
726
+ conformance gate has nothing to run there. Copy
727
+ [`docs/ci/brownfield-gate.yml`](../../docs/ci/brownfield-gate.yml) into the client
728
+ repo's `.github/workflows/` and edit its one `EDIT SPOT`: the
729
+ `HEXAGEN_VERSION` pin. `contract check --base` (step 3) and `evidence verify`
730
+ (step 4b) first ship in 0.14.0, so that is the **minimum** the gate needs rather
731
+ than a published release — release tags are the owner's to cut. Set it to a
732
+ version you can install and bump it deliberately; `hexagen --help` is the check
733
+ that the pin exists, because an older CLI's command parser refuses those two
734
+ flags and the job then fails at step 3 for a reason that has nothing to do with
735
+ the change under review.
736
+
737
+ `evidence pack` and `evidence verify` are the two halves of the gate, and the
738
+ recipe is a document rather than a template:
739
+ [`docs/ci/brownfield-gate-recipe.md`](../../docs/ci/brownfield-gate-recipe.md).
740
+ Every step's `run:` script is read out of that workflow and executed against the
741
+ built CLI on a fixture client repo by
742
+ `__tests__/contract/brownfield-gate.contract.test.ts`, so the recipe cannot drift
743
+ from what the job does. The one exception is `Install the hexagen CLI`: the
744
+ fixture already holds the artifact that install fetches — the built dist, copied
745
+ into the consumer's `node_modules/@hexagen-monaco/sync` — so the install is the
746
+ only step the suite does not run. Every kit command, and every step that can
747
+ decide the job, does run.
748
+
749
+ - `evidence pack <trace> --grant <file>... --out <zip>` checks the whole trace and
750
+ writes an HMAC'd bundle: 0 packed, 1 the evidence is invalid and nothing was
751
+ written, 2 usage or a failed precondition (no key, `--out` outside `.hexagen/`,
752
+ an `--out` that already exists). It is step 4, and it is also the only command
753
+ that anchors a line — so it runs even where nothing needs the bundle, because
754
+ step 4b counts only what a `pack` anchored.
755
+ - `evidence verify --since <ref> --grant <file>...` is step 4b and writes
756
+ nothing. It is documented under
757
+ [`hexagen evidence verify`](#hexagen-evidence-verify) above.
758
+
759
+ Fail-fast and in order, every step printing `step <n> exit <code>` — 1 is a
760
+ violation, 2 is bad input or stale state — and step 2 the one non-blocking
761
+ drift report. The steps are: the staged `.hexagen/` paths are tracked
762
+ (`git ls-files --error-unmatch`, exit 2 otherwise), `observe --out … --yes`,
763
+ `slice check --strict`, `contract check --base` against the pinned PR base SHA,
764
+ `evidence pack` into a disposable path under `.hexagen/`, then `evidence verify`
765
+ against the same base. Step 3 asks what the base holds and there are three
766
+ answers, not two: both sidecar files (compare, and let violations and growth
767
+ fail), neither (the PR that first stages them, judged on violations alone), or
768
+ exactly one — which it refuses with exit 2 rather than compare half a baseline.
769
+ Step 4b is skipped on exactly one PR, the bootstrap whose base carries no slice;
770
+ a base with a slice but no trace runs it and lets it exit 2.
771
+
772
+ The gate needs no manifest, no `apps/web` and no workbench package: the published
773
+ CLI is the only dependency. The engagement key is injected from a CI secret into
774
+ `$RUNNER_TEMP` at mode 0600 and read through `HEXAGEN_GRANT_KEY_FILE`, never
775
+ from the checkout. A missing or weak key is a denial, never a skip — and
776
+ because the job is fail-fast, only the first step that reads the key reports
777
+ it: the injection step exits 2 on an empty secret, while a non-empty but weak
778
+ key is caught by `evidence pack` in step 4, which exits 2 too.
779
+ `evidence verify` never runs in either case, because the job stopped first. The
780
+ bundle's HMAC is symmetric, so the CI secret can forge it and the FDE and CI
781
+ cannot be told apart.
782
+
783
+ ---
784
+
486
785
  ## Programmatic Usage
487
786
 
488
787
  > **The supported contract of this package is the `hexagen` binary.** The root
@@ -647,6 +946,7 @@ The source `packages/sync/package.json` is never mutated by this process.
647
946
  - **HexaGen Monaco repository:** https://github.com/martinkrakowski/hexagen-monaco
648
947
  - **Architecture Decision Record:** [`ADR-0068`](../../.architecture/decisions/ADR-0068-published-cli-bundling.md) — CLI Bundling Strategy
649
948
  - **Manifest schema:** `@hexagen/project-configuration`
949
+ - **Brownfield CI gate recipe:** [`docs/ci/brownfield-gate-recipe.md`](../../docs/ci/brownfield-gate-recipe.md) — the gate a client repo runs when the workbench is gone
650
950
  - **Issue tracker:** https://github.com/martinkrakowski/hexagen-monaco/issues
651
951
 
652
952
  ---