Skip to content

cryptificate init, doctor and a cryptificate.json project configuration - #12

Merged
4waan merged 13 commits into
mainfrom
feat/cli-init-doctor
Nov 11, 2026
Merged

4waan merged 13 commits into
mainfrom
feat/cli-init-doctor

Conversation

@4waan

@4waan 4waan commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Stacked on #10 (feat/ci-gate); review and merge that one first.

Summary

Adopting Cryptificate in another repository now takes three commands: cryptificate init scaffolds a checked project and its GitHub workflow, cryptificate doctor says what is missing on the machine and how to fix it, and cryptificate check with no arguments applies the project's cryptificate.json. The GitHub Action reads the same file when its inputs is empty, so one file holds the inputs, the policy and the claim scope for local runs and for CI.

The branch also fixes a bug in the action on feat/ci-gate: Actions runs a composite step's bash with -e, so when cryptificate check exited 1 (policy failed) or 2 (error), the step stopped before it wrote the SARIF and JUnit files and the exit-code / outcome outputs. The repository's own action CI job, which expects exit-code 1 for the refuted design, would have failed on that.

Review fixes on this branch: the action's SARIF locations are now relative to the repository root, also when working-directory is a subdirectory (as init writes it) or cryptificate.json is in a parent of it; a cryptificate.json without failOn gates on refuted instead of silently disabling the gate; the workflow quotes its paths for YAML and names the repository's default branch; doctor's fix commands quote paths for the shell; the usage text lists every init exit 2 case.

Base: feat/ci-gate. Twelve commits:

  1. fix: keep the action's check step going when check or report exits non-zero
  2. feat(server): check reads its inputs and policy from cryptificate.json
  3. feat: the GitHub Action reads cryptificate.json when inputs is empty
  4. feat(server): cryptificate init scaffolds a checked project and its workflow
  5. feat(server): cryptificate doctor checks the machine and prints the fixes
  6. docs: describe init, doctor and cryptificate.json
  7. fix(server): place SARIF locations from the recorded input base and the repository root
  8. fix: a cryptificate.json without failOn gates on refuted claims
  9. fix(server): init quotes workflow paths and finds the default branch
  10. fix(server): doctor quotes the paths in its fix commands
  11. docs(server): list every init exit status 2 case in the usage text
  12. docs: describe --uri-base, the recorded input base and the refuted default of cryptificate.json

What is proved / changed (precise)

No Lean code, Lean theorem, template, claim, acceptance rule or engine code changes. What a claim's status is, and how it is established, is unchanged. Nothing new is proved. The changes affect which inputs are checked and which policy applies, and they add setup tooling.

cryptificate.json and check (apps/server/src/project.ts, schemas/project-config.schema.json)

  • Keys: inputs (required), failOn, claims, target, format, output, bundleDir, $schema (ignored). Unknown keys are rejected.
  • check with no input arguments uses the nearest cryptificate.json in the working directory or a parent. --config FILE names the file explicitly; its settings then also apply to inputs given on the command line. When inputs are given without --config, no file is read, even an invalid one.
  • Relative paths in the file are resolved against the file's directory. The result's input paths and the SARIF locations are relative to that directory too. Command-line options override the file. A path given as an option stays relative to the working directory.
  • failOn defaults to refuted when a cryptificate.json is in use (found, or named with --config). Without the file the command-line default stays none.
  • A check --format json result (cryptificate-check/v1) gains an optional base field: the absolute directory its relative input paths are relative to (the config's directory, or the working directory for command-line inputs). report resolves the input paths of a saved check result against base, so it finds the files (and gives SARIF locations their line regions) from any working directory; the results it writes name the inputs relative to its own working directory. A saved result without base is read as before, relative to the working directory.
  • check, verify and report take --uri-base DIR: SARIF file locations are made relative to DIR (resolved against the working directory) instead of the working directory; a file outside it gets a file:// URI, as before.
  • An invalid file is a usage error (exit 2) that lists every problem with its JSON Pointer: invalid JSON, an unknown key, a wrong type or value, an unknown or duplicated claim id. A test checks that the schema's keys and enums equal the validator's (FAIL_ON, formats, targets, every known claim id).
  • verify and report do not read the file.

Action (action.yml)

  • inputs is no longer required. When it is empty, the action runs check without inputs, so the inputs come from cryptificate.json. The action still passes --format json --output … --bundle-dir …, which replace the file's format, output and bundleDir.
  • fail-on now defaults to empty. With empty inputs the action passes no --fail-on, so the file's failOn applies (refuted if the file sets none). With explicit inputs it passes --fail-on refuted, as before, so existing workflows keep their policy. When the policy in force is none (set explicitly), the step logs a ::warning::.
  • report … --format sarif is run with --uri-base "$GITHUB_WORKSPACE", so the SARIF locations are relative to the repository root, which is how code scanning reads them, whatever working-directory is and wherever cryptificate.json sits above it.
  • The -e fix: node … || code=$?, and report … || true for the SARIF and JUnit renderings, which exit with the recorded policy's status.

init [dir] (init.ts, presets.ts, prompt.ts)

  • Writes cryptificate.json, cryptificate/designs/<preset>.json, cryptificate/README.md, cryptificate/.gitignore (evidence/) and, with --ci github (the default), .github/workflows/cryptificate.yml.
  • Presets: aes, aes-row-scaled (both aes-like) and poseidon2-bn254 (hades). Each is identical to a file in examples/designs, and a test checks this; the AES-like presets therefore have 4 rounds. With --circuit, the design file is a request file that also holds the example's reference circuit: aes-known-shared-sum, or poseidon2-external-shared-sum for the external matrix.
  • Written claim scope: the model's design claims, plus circuit.equivalence and native.correctness when a circuit is included. rust.refinement is left out: the action does not build the refinement proofs, and for BN254 the claim is unsupported. native.timing is left out because only experiments measure it.
  • The workflow runs on pull requests that change those files, on pushes to the default branch, and on workflow_dispatch. The push branch is the origin remote's default branch when git has recorded it (refs/remotes/origin/HEAD), else main or master when the repository has one (loose or packed ref), else the branch checked out, else main; a .git file (linked worktree, submodule) is followed to its git directory and its commondir. It has security-events: write and uses 4waan/Cryptificate@main with upload-sarif: "true" and no inputs. --action OWNER/REPO@SHA pins it. Inside a git repository, the workflow goes to the repository root; when the init directory is a subdirectory, working-directory is set and the path filters are prefixed with it. working-directory, the path filters and the branch are written as YAML double-quoted strings (JSON string syntax).
  • When stdin is a terminal and --yes is not given, init asks for the model, the preset, the circuit (only when the preset has one), the policy and the workflow, then confirms the file list. Flags answer their own questions. With a non-terminal stdin or --yes, init takes the defaults (aes, no circuit, refuted, a workflow) without asking.
  • If any target file exists, init writes nothing and exits 2, unless --force is given. Exit status: 0 written, 1 declined at the prompt, 2 usage error, existing file, or a question left without a valid answer (end of input or five invalid answers); the usage text now says so.

doctor (doctor.ts)

  • Checks, in order:
    • Node.js 20 or later. A test checks this against engines in package.json.
    • elan.
    • The lean/lean-toolchain pin appears in elan toolchain list.
    • lake.
    • Mathlib.olean is present.
    • lake build --no-build Cryptificate exits 0. It is skipped while lake, the pinned toolchain or Mathlib is missing, so elan never downloads a toolchain as a side effect.
    • The engine: --version equals cryptificate-engine <Cargo workspace version>; it has validate, diagnose and emit-lean (a failure otherwise); it has native (a warning otherwise); its mtime is not older than crates/**/*.rs, Cargo.toml or Cargo.lock (a warning otherwise).
    • rustc (a warning).
    • The state directory is writable: a probe file is written and removed, or, when the directory does not exist yet, its nearest existing parent is checked with W_OK.
    • Free disk space: below 0.5 GiB fails, below 2 GiB is a warning.
    • GET <url>/api/capabilities (default http://127.0.0.1:4173): a warning when the service is unreachable or runs a different checker version, because check, verify and report do not need the service.
  • Each failed or warned check prints a fix command; the checkout paths in the cd … commands are quoted for a POSIX shell when they hold characters other than letters, digits and _/.,:@%+=-. The command exits 0 when no check failed and 1 otherwise. --json prints cryptificate-doctor/v1.

Docs: README "Start in one step" (own-repository commands) and "Use it in CI"; docs/adopter-guide.md gets the doctor checks after install, a new section 2 on init (including where the SARIF locations point after init in a subdirectory and how the push branch is chosen), and the later sections renumbered; docs/ci.md gets a new "Project configuration" section (the refuted default of failOn, the recorded base) and updates the action input defaults, the working-directory row, the gate options (--uri-base) and the check argument description; the schema's failOn description; the help text of the command; apps/server/README.md.

Tests run

  • npm ci (worktree).
  • npm run build: exit 0 (schema, server, web).
  • npm test: exit 0.
    • packages/schema: 14 pass. The new schema file passes the existing $id/$schema/$ref test.
    • apps/server: 90 pass, 5 skipped. The skipped tests are the existing integration tests, which need CRYPTIFICATE_INTEGRATION=1 and a built Lean library.
    • apps/web: 53 pass.
  • New server tests:
    • project.test.ts (8): validator, schema agreement, lookup from a subdirectory, precedence, --config, error messages, the refuted default of a file without failOn (and none without the file), and report on a result saved with the config in a parent directory: the recorded base, line regions found from sub/deeper, --uri-base for report and check, input paths rewritten relative to report's directory.
    • init.test.ts (8): presets equal the examples, non-interactive init followed by check on the scaffolded project (pass, then exit 1 after adding a weak design), refusal to overwrite and --force, the interactive flow on a stream with isTTY (re-ask, decline, end of input, --yes), the git-subdirectory workflow, usage errors, the default-branch choice (checked-out develop, packed master, origin/HEAD → trunk, a linked worktree with commondir, a malformed .git file), and a directory named *odd #dir: "x" [y] whose working-directory and path filters parse back to the exact strings.
    • doctor.test.ts (6): fake elan, lake and engine, with injected service, disk and Node probes; shellQuote round-trips paths with spaces, quotes, ;, &&, $ and backticks through bash -c.
    • action.test.ts (4): extracts the "Check the inputs" step from action.yml and runs it with bash -e against the built command and the fake engine. One test fails on the base branch's action.yml, which confirms the -e bug. The other cases: config-driven inputs and policy, a config without failOn (refuted, exit 1, no warning) and the none warning; working-directory crypto/ under the workspace (SARIF uri crypto/cryptificate/designs/identity.json with a region, for config and explicit inputs); config in sub/ with working-directory sub/deeper (result base is sub, SARIF uri sub/designs/identity.json with a region, JUnit names ../designs/identity.json).
  • python3 -m unittest discover -s python/tests -t python: OK. The Python client is unchanged; this run is a sanity check.
  • Manual end-to-end runs with the real toolchain:
    • cryptificate init --yes --preset aes --circuit in a scratch git repository, then cryptificate check with the real engine and Lean (CRYPTIFICATE_ROOT set to a built checkout). Exit 0 in about 30 s: all six in-scope claims proved, including 9,214 native correctness cases; a bundle was written to cryptificate/evidence/.
    • cryptificate init on a real pseudo-terminal (script): the answers were read and the process exited cleanly.
    • cryptificate doctor in this worktree, whose Lean library is not built. It reported lake build Cryptificate is not up to date with the fix, warned that the engine binary is older than the checked-out crates/ sources, warned that no service was running, and exited 1.
  • Not run: cargo test --workspace, lake build, check_examples.py and claims.py --check. No Rust, Lean, example or refinement file changed.

Scope and limits

  • The command is not published to npm. From another repository you run the checkout's apps/server/dist/src/cli.js; the docs show an alias. init and doctor do not install anything; doctor prints the commands, and scripts/setup.sh installs everything.
  • The engine staleness check compares mtimes, so it is a heuristic. A checkout that touched crates/ without changing it gives a warning, never a failure. The engine version check compares --version against the Cargo workspace version, so it cannot detect two builds of the same version from different sources.
  • The disk thresholds (0.5 GiB to fail, 2 GiB to warn) are operating guidance, not measured requirements. The first scripts/setup.sh run needs several GB more.
  • doctor writes and removes a probe file in an existing state directory. lake may refresh its own configuration cache under lean/.lake when it answers --no-build.
  • The workflow written by init uses 4waan/Cryptificate@main unless --action pins a SHA; init prints a reminder. Its pull_request path filter covers cryptificate.json and cryptificate/** only; inputs added elsewhere need the filter extended, as a comment in the file says.
  • The scaffolded claim scope is explicit. Claim ids added in later versions are not gated until they are added to claims. An input of the other model family (for example a HADES design under an AES-like scope) is an error (exit 2) under a policy, as docs/ci.md already describes.
  • The push branch is read from local git files; a clone without refs/remotes/origin/HEAD and without main or master gets the branch checked out at init time, which may not be the default branch. The adopter guide says to check it in the written workflow. Path filters are GitHub glob patterns, so a directory name containing *, ?, [ or ! is quoted correctly for YAML but still read as a glob by GitHub's filter.
  • --uri-base and the recorded base are plain path arithmetic (path.relative/path.resolve); symbolic links between $GITHUB_WORKSPACE and the working directory are not resolved. On GitHub-hosted runners the workspace path has none.
  • base is an absolute path of the machine that ran check; a result moved to another machine falls back to resolving against the original absolute paths, which then do not exist there (the SARIF locations then lose their regions, as any missing file does).

Generated by Claude Code

…n-zero

Actions runs a composite step's bash with -e, so a policy failure (exit 1)
or an error (exit 2) of cryptificate check ended the step before it wrote
the SARIF and JUnit files and the exit-code and outcome outputs, and the
later steps saw no result. The exit status is now captured with || and the
report renderings, which exit with the recorded policy's status, no longer
stop the step. A test runs the step with bash -e against the fake engine.
Without input arguments, cryptificate check reads the nearest
cryptificate.json (the working directory or a parent), or the file named
with --config: inputs, failOn, claims, target, format, output and
bundleDir. Paths in the file are relative to its directory, and so are the
input paths in the result and the SARIF locations. Options on the command
line override the file; inputs on the command line replace it, and then
the file is not read unless --config names it.

The file is validated against the keys and values of the new
schemas/project-config.schema.json; an unknown key, a wrong value or an
unknown claim id is a usage error (exit 2) that lists every problem with
its JSON Pointer. A test keeps the schema and the validator in step.
The inputs input is no longer required. Left empty, the action runs
cryptificate check without input arguments, so the inputs, the policy and
the claim scope come from the nearest cryptificate.json; its format,
output and bundleDir are replaced by the action's result files. fail-on
now defaults to empty: the file's failOn when inputs is empty, otherwise
refuted as before, so existing workflows keep their policy.
…orkflow

cryptificate init [dir] writes cryptificate.json (inputs, failOn, the
claim scope and bundleDir), a starting design under cryptificate/designs
taken from the example designs (aes, aes-row-scaled, poseidon2-bn254),
optionally with the example's reference circuit as a request file, a short
README and .gitignore for the folder, and .github/workflows/cryptificate.yml,
which runs the action on pull requests that touch these files and uploads
the SARIF result to code scanning.

On a terminal it asks for the model, the starting design, the circuit, the
policy and the workflow, and confirms the file list; --model, --preset,
--circuit/--no-circuit, --fail-on, --ci and --action answer from the
command line, and --yes or a non-terminal stdin takes the defaults. It
writes nothing when one of its files exists, unless --force is given. In a
subdirectory of a git repository the workflow goes to the repository root
with working-directory set.

The claim scope is the model's design claims and, with a circuit,
circuit.equivalence and native.correctness; rust.refinement and
native.timing are left out. Tests check the presets against the example
files and run check on a freshly scaffolded project.
…ixes

doctor checks Node.js 20 or later, elan, that the Lean toolchain pinned in
lean/lean-toolchain is installed, lake, the Mathlib build, that lake build
Cryptificate is up to date (lake build --no-build, which builds nothing and
is not started while the pinned toolchain is missing), that the engine
reports the Cargo workspace version, has the subcommands check needs and
the native backend and is not older than crates/, rustc, that the state
directory is writable, the free disk space there, and whether a service
answers at --url. Each failed or warned check carries the command that
fixes it. Exit 0 when no check failed, 1 otherwise; --json prints the
checklist as cryptificate-doctor/v1. Tests use a fake elan, lake and
engine and injected probes for the service, the disk and Node.js.
The README's start section shows the three commands an adopter runs in
their own repository. The adopter guide gains a section on init (questions,
flags, the files written and the claim scope) and describes each doctor
check, which problems are warnings and which are failures. docs/ci.md
describes the project configuration, its precedence over and under
command-line options, and the action's new defaults for inputs, fail-on and
claims.
…he repository root

check records in its JSON result the directory that the input paths are
relative to (base: the working directory, or the directory of
cryptificate.json when the inputs came from it). report resolves the input
paths of a saved check result against it, so a result written with the
config in a parent directory still finds its files and keeps the line
regions of its SARIF locations.

check, verify and report take --uri-base DIR, which makes SARIF file
locations relative to DIR instead of the working directory. The action
passes --uri-base "$GITHUB_WORKSPACE", so the locations are relative to
the repository root, as code scanning reads them, when working-directory
is a subdirectory (as init writes it) or the config is in a parent of it.
check took the policy none when cryptificate.json set no failOn, so the
action with empty inputs and fail-on never failed the job, not even on a
refuted claim. A loaded cryptificate.json now defaults the policy to
refuted, which is also the action's default with explicit inputs; a
failOn or --fail-on in force still wins, and without the file the
command-line default stays none. The action logs a warning when the
policy in force is none.
The workflow written by init now emits working-directory, the paths
filters and the push branch as YAML double-quoted strings, so a directory
name with "#", ": ", quotes or a leading "*", "&", "!" or "[" stays one
string. The push trigger names the default branch recorded for the origin
remote (refs/remotes/origin/HEAD), else main or master when the repository
has one, else the branch checked out, instead of falling back to main. A
.git file (a linked worktree or a submodule) is followed to its git
directory and to the common directory that holds the refs.
The cd commands doctor prints for the Mathlib cache, the certificate
library, the engine build and the local service now quote the checkout
path for a POSIX shell, so they work when it holds spaces or shell
characters.
A question left without a valid answer (end of input, or five invalid
answers) cancels init with exit status 2; the usage line named only usage
errors and existing files.
…fault of cryptificate.json

docs/ci.md says how the action places SARIF locations at the repository
root, that working-directory only sets where the command runs, that
check results record the base of their input paths and report resolves
against it, that failOn defaults to refuted in cryptificate.json, and
that the action warns under the policy none. The adopter guide states
where the SARIF locations point after init in a subdirectory and how the
push branch is chosen.
Resolve the overlap with the branches merged before it, as in the
release/v0.2.0 integration.
@4waan
4waan merged commit 17e921f into main Nov 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants