Skip to content

ArghDA M1: Backend abstraction — make the engine prover-parametric#32

Merged
hyperpolymath merged 1 commit into
mainfrom
claude/arghda-roadmap-planning-p5mu93
Jul 1, 2026
Merged

ArghDA M1: Backend abstraction — make the engine prover-parametric#32
hyperpolymath merged 1 commit into
mainfrom
claude/arghda-roadmap-planning-p5mu93

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

What & why

The keystone of the "Flying Logic for provers/solvers" epic. Every Agda-baked seam now lives behind an object-safe Backend trait, so the four-state workspace, DAG builder, content-hash invalidation and the cycle-safe reachability walk become backend-neutral. Agda is the first (v0.1 reference) impl; adding Idris2 / Lean4 / Z3 / CVC5 / Coq / Isabelle / Mizar is now an impl, not a rewrite.

Follow-on from M0 (toolchain provisioning, merged as #31). #31 being merged, this is a fresh PR on the same working branch.

This is a pure refactor — the test suite is the oracle

Behaviour is unchanged, ground-truthed by running the tools (not inferred):

  • cargo test — the 64 pre-existing tests (50 lib + 14 integration) all stay green; +2 new Agda-backend tests = 66 passing, 0 failed.
  • cargo clippy --all-targets --all-features -- -D warnings — clean.
  • cargo fmt --check — clean.
  • scripts/check-spdx.sh .SPDX licence invariant: OK.
  • Dogfoodarghda dag tests/fixtures/wellformed emits byte-compatible JSON (version: "0.1", same nodes/edges); arghda check …/All.agda ran a real Agda typecheck → proven-eligible (agda is present from ArghDA → Flying Logic for provers/solvers: M0 (toolchain provisioning + doctor) #31's provisioning).

Changes

New src/prover/:

  • Backend trait — name / kind / extensions / safe_mode / check_file + the import-graph trio (module_name_of / module_to_path / direct_imports) + discover_roots + lint_rules.
  • BackendKind { Assistant, Solver } — the two interaction models (typecheck-a-file vs SMT query).
  • Verdict { Proven, Refuted, Unknown, Admitted, Postulated, Error, Unavailable } — the common verdict both models map into. Only Proven is green; Admitted/Postulated are amber.
  • Outcome — superset of the old AgdaOutcome (raw process facts + kind + verdict).

Refactor:

  • src/agda.rssrc/prover/agda.rs. Agda is the first impl: owns the agda shell-out, delegates parsing to graph:: free fns and the lint pack to lint::. Verdict is exit-code-only (0 → Proven, ran-nonzero → Error, absent → Unavailable) — arghda never claims a result Agda did not return; Admitted/Postulated stay lint-derived, never manufactured from a green exit.
  • graph::build and dag::build take &dyn Backend and use the backend's extension filter + import parsing. The cycle-safe reachability walk and its transitive_imports_terminates_on_a_cycle regression are untouched — cycle safety is inherited free by every backend.
  • main.rs scan/check/dag/resolve_roots_and_rules route through the backend; the check JSON key agdabackend (now carries kind + verdict).
  • STATE.a2ml records M1 = 100%; .gitignore ignores *.agdai.

Honesty note (owner directive + AGENTIC.a2ml)

The Backend module is the boundary where "never report a verdict the tool did not emit" is enforced: check_file derives its verdict from the actual exit code and degrades to Unavailable when the binary is absent.

Next (trait now stable → parallelisable)

M3 reasoning-graph (src/reason), M4 Idris2, M5 SMT (Z3/CVC5), M2 Cubical-Agda.


Generated by Claude Code

The keystone refactor of the "Flying Logic for provers/solvers" epic.
Every Agda-baked seam now lives behind an object-safe `Backend` trait, so
the four-state workspace, DAG builder, content-hash invalidation and the
cycle-safe reachability walk are backend-neutral. Agda is the first (v0.1
reference) impl; adding Idris2/Lean4/Z3/CVC5/… now means an impl, not a
rewrite.

Behaviour is unchanged — this is the promised pure refactor with the test
suite as the oracle: the 64 pre-existing tests (50 lib + 14 integration)
all stay green, +2 new Agda-backend tests = 66 passing. clippy -D warnings,
fmt and the SPDX gate are clean; the `dag` JSON output is byte-compatible
and `check` still runs a real Agda typecheck.

New `src/prover/`:
- `Backend` trait: name/kind/extensions/safe_mode/check_file +
  module_name_of/module_to_path/direct_imports/discover_roots/lint_rules.
- `BackendKind { Assistant, Solver }` — the two interaction models.
- `Verdict { Proven, Refuted, Unknown, Admitted, Postulated, Error,
  Unavailable }` — the common verdict both models map into; only Proven is
  green, Admitted/Postulated are amber.
- `Outcome` — superset of the old AgdaOutcome (raw process facts + kind +
  verdict).

- `src/agda.rs` -> `src/prover/agda.rs` (Agda impl; owns the shell-out,
  delegates parsing to `graph::` free fns and the lint pack to `lint::`).
  Verdict is exit-code-only (0 -> Proven, ran-nonzero -> Error, absent ->
  Unavailable) — arghda never claims a result Agda did not return;
  Admitted/Postulated stay lint-derived, not manufactured from a green exit.
- `graph::build` and `dag::build` gain a `&dyn Backend` parameter and use
  the backend's extension filter + import parsing; the reachability walk
  and its cycle-termination regression are untouched.
- `main.rs` scan/check/dag/resolve_roots_and_rules route through the
  backend; the `check` JSON key `agda` -> `backend` (now carries kind +
  verdict).
- STATE.a2ml records M1 = 100%.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012MpYSh6Wy8YMBH2E3qVyT7
@hyperpolymath
hyperpolymath marked this pull request as ready for review July 1, 2026 07:25
@hyperpolymath
hyperpolymath merged commit 75eac52 into main Jul 1, 2026
2 checks passed
@hyperpolymath
hyperpolymath deleted the claude/arghda-roadmap-planning-p5mu93 branch July 1, 2026 07:26
hyperpolymath added a commit that referenced this pull request Jul 1, 2026
…tion (#33)

## What & why

The **headline capability** of the "Flying Logic for provers/solvers"
epic, built on the M1 `Backend` trait (merged #32). A new `src/reason/`
layer *wraps* (does not replace) the DAG: the `DagDocument` is embedded
verbatim, and on top go a per-node `Verdict`, `And`/`Or` edge juncts,
and a memoised, cycle-safe, **demote-only** propagation fold.

## The honesty invariant (enforced end-to-end)

A node's effective verdict can only be **lowered** by its dependencies,
never manufactured:
- **lint-clean + no typecheck = `Unknown`**, never green. Only a real
prover exit-0 makes `Proven`.
- Only `Proven` is green; `Admitted`/`Postulated` are amber.
- Because the fold is demote-only over `And` import edges, **structural
amber infects downstream** — anything that transitively imports a
`postulate` (or `missing-safe` / escape-hatch) module is itself capped.
Visible *before any prover runs*.
- `Or` groups are forgiving (one green route keeps a goal up). Import
cycles degrade to `Error` and terminate. Staleness (closure-hash-changed
`Proven` → `Unknown`) is applied pre-fold so it propagates. `wired`
marks the CRT-root-reachable cone.

## Changes

- `src/reason/mod.rs`: `Junct`, `ReasonNode`
(`self_verdict`/`effective`/`verdict_evidence`/`soundness`/`wired`),
`ReasonEdge`, `ReasonDocument` (`version:"0.1"`, embedded `dag`,
`crt_roots`); the rank/demote/promote lattice; lint→verdict caps; the
propagation fold.
- `arghda reason <path> [--check]`: `--check` runs the backend per node
for **real** exit-code verdicts; default is structure+lint-derived (all
`unknown` on a clean tree, honestly).
- `STATE.a2ml` records M3 = 100%.

## Verified (ran, not inferred)

- `cargo test` → **81 passing, 0 failed** (61 lib + 20 integration; +9
reason unit tests covering demote / downstream-amber-infection /
Or-forgiveness / cycle-termination / wiring /
clean-but-unchecked→Unknown, +6 reason integration).
- `cargo clippy -D warnings` clean · `cargo fmt --check` clean ·
`check-spdx.sh` OK.
- **Dogfood** — `arghda reason tests/fixtures/wellformed --check` ran
real `agda` typechecks → the whole cone `proven` + `wired`.

### A bug dogfooding caught (and I fixed)

The first `--check` dogfood showed **every node `wired=false`** with
`crt_roots=['tests.fixtures.wellformed.All']`. The CLI's
`discover_roots` yields include-root-*relative* paths, which a stray
`include_root.join` double-prefixed — so the CRT-root ids never matched
the node ids. The unit/integration tests missed it because they passed
*absolute* roots (where the join is a silent no-op). Fixed to match the
orphan-module rule's convention (paths go straight to `module_name_of`),
plus a regression test that exercises the `discover_roots` path.
Re-dogfooded green.

## Next (all unblocked by the stable trait)

M4 Idris2 · M5 SMT (Z3/CVC5) · M2 Cubical-Agda · M3 follow-on (feed real
verdicts + staleness from a workspace `proven/` state so `reason` lights
the cone without `--check`).

---
_Generated by [Claude
Code](https://claude.ai/code/session_012MpYSh6Wy8YMBH2E3qVyT7)_

Co-authored-by: Claude <noreply@anthropic.com>
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