@hexagen-monaco/sync 0.12.1 → 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 (107) hide show
  1. package/README.md +729 -0
  2. package/dist/cli.js +7635 -516
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/arch/edit.d.ts.map +1 -1
  5. package/dist/commands/contract/evaluate.d.ts +99 -0
  6. package/dist/commands/contract/evaluate.d.ts.map +1 -0
  7. package/dist/commands/contract/growth.d.ts +22 -0
  8. package/dist/commands/contract/growth.d.ts.map +1 -0
  9. package/dist/commands/contract/index.d.ts +32 -0
  10. package/dist/commands/contract/index.d.ts.map +1 -0
  11. package/dist/commands/evidence/check.d.ts +33 -0
  12. package/dist/commands/evidence/check.d.ts.map +1 -0
  13. package/dist/commands/evidence/index.d.ts +3 -0
  14. package/dist/commands/evidence/index.d.ts.map +1 -0
  15. package/dist/commands/evidence/pack.d.ts +41 -0
  16. package/dist/commands/evidence/pack.d.ts.map +1 -0
  17. package/dist/commands/evidence/verify.d.ts +83 -0
  18. package/dist/commands/evidence/verify.d.ts.map +1 -0
  19. package/dist/commands/grant/build.d.ts +53 -0
  20. package/dist/commands/grant/build.d.ts.map +1 -0
  21. package/dist/commands/grant/canonical.d.ts +27 -0
  22. package/dist/commands/grant/canonical.d.ts.map +1 -0
  23. package/dist/commands/grant/check.d.ts +26 -0
  24. package/dist/commands/grant/check.d.ts.map +1 -0
  25. package/dist/commands/grant/duration.d.ts +8 -0
  26. package/dist/commands/grant/duration.d.ts.map +1 -0
  27. package/dist/commands/grant/index.d.ts +2 -0
  28. package/dist/commands/grant/index.d.ts.map +1 -0
  29. package/dist/commands/grant/issue.d.ts +23 -0
  30. package/dist/commands/grant/issue.d.ts.map +1 -0
  31. package/dist/commands/grant/key-init.d.ts +16 -0
  32. package/dist/commands/grant/key-init.d.ts.map +1 -0
  33. package/dist/commands/grant/list.d.ts +72 -0
  34. package/dist/commands/grant/list.d.ts.map +1 -0
  35. package/dist/commands/grant/revoke.d.ts +35 -0
  36. package/dist/commands/grant/revoke.d.ts.map +1 -0
  37. package/dist/commands/grant/show.d.ts +18 -0
  38. package/dist/commands/grant/show.d.ts.map +1 -0
  39. package/dist/commands/grant/sign.d.ts +3 -0
  40. package/dist/commands/grant/sign.d.ts.map +1 -0
  41. package/dist/commands/grant/signing-key.d.ts +22 -0
  42. package/dist/commands/grant/signing-key.d.ts.map +1 -0
  43. package/dist/commands/grant/verify.d.ts +51 -0
  44. package/dist/commands/grant/verify.d.ts.map +1 -0
  45. package/dist/commands/grant/workspace.d.ts +11 -0
  46. package/dist/commands/grant/workspace.d.ts.map +1 -0
  47. package/dist/commands/observe/imports/jsonc.d.ts +6 -0
  48. package/dist/commands/observe/imports/jsonc.d.ts.map +1 -0
  49. package/dist/commands/observe/imports/pass.d.ts +45 -0
  50. package/dist/commands/observe/imports/pass.d.ts.map +1 -0
  51. package/dist/commands/observe/imports/resolve.d.ts +44 -0
  52. package/dist/commands/observe/imports/resolve.d.ts.map +1 -0
  53. package/dist/commands/observe/imports/safe-read.d.ts +30 -0
  54. package/dist/commands/observe/imports/safe-read.d.ts.map +1 -0
  55. package/dist/commands/observe/imports/scan.d.ts +59 -0
  56. package/dist/commands/observe/imports/scan.d.ts.map +1 -0
  57. package/dist/commands/observe/index.d.ts +59 -0
  58. package/dist/commands/observe/index.d.ts.map +1 -0
  59. package/dist/commands/observe/same-path.d.ts +9 -0
  60. package/dist/commands/observe/same-path.d.ts.map +1 -0
  61. package/dist/commands/observe/walk.d.ts +29 -0
  62. package/dist/commands/observe/walk.d.ts.map +1 -0
  63. package/dist/commands/report/exec-git.d.ts.map +1 -1
  64. package/dist/commands/shared/brownfield-sidecar.d.ts +98 -0
  65. package/dist/commands/shared/brownfield-sidecar.d.ts.map +1 -0
  66. package/dist/commands/shared/git-exclude.d.ts +36 -0
  67. package/dist/commands/shared/git-exclude.d.ts.map +1 -0
  68. package/dist/commands/shared/glob.d.ts +29 -0
  69. package/dist/commands/shared/glob.d.ts.map +1 -0
  70. package/dist/commands/shared/grant-enumerator.d.ts +32 -0
  71. package/dist/commands/shared/grant-enumerator.d.ts.map +1 -0
  72. package/dist/commands/shared/ignore.d.ts +32 -0
  73. package/dist/commands/shared/ignore.d.ts.map +1 -0
  74. package/dist/commands/shared/sidecar-out.d.ts +6 -0
  75. package/dist/commands/shared/sidecar-out.d.ts.map +1 -0
  76. package/dist/commands/shared/sidecar-write.d.ts +2 -0
  77. package/dist/commands/shared/sidecar-write.d.ts.map +1 -0
  78. package/dist/commands/slice/index.d.ts +23 -0
  79. package/dist/commands/slice/index.d.ts.map +1 -0
  80. package/dist/commands/workbook/allow-list.d.ts +27 -0
  81. package/dist/commands/workbook/allow-list.d.ts.map +1 -0
  82. package/dist/commands/workbook/export.d.ts +41 -0
  83. package/dist/commands/workbook/export.d.ts.map +1 -0
  84. package/dist/commands/workbook/index.d.ts +3 -0
  85. package/dist/commands/workbook/index.d.ts.map +1 -0
  86. package/dist/commands/workbook/zip-read.d.ts +7 -0
  87. package/dist/commands/workbook/zip-read.d.ts.map +1 -0
  88. package/dist/fs-utils.d.ts.map +1 -1
  89. package/dist/generators/root-file-templates.d.ts +5 -4
  90. package/dist/generators/root-file-templates.d.ts.map +1 -1
  91. package/dist/generators/root-files.d.ts.map +1 -1
  92. package/dist/index.js +367 -37
  93. package/dist/index.js.map +1 -1
  94. package/dist/templates/agents-md/findings/0001-session-log-grows-unbounded.md +35 -0
  95. package/dist/templates/ci-github-actions/findings/0001-ci-runners-have-no-zsh.md +34 -0
  96. package/dist/templates/orchestration/README.md +88 -0
  97. package/dist/templates/orchestration/files/.agents/skills/orchestrate-wave/SKILL.md +511 -0
  98. package/dist/templates/orchestration/files/.agents/skills/orchestrate-wave/references/briefs.md +178 -0
  99. package/dist/templates/orchestration/files/.agents/skills/orchestrate-wave/references/rationale.md +520 -0
  100. package/dist/templates/orchestration/files/.agents/skills/orchestrate-wave/scripts/wave-event.sh +17 -0
  101. package/dist/templates/orchestration/files/.github/workflows/gate.yml +66 -0
  102. package/dist/templates/orchestration/findings/0001-relative-runbook-links-escape-the-skill.md +48 -0
  103. package/dist/templates/orchestration/findings/0002-interpolation-hazard-in-graphql-line.md +46 -0
  104. package/dist/templates/orchestration/manifest.json +41 -0
  105. package/dist/types/manifest/monorepo.d.ts +5 -0
  106. package/dist/types/manifest/monorepo.d.ts.map +1 -1
  107. package/package.json +1 -1
package/README.md CHANGED
@@ -52,6 +52,734 @@ npx hexagen sync
52
52
 
53
53
  Consult `npx hexagen arch --help` for the full list of manifest operations.
54
54
 
55
+ ### `hexagen grant issue`
56
+
57
+ Mints a signed Grant — the file `hexagen_accept_transaction` trusts as its
58
+ `grant` argument (see `docs/kernel/GRANT.md`). Local, no server:
59
+
60
+ ```bash
61
+ npx hexagen grant issue \
62
+ --principal martin \
63
+ --agent lane-ow3b \
64
+ --paths .architecture/,packages/billing/ \
65
+ --tools hexagen_accept_transaction,hexagen_create_port \
66
+ --mode write \
67
+ --expires-in 4h \
68
+ --out .hexagen/grants/<id>.json
69
+ ```
70
+
71
+ Signs with an HMAC-SHA256 key. Which key, and where it lives, depends on the
72
+ mode, and `hexagen_accept_transaction`'s server resolves it the same way
73
+ (one shared resolver), in this order:
74
+
75
+ 1. `--key-file <path>`
76
+ 2. `HEXAGEN_GRANT_KEY_FILE`
77
+ 3. **Repo mode** (`.architecture/manifest.yaml` exists): `.hexagen/grant-signing.key`,
78
+ created on first use if missing, with a `.gitignore` entry added for it.
79
+ Never commit it. **Brownfield** (no manifest, a client repo you do not
80
+ control): `~/.hexagen/keys/<engagement>.key`, never inside the repo. There
81
+ is no fallback to an in-repo key.
82
+
83
+ The key must be a full 32-byte hex value, so a hand-edited or truncated key
84
+ file is rejected by the issuer and denied by the server rather than silently
85
+ used. Keys are shown by path and
86
+ fingerprint (first 16 hex chars of the SHA-256 of the key bytes), never
87
+ printed.
88
+
89
+ #### Brownfield: `grant key init` and `--engagement`
90
+
91
+ ```bash
92
+ npx hexagen grant key init --engagement acme-q3 [--key-file <path>]
93
+ ```
94
+
95
+ The only command that mints a key outside repo mode. It writes 32 random bytes
96
+ as hex at mode 0600 in `~/.hexagen/keys/` (0700, tightened if it was loose),
97
+ refuses to overwrite an existing key (exit 1), and accepts engagement ids
98
+ matching `^[A-Za-z0-9._-]{1,64}$` with no `..`. `grant issue` in a repo with no
99
+ manifest never mints and never edits `.gitignore`:
100
+
101
+ - The engagement id is `--engagement <id>`, or the `id` of a valid
102
+ `.hexagen/slice.json`. Without either, exit 2.
103
+ - `--paths` defaults to the slice's paths; every entry must be a valid slice
104
+ path inside the slice, and no slice exclude may sit beneath a directory entry
105
+ (grants carry no excludes, so issue narrower paths; exit 2). `--contexts` is
106
+ refused (exit 2), and the grant omits `contexts`.
107
+ - The root is the git toplevel of the current directory when the discovered
108
+ manifest root lies outside it, so a client repo nested under a directory with
109
+ a manifest is still brownfield. A manifest at or below the toplevel keeps repo
110
+ mode. `--workspace-root` overrides both.
111
+ - `--out` must be a new file under `<root>/.hexagen/` (symlink escapes are
112
+ refused, exit 2; an existing file is never overwritten, exit 1) and is written
113
+ via a temp file plus a hard link.
114
+ - `.hexagen/` is added to `.git/info/exclude`. When a write is pending (the
115
+ `--out` file or an exclude change) the preflight lists it and `--yes` is
116
+ required; otherwise exit 2 without writing. With nothing to write, `--yes`
117
+ is not needed.
118
+ - It prints the workspace root, key path and fingerprint on stderr. If
119
+ `--key-file` points somewhere the server would not look by default, it warns
120
+ with both paths and fingerprints (likewise when `--engagement` differs from the
121
+ slice's id). The grant is validated and signed before `.git/info/exclude` is
122
+ touched. The MCP server takes `--key-file` and
123
+ `--engagement` too, and logs the same line at startup.
124
+
125
+ `--contexts <name[,name...]>` is a monaco-only convenience (repo mode): it
126
+ looks each name up in `manifest.yaml` and expands it to `packages/<name>/`,
127
+ appended to `--paths`.
128
+
129
+ `hexagen_accept_transaction`'s enforcement (`checkMutationAgainstGrant`)
130
+ requires `grant.contexts` to independently name every context a mutation
131
+ targets — a grant's `paths` alone never satisfies that check, and an empty
132
+ `contexts` denies everything. So the CLI also reverse-matches any
133
+ `packages/<name>/` prefix already present in `--paths` against the
134
+ manifest, folding matching names into `grant.contexts` automatically
135
+ (`--contexts` can usually be omitted when `--paths` already names the
136
+ context's package directory, as in the example above). Symmetrically,
137
+ `.architecture/` — the one path every manifest mutation actually writes
138
+ through — is always added to the grant's `paths` whenever it authorizes any
139
+ context, so `--contexts` alone is enough without repeating
140
+ `.architecture/` in `--paths`. This reconciliation only works where a
141
+ manifest exists: a grant that names no context at all (no manifest to
142
+ derive contexts from, and no `--contexts` given) is paths-only in the
143
+ literal sense, but since every manifest-mutation tool's enforcement
144
+ requires a context match, such a grant cannot authorize any of those seven
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.
150
+
151
+ ### `hexagen grant show` and `hexagen grant check`
152
+
153
+ ```bash
154
+ npx hexagen grant show .hexagen/grants/<id>.json
155
+ npx hexagen grant check .hexagen/grants/<id>.json \
156
+ --tool hexagen_propose_patch --path src/a.ts src/b.ts
157
+ ```
158
+
159
+ Both resolve the verification key exactly as `grant issue` and the MCP server
160
+ do (`--key-file`, then `HEXAGEN_GRANT_KEY_FILE`, then the engagement from
161
+ `.hexagen/slice.json` or `--engagement`, or the in-repo key in repo mode), and
162
+ print the workspace root, the key path and its fingerprint, never the key.
163
+
164
+ - `show` pretty-prints id, principal, agent, contexts (when present), paths,
165
+ tools, mode, `max_files`, `expires_at` and `revoked_at`, the window status,
166
+ and whether the signature verifies. Exit 0 verified, 1 not verified (the
167
+ reason is printed), 2 bad input. A revoked or expired grant with a valid
168
+ signature still exits 0; `check` enforces the window.
169
+ - `check` verifies the signature, then the window, then the tool, the paths
170
+ and `max_files` (`checkWriteAgainstGrant`). It never runs the mode check, so
171
+ a propose-only grant is allowed. In a client repo (no manifest) it also
172
+ denies a path outside the slice or inside its excludes, even if the grant
173
+ allows it, and with no `.hexagen/slice.json` it denies (the slice bounds every
174
+ write). Paths are judged by text only; the MCP propose tool also checks the
175
+ on-disk spelling. `--path` may be repeated or list several paths, and every one is checked.
176
+ The Field Kit form is for client repos; in a repo with a manifest it exits 2.
177
+ The root is the git toplevel unless `--workspace-root` is given. Exit 0
178
+ allow, 1 deny, 2 bad input (including an invalid `.hexagen/slice.json` or
179
+ timestamp, which `show` also rejects). A missing or weak key, or a
180
+ signature made under another key, is a denial; with `--key-file` or
181
+ `--engagement` it names both keys' fingerprints.
182
+ - The monaco form, `grant check <grant-file> <transaction-id>`, is not built:
183
+ pending transactions live in the MCP server's memory. It exits 2.
184
+ - `revoke` sets `revoked_at` and re-signs the grant:
185
+ `hexagen grant revoke .hexagen/grants/<id>.json [--at <iso>] --yes`. It
186
+ verifies the grant under the resolved key first and refuses one that does not
187
+ verify (exit 1). It previews the write and needs `--yes`; the file is replaced
188
+ by a temp file and an atomic rename; in a client repo it must be under
189
+ `.hexagen/`. Revoking again is a no-op ("already revoked at ..."), except an
190
+ earlier `--at` moves the date earlier. Hand-editing `revoked_at` breaks the
191
+ signature, so `check` denies the grant as a signature failure; `revoke`
192
+ re-signs it, so `check` reports `grant_revoked`. Deleting the engagement key
193
+ revokes every grant in that engagement (an emergency stop).
194
+ A future `--at` schedules the revocation (the grant stays valid until then,
195
+ and the preflight warns); a value at or after `expires_at` has no effect. In
196
+ a repo with a manifest it re-signs with the in-repo key.
197
+ Concurrent revokes are serialised by `<grant>.lock` (a held lock exits 2, never
198
+ auto-broken), and `--key-file`/`--engagement` pointing at a key other than the
199
+ server default produces a warning naming both keys.
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
+
261
+ ### `hexagen observe`
262
+
263
+ A read-only scan of a repo you do not control. It reports what is already
264
+ there, in the repo's own names, and never runs `adopt`, `bootstrap`, `sync`
265
+ or `hexagen-lint`:
266
+
267
+ ```bash
268
+ npx hexagen observe --root ../client-repo # JSON to stdout
269
+ npx hexagen observe --root ../client-repo \
270
+ --out .hexagen/observed.json --yes # write the file
271
+ npx hexagen observe --dont-touch src/legacy/ vendor-patches/ # report-only
272
+ ```
273
+
274
+ - `--root <dir>` is used exactly as given (default: cwd); it is never searched
275
+ upward, and it must be the repo top level (exit 2 otherwise, naming the
276
+ top level git reports). The directory must be a git checkout with at least one
277
+ commit, whose `HEAD` is recorded in `repo.commit`. Credentials, query and fragment in the `origin` URL are stripped.
278
+ - `--out <file>` must resolve under `<root>/.hexagen/` (symlinks included);
279
+ anything else exits 2, as does a `.hexagen` that is a regular file. It
280
+ prints a `will write:` line for `observed.json` and one for the exclude file,
281
+ and writes only with `--yes` (without it, exit 2). The report is written as a
282
+ temp file plus rename. `.hexagen/` is then kept out of `git status` by
283
+ appending it, if absent, to the file `git rev-parse --git-path info/exclude`
284
+ prints (correct in linked worktrees and submodules); the tracked
285
+ `.gitignore` is never edited, and `git add -f` can still stage the
286
+ directory. If that update fails, the command exits 2 before writing the
287
+ report.
288
+ - `--max-files <n>` (default 50000) and `--max-ms <n>` (default 30000) cap the
289
+ walk. A tripped cap marks `packages`, `languages`, `build` and `generated` as
290
+ `collected: false` with the reason, and sets `limits.truncated`.
291
+ - The output validates against `ObservedReport` (`docs/kernel/observed.schema.json`)
292
+ and has no `type`, layer, plane or context key.
293
+ - `--max-import-files <n>` (default 20000: the pass refuses to run when there
294
+ are more than `n` JS/TS files), `--max-import-bytes <n>` (default 268435456)
295
+ and `--max-import-ms <n>` (default 30000) cap the import pass. It has its own
296
+ clock, started when it begins, and runs after `generated` is collected, so it
297
+ cannot use up the time `--max-ms` gives the walk and `generated`. A tripped
298
+ cap sets `edges` and `unresolved` to `collected: false` with the reason, and
299
+ sets `limits.truncated`; the other sections keep what they collected. If the
300
+ walk itself was truncated, the pass does not run and both sections carry the
301
+ walk's reason.
302
+
303
+ What it reads:
304
+
305
+ - **Walk.** Skips `node_modules`, `vendor`, `bower_components`, `jspm_packages`,
306
+ `.yarn`, `.git`, `.hg`, `.svn` and `.hexagen`,
307
+ does not follow symlinks, and honours the root `.gitignore` and nested
308
+ `.gitignore` files (not `info/exclude` or `core.excludesFile`). A path that
309
+ fails the slice-path rules (a backslash or control character) is skipped
310
+ with a note.
311
+ - **Import pass (`edges`, `unresolved`).** A lexical scan of `.ts .tsx .mts
312
+ .cts .js .jsx .mjs .cjs` files from the same walk. It is a tokenizer, not a
313
+ parser, and never uses ts-morph or the TypeScript compiler API. It reads
314
+ `import … from 'x'`, `import 'x'`, `export … from 'x'`, `import('x')`,
315
+ `require('x')` (also `require?.('x')` and `(require)('x')`) and
316
+ `import x = require('x')`; comments, strings and
317
+ template literals (including `${…}` contents) are skipped. Source files and
318
+ tsconfigs are opened without following a symlink in the last path component
319
+ (`O_NOFOLLOW`; on Windows an `lstat` check instead), and the size limit and the
320
+ read both use the opened handle. Bytes read from tsconfigs count toward
321
+ `--max-import-bytes`, and the time cap is checked while they load. Only files
322
+ up to
323
+ 1 MiB are read. A larger or unreadable file is skipped, noted in
324
+ `limits.reasons` (the notes are capped at 50), and given its own `unresolved`
325
+ row, so its missing edges never read as clean. The scan is linear in the file
326
+ size. Known limits: JSX text with an apostrophe opens a string that ends at the
327
+ line end; a regex literal right after `)` (`if (x) /re/.test(y)`) is read as
328
+ division, so a specifier-shaped string inside it can appear as a phantom
329
+ import; a wrong regex or string guess can swallow a backtick and misread the
330
+ template state until the next one; and a `/` after `>` starts a regex (so
331
+ `x => /re/.test(x)` works) but after `<` it does not (`</p>`); a postfix
332
+ `++`/`--` followed by an unbalanced `[` in a divisor string can make the line
333
+ guard hide a later quote-bearing regex on the same line
334
+ (`x = i++ / "["; y = /it's/.test(s);`); a block statement after a
335
+ semicolon-less non-literal `require(x)` (ASI only) is dropped. A class method named `require` or `import`
336
+ (`require(id) {}`) is not reported.
337
+ - **Resolution order, per specifier:** (1) a relative specifier (`./`, `../`)
338
+ against the walked files: the exact file, then `.js`→`.ts/.tsx`
339
+ (`.jsx`→`.tsx`, `.mjs`→`.mts`, `.cjs`→`.cts`), then each extension, then
340
+ `/index.*` (a trailing slash, `.` and `..` name a directory and match only
341
+ its `index.*`; `C:/x` and `C:\x` are `outside-repo`; `.\x` is `not-found`); (2) a workspace package name, exactly as declared including
342
+ scope, mapped to that package's root (`"."` for the root package); (3) the
343
+ nearest `tsconfig.json` at or above the file, within the repo:
344
+ `compilerOptions.paths` (longest matching prefix wins) and `baseUrl`,
345
+ following `extends` only to repo-relative files, at most 5 levels past the
346
+ nearest file, with a note on a cycle, an unreadable or over-1-MiB file or an
347
+ `extends` that leaves the repo; for an `extends` array only the last entry
348
+ is followed (noted), not TypeScript's merge of all of them;
349
+ (4) a `#` specifier (package `imports`). A tsconfig further up the tree is
350
+ not consulted when the nearest one has no `paths`/`baseUrl`.
351
+ - **`edges[]`** are `{from, to, specifier}` with `to` a file or a package
352
+ root, deduplicated.
353
+ - **`unresolved[]`** are `{from, specifier, reason}`. Reasons:
354
+ `not-found` (a relative or alias target that is not in the walk),
355
+ `exports-subpath` (`@scope/pkg/sub`, when no tsconfig `paths` alias matches it;
356
+ `exports` maps are not read),
357
+ `non-literal` (`import(x)`, `require(a + b)`, and an escaped or empty static
358
+ specifier such as `import '\u0061'`; recorded as `import(<non-literal>)`,
359
+ `require(<non-literal>)`, `import <non-literal>` or `export <non-literal>`), `outside-repo` (the
360
+ target leaves the repo root, or is an absolute or drive path),
361
+ `package-imports` (a `#` specifier) and `not-scanned` (the file itself was
362
+ skipped: the specifier reads `<not scanned: larger than 1 MiB>` or
363
+ `<not scanned: unreadable>`).
364
+ - **External specifiers** (node builtins, `node:` URLs, dependencies) are
365
+ neither edges nor unresolved. They are counted in one note in
366
+ `limits.reasons`.
367
+ - **`edgesComplete`.** `edges.unreadLanguages` lists the file extension of
368
+ every counted language the pass does not read (`go`, `py`, `rs`, `vue`, …).
369
+ These are extensions, whereas `languages[].name` holds display names
370
+ (`Go`, `Python`); a consumer must join on the extension, not the name.
371
+ A non-empty list makes `edgesComplete(edges)` false, so an empty edge list
372
+ for such a repo never reads as a clean bill. Consumers must call
373
+ `edgesComplete`, never read `collected` alone.
374
+ - **Metadata files** (`package.json`, `pnpm-workspace.yaml`, `.gitattributes`,
375
+ `CODEOWNERS`) are never read through a symlink; a link is noted and skipped.
376
+ - **Packages.** Every `package.json` the walk reaches is a package: a repo with no
377
+ workspaces has one at `"."`. Names are exactly as written, scope included; a
378
+ manifest with no `name` is reported under its directory path (the root
379
+ directory's basename for `"."`). Workspace `!` exclusions from `workspaces`
380
+ (array or `{packages}`) and `pnpm-workspace.yaml` are honoured, with full glob
381
+ syntax (`*`, `**`, `?`, `[..]`, `{a,b}`); include globs add nothing the walk
382
+ has not already found.
383
+ - **Languages** by extension (file counts), **build markers** (`package.json`,
384
+ `nx.json`, `turbo.json`, `go.mod`, `Cargo.toml`, `pom.xml`, `build.gradle*`,
385
+ `pyproject.toml`, `Makefile`).
386
+ - **Generated** paths: root `.gitattributes` `linguist-generated`, `@generated`
387
+ in the first 5 lines of a source file, and gitignored `dist/` or `build/`.
388
+ - **dontTouch**: `--dont-touch` plus literal anchored `CODEOWNERS` paths
389
+ (`.github/CODEOWNERS`, then `CODEOWNERS`, then `docs/CODEOWNERS`; the first found is read), reported with their
390
+ owners and never turned into a rule. Glob and unanchored CODEOWNERS patterns
391
+ cannot be a path, so they are skipped and noted in `limits.reasons`.
392
+ `limits.reasons` may carry `note:` lines (an unreadable directory, an
393
+ unnamed package, a pattern that does not compile) while `truncated` is
394
+ `false`; only a tripped cap sets `truncated`.
395
+
396
+ ### `hexagen slice` and `hexagen contract`
397
+
398
+ Bind work to part of a repo you do not control, then gate it. Both read the
399
+ `.hexagen/observed.json` that `hexagen observe` wrote, so run `observe` first
400
+ (and again after the repo moves). Neither runs `adopt`, `bootstrap`, `sync` or
401
+ `hexagen-lint`, and neither needs a manifest. Every command takes
402
+ `--root <dir>` (default cwd, never searched upward, must be the repo top level).
403
+
404
+ ```bash
405
+ npx hexagen observe --out .hexagen/observed.json --yes
406
+ npx hexagen slice init --path src/billing/ --exclude src/billing/generated/ --yes
407
+ npx hexagen slice check # drift report
408
+ npx hexagen contract propose # candidate rules; writes nothing
409
+ npx hexagen contract propose --closed # one candidate `closed` rule instead
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
412
+ npx hexagen contract check # gate; exit 1 on a new violation
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>"
416
+ ```
417
+
418
+ **`slice`** writes `.hexagen/slice.json`.
419
+
420
+ - `slice init --path <p>… [--exclude <p>…] [--id <id>] [--by <who>]`. Each entry
421
+ must pass the slice-path rules (a trailing `/` is a directory prefix, anything
422
+ else is one file). `--id` matches `[A-Za-z0-9._-]{1,64}` without `..` and
423
+ defaults to a random slug. `repo.commit` is `HEAD` and `repo.remote` is
424
+ `origin` with credentials stripped. `createdBy` is `--by`, else
425
+ `git config user.email`. It never overwrites an existing slice.
426
+ - `slice show` prints the slice.
427
+ - `slice check` reports drift (exit 1): a `paths` entry that matches no file; a
428
+ file under the slice changed between `repo.commit` and `HEAD` (`excludes`
429
+ applied; uncommitted working-tree edits are not drift, only commits since
430
+ `repo.commit` are); and incomplete edges (`edgesComplete` is false: an unread
431
+ language, or edges not collected), which are never clean. An `excludes` entry
432
+ that matches no file only gets a `note:` line. Observed edges that cross the
433
+ slice boundary are always listed (`leaves` and `enters`, with counts; a
434
+ package-root target is judged with excludes first, under both spellings) but
435
+ fail the check only with `--closed`. `--strict` is described below.
436
+
437
+ **`contract`** writes `.hexagen/contract.json`, whose `sliceId` comes from
438
+ `slice.json`.
439
+
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.
463
+ - `contract add-rule --kind forbid|allow-only --from <prefix> --to <prefix>
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
490
+ `from` prefix to its `to` prefix. An `allow-only` rule fails on an edge from
491
+ its `from` prefix to anywhere that is neither its `to` prefix nor its own
492
+ `from` prefix. A `warn` rule is printed but does not fail the check. The
493
+ built-in rule `unresolved-import` fails on **every** `unresolved` row whose
494
+ `from` is in the slice (including `not-scanned`, `package-imports` and
495
+ `non-literal`) and on every in-slice file whose extension is in
496
+ `edges.unreadLanguages` (`go`, `py`, … joined on the extension, never on the
497
+ display name), so a green result never means "the pass could not see the
498
+ imports". If edges were not collected at all the check cannot be clean (exit
499
+ code 1) and cannot be baselined. `--baseline` writes the current failing violations
500
+ to `knownViolations` (keeping any `reason`/`expires` already there) and needs
501
+ `--yes`; without it, any violation not in the baseline names its rule, file
502
+ and specifier and exits 1. A known violation is matched on rule, file and
503
+ specifier, and an entry whose `expires` date has passed (inclusive to the end
504
+ of that UTC day) no longer hides its violation. A root-package target (`.`)
505
+ is never inside a `to` prefix, so it always violates an `allow-only` rule.
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
+
568
+ **Concurrent edits.** `add-rule` and `check --baseline` (with `--yes`) hold
569
+ `.hexagen/contract.json.lock`, created exclusively with the process id inside,
570
+ while they read and rewrite `contract.json`, and remove it when they finish. If
571
+ the lock is already there they exit 2 ("another contract command is running").
572
+ A lock left behind by a killed command is never broken automatically: delete
573
+ the file yourself. A `knownViolations[].expires` that is not a real calendar
574
+ date is refused at load (exit 2).
575
+
576
+ **Writes.** `slice init`, `contract add-rule` and `contract check --baseline`
577
+ print a `will write:` line for each file, including the git exclude file when
578
+ `.hexagen/` is not yet in it, and write nothing without `--yes` (exit 2). The
579
+ exclude is updated first (a failure stops the command), then the file is written
580
+ as a temp file plus a link (a new file, never replacing one) or a rename (an
581
+ update of `contract.json`). The client's `.gitignore` is never edited, and
582
+ `git add -f` can still stage `.hexagen/`.
583
+
584
+ **Stale inputs.** `observed.json` must exist and its `repo.commit` must be the
585
+ slice's `repo.commit` or a descendant of it. If it was read at a commit other
586
+ than `HEAD` the commands warn, and with `--strict` fail.
587
+
588
+ **Exit codes** (`slice check`, `contract check`, `contract propose`):
589
+
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` |
595
+
596
+ `init`, `add-rule`, `show` and `--baseline` return 0 on success and 2 otherwise.
597
+
598
+ ---
599
+
600
+ ### `hexagen workbook export`
601
+
602
+ Two separate modes:
603
+
604
+ - `--out` creates one new file under `.hexagen/` in the working tree. It changes
605
+ nothing else.
606
+ - `--stage` changes the git index and nothing else: it writes no file and
607
+ never commits.
608
+
609
+ ```bash
610
+ # the bundle: one new file under .hexagen/, never overwritten
611
+ npx hexagen workbook export --out .hexagen/workbook.zip [--root <dir>] [--key-file <path>] [--engagement <id>]
612
+
613
+ # the only way anything from .hexagen/ reaches the client's history (BW-D1)
614
+ npx hexagen workbook export --stage .hexagen/slice.json .hexagen/contract.json # prints the diff, stages nothing
615
+ npx hexagen workbook export --stage .hexagen/slice.json .hexagen/contract.json --yes # git add -f on exactly those files
616
+ ```
617
+
618
+ **Bundle.** `bundle.json` (the index, with an HMAC from the engagement key,
619
+ resolved the same way as `grant` and `evidence pack`), `observed.json`,
620
+ `slice.json`, `contract.json` (the last two optional; `slice.json` is required),
621
+ `grants/<id>.json` (every grant in `.hexagen/grants/`, byte for byte, each
622
+ signature verified first), `proposals/<id>.patch` and `<id>.json`, the packed
623
+ evidence (`evidence/trace.jsonl`, `evidence/verdicts.json`, with the denials in
624
+ `verdicts.json`) and `tip.json`. Export runs the `evidence pack` logic, so a
625
+ broken chain, a truncated tail or a bad grant fails the export (exit 1, nothing
626
+ written) and the anchored tip advances as it does for `evidence pack`, even when
627
+ the final bundle write then fails.
628
+
629
+ **Allow-list.** The bundle is built from named files only; nothing else in
630
+ `.hexagen/` is read. A key or env file is never included: `grant-signing.key`,
631
+ any `*.key`, anything under `keys/` or `~/.hexagen/keys/`, any `.env*`. The
632
+ check runs on the source path and again on the bundle path. A key or env file
633
+ found inside `.hexagen/grants/` or `.hexagen/proposals/` refuses the whole
634
+ export (exit 2); a symlink there is refused too.
635
+
636
+ **`--out`** must resolve under `<root>/.hexagen/`, not under `evidence/`, and must
637
+ not exist; the bundle is written to a temporary file and hard-linked.
638
+
639
+ **`--stage`** accepts only allow-listed `.hexagen/` files (`observed.json`,
640
+ `slice.json`, `contract.json`, `grants/*.json`, `proposals/*.patch|json`,
641
+ `evidence/trace.jsonl`, `evidence/tip.json`). Without `--yes` it prints the
642
+ unified diff and stages nothing. With `--yes` it runs `git add -f` on exactly
643
+ those files; it never commits. One refused path (a key, a file off the list, a
644
+ path outside `.hexagen/`, a symlink) refuses the whole call and stages nothing.
645
+
646
+ | Code | Meaning |
647
+ | ---- | -------------------------------------------------------------------------------------------- |
648
+ | 0 | Bundle written, or the stage diff printed / files staged |
649
+ | 1 | A grant signature, the trace chain or the anchored tip is invalid; nothing written |
650
+ | 2 | Bad input or refused: a bad `--out`, an existing file, a key or off-list path, no slice, ... |
651
+
652
+ ---
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
+
55
783
  ---
56
784
 
57
785
  ## Programmatic Usage
@@ -218,6 +946,7 @@ The source `packages/sync/package.json` is never mutated by this process.
218
946
  - **HexaGen Monaco repository:** https://github.com/martinkrakowski/hexagen-monaco
219
947
  - **Architecture Decision Record:** [`ADR-0068`](../../.architecture/decisions/ADR-0068-published-cli-bundling.md) — CLI Bundling Strategy
220
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
221
950
  - **Issue tracker:** https://github.com/martinkrakowski/hexagen-monaco/issues
222
951
 
223
952
  ---