@ligeti/shell 1.2.0 → 1.4.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 (89) hide show
  1. package/README.md +58 -0
  2. package/dist/bin-resolve.d.ts +5 -0
  3. package/dist/bin-resolve.d.ts.map +1 -1
  4. package/dist/bin-resolve.js +12 -3
  5. package/dist/bin-resolve.js.map +1 -1
  6. package/dist/cli/config.d.ts.map +1 -1
  7. package/dist/cli/config.js +2 -3
  8. package/dist/cli/config.js.map +1 -1
  9. package/dist/cli/installed-versions.d.ts +9 -0
  10. package/dist/cli/installed-versions.d.ts.map +1 -0
  11. package/dist/cli/installed-versions.js +50 -0
  12. package/dist/cli/installed-versions.js.map +1 -0
  13. package/dist/cli/plugin.d.ts +13 -0
  14. package/dist/cli/plugin.d.ts.map +1 -0
  15. package/dist/cli/plugin.js +188 -0
  16. package/dist/cli/plugin.js.map +1 -0
  17. package/dist/cli/pre-push.d.ts +12 -0
  18. package/dist/cli/pre-push.d.ts.map +1 -0
  19. package/dist/cli/pre-push.js +56 -0
  20. package/dist/cli/pre-push.js.map +1 -0
  21. package/dist/cli/share-dir.d.ts +3 -0
  22. package/dist/cli/share-dir.d.ts.map +1 -0
  23. package/dist/cli/share-dir.js +13 -0
  24. package/dist/cli/share-dir.js.map +1 -0
  25. package/dist/cli/steps.d.ts +16 -0
  26. package/dist/cli/steps.d.ts.map +1 -0
  27. package/dist/cli/steps.js +102 -0
  28. package/dist/cli/steps.js.map +1 -0
  29. package/dist/cli/version.d.ts +6 -0
  30. package/dist/cli/version.d.ts.map +1 -0
  31. package/dist/cli/version.js +14 -0
  32. package/dist/cli/version.js.map +1 -0
  33. package/dist/cli.d.ts.map +1 -1
  34. package/dist/cli.js +36 -4
  35. package/dist/cli.js.map +1 -1
  36. package/dist/installed-steps.d.ts +8 -0
  37. package/dist/installed-steps.d.ts.map +1 -0
  38. package/dist/installed-steps.js +90 -0
  39. package/dist/installed-steps.js.map +1 -0
  40. package/dist/settings.d.ts +1 -0
  41. package/dist/settings.d.ts.map +1 -1
  42. package/dist/settings.js +4 -0
  43. package/dist/settings.js.map +1 -1
  44. package/dist/workers.d.ts +4 -1
  45. package/dist/workers.d.ts.map +1 -1
  46. package/dist/workers.js +59 -3
  47. package/dist/workers.js.map +1 -1
  48. package/package.json +10 -9
  49. package/share/.claude-plugin/marketplace.json +14 -0
  50. package/share/plugins/ligeti/.claude-plugin/plugin.json +6 -0
  51. package/share/plugins/ligeti/README.md +31 -0
  52. package/share/plugins/ligeti/docs/attestation.md +590 -0
  53. package/share/plugins/ligeti/docs/shell.md +442 -0
  54. package/share/plugins/ligeti/docs/troubleshooting.md +28 -0
  55. package/share/plugins/ligeti/references/rules.md +93 -0
  56. package/share/plugins/ligeti/skills/authoring-steps/SKILL.md +149 -0
  57. package/share/plugins/ligeti/skills/authoring-workflows/SKILL.md +146 -0
  58. package/share/plugins/ligeti/skills/installing-workflows/SKILL.md +121 -0
  59. package/share/plugins/ligeti/skills/onboard/SKILL.md +290 -0
  60. package/share/plugins/ligeti/skills/onboard/assets/ligeti-verify-attestation.github.yml +66 -0
  61. package/share/plugins/ligeti/skills/onboard/assets/ligeti-verify-attestation.yml +69 -0
  62. package/share/plugins/ligeti/skills/onboard/assets/pre-push.sh +11 -0
  63. package/share/plugins/ligeti/skills/scheduling-workflows/SKILL.md +102 -0
  64. package/share/plugins/ligeti/skills/troubleshooting/SKILL.md +94 -0
  65. package/share/plugins/ligeti/templates/step/.prettierignore +3 -0
  66. package/share/plugins/ligeti/templates/step/README.md +52 -0
  67. package/share/plugins/ligeti/templates/step/eslint.config.js +105 -0
  68. package/share/plugins/ligeti/templates/step/package.json +52 -0
  69. package/share/plugins/ligeti/templates/step/src/index.ts +3 -0
  70. package/share/plugins/ligeti/templates/step/src/settings.ts +27 -0
  71. package/share/plugins/ligeti/templates/step/src/tool-version.ts +61 -0
  72. package/share/plugins/ligeti/templates/step/test/rules.test.ts +144 -0
  73. package/share/plugins/ligeti/templates/step/test/settings.test.ts +30 -0
  74. package/share/plugins/ligeti/templates/step/test/tool-version.feature +32 -0
  75. package/share/plugins/ligeti/templates/step/tsconfig.build.json +26 -0
  76. package/share/plugins/ligeti/templates/step/tsconfig.json +21 -0
  77. package/share/plugins/ligeti/templates/workflow/.prettierignore +3 -0
  78. package/share/plugins/ligeti/templates/workflow/README.md +56 -0
  79. package/share/plugins/ligeti/templates/workflow/eslint.config.js +99 -0
  80. package/share/plugins/ligeti/templates/workflow/package.json +46 -0
  81. package/share/plugins/ligeti/templates/workflow/src/workflow.ts +72 -0
  82. package/share/plugins/ligeti/templates/workflow/test/__snapshots__/workflow.test.ts.snap +132 -0
  83. package/share/plugins/ligeti/templates/workflow/test/rules.test.ts +160 -0
  84. package/share/plugins/ligeti/templates/workflow/test/template-workflow.feature +31 -0
  85. package/share/plugins/ligeti/templates/workflow/test/workflow.test.ts +64 -0
  86. package/share/plugins/ligeti/templates/workflow/tsconfig.build.json +26 -0
  87. package/share/plugins/ligeti/templates/workflow/tsconfig.json +21 -0
  88. package/share/scripts/pre-push-gate.sh +308 -0
  89. package/share/scripts/pre-push-lib.sh +64 -0
@@ -0,0 +1,590 @@
1
+ # The local-verification gate
2
+
3
+ Ligeti can run a target project's checks on the developer's machine and produce a signed
4
+ attestation bound to the commit. That project's CI then verifies the attestation and runs
5
+ nothing else.
6
+
7
+ The motivation is an agent workflow's iteration cost: discovering a lint or test failure only
8
+ after pushing pays a full CI round trip and a context switch per iteration. Running the checks
9
+ locally, inside the workflow, lets a failure be repaired in the same context that produced it.
10
+
11
+ This is a capability Ligeti applies to **any** target repository, not a CI arrangement for Ligeti
12
+ itself. Only the configuration is per-project; the runner, the signer and the verifier are
13
+ universal.
14
+
15
+ ## What is and is not proven
16
+
17
+ **No scheme can cryptographically prove that the checks ran and succeeded** on a machine the
18
+ verifier does not control. A signature proves that an entity holding key K asserted a payload; it
19
+ says nothing about whether the assertion is true. Proving execution would need re-execution by
20
+ the verifier, or hardware remote attestation. Neither is in scope.
21
+
22
+ Verifiable, with zero execution in CI:
23
+
24
+ | Claim | Mechanism |
25
+ | -------------------------------- | --------------------------------------------------------------------------------- |
26
+ | Who attested | signature over the envelope, against a public key committed in the target repo |
27
+ | Payload unaltered since signing | signature |
28
+ | Bound to this exact commit | the SHA inside the signed payload equals the merge request's head SHA |
29
+ | The rules were the reviewed ones | CI recomputes the gate config's sha256 from `git cat-file` at that commit |
30
+ | The required set is complete | required checks are read from the repo at that commit, never from the attestation |
31
+ | Freshness | `verifiedAt` against the config's `maxAgeHours` |
32
+
33
+ **Not verifiable: that the checks ran, or that they passed.** That is the standing assumption, and
34
+ it is written down here rather than left implicit.
35
+
36
+ ## The boundary this draws
37
+
38
+ The boundary is **the agent, not the developer**; the full security posture -- what a worker and a
39
+ spawned agent can and cannot do, and why the attestation gate cannot be forged with the callback
40
+ token -- is in [`docs/trust-model.md`](trust-model.md), not restated here.
41
+
42
+ ### The one escalation to be aware of
43
+
44
+ A gate's checks are commands declared in the target repo's gate config, which is a file the agent
45
+ can edit. The shell executes them. Relative to a sandboxed agent, that is a local privilege
46
+ escalation: the agent chooses what the shell runs.
47
+
48
+ Two things contain it, neither of which is a substitute for knowing it is there:
49
+
50
+ - Each check runs in an explicit environment -- the minimal OS variables plus exactly the variables
51
+ _that check_ declares in `requires.env`, so a token one check needs is not visible to the others -- with the callback and attest secrets, the derived keys
52
+ and the database URL denied unconditionally. A check cannot read the signing key's path.
53
+ - CI's drift guard (below) fails a merge request whose gate config differs from the target
54
+ branch's without a human-review label, so a modified gate config cannot be merged unnoticed.
55
+
56
+ ## The pieces
57
+
58
+ | Concern | Scope | Runs where |
59
+ | --------------------------------- | --------------------------------------------- | --------------------------------------- |
60
+ | What the checks are | **per-project**, committed in the target repo | -- |
61
+ | Executing the checks | universal | shell, on the developer's machine |
62
+ | Building the manifest and signing | universal | shell; the key never enters a child env |
63
+ | Publishing, keyed by commit SHA | universal, plus a store adapter | a step |
64
+ | Verifying | universal | the target repo's CI |
65
+
66
+ **The shell executes the gate itself** rather than accepting a step's report of it. A step runs in
67
+ a worker that can write the database directly, so a verdict assembled from step output would sit
68
+ inside the trust boundary it exists to defend.
69
+
70
+ **Signing and publishing are split.** Because the envelope is signed, the publication channel need
71
+ not be trusted: a dishonest publisher can withhold or corrupt an attestation -- both surface in CI
72
+ as "missing or invalid" -- but cannot forge one. Keeping them together would require the shell to
73
+ hold write credentials for every target project's registry, a far broader secret than a signing
74
+ key.
75
+
76
+ ## Formats
77
+
78
+ The envelope is [DSSE](https://github.com/secure-systems-lab/dsse), carrying an
79
+ [in-toto Statement v1](https://github.com/in-toto/attestation/blob/main/spec/v1/statement.md)
80
+ whose subject digest is the `gitCommit` of the attested commit, and whose predicate type is
81
+ `https://gitlab.com/nagyv-projects/ligeti/attestations/gate/v2`. Signatures are Ed25519.
82
+ The predicate records the merge-base the gate diffed against, `mergeBase` (see
83
+ [Checks that run only when their files changed](#checks-that-run-only-when-their-files-changed)).
84
+
85
+ Using DSSE rather than a bespoke envelope means unambiguous signed bytes, existing verifiers, and
86
+ an open path to short-lived signing certificates later. Per the DSSE specification a signature's
87
+ `keyid` is an unauthenticated hint, so verification tries every public key the target repo lists
88
+ regardless of what `keyid` claims.
89
+
90
+ ## Setting it up for a target repository
91
+
92
+ The [`ligeti`](../plugins/ligeti/README.md) Claude Code plugin's `onboard` skill walks a GitLab or
93
+ GitHub repository through these steps, the pre-push hook and the CI change.
94
+
95
+ 1. Generate a signing key on the developer machine:
96
+
97
+ ```
98
+ npx --yes --package=@ligeti/attest@<version> ligeti-attest keygen --out ~/.ligeti/attest-key.pem
99
+ ```
100
+
101
+ where `<version>` is the `@ligeti/attest` version `ligeti --version` prints.
102
+
103
+ From a checkout of this repository, `pnpm attest keygen --out <path>` does the same.
104
+
105
+ It writes the private key `0600`, refuses to overwrite an existing file, and prints the public
106
+ key and its keyid.
107
+
108
+ 2. Configure the shell with `LIGETI_ATTEST_SECRET` and `LIGETI_ATTEST_KEY_FILE`. Both or neither:
109
+ setting exactly one fails at startup rather than silently disabling attestation.
110
+
111
+ 3. Commit a gate config to the target repo at `.ligeti/gate.json`, listing the public key from
112
+ step 1 under `attestors` and the project's checks. A check declares its command as an argv
113
+ array (there is no shell, so nothing to quote against), whether it is `required`, a timeout,
114
+ and any prerequisites:
115
+
116
+ ```json
117
+ {
118
+ "version": 1,
119
+ "attestors": [
120
+ { "name": "laptop", "keyid": "...", "publicKey": "-----BEGIN PUBLIC KEY-----\n..." }
121
+ ],
122
+ "maxAgeHours": 24,
123
+ "checks": [
124
+ { "id": "lint", "command": ["pnpm", "lint"], "required": true, "timeoutSeconds": 600 },
125
+ {
126
+ "id": "test",
127
+ "command": ["pnpm", "test"],
128
+ "required": true,
129
+ "timeoutSeconds": 1800,
130
+ "requires": { "binaries": ["bd"], "env": ["LIGETI_TEST_DATABASE_URL"] }
131
+ }
132
+ ]
133
+ }
134
+ ```
135
+
136
+ A check whose prerequisites are unmet reports `skipped_unmet_prerequisites` and its command is
137
+ never executed, and a _required_ check in that status **fails** the gate -- so the suite cannot
138
+ be turned green by uninstalling a tool. `requires.env` doubles as the allow-list for the check's own environment, so a
139
+ check that needs a variable must declare it in this reviewed, checksummed file, and no other
140
+ check sees it.
141
+
142
+ A check may also declare `"fixedBy": "agent" | "human"` (default `"agent"`): who can resolve its
143
+ failure. `"human"` marks a check an agent cannot fix, such as one that needs an encrypted secret
144
+ or credentials, so a workflow that hands failed gates to an agent sends that failure straight to a
145
+ human. The runner ignores the field; it is metadata for workflows. A repository that declares it
146
+ needs `@ligeti/attest` >= 1.1.0 on the verifier side, because the check schema is strict and an
147
+ older `verify-attestation` rejects the unknown key.
148
+
149
+ A check may also declare `"paths"`, an array of globs, to run only when a changed file matches;
150
+ see [Checks that run only when their files changed](#checks-that-run-only-when-their-files-changed).
151
+ A repository that declares it needs `@ligeti/attest` >= 2.0.0 on the verifier side (which also
152
+ brings `gate/v2`): the check schema is strict, so an older `verify-attestation` rejects the
153
+ unknown key, as with `fixedBy`. Globs are matched whole, so a bare `docs` matches only a file
154
+ named `docs`; write `docs/**` for the directory.
155
+
156
+ 4. Before opening a merge request, run the gate and publish its attestation with the
157
+ `attest-and-publish` workflow (`workflows/attest-and-publish`): it runs `attest.gate` and, only
158
+ when the gate passes, the publish step of the attestation store (see
159
+ [Where attestations are stored](#where-attestations-are-stored)). Start `ligeti serve` with
160
+ `LIGETI_ATTEST_SECRET`/`LIGETI_ATTEST_KEY_FILE` (the key from step 1) and, for the GitLab
161
+ registry store, `GITLAB_TOKEN` configured (`attest-and-publish` is one of the default
162
+ workflows, offered while `LIGETI_WORKFLOWS` is unset), then run
163
+ `ligeti run --wait attest-and-publish`, which reads its input from stdin:
164
+
165
+ ```json
166
+ {
167
+ "repoPath": "/path/to/repo",
168
+ "commit": "<sha>",
169
+ "projectUrl": "https://gitlab.com/group/project"
170
+ }
171
+ ```
172
+
173
+ `projectUrl` is for the GitLab registry. For a repository whose `origin` is not on `gitlab.com`
174
+ the workflow publishes a git note instead and needs no `projectUrl`; pass `store` to override
175
+ (see the [attest-and-publish README](../workflows/attest-and-publish/README.md#choosing-the-store)).
176
+
177
+ `ligeti run` needs none of the attest variables -- it reaches the shell over HTTP, at
178
+ the address [`ligeti run`](../packages/shell/README.md#ligeti-run) resolves (`--url`,
179
+ `$LIGETI_PUBLIC_BASE_URL`, or `http://<LIGETI_HOST>:<LIGETI_PORT>`).
180
+ Without `--wait` it returns as soon as the run has started (follow it with `ligeti trace <id>`).
181
+ A failed gate is never published -- the run still returns the predicate and its checks, but there
182
+ is nothing for CI to verify until the gate passes.
183
+
184
+ See [How a gate run works](#how-a-gate-run-works) below for what the shell does with that
185
+ request, and [The pre-push hook](#the-pre-push-hook) for how this repository runs it on every
186
+ push.
187
+
188
+ 5. Add the verification job to the target repo's CI. For GitHub, copy
189
+ `plugins/ligeti/skills/onboard/assets/ligeti-verify-attestation.github.yml` (see
190
+ [Verifying on GitHub](#verifying-on-github)). For GitLab, see
191
+ `plugins/ligeti/skills/onboard/assets/ligeti-verify-attestation.yml` for the template, including the two details most likely to break silently:
192
+ the commit under test is `CI_MERGE_REQUEST_SOURCE_BRANCH_SHA` when set and `CI_COMMIT_SHA`
193
+ otherwise (in a merged-results pipeline the latter is an ephemeral merge commit that exists on
194
+ no branch), and the target branch must be fetched explicitly, since GitLab's default clone is
195
+ shallow and single-branch -- with enough history to compute a merge-base (see
196
+ [Verifying in a target repository](#verifying-in-a-target-repository)). The job must also fail closed: a commit with no published attestation
197
+ and a commit whose attestation fails verification are both a failed job, so the download uses
198
+ `curl --fail` rather than letting an error page reach the verifier.
199
+
200
+ ### Where attestations are stored
201
+
202
+ The envelope is signed, so the store only has to be durable, keyed by commit and readable from CI.
203
+ There are two, chosen by [ADR-0026](../adr/0026-attestations-live-in-git-notes-off-gitlab-com.md)'s
204
+ host rule:
205
+
206
+ - **`gitlab-registry`**: the GitLab project's generic package registry. Used when the remote's host
207
+ is exactly `gitlab.com`.
208
+ - **`git-notes`**: one git note per commit on `refs/notes/ligeti-attestations`, holding the envelope's
209
+ JSON, pushed to the same remote the code goes to. Used for every other host, including a
210
+ self-hosted GitLab. It needs no forge API and no token of its own. The shell's worker pushes the
211
+ note with the environment `ligeti serve` was started with: `SSH_AUTH_SOCK`, git credential helpers
212
+ reached through `HOME`. `GITLAB_TOKEN` and `GITHUB_TOKEN` are deliberately not passed to git, so
213
+ HTTPS needs a credential helper that does not depend on an env-only token, or SSH (see the
214
+ [step's README](../steps/git-notes-attestation/README.md#credentials-and-environment)).
215
+ `steps/git-notes-attestation` publishes it from a private per-run ref and retries a push that loses
216
+ a race to another publisher; a stale note is overwritten.
217
+
218
+ `attest-and-publish` applies the rule to the `remote` input's URL (`store` overrides it), the
219
+ pre-push hook applies it to the remote being pushed to, and the GitLab CI verify job takes the store
220
+ from `LIGETI_ATTESTATION_STORE` (`gitlab-registry` or `git-notes`); the GitHub job reads notes only.
221
+ The same variable overrides the host rule in the hook, which is how a self-hosted GitLab opts into
222
+ the registry. Nothing else about a host is guessed.
223
+
224
+ ### Verifying in a target repository
225
+
226
+ A target repository's CI does not need to build Ligeti: it installs the verifier,
227
+ `@ligeti/attest`, from npmjs.org, where `scripts/publish-packages.sh` publishes it, for every target
228
+ including a self-hosted GitLab. The package is versioned and the target repository pins an exact
229
+ version. It needs no registry credentials and no `.npmrc`. Run the pinned version without installing
230
+ it into the project. The bin name differs from the package name, so `npx` needs `--package`:
231
+
232
+ ```
233
+ npx --yes --package=@ligeti/attest@2.0.0 ligeti-attest verify <flags>
234
+ ```
235
+
236
+ `--base` and the `gate/v2` predicate (statuses `skipped_unmet_prerequisites` and
237
+ `skipped_not_applicable`) need `@ligeti/attest` >= 2.0.0. An older pinned verifier rejects both.
238
+
239
+ The verify job for a GitLab target is the onboarding template
240
+ `plugins/ligeti/skills/onboard/assets/ligeti-verify-attestation.yml` (read that file for
241
+ the reasoning behind each step); the example below is its GitLab registry variant. This repository's
242
+ own jobs (`.gitlab/ci/verify-attestation.yml` and `.github/workflows/verify-attestation.yml`) differ:
243
+ they call `scripts/ci-verify-attestation.sh`. The GitLab job fetches the target branch from `origin`, except in a
244
+ fork merge request's pipeline, which runs in the fork and so fetches from the _target project's_ URL
245
+ (`$CI_MERGE_REQUEST_PROJECT_URL`); a private target project would need credentials for that fork
246
+ fetch. It fetches full blobs so the worktree checkout never needs a lazy fetch from a remote that
247
+ lacks them. The script resolves the fetched target branch to its tip sha, checks that sha out as a detached worktree,
248
+ builds the verifier there (`pnpm install --frozen-lockfile --filter . --filter @ligeti/attest`,
249
+ `tsc -p packages/attest/tsconfig.build.json`) and runs that build's `verify` against the merge
250
+ request's commit. A merge request that changes the verifier is therefore verified by the verifier it
251
+ changes _from_, and the job fails closed when the target's tip cannot build one. The attestation
252
+ is fetched from the target repository's _own_ generic registry, where `attest-and-publish`
253
+ published it:
254
+
255
+ ```yaml
256
+ verify-attestation:
257
+ image: node:22
258
+ rules:
259
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
260
+ script:
261
+ - |
262
+ set -e
263
+ SHA="${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA:-$CI_COMMIT_SHA}"
264
+ if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
265
+ git fetch --filter=blob:none --unshallow origin
266
+ fi
267
+ git fetch --filter=blob:none origin \
268
+ "+refs/merge-requests/${CI_MERGE_REQUEST_IID}/head:refs/merge-requests/${CI_MERGE_REQUEST_IID}/head" \
269
+ || echo "cannot fetch the merge request head from origin; the verifier fails closed if the merge-base is missing" >&2
270
+ git fetch --filter=blob:none origin \
271
+ "+${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}:refs/remotes/origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
272
+ curl --fail --show-error --location \
273
+ --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
274
+ --output attestation.json \
275
+ "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/ligeti-attestation/${SHA}/attestation.json"
276
+ set -- --repo "$CI_PROJECT_DIR" --commit "$SHA" \
277
+ --target-ref "refs/remotes/origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" \
278
+ --base "refs/remotes/origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" \
279
+ --envelope-file attestation.json
280
+ OLD_IFS=$IFS; IFS=','
281
+ for label in $CI_MERGE_REQUEST_LABELS; do set -- "$@" --label "$label"; done
282
+ IFS=$OLD_IFS
283
+ npx --yes --package=@ligeti/attest@2.0.0 ligeti-attest verify "$@"
284
+ ```
285
+
286
+ **Fetch depth.** `--base` needs a merge-base, so the job cannot clone with `--depth 1`. It fetches
287
+ the full commit history with `--filter=blob:none`: the verifier diffs trees (`git diff --name-only
288
+ --no-renames`), which needs commits and trees only, and reads the gate config blob at the attested
289
+ commit on demand from the promisor remote. A shallow clone has no merge-base and the verifier then
290
+ fails closed (see below). The GitHub template does the same with `fetch-depth: 0` and `filter:
291
+ blob:none`.
292
+
293
+ **Branch pipelines.** A job that also runs outside merge requests, for example on the default
294
+ branch after a push, passes `--base "$CI_COMMIT_BEFORE_SHA"` instead. GitLab sets it to all zeros
295
+ for the first push of a branch; the verifier treats that as no base.
296
+
297
+ **Releasing a new version.** The `publish-packages` CI job on the default branch publishes every
298
+ package listed in `scripts/publishable-packages.txt` whose `package.json` version is not yet on
299
+ npmjs.org, so a release is a merge request that bumps that version. The `published-versions` gate
300
+ check keeps that honest: it fails when a version already in the registry would pack to different
301
+ content (`scripts/README.md`). Consumers keep running their pinned version until they
302
+ change the pin, in a merge request of their own.
303
+
304
+ A change to the attestation format or the gate config schema is a breaking release of
305
+ `@ligeti/attest`: target repositories must bump their pin to a verifier that accepts the new shape
306
+ before they can verify what the shell then signs. This repository is held to the same order, with
307
+ "release" meaning a merge to the target branch: first a merge request makes the verifier accept the
308
+ new shape, and only once it has merged does a later one start producing it.
309
+
310
+ ### Verifying on GitHub
311
+
312
+ `plugins/ligeti/skills/onboard/assets/ligeti-verify-attestation.github.yml` is the template
313
+ for a GitHub target. A target copies it to `.github/workflows/`, and the commit it fetches is the pull request's head SHA. The job fetches
314
+ the notes ref from `origin`, reads the head commit's note, and runs the pinned `@ligeti/attest`,
315
+ installed from npmjs.org, where `scripts/publish-packages.sh` publishes it. The target pins an exact
316
+ version in the file's `LIGETI_ATTEST_VERSION` and bumps it in its own changes, as for GitLab.
317
+ It needs no registry credentials and no `.npmrc`.
318
+
319
+ For a `push` event, `--base` is `github.event.before`; for a pull request it is the base ref's tip,
320
+ as in the template.
321
+
322
+ The job reads the pull request's labels live with `gh pr view` rather than from
323
+ `github.event.pull_request.labels`: a re-run reuses the original event payload, so a
324
+ `gate-config-reviewed` label added after the first run would otherwise never be seen. That is the
325
+ one place it differs in behaviour from a naive translation of the GitLab job.
326
+
327
+ ### A workflow that gates, publishes, pushes and opens its own merge request
328
+
329
+ A workflow can also gate and publish itself rather than delegating to `attest-and-publish`, and
330
+ does not need a merge request to exist first: the software-factory workflow's `implement-bead` runs
331
+ `attest.gate` in its own review loop, against the worktree's own `HEAD` -- the implementation agent
332
+ is told to commit only, never push or open a merge request itself. Once the review converges, it
333
+ calls `gitlab-registry.publish-attestation` directly for the converged round's exact gated commit
334
+ (`minRemainingHours: 12`, matching the pre-push hook below), pushes that same commit to the step's
335
+ branch itself (`git.push`, a no-op if the branch already points at it; a non-fast-forward push is
336
+ rejected by `git.push` itself), and only then opens the merge request (`gitlab-mr.create`, which
337
+ finds the existing one instead on a replay). It waits out that merge request's pipeline for the
338
+ gated sha (`gitlab-mr.await-pipeline`) before merging synchronously with `squash: false`, so the
339
+ branch head that lands is exactly the commit that was gated. Publishing before pushing matters
340
+ because this repository's own pre-push hook fires on that push (hooks stay enabled in the
341
+ workflow's worktree): with the attestation already published, the hook finds it and only verifies,
342
+ instead of running its own multi-minute gate inside the workflow's `git.push` call. The software-factory workflow's own documentation has the full sequence, every failure path, and
343
+ the known limit of merging without squash.
344
+
345
+ ## How a gate run works
346
+
347
+ The request names a **commit** and the local **repository** it comes from -- not a working
348
+ directory whose `HEAD` happens to be the commit. For every run the shell:
349
+
350
+ 1. resolves `commit` in `repository` once (a sha, or a ref such as `HEAD`);
351
+ 2. clones `repository` into a fresh gate checkout under `$LIGETI_STATE_DIR/gate-checkouts/` and
352
+ checks that sha out, detached, with hooks switched off;
353
+ 3. reads the gate config from the commit itself;
354
+ 4. runs `pnpm install --frozen-lockfile` when the commit has a `pnpm-lock.yaml`;
355
+ 5. confirms the checkout's `HEAD` is the requested sha, runs the checks, and signs; then
356
+ 6. removes the gate checkout, whatever the outcome.
357
+
358
+ Because the gate checkout is a clone, nothing outside the commit reaches the checks: not an
359
+ uncommitted edit, not an untracked or gitignored file (a planted `node_modules/.bin/vitest`, a
360
+ stale `dist/`), and not an edit made while the gate runs. Nothing is reused between runs, so every
361
+ run is a cold build.
362
+
363
+ Every child environment -- git, pnpm and each check -- is built from the **shell's** own
364
+ environment, key by key ([ADR-0004](../adr/0004-child-processes-take-argv-and-an-explicit-environment.md)),
365
+ never from the caller's. A variable a check needs, such as this repository's
366
+ `LIGETI_TEST_DATABASE_URL` must be set where `ligeti serve` runs; exporting it in the terminal that
367
+ runs `git push` has no effect.
368
+
369
+ ### Checks that run only when their files changed
370
+
371
+ A gate check may declare `paths`, an array of globs. It runs only when at least one changed file
372
+ matches one of them; a check without `paths` runs on every gate run. Globs are
373
+ [picomatch](https://github.com/micromatch/picomatch) patterns matched against repository-relative
374
+ POSIX paths, with `dot` on: `docs/**` matches `docs/.vitepress/config.ts` and `**` matches
375
+ dotfiles. Globs match whole paths, so a bare `docs` matches only a file named `docs`; write `docs/**`
376
+ for a directory. Needs `@ligeti/attest` >= 2.0.0. The gate config is rejected when it is parsed if a
377
+ glob starts with `./` or `/` (no changed file path ever starts that way), starts with `!` (negation
378
+ is not supported; it would be literal and the check would never apply), ends with `/` (it matches
379
+ no file), or is not a valid glob. A deleted file,
380
+ and both sides of a rename, count as changed files. The changed files are those
381
+ between `merge-base(base, commit)` and `commit`, where `base` is an optional commit-ish in the gate
382
+ request naming the tip of the branch the commit will land on. One rule covers every push: a feature
383
+ branch diffs from its fork point, and a push to the default branch diffs against the remote's
384
+ current tip, so every commit of a multi-commit push counts -- not only the tip the hook gates.
385
+
386
+ **Who supplies `base`.** The pre-push hook sends `$REMOTE/HEAD` resolved to a sha, or, when that
387
+ ref is unset, the sha `git ls-remote --symref $REMOTE HEAD` reports if the commit exists locally;
388
+ otherwise it sends none. When a merge request targets a branch other than the remote's default, CI's
389
+ base (the target tip) differs from the hook's, so CI may see a wider diff than the gate did, and
390
+ a not-applicable check can fail verification until the commit is re-gated with `replace`. The factory workflows send the sha of the rebase that comes just before the
391
+ gate. Any other caller may omit it.
392
+
393
+ **A gate config change runs everything.** When the gate config itself is among the changed files,
394
+ every check applies, whatever its `paths`: a new or edited check must not be able to hide behind a
395
+ narrow glob. The verifier applies the same rule and rejects a required `skipped_not_applicable`
396
+ check when the gate config changed since the merge-base.
397
+
398
+ **Fail safe.** When `base` is absent, cannot be resolved by the shell, looks like a command-line
399
+ option (starts with `-`), or has no merge-base with `commit` (a root commit, say), every check
400
+ runs. A stale `base` yields an older merge-base and so a
401
+ wider diff, which is also safe.
402
+
403
+ **Statuses.** A check whose `paths` match no changed file is not executed and reports
404
+ `skipped_not_applicable`; a required check in that status does _not_ fail the gate. This is
405
+ distinct from `skipped_unmet_prerequisites`, where the prerequisites are unmet and a required check
406
+ _does_ fail. The signed predicate records the merge-base it diffed against as `mergeBase` (`null`
407
+ when every check ran), so a reader can see why a check was not applicable.
408
+
409
+ **The verifier recomputes it.** `base` is caller-supplied and an agent can move refs in its
410
+ worktree, so a narrow `base` could make a required check look not applicable. That would break the
411
+ rule that the required set comes from the repository and never from the attestation. So
412
+ `ligeti-attest verify --base <ref>` computes `merge-base(base, commit)` itself for every required
413
+ `skipped_not_applicable` check and fails (check `applicability`) if a file changed since then
414
+ matches the check's `paths` in the gate config at the commit. It never trusts the recorded
415
+ `mergeBase`. With no usable base -- absent, unresolvable, an all-zero sha, starting with `-`, no
416
+ merge-base, or too shallow a clone -- any required `skipped_not_applicable` check fails verification. An attestation is
417
+ keyed by commit alone, so this is also what stops one signed against a narrow base from being
418
+ reused for a merge request with a wider range. In the pre-push hook an `applicability` failure
419
+ counts as failing beyond freshness, so the hook re-gates and replaces the attestation.
420
+
421
+ **Upgrade order.** `POST /attest` and the `attest.gate` input are strict, so a shell that predates
422
+ `base` answers 400 to a request carrying it: upgrade the shell before the workflows that send it.
423
+
424
+ ### The residual risk: install scripts
425
+
426
+ `pnpm install` runs package lifecycle scripts -- the target repository's own `preinstall`,
427
+ `install`, `postinstall` and `prepare`, and those of any dependency the lockfile allows to build.
428
+ They run with the shell's user and filesystem access, in the minimal OS environment (no `LIGETI_*`
429
+ variable, no GitLab token), before any check. That is the same trust the checks themselves get --
430
+ the gate config already chooses what the shell runs -- but it is not governed by the gate config,
431
+ so it is written down here rather than left implicit.
432
+
433
+ ## The pre-push hook
434
+
435
+ A target repository gates from the hook the `onboard` skill installs, which runs
436
+ `ligeti pre-push "$@"` and fails with ``install Ligeti with `npm install -g @ligeti/shell` and push
437
+ again`` when `ligeti` is not on `PATH`. `ligeti pre-push` runs the gate script shipped in
438
+ `@ligeti/shell`'s share directory (`scripts/pre-push-gate.sh`) in the pushing terminal's own
439
+ environment, because the gate reads `GITLAB_TOKEN`, `glab`'s config through `HOME`,
440
+ `SSH_AUTH_SOCK`, `LIGETI_PUBLIC_BASE_URL` and `LIGETI_ATTESTATION_STORE` exactly as a hook sees them
441
+ ([ADR-0030](../adr/0030-the-ligeti-plugin-and-the-pre-push-gate-ship-in-the-shells-share-directory.md)).
442
+ This repository gates from `githooks/pre-push` (install with `git config core.hooksPath githooks`),
443
+ which runs the same script from the checkout. For each ref being pushed the gate skips deletes
444
+ and anything outside `refs/heads/*`, checks each distinct sha once, and:
445
+
446
+ 1. fetches the sha's attestation from the attestation store (see below) and runs `ligeti-attest verify`
447
+ with `--no-drift-guard` (there is no merge request, so no target branch, at push time),
448
+ `--min-remaining-hours 12` and `--base` set to the [push's base](#checks-that-run-only-when-their-files-changed)
449
+ when it has one. If it passes, the sha is done. An attestation with less remaining
450
+ lifetime could expire before the merge request's pipeline verifies it, so it is replaced now
451
+ rather than rejected later. An existing attestation that fails verification for any reason other
452
+ than freshness (a bad signature, a wrong commit, a `verifiedAt` in the future beyond the clock-skew
453
+ allowance) is re-gated and replaced too.
454
+ 2. Otherwise it asks the shell at `$LIGETI_GATE_BASE_URL`, which `ligeti pre-push` sets from the
455
+ caller's environment and `.env` the way `ligeti run` finds the shell (else `$LIGETI_PUBLIC_BASE_URL`,
456
+ default `http://127.0.0.1:8100`), to
457
+ run `attest-and-publish` for that sha, with `minRemainingHours: 12` and the same `base` (and `replace: true` when the
458
+ existing attestation failed verification beyond freshness), and then verifies again.
459
+ 3. Any failure refuses the push, naming the failed check. For a gate that failed, the hook also
460
+ prints each failed gate check's stderr (truncated, see the
461
+ [attest-and-publish README](../workflows/attest-and-publish/README.md)), the id of the
462
+ attest-and-publish run, and the `ligeti trace <runId>` command that shows the full output.
463
+
464
+ The hook applies the same host rule to the remote it is pushing to: `gitlab.com` uses the GitLab
465
+ package registry as above; any other host uses git notes (`LIGETI_ATTESTATION_STORE=gitlab-registry`
466
+ or `git-notes` overrides it, e.g. for a self-hosted GitLab). With git notes there is no token and no
467
+ forge API: step 1 is `git fetch <remote> +refs/notes/ligeti-attestations:refs/notes/ligeti-attestations`
468
+ followed by `git notes --ref=ligeti-attestations show <sha>`, where a missing ref or note means "not
469
+ attested yet", and the workflow pushes the note to that same remote. The push must name its remote
470
+ (`git push origin`, not `git push <url>`), because the note is published to a remote by name. A
471
+ remote that really is gitlab.com under another name (an SSH host alias such as
472
+ `git@gitlab-work:group/p.git`) resolves to git notes, and the hook prints a notice saying so. Set
473
+ `LIGETI_ATTESTATION_STORE=gitlab-registry` for the hook there; otherwise the merge request's registry
474
+ verify job finds no attestation (404).
475
+
476
+ With no shell answering, the hook refuses and prints the `ligeti run --wait` command to run by hand. It
477
+ reads the registry store with `GITLAB_TOKEN` or `GITLAB_ACCESS_TOKEN` from the pushing terminal, or
478
+ with the token `glab` has stored for the GitLab host; the notes store needs neither.
479
+
480
+ `ligeti pre-push` hands the script the installed `ligeti-attest` and `ligeti` CLIs through
481
+ `LIGETI_GATE_ATTEST_CLI` and `LIGETI_GATE_LIGETI_CLI`, and the node running `ligeti` through
482
+ `LIGETI_GATE_NODE`. Without them, which is how
483
+ `githooks/pre-push` runs it, the script uses the CLIs built in the checkout the hook belongs to --
484
+ for a linked worktree, that worktree's own checkout, which normally has no build of its own (`dist/`
485
+ is gitignored and a worktree add only ever materializes tracked files). When that checkout has no
486
+ build, the script falls back to the repository's main checkout instead, found through
487
+ `git rev-parse --git-common-dir`'s parent -- the one checkout `pnpm build` is ordinarily run in.
488
+ The worktree's own build wins whenever it is present. When neither checkout has one, the hook
489
+ refuses with a `run \`pnpm build\`` error.
490
+
491
+ The hook is a convenience, not enforcement: `git push --no-verify` skips it, and CI's
492
+ `verify-attestation` job is what refuses an unattested merge request.
493
+
494
+ A linked worktree shares its main checkout's `core.hooksPath` by default, so this hook fires there
495
+ too, including on a coding agent's own commits, and on a workflow's own push of a commit it gated
496
+ itself (implement-bead, see above). That workflow publishes the attestation for the gated sha
497
+ before its own `git.push`, so by the time the pre-push hook runs it finds a fresh attestation
498
+ already on the registry and only verifies -- step 1 above passes and steps 2-3 never run. Hooks are
499
+ not disabled in a workflow worktree; the multi-minute gate never re-runs inside that `git.push`
500
+ call because the hook's own check is cheap once the attestation is already there.
501
+
502
+ The software-factory workflow's spec phase and the whole of small-factory are different: nothing
503
+ publishes an attestation for their commits ahead of time, so their own `pushBranch`'s `git.push`
504
+ call (`steps/git-worktree/src/push.ts` underneath) runs the target repository's pre-push hook and
505
+ its own fallback gate in full every time -- not the rare case, since step 1 always fails for want
506
+ of an attestation and steps 2-3 always run. The exception is each workflow's first push, of the
507
+ branch still exactly at its base: it passes `noVerify`, because that commit was gated before it
508
+ became the base. `git.push` gives the underlying `git push` a 25-minute
509
+ timeout, comfortably above the fallback gate's observed worst case, and passes
510
+ only the env vars `LIGETI_STEP_GIT_PUSH_ENV` names through to it; for this repository's hook that
511
+ is `GITLAB_TOKEN,LIGETI_PUBLIC_BASE_URL`, so it can reach the registry and the shell from inside a
512
+ worker process with no interactive `glab` login of its own (`steps/git-worktree/README.md`). CI's
513
+ `verify-attestation` job still enforces the gate on any merge request built from those commits regardless; the software-factory parent workflow attests
514
+ the specification branch's own head before marking the spec MR ready.
515
+
516
+ ### A stale attestation is replaced
517
+
518
+ With the notes store, `git-notes-attestation.publish` overwrites a stale note itself. The rest of
519
+ this section is the registry store.
520
+
521
+ GitLab keeps one generic package per sha and rejects a second upload for the same one. When that
522
+ happens, `gitlab-registry.publish-attestation` reads the existing attestation's `verifiedAt`: if it
523
+ still has at least `minRemainingHours` (default 0) of the gate config's `maxAgeHours` left, the
524
+ publish reports `already-published`. Otherwise -- or if the existing attestation cannot be read --
525
+ it reports `stale`, and `attest-and-publish` and the software-factory workflows delete that package
526
+ with `gitlab-registry.delete-attestation` and publish again. The same delete-then-publish runs when
527
+ `replace` is true, which the pre-push hook sets for an existing attestation that fails verification
528
+ beyond freshness, so the shell's GitLab token needs permission to delete the package, not only to
529
+ write it. See
530
+ [`steps/gitlab-registry/README.md`](../steps/gitlab-registry/README.md).
531
+
532
+ ## The gate-config drift guard
533
+
534
+ The sharpest hole in the design: a merge request that flips `required: false` on the tests,
535
+ verified by a gate that reads the modified config, produces a perfectly valid signature over a
536
+ meaningless claim. Signing does nothing about this.
537
+
538
+ So the verifier compares the gate config at the commit under test with the config on the target
539
+ branch. If they differ, verification fails unless the merge request carries the review label
540
+ (`gate-config-reviewed` by default). A config absent on the target branch counts as changed.
541
+
542
+ The guard **fails closed**: omitting the target ref does not skip it, it fails. Declaring the
543
+ guard inapplicable is a separate, explicit input (`--no-drift-guard`), so a waiver has to be
544
+ written into the target repo's CI file where it is reviewable, rather than fallen into by leaving
545
+ a variable unset.
546
+
547
+ Pair it with CODEOWNERS over the gate config and any agent-instruction files. Note that CODEOWNERS
548
+ approval and a CI job are enforced independently: someone able to push directly to a protected
549
+ branch bypasses both, so the branch must also require pipelines to succeed.
550
+
551
+ ## Known limits
552
+
553
+ - **No independent escape detector.** With CI executing nothing, nothing catches a systematically
554
+ lying gate, or a darwin/arm64 pass that would have failed on linux/amd64 -- path casing, tool
555
+ version skew, line endings. The attestation records the platform it ran on, which is the only
556
+ signal available. Traded away deliberately.
557
+ - **Key scope and rotation.** One Ligeti instance signing for many repos means that key can attest
558
+ for every repo trusting it, and rotation is a merge request against each of them. Fine at three
559
+ repos, painful at thirty. The scaling answer is a short-lived signing certificate chained to a
560
+ root the repos trust; DSSE keeps that path open.
561
+ - **Attestations can vanish.** Registry cleanup policies, a project transfer or an outage produce
562
+ "no attestation for this SHA", which is indistinguishable from "never verified" -- so
563
+ verification fails closed on a missing attestation. Exclude the package from cleanup policies.
564
+ This is an operational mitigation, not an architectural one. A note vanishes only if someone
565
+ deletes `refs/notes/ligeti-attestations` from the remote.
566
+ - **Notes are invisible in GitHub's UI.** GitHub does not display notes, so a developer cannot see
567
+ from the pull request that a commit is attested, only that the verify job passed. `git fetch origin
568
+ refs/notes/ligeti-attestations:refs/notes/ligeti-attestations` and `git notes --ref=ligeti-attestations
569
+ show <sha>` read one.
570
+ - **Push access cannot forge a note, only remove one.** A rewritten note fails verification, and the
571
+ next push re-gates and replaces it. Deleting or replacing notes forces a re-gate, which costs time
572
+ and is not a bypass: a missing attestation fails closed.
573
+ - **Fork pull requests fail verification with git notes.** The hook pushes the note to the remote the
574
+ contributor pushes to, their fork, while the GitHub job fetches notes from `origin`, the base
575
+ repository. The same holds for a GitLab fork with the notes store.
576
+ - **A step's merge commit is never itself gated.** `implement-bead` merges a step's merge request
577
+ with `squash: false` so the branch head that lands is exactly the gated commit, but the merge
578
+ commit GitLab builds to combine that branch with whatever has landed on the target branch since
579
+ is never itself gated or attested -- only a fast-forward-only merge on the target project avoids
580
+ this, which is why the software-factory workflow requires it.
581
+ - **Distribution.** The verifier is published as the versioned npm package `@ligeti/attest`, which
582
+ target repositories pin (see [Verifying in a target repository](#verifying-in-a-target-repository)).
583
+ What remains: each target repository's pin is its own line, so shipping attestation format v2 is a version
584
+ bump merge request per repository, and a repository left on v1 keeps running a v1 validator. The
585
+ CI/CD component that would hold the job definition in one place is not built, and target repositories
586
+ copy the job YAML. This repository's own `verify-attestation` job builds the verifier from the
587
+ target branch's tip (`scripts/ci-verify-attestation.sh`), so a merge request that changes
588
+ `packages/attest` is verified by the verifier it changes from. The gap: the job definition
589
+ itself (both workflow files and the script) is read from the merge request, so a merge request can
590
+ still rewrite the job, and the protection there is code review of those files.