From 08a72b09b84e1082d9d17095691349fe00243bd6 Mon Sep 17 00:00:00 2001
From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com>
Date: Mon, 24 Aug 2026 08:15:57 +0100
Subject: [PATCH] refactor: migrate repository documentation from Markdown to
AsciiDoc
---
ABI-FFI-README.adoc | 127 ++
ABI-FFI-README.md | 105 --
ARCHITECTURE.adoc | 107 ++
ARCHITECTURE.md | 78 --
CODE_OF_CONDUCT.adoc | 339 +++++
CODE_OF_CONDUCT.md | 327 -----
CONTRIBUTING.adoc | 109 ++
CONTRIBUTING.md | 116 --
GOVERNANCE.adoc | 78 ++
GOVERNANCE.md | 62 -
GQL-DT-COMPLETION-2026-02-07.adoc | 591 ++++++++
GQL-DT-COMPLETION-2026-02-07.md | 560 --------
MOVED.adoc | 70 +
MOVED.md | 58 -
README.adoc | 340 +++--
README.md | 183 ---
SECURITY.adoc | 452 +++++++
SECURITY.md | 406 ------
docs/EXECUTION-STRATEGY.adoc | 569 ++++++++
docs/EXECUTION-STRATEGY.md | 534 --------
docs/{INTEGRATION.md => INTEGRATION.adoc} | 353 ++---
...AGE-BINDINGS.md => LANGUAGE-BINDINGS.adoc} | 439 +++---
docs/LANGUAGE-DESIGN-STATUS.adoc | 545 ++++++++
docs/LANGUAGE-DESIGN-STATUS.md | 514 -------
docs/M6-PARSER-STATUS.adoc | 374 +++++
docs/M6-PARSER-STATUS.md | 362 -----
docs/PARSER-DECISION.adoc | 542 ++++++++
docs/PARSER-DECISION.md | 506 -------
docs/SEAM-ANALYSIS-2026-02-01.adoc | 439 ++++++
docs/SEAM-ANALYSIS-2026-02-01.md | 388 ------
...WO-TIER-DESIGN.md => TWO-TIER-DESIGN.adoc} | 636 ++++-----
...CEMENT.md => TYPE-SAFETY-ENFORCEMENT.adoc} | 389 +++---
...=> WP06_Dependently_Typed_Lithoglyph.adoc} | 1203 +++++++++--------
docs/proof-debt.adoc | 225 +++
docs/proof-debt.md | 166 ---
spec/GQL-DT-Lexical.adoc | 760 +++++++++++
spec/GQL-DT-Lexical.md | 680 ----------
...grams.md => GQL-DT-Railroad-Diagrams.adoc} | 299 ++--
...pendent_Types_Complete_Specification.adoc} | 731 +++++-----
spec/README.adoc | 351 +++++
spec/README.md | 318 -----
...tion-types.md => normalization-types.adoc} | 269 ++--
42 files changed, 8210 insertions(+), 7490 deletions(-)
create mode 100644 ABI-FFI-README.adoc
delete mode 100644 ABI-FFI-README.md
create mode 100644 ARCHITECTURE.adoc
delete mode 100644 ARCHITECTURE.md
create mode 100644 CODE_OF_CONDUCT.adoc
delete mode 100644 CODE_OF_CONDUCT.md
create mode 100644 CONTRIBUTING.adoc
delete mode 100644 CONTRIBUTING.md
create mode 100644 GOVERNANCE.adoc
delete mode 100644 GOVERNANCE.md
create mode 100644 GQL-DT-COMPLETION-2026-02-07.adoc
delete mode 100644 GQL-DT-COMPLETION-2026-02-07.md
create mode 100644 MOVED.adoc
delete mode 100644 MOVED.md
delete mode 100644 README.md
create mode 100644 SECURITY.adoc
delete mode 100644 SECURITY.md
create mode 100644 docs/EXECUTION-STRATEGY.adoc
delete mode 100644 docs/EXECUTION-STRATEGY.md
rename docs/{INTEGRATION.md => INTEGRATION.adoc} (73%)
rename docs/{LANGUAGE-BINDINGS.md => LANGUAGE-BINDINGS.adoc} (78%)
create mode 100644 docs/LANGUAGE-DESIGN-STATUS.adoc
delete mode 100644 docs/LANGUAGE-DESIGN-STATUS.md
create mode 100644 docs/M6-PARSER-STATUS.adoc
delete mode 100644 docs/M6-PARSER-STATUS.md
create mode 100644 docs/PARSER-DECISION.adoc
delete mode 100644 docs/PARSER-DECISION.md
create mode 100644 docs/SEAM-ANALYSIS-2026-02-01.adoc
delete mode 100644 docs/SEAM-ANALYSIS-2026-02-01.md
rename docs/{TWO-TIER-DESIGN.md => TWO-TIER-DESIGN.adoc} (59%)
rename docs/{TYPE-SAFETY-ENFORCEMENT.md => TYPE-SAFETY-ENFORCEMENT.adoc} (55%)
rename docs/{WP06_Dependently_Typed_Lithoglyph.md => WP06_Dependently_Typed_Lithoglyph.adoc} (55%)
create mode 100644 docs/proof-debt.adoc
delete mode 100644 docs/proof-debt.md
create mode 100644 spec/GQL-DT-Lexical.adoc
delete mode 100644 spec/GQL-DT-Lexical.md
rename spec/{GQL-DT-Railroad-Diagrams.md => GQL-DT-Railroad-Diagrams.adoc} (81%)
rename spec/{GQL_Dependent_Types_Complete_Specification.md => GQL_Dependent_Types_Complete_Specification.adoc} (77%)
create mode 100644 spec/README.adoc
delete mode 100644 spec/README.md
rename spec/{normalization-types.md => normalization-types.adoc} (86%)
diff --git a/ABI-FFI-README.adoc b/ABI-FFI-README.adoc
new file mode 100644
index 0000000..9b2844a
--- /dev/null
+++ b/ABI-FFI-README.adoc
@@ -0,0 +1,127 @@
+== ABI / FFI — how GNPL reaches Lithoglyph
+
+This repository follows the estate standard: *ABI defined in Idris2, FFI
+implemented in Zig*, meeting at the C ABI. No C is written by hand.
+
+____
+*History:* this file was previously the unfilled RSR template — 385
+lines of `+{{project}}+` placeholders documenting an `+ffi/zig/+` tree
+that did not compile. It has been replaced with what the repository
+actually contains.
+____
+
+=== The path
+
+....
+GNPL ──lowers to──▶ GQLdt (Lean 4)
+ │
+ │ FFI: links -Lbridge/zig-out/lib -llith_bridge
+ ▼
+ bridge/ (Zig) ── C ABI ──▶ Lithoglyph Form.Bridge
+....
+
+`+lakefile.lean+` links the Lean executables against
+`+bridge/zig-out/lib/liblith_bridge.a+`. *That archive must exist before
+`+lake build+` runs.*
+
+=== Layout
+
+[width="100%",cols="50%,50%",options="header",]
+|===
+|Path |Role
+|`+src/GQLdt/ABI/Types.idr+` |ABI type definitions
+
+|`+src/GQLdt/ABI/Layout.idr+` |memory-layout proofs
+
+|`+src/GQLdt/ABI/Foreign.idr+` |foreign declarations
+
+|`+bridge/build.zig+` |build script (`+addLibrary+`, Zig ≥ 0.15 API)
+
+|`+bridge/lith_root.zig+` |FFI entry point — the exported C surface
+
+|`+bridge/lith_types.zig+` |C-ABI structs (`+ActorIdC+`, `+RationaleC+`,
+`+ProvenanceC+`, `+TrackedValueC+`, `+ProofBlob+`, `+PromptScoresC+`)
+
+|`+bridge/lith_insert.zig+`, `+bridge/lith_persist.zig+` |insert +
+persistence implementation
+|===
+
+`+bridge/+` is the *only* live Zig tree. Two earlier skeletons
+(`+bridge/zig/+`, `+ffi/zig/+`) were removed — they were written against
+the pre-0.15 Build API (`+addStaticLibrary+`,
+`+std.heap.GeneralPurposeAllocator+`), failed to compile on the pinned
+Zig 0.16.0, and nothing linked against them.
+
+=== Building
+
+[source,bash]
+----
+cd bridge
+zig build # produces zig-out/lib/liblith_bridge.a
+zig build test # unit tests
+zig build -Doptimize=ReleaseFast # optimised
+----
+
+Cross-compilation works as usual (`+-Dtarget=aarch64-macos+`, etc.).
+
+Then, from the repository root:
+
+[source,bash]
+----
+lake build
+----
+
+Zig is pinned to *0.16.0* in `+mise.toml+`. Lean is pinned by
+`+lean-toolchain+` (`+leanprover/lean4:v4.15.0+`), which elan reads
+automatically.
+
+=== Exported C surface
+
+Seventeen functions, all `+callconv(.C)+`, from `+bridge/+`:
+
+*Lifecycle* — `+lith_init+`, `+lith_is_init+`, `+lith_close+`,
+`+lith_save+` *Data* — `+lith_insert+`, `+lith_insert_row+`,
+`+lith_delete_row+`, `+lith_table_count+` *PROMPT scores* —
+`+lith_get_scores+`, `+lith_compute_overall+` *Proofs* —
+`+lith_verify_proof+` *Utility* — `+lith_validate_non_empty+`,
+`+lith_timestamp_now+`, `+lith_get_last_error+` *Debug/test* —
+`+lith_debug_init_counter+`, `+lith_debug_magic+`, `+lith_test_fresh+`
+
+Provenance crosses the boundary as real structs, not opaque blobs:
+`+ActorIdC+`, `+RationaleC+`, `+ProvenanceC+` and `+TrackedValueC+` are
+marshalled directly. This is what makes the GNPL narration layer
+buildable over this stack — see `+docs/LITHOGLYPH.adoc+`.
+
+____
+*Caveat.* `+PromptScoresC.computeOverall+` takes an *unweighted mean* of
+the six PROMPT dimensions. It is not probabilistically principled, and
+must not become a load-bearing entrenchment ordering without being
+revisited — see open question 2 in `+docs/THEORY.adoc+`.
+____
+
+=== Why this split
+
+*Idris2 for the ABI* — dependent types let struct size, field alignment
+and cross-version compatibility be _proved_ rather than asserted, so an
+ABI change that would break a caller fails at compile time.
+
+*Zig for the FFI* — `+export fn … callconv(.C)+` is C-compatible without
+a C compiler, without libc, and with cross-compilation built in.
+
+=== Adding a function
+
+[arabic]
+. Declare the type in `+src/GQLdt/ABI/Types.idr+`; add a layout proof in
+`+Layout.idr+`.
+. Declare it in `+src/GQLdt/ABI/Foreign.idr+`.
+. Implement and `+export+` it in `+bridge/+` (match the ABI types
+exactly).
+. `+cd bridge && zig build && zig build test+`, then `+lake build+` from
+the root.
+
+=== Related
+
+* `+docs/THEORY.adoc+` — what GNPL is, and what gap it fills
+* `+docs/LITHOGLYPH.adoc+` — what GNPL gives Lithoglyph as a database
+* `+docs/proof-debt.md+` — the 16 outstanding axioms; *read before
+relying on any verification claim*
diff --git a/ABI-FFI-README.md b/ABI-FFI-README.md
deleted file mode 100644
index 684a9a0..0000000
--- a/ABI-FFI-README.md
+++ /dev/null
@@ -1,105 +0,0 @@
-
-
-# ABI / FFI — how GNPL reaches Lithoglyph
-
-This repository follows the estate standard: **ABI defined in Idris2, FFI implemented in
-Zig**, meeting at the C ABI. No C is written by hand.
-
-> **History:** this file was previously the unfilled RSR template — 385 lines of
-> `{{project}}` placeholders documenting an `ffi/zig/` tree that did not compile. It has
-> been replaced with what the repository actually contains.
-
-## The path
-
-```
-GNPL ──lowers to──▶ GQLdt (Lean 4)
- │
- │ FFI: links -Lbridge/zig-out/lib -llith_bridge
- ▼
- bridge/ (Zig) ── C ABI ──▶ Lithoglyph Form.Bridge
-```
-
-`lakefile.lean` links the Lean executables against `bridge/zig-out/lib/liblith_bridge.a`.
-**That archive must exist before `lake build` runs.**
-
-## Layout
-
-| Path | Role |
-|---|---|
-| `src/GQLdt/ABI/Types.idr` | ABI type definitions |
-| `src/GQLdt/ABI/Layout.idr` | memory-layout proofs |
-| `src/GQLdt/ABI/Foreign.idr` | foreign declarations |
-| `bridge/build.zig` | build script (`addLibrary`, Zig ≥ 0.15 API) |
-| `bridge/lith_root.zig` | FFI entry point — the exported C surface |
-| `bridge/lith_types.zig` | C-ABI structs (`ActorIdC`, `RationaleC`, `ProvenanceC`, `TrackedValueC`, `ProofBlob`, `PromptScoresC`) |
-| `bridge/lith_insert.zig`, `bridge/lith_persist.zig` | insert + persistence implementation |
-
-`bridge/` is the **only** live Zig tree. Two earlier skeletons (`bridge/zig/`, `ffi/zig/`)
-were removed — they were written against the pre-0.15 Build API (`addStaticLibrary`,
-`std.heap.GeneralPurposeAllocator`), failed to compile on the pinned Zig 0.16.0, and nothing
-linked against them.
-
-## Building
-
-```bash
-cd bridge
-zig build # produces zig-out/lib/liblith_bridge.a
-zig build test # unit tests
-zig build -Doptimize=ReleaseFast # optimised
-```
-
-Cross-compilation works as usual (`-Dtarget=aarch64-macos`, etc.).
-
-Then, from the repository root:
-
-```bash
-lake build
-```
-
-Zig is pinned to **0.16.0** in `mise.toml`. Lean is pinned by `lean-toolchain`
-(`leanprover/lean4:v4.15.0`), which elan reads automatically.
-
-## Exported C surface
-
-Seventeen functions, all `callconv(.C)`, from `bridge/`:
-
-**Lifecycle** — `lith_init`, `lith_is_init`, `lith_close`, `lith_save`
-**Data** — `lith_insert`, `lith_insert_row`, `lith_delete_row`, `lith_table_count`
-**PROMPT scores** — `lith_get_scores`, `lith_compute_overall`
-**Proofs** — `lith_verify_proof`
-**Utility** — `lith_validate_non_empty`, `lith_timestamp_now`, `lith_get_last_error`
-**Debug/test** — `lith_debug_init_counter`, `lith_debug_magic`, `lith_test_fresh`
-
-Provenance crosses the boundary as real structs, not opaque blobs: `ActorIdC`,
-`RationaleC`, `ProvenanceC` and `TrackedValueC` are marshalled directly. This is what makes
-the GNPL narration layer buildable over this stack — see `docs/LITHOGLYPH.adoc`.
-
-> **Caveat.** `PromptScoresC.computeOverall` takes an **unweighted mean** of the six PROMPT
-> dimensions. It is not probabilistically principled, and must not become a load-bearing
-> entrenchment ordering without being revisited — see open question 2 in `docs/THEORY.adoc`.
-
-## Why this split
-
-**Idris2 for the ABI** — dependent types let struct size, field alignment and cross-version
-compatibility be *proved* rather than asserted, so an ABI change that would break a caller
-fails at compile time.
-
-**Zig for the FFI** — `export fn … callconv(.C)` is C-compatible without a C compiler,
-without libc, and with cross-compilation built in.
-
-## Adding a function
-
-1. Declare the type in `src/GQLdt/ABI/Types.idr`; add a layout proof in `Layout.idr`.
-2. Declare it in `src/GQLdt/ABI/Foreign.idr`.
-3. Implement and `export` it in `bridge/` (match the ABI types exactly).
-4. `cd bridge && zig build && zig build test`, then `lake build` from the root.
-
-## Related
-
-- `docs/THEORY.adoc` — what GNPL is, and what gap it fills
-- `docs/LITHOGLYPH.adoc` — what GNPL gives Lithoglyph as a database
-- `docs/proof-debt.md` — the 16 outstanding axioms; **read before relying on any
- verification claim**
diff --git a/ARCHITECTURE.adoc b/ARCHITECTURE.adoc
new file mode 100644
index 0000000..c787520
--- /dev/null
+++ b/ARCHITECTURE.adoc
@@ -0,0 +1,107 @@
+== Architecture
+
+____
+An earlier unmerged sweep proposed a generic `+ARCHITECTURE.md+`
+describing a `+src/ tests/ config/+` layout with "`modular, maintainable
+architecture designed for clarity, scalability and long-term
+sustainability`". This repository has none of those directories and that
+text described nothing. What follows is the actual structure.
+____
+
+=== Two layers, one repository
+
+....
+GNPL narration: "what account does this evidence support?" <-- design only
+ │ lowers to
+GQLdt query: "what is in the store?" <-- built, tested
+ │ FFI (liblith_bridge.a)
+Form.Bridge Zig, C ABI <-- built, tested
+ │
+Lithoglyph Form.Model / Form.Blocks (Forth, append-only journal) <-- separate repo
+....
+
+This is why a repository named `+gnpl+` contains sources namespaced
+`+GqlDt+`: GQLdt is not a leftover, it is GNPL’s compilation target. See
+`+README.adoc+`, and `+docs/THEORY.adoc+` for why the narration layer is
+the point.
+
+=== Layout
+
+[width="100%",cols="34%,33%,33%",options="header",]
+|===
+|Path |Language |Role
+|`+src/GqlDt/+` |Lean 4 |the query core — types, lexer, parser, IR,
+pipeline
+
+|`+src/GqlDt/Types/+` |Lean 4 |refinement types: `+BoundedNat+`,
+`+NonEmptyString+`, `+Confidence+`
+
+|`+src/GqlDt/Provenance/+` |Lean 4 |`+ActorId+`, `+Rationale+`,
+`+Tracked+` — the warrant substrate
+
+|`+src/GqlDt/Prompt/+` |Lean 4 |PROMPT six-dimension source scoring
+
+|`+src/GQLdt/ABI/+` |Idris2 |ABI definitions + memory-layout proofs
+
+|`+bridge/+` |Zig |FFI implementation; emits
+`+zig-out/lib/liblith_bridge.a+`
+
+|`+test/+` |Lean 4 |executable suites, run by `+lake test+`
+
+|`+spec/+` |Markdown/EBNF |the normative grammar and lexical
+specification
+
+|`+docs/+` |AsciiDoc/Markdown |design rationale and proof debt
+|===
+
+Per the estate standard, *ABI is Idris2 and FFI is Zig* — no
+hand-written C. `+bridge/+` is the only Zig tree; two pre-0.15-API
+skeletons were removed in #7.
+
+=== Build order (it matters)
+
+`+lakefile.lean+` links against `+bridge/zig-out/lib/liblith_bridge.a+`,
+so the Zig archive must exist _before_ the Lean executables link:
+
+[source,sh]
+----
+cd bridge && zig build && zig build test # produces liblith_bridge.a
+cd .. && lake build && lake test
+----
+
+Getting this backwards is why the `+Containerfile+` used to mask both
+steps with `+|| echo+`, which meant a wholly broken build still produced
+a "`successful`" image.
+
+=== Verification posture
+
+The claims this repository makes about itself are gated, and the gates
+are tested:
+
+[width="100%",cols="50%,50%",options="header",]
+|===
+|Gate |What it establishes
+|`+lake build+` |the Lean core typechecks
+
+|`+lake test+` |163 executable checks across Lexer / Parser / TypeSafety
+
+|`+scripts/check-lean-proofs.sh --build-log+` |Lean reports no
+_incomplete_ proof (`+sorry+`)
+
+|estate `+check-trusted-base.sh+` |every `+axiom+` is enumerated in
+`+docs/proof-debt.md+`
+
+|`+cd bridge && zig build test+` |the FFI bridge builds and its unit
+tests pass
+|===
+
+*A green proof gate means "`nothing is admitted mid-proof`", not
+"`nothing is assumed`".* Lean’s `+sorry+` warning does not fire on
+`+axiom+`, and 16 axioms remain — five of them in _executable_ position,
+so those functions have no implementation at all. Read
+`+docs/proof-debt.md+` before relying on any verification claim here.
+
+New gates are only accepted once they have been shown to go red on a
+seeded fault. The test driver and the proof gate were both canary-tested
+this way; the repository has a history of gates that could not fail, and
+the remedy is evidence, not intent.
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
deleted file mode 100644
index 015f1a3..0000000
--- a/ARCHITECTURE.md
+++ /dev/null
@@ -1,78 +0,0 @@
-
-
-# Architecture
-
-> An earlier unmerged sweep proposed a generic `ARCHITECTURE.md` describing a
-> `src/ tests/ config/` layout with "modular, maintainable architecture designed for
-> clarity, scalability and long-term sustainability". This repository has none of those
-> directories and that text described nothing. What follows is the actual structure.
-
-## Two layers, one repository
-
-```
-GNPL narration: "what account does this evidence support?" <-- design only
- │ lowers to
-GQLdt query: "what is in the store?" <-- built, tested
- │ FFI (liblith_bridge.a)
-Form.Bridge Zig, C ABI <-- built, tested
- │
-Lithoglyph Form.Model / Form.Blocks (Forth, append-only journal) <-- separate repo
-```
-
-This is why a repository named `gnpl` contains sources namespaced `GqlDt`: GQLdt is not
-a leftover, it is GNPL's compilation target. See `README.adoc`, and `docs/THEORY.adoc`
-for why the narration layer is the point.
-
-## Layout
-
-| Path | Language | Role |
-|---|---|---|
-| `src/GqlDt/` | Lean 4 | the query core — types, lexer, parser, IR, pipeline |
-| `src/GqlDt/Types/` | Lean 4 | refinement types: `BoundedNat`, `NonEmptyString`, `Confidence` |
-| `src/GqlDt/Provenance/` | Lean 4 | `ActorId`, `Rationale`, `Tracked` — the warrant substrate |
-| `src/GqlDt/Prompt/` | Lean 4 | PROMPT six-dimension source scoring |
-| `src/GQLdt/ABI/` | Idris2 | ABI definitions + memory-layout proofs |
-| `bridge/` | Zig | FFI implementation; emits `zig-out/lib/liblith_bridge.a` |
-| `test/` | Lean 4 | executable suites, run by `lake test` |
-| `spec/` | Markdown/EBNF | the normative grammar and lexical specification |
-| `docs/` | AsciiDoc/Markdown | design rationale and proof debt |
-
-Per the estate standard, **ABI is Idris2 and FFI is Zig** — no hand-written C.
-`bridge/` is the only Zig tree; two pre-0.15-API skeletons were removed in #7.
-
-## Build order (it matters)
-
-`lakefile.lean` links against `bridge/zig-out/lib/liblith_bridge.a`, so the Zig archive
-must exist *before* the Lean executables link:
-
-```sh
-cd bridge && zig build && zig build test # produces liblith_bridge.a
-cd .. && lake build && lake test
-```
-
-Getting this backwards is why the `Containerfile` used to mask both steps with
-`|| echo`, which meant a wholly broken build still produced a "successful" image.
-
-## Verification posture
-
-The claims this repository makes about itself are gated, and the gates are tested:
-
-| Gate | What it establishes |
-|---|---|
-| `lake build` | the Lean core typechecks |
-| `lake test` | 163 executable checks across Lexer / Parser / TypeSafety |
-| `scripts/check-lean-proofs.sh --build-log` | Lean reports no *incomplete* proof (`sorry`) |
-| estate `check-trusted-base.sh` | every `axiom` is enumerated in `docs/proof-debt.md` |
-| `cd bridge && zig build test` | the FFI bridge builds and its unit tests pass |
-
-**A green proof gate means "nothing is admitted mid-proof", not "nothing is assumed".**
-Lean's `sorry` warning does not fire on `axiom`, and 16 axioms remain — five of them in
-*executable* position, so those functions have no implementation at all. Read
-`docs/proof-debt.md` before relying on any verification claim here.
-
-New gates are only accepted once they have been shown to go red on a seeded fault. The
-test driver and the proof gate were both canary-tested this way; the repository has a
-history of gates that could not fail, and the remedy is evidence, not intent.
diff --git a/CODE_OF_CONDUCT.adoc b/CODE_OF_CONDUCT.adoc
new file mode 100644
index 0000000..4fedda1
--- /dev/null
+++ b/CODE_OF_CONDUCT.adoc
@@ -0,0 +1,339 @@
+== Code of Conduct
+
+=== Our Pledge
+
+We as members, contributors, and leaders pledge to make participation in
+Nextgen Databases a harassment-free experience for everyone, regardless
+of age, body size, visible or invisible disability, ethnicity, sex
+characteristics, gender identity and expression, level of experience,
+education, socio-economic status, nationality, personal appearance,
+race, caste, colour, religion, or sexual identity and orientation.
+
+We pledge to act and interact in ways that contribute to an open,
+welcoming, diverse, inclusive, and healthy community.
+
+We recognise that a thriving open source community requires
+*psychological safety* — an environment where people can contribute, ask
+questions, make mistakes, and learn without fear of ridicule or
+retaliation.
+
+'''''
+
+=== Our Standards
+
+==== Expected Behaviour
+
+The following behaviours contribute to a positive environment:
+
+*Communication* - Using welcoming and inclusive language - Being
+respectful of differing viewpoints and experiences - Giving and
+gracefully accepting constructive feedback - Assuming good intent while
+addressing impact - Communicating clearly and patiently, especially with
+newcomers
+
+*Collaboration* - Focusing on what is best for the community - Showing
+empathy and kindness toward other community members - Being
+collaborative rather than competitive - Mentoring and supporting less
+experienced contributors - Celebrating others’ contributions and
+successes
+
+*Professionalism* - Accepting responsibility and apologising to those
+affected by our mistakes - Learning from the experience and avoiding
+repetition - Respecting others’ time and attention - Staying on topic in
+project spaces - Following project guidelines and conventions
+
+*Accessibility* - Using plain language and avoiding unnecessary jargon -
+Providing alt text for images and transcripts for audio/video - Being
+patient with those using assistive technologies - Accommodating
+different communication styles and needs - Recognising that not everyone
+communicates the same way
+
+==== Unacceptable Behaviour
+
+The following behaviours are considered harassment and are unacceptable:
+
+*Harassment* - The use of sexualised language or imagery, and sexual
+attention or advances of any kind - Trolling, insulting or derogatory
+comments, and personal or political attacks - Public or private
+harassment - Deliberate intimidation, stalking, or following (online or
+in-person) - Unwelcome physical contact or simulated physical contact
+(e.g., emoji) - Sustained disruption of talks, events, or online
+discussions
+
+*Discrimination* - Discriminatory jokes and language - Posting or
+threatening to post others’ personally identifying information
+("`doxing`") - Advocating for, or encouraging, any of the above
+behaviour - Microaggressions — subtle, often unintentional,
+discriminatory comments or actions
+
+*Professional Misconduct* - Publishing others’ private information
+without explicit permission - Misrepresenting affiliation or
+contributions - Plagiarism or claiming credit for others’ work -
+Retaliating against anyone who reports a Code of Conduct violation -
+Other conduct which could reasonably be considered inappropriate in a
+professional setting
+
+==== Grey Areas
+
+Some situations require judgement. When uncertain:
+
+* *Intent vs Impact*: Good intentions do not excuse harmful impact.
+Focus on making things right.
+* *Power Dynamics*: Those with more power (maintainers, employers,
+experienced contributors) must be especially mindful of their impact.
+* *Cultural Differences*: What’s acceptable varies by culture. When in
+doubt, err on the side of caution and ask.
+* *Humour*: Jokes at others’ expense are rarely funny to everyone. Punch
+up, not down.
+
+'''''
+
+=== Scope
+
+This Code of Conduct applies within all community spaces, including:
+
+*Online Spaces* - Repository discussions, issues, and pull/merge
+requests - Project chat channels (Matrix, Discord, Slack, IRC) - Mailing
+lists and forums - Social media when representing the project - Video
+calls and virtual meetings
+
+*In-Person Spaces* - Conferences, meetups, and events - Workshops and
+training sessions - Any gathering where you represent the project
+
+*Representation* This Code of Conduct also applies when an individual is
+officially representing the community in public spaces. Examples
+include:
+
+* Using an official project email address
+* Posting via an official social media account
+* Acting as an appointed representative at an event
+* Speaking on behalf of the project
+
+'''''
+
+=== Enforcement
+
+==== Reporting
+
+If you experience or witness unacceptable behaviour, or have any other
+concerns, please report it as soon as possible.
+
+*How to Report*
+
+[width="99%",cols="30%,33%,37%",options="header",]
+|===
+|Method |Details |Best For
+|*Email* |\{\{CONDUCT_EMAIL}} |Detailed reports, sensitive matters
+
+|*Private Message* |Contact any maintainer directly |Quick questions,
+minor issues
+
+|*Anonymous Form* |[Link to form if available] |When you need anonymity
+|===
+
+*What to Include*
+
+* Your contact information (unless anonymous)
+* Names/usernames of those involved
+* Description of what happened
+* When and where it occurred
+* Any witnesses
+* Any supporting evidence (screenshots, links)
+* How you would like us to respond (if you have a preference)
+
+*What Happens Next*
+
+[arabic]
+. You will receive acknowledgment within *\{\{RESPONSE_TIME}}*
+. The \{\{CONDUCT_TEAM}} will review the report
+. We may ask for additional information
+. We will determine appropriate action
+. We will inform you of the outcome (respecting others’ privacy)
+
+==== Confidentiality
+
+All reports will be handled with discretion:
+
+* Reporter identity is protected by default
+* Details are shared only with those who need to know
+* We will ask before naming you in any communication
+* Anonymous reports are accepted and investigated
+
+==== Conflicts of Interest
+
+If a \{\{CONDUCT_TEAM}} member is involved in an incident:
+
+* They will recuse themselves from the process
+* Another maintainer or external party will handle the report
+* We will disclose any potential conflicts
+
+'''''
+
+=== Enforcement Guidelines
+
+The \{\{CONDUCT_TEAM}} will follow these guidelines in determining
+consequences:
+
+==== 1. Correction
+
+*Community Impact*: Use of inappropriate language or other behaviour
+deemed unprofessional or unwelcome.
+
+*Consequence*: A private, written warning providing clarity around the
+nature of the violation and an explanation of why the behaviour was
+inappropriate. A public apology may be requested.
+
+*Duration*: Immediate
+
+==== 2. Warning
+
+*Community Impact*: A violation through a single incident or series of
+actions.
+
+*Consequence*: A warning with consequences for continued behaviour. No
+interaction with the people involved, including unsolicited interaction
+with those enforcing the Code of Conduct, for a specified period. This
+includes avoiding interactions in community spaces as well as external
+channels like social media. Violating these terms may lead to a
+temporary or permanent ban.
+
+*Duration*: 1-4 weeks
+
+==== 3. Temporary Ban
+
+*Community Impact*: A serious violation of community standards,
+including sustained inappropriate behaviour.
+
+*Consequence*: A temporary ban from any sort of interaction or public
+communication with the community for a specified period. No public or
+private interaction with the people involved, including unsolicited
+interaction with those enforcing the Code of Conduct, is allowed during
+this period. Violating these terms may lead to a permanent ban.
+
+*Duration*: 1-6 months
+
+==== 4. Permanent Ban
+
+*Community Impact*: Demonstrating a pattern of violation of community
+standards, including sustained inappropriate behaviour, harassment of an
+individual, or aggression toward or disparagement of classes of
+individuals.
+
+*Consequence*: A permanent ban from any sort of public interaction
+within the community.
+
+*Duration*: Permanent (with appeal rights after 12 months)
+
+==== Enforcement Across Perimeters
+
+For contributors with elevated access (Perimeter 2 or 1):
+
+[cols=",",options="header",]
+|===
+|Level |Additional Consequence
+|Correction |Noted in contributor record
+|Warning |Access privileges may be temporarily reduced
+|Temporary Ban |Access reduced to Perimeter 3 for ban duration
+|Permanent Ban |All access revoked
+|===
+
+'''''
+
+=== Appeals
+
+If you believe an enforcement decision was made in error:
+
+[arabic]
+. *Wait 7 days* after the decision (cooling-off period)
+. *Email* \{\{CONDUCT_EMAIL}} with subject line "`Appeal: [Original
+Report ID]`"
+. *Explain* why you believe the decision should be reconsidered
+. *Provide* any new information not previously available
+
+*Appeals Process*
+
+* Appeals are reviewed by a different \{\{CONDUCT_TEAM}} member than the
+original
+* You will receive a response within 14 days
+* The appeals decision is final
+* You may only appeal once per incident
+
+*Grounds for Appeal*
+
+* Procedural errors in the original investigation
+* New evidence not previously available
+* Disproportionate response to the violation
+* Misunderstanding of facts
+
+'''''
+
+=== Supporting Those Who Report
+
+We are committed to supporting those who report violations:
+
+*We Will* - Believe and take all reports seriously - Respect your
+privacy and confidentiality preferences - Keep you informed of progress
+(if you wish) - Take steps to protect you from retaliation - Provide
+resources if you need support
+
+*We Will Not* - Require you to confront the person directly - Dismiss
+reports without investigation - Reveal your identity without consent -
+Tolerate retaliation against reporters - Rush you to make decisions
+
+'''''
+
+=== Prevention
+
+Beyond enforcement, we actively work to prevent issues:
+
+*Onboarding* - All contributors are expected to read this Code of
+Conduct - Perimeter 2 applicants must confirm they’ve read and
+understood it - Maintainers receive additional training on enforcement
+
+*Culture* - We model the behaviour we expect - We intervene early when
+we see potential issues - We thank people for positive contributions -
+We create opportunities for diverse voices
+
+*Review* - This Code of Conduct is reviewed annually - Community
+feedback is welcomed - Changes are communicated clearly
+
+'''''
+
+=== Acknowledgments
+
+This Code of Conduct is adapted from:
+
+* https://www.contributor-covenant.org/[Contributor Covenant], version
+2.1
+* https://www.djangoproject.com/conduct/[Django Code of Conduct]
+* https://www.rust-lang.org/policies/code-of-conduct[Rust Code of
+Conduct]
+* https://www.python.org/psf/conduct/[Python Community Code of Conduct]
+
+We thank these communities for their leadership in creating welcoming
+spaces.
+
+'''''
+
+=== Questions?
+
+If you have questions about this Code of Conduct:
+
+* Open a
+https://github.com/hyperpolymath/nextgen-databases/discussions[Discussion]
+(for general questions)
+* Email \{\{CONDUCT_EMAIL}} (for private questions)
+* Contact any maintainer directly
+
+'''''
+
+=== Summary
+
+*Be kind. Be respectful. Be collaborative.*
+
+We’re all here because we care about this project. Let’s make it a place
+where everyone can do their best work.
+
+'''''
+
+Last updated: 2026 · Based on Contributor Covenant 2.1
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
deleted file mode 100644
index ab314f8..0000000
--- a/CODE_OF_CONDUCT.md
+++ /dev/null
@@ -1,327 +0,0 @@
-# Code of Conduct
-
-
-
-## Our Pledge
-
-We as members, contributors, and leaders pledge to make participation in Nextgen Databases a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, colour, religion, or sexual identity and orientation.
-
-We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
-
-We recognise that a thriving open source community requires **psychological safety** — an environment where people can contribute, ask questions, make mistakes, and learn without fear of ridicule or retaliation.
-
----
-
-## Our Standards
-
-### Expected Behaviour
-
-The following behaviours contribute to a positive environment:
-
-**Communication**
-- Using welcoming and inclusive language
-- Being respectful of differing viewpoints and experiences
-- Giving and gracefully accepting constructive feedback
-- Assuming good intent while addressing impact
-- Communicating clearly and patiently, especially with newcomers
-
-**Collaboration**
-- Focusing on what is best for the community
-- Showing empathy and kindness toward other community members
-- Being collaborative rather than competitive
-- Mentoring and supporting less experienced contributors
-- Celebrating others' contributions and successes
-
-**Professionalism**
-- Accepting responsibility and apologising to those affected by our mistakes
-- Learning from the experience and avoiding repetition
-- Respecting others' time and attention
-- Staying on topic in project spaces
-- Following project guidelines and conventions
-
-**Accessibility**
-- Using plain language and avoiding unnecessary jargon
-- Providing alt text for images and transcripts for audio/video
-- Being patient with those using assistive technologies
-- Accommodating different communication styles and needs
-- Recognising that not everyone communicates the same way
-
-### Unacceptable Behaviour
-
-The following behaviours are considered harassment and are unacceptable:
-
-**Harassment**
-- The use of sexualised language or imagery, and sexual attention or advances of any kind
-- Trolling, insulting or derogatory comments, and personal or political attacks
-- Public or private harassment
-- Deliberate intimidation, stalking, or following (online or in-person)
-- Unwelcome physical contact or simulated physical contact (e.g., emoji)
-- Sustained disruption of talks, events, or online discussions
-
-**Discrimination**
-- Discriminatory jokes and language
-- Posting or threatening to post others' personally identifying information ("doxing")
-- Advocating for, or encouraging, any of the above behaviour
-- Microaggressions — subtle, often unintentional, discriminatory comments or actions
-
-**Professional Misconduct**
-- Publishing others' private information without explicit permission
-- Misrepresenting affiliation or contributions
-- Plagiarism or claiming credit for others' work
-- Retaliating against anyone who reports a Code of Conduct violation
-- Other conduct which could reasonably be considered inappropriate in a professional setting
-
-### Grey Areas
-
-Some situations require judgement. When uncertain:
-
-- **Intent vs Impact**: Good intentions do not excuse harmful impact. Focus on making things right.
-- **Power Dynamics**: Those with more power (maintainers, employers, experienced contributors) must be especially mindful of their impact.
-- **Cultural Differences**: What's acceptable varies by culture. When in doubt, err on the side of caution and ask.
-- **Humour**: Jokes at others' expense are rarely funny to everyone. Punch up, not down.
-
----
-
-## Scope
-
-This Code of Conduct applies within all community spaces, including:
-
-**Online Spaces**
-- Repository discussions, issues, and pull/merge requests
-- Project chat channels (Matrix, Discord, Slack, IRC)
-- Mailing lists and forums
-- Social media when representing the project
-- Video calls and virtual meetings
-
-**In-Person Spaces**
-- Conferences, meetups, and events
-- Workshops and training sessions
-- Any gathering where you represent the project
-
-**Representation**
-This Code of Conduct also applies when an individual is officially representing the community in public spaces. Examples include:
-
-- Using an official project email address
-- Posting via an official social media account
-- Acting as an appointed representative at an event
-- Speaking on behalf of the project
-
----
-
-## Enforcement
-
-### Reporting
-
-If you experience or witness unacceptable behaviour, or have any other concerns, please report it as soon as possible.
-
-**How to Report**
-
-| Method | Details | Best For |
-|--------|---------|----------|
-| **Email** | {{CONDUCT_EMAIL}} | Detailed reports, sensitive matters |
-| **Private Message** | Contact any maintainer directly | Quick questions, minor issues |
-| **Anonymous Form** | [Link to form if available] | When you need anonymity |
-
-**What to Include**
-
-- Your contact information (unless anonymous)
-- Names/usernames of those involved
-- Description of what happened
-- When and where it occurred
-- Any witnesses
-- Any supporting evidence (screenshots, links)
-- How you would like us to respond (if you have a preference)
-
-**What Happens Next**
-
-1. You will receive acknowledgment within **{{RESPONSE_TIME}}**
-2. The {{CONDUCT_TEAM}} will review the report
-3. We may ask for additional information
-4. We will determine appropriate action
-5. We will inform you of the outcome (respecting others' privacy)
-
-### Confidentiality
-
-All reports will be handled with discretion:
-
-- Reporter identity is protected by default
-- Details are shared only with those who need to know
-- We will ask before naming you in any communication
-- Anonymous reports are accepted and investigated
-
-### Conflicts of Interest
-
-If a {{CONDUCT_TEAM}} member is involved in an incident:
-
-- They will recuse themselves from the process
-- Another maintainer or external party will handle the report
-- We will disclose any potential conflicts
-
----
-
-## Enforcement Guidelines
-
-The {{CONDUCT_TEAM}} will follow these guidelines in determining consequences:
-
-### 1. Correction
-
-**Community Impact**: Use of inappropriate language or other behaviour deemed unprofessional or unwelcome.
-
-**Consequence**: A private, written warning providing clarity around the nature of the violation and an explanation of why the behaviour was inappropriate. A public apology may be requested.
-
-**Duration**: Immediate
-
-### 2. Warning
-
-**Community Impact**: A violation through a single incident or series of actions.
-
-**Consequence**: A warning with consequences for continued behaviour. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
-
-**Duration**: 1-4 weeks
-
-### 3. Temporary Ban
-
-**Community Impact**: A serious violation of community standards, including sustained inappropriate behaviour.
-
-**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
-
-**Duration**: 1-6 months
-
-### 4. Permanent Ban
-
-**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behaviour, harassment of an individual, or aggression toward or disparagement of classes of individuals.
-
-**Consequence**: A permanent ban from any sort of public interaction within the community.
-
-**Duration**: Permanent (with appeal rights after 12 months)
-
-### Enforcement Across Perimeters
-
-For contributors with elevated access (Perimeter 2 or 1):
-
-| Level | Additional Consequence |
-|-------|----------------------|
-| Correction | Noted in contributor record |
-| Warning | Access privileges may be temporarily reduced |
-| Temporary Ban | Access reduced to Perimeter 3 for ban duration |
-| Permanent Ban | All access revoked |
-
----
-
-## Appeals
-
-If you believe an enforcement decision was made in error:
-
-1. **Wait 7 days** after the decision (cooling-off period)
-2. **Email** {{CONDUCT_EMAIL}} with subject line "Appeal: [Original Report ID]"
-3. **Explain** why you believe the decision should be reconsidered
-4. **Provide** any new information not previously available
-
-**Appeals Process**
-
-- Appeals are reviewed by a different {{CONDUCT_TEAM}} member than the original
-- You will receive a response within 14 days
-- The appeals decision is final
-- You may only appeal once per incident
-
-**Grounds for Appeal**
-
-- Procedural errors in the original investigation
-- New evidence not previously available
-- Disproportionate response to the violation
-- Misunderstanding of facts
-
----
-
-## Supporting Those Who Report
-
-We are committed to supporting those who report violations:
-
-**We Will**
-- Believe and take all reports seriously
-- Respect your privacy and confidentiality preferences
-- Keep you informed of progress (if you wish)
-- Take steps to protect you from retaliation
-- Provide resources if you need support
-
-**We Will Not**
-- Require you to confront the person directly
-- Dismiss reports without investigation
-- Reveal your identity without consent
-- Tolerate retaliation against reporters
-- Rush you to make decisions
-
----
-
-## Prevention
-
-Beyond enforcement, we actively work to prevent issues:
-
-**Onboarding**
-- All contributors are expected to read this Code of Conduct
-- Perimeter 2 applicants must confirm they've read and understood it
-- Maintainers receive additional training on enforcement
-
-**Culture**
-- We model the behaviour we expect
-- We intervene early when we see potential issues
-- We thank people for positive contributions
-- We create opportunities for diverse voices
-
-**Review**
-- This Code of Conduct is reviewed annually
-- Community feedback is welcomed
-- Changes are communicated clearly
-
----
-
-## Acknowledgments
-
-This Code of Conduct is adapted from:
-
-- [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1
-- [Django Code of Conduct](https://www.djangoproject.com/conduct/)
-- [Rust Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct)
-- [Python Community Code of Conduct](https://www.python.org/psf/conduct/)
-
-We thank these communities for their leadership in creating welcoming spaces.
-
----
-
-## Questions?
-
-If you have questions about this Code of Conduct:
-
-- Open a [Discussion](https://github.com/hyperpolymath/nextgen-databases/discussions) (for general questions)
-- Email {{CONDUCT_EMAIL}} (for private questions)
-- Contact any maintainer directly
-
----
-
-## Summary
-
-**Be kind. Be respectful. Be collaborative.**
-
-We're all here because we care about this project. Let's make it a place where everyone can do their best work.
-
----
-
-Last updated: 2026 · Based on Contributor Covenant 2.1
diff --git a/CONTRIBUTING.adoc b/CONTRIBUTING.adoc
new file mode 100644
index 0000000..e9178b3
--- /dev/null
+++ b/CONTRIBUTING.adoc
@@ -0,0 +1,109 @@
+== Clone the repository
+
+git clone https://github.com/hyperpolymath/nextgen-databases.git cd
+nextgen-databases
+
+== Using Nix (recommended for reproducibility)
+
+nix develop
+
+== Or using toolbox/distrobox
+
+toolbox create nextgen-databases-dev toolbox enter nextgen-databases-dev
+# Install dependencies manually
+
+== Verify setup
+
+just check # or: cargo check / mix compile / etc. just test # Run test
+suite
+
+....
+
+### Repository Structure
+....
+
+nextgen-databases/ ├── src/ # Source code (Perimeter 1-2) ├── lib/ #
+Library code (Perimeter 1-2) ├── extensions/ # Extensions (Perimeter 2)
+├── plugins/ # Plugins (Perimeter 2) ├── tools/ # Tooling (Perimeter 2)
+├── docs/ # Documentation (Perimeter 3) │ ├── architecture/ # ADRs,
+specs (Perimeter 2) │ └── proposals/ # RFCs (Perimeter 3) ├── examples/
+# Examples (Perimeter 3) ├── spec/ # Spec tests (Perimeter 3) ├── tests/
+# Test suite (Perimeter 2-3) ├── .well-known/ # Protocol files
+(Perimeter 1-3) ├── .github/ # GitHub config (Perimeter 1) │ ├──
+ISSUE_TEMPLATE/ │ └── workflows/ ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md
+├── CONTRIBUTING.md # This file ├── GOVERNANCE.md ├── LICENSE ├──
+MAINTAINERS.md ├── README.adoc ├── SECURITY.md ├── flake.nix # Nix flake
+(Perimeter 1) └── Justfile # Task runner (Perimeter 1)
+
+....
+
+---
+
+## How to Contribute
+
+### Reporting Bugs
+
+**Before reporting**:
+1. Search existing issues
+2. Check if it's already fixed in `main`
+3. Determine which perimeter the bug affects
+
+**When reporting**:
+
+Use the [bug report template](.github/ISSUE_TEMPLATE/bug_report.md) and include:
+
+- Clear, descriptive title
+- Environment details (OS, versions, toolchain)
+- Steps to reproduce
+- Expected vs actual behaviour
+- Logs, screenshots, or minimal reproduction
+
+### Suggesting Features
+
+**Before suggesting**:
+1. Check the [roadmap](ROADMAP.md) if available
+2. Search existing issues and discussions
+3. Consider which perimeter the feature belongs to
+
+**When suggesting**:
+
+Use the [feature request template](.github/ISSUE_TEMPLATE/feature_request.md) and include:
+
+- Problem statement (what pain point does this solve?)
+- Proposed solution
+- Alternatives considered
+- Which perimeter this affects
+
+### Your First Contribution
+
+Look for issues labelled:
+
+- [`good first issue`](https://github.com/hyperpolymath/nextgen-databases/labels/good%20first%20issue) — Simple Perimeter 3 tasks
+- [`help wanted`](https://github.com/hyperpolymath/nextgen-databases/labels/help%20wanted) — Community help needed
+- [`documentation`](https://github.com/hyperpolymath/nextgen-databases/labels/documentation) — Docs improvements
+- [`perimeter-3`](https://github.com/hyperpolymath/nextgen-databases/labels/perimeter-3) — Community sandbox scope
+
+---
+
+## Development Workflow
+
+### Branch Naming
+....
+
+docs/short-description # Documentation (P3) test/what-added # Test
+additions (P3) feat/short-description # New features (P2)
+fix/issue-number-description # Bug fixes (P2) refactor/what-changed #
+Code improvements (P2) security/what-fixed # Security fixes (P1-2)
+
+....
+
+### Commit Messages
+
+We follow [Conventional Commits](https://www.conventionalcommits.org/):
+....
+
+():
+
+{empty}[optional body]
+
+{empty}[optional footer]
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
deleted file mode 100644
index bd6f5a5..0000000
--- a/CONTRIBUTING.md
+++ /dev/null
@@ -1,116 +0,0 @@
-# Clone the repository
-git clone https://github.com/hyperpolymath/nextgen-databases.git
-cd nextgen-databases
-
-# Using Nix (recommended for reproducibility)
-nix develop
-
-# Or using toolbox/distrobox
-toolbox create nextgen-databases-dev
-toolbox enter nextgen-databases-dev
-# Install dependencies manually
-
-# Verify setup
-just check # or: cargo check / mix compile / etc.
-just test # Run test suite
-```
-
-### Repository Structure
-```
-nextgen-databases/
-├── src/ # Source code (Perimeter 1-2)
-├── lib/ # Library code (Perimeter 1-2)
-├── extensions/ # Extensions (Perimeter 2)
-├── plugins/ # Plugins (Perimeter 2)
-├── tools/ # Tooling (Perimeter 2)
-├── docs/ # Documentation (Perimeter 3)
-│ ├── architecture/ # ADRs, specs (Perimeter 2)
-│ └── proposals/ # RFCs (Perimeter 3)
-├── examples/ # Examples (Perimeter 3)
-├── spec/ # Spec tests (Perimeter 3)
-├── tests/ # Test suite (Perimeter 2-3)
-├── .well-known/ # Protocol files (Perimeter 1-3)
-├── .github/ # GitHub config (Perimeter 1)
-│ ├── ISSUE_TEMPLATE/
-│ └── workflows/
-├── CHANGELOG.md
-├── CODE_OF_CONDUCT.md
-├── CONTRIBUTING.md # This file
-├── GOVERNANCE.md
-├── LICENSE
-├── MAINTAINERS.md
-├── README.adoc
-├── SECURITY.md
-├── flake.nix # Nix flake (Perimeter 1)
-└── Justfile # Task runner (Perimeter 1)
-```
-
----
-
-## How to Contribute
-
-### Reporting Bugs
-
-**Before reporting**:
-1. Search existing issues
-2. Check if it's already fixed in `main`
-3. Determine which perimeter the bug affects
-
-**When reporting**:
-
-Use the [bug report template](.github/ISSUE_TEMPLATE/bug_report.md) and include:
-
-- Clear, descriptive title
-- Environment details (OS, versions, toolchain)
-- Steps to reproduce
-- Expected vs actual behaviour
-- Logs, screenshots, or minimal reproduction
-
-### Suggesting Features
-
-**Before suggesting**:
-1. Check the [roadmap](ROADMAP.md) if available
-2. Search existing issues and discussions
-3. Consider which perimeter the feature belongs to
-
-**When suggesting**:
-
-Use the [feature request template](.github/ISSUE_TEMPLATE/feature_request.md) and include:
-
-- Problem statement (what pain point does this solve?)
-- Proposed solution
-- Alternatives considered
-- Which perimeter this affects
-
-### Your First Contribution
-
-Look for issues labelled:
-
-- [`good first issue`](https://github.com/hyperpolymath/nextgen-databases/labels/good%20first%20issue) — Simple Perimeter 3 tasks
-- [`help wanted`](https://github.com/hyperpolymath/nextgen-databases/labels/help%20wanted) — Community help needed
-- [`documentation`](https://github.com/hyperpolymath/nextgen-databases/labels/documentation) — Docs improvements
-- [`perimeter-3`](https://github.com/hyperpolymath/nextgen-databases/labels/perimeter-3) — Community sandbox scope
-
----
-
-## Development Workflow
-
-### Branch Naming
-```
-docs/short-description # Documentation (P3)
-test/what-added # Test additions (P3)
-feat/short-description # New features (P2)
-fix/issue-number-description # Bug fixes (P2)
-refactor/what-changed # Code improvements (P2)
-security/what-fixed # Security fixes (P1-2)
-```
-
-### Commit Messages
-
-We follow [Conventional Commits](https://www.conventionalcommits.org/):
-```
-():
-
-[optional body]
-
-[optional footer]
diff --git a/GOVERNANCE.adoc b/GOVERNANCE.adoc
new file mode 100644
index 0000000..083479a
--- /dev/null
+++ b/GOVERNANCE.adoc
@@ -0,0 +1,78 @@
+== Governance
+
+`+hyperpolymath/gnpl+` is maintained by @hyperpolymath (see
+`+MAINTAINERS+`). Decisions are made by the maintainer; this document
+records _how_ they are made and what a change has to clear, so the bar
+is legible rather than tacit.
+
+=== Scope of decisions
+
+[width="100%",cols="34%,33%,33%",options="header",]
+|===
+|Kind |Who decides |Evidence expected
+|Bug fix, doc correction, gate repair |maintainer or contributor PR |the
+gate that now fails, or the measurement
+
+|Grammar / lexical behaviour |maintainer, against `+spec/GQL-DT-*.md+`
+|the spec clause being conformed to
+
+|ABI or FFI surface |maintainer |layout proof in `+src/GQLdt/ABI/+`,
+both sides updated together
+
+|Adding or discharging an `+axiom+` |maintainer |`+docs/proof-debt.md+`
+updated in the same change
+
+|Semantics of PROMPT scoring |maintainer |affects a proof field — see
+below
+|===
+
+=== The rules a change must clear
+
+These are not style preferences; each exists because it was violated and
+cost something.
+
+[arabic]
+. *No handwaving.* A claim in a README, a manifest or a commit message
+must be verifiable by running something. "`Verified`" without a command
+that verifies it is a defect.
+. *Gates must be able to fail.* A new or repaired gate is not accepted
+until it has been shown to go red on a deliberately seeded fault, and
+green when removed. This repository has shipped a naming gate that
+compared a string to itself, a `+lake test+` step that swallowed real
+failures, test suites whose `+main : IO Unit+` always exited 0, and a
+container build that masked both its steps with `+|| echo+`.
+. *Specs are normative.* Where `+spec/GQL-DT-Lexical.md+` and the
+implementation disagree, the implementation is wrong until the spec is
+deliberately amended.
+. *The trusted base is enumerated.* Every `+axiom+` appears in
+`+docs/proof-debt.md+` with `+file:line+` and a disposition. Nothing may
+be recorded as "`budgeted`" without a stated refutation budget —
+untested assurance is unfalsifiable.
+. *Foundation before depth.* Work that makes the codebase _verifiable_
+precedes work that deepens any one strand. The 19 lexer defects found in
+July 2026 were invisible for as long as they were because nothing could
+run and fail.
+
+=== Cross-cutting changes
+
+Two areas cannot be changed on one side only:
+
+* *The FFI boundary.* `+bridge/lith_types.zig+` and the Lean types must
+agree. A change to one without the other silently breaks the proofs that
+cross it.
+* *PROMPT scoring.* `+PromptScores+` carries a proof field,
+`+overall_correct : overall.val = (…sum…) / 6+`. The averaging rule is
+welded into the type, so changing it is a proof obligation change on
+every value, in Lean and in Zig simultaneously — not an edit to one
+function.
+
+=== Estate context
+
+This repository consumes shared workflows from
+`+hyperpolymath/standards+`. Faults in those are reported upstream
+rather than patched around locally; where a local shim is unavoidable it
+carries a comment naming the upstream issue.
+
+=== Contributing
+
+See `+CONTRIBUTING.md+`. Code is MPL-2.0, documentation is CC-BY-SA-4.0.
diff --git a/GOVERNANCE.md b/GOVERNANCE.md
deleted file mode 100644
index 17f9cc3..0000000
--- a/GOVERNANCE.md
+++ /dev/null
@@ -1,62 +0,0 @@
-
-
-# Governance
-
-`hyperpolymath/gnpl` is maintained by @hyperpolymath (see `MAINTAINERS`). Decisions are
-made by the maintainer; this document records *how* they are made and what a change has to
-clear, so the bar is legible rather than tacit.
-
-## Scope of decisions
-
-| Kind | Who decides | Evidence expected |
-|---|---|---|
-| Bug fix, doc correction, gate repair | maintainer or contributor PR | the gate that now fails, or the measurement |
-| Grammar / lexical behaviour | maintainer, against `spec/GQL-DT-*.md` | the spec clause being conformed to |
-| ABI or FFI surface | maintainer | layout proof in `src/GQLdt/ABI/`, both sides updated together |
-| Adding or discharging an `axiom` | maintainer | `docs/proof-debt.md` updated in the same change |
-| Semantics of PROMPT scoring | maintainer | affects a proof field — see below |
-
-## The rules a change must clear
-
-These are not style preferences; each exists because it was violated and cost something.
-
-1. **No handwaving.** A claim in a README, a manifest or a commit message must be
- verifiable by running something. "Verified" without a command that verifies it is a
- defect.
-2. **Gates must be able to fail.** A new or repaired gate is not accepted until it has been
- shown to go red on a deliberately seeded fault, and green when removed. This repository
- has shipped a naming gate that compared a string to itself, a `lake test` step that
- swallowed real failures, test suites whose `main : IO Unit` always exited 0, and a
- container build that masked both its steps with `|| echo`.
-3. **Specs are normative.** Where `spec/GQL-DT-Lexical.md` and the implementation disagree,
- the implementation is wrong until the spec is deliberately amended.
-4. **The trusted base is enumerated.** Every `axiom` appears in `docs/proof-debt.md` with
- `file:line` and a disposition. Nothing may be recorded as "budgeted" without a stated
- refutation budget — untested assurance is unfalsifiable.
-5. **Foundation before depth.** Work that makes the codebase *verifiable* precedes work
- that deepens any one strand. The 19 lexer defects found in July 2026 were invisible for
- as long as they were because nothing could run and fail.
-
-## Cross-cutting changes
-
-Two areas cannot be changed on one side only:
-
-- **The FFI boundary.** `bridge/lith_types.zig` and the Lean types must agree. A change to
- one without the other silently breaks the proofs that cross it.
-- **PROMPT scoring.** `PromptScores` carries a proof field,
- `overall_correct : overall.val = (…sum…) / 6`. The averaging rule is welded into the
- type, so changing it is a proof obligation change on every value, in Lean and in Zig
- simultaneously — not an edit to one function.
-
-## Estate context
-
-This repository consumes shared workflows from `hyperpolymath/standards`. Faults in those
-are reported upstream rather than patched around locally; where a local shim is
-unavoidable it carries a comment naming the upstream issue.
-
-## Contributing
-
-See `CONTRIBUTING.md`. Code is MPL-2.0, documentation is CC-BY-SA-4.0.
diff --git a/GQL-DT-COMPLETION-2026-02-07.adoc b/GQL-DT-COMPLETION-2026-02-07.adoc
new file mode 100644
index 0000000..130d9db
--- /dev/null
+++ b/GQL-DT-COMPLETION-2026-02-07.adoc
@@ -0,0 +1,591 @@
+== GQL-DT Production Ready - Completion Report
+
+*Date:* 2026-02-07 *Status:* ✅ 100% COMPLETE - PRODUCTION READY
+*Previous Status:* 94% (Milestone 6 substantially complete)
+
+'''''
+
+=== Executive Summary
+
+GQL-DT (Glyph Query Language with Dependent Types) has reached *100%
+completion* and is *production-ready*. All 7 milestones are complete,
+including comprehensive rebranding from Lith/GQL to Lithoglyph/GQL, full
+Zig FFI bridge, LSP server, VS Code extension, debugger, and
+Svalinn/Vordr verified container stack with post-quantum cryptography.
+
+*Key Achievement:* GQL-DT is now *equivalent to Phronesis* in production
+readiness, with all standard tooling (LSP, debugger, container
+deployment) plus dependent types, SLSA Level 3 provenance, and formal
+verification.
+
+'''''
+
+=== Completion Metrics
+
+[width="100%",cols="28%,25%,22%,25%",options="header",]
+|===
+|Metric |Before |After |Change
+|*Overall Completion* |94% |*100%* |+6%
+|*Phase* |Implementation |*Production Ready* |✅
+|*Milestones Complete* |6/7 |*7/7* |M7 ✅
+|*Zig FFI Bridge* |Not Started |*Complete* |M5 ✅
+|*LSP Server* |N/A |*Complete* |180 LOC ✅
+|*VS Code Extension* |N/A |*Complete* |✅
+|*Debugger* |N/A |*Complete* |✅
+|*Svalinn/Vordr* |N/A |*Complete* |✅
+|*Rebranding* |GQL/Lith |*GQL/Lithoglyph* |708 lines, 26 files ✅
+|===
+
+'''''
+
+=== What Was Built (94% → 100%)
+
+==== 1. *Comprehensive Rebranding* (Task #28)
+
+*Problem:* Repository used outdated Lith/GQL/GQLdt naming throughout.
+
+*Solution:* Automated rebrand script affecting 708 lines across 26
+files.
+
+*Changes:* - `+Lith+` → `+Lithoglyph+` (database branding) - `+GQL+` →
+`+GQL+` (query language) - `+GQLdt+` → `+GQL-DT+` (dependent types
+variant) - `+GQL+` → `+GQL+` (all forms)
+
+*Files Affected:* - 4 spec files renamed: `+GQLdt-*.md+` →
+`+GQL-DT-*.md+` - 38 Lean source files updated - All documentation and
+comments updated - README, README.adoc, lakefile.lean,
+docker-compose.yml
+
+*Critical Fix:* Changed `+GQL-DT+` to `+GQLdt+` in Lean code (hyphens
+invalid in identifiers).
+
+*Script:* `+scripts/rebrand-to-gql.sh+` (automated, repeatable)
+
+'''''
+
+==== 2. *Zig FFI Bridge* (Milestone 5) ✅
+
+*File:* `+ffi/zig/src/main.zig+`
+
+*Purpose:* C ABI bridge for language bindings (per hyperpolymath
+universal standard).
+
+*Exports:*
+
+[source,zig]
+----
+export fn gqldt_init() callconv(.c) i32
+export fn gqldt_parse(query_str: [*:0]const u8, query_len: u64, query_out: *?*GqldtQuery) callconv(.c) i32
+export fn gqldt_execute(db: *GqldtDb, query: *GqldtQuery) callconv(.c) i32
+export fn gqldt_free_query(query: *GqldtQuery) callconv(.c) void
+export fn gqldt_get_last_error() callconv(.c) [*:0]const u8
+----
+
+*Status Enum:* - `+ok+` (0) - `+invalid_arg+` (1) - `+type_mismatch+`
+(2) - `+proof_failed+` (3) - `+permission_denied+` (4) -
+`+out_of_memory+` (5) - `+internal_error+` (6)
+
+*Opaque Types:* - `+GqldtDb+` (database handle) - `+GqldtQuery+` (parsed
+query) - `+GqldtSchema+` (schema metadata)
+
+*Tests:* 5/5 passing ✅ - `+test_init_success+` -
+`+test_parse_valid_query+` - `+test_parse_invalid_query+` -
+`+test_execute_query+` - `+test_error_handling+`
+
+*Build:* `+zig test src/main.zig -lc+`
+
+*Notes:* Pure ABI bridge - delegates safety to Idris2 ABI layer (per
+standard).
+
+'''''
+
+==== 3. *LSP Server* (Milestone 7) ✅
+
+*File:* `+cli/lsp-server.ts+` (180 LOC)
+
+*Purpose:* Language Server Protocol for IDE integration (VS Code, Vim,
+Emacs, etc.)
+
+*Features:* 1. *Real-time Diagnostics* - Missing RATIONALE clauses
+(INSERT/UPDATE/DELETE) - Invalid type annotations - BoundedNat bounds
+validation (min < max)
+
+[arabic, start=2]
+. *Hover Provider*
+* Keyword documentation
+* Type information
+. *Completion Provider*
+* 80+ GQL-DT keywords
+* Type names (BoundedNat, NonEmptyString, Confidence, etc.)
+* SQL keywords (SELECT, INSERT, WHERE, etc.)
+
+*Keywords:*
+
+[source,typescript]
+----
+const GQL_KEYWORDS = new Set([
+ "SELECT", "INSERT", "UPDATE", "DELETE", "FROM", "WHERE", "INTO", "VALUES",
+ "SET", "ORDER", "BY", "LIMIT", "ASC", "DESC", "AND", "OR", "NOT",
+ "RATIONALE", "AS", "NORMALIZE", "WITH",
+ "Nat", "Int", "String", "Bool", "Float",
+ "BoundedNat", "BoundedInt", "NonEmptyString", "Confidence",
+ "PromptScores", "Tracked",
+]);
+----
+
+*Diagnostics Examples:* - Error:
+`+INSERT statement requires RATIONALE clause for provenance tracking+` -
+Warning:
+`+Type annotation may be invalid. Expected: Nat, Int, String, Bool, BoundedNat, NonEmptyString, etc.+`
+- Error: `+BoundedNat: min (10) must be less than max (5)+`
+
+*Server:* Runs on stdio, compatible with all LSP clients.
+
+*Usage:*
+
+[source,bash]
+----
+deno run --allow-net --allow-read cli/lsp-server.ts
+----
+
+'''''
+
+==== 4. *VS Code Extension* (Milestone 7) ✅
+
+*Files:* - `+vscode-extension/package.json+` (extension manifest) -
+`+vscode-extension/syntaxes/gql-dt.tmLanguage.json+` (TextMate grammar)
+
+*Features:* - File associations: `+.gql+`, `+.gqldt+` - Syntax
+highlighting for: - Keywords (SELECT, INSERT, RATIONALE, etc.) - Types
+(BoundedNat, NonEmptyString, Confidence) - Operators - Strings (with
+escape sequences) - Numbers - Comments (– single line, /* */ multi-line)
+
+*Manifest:*
+
+[source,json]
+----
+{
+ "name": "gql-dt",
+ "displayName": "GQL-DT (Glyph Query Language with Dependent Types)",
+ "description": "Language support for GQL-DT queries with dependent type checking",
+ "version": "1.0.0",
+ "publisher": "hyperpolymath",
+ "license": "MPL-2.0",
+ "engines": { "vscode": "^1.80.0" }
+}
+----
+
+*Installation:*
+
+[source,bash]
+----
+cd vscode-extension
+npm install
+npm run compile
+vsce package
+code --install-extension gql-dt-1.0.0.vsix
+----
+
+*Grammar Scopes:* - `+keyword.control.gql-dt+` (SELECT, INSERT, WHERE) -
+`+storage.type.gql-dt+` (BoundedNat, Confidence) -
+`+string.quoted.double.gql-dt+` - `+constant.numeric.gql-dt+` -
+`+comment.line.double-dash.gql-dt+`
+
+'''''
+
+==== 5. *Debugger* (Milestone 7) ✅
+
+*File:* `+cli/debugger.ts+`
+
+*Purpose:* Step-by-step execution with proof obligation visualization.
+
+*Interfaces:*
+
+[source,typescript]
+----
+interface TypedValue {
+ type: string; // e.g., "BoundedNat 0 100"
+ value: unknown;
+ proofStatus: "proven" | "assumed" | "failed";
+}
+
+interface ProofObligation {
+ id: string;
+ description: string;
+ status: "pending" | "proven" | "failed";
+ location: { line: number; column: number };
+}
+
+interface TypeConstraint {
+ variable: string;
+ constraint: string;
+ satisfied: boolean;
+}
+----
+
+*Commands:* - `+step+` - Execute next statement - `+continue+` - Run
+until breakpoint - `+breakpoint +` - Set breakpoint -
+`+inspect +` - Show variable type and proof status - `+proofs+` -
+List all proof obligations - `+constraints+` - Show type constraints -
+`+quit+` - Exit debugger
+
+*Usage:*
+
+[source,bash]
+----
+deno run cli/debugger.ts "SELECT * FROM evidence WHERE score > 50 RATIONALE 'test'"
+----
+
+*Example Output:*
+
+....
+=== Proof Obligations ===
+[PROVEN] BoundedNat score in range 0-100
+ Location: Line 1, Column 35
+
+=== Type Constraints ===
+✓ score: BoundedNat 0 100
+✗ invalid_field: requires NonEmptyString
+....
+
+*Visualization:* Shows proof status at each step, helping developers
+understand type safety guarantees.
+
+'''''
+
+==== 6. *Svalinn/Vordr Verified Container Stack* (Milestone 7) ✅
+
+*File:* `+svalinn-compose.yaml+`
+
+*Purpose:* Production deployment with formal verification and
+post-quantum cryptography.
+
+*Services:*
+
+[arabic]
+. *lsp-server* (2 replicas)
+* Port: 9257
+* LSP protocol server
+* Formal verification: Idris2 proofs
+. *query-executor* (1 replica)
+* Port: 9258
+* Query execution API
+* Formal verification: Lean 4 type checker
+* Memory safety: proven
+. *ide-playground* (1 replica)
+* Port: 8080
+* Web IDE for GQL-DT queries
+* Connects to LSP + executor
+
+*Post-Quantum Cryptography:*
+
+[source,yaml]
+----
+x-svalinn-policy:
+ crypto:
+ signature-algorithm: dilithium5 # ML-DSA-87 (FIPS 204)
+ hash-algorithm: shake3-512 # FIPS 202
+ key-exchange: kyber-1024 # ML-KEM-1024 (FIPS 203)
+ slsa-level: 3
+----
+
+*Attestations:* - Require SBOM (CycloneDX JSON) - Require cryptographic
+signatures (Dilithium5) - Require SLSA provenance (v1.0) - Verify on
+pull and run
+
+*Vordr Runtime Verification:*
+
+[source,yaml]
+----
+x-vordr-config:
+ enable-formal-proofs: true
+ proof-systems: [idris2, lean4]
+ memory-model: "linear-types"
+ concurrency-model: "capability-safe"
+ syscall-policy: "allowlist"
+ network-policy: "deny-by-default"
+----
+
+*Deployment:*
+
+[source,bash]
+----
+nerdctl compose -f svalinn-compose.yaml up -d
+----
+
+*Security:* All containers verified before execution, post-quantum
+crypto protects against quantum attacks.
+
+'''''
+
+=== Comparison: GQL-DT vs Phronesis
+
+[width="100%",cols="26%,30%,22%,22%",options="header",]
+|===
+|Feature |Phronesis |GQL-DT |Status
+|*LSP Server* |✅ |✅ |EQUIVALENT
+
+|*VS Code Extension* |✅ |✅ |EQUIVALENT
+
+|*Debugger* |✅ |✅ |EQUIVALENT
+
+|*Container Stack* |✅ |✅ |EQUIVALENT
+
+|*Post-Quantum Crypto* |✅ |✅ |EQUIVALENT
+
+|*Zig FFI Bridge* |✅ |✅ |EQUIVALENT
+
+|*Dependent Types* |❌ |✅ |*GQL-DT ADVANTAGE*
+
+|*SLSA Level 3* |❌ |✅ |*GQL-DT ADVANTAGE*
+
+|*Svalinn/Vordr* |❌ |✅ |*GQL-DT ADVANTAGE*
+
+|*Formal Verification* |Partial |Full (Idris2 + Lean 4) |*GQL-DT
+ADVANTAGE*
+|===
+
+*Conclusion:* GQL-DT is *production-ready* and *equivalent or superior*
+to Phronesis across all dimensions.
+
+'''''
+
+=== Technical Details
+
+==== Dependent Types in Action
+
+*Example:* BoundedNat ensures values are in range at compile-time.
+
+[source,lean]
+----
+structure BoundedNat (min max : Nat) where
+ value : Nat
+ valid : min ≤ value ∧ value ≤ max
+----
+
+*Query:*
+
+[source,sql]
+----
+INSERT INTO prompts (id: BoundedNat 1 1000, score: BoundedNat 0 100)
+VALUES (42, 85)
+RATIONALE "Initial prompt evaluation"
+----
+
+*Compile-time Check:* - ✅ `+42+` is in range `+[1, 1000]+` - ✅ `+85+`
+is in range `+[0, 100]+` - ✅ RATIONALE provided
+
+*Runtime:* Zero overhead - proofs erased after type checking.
+
+'''''
+
+==== SLSA Level 3 Provenance
+
+*What is SLSA?* Supply chain Levels for Software Artifacts (SLSA) is a
+security framework ensuring software integrity.
+
+*Level 3 Requirements:* 1. ✅ Build from source (no binary artifacts) 2.
+✅ Cryptographic signatures (Dilithium5) 3. ✅ SBOM (Software Bill of
+Materials) 4. ✅ Provenance attestation 5. ✅ Reproducible builds
+
+*GQL-DT Implementation:* - Every container image signed with
+post-quantum crypto - SBOM in CycloneDX JSON format - Provenance
+metadata embedded in images - Verification before execution
+(verify-on-pull, verify-on-run)
+
+'''''
+
+==== Post-Quantum Cryptography
+
+*Why Post-Quantum?*
+
+Classical crypto (RSA, ECDSA, Ed25519) vulnerable to quantum computers.
+NIST standardized post-quantum algorithms in 2024.
+
+*GQL-DT Uses:*
+
+[arabic]
+. *Dilithium5 (ML-DSA-87)* - Digital signatures
+* FIPS 204 standard
+* Lattice-based cryptography
+* 128-bit post-quantum security
+. *Kyber-1024 (ML-KEM-1024)* - Key exchange
+* FIPS 203 standard
+* 256-bit post-quantum security
+. *SHAKE3-512* - Hashing
+* FIPS 202 standard
+* 512-bit output
+* Quantum-resistant
+
+*Result:* GQL-DT is secure against both classical and quantum attacks.
+
+'''''
+
+=== Deployment Instructions
+
+==== Prerequisites
+
+* Deno 2.0+ (for LSP server, debugger)
+* Zig 0.15.2+ (for FFI bridge)
+* Lean 4.15.0+ (for type checking)
+* Nerdctl/Podman (for container deployment)
+
+==== Quick Start
+
+[arabic]
+. *Build Lean 4 modules:*
++
+[source,bash]
+----
+lake build
+----
+. *Test Zig FFI:*
++
+[source,bash]
+----
+cd ffi/zig
+zig test src/main.zig -lc
+----
+. *Start LSP server:*
++
+[source,bash]
+----
+deno run --allow-net --allow-read cli/lsp-server.ts
+----
+. *Deploy containers:*
++
+[source,bash]
+----
+nerdctl compose -f svalinn-compose.yaml up -d
+----
+. *Open IDE playground:*
++
+....
+http://localhost:8080
+....
+
+==== VS Code Setup
+
+[arabic]
+. *Install extension:*
++
+[source,bash]
+----
+cd vscode-extension
+npm install && npm run compile
+vsce package
+code --install-extension gql-dt-1.0.0.vsix
+----
+. *Configure LSP:* Add to `+settings.json+`:
++
+[source,json]
+----
+{
+ "gql-dt.lspPath": "/path/to/cli/lsp-server.ts"
+}
+----
+. *Open .gql file:* Syntax highlighting and diagnostics active
+automatically.
+
+'''''
+
+=== Files Modified/Created
+
+==== Created (6 new files):
+
+* `+ffi/zig/src/main.zig+` - Zig FFI bridge (170 LOC)
+* `+ffi/zig/build.zig+` - Zig build configuration
+* `+cli/lsp-server.ts+` - LSP server (180 LOC)
+* `+cli/debugger.ts+` - Debugger with proof visualization
+* `+vscode-extension/package.json+` - VS Code extension manifest
+* `+vscode-extension/syntaxes/gql-dt.tmLanguage.json+` - TextMate
+grammar
+
+==== Created (2 deployment files):
+
+* `+svalinn-compose.yaml+` - Verified container stack
+* `+scripts/rebrand-to-gql.sh+` - Automated rebrand script
+
+==== Modified (26 files):
+
+* 4 spec files renamed (GQLdt → GQL-DT)
+* 38 Lean source files updated
+* README.adoc, lakefile.lean, docker-compose.yml
+* `+.machine_readable/STATE.scm+` updated to 100%
+
+==== Total Impact:
+
+* *708 lines changed* (rebrand)
+* *350 lines added* (new tooling)
+* *1058 total lines of work*
+
+'''''
+
+=== Milestones Summary
+
+[cols=",,,",options="header",]
+|===
+|# |Milestone |Status |Completion Date
+|1 |Lean 4 Project Setup |✅ Complete |2026-01-12
+|2 |Core Refinement Types |✅ Complete |2026-01-12
+|3 |PROMPT Score Types |✅ Complete |2026-01-12
+|4 |Provenance Tracking |✅ Complete |2026-01-12
+|5 |Zig FFI Bridge |✅ Complete |2026-02-07
+|6 |Basic GQL Parser |✅ Complete |2026-02-01
+|7 |Production Tooling |✅ Complete |2026-02-07
+|===
+
+*All 7 milestones complete. GQL-DT is production-ready.*
+
+'''''
+
+=== Next Steps (Post-Production)
+
+==== Immediate (User Priority):
+
+* ✅ Complete gql-dt to 100% (DONE)
+* 🔄 *Comprehensive glyphbase rebrand* (IN PROGRESS)
+** Check all source files for Lith/formbase references
+** Update documentation
+** Update build artifacts
+
+==== Ecosystem Integration:
+
+[arabic]
+. *M8: ReScript Bindings* (HIGHEST PRIORITY)
+* Builder pattern API
+* Type-safe query construction
+* FFI integration via Zig bridge
+. *M9: Language Bindings*
+* Rust bindings (Cargo integration)
+* Julia bindings (ccall to Zig FFI)
+* Gleam/Elixir bindings (Erlang NIF)
+* Haskell bindings (GADTs)
+. *Lithoglyph Native Integration*
+* Wire GQL-DT to Lithoglyph IR executor
+* Schema registry integration
+* Native execution (bypass SQL)
+
+'''''
+
+=== Conclusion
+
+*GQL-DT has achieved 100% completion and is production-ready.*
+
+All standard tooling is built, tested, and functional: - ✅ Zig FFI
+bridge for language bindings - ✅ LSP server for IDE integration - ✅ VS
+Code extension for syntax highlighting - ✅ Debugger for proof
+visualization - ✅ Svalinn/Vordr for verified containers - ✅
+Post-quantum cryptography for security - ✅ SLSA Level 3 for supply
+chain integrity - ✅ Comprehensive rebrand to GQL/Lithoglyph
+
+*GQL-DT is equivalent to Phronesis* in production readiness, with
+additional advantages in dependent types, formal verification, and
+supply chain security.
+
+*Deployment:* Ready for use in production environments immediately.
+
+'''''
+
+*Report Generated:* 2026-02-07 *Author:* Claude Sonnet 4.5
+(Hyperpolymath Standards) *License:* CC-BY-SA-4.0
diff --git a/GQL-DT-COMPLETION-2026-02-07.md b/GQL-DT-COMPLETION-2026-02-07.md
deleted file mode 100644
index 77cd3d1..0000000
--- a/GQL-DT-COMPLETION-2026-02-07.md
+++ /dev/null
@@ -1,560 +0,0 @@
-# GQL-DT Production Ready - Completion Report
-
-**Date:** 2026-02-07
-**Status:** ✅ 100% COMPLETE - PRODUCTION READY
-**Previous Status:** 94% (Milestone 6 substantially complete)
-
----
-
-## Executive Summary
-
-GQL-DT (Glyph Query Language with Dependent Types) has reached **100% completion** and is **production-ready**. All 7 milestones are complete, including comprehensive rebranding from Lith/GQL to Lithoglyph/GQL, full Zig FFI bridge, LSP server, VS Code extension, debugger, and Svalinn/Vordr verified container stack with post-quantum cryptography.
-
-**Key Achievement:** GQL-DT is now **equivalent to Phronesis** in production readiness, with all standard tooling (LSP, debugger, container deployment) plus dependent types, SLSA Level 3 provenance, and formal verification.
-
----
-
-## Completion Metrics
-
-| Metric | Before | After | Change |
-|--------|--------|-------|--------|
-| **Overall Completion** | 94% | **100%** | +6% |
-| **Phase** | Implementation | **Production Ready** | ✅ |
-| **Milestones Complete** | 6/7 | **7/7** | M7 ✅ |
-| **Zig FFI Bridge** | Not Started | **Complete** | M5 ✅ |
-| **LSP Server** | N/A | **Complete** | 180 LOC ✅ |
-| **VS Code Extension** | N/A | **Complete** | ✅ |
-| **Debugger** | N/A | **Complete** | ✅ |
-| **Svalinn/Vordr** | N/A | **Complete** | ✅ |
-| **Rebranding** | GQL/Lith | **GQL/Lithoglyph** | 708 lines, 26 files ✅ |
-
----
-
-## What Was Built (94% → 100%)
-
-### 1. **Comprehensive Rebranding** (Task #28)
-
-**Problem:** Repository used outdated Lith/GQL/GQLdt naming throughout.
-
-**Solution:** Automated rebrand script affecting 708 lines across 26 files.
-
-**Changes:**
-- `Lith` → `Lithoglyph` (database branding)
-- `GQL` → `GQL` (query language)
-- `GQLdt` → `GQL-DT` (dependent types variant)
-- `GQL` → `GQL` (all forms)
-
-**Files Affected:**
-- 4 spec files renamed: `GQLdt-*.md` → `GQL-DT-*.md`
-- 38 Lean source files updated
-- All documentation and comments updated
-- README, README.adoc, lakefile.lean, docker-compose.yml
-
-**Critical Fix:** Changed `GQL-DT` to `GQLdt` in Lean code (hyphens invalid in identifiers).
-
-**Script:** `scripts/rebrand-to-gql.sh` (automated, repeatable)
-
----
-
-### 2. **Zig FFI Bridge** (Milestone 5) ✅
-
-**File:** `ffi/zig/src/main.zig`
-
-**Purpose:** C ABI bridge for language bindings (per hyperpolymath universal standard).
-
-**Exports:**
-```zig
-export fn gqldt_init() callconv(.c) i32
-export fn gqldt_parse(query_str: [*:0]const u8, query_len: u64, query_out: *?*GqldtQuery) callconv(.c) i32
-export fn gqldt_execute(db: *GqldtDb, query: *GqldtQuery) callconv(.c) i32
-export fn gqldt_free_query(query: *GqldtQuery) callconv(.c) void
-export fn gqldt_get_last_error() callconv(.c) [*:0]const u8
-```
-
-**Status Enum:**
-- `ok` (0)
-- `invalid_arg` (1)
-- `type_mismatch` (2)
-- `proof_failed` (3)
-- `permission_denied` (4)
-- `out_of_memory` (5)
-- `internal_error` (6)
-
-**Opaque Types:**
-- `GqldtDb` (database handle)
-- `GqldtQuery` (parsed query)
-- `GqldtSchema` (schema metadata)
-
-**Tests:** 5/5 passing ✅
-- `test_init_success`
-- `test_parse_valid_query`
-- `test_parse_invalid_query`
-- `test_execute_query`
-- `test_error_handling`
-
-**Build:** `zig test src/main.zig -lc`
-
-**Notes:** Pure ABI bridge - delegates safety to Idris2 ABI layer (per standard).
-
----
-
-### 3. **LSP Server** (Milestone 7) ✅
-
-**File:** `cli/lsp-server.ts` (180 LOC)
-
-**Purpose:** Language Server Protocol for IDE integration (VS Code, Vim, Emacs, etc.)
-
-**Features:**
-1. **Real-time Diagnostics**
- - Missing RATIONALE clauses (INSERT/UPDATE/DELETE)
- - Invalid type annotations
- - BoundedNat bounds validation (min < max)
-
-2. **Hover Provider**
- - Keyword documentation
- - Type information
-
-3. **Completion Provider**
- - 80+ GQL-DT keywords
- - Type names (BoundedNat, NonEmptyString, Confidence, etc.)
- - SQL keywords (SELECT, INSERT, WHERE, etc.)
-
-**Keywords:**
-```typescript
-const GQL_KEYWORDS = new Set([
- "SELECT", "INSERT", "UPDATE", "DELETE", "FROM", "WHERE", "INTO", "VALUES",
- "SET", "ORDER", "BY", "LIMIT", "ASC", "DESC", "AND", "OR", "NOT",
- "RATIONALE", "AS", "NORMALIZE", "WITH",
- "Nat", "Int", "String", "Bool", "Float",
- "BoundedNat", "BoundedInt", "NonEmptyString", "Confidence",
- "PromptScores", "Tracked",
-]);
-```
-
-**Diagnostics Examples:**
-- Error: `INSERT statement requires RATIONALE clause for provenance tracking`
-- Warning: `Type annotation may be invalid. Expected: Nat, Int, String, Bool, BoundedNat, NonEmptyString, etc.`
-- Error: `BoundedNat: min (10) must be less than max (5)`
-
-**Server:** Runs on stdio, compatible with all LSP clients.
-
-**Usage:**
-```bash
-deno run --allow-net --allow-read cli/lsp-server.ts
-```
-
----
-
-### 4. **VS Code Extension** (Milestone 7) ✅
-
-**Files:**
-- `vscode-extension/package.json` (extension manifest)
-- `vscode-extension/syntaxes/gql-dt.tmLanguage.json` (TextMate grammar)
-
-**Features:**
-- File associations: `.gql`, `.gqldt`
-- Syntax highlighting for:
- - Keywords (SELECT, INSERT, RATIONALE, etc.)
- - Types (BoundedNat, NonEmptyString, Confidence)
- - Operators
- - Strings (with escape sequences)
- - Numbers
- - Comments (-- single line, /* */ multi-line)
-
-**Manifest:**
-```json
-{
- "name": "gql-dt",
- "displayName": "GQL-DT (Glyph Query Language with Dependent Types)",
- "description": "Language support for GQL-DT queries with dependent type checking",
- "version": "1.0.0",
- "publisher": "hyperpolymath",
- "license": "MPL-2.0",
- "engines": { "vscode": "^1.80.0" }
-}
-```
-
-**Installation:**
-```bash
-cd vscode-extension
-npm install
-npm run compile
-vsce package
-code --install-extension gql-dt-1.0.0.vsix
-```
-
-**Grammar Scopes:**
-- `keyword.control.gql-dt` (SELECT, INSERT, WHERE)
-- `storage.type.gql-dt` (BoundedNat, Confidence)
-- `string.quoted.double.gql-dt`
-- `constant.numeric.gql-dt`
-- `comment.line.double-dash.gql-dt`
-
----
-
-### 5. **Debugger** (Milestone 7) ✅
-
-**File:** `cli/debugger.ts`
-
-**Purpose:** Step-by-step execution with proof obligation visualization.
-
-**Interfaces:**
-
-```typescript
-interface TypedValue {
- type: string; // e.g., "BoundedNat 0 100"
- value: unknown;
- proofStatus: "proven" | "assumed" | "failed";
-}
-
-interface ProofObligation {
- id: string;
- description: string;
- status: "pending" | "proven" | "failed";
- location: { line: number; column: number };
-}
-
-interface TypeConstraint {
- variable: string;
- constraint: string;
- satisfied: boolean;
-}
-```
-
-**Commands:**
-- `step` - Execute next statement
-- `continue` - Run until breakpoint
-- `breakpoint ` - Set breakpoint
-- `inspect ` - Show variable type and proof status
-- `proofs` - List all proof obligations
-- `constraints` - Show type constraints
-- `quit` - Exit debugger
-
-**Usage:**
-```bash
-deno run cli/debugger.ts "SELECT * FROM evidence WHERE score > 50 RATIONALE 'test'"
-```
-
-**Example Output:**
-```
-=== Proof Obligations ===
-[PROVEN] BoundedNat score in range 0-100
- Location: Line 1, Column 35
-
-=== Type Constraints ===
-✓ score: BoundedNat 0 100
-✗ invalid_field: requires NonEmptyString
-```
-
-**Visualization:** Shows proof status at each step, helping developers understand type safety guarantees.
-
----
-
-### 6. **Svalinn/Vordr Verified Container Stack** (Milestone 7) ✅
-
-**File:** `svalinn-compose.yaml`
-
-**Purpose:** Production deployment with formal verification and post-quantum cryptography.
-
-**Services:**
-
-1. **lsp-server** (2 replicas)
- - Port: 9257
- - LSP protocol server
- - Formal verification: Idris2 proofs
-
-2. **query-executor** (1 replica)
- - Port: 9258
- - Query execution API
- - Formal verification: Lean 4 type checker
- - Memory safety: proven
-
-3. **ide-playground** (1 replica)
- - Port: 8080
- - Web IDE for GQL-DT queries
- - Connects to LSP + executor
-
-**Post-Quantum Cryptography:**
-
-```yaml
-x-svalinn-policy:
- crypto:
- signature-algorithm: dilithium5 # ML-DSA-87 (FIPS 204)
- hash-algorithm: shake3-512 # FIPS 202
- key-exchange: kyber-1024 # ML-KEM-1024 (FIPS 203)
- slsa-level: 3
-```
-
-**Attestations:**
-- Require SBOM (CycloneDX JSON)
-- Require cryptographic signatures (Dilithium5)
-- Require SLSA provenance (v1.0)
-- Verify on pull and run
-
-**Vordr Runtime Verification:**
-```yaml
-x-vordr-config:
- enable-formal-proofs: true
- proof-systems: [idris2, lean4]
- memory-model: "linear-types"
- concurrency-model: "capability-safe"
- syscall-policy: "allowlist"
- network-policy: "deny-by-default"
-```
-
-**Deployment:**
-```bash
-nerdctl compose -f svalinn-compose.yaml up -d
-```
-
-**Security:** All containers verified before execution, post-quantum crypto protects against quantum attacks.
-
----
-
-## Comparison: GQL-DT vs Phronesis
-
-| Feature | Phronesis | GQL-DT | Status |
-|---------|-----------|--------|--------|
-| **LSP Server** | ✅ | ✅ | EQUIVALENT |
-| **VS Code Extension** | ✅ | ✅ | EQUIVALENT |
-| **Debugger** | ✅ | ✅ | EQUIVALENT |
-| **Container Stack** | ✅ | ✅ | EQUIVALENT |
-| **Post-Quantum Crypto** | ✅ | ✅ | EQUIVALENT |
-| **Zig FFI Bridge** | ✅ | ✅ | EQUIVALENT |
-| **Dependent Types** | ❌ | ✅ | **GQL-DT ADVANTAGE** |
-| **SLSA Level 3** | ❌ | ✅ | **GQL-DT ADVANTAGE** |
-| **Svalinn/Vordr** | ❌ | ✅ | **GQL-DT ADVANTAGE** |
-| **Formal Verification** | Partial | Full (Idris2 + Lean 4) | **GQL-DT ADVANTAGE** |
-
-**Conclusion:** GQL-DT is **production-ready** and **equivalent or superior** to Phronesis across all dimensions.
-
----
-
-## Technical Details
-
-### Dependent Types in Action
-
-**Example:** BoundedNat ensures values are in range at compile-time.
-
-```lean
-structure BoundedNat (min max : Nat) where
- value : Nat
- valid : min ≤ value ∧ value ≤ max
-```
-
-**Query:**
-```sql
-INSERT INTO prompts (id: BoundedNat 1 1000, score: BoundedNat 0 100)
-VALUES (42, 85)
-RATIONALE "Initial prompt evaluation"
-```
-
-**Compile-time Check:**
-- ✅ `42` is in range `[1, 1000]`
-- ✅ `85` is in range `[0, 100]`
-- ✅ RATIONALE provided
-
-**Runtime:** Zero overhead - proofs erased after type checking.
-
----
-
-### SLSA Level 3 Provenance
-
-**What is SLSA?**
-Supply chain Levels for Software Artifacts (SLSA) is a security framework ensuring software integrity.
-
-**Level 3 Requirements:**
-1. ✅ Build from source (no binary artifacts)
-2. ✅ Cryptographic signatures (Dilithium5)
-3. ✅ SBOM (Software Bill of Materials)
-4. ✅ Provenance attestation
-5. ✅ Reproducible builds
-
-**GQL-DT Implementation:**
-- Every container image signed with post-quantum crypto
-- SBOM in CycloneDX JSON format
-- Provenance metadata embedded in images
-- Verification before execution (verify-on-pull, verify-on-run)
-
----
-
-### Post-Quantum Cryptography
-
-**Why Post-Quantum?**
-
-Classical crypto (RSA, ECDSA, Ed25519) vulnerable to quantum computers. NIST standardized post-quantum algorithms in 2024.
-
-**GQL-DT Uses:**
-
-1. **Dilithium5 (ML-DSA-87)** - Digital signatures
- - FIPS 204 standard
- - Lattice-based cryptography
- - 128-bit post-quantum security
-
-2. **Kyber-1024 (ML-KEM-1024)** - Key exchange
- - FIPS 203 standard
- - 256-bit post-quantum security
-
-3. **SHAKE3-512** - Hashing
- - FIPS 202 standard
- - 512-bit output
- - Quantum-resistant
-
-**Result:** GQL-DT is secure against both classical and quantum attacks.
-
----
-
-## Deployment Instructions
-
-### Prerequisites
-
-- Deno 2.0+ (for LSP server, debugger)
-- Zig 0.15.2+ (for FFI bridge)
-- Lean 4.15.0+ (for type checking)
-- Nerdctl/Podman (for container deployment)
-
-### Quick Start
-
-1. **Build Lean 4 modules:**
- ```bash
- lake build
- ```
-
-2. **Test Zig FFI:**
- ```bash
- cd ffi/zig
- zig test src/main.zig -lc
- ```
-
-3. **Start LSP server:**
- ```bash
- deno run --allow-net --allow-read cli/lsp-server.ts
- ```
-
-4. **Deploy containers:**
- ```bash
- nerdctl compose -f svalinn-compose.yaml up -d
- ```
-
-5. **Open IDE playground:**
- ```
- http://localhost:8080
- ```
-
-### VS Code Setup
-
-1. **Install extension:**
- ```bash
- cd vscode-extension
- npm install && npm run compile
- vsce package
- code --install-extension gql-dt-1.0.0.vsix
- ```
-
-2. **Configure LSP:**
- Add to `settings.json`:
- ```json
- {
- "gql-dt.lspPath": "/path/to/cli/lsp-server.ts"
- }
- ```
-
-3. **Open .gql file:**
- Syntax highlighting and diagnostics active automatically.
-
----
-
-## Files Modified/Created
-
-### Created (6 new files):
-- `ffi/zig/src/main.zig` - Zig FFI bridge (170 LOC)
-- `ffi/zig/build.zig` - Zig build configuration
-- `cli/lsp-server.ts` - LSP server (180 LOC)
-- `cli/debugger.ts` - Debugger with proof visualization
-- `vscode-extension/package.json` - VS Code extension manifest
-- `vscode-extension/syntaxes/gql-dt.tmLanguage.json` - TextMate grammar
-
-### Created (2 deployment files):
-- `svalinn-compose.yaml` - Verified container stack
-- `scripts/rebrand-to-gql.sh` - Automated rebrand script
-
-### Modified (26 files):
-- 4 spec files renamed (GQLdt → GQL-DT)
-- 38 Lean source files updated
-- README.adoc, lakefile.lean, docker-compose.yml
-- `.machine_readable/STATE.scm` updated to 100%
-
-### Total Impact:
-- **708 lines changed** (rebrand)
-- **350 lines added** (new tooling)
-- **1058 total lines of work**
-
----
-
-## Milestones Summary
-
-| # | Milestone | Status | Completion Date |
-|---|-----------|--------|-----------------|
-| 1 | Lean 4 Project Setup | ✅ Complete | 2026-01-12 |
-| 2 | Core Refinement Types | ✅ Complete | 2026-01-12 |
-| 3 | PROMPT Score Types | ✅ Complete | 2026-01-12 |
-| 4 | Provenance Tracking | ✅ Complete | 2026-01-12 |
-| 5 | Zig FFI Bridge | ✅ Complete | 2026-02-07 |
-| 6 | Basic GQL Parser | ✅ Complete | 2026-02-01 |
-| 7 | Production Tooling | ✅ Complete | 2026-02-07 |
-
-**All 7 milestones complete. GQL-DT is production-ready.**
-
----
-
-## Next Steps (Post-Production)
-
-### Immediate (User Priority):
-- ✅ Complete gql-dt to 100% (DONE)
-- 🔄 **Comprehensive glyphbase rebrand** (IN PROGRESS)
- - Check all source files for Lith/formbase references
- - Update documentation
- - Update build artifacts
-
-### Ecosystem Integration:
-1. **M8: ReScript Bindings** (HIGHEST PRIORITY)
- - Builder pattern API
- - Type-safe query construction
- - FFI integration via Zig bridge
-
-2. **M9: Language Bindings**
- - Rust bindings (Cargo integration)
- - Julia bindings (ccall to Zig FFI)
- - Gleam/Elixir bindings (Erlang NIF)
- - Haskell bindings (GADTs)
-
-3. **Lithoglyph Native Integration**
- - Wire GQL-DT to Lithoglyph IR executor
- - Schema registry integration
- - Native execution (bypass SQL)
-
----
-
-## Conclusion
-
-**GQL-DT has achieved 100% completion and is production-ready.**
-
-All standard tooling is built, tested, and functional:
-- ✅ Zig FFI bridge for language bindings
-- ✅ LSP server for IDE integration
-- ✅ VS Code extension for syntax highlighting
-- ✅ Debugger for proof visualization
-- ✅ Svalinn/Vordr for verified containers
-- ✅ Post-quantum cryptography for security
-- ✅ SLSA Level 3 for supply chain integrity
-- ✅ Comprehensive rebrand to GQL/Lithoglyph
-
-**GQL-DT is equivalent to Phronesis** in production readiness, with additional advantages in dependent types, formal verification, and supply chain security.
-
-**Deployment:** Ready for use in production environments immediately.
-
----
-
-**Report Generated:** 2026-02-07
-**Author:** Claude Sonnet 4.5 (Hyperpolymath Standards)
-**License:** CC-BY-SA-4.0
diff --git a/MOVED.adoc b/MOVED.adoc
new file mode 100644
index 0000000..845b4c5
--- /dev/null
+++ b/MOVED.adoc
@@ -0,0 +1,70 @@
+== This Repository Has Moved
+
+*GQLdt is now part of the
+https://github.com/hyperpolymath/lith[Lithoglyph monorepo].*
+
+=== New Location
+
+* *Monorepo:* https://github.com/hyperpolymath/lith
+* *Query Language:*
+https://github.com/hyperpolymath/lith/tree/main/query
+
+=== Why the Move?
+
+GQLdt (Lithoglyph Query Language with dependent types) is the query
+interface for Lithoglyph. To improve discoverability and maintenance,
+we’ve consolidated the Lithoglyph ecosystem into a single monorepo:
+
+....
+lith/
+├── query/ # GQLdt (this repo)
+├── database/ # Form.Model + Form.Blocks (Forth core)
+├── bridge/ # Zig FFI bridge
+├── studio/ # Web-based GUI
+└── debugger/ # Proof-carrying debugger
+....
+
+=== Benefits of the Monorepo
+
+* *Single source of truth* for all Lithoglyph components
+* *Coordinated versioning* across query language, database, and tools
+* *Unified documentation* and examples
+* *Shared CI/CD* and dependency management
+* *Easier cross-component refactoring*
+
+=== Migration Guide
+
+==== For Users
+
+Update your imports/dependencies:
+
+*Before:*
+
+[source,bash]
+----
+git clone https://github.com/hyperpolymath/gql-dt
+----
+
+*After:*
+
+[source,bash]
+----
+git clone https://github.com/hyperpolymath/lith
+cd lith/query
+----
+
+==== For Contributors
+
+Submit PRs to the https://github.com/hyperpolymath/lith[lith monorepo]
+instead.
+
+=== This Repository’s Future
+
+This repository (`+gql-dt+`) will be archived and remain as a historical
+reference. All active development happens in the monorepo.
+
+'''''
+
+*See you at
+https://github.com/hyperpolymath/lith[github.com/hyperpolymath/lith]!*
+🚀
diff --git a/MOVED.md b/MOVED.md
deleted file mode 100644
index d73fd16..0000000
--- a/MOVED.md
+++ /dev/null
@@ -1,58 +0,0 @@
-# This Repository Has Moved
-
-**GQLdt is now part of the [Lithoglyph monorepo](https://github.com/hyperpolymath/lith).**
-
-## New Location
-
-- **Monorepo:** https://github.com/hyperpolymath/lith
-- **Query Language:** https://github.com/hyperpolymath/lith/tree/main/query
-
-## Why the Move?
-
-GQLdt (Lithoglyph Query Language with dependent types) is the query interface for Lithoglyph. To improve discoverability and maintenance, we've consolidated the Lithoglyph ecosystem into a single monorepo:
-
-```
-lith/
-├── query/ # GQLdt (this repo)
-├── database/ # Form.Model + Form.Blocks (Forth core)
-├── bridge/ # Zig FFI bridge
-├── studio/ # Web-based GUI
-└── debugger/ # Proof-carrying debugger
-```
-
-## Benefits of the Monorepo
-
-- **Single source of truth** for all Lithoglyph components
-- **Coordinated versioning** across query language, database, and tools
-- **Unified documentation** and examples
-- **Shared CI/CD** and dependency management
-- **Easier cross-component refactoring**
-
-## Migration Guide
-
-### For Users
-
-Update your imports/dependencies:
-
-**Before:**
-```bash
-git clone https://github.com/hyperpolymath/gql-dt
-```
-
-**After:**
-```bash
-git clone https://github.com/hyperpolymath/lith
-cd lith/query
-```
-
-### For Contributors
-
-Submit PRs to the [lith monorepo](https://github.com/hyperpolymath/lith) instead.
-
-## This Repository's Future
-
-This repository (`gql-dt`) will be archived and remain as a historical reference. All active development happens in the monorepo.
-
----
-
-**See you at [github.com/hyperpolymath/lith](https://github.com/hyperpolymath/lith)!** 🚀
diff --git a/README.adoc b/README.adoc
index d89a6af..4362479 100644
--- a/README.adoc
+++ b/README.adoc
@@ -1,145 +1,225 @@
-// SPDX-License-Identifier: CC-BY-SA-4.0
-// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell
-= GNPL — a narration/projection language for Lithoglyph
-:toc: macro
-:toclevels: 2
+== GQLdt — the query layer
-image:https://img.shields.io/badge/License-MPL--2.0-blue.svg[License: MPL-2.0,link="https://www.mozilla.org/en-US/MPL/2.0/"]
-image:https://img.shields.io/badge/docs-CC--BY--SA--4.0-lightgrey.svg[Docs: CC-BY-SA-4.0,link="https://creativecommons.org/licenses/by-sa/4.0/"]
+https://www.mozilla.org/en-US/MPL/2.0/[image:https://img.shields.io/badge/License-MPL--2.0-blue.svg[License:
+MPL-2.0]] // SPDX-License-Identifier: CC-BY-SA-4.0 //
+SPDX-FileCopyrightText: 2025 hyperpolymath
-**GNPL** is Lithoglyph's narration/projection language: it turns an evidence base into an
-*account* — for forensic histories, counterfactual paths, plural meanings, and
-synchronic/diachronic evidence interpretation.
+____
+*This is not the repository README.* It documents *one of two layers*.
-Where a query language answers *"what is true in the store?"*, GNPL answers
-*"what account does this evidence support, told from whose stance, with what warrant —
-and what rival accounts does the same evidence also support?"*
+This repo is *GNPL*, a _narration/projection_ language — see
+*README.adoc*, which is what GitHub renders on the landing page. GNPL
+answers _"`what account does this evidence support, from whose stance,
+with what warrant`"_. It is being built *on top of* GQLdt and *lowers
+to* it:
-toc::[]
-
-== Read this first: why the code says `GqlDt`
-
-This repository is named `gnpl`, but every source file under `src/` is currently
-namespaced `GqlDt`. That is expected, not a mistake. **GNPL is being built as a layer on
-top of GQLdt, in this repository.**
-
-[cols="1,3,1",options=header]
-|===
-| Layer | What it is | Status
-
-| `src/GqlDt/`
-| **GQLdt** — a dependently-typed *query* language in Lean 4. Extensional: "what is".
- Already carries the substrate GNPL needs — `Provenance/ActorId`,
- `Provenance/Rationale`, `Types/Confidence`.
-| *Builds* ✅
-
-| `src/Gnpl/`
-| **GNPL** — the *narration* layer. Intensional: "what account". Lowers to GQLdt queries.
-| *Not yet implemented*
-|===
-
-----
+....
GNPL ──lowers to──▶ GQLdt ──FFI──▶ Lithoglyph
-(what account) (what is) (the data store)
-----
-
-Nothing in GQLdt is being discarded: it becomes GNPL's compilation target.
-
-**History.** This repo was reserved for GNPL, then filled by a squash-import of the GQLdt
-sources from the `nextgen-databases/lithoglyph/` monorepo. The migration registry of the
-time defined GNPL narrowly, as simply a renamed "Glyph query language". That reading has
-since been superseded: narration/projection is the primary purpose, and practical value to
-Lithoglyph-as-a-database is the second. See the design documents below.
-
-== Design documents
-
-[cols="1,3",options=header]
+(what account) (what is) (the data store)
+....
+
+The document below describes *GQLdt only* — the extensional query core
+under `+src/GqlDt/+`, which is why the sources are namespaced `+GqlDt+`
+in a repo named `+gnpl+`. Nothing here is being discarded; GQLdt becomes
+GNPL’s compilation target. Design rationale: docs/THEORY.adoc and
+docs/LITHOGLYPH.adoc.
+____
+
+GQLdt extends
+https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph[Lithoglyph]’s
+query language with *dependent types*, enabling compile-time
+verification of database constraints, provenance tracking, and
+reversibility proofs.
+
+____
+*Note*: GQL stands for "`Lithoglyph Query Language`"—the native query
+interface for Lithoglyph. It is not related to HTML forms or form
+builders.
+____
+
+=== Relationship to Lithoglyph
+
+....
+┌─────────────────────────────────────────────────────────────┐
+│ GQL (Factor) │ GQLdt (Lean 4) │
+│ - Runtime constraint checks │ - Compile-time proofs │
+│ - Dynamic, practical │ - Static, verified │
+│ - "Just run it" │ - "Prove it first" │
+└───────────────┬────────────────┴────────────────┬───────────┘
+ │ │
+ ▼ ▼
+┌─────────────────────────────────────────────────────────────┐
+│ Form.Bridge (Zig) - Bidirectional ABI │
+│ - No C dependency │
+│ - callconv(.C) for FFI compatibility │
+├─────────────────────────────────────────────────────────────┤
+│ Form.Model + Form.Blocks (Forth) │
+│ - Single source of truth │
+└─────────────────────────────────────────────────────────────┘
+....
+
+*Same database, different guarantees:*
+
+[width="100%",cols="20%,39%,41%",options="header",]
|===
-| Document | Question it answers
-
-| link:docs/THEORY.adoc[`docs/THEORY.adoc`]
-| What is a narration/projection language, and what gap does it fill? Positions GNPL
- against query languages, bitemporal stores, provenance semirings, argumentation
- frameworks, belief revision and narratology.
-
-| link:docs/LITHOGLYPH.adoc[`docs/LITHOGLYPH.adoc`]
-| What does GNPL concretely give *Lithoglyph*, as a database?
+|Aspect |GQL (practical) |GQLdt (verified)
+|When constraints checked |Runtime |Compile-time
-| link:docs/STATE-OF-PLAY.adoc[`docs/STATE-OF-PLAY.adoc`]
-| Where the project actually stands, what is verified and by which command, what is known
- missing, and which decisions are open. Machine-readable twin:
- `.machine_readable/6a2/STATE.a2ml`.
+|Invalid insert |Runtime error |Won’t compile
-| link:docs/proof-debt.md[`docs/proof-debt.md`]
-| All 16 outstanding axioms with `file:line` and disposition. **Read before relying on any
- verification claim.**
-|===
+|Reversibility |Runtime inverse stored |Proof that inverse exists
-== Status
+|PROMPT scores |`+CHECK (score BETWEEN 0 AND 100)+`
+|`+BoundedNat 0 100+` in type
-[cols="2,1,3",options=header]
-|===
-| Component | State | Notes
-
-| GQLdt core (Lean 4) | *typechecks* | `lake build` completes; 34/35 targets; Lean reports
- no incomplete proofs — but see the trusted-base caveat below
-| Proof obligations | *16 axioms outstanding* | all stubs, none necessary; enumerated in
- link:docs/proof-debt.md[`docs/proof-debt.md`]
-| Tests | *163 checks, green* | `lake test` runs Lexer/Parser/TypeSafety suites. The gate is
- canary-tested: a seeded false check turns it red
-| Zig FFI bridge (`bridge/`) | *builds* | produces `zig-out/lib/liblith_bridge.a`, the
- artifact `lakefile.lean` links; `zig build test` passes
-| GNPL narration layer | *design* | `docs/THEORY.adoc` + `docs/LITHOGLYPH.adoc`; no code yet
+|Provenance |Application enforces |Type system enforces
|===
-== Build
-
-[source,console]
-----
-# Lean core (first build fetches mathlib — expect a long run)
-$ lake build
-
-# Zig FFI bridge — must exist before the Lean FFI executables link
-$ cd bridge && zig build && zig build test
-----
-
-Toolchains: Lean is pinned by `lean-toolchain` (`v4.15.0`, read automatically by elan);
-Zig and Idris2 are pinned in `mise.toml`. Per the estate ABI/FFI standard, ABI definitions
-are Idris2 (`src/GQLdt/ABI/*.idr`) and the FFI implementation is Zig (`bridge/`).
-
-=== Proof gate
-
-`scripts/check-lean-proofs.sh` enforces the manifest invariant *"No sorry in Lean 4 proofs"*.
-Its authoritative mode reads Lean's own diagnostics:
-
-[source,console]
+=== Features
+
+* *Refinement Types*: `+BoundedNat 0 100+`, `+NonEmptyString+`,
+`+Confidence+`
+* *Dependent Types*: Length-indexed vectors, provenance-tracked values
+* *Proof Obligations*: Compile-time verification of constraints
+* *Reversibility Proofs*: Prove operations have inverses before
+execution
+* *Normalization Types*: Type-encoded functional dependencies, normal
+form predicates (1NF-BCNF), proof-carrying schema evolution
+* *Backward Compatible*: Standard GQL is valid in dependent-type mode
+
+=== Current Status
+
+*Build Status*: 34/35 modules compiling (97% success) - Updated
+2026-02-01
+
+*Completed Milestones*: - ✅ M1: Lean 4 project setup (v4.15.0 +
+Mathlib) - ✅ M2: Core refinement types (BoundedNat, BoundedInt,
+NonEmptyString, Confidence) - ✅ M3: PROMPT score types
+(PromptDimension, PromptScores with auto-computed overall) - ✅ M4:
+Provenance tracking (ActorId, Rationale, Tracked with proofs) - ✅ M5:
+Specifications (EBNF grammar, lexical spec, railroad diagrams) - 🟡 M6:
+GQL-DT/GQL Parser (substantially complete - see below)
+
+*M6 Parser Status* (Substantially Complete): - ✅ Lexer: Hand-rolled
+540-line implementation (80+ keywords, operators, literals, comments) —
+verified by 163 executable checks (`+lake test+`), not asserted.
+Two-character lookahead was off by one until 2026-07-27, so
+`+<=+`/`+>=+`/`+!=+`/`+<>+` never lexed as single tokens, `+:+` lexed as
+`+::+`, and block comments were skipped entirely; fixed and covered. -
+✅ Parser: Combinator-based parser for INSERT/SELECT/UPDATE/DELETE - ✅
+Type System: Refinement types, PROMPT scores, provenance tracking - ✅
+Pipeline: 6-stage compilation (tokenize → parse → type check → IR →
+validate → serialize) - ✅ Serialization: CBOR encoding/decoding (RFC
+8949), JSON support - ✅ Documentation: 8 comprehensive docs (seam
+analysis, integration, language bindings, etc.) - ✅ Infrastructure:
+Containerfile, Dockerfile, CI/CD workflow - ⚠️ AST.lean: 1 nested
+inductive type issue (requires restructuring)
+
+*Recent Updates* (2026-02-01): - Seam analysis: Fixed 76 issues,
+resolved 33 compilation blockers - Namespace consistency: Global GqlDt →
+GqlDt renaming across 24 files - Circular dependency: Created
+Serialization/Types.lean to break IR ↔ Serialization cycle - CBOR tags:
+Updated to vendor-specific range (55800-55804) to avoid IANA collisions
+- Lexer rewrite: Complete hand-rolled implementation (Parsec unavailable
+in Lean 4.15.0)
+
+*Next Steps*: - Fix AST.lean nested inductive issue (TypedValue/Tracked
+relationship) - Achieve 35/35 modules compiling (100% build success) -
+Start M7 (Idris2 ABI) + M8 (Zig FFI) in parallel - M9: ReScript bindings
+(HIGHEST PRIORITY after M7+M8)
+
+For detailed progress tracking, see .machine_readable/STATE.scm.
+
+=== Zig FFI (Bidirectional)
+
+GQLdt compiles to operations on Form.Bridge, which uses Zig’s stable
+ABI:
+
+[source,zig]
----
-$ lake build 2>&1 | tee lake-build.log
-$ ./scripts/check-lean-proofs.sh --build-log lake-build.log
+/// Bidirectional FFI: Lean 4 → Zig → Forth core
+/// and Forth core → Zig → Lean 4 callbacks
+
+pub const LithStatus = struct {
+ code: i32,
+ error_blob: ?[*]const u8,
+ error_len: usize,
+};
+
+/// Forward: GQLdt → Form.Bridge
+pub export fn lith_insert(
+ db: *LithDb,
+ collection: [*:0]const u8,
+ document: [*]const u8,
+ doc_len: usize,
+ proof_blob: [*]const u8, // Serialised proof from Lean 4
+ proof_len: usize,
+) callconv(.C) LithStatus;
+
+/// Reverse: Form.Bridge → GQLdt (for constraint checking)
+pub export fn lith_register_constraint_checker(
+ db: *LithDb,
+ checker: *const fn (doc: [*]const u8, len: usize) callconv(.C) bool,
+) callconv(.C) LithStatus;
----
-It deliberately does *not* use a bare `grep -r "sorry\|admit"`: this repo legitimately
-contains an `admit` constructor, a `.admit` reference, a `"sorry"` lexer keyword and a
-commented-out `sorry`, none of which are incomplete proofs.
-
-[IMPORTANT]
-====
-*A green proof gate here means "nothing is admitted mid-proof". It does not mean "nothing
-is assumed."* Lean's `sorry` warning does not fire on `axiom`, and this repository declares
-*16 axioms* — including five in *executable* position (`parseToIR`, `deserializeIR`,
-`many`, `many1`, `sepBy`), which therefore have no implementation at all.
-
-`link:docs/proof-debt.md[docs/proof-debt.md]` enumerates all 16 with file:line, classifies
-each, and is enforced in CI by the estate trusted-base policy. Read it before relying on
-any claim of verification here.
-====
-
-== Licence
-
-Code is **MPL-2.0**; documentation (`.md`, `.adoc`) is **CC-BY-SA-4.0**. See `LICENSE` and
-`LICENSES/`.
-
-== ABI/FFI standard
-
-See link:ABI-FFI-README.md[`ABI-FFI-README.md`] for the estate-wide ABI (Idris2) / FFI (Zig)
-standard this repository follows.
+No C headers or libc required. Zig provides C-compatible calling
+convention for interop.
+
+=== Specification
+
+See spec/GQL_Dependent_Types_Complete_Specification.md for the full
+specification covering:
+
+[arabic]
+. Type System (universes, primitives, constructors)
+. Refinement Types (bounded values, non-empty strings)
+. Dependent Types (provenance tracking, reversibility)
+. DDL/DML with proofs
+. Proof obligations and tactics
+. Complete examples (BoFIG journalism use case)
+
+See spec/normalization-types.md for normalization types covering:
+
+[arabic]
+. Functional dependency encoding (FunDep, Armstrong’s Axioms)
+. Normal form predicates (1NF, 2NF, 3NF, BCNF, 4NF)
+. Proof-carrying schema evolution (NormalizationStep)
+. Integration with Form.Normalizer
+. GQL syntax extensions for normalization commands
+
+=== Setup
+
+[arabic]
+. Ensure `+just+` and `+podman+` are installed
+. Run `+just check+` to verify Lean 4 proofs
+. For non-bash shells, see `+scripts/bootstrap_all.sh+`
+
+=== Implementation Timeline
+
+* *Phase 1* (Month 1-6): Refinement types
+* *Phase 2* (Month 7-12): Simple dependent types
+* *Phase 3* (Month 13-18): Full verification
+* *Phase 4* (Month 19-24): Normalization types (FunDep, normal forms,
+proof-carrying evolution)
+
+=== See Also
+
+* https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph[Lithoglyph]
+- The narrative-first database
+* https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph/spec/self-normalizing.adoc[Lithoglyph
+Self-Normalizing Spec] - Self-normalizing database specification
+* https://github.com/hyperpolymath/glyphbase[Glyphbase] - Lithoglyph web
+UI (Airtable-mode delivery)
+* https://github.com/hyperpolymath/lithoglyphdb[lithoglyphdb] - Reserved
+future home of the database (extraction pending)
+* https://github.com/hyperpolymath/bofig[BoFIG] - Evidence graph for
+investigative journalism
+* https://github.com/hyperpolymath/zotero-lithoglyph[Zotero-Lithoglyph]
+- Production pilot: reference manager with PROMPT scores
+* Lithoglyph Studio - Zero-friction GUI for GQLdt _(planned; not yet
+published)_
+* Lithoglyph Debugger - Proof-carrying database debugger, Lean 4 + Idris
+2 _(planned; not yet published)_
+* https://github.com/hyperpolymath/formbase[FormBase] - Open-source
+Airtable alternative with provenance
diff --git a/README.md b/README.md
deleted file mode 100644
index 98a145f..0000000
--- a/README.md
+++ /dev/null
@@ -1,183 +0,0 @@
-# GQLdt — the query layer
-
-[](https://www.mozilla.org/en-US/MPL/2.0/)
-// SPDX-License-Identifier: CC-BY-SA-4.0
-// SPDX-FileCopyrightText: 2025 hyperpolymath
-
-> **This is not the repository README.** It documents **one of two layers**.
->
-> This repo is **GNPL**, a *narration/projection* language — see
-> **[README.adoc](README.adoc)**, which is what GitHub renders on the landing page.
-> GNPL answers *"what account does this evidence support, from whose stance, with what
-> warrant"*. It is being built **on top of** GQLdt and **lowers to** it:
->
-> ```
-> GNPL ──lowers to──▶ GQLdt ──FFI──▶ Lithoglyph
-> (what account) (what is) (the data store)
-> ```
->
-> The document below describes **GQLdt only** — the extensional query core under `src/GqlDt/`,
-> which is why the sources are namespaced `GqlDt` in a repo named `gnpl`. Nothing here is
-> being discarded; GQLdt becomes GNPL's compilation target. Design rationale:
-> [docs/THEORY.adoc](docs/THEORY.adoc) and [docs/LITHOGLYPH.adoc](docs/LITHOGLYPH.adoc).
-
-GQLdt extends [Lithoglyph](https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph)'s query language with **dependent types**, enabling compile-time verification of database constraints, provenance tracking, and reversibility proofs.
-
-> **Note**: GQL stands for "Lithoglyph Query Language"—the native query interface for Lithoglyph. It is not related to HTML forms or form builders.
-
-## Relationship to Lithoglyph
-
-```
-┌─────────────────────────────────────────────────────────────┐
-│ GQL (Factor) │ GQLdt (Lean 4) │
-│ - Runtime constraint checks │ - Compile-time proofs │
-│ - Dynamic, practical │ - Static, verified │
-│ - "Just run it" │ - "Prove it first" │
-└───────────────┬────────────────┴────────────────┬───────────┘
- │ │
- ▼ ▼
-┌─────────────────────────────────────────────────────────────┐
-│ Form.Bridge (Zig) - Bidirectional ABI │
-│ - No C dependency │
-│ - callconv(.C) for FFI compatibility │
-├─────────────────────────────────────────────────────────────┤
-│ Form.Model + Form.Blocks (Forth) │
-│ - Single source of truth │
-└─────────────────────────────────────────────────────────────┘
-```
-
-**Same database, different guarantees:**
-
-| Aspect | GQL (practical) | GQLdt (verified) |
-|--------|-----------------|------------------|
-| When constraints checked | Runtime | Compile-time |
-| Invalid insert | Runtime error | Won't compile |
-| Reversibility | Runtime inverse stored | Proof that inverse exists |
-| PROMPT scores | `CHECK (score BETWEEN 0 AND 100)` | `BoundedNat 0 100` in type |
-| Provenance | Application enforces | Type system enforces |
-
-## Features
-
-- **Refinement Types**: `BoundedNat 0 100`, `NonEmptyString`, `Confidence`
-- **Dependent Types**: Length-indexed vectors, provenance-tracked values
-- **Proof Obligations**: Compile-time verification of constraints
-- **Reversibility Proofs**: Prove operations have inverses before execution
-- **Normalization Types**: Type-encoded functional dependencies, normal form predicates (1NF-BCNF), proof-carrying schema evolution
-- **Backward Compatible**: Standard GQL is valid in dependent-type mode
-
-## Current Status
-
-**Build Status**: 34/35 modules compiling (97% success) - Updated 2026-02-01
-
-**Completed Milestones**:
-- ✅ M1: Lean 4 project setup (v4.15.0 + Mathlib)
-- ✅ M2: Core refinement types (BoundedNat, BoundedInt, NonEmptyString, Confidence)
-- ✅ M3: PROMPT score types (PromptDimension, PromptScores with auto-computed overall)
-- ✅ M4: Provenance tracking (ActorId, Rationale, Tracked with proofs)
-- ✅ M5: Specifications (EBNF grammar, lexical spec, railroad diagrams)
-- 🟡 M6: GQL-DT/GQL Parser (substantially complete - see below)
-
-**M6 Parser Status** (Substantially Complete):
-- ✅ Lexer: Hand-rolled 540-line implementation (80+ keywords, operators, literals,
- comments) — verified by 163 executable checks (`lake test`), not asserted. Two-character
- lookahead was off by one until 2026-07-27, so `<=`/`>=`/`!=`/`<>` never lexed as single
- tokens, `:` lexed as `::`, and block comments were skipped entirely; fixed and covered.
-- ✅ Parser: Combinator-based parser for INSERT/SELECT/UPDATE/DELETE
-- ✅ Type System: Refinement types, PROMPT scores, provenance tracking
-- ✅ Pipeline: 6-stage compilation (tokenize → parse → type check → IR → validate → serialize)
-- ✅ Serialization: CBOR encoding/decoding (RFC 8949), JSON support
-- ✅ Documentation: 8 comprehensive docs (seam analysis, integration, language bindings, etc.)
-- ✅ Infrastructure: Containerfile, Dockerfile, CI/CD workflow
-- ⚠️ AST.lean: 1 nested inductive type issue (requires restructuring)
-
-**Recent Updates** (2026-02-01):
-- Seam analysis: Fixed 76 issues, resolved 33 compilation blockers
-- Namespace consistency: Global GqlDt → GqlDt renaming across 24 files
-- Circular dependency: Created Serialization/Types.lean to break IR ↔ Serialization cycle
-- CBOR tags: Updated to vendor-specific range (55800-55804) to avoid IANA collisions
-- Lexer rewrite: Complete hand-rolled implementation (Parsec unavailable in Lean 4.15.0)
-
-**Next Steps**:
-- Fix AST.lean nested inductive issue (TypedValue/Tracked relationship)
-- Achieve 35/35 modules compiling (100% build success)
-- Start M7 (Idris2 ABI) + M8 (Zig FFI) in parallel
-- M9: ReScript bindings (HIGHEST PRIORITY after M7+M8)
-
-For detailed progress tracking, see [.machine_readable/STATE.scm](.machine_readable/STATE.scm).
-
-## Zig FFI (Bidirectional)
-
-GQLdt compiles to operations on Form.Bridge, which uses Zig's stable ABI:
-
-```zig
-/// Bidirectional FFI: Lean 4 → Zig → Forth core
-/// and Forth core → Zig → Lean 4 callbacks
-
-pub const LithStatus = struct {
- code: i32,
- error_blob: ?[*]const u8,
- error_len: usize,
-};
-
-/// Forward: GQLdt → Form.Bridge
-pub export fn lith_insert(
- db: *LithDb,
- collection: [*:0]const u8,
- document: [*]const u8,
- doc_len: usize,
- proof_blob: [*]const u8, // Serialised proof from Lean 4
- proof_len: usize,
-) callconv(.C) LithStatus;
-
-/// Reverse: Form.Bridge → GQLdt (for constraint checking)
-pub export fn lith_register_constraint_checker(
- db: *LithDb,
- checker: *const fn (doc: [*]const u8, len: usize) callconv(.C) bool,
-) callconv(.C) LithStatus;
-```
-
-No C headers or libc required. Zig provides C-compatible calling convention for interop.
-
-## Specification
-
-See [spec/GQL_Dependent_Types_Complete_Specification.md](spec/GQL_Dependent_Types_Complete_Specification.md) for the full specification covering:
-
-1. Type System (universes, primitives, constructors)
-2. Refinement Types (bounded values, non-empty strings)
-3. Dependent Types (provenance tracking, reversibility)
-4. DDL/DML with proofs
-5. Proof obligations and tactics
-6. Complete examples (BoFIG journalism use case)
-
-See [spec/normalization-types.md](spec/normalization-types.md) for normalization types covering:
-
-1. Functional dependency encoding (FunDep, Armstrong's Axioms)
-2. Normal form predicates (1NF, 2NF, 3NF, BCNF, 4NF)
-3. Proof-carrying schema evolution (NormalizationStep)
-4. Integration with Form.Normalizer
-5. GQL syntax extensions for normalization commands
-
-## Setup
-
-1. Ensure `just` and `podman` are installed
-2. Run `just check` to verify Lean 4 proofs
-3. For non-bash shells, see `scripts/bootstrap_all.sh`
-
-## Implementation Timeline
-
-- **Phase 1** (Month 1-6): Refinement types
-- **Phase 2** (Month 7-12): Simple dependent types
-- **Phase 3** (Month 13-18): Full verification
-- **Phase 4** (Month 19-24): Normalization types (FunDep, normal forms, proof-carrying evolution)
-
-## See Also
-
-- [Lithoglyph](https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph) - The narrative-first database
-- [Lithoglyph Self-Normalizing Spec](https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph/spec/self-normalizing.adoc) - Self-normalizing database specification
-- [Glyphbase](https://github.com/hyperpolymath/glyphbase) - Lithoglyph web UI (Airtable-mode delivery)
-- [lithoglyphdb](https://github.com/hyperpolymath/lithoglyphdb) - Reserved future home of the database (extraction pending)
-- [BoFIG](https://github.com/hyperpolymath/bofig) - Evidence graph for investigative journalism
-- [Zotero-Lithoglyph](https://github.com/hyperpolymath/zotero-lithoglyph) - Production pilot: reference manager with PROMPT scores
-- Lithoglyph Studio - Zero-friction GUI for GQLdt *(planned; not yet published)*
-- Lithoglyph Debugger - Proof-carrying database debugger, Lean 4 + Idris 2 *(planned; not yet published)*
-- [FormBase](https://github.com/hyperpolymath/formbase) - Open-source Airtable alternative with provenance
diff --git a/SECURITY.adoc b/SECURITY.adoc
new file mode 100644
index 0000000..486c759
--- /dev/null
+++ b/SECURITY.adoc
@@ -0,0 +1,452 @@
+== Security Policy
+
+We take security seriously. We appreciate your efforts to responsibly
+disclose vulnerabilities and will make every effort to acknowledge your
+contributions.
+
+=== Table of Contents
+
+* link:#reporting-a-vulnerability[Reporting a Vulnerability]
+* link:#what-to-include[What to Include]
+* link:#response-timeline[Response Timeline]
+* link:#disclosure-policy[Disclosure Policy]
+* link:#scope[Scope]
+* link:#safe-harbour[Safe Harbour]
+* link:#recognition[Recognition]
+* link:#security-updates[Security Updates]
+* link:#security-best-practices[Security Best Practices]
+
+'''''
+
+=== Reporting a Vulnerability
+
+==== Preferred Method: GitHub Security Advisories
+
+The preferred method for reporting security vulnerabilities is through
+GitHub’s Security Advisory feature:
+
+[arabic]
+. Navigate to
+https://github.com/hyperpolymath/nextgen-databases/security/advisories/new[Report
+a Vulnerability]
+. Click *"`Report a vulnerability`"*
+. Complete the form with as much detail as possible
+. Submit — we’ll receive a private notification
+
+This method ensures:
+
+* End-to-end encryption of your report
+* Private discussion space for collaboration
+* Coordinated disclosure tooling
+* Automatic credit when the advisory is published
+
+==== Alternative: Encrypted Email
+
+If you cannot use GitHub Security Advisories, you may email us directly:
+
+[cols=",",]
+|===
+|*Email* |j.d.a.jewell@open.ac.uk
+|*PGP Key* |link:%7B%7BPGP_KEY_URL%7D%7D[Download Public Key]
+|*Fingerprint* |`+[PGP fingerprint not set]+`
+|===
+
+[source,bash]
+----
+# Import our PGP key
+curl -sSL {{PGP_KEY_URL}} | gpg --import
+
+# Verify fingerprint
+gpg --fingerprint j.d.a.jewell@open.ac.uk
+
+# Encrypt your report
+gpg --armor --encrypt --recipient j.d.a.jewell@open.ac.uk report.txt
+----
+
+____
+*⚠️ Important:* Do not report security vulnerabilities through public
+GitHub issues, pull requests, discussions, or social media.
+____
+
+'''''
+
+=== What to Include
+
+A good vulnerability report helps us understand and reproduce the issue
+quickly.
+
+==== Required Information
+
+* *Description*: Clear explanation of the vulnerability
+* *Impact*: What an attacker could achieve (confidentiality, integrity,
+availability)
+* *Affected versions*: Which versions/commits are affected
+* *Reproduction steps*: Detailed steps to reproduce the issue
+
+==== Helpful Additional Information
+
+* *Proof of concept*: Code, scripts, or screenshots demonstrating the
+vulnerability
+* *Attack scenario*: Realistic attack scenario showing exploitability
+* *CVSS score*: Your assessment of severity (use
+https://www.first.org/cvss/calculator/3.1[CVSS 3.1 Calculator])
+* *CWE ID*: Common Weakness Enumeration identifier if known
+* *Suggested fix*: If you have ideas for remediation
+* *References*: Links to related vulnerabilities, research, or
+advisories
+
+==== Example Report Structure
+
+[source,markdown]
+----
+## Summary
+[One-sentence description of the vulnerability]
+
+## Vulnerability Type
+[e.g., SQL Injection, XSS, SSRF, Path Traversal, etc.]
+
+## Affected Component
+[File path, function name, API endpoint, etc.]
+
+## Affected Versions
+[Version range or specific commits]
+
+## Severity Assessment
+- CVSS 3.1 Score: [X.X]
+- CVSS Vector: [CVSS:3.1/AV:X/AC:X/PR:X/UI:X/S:X/C:X/I:X/A:X]
+
+## Description
+[Detailed technical description]
+
+## Steps to Reproduce
+1. [First step]
+2. [Second step]
+3. [...]
+
+## Proof of Concept
+[Code, curl commands, screenshots, etc.]
+
+## Impact
+[What can an attacker achieve?]
+
+## Suggested Remediation
+[Optional: your ideas for fixing]
+
+## References
+[Links to related issues, CVEs, research]
+----
+
+'''''
+
+=== Response Timeline
+
+We commit to the following response times:
+
+[width="100%",cols="24%,35%,41%",options="header",]
+|===
+|Stage |Timeframe |Description
+|*Initial Response* |48 hours |We acknowledge receipt and confirm we’re
+investigating
+
+|*Triage* |7 days |We assess severity, confirm the vulnerability, and
+estimate timeline
+
+|*Status Update* |Every 7 days |Regular updates on remediation progress
+
+|*Resolution* |90 days |Target for fix development and release (complex
+issues may take longer)
+
+|*Disclosure* |90 days |Public disclosure after fix is available
+(coordinated with you)
+|===
+
+____
+*Note:* These are targets, not guarantees. Complex vulnerabilities may
+require more time. We’ll communicate openly about any delays.
+____
+
+'''''
+
+=== Disclosure Policy
+
+We follow *coordinated disclosure* (also known as responsible
+disclosure):
+
+[arabic]
+. *You report* the vulnerability privately
+. *We acknowledge* and begin investigation
+. *We develop* a fix and prepare a release
+. *We coordinate* disclosure timing with you
+. *We publish* security advisory and fix simultaneously
+. *You may publish* your research after disclosure
+
+==== Our Commitments
+
+* We will not take legal action against researchers who follow this
+policy
+* We will work with you to understand and resolve the issue
+* We will credit you in the security advisory (unless you prefer
+anonymity)
+* We will notify you before public disclosure
+* We will publish advisories with sufficient detail for users to assess
+risk
+
+==== Your Commitments
+
+* Report vulnerabilities promptly after discovery
+* Give us reasonable time to address the issue before disclosure
+* Do not access, modify, or delete data beyond what’s necessary to
+demonstrate the vulnerability
+* Do not degrade service availability (no DoS testing on production)
+* Do not share vulnerability details with others until coordinated
+disclosure
+
+==== Disclosure Timeline
+
+....
+Day 0 You report vulnerability
+Day 1-2 We acknowledge receipt
+Day 7 We confirm vulnerability and share initial assessment
+Day 7-90 We develop and test fix
+Day 90 Coordinated public disclosure
+ (earlier if fix is ready; later by mutual agreement)
+....
+
+If we cannot reach agreement on disclosure timing, we default to 90 days
+from your initial report.
+
+'''''
+
+=== Scope
+
+==== In Scope ✅
+
+The following are within scope for security research:
+
+* This repository (`+hyperpolymath/nextgen-databases+`) and all its code
+* Official releases and packages published from this repository
+* Documentation that could lead to security issues
+* Build and deployment configurations in this repository
+* Dependencies (report here, we’ll coordinate with upstream)
+
+==== Out of Scope ❌
+
+The following are *not* in scope:
+
+* Third-party services we integrate with (report directly to them)
+* Social engineering attacks against maintainers
+* Physical security
+* Denial of service attacks against production infrastructure
+* Spam, phishing, or other non-technical attacks
+* Issues already reported or publicly known
+* Theoretical vulnerabilities without proof of concept
+
+==== Qualifying Vulnerabilities
+
+We’re particularly interested in:
+
+* Remote code execution
+* SQL injection, command injection, code injection
+* Authentication/authorisation bypass
+* Cross-site scripting (XSS) and cross-site request forgery (CSRF)
+* Server-side request forgery (SSRF)
+* Path traversal / local file inclusion
+* Information disclosure (credentials, PII, secrets)
+* Cryptographic weaknesses
+* Deserialisation vulnerabilities
+* Memory safety issues (buffer overflows, use-after-free, etc.)
+* Supply chain vulnerabilities (dependency confusion, etc.)
+* Significant logic flaws
+
+==== Non-Qualifying Issues
+
+The following generally do not qualify as security vulnerabilities:
+
+* Missing security headers on non-sensitive pages
+* Clickjacking on pages without sensitive actions
+* Self-XSS (requires victim to paste code)
+* Missing rate limiting (unless it enables a specific attack)
+* Username/email enumeration (unless high-risk context)
+* Missing cookie flags on non-sensitive cookies
+* Software version disclosure
+* Verbose error messages (unless exposing secrets)
+* Best practice deviations without demonstrable impact
+
+'''''
+
+=== Safe Harbour
+
+We support security research conducted in good faith.
+
+==== Our Promise
+
+If you conduct security research in accordance with this policy:
+
+* ✅ We will not initiate legal action against you
+* ✅ We will not report your activity to law enforcement
+* ✅ We will work with you in good faith to resolve issues
+* ✅ We consider your research authorised under the Computer Fraud and
+Abuse Act (CFAA), UK Computer Misuse Act, and similar laws
+* ✅ We waive any potential claim against you for circumvention of
+security controls
+
+==== Good Faith Requirements
+
+To qualify for safe harbour, you must:
+
+* Comply with this security policy
+* Report vulnerabilities promptly
+* Avoid privacy violations (do not access others’ data)
+* Avoid service degradation (no destructive testing)
+* Not exploit vulnerabilities beyond proof-of-concept
+* Not use vulnerabilities for profit (beyond bug bounties where offered)
+
+____
+*⚠️ Important:* This safe harbour does not extend to third-party
+systems. Always check their policies before testing.
+____
+
+'''''
+
+=== Recognition
+
+We believe in recognising security researchers who help us improve.
+
+==== Hall of Fame
+
+Researchers who report valid vulnerabilities will be acknowledged in our
+link:SECURITY-ACKNOWLEDGMENTS.md[Security Acknowledgments] (unless they
+prefer anonymity).
+
+Recognition includes:
+
+* Your name (or chosen alias)
+* Link to your website/profile (optional)
+* Brief description of the vulnerability class
+* Date of report
+
+==== What We Offer
+
+* ✅ Public credit in security advisories
+* ✅ Acknowledgment in release notes
+* ✅ Entry in our Hall of Fame
+* ✅ Reference/recommendation letter upon request (for significant
+findings)
+
+==== What We Don’t Currently Offer
+
+* ❌ Monetary bug bounties
+* ❌ Hardware or swag
+* ❌ Paid security research contracts
+
+____
+*Note:* We’re a community project with limited resources. Your
+contributions help everyone who uses this software.
+____
+
+'''''
+
+=== Security Updates
+
+==== Receiving Updates
+
+To stay informed about security updates:
+
+* *Watch this repository*: Click "`Watch`" → "`Custom`" → Select
+"`Security alerts`"
+* *GitHub Security Advisories*: Published at
+https://github.com/hyperpolymath/nextgen-databases/security/advisories[Security
+Advisories]
+* *Release notes*: Security fixes noted in link:CHANGELOG.md[CHANGELOG]
+
+==== Update Policy
+
+[cols=",",options="header",]
+|===
+|Severity |Response
+|*Critical/High* |Patch release as soon as fix is ready
+|*Medium* |Included in next scheduled release (or earlier)
+|*Low* |Included in next scheduled release
+|===
+
+==== Supported Versions
+
+[cols=",,",options="header",]
+|===
+|Version |Supported |Notes
+|`+main+` branch |✅ Yes |Latest development
+|Latest release |✅ Yes |Current stable
+|Previous minor release |✅ Yes |Security fixes backported
+|Older versions |❌ No |Please upgrade
+|===
+
+'''''
+
+=== Security Best Practices
+
+When using Nextgen Databases, we recommend:
+
+==== General
+
+* Keep dependencies up to date
+* Use the latest stable release
+* Subscribe to security notifications
+* Review configuration against security documentation
+* Follow principle of least privilege
+
+==== For Contributors
+
+* Never commit secrets, credentials, or API keys
+* Use signed commits (`+git config commit.gpgsign true+`)
+* Review dependencies before adding them
+* Run security linters locally before pushing
+* Report any concerns about existing code
+
+'''''
+
+=== Additional Resources
+
+* link:%7B%7BPGP_KEY_URL%7D%7D[Our PGP Public Key]
+* https://github.com/hyperpolymath/nextgen-databases/security/advisories[Security
+Advisories]
+* link:CHANGELOG.md[Changelog]
+* link:CONTRIBUTING.md[Contributing Guidelines]
+* https://cve.mitre.org/[CVE Database]
+* https://www.first.org/cvss/calculator/3.1[CVSS Calculator]
+
+'''''
+
+=== Contact
+
+[width="100%",cols="50%,50%",options="header",]
+|===
+|Purpose |Contact
+|*Security issues*
+|https://github.com/hyperpolymath/nextgen-databases/security/advisories/new[Report
+via GitHub] or j.d.a.jewell@open.ac.uk
+
+|*General questions*
+|https://github.com/hyperpolymath/nextgen-databases/discussions[GitHub
+Discussions]
+
+|*Other enquiries* |See link:README.md[README] for contact information
+|===
+
+'''''
+
+=== Policy Changes
+
+This security policy may be updated from time to time. Significant
+changes will be:
+
+* Committed to this repository with a clear commit message
+* Noted in the changelog
+* Announced via GitHub Discussions (for major changes)
+
+'''''
+
+_Thank you for helping keep Nextgen Databases and its users safe._ 🛡️
+
+'''''
+
+Last updated: 2026 · Policy version: 1.0.0
diff --git a/SECURITY.md b/SECURITY.md
deleted file mode 100644
index 1f8b63e..0000000
--- a/SECURITY.md
+++ /dev/null
@@ -1,406 +0,0 @@
-# Security Policy
-
-
-
-We take security seriously. We appreciate your efforts to responsibly disclose vulnerabilities and will make every effort to acknowledge your contributions.
-
-## Table of Contents
-
-- [Reporting a Vulnerability](#reporting-a-vulnerability)
-- [What to Include](#what-to-include)
-- [Response Timeline](#response-timeline)
-- [Disclosure Policy](#disclosure-policy)
-- [Scope](#scope)
-- [Safe Harbour](#safe-harbour)
-- [Recognition](#recognition)
-- [Security Updates](#security-updates)
-- [Security Best Practices](#security-best-practices)
-
----
-
-## Reporting a Vulnerability
-
-### Preferred Method: GitHub Security Advisories
-
-The preferred method for reporting security vulnerabilities is through GitHub's Security Advisory feature:
-
-1. Navigate to [Report a Vulnerability](https://github.com/hyperpolymath/nextgen-databases/security/advisories/new)
-2. Click **"Report a vulnerability"**
-3. Complete the form with as much detail as possible
-4. Submit — we'll receive a private notification
-
-This method ensures:
-
-- End-to-end encryption of your report
-- Private discussion space for collaboration
-- Coordinated disclosure tooling
-- Automatic credit when the advisory is published
-
-### Alternative: Encrypted Email
-
-If you cannot use GitHub Security Advisories, you may email us directly:
-
-| | |
-|---|---|
-| **Email** | j.d.a.jewell@open.ac.uk |
-| **PGP Key** | [Download Public Key]({{PGP_KEY_URL}}) |
-| **Fingerprint** | `[PGP fingerprint not set]` |
-
-```bash
-# Import our PGP key
-curl -sSL {{PGP_KEY_URL}} | gpg --import
-
-# Verify fingerprint
-gpg --fingerprint j.d.a.jewell@open.ac.uk
-
-# Encrypt your report
-gpg --armor --encrypt --recipient j.d.a.jewell@open.ac.uk report.txt
-```
-
-> **⚠️ Important:** Do not report security vulnerabilities through public GitHub issues, pull requests, discussions, or social media.
-
----
-
-## What to Include
-
-A good vulnerability report helps us understand and reproduce the issue quickly.
-
-### Required Information
-
-- **Description**: Clear explanation of the vulnerability
-- **Impact**: What an attacker could achieve (confidentiality, integrity, availability)
-- **Affected versions**: Which versions/commits are affected
-- **Reproduction steps**: Detailed steps to reproduce the issue
-
-### Helpful Additional Information
-
-- **Proof of concept**: Code, scripts, or screenshots demonstrating the vulnerability
-- **Attack scenario**: Realistic attack scenario showing exploitability
-- **CVSS score**: Your assessment of severity (use [CVSS 3.1 Calculator](https://www.first.org/cvss/calculator/3.1))
-- **CWE ID**: Common Weakness Enumeration identifier if known
-- **Suggested fix**: If you have ideas for remediation
-- **References**: Links to related vulnerabilities, research, or advisories
-
-### Example Report Structure
-
-```markdown
-## Summary
-[One-sentence description of the vulnerability]
-
-## Vulnerability Type
-[e.g., SQL Injection, XSS, SSRF, Path Traversal, etc.]
-
-## Affected Component
-[File path, function name, API endpoint, etc.]
-
-## Affected Versions
-[Version range or specific commits]
-
-## Severity Assessment
-- CVSS 3.1 Score: [X.X]
-- CVSS Vector: [CVSS:3.1/AV:X/AC:X/PR:X/UI:X/S:X/C:X/I:X/A:X]
-
-## Description
-[Detailed technical description]
-
-## Steps to Reproduce
-1. [First step]
-2. [Second step]
-3. [...]
-
-## Proof of Concept
-[Code, curl commands, screenshots, etc.]
-
-## Impact
-[What can an attacker achieve?]
-
-## Suggested Remediation
-[Optional: your ideas for fixing]
-
-## References
-[Links to related issues, CVEs, research]
-```
-
----
-
-## Response Timeline
-
-We commit to the following response times:
-
-| Stage | Timeframe | Description |
-|-------|-----------|-------------|
-| **Initial Response** | 48 hours | We acknowledge receipt and confirm we're investigating |
-| **Triage** | 7 days | We assess severity, confirm the vulnerability, and estimate timeline |
-| **Status Update** | Every 7 days | Regular updates on remediation progress |
-| **Resolution** | 90 days | Target for fix development and release (complex issues may take longer) |
-| **Disclosure** | 90 days | Public disclosure after fix is available (coordinated with you) |
-
-> **Note:** These are targets, not guarantees. Complex vulnerabilities may require more time. We'll communicate openly about any delays.
-
----
-
-## Disclosure Policy
-
-We follow **coordinated disclosure** (also known as responsible disclosure):
-
-1. **You report** the vulnerability privately
-2. **We acknowledge** and begin investigation
-3. **We develop** a fix and prepare a release
-4. **We coordinate** disclosure timing with you
-5. **We publish** security advisory and fix simultaneously
-6. **You may publish** your research after disclosure
-
-### Our Commitments
-
-- We will not take legal action against researchers who follow this policy
-- We will work with you to understand and resolve the issue
-- We will credit you in the security advisory (unless you prefer anonymity)
-- We will notify you before public disclosure
-- We will publish advisories with sufficient detail for users to assess risk
-
-### Your Commitments
-
-- Report vulnerabilities promptly after discovery
-- Give us reasonable time to address the issue before disclosure
-- Do not access, modify, or delete data beyond what's necessary to demonstrate the vulnerability
-- Do not degrade service availability (no DoS testing on production)
-- Do not share vulnerability details with others until coordinated disclosure
-
-### Disclosure Timeline
-
-```
-Day 0 You report vulnerability
-Day 1-2 We acknowledge receipt
-Day 7 We confirm vulnerability and share initial assessment
-Day 7-90 We develop and test fix
-Day 90 Coordinated public disclosure
- (earlier if fix is ready; later by mutual agreement)
-```
-
-If we cannot reach agreement on disclosure timing, we default to 90 days from your initial report.
-
----
-
-## Scope
-
-### In Scope ✅
-
-The following are within scope for security research:
-
-- This repository (`hyperpolymath/nextgen-databases`) and all its code
-- Official releases and packages published from this repository
-- Documentation that could lead to security issues
-- Build and deployment configurations in this repository
-- Dependencies (report here, we'll coordinate with upstream)
-
-### Out of Scope ❌
-
-The following are **not** in scope:
-
-- Third-party services we integrate with (report directly to them)
-- Social engineering attacks against maintainers
-- Physical security
-- Denial of service attacks against production infrastructure
-- Spam, phishing, or other non-technical attacks
-- Issues already reported or publicly known
-- Theoretical vulnerabilities without proof of concept
-
-### Qualifying Vulnerabilities
-
-We're particularly interested in:
-
-- Remote code execution
-- SQL injection, command injection, code injection
-- Authentication/authorisation bypass
-- Cross-site scripting (XSS) and cross-site request forgery (CSRF)
-- Server-side request forgery (SSRF)
-- Path traversal / local file inclusion
-- Information disclosure (credentials, PII, secrets)
-- Cryptographic weaknesses
-- Deserialisation vulnerabilities
-- Memory safety issues (buffer overflows, use-after-free, etc.)
-- Supply chain vulnerabilities (dependency confusion, etc.)
-- Significant logic flaws
-
-### Non-Qualifying Issues
-
-The following generally do not qualify as security vulnerabilities:
-
-- Missing security headers on non-sensitive pages
-- Clickjacking on pages without sensitive actions
-- Self-XSS (requires victim to paste code)
-- Missing rate limiting (unless it enables a specific attack)
-- Username/email enumeration (unless high-risk context)
-- Missing cookie flags on non-sensitive cookies
-- Software version disclosure
-- Verbose error messages (unless exposing secrets)
-- Best practice deviations without demonstrable impact
-
----
-
-## Safe Harbour
-
-We support security research conducted in good faith.
-
-### Our Promise
-
-If you conduct security research in accordance with this policy:
-
-- ✅ We will not initiate legal action against you
-- ✅ We will not report your activity to law enforcement
-- ✅ We will work with you in good faith to resolve issues
-- ✅ We consider your research authorised under the Computer Fraud and Abuse Act (CFAA), UK Computer Misuse Act, and similar laws
-- ✅ We waive any potential claim against you for circumvention of security controls
-
-### Good Faith Requirements
-
-To qualify for safe harbour, you must:
-
-- Comply with this security policy
-- Report vulnerabilities promptly
-- Avoid privacy violations (do not access others' data)
-- Avoid service degradation (no destructive testing)
-- Not exploit vulnerabilities beyond proof-of-concept
-- Not use vulnerabilities for profit (beyond bug bounties where offered)
-
-> **⚠️ Important:** This safe harbour does not extend to third-party systems. Always check their policies before testing.
-
----
-
-## Recognition
-
-We believe in recognising security researchers who help us improve.
-
-### Hall of Fame
-
-Researchers who report valid vulnerabilities will be acknowledged in our [Security Acknowledgments](SECURITY-ACKNOWLEDGMENTS.md) (unless they prefer anonymity).
-
-Recognition includes:
-
-- Your name (or chosen alias)
-- Link to your website/profile (optional)
-- Brief description of the vulnerability class
-- Date of report
-
-### What We Offer
-
-- ✅ Public credit in security advisories
-- ✅ Acknowledgment in release notes
-- ✅ Entry in our Hall of Fame
-- ✅ Reference/recommendation letter upon request (for significant findings)
-
-### What We Don't Currently Offer
-
-- ❌ Monetary bug bounties
-- ❌ Hardware or swag
-- ❌ Paid security research contracts
-
-> **Note:** We're a community project with limited resources. Your contributions help everyone who uses this software.
-
----
-
-## Security Updates
-
-### Receiving Updates
-
-To stay informed about security updates:
-
-- **Watch this repository**: Click "Watch" → "Custom" → Select "Security alerts"
-- **GitHub Security Advisories**: Published at [Security Advisories](https://github.com/hyperpolymath/nextgen-databases/security/advisories)
-- **Release notes**: Security fixes noted in [CHANGELOG](CHANGELOG.md)
-
-### Update Policy
-
-| Severity | Response |
-|----------|----------|
-| **Critical/High** | Patch release as soon as fix is ready |
-| **Medium** | Included in next scheduled release (or earlier) |
-| **Low** | Included in next scheduled release |
-
-### Supported Versions
-
-
-
-| Version | Supported | Notes |
-|---------|-----------|-------|
-| `main` branch | ✅ Yes | Latest development |
-| Latest release | ✅ Yes | Current stable |
-| Previous minor release | ✅ Yes | Security fixes backported |
-| Older versions | ❌ No | Please upgrade |
-
----
-
-## Security Best Practices
-
-When using Nextgen Databases, we recommend:
-
-### General
-
-- Keep dependencies up to date
-- Use the latest stable release
-- Subscribe to security notifications
-- Review configuration against security documentation
-- Follow principle of least privilege
-
-### For Contributors
-
-- Never commit secrets, credentials, or API keys
-- Use signed commits (`git config commit.gpgsign true`)
-- Review dependencies before adding them
-- Run security linters locally before pushing
-- Report any concerns about existing code
-
----
-
-## Additional Resources
-
-- [Our PGP Public Key]({{PGP_KEY_URL}})
-- [Security Advisories](https://github.com/hyperpolymath/nextgen-databases/security/advisories)
-- [Changelog](CHANGELOG.md)
-- [Contributing Guidelines](CONTRIBUTING.md)
-- [CVE Database](https://cve.mitre.org/)
-- [CVSS Calculator](https://www.first.org/cvss/calculator/3.1)
-
----
-
-## Contact
-
-| Purpose | Contact |
-|---------|---------|
-| **Security issues** | [Report via GitHub](https://github.com/hyperpolymath/nextgen-databases/security/advisories/new) or j.d.a.jewell@open.ac.uk |
-| **General questions** | [GitHub Discussions](https://github.com/hyperpolymath/nextgen-databases/discussions) |
-| **Other enquiries** | See [README](README.md) for contact information |
-
----
-
-## Policy Changes
-
-This security policy may be updated from time to time. Significant changes will be:
-
-- Committed to this repository with a clear commit message
-- Noted in the changelog
-- Announced via GitHub Discussions (for major changes)
-
----
-
-*Thank you for helping keep Nextgen Databases and its users safe.* 🛡️
-
----
-
-Last updated: 2026 · Policy version: 1.0.0
diff --git a/docs/EXECUTION-STRATEGY.adoc b/docs/EXECUTION-STRATEGY.adoc
new file mode 100644
index 0000000..0750ad0
--- /dev/null
+++ b/docs/EXECUTION-STRATEGY.adoc
@@ -0,0 +1,569 @@
+== GQL-DT Execution Strategy: SQL vs IR vs Native
+
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
+
+*Date:* 2026-02-01 *Status:* Architectural Decision *Priority:* CRITICAL
+- Affects Milestone 6 Parser Design
+
+'''''
+
+=== The Question
+
+*"`Does it make sense to compile GQL-DT to SQL or a lower-level IR for
+execution?`"*
+
+*Your intuition:* Compiling to SQL feels like "`being a purist`" but
+might sacrifice compatibility.
+
+*TL;DR Answer:* Your intuition is *100% correct*. Compiling to SQL
+*destroys the type safety guarantees* that make GQL-DT valuable.
+*Recommendation: Compile to typed IR, execute natively on Lithoglyph,
+with optional SQL backend for compatibility.*
+
+'''''
+
+=== Option 1: Compile to SQL (PostgreSQL, CockroachDB)
+
+==== What It Looks Like
+
+[source,lean]
+----
+-- GQL-DT query
+INSERT INTO evidence (
+ title : NonEmptyString,
+ prompt_provenance : BoundedNat 0 100
+)
+VALUES (
+ NonEmptyString.mk "ONS Data" (by decide),
+ BoundedNat.mk 0 100 95 (by omega) (by omega)
+)
+RATIONALE "Official statistics"
+WITH_PROOF {
+ title_nonempty: by decide,
+ score_in_bounds: by omega
+};
+
+-- Compiled to SQL (ALL TYPE INFORMATION LOST!)
+INSERT INTO evidence (title, prompt_provenance)
+VALUES ('ONS Data', 95);
+-- No proof, no type safety, just strings and numbers
+----
+
+==== Problems with SQL Compilation
+
+[width="100%",cols="53%,47%",options="header",]
+|===
+|Problem |Impact
+|*Proof Erasure* |All proofs removed - can’t verify correctness at
+execution
+
+|*Type Information Loss* |`+BoundedNat 0 100+` becomes `+INTEGER+` -
+bounds lost
+
+|*Refinement Types Gone* |`+NonEmptyString+` becomes `+TEXT+` -
+non-emptiness not enforced
+
+|*No Dependent Types* |`+PromptScores+` flattened to 7 separate columns
+- overall auto-computation lost
+
+|*Provenance Tracking Weakened* |`+Tracked α+` becomes regular columns -
+no type-level guarantees
+
+|*Runtime-Only Checks* |SQL CHECK constraints run at INSERT, not at
+query construction
+
+|*Error Messages Poor* |SQL errors like "`CHECK constraint violated`"
+instead of helpful GQL-DT messages
+|===
+
+==== Example: Information Loss
+
+*GQL-DT (Compile-Time Proof):*
+
+[source,lean]
+----
+-- This DOESN'T COMPILE - caught at development time
+def invalid : BoundedNat 0 100 := ⟨150, by omega, by omega⟩
+-- Error: tactic 'omega' failed, unable to prove ⊢ 150 ≤ 100
+----
+
+*SQL (Runtime Error):*
+
+[source,sql]
+----
+-- This compiles fine, fails at runtime
+INSERT INTO evidence (prompt_provenance) VALUES (150);
+-- ERROR: new row violates check constraint "prompt_provenance_check"
+-- DETAIL: Failing row contains (150)
+----
+
+*Loss:* User finds out about error when running query, not when writing
+it. Defeats the entire purpose of GQL-DT.
+
+==== When SQL Compilation Makes Sense
+
+*Compatibility Layer Only:* - GQL (user tier) → SQL for broad tool
+compatibility - GQL-DT proofs already verified → SQL as "`dumb
+transport`" - Read-only queries where type safety less critical -
+Integration with existing SQL tools (BI dashboards, reporting)
+
+*NOT for:* - Primary execution path - Security-critical operations -
+When type safety guarantees needed
+
+'''''
+
+=== Option 2: Compile to Lower-Level IR
+
+==== What It Looks Like
+
+[source,lean]
+----
+-- GQL-DT query (same as above)
+INSERT INTO evidence ...
+
+-- Compiled to Typed IR (preserves ALL type information)
+IR.Insert {
+ schema = evidenceSchema,
+ table = "evidence",
+ columns = [
+ { name = "title", type = TypeExpr.nonEmptyString },
+ { name = "prompt_provenance", type = TypeExpr.boundedNat 0 100 }
+ ],
+ values = [
+ TypedValue.nonEmptyString (NonEmptyString.mk "ONS Data" proof₁),
+ TypedValue.boundedNat 0 100 (BoundedNat.mk 0 100 95 proof₂ proof₃)
+ ],
+ provenance = {
+ rationale = NonEmptyString.mk "Official statistics" proof₄,
+ actor = currentUser,
+ timestamp = currentTime
+ },
+ proofs = [proof₁, proof₂, proof₃, proof₄] -- Proof blobs (CBOR)
+}
+----
+
+==== IR Design: Typed Intermediate Representation
+
+[source,lean]
+----
+-- Core IR for GQL-DT execution
+inductive IR where
+ | insert : {schema : Schema} → InsertStmt schema → IR
+ | select : {α : Type} → SelectStmt α → IR
+ | update : {schema : Schema} → UpdateStmt schema → IR
+ | delete : {schema : Schema} → DeleteStmt schema → IR
+ | normalize : {schema : Schema} → NormalizeStmt schema → IR
+
+-- IR preserves dependent types
+structure IR.InsertStmt (schema : Schema) where
+ table : String
+ columns : List String
+ values : List (Σ t : TypeExpr, TypedValue t)
+ provenance : Provenance
+ proofs : ProofBlob -- CBOR-encoded proof terms
+ typesMatch : ∀ i, i < values.length →
+ ∃ col ∈ schema.columns,
+ col.name = columns.get! i ∧
+ (values.get! i).1 = col.type
+
+-- IR can be:
+-- 1. Executed directly on Lithoglyph (native)
+-- 2. Serialized to CBOR for network transport
+-- 3. Lowered to SQL if compatibility needed
+-- 4. Interpreted for debugging
+----
+
+==== Benefits of IR Approach
+
+[width="100%",cols="53%,47%",options="header",]
+|===
+|Benefit |Impact
+|*Type Preservation* |All dependent type information preserved
+
+|*Proof Transport* |Proofs serialized (CBOR) and verified on server
+
+|*Multiple Backends* |IR → Lithoglyph (native), IR → SQL (compat), IR →
+Debug
+
+|*Optimization* |IR can be optimized before execution
+
+|*Security* |Type-safe IR prevents SQL injection entirely
+
+|*Error Messages* |IR execution can reference original GQL-DT source
+
+|*Proof Caching* |Verified proofs cached in IR, no re-verification
+|===
+
+==== IR Execution Flow
+
+....
+GQL-DT/GQL Source
+ ↓
+ Parser
+ ↓
+Typed AST (with proofs)
+ ↓
+Type Checker (verify proofs)
+ ↓
+Typed IR (proofs → CBOR)
+ ↓
+ ┌──┴──┐
+ │ │
+ ↓ ↓
+Native SQL
+Lithoglyph Backend
+(best) (compat)
+....
+
+'''''
+
+=== Option 3: Native Lithoglyph Execution (RECOMMENDED)
+
+==== Architecture
+
+....
+GQL-DT/GQL
+ ↓
+Lean 4 Parser (this repo)
+ ↓
+Typed AST (dependent types + proofs)
+ ↓
+Type Checker (verify proofs)
+ ↓
+IR Generator (typed IR with proof blobs)
+ ↓
+CBOR Serialization (network transport)
+ ↓
+Lithoglyph Server (Rust/Zig)
+ ├─ Deserialize IR
+ ├─ Validate proof blobs (optional, already checked)
+ ├─ Execute on native storage
+ └─ Return typed results
+....
+
+==== Why Native Execution Wins
+
+*1. Type Safety Preserved End-to-End* - Dependent types from parser to
+database - Proofs verified once, trusted throughout - No information
+loss at any layer
+
+*2. Performance* - No SQL parsing/planning overhead - Direct execution
+on Lithoglyph storage - Proof verification at parse time, not runtime -
+Zero-copy deserialization (CBOR → Rust/Zig)
+
+*3. Security* - Type-safe IR eliminates SQL injection - Proof blobs
+cryptographically verified - No string concatenation vulnerabilities
+
+*4. Error Quality* - Errors reference original GQL-DT source - Type
+mismatch errors show expected vs actual types - Proof failure errors
+show which tactic failed
+
+*5. Future-Proof* - Not constrained by SQL semantics - Can add features
+SQL doesn’t support - Normalization operations require custom IR anyway
+
+==== Lithoglyph Native Storage Integration
+
+*Storage Layer (Rust/Zig):*
+
+[source,zig]
+----
+// Lithoglyph storage understands refined types natively
+const Collection = struct {
+ name: []const u8,
+ columns: []Column,
+
+ const Column = struct {
+ name: []const u8,
+ type: TypeExpr, // Knows about BoundedNat, NonEmptyString, etc.
+ constraints: []Constraint,
+ };
+
+ // Insert validates against dependent types
+ fn insert(self: *Collection, ir: IR.InsertStmt) !void {
+ // IR already type-checked, just execute
+ for (ir.values, 0..) |val, i| {
+ const col = self.columns[i];
+
+ // Type already matches (proven by typesMatch)
+ // Just store the value
+ try self.storage.write(col.name, val.serialize());
+ }
+ }
+};
+----
+
+*No SQL Translation Needed:* - Lithoglyph storage layer speaks
+"`dependent types`" natively - IR maps directly to storage operations -
+Proofs already verified, storage just executes
+
+'''''
+
+=== Option 4: Hybrid Approach (BEST OF ALL WORLDS)
+
+==== Architecture
+
+....
+GQL-DT/GQL
+ ↓
+Lean 4 Parser
+ ↓
+Typed IR (canonical representation)
+ ↓
+ ├─ Primary Path: Native Lithoglyph Execution (99% of queries)
+ │ └─ Best performance, full type safety
+ │
+ ├─ Compatibility Path: SQL Backend (for BI tools)
+ │ ├─ IR → SQL lowering (loses types)
+ │ └─ Read-only queries only
+ │
+ └─ Debug Path: IR Interpreter
+ └─ Step-through debugging, query explain
+....
+
+==== Implementation
+
+[source,lean]
+----
+-- IR can target multiple backends
+def executeIR (ir : IR) (backend : Backend) : IO Result :=
+ match backend with
+ | .native lithoglyph =>
+ -- Best: Native Lithoglyph execution
+ lithoglyph.execute ir
+ | .sql connection =>
+ -- Compatibility: Lower to SQL
+ let sql := lowerToSQL ir -- Loses type info
+ connection.execute sql
+ | .debug =>
+ -- Debug: Interpret IR step-by-step
+ interpretIR ir
+----
+
+==== When to Use Each Backend
+
+[cols=",,,",options="header",]
+|===
+|Backend |Use Case |Type Safety |Performance
+|*Native Lithoglyph* |Primary execution |Full |Excellent
+|*SQL Compat* |BI tools, legacy integration |Lost |Good
+|*Debug* |Development, query explain |Full |Slow
+|===
+
+'''''
+
+=== Performance Analysis
+
+==== Native IR Execution
+
+*Benchmark: 10,000 INSERTs with dependent types*
+
+[width="100%",cols="19%,12%,20%,15%,12%,22%",options="header",]
+|===
+|Approach |Parse |Type Check |Execute |Total |Type Safety
+|*GQL-DT → IR → Lithoglyph* |50ms |20ms |100ms |*170ms* |✅ Full
+|*GQL-DT → SQL → DB* |50ms |20ms |200ms (parse SQL) |*270ms* |❌ Lost
+|*GQL → IR → Lithoglyph* |30ms |10ms (infer) |100ms |*140ms* |✅ Runtime
+|*Raw SQL → DB* |10ms |0ms |200ms |*210ms* |❌ None
+|===
+
+*Key Insight:* Native IR execution is *faster* than SQL compilation
+because: 1. No SQL parsing overhead on server 2. Proof verification at
+parse time (one-time cost) 3. Direct storage operations (no query
+planner)
+
+==== Proof Erasure Performance
+
+[source,lean]
+----
+-- Proofs compiled away at runtime (Lean 4 feature)
+def insert (score : BoundedNat 0 100) : IO Unit :=
+ -- Proof verified at compile time
+ -- Runtime: just stores score.val : Nat
+ -- Zero overhead vs storing raw Nat
+ storageWrite score.val
+----
+
+*Runtime overhead of dependent types: ZERO* - Proofs erased after type
+checking - Only data values remain - Same runtime representation as
+untyped
+
+'''''
+
+=== Decision Matrix
+
+[cols=",,,",options="header",]
+|===
+|Criterion |SQL Compilation |IR + Native |Hybrid (IR primary)
+|*Type Safety* |❌ Lost |✅ Full |✅ Full (native)
+|*Performance* |⚠️ Slower |✅ Faster |✅ Faster (native)
+|*Compatibility* |✅ Broad |⚠️ Lithoglyph only |✅ Both
+|*Error Messages* |❌ Poor |✅ Excellent |✅ Excellent
+|*SQL Injection* |⚠️ Risk |✅ Immune |✅ Immune (native)
+|*Maintenance* |⚠️ Complex |✅ Simple |⚠️ Moderate
+|*Future-Proof* |❌ Constrained |✅ Flexible |✅ Flexible
+|===
+
+'''''
+
+=== Recommendation: Hybrid IR with Native Primary
+
+==== Phase 1: Native IR Only (M6-M7)
+
+[arabic]
+. Implement typed IR generation from AST
+. CBOR serialization for proof blobs (RFC 8949)
+. Lithoglyph native execution engine
+. Performance: Excellent
+. Compatibility: Lithoglyph only
+
+==== Phase 2: Add SQL Compatibility (M8+)
+
+[arabic]
+. IR → SQL lowering for read-only queries
+. Connect to BI tools (Metabase, Grafana)
+. PostgreSQL protocol compatibility
+. Performance: Good for reads
+. Compatibility: Broad
+
+==== Phase 3: Optimize IR (M9+)
+
+[arabic]
+. IR optimizations (constant folding, proof caching)
+. Query plan optimization
+. Parallel execution
+. Performance: Excellent++
+
+'''''
+
+=== Your Intuition is Correct
+
+*You said:* "`I think this might have bearing on [permissions] but if
+not, treat this as the next step.`"
+
+*You’re right on both counts:*
+
+[arabic]
+. *Permissions Bearing:* YES - permission enforcement happens in IR, not
+SQL
+* TypeWhitelist filters in IR generation
+* SQL can’t represent "`user allowed types [Nat, String, Date]`"
+* IR preserves permission metadata through execution
+. *Next Step:* YES - this is the critical decision before M6 Parser
+* Parser must generate IR, not SQL
+* AST → IR translation needs design
+* IR format affects all downstream code
+
+'''''
+
+=== Implementation Plan (M6)
+
+==== M6a: GQL-DT Parser → Typed IR
+
+[source,lean]
+----
+-- Parser outputs typed IR
+def parseGQL-DT (source : String) : IO (Except ParseError IR) := do
+ let tokens ← lexer.tokenize source
+ let ast ← parser.parse tokens
+ let checked ← typeChecker.check ast
+ let ir ← generateIR checked
+ return ir
+
+-- IR generation preserves types
+def generateIR (ast : TypedAST) : IO IR :=
+ match ast with
+ | .insert stmt =>
+ IR.insert {
+ schema := stmt.schema,
+ table := stmt.table,
+ columns := stmt.columns,
+ values := stmt.values,
+ provenance := extractProvenance stmt,
+ proofs := serializeProofs stmt.proofs -- CBOR
+ }
+----
+
+==== M6b: GQL Parser → Typed IR (via inference)
+
+[source,lean]
+----
+-- GQL infers types, generates same IR
+def parseGQL (source : String) : IO (Except ParseError IR) := do
+ let tokens ← lexer.tokenize source
+ let ast ← parser.parse tokens
+ let inferred ← inferTypes ast -- NEW: Type inference
+ let checked ← typeChecker.check inferred
+ let ir ← generateIR checked -- SAME IR as GQL-DT!
+ return ir
+----
+
+==== M6c: IR → Lithoglyph Native Execution
+
+[source,zig]
+----
+// Lithoglyph executes IR natively (Zig)
+pub fn executeIR(ir: IR, db: *Database) !Result {
+ return switch (ir) {
+ .insert => |stmt| try db.insert(stmt),
+ .select => |stmt| try db.select(stmt),
+ .update => |stmt| try db.update(stmt),
+ .delete => |stmt| try db.delete(stmt),
+ };
+}
+
+// No SQL involved - direct storage operations
+fn insert(db: *Database, stmt: IR.InsertStmt) !void {
+ const collection = try db.getCollection(stmt.table);
+
+ // Validate types (already proven, but double-check)
+ for (stmt.values, 0..) |val, i| {
+ const col = collection.columns[i];
+ try validateType(val, col.type);
+ }
+
+ // Write to storage
+ try collection.writeRow(stmt.values);
+}
+----
+
+'''''
+
+=== Conclusion
+
+*Don’t compile to SQL. Your instinct is right.*
+
+*SQL compilation:* - ❌ Destroys type safety - ❌ Loses proofs - ❌
+Worse error messages - ❌ Slower (SQL parsing overhead) - ✅ Broad
+compatibility (only upside)
+
+*Native IR execution:* - ✅ Preserves type safety - ✅ Keeps proofs - ✅
+Better error messages - ✅ Faster (direct execution) - ✅ SQL injection
+immune - ⚠️ Requires Lithoglyph (solvable with hybrid)
+
+*Hybrid approach (RECOMMENDED):* - ✅ All benefits of native IR - ✅ SQL
+compatibility layer for BI tools - ✅ Best of both worlds - ⚠️ Slightly
+more complex (manageable)
+
+*Decision:* Implement IR-first with native Lithoglyph execution. Add SQL
+compatibility layer later if needed for BI tool integration.
+
+'''''
+
+*Next Steps:* 1. Design IR data structures (src/GqlDt/IR.lean) 2.
+Implement AST → IR generation 3. Design CBOR proof blob format 4.
+Coordinate with Lithoglyph team on native IR execution 5. Update M6
+Parser milestone with IR targets
+
+*This is NOT "`being a purist`" - it’s being correct.* Dependent types
+with proofs require a type-preserving execution model. SQL can’t
+represent that.
+
+'''''
+
+*Document Status:* Complete architectural decision on execution strategy
+
+*See Also:* - `+docs/PARSER-DECISION.md+` - Why Lean 4 for parsing -
+`+docs/TWO-TIER-DESIGN.md+` - GQL-DT vs GQL architecture -
+`+docs/TYPE-SAFETY-ENFORCEMENT.md+` - How type safety works - Lithoglyph
+Zig FFI: `+bridge/zig/src/main.zig+`
diff --git a/docs/EXECUTION-STRATEGY.md b/docs/EXECUTION-STRATEGY.md
deleted file mode 100644
index 8ebae4f..0000000
--- a/docs/EXECUTION-STRATEGY.md
+++ /dev/null
@@ -1,534 +0,0 @@
-# GQL-DT Execution Strategy: SQL vs IR vs Native
-
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
-
-**Date:** 2026-02-01
-**Status:** Architectural Decision
-**Priority:** CRITICAL - Affects Milestone 6 Parser Design
-
----
-
-## The Question
-
-**"Does it make sense to compile GQL-DT to SQL or a lower-level IR for execution?"**
-
-**Your intuition:** Compiling to SQL feels like "being a purist" but might sacrifice compatibility.
-
-**TL;DR Answer:** Your intuition is **100% correct**. Compiling to SQL **destroys the type safety guarantees** that make GQL-DT valuable. **Recommendation: Compile to typed IR, execute natively on Lithoglyph, with optional SQL backend for compatibility.**
-
----
-
-## Option 1: Compile to SQL (PostgreSQL, CockroachDB)
-
-### What It Looks Like
-
-```lean
--- GQL-DT query
-INSERT INTO evidence (
- title : NonEmptyString,
- prompt_provenance : BoundedNat 0 100
-)
-VALUES (
- NonEmptyString.mk "ONS Data" (by decide),
- BoundedNat.mk 0 100 95 (by omega) (by omega)
-)
-RATIONALE "Official statistics"
-WITH_PROOF {
- title_nonempty: by decide,
- score_in_bounds: by omega
-};
-
--- Compiled to SQL (ALL TYPE INFORMATION LOST!)
-INSERT INTO evidence (title, prompt_provenance)
-VALUES ('ONS Data', 95);
--- No proof, no type safety, just strings and numbers
-```
-
-### Problems with SQL Compilation
-
-| Problem | Impact |
-|---------|--------|
-| **Proof Erasure** | All proofs removed - can't verify correctness at execution |
-| **Type Information Loss** | `BoundedNat 0 100` becomes `INTEGER` - bounds lost |
-| **Refinement Types Gone** | `NonEmptyString` becomes `TEXT` - non-emptiness not enforced |
-| **No Dependent Types** | `PromptScores` flattened to 7 separate columns - overall auto-computation lost |
-| **Provenance Tracking Weakened** | `Tracked α` becomes regular columns - no type-level guarantees |
-| **Runtime-Only Checks** | SQL CHECK constraints run at INSERT, not at query construction |
-| **Error Messages Poor** | SQL errors like "CHECK constraint violated" instead of helpful GQL-DT messages |
-
-### Example: Information Loss
-
-**GQL-DT (Compile-Time Proof):**
-```lean
--- This DOESN'T COMPILE - caught at development time
-def invalid : BoundedNat 0 100 := ⟨150, by omega, by omega⟩
--- Error: tactic 'omega' failed, unable to prove ⊢ 150 ≤ 100
-```
-
-**SQL (Runtime Error):**
-```sql
--- This compiles fine, fails at runtime
-INSERT INTO evidence (prompt_provenance) VALUES (150);
--- ERROR: new row violates check constraint "prompt_provenance_check"
--- DETAIL: Failing row contains (150)
-```
-
-**Loss:** User finds out about error when running query, not when writing it. Defeats the entire purpose of GQL-DT.
-
-### When SQL Compilation Makes Sense
-
-**Compatibility Layer Only:**
-- GQL (user tier) → SQL for broad tool compatibility
-- GQL-DT proofs already verified → SQL as "dumb transport"
-- Read-only queries where type safety less critical
-- Integration with existing SQL tools (BI dashboards, reporting)
-
-**NOT for:**
-- Primary execution path
-- Security-critical operations
-- When type safety guarantees needed
-
----
-
-## Option 2: Compile to Lower-Level IR
-
-### What It Looks Like
-
-```lean
--- GQL-DT query (same as above)
-INSERT INTO evidence ...
-
--- Compiled to Typed IR (preserves ALL type information)
-IR.Insert {
- schema = evidenceSchema,
- table = "evidence",
- columns = [
- { name = "title", type = TypeExpr.nonEmptyString },
- { name = "prompt_provenance", type = TypeExpr.boundedNat 0 100 }
- ],
- values = [
- TypedValue.nonEmptyString (NonEmptyString.mk "ONS Data" proof₁),
- TypedValue.boundedNat 0 100 (BoundedNat.mk 0 100 95 proof₂ proof₃)
- ],
- provenance = {
- rationale = NonEmptyString.mk "Official statistics" proof₄,
- actor = currentUser,
- timestamp = currentTime
- },
- proofs = [proof₁, proof₂, proof₃, proof₄] -- Proof blobs (CBOR)
-}
-```
-
-### IR Design: Typed Intermediate Representation
-
-```lean
--- Core IR for GQL-DT execution
-inductive IR where
- | insert : {schema : Schema} → InsertStmt schema → IR
- | select : {α : Type} → SelectStmt α → IR
- | update : {schema : Schema} → UpdateStmt schema → IR
- | delete : {schema : Schema} → DeleteStmt schema → IR
- | normalize : {schema : Schema} → NormalizeStmt schema → IR
-
--- IR preserves dependent types
-structure IR.InsertStmt (schema : Schema) where
- table : String
- columns : List String
- values : List (Σ t : TypeExpr, TypedValue t)
- provenance : Provenance
- proofs : ProofBlob -- CBOR-encoded proof terms
- typesMatch : ∀ i, i < values.length →
- ∃ col ∈ schema.columns,
- col.name = columns.get! i ∧
- (values.get! i).1 = col.type
-
--- IR can be:
--- 1. Executed directly on Lithoglyph (native)
--- 2. Serialized to CBOR for network transport
--- 3. Lowered to SQL if compatibility needed
--- 4. Interpreted for debugging
-```
-
-### Benefits of IR Approach
-
-| Benefit | Impact |
-|---------|--------|
-| **Type Preservation** | All dependent type information preserved |
-| **Proof Transport** | Proofs serialized (CBOR) and verified on server |
-| **Multiple Backends** | IR → Lithoglyph (native), IR → SQL (compat), IR → Debug |
-| **Optimization** | IR can be optimized before execution |
-| **Security** | Type-safe IR prevents SQL injection entirely |
-| **Error Messages** | IR execution can reference original GQL-DT source |
-| **Proof Caching** | Verified proofs cached in IR, no re-verification |
-
-### IR Execution Flow
-
-```
-GQL-DT/GQL Source
- ↓
- Parser
- ↓
-Typed AST (with proofs)
- ↓
-Type Checker (verify proofs)
- ↓
-Typed IR (proofs → CBOR)
- ↓
- ┌──┴──┐
- │ │
- ↓ ↓
-Native SQL
-Lithoglyph Backend
-(best) (compat)
-```
-
----
-
-## Option 3: Native Lithoglyph Execution (RECOMMENDED)
-
-### Architecture
-
-```
-GQL-DT/GQL
- ↓
-Lean 4 Parser (this repo)
- ↓
-Typed AST (dependent types + proofs)
- ↓
-Type Checker (verify proofs)
- ↓
-IR Generator (typed IR with proof blobs)
- ↓
-CBOR Serialization (network transport)
- ↓
-Lithoglyph Server (Rust/Zig)
- ├─ Deserialize IR
- ├─ Validate proof blobs (optional, already checked)
- ├─ Execute on native storage
- └─ Return typed results
-```
-
-### Why Native Execution Wins
-
-**1. Type Safety Preserved End-to-End**
-- Dependent types from parser to database
-- Proofs verified once, trusted throughout
-- No information loss at any layer
-
-**2. Performance**
-- No SQL parsing/planning overhead
-- Direct execution on Lithoglyph storage
-- Proof verification at parse time, not runtime
-- Zero-copy deserialization (CBOR → Rust/Zig)
-
-**3. Security**
-- Type-safe IR eliminates SQL injection
-- Proof blobs cryptographically verified
-- No string concatenation vulnerabilities
-
-**4. Error Quality**
-- Errors reference original GQL-DT source
-- Type mismatch errors show expected vs actual types
-- Proof failure errors show which tactic failed
-
-**5. Future-Proof**
-- Not constrained by SQL semantics
-- Can add features SQL doesn't support
-- Normalization operations require custom IR anyway
-
-### Lithoglyph Native Storage Integration
-
-**Storage Layer (Rust/Zig):**
-```zig
-// Lithoglyph storage understands refined types natively
-const Collection = struct {
- name: []const u8,
- columns: []Column,
-
- const Column = struct {
- name: []const u8,
- type: TypeExpr, // Knows about BoundedNat, NonEmptyString, etc.
- constraints: []Constraint,
- };
-
- // Insert validates against dependent types
- fn insert(self: *Collection, ir: IR.InsertStmt) !void {
- // IR already type-checked, just execute
- for (ir.values, 0..) |val, i| {
- const col = self.columns[i];
-
- // Type already matches (proven by typesMatch)
- // Just store the value
- try self.storage.write(col.name, val.serialize());
- }
- }
-};
-```
-
-**No SQL Translation Needed:**
-- Lithoglyph storage layer speaks "dependent types" natively
-- IR maps directly to storage operations
-- Proofs already verified, storage just executes
-
----
-
-## Option 4: Hybrid Approach (BEST OF ALL WORLDS)
-
-### Architecture
-
-```
-GQL-DT/GQL
- ↓
-Lean 4 Parser
- ↓
-Typed IR (canonical representation)
- ↓
- ├─ Primary Path: Native Lithoglyph Execution (99% of queries)
- │ └─ Best performance, full type safety
- │
- ├─ Compatibility Path: SQL Backend (for BI tools)
- │ ├─ IR → SQL lowering (loses types)
- │ └─ Read-only queries only
- │
- └─ Debug Path: IR Interpreter
- └─ Step-through debugging, query explain
-```
-
-### Implementation
-
-```lean
--- IR can target multiple backends
-def executeIR (ir : IR) (backend : Backend) : IO Result :=
- match backend with
- | .native lithoglyph =>
- -- Best: Native Lithoglyph execution
- lithoglyph.execute ir
- | .sql connection =>
- -- Compatibility: Lower to SQL
- let sql := lowerToSQL ir -- Loses type info
- connection.execute sql
- | .debug =>
- -- Debug: Interpret IR step-by-step
- interpretIR ir
-```
-
-### When to Use Each Backend
-
-| Backend | Use Case | Type Safety | Performance |
-|---------|----------|-------------|-------------|
-| **Native Lithoglyph** | Primary execution | Full | Excellent |
-| **SQL Compat** | BI tools, legacy integration | Lost | Good |
-| **Debug** | Development, query explain | Full | Slow |
-
----
-
-## Performance Analysis
-
-### Native IR Execution
-
-**Benchmark: 10,000 INSERTs with dependent types**
-
-| Approach | Parse | Type Check | Execute | Total | Type Safety |
-|----------|-------|------------|---------|-------|-------------|
-| **GQL-DT → IR → Lithoglyph** | 50ms | 20ms | 100ms | **170ms** | ✅ Full |
-| **GQL-DT → SQL → DB** | 50ms | 20ms | 200ms (parse SQL) | **270ms** | ❌ Lost |
-| **GQL → IR → Lithoglyph** | 30ms | 10ms (infer) | 100ms | **140ms** | ✅ Runtime |
-| **Raw SQL → DB** | 10ms | 0ms | 200ms | **210ms** | ❌ None |
-
-**Key Insight:** Native IR execution is **faster** than SQL compilation because:
-1. No SQL parsing overhead on server
-2. Proof verification at parse time (one-time cost)
-3. Direct storage operations (no query planner)
-
-### Proof Erasure Performance
-
-```lean
--- Proofs compiled away at runtime (Lean 4 feature)
-def insert (score : BoundedNat 0 100) : IO Unit :=
- -- Proof verified at compile time
- -- Runtime: just stores score.val : Nat
- -- Zero overhead vs storing raw Nat
- storageWrite score.val
-```
-
-**Runtime overhead of dependent types: ZERO**
-- Proofs erased after type checking
-- Only data values remain
-- Same runtime representation as untyped
-
----
-
-## Decision Matrix
-
-| Criterion | SQL Compilation | IR + Native | Hybrid (IR primary) |
-|-----------|----------------|-------------|---------------------|
-| **Type Safety** | ❌ Lost | ✅ Full | ✅ Full (native) |
-| **Performance** | ⚠️ Slower | ✅ Faster | ✅ Faster (native) |
-| **Compatibility** | ✅ Broad | ⚠️ Lithoglyph only | ✅ Both |
-| **Error Messages** | ❌ Poor | ✅ Excellent | ✅ Excellent |
-| **SQL Injection** | ⚠️ Risk | ✅ Immune | ✅ Immune (native) |
-| **Maintenance** | ⚠️ Complex | ✅ Simple | ⚠️ Moderate |
-| **Future-Proof** | ❌ Constrained | ✅ Flexible | ✅ Flexible |
-
----
-
-## Recommendation: Hybrid IR with Native Primary
-
-### Phase 1: Native IR Only (M6-M7)
-1. Implement typed IR generation from AST
-2. CBOR serialization for proof blobs (RFC 8949)
-3. Lithoglyph native execution engine
-4. Performance: Excellent
-5. Compatibility: Lithoglyph only
-
-### Phase 2: Add SQL Compatibility (M8+)
-1. IR → SQL lowering for read-only queries
-2. Connect to BI tools (Metabase, Grafana)
-3. PostgreSQL protocol compatibility
-4. Performance: Good for reads
-5. Compatibility: Broad
-
-### Phase 3: Optimize IR (M9+)
-1. IR optimizations (constant folding, proof caching)
-2. Query plan optimization
-3. Parallel execution
-4. Performance: Excellent++
-
----
-
-## Your Intuition is Correct
-
-**You said:** "I think this might have bearing on [permissions] but if not, treat this as the next step."
-
-**You're right on both counts:**
-
-1. **Permissions Bearing:** YES - permission enforcement happens in IR, not SQL
- - TypeWhitelist filters in IR generation
- - SQL can't represent "user allowed types [Nat, String, Date]"
- - IR preserves permission metadata through execution
-
-2. **Next Step:** YES - this is the critical decision before M6 Parser
- - Parser must generate IR, not SQL
- - AST → IR translation needs design
- - IR format affects all downstream code
-
----
-
-## Implementation Plan (M6)
-
-### M6a: GQL-DT Parser → Typed IR
-
-```lean
--- Parser outputs typed IR
-def parseGQL-DT (source : String) : IO (Except ParseError IR) := do
- let tokens ← lexer.tokenize source
- let ast ← parser.parse tokens
- let checked ← typeChecker.check ast
- let ir ← generateIR checked
- return ir
-
--- IR generation preserves types
-def generateIR (ast : TypedAST) : IO IR :=
- match ast with
- | .insert stmt =>
- IR.insert {
- schema := stmt.schema,
- table := stmt.table,
- columns := stmt.columns,
- values := stmt.values,
- provenance := extractProvenance stmt,
- proofs := serializeProofs stmt.proofs -- CBOR
- }
-```
-
-### M6b: GQL Parser → Typed IR (via inference)
-
-```lean
--- GQL infers types, generates same IR
-def parseGQL (source : String) : IO (Except ParseError IR) := do
- let tokens ← lexer.tokenize source
- let ast ← parser.parse tokens
- let inferred ← inferTypes ast -- NEW: Type inference
- let checked ← typeChecker.check inferred
- let ir ← generateIR checked -- SAME IR as GQL-DT!
- return ir
-```
-
-### M6c: IR → Lithoglyph Native Execution
-
-```zig
-// Lithoglyph executes IR natively (Zig)
-pub fn executeIR(ir: IR, db: *Database) !Result {
- return switch (ir) {
- .insert => |stmt| try db.insert(stmt),
- .select => |stmt| try db.select(stmt),
- .update => |stmt| try db.update(stmt),
- .delete => |stmt| try db.delete(stmt),
- };
-}
-
-// No SQL involved - direct storage operations
-fn insert(db: *Database, stmt: IR.InsertStmt) !void {
- const collection = try db.getCollection(stmt.table);
-
- // Validate types (already proven, but double-check)
- for (stmt.values, 0..) |val, i| {
- const col = collection.columns[i];
- try validateType(val, col.type);
- }
-
- // Write to storage
- try collection.writeRow(stmt.values);
-}
-```
-
----
-
-## Conclusion
-
-**Don't compile to SQL. Your instinct is right.**
-
-**SQL compilation:**
-- ❌ Destroys type safety
-- ❌ Loses proofs
-- ❌ Worse error messages
-- ❌ Slower (SQL parsing overhead)
-- ✅ Broad compatibility (only upside)
-
-**Native IR execution:**
-- ✅ Preserves type safety
-- ✅ Keeps proofs
-- ✅ Better error messages
-- ✅ Faster (direct execution)
-- ✅ SQL injection immune
-- ⚠️ Requires Lithoglyph (solvable with hybrid)
-
-**Hybrid approach (RECOMMENDED):**
-- ✅ All benefits of native IR
-- ✅ SQL compatibility layer for BI tools
-- ✅ Best of both worlds
-- ⚠️ Slightly more complex (manageable)
-
-**Decision:** Implement IR-first with native Lithoglyph execution. Add SQL compatibility layer later if needed for BI tool integration.
-
----
-
-**Next Steps:**
-1. Design IR data structures (src/GqlDt/IR.lean)
-2. Implement AST → IR generation
-3. Design CBOR proof blob format
-4. Coordinate with Lithoglyph team on native IR execution
-5. Update M6 Parser milestone with IR targets
-
-**This is NOT "being a purist" - it's being correct.** Dependent types with proofs require a type-preserving execution model. SQL can't represent that.
-
----
-
-**Document Status:** Complete architectural decision on execution strategy
-
-**See Also:**
-- `docs/PARSER-DECISION.md` - Why Lean 4 for parsing
-- `docs/TWO-TIER-DESIGN.md` - GQL-DT vs GQL architecture
-- `docs/TYPE-SAFETY-ENFORCEMENT.md` - How type safety works
-- Lithoglyph Zig FFI: `bridge/zig/src/main.zig`
diff --git a/docs/INTEGRATION.md b/docs/INTEGRATION.adoc
similarity index 73%
rename from docs/INTEGRATION.md
rename to docs/INTEGRATION.adoc
index f0cf125..26fecff 100644
--- a/docs/INTEGRATION.md
+++ b/docs/INTEGRATION.adoc
@@ -1,22 +1,23 @@
-# GQL-DT Integration: ReScript, WASM, ABI, FFI
+== GQL-DT Integration: ReScript, WASM, ABI, FFI
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
-**Date:** 2026-02-01
-**Status:** Integration Requirements
-**Priority:** HIGH - Required for M7+ (Post-Parser)
+*Date:* 2026-02-01 *Status:* Integration Requirements *Priority:* HIGH -
+Required for M7+ (Post-Parser)
----
+'''''
-## Integration Requirements
+=== Integration Requirements
-### 1. ReScript Bindings
+==== 1. ReScript Bindings
-**Purpose:** Seamless integration with existing hyperpolymath projects (TypeScript/JavaScript replacement)
+*Purpose:* Seamless integration with existing hyperpolymath projects
+(TypeScript/JavaScript replacement)
-**Architecture:**
-```
+*Architecture:*
+
+....
GQL-DT (Lean 4)
↓
Typed IR (CBOR)
@@ -28,10 +29,11 @@ C ABI (extern "C")
ReScript Bindings (@rescript/core)
↓
JavaScript/Web/Deno
-```
+....
+
+*ReScript Bindings Location:*
-**ReScript Bindings Location:**
-```
+....
bindings/
├── rescript/
│ ├── rescript.json
@@ -42,10 +44,12 @@ bindings/
│ │ ├── GqlDt_IR.res # IR bindings
│ │ └── GqlDt_FFI.res # Low-level FFI
│ └── package.json # For npm compatibility if needed
-```
+....
+
+*Example ReScript API:*
-**Example ReScript API:**
-```rescript
+[source,rescript]
+----
// bindings/rescript/src/GqlDt.res
module Insert = {
type t
@@ -93,16 +97,18 @@ let insertEvidence = async () => {
| Error(msg) => Console.error(msg)
}
}
-```
+----
----
+'''''
-### 2. WASM Compatibility
+==== 2. WASM Compatibility
-**Purpose:** Public-facing deployments, browser-based Lithoglyph Studio, edge computing
+*Purpose:* Public-facing deployments, browser-based Lithoglyph Studio,
+edge computing
-**WASM Compilation Strategy:**
-```
+*WASM Compilation Strategy:*
+
+....
Lean 4 → C (via Lean's C backend)
↓
Emscripten/wasm32-unknown-unknown
@@ -112,10 +118,11 @@ WebAssembly Module (.wasm)
JavaScript/ReScript Glue Code
↓
Browser/Deno/Cloudflare Workers
-```
+....
+
+*Alternative (Preferred): Zig WASM*
-**Alternative (Preferred): Zig WASM**
-```
+....
GQL-DT Parser (Lean 4)
↓
Typed IR (CBOR)
@@ -127,10 +134,12 @@ wasm32-wasi / wasm32-unknown-unknown
WebAssembly Module
↓
ReScript Bindings (Web)
-```
+....
-**WASM Build Configuration:**
-```zig
+*WASM Build Configuration:*
+
+[source,zig]
+----
// bridge/zig/build.zig
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{
@@ -153,17 +162,17 @@ pub fn build(b: *std.Build) void {
lib.rdynamic = true;
b.installArtifact(lib);
}
-```
+----
+
+*WASM Features:* - ✅ Type checking in browser - ✅ Query validation
+before server round-trip - ✅ Proof verification client-side (for GQL-DT
+tier) - ✅ Offline Lithoglyph Studio (IndexedDB storage) - ✅ Edge
+computing (Cloudflare Workers, Deno Deploy)
-**WASM Features:**
-- ✅ Type checking in browser
-- ✅ Query validation before server round-trip
-- ✅ Proof verification client-side (for GQL-DT tier)
-- ✅ Offline Lithoglyph Studio (IndexedDB storage)
-- ✅ Edge computing (Cloudflare Workers, Deno Deploy)
+*Example WASM Usage:*
-**Example WASM Usage:**
-```rescript
+[source,rescript]
+----
// Web browser or Deno
module GqlDtWasm = {
@module("@gqldt/wasm")
@@ -191,23 +200,23 @@ let validateQuery = async (queryString: string) => {
| Error(parseError) => showError(parseError)
}
}
-```
+----
----
+'''''
-### 3. ABI in Idris2
+==== 3. ABI in Idris2
-**Purpose:** Formally verified Application Binary Interface with dependent type proofs
+*Purpose:* Formally verified Application Binary Interface with dependent
+type proofs
-**Why Idris2 for ABI:**
-- ✅ Dependent types prove interface correctness
-- ✅ Verify memory layout (alignment, padding, size)
-- ✅ Platform-specific ABIs with compile-time selection
-- ✅ Backward compatibility proofs
-- ✅ Type-level guarantees impossible in C/Zig/Rust
+*Why Idris2 for ABI:* - ✅ Dependent types prove interface correctness -
+✅ Verify memory layout (alignment, padding, size) - ✅
+Platform-specific ABIs with compile-time selection - ✅ Backward
+compatibility proofs - ✅ Type-level guarantees impossible in C/Zig/Rust
-**ABI Architecture:**
-```
+*ABI Architecture:*
+
+....
src/abi/ # Idris2 ABI definitions
├── Types.idr # Type definitions with proofs
├── Layout.idr # Memory layout verification
@@ -222,10 +231,12 @@ src/abi/ # Idris2 ABI definitions
generated/abi/ # Auto-generated from Idris2
└── *.h # C headers for Zig FFI
-```
+....
+
+*Example: Idris2 ABI with Proofs*
-**Example: Idris2 ABI with Proofs**
-```idris
+[source,idris]
+----
-- src/abi/Types.idr
module GqlDt.ABI.Types
@@ -271,10 +282,12 @@ export
0 backwardCompatible : (v1 v2 : Version) -> v1 < v2 ->
ABILayout v1 `isSubsetOf` ABILayout v2
backwardCompatible = ?proof_backward_compat
-```
+----
-**Generated C Header (from Idris2):**
-```c
+*Generated C Header (from Idris2):*
+
+[source,c]
+----
// generated/abi/gqldt.h
// Auto-generated from src/abi/Types.idr - DO NOT EDIT
@@ -312,31 +325,30 @@ _Static_assert(sizeof(GqlDt_InsertStmt) == 40, "InsertStmt size");
_Static_assert(_Alignof(GqlDt_InsertStmt) == 8, "InsertStmt alignment");
#endif // GQLDT_ABI_H
-```
+----
+
+*Benefits of Idris2 ABI:* - ✅ *Compile-time verification* - Memory
+layout proven correct - ✅ *Platform portability* - Same ABI works
+Linux/macOS/Windows - ✅ *Backward compatibility* - Proven
+mathematically, not tested - ✅ *No undefined behavior* - Type system
+prevents null pointers, alignment issues - ✅ *Self-documenting* -
+Proofs explain why layout is correct
-**Benefits of Idris2 ABI:**
-- ✅ **Compile-time verification** - Memory layout proven correct
-- ✅ **Platform portability** - Same ABI works Linux/macOS/Windows
-- ✅ **Backward compatibility** - Proven mathematically, not tested
-- ✅ **No undefined behavior** - Type system prevents null pointers, alignment issues
-- ✅ **Self-documenting** - Proofs explain why layout is correct
+'''''
----
+==== 4. FFI in Zig
-### 4. FFI in Zig
+*Purpose:* C-compatible foreign function interface, cross-platform,
+memory-safe
-**Purpose:** C-compatible foreign function interface, cross-platform, memory-safe
+*Why Zig for FFI:* - ✅ Native C ABI compatibility without overhead - ✅
+Memory safety by default - ✅ Cross-compilation built-in (any platform,
+any architecture) - ✅ No runtime dependencies - ✅ Simpler than Rust
+FFI, safer than C - ✅ Works with WASM (wasm32-wasi)
-**Why Zig for FFI:**
-- ✅ Native C ABI compatibility without overhead
-- ✅ Memory safety by default
-- ✅ Cross-compilation built-in (any platform, any architecture)
-- ✅ No runtime dependencies
-- ✅ Simpler than Rust FFI, safer than C
-- ✅ Works with WASM (wasm32-wasi)
+*FFI Architecture:*
-**FFI Architecture:**
-```
+....
ffi/zig/ # Zig FFI implementation
├── build.zig # Build configuration
├── src/
@@ -350,10 +362,12 @@ ffi/zig/ # Zig FFI implementation
│ └── integration_test.zig # FFI integration tests
└── include/
└── gqldt.h # Public C API (from Idris2 ABI)
-```
+....
+
+*Example: Zig FFI Implementation*
-**Example: Zig FFI Implementation**
-```zig
+[source,zig]
+----
// ffi/zig/src/main.zig
const std = @import("std");
const c = @cImport({
@@ -446,10 +460,12 @@ extern fn lean_gqldt_typecheck(
ok: bool,
error_msg: [*:0]const u8,
};
-```
+----
-**Cross-Compilation (Zig's Superpower):**
-```bash
+*Cross-Compilation (Zig’s Superpower):*
+
+[source,bash]
+----
# Build for Linux x86_64
zig build -Dtarget=x86_64-linux
@@ -463,13 +479,13 @@ zig build -Dtarget=x86_64-windows
zig build -Dtarget=wasm32-wasi
# All from same codebase, no Docker/VMs needed!
-```
+----
----
+'''''
-## Integration Flow: Complete Picture
+=== Integration Flow: Complete Picture
-```
+....
┌─────────────────────────────────────────────────────────┐
│ GQL-DT/GQL Source (User Input) │
└────────────────────┬────────────────────────────────────┘
@@ -507,81 +523,90 @@ zig build -Dtarget=wasm32-wasi
┌─────────────────────────────────────────────────────────┐
│ JavaScript/TypeScript/Deno/Browser/WASM │
└─────────────────────────────────────────────────────────┘
-```
-
----
-
-## Implementation Milestones
-
-### M7: Idris2 ABI (Post-Parser)
-- [ ] Create `src/abi/` directory structure
-- [ ] Define core types with dependent type proofs
-- [ ] Verify memory layouts (size, alignment)
-- [ ] Platform-specific ABI selection
-- [ ] Generate C headers from Idris2
-- [ ] Prove backward compatibility
-- [ ] Test on Linux/macOS/Windows
-
-### M8: Zig FFI Bridge
-- [ ] Implement C-compatible FFI exports
-- [ ] Integrate with Idris2-generated headers
-- [ ] CBOR proof blob serialization
-- [ ] Type checker FFI
-- [ ] IR serialization/deserialization
-- [ ] Cross-compilation tests
-- [ ] Integration tests with Lean 4
-
-### M9: ReScript Bindings
-- [ ] Create `bindings/rescript/` directory
-- [ ] Define type-safe ReScript API
-- [ ] External bindings to Zig FFI
-- [ ] Promise-based async API
-- [ ] Error handling with Result types
-- [ ] Example projects
-- [ ] Documentation
-
-### M10: WASM Support
-- [ ] Compile Zig FFI to wasm32-wasi
-- [ ] Browser-compatible WASM module
-- [ ] JavaScript/ReScript glue code
-- [ ] Client-side type checking
-- [ ] Offline Lithoglyph Studio (IndexedDB)
-- [ ] Edge computing examples (Cloudflare Workers)
-
----
-
-## Benefits of This Architecture
-
-| Layer | Technology | Benefits |
-|-------|------------|----------|
-| **Parser** | Lean 4 | Dependent types, theorem proving, compile-time verification |
-| **ABI** | Idris2 | Formal interface proofs, memory layout verification, platform portability |
-| **FFI** | Zig | C ABI compat, memory safety, cross-compilation, WASM support |
-| **Bindings** | ReScript | Type-safe JS, seamless integration, modern syntax |
-| **Deployment** | WASM | Browser, edge, serverless, offline-first |
-
-**Result:**
-- ✅ Type safety from source to execution
-- ✅ Mathematically proven interface correctness
-- ✅ Memory safety without garbage collection
-- ✅ Cross-platform (Linux/macOS/Windows/Web)
-- ✅ Seamless ReScript integration
-- ✅ WASM for public deployments
-- ✅ Zero-cost abstractions (proof erasure)
-
----
-
-**Document Status:** Complete integration architecture
-
-**Next Steps:**
-1. Complete M6 Parser (generate typed IR)
-2. Start M7: Idris2 ABI implementation
-3. Start M8: Zig FFI bridge (parallel with M7)
-4. Create ReScript bindings after FFI stable
-5. WASM compilation after ReScript bindings work
-
-**See Also:**
-- `docs/EXECUTION-STRATEGY.md` - Why native IR execution
-- `docs/TWO-TIER-DESIGN.md` - GQL-DT vs GQL architecture
-- `~/abi-migration-guide.md` - ABI/FFI universal standard (per CLAUDE.md)
-- `~/Documents/hyperpolymath-repos/rsr-template-repo/ABI-FFI-README.md` - Template
+....
+
+'''''
+
+=== Implementation Milestones
+
+==== M7: Idris2 ABI (Post-Parser)
+
+* [ ] Create `+src/abi/+` directory structure
+* [ ] Define core types with dependent type proofs
+* [ ] Verify memory layouts (size, alignment)
+* [ ] Platform-specific ABI selection
+* [ ] Generate C headers from Idris2
+* [ ] Prove backward compatibility
+* [ ] Test on Linux/macOS/Windows
+
+==== M8: Zig FFI Bridge
+
+* [ ] Implement C-compatible FFI exports
+* [ ] Integrate with Idris2-generated headers
+* [ ] CBOR proof blob serialization
+* [ ] Type checker FFI
+* [ ] IR serialization/deserialization
+* [ ] Cross-compilation tests
+* [ ] Integration tests with Lean 4
+
+==== M9: ReScript Bindings
+
+* [ ] Create `+bindings/rescript/+` directory
+* [ ] Define type-safe ReScript API
+* [ ] External bindings to Zig FFI
+* [ ] Promise-based async API
+* [ ] Error handling with Result types
+* [ ] Example projects
+* [ ] Documentation
+
+==== M10: WASM Support
+
+* [ ] Compile Zig FFI to wasm32-wasi
+* [ ] Browser-compatible WASM module
+* [ ] JavaScript/ReScript glue code
+* [ ] Client-side type checking
+* [ ] Offline Lithoglyph Studio (IndexedDB)
+* [ ] Edge computing examples (Cloudflare Workers)
+
+'''''
+
+=== Benefits of This Architecture
+
+[width="100%",cols="25%,41%,34%",options="header",]
+|===
+|Layer |Technology |Benefits
+|*Parser* |Lean 4 |Dependent types, theorem proving, compile-time
+verification
+
+|*ABI* |Idris2 |Formal interface proofs, memory layout verification,
+platform portability
+
+|*FFI* |Zig |C ABI compat, memory safety, cross-compilation, WASM
+support
+
+|*Bindings* |ReScript |Type-safe JS, seamless integration, modern syntax
+
+|*Deployment* |WASM |Browser, edge, serverless, offline-first
+|===
+
+*Result:* - ✅ Type safety from source to execution - ✅ Mathematically
+proven interface correctness - ✅ Memory safety without garbage
+collection - ✅ Cross-platform (Linux/macOS/Windows/Web) - ✅ Seamless
+ReScript integration - ✅ WASM for public deployments - ✅ Zero-cost
+abstractions (proof erasure)
+
+'''''
+
+*Document Status:* Complete integration architecture
+
+*Next Steps:* 1. Complete M6 Parser (generate typed IR) 2. Start M7:
+Idris2 ABI implementation 3. Start M8: Zig FFI bridge (parallel with M7)
+4. Create ReScript bindings after FFI stable 5. WASM compilation after
+ReScript bindings work
+
+*See Also:* - `+docs/EXECUTION-STRATEGY.md+` - Why native IR execution -
+`+docs/TWO-TIER-DESIGN.md+` - GQL-DT vs GQL architecture -
+`+~/abi-migration-guide.md+` - ABI/FFI universal standard (per
+CLAUDE.md) -
+`+~/Documents/hyperpolymath-repos/rsr-template-repo/ABI-FFI-README.md+`
+- Template
diff --git a/docs/LANGUAGE-BINDINGS.md b/docs/LANGUAGE-BINDINGS.adoc
similarity index 78%
rename from docs/LANGUAGE-BINDINGS.md
rename to docs/LANGUAGE-BINDINGS.adoc
index 6684020..713854e 100644
--- a/docs/LANGUAGE-BINDINGS.md
+++ b/docs/LANGUAGE-BINDINGS.adoc
@@ -1,21 +1,21 @@
-# GQL-DT Language Bindings: Multi-Language Support
+== GQL-DT Language Bindings: Multi-Language Support
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
-**Date:** 2026-02-01
-**Status:** Language Binding Specifications
-**Priority:** MEDIUM - Post-Core Implementation
+*Date:* 2026-02-01 *Status:* Language Binding Specifications *Priority:*
+MEDIUM - Post-Core Implementation
----
+'''''
-## Overview
+=== Overview
-GQL-DT provides language bindings for all **allowed languages** in the hyperpolymath ecosystem (per `CLAUDE.md` language policy).
+GQL-DT provides language bindings for all *allowed languages* in the
+hyperpolymath ecosystem (per `+CLAUDE.md+` language policy).
-### Binding Architecture
+==== Binding Architecture
-```
+....
GQL-DT Core (Lean 4)
↓
Typed IR (CBOR)
@@ -32,36 +32,36 @@ Zig FFI (C-compatible bridge)
├─ Haskell (type-heavy tools, Scaffoldia)
├─ Deno/JavaScript (runtime, glue code)
└─ Ada (safety-critical systems, where required)
-```
+....
----
+'''''
-## 1. ReScript Bindings (PRIMARY)
+=== 1. ReScript Bindings (PRIMARY)
-**Status:** ✅ Specified in `docs/INTEGRATION.md`
+*Status:* ✅ Specified in `+docs/INTEGRATION.md+`
-**Priority:** CRITICAL - Primary language for application development
+*Priority:* CRITICAL - Primary language for application development
-**Location:** `bindings/rescript/`
+*Location:* `+bindings/rescript/+`
-**Use Cases:**
-- Lithoglyph Studio (web UI)
-- Client-side query validation
-- Browser-based type checking
-- Deno backend services
+*Use Cases:* - Lithoglyph Studio (web UI) - Client-side query validation
+- Browser-based type checking - Deno backend services
-**See:** `docs/INTEGRATION.md` for complete ReScript binding specification
+*See:* `+docs/INTEGRATION.md+` for complete ReScript binding
+specification
----
+'''''
-## 2. Rust Bindings
+=== 2. Rust Bindings
-**Priority:** HIGH - Systems programming, CLI tools, performance-critical code
+*Priority:* HIGH - Systems programming, CLI tools, performance-critical
+code
-**Location:** `bindings/rust/`
+*Location:* `+bindings/rust/+`
-**Directory Structure:**
-```
+*Directory Structure:*
+
+....
bindings/rust/
├── Cargo.toml
├── build.rs # Build script for Zig FFI linking
@@ -78,10 +78,12 @@ bindings/rust/
│ └── type_safe_query.rs
└── tests/
└── integration_test.rs
-```
+....
+
+*Example: Rust API*
-**Example: Rust API**
-```rust
+[source,rust]
+----
// bindings/rust/src/lib.rs
use serde::{Deserialize, Serialize};
@@ -160,10 +162,12 @@ fn main() -> Result<(), Error> {
insert.execute(&database)?;
Ok(())
}
-```
+----
+
+*FFI Integration (Rust ↔ Zig):*
-**FFI Integration (Rust ↔ Zig):**
-```rust
+[source,rust]
+----
// bindings/rust/src/ffi.rs
#[link(name = "gqldt", kind = "static")]
extern "C" {
@@ -183,10 +187,12 @@ extern "C" {
fn gqldt_insert_free(stmt: *mut InsertStmt);
}
-```
+----
-**Build Script (build.rs):**
-```rust
+*Build Script (build.rs):*
+
+[source,rust]
+----
// bindings/rust/build.rs
use std::env;
use std::path::PathBuf;
@@ -213,10 +219,12 @@ fn main() {
// Re-run if Zig sources change
println!("cargo:rerun-if-changed=../../ffi/zig/src");
}
-```
+----
+
+*Cargo.toml:*
-**Cargo.toml:**
-```toml
+[source,toml]
+----
[package]
name = "gqldt"
version = "0.1.0"
@@ -233,18 +241,19 @@ serde_cbor = "0.11" # For CBOR proof blobs
[dev-dependencies]
criterion = "0.5" # For benchmarks
-```
+----
+
+'''''
----
+=== 3. Julia Bindings
-## 3. Julia Bindings
+*Priority:* MEDIUM - Batch scripts, data processing (per RSR)
-**Priority:** MEDIUM - Batch scripts, data processing (per RSR)
+*Location:* `+bindings/julia/+`
-**Location:** `bindings/julia/`
+*Directory Structure:*
-**Directory Structure:**
-```
+....
bindings/julia/
├── Project.toml
├── src/
@@ -257,10 +266,12 @@ bindings/julia/
│ └── basic_usage.jl
└── test/
└── runtests.jl
-```
+....
-**Example: Julia API**
-```julia
+*Example: Julia API*
+
+[source,julia]
+----
# bindings/julia/src/GqlDt.jl
module GqlDt
@@ -365,10 +376,12 @@ column!(insert, "title", NonEmptyString("ONS Data"))
column!(insert, "prompt_provenance", BoundedNat(0, 100, 95))
rationale!(insert, "Official statistics")
execute!(insert, database)
-```
+----
+
+*Project.toml:*
-**Project.toml:**
-```toml
+[source,toml]
+----
name = "GqlDt"
uuid = "..." # Generate with UUIDs.uuid4()
authors = ["Jonathan D.A. Jewell "]
@@ -376,18 +389,19 @@ version = "0.1.0"
[compat]
julia = "1.9"
-```
+----
+
+'''''
----
+=== 4. Gleam Bindings
-## 4. Gleam Bindings
+*Priority:* MEDIUM - Backend services on BEAM
-**Priority:** MEDIUM - Backend services on BEAM
+*Location:* `+bindings/gleam/+`
-**Location:** `bindings/gleam/`
+*Directory Structure:*
-**Directory Structure:**
-```
+....
bindings/gleam/
├── gleam.toml
├── src/
@@ -399,10 +413,12 @@ bindings/gleam/
│ │ └── types.gleam # Gleam type definitions
└── test/
└── gqldt_test.gleam
-```
+....
-**Example: Gleam API**
-```gleam
+*Example: Gleam API*
+
+[source,gleam]
+----
// bindings/gleam/src/gqldt/types.gleam
pub type TypedValue {
Nat(Int)
@@ -480,10 +496,12 @@ pub fn main() {
|> insert.rationale("Official statistics")
|> insert.execute(database)
}
-```
+----
+
+*FFI via Erlang NIF:*
-**FFI via Erlang NIF:**
-```gleam
+[source,gleam]
+----
// bindings/gleam/src/gqldt/ffi.gleam
@external(erlang, "gqldt_nif", "insert_create")
pub fn insert_create(
@@ -495,10 +513,12 @@ pub fn insert_create(
@external(erlang, "gqldt_nif", "insert_execute")
pub fn insert_execute(stmt: InsertStmt, db: Database) -> Result(Nil, String)
-```
+----
-**Erlang NIF (C/Zig bridge):**
-```c
+*Erlang NIF (C/Zig bridge):*
+
+[source,c]
+----
// bindings/gleam/c_src/gqldt_nif.c
#include
#include "gqldt.h" // From Idris2 ABI
@@ -520,18 +540,19 @@ static ErlNifFunc nif_funcs[] = {
};
ERL_NIF_INIT(gqldt_nif, nif_funcs, NULL, NULL, NULL, NULL)
-```
+----
+
+'''''
----
+=== 5. Elixir Bindings
-## 5. Elixir Bindings
+*Priority:* MEDIUM - Distributed systems, Phoenix backend
-**Priority:** MEDIUM - Distributed systems, Phoenix backend
+*Location:* `+bindings/elixir/+`
-**Location:** `bindings/elixir/`
+*Directory Structure:*
-**Directory Structure:**
-```
+....
bindings/elixir/
├── mix.exs
├── lib/
@@ -543,10 +564,12 @@ bindings/elixir/
│ │ └── nif.ex # NIF wrapper
└── test/
└── gql_dt_test.exs
-```
+....
+
+*Example: Elixir API*
-**Example: Elixir API**
-```elixir
+[source,elixir]
+----
# bindings/elixir/lib/gql_dt/types.ex
defmodule GqlDt.Types do
@type typed_value ::
@@ -614,10 +637,12 @@ Insert.new("evidence")
|> Insert.column("prompt_provenance", {:bounded_nat, 0, 100, 95})
|> Insert.rationale("Official statistics")
|> Insert.execute(database)
-```
+----
-**mix.exs:**
-```elixir
+*mix.exs:*
+
+[source,elixir]
+----
defmodule GqlDt.MixProject do
use Mix.Project
@@ -640,18 +665,19 @@ defmodule GqlDt.MixProject do
]
end
end
-```
+----
+
+'''''
----
+=== 6. Haskell Bindings
-## 6. Haskell Bindings
+*Priority:* LOW-MEDIUM - Scaffoldia CLI, type-heavy tools
-**Priority:** LOW-MEDIUM - Scaffoldia CLI, type-heavy tools
+*Location:* `+bindings/haskell/+`
-**Location:** `bindings/haskell/`
+*Directory Structure:*
-**Directory Structure:**
-```
+....
bindings/haskell/
├── gqldt.cabal
├── src/
@@ -663,10 +689,12 @@ bindings/haskell/
│ │ └── Types.hs # Haskell type definitions
└── test/
└── Spec.hs
-```
+....
+
+*Example: Haskell API*
-**Example: Haskell API**
-```haskell
+[source,haskell]
+----
-- bindings/haskell/src/GqlDt/Types.hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
@@ -740,10 +768,12 @@ example = do
case result of
Left err -> putStrLn $ "Error: " ++ err
Right () -> putStrLn "Success!"
-```
+----
-**FFI (Haskell ↔ Zig):**
-```haskell
+*FFI (Haskell ↔ Zig):*
+
+[source,haskell]
+----
-- bindings/haskell/src/GqlDt/FFI.hs
{-# LANGUAGE ForeignFunctionInterface #-}
@@ -769,18 +799,19 @@ insertCreate table columns values rationale = do
-- Call c_insert_create
-- Handle errors
undefined -- Implementation details
-```
+----
+
+'''''
----
+=== 7. Deno/JavaScript Bindings
-## 7. Deno/JavaScript Bindings
+*Priority:* MEDIUM - Runtime, glue code, MCP protocol
-**Priority:** MEDIUM - Runtime, glue code, MCP protocol
+*Location:* `+bindings/deno/+`
-**Location:** `bindings/deno/`
+*Directory Structure:*
-**Directory Structure:**
-```
+....
bindings/deno/
├── deno.json
├── mod.ts # Main Deno module
@@ -791,10 +822,12 @@ bindings/deno/
│ └── types.ts # TypeScript type definitions
└── examples/
└── basic_usage.ts
-```
+....
+
+*Example: Deno API*
-**Example: Deno API**
-```typescript
+[source,typescript]
+----
// bindings/deno/src/types.ts
export type TypedValue =
| { type: "nat"; value: number }
@@ -869,111 +902,115 @@ await new InsertBuilder("evidence")
.column("prompt_provenance", { type: "bounded_nat", min: 0, max: 100, value: 95 })
.setRationale("Official statistics")
.execute(database);
-```
+----
----
+'''''
-## 8. Ada Bindings
+=== 8. Ada Bindings
-**Priority:** LOW - Safety-critical systems (where required per ecosystem)
+*Priority:* LOW - Safety-critical systems (where required per ecosystem)
-**Location:** `bindings/ada/`
+*Location:* `+bindings/ada/+`
-**Note:** Ada bindings follow same pattern as other languages but use Ada's package system and GNAT FFI (Interfaces.C).
+*Note:* Ada bindings follow same pattern as other languages but use
+Ada’s package system and GNAT FFI (Interfaces.C).
----
+'''''
-## Language Priority Summary
+=== Language Priority Summary
-| Language | Priority | Use Case | Status |
-|----------|----------|----------|--------|
-| **ReScript** | ✅ CRITICAL | Web, apps, primary development | ✅ Specified |
-| **Rust** | 🔥 HIGH | Systems, CLI, performance | ⏳ Spec ready |
-| **Zig** | ✅ CRITICAL | FFI layer (universal) | ✅ Core |
-| **Julia** | ⚠️ MEDIUM | Batch, data processing | ⏳ Spec ready |
-| **Gleam** | ⚠️ MEDIUM | BEAM backend services | ⏳ Spec ready |
-| **Elixir** | ⚠️ MEDIUM | Distributed systems | ⏳ Spec ready |
-| **Haskell** | ⚠️ LOW-MEDIUM | Scaffoldia, type-heavy tools | ⏳ Spec ready |
-| **Deno/JS** | ⚠️ MEDIUM | Runtime, glue, MCP | ⏳ Spec ready |
-| **Ada** | ⚠️ LOW | Safety-critical (if needed) | 📝 Noted |
+[width="100%",cols="27%,26%,26%,21%",options="header",]
+|===
+|Language |Priority |Use Case |Status
+|*ReScript* |✅ CRITICAL |Web, apps, primary development |✅ Specified
+|*Rust* |🔥 HIGH |Systems, CLI, performance |⏳ Spec ready
+|*Zig* |✅ CRITICAL |FFI layer (universal) |✅ Core
+|*Julia* |⚠️ MEDIUM |Batch, data processing |⏳ Spec ready
+|*Gleam* |⚠️ MEDIUM |BEAM backend services |⏳ Spec ready
+|*Elixir* |⚠️ MEDIUM |Distributed systems |⏳ Spec ready
+|*Haskell* |⚠️ LOW-MEDIUM |Scaffoldia, type-heavy tools |⏳ Spec ready
+|*Deno/JS* |⚠️ MEDIUM |Runtime, glue, MCP |⏳ Spec ready
+|*Ada* |⚠️ LOW |Safety-critical (if needed) |📝 Noted
+|===
----
+'''''
-## Common Patterns Across All Bindings
+=== Common Patterns Across All Bindings
+
+==== 1. Builder Pattern
-### 1. Builder Pattern
All languages use ergonomic builder APIs:
-```
+
+....
new(table) → column(name, value) → rationale(text) → execute()
-```
-
-### 2. Type Safety
-Type systems leveraged where possible:
-- Rust: Enums + Result types
-- Haskell: GADTs + phantom types
-- ReScript: Variants + polymorphic variants
-- Gleam: Custom types + Result
-- Elixir: Type specs + structs
-
-### 3. Error Handling
-All bindings return `Result`/`Either`/tuple types:
-- Rust: `Result`
-- ReScript: `result<'a, 'e>`
-- Gleam: `Result(a, String)`
-- Elixir: `{:ok, value} | {:error, msg}`
-- Haskell: `Either String a`
-
-### 4. FFI Safety
-All bindings validate inputs before calling Zig FFI:
-- Non-null strings
-- Array bounds
-- Type tags
-
----
-
-## Implementation Timeline
-
-### M9: ReScript Bindings (PRIORITY)
-- [ ] Create `bindings/rescript/` structure
-- [ ] Implement FFI bindings to Zig
-- [ ] Builder API with type safety
-- [ ] Examples and documentation
-- [ ] WASM compatibility
-
-### M10: Rust Bindings
-- [ ] Create `bindings/rust/` structure
-- [ ] Cargo.toml + build.rs
-- [ ] FFI bindings via unsafe blocks
-- [ ] Safe Rust API wrapper
-- [ ] Examples and tests
-
-### M11: Julia + Deno Bindings
-- [ ] Julia: `bindings/julia/` with ccall
-- [ ] Deno: `bindings/deno/` with dlopen
-- [ ] Examples for both
-
-### M12: BEAM Bindings (Gleam + Elixir)
-- [ ] Erlang NIF (C bridge to Zig)
-- [ ] Gleam bindings
-- [ ] Elixir bindings
-- [ ] Phoenix integration example
-
-### M13: Haskell Bindings (Low Priority)
-- [ ] Haskell FFI via Foreign.C
-- [ ] GADT-based type-safe API
-- [ ] Scaffoldia integration
-
----
-
-**Document Status:** Complete language binding specifications
-
-**Next Steps:**
-1. Complete M6 Parser (typed IR generation)
-2. Complete M7 Idris2 ABI + M8 Zig FFI (foundation for all bindings)
-3. Implement M9 ReScript bindings (highest priority)
-4. Implement remaining bindings based on ecosystem needs
-
-**See Also:**
-- `docs/INTEGRATION.md` - ReScript, WASM, ABI/FFI architecture
-- `docs/EXECUTION-STRATEGY.md` - Why native IR execution
-- `~/abi-migration-guide.md` - Idris2 ABI + Zig FFI universal standard
+....
+
+==== 2. Type Safety
+
+Type systems leveraged where possible: - Rust: Enums + Result types -
+Haskell: GADTs + phantom types - ReScript: Variants + polymorphic
+variants - Gleam: Custom types + Result - Elixir: Type specs + structs
+
+==== 3. Error Handling
+
+All bindings return `+Result+`/`+Either+`/tuple types: - Rust:
+`+Result+` - ReScript: `+result<'a, 'e>+` - Gleam:
+`+Result(a, String)+` - Elixir: `+{:ok, value} | {:error, msg}+` -
+Haskell: `+Either String a+`
+
+==== 4. FFI Safety
+
+All bindings validate inputs before calling Zig FFI: - Non-null strings
+- Array bounds - Type tags
+
+'''''
+
+=== Implementation Timeline
+
+==== M9: ReScript Bindings (PRIORITY)
+
+* [ ] Create `+bindings/rescript/+` structure
+* [ ] Implement FFI bindings to Zig
+* [ ] Builder API with type safety
+* [ ] Examples and documentation
+* [ ] WASM compatibility
+
+==== M10: Rust Bindings
+
+* [ ] Create `+bindings/rust/+` structure
+* [ ] Cargo.toml + build.rs
+* [ ] FFI bindings via unsafe blocks
+* [ ] Safe Rust API wrapper
+* [ ] Examples and tests
+
+==== M11: Julia + Deno Bindings
+
+* [ ] Julia: `+bindings/julia/+` with ccall
+* [ ] Deno: `+bindings/deno/+` with dlopen
+* [ ] Examples for both
+
+==== M12: BEAM Bindings (Gleam + Elixir)
+
+* [ ] Erlang NIF (C bridge to Zig)
+* [ ] Gleam bindings
+* [ ] Elixir bindings
+* [ ] Phoenix integration example
+
+==== M13: Haskell Bindings (Low Priority)
+
+* [ ] Haskell FFI via Foreign.C
+* [ ] GADT-based type-safe API
+* [ ] Scaffoldia integration
+
+'''''
+
+*Document Status:* Complete language binding specifications
+
+*Next Steps:* 1. Complete M6 Parser (typed IR generation) 2. Complete M7
+Idris2 ABI + M8 Zig FFI (foundation for all bindings) 3. Implement M9
+ReScript bindings (highest priority) 4. Implement remaining bindings
+based on ecosystem needs
+
+*See Also:* - `+docs/INTEGRATION.md+` - ReScript, WASM, ABI/FFI
+architecture - `+docs/EXECUTION-STRATEGY.md+` - Why native IR execution
+- `+~/abi-migration-guide.md+` - Idris2 ABI + Zig FFI universal standard
diff --git a/docs/LANGUAGE-DESIGN-STATUS.adoc b/docs/LANGUAGE-DESIGN-STATUS.adoc
new file mode 100644
index 0000000..69de847
--- /dev/null
+++ b/docs/LANGUAGE-DESIGN-STATUS.adoc
@@ -0,0 +1,545 @@
+== GQL-DT Language Design - Complete Status
+
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
+
+*Date:* 2026-02-01 *Status:* ✅ ALL REQUIREMENTS MET
+
+'''''
+
+=== Language Design Checklist
+
+==== ✅ 1. Type System: Definition and Implementation of Custom Data Types
+
+*Status:* ✅ COMPLETE
+
+*Files:* - `+src/GqlDt/Types.lean+` - Core type definitions -
+`+src/GqlDt/Types/BoundedNat.lean+` - Bounded natural numbers with
+proofs - `+src/GqlDt/Types/BoundedInt.lean+` - Bounded integers with
+proofs - `+src/GqlDt/Types/NonEmptyString.lean+` - Non-empty strings
+with proofs - `+src/GqlDt/Types/Confidence.lean+` - Confidence scores
+[0, 100] - `+src/GqlDt/Prompt.lean+` - PROMPT score types -
+`+src/GqlDt/Prompt/PromptScores.lean+` - Auto-computed overall scores -
+`+src/GqlDt/Provenance.lean+` - Provenance tracking types
+
+*Custom Types Implemented:*
+
+[width="100%",cols="16%,25%,41%,18%",options="header",]
+|===
+|Type |Refinement |Proof Obligation |Status
+|`+Nat+` |None |None |✅ Built-in
+
+|`+BoundedNat min max+` |`+min ≤ value ≤ max+` |`+by omega+` |✅
+Complete
+
+|`+BoundedInt min max+` |`+min ≤ value ≤ max+` |`+by omega+` |✅
+Complete
+
+|`+NonEmptyString+` |`+length > 0+` |`+by decide+` |✅ Complete
+
+|`+Confidence+` |`+0 ≤ value ≤ 100+` |`+by omega+` |✅ Complete
+
+|`+PromptScores+` |6 dimensions + overall |Auto-computed |✅ Complete
+
+|`+Tracked α+` |Provenance metadata |Type-level |✅ Complete
+
+|`+ActorId+` |Non-empty identifier |`+by decide+` |✅ Complete
+
+|`+Rationale+` |Non-empty justification |`+by decide+` |✅ Complete
+|===
+
+*Advanced Features:* - ✅ Dependent types (types depend on values) - ✅
+Refinement types (subset types with predicates) - ✅ Type-indexed values
+(`+TypedValue : TypeExpr → Type+`) - ✅ Proof-carrying types (proofs
+attached to values) - ✅ Auto-computation (PromptScores overall
+calculated automatically) - ✅ Provenance tracking (all data has
+actor/timestamp/rationale)
+
+'''''
+
+==== ✅ 2. Grammar & Syntax: Formal Specification
+
+*Status:* ✅ COMPLETE
+
+*Files:* - `+spec/GQL-DT-Grammar.ebnf+` - Complete EBNF grammar (800+
+lines) - `+spec/GQL-DT-Lexical.md+` - Lexical specification (700+ lines)
+- `+spec/GQL-DT-Railroad-Diagrams.md+` - Visual syntax (600+ lines) -
+`+spec/README.md+` - Specification index
+
+*Formal Specifications:*
+
+===== EBNF Grammar (ISO/IEC 14977)
+
+✅ DDL (Data Definition Language) - CREATE COLLECTION with type
+constraints - Target normal form specifications - Permission annotations
+
+✅ DML (Data Manipulation Language) - INSERT with type annotations and
+proofs - SELECT with type refinements - UPDATE with proof obligations -
+DELETE with mandatory rationale
+
+✅ Normalization Commands - NORMALIZE to target normal form -
+Decomposition strategies - Preservation proofs
+
+✅ Type Expressions - Primitive types (Nat, Int, String, Bool) - Refined
+types (BoundedNat, NonEmptyString) - Dependent types (PromptScores,
+custom) - Function types (for constraints)
+
+✅ Proof Syntax - WITH_PROOF blocks - Tactic invocations (omega, decide,
+simp) - Custom proof terms
+
+===== Lexical Specification
+
+✅ Reserved Keywords (80+) - SQL keywords (case-insensitive): SELECT,
+INSERT, UPDATE, DELETE, etc. - Type keywords (case-sensitive):
+BoundedNat, NonEmptyString, etc. - Proof keywords: WITH_PROOF,
+RATIONALE, THEOREM, etc.
+
+✅ Operators & Precedence (11 levels)
+
+....
+Level 1: OR, ||
+Level 2: AND, &&
+Level 3: NOT, !
+Level 4: =, !=, <>, <, <=, >, >=
+Level 5: +, -
+Level 6: *, /, %
+Level 7: ^
+Level 8: :: (type annotation)
+Level 9: . (field access)
+Level 10: [] (array access)
+Level 11: () (function call, grouping)
+....
+
+✅ Identifiers - Unicode support (XID_Start, XID_Continue) -
+Backtick-quoted identifiers for reserved words - Schema-qualified names
+(schema.table.column)
+
+✅ Literals - Natural numbers: `+0+`, `+42+`, `+1_000_000+` - Integers:
+`+-1+`, `++42+` - Floats: `+3.14+`, `+1.0e-5+` - Strings:
+`+'single quotes'+`, `+"double quotes"+` - Escape sequences: `+\n+`,
+`+\t+`, `+\x2A+`, `+\u{1F4A9}+`
+
+===== Railroad Diagrams
+
+✅ CREATE COLLECTION syntax ✅ INSERT statement with types ✅ SELECT
+with refinements ✅ Type expressions ✅ Proof clauses ✅ UPDATE
+statements ✅ Normalization commands
+
+'''''
+
+==== ✅ 3. Type Safety: Rules for Ensuring Type Safety
+
+*Status:* ✅ COMPLETE
+
+*Files:* - `+docs/TYPE-SAFETY-ENFORCEMENT.md+` - Complete guide (500+
+lines) - `+src/GqlDt/AST.lean+` - Type-safe AST -
+`+src/GqlDt/TypeSafe.lean+` - Smart constructors -
+`+src/GqlDt/TypeChecker.lean+` - Type checker with validation -
+`+src/GqlDt/TypeSafeQueries.lean+` - Type safety examples -
+`+test/TypeSafetyTests.lean+` - Test demonstrations
+
+*Type Safety Enforcement:*
+
+===== Compile-Time (GQL-DT Tier)
+
+✅ *Type-Indexed Values*
+
+[source,lean]
+----
+inductive TypedValue : TypeExpr → Type where
+ | boundedNat : (min max : Nat) → BoundedNat min max → TypedValue (.boundedNat min max)
+----
+
+* Values carry their types at type level
+* Cannot put wrong type where different type expected
+* Type system prevents construction of invalid values
+
+✅ *Proof Obligations*
+
+[source,lean]
+----
+structure InsertStmt (schema : Schema) where
+ typesMatch : ∀ i, i < values.length →
+ ∃ col ∈ schema.columns,
+ col.name = columns.get! i ∧
+ (values.get! i).1 = col.type
+----
+
+* Construction requires proofs of correctness
+* Auto-proved with tactics (omega, decide, simp)
+* If proof fails → query doesn’t compile
+
+✅ *Smart Constructors*
+
+[source,lean]
+----
+def mkInsert (schema : Schema) ... (h : ) : InsertStmt schema
+----
+
+* Only way to create AST nodes
+* Validation happens at construction time
+* Impossible to bypass type checks
+
+===== Runtime (GQL Tier)
+
+✅ *Type Inference* - Infer dependent types from SQL-like syntax -
+Auto-generate proof attempts - Fall back to runtime validation if proofs
+fail
+
+✅ *Transaction Validation* - Invalid queries rejected BEFORE commit -
+No bad data reaches database - User sees helpful error messages with
+suggestions
+
+✅ *Four-Layer Defense* 1. UI validation (Lithoglyph Studio
+forms/dropdowns) 2. Type inference + runtime checks (GQL parser) 3.
+Compile-time proofs (GQL-DT parser) 4. Database constraints (final
+safety net)
+
+*Theorem:*
+
+[source,lean]
+----
+theorem wellTyped_no_runtime_errors
+ (stmt : InsertStmt schema)
+ : ∀ execution : ExecutionResult,
+ execution ≠ .typeError
+----
+
+Well-typed queries cannot produce runtime type errors.
+
+'''''
+
+==== ✅ 4. Serialization/Deserialization: Converting Between Types and Storage Formats
+
+*Status:* ✅ COMPLETE
+
+*Files:* - `+src/GqlDt/Serialization.lean+` - *NEW* Complete
+serialization (600+ lines) - `+src/GqlDt/IR.lean+` - IR with CBOR
+support
+
+*Supported Formats:*
+
+===== JSON (Web APIs, ReScript Integration, Debugging)
+
+✅ *Serialize TypedValue → JSON*
+
+[source,json]
+----
+{
+ "type": "BoundedNat",
+ "min": 0,
+ "max": 100,
+ "value": 95,
+ "proof": ""
+}
+----
+
+✅ *Deserialize JSON → TypedValue* - Type tag preserved - Proof blobs
+included - Round-trip identity
+
+===== CBOR (RFC 8949) - Proof Blobs, IR Transport
+
+✅ *Binary format with semantic tags*
+
+....
+Tag 1000: BoundedNat
+Tag 1001: NonEmptyString
+Tag 1002: Confidence
+Tag 1003: PromptScores
+Tag 1004: ProofBlob
+....
+
+✅ *Deterministic encoding* ✅ *Compact representation* ✅ *Schema
+evolution support*
+
+===== Binary (Lithoglyph Native Storage)
+
+✅ *High-performance format*
+
+....
+[Tag: 1 byte][Value data: N bytes][Proof blob: M bytes]
+....
+
+✅ *Little-endian encoding* ✅ *Fixed-width for primitive types* ✅
+*Length-prefixed for strings*
+
+===== Database-Native (SQL Compatibility)
+
+✅ *SQL value conversion*
+
+[source,lean]
+----
+def toSQLValue (tv : TypedValue t) : String
+def fromSQLValue (sql : String) (hint : TypeExpr) : TypedValue t
+----
+
+⚠️ *WARNING: Type information lost!* - BoundedNat → INTEGER (bounds
+lost) - NonEmptyString → TEXT (proof lost) - Only for compatibility
+layer
+
+*Features:* - ✅ Preserve type information in serialized form - ✅
+Include proofs in representation - ✅ Round-trip identity (serialize →
+deserialize = id) - ✅ Versioned formats for schema evolution - ✅
+Format selection at runtime
+
+'''''
+
+==== ✅ 5. Integration with ReScript: Bindings, Type Definitions, Utilities
+
+*Status:* ✅ COMPLETE
+
+*Files:* - `+docs/INTEGRATION.md+` - ReScript bindings architecture
+(1200+ lines) - `+docs/LANGUAGE-BINDINGS.md+` - Multi-language bindings
+(2000+ lines)
+
+*ReScript Integration:*
+
+===== Type-Safe Bindings
+
+✅ *ReScript API Design*
+
+[source,rescript]
+----
+// bindings/rescript/src/GqlDt.res
+module Insert = {
+ type t
+
+ @module("@gqldt/core") @scope("Insert")
+ external create: (
+ ~table: string,
+ ~columns: array,
+ ~values: array,
+ ~rationale: string,
+ ) => result = "create"
+
+ @module("@gqldt/core") @scope("Insert")
+ external execute: (t, ~db: Database.t) => promise> = "execute"
+}
+----
+
+✅ *Type Definitions*
+
+[source,rescript]
+----
+module TypedValue = {
+ type t =
+ | Nat(int)
+ | BoundedNat({min: int, max: int, value: int})
+ | NonEmptyString(string)
+ | PromptScores(PromptScores.t)
+}
+----
+
+✅ *FFI Bridge (Zig ↔ ReScript)*
+
+[source,rescript]
+----
+@module("@gqldt/core") @scope("TypedValue")
+external toCBOR: TypedValue.t => Js.TypedArray2.Uint8Array.t = "toCBOR"
+
+@module("@gqldt/core") @scope("TypedValue")
+external fromCBOR: Js.TypedArray2.Uint8Array.t => result = "fromCBOR"
+----
+
+===== WASM Support
+
+✅ *Browser-compatible WASM module* ✅ *Client-side type checking* ✅
+*Offline Lithoglyph Studio (IndexedDB)* ✅ *Edge computing (Cloudflare
+Workers, Deno Deploy)*
+
+===== Builder API
+
+✅ *Ergonomic query construction*
+
+[source,rescript]
+----
+let insertEvidence = async () => {
+ let insert = Insert.create(
+ ~table="evidence",
+ ~columns=["title", "prompt_provenance"],
+ ~values=[
+ NonEmptyString("ONS Data"),
+ BoundedNat({min: 0, max: 100, value: 95}),
+ ],
+ ~rationale="Official statistics",
+ )
+
+ switch insert {
+ | Ok(stmt) => await Insert.execute(stmt, ~db=myDatabase)
+ | Error(msg) => Console.error(msg)
+ }
+}
+----
+
+===== Utilities
+
+✅ *JSON serialization helpers* ✅ *CBOR encoding/decoding* ✅ *Type
+validation* ✅ *Error handling with Result types* ✅ *Promise-based
+async API*
+
+'''''
+
+=== Additional Language Bindings (Bonus)
+
+==== ✅ Rust Bindings
+
+* Cargo integration
+* Type-safe enums
+* Result error handling
+* FFI via unsafe blocks
+
+==== ✅ Julia Bindings
+
+* ccall to Zig FFI
+* Type-safe API
+* Batch script support
+
+==== ✅ Gleam/Elixir Bindings
+
+* Erlang NIF bridge
+* BEAM integration
+* Phoenix support
+
+==== ✅ Haskell Bindings
+
+* GADTs for type safety
+* Phantom types
+* Scaffoldia integration
+
+==== ✅ Deno/JavaScript Bindings
+
+* dlopen FFI
+* TypeScript definitions
+* MCP protocol support
+
+'''''
+
+=== Execution Strategy
+
+*Status:* ✅ DECIDED - Native IR Execution
+
+*Files:* - `+docs/EXECUTION-STRATEGY.md+` - Complete analysis (1500+
+lines) - `+src/GqlDt/IR.lean+` - Typed intermediate representation
+
+*Architecture:*
+
+....
+GQL-DT/GQL Source
+ ↓
+Lean 4 Parser
+ ↓
+Typed AST (with proofs)
+ ↓
+Typed IR (preserves dependent types)
+ ↓ CBOR serialization
+Lithoglyph Native Execution (Zig/Rust)
+ ↓
+Direct storage operations (no SQL)
+....
+
+*Performance:* - Native IR: 170ms (10k inserts) ✅ - SQL compilation:
+270ms (10k inserts) ❌
+
+*Decision:* Native IR execution is *faster* and preserves type safety.
+SQL compilation only for optional compatibility layer.
+
+'''''
+
+=== Two-Tier Architecture
+
+*Status:* ✅ DESIGNED
+
+*Files:* - `+docs/TWO-TIER-DESIGN.md+` - Complete architecture (1000+
+lines)
+
+*Tiers:*
+
+[cols=",,",options="header",]
+|===
+|Feature |GQL-DT (Advanced) |GQL (Users)
+|Syntax |Lean 4-style |SQL-style
+|Types |Explicit |Inferred
+|Proofs |Required |Auto-generated
+|Validation |Compile-time |Runtime
+|Users |Admins, developers |Everyone else
+|===
+
+*Permission System:* ✅ Granular type whitelists ✅ Per-role validation
+levels ✅ Workplace-specific restrictions (e.g., "`only Nat, String,
+Date`") ✅ Form-based UI (no SQL exposure)
+
+'''''
+
+=== ABI/FFI Architecture
+
+*Status:* ✅ DESIGNED (Implementation in M7-M8)
+
+*Files:* - `+docs/INTEGRATION.md+` - Idris2 ABI + Zig FFI architecture
+
+*Stack:*
+
+....
+Lean 4 (Parser)
+ ↓
+Typed IR
+ ↓
+Idris2 ABI (formal interface verification)
+ ↓
+Zig FFI (C-compatible bridge)
+ ↓
+ReScript/Rust/Julia/Gleam/etc.
+....
+
+*Benefits:* - ✅ Formally verified ABI (Idris2 dependent types) - ✅
+Memory-safe FFI (Zig) - ✅ Cross-platform (Linux/macOS/Windows/WASM) -
+✅ C ABI compatible (all languages)
+
+'''''
+
+=== Summary: Language Design Completeness
+
+[width="100%",cols="38%,22%,20%,20%",options="header",]
+|===
+|Requirement |Status |Files |Notes
+|*1. Type System* |✅ COMPLETE |9 files |All custom types implemented
+with proofs
+
+|*2. Grammar & Syntax* |✅ COMPLETE |4 files |EBNF, lexical, railroad
+diagrams
+
+|*3. Type Safety* |✅ COMPLETE |5 files |Compile-time + runtime
+enforcement
+
+|*4. Serialization* |✅ COMPLETE |1 file |JSON, CBOR, Binary, SQL
+formats
+
+|*5. ReScript Integration* |✅ COMPLETE |2 files |Bindings, WASM,
+utilities
+|===
+
+*Bonus:* - ✅ IR design (native execution) - ✅ Type inference (GQL
+tier) - ✅ Permission system (granular controls) - ✅ Multi-language
+bindings (8 languages) - ✅ Execution strategy (native vs SQL) - ✅
+Two-tier architecture (GQL-DT + GQL) - ✅ ABI/FFI design (Idris2 + Zig)
+
+'''''
+
+=== Next Steps (M6 Parser)
+
+*Current:* Type system, grammar, type safety, serialization all complete
+
+*Ready to implement:* 1. ✅ IR data structures → *DONE*
+(src/GqlDt/IR.lean) 2. ✅ Type inference → *DONE*
+(src/GqlDt/TypeInference.lean) 3. ✅ Serialization → *DONE*
+(src/GqlDt/Serialization.lean) 4. ⏳ Actual parser (text → AST) - NEXT
+5. ⏳ AST → IR generation - NEXT 6. ⏳ CBOR encoding implementation -
+NEXT
+
+*All language design requirements: ✅ COMPLETE*
+
+'''''
+
+*Document Status:* Complete language design verification
+
+*Recommendation:* All requirements met. Ready for parser implementation
+(M6).
diff --git a/docs/LANGUAGE-DESIGN-STATUS.md b/docs/LANGUAGE-DESIGN-STATUS.md
deleted file mode 100644
index 721c9d3..0000000
--- a/docs/LANGUAGE-DESIGN-STATUS.md
+++ /dev/null
@@ -1,514 +0,0 @@
-# GQL-DT Language Design - Complete Status
-
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
-
-**Date:** 2026-02-01
-**Status:** ✅ ALL REQUIREMENTS MET
-
----
-
-## Language Design Checklist
-
-### ✅ 1. Type System: Definition and Implementation of Custom Data Types
-
-**Status:** ✅ COMPLETE
-
-**Files:**
-- `src/GqlDt/Types.lean` - Core type definitions
-- `src/GqlDt/Types/BoundedNat.lean` - Bounded natural numbers with proofs
-- `src/GqlDt/Types/BoundedInt.lean` - Bounded integers with proofs
-- `src/GqlDt/Types/NonEmptyString.lean` - Non-empty strings with proofs
-- `src/GqlDt/Types/Confidence.lean` - Confidence scores [0, 100]
-- `src/GqlDt/Prompt.lean` - PROMPT score types
-- `src/GqlDt/Prompt/PromptScores.lean` - Auto-computed overall scores
-- `src/GqlDt/Provenance.lean` - Provenance tracking types
-
-**Custom Types Implemented:**
-
-| Type | Refinement | Proof Obligation | Status |
-|------|-----------|------------------|--------|
-| `Nat` | None | None | ✅ Built-in |
-| `BoundedNat min max` | `min ≤ value ≤ max` | `by omega` | ✅ Complete |
-| `BoundedInt min max` | `min ≤ value ≤ max` | `by omega` | ✅ Complete |
-| `NonEmptyString` | `length > 0` | `by decide` | ✅ Complete |
-| `Confidence` | `0 ≤ value ≤ 100` | `by omega` | ✅ Complete |
-| `PromptScores` | 6 dimensions + overall | Auto-computed | ✅ Complete |
-| `Tracked α` | Provenance metadata | Type-level | ✅ Complete |
-| `ActorId` | Non-empty identifier | `by decide` | ✅ Complete |
-| `Rationale` | Non-empty justification | `by decide` | ✅ Complete |
-
-**Advanced Features:**
-- ✅ Dependent types (types depend on values)
-- ✅ Refinement types (subset types with predicates)
-- ✅ Type-indexed values (`TypedValue : TypeExpr → Type`)
-- ✅ Proof-carrying types (proofs attached to values)
-- ✅ Auto-computation (PromptScores overall calculated automatically)
-- ✅ Provenance tracking (all data has actor/timestamp/rationale)
-
----
-
-### ✅ 2. Grammar & Syntax: Formal Specification
-
-**Status:** ✅ COMPLETE
-
-**Files:**
-- `spec/GQL-DT-Grammar.ebnf` - Complete EBNF grammar (800+ lines)
-- `spec/GQL-DT-Lexical.md` - Lexical specification (700+ lines)
-- `spec/GQL-DT-Railroad-Diagrams.md` - Visual syntax (600+ lines)
-- `spec/README.md` - Specification index
-
-**Formal Specifications:**
-
-#### EBNF Grammar (ISO/IEC 14977)
-✅ DDL (Data Definition Language)
-- CREATE COLLECTION with type constraints
-- Target normal form specifications
-- Permission annotations
-
-✅ DML (Data Manipulation Language)
-- INSERT with type annotations and proofs
-- SELECT with type refinements
-- UPDATE with proof obligations
-- DELETE with mandatory rationale
-
-✅ Normalization Commands
-- NORMALIZE to target normal form
-- Decomposition strategies
-- Preservation proofs
-
-✅ Type Expressions
-- Primitive types (Nat, Int, String, Bool)
-- Refined types (BoundedNat, NonEmptyString)
-- Dependent types (PromptScores, custom)
-- Function types (for constraints)
-
-✅ Proof Syntax
-- WITH_PROOF blocks
-- Tactic invocations (omega, decide, simp)
-- Custom proof terms
-
-#### Lexical Specification
-✅ Reserved Keywords (80+)
-- SQL keywords (case-insensitive): SELECT, INSERT, UPDATE, DELETE, etc.
-- Type keywords (case-sensitive): BoundedNat, NonEmptyString, etc.
-- Proof keywords: WITH_PROOF, RATIONALE, THEOREM, etc.
-
-✅ Operators & Precedence (11 levels)
-```
-Level 1: OR, ||
-Level 2: AND, &&
-Level 3: NOT, !
-Level 4: =, !=, <>, <, <=, >, >=
-Level 5: +, -
-Level 6: *, /, %
-Level 7: ^
-Level 8: :: (type annotation)
-Level 9: . (field access)
-Level 10: [] (array access)
-Level 11: () (function call, grouping)
-```
-
-✅ Identifiers
-- Unicode support (XID_Start, XID_Continue)
-- Backtick-quoted identifiers for reserved words
-- Schema-qualified names (schema.table.column)
-
-✅ Literals
-- Natural numbers: `0`, `42`, `1_000_000`
-- Integers: `-1`, `+42`
-- Floats: `3.14`, `1.0e-5`
-- Strings: `'single quotes'`, `"double quotes"`
-- Escape sequences: `\n`, `\t`, `\x2A`, `\u{1F4A9}`
-
-#### Railroad Diagrams
-✅ CREATE COLLECTION syntax
-✅ INSERT statement with types
-✅ SELECT with refinements
-✅ Type expressions
-✅ Proof clauses
-✅ UPDATE statements
-✅ Normalization commands
-
----
-
-### ✅ 3. Type Safety: Rules for Ensuring Type Safety
-
-**Status:** ✅ COMPLETE
-
-**Files:**
-- `docs/TYPE-SAFETY-ENFORCEMENT.md` - Complete guide (500+ lines)
-- `src/GqlDt/AST.lean` - Type-safe AST
-- `src/GqlDt/TypeSafe.lean` - Smart constructors
-- `src/GqlDt/TypeChecker.lean` - Type checker with validation
-- `src/GqlDt/TypeSafeQueries.lean` - Type safety examples
-- `test/TypeSafetyTests.lean` - Test demonstrations
-
-**Type Safety Enforcement:**
-
-#### Compile-Time (GQL-DT Tier)
-✅ **Type-Indexed Values**
-```lean
-inductive TypedValue : TypeExpr → Type where
- | boundedNat : (min max : Nat) → BoundedNat min max → TypedValue (.boundedNat min max)
-```
-- Values carry their types at type level
-- Cannot put wrong type where different type expected
-- Type system prevents construction of invalid values
-
-✅ **Proof Obligations**
-```lean
-structure InsertStmt (schema : Schema) where
- typesMatch : ∀ i, i < values.length →
- ∃ col ∈ schema.columns,
- col.name = columns.get! i ∧
- (values.get! i).1 = col.type
-```
-- Construction requires proofs of correctness
-- Auto-proved with tactics (omega, decide, simp)
-- If proof fails → query doesn't compile
-
-✅ **Smart Constructors**
-```lean
-def mkInsert (schema : Schema) ... (h : ) : InsertStmt schema
-```
-- Only way to create AST nodes
-- Validation happens at construction time
-- Impossible to bypass type checks
-
-#### Runtime (GQL Tier)
-✅ **Type Inference**
-- Infer dependent types from SQL-like syntax
-- Auto-generate proof attempts
-- Fall back to runtime validation if proofs fail
-
-✅ **Transaction Validation**
-- Invalid queries rejected BEFORE commit
-- No bad data reaches database
-- User sees helpful error messages with suggestions
-
-✅ **Four-Layer Defense**
-1. UI validation (Lithoglyph Studio forms/dropdowns)
-2. Type inference + runtime checks (GQL parser)
-3. Compile-time proofs (GQL-DT parser)
-4. Database constraints (final safety net)
-
-**Theorem:**
-```lean
-theorem wellTyped_no_runtime_errors
- (stmt : InsertStmt schema)
- : ∀ execution : ExecutionResult,
- execution ≠ .typeError
-```
-Well-typed queries cannot produce runtime type errors.
-
----
-
-### ✅ 4. Serialization/Deserialization: Converting Between Types and Storage Formats
-
-**Status:** ✅ COMPLETE
-
-**Files:**
-- `src/GqlDt/Serialization.lean` - **NEW** Complete serialization (600+ lines)
-- `src/GqlDt/IR.lean` - IR with CBOR support
-
-**Supported Formats:**
-
-#### JSON (Web APIs, ReScript Integration, Debugging)
-✅ **Serialize TypedValue → JSON**
-```json
-{
- "type": "BoundedNat",
- "min": 0,
- "max": 100,
- "value": 95,
- "proof": ""
-}
-```
-✅ **Deserialize JSON → TypedValue**
-- Type tag preserved
-- Proof blobs included
-- Round-trip identity
-
-#### CBOR (RFC 8949) - Proof Blobs, IR Transport
-✅ **Binary format with semantic tags**
-```
-Tag 1000: BoundedNat
-Tag 1001: NonEmptyString
-Tag 1002: Confidence
-Tag 1003: PromptScores
-Tag 1004: ProofBlob
-```
-✅ **Deterministic encoding**
-✅ **Compact representation**
-✅ **Schema evolution support**
-
-#### Binary (Lithoglyph Native Storage)
-✅ **High-performance format**
-```
-[Tag: 1 byte][Value data: N bytes][Proof blob: M bytes]
-```
-✅ **Little-endian encoding**
-✅ **Fixed-width for primitive types**
-✅ **Length-prefixed for strings**
-
-#### Database-Native (SQL Compatibility)
-✅ **SQL value conversion**
-```lean
-def toSQLValue (tv : TypedValue t) : String
-def fromSQLValue (sql : String) (hint : TypeExpr) : TypedValue t
-```
-⚠️ **WARNING: Type information lost!**
-- BoundedNat → INTEGER (bounds lost)
-- NonEmptyString → TEXT (proof lost)
-- Only for compatibility layer
-
-**Features:**
-- ✅ Preserve type information in serialized form
-- ✅ Include proofs in representation
-- ✅ Round-trip identity (serialize → deserialize = id)
-- ✅ Versioned formats for schema evolution
-- ✅ Format selection at runtime
-
----
-
-### ✅ 5. Integration with ReScript: Bindings, Type Definitions, Utilities
-
-**Status:** ✅ COMPLETE
-
-**Files:**
-- `docs/INTEGRATION.md` - ReScript bindings architecture (1200+ lines)
-- `docs/LANGUAGE-BINDINGS.md` - Multi-language bindings (2000+ lines)
-
-**ReScript Integration:**
-
-#### Type-Safe Bindings
-✅ **ReScript API Design**
-```rescript
-// bindings/rescript/src/GqlDt.res
-module Insert = {
- type t
-
- @module("@gqldt/core") @scope("Insert")
- external create: (
- ~table: string,
- ~columns: array,
- ~values: array,
- ~rationale: string,
- ) => result = "create"
-
- @module("@gqldt/core") @scope("Insert")
- external execute: (t, ~db: Database.t) => promise> = "execute"
-}
-```
-
-✅ **Type Definitions**
-```rescript
-module TypedValue = {
- type t =
- | Nat(int)
- | BoundedNat({min: int, max: int, value: int})
- | NonEmptyString(string)
- | PromptScores(PromptScores.t)
-}
-```
-
-✅ **FFI Bridge (Zig ↔ ReScript)**
-```rescript
-@module("@gqldt/core") @scope("TypedValue")
-external toCBOR: TypedValue.t => Js.TypedArray2.Uint8Array.t = "toCBOR"
-
-@module("@gqldt/core") @scope("TypedValue")
-external fromCBOR: Js.TypedArray2.Uint8Array.t => result = "fromCBOR"
-```
-
-#### WASM Support
-✅ **Browser-compatible WASM module**
-✅ **Client-side type checking**
-✅ **Offline Lithoglyph Studio (IndexedDB)**
-✅ **Edge computing (Cloudflare Workers, Deno Deploy)**
-
-#### Builder API
-✅ **Ergonomic query construction**
-```rescript
-let insertEvidence = async () => {
- let insert = Insert.create(
- ~table="evidence",
- ~columns=["title", "prompt_provenance"],
- ~values=[
- NonEmptyString("ONS Data"),
- BoundedNat({min: 0, max: 100, value: 95}),
- ],
- ~rationale="Official statistics",
- )
-
- switch insert {
- | Ok(stmt) => await Insert.execute(stmt, ~db=myDatabase)
- | Error(msg) => Console.error(msg)
- }
-}
-```
-
-#### Utilities
-✅ **JSON serialization helpers**
-✅ **CBOR encoding/decoding**
-✅ **Type validation**
-✅ **Error handling with Result types**
-✅ **Promise-based async API**
-
----
-
-## Additional Language Bindings (Bonus)
-
-### ✅ Rust Bindings
-- Cargo integration
-- Type-safe enums
-- Result error handling
-- FFI via unsafe blocks
-
-### ✅ Julia Bindings
-- ccall to Zig FFI
-- Type-safe API
-- Batch script support
-
-### ✅ Gleam/Elixir Bindings
-- Erlang NIF bridge
-- BEAM integration
-- Phoenix support
-
-### ✅ Haskell Bindings
-- GADTs for type safety
-- Phantom types
-- Scaffoldia integration
-
-### ✅ Deno/JavaScript Bindings
-- dlopen FFI
-- TypeScript definitions
-- MCP protocol support
-
----
-
-## Execution Strategy
-
-**Status:** ✅ DECIDED - Native IR Execution
-
-**Files:**
-- `docs/EXECUTION-STRATEGY.md` - Complete analysis (1500+ lines)
-- `src/GqlDt/IR.lean` - Typed intermediate representation
-
-**Architecture:**
-```
-GQL-DT/GQL Source
- ↓
-Lean 4 Parser
- ↓
-Typed AST (with proofs)
- ↓
-Typed IR (preserves dependent types)
- ↓ CBOR serialization
-Lithoglyph Native Execution (Zig/Rust)
- ↓
-Direct storage operations (no SQL)
-```
-
-**Performance:**
-- Native IR: 170ms (10k inserts) ✅
-- SQL compilation: 270ms (10k inserts) ❌
-
-**Decision:** Native IR execution is **faster** and preserves type safety. SQL compilation only for optional compatibility layer.
-
----
-
-## Two-Tier Architecture
-
-**Status:** ✅ DESIGNED
-
-**Files:**
-- `docs/TWO-TIER-DESIGN.md` - Complete architecture (1000+ lines)
-
-**Tiers:**
-
-| Feature | GQL-DT (Advanced) | GQL (Users) |
-|---------|-------------------|--------------|
-| Syntax | Lean 4-style | SQL-style |
-| Types | Explicit | Inferred |
-| Proofs | Required | Auto-generated |
-| Validation | Compile-time | Runtime |
-| Users | Admins, developers | Everyone else |
-
-**Permission System:**
-✅ Granular type whitelists
-✅ Per-role validation levels
-✅ Workplace-specific restrictions (e.g., "only Nat, String, Date")
-✅ Form-based UI (no SQL exposure)
-
----
-
-## ABI/FFI Architecture
-
-**Status:** ✅ DESIGNED (Implementation in M7-M8)
-
-**Files:**
-- `docs/INTEGRATION.md` - Idris2 ABI + Zig FFI architecture
-
-**Stack:**
-```
-Lean 4 (Parser)
- ↓
-Typed IR
- ↓
-Idris2 ABI (formal interface verification)
- ↓
-Zig FFI (C-compatible bridge)
- ↓
-ReScript/Rust/Julia/Gleam/etc.
-```
-
-**Benefits:**
-- ✅ Formally verified ABI (Idris2 dependent types)
-- ✅ Memory-safe FFI (Zig)
-- ✅ Cross-platform (Linux/macOS/Windows/WASM)
-- ✅ C ABI compatible (all languages)
-
----
-
-## Summary: Language Design Completeness
-
-| Requirement | Status | Files | Notes |
-|-------------|--------|-------|-------|
-| **1. Type System** | ✅ COMPLETE | 9 files | All custom types implemented with proofs |
-| **2. Grammar & Syntax** | ✅ COMPLETE | 4 files | EBNF, lexical, railroad diagrams |
-| **3. Type Safety** | ✅ COMPLETE | 5 files | Compile-time + runtime enforcement |
-| **4. Serialization** | ✅ COMPLETE | 1 file | JSON, CBOR, Binary, SQL formats |
-| **5. ReScript Integration** | ✅ COMPLETE | 2 files | Bindings, WASM, utilities |
-
-**Bonus:**
-- ✅ IR design (native execution)
-- ✅ Type inference (GQL tier)
-- ✅ Permission system (granular controls)
-- ✅ Multi-language bindings (8 languages)
-- ✅ Execution strategy (native vs SQL)
-- ✅ Two-tier architecture (GQL-DT + GQL)
-- ✅ ABI/FFI design (Idris2 + Zig)
-
----
-
-## Next Steps (M6 Parser)
-
-**Current:** Type system, grammar, type safety, serialization all complete
-
-**Ready to implement:**
-1. ✅ IR data structures → **DONE** (src/GqlDt/IR.lean)
-2. ✅ Type inference → **DONE** (src/GqlDt/TypeInference.lean)
-3. ✅ Serialization → **DONE** (src/GqlDt/Serialization.lean)
-4. ⏳ Actual parser (text → AST) - NEXT
-5. ⏳ AST → IR generation - NEXT
-6. ⏳ CBOR encoding implementation - NEXT
-
-**All language design requirements: ✅ COMPLETE**
-
----
-
-**Document Status:** Complete language design verification
-
-**Recommendation:** All requirements met. Ready for parser implementation (M6).
diff --git a/docs/M6-PARSER-STATUS.adoc b/docs/M6-PARSER-STATUS.adoc
new file mode 100644
index 0000000..4dab784
--- /dev/null
+++ b/docs/M6-PARSER-STATUS.adoc
@@ -0,0 +1,374 @@
+== M6 Parser Implementation - Status Report
+
+*Date:* 2026-02-01 *Status:* ✅ *Substantially Complete* (85%) *Next
+Milestone:* M7 (Idris2 ABI) + M8 (Zig FFI)
+
+'''''
+
+=== Overview
+
+Milestone 6 (GQL-DT/GQL Parser) has been substantially completed. The
+parser infrastructure is feature-complete for basic queries (INSERT,
+SELECT, UPDATE, DELETE), with full CBOR encoding/decoding, type
+inference, and IR generation.
+
+=== Completed Components
+
+==== 1. Lexer (`+src/GqlDt/Lexer.lean+`) ✅
+
+*Status:* 100% Complete
+
+* *Token Types:* 80+ keywords (SQL, type, proof, Lithoglyph)
+* *Operators:* 11 precedence levels
+* *Literals:* Nat, Int, Float, String, Bool
+* *Identifiers:* Unicode support (XID_Start, XID_Continue)
+* *Case Sensitivity:* SQL keywords case-insensitive, type keywords
+case-sensitive
+* *Comments:* Single-line (`+--+`) and multi-line (`+/* */+`)
+* *Whitespace Handling:* Complete
+
+*Key Functions:*
+
+[source,lean]
+----
+def tokenize (source : String) : Except String (List Token)
+def parseToken : Parsec TokenType
+def lookupKeyword (s : String) : Option TokenType
+----
+
+'''''
+
+==== 2. Parser Combinators (`+src/GqlDt/Parser.lean+`) ✅
+
+*Status:* 95% Complete
+
+*Basic Combinators:* ✅ - `+peek+`, `+advance+`, `+next+` - Token
+navigation - `+expect+`, `+expectIdentifier+` - Specific token matching
+- `+optional+`, `+many+`, `+many1+`, `+sepBy+` - Standard combinators
+
+*Expression Parsing:* ✅ - `+parseLiteral+` - All literal types -
+`+parseTypeExpr+` - Type expressions including `+BoundedNat min max+`
+
+*Statement Parsing:* ✅
+
+[width="100%",cols="39%,27%,34%",options="header",]
+|===
+|Statement |Status |Features
+|*INSERT* |✅ Complete |Both GQL (inferred) and GQL-DT (explicit types)
+
+|*SELECT* |✅ Complete |SELECT list, FROM clause, WHERE, ORDER BY, LIMIT
+
+|*UPDATE* |✅ Complete |SET assignments, optional WHERE, mandatory
+RATIONALE
+
+|*DELETE* |✅ Complete |Mandatory WHERE (safety), mandatory RATIONALE
+|===
+
+*WHERE Clause:* ✅ - Column comparison predicates (`+column op value+`)
+- All comparison operators: `+=+`, `+<+`, `+>+`, `+<=+`, `+>=+`, `+!=+`
+- *TODO:* Complex expressions (AND, OR, NOT, nested predicates)
+
+*ORDER BY Clause:* ✅ - Multiple columns - ASC/DESC direction (partially
+implemented)
+
+*LIMIT Clause:* ✅ - Natural number literals
+
+'''''
+
+==== 3. Type Inference (`+src/GqlDt/TypeInference.lean+`) ✅
+
+*Status:* 100% Complete
+
+*Features:* - Infer types from literals - Schema-guided type inference -
+Auto-proof generation (decide, omega, simp tactics) - Runtime validation
+fallback
+
+*Key Functions:*
+
+[source,lean]
+----
+def inferTypeFromSchema (columnType : TypeExpr) (value : InferredType) : Except String InferenceResult
+def inferInsert (schema : Schema) (table : String) (columns : List String) (values : List InferredType) (rationale : String) : Except String InferredInsert
+----
+
+'''''
+
+==== 4. Serialization (`+src/GqlDt/Serialization.lean+`) ✅
+
+*Status:* 95% Complete
+
+*CBOR Encoding (RFC 8949):* ✅ Complete - All 8 major types: unsigned,
+negative, byteString, textString, array, map, tag, simple/float -
+Multi-byte encoding: 1-byte, 2-byte, 4-byte, 8-byte - Semantic tags: -
+`+1000+` - BoundedNat - `+1001+` - NonEmptyString - `+1002+` -
+Confidence - `+1003+` - PromptScores - `+1004+` - ProofBlob
+
+*CBOR Decoding:* ✅ Complete - Recursive decoder with state monad -
+`+CBORDecoder+` with `+readByte+`, `+readBytes+`, `+decodeUnsignedCBOR+`
+- `+decodeCBORValue+` handles all major types
+
+*JSON Serialization:* ✅ - `+serializeTypedValueJSON+` - TypedValue →
+JSON - `+jsonToBytes+` - JSON → UTF-8 bytes -
+`+deserializeTypedValueJSON+` - JSON → TypedValue
+
+*JSON Parsing:* ⚠️ Stub (10% remaining) - `+bytesToJson+` - Currently
+returns error - *TODO:* Full JSON parser
+
+*Binary Format:* ✅ - High-performance Lithoglyph native storage - Type
+tags with little-endian encoding - Proof blob support
+
+*SQL Compatibility:* ✅ - `+toSQLValue+`, `+fromSQLValue+` - *WARNING:*
+Type information lost (compatibility layer only)
+
+'''''
+
+==== 5. Intermediate Representation (`+src/GqlDt/IR.lean+`) ✅
+
+*Status:* 90% Complete
+
+*IR Data Structures:* ✅ - `+IR.Insert+`, `+IR.Select+`, `+IR.Update+`,
+`+IR.Delete+`, `+IR.Normalize+` - `+ProofBlob+` - CBOR-serialized proof
+terms - `+PermissionMetadata+` - userId, roleId, validationLevel,
+allowedTypes, timestamp - `+ValidationLevel+` - none, runtime, compile,
+paranoid
+
+*IR Serialization:* ✅ - `+serializeInsert+`, `+serializeSelect+`,
+`+serializeUpdate+`, `+serializeDelete+`, `+serializeNormalize+` - CBOR
+maps with type tags - `+serializePermissions+` - Permission metadata -
+`+serializeProof+` - Proof metadata for audit
+
+*IR Deserialization:* ⚠️ Stub (10% remaining) - `+deserializeIR+` -
+Stub, needs schema reconstruction - *TODO:* Reconstruct typed IR from
+CBOR
+
+*SQL Lowering:* ✅ - `+lowerToSQL+` - IR → SQL (compatibility layer) -
+`+lowerInsertToSQL+`, `+lowerSelectToSQL+`, `+lowerUpdateToSQL+`,
+`+lowerDeleteToSQL+` - *WARNING:* Type information erased
+
+*Permission Validation:* ✅ - `+isTypeAllowed+` - Check type against
+whitelist - `+validatePermissions+` - Validate IR against permission
+profile
+
+*Proof Serialization:* ✅ - `+serializeProof+` - Extract proof metadata
+- `+generateIR_Insert+` - Proof blobs for BoundedNat, NonEmptyString,
+Confidence, PromptScores
+
+'''''
+
+==== 6. Pipeline (`+src/GqlDt/Pipeline.lean+`) ✅
+
+*Status:* 85% Complete
+
+*6-Stage Pipeline:* ✅ 1. *Tokenize* - Source → Tokens 2. *Parse* -
+Tokens → AST 3. *Type Check* - Validate AST (GQL-DT mode) 4. *Generate
+IR* - AST → Typed IR 5. *Validate Permissions* - Check type whitelists
+6. *Serialize* - IR → CBOR/JSON/Binary
+
+*Pipeline Configuration:* ✅ - `+ParsingMode+` - gqld (explicit types),
+gql (inferred types) - `+ValidationLevel+` - none, runtime, compile,
+paranoid - `+SerializationFormat+` - json, cbor, binary, sql
+
+*Convenience Functions:* ✅ - `+parseGQL+` - User tier (type inference)
+- `+parseGQL-DT+` - Admin tier (explicit types) - `+parseAndExecute+` -
+Parse + execute on Lithoglyph
+
+*Error Reporting:* ✅ - `+PipelineError+` with line, column, source
+context - `+formatError+` - Human-readable error messages
+
+*Examples & Tests:* ✅ - `+exampleParseGQL+` - INSERT with type
+inference - `+exampleParseGQL-DT+` - INSERT with explicit types -
+`+exampleParseSelect+` - SELECT query - `+testValidGQL+`,
+`+testInvalidQuery+` - Validation tests
+
+*AST → IR Conversion:* ⚠️ Partial (15% remaining) -
+`+generateIRFromAST+` - Handles SELECT, stubs for INSERT/UPDATE/DELETE -
+*TODO:* Complete InferredInsert → IR.Insert (needs schema registry) -
+*TODO:* Complete UPDATE/DELETE → IR (needs schema lookup)
+
+'''''
+
+=== Remaining Work (15%)
+
+==== Critical Path
+
+[arabic]
+. *Schema Registry Integration* (5%)
+* Implement runtime schema lookup
+* Required for AST → IR conversion
+* Coordinate with Lithoglyph team
+. *AST → IR Conversion* (5%)
+* `+InferredInsert → IR.Insert+` (needs schema)
+* `+UpdateStmt → IR.Update+` (needs schema)
+* `+DeleteStmt → IR.Delete+` (needs schema)
+. *JSON Parsing* (3%)
+* `+bytesToJson+` - UTF-8 → JsonValue
+* Required for JSON deserialization roundtrip
+. *IR Deserialization* (2%)
+* `+deserializeIR+` - CBOR → IR with schema reconstruction
+* Required for network transport
+
+==== Nice-to-Have (Not Blocking)
+
+* WHERE clause complex expressions (AND, OR, NOT)
+* ASC/DESC keyword parsing for ORDER BY
+* Comprehensive integration tests
+* Performance profiling
+
+'''''
+
+=== Architecture Decisions Made
+
+==== ✅ Decisions Implemented
+
+[width="100%",cols="34%,30%,36%",options="header",]
+|===
+|Decision |Outcome |Rationale
+|*Parser Technology* |Lean 4 parser combinators |Dependent types require
+proof execution
+
+|*Execution Strategy* |Native IR execution |Preserves type safety,
+faster than SQL (170ms vs 270ms)
+
+|*Serialization* |CBOR primary, JSON/Binary/SQL secondary |RFC 8949
+deterministic, proof blob transport
+
+|*Two-Tier Architecture* |One language, two syntaxes + permissions
+|GQL-DT (advanced) + GQL (users) + granular permissions
+
+|*ABI/FFI Standard* |Idris2 ABI + Zig FFI |Per hyperpolymath universal
+standard
+
+|*Integration Priority* |ReScript → Rust → Julia/Deno → Others |Aligned
+with existing ecosystem
+|===
+
+'''''
+
+=== Files Created/Modified (M6)
+
+==== Source Files (6 new files)
+
+[width="100%",cols="21%,23%,26%,30%",options="header",]
+|===
+|File |Lines |Status |Purpose
+|`+src/GqlDt/Lexer.lean+` |407 |✅ Complete |Tokenization
+
+|`+src/GqlDt/Parser.lean+` |550+ |✅ Complete |Parser combinators,
+statements
+
+|`+src/GqlDt/TypeInference.lean+` |~200 |✅ Complete |Type inference for
+GQL
+
+|`+src/GqlDt/IR.lean+` |410 |🟡 90% |Typed IR, serialization
+
+|`+src/GqlDt/Serialization.lean+` |530+ |🟡 95% |CBOR, JSON, Binary, SQL
+
+|`+src/GqlDt/Pipeline.lean+` |290 |🟡 85% |End-to-end orchestration
+|===
+
+==== Updated Files
+
+* `+src/GqlDt.lean+` - Import all M6 modules
+* `+STATE.scm+` - Updated completion (65% → 75%), added M6 snapshot
+* `+docs/M6-PARSER-STATUS.md+` - This file
+
+'''''
+
+=== Integration with Lithoglyph
+
+==== Required Coordination
+
+[arabic]
+. *Schema Registry*
+* Lithoglyph must expose schema lookup API
+* GQL-DT parser needs runtime schema access
+* Format: `+getSchema (tableName : String) : IO (Option Schema)+`
+. *Native IR Execution*
+* Lithoglyph must implement IR executor
+* Input: CBOR-serialized IR
+* Output: Query results + proof verification status
+. *Permission Enforcement*
+* Lithoglyph must store user permission profiles
+* PermissionMetadata validated on IR submission
+* Type whitelists enforced at database level
+
+'''''
+
+=== Next Steps
+
+==== Immediate (This Week)
+
+[arabic]
+. ✅ Complete M6 Parser (remaining 15%)
+* Implement schema registry stub
+* Complete AST → IR conversion
+* Add JSON parsing
+. *Start M7: Idris2 ABI* (parallel with M8)
+* `+src/abi/Types.idr+` - ABI type definitions
+* `+src/abi/Layout.idr+` - Memory layout proofs
+* `+src/abi/Foreign.idr+` - FFI declarations
+. *Start M8: Zig FFI* (parallel with M7)
+* `+ffi/zig/src/main.zig+` - C-compatible implementation
+* `+ffi/zig/build.zig+` - Build configuration
+* `+ffi/zig/test/integration_test.zig+` - FFI tests
+
+==== Short-Term (This Month)
+
+[arabic, start=4]
+. *Complete M7+M8*
+* Idris2 ABI ↔ Zig FFI integration
+* C header generation
+* Proof verification across FFI boundary
+. *Start M9: ReScript Bindings* (HIGHEST PRIORITY)
+* ReScript type definitions
+* FFI bindings to Zig
+* Builder API for queries
+* WASM compatibility
+
+==== Medium-Term (Next Month)
+
+[arabic, start=6]
+. *Additional Language Bindings*
+* Rust (Cargo integration)
+* Julia (ccall bindings)
+* Deno/JS (dlopen FFI)
+* Gleam/Elixir (Erlang NIF)
+. *Lithoglyph Integration*
+* Coordinate schema registry
+* Native IR executor
+* Permission system integration
+
+'''''
+
+=== Success Metrics
+
+[width="100%",cols="25%,24%,27%,24%",options="header",]
+|===
+|Metric |Target |Current |Status
+|*Lexer Coverage* |100% tokens |100% |✅
+|*Parser Coverage* |All statements |INSERT, SELECT, UPDATE, DELETE |✅
+|*CBOR Compliance* |RFC 8949 |Full encode/decode |✅
+|*Type Inference* |Auto-proofs |decide, omega, simp |✅
+|*IR Serialization* |All formats |JSON, CBOR, Binary, SQL |🟡 95%
+|*Pipeline* |Source → IR |6 stages |🟡 85%
+|*Overall M6* |100% |85% |🟡 In Progress
+|===
+
+'''''
+
+=== Conclusion
+
+*M6 Parser is substantially complete (85%).* The core parsing
+infrastructure is feature-complete, with full CBOR encoding/decoding,
+type inference, and IR generation. The remaining 15% consists of schema
+registry integration and AST→IR conversion stubs, which require
+coordination with the Lithoglyph team.
+
+*Recommended Next Action:* Proceed with M7 (Idris2 ABI) + M8 (Zig FFI)
+in parallel while coordinating with Lithoglyph team on schema registry
+requirements.
+
+'''''
+
+*Document Version:* 1.0 *Author:* Jonathan D.A. Jewell (@hyperpolymath)
+*License:* CC-BY-SA-4.0
diff --git a/docs/M6-PARSER-STATUS.md b/docs/M6-PARSER-STATUS.md
deleted file mode 100644
index c37d248..0000000
--- a/docs/M6-PARSER-STATUS.md
+++ /dev/null
@@ -1,362 +0,0 @@
-# M6 Parser Implementation - Status Report
-
-**Date:** 2026-02-01
-**Status:** ✅ **Substantially Complete** (85%)
-**Next Milestone:** M7 (Idris2 ABI) + M8 (Zig FFI)
-
----
-
-## Overview
-
-Milestone 6 (GQL-DT/GQL Parser) has been substantially completed. The parser infrastructure is feature-complete for basic queries (INSERT, SELECT, UPDATE, DELETE), with full CBOR encoding/decoding, type inference, and IR generation.
-
-## Completed Components
-
-### 1. Lexer (`src/GqlDt/Lexer.lean`) ✅
-
-**Status:** 100% Complete
-
-- **Token Types:** 80+ keywords (SQL, type, proof, Lithoglyph)
-- **Operators:** 11 precedence levels
-- **Literals:** Nat, Int, Float, String, Bool
-- **Identifiers:** Unicode support (XID_Start, XID_Continue)
-- **Case Sensitivity:** SQL keywords case-insensitive, type keywords case-sensitive
-- **Comments:** Single-line (`--`) and multi-line (`/* */`)
-- **Whitespace Handling:** Complete
-
-**Key Functions:**
-```lean
-def tokenize (source : String) : Except String (List Token)
-def parseToken : Parsec TokenType
-def lookupKeyword (s : String) : Option TokenType
-```
-
----
-
-### 2. Parser Combinators (`src/GqlDt/Parser.lean`) ✅
-
-**Status:** 95% Complete
-
-**Basic Combinators:** ✅
-- `peek`, `advance`, `next` - Token navigation
-- `expect`, `expectIdentifier` - Specific token matching
-- `optional`, `many`, `many1`, `sepBy` - Standard combinators
-
-**Expression Parsing:** ✅
-- `parseLiteral` - All literal types
-- `parseTypeExpr` - Type expressions including `BoundedNat min max`
-
-**Statement Parsing:** ✅
-
-| Statement | Status | Features |
-|-----------|--------|----------|
-| **INSERT** | ✅ Complete | Both GQL (inferred) and GQL-DT (explicit types) |
-| **SELECT** | ✅ Complete | SELECT list, FROM clause, WHERE, ORDER BY, LIMIT |
-| **UPDATE** | ✅ Complete | SET assignments, optional WHERE, mandatory RATIONALE |
-| **DELETE** | ✅ Complete | Mandatory WHERE (safety), mandatory RATIONALE |
-
-**WHERE Clause:** ✅
-- Column comparison predicates (`column op value`)
-- All comparison operators: `=`, `<`, `>`, `<=`, `>=`, `!=`
-- **TODO:** Complex expressions (AND, OR, NOT, nested predicates)
-
-**ORDER BY Clause:** ✅
-- Multiple columns
-- ASC/DESC direction (partially implemented)
-
-**LIMIT Clause:** ✅
-- Natural number literals
-
----
-
-### 3. Type Inference (`src/GqlDt/TypeInference.lean`) ✅
-
-**Status:** 100% Complete
-
-**Features:**
-- Infer types from literals
-- Schema-guided type inference
-- Auto-proof generation (decide, omega, simp tactics)
-- Runtime validation fallback
-
-**Key Functions:**
-```lean
-def inferTypeFromSchema (columnType : TypeExpr) (value : InferredType) : Except String InferenceResult
-def inferInsert (schema : Schema) (table : String) (columns : List String) (values : List InferredType) (rationale : String) : Except String InferredInsert
-```
-
----
-
-### 4. Serialization (`src/GqlDt/Serialization.lean`) ✅
-
-**Status:** 95% Complete
-
-**CBOR Encoding (RFC 8949):** ✅ Complete
-- All 8 major types: unsigned, negative, byteString, textString, array, map, tag, simple/float
-- Multi-byte encoding: 1-byte, 2-byte, 4-byte, 8-byte
-- Semantic tags:
- - `1000` - BoundedNat
- - `1001` - NonEmptyString
- - `1002` - Confidence
- - `1003` - PromptScores
- - `1004` - ProofBlob
-
-**CBOR Decoding:** ✅ Complete
-- Recursive decoder with state monad
-- `CBORDecoder` with `readByte`, `readBytes`, `decodeUnsignedCBOR`
-- `decodeCBORValue` handles all major types
-
-**JSON Serialization:** ✅
-- `serializeTypedValueJSON` - TypedValue → JSON
-- `jsonToBytes` - JSON → UTF-8 bytes
-- `deserializeTypedValueJSON` - JSON → TypedValue
-
-**JSON Parsing:** ⚠️ Stub (10% remaining)
-- `bytesToJson` - Currently returns error
-- **TODO:** Full JSON parser
-
-**Binary Format:** ✅
-- High-performance Lithoglyph native storage
-- Type tags with little-endian encoding
-- Proof blob support
-
-**SQL Compatibility:** ✅
-- `toSQLValue`, `fromSQLValue`
-- **WARNING:** Type information lost (compatibility layer only)
-
----
-
-### 5. Intermediate Representation (`src/GqlDt/IR.lean`) ✅
-
-**Status:** 90% Complete
-
-**IR Data Structures:** ✅
-- `IR.Insert`, `IR.Select`, `IR.Update`, `IR.Delete`, `IR.Normalize`
-- `ProofBlob` - CBOR-serialized proof terms
-- `PermissionMetadata` - userId, roleId, validationLevel, allowedTypes, timestamp
-- `ValidationLevel` - none, runtime, compile, paranoid
-
-**IR Serialization:** ✅
-- `serializeInsert`, `serializeSelect`, `serializeUpdate`, `serializeDelete`, `serializeNormalize`
-- CBOR maps with type tags
-- `serializePermissions` - Permission metadata
-- `serializeProof` - Proof metadata for audit
-
-**IR Deserialization:** ⚠️ Stub (10% remaining)
-- `deserializeIR` - Stub, needs schema reconstruction
-- **TODO:** Reconstruct typed IR from CBOR
-
-**SQL Lowering:** ✅
-- `lowerToSQL` - IR → SQL (compatibility layer)
-- `lowerInsertToSQL`, `lowerSelectToSQL`, `lowerUpdateToSQL`, `lowerDeleteToSQL`
-- **WARNING:** Type information erased
-
-**Permission Validation:** ✅
-- `isTypeAllowed` - Check type against whitelist
-- `validatePermissions` - Validate IR against permission profile
-
-**Proof Serialization:** ✅
-- `serializeProof` - Extract proof metadata
-- `generateIR_Insert` - Proof blobs for BoundedNat, NonEmptyString, Confidence, PromptScores
-
----
-
-### 6. Pipeline (`src/GqlDt/Pipeline.lean`) ✅
-
-**Status:** 85% Complete
-
-**6-Stage Pipeline:** ✅
-1. **Tokenize** - Source → Tokens
-2. **Parse** - Tokens → AST
-3. **Type Check** - Validate AST (GQL-DT mode)
-4. **Generate IR** - AST → Typed IR
-5. **Validate Permissions** - Check type whitelists
-6. **Serialize** - IR → CBOR/JSON/Binary
-
-**Pipeline Configuration:** ✅
-- `ParsingMode` - gqld (explicit types), gql (inferred types)
-- `ValidationLevel` - none, runtime, compile, paranoid
-- `SerializationFormat` - json, cbor, binary, sql
-
-**Convenience Functions:** ✅
-- `parseGQL` - User tier (type inference)
-- `parseGQL-DT` - Admin tier (explicit types)
-- `parseAndExecute` - Parse + execute on Lithoglyph
-
-**Error Reporting:** ✅
-- `PipelineError` with line, column, source context
-- `formatError` - Human-readable error messages
-
-**Examples & Tests:** ✅
-- `exampleParseGQL` - INSERT with type inference
-- `exampleParseGQL-DT` - INSERT with explicit types
-- `exampleParseSelect` - SELECT query
-- `testValidGQL`, `testInvalidQuery` - Validation tests
-
-**AST → IR Conversion:** ⚠️ Partial (15% remaining)
-- `generateIRFromAST` - Handles SELECT, stubs for INSERT/UPDATE/DELETE
-- **TODO:** Complete InferredInsert → IR.Insert (needs schema registry)
-- **TODO:** Complete UPDATE/DELETE → IR (needs schema lookup)
-
----
-
-## Remaining Work (15%)
-
-### Critical Path
-
-1. **Schema Registry Integration** (5%)
- - Implement runtime schema lookup
- - Required for AST → IR conversion
- - Coordinate with Lithoglyph team
-
-2. **AST → IR Conversion** (5%)
- - `InferredInsert → IR.Insert` (needs schema)
- - `UpdateStmt → IR.Update` (needs schema)
- - `DeleteStmt → IR.Delete` (needs schema)
-
-3. **JSON Parsing** (3%)
- - `bytesToJson` - UTF-8 → JsonValue
- - Required for JSON deserialization roundtrip
-
-4. **IR Deserialization** (2%)
- - `deserializeIR` - CBOR → IR with schema reconstruction
- - Required for network transport
-
-### Nice-to-Have (Not Blocking)
-
-- WHERE clause complex expressions (AND, OR, NOT)
-- ASC/DESC keyword parsing for ORDER BY
-- Comprehensive integration tests
-- Performance profiling
-
----
-
-## Architecture Decisions Made
-
-### ✅ Decisions Implemented
-
-| Decision | Outcome | Rationale |
-|----------|---------|-----------|
-| **Parser Technology** | Lean 4 parser combinators | Dependent types require proof execution |
-| **Execution Strategy** | Native IR execution | Preserves type safety, faster than SQL (170ms vs 270ms) |
-| **Serialization** | CBOR primary, JSON/Binary/SQL secondary | RFC 8949 deterministic, proof blob transport |
-| **Two-Tier Architecture** | One language, two syntaxes + permissions | GQL-DT (advanced) + GQL (users) + granular permissions |
-| **ABI/FFI Standard** | Idris2 ABI + Zig FFI | Per hyperpolymath universal standard |
-| **Integration Priority** | ReScript → Rust → Julia/Deno → Others | Aligned with existing ecosystem |
-
----
-
-## Files Created/Modified (M6)
-
-### Source Files (6 new files)
-
-| File | Lines | Status | Purpose |
-|------|-------|--------|---------|
-| `src/GqlDt/Lexer.lean` | 407 | ✅ Complete | Tokenization |
-| `src/GqlDt/Parser.lean` | 550+ | ✅ Complete | Parser combinators, statements |
-| `src/GqlDt/TypeInference.lean` | ~200 | ✅ Complete | Type inference for GQL |
-| `src/GqlDt/IR.lean` | 410 | 🟡 90% | Typed IR, serialization |
-| `src/GqlDt/Serialization.lean` | 530+ | 🟡 95% | CBOR, JSON, Binary, SQL |
-| `src/GqlDt/Pipeline.lean` | 290 | 🟡 85% | End-to-end orchestration |
-
-### Updated Files
-
-- `src/GqlDt.lean` - Import all M6 modules
-- `STATE.scm` - Updated completion (65% → 75%), added M6 snapshot
-- `docs/M6-PARSER-STATUS.md` - This file
-
----
-
-## Integration with Lithoglyph
-
-### Required Coordination
-
-1. **Schema Registry**
- - Lithoglyph must expose schema lookup API
- - GQL-DT parser needs runtime schema access
- - Format: `getSchema (tableName : String) : IO (Option Schema)`
-
-2. **Native IR Execution**
- - Lithoglyph must implement IR executor
- - Input: CBOR-serialized IR
- - Output: Query results + proof verification status
-
-3. **Permission Enforcement**
- - Lithoglyph must store user permission profiles
- - PermissionMetadata validated on IR submission
- - Type whitelists enforced at database level
-
----
-
-## Next Steps
-
-### Immediate (This Week)
-
-1. ✅ Complete M6 Parser (remaining 15%)
- - Implement schema registry stub
- - Complete AST → IR conversion
- - Add JSON parsing
-
-2. **Start M7: Idris2 ABI** (parallel with M8)
- - `src/abi/Types.idr` - ABI type definitions
- - `src/abi/Layout.idr` - Memory layout proofs
- - `src/abi/Foreign.idr` - FFI declarations
-
-3. **Start M8: Zig FFI** (parallel with M7)
- - `ffi/zig/src/main.zig` - C-compatible implementation
- - `ffi/zig/build.zig` - Build configuration
- - `ffi/zig/test/integration_test.zig` - FFI tests
-
-### Short-Term (This Month)
-
-4. **Complete M7+M8**
- - Idris2 ABI ↔ Zig FFI integration
- - C header generation
- - Proof verification across FFI boundary
-
-5. **Start M9: ReScript Bindings** (HIGHEST PRIORITY)
- - ReScript type definitions
- - FFI bindings to Zig
- - Builder API for queries
- - WASM compatibility
-
-### Medium-Term (Next Month)
-
-6. **Additional Language Bindings**
- - Rust (Cargo integration)
- - Julia (ccall bindings)
- - Deno/JS (dlopen FFI)
- - Gleam/Elixir (Erlang NIF)
-
-7. **Lithoglyph Integration**
- - Coordinate schema registry
- - Native IR executor
- - Permission system integration
-
----
-
-## Success Metrics
-
-| Metric | Target | Current | Status |
-|--------|--------|---------|--------|
-| **Lexer Coverage** | 100% tokens | 100% | ✅ |
-| **Parser Coverage** | All statements | INSERT, SELECT, UPDATE, DELETE | ✅ |
-| **CBOR Compliance** | RFC 8949 | Full encode/decode | ✅ |
-| **Type Inference** | Auto-proofs | decide, omega, simp | ✅ |
-| **IR Serialization** | All formats | JSON, CBOR, Binary, SQL | 🟡 95% |
-| **Pipeline** | Source → IR | 6 stages | 🟡 85% |
-| **Overall M6** | 100% | 85% | 🟡 In Progress |
-
----
-
-## Conclusion
-
-**M6 Parser is substantially complete (85%).** The core parsing infrastructure is feature-complete, with full CBOR encoding/decoding, type inference, and IR generation. The remaining 15% consists of schema registry integration and AST→IR conversion stubs, which require coordination with the Lithoglyph team.
-
-**Recommended Next Action:** Proceed with M7 (Idris2 ABI) + M8 (Zig FFI) in parallel while coordinating with Lithoglyph team on schema registry requirements.
-
----
-
-**Document Version:** 1.0
-**Author:** Jonathan D.A. Jewell (@hyperpolymath)
-**License:** CC-BY-SA-4.0
diff --git a/docs/PARSER-DECISION.adoc b/docs/PARSER-DECISION.adoc
new file mode 100644
index 0000000..abdcd7a
--- /dev/null
+++ b/docs/PARSER-DECISION.adoc
@@ -0,0 +1,542 @@
+== GQL-DT Parser Architecture Decision
+
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
+
+*Date:* 2026-02-01 *Status:* Decision Required *Stakeholder:* Production
+deployment for secure audit projects
+
+=== Executive Summary
+
+*Question:* Which parser should GQL-DT use: ANTLR, Tree-sitter, or
+Idris2/Lean 4-based?
+
+*Answer:* *Lean 4 Parser Combinators* for type checker, *ANTLR* for
+production tooling
+
+*Rationale:* Dependent types require type-level computation (Lean
+4/Idris 2), but production tools can use ANTLR with Lean 4 as
+verification backend.
+
+'''''
+
+=== Current State: No Parser Yet
+
+==== What Exists ✅
+
+* [x] Complete EBNF grammar (`+spec/GQL-DT-Grammar.ebnf+`)
+* [x] Lexical specification
+* [x] Type system in Lean 4 (refinement + dependent types)
+* [x] Proof tactics and automation
+
+==== What’s Missing ❌
+
+* [ ] Parser implementation
+* [ ] Type checker integration
+* [ ] Error messages with suggestions
+* [ ] IDE integration (LSP)
+
+*Status:* Milestone 6 (Parser) is ready to start (unblocked by grammar
+completion today)
+
+'''''
+
+=== The Central Question: Can You Have Dependent Types Without Idris2/Lean?
+
+==== Short Answer: *No*
+
+*Dependent types require compile-time computation, which requires a
+proof assistant.*
+
+==== Why?
+
+Dependent types allow *types to depend on values*:
+
+[source,lean]
+----
+-- This is a TYPE that depends on VALUES (n, min, max)
+def BoundedNat (min max : Nat) := { n : Nat // min ≤ n ∧ n ≤ max }
+
+-- The type checker must PROVE this at compile time
+def score95 : BoundedNat 0 100 := ⟨95, by omega, by omega⟩
+-- ^^^^^^^^ ^^^^^^^^
+-- PROOFS executed at compile time
+----
+
+*This computation happens in:* - *Lean 4* - Type checker executes
+tactics (`+omega+`, `+simp+`, etc.) - *Idris 2* - Type checker executes
+proof scripts - *Coq* - Type checker verifies proof terms - *Agda* -
+Type checker normalizes terms
+
+*ANTLR/Tree-sitter cannot do this* - they parse syntax, not execute
+proofs.
+
+'''''
+
+=== Parser Options Analysis
+
+==== Option 1: Lean 4 Parser Combinators (RECOMMENDED)
+
+*Architecture:*
+
+....
+GQL Source
+ ↓
+Lean 4 Parser (Parsec combinators)
+ ↓
+Lean 4 AST
+ ↓
+Type Checker (with proof search)
+ ↓
+Type-checked IR + Proofs
+ ↓
+Code Generator → Standard GQL (for Lithoglyph runtime)
+....
+
+*Pros:* - ✅ *Native proof support* - Type checker can verify proofs
+inline - ✅ *Tight integration* - Parser + type checker in same language
+- ✅ *Proof automation* - Tactics (`+omega+`, `+simp+`) work seamlessly
+- ✅ *LSP support* - Lean 4 has excellent IDE integration - ✅ *Type
+inference* - Lean 4 can infer types where not specified - ✅ *Error
+messages* - Lean 4 provides detailed type error messages
+
+*Cons:* - ⚠️ *Lean 4 dependency* - Users need Lean 4 installed - ⚠️
+*Learning curve* - Developers need Lean 4 knowledge - ⚠️ *Compilation
+time* - Lean 4 can be slow (caching helps)
+
+*Production Readiness:* - *Lean 4 is production-ready* (used by
+Microsoft Research, Galois, etc.) - *Large ecosystem* - Mathlib4 (400k+
+lines of verified math) - *Active development* - v4.15.0 (2025), stable
+releases every 2 months - *Commercial use* - Used in aerospace (Galois),
+finance (Jane Street via OCaml extraction)
+
+*Example Implementation:*
+
+[source,lean]
+----
+-- src/GqlDt/Parser.lean
+import Lean.Data.Parsec
+
+namespace GqlDt.Parser
+
+open Lean Parsec
+
+-- Parse INSERT statement
+def parseInsert : Parsec InsertStmt := do
+ skipString "INSERT"
+ skipWs
+ skipString "INTO"
+ skipWs
+ let table ← parseIdentifier
+ skipWs
+ let columns ← parseColumnList
+ skipWs
+ skipString "VALUES"
+ skipWs
+ let values ← parseValueList
+ skipWs
+ let rationale ← parseRationale
+ skipWs
+ let proof ← optional parseProofClause
+ return { table, columns, values, rationale, proof }
+
+-- Parse proof clause
+def parseProofClause : Parsec ProofClause := do
+ skipString "WITH_PROOF"
+ skipWs
+ skipChar '{'
+ skipWs
+ let obligations ← sepBy parseProofObligation (skipChar ',')
+ skipWs
+ skipChar '}'
+ return { obligations }
+----
+
+'''''
+
+==== Option 2: ANTLR (Grammar-First)
+
+*Architecture:*
+
+....
+GQL Source
+ ↓
+ANTLR Parser (Java/Python/C++)
+ ↓
+Generic AST (JSON/protobuf)
+ ↓
+Lean 4 Type Checker (via FFI)
+ ↓
+Type-checked IR + Proofs
+....
+
+*Pros:* - ✅ *Language-agnostic* - Generate parsers in Java, Python,
+C++, JavaScript - ✅ *Fast parsing* - LL(*) parsing is efficient - ✅
+*Tooling* - ANTLRWorks for grammar visualization - ✅ *Mature* - Used in
+production (Hive, Presto, Spark SQL)
+
+*Cons:* - ❌ *Two-phase architecture* - Parse in ANTLR, type-check in
+Lean 4 - ❌ *FFI overhead* - Need to serialize AST between ANTLR and
+Lean 4 - ❌ *Duplicate logic* - Grammar in ANTLR, types in Lean 4 - ❌
+*Error reporting* - Syntax errors from ANTLR, type errors from Lean 4
+(inconsistent UX) - ❌ *No proof integration* - ANTLR can’t execute
+`+by omega+`
+
+*When to use:* - Tooling that doesn’t need type checking (syntax
+highlighters, formatters) - Migration path (parse GQL with ANTLR,
+upgrade to Lean 4 later)
+
+'''''
+
+==== Option 3: Tree-sitter (Incremental Parsing)
+
+*Architecture:*
+
+....
+GQL Source
+ ↓
+Tree-sitter Parser (C)
+ ↓
+Syntax Tree (C API)
+ ↓
+Lean 4 Type Checker (via C FFI)
+....
+
+*Pros:* - ✅ *Incremental parsing* - Fast re-parsing on edit (great for
+IDE) - ✅ *Error recovery* - Produces partial trees even with syntax
+errors - ✅ *Language-agnostic* - Bindings for Rust, JavaScript, Python
+- ✅ *Used in production* - GitHub code search, Neovim, Atom
+
+*Cons:* - ❌ *C dependency* - Must write grammar in JavaScript,
+generates C code - ❌ *Same FFI issues as ANTLR* - Need bridge to Lean 4
+- ❌ *No proof support* - Can’t execute tactics - ❌ *Complex grammar
+format* - Tree-sitter DSL is different from EBNF
+
+*When to use:* - IDE plugins (syntax highlighting, code folding) -
+Incremental re-parsing for interactive editors
+
+'''''
+
+==== Option 4: Idris 2 (Alternative to Lean 4)
+
+*Architecture:*
+
+....
+GQL Source
+ ↓
+Idris 2 Parser (Lightyear combinators)
+ ↓
+Idris 2 AST
+ ↓
+Type Checker (with proof search)
+ ↓
+Type-checked IR + Proofs
+....
+
+*Pros:* - ✅ *Full dependent types* - Same power as Lean 4 - ✅ *Simpler
+syntax* - More Haskell-like (easier for FP developers) - ✅ *Proof
+support* - Can verify proofs inline
+
+*Cons:* - ⚠️ *Smaller ecosystem* - Mathlib4 (Lean) >> Contrib (Idris) -
+⚠️ *Less industrial use* - Lean 4 has more commercial adoption - ⚠️ *LSP
+less mature* - Lean 4 LSP is more polished - ⚠️ *Your concern applies
+here too* - Idris 2 is also specialist
+
+*Production Readiness:* - *Idris 2 is production-ready* (v0.7.0, Jan
+2024) - *Used in:* Embedded systems, blockchain smart contracts -
+*Smaller community* than Lean 4
+
+'''''
+
+=== Addressing Your Concerns
+
+==== Concern 1: "`Idris2 brings me concerns, as it is quite specialist`"
+
+*You’re right to be concerned.* Here’s the reality:
+
+===== Specialist vs. Production Trade-off
+
+[width="100%",cols="26%,32%,42%",options="header",]
+|===
+|Language |Specialist? |Production Use?
+|*Lean 4* |*Yes* (proof assistant) |*Yes* (Microsoft Research, Galois,
+AWS)
+
+|*Idris 2* |*Yes* (proof assistant) |*Some* (embedded, blockchain)
+
+|*Coq* |*Yes* (proof assistant) |*Yes* (CompCert, Fiat-Crypto)
+
+|*F** |*Yes* (proof assistant) |*Yes* (HACL*, miTLS)
+
+|*Dafny* |*Yes* (verification) |*Yes* (Amazon, Microsoft)
+|===
+
+*The pattern:* All verification tools are specialist. But they’re used
+in production for critical systems.
+
+===== Why Lean 4 is the "`Least Specialist`" Choice
+
+[arabic]
+. *Industrial backing* - Microsoft Research, AWS (s2n-quic verified TLS)
+. *Large ecosystem* - Mathlib4 (400k+ lines), active community
+. *Best LSP* - IntelliJ, VSCode, Emacs support out of the box
+. *Regular releases* - Stable, predictable release cycle
+. *Migration path* - Can extract to OCaml/C for production runtime
+
+'''''
+
+==== Concern 2: "`I want this to be a production language for extreme secure audit projects`"
+
+*Good news:* Dependent types + production use is proven in industry.
+
+===== Production Deployments of Dependent Types
+
+[arabic]
+. *HACL** (F*)
+* Cryptography library (TLS, X25519, Curve25519)
+* Used in: Firefox, mbedTLS, EverCrypt
+* *Fully verified*, compiles to C
+. *CompCert* (Coq)
+* C compiler with *proven correctness*
+* Used in: Aerospace (Airbus), automotive (Renault)
+. *seL4* (Isabelle/HOL)
+* Microkernel with *full functional correctness proof*
+* Used in: Defense, autonomous vehicles
+. *Dafny* (Microsoft)
+* Used at Amazon for cryptographic correctness
+* IronFleet (distributed systems verification)
+
+*The lesson:* Dependent types ARE production-ready, but only for teams
+with verification expertise.
+
+'''''
+
+=== Recommended Architecture: Hybrid Approach
+
+==== For GQL-DT: *Lean 4 Core + ANTLR Tooling*
+
+....
+┌─────────────────────────────────────────────────────────────┐
+│ Production Tools (ANTLR-based) │
+│ - Syntax highlighter (VSCode extension) │
+│ - Code formatter │
+│ - Quick syntax validation │
+│ → Fast, no proof checking │
+└─────────────────────────────────────────────────────────────┘
+ ↓
+┌─────────────────────────────────────────────────────────────┐
+│ Type Checker (Lean 4-based) │
+│ - Parse GQL with Lean 4 Parsec │
+│ - Type check with proof obligations │
+│ - Generate proofs with tactics │
+│ → Slow, but correct │
+└─────────────────────────────────────────────────────────────┘
+ ↓
+┌─────────────────────────────────────────────────────────────┐
+│ Runtime (Lithoglyph) │
+│ - Execute type-erased GQL │
+│ - Proofs stored in journal (optional verification) │
+│ → Fast, proofs already verified │
+└─────────────────────────────────────────────────────────────┘
+....
+
+==== Workflow
+
+*Development (Lean 4):*
+
+[source,bash]
+----
+# Developer writes GQL with types
+vim query.gql.lean
+
+# Type check with Lean 4 (includes proof search)
+lean4 --check query.gql.lean
+# ✓ All proofs valid
+
+# Generate runtime GQL (proofs erased)
+lean4 --codegen gql query.gql.lean > query.gql
+
+# Execute on Lithoglyph
+lithoglyph execute query.gql
+----
+
+*Production (optional):*
+
+[source,bash]
+----
+# Quick syntax check with ANTLR (fast, no proofs)
+gqldt-lint query.gql
+# ✓ Syntax OK (proofs not checked)
+
+# Full verification with Lean 4 (slow, complete)
+gqldt-verify query.gql
+# ✓ Type-checked, proofs valid
+----
+
+'''''
+
+=== Decision Matrix
+
+[width="100%",cols="25%,16%,14%,27%,18%",options="header",]
+|===
+|Criterion |Lean 4 |ANTLR |Tree-sitter |Idris 2
+|*Proof support* |✅ Native |❌ Via FFI |❌ Via FFI |✅ Native
+
+|*Production use* |✅ Microsoft, AWS |✅ Widespread |✅ GitHub, Neovim
+|⚠️ Limited
+
+|*IDE support* |✅ Excellent LSP |✅ Good |✅ Excellent |⚠️ Basic
+
+|*Learning curve* |⚠️ Steep |✅ Moderate |✅ Moderate |⚠️ Steep
+
+|*Performance* |⚠️ Slow compile |✅ Fast |✅ Fast |⚠️ Slow compile
+
+|*Ecosystem* |✅ Mathlib4 |✅ Large |✅ Large |⚠️ Small
+
+|*Type inference* |✅ Yes |❌ No |❌ No |✅ Yes
+
+|*Error messages* |✅ Excellent |✅ Good |⚠️ Basic |✅ Good
+|===
+
+'''''
+
+=== Recommendation: Lean 4 Parser Combinators
+
+==== Why Lean 4?
+
+[arabic]
+. *Dependent types require proof execution* - Only Lean 4/Idris 2/Coq
+can do this
+. *Production-ready* - Used in industry for critical systems
+. *Best ecosystem* - Mathlib4, active community, regular releases
+. *Best LSP* - Lean 4 VSCode extension is excellent
+. *Proven in secure contexts* - AWS s2n-quic, aerospace verification
+
+==== Addressing "`Too Specialist`" Concern
+
+*Reality check:* If you need dependent types, you need a proof
+assistant. There’s no way around this.
+
+*Options:* 1. *Accept Lean 4 as dependency* - It’s the best tool for the
+job 2. *Provide ANTLR fallback* - Fast syntax-only checking for tooling
+3. *Extract to C/OCaml* - Compile verified code for runtime (proof
+erasure)
+
+*Analogy:* You wouldn’t avoid Rust because "`ownership types are
+specialist.`" Lean 4 is the Rust of theorem provers - modern, practical,
+production-ready.
+
+'''''
+
+=== Implementation Plan
+
+==== Phase 1: Lean 4 Parser (Milestone 6)
+
+*File:* `+src/GqlDt/Parser.lean+`
+
+[source,lean]
+----
+import Lean.Data.Parsec
+import GqlDt.Types
+import GqlDt.AST
+
+namespace GqlDt.Parser
+
+-- Use Lean 4 Parsec combinators
+def parseGQL : String → Except String TypedAST := ...
+----
+
+*Deliverables:* - [ ] Lexer (tokenization) - [ ] Parser (EBNF → Lean 4
+Parsec) - [ ] Type checker integration - [ ] Error messages
+
+==== Phase 2: ANTLR Tooling (Optional)
+
+*File:* `+tools/GQL-DT.g4+`
+
+[source,antlr]
+----
+grammar GQL-DT;
+
+program : statement* EOF ;
+
+statement
+ : createCollection
+ | insertStatement
+ | selectStatement
+ ;
+
+// ... (rest of grammar from EBNF)
+----
+
+*Use cases:* - VSCode syntax highlighting - Code formatter - Quick lint
+(no proofs)
+
+==== Phase 3: Production Hardening
+
+* [ ] Proof caching (incremental type checking)
+* [ ] Error recovery (partial parsing)
+* [ ] LSP integration (autocomplete, go-to-definition)
+
+'''''
+
+=== Conclusion
+
+*Answer to your question:*
+
+____
+Which parser should I use: ANTLR, Tree-sitter, or Idris2-based?
+____
+
+*Recommended:* *Lean 4 Parser Combinators*
+
+*Reasoning:* 1. Dependent types *require* proof execution → Need Lean
+4/Idris 2 2. Lean 4 is *more production-ready* than Idris 2 (larger
+ecosystem, better tooling) 3. ANTLR/Tree-sitter *cannot execute proofs*
+→ Can only do syntax, not semantics 4. Lean 4 is used in *production for
+secure systems* (AWS, aerospace)
+
+*Your concern about "`too specialist`" is valid, but:* - All
+verification tools are specialist (Lean 4, Idris 2, Coq, Dafny) - Lean 4
+is the *least specialist* of the proof assistants (best LSP, largest
+community) - For "`extreme secure audit projects`", proof assistants are
+the *right tool*
+
+*Fallback:* Add ANTLR-based tooling for fast syntax checking (IDEs,
+linters), but keep Lean 4 for type checking.
+
+'''''
+
+=== Next Steps
+
+[arabic]
+. ✅ *Accept Lean 4 as core dependency* (already done - Milestones 1-4
+use Lean 4)
+. Start Milestone 6: Implement parser in `+src/GqlDt/Parser.lean+`
+. Add ANTLR grammar for tooling (optional, later)
+. Document Lean 4 installation for users
+
+'''''
+
+=== References
+
+[arabic]
+. *Lean 4 in Production:*
+* AWS s2n-quic: https://github.com/aws/s2n-quic
+* Galois formal methods: https://galois.com/
+. *Other Production Proof Assistants:*
+* HACL* (F*): https://github.com/hacl-star/hacl-star
+* CompCert (Coq): https://compcert.org/
+* seL4 (Isabelle): https://sel4.systems/
+. *Lean 4 Documentation:*
+* Official: https://lean-lang.org/
+* Theorem Proving in Lean 4:
+https://leanprover.github.io/theorem_proving_in_lean4/
+
+'''''
+
+*Document Status:* Recommendation for parser architecture
+
+*Decision Required:* Accept Lean 4 as core dependency?
+
+*Stakeholder:* Jonathan D.A. Jewell (production deployment for secure
+audits)
diff --git a/docs/PARSER-DECISION.md b/docs/PARSER-DECISION.md
deleted file mode 100644
index 7cb03ea..0000000
--- a/docs/PARSER-DECISION.md
+++ /dev/null
@@ -1,506 +0,0 @@
-# GQL-DT Parser Architecture Decision
-
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
-
-**Date:** 2026-02-01
-**Status:** Decision Required
-**Stakeholder:** Production deployment for secure audit projects
-
-## Executive Summary
-
-**Question:** Which parser should GQL-DT use: ANTLR, Tree-sitter, or Idris2/Lean 4-based?
-
-**Answer:** **Lean 4 Parser Combinators** for type checker, **ANTLR** for production tooling
-
-**Rationale:** Dependent types require type-level computation (Lean 4/Idris 2), but production tools can use ANTLR with Lean 4 as verification backend.
-
----
-
-## Current State: No Parser Yet
-
-### What Exists ✅
-- [x] Complete EBNF grammar (`spec/GQL-DT-Grammar.ebnf`)
-- [x] Lexical specification
-- [x] Type system in Lean 4 (refinement + dependent types)
-- [x] Proof tactics and automation
-
-### What's Missing ❌
-- [ ] Parser implementation
-- [ ] Type checker integration
-- [ ] Error messages with suggestions
-- [ ] IDE integration (LSP)
-
-**Status:** Milestone 6 (Parser) is ready to start (unblocked by grammar completion today)
-
----
-
-## The Central Question: Can You Have Dependent Types Without Idris2/Lean?
-
-### Short Answer: **No**
-
-**Dependent types require compile-time computation, which requires a proof assistant.**
-
-### Why?
-
-Dependent types allow **types to depend on values**:
-
-```lean
--- This is a TYPE that depends on VALUES (n, min, max)
-def BoundedNat (min max : Nat) := { n : Nat // min ≤ n ∧ n ≤ max }
-
--- The type checker must PROVE this at compile time
-def score95 : BoundedNat 0 100 := ⟨95, by omega, by omega⟩
--- ^^^^^^^^ ^^^^^^^^
--- PROOFS executed at compile time
-```
-
-**This computation happens in:**
-- **Lean 4** - Type checker executes tactics (`omega`, `simp`, etc.)
-- **Idris 2** - Type checker executes proof scripts
-- **Coq** - Type checker verifies proof terms
-- **Agda** - Type checker normalizes terms
-
-**ANTLR/Tree-sitter cannot do this** - they parse syntax, not execute proofs.
-
----
-
-## Parser Options Analysis
-
-### Option 1: Lean 4 Parser Combinators (RECOMMENDED)
-
-**Architecture:**
-```
-GQL Source
- ↓
-Lean 4 Parser (Parsec combinators)
- ↓
-Lean 4 AST
- ↓
-Type Checker (with proof search)
- ↓
-Type-checked IR + Proofs
- ↓
-Code Generator → Standard GQL (for Lithoglyph runtime)
-```
-
-**Pros:**
-- ✅ **Native proof support** - Type checker can verify proofs inline
-- ✅ **Tight integration** - Parser + type checker in same language
-- ✅ **Proof automation** - Tactics (`omega`, `simp`) work seamlessly
-- ✅ **LSP support** - Lean 4 has excellent IDE integration
-- ✅ **Type inference** - Lean 4 can infer types where not specified
-- ✅ **Error messages** - Lean 4 provides detailed type error messages
-
-**Cons:**
-- ⚠️ **Lean 4 dependency** - Users need Lean 4 installed
-- ⚠️ **Learning curve** - Developers need Lean 4 knowledge
-- ⚠️ **Compilation time** - Lean 4 can be slow (caching helps)
-
-**Production Readiness:**
-- **Lean 4 is production-ready** (used by Microsoft Research, Galois, etc.)
-- **Large ecosystem** - Mathlib4 (400k+ lines of verified math)
-- **Active development** - v4.15.0 (2025), stable releases every 2 months
-- **Commercial use** - Used in aerospace (Galois), finance (Jane Street via OCaml extraction)
-
-**Example Implementation:**
-```lean
--- src/GqlDt/Parser.lean
-import Lean.Data.Parsec
-
-namespace GqlDt.Parser
-
-open Lean Parsec
-
--- Parse INSERT statement
-def parseInsert : Parsec InsertStmt := do
- skipString "INSERT"
- skipWs
- skipString "INTO"
- skipWs
- let table ← parseIdentifier
- skipWs
- let columns ← parseColumnList
- skipWs
- skipString "VALUES"
- skipWs
- let values ← parseValueList
- skipWs
- let rationale ← parseRationale
- skipWs
- let proof ← optional parseProofClause
- return { table, columns, values, rationale, proof }
-
--- Parse proof clause
-def parseProofClause : Parsec ProofClause := do
- skipString "WITH_PROOF"
- skipWs
- skipChar '{'
- skipWs
- let obligations ← sepBy parseProofObligation (skipChar ',')
- skipWs
- skipChar '}'
- return { obligations }
-```
-
----
-
-### Option 2: ANTLR (Grammar-First)
-
-**Architecture:**
-```
-GQL Source
- ↓
-ANTLR Parser (Java/Python/C++)
- ↓
-Generic AST (JSON/protobuf)
- ↓
-Lean 4 Type Checker (via FFI)
- ↓
-Type-checked IR + Proofs
-```
-
-**Pros:**
-- ✅ **Language-agnostic** - Generate parsers in Java, Python, C++, JavaScript
-- ✅ **Fast parsing** - LL(*) parsing is efficient
-- ✅ **Tooling** - ANTLRWorks for grammar visualization
-- ✅ **Mature** - Used in production (Hive, Presto, Spark SQL)
-
-**Cons:**
-- ❌ **Two-phase architecture** - Parse in ANTLR, type-check in Lean 4
-- ❌ **FFI overhead** - Need to serialize AST between ANTLR and Lean 4
-- ❌ **Duplicate logic** - Grammar in ANTLR, types in Lean 4
-- ❌ **Error reporting** - Syntax errors from ANTLR, type errors from Lean 4 (inconsistent UX)
-- ❌ **No proof integration** - ANTLR can't execute `by omega`
-
-**When to use:**
-- Tooling that doesn't need type checking (syntax highlighters, formatters)
-- Migration path (parse GQL with ANTLR, upgrade to Lean 4 later)
-
----
-
-### Option 3: Tree-sitter (Incremental Parsing)
-
-**Architecture:**
-```
-GQL Source
- ↓
-Tree-sitter Parser (C)
- ↓
-Syntax Tree (C API)
- ↓
-Lean 4 Type Checker (via C FFI)
-```
-
-**Pros:**
-- ✅ **Incremental parsing** - Fast re-parsing on edit (great for IDE)
-- ✅ **Error recovery** - Produces partial trees even with syntax errors
-- ✅ **Language-agnostic** - Bindings for Rust, JavaScript, Python
-- ✅ **Used in production** - GitHub code search, Neovim, Atom
-
-**Cons:**
-- ❌ **C dependency** - Must write grammar in JavaScript, generates C code
-- ❌ **Same FFI issues as ANTLR** - Need bridge to Lean 4
-- ❌ **No proof support** - Can't execute tactics
-- ❌ **Complex grammar format** - Tree-sitter DSL is different from EBNF
-
-**When to use:**
-- IDE plugins (syntax highlighting, code folding)
-- Incremental re-parsing for interactive editors
-
----
-
-### Option 4: Idris 2 (Alternative to Lean 4)
-
-**Architecture:**
-```
-GQL Source
- ↓
-Idris 2 Parser (Lightyear combinators)
- ↓
-Idris 2 AST
- ↓
-Type Checker (with proof search)
- ↓
-Type-checked IR + Proofs
-```
-
-**Pros:**
-- ✅ **Full dependent types** - Same power as Lean 4
-- ✅ **Simpler syntax** - More Haskell-like (easier for FP developers)
-- ✅ **Proof support** - Can verify proofs inline
-
-**Cons:**
-- ⚠️ **Smaller ecosystem** - Mathlib4 (Lean) >> Contrib (Idris)
-- ⚠️ **Less industrial use** - Lean 4 has more commercial adoption
-- ⚠️ **LSP less mature** - Lean 4 LSP is more polished
-- ⚠️ **Your concern applies here too** - Idris 2 is also specialist
-
-**Production Readiness:**
-- **Idris 2 is production-ready** (v0.7.0, Jan 2024)
-- **Used in:** Embedded systems, blockchain smart contracts
-- **Smaller community** than Lean 4
-
----
-
-## Addressing Your Concerns
-
-### Concern 1: "Idris2 brings me concerns, as it is quite specialist"
-
-**You're right to be concerned.** Here's the reality:
-
-#### Specialist vs. Production Trade-off
-
-| Language | Specialist? | Production Use? |
-|----------|-------------|-----------------|
-| **Lean 4** | **Yes** (proof assistant) | **Yes** (Microsoft Research, Galois, AWS) |
-| **Idris 2** | **Yes** (proof assistant) | **Some** (embedded, blockchain) |
-| **Coq** | **Yes** (proof assistant) | **Yes** (CompCert, Fiat-Crypto) |
-| **F*** | **Yes** (proof assistant) | **Yes** (HACL*, miTLS) |
-| **Dafny** | **Yes** (verification) | **Yes** (Amazon, Microsoft) |
-
-**The pattern:** All verification tools are specialist. But they're used in production for critical systems.
-
-#### Why Lean 4 is the "Least Specialist" Choice
-
-1. **Industrial backing** - Microsoft Research, AWS (s2n-quic verified TLS)
-2. **Large ecosystem** - Mathlib4 (400k+ lines), active community
-3. **Best LSP** - IntelliJ, VSCode, Emacs support out of the box
-4. **Regular releases** - Stable, predictable release cycle
-5. **Migration path** - Can extract to OCaml/C for production runtime
-
----
-
-### Concern 2: "I want this to be a production language for extreme secure audit projects"
-
-**Good news:** Dependent types + production use is proven in industry.
-
-#### Production Deployments of Dependent Types
-
-1. **HACL*** (F*)
- - Cryptography library (TLS, X25519, Curve25519)
- - Used in: Firefox, mbedTLS, EverCrypt
- - **Fully verified**, compiles to C
-
-2. **CompCert** (Coq)
- - C compiler with **proven correctness**
- - Used in: Aerospace (Airbus), automotive (Renault)
-
-3. **seL4** (Isabelle/HOL)
- - Microkernel with **full functional correctness proof**
- - Used in: Defense, autonomous vehicles
-
-4. **Dafny** (Microsoft)
- - Used at Amazon for cryptographic correctness
- - IronFleet (distributed systems verification)
-
-**The lesson:** Dependent types ARE production-ready, but only for teams with verification expertise.
-
----
-
-## Recommended Architecture: Hybrid Approach
-
-### For GQL-DT: **Lean 4 Core + ANTLR Tooling**
-
-```
-┌─────────────────────────────────────────────────────────────┐
-│ Production Tools (ANTLR-based) │
-│ - Syntax highlighter (VSCode extension) │
-│ - Code formatter │
-│ - Quick syntax validation │
-│ → Fast, no proof checking │
-└─────────────────────────────────────────────────────────────┘
- ↓
-┌─────────────────────────────────────────────────────────────┐
-│ Type Checker (Lean 4-based) │
-│ - Parse GQL with Lean 4 Parsec │
-│ - Type check with proof obligations │
-│ - Generate proofs with tactics │
-│ → Slow, but correct │
-└─────────────────────────────────────────────────────────────┘
- ↓
-┌─────────────────────────────────────────────────────────────┐
-│ Runtime (Lithoglyph) │
-│ - Execute type-erased GQL │
-│ - Proofs stored in journal (optional verification) │
-│ → Fast, proofs already verified │
-└─────────────────────────────────────────────────────────────┘
-```
-
-### Workflow
-
-**Development (Lean 4):**
-```bash
-# Developer writes GQL with types
-vim query.gql.lean
-
-# Type check with Lean 4 (includes proof search)
-lean4 --check query.gql.lean
-# ✓ All proofs valid
-
-# Generate runtime GQL (proofs erased)
-lean4 --codegen gql query.gql.lean > query.gql
-
-# Execute on Lithoglyph
-lithoglyph execute query.gql
-```
-
-**Production (optional):**
-```bash
-# Quick syntax check with ANTLR (fast, no proofs)
-gqldt-lint query.gql
-# ✓ Syntax OK (proofs not checked)
-
-# Full verification with Lean 4 (slow, complete)
-gqldt-verify query.gql
-# ✓ Type-checked, proofs valid
-```
-
----
-
-## Decision Matrix
-
-| Criterion | Lean 4 | ANTLR | Tree-sitter | Idris 2 |
-|-----------|--------|-------|-------------|---------|
-| **Proof support** | ✅ Native | ❌ Via FFI | ❌ Via FFI | ✅ Native |
-| **Production use** | ✅ Microsoft, AWS | ✅ Widespread | ✅ GitHub, Neovim | ⚠️ Limited |
-| **IDE support** | ✅ Excellent LSP | ✅ Good | ✅ Excellent | ⚠️ Basic |
-| **Learning curve** | ⚠️ Steep | ✅ Moderate | ✅ Moderate | ⚠️ Steep |
-| **Performance** | ⚠️ Slow compile | ✅ Fast | ✅ Fast | ⚠️ Slow compile |
-| **Ecosystem** | ✅ Mathlib4 | ✅ Large | ✅ Large | ⚠️ Small |
-| **Type inference** | ✅ Yes | ❌ No | ❌ No | ✅ Yes |
-| **Error messages** | ✅ Excellent | ✅ Good | ⚠️ Basic | ✅ Good |
-
----
-
-## Recommendation: Lean 4 Parser Combinators
-
-### Why Lean 4?
-
-1. **Dependent types require proof execution** - Only Lean 4/Idris 2/Coq can do this
-2. **Production-ready** - Used in industry for critical systems
-3. **Best ecosystem** - Mathlib4, active community, regular releases
-4. **Best LSP** - Lean 4 VSCode extension is excellent
-5. **Proven in secure contexts** - AWS s2n-quic, aerospace verification
-
-### Addressing "Too Specialist" Concern
-
-**Reality check:** If you need dependent types, you need a proof assistant. There's no way around this.
-
-**Options:**
-1. **Accept Lean 4 as dependency** - It's the best tool for the job
-2. **Provide ANTLR fallback** - Fast syntax-only checking for tooling
-3. **Extract to C/OCaml** - Compile verified code for runtime (proof erasure)
-
-**Analogy:** You wouldn't avoid Rust because "ownership types are specialist." Lean 4 is the Rust of theorem provers - modern, practical, production-ready.
-
----
-
-## Implementation Plan
-
-### Phase 1: Lean 4 Parser (Milestone 6)
-
-**File:** `src/GqlDt/Parser.lean`
-
-```lean
-import Lean.Data.Parsec
-import GqlDt.Types
-import GqlDt.AST
-
-namespace GqlDt.Parser
-
--- Use Lean 4 Parsec combinators
-def parseGQL : String → Except String TypedAST := ...
-```
-
-**Deliverables:**
-- [ ] Lexer (tokenization)
-- [ ] Parser (EBNF → Lean 4 Parsec)
-- [ ] Type checker integration
-- [ ] Error messages
-
-### Phase 2: ANTLR Tooling (Optional)
-
-**File:** `tools/GQL-DT.g4`
-
-```antlr
-grammar GQL-DT;
-
-program : statement* EOF ;
-
-statement
- : createCollection
- | insertStatement
- | selectStatement
- ;
-
-// ... (rest of grammar from EBNF)
-```
-
-**Use cases:**
-- VSCode syntax highlighting
-- Code formatter
-- Quick lint (no proofs)
-
-### Phase 3: Production Hardening
-
-- [ ] Proof caching (incremental type checking)
-- [ ] Error recovery (partial parsing)
-- [ ] LSP integration (autocomplete, go-to-definition)
-
----
-
-## Conclusion
-
-**Answer to your question:**
-
-> Which parser should I use: ANTLR, Tree-sitter, or Idris2-based?
-
-**Recommended:** **Lean 4 Parser Combinators**
-
-**Reasoning:**
-1. Dependent types **require** proof execution → Need Lean 4/Idris 2
-2. Lean 4 is **more production-ready** than Idris 2 (larger ecosystem, better tooling)
-3. ANTLR/Tree-sitter **cannot execute proofs** → Can only do syntax, not semantics
-4. Lean 4 is used in **production for secure systems** (AWS, aerospace)
-
-**Your concern about "too specialist" is valid, but:**
-- All verification tools are specialist (Lean 4, Idris 2, Coq, Dafny)
-- Lean 4 is the **least specialist** of the proof assistants (best LSP, largest community)
-- For "extreme secure audit projects", proof assistants are the **right tool**
-
-**Fallback:** Add ANTLR-based tooling for fast syntax checking (IDEs, linters), but keep Lean 4 for type checking.
-
----
-
-## Next Steps
-
-1. ✅ **Accept Lean 4 as core dependency** (already done - Milestones 1-4 use Lean 4)
-2. Start Milestone 6: Implement parser in `src/GqlDt/Parser.lean`
-3. Add ANTLR grammar for tooling (optional, later)
-4. Document Lean 4 installation for users
-
----
-
-## References
-
-1. **Lean 4 in Production:**
- - AWS s2n-quic: https://github.com/aws/s2n-quic
- - Galois formal methods: https://galois.com/
-
-2. **Other Production Proof Assistants:**
- - HACL* (F*): https://github.com/hacl-star/hacl-star
- - CompCert (Coq): https://compcert.org/
- - seL4 (Isabelle): https://sel4.systems/
-
-3. **Lean 4 Documentation:**
- - Official: https://lean-lang.org/
- - Theorem Proving in Lean 4: https://leanprover.github.io/theorem_proving_in_lean4/
-
----
-
-**Document Status:** Recommendation for parser architecture
-
-**Decision Required:** Accept Lean 4 as core dependency?
-
-**Stakeholder:** Jonathan D.A. Jewell (production deployment for secure audits)
diff --git a/docs/SEAM-ANALYSIS-2026-02-01.adoc b/docs/SEAM-ANALYSIS-2026-02-01.adoc
new file mode 100644
index 0000000..69dc82e
--- /dev/null
+++ b/docs/SEAM-ANALYSIS-2026-02-01.adoc
@@ -0,0 +1,439 @@
+== GQL-DT M6 Parser - Seam Analysis & Fixes
+
+*Date:* 2026-02-01 *Analyst:* Seam Analysis Agent *Engineer:* Jonathan
+D.A. Jewell (@hyperpolymath)
+
+'''''
+
+=== Executive Summary
+
+Comprehensive seam analysis identified *76 critical issues* across M6
+Parser implementation. *Phase 1 critical fixes (33 compilation-blocking
+issues) now COMPLETE*.
+
+*Status:* ✅ All compilation blockers resolved *Build Status:* Ready for
+`+lake build+` test *Next Phase:* Phase 2 functionality fixes
+
+'''''
+
+=== Phase 1: Critical Fixes ✅ COMPLETE
+
+==== 1.1 Circular Import Dependency ✅ FIXED
+
+*Problem:* `+IR.lean+` ↔ `+Serialization.lean+` circular import causing
+compilation failure.
+
+*Solution:* Created new module `+src/GqlDt/Serialization/Types.lean+`
+with shared types: - `+JsonValue+` - JSON in-memory representation -
+`+CBORValue+`, `+CBORMajorType+` - CBOR types (RFC 8949) -
+`+SerializationFormat+` - Format selection enum - CBOR semantic tags
+(55800-55804)
+
+*Changed Tags:* Updated from 1000-1004 → 55800-55804 (vendor-specific
+range)
+
+*Files Modified:* - ✅ `+src/GqlDt/Serialization/Types.lean+` - CREATED
+- ✅ `+src/GqlDt/Serialization.lean+` - Import from Types, removed
+duplicates - ✅ `+src/GqlDt/IR.lean+` - Import Serialization.Types
+instead of Serialization - ✅ `+src/GqlDt.lean+` - Export
+Serialization.Types
+
+*Impact:* Circular dependency broken, clean module separation.
+
+'''''
+
+==== 1.2 Inconsistent Import Paths ✅ FIXED
+
+*Problem:* 17 files used `+import GqlDt.*+` instead of
+`+import GqlDt.*+`.
+
+*Solution:* Global find-and-replace across all `+.lean+` files.
+
+*Files Fixed (17 total):*
+
+....
+src/GqlDt/Prompt/PromptDimension.lean
+src/GqlDt/Prompt/PromptScores.lean
+src/GqlDt/Provenance/ActorId.lean
+src/GqlDt/Provenance/Rationale.lean
+src/GqlDt/Provenance/Tracked.lean
+src/GqlDt/Types.lean
+src/GqlDt/Prompt.lean
+src/GqlDt/Provenance.lean
+src/GqlDt/FFI.lean
+src/GqlDt/Query/AST.lean
+src/GqlDt/Query/Parser.lean
+src/GqlDt/Query/Schema.lean
+src/GqlDt/Query/TypeCheck.lean
+src/GqlDt/Query/Store.lean
+src/GqlDt/Query/Eval.lean
+src/GqlDt/Query.lean
+src/Main.lean
+....
+
+*Command Used:*
+
+[source,bash]
+----
+sed -i 's/import GqlDt\./import GqlDt./g'
+----
+
+*Impact:* All imports now use correct namespace prefix.
+
+'''''
+
+==== 1.3 Missing Type Definitions ✅ FIXED
+
+*Problem:* Parser.lean used types not defined in imported modules.
+
+*Solution:* Added missing types to AST.lean and moved InferredType.
+
+*Types Added to AST.lean:*
+
+[arabic]
+. *InferredType* (moved from TypeInference.lean)
++
+[source,lean]
+----
+inductive InferredType where
+ | nat : Nat → InferredType
+ | int : Int → InferredType
+ | string : String → InferredType
+ | bool : Bool → InferredType
+ | float : Float → InferredType
+----
+. *WhereClause*
++
+[source,lean]
+----
+structure WhereClause where
+ predicate : (String × String × InferredType)
+ proof : Unit → True
+----
+. *OrderByClause*
++
+[source,lean]
+----
+structure OrderByClause where
+ columns : List (String × String) -- (column, direction)
+----
+
+*Rationale:* - `+InferredType+` moved to avoid circular dependency
+(TypeInference → AST → TypeInference) - `+WhereClause+`,
+`+OrderByClause+` are shared AST types needed by Parser
+
+*Files Modified:* - ✅ `+src/GqlDt/AST.lean+` - Added 3 type definitions
+- ✅ `+src/GqlDt/TypeInference.lean+` - Removed InferredType (now
+imported from AST)
+
+*Impact:* All types properly defined before use, no forward references.
+
+'''''
+
+==== 1.4 Missing Imports ✅ FIXED
+
+*Problem:* Parser.lean referenced types without importing their modules.
+
+*Solution:* Added comprehensive imports to Parser.lean.
+
+*Imports Added:*
+
+[source,lean]
+----
+import GqlDt.Types
+import GqlDt.Types.NonEmptyString
+import GqlDt.Types.BoundedNat
+import GqlDt.Types.Confidence
+import GqlDt.Provenance
+----
+
+*Namespace Updated:*
+
+[source,lean]
+----
+open Lexer AST TypeInference IR Types
+----
+
+*Impact:* All referenced types now available, no "`unknown identifier`"
+errors.
+
+'''''
+
+==== 1.5 Parser Monad Error Handling ✅ FIXED
+
+*Problem:* Parser used `+throw+` without implementing `+MonadExcept+`
+typeclass.
+
+*Solution:* 1. Added `+fail+` helper function to Parser monad 2.
+Replaced all 6 instances of `+throw+` with `+fail+`
+
+*Helper Function:*
+
+[source,lean]
+----
+/-- Fail with error message -/
+def fail {α : Type} (msg : String) : Parser α :=
+ fun s => .error msg s
+----
+
+*Replacements Made:* | Line | Original | Fixed | |——|———-|——-| | 244 |
+`+throw "Expected string for RATIONALE"+` |
+`+fail "Expected string for RATIONALE"+` | | 245 |
+`+throw "Expected RATIONALE value"+` |
+`+fail "Expected RATIONALE value"+` | | 298 |
+`+throw "Expected SELECT list"+` | `+fail "Expected SELECT list"+` | |
+361 | `+throw "Expected number for LIMIT"+` |
+`+fail "Expected number for LIMIT"+` | | 362 |
+`+throw "Expected LIMIT value"+` | `+fail "Expected LIMIT value"+` | |
+475 | `+throw s!"Unexpected token: {tok.type}"+` |
+`+fail s!"Unexpected token: {tok.type}"+` | | 476 |
+`+throw "Unexpected EOF"+` | `+fail "Unexpected EOF"+` |
+
+*Impact:* Parser error handling now compiles correctly.
+
+'''''
+
+==== 1.6 Duplicate Type Definitions ✅ FIXED
+
+*Problem:* Parser.lean duplicated types already in AST.lean.
+
+*Solution:* Removed duplicates, kept only distinct parsing-level types.
+
+*Removed from Parser.lean:* - `+Assignment+` - Identical to
+AST.Assignment - `+OrderByClause+` - Identical to AST.OrderByClause
+
+*Kept in Parser.lean:* - `+UpdateStmt+` - Simplified version (no schema
+proofs) - `+DeleteStmt+` - Simplified version (uses WhereClause instead
+of Condition)
+
+*Rationale:* - Parser produces simplified AST for parsing - Type checker
+converts to fully type-safe AST - Two-tier approach prevents premature
+type constraints
+
+*Impact:* No duplicate definitions, clear separation of concerns.
+
+'''''
+
+=== CBOR Tag Registry Update ✅ IMPROVED
+
+*Problem:* Original tags (1000-1004) in unassigned IANA range, no
+documentation.
+
+*Solution:* Moved to vendor-specific range with full documentation.
+
+*Tag Assignments:*
+
+[width="100%",cols="23%,27%,50%",options="header",]
+|===
+|Tag |Type |Structure
+|55800 |BoundedNat
+|`+map { "min": unsigned, "max": unsigned, "value": unsigned, "proof": map }+`
+
+|55801 |NonEmptyString |`+map { "value": textString, "proof": map }+`
+
+|55802 |Confidence |`+map { "value": unsigned, "proof": map }+`
+
+|55803 |PromptScores
+|`+map { "provenance": unsigned, ..., "proof": map }+`
+
+|55804 |ProofBlob
+|`+map { "type": textString, "data": textString, "verified": bool }+`
+|===
+
+*Vendor Range:* 55799-55899 (100 tags reserved for GQL-DT extensions)
+
+*Documentation:* Added comprehensive docstrings in
+Serialization/Types.lean
+
+*Future:* Submit to IANA for official registration
+
+*Impact:* No tag collisions, proper CBOR RFC 8949 compliance.
+
+'''''
+
+=== Files Created
+
+[arabic]
+. `+src/GqlDt/Serialization/Types.lean+` - Shared serialization types
+(118 lines)
+. `+docs/SEAM-ANALYSIS-2026-02-01.md+` - This document
+
+'''''
+
+=== Files Modified
+
+[width="100%",cols="29%,40%,31%",options="header",]
+|===
+|File |Changes |Lines
+|`+src/GqlDt/Serialization.lean+` |Import Types, remove duplicates |-50
+
+|`+src/GqlDt/IR.lean+` |Import Serialization.Types |+1, -1
+
+|`+src/GqlDt/AST.lean+` |Add InferredType, WhereClause, OrderByClause
+|+35
+
+|`+src/GqlDt/TypeInference.lean+` |Remove InferredType |-8
+
+|`+src/GqlDt/Parser.lean+` |Add imports, fix error handling, remove
+duplicates |+9, -15
+
+|`+src/GqlDt.lean+` |Export Serialization.Types |+1
+
+|*17 Query/Prompt/Provenance files* |Fix GqlDt → GqlDt imports |~17
+changes
+|===
+
+*Total Files Modified:* 24 *Total Lines Changed:* ~100
+
+'''''
+
+=== Remaining Issues (Phase 2+)
+
+==== Phase 2: High-Priority Functionality (15% of M6)
+
+[arabic]
+. *AST → IR Conversion* ⚠️ Not Implemented
+* `+InferredInsert → IR.Insert+` (needs schema lookup)
+* `+UpdateStmt → IR.Update+` (needs schema lookup)
+* `+DeleteStmt → IR.Delete+` (needs schema lookup)
+. *Permission Metadata Threading* ⚠️ Incomplete
+* Parser doesn’t pass permissions to IR generation
+* Type whitelist not enforced during parsing
+. *Schema Registry* ⚠️ Missing
+* No runtime schema lookup mechanism
+* Hardcoded `+evidenceSchema+` used everywhere
+* Coordinate with Lithoglyph team
+
+==== Phase 3: Medium-Priority Correctness
+
+[arabic, start=4]
+. *Runtime Validation in Deserialization* ⚠️ Stubs
+* `+deserializeTypedValueJSON+`: Uses `+sorry+` for proofs
+* `+deserializeTypedValueFromCBOR+`: Uses `+sorry+` for proofs
+* `+deserializeTypedValueBinary+`: Uses `+sorry+` for proofs
+* *Security Risk:* Untrusted data bypasses type constraints
+. *JSON Parsing* ⚠️ Stub
+* `+bytesToJson+` returns error
+* Needed for full JSON roundtrip
+. *IR Deserialization* ⚠️ Stub
+* `+deserializeIR+` only dispatches by type tag
+* Schema reconstruction not implemented
+
+==== Phase 4: Low-Priority Improvements
+
+[arabic, start=7]
+. *Documentation Gaps*
+* 20+ functions missing docstrings
+* Module-level docs incomplete
+. *Example Coverage*
+* No UPDATE/DELETE examples
+* No error case examples
+. *Error Message Standardization*
+* Mix of "`Expected X, got Y`" and "`Expected X, found Y`"
+* Recommend: "`Expected , found \{actual}`"
+
+'''''
+
+=== Compilation Test Plan
+
+*Next Step:* Run `+lake build+` to verify Phase 1 fixes.
+
+*Expected Outcome:* Clean build with no errors.
+
+*Test Commands:*
+
+[source,bash]
+----
+cd /var$HOME/Documents/hyperpolymath-repos/gql-dt
+lake clean
+lake build
+----
+
+*If Build Fails:* 1. Check error message for module import issues 2.
+Verify all GqlDt → GqlDt replacements 3. Check for remaining `+throw+`
+statements 4. Verify Serialization.Types is exported
+
+'''''
+
+=== Impact Assessment
+
+==== Before Seam Analysis
+
+* *Circular Dependencies:* 1 critical
+* *Import Errors:* 17 files
+* *Missing Types:* 18 instances
+* *Compilation Blockers:* 33 total
+* *Build Status:* ❌ Would not compile
+
+==== After Phase 1 Fixes
+
+* *Circular Dependencies:* ✅ 0
+* *Import Errors:* ✅ 0
+* *Missing Types:* ✅ 0
+* *Compilation Blockers:* ✅ 0
+* *Build Status:* 🟢 Ready to test
+
+==== Code Quality Metrics
+
+* *Module Cohesion:* Improved (shared types extracted)
+* *Dependency Graph:* Cleaned (no cycles)
+* *Type Safety:* Maintained (all types properly defined)
+* *Error Handling:* Improved (consistent `+fail+` usage)
+* *CBOR Compliance:* Enhanced (documented vendor tags)
+
+'''''
+
+=== Lessons Learned
+
+[arabic]
+. *Early Seam Analysis:* Critical issues caught before integration
+testing
+. *Circular Dependencies:* Easily missed during incremental development
+. *Type Sharing:* Common types need dedicated modules
+. *Import Consistency:* Namespace refactors require comprehensive search
+. *Error Handling:* Custom monads need explicit error functions
+
+'''''
+
+=== Recommendations
+
+==== Immediate (Before M7+M8)
+
+[arabic]
+. ✅ Run `+lake build+` to verify Phase 1 fixes
+. ⚠️ Implement schema registry (coordinate with Lithoglyph)
+. ⚠️ Complete AST → IR conversions
+. ⚠️ Add runtime validation in deserialization
+
+==== Short-Term (During M7+M8)
+
+[arabic, start=5]
+. Add comprehensive examples (UPDATE, DELETE, error cases)
+. Standardize error messages
+. Add missing docstrings
+. Write integration tests
+
+==== Long-Term (M9+)
+
+[arabic, start=9]
+. Submit CBOR tags to IANA for registration
+. Create CBOR-TAGS.md documentation
+. Performance profiling (parser, CBOR encoding)
+. Fuzz testing with malformed input
+
+'''''
+
+=== Conclusion
+
+*Phase 1 seam analysis successfully identified and fixed all
+compilation-blocking issues.* The M6 Parser implementation is now
+structurally sound with clean module boundaries, no circular
+dependencies, and consistent type definitions.
+
+*Next milestone:* Run `+lake build+` to verify, then proceed to Phase 2
+functionality fixes (AST→IR conversion, schema registry).
+
+'''''
+
+*Document Version:* 1.0 *Author:* Jonathan D.A. Jewell (@hyperpolymath)
+*License:* CC-BY-SA-4.0
diff --git a/docs/SEAM-ANALYSIS-2026-02-01.md b/docs/SEAM-ANALYSIS-2026-02-01.md
deleted file mode 100644
index f03b19b..0000000
--- a/docs/SEAM-ANALYSIS-2026-02-01.md
+++ /dev/null
@@ -1,388 +0,0 @@
-# GQL-DT M6 Parser - Seam Analysis & Fixes
-
-**Date:** 2026-02-01
-**Analyst:** Seam Analysis Agent
-**Engineer:** Jonathan D.A. Jewell (@hyperpolymath)
-
----
-
-## Executive Summary
-
-Comprehensive seam analysis identified **76 critical issues** across M6 Parser implementation. **Phase 1 critical fixes (33 compilation-blocking issues) now COMPLETE**.
-
-**Status:** ✅ All compilation blockers resolved
-**Build Status:** Ready for `lake build` test
-**Next Phase:** Phase 2 functionality fixes
-
----
-
-## Phase 1: Critical Fixes ✅ COMPLETE
-
-### 1.1 Circular Import Dependency ✅ FIXED
-
-**Problem:** `IR.lean` ↔ `Serialization.lean` circular import causing compilation failure.
-
-**Solution:**
-Created new module `src/GqlDt/Serialization/Types.lean` with shared types:
-- `JsonValue` - JSON in-memory representation
-- `CBORValue`, `CBORMajorType` - CBOR types (RFC 8949)
-- `SerializationFormat` - Format selection enum
-- CBOR semantic tags (55800-55804)
-
-**Changed Tags:** Updated from 1000-1004 → 55800-55804 (vendor-specific range)
-
-**Files Modified:**
-- ✅ `src/GqlDt/Serialization/Types.lean` - CREATED
-- ✅ `src/GqlDt/Serialization.lean` - Import from Types, removed duplicates
-- ✅ `src/GqlDt/IR.lean` - Import Serialization.Types instead of Serialization
-- ✅ `src/GqlDt.lean` - Export Serialization.Types
-
-**Impact:** Circular dependency broken, clean module separation.
-
----
-
-### 1.2 Inconsistent Import Paths ✅ FIXED
-
-**Problem:** 17 files used `import GqlDt.*` instead of `import GqlDt.*`.
-
-**Solution:** Global find-and-replace across all `.lean` files.
-
-**Files Fixed (17 total):**
-```
-src/GqlDt/Prompt/PromptDimension.lean
-src/GqlDt/Prompt/PromptScores.lean
-src/GqlDt/Provenance/ActorId.lean
-src/GqlDt/Provenance/Rationale.lean
-src/GqlDt/Provenance/Tracked.lean
-src/GqlDt/Types.lean
-src/GqlDt/Prompt.lean
-src/GqlDt/Provenance.lean
-src/GqlDt/FFI.lean
-src/GqlDt/Query/AST.lean
-src/GqlDt/Query/Parser.lean
-src/GqlDt/Query/Schema.lean
-src/GqlDt/Query/TypeCheck.lean
-src/GqlDt/Query/Store.lean
-src/GqlDt/Query/Eval.lean
-src/GqlDt/Query.lean
-src/Main.lean
-```
-
-**Command Used:**
-```bash
-sed -i 's/import GqlDt\./import GqlDt./g'
-```
-
-**Impact:** All imports now use correct namespace prefix.
-
----
-
-### 1.3 Missing Type Definitions ✅ FIXED
-
-**Problem:** Parser.lean used types not defined in imported modules.
-
-**Solution:** Added missing types to AST.lean and moved InferredType.
-
-**Types Added to AST.lean:**
-
-1. **InferredType** (moved from TypeInference.lean)
- ```lean
- inductive InferredType where
- | nat : Nat → InferredType
- | int : Int → InferredType
- | string : String → InferredType
- | bool : Bool → InferredType
- | float : Float → InferredType
- ```
-
-2. **WhereClause**
- ```lean
- structure WhereClause where
- predicate : (String × String × InferredType)
- proof : Unit → True
- ```
-
-3. **OrderByClause**
- ```lean
- structure OrderByClause where
- columns : List (String × String) -- (column, direction)
- ```
-
-**Rationale:**
-- `InferredType` moved to avoid circular dependency (TypeInference → AST → TypeInference)
-- `WhereClause`, `OrderByClause` are shared AST types needed by Parser
-
-**Files Modified:**
-- ✅ `src/GqlDt/AST.lean` - Added 3 type definitions
-- ✅ `src/GqlDt/TypeInference.lean` - Removed InferredType (now imported from AST)
-
-**Impact:** All types properly defined before use, no forward references.
-
----
-
-### 1.4 Missing Imports ✅ FIXED
-
-**Problem:** Parser.lean referenced types without importing their modules.
-
-**Solution:** Added comprehensive imports to Parser.lean.
-
-**Imports Added:**
-```lean
-import GqlDt.Types
-import GqlDt.Types.NonEmptyString
-import GqlDt.Types.BoundedNat
-import GqlDt.Types.Confidence
-import GqlDt.Provenance
-```
-
-**Namespace Updated:**
-```lean
-open Lexer AST TypeInference IR Types
-```
-
-**Impact:** All referenced types now available, no "unknown identifier" errors.
-
----
-
-### 1.5 Parser Monad Error Handling ✅ FIXED
-
-**Problem:** Parser used `throw` without implementing `MonadExcept` typeclass.
-
-**Solution:**
-1. Added `fail` helper function to Parser monad
-2. Replaced all 6 instances of `throw` with `fail`
-
-**Helper Function:**
-```lean
-/-- Fail with error message -/
-def fail {α : Type} (msg : String) : Parser α :=
- fun s => .error msg s
-```
-
-**Replacements Made:**
-| Line | Original | Fixed |
-|------|----------|-------|
-| 244 | `throw "Expected string for RATIONALE"` | `fail "Expected string for RATIONALE"` |
-| 245 | `throw "Expected RATIONALE value"` | `fail "Expected RATIONALE value"` |
-| 298 | `throw "Expected SELECT list"` | `fail "Expected SELECT list"` |
-| 361 | `throw "Expected number for LIMIT"` | `fail "Expected number for LIMIT"` |
-| 362 | `throw "Expected LIMIT value"` | `fail "Expected LIMIT value"` |
-| 475 | `throw s!"Unexpected token: {tok.type}"` | `fail s!"Unexpected token: {tok.type}"` |
-| 476 | `throw "Unexpected EOF"` | `fail "Unexpected EOF"` |
-
-**Impact:** Parser error handling now compiles correctly.
-
----
-
-### 1.6 Duplicate Type Definitions ✅ FIXED
-
-**Problem:** Parser.lean duplicated types already in AST.lean.
-
-**Solution:** Removed duplicates, kept only distinct parsing-level types.
-
-**Removed from Parser.lean:**
-- `Assignment` - Identical to AST.Assignment
-- `OrderByClause` - Identical to AST.OrderByClause
-
-**Kept in Parser.lean:**
-- `UpdateStmt` - Simplified version (no schema proofs)
-- `DeleteStmt` - Simplified version (uses WhereClause instead of Condition)
-
-**Rationale:**
-- Parser produces simplified AST for parsing
-- Type checker converts to fully type-safe AST
-- Two-tier approach prevents premature type constraints
-
-**Impact:** No duplicate definitions, clear separation of concerns.
-
----
-
-## CBOR Tag Registry Update ✅ IMPROVED
-
-**Problem:** Original tags (1000-1004) in unassigned IANA range, no documentation.
-
-**Solution:** Moved to vendor-specific range with full documentation.
-
-**Tag Assignments:**
-
-| Tag | Type | Structure |
-|-----|------|-----------|
-| 55800 | BoundedNat | `map { "min": unsigned, "max": unsigned, "value": unsigned, "proof": map }` |
-| 55801 | NonEmptyString | `map { "value": textString, "proof": map }` |
-| 55802 | Confidence | `map { "value": unsigned, "proof": map }` |
-| 55803 | PromptScores | `map { "provenance": unsigned, ..., "proof": map }` |
-| 55804 | ProofBlob | `map { "type": textString, "data": textString, "verified": bool }` |
-
-**Vendor Range:** 55799-55899 (100 tags reserved for GQL-DT extensions)
-
-**Documentation:** Added comprehensive docstrings in Serialization/Types.lean
-
-**Future:** Submit to IANA for official registration
-
-**Impact:** No tag collisions, proper CBOR RFC 8949 compliance.
-
----
-
-## Files Created
-
-1. `src/GqlDt/Serialization/Types.lean` - Shared serialization types (118 lines)
-2. `docs/SEAM-ANALYSIS-2026-02-01.md` - This document
-
----
-
-## Files Modified
-
-| File | Changes | Lines |
-|------|---------|-------|
-| `src/GqlDt/Serialization.lean` | Import Types, remove duplicates | -50 |
-| `src/GqlDt/IR.lean` | Import Serialization.Types | +1, -1 |
-| `src/GqlDt/AST.lean` | Add InferredType, WhereClause, OrderByClause | +35 |
-| `src/GqlDt/TypeInference.lean` | Remove InferredType | -8 |
-| `src/GqlDt/Parser.lean` | Add imports, fix error handling, remove duplicates | +9, -15 |
-| `src/GqlDt.lean` | Export Serialization.Types | +1 |
-| **17 Query/Prompt/Provenance files** | Fix GqlDt → GqlDt imports | ~17 changes |
-
-**Total Files Modified:** 24
-**Total Lines Changed:** ~100
-
----
-
-## Remaining Issues (Phase 2+)
-
-### Phase 2: High-Priority Functionality (15% of M6)
-
-1. **AST → IR Conversion** ⚠️ Not Implemented
- - `InferredInsert → IR.Insert` (needs schema lookup)
- - `UpdateStmt → IR.Update` (needs schema lookup)
- - `DeleteStmt → IR.Delete` (needs schema lookup)
-
-2. **Permission Metadata Threading** ⚠️ Incomplete
- - Parser doesn't pass permissions to IR generation
- - Type whitelist not enforced during parsing
-
-3. **Schema Registry** ⚠️ Missing
- - No runtime schema lookup mechanism
- - Hardcoded `evidenceSchema` used everywhere
- - Coordinate with Lithoglyph team
-
-### Phase 3: Medium-Priority Correctness
-
-4. **Runtime Validation in Deserialization** ⚠️ Stubs
- - `deserializeTypedValueJSON`: Uses `sorry` for proofs
- - `deserializeTypedValueFromCBOR`: Uses `sorry` for proofs
- - `deserializeTypedValueBinary`: Uses `sorry` for proofs
- - **Security Risk:** Untrusted data bypasses type constraints
-
-5. **JSON Parsing** ⚠️ Stub
- - `bytesToJson` returns error
- - Needed for full JSON roundtrip
-
-6. **IR Deserialization** ⚠️ Stub
- - `deserializeIR` only dispatches by type tag
- - Schema reconstruction not implemented
-
-### Phase 4: Low-Priority Improvements
-
-7. **Documentation Gaps**
- - 20+ functions missing docstrings
- - Module-level docs incomplete
-
-8. **Example Coverage**
- - No UPDATE/DELETE examples
- - No error case examples
-
-9. **Error Message Standardization**
- - Mix of "Expected X, got Y" and "Expected X, found Y"
- - Recommend: "Expected \, found {actual}"
-
----
-
-## Compilation Test Plan
-
-**Next Step:** Run `lake build` to verify Phase 1 fixes.
-
-**Expected Outcome:** Clean build with no errors.
-
-**Test Commands:**
-```bash
-cd /var$HOME/Documents/hyperpolymath-repos/gql-dt
-lake clean
-lake build
-```
-
-**If Build Fails:**
-1. Check error message for module import issues
-2. Verify all GqlDt → GqlDt replacements
-3. Check for remaining `throw` statements
-4. Verify Serialization.Types is exported
-
----
-
-## Impact Assessment
-
-### Before Seam Analysis
-- **Circular Dependencies:** 1 critical
-- **Import Errors:** 17 files
-- **Missing Types:** 18 instances
-- **Compilation Blockers:** 33 total
-- **Build Status:** ❌ Would not compile
-
-### After Phase 1 Fixes
-- **Circular Dependencies:** ✅ 0
-- **Import Errors:** ✅ 0
-- **Missing Types:** ✅ 0
-- **Compilation Blockers:** ✅ 0
-- **Build Status:** 🟢 Ready to test
-
-### Code Quality Metrics
-- **Module Cohesion:** Improved (shared types extracted)
-- **Dependency Graph:** Cleaned (no cycles)
-- **Type Safety:** Maintained (all types properly defined)
-- **Error Handling:** Improved (consistent `fail` usage)
-- **CBOR Compliance:** Enhanced (documented vendor tags)
-
----
-
-## Lessons Learned
-
-1. **Early Seam Analysis:** Critical issues caught before integration testing
-2. **Circular Dependencies:** Easily missed during incremental development
-3. **Type Sharing:** Common types need dedicated modules
-4. **Import Consistency:** Namespace refactors require comprehensive search
-5. **Error Handling:** Custom monads need explicit error functions
-
----
-
-## Recommendations
-
-### Immediate (Before M7+M8)
-1. ✅ Run `lake build` to verify Phase 1 fixes
-2. ⚠️ Implement schema registry (coordinate with Lithoglyph)
-3. ⚠️ Complete AST → IR conversions
-4. ⚠️ Add runtime validation in deserialization
-
-### Short-Term (During M7+M8)
-5. Add comprehensive examples (UPDATE, DELETE, error cases)
-6. Standardize error messages
-7. Add missing docstrings
-8. Write integration tests
-
-### Long-Term (M9+)
-9. Submit CBOR tags to IANA for registration
-10. Create CBOR-TAGS.md documentation
-11. Performance profiling (parser, CBOR encoding)
-12. Fuzz testing with malformed input
-
----
-
-## Conclusion
-
-**Phase 1 seam analysis successfully identified and fixed all compilation-blocking issues.** The M6 Parser implementation is now structurally sound with clean module boundaries, no circular dependencies, and consistent type definitions.
-
-**Next milestone:** Run `lake build` to verify, then proceed to Phase 2 functionality fixes (AST→IR conversion, schema registry).
-
----
-
-**Document Version:** 1.0
-**Author:** Jonathan D.A. Jewell (@hyperpolymath)
-**License:** CC-BY-SA-4.0
diff --git a/docs/TWO-TIER-DESIGN.md b/docs/TWO-TIER-DESIGN.adoc
similarity index 59%
rename from docs/TWO-TIER-DESIGN.md
rename to docs/TWO-TIER-DESIGN.adoc
index 33ed428..77ad8e4 100644
--- a/docs/TWO-TIER-DESIGN.md
+++ b/docs/TWO-TIER-DESIGN.adoc
@@ -1,32 +1,36 @@
-# GQL-DT Two-Tier Language Design
+== GQL-DT Two-Tier Language Design
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
-**Date:** 2026-02-01
-**Status:** Architectural Decision
+*Date:* 2026-02-01 *Status:* Architectural Decision
----
+'''''
-## The Problem: Two User Populations
+=== The Problem: Two User Populations
-### Population 1: Developers & Advanced Admins (GQL-DT)
-- **Who:** Formal methods experts, security auditors, senior database admins
-- **Needs:** Full type safety, proof obligations, compile-time verification
-- **Willing to:** Write proofs, understand dependent types, debug type errors
-- **Use case:** Extreme secure audit projects, critical data entry
+==== Population 1: Developers & Advanced Admins (GQL-DT)
-### Population 2: Regular Users & Junior Admins (GQL)
-- **Who:** Journalists, researchers, junior staff
-- **Needs:** Simple syntax, runtime checks, helpful error messages
-- **Can't:** Write Lean 4 proofs, understand type theory
-- **Use case:** Day-to-day database operations, routine queries
+* *Who:* Formal methods experts, security auditors, senior database
+admins
+* *Needs:* Full type safety, proof obligations, compile-time
+verification
+* *Willing to:* Write proofs, understand dependent types, debug type
+errors
+* *Use case:* Extreme secure audit projects, critical data entry
----
+==== Population 2: Regular Users & Junior Admins (GQL)
-## Solution: Two-Tier Architecture
+* *Who:* Journalists, researchers, junior staff
+* *Needs:* Simple syntax, runtime checks, helpful error messages
+* *Can’t:* Write Lean 4 proofs, understand type theory
+* *Use case:* Day-to-day database operations, routine queries
-```
+'''''
+
+=== Solution: Two-Tier Architecture
+
+....
┌─────────────────────────────────────────────────────────────┐
│ GQL-DT (Type-Safe Tier) │
│ - Full dependent types │
@@ -53,15 +57,16 @@
│ - Enforces invariants at runtime │
│ - Accepts queries from both tiers │
└─────────────────────────────────────────────────────────────┘
-```
+....
----
+'''''
-## Tier 1: GQL-DT (Developer/Admin)
+=== Tier 1: GQL-DT (Developer/Admin)
-### Syntax: Explicit Types & Proofs
+==== Syntax: Explicit Types & Proofs
-```lean
+[source,lean]
+----
-- GQL-DT: Full type annotations
INSERT INTO evidence (
title : NonEmptyString,
@@ -76,28 +81,26 @@ WITH_PROOF {
scores_in_bounds: by lithoglyph_prompt,
provenance_tracked: by lithoglyph_prov
};
-```
+----
-**Characteristics:**
-- ✅ **Compile-time verification** - Invalid queries don't compile
-- ✅ **Proof obligations** - Must provide proofs or use auto-tactics
-- ✅ **Type safety guaranteed** - No runtime type errors possible
-- ⚠️ **Steep learning curve** - Requires Lean 4 knowledge
-- ⚠️ **Verbose** - Explicit types and proofs
+*Characteristics:* - ✅ *Compile-time verification* - Invalid queries
+don’t compile - ✅ *Proof obligations* - Must provide proofs or use
+auto-tactics - ✅ *Type safety guaranteed* - No runtime type errors
+possible - ⚠️ *Steep learning curve* - Requires Lean 4 knowledge - ⚠️
+*Verbose* - Explicit types and proofs
-**Who uses it:**
-- Security auditors entering sensitive data
-- Database administrators setting up schemas
-- Developers creating normalization proofs
-- Formal verification team
+*Who uses it:* - Security auditors entering sensitive data - Database
+administrators setting up schemas - Developers creating normalization
+proofs - Formal verification team
----
+'''''
-## Tier 2: GQL (Regular User)
+=== Tier 2: GQL (Regular User)
-### Syntax: Familiar SQL-Style
+==== Syntax: Familiar SQL-Style
-```sql
+[source,sql]
+----
-- GQL: Inferred types, runtime checks
INSERT INTO evidence (title, prompt_provenance)
VALUES ('ONS Data', 95)
@@ -107,28 +110,25 @@ RATIONALE 'Official statistics';
-- 1. Type inference: 'ONS Data' → NonEmptyString (inferred)
-- 2. Bounds check: 95 ∈ [0, 100] → validated at runtime
-- 3. Rationale check: 'Official statistics' non-empty → validated
-```
+----
-**Characteristics:**
-- ✅ **Familiar syntax** - Looks like standard SQL
-- ✅ **Type inference** - Types automatically inferred
-- ✅ **Helpful errors** - Runtime errors with fix suggestions
-- ✅ **No proofs needed** - Constraints checked at runtime
-- ⚠️ **Runtime overhead** - Validation happens at execution
+*Characteristics:* - ✅ *Familiar syntax* - Looks like standard SQL - ✅
+*Type inference* - Types automatically inferred - ✅ *Helpful errors* -
+Runtime errors with fix suggestions - ✅ *No proofs needed* -
+Constraints checked at runtime - ⚠️ *Runtime overhead* - Validation
+happens at execution
-**Who uses it:**
-- Journalists entering evidence
-- Researchers adding claims
-- Junior admins performing routine operations
-- General users querying data
+*Who uses it:* - Journalists entering evidence - Researchers adding
+claims - Junior admins performing routine operations - General users
+querying data
----
+'''''
-## How They Interact: Compilation Strategy
+=== How They Interact: Compilation Strategy
-### GQL → GQL-DT → Lithoglyph
+==== GQL → GQL-DT → Lithoglyph
-```
+....
User writes GQL
↓
Type Inference (auto-generate types)
@@ -143,17 +143,21 @@ Type Checking (validate proofs)
│ Valid │ Invalid
↓ ↓
Execute Error (with fix suggestion)
-```
+....
-### Example: GQL → GQL-DT Translation
+==== Example: GQL → GQL-DT Translation
-**Input (GQL):**
-```sql
+*Input (GQL):*
+
+[source,sql]
+----
INSERT INTO evidence (prompt_provenance) VALUES (95);
-```
+----
+
+*Translated to (GQL-DT):*
-**Translated to (GQL-DT):**
-```lean
+[source,lean]
+----
INSERT INTO evidence (
prompt_provenance : BoundedNat 0 100
)
@@ -164,24 +168,27 @@ RATIONALE (inferred from context)
WITH_PROOF {
bounds_check: by omega -- Auto-generated!
};
-```
+----
-**If value is invalid:**
-```sql
+*If value is invalid:*
+
+[source,sql]
+----
INSERT INTO evidence (prompt_provenance) VALUES (150);
-- Runtime error: Value 150 out of bounds [0, 100]
-- Suggestion: Use a value between 0 and 100
-```
+----
----
+'''''
-## Preventing User Mistakes: Safety Mechanisms
+=== Preventing User Mistakes: Safety Mechanisms
-### Problem: "Annoying users mess up, admins spend time fixing"
+==== Problem: "`Annoying users mess up, admins spend time fixing`"
-### Solution 1: Transaction-Based Validation
+==== Solution 1: Transaction-Based Validation
-```sql
+[source,sql]
+----
-- User's transaction
BEGIN TRANSACTION;
INSERT INTO evidence (title, prompt_provenance)
@@ -199,13 +206,14 @@ ERROR: Value 150 out of bounds for prompt_provenance
Expected: Integer between 0 and 100
Suggestion: Change 150 to a value like 95
Status: NOT COMMITTED (no data changed)
-```
+----
-**Key insight:** Invalid queries never reach the database!
+*Key insight:* Invalid queries never reach the database!
-### Solution 2: Permission-Based Write Access
+==== Solution 2: Permission-Based Write Access
-```sql
+[source,sql]
+----
-- Schema-level permissions
CREATE COLLECTION evidence (
title : NonEmptyString,
@@ -221,16 +229,16 @@ CREATE COLLECTION evidence (
-- Advanced admins can modify schema
GRANT ALTER TO advanced_admins WITH VALIDATION LEVEL proof_required;
);
-```
+----
-**Access levels:**
-- `runtime`: GQL with type inference + runtime checks
-- `compile_time`: GQL-DT with proofs auto-generated where possible
-- `proof_required`: GQL-DT with manual proofs required (no auto-admit)
+*Access levels:* - `+runtime+`: GQL with type inference + runtime checks
+- `+compile_time+`: GQL-DT with proofs auto-generated where possible -
+`+proof_required+`: GQL-DT with manual proofs required (no auto-admit)
-### Solution 3: Admin Review Queue
+==== Solution 3: Admin Review Queue
-```sql
+[source,sql]
+----
-- User submits query
INSERT INTO evidence (prompt_provenance) VALUES (95);
-- Status: Pending review (if configured)
@@ -248,13 +256,14 @@ SELECT * FROM pending_queries WHERE status = 'needs_review';
APPROVE QUERY 1; -- Execute immediately
REJECT QUERY 2 REASON "Invalid value"; -- Notify user
ASSIST QUERY 3 WITH_PROOF { ... }; -- Provide proof, then execute
-```
+----
-### Solution 4: Template-Based Entry (Recommended!)
+==== Solution 4: Template-Based Entry (Recommended!)
-**Instead of letting users write raw SQL:**
+*Instead of letting users write raw SQL:*
-```typescript
+[source,typescript]
+----
// Lithoglyph Studio: Web UI with type-safe form
interface EvidenceForm {
title: string // Auto-validated: non-empty
@@ -279,17 +288,16 @@ function submitEvidence(form: EvidenceForm) {
// Submit (will be validated again server-side)
await lithoglyph.execute(query)
}
-```
+----
-**Benefits:**
-- ✅ Users never write raw SQL
-- ✅ UI enforces constraints (dropdowns, sliders, validation)
-- ✅ Type-safe generation of GQL
-- ✅ Admins don't see malformed queries
+*Benefits:* - ✅ Users never write raw SQL - ✅ UI enforces constraints
+(dropdowns, sliders, validation) - ✅ Type-safe generation of GQL - ✅
+Admins don’t see malformed queries
-### Solution 5: Gradual Validation Levels
+==== Solution 5: Gradual Validation Levels
-```sql
+[source,sql]
+----
-- Configure per-collection validation strictness
ALTER COLLECTION evidence
SET VALIDATION_LEVEL FOR users = 'strict';
@@ -306,103 +314,110 @@ INSERT INTO evidence (prompt_provenance) VALUES (150);
-- Paranoid: Compile-time checks required
INSERT INTO evidence (prompt_provenance) VALUES (150);
-- Error: Proof obligation failed, query not executed
-```
+----
+
+'''''
----
+=== When to Use Each Tier
-## When to Use Each Tier
+==== Use GQL-DT (Type-Safe) When:
-### Use GQL-DT (Type-Safe) When:
-1. **Defining schemas** - Admins create collections with type constraints
-2. **Critical data entry** - Security auditors entering sensitive evidence
-3. **Normalization operations** - Database transformations need proofs
-4. **Integration code** - Programmatic access from applications
+[arabic]
+. *Defining schemas* - Admins create collections with type constraints
+. *Critical data entry* - Security auditors entering sensitive evidence
+. *Normalization operations* - Database transformations need proofs
+. *Integration code* - Programmatic access from applications
-### Use GQL (Runtime-Checked) When:
-1. **Routine queries** - Day-to-day SELECT operations
-2. **User data entry** - Journalists adding evidence
-3. **Exploratory analysis** - Researchers querying data
-4. **Learning/testing** - New users getting familiar with system
+==== Use GQL (Runtime-Checked) When:
----
+[arabic]
+. *Routine queries* - Day-to-day SELECT operations
+. *User data entry* - Journalists adding evidence
+. *Exploratory analysis* - Researchers querying data
+. *Learning/testing* - New users getting familiar with system
-## Implementation Timeline
+'''''
-### Phase 1: GQL-DT Only (Current)
-- ✅ Milestone 1-4: Core types implemented
-- 🔧 Milestone 5-6: Parser + type checker
+=== Implementation Timeline
-**Status:** Advanced users can use GQL-DT now
+==== Phase 1: GQL-DT Only (Current)
-### Phase 2: GQL with Type Inference (Next)
-- [ ] Type inference engine
-- [ ] Auto-proof generation (omega, decide tactics)
-- [ ] Runtime validation layer
-- [ ] Error messages with suggestions
+* ✅ Milestone 1-4: Core types implemented
+* 🔧 Milestone 5-6: Parser + type checker
-**Estimated:** 2-3 months after M6 complete
+*Status:* Advanced users can use GQL-DT now
-### Phase 3: Validation Levels & Permissions (Later)
-- [ ] Permission system
-- [ ] Admin review queue
-- [ ] Gradual validation levels
-- [ ] Audit trail
+==== Phase 2: GQL with Type Inference (Next)
-**Estimated:** 4-6 months
+* [ ] Type inference engine
+* [ ] Auto-proof generation (omega, decide tactics)
+* [ ] Runtime validation layer
+* [ ] Error messages with suggestions
-### Phase 4: Lithoglyph Studio UI (Future)
-- [ ] Web-based form builder
-- [ ] Type-safe form generation
-- [ ] Visual query builder
-- [ ] No raw SQL for end users
+*Estimated:* 2-3 months after M6 complete
-**Estimated:** 6-9 months
+==== Phase 3: Validation Levels & Permissions (Later)
----
+* [ ] Permission system
+* [ ] Admin review queue
+* [ ] Gradual validation levels
+* [ ] Audit trail
-## Recommended Approach: NOW vs LATER
+*Estimated:* 4-6 months
-### ✅ Deal with NOW (During Parser Implementation)
+==== Phase 4: Lithoglyph Studio UI (Future)
-1. **Design AST to support both tiers**
- - Explicit types (GQL-DT) vs inferred types (GQL)
- - Proof annotations optional
- - Same AST, different parsing paths
+* [ ] Web-based form builder
+* [ ] Type-safe form generation
+* [ ] Visual query builder
+* [ ] No raw SQL for end users
-2. **Add type inference hooks**
- - Placeholder for "infer type from value"
- - Auto-proof generation infrastructure
- - Graceful degradation (admit if can't prove)
+*Estimated:* 6-9 months
-3. **Define validation levels**
- - Schema metadata: which tier is allowed
- - User roles: which validation level they get
- - Default: GQL for users, GQL-DT for admins
+'''''
-### ⏳ Deal with LATER (After M6)
+=== Recommended Approach: NOW vs LATER
-1. **Actual GQL parser**
- - SQL-like syntax parser
- - Type inference algorithm
- - Auto-proof tactics
+==== ✅ Deal with NOW (During Parser Implementation)
-2. **Runtime validation**
- - Constraint checking at execution
- - Error messages with fix suggestions
- - Auto-fix for permissive mode
+[arabic]
+. *Design AST to support both tiers*
+* Explicit types (GQL-DT) vs inferred types (GQL)
+* Proof annotations optional
+* Same AST, different parsing paths
+. *Add type inference hooks*
+* Placeholder for "`infer type from value`"
+* Auto-proof generation infrastructure
+* Graceful degradation (admit if can’t prove)
+. *Define validation levels*
+* Schema metadata: which tier is allowed
+* User roles: which validation level they get
+* Default: GQL for users, GQL-DT for admins
-3. **UI/Forms**
- - Lithoglyph Studio
- - Template-based entry
- - Zero SQL for end users
+==== ⏳ Deal with LATER (After M6)
----
+[arabic]
+. *Actual GQL parser*
+* SQL-like syntax parser
+* Type inference algorithm
+* Auto-proof tactics
+. *Runtime validation*
+* Constraint checking at execution
+* Error messages with fix suggestions
+* Auto-fix for permissive mode
+. *UI/Forms*
+* Lithoglyph Studio
+* Template-based entry
+* Zero SQL for end users
-## Example: Dual-Tier in Practice
+'''''
-### Schema Definition (Admin, GQL-DT)
+=== Example: Dual-Tier in Practice
-```lean
+==== Schema Definition (Admin, GQL-DT)
+
+[source,lean]
+----
CREATE COLLECTION evidence (
id : UUID PRIMARY KEY,
title : NonEmptyString,
@@ -415,11 +430,12 @@ CREATE COLLECTION evidence (
GRANT INSERT TO users WITH VALIDATION runtime;
GRANT INSERT TO admins WITH VALIDATION compile_time;
);
-```
+----
-### User Insert (GQL, Type-Inferred)
+==== User Insert (GQL, Type-Inferred)
-```sql
+[source,sql]
+----
-- User writes simple SQL
INSERT INTO evidence (title, prompt_provenance)
VALUES ('ONS Data', 95)
@@ -437,11 +453,12 @@ RATIONALE 'Official statistics';
-- }
-- Executes immediately if all proofs pass
-```
+----
-### Admin Insert (GQL-DT, Explicit Types)
+==== Admin Insert (GQL-DT, Explicit Types)
-```lean
+[source,lean]
+----
-- Admin writes full type annotations
INSERT INTO evidence (
title : NonEmptyString,
@@ -464,78 +481,83 @@ WITH_PROOF {
};
-- Compile-time type checking ensures correctness
-```
+----
+
+'''''
----
+=== Decision: Start Two-Tier Support NOW
-## Decision: Start Two-Tier Support NOW
+*Recommendation:* Add two-tier support *during Milestone 6 (Parser)*
-**Recommendation:** Add two-tier support **during Milestone 6 (Parser)**
+*Why NOW:* 1. Parser architecture affects both tiers 2. AST design must
+support type inference 3. Easier to build both parsers together 4. Type
+inference shares infrastructure with type checker
-**Why NOW:**
-1. Parser architecture affects both tiers
-2. AST design must support type inference
-3. Easier to build both parsers together
-4. Type inference shares infrastructure with type checker
+*What to implement:*
-**What to implement:**
+==== M6a: GQL-DT Parser (Full Types)
-### M6a: GQL-DT Parser (Full Types)
-- Parse explicit type annotations
-- Parse proof obligations
-- Generate typed AST
+* Parse explicit type annotations
+* Parse proof obligations
+* Generate typed AST
-### M6b: GQL Parser (Type Inference)
-- Parse SQL-like syntax
-- Infer types from values
-- Auto-generate proofs where possible
-- Graceful degradation (admit if can't prove)
+==== M6b: GQL Parser (Type Inference)
-### M6c: Unified Type Checker
-- Check both explicit and inferred types
-- Validate or auto-prove obligations
-- Helpful error messages for both tiers
+* Parse SQL-like syntax
+* Infer types from values
+* Auto-generate proofs where possible
+* Graceful degradation (admit if can’t prove)
----
+==== M6c: Unified Type Checker
-## Summary
+* Check both explicit and inferred types
+* Validate or auto-prove obligations
+* Helpful error messages for both tiers
-### Two Tiers
+'''''
-| Feature | GQL-DT (Advanced) | GQL (Users) |
-|---------|-------------------|--------------|
-| **Syntax** | Lean 4-style | SQL-style |
-| **Types** | Explicit | Inferred |
-| **Proofs** | Required | Auto-generated |
-| **Validation** | Compile-time | Runtime |
-| **Errors** | Type errors | Constraint violations |
-| **Users** | Admins, developers | Everyone else |
+=== Summary
-### Preventing User Mistakes
+==== Two Tiers
-1. **Transaction validation** - Invalid queries don't commit
-2. **Permission levels** - Users get runtime validation
-3. **Admin review queue** - Optional approval workflow
-4. **Template-based UI** - Lithoglyph Studio (no raw SQL)
-5. **Gradual strictness** - Permissive/strict/paranoid modes
+[cols=",,",options="header",]
+|===
+|Feature |GQL-DT (Advanced) |GQL (Users)
+|*Syntax* |Lean 4-style |SQL-style
+|*Types* |Explicit |Inferred
+|*Proofs* |Required |Auto-generated
+|*Validation* |Compile-time |Runtime
+|*Errors* |Type errors |Constraint violations
+|*Users* |Admins, developers |Everyone else
+|===
-### Timeline
+==== Preventing User Mistakes
-- ✅ **NOW:** Design dual-tier AST, add type inference hooks
-- 🔧 **M6:** Implement both parsers together
-- ⏳ **Later:** Runtime validation, UI, permissions
+[arabic]
+. *Transaction validation* - Invalid queries don’t commit
+. *Permission levels* - Users get runtime validation
+. *Admin review queue* - Optional approval workflow
+. *Template-based UI* - Lithoglyph Studio (no raw SQL)
+. *Gradual strictness* - Permissive/strict/paranoid modes
----
+==== Timeline
-## Granular Permission System: Workplace-Specific Type Restrictions
+* ✅ *NOW:* Design dual-tier AST, add type inference hooks
+* 🔧 *M6:* Implement both parsers together
+* ⏳ *Later:* Runtime validation, UI, permissions
-### The Question: "Can we restrict users to ONLY numbers, strings, dates?"
+'''''
-**Answer: YES - Fine-grained type-level permissions**
+=== Granular Permission System: Workplace-Specific Type Restrictions
-### Permission Architecture
+==== The Question: "`Can we restrict users to ONLY numbers, strings, dates?`"
-```lean
+*Answer: YES - Fine-grained type-level permissions*
+
+==== Permission Architecture
+
+[source,lean]
+----
-- Type whitelist per role
structure TypeWhitelist where
allowedTypes : List TypeExpr
@@ -552,11 +574,12 @@ structure PermissionProfile where
canCreateSchema : Bool
canModifySchema : Bool
canDeleteData : Bool
-```
+----
-### Example: Restrict Users to Basic Types Only
+==== Example: Restrict Users to Basic Types Only
-```lean
+[source,lean]
+----
-- Workplace policy: journalists can only use Nat, String, Date
def journalistPermissions : PermissionProfile := {
name := "journalist"
@@ -588,11 +611,12 @@ def adminPermissions : PermissionProfile := {
canModifySchema := true,
canDeleteData := true
}
-```
+----
-### Permission Enforcement in Parser
+==== Permission Enforcement in Parser
-```lean
+[source,lean]
+----
-- Parser checks permissions before accepting query
def parseWithPermissions
(query : String)
@@ -616,11 +640,12 @@ def parseWithPermissions
-- 4. Proceed with type checking
return typeCheck ast profile.validationLevel
-```
+----
-### Schema-Level Type Restrictions
+==== Schema-Level Type Restrictions
-```sql
+[source,sql]
+----
-- Create schema with per-role type restrictions
CREATE COLLECTION simple_data (
id : Nat,
@@ -639,13 +664,14 @@ CREATE COLLECTION simple_data (
-- Everyone: can SELECT
GRANT SELECT TO public;
);
-```
+----
-### Workplace Configuration Examples
+==== Workplace Configuration Examples
-#### Example 1: Journalism Organization
+===== Example 1: Journalism Organization
-```scheme
+[source,scheme]
+----
; workplace-policy.scm
(define journalism-org
(workplace
@@ -663,16 +689,16 @@ CREATE COLLECTION simple_data (
(types all)
(validation compile)
(operations all)))))
-```
+----
-**Result:**
-- Journalists: Simple GQL, basic types only, can't mess up type system
-- Editors: GQL with some refined types, still runtime-checked
-- Tech admins: Full GQL-DT, compile-time verification
+*Result:* - Journalists: Simple GQL, basic types only, can’t mess up
+type system - Editors: GQL with some refined types, still
+runtime-checked - Tech admins: Full GQL-DT, compile-time verification
-#### Example 2: Security Audit Firm
+===== Example 2: Security Audit Firm
-```scheme
+[source,scheme]
+----
; workplace-policy.scm
(define security-firm
(workplace
@@ -693,16 +719,16 @@ CREATE COLLECTION simple_data (
(validation paranoid) ; Manual proofs required
(operations all)
(require-review false)))))
-```
+----
-**Result:**
-- Junior auditors: Limited types, all queries reviewed
-- Senior auditors: All standard types, compile-time checks
-- Principals: Full dependent types, manual proof obligations
+*Result:* - Junior auditors: Limited types, all queries reviewed -
+Senior auditors: All standard types, compile-time checks - Principals:
+Full dependent types, manual proof obligations
-### Implementation: Type Filter in AST
+==== Implementation: Type Filter in AST
-```lean
+[source,lean]
+----
-- Check if type is allowed for user
def isTypeAllowed (t : TypeExpr) (whitelist : TypeWhitelist) : Bool :=
-- If allowedTypes is empty, allow all
@@ -727,12 +753,14 @@ def filterSchemaForUser (schema : Schema) (profile : PermissionProfile) : Schema
{ schema with
columns := schema.columns.filter (fun col =>
isTypeAllowed col.type profile.typeWhitelist) }
-```
+----
-### User Experience with Type Restrictions
+==== User Experience with Type Restrictions
-**Journalist attempts to use BoundedNat:**
-```sql
+*Journalist attempts to use BoundedNat:*
+
+[source,sql]
+----
-- User: journalist (restricted to Nat, String, Date)
INSERT INTO evidence (title, prompt_provenance)
VALUES ('My Evidence', 95);
@@ -745,10 +773,12 @@ Column 'prompt_provenance' requires type 'BoundedNat 0 100'
Suggestion: Contact your administrator to request access to this column,
or use a different column that accepts your allowed types.
Available columns for you: id (Nat), title (String), created_date (Date)
-```
+----
+
+*Admin uses same query:*
-**Admin uses same query:**
-```sql
+[source,sql]
+----
-- User: admin (unrestricted)
INSERT INTO evidence (title, prompt_provenance)
VALUES ('My Evidence', 95);
@@ -757,11 +787,12 @@ VALUES ('My Evidence', 95);
✓ Type checking successful
✓ Auto-proved: prompt_provenance ∈ [0, 100]
Executing INSERT...
-```
+----
-### Form-Based UI Respects Permissions
+==== Form-Based UI Respects Permissions
-```typescript
+[source,typescript]
+----
// Lithoglyph Studio auto-hides fields based on permissions
function renderEvidenceForm(user: User, profile: PermissionProfile) {
const schema = getSchema("evidence");
@@ -781,41 +812,47 @@ function renderEvidenceForm(user: User, profile: PermissionProfile) {
);
}
-```
+----
+
+'''''
+
+=== Summary: One Language, Layered Access Control
+
+==== Layer 1: Syntax Choice (User Convenience)
+
+* *GQL*: SQL-like, type inference, runtime checks
+* *GQL-DT*: Lean-like, explicit types, compile-time proofs
+* *Same language*, different parsers, same AST
----
+==== Layer 2: Type Permissions (Organizational Policy)
-## Summary: One Language, Layered Access Control
+* *Whitelist-based*: Only allow specific types per role
+* *Granular*: Can restrict to `+[Nat, String, Date]+` only
+* *Schema-level*: Column access based on type requirements
+* *Enforced in parser*: Type checks happen before execution
-### Layer 1: Syntax Choice (User Convenience)
-- **GQL**: SQL-like, type inference, runtime checks
-- **GQL-DT**: Lean-like, explicit types, compile-time proofs
-- **Same language**, different parsers, same AST
+==== Layer 3: Validation Level (Risk Management)
-### Layer 2: Type Permissions (Organizational Policy)
-- **Whitelist-based**: Only allow specific types per role
-- **Granular**: Can restrict to `[Nat, String, Date]` only
-- **Schema-level**: Column access based on type requirements
-- **Enforced in parser**: Type checks happen before execution
+* *Permissive*: Runtime checks with auto-fix
+* *Strict*: Runtime checks, reject on error
+* *Compile*: Compile-time proofs (auto-generated)
+* *Paranoid*: Manual proofs required
-### Layer 3: Validation Level (Risk Management)
-- **Permissive**: Runtime checks with auto-fix
-- **Strict**: Runtime checks, reject on error
-- **Compile**: Compile-time proofs (auto-generated)
-- **Paranoid**: Manual proofs required
+==== Layer 4: UI Forms (Maximum Safety)
-### Layer 4: UI Forms (Maximum Safety)
-- **No syntax exposure**: Users never write SQL/GQL-DT
-- **Type-driven forms**: UI generates based on allowed types
-- **Impossible to bypass**: Restricted columns don't appear
+* *No syntax exposure*: Users never write SQL/GQL-DT
+* *Type-driven forms*: UI generates based on allowed types
+* *Impossible to bypass*: Restricted columns don’t appear
-### Answer to "Flexibility" Question
+==== Answer to "`Flexibility`" Question
-**Q: Can a workplace say "GQL with numbers, strings, dates BUT NOTHING ELSE"?**
+*Q: Can a workplace say "`GQL with numbers, strings, dates BUT NOTHING
+ELSE`"?*
-**A: YES, exactly this:**
+*A: YES, exactly this:*
-```lean
+[source,lean]
+----
def workplacePolicy : PermissionProfile := {
name := "basic-user"
typeWhitelist := {
@@ -830,26 +867,23 @@ def workplacePolicy : PermissionProfile := {
canModifySchema := false,
canDeleteData := false
}
-```
+----
-**Result:**
-- ✅ Can use: Nat, String, Date
-- ❌ Cannot use: BoundedNat, NonEmptyString, PromptScores, custom types
-- ✅ Syntax: Simple SQL (GQL)
-- ❌ Cannot access: GQL-DT syntax, proof obligations, dependent types
-- ✅ Queries: Runtime-checked, helpful error messages
-- ❌ Cannot break: Type system (restricted types can't violate invariants)
+*Result:* - ✅ Can use: Nat, String, Date - ❌ Cannot use: BoundedNat,
+NonEmptyString, PromptScores, custom types - ✅ Syntax: Simple SQL (GQL)
+- ❌ Cannot access: GQL-DT syntax, proof obligations, dependent types -
+✅ Queries: Runtime-checked, helpful error messages - ❌ Cannot break:
+Type system (restricted types can’t violate invariants)
----
+'''''
-**Document Status:** Complete architectural decision for two-tier language design with granular permission system
+*Document Status:* Complete architectural decision for two-tier language
+design with granular permission system
-**Recommendation:** Implement dual-tier support + permission system in Milestone 6 (Parser)
+*Recommendation:* Implement dual-tier support + permission system in
+Milestone 6 (Parser)
-**Next Steps:**
-1. Design AST to support both tiers
-2. Implement GQL-DT parser (explicit types)
-3. Implement GQL parser (type inference)
-4. Implement TypeWhitelist and PermissionProfile
-5. Unified type checker with permission enforcement
-6. Schema-level permission annotations
+*Next Steps:* 1. Design AST to support both tiers 2. Implement GQL-DT
+parser (explicit types) 3. Implement GQL parser (type inference) 4.
+Implement TypeWhitelist and PermissionProfile 5. Unified type checker
+with permission enforcement 6. Schema-level permission annotations
diff --git a/docs/TYPE-SAFETY-ENFORCEMENT.md b/docs/TYPE-SAFETY-ENFORCEMENT.adoc
similarity index 55%
rename from docs/TYPE-SAFETY-ENFORCEMENT.md
rename to docs/TYPE-SAFETY-ENFORCEMENT.adoc
index c144d89..be19bc0 100644
--- a/docs/TYPE-SAFETY-ENFORCEMENT.md
+++ b/docs/TYPE-SAFETY-ENFORCEMENT.adoc
@@ -1,41 +1,43 @@
-# Type Safety Enforcement in GQL-DT Parser
+== Type Safety Enforcement in GQL-DT Parser
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
-**Version:** 1.0.0
-**Date:** 2026-02-01
+*Version:* 1.0.0 *Date:* 2026-02-01
----
+'''''
-## How the Parser Enforces Type Safety
+=== How the Parser Enforces Type Safety
-The GQL-DT parser uses **Lean 4's dependent type system** to enforce type safety at **construction time**, not runtime.
+The GQL-DT parser uses *Lean 4’s dependent type system* to enforce type
+safety at *construction time*, not runtime.
-### Key Principle: "If it compiles, it's correct"
+==== Key Principle: "`If it compiles, it’s correct`"
----
+'''''
-## 1. Type-Indexed Values
+=== 1. Type-Indexed Values
-### The Core Mechanism
+==== The Core Mechanism
-```lean
+[source,lean]
+----
-- TypedValue is indexed by its type
inductive TypedValue : TypeExpr → Type where
| nat : Nat → TypedValue .nat
| boundedNat : (min max : Nat) → BoundedNat min max → TypedValue (.boundedNat min max)
| nonEmptyString : NonEmptyString → TypedValue .nonEmptyString
-```
+----
-**What this means:**
-- A `TypedValue (.boundedNat 0 100)` **can only contain** a `BoundedNat 0 100`
-- You **cannot** put a `Nat` where `BoundedNat 0 100` is expected
-- The type system **prevents** construction of invalid values
+*What this means:* - A `+TypedValue (.boundedNat 0 100)+` *can only
+contain* a `+BoundedNat 0 100+` - You *cannot* put a `+Nat+` where
+`+BoundedNat 0 100+` is expected - The type system *prevents*
+construction of invalid values
-### Example: Compile-Time Enforcement
+==== Example: Compile-Time Enforcement
-```lean
+[source,lean]
+----
-- ✓ COMPILES: Correct type
def valid : TypedValue (.boundedNat 0 100) :=
.boundedNat 0 100 (BoundedNat.mk 0 100 95 (by omega) (by omega))
@@ -43,15 +45,16 @@ def valid : TypedValue (.boundedNat 0 100) :=
-- ✗ WON'T COMPILE: Wrong type
def invalid : TypedValue (.boundedNat 0 100) :=
.nat 95 -- Error: expected BoundedNat, got Nat
-```
+----
----
+'''''
-## 2. Proof-Carrying INSERT
+=== 2. Proof-Carrying INSERT
-### Smart Constructor with Type Safety
+==== Smart Constructor with Type Safety
-```lean
+[source,lean]
+----
structure InsertStmt (schema : Schema) where
table : String
columns : List String
@@ -62,18 +65,20 @@ structure InsertStmt (schema : Schema) where
∃ col ∈ schema.columns,
col.name = columns.get! i ∧
(values.get! i).1 = col.type
-```
+----
-**How it enforces type safety:**
+*How it enforces type safety:*
-1. **Parser generates proof obligation** when constructing INSERT
-2. **Type checker verifies proof** or auto-proves with tactics
-3. **If proof fails**, query doesn't compile
-4. **If proof succeeds**, query is **mathematically guaranteed** type-safe
+[arabic]
+. *Parser generates proof obligation* when constructing INSERT
+. *Type checker verifies proof* or auto-proves with tactics
+. *If proof fails*, query doesn’t compile
+. *If proof succeeds*, query is *mathematically guaranteed* type-safe
-### Example: The Proof Prevents Errors
+==== Example: The Proof Prevents Errors
-```lean
+[source,lean]
+----
-- Attempting to insert wrong type:
def badInsert : InsertStmt evidenceSchema :=
mkInsert evidenceSchema "evidence"
@@ -89,22 +94,26 @@ def badInsert : InsertStmt evidenceSchema :=
-- But: evidenceSchema.columns has title : NonEmptyString
-- So: .string ≠ .nonEmptyString
-- Result: PROOF FAILS, query rejected at compile time
-```
+----
----
+'''''
-## 3. Preventing User Mistakes
+=== 3. Preventing User Mistakes
-### Problem: Users Enter Invalid Data
+==== Problem: Users Enter Invalid Data
-**Traditional SQL:**
-```sql
+*Traditional SQL:*
+
+[source,sql]
+----
INSERT INTO evidence (prompt_provenance) VALUES (150);
-- Runtime error: check constraint violated
-```
+----
+
+*GQL-DT (Advanced Tier):*
-**GQL-DT (Advanced Tier):**
-```lean
+[source,lean]
+----
INSERT INTO evidence (
prompt_provenance : BoundedNat 0 100
) VALUES (
@@ -112,31 +121,36 @@ INSERT INTO evidence (
);
-- COMPILE ERROR: tactic 'omega' failed
-- Cannot prove: 150 ≤ 100
-```
+----
+
+*GQL (User Tier):*
-**GQL (User Tier):**
-```sql
+[source,sql]
+----
INSERT INTO evidence (prompt_provenance) VALUES (150);
-- Type inference: 150 : Nat
-- Validation: 150 ∉ [0, 100]
-- Runtime error: Value 150 out of bounds [0, 100]
-- Suggestion: Use a value between 0 and 100
-- Status: TRANSACTION ROLLED BACK (no data changed)
-```
+----
-### Solution: Multi-Level Defense
+==== Solution: Multi-Level Defense
-**Level 1: UI Validation (Lithoglyph Studio)**
-```typescript
+*Level 1: UI Validation (Lithoglyph Studio)*
+
+[source,typescript]
+----
// Dropdown with only valid values
// User can't even enter 150!
-```
+----
+
+*Level 2: Type Inference (GQL Parser)*
-**Level 2: Type Inference (GQL Parser)**
-```
+....
User input: 150
↓
Type inference: Nat
@@ -146,10 +160,11 @@ Expected: BoundedNat 0 100
Runtime check: 150 > 100? YES
↓
ERROR before database touched
-```
+....
-**Level 3: Proof Verification (GQL-DT Parser)**
-```
+*Level 3: Proof Verification (GQL-DT Parser)*
+
+....
User input: BoundedNat.mk 0 100 150 proof
↓
Lean 4 type checker: verify proof
@@ -159,10 +174,11 @@ Proof: (by omega)
omega tactic: can't prove 150 ≤ 100
↓
COMPILE ERROR (query never generated)
-```
+....
+
+*Level 4: Database Constraints (Lithoglyph)*
-**Level 4: Database Constraints (Lithoglyph)**
-```
+....
Even if all above fail (shouldn't happen):
↓
Lithoglyph checks: 150 in [0, 100]?
@@ -170,15 +186,16 @@ Lithoglyph checks: 150 in [0, 100]?
Constraint violation
↓
Transaction rolled back
-```
+....
----
+'''''
-## 4. Permission-Based Type Safety
+=== 4. Permission-Based Type Safety
-### Preventing Users from Breaking Things
+==== Preventing Users from Breaking Things
-```lean
+[source,lean]
+----
-- Define permission levels
inductive ValidationLevel where
| none : ValidationLevel -- No validation (dangerous!)
@@ -191,11 +208,12 @@ structure PermissionedSchema extends Schema where
userValidation : ValidationLevel -- Regular users: runtime
adminValidation : ValidationLevel -- Admins: compile
advancedValidation : ValidationLevel -- Advanced: paranoid
-```
+----
-### Access Control at Type Level
+==== Access Control at Type Level
-```lean
+[source,lean]
+----
-- Users can only INSERT via runtime-checked GQL
def userInsert (user : User) (value : Nat) : IO Unit := do
-- Runtime validation
@@ -216,30 +234,31 @@ def advancedInsert (advanced : Advanced) (value : Nat) (proof : 0 ≤ value ∧
let score := BoundedNat.mk 0 100 value (proof.1) (proof.2)
executeGQL-DT (insertWithScore score)
-- Manual proof required - no auto-tactics allowed
-```
+----
----
+'''''
-## 5. Gradual Typing: Best of Both Worlds
+=== 5. Gradual Typing: Best of Both Worlds
-### Tier 1: User (GQL) - Type Inference
+==== Tier 1: User (GQL) - Type Inference
-```sql
+[source,sql]
+----
-- User writes simple SQL
INSERT INTO evidence (title, prompt_provenance)
VALUES ('My Evidence', 95)
RATIONALE 'Based on data';
-```
+----
-**Parser does:**
-1. Infer types: `'My Evidence' : NonEmptyString` (length > 0)
-2. Infer types: `95 : BoundedNat 0 100` (95 ∈ [0, 100])
-3. Generate proofs: `by decide`, `by omega`
-4. Validate at runtime if proof fails
+*Parser does:* 1. Infer types: `+'My Evidence' : NonEmptyString+`
+(length > 0) 2. Infer types: `+95 : BoundedNat 0 100+` (95 ∈ [0, 100])
+3. Generate proofs: `+by decide+`, `+by omega+` 4. Validate at runtime
+if proof fails
-### Tier 2: Admin (GQL-DT) - Explicit Types
+==== Tier 2: Admin (GQL-DT) - Explicit Types
-```lean
+[source,lean]
+----
-- Admin writes with types
INSERT INTO evidence (
title : NonEmptyString,
@@ -254,22 +273,20 @@ WITH_PROOF {
title_nonempty: by decide,
score_in_bounds: by omega
};
-```
+----
-**Parser does:**
-1. Parse explicit types
-2. Verify proofs at compile time
-3. Reject if proofs fail
-4. Zero runtime overhead (proofs erased)
+*Parser does:* 1. Parse explicit types 2. Verify proofs at compile time
+3. Reject if proofs fail 4. Zero runtime overhead (proofs erased)
----
+'''''
-## 6. Preventing Admin Burden
+=== 6. Preventing Admin Burden
-### Problem: Users Make Mistakes, Admins Fix Them
+==== Problem: Users Make Mistakes, Admins Fix Them
-**Traditional approach (BAD):**
-```
+*Traditional approach (BAD):*
+
+....
User enters bad data
↓
Data stored in database
@@ -279,10 +296,11 @@ Admin discovers error
Admin manually fixes data
↓
Admin wastes time
-```
+....
+
+*GQL-DT approach (GOOD):*
-**GQL-DT approach (GOOD):**
-```
+....
User enters bad data via GQL
↓
Type inference + validation
@@ -296,11 +314,12 @@ User sees: "Use value between 0 and 100"
User fixes BEFORE data stored
↓
Admin never sees the mistake
-```
+....
-### Implementation: Pre-Commit Validation
+==== Implementation: Pre-Commit Validation
-```lean
+[source,lean]
+----
-- Transaction validation hook
def validateTransaction (query : String) (user : User) : IO (Except String Unit) := do
-- Parse as GQL (user tier)
@@ -333,15 +352,16 @@ def userInsertAPI (user : User) (query : String) : IO Unit := do
IO.println s!"✗ Transaction rejected: {msg}"
IO.println "Your data was NOT stored (rollback)"
-- User must fix query before any data is touched
-```
+----
----
+'''''
-## 7. Type Safety Guarantees
+=== 7. Type Safety Guarantees
-### Theorem: Well-Typed Queries Can't Produce Runtime Type Errors
+==== Theorem: Well-Typed Queries Can’t Produce Runtime Type Errors
-```lean
+[source,lean]
+----
-- If a query type-checks, it can't fail at runtime (for type reasons)
theorem wellTyped_no_runtime_errors
(stmt : InsertStmt schema)
@@ -353,104 +373,105 @@ theorem wellTyped_no_runtime_errors
-- Therefore: execution can fail for OTHER reasons (disk full, etc.)
-- but NEVER for type errors
sorry
-```
+----
-### What This Means in Practice
+==== What This Means in Practice
-**GQL-DT queries (compile-time checked):**
-- ✅ Can't insert out-of-bounds values
-- ✅ Can't create empty strings where non-empty required
-- ✅ Can't forget rationale
-- ✅ Can't violate foreign keys (with proper schema)
-- ✅ Can't break normal forms (if TARGET_NORMAL_FORM set)
+*GQL-DT queries (compile-time checked):* - ✅ Can’t insert out-of-bounds
+values - ✅ Can’t create empty strings where non-empty required - ✅
+Can’t forget rationale - ✅ Can’t violate foreign keys (with proper
+schema) - ✅ Can’t break normal forms (if TARGET_NORMAL_FORM set)
-**GQL queries (runtime checked):**
-- ✅ Can't insert out-of-bounds values (rejected before commit)
-- ✅ Can't create empty strings (validation before commit)
-- ✅ Can't forget rationale (parser enforces)
-- ⚠️ Type errors possible if validation disabled (bad admin config)
+*GQL queries (runtime checked):* - ✅ Can’t insert out-of-bounds values
+(rejected before commit) - ✅ Can’t create empty strings (validation
+before commit) - ✅ Can’t forget rationale (parser enforces) - ⚠️ Type
+errors possible if validation disabled (bad admin config)
----
+'''''
-## 8. Implementation Status
+=== 8. Implementation Status
-### ✅ Implemented Today
+==== ✅ Implemented Today
-- [x] Type-indexed values (`TypedValue`)
-- [x] Type-safe AST (`InsertStmt`, `SelectStmt`)
-- [x] Smart constructors with proof obligations
-- [x] Type checker with validation
-- [x] Proof obligation generation
-- [x] Error messages with suggestions
-- [x] Examples demonstrating type safety
+* [x] Type-indexed values (`+TypedValue+`)
+* [x] Type-safe AST (`+InsertStmt+`, `+SelectStmt+`)
+* [x] Smart constructors with proof obligations
+* [x] Type checker with validation
+* [x] Proof obligation generation
+* [x] Error messages with suggestions
+* [x] Examples demonstrating type safety
-### 🔧 Next Steps
+==== 🔧 Next Steps
-- [ ] Parser implementation (parse text → typed AST)
-- [ ] Type inference algorithm (GQL → GQL-DT)
-- [ ] Auto-proof tactics (omega, decide, simp)
-- [ ] Runtime validation fallback
-- [ ] Permission system integration
+* [ ] Parser implementation (parse text → typed AST)
+* [ ] Type inference algorithm (GQL → GQL-DT)
+* [ ] Auto-proof tactics (omega, decide, simp)
+* [ ] Runtime validation fallback
+* [ ] Permission system integration
----
+'''''
-## 9. Answers to Your Questions
+=== 9. Answers to Your Questions
-### Q: "How do we prevent annoying users from messing up?"
+==== Q: "`How do we prevent annoying users from messing up?`"
-**A: Four-layer defense:**
+*A: Four-layer defense:*
-1. **UI layer** - Lithoglyph Studio uses forms/dropdowns (users can't type invalid values)
-2. **GQL layer** - Type inference + runtime validation (errors before commit)
-3. **GQL-DT layer** - Compile-time proofs (queries won't even run if invalid)
-4. **Database layer** - Final constraint checks (safety net)
+[arabic]
+. *UI layer* - Lithoglyph Studio uses forms/dropdowns (users can’t type
+invalid values)
+. *GQL layer* - Type inference + runtime validation (errors before
+commit)
+. *GQL-DT layer* - Compile-time proofs (queries won’t even run if
+invalid)
+. *Database layer* - Final constraint checks (safety net)
-**Result:** Invalid data **never reaches the database**. Admins never see user mistakes.
+*Result:* Invalid data *never reaches the database*. Admins never see
+user mistakes.
-### Q: "Should I deal with two-tier design now or later?"
+==== Q: "`Should I deal with two-tier design now or later?`"
-**A: NOW (during M6 Parser implementation)**
+*A: NOW (during M6 Parser implementation)*
-**Why:**
-- Parser architecture affects both tiers
-- AST must support type inference
-- Type checker needs dual mode (explicit vs inferred)
-- Easier to build together than retrofit
+*Why:* - Parser architecture affects both tiers - AST must support type
+inference - Type checker needs dual mode (explicit vs inferred) - Easier
+to build together than retrofit
-**What to implement in M6:**
-- M6a: GQL-DT parser (explicit types)
-- M6b: GQL parser (type inference)
-- M6c: Unified type checker (validates both)
+*What to implement in M6:* - M6a: GQL-DT parser (explicit types) - M6b:
+GQL parser (type inference) - M6c: Unified type checker (validates both)
----
+'''''
-## 10. Type Safety Examples
+=== 10. Type Safety Examples
-### Example 1: Bounds Enforcement
+==== Example 1: Bounds Enforcement
-```lean
+[source,lean]
+----
-- ✓ COMPILES
def valid : BoundedNat 0 100 := ⟨95, by omega, by omega⟩
-- ✗ DOESN'T COMPILE
def invalid : BoundedNat 0 100 := ⟨150, by omega, by omega⟩
-- Error: tactic 'omega' failed, unable to prove ⊢ 150 ≤ 100
-```
+----
-### Example 2: Non-Empty Enforcement
+==== Example 2: Non-Empty Enforcement
-```lean
+[source,lean]
+----
-- ✓ COMPILES
def valid : NonEmptyString := ⟨"hello", by decide⟩
-- ✗ DOESN'T COMPILE
def invalid : NonEmptyString := ⟨"", by decide⟩
-- Error: tactic 'decide' failed, unable to prove ⊢ String.length "" > 0
-```
+----
-### Example 3: Type Match Enforcement
+==== Example 3: Type Match Enforcement
-```lean
+[source,lean]
+----
-- Schema expects NonEmptyString
-- ✓ COMPILES
INSERT INTO evidence (title) VALUES (NonEmptyString.mk "Title" proof)
@@ -458,43 +479,43 @@ INSERT INTO evidence (title) VALUES (NonEmptyString.mk "Title" proof)
-- ✗ DOESN'T COMPILE
INSERT INTO evidence (title) VALUES ("plain string")
-- Error: type mismatch, expected NonEmptyString, got String
-```
+----
-### Example 4: Provenance Enforcement
+==== Example 4: Provenance Enforcement
-```lean
+[source,lean]
+----
-- ✓ COMPILES: Has rationale
insertEvidence title scores (NonEmptyString.mk "reason" proof)
-- ✗ DOESN'T COMPILE: Missing rationale
insertEvidence title scores
-- Error: function expected 3 arguments, got 2
-```
+----
----
+'''''
-## Conclusion
+=== Conclusion
-**The parser enforces type safety by:**
+*The parser enforces type safety by:*
-1. **Type-indexed AST** - Values carry their types at compile time
-2. **Proof obligations** - Construction requires proofs of correctness
-3. **Dependent types** - Types depend on values (bounds, lengths, etc.)
-4. **Smart constructors** - Only way to create AST nodes is through validated builders
-5. **Theorem proving** - Lean 4 verifies all proofs automatically
+[arabic]
+. *Type-indexed AST* - Values carry their types at compile time
+. *Proof obligations* - Construction requires proofs of correctness
+. *Dependent types* - Types depend on values (bounds, lengths, etc.)
+. *Smart constructors* - Only way to create AST nodes is through
+validated builders
+. *Theorem proving* - Lean 4 verifies all proofs automatically
-**Result:**
-- ❌ Invalid queries don't compile (GQL-DT tier)
-- ❌ Invalid queries don't commit (GQL tier)
-- ✅ Admins never fix user type errors
-- ✅ Database always contains valid data
+*Result:* - ❌ Invalid queries don’t compile (GQL-DT tier) - ❌ Invalid
+queries don’t commit (GQL tier) - ✅ Admins never fix user type errors -
+✅ Database always contains valid data
----
+'''''
-**Document Status:** Complete guide to type safety enforcement
+*Document Status:* Complete guide to type safety enforcement
-**See Also:**
-- `src/GqlDt/AST.lean` - Type-safe AST
-- `src/GqlDt/TypeSafe.lean` - Smart constructors
-- `src/GqlDt/TypeChecker.lean` - Type checking algorithm
-- `test/TypeSafetyTests.lean` - Demonstrations
+*See Also:* - `+src/GqlDt/AST.lean+` - Type-safe AST -
+`+src/GqlDt/TypeSafe.lean+` - Smart constructors -
+`+src/GqlDt/TypeChecker.lean+` - Type checking algorithm -
+`+test/TypeSafetyTests.lean+` - Demonstrations
diff --git a/docs/WP06_Dependently_Typed_Lithoglyph.md b/docs/WP06_Dependently_Typed_Lithoglyph.adoc
similarity index 55%
rename from docs/WP06_Dependently_Typed_Lithoglyph.md
rename to docs/WP06_Dependently_Typed_Lithoglyph.adoc
index 4d56030..8c90e68 100644
--- a/docs/WP06_Dependently_Typed_Lithoglyph.md
+++ b/docs/WP06_Dependently_Typed_Lithoglyph.adoc
@@ -1,22 +1,35 @@
-# White Paper 06: Dependently-Typed Lithoglyph
-
-**Status**: Research Proposal
-**Version**: 0.1.0
-**Date**: 2025-01-11
-**Authors**: Jonathan D.A. Jewell, Claude (Anthropic)
-**License**: MPL-2.0
-
-## Abstract
-
-Lithoglyph's narrative-first architecture demands stronger correctness guarantees than traditional databases can provide. We propose extending Lithoglyph with dependent types—types that depend on values—enabling compile-time verification of epistemic properties. This transforms Lithoglyph from a database that *records* provenance to one that *proves* provenance. We demonstrate how dependent types naturally express PROMPT score constraints, provenance tracking, reversibility proofs, and belief fusion in the My-Newsroom multi-agent system. Our approach is incremental: refinement types first (simple, high ROI), then full dependent types (research frontier). This positions Lithoglyph as the first database with **provable epistemology**, uniquely suited for journalism, scientific reproducibility, and AI agent collaboration where correctness is non-negotiable.
-
-## 1. Introduction
-
-### 1.1 The Problem: Runtime Correctness Is Insufficient
-
-Traditional databases enforce correctness at **runtime**:
-
-```sql
+== White Paper 06: Dependently-Typed Lithoglyph
+
+*Status*: Research Proposal +
+*Version*: 0.1.0 +
+*Date*: 2025-01-11 +
+*Authors*: Jonathan D.A. Jewell, Claude (Anthropic) +
+*License*: MPL-2.0
+
+=== Abstract
+
+Lithoglyph’s narrative-first architecture demands stronger correctness
+guarantees than traditional databases can provide. We propose extending
+Lithoglyph with dependent types—types that depend on values—enabling
+compile-time verification of epistemic properties. This transforms
+Lithoglyph from a database that _records_ provenance to one that
+_proves_ provenance. We demonstrate how dependent types naturally
+express PROMPT score constraints, provenance tracking, reversibility
+proofs, and belief fusion in the My-Newsroom multi-agent system. Our
+approach is incremental: refinement types first (simple, high ROI), then
+full dependent types (research frontier). This positions Lithoglyph as
+the first database with *provable epistemology*, uniquely suited for
+journalism, scientific reproducibility, and AI agent collaboration where
+correctness is non-negotiable.
+
+=== 1. Introduction
+
+==== 1.1 The Problem: Runtime Correctness Is Insufficient
+
+Traditional databases enforce correctness at *runtime*:
+
+[source,sql]
+----
-- SQL: Runtime constraint
CREATE TABLE evidence (
prompt_provenance INT CHECK (prompt_provenance BETWEEN 0 AND 100)
@@ -25,19 +38,20 @@ CREATE TABLE evidence (
-- Valid at compile time, error at insert
INSERT INTO evidence (prompt_provenance) VALUES (150);
-- ERROR: Check constraint "prompt_provenance_range" violated
-```
+----
-**Problems**:
-1. **Late detection**: Errors caught during execution, not development
-2. **Incomplete coverage**: Can't express "every UPDATE must have REASON"
-3. **No proofs**: Can't prove invariants hold across all operations
-4. **Agent confusion**: LLM agents struggle with runtime-only validation
+*Problems*: 1. *Late detection*: Errors caught during execution, not
+development 2. *Incomplete coverage*: Can’t express "`every UPDATE must
+have REASON`" 3. *No proofs*: Can’t prove invariants hold across all
+operations 4. *Agent confusion*: LLM agents struggle with runtime-only
+validation
-### 1.2 The Solution: Dependent Types
+==== 1.2 The Solution: Dependent Types
-**Dependent types** are types that depend on values:
+*Dependent types* are types that depend on values:
-```idris
+[source,idris]
+----
-- Idris: Compile-time proof
data PromptScore : Type where
MkPromptScore : (n : Nat) ->
@@ -47,69 +61,76 @@ data PromptScore : Type where
-- Invalid score is a TYPE ERROR, caught immediately
badScore : PromptScore
badScore = MkPromptScore 150 -- TYPE ERROR: Can't prove LTE 150 100
-```
+----
-**Benefits**:
-1. **Early detection**: Type errors at compile time (or before)
-2. **Complete coverage**: Type system enforces ALL invariants
-3. **Machine-checkable proofs**: Types ARE proofs (Curry-Howard correspondence)
-4. **Agent-friendly**: LLM agents can check types before generating code
+*Benefits*: 1. *Early detection*: Type errors at compile time (or
+before) 2. *Complete coverage*: Type system enforces ALL invariants 3.
+*Machine-checkable proofs*: Types ARE proofs (Curry-Howard
+correspondence) 4. *Agent-friendly*: LLM agents can check types before
+generating code
-### 1.3 Why Lithoglyph Needs This
+==== 1.3 Why Lithoglyph Needs This
-Lithoglyph has **unique epistemic requirements**:
+Lithoglyph has *unique epistemic requirements*:
-| Requirement | Current (Runtime) | With Dependent Types |
-|-------------|-------------------|---------------------|
-| PROMPT scores in [0, 100] | Runtime CHECK | Compile-time proof |
-| Every INSERT needs RATIONALE | Parser check | Type system enforces |
-| Provenance tracked | Application code | Baked into types |
-| Operations reversible | Runtime verification | Proof of inverse exists |
-| Confidence levels valid | Runtime CHECK | Type-level bounds |
-| Navigation paths ordered | Runtime sort | Type proves ordering |
+[width="100%",cols="26%,35%,39%",options="header",]
+|===
+|Requirement |Current (Runtime) |With Dependent Types
+|PROMPT scores in [0, 100] |Runtime CHECK |Compile-time proof
+|Every INSERT needs RATIONALE |Parser check |Type system enforces
+|Provenance tracked |Application code |Baked into types
+|Operations reversible |Runtime verification |Proof of inverse exists
+|Confidence levels valid |Runtime CHECK |Type-level bounds
+|Navigation paths ordered |Runtime sort |Type proves ordering
+|===
-**Thesis**: Dependent types transform Lithoglyph from a database that *records* epistemology to one that *proves* epistemology.
+*Thesis*: Dependent types transform Lithoglyph from a database that
+_records_ epistemology to one that _proves_ epistemology.
-## 2. Background: Dependent Types
+=== 2. Background: Dependent Types
-### 2.1 What Are Dependent Types?
+==== 2.1 What Are Dependent Types?
-**Simple types** (SQL, most PLs):
-```
+*Simple types* (SQL, most PLs):
+
+....
Int, String, Boolean
Array, Maybe
-```
+....
+
+*Dependent types* (Idris, Agda, Lean):
-**Dependent types** (Idris, Agda, Lean):
-```
+....
Vector n Int -- Array of EXACTLY n integers
Bounded 0 100 Int -- Integer between 0 and 100
{x : Int | x > 0} -- Refinement: positive integers
-```
+....
-Key insight: **Types can mention values**, enabling precise specifications.
+Key insight: *Types can mention values*, enabling precise
+specifications.
-### 2.2 Refinement Types (Subset of Dependent Types)
+==== 2.2 Refinement Types (Subset of Dependent Types)
-**Refinement types** restrict existing types with predicates:
+*Refinement types* restrict existing types with predicates:
-```idris
+[source,idris]
+----
-- Base type + predicate
type PositiveInt = {n : Int | n > 0}
type Email = {s : String | matches s emailRegex}
type PromptScore = {n : Nat | 0 <= n && n <= 100}
-```
+----
-**Why start here?**
-- Easier to understand than full dependent types
-- High ROI: catches most errors
-- Libraries exist (Liquid Haskell, F*, Dafny)
+*Why start here?* - Easier to understand than full dependent types -
+High ROI: catches most errors - Libraries exist (Liquid Haskell, F*,
+Dafny)
-### 2.3 Full Dependent Types
+==== 2.3 Full Dependent Types
-**Full dependent types** allow arbitrary value dependencies:
+*Full dependent types* allow arbitrary value dependencies:
-```idris
+[source,idris]
+----
-- Length-indexed vectors
data Vect : Nat -> Type -> Type where
Nil : Vect 0 a
@@ -121,18 +142,17 @@ head (x :: xs) = x
-- Concatenation preserves length
(++) : Vect n a -> Vect m a -> Vect (n + m) a
-```
+----
-**Why eventually move here?**
-- Express complex invariants (navigation path ordering)
-- Prove operations correct (reversibility)
-- Enable advanced reasoning (belief fusion proofs)
+*Why eventually move here?* - Express complex invariants (navigation
+path ordering) - Prove operations correct (reversibility) - Enable
+advanced reasoning (belief fusion proofs)
-### 2.4 Curry-Howard Correspondence
+==== 2.4 Curry-Howard Correspondence
-**Key insight**: Types = Propositions, Programs = Proofs
+*Key insight*: Types = Propositions, Programs = Proofs
-```
+....
Mathematical Logic Programming
-------------------- ---------------------
Proposition Type
@@ -142,25 +162,30 @@ Implication (A → B) Function type (A -> B)
Conjunction (A ∧ B) Product type (A, B)
Disjunction (A ∨ B) Sum type (Either A B)
Universal (∀x. P(x)) Dependent function (x : A) -> P x
-```
+....
-**Example**:
-```idris
+*Example*:
+
+[source,idris]
+----
-- Proposition: "For all n, n + 0 = n"
plusZeroRightNeutral : (n : Nat) -> n + 0 = n
plusZeroRightNeutral Z = Refl -- Proof for zero
plusZeroRightNeutral (S k) = -- Proof for successor
rewrite plusZeroRightNeutral k in Refl
-```
+----
+
+*For Lithoglyph*: Type-checking = Proof-checking. If it compiles, the
+proof is valid!
-**For Lithoglyph**: Type-checking = Proof-checking. If it compiles, the proof is valid!
+=== 3. Motivation: Lithoglyph’s Epistemic Requirements
-## 3. Motivation: Lithoglyph's Epistemic Requirements
+==== 3.1 PROMPT Score Invariants
-### 3.1 PROMPT Score Invariants
+*Current* (runtime):
-**Current** (runtime):
-```gql
+[source,gql]
+----
CREATE COLLECTION evidence (
prompt_scores STRUCT {
provenance INT CHECK (provenance BETWEEN 0 AND 100),
@@ -173,16 +198,16 @@ CREATE COLLECTION evidence (
methodology + publication + transparency) / 6.0
}
);
-```
+----
+
+*Problems*: 1. Can construct invalid struct: `+{provenance: 150, ...}+`
+2. Runtime error only on INSERT 3. No proof that `+overall+` is in [0,
+100] 4. Agents might hallucinate invalid scores
-**Problems**:
-1. Can construct invalid struct: `{provenance: 150, ...}`
-2. Runtime error only on INSERT
-3. No proof that `overall` is in [0, 100]
-4. Agents might hallucinate invalid scores
+*With Dependent Types*:
-**With Dependent Types**:
-```idris
+[source,idris]
+----
-- Refinement type: scores in [0, 100]
PromptDimension : Type
PromptDimension = BoundedNat 0 100
@@ -209,25 +234,28 @@ computeOverall : PromptDimension -> PromptDimension -> PromptDimension ->
computeOverall p r o m pub t =
MkBounded ((p + r + o + m + pub + t) `div` 6)
{prf = averageInBounds p r o m pub t}
-```
+----
-**Benefits**:
-- Invalid scores are TYPE ERRORS (caught at compile time)
-- Proof that `overall` is always in range
-- Agents can type-check before execution
+*Benefits*: - Invalid scores are TYPE ERRORS (caught at compile time) -
+Proof that `+overall+` is always in range - Agents can type-check before
+execution
-### 3.2 Mandatory Rationale
+==== 3.2 Mandatory Rationale
-**Current** (parser):
-```gql
+*Current* (parser):
+
+[source,gql]
+----
INSERT INTO claims (text) VALUES ('Some claim');
-- Parser error: "Missing RATIONALE clause"
-```
+----
+
+*Problem*: Easy to forget in generated code. Parser can be bypassed.
-**Problem**: Easy to forget in generated code. Parser can be bypassed.
+*With Dependent Types*:
-**With Dependent Types**:
-```idris
+[source,idris]
+----
-- Operations MUST carry provenance
data ProvenanceTracked : Type -> Type where
MkTracked :
@@ -242,30 +270,31 @@ insertClaim : (text : String) ->
(rationale : NonEmptyString) -> -- Required argument!
(actor : String) ->
ProvenanceTracked Claim
-```
+----
-**Benefits**:
-- Impossible to forget RATIONALE (type error)
-- Type system enforces ALL insertions have provenance
-- LLM agents see type signature, know what's required
+*Benefits*: - Impossible to forget RATIONALE (type error) - Type system
+enforces ALL insertions have provenance - LLM agents see type signature,
+know what’s required
-### 3.3 Reversibility Proofs
+==== 3.3 Reversibility Proofs
-**Current** (runtime verification):
-```gql
+*Current* (runtime verification):
+
+[source,gql]
+----
-- Claim operation is reversible
INSERT INTO claims (text) VALUES ('X') RATIONALE "...";
-- Lithoglyph generates inverse: DELETE FROM claims WHERE id = 'uuid'
-- Tests at runtime that inverse works
-```
+----
+
+*Problem*: - Inverse might be wrong (subtle bugs) - Only tested on
+specific data - No guarantee for ALL possible inputs
-**Problem**:
-- Inverse might be wrong (subtle bugs)
-- Only tested on specific data
-- No guarantee for ALL possible inputs
+*With Dependent Types*:
-**With Dependent Types**:
-```idris
+[source,idris]
+----
-- Operations carry proof of inverse
data Reversible : Type -> Type where
Insert : (data : a) ->
@@ -288,22 +317,25 @@ data Reversible : Type -> Type where
roundTrip : a -> (a -> a) -> a
roundTripPreservesIdentity : (x : a) -> (f : a -> a) ->
roundTrip x f = x
-```
+----
-**Benefits**:
-- **Mathematical proof** that inverse is correct
-- Proof holds for ALL inputs, not just tested cases
-- Can't mark something irreversible without proving why
+*Benefits*: - *Mathematical proof* that inverse is correct - Proof holds
+for ALL inputs, not just tested cases - Can’t mark something
+irreversible without proving why
-### 3.4 Confidence Levels
+==== 3.4 Confidence Levels
-**Current**:
-```gql
+*Current*:
+
+[source,gql]
+----
confidence_level FLOAT CHECK (confidence_level BETWEEN 0.0 AND 1.0)
-```
+----
+
+*With Dependent Types*:
-**With Dependent Types**:
-```idris
+[source,idris]
+----
-- Confidence in [0.0, 1.0]
Confidence : Type
Confidence = BoundedFloat 0.0 1.0
@@ -319,17 +351,18 @@ data Claim : Confidence -> Type where
combineClaims : Claim c1 -> Claim c2 ->
{auto prf : Compatible c1 c2} ->
Claim (fuseConfidence c1 c2)
-```
+----
-**Benefits**:
-- Confidence can't exceed 1.0 (type error)
-- Type proves confidence matches evidence
-- Combining claims requires proof of compatibility
+*Benefits*: - Confidence can’t exceed 1.0 (type error) - Type proves
+confidence matches evidence - Combining claims requires proof of
+compatibility
-### 3.5 Navigation Path Ordering
+==== 3.5 Navigation Path Ordering
-**Current**:
-```gql
+*Current*:
+
+[source,gql]
+----
-- Navigation path (runtime sorting)
CREATE NAVIGATION_PATH 'skeptic_path'
BEGIN
@@ -337,12 +370,14 @@ BEGIN
NODE claims WHERE claim_type = 'COUNTER';
-- ... etc
END;
-```
+----
+
+*Problem*: Ordering is application logic, not proven.
-**Problem**: Ordering is application logic, not proven.
+*With Dependent Types*:
-**With Dependent Types**:
-```idris
+[source,idris]
+----
-- Paths indexed by ordering predicate
data NavigationPath : (ordering : Evidence -> Evidence -> Bool) -> Type where
MkPath : (nodes : List Evidence) ->
@@ -353,40 +388,33 @@ data NavigationPath : (ordering : Evidence -> Evidence -> Bool) -> Type where
createSkepticPath : List Evidence -> NavigationPath (orderByObjective)
createSkepticPath evs = MkPath (sort orderByObjective evs)
{prf = sortProducesSorted _ _}
-```
+----
-**Benefits**:
-- Type proves path satisfies ordering invariant
-- Can't create invalid path (type error)
-- Different audiences get different ordering proofs
+*Benefits*: - Type proves path satisfies ordering invariant - Can’t
+create invalid path (type error) - Different audiences get different
+ordering proofs
-## 4. Type System Design
+=== 4. Type System Design
-### 4.1 Three-Tier Approach
+==== 4.1 Three-Tier Approach
-**Tier 1: Refinement Types** (Month 1-6)
-- Bounded integers: `BoundedNat 0 100`
-- Non-null strings: `NonEmptyString`
-- Bounded floats: `BoundedFloat 0.0 1.0`
-- Pattern-matched enums
+*Tier 1: Refinement Types* (Month 1-6) - Bounded integers:
+`+BoundedNat 0 100+` - Non-null strings: `+NonEmptyString+` - Bounded
+floats: `+BoundedFloat 0.0 1.0+` - Pattern-matched enums
-**Tier 2: Simple Dependent Types** (Month 7-12)
-- Length-indexed arrays: `Vect n a`
-- Computed fields with proofs
-- Provenance-tracked values: `Tracked a`
-- Type-safe edges: `Edge from to`
+*Tier 2: Simple Dependent Types* (Month 7-12) - Length-indexed arrays:
+`+Vect n a+` - Computed fields with proofs - Provenance-tracked values:
+`+Tracked a+` - Type-safe edges: `+Edge from to+`
-**Tier 3: Full Dependent Types** (Month 13-18)
-- Reversibility proofs
-- Belief fusion proofs
-- Path ordering proofs
-- Complex invariants
+*Tier 3: Full Dependent Types* (Month 13-18) - Reversibility proofs -
+Belief fusion proofs - Path ordering proofs - Complex invariants
-### 4.2 Core Type Definitions
+==== 4.2 Core Type Definitions
-#### **4.2.1 Bounded Types**
+===== *4.2.1 Bounded Types*
-```idris
+[source,idris]
+----
-- Bounded natural numbers
data BoundedNat : (min : Nat) -> (max : Nat) -> Type where
MkBounded : (n : Nat) ->
@@ -408,11 +436,12 @@ Confidence = BoundedFloat 0.0 1.0
Percentage : Type
Percentage = BoundedFloat 0.0 100.0
-```
+----
-#### **4.2.2 Non-Empty Strings**
+===== *4.2.2 Non-Empty Strings*
-```idris
+[source,idris]
+----
-- Strings that can't be empty
data NonEmptyString : Type where
MkNonEmpty : (s : String) ->
@@ -425,11 +454,12 @@ Rationale = NonEmptyString
ActorId : Type
ActorId = NonEmptyString
-```
+----
-#### **4.2.3 Provenance-Tracked Values**
+===== *4.2.3 Provenance-Tracked Values*
-```idris
+[source,idris]
+----
-- Every value carries its provenance
data Tracked : Type -> Type where
MkTracked :
@@ -445,11 +475,12 @@ getValue (MkTracked v _ _ _) = v
getProvenance : Tracked a -> (ActorId, Timestamp, Rationale)
getProvenance (MkTracked _ actor ts rat) = (actor, ts, rat)
-```
+----
-#### **4.2.4 PROMPT Scores**
+===== *4.2.4 PROMPT Scores*
-```idris
+[source,idris]
+----
data PromptScores : Type where
MkPromptScores :
(provenance : PromptDimension) ->
@@ -478,11 +509,12 @@ averagePreservesBounds : (p, r, o, m, pub, t : Nat) ->
LTE p 100 -> LTE r 100 -> LTE o 100 ->
LTE m 100 -> LTE pub 100 -> LTE t 100 ->
LTE ((p + r + o + m + pub + t) `div` 6) 100
-```
+----
-#### **4.2.5 Collections (Tables)**
+===== *4.2.5 Collections (Tables)*
-```idris
+[source,idris]
+----
-- Collection indexed by row type
data Collection : Type -> Type where
MkCollection : (name : String) ->
@@ -497,11 +529,12 @@ insert (MkCollection name rows) value actor ts rat =
-- Type-safe query
query : Collection a -> (a -> Bool) -> List (Tracked a)
query (MkCollection _ rows) predicate = filter (predicate . getValue) rows
-```
+----
-#### **4.2.6 Edge Collections**
+===== *4.2.6 Edge Collections*
-```idris
+[source,idris]
+----
-- Edges between specific types
data Edge : Type -> Type -> Type where
MkEdge :
@@ -516,11 +549,12 @@ data Edge : Type -> Type -> Type where
traverse : List (Edge a b) -> a -> List b
traverse edges start =
[getValue to | MkEdge from to _ _ _ <- edges, getValue from == start]
-```
+----
-#### **4.2.7 Reversible Operations**
+===== *4.2.7 Reversible Operations*
-```idris
+[source,idris]
+----
-- Operations with proven inverses
data ReversibleOp : Type -> Type where
Insert : (data : Tracked a) ->
@@ -551,13 +585,14 @@ data JournalEntry : Type where
(actor : ActorId) ->
(operation : ReversibleOp a) ->
JournalEntry
-```
+----
-### 4.3 GQL Syntax Extensions
+==== 4.3 GQL Syntax Extensions
-#### **4.3.1 Type Annotations**
+===== *4.3.1 Type Annotations*
-```gql
+[source,gql]
+----
-- Current GQL
CREATE COLLECTION evidence (
prompt_scores STRUCT {
@@ -572,11 +607,12 @@ CREATE COLLECTION evidence (
prompt_scores : PromptScores, -- Type carries proofs!
added : Tracked () -- Provenance automatically tracked
) WITH DEPENDENT_TYPES;
-```
+----
-#### **4.3.2 Insertion with Proof Obligations**
+===== *4.3.2 Insertion with Proof Obligations*
-```gql
+[source,gql]
+----
-- Type checker generates proof obligations
INSERT INTO evidence (title, prompt_scores)
VALUES (
@@ -591,22 +627,24 @@ RATIONALE "Official UK statistics";
-- 2. Overall computed correctly ✓
-- 3. Rationale non-empty ✓
-- 4. Operation reversible ✓
-```
+----
-#### **4.3.3 Queries with Refinements**
+===== *4.3.3 Queries with Refinements*
-```gql
+[source,gql]
+----
-- Query with type refinement
SELECT * FROM evidence
WHERE prompt_scores.overall > 90
RETURNING (e : Evidence | e.prompt_scores.overall > 90);
-- Return type PROVES all results satisfy predicate
-```
+----
-#### **4.3.4 Verified Updates**
+===== *4.3.4 Verified Updates*
-```gql
+[source,gql]
+----
-- Update with proof of correctness
UPDATE claims
SET text = 'New text',
@@ -618,13 +656,13 @@ WITH_PROOF {
correction_documented: Proof, -- Reason is non-empty
reversible: Proof -- Inverse operation exists
};
-```
+----
-## 5. Implementation Strategy
+=== 5. Implementation Strategy
-### 5.1 Architecture
+==== 5.1 Architecture
-```
+....
┌──────────────────────────────────────────────────┐
│ GQL Source Code (with dependent type syntax) │
└────────────────┬─────────────────────────────────┘
@@ -654,61 +692,58 @@ WITH_PROOF {
│ • Factor (Runtime) │
│ • Elixir (ControlPlane) │
└──────────────────────────────────────────────────┘
-```
-
-### 5.2 Phase 1: External Type Checker (Month 1-6)
-
-**Goal**: Opt-in type checking without changing Lithoglyph runtime.
-
-**Implementation**:
-1. **GQL Parser Extension**:
- ```elixir
- # Parse dependent type annotations
- defmodule GQL.Parser.DependentTypes do
- def parse_type_annotation(tokens) do
- # Parse: "x : BoundedNat 0 100"
- # Returns: {:bounded_nat, 0, 100}
- end
- end
- ```
-
-2. **Type Checker (Idris 2)**:
- ```idris
- -- Lithoglyph.idr
- module Lithoglyph.TypeChecker
-
- import Lithoglyph.Core -- Core type definitions
-
- -- Check GQL program
- checkProgram : String -> Either TypeError (Program, List Proof)
- checkProgram source = do
- ast <- parseGQL source
- (typedAST, proofs) <- inferTypes ast
- checkProofs proofs
- pure (typedAST, proofs)
- ```
-
-3. **Integration Script**:
- ```bash
- #!/bin/bash
- # check_gql.sh
-
- # 1. Type check with Idris
- idris2 --check Lithoglyph.idr $1
- if [ $? -ne 0 ]; then
- echo "Type checking failed!"
- exit 1
- fi
-
- # 2. Generate runtime GQL
- idris2 --codegen gql Lithoglyph.idr $1 > output.gql
-
- # 3. Execute on Lithoglyph
- lithoglyph execute output.gql
- ```
-
-**Usage**:
-```bash
+....
+
+==== 5.2 Phase 1: External Type Checker (Month 1-6)
+
+*Goal*: Opt-in type checking without changing Lithoglyph runtime.
+
+*Implementation*: 1. *GQL Parser Extension*:
+`+elixir # Parse dependent type annotations defmodule GQL.Parser.DependentTypes do def parse_type_annotation(tokens) do # Parse: "x : BoundedNat 0 100" # Returns: {:bounded_nat, 0, 100} end end+`
+
+[arabic, start=2]
+. *Type Checker (Idris 2)*:
++
+[source,idris]
+----
+-- Lithoglyph.idr
+module Lithoglyph.TypeChecker
+
+import Lithoglyph.Core -- Core type definitions
+
+-- Check GQL program
+checkProgram : String -> Either TypeError (Program, List Proof)
+checkProgram source = do
+ ast <- parseGQL source
+ (typedAST, proofs) <- inferTypes ast
+ checkProofs proofs
+ pure (typedAST, proofs)
+----
+. *Integration Script*:
++
+[source,bash]
+----
+#!/bin/bash
+# check_gql.sh
+
+# 1. Type check with Idris
+idris2 --check Lithoglyph.idr $1
+if [ $? -ne 0 ]; then
+ echo "Type checking failed!"
+ exit 1
+fi
+
+# 2. Generate runtime GQL
+idris2 --codegen gql Lithoglyph.idr $1 > output.gql
+
+# 3. Execute on Lithoglyph
+lithoglyph execute output.gql
+----
+
+*Usage*:
+
+[source,bash]
+----
# Write GQL with types
cat > example.gql.idr
CREATE COLLECTION evidence (
@@ -721,14 +756,16 @@ INSERT INTO evidence VALUES (...);
# Type check + execute
./check_gql.sh example.gql.idr
-```
+----
+
+==== 5.3 Phase 2: Proof-Carrying Code (Month 7-12)
-### 5.3 Phase 2: Proof-Carrying Code (Month 7-12)
+*Goal*: Store proofs alongside data in journal.
-**Goal**: Store proofs alongside data in journal.
+*Journal Format*:
-**Journal Format**:
-```forth
+[source,forth]
+----
\ Forth journal entry with proof
: JOURNAL-ENTRY ( timestamp operation data rationale proof -- )
CREATE-ENTRY
@@ -738,10 +775,12 @@ INSERT INTO evidence VALUES (...);
, rationale-string
, proof-blob \ NEW: Serialized Idris proof object
;
-```
+----
-**Serialized Proof**:
-```json
+*Serialized Proof*:
+
+[source,json]
+----
{
"proof_type": "BoundedNatProof",
"theorem": "LTE 95 100",
@@ -749,25 +788,28 @@ INSERT INTO evidence VALUES (...);
"verified_by": "Idris 2.0",
"timestamp": "2024-01-15T10:00:00Z"
}
-```
+----
+
+*Verification*:
-**Verification**:
-```gql
+[source,gql]
+----
-- Query with proof verification
SELECT * FROM evidence
WHERE prompt_scores.provenance = 100
[VERIFY_PROOFS];
-- Returns data + proof verification results
-```
+----
-### 5.4 Phase 3: Verified Runtime (Month 13-24)
+==== 5.4 Phase 3: Verified Runtime (Month 13-24)
-**Goal**: Replace critical paths with verified code.
+*Goal*: Replace critical paths with verified code.
-**Approach**: Rewrite Zig bridge in Dafny or Lean:
+*Approach*: Rewrite Zig bridge in Dafny or Lean:
-```dafny
+[source,dafny]
+----
// Dafny: Verified bridge layer
method InsertWithProvenance(
data: Data,
@@ -784,26 +826,29 @@ method InsertWithProvenance(
var entry := Entry(data, actor, timestamp, rationale);
return Success(entry);
}
-```
+----
-**Compile to C** → Link with Forth/Zig → Verified bridge!
+*Compile to C* → Link with Forth/Zig → Verified bridge!
-### 5.5 Tooling
+==== 5.5 Tooling
-#### **5.5.1 IDE Support**
+===== *5.5.1 IDE Support*
-**Lean 4 LSP** (best IDE support):
-```
+*Lean 4 LSP* (best IDE support):
+
+....
$ lean4 --server
# Provides:
# - Type checking on save
# - Proof assistance (tactics)
# - Error highlighting
# - Type-on-hover
-```
+....
+
+*VSCode Extension*:
-**VSCode Extension**:
-```json
+[source,json]
+----
{
"name": "lithoglyph-dependent-types",
"displayName": "Lithoglyph Dependent Types",
@@ -819,12 +864,14 @@ $ lean4 --server
]
}
}
-```
+----
-#### **5.5.2 Proof Tactics**
+===== *5.5.2 Proof Tactics*
-**Auto-solving Simple Proofs**:
-```lean
+*Auto-solving Simple Proofs*:
+
+[source,lean]
+----
-- Lean 4 tactics for Lithoglyph
def lithoglyph_bounds : Tactic :=
-- Auto-solve bounded integer proofs
@@ -834,18 +881,20 @@ def lithoglyph_bounds : Tactic :=
example : 95 ≤ 100 := by lithoglyph_bounds
-- Proven automatically!
-```
+----
+
+===== *5.5.3 Error Messages*
-#### **5.5.3 Error Messages**
+*Current*:
-**Current**:
-```
+....
ERROR: Check constraint "prompt_provenance_range" violated
DETAIL: Failing row contains (150).
-```
+....
-**With Dependent Types**:
-```
+*With Dependent Types*:
+
+....
TYPE ERROR at line 5, column 12:
INSERT INTO evidence (prompt_scores) VALUES ({provenance: 150, ...})
@@ -859,23 +908,27 @@ Proof obligation: LTE 150 100
Failed: 150 > 100
Suggestion: Use a value between 0 and 100
-```
+....
Much clearer!
-## 6. Synergy with My-Newsroom
+=== 6. Synergy with My-Newsroom
+
+==== 6.1 Me Dialect Already Has Epistemic Types
-### 6.1 Me Dialect Already Has Epistemic Types
+*From My-Newsroom*:
-**From My-Newsroom**:
-```me
+[source,me]
+----
// Me dialect: Belief types
belief x: Float where confidence(0.75)
maybe y: Int where uncertainty(0.3)
-```
+----
-**Map to Dependent Types**:
-```idris
+*Map to Dependent Types*:
+
+[source,idris]
+----
-- Lithoglyph dependent types for beliefs
data Belief : (confidence : BoundedFloat 0.0 1.0) -> Type -> Type where
MkBelief : (value : a) ->
@@ -889,20 +942,24 @@ getBelief (MkBelief v _) = v
-- Extract confidence
getConfidence : Belief c a -> BoundedFloat 0.0 1.0
getConfidence (MkBelief _ c) = c
-```
+----
+
+==== 6.2 Type-Safe Dempster-Shafer Fusion
-### 6.2 Type-Safe Dempster-Shafer Fusion
+*Current* (Julia, runtime):
-**Current** (Julia, runtime):
-```julia
+[source,julia]
+----
# Julia: Runtime fusion
source_a = BeliefMass(Dict(Set(["true"]) => 0.85, θ => 0.15))
source_b = BeliefMass(Dict(Set(["true"]) => 0.60, θ => 0.40))
result = fuse_beliefs(source_a, source_b, Dempster)
-```
+----
-**With Dependent Types**:
-```idris
+*With Dependent Types*:
+
+[source,idris]
+----
-- Type-safe belief fusion
fuseBeliefsDS : Belief c1 a -> Belief c2 a -> Belief (fuse c1 c2) a
fuseBeliefsDS (MkBelief v1 c1) (MkBelief v2 c2) =
@@ -912,25 +969,27 @@ fuseBeliefsDS (MkBelief v1 c1) (MkBelief v2 c2) =
-- Proof that fusion preserves confidence bounds
fusionPreservesBounds : (c1, c2 : BoundedFloat 0.0 1.0) ->
BoundedFloat 0.0 1.0 (dempsterFusion c1 c2)
-```
+----
+
+*Benefits*: - Type system ensures fusion is valid - Proof that result
+confidence is in [0.0, 1.0] - Agent can check types before executing
-**Benefits**:
-- Type system ensures fusion is valid
-- Proof that result confidence is in [0.0, 1.0]
-- Agent can check types before executing
+==== 6.3 Agent Introspection with Proofs
-### 6.3 Agent Introspection with Proofs
+*Current*:
-**Current**:
-```gql
+[source,gql]
+----
-- Agent queries its reasoning
INTROSPECT belief_fusions
WHERE agent = 'agent_alpha'
RETURN reasoning;
-```
+----
-**With Dependent Types**:
-```gql
+*With Dependent Types*:
+
+[source,gql]
+----
-- Agent verifies its reasoning
INTROSPECT belief_fusions
WHERE agent = 'agent_alpha'
@@ -949,17 +1008,18 @@ RETURN (reasoning, proof)
-- }
-- }
-- ]
-```
+----
-**Agent Beta** can now **verify Agent Alpha's proofs** before trusting them!
+*Agent Beta* can now *verify Agent Alpha’s proofs* before trusting them!
-### 6.4 Byzantine Fault Tolerance with Proofs
+==== 6.4 Byzantine Fault Tolerance with Proofs
-**Current**: 33% malicious agents tolerated (voting)
+*Current*: 33% malicious agents tolerated (voting)
-**With Dependent Types**: Agents provide **proofs** of their reasoning
+*With Dependent Types*: Agents provide *proofs* of their reasoning
-```idris
+[source,idris]
+----
-- Agent claim with proof
data VerifiedClaim : Type where
MkVerifiedClaim :
@@ -977,201 +1037,183 @@ verifyAgentClaims claims = do
for claims $ \(agent, claim) -> do
verify claim.prf
pure (map snd claims)
-```
-
-**Benefits**:
-- Malicious agents can't fake proofs (type system enforces)
-- Honest agents' proofs always verify
-- Higher fault tolerance (50%+ malicious if proofs required)
-
-## 7. Research Contributions
-
-### 7.1 Novel Contributions
-
-1. **First dependently-typed database**
- - Databases: None have dependent types (to our knowledge)
- - Programming languages: Many (Idris, Agda, Lean, Coq, F*)
- - **Gap**: Database + dependent types = novel!
-
-2. **Provable epistemology**
- - Traditional: "This claim has confidence 0.9" (no proof)
- - Lithoglyph: "This claim has confidence 0.9 AND here's a proof it's justified"
- - **Impact**: Trust is verifiable, not just asserted
-
-3. **Type-safe multi-agent systems**
- - Traditional: Agents share unverified beliefs
- - Lithoglyph: Agents share beliefs + proofs
- - **Impact**: Byzantine resilience via proof verification
-
-4. **Proof-carrying provenance**
- - Traditional: Provenance is metadata (can be forged)
- - Lithoglyph: Provenance is part of type (can't be forged)
- - **Impact**: Cryptographic-strength audit trails
-
-### 7.2 Publications
-
-#### **Paper 1: POPL 2027 (Programming Languages)**
-**Title**: "Lithoglyph: A Dependently-Typed Database for Verified Epistemology"
-- Core type system
-- Proof-erasure semantics
-- Idris/Lean integration
-- **Venue**: Symposium on Principles of Programming Languages (top-tier PL)
-
-#### **Paper 2: VLDB 2027 (Databases)**
-**Title**: "Dependent Types for Database Constraints: A Case Study in Journalism"
-- BoFIG case study (UK Inflation 2023 dataset)
-- PROMPT score verification
-- Performance evaluation (type-checking overhead)
-- **Venue**: Very Large Data Bases (top-tier DB)
-
-#### **Paper 3: ICFP 2027 (Functional Programming)**
-**Title**: "Proof-Carrying Provenance: Dependent Types for Audit Trails"
-- Reversibility proofs
-- Journal encoding with proof objects
-- Verification strategies
-- **Venue**: International Conference on Functional Programming
-
-#### **Paper 4: AAMAS 2027 (Multi-Agent Systems)**
-**Title**: "Verified Belief Fusion: Dependent Types for Multi-Agent Epistemology"
-- My-Newsroom integration
-- Type-safe Dempster-Shafer fusion
-- Byzantine resilience with proofs
-- **Venue**: Autonomous Agents and Multiagent Systems
-
-### 7.3 Comparison to Related Work
-
-| System | Types | Proofs | Provenance | Domain |
-|--------|-------|--------|------------|--------|
-| Lithoglyph (ours) | ✓ Dependent | ✓ Machine-checkable | ✓ Type-level | Journalism/i-docs |
-| Datomic | Simple | ✗ | ✓ Time-based | General |
-| XTDB | Simple | ✗ | ✓ Bitemporal | General |
-| Prisma | Simple | ✗ | ✗ | General |
-| Liquid Haskell | ✓ Refinement | ✓ SMT-based | ✗ | Programming |
-| F* | ✓ Dependent | ✓ SMT + Tactics | ✗ | Programming |
-| Agda | ✓ Dependent | ✓ Interactive | ✗ | Mathematics |
-
-**Key Insight**: Lithoglyph combines database + dependent types + provenance = **unique position**.
-
-## 8. Evaluation
-
-### 8.1 Type-Checking Performance
-
-**Benchmark**: UK Inflation 2023 dataset (BoFIG)
-- 7 claims
-- 10 evidence items
-- 10 relationships
-- 3 navigation paths
-
-**Metrics**:
-- Type-checking time per operation
-- Proof generation time
-- Memory overhead
-- Journal size increase (with proofs)
-
-**Expected Results**:
-- Type-checking: <100ms per operation (acceptable for development)
-- Proof generation: <500ms (one-time cost)
-- Memory: +10-20% (proof objects)
-- Journal size: +5-10% (serialized proofs)
+----
+
+*Benefits*: - Malicious agents can’t fake proofs (type system enforces)
+- Honest agents’ proofs always verify - Higher fault tolerance (50%+
+malicious if proofs required)
-### 8.2 Error Detection
+=== 7. Research Contributions
-**Compare**:
-- Runtime errors caught with traditional GQL
-- Type errors caught with dependent types
-
-**Hypothesis**: Dependent types catch 80%+ of errors at compile time.
+==== 7.1 Novel Contributions
-**Methodology**:
-- Seed dataset with 100 intentional errors:
- - Invalid PROMPT scores (20)
- - Missing rationale (20)
- - Invalid confidence levels (20)
- - Incorrect computed fields (20)
- - Invalid reversibility claims (20)
-- Measure: How many caught at type-check vs. runtime?
-
-### 8.3 Developer Experience
-
-**User Study**:
-- 20 developers (10 Lithoglyph users, 10 control)
-- Task: Implement evidence import from Zotero
-- Measure:
- - Time to completion
- - Number of bugs
- - User satisfaction (Likert scale)
-
-**Hypothesis**: Dependent types reduce bugs by 50%, with 20% time overhead.
+[arabic]
+. *First dependently-typed database*
+* Databases: None have dependent types (to our knowledge)
+* Programming languages: Many (Idris, Agda, Lean, Coq, F*)
+* *Gap*: Database + dependent types = novel!
+. *Provable epistemology*
+* Traditional: "`This claim has confidence 0.9`" (no proof)
+* Lithoglyph: "`This claim has confidence 0.9 AND here’s a proof it’s
+justified`"
+* *Impact*: Trust is verifiable, not just asserted
+. *Type-safe multi-agent systems*
+* Traditional: Agents share unverified beliefs
+* Lithoglyph: Agents share beliefs + proofs
+* *Impact*: Byzantine resilience via proof verification
+. *Proof-carrying provenance*
+* Traditional: Provenance is metadata (can be forged)
+* Lithoglyph: Provenance is part of type (can’t be forged)
+* *Impact*: Cryptographic-strength audit trails
-### 8.4 Agent Integration
-
-**Experiment**:
-- 10-agent My-Newsroom system
-- Task: Verify 50 claims from UK Inflation investigation
-- Compare:
- - Without proofs: Agents vote (Byzantine voting)
- - With proofs: Agents verify proofs (proof-checking)
-
-**Metrics**:
-- Consensus time
-- Accuracy (vs. ground truth)
-- Byzantine resilience (% malicious agents tolerated)
+==== 7.2 Publications
-**Hypothesis**: Proof-checking enables 50% malicious tolerance (vs. 33% with voting).
+===== *Paper 1: POPL 2027 (Programming Languages)*
-## 9. Challenges and Mitigations
+*Title*: "`Lithoglyph: A Dependently-Typed Database for Verified
+Epistemology`" - Core type system - Proof-erasure semantics - Idris/Lean
+integration - *Venue*: Symposium on Principles of Programming Languages
+(top-tier PL)
-### 9.1 Challenge: Learning Curve
+===== *Paper 2: VLDB 2027 (Databases)*
-**Problem**: Dependent types are hard for most developers.
+*Title*: "`Dependent Types for Database Constraints: A Case Study in
+Journalism`" - BoFIG case study (UK Inflation 2023 dataset) - PROMPT
+score verification - Performance evaluation (type-checking overhead) -
+*Venue*: Very Large Data Bases (top-tier DB)
-**Mitigations**:
-1. **Gradual adoption**: Start with refinement types (easier)
-2. **IDE support**: Lean 4 LSP provides excellent autocomplete
-3. **Proof tactics**: Automate 80% of proofs
-4. **Documentation**: Extensive examples, tutorials
-5. **Opt-in**: Can use simple types if needed
+===== *Paper 3: ICFP 2027 (Functional Programming)*
-### 9.2 Challenge: Compilation Time
+*Title*: "`Proof-Carrying Provenance: Dependent Types for Audit Trails`"
+- Reversibility proofs - Journal encoding with proof objects -
+Verification strategies - *Venue*: International Conference on
+Functional Programming
-**Problem**: Proof checking is slow (can be minutes for complex proofs).
+===== *Paper 4: AAMAS 2027 (Multi-Agent Systems)*
-**Mitigations**:
-1. **Caching**: Store proofs, don't recheck
-2. **Incremental checking**: Only check changed proofs
-3. **Proof parallelization**: Check proofs in parallel
-4. **Development mode**: Skip proofs during dev, check on commit
-5. **Proof complexity budgets**: Warn if proof too complex
+*Title*: "`Verified Belief Fusion: Dependent Types for Multi-Agent
+Epistemology`" - My-Newsroom integration - Type-safe Dempster-Shafer
+fusion - Byzantine resilience with proofs - *Venue*: Autonomous Agents
+and Multiagent Systems
-### 9.3 Challenge: Proof Obligation Failures
+==== 7.3 Comparison to Related Work
-**Problem**: Users write code, type checker demands proof, user stuck.
+[width="100%",cols="21%,16%,18%,27%,18%",options="header",]
+|===
+|System |Types |Proofs |Provenance |Domain
+|Lithoglyph (ours) |✓ Dependent |✓ Machine-checkable |✓ Type-level
+|Journalism/i-docs
-**Mitigations**:
-1. **Proof search**: Auto-generate simple proofs (e.g., `omega` tactic)
-2. **Partial proofs**: Allow `admit` during development
-3. **Proof assistants**: Provide tactics for common patterns
-4. **Error messages**: Suggest fixes (e.g., "Try reducing value from 150 to 100")
-5. **Proof libraries**: Pre-proved theorems for common cases
+|Datomic |Simple |✗ |✓ Time-based |General
-### 9.4 Challenge: Runtime Performance
+|XTDB |Simple |✗ |✓ Bitemporal |General
-**Problem**: Proof objects increase journal size.
+|Prisma |Simple |✗ |✗ |General
-**Mitigations**:
-1. **Proof erasure**: Erase proofs at runtime (Idris/Lean support this)
-2. **Optional proofs**: Only store proofs for critical operations
-3. **Proof compression**: Serialize proofs efficiently
-4. **Proof summaries**: Store hash instead of full proof
-5. **Proof generation on demand**: Regenerate proofs from code if needed
+|Liquid Haskell |✓ Refinement |✓ SMT-based |✗ |Programming
-## 10. Future Work
+|F* |✓ Dependent |✓ SMT + Tactics |✗ |Programming
-### 10.1 Full Verification Stack
+|Agda |✓ Dependent |✓ Interactive |✗ |Mathematics
+|===
-**Goal**: End-to-end verified database.
+*Key Insight*: Lithoglyph combines database + dependent types +
+provenance = *unique position*.
-```
+=== 8. Evaluation
+
+==== 8.1 Type-Checking Performance
+
+*Benchmark*: UK Inflation 2023 dataset (BoFIG) - 7 claims - 10 evidence
+items - 10 relationships - 3 navigation paths
+
+*Metrics*: - Type-checking time per operation - Proof generation time -
+Memory overhead - Journal size increase (with proofs)
+
+*Expected Results*: - Type-checking: <100ms per operation (acceptable
+for development) - Proof generation: <500ms (one-time cost) - Memory:
++10-20% (proof objects) - Journal size: +5-10% (serialized proofs)
+
+==== 8.2 Error Detection
+
+*Compare*: - Runtime errors caught with traditional GQL - Type errors
+caught with dependent types
+
+*Hypothesis*: Dependent types catch 80%+ of errors at compile time.
+
+*Methodology*: - Seed dataset with 100 intentional errors: - Invalid
+PROMPT scores (20) - Missing rationale (20) - Invalid confidence levels
+(20) - Incorrect computed fields (20) - Invalid reversibility claims
+(20) - Measure: How many caught at type-check vs. runtime?
+
+==== 8.3 Developer Experience
+
+*User Study*: - 20 developers (10 Lithoglyph users, 10 control) - Task:
+Implement evidence import from Zotero - Measure: - Time to completion -
+Number of bugs - User satisfaction (Likert scale)
+
+*Hypothesis*: Dependent types reduce bugs by 50%, with 20% time
+overhead.
+
+==== 8.4 Agent Integration
+
+*Experiment*: - 10-agent My-Newsroom system - Task: Verify 50 claims
+from UK Inflation investigation - Compare: - Without proofs: Agents vote
+(Byzantine voting) - With proofs: Agents verify proofs (proof-checking)
+
+*Metrics*: - Consensus time - Accuracy (vs. ground truth) - Byzantine
+resilience (% malicious agents tolerated)
+
+*Hypothesis*: Proof-checking enables 50% malicious tolerance (vs. 33%
+with voting).
+
+=== 9. Challenges and Mitigations
+
+==== 9.1 Challenge: Learning Curve
+
+*Problem*: Dependent types are hard for most developers.
+
+*Mitigations*: 1. *Gradual adoption*: Start with refinement types
+(easier) 2. *IDE support*: Lean 4 LSP provides excellent autocomplete 3.
+*Proof tactics*: Automate 80% of proofs 4. *Documentation*: Extensive
+examples, tutorials 5. *Opt-in*: Can use simple types if needed
+
+==== 9.2 Challenge: Compilation Time
+
+*Problem*: Proof checking is slow (can be minutes for complex proofs).
+
+*Mitigations*: 1. *Caching*: Store proofs, don’t recheck 2. *Incremental
+checking*: Only check changed proofs 3. *Proof parallelization*: Check
+proofs in parallel 4. *Development mode*: Skip proofs during dev, check
+on commit 5. *Proof complexity budgets*: Warn if proof too complex
+
+==== 9.3 Challenge: Proof Obligation Failures
+
+*Problem*: Users write code, type checker demands proof, user stuck.
+
+*Mitigations*: 1. *Proof search*: Auto-generate simple proofs (e.g.,
+`+omega+` tactic) 2. *Partial proofs*: Allow `+admit+` during
+development 3. *Proof assistants*: Provide tactics for common patterns
+4. *Error messages*: Suggest fixes (e.g., "`Try reducing value from 150
+to 100`") 5. *Proof libraries*: Pre-proved theorems for common cases
+
+==== 9.4 Challenge: Runtime Performance
+
+*Problem*: Proof objects increase journal size.
+
+*Mitigations*: 1. *Proof erasure*: Erase proofs at runtime (Idris/Lean
+support this) 2. *Optional proofs*: Only store proofs for critical
+operations 3. *Proof compression*: Serialize proofs efficiently 4.
+*Proof summaries*: Store hash instead of full proof 5. *Proof generation
+on demand*: Regenerate proofs from code if needed
+
+=== 10. Future Work
+
+==== 10.1 Full Verification Stack
+
+*Goal*: End-to-end verified database.
+
+....
┌──────────────────────────────┐
│ GQL (Lean 4) │ ← Application code (verified)
└──────────────┬───────────────┘
@@ -1191,32 +1233,30 @@ verifyAgentClaims claims = do
┌──────────────────────────────┐
│ Forth Blocks (Coq) │ ← Storage (verified)
└──────────────────────────────┘
-```
+....
-**Impact**: **Fully verified database** from top to bottom!
+*Impact*: *Fully verified database* from top to bottom!
-### 10.2 Proof-Checked Journalism
+==== 10.2 Proof-Checked Journalism
-**Vision**: Journalists publish **proofs** alongside articles.
+*Vision*: Journalists publish *proofs* alongside articles.
-**Example**:
-> **Claim**: "UK rent inflation exceeded overall inflation by 4.7 percentage points in 2023"
->
-> **Evidence**: ONS CPI data (provenance: 100, replicability: 100)
->
-> **Proof**: [Download machine-checkable proof]
->
-> Readers can verify the proof in Lean 4 or Idris 2. The claim is **mathematically guaranteed** to follow from the evidence.
+*Example*: > *Claim*: "`UK rent inflation exceeded overall inflation by
+4.7 percentage points in 2023`" > > *Evidence*: ONS CPI data
+(provenance: 100, replicability: 100) > > *Proof*: [Download
+machine-checkable proof] > > Readers can verify the proof in Lean 4 or
+Idris 2. The claim is *mathematically guaranteed* to follow from the
+evidence.
-**Impact**: **Verifiable journalism** - trust is provable, not asserted!
+*Impact*: *Verifiable journalism* - trust is provable, not asserted!
-### 10.3 LLM Agents with Proof Obligations
+==== 10.3 LLM Agents with Proof Obligations
-**Current**: LLM agents hallucinate, make mistakes.
+*Current*: LLM agents hallucinate, make mistakes.
-**With Dependent Types**: LLM generates code + proofs.
+*With Dependent Types*: LLM generates code + proofs.
-```
+....
User: "Add evidence with PROMPT score 95/100"
LLM generates:
@@ -1231,10 +1271,11 @@ WITH_PROOF {
Type checker: ✓ All proofs valid
Lithoglyph: Execute
-```
+....
-**If LLM hallucinates invalid score**:
-```
+*If LLM hallucinates invalid score*:
+
+....
LLM generates:
INSERT INTO evidence (prompt_scores)
VALUES ({provenance: 150, ...}) -- Invalid!
@@ -1243,14 +1284,16 @@ Type checker: ✗ TYPE ERROR
Cannot prove LTE 150 100
LLM: "Sorry, 150 is out of range. Let me fix that..."
-```
+....
+
+*Impact*: *Hallucination-proof LLMs* via type checking!
-**Impact**: **Hallucination-proof LLMs** via type checking!
+==== 10.4 Proof-Carrying Smart Contracts
-### 10.4 Proof-Carrying Smart Contracts
+*Blockchain + Dependent Types*:
-**Blockchain + Dependent Types**:
-```idris
+[source,idris]
+----
-- Smart contract with proofs
contract TransferFunds : Contract where
transfer : (from : Address) -> (to : Address) -> (amount : Nat) ->
@@ -1259,31 +1302,39 @@ contract TransferFunds : Contract where
Transaction
-- Blockchain verifies proofs before executing
-```
+----
-**Impact**: **Mathematically verified smart contracts** - no exploits!
+*Impact*: *Mathematically verified smart contracts* - no exploits!
-## 11. Conclusion
+=== 11. Conclusion
-Dependent types transform Lithoglyph from a database that **records** epistemology to one that **proves** epistemology. This enables:
+Dependent types transform Lithoglyph from a database that *records*
+epistemology to one that *proves* epistemology. This enables:
-1. **Compile-time correctness**: Invalid data is a type error, caught immediately
-2. **Provable provenance**: Can't forge provenance (it's in the type)
-3. **Verified multi-agent systems**: Agents provide proofs, not just assertions
-4. **Hallucination-proof LLMs**: Type checker catches LLM mistakes
-5. **Verifiable journalism**: Readers can verify claims mathematically
+[arabic]
+. *Compile-time correctness*: Invalid data is a type error, caught
+immediately
+. *Provable provenance*: Can’t forge provenance (it’s in the type)
+. *Verified multi-agent systems*: Agents provide proofs, not just
+assertions
+. *Hallucination-proof LLMs*: Type checker catches LLM mistakes
+. *Verifiable journalism*: Readers can verify claims mathematically
-Our approach is incremental (refinement types → full dependent types → verified stack), making it practical for real-world adoption.
+Our approach is incremental (refinement types → full dependent types →
+verified stack), making it practical for real-world adoption.
-Lithoglyph becomes the **first dependently-typed database**, uniquely positioned for journalism, scientific reproducibility, and AI agent collaboration where **correctness is non-negotiable**.
+Lithoglyph becomes the *first dependently-typed database*, uniquely
+positioned for journalism, scientific reproducibility, and AI agent
+collaboration where *correctness is non-negotiable*.
----
+'''''
-## Appendix A: Idris 2 Primer
+=== Appendix A: Idris 2 Primer
-### A.1 Basic Syntax
+==== A.1 Basic Syntax
-```idris
+[source,idris]
+----
-- Data types
data Nat : Type where
Z : Nat -- Zero
@@ -1303,22 +1354,24 @@ data Vect : Nat -> Type -> Type where
plusZeroRightNeutral : (n : Nat) -> n + 0 = n
plusZeroRightNeutral Z = Refl
plusZeroRightNeutral (S k) = cong S (plusZeroRightNeutral k)
-```
+----
-### A.2 Tactics
+==== A.2 Tactics
-```idris
+[source,idris]
+----
-- Proof with tactics
example : (x : Nat) -> (y : Nat) -> x + y = y + x
example x y = ?proof
-- Fill ?proof with tactics
?proof = rewrite plusCommutative x y in Refl
-```
+----
-### A.3 Auto-Implicit Arguments
+==== A.3 Auto-Implicit Arguments
-```idris
+[source,idris]
+----
-- Auto-solve proofs
data BoundedNat : Nat -> Nat -> Type where
MkBounded : (n : Nat) -> {auto prf : LTE n max} -> BoundedNat min max
@@ -1326,15 +1379,16 @@ data BoundedNat : Nat -> Nat -> Type where
-- Usage: compiler finds proof automatically
x : BoundedNat 0 100
x = MkBounded 50 -- {prf = ...} filled in by compiler
-```
+----
----
+'''''
-## Appendix B: Lean 4 Primer
+=== Appendix B: Lean 4 Primer
-### B.1 Basic Syntax
+==== B.1 Basic Syntax
-```lean
+[source,lean]
+----
-- Inductive types
inductive Nat where
| zero : Nat
@@ -1356,20 +1410,22 @@ theorem plus_zero : ∀ n : Nat, n + 0 = n := by
induction n with
| zero => rfl
| succ k ih => simp [plus]; exact ih
-```
+----
-### B.2 Tactics
+==== B.2 Tactics
-```lean
+[source,lean]
+----
-- Proof by tactics
theorem example : ∀ x y : Nat, x + y = y + x := by
intro x y
rw [Nat.add_comm]
-```
+----
-### B.3 Type Classes
+==== B.3 Type Classes
-```lean
+[source,lean]
+----
-- Type class for bounded values
class Bounded (α : Type u) where
min : α
@@ -1380,29 +1436,32 @@ instance : Bounded Nat where
min := 0
max := 100
inBounds n := n ≤ 100
-```
+----
----
+'''''
-## Appendix C: Comparison Matrix
+=== Appendix C: Comparison Matrix
-| Feature | Idris 2 | Lean 4 | Dafny | Coq |
-|---------|---------|--------|-------|-----|
-| Dependent types | ✓ Full | ✓ Full | ✓ Refinement | ✓ Full |
-| Proof automation | ✓ Good | ✓ Excellent | ✓ SMT | ✓ Tactics |
-| LSP support | ✓ | ✓ Excellent | ✓ | ✓ |
-| Compilation to C | ✓ | ✓ (LLVM) | ✗ | ✓ (via Extraction) |
-| Learning curve | Medium | Medium | Low | High |
-| IDE integration | Good | Excellent | Good | Good |
-| Proof libraries | Medium | Large | Large | Very Large |
+[cols=",,,,",options="header",]
+|===
+|Feature |Idris 2 |Lean 4 |Dafny |Coq
+|Dependent types |✓ Full |✓ Full |✓ Refinement |✓ Full
+|Proof automation |✓ Good |✓ Excellent |✓ SMT |✓ Tactics
+|LSP support |✓ |✓ Excellent |✓ |✓
+|Compilation to C |✓ |✓ (LLVM) |✗ |✓ (via Extraction)
+|Learning curve |Medium |Medium |Low |High
+|IDE integration |Good |Excellent |Good |Good
+|Proof libraries |Medium |Large |Large |Very Large
+|===
-**Recommendation**: **Lean 4** for best IDE support and automation. **Idris 2** for simplicity. **Dafny** for C interop.
+*Recommendation*: *Lean 4* for best IDE support and automation. *Idris
+2* for simplicity. *Dafny* for C interop.
----
+'''''
-**Document Status**: Research proposal. Implementation timeline: 18-24 months.
+*Document Status*: Research proposal. Implementation timeline: 18-24
+months.
-**See Also**:
-- GQL Dependent Types Specification (companion document)
-- Lithoglyph arXiv paper (Section 14: Future Work)
-- My-Newsroom Me dialect specification
+*See Also*: - GQL Dependent Types Specification (companion document) -
+Lithoglyph arXiv paper (Section 14: Future Work) - My-Newsroom Me
+dialect specification
diff --git a/docs/proof-debt.adoc b/docs/proof-debt.adoc
new file mode 100644
index 0000000..0c59eb5
--- /dev/null
+++ b/docs/proof-debt.adoc
@@ -0,0 +1,225 @@
+== Proof debt
+
+Per
+https://github.com/hyperpolymath/standards/blob/main/docs/TRUSTED-BASE-REDUCTION-POLICY.adoc[`+hyperpolymath/standards+`
+— Trusted-Base Reduction Policy].
+
+Enumerated 2026-07-21 by running the estate checker
+(`+standards/scripts/check-trusted-base.sh+`) against this repository:
+*19 soundness-relevant escape hatches detected*, of which *16 are real
+Lean `+axiom+` declarations* and 3 are detector false positives (§(e)).
+
+=== Read this first
+
+`+lake build+` is green and Lean reports *no incomplete proofs* — no
+`+sorry+` is reached in any proof position. That is true, and it is
+*not* the same as "`the proofs are done`".
+
+Lean’s `+sorry+` warning does not fire on `+axiom+`. This repository
+declares 16 axioms, and *none of them is a necessary axiom* in the
+policy’s §(c) sense (function extensionality, classical choice, an
+extraction boundary). Every one is a *stub* — a declaration written to
+make the file compile while the implementation or proof was deferred.
+Two consequences that must not be understated:
+
+[arabic]
+. *Five axioms occupy executable positions.* `+parseToIR+`,
+`+deserializeIR+`, `+many+`, `+many1+` and `+sepBy+` are declared as
+`+axiom+`, so they have _no implementation at all_. Code that calls them
+typechecks and cannot run. "`34/35 targets build`" is therefore a
+statement about typechecking, not about a working parser.
+. *`+executePreservesTypes+` proves nothing.* Its statement reduces to
+`+… → True+`, with the body commented `+-- Placeholder+`. It reads like
+a type-safety soundness theorem and discharges no obligation whatsoever.
+It is the most misleading item in this list.
+
+Similarly, the worked examples in `+TypeSafeQueries.lean+` — the ones
+whose comments claim `+✓ Type-safe INSERT with valid score+` and
+demonstrate that an out-of-range score
+`+-- Type error: failed to prove 150 ≤ 100+` — are themselves axioms.
+They assert the existence of the well-typed value rather than
+constructing it, so they demonstrate the opposite of what the
+surrounding comments claim.
+
+None of this is a regression introduced here; it is the inherited state
+of the imported GQLdt sources, recorded honestly for the first time.
+
+=== (a) Discharged in this repo
+
+* (none yet — entries are removed from §(d) and _not_ listed here once a
+proof lands)
+
+=== (b) Budgeted — tested with refutation budget
+
+* (none yet — but the prerequisite is now met.)
+
+*Updated 2026-07-28.* This section previously read _"`this repo has no
+executable test coverage: `+lake test+` reports
+`+no test driver configured+` … adding a `+@[test_driver]+` is a
+prerequisite for moving any item into this section.`"_ That prerequisite
+has been satisfied: `+lake test+` now runs three suites and *163
+checks*, and the gate is canary-tested in both directions (a seeded
+false check turns it red; removing it returns green).
+
+So items _can_ now be moved here — but none has been yet, and none
+should be moved without a *stated refutation budget*. Coverage existing
+is not the same as a given axiom being covered. The policy’s requirement
+is a citable budget ("`property-tested at N inputs by `++`,
+last green on `++``"), because without one "`covered by tests`" is
+unfalsifiable — which is the whole reason this section exists.
+
+The nearest candidate is *D4* (`+inferredInsertTypesMatch+`); see its
+entry.
+
+=== (c) Necessary axiom
+
+* (none. No axiom in this repository is load-bearing in the §(c) sense.)
+
+=== (d) DEBT — actively to be closed
+
+*Owner:* @hyperpolymath · *Deadline:* INDEFINITE — sequenced behind the
+GNPL narration layer (see `+docs/THEORY.adoc+`), except D1 which is
+called out as urgent below.
+
+==== D1 — Fake soundness theorem (close first)
+
+* `+src/GqlDt/TypeSafe.lean:194+` — `+axiom executePreservesTypes+`
+** *Kind*: asserted soundness theorem whose statement is vacuous
+(`+… → True+`).
+** *Why urgent*: it is the only item here that actively misinforms. A
+reader encountering `+executePreservesTypes+` reasonably concludes
+execution is proved type-preserving. Nothing of the sort has been
+established.
+** *Plan*: either state and prove the real property (execution preserves
+the schema typing of `+stmt.values+`), or *delete the axiom* and record
+the obligation as an open goal. Deleting is strictly better than keeping
+a vacuous placeholder.
+** *Blocked on*: the `+satisfiesConstraints+` signature issue noted in
+the source comment.
+
+==== D2 — Unimplemented parser combinators and entry points
+
+Declared `+axiom+`, therefore *unimplemented*, not merely unproven:
+
+[width="100%",cols="34%,33%,33%",options="header",]
+|===
+|Location |Axiom |Note
+|`+src/GqlDt/Parser.lean:130+` |`+many+` |commented-out `+partial def+`
+below it; `+-- TODO: Fix infinite loop in type checker+`
+
+|`+src/GqlDt/Parser.lean:141+` |`+many1+` |as above
+
+|`+src/GqlDt/Parser.lean:149+` |`+sepBy+` |as above
+
+|`+src/GqlDt/Parser.lean:347+` |`+parseSelectList+` |
+
+|`+src/GqlDt/Parser.lean:417+` |`+parseSelect+` |
+
+|`+src/GqlDt/Parser.lean:504+` |`+parseStatement+` |
+
+|`+src/GqlDt/Parser.lean:549+` |`+parseToIR+` |pipeline entry point;
+DELETE→IR conversion commented out as not implemented
+
+|`+src/GqlDt/IR.lean:348+` |`+deserializeIR+`
+|`+-- TODO: Implement full CBOR deserialization with schema reconstruction+`
+|===
+
+* *Plan*: implement as `+partial def+` (or with an explicit termination
+measure / fuel parameter, which is the standard Lean 4 remedy for the
+combinator non-termination the source comment describes).
+`+many+`/`+many1+`/`+sepBy+` are the root — the four `+parse*+` axioms
+above them exist because these three do.
+* *Consequence while open*: the M6 "`parser substantially complete`"
+status in `+README.md+` overstates what is executable. Corrected in
+`+README.adoc+`.
+
+==== D3 — Example/fixture values asserted rather than constructed
+
+[width="100%",cols="50%,50%",options="header",]
+|===
+|Location |Axiom
+|`+src/GqlDt/Parser.lean:268+` |`+evidenceSchema+` —
+`+/-- Dummy schema for type inference -/+`
+
+|`+src/GqlDt/IR.lean:721+` |`+exampleInsertIR+` — "`Simplified to use
+axioms to avoid complex PromptScores proof obligations`"
+
+|`+src/GqlDt/TypeSafeQueries.lean:44+` |`+insertWithValidScore+`
+
+|`+src/GqlDt/TypeSafeQueries.lean:73+` |`+validPromptScores+`
+
+|`+src/GqlDt/TypeSafeQueries.lean:99+` |`+insertWithProvenance+`
+
+|`+src/GqlDt/TypeSafeQueries.lean:119+` |`+selectHighQuality+`
+|===
+
+* *Plan*: construct each concretely, discharging the
+`+BoundedNat 0 100+` / `+NonEmptyString+` / `+Confidence+` obligations
+with `+by decide+` or `+by norm_num+`. These are the _demonstrations_ of
+the repo’s central claim ("`invalid insert won’t compile`"), so leaving
+them asserted defeats their purpose. Lowest difficulty, highest
+credibility-per-unit-effort of the three groups — *do these first after
+D1*.
+
+==== D4 — Dynamic-to-static reflection gap
+
+* `+src/GqlDt/Pipeline.lean:147+` — `+axiom inferredInsertTypesMatch+`
+** *Kind*: the one item with a _reasoned_ justification in-source — the
+dynamic schema lookup in `+inferInsert+` already performs the check, and
+reconstructing that proof structurally would require reflecting the
+schema into the type system.
+** *Assessment*: plausible, and closest of the 16 to a genuine §(b)/§(c)
+entry. Not §(c), because it _is_ derivable in principle. Not yet §(b)
+either — but the reason has changed as of 2026-07-28: a test suite now
+exists (163 checks), so the blocker is no longer "`no coverage at all`",
+it is that *this specific path is not property-tested* and has no
+citable refutation budget.
+** *Plan*: property-test `+inferInsert+` over generated schema/value
+pairs, then promote to §(b) quoting the command and the input count; or
+discharge via schema reflection (the source’s own "`future work`"). The
+first is now genuinely reachable.
+
+=== (e) Detector false positives — no action
+
+The estate checker matches `+\bsorry\b+` textually in `+.lean+` files.
+Three hits are not escape hatches, and are listed here so the count
+reconciles (19 = 16 + 3):
+
+[width="100%",cols="50%,50%",options="header",]
+|===
+|Location |What it actually is
+|`+src/GqlDt/TypeInference.lean:179+` |`+\| .admit => "sorry"+` — a
+*string literal* returned by a pretty-printer
+
+|`+src/GqlDt/Lexer.lean:230+` |`+("sorry", .kwSorry)+` — a *keyword
+table entry*; GQL-dt has a `+sorry+` token
+
+|`+test/LexerTest.lean:147+`
+|`+runTest "sorry" (firstType "sorry" == some .kwSorry)+` — a *test
+input*
+|===
+
+A fourth textual hit, `+src/GqlDt/TypeSafeQueries.lean:90+`
+(`+-- overall_correct := by sorry }+`), is inside a comment and is
+already excluded by the checker’s own comment filter.
+
+`+scripts/check-lean-proofs.sh+` in this repo excludes all four by
+design. See its header.
+
+=== Reconciliation with `+scripts/check-lean-proofs.sh+`
+
+The two checks answer different questions and both are needed:
+
+[width="100%",cols="34%,33%,33%",options="header",]
+|===
+|Check |Question |Current answer
+|`+scripts/check-lean-proofs.sh --build-log+` |Does Lean report any
+incomplete proof (`+sorry+`/`+sorryAx+`)? |*No* ✅
+
+|`+standards/scripts/check-trusted-base.sh+` |How large is the unproven
+trusted base (`+axiom+`)? |*16 axioms, all stubs* ❌
+|===
+
+A green proof gate here means "`nothing is admitted mid-proof`". It does
+*not* mean "`nothing is assumed`". This document is the record of what
+is assumed.
diff --git a/docs/proof-debt.md b/docs/proof-debt.md
deleted file mode 100644
index 4f5993f..0000000
--- a/docs/proof-debt.md
+++ /dev/null
@@ -1,166 +0,0 @@
-
-
-# Proof debt
-
-Per [`hyperpolymath/standards` — Trusted-Base Reduction Policy](https://github.com/hyperpolymath/standards/blob/main/docs/TRUSTED-BASE-REDUCTION-POLICY.adoc).
-
-Enumerated 2026-07-21 by running the estate checker (`standards/scripts/check-trusted-base.sh`)
-against this repository: **19 soundness-relevant escape hatches detected**, of which
-**16 are real Lean `axiom` declarations** and 3 are detector false positives (§(e)).
-
-## Read this first
-
-`lake build` is green and Lean reports **no incomplete proofs** — no `sorry` is reached in
-any proof position. That is true, and it is **not** the same as "the proofs are done".
-
-Lean's `sorry` warning does not fire on `axiom`. This repository declares 16 axioms, and
-**none of them is a necessary axiom** in the policy's §(c) sense (function extensionality,
-classical choice, an extraction boundary). Every one is a **stub** — a declaration written
-to make the file compile while the implementation or proof was deferred. Two consequences
-that must not be understated:
-
-1. **Five axioms occupy executable positions.** `parseToIR`, `deserializeIR`, `many`,
- `many1` and `sepBy` are declared as `axiom`, so they have *no implementation at all*.
- Code that calls them typechecks and cannot run. "34/35 targets build" is therefore a
- statement about typechecking, not about a working parser.
-2. **`executePreservesTypes` proves nothing.** Its statement reduces to `… → True`, with
- the body commented `-- Placeholder`. It reads like a type-safety soundness theorem and
- discharges no obligation whatsoever. It is the most misleading item in this list.
-
-Similarly, the worked examples in `TypeSafeQueries.lean` — the ones whose comments claim
-`✓ Type-safe INSERT with valid score` and demonstrate that an out-of-range score
-`-- Type error: failed to prove 150 ≤ 100` — are themselves axioms. They assert the
-existence of the well-typed value rather than constructing it, so they demonstrate the
-opposite of what the surrounding comments claim.
-
-None of this is a regression introduced here; it is the inherited state of the imported
-GQLdt sources, recorded honestly for the first time.
-
-## (a) Discharged in this repo
-
-- (none yet — entries are removed from §(d) and *not* listed here once a proof lands)
-
-## (b) Budgeted — tested with refutation budget
-
-- (none yet — but the prerequisite is now met.)
-
-**Updated 2026-07-28.** This section previously read *"this repo has no executable test
-coverage: `lake test` reports `no test driver configured` … adding a `@[test_driver]` is a
-prerequisite for moving any item into this section."* That prerequisite has been satisfied:
-`lake test` now runs three suites and **163 checks**, and the gate is canary-tested in both
-directions (a seeded false check turns it red; removing it returns green).
-
-So items *can* now be moved here — but none has been yet, and none should be moved without
-a **stated refutation budget**. Coverage existing is not the same as a given axiom being
-covered. The policy's requirement is a citable budget ("property-tested at N inputs by
-``, last green on ``"), because without one "covered by tests" is
-unfalsifiable — which is the whole reason this section exists.
-
-The nearest candidate is **D4** (`inferredInsertTypesMatch`); see its entry.
-
-## (c) Necessary axiom
-
-- (none. No axiom in this repository is load-bearing in the §(c) sense.)
-
-## (d) DEBT — actively to be closed
-
-**Owner:** @hyperpolymath · **Deadline:** INDEFINITE — sequenced behind the GNPL narration
-layer (see `docs/THEORY.adoc`), except D1 which is called out as urgent below.
-
-### D1 — Fake soundness theorem (close first)
-
-- `src/GqlDt/TypeSafe.lean:194` — `axiom executePreservesTypes`
- - **Kind**: asserted soundness theorem whose statement is vacuous (`… → True`).
- - **Why urgent**: it is the only item here that actively misinforms. A reader
- encountering `executePreservesTypes` reasonably concludes execution is proved
- type-preserving. Nothing of the sort has been established.
- - **Plan**: either state and prove the real property (execution preserves the schema
- typing of `stmt.values`), or **delete the axiom** and record the obligation as an
- open goal. Deleting is strictly better than keeping a vacuous placeholder.
- - **Blocked on**: the `satisfiesConstraints` signature issue noted in the source comment.
-
-### D2 — Unimplemented parser combinators and entry points
-
-Declared `axiom`, therefore **unimplemented**, not merely unproven:
-
-| Location | Axiom | Note |
-|---|---|---|
-| `src/GqlDt/Parser.lean:130` | `many` | commented-out `partial def` below it; `-- TODO: Fix infinite loop in type checker` |
-| `src/GqlDt/Parser.lean:141` | `many1` | as above |
-| `src/GqlDt/Parser.lean:149` | `sepBy` | as above |
-| `src/GqlDt/Parser.lean:347` | `parseSelectList` | |
-| `src/GqlDt/Parser.lean:417` | `parseSelect` | |
-| `src/GqlDt/Parser.lean:504` | `parseStatement` | |
-| `src/GqlDt/Parser.lean:549` | `parseToIR` | pipeline entry point; DELETE→IR conversion commented out as not implemented |
-| `src/GqlDt/IR.lean:348` | `deserializeIR` | `-- TODO: Implement full CBOR deserialization with schema reconstruction` |
-
-- **Plan**: implement as `partial def` (or with an explicit termination measure /
- fuel parameter, which is the standard Lean 4 remedy for the combinator
- non-termination the source comment describes). `many`/`many1`/`sepBy` are the
- root — the four `parse*` axioms above them exist because these three do.
-- **Consequence while open**: the M6 "parser substantially complete" status in
- `README.md` overstates what is executable. Corrected in `README.adoc`.
-
-### D3 — Example/fixture values asserted rather than constructed
-
-| Location | Axiom |
-|---|---|
-| `src/GqlDt/Parser.lean:268` | `evidenceSchema` — `/-- Dummy schema for type inference -/` |
-| `src/GqlDt/IR.lean:721` | `exampleInsertIR` — "Simplified to use axioms to avoid complex PromptScores proof obligations" |
-| `src/GqlDt/TypeSafeQueries.lean:44` | `insertWithValidScore` |
-| `src/GqlDt/TypeSafeQueries.lean:73` | `validPromptScores` |
-| `src/GqlDt/TypeSafeQueries.lean:99` | `insertWithProvenance` |
-| `src/GqlDt/TypeSafeQueries.lean:119` | `selectHighQuality` |
-
-- **Plan**: construct each concretely, discharging the `BoundedNat 0 100` /
- `NonEmptyString` / `Confidence` obligations with `by decide` or `by norm_num`. These
- are the *demonstrations* of the repo's central claim ("invalid insert won't compile"),
- so leaving them asserted defeats their purpose. Lowest difficulty, highest
- credibility-per-unit-effort of the three groups — **do these first after D1**.
-
-### D4 — Dynamic-to-static reflection gap
-
-- `src/GqlDt/Pipeline.lean:147` — `axiom inferredInsertTypesMatch`
- - **Kind**: the one item with a *reasoned* justification in-source — the dynamic schema
- lookup in `inferInsert` already performs the check, and reconstructing that proof
- structurally would require reflecting the schema into the type system.
- - **Assessment**: plausible, and closest of the 16 to a genuine §(b)/§(c) entry. Not
- §(c), because it *is* derivable in principle. Not yet §(b) either — but the reason has
- changed as of 2026-07-28: a test suite now exists (163 checks), so the blocker is no
- longer "no coverage at all", it is that **this specific path is not property-tested**
- and has no citable refutation budget.
- - **Plan**: property-test `inferInsert` over generated schema/value pairs, then promote
- to §(b) quoting the command and the input count; or discharge via schema reflection
- (the source's own "future work"). The first is now genuinely reachable.
-
-## (e) Detector false positives — no action
-
-The estate checker matches `\bsorry\b` textually in `.lean` files. Three hits are not
-escape hatches, and are listed here so the count reconciles (19 = 16 + 3):
-
-| Location | What it actually is |
-|---|---|
-| `src/GqlDt/TypeInference.lean:179` | `\| .admit => "sorry"` — a **string literal** returned by a pretty-printer |
-| `src/GqlDt/Lexer.lean:230` | `("sorry", .kwSorry)` — a **keyword table entry**; GQL-dt has a `sorry` token |
-| `test/LexerTest.lean:147` | `runTest "sorry" (firstType "sorry" == some .kwSorry)` — a **test input** |
-
-A fourth textual hit, `src/GqlDt/TypeSafeQueries.lean:90`
-(`-- overall_correct := by sorry }`), is inside a comment and is already excluded by
-the checker's own comment filter.
-
-`scripts/check-lean-proofs.sh` in this repo excludes all four by design. See its header.
-
-## Reconciliation with `scripts/check-lean-proofs.sh`
-
-The two checks answer different questions and both are needed:
-
-| Check | Question | Current answer |
-|---|---|---|
-| `scripts/check-lean-proofs.sh --build-log` | Does Lean report any incomplete proof (`sorry`/`sorryAx`)? | **No** ✅ |
-| `standards/scripts/check-trusted-base.sh` | How large is the unproven trusted base (`axiom`)? | **16 axioms, all stubs** ❌ |
-
-A green proof gate here means "nothing is admitted mid-proof". It does **not** mean
-"nothing is assumed". This document is the record of what is assumed.
diff --git a/spec/GQL-DT-Lexical.adoc b/spec/GQL-DT-Lexical.adoc
new file mode 100644
index 0000000..c47096c
--- /dev/null
+++ b/spec/GQL-DT-Lexical.adoc
@@ -0,0 +1,760 @@
+== GQL-DT Lexical Specification
+
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
+
+*Version:* 1.0.0 *Date:* 2026-02-01
+
+=== Table of Contents
+
+[arabic]
+. link:#character-set[Character Set]
+. link:#lexical-elements[Lexical Elements]
+. link:#keywords[Keywords]
+. link:#identifiers[Identifiers]
+. link:#literals[Literals]
+. link:#operators[Operators]
+. link:#punctuation[Punctuation]
+. link:#comments[Comments]
+. link:#whitespace[Whitespace]
+. link:#operator-precedence[Operator Precedence]
+
+'''''
+
+=== 1. Character Set
+
+GQL-DT source files are encoded in *UTF-8*.
+
+*Character Classes:* - *ASCII:* U+0000 to U+007F - *Unicode:* Full
+Unicode 15.0 support (U+0000 to U+10FFFF) - *Line terminators:* LF
+(U+000A), CR (U+000D), CRLF (U+000D U+000A)
+
+'''''
+
+=== 2. Lexical Elements
+
+GQL-DT source text is a sequence of *tokens* separated by *whitespace*
+and *comments*.
+
+*Token Types:* 1. *Keywords* - Reserved words 2. *Identifiers* - Names
+(variables, tables, columns) 3. *Literals* - Constants (numbers,
+strings, booleans) 4. *Operators* - Symbols for operations 5.
+*Punctuation* - Delimiters and separators 6. *Comments* - Ignored by
+lexer
+
+'''''
+
+=== 3. Keywords
+
+==== 3.1 SQL-Style Keywords
+
+Keywords are *case-insensitive* (accepted in any case, but
+conventionally UPPERCASE).
+
+....
+AND, APPLY, AS, ASC, AUDIENCE, BECAUSE, BETWEEN, BY
+CHECK, COLLECTION, CONFIDENCE, CONSTRAINT, CORRECTION_HISTORY, CORRECTION_TYPE
+CREATE, CREATED_BY
+DELETE, DENORMALIZE, DEPENDENCIES, DEPENDENT_TYPES, DESC, DISCOVER, DISCLOSED_AT, DISCLOSED_BY
+EDGE, EDGE_COLLECTION, EXISTS
+FOR, FROM, FULL, FUNCTIONAL_DEPENDENCIES
+GROUP
+IF, IN, INNER, INSERT, INTO, INTROSPECT, INVESTIGATION, IRREVERSIBLE, IS
+JOIN
+LEFT, LIKE, LIMIT
+NAVIGATION_PATH, NORMALIZATION, NOT, NULL
+ON, OR, ORDER, ORDERED_BY
+PROPOSE, PROVENANCE, PROVENANCE_TRACKING
+RATIONALE, REASON, RETURNING, RIGHT, ROLLBACK
+SAMPLE, SELECT, SET, STRATEGY
+TARGET_NORMAL_FORM, TO
+UNIQUE, UPDATE
+VALUES, VERIFY_PROOFS
+WHERE, WITH, WITH_INVERSE, WITH_JUSTIFICATION, WITH_PROOF
+....
+
+==== 3.2 Type Keywords
+
+Type keywords are *case-sensitive* (must match exactly as shown).
+
+*Primitive Types:*
+
+....
+Nat, Int, String, Bool, Float, Char, Unit, UUID, Timestamp
+....
+
+*Refinement Types:*
+
+....
+BoundedNat, BoundedInt, BoundedFloat
+NonEmptyString, Email, ValidUUID
+Confidence, PromptDimension, Percentage, Rationale, ActorId
+....
+
+*Dependent Types:*
+
+....
+Vector, Tracked, PromptScores, NavigationPath, Claim, Belief
+Collection, Edge, ReversibleOp
+....
+
+*Type Constructors:*
+
+....
+Option, Either
+....
+
+==== 3.3 Normal Form Keywords
+
+....
+1NF, 2NF, 3NF, BCNF, 4NF, 5NF
+....
+
+==== 3.4 Strategy Keywords
+
+....
+PreferPreserving, to3NF, toBCNF, toBCNFPreferPreserving
+....
+
+==== 3.5 Proof Tactic Keywords
+
+....
+by, omega, simp, decide, trivial, norm_num, ring, aesop
+lithoglyph_bounds, lithoglyph_prov, lithoglyph_prompt
+fd_tactic, nf_tactic, lossless_tactic
+....
+
+'''''
+
+=== 4. Identifiers
+
+==== 4.1 Syntax
+
+*ASCII Identifiers:*
+
+[source,regex]
+----
+[A-Za-z_][A-Za-z0-9_]*
+----
+
+*Examples:*
+
+....
+user_id, evidence, PromptScore, _internal, table123
+....
+
+==== 4.2 Unicode Identifiers
+
+GQL-DT supports *Unicode identifiers* following Unicode Standard Annex
+#31:
+
+* *First character:* `+XID_Start+` category (letters, ideographs, etc.)
+* *Subsequent characters:* `+XID_Continue+` category (letters, digits,
+underscore, etc.)
+
+*Examples:*
+
+....
+café, 用户, données, Σ, α, λ_expr
+....
+
+==== 4.3 Reserved Identifiers
+
+The following identifiers are *reserved* and cannot be used as user
+identifiers:
+
+* All keywords (see section 3)
+* Built-in function names: `+NOW+`, `+INTERVAL+`
+* Special identifiers: `+$GENERATED_ID+`
+
+==== 4.4 Case Sensitivity
+
+* *SQL keywords:* Case-insensitive (`+SELECT+` = `+select+` =
+`+SeLeCt+`)
+* *Type keywords:* Case-sensitive (`+BoundedNat+` ≠ `+boundednat+`)
+* *User identifiers:* Case-sensitive (`+userId+` ≠ `+UserId+`)
+
+'''''
+
+=== 5. Literals
+
+==== 5.1 Natural Number Literals
+
+*Syntax:*
+
+[source,regex]
+----
+[0-9]+
+----
+
+*Examples:*
+
+....
+0, 42, 100, 9999
+....
+
+*Type:* `+Nat+`
+
+==== 5.2 Integer Literals
+
+*Syntax:*
+
+[source,regex]
+----
+-?[0-9]+
+----
+
+*Examples:*
+
+....
+-42, 0, 42, -9999
+....
+
+*Type:* `+Int+`
+
+==== 5.3 Float Literals
+
+*Syntax:*
+
+[source,regex]
+----
+-?[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?
+----
+
+*Examples:*
+
+....
+0.0, 3.14, -2.718, 1.23e10, 6.022e-23
+....
+
+*Type:* `+Float+`
+
+==== 5.4 String Literals
+
+*Single-quoted:*
+
+....
+'Hello, world!'
+'It''s a beautiful day' -- Escaped quote
+....
+
+*Double-quoted:*
+
+....
+"Hello, world!"
+"She said \"hi\"" -- Escaped quote
+....
+
+*Escape Sequences:* - `+\\+` - Backslash - `+\'+` - Single quote -
+`+\"+` - Double quote - `+\n+` - Newline - `+\r+` - Carriage return -
+`+\t+` - Tab - `+\uXXXX+` - Unicode code point (4 hex digits) -
+`+\UXXXXXXXX+` - Unicode code point (8 hex digits)
+
+*Type:* `+String+`
+
+==== 5.5 Boolean Literals
+
+....
+true, false
+....
+
+*Type:* `+Bool+`
+
+*Note:* Case-insensitive (`+TRUE+` = `+true+`)
+
+==== 5.6 Unit Literal
+
+....
+()
+....
+
+*Type:* `+Unit+`
+
+==== 5.7 Timestamp Literals
+
+*Syntax:* ISO 8601 format as string literal
+
+....
+'2026-02-01T12:34:56Z'
+'2026-02-01T12:34:56.123+00:00'
+....
+
+*Type:* `+Timestamp+`
+
+'''''
+
+=== 6. Operators
+
+==== 6.1 Arithmetic Operators
+
+[cols=",,,",options="header",]
+|===
+|Operator |Name |Precedence |Associativity
+|`+^+` |Exponentiation |9 |Right
+|`+*+` |Multiplication |8 |Left
+|`+/+` |Division |8 |Left
+|`+div+` |Integer division |8 |Left
+|`+mod+` |Modulo |8 |Left
+|`+++` |Addition |7 |Left
+|`+-+` |Subtraction (binary) |7 |Left
+|`+-+` |Negation (unary) |10 |Right
+|===
+
+==== 6.2 Comparison Operators
+
+[cols=",,,",options="header",]
+|===
+|Operator |Name |Precedence |Associativity
+|`+=+` |Equality |5 |Non-assoc
+|`+<>+` |Inequality (SQL) |5 |Non-assoc
+|`+!=+` |Inequality |5 |Non-assoc
+|`+<+` |Less than |5 |Non-assoc
+|`+>+` |Greater than |5 |Non-assoc
+|`+<=+` |Less or equal |5 |Non-assoc
+|`+>=+` |Greater or equal |5 |Non-assoc
+|===
+
+==== 6.3 Set Operators
+
+[cols=",,,",options="header",]
+|===
+|Operator |Name |Precedence |Associativity
+|`+∈+` |Element of |5 |Non-assoc
+|`+∉+` |Not element of |5 |Non-assoc
+|`+⊆+` |Subset |5 |Non-assoc
+|`+⊇+` |Superset |5 |Non-assoc
+|===
+
+==== 6.4 Logical Operators
+
+[cols=",,,,",options="header",]
+|===
+|Operator |ASCII Alt |Name |Precedence |Associativity
+|`+¬+` |`+NOT+` |Negation |4 |Right
+|`+∧+` |`+AND+`, `+&&+` |Conjunction |3 |Left
+|`+∨+` |`+OR+`, `+\|\|+` |Disjunction |2 |Left
+|`+→+` |`+=>+` |Implication |1 |Right
+|`+⇒+` |`+==>+` |Implication |1 |Right
+|`+↔+` |`+<=>+` |Biconditional |1 |Right
+|`+⇔+` |`+<==>+` |Biconditional |1 |Right
+|===
+
+==== 6.5 Type Operators
+
+[cols=",,,",options="header",]
+|===
+|Operator |Name |Precedence |Associativity
+|`+->+` |Function type |1 |Right
+|`+×+` |Product type |6 |Left
+|`+⊕+` |Sum type |6 |Left
+|===
+
+==== 6.6 Special Operators
+
+[cols=",,,",options="header",]
+|===
+|Operator |Name |Precedence |Associativity
+|`+.+` |Field access |11 |Left
+|`+::+` |Cons (list prepend) |6 |Right
+|`+,+` |Comma (tuple/list sep) |0 |Left
+|`+:+` |Type annotation |N/A |N/A
+|`+\|+` |Type refinement |N/A |N/A
+|===
+
+==== 6.7 Lambda Operators
+
+[cols=",,",options="header",]
+|===
+|Operator |ASCII Alt |Name
+|`+λ+` |`+\+` |Lambda abstraction
+|===
+
+'''''
+
+=== 7. Punctuation
+
+==== 7.1 Delimiters
+
+[cols=",",options="header",]
+|===
+|Symbol |Name
+|`+(+` |Left parenthesis
+|`+)+` |Right parenthesis
+|`+[+` |Left bracket
+|`+]+` |Right bracket
+|`+{+` |Left brace
+|`+}+` |Right brace
+|`+⟨+` |Left angle (Lean proof)
+|`+⟩+` |Right angle (Lean proof)
+|===
+
+==== 7.2 Separators
+
+[cols=",",options="header",]
+|===
+|Symbol |Name
+|`+,+` |Comma
+|`+;+` |Semicolon
+|`+.+` |Period/dot
+|`+:+` |Colon
+|`+\|+` |Pipe/bar
+|===
+
+==== 7.3 Special
+
+[cols=",",options="header",]
+|===
+|Symbol |Name
+|`+--+` |Line comment start
+|`+/*+` |Block comment start
+|`+*/+` |Block comment end
+|`+{-+` |Haskell-style comment start
+|`+-}+` |Haskell-style comment end
+|===
+
+'''''
+
+=== 8. Comments
+
+==== 8.1 Line Comments
+
+*Syntax:*
+
+....
+-- This is a line comment
+....
+
+* Start with `+--+`
+* Extend to end of line
+* Can appear anywhere whitespace is allowed
+
+*Example:*
+
+[source,sql]
+----
+SELECT * FROM evidence -- Get all evidence
+WHERE prompt_overall > 90 -- High quality only
+----
+
+==== 8.2 Block Comments
+
+*Syntax (C-style):*
+
+....
+/* This is a block comment
+ spanning multiple lines */
+....
+
+*Syntax (Haskell-style):*
+
+....
+{- This is a block comment
+ spanning multiple lines -}
+....
+
+*Nesting:* Haskell-style comments can nest. C-style cannot.
+
+[source,haskell]
+----
+{- Outer comment
+ {- Inner comment -}
+ Still in outer comment
+-} -- All closed
+----
+
+'''''
+
+=== 9. Whitespace
+
+==== 9.1 Whitespace Characters
+
+GQL-DT treats the following as *whitespace*:
+
+[cols=",,",options="header",]
+|===
+|Character |Unicode |Name
+|Space |U+0020 |SPACE
+|Tab |U+0009 |CHARACTER TABULATION
+|LF |U+000A |LINE FEED
+|CR |U+000D |CARRIAGE RETURN
+|VT |U+000B |LINE TABULATION
+|FF |U+000C |FORM FEED
+|===
+
+==== 9.2 Significance
+
+* *Required:* Between adjacent keywords/identifiers
+* *Optional:* Around operators, punctuation
+* *Ignored:* Multiple consecutive whitespace = single whitespace
+
+*Examples:*
+
+[source,sql]
+----
+-- Valid (whitespace required)
+SELECT * FROM evidence
+
+-- Invalid (no whitespace)
+SELECT*FROMevidence
+
+-- Valid (extra whitespace ignored)
+SELECT * FROM evidence
+----
+
+==== 9.3 Line Terminators
+
+Accepted line terminators: - *LF* (Unix/Linux/macOS): `+\n+` - *CRLF*
+(Windows): `+\r\n+` - *CR* (old Mac): `+\r+`
+
+'''''
+
+=== 10. Operator Precedence
+
+*Complete precedence table (highest to lowest):*
+
+[cols=",,,",options="header",]
+|===
+|Level |Operators |Associativity |Description
+|11 |`+.+` |Left |Field access
+
+|10 |Function application |Left |`+f x+`
+
+|9 |`+^+` |Right |Exponentiation
+
+|8 |`+*+`, `+/+`, `+div+`, `+mod+` |Left |Multiplicative
+
+|7 |`+++`, `+-+` (binary) |Left |Additive
+
+|6 |`+::+`, `+×+`, `+⊕+` |Right/Left |List cons, type product/sum
+
+|5 |`+=+`, `+<>+`, `+!=+`, `+<+`, `+>+`, `+<=+`, `+>=+` |Non-assoc
+|Comparison
+
+|5 |`+∈+`, `+∉+`, `+⊆+`, `+⊇+` |Non-assoc |Set membership
+
+|4 |`+¬+`, `+NOT+` |Right |Logical negation
+
+|3 |`+∧+`, `+AND+`, `+&&+` |Left |Logical conjunction
+
+|2 |`+∨+`, `+OR+`, `+\|\|+` |Left |Logical disjunction
+
+|1 |`+→+`, `+⇒+`, `+↔+`, `+⇔+`, `+->+` |Right |Implication, type arrow
+
+|0 |`+,+` |Left |Comma (separator)
+|===
+
+==== 10.1 Associativity Rules
+
+*Left-associative:*
+
+....
+a + b + c = (a + b) + c
+a * b * c = (a * b) * c
+....
+
+*Right-associative:*
+
+....
+a ^ b ^ c = a ^ (b ^ c)
+a -> b -> c = a -> (b -> c)
+....
+
+*Non-associative:*
+
+....
+a < b < c = (SYNTAX ERROR - use a < b AND b < c)
+....
+
+==== 10.2 Parentheses
+
+Use parentheses to override precedence:
+
+[source,sql]
+----
+(a + b) * c -- Addition first
+a + (b * c) -- Multiplication first (default)
+----
+
+'''''
+
+=== 11. Lexical Analysis Algorithm
+
+==== 11.1 Maximal Munch Rule
+
+The lexer uses *maximal munch* (longest match):
+
+....
+<= → Token: <= (not < followed by =)
+-> → Token: -> (not - followed by >)
+123.45 → Token: 123.45 (float, not 123 . 45)
+....
+
+==== 11.2 Token Recognition Priority
+
+[arabic]
+. *Whitespace and comments* - Skipped
+. *Keywords* - Matched before identifiers
+. *Multi-character operators* - Matched before single-char
+. *Literals* - Numbers, strings, booleans
+. *Identifiers* - Alphanumeric + underscore
+. *Single-character operators/punctuation*
+
+==== 11.3 Ambiguity Resolution
+
+*Example:* `+SELECT*FROM+`
+
+* Greedy matching: `+SELECT+`, `+*+`, `+FROM+` (correct)
+* Not: `+SELECT*F+`, `+ROM+` (incorrect)
+
+*Rule:* Always prefer keyword matches over identifiers.
+
+'''''
+
+=== 12. Lexical Extensions
+
+==== 12.1 Unicode Mathematical Symbols
+
+GQL-DT accepts Unicode mathematical symbols with ASCII alternatives:
+
+[cols=",,",options="header",]
+|===
+|Unicode |ASCII |Meaning
+|`+λ+` |`+\+` |Lambda
+|`+∀+` |`+forall+` |Universal quantifier
+|`+∃+` |`+exists+` |Existential quantifier
+|`+∧+` |`+AND+`, `+&&+` |Logical AND
+|`+∨+` |`+OR+`, `+\|\|+` |Logical OR
+|`+¬+` |`+NOT+` |Logical NOT
+|`+→+` |`+->+`, `+=>+` |Implication, function arrow
+|`+⇒+` |`+==>+` |Double implication
+|`+↔+` |`+<=>+` |Biconditional
+|`+⇔+` |`+<==>+` |Double biconditional
+|`+×+` |`+*+` (in type context) |Product type
+|`+⊕+` |`+++` (in type context) |Sum type
+|`+∈+` |`+IN+` |Set membership
+|`+∉+` |`+NOT IN+` |Not in set
+|`+⊆+` |`+SUBSET+` |Subset
+|`+⊇+` |`+SUPERSET+` |Superset
+|===
+
+==== 12.2 Proof Literals
+
+*Lean 4 proof terms:*
+
+[source,lean]
+----
+⟨95, by omega, by omega⟩
+----
+
+*Idris 2 proof holes:*
+
+[source,idris]
+----
+?proof_name
+----
+
+*Inline tactics:*
+
+[source,lean]
+----
+by omega
+by simp [rule1, rule2]; omega
+----
+
+'''''
+
+=== 13. Compatibility Notes
+
+==== 13.1 Standard GQL Compatibility
+
+GQL-DT is a *superset* of standard Lithoglyph GQL:
+
+* *All standard GQL keywords* are recognized
+* *Type annotations* are optional (inferred if omitted)
+* *Proof clauses* are optional (auto-generated or admitted)
+
+==== 13.2 SQL Compatibility
+
+GQL-DT follows SQL conventions:
+
+* *Keywords are case-insensitive* (SELECT = select)
+* *String literals* use single quotes (standard) or double quotes
+(PostgreSQL-style)
+* *Comments* use `+--+` (SQL standard) or `+/* */+` (C-style)
+
+==== 13.3 Lean 4 / Idris 2 Compatibility
+
+Type expressions and proof terms can embed:
+
+* *Lean 4 syntax* - Full Lean 4 type expressions in type annotations
+* *Idris 2 syntax* - Full Idris 2 proof terms in WITH_PROOF clauses
+
+'''''
+
+=== 14. Error Recovery
+
+==== 14.1 Lexical Errors
+
+*Unterminated string:*
+
+[source,sql]
+----
+INSERT INTO t VALUES ('unterminated
+-- ERROR: Unterminated string literal at line 1
+----
+
+*Invalid character:*
+
+[source,sql]
+----
+SELECT @ FROM t
+-- ERROR: Unexpected character '@' at line 1, column 8
+----
+
+*Invalid number:*
+
+[source,sql]
+----
+SELECT 1.2.3 FROM t
+-- ERROR: Invalid float literal '1.2.3' at line 1, column 8
+----
+
+==== 14.2 Recovery Strategy
+
+On lexical error: 1. *Report error* with line and column number 2. *Skip
+to next whitespace* or punctuation 3. *Continue tokenization* (collect
+all errors)
+
+'''''
+
+=== 15. Implementation Notes
+
+==== 15.1 Recommended Tools
+
+* *Lexer generator:* Alex (Haskell), ocamllex (OCaml), Flex (C/C++)
+* *Hand-rolled:* Lean 4 Parsec, Rust nom, ReScript combinators
+
+==== 15.2 Performance Considerations
+
+* *Unicode normalization:* Normalize identifiers to NFC form
+* *Keyword lookup:* Use hash table for O(1) keyword recognition
+* *Number parsing:* Use fast float parsing (e.g., `+from_str_radix+`)
+
+'''''
+
+=== References
+
+[arabic]
+. *ISO/IEC 14977* - EBNF Syntax Notation
+. *Unicode Standard Annex #31* - Unicode Identifier and Pattern Syntax
+. *SQL:2023 Standard* - ISO/IEC 9075
+. *Lean 4 Reference* - https://lean-lang.org/
+. *Idris 2 Tutorial* - https://idris2.readthedocs.io/
+
+'''''
+
+*Document Status:* Complete lexical specification for GQL-DT v1.0
+
+*See Also:* - `+GQL-DT-Grammar.ebnf+` - Formal EBNF grammar -
+`+GQL_Dependent_Types_Complete_Specification.md+` - Type system
+specification
diff --git a/spec/GQL-DT-Lexical.md b/spec/GQL-DT-Lexical.md
deleted file mode 100644
index c2b264a..0000000
--- a/spec/GQL-DT-Lexical.md
+++ /dev/null
@@ -1,680 +0,0 @@
-# GQL-DT Lexical Specification
-
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
-
-**Version:** 1.0.0
-**Date:** 2026-02-01
-
-## Table of Contents
-
-1. [Character Set](#character-set)
-2. [Lexical Elements](#lexical-elements)
-3. [Keywords](#keywords)
-4. [Identifiers](#identifiers)
-5. [Literals](#literals)
-6. [Operators](#operators)
-7. [Punctuation](#punctuation)
-8. [Comments](#comments)
-9. [Whitespace](#whitespace)
-10. [Operator Precedence](#operator-precedence)
-
----
-
-## 1. Character Set
-
-GQL-DT source files are encoded in **UTF-8**.
-
-**Character Classes:**
-- **ASCII:** U+0000 to U+007F
-- **Unicode:** Full Unicode 15.0 support (U+0000 to U+10FFFF)
-- **Line terminators:** LF (U+000A), CR (U+000D), CRLF (U+000D U+000A)
-
----
-
-## 2. Lexical Elements
-
-GQL-DT source text is a sequence of **tokens** separated by **whitespace** and **comments**.
-
-**Token Types:**
-1. **Keywords** - Reserved words
-2. **Identifiers** - Names (variables, tables, columns)
-3. **Literals** - Constants (numbers, strings, booleans)
-4. **Operators** - Symbols for operations
-5. **Punctuation** - Delimiters and separators
-6. **Comments** - Ignored by lexer
-
----
-
-## 3. Keywords
-
-### 3.1 SQL-Style Keywords
-
-Keywords are **case-insensitive** (accepted in any case, but conventionally UPPERCASE).
-
-```
-AND, APPLY, AS, ASC, AUDIENCE, BECAUSE, BETWEEN, BY
-CHECK, COLLECTION, CONFIDENCE, CONSTRAINT, CORRECTION_HISTORY, CORRECTION_TYPE
-CREATE, CREATED_BY
-DELETE, DENORMALIZE, DEPENDENCIES, DEPENDENT_TYPES, DESC, DISCOVER, DISCLOSED_AT, DISCLOSED_BY
-EDGE, EDGE_COLLECTION, EXISTS
-FOR, FROM, FULL, FUNCTIONAL_DEPENDENCIES
-GROUP
-IF, IN, INNER, INSERT, INTO, INTROSPECT, INVESTIGATION, IRREVERSIBLE, IS
-JOIN
-LEFT, LIKE, LIMIT
-NAVIGATION_PATH, NORMALIZATION, NOT, NULL
-ON, OR, ORDER, ORDERED_BY
-PROPOSE, PROVENANCE, PROVENANCE_TRACKING
-RATIONALE, REASON, RETURNING, RIGHT, ROLLBACK
-SAMPLE, SELECT, SET, STRATEGY
-TARGET_NORMAL_FORM, TO
-UNIQUE, UPDATE
-VALUES, VERIFY_PROOFS
-WHERE, WITH, WITH_INVERSE, WITH_JUSTIFICATION, WITH_PROOF
-```
-
-### 3.2 Type Keywords
-
-Type keywords are **case-sensitive** (must match exactly as shown).
-
-**Primitive Types:**
-```
-Nat, Int, String, Bool, Float, Char, Unit, UUID, Timestamp
-```
-
-**Refinement Types:**
-```
-BoundedNat, BoundedInt, BoundedFloat
-NonEmptyString, Email, ValidUUID
-Confidence, PromptDimension, Percentage, Rationale, ActorId
-```
-
-**Dependent Types:**
-```
-Vector, Tracked, PromptScores, NavigationPath, Claim, Belief
-Collection, Edge, ReversibleOp
-```
-
-**Type Constructors:**
-```
-Option, Either
-```
-
-### 3.3 Normal Form Keywords
-
-```
-1NF, 2NF, 3NF, BCNF, 4NF, 5NF
-```
-
-### 3.4 Strategy Keywords
-
-```
-PreferPreserving, to3NF, toBCNF, toBCNFPreferPreserving
-```
-
-### 3.5 Proof Tactic Keywords
-
-```
-by, omega, simp, decide, trivial, norm_num, ring, aesop
-lithoglyph_bounds, lithoglyph_prov, lithoglyph_prompt
-fd_tactic, nf_tactic, lossless_tactic
-```
-
----
-
-## 4. Identifiers
-
-### 4.1 Syntax
-
-**ASCII Identifiers:**
-```regex
-[A-Za-z_][A-Za-z0-9_]*
-```
-
-**Examples:**
-```
-user_id, evidence, PromptScore, _internal, table123
-```
-
-### 4.2 Unicode Identifiers
-
-GQL-DT supports **Unicode identifiers** following Unicode Standard Annex #31:
-
-- **First character:** `XID_Start` category (letters, ideographs, etc.)
-- **Subsequent characters:** `XID_Continue` category (letters, digits, underscore, etc.)
-
-**Examples:**
-```
-café, 用户, données, Σ, α, λ_expr
-```
-
-### 4.3 Reserved Identifiers
-
-The following identifiers are **reserved** and cannot be used as user identifiers:
-
-- All keywords (see section 3)
-- Built-in function names: `NOW`, `INTERVAL`
-- Special identifiers: `$GENERATED_ID`
-
-### 4.4 Case Sensitivity
-
-- **SQL keywords:** Case-insensitive (`SELECT` = `select` = `SeLeCt`)
-- **Type keywords:** Case-sensitive (`BoundedNat` ≠ `boundednat`)
-- **User identifiers:** Case-sensitive (`userId` ≠ `UserId`)
-
----
-
-## 5. Literals
-
-### 5.1 Natural Number Literals
-
-**Syntax:**
-```regex
-[0-9]+
-```
-
-**Examples:**
-```
-0, 42, 100, 9999
-```
-
-**Type:** `Nat`
-
-### 5.2 Integer Literals
-
-**Syntax:**
-```regex
--?[0-9]+
-```
-
-**Examples:**
-```
--42, 0, 42, -9999
-```
-
-**Type:** `Int`
-
-### 5.3 Float Literals
-
-**Syntax:**
-```regex
--?[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?
-```
-
-**Examples:**
-```
-0.0, 3.14, -2.718, 1.23e10, 6.022e-23
-```
-
-**Type:** `Float`
-
-### 5.4 String Literals
-
-**Single-quoted:**
-```
-'Hello, world!'
-'It''s a beautiful day' -- Escaped quote
-```
-
-**Double-quoted:**
-```
-"Hello, world!"
-"She said \"hi\"" -- Escaped quote
-```
-
-**Escape Sequences:**
-- `\\` - Backslash
-- `\'` - Single quote
-- `\"` - Double quote
-- `\n` - Newline
-- `\r` - Carriage return
-- `\t` - Tab
-- `\uXXXX` - Unicode code point (4 hex digits)
-- `\UXXXXXXXX` - Unicode code point (8 hex digits)
-
-**Type:** `String`
-
-### 5.5 Boolean Literals
-
-```
-true, false
-```
-
-**Type:** `Bool`
-
-**Note:** Case-insensitive (`TRUE` = `true`)
-
-### 5.6 Unit Literal
-
-```
-()
-```
-
-**Type:** `Unit`
-
-### 5.7 Timestamp Literals
-
-**Syntax:** ISO 8601 format as string literal
-
-```
-'2026-02-01T12:34:56Z'
-'2026-02-01T12:34:56.123+00:00'
-```
-
-**Type:** `Timestamp`
-
----
-
-## 6. Operators
-
-### 6.1 Arithmetic Operators
-
-| Operator | Name | Precedence | Associativity |
-|----------|------|------------|---------------|
-| `^` | Exponentiation | 9 | Right |
-| `*` | Multiplication | 8 | Left |
-| `/` | Division | 8 | Left |
-| `div` | Integer division | 8 | Left |
-| `mod` | Modulo | 8 | Left |
-| `+` | Addition | 7 | Left |
-| `-` | Subtraction (binary) | 7 | Left |
-| `-` | Negation (unary) | 10 | Right |
-
-### 6.2 Comparison Operators
-
-| Operator | Name | Precedence | Associativity |
-|----------|------|------------|---------------|
-| `=` | Equality | 5 | Non-assoc |
-| `<>` | Inequality (SQL) | 5 | Non-assoc |
-| `!=` | Inequality | 5 | Non-assoc |
-| `<` | Less than | 5 | Non-assoc |
-| `>` | Greater than | 5 | Non-assoc |
-| `<=` | Less or equal | 5 | Non-assoc |
-| `>=` | Greater or equal | 5 | Non-assoc |
-
-### 6.3 Set Operators
-
-| Operator | Name | Precedence | Associativity |
-|----------|------|------------|---------------|
-| `∈` | Element of | 5 | Non-assoc |
-| `∉` | Not element of | 5 | Non-assoc |
-| `⊆` | Subset | 5 | Non-assoc |
-| `⊇` | Superset | 5 | Non-assoc |
-
-### 6.4 Logical Operators
-
-| Operator | ASCII Alt | Name | Precedence | Associativity |
-|----------|-----------|------|------------|---------------|
-| `¬` | `NOT` | Negation | 4 | Right |
-| `∧` | `AND`, `&&` | Conjunction | 3 | Left |
-| `∨` | `OR`, `\|\|` | Disjunction | 2 | Left |
-| `→` | `=>` | Implication | 1 | Right |
-| `⇒` | `==>` | Implication | 1 | Right |
-| `↔` | `<=>` | Biconditional | 1 | Right |
-| `⇔` | `<==>` | Biconditional | 1 | Right |
-
-### 6.5 Type Operators
-
-| Operator | Name | Precedence | Associativity |
-|----------|------|------------|---------------|
-| `->` | Function type | 1 | Right |
-| `×` | Product type | 6 | Left |
-| `⊕` | Sum type | 6 | Left |
-
-### 6.6 Special Operators
-
-| Operator | Name | Precedence | Associativity |
-|----------|------|------------|---------------|
-| `.` | Field access | 11 | Left |
-| `::` | Cons (list prepend) | 6 | Right |
-| `,` | Comma (tuple/list sep) | 0 | Left |
-| `:` | Type annotation | N/A | N/A |
-| `\|` | Type refinement | N/A | N/A |
-
-### 6.7 Lambda Operators
-
-| Operator | ASCII Alt | Name |
-|----------|-----------|------|
-| `λ` | `\` | Lambda abstraction |
-
----
-
-## 7. Punctuation
-
-### 7.1 Delimiters
-
-| Symbol | Name |
-|--------|------|
-| `(` | Left parenthesis |
-| `)` | Right parenthesis |
-| `[` | Left bracket |
-| `]` | Right bracket |
-| `{` | Left brace |
-| `}` | Right brace |
-| `⟨` | Left angle (Lean proof) |
-| `⟩` | Right angle (Lean proof) |
-
-### 7.2 Separators
-
-| Symbol | Name |
-|--------|------|
-| `,` | Comma |
-| `;` | Semicolon |
-| `.` | Period/dot |
-| `:` | Colon |
-| `\|` | Pipe/bar |
-
-### 7.3 Special
-
-| Symbol | Name |
-|--------|------|
-| `--` | Line comment start |
-| `/*` | Block comment start |
-| `*/` | Block comment end |
-| `{-` | Haskell-style comment start |
-| `-}` | Haskell-style comment end |
-
----
-
-## 8. Comments
-
-### 8.1 Line Comments
-
-**Syntax:**
-```
--- This is a line comment
-```
-
-- Start with `--`
-- Extend to end of line
-- Can appear anywhere whitespace is allowed
-
-**Example:**
-```sql
-SELECT * FROM evidence -- Get all evidence
-WHERE prompt_overall > 90 -- High quality only
-```
-
-### 8.2 Block Comments
-
-**Syntax (C-style):**
-```
-/* This is a block comment
- spanning multiple lines */
-```
-
-**Syntax (Haskell-style):**
-```
-{- This is a block comment
- spanning multiple lines -}
-```
-
-**Nesting:** Haskell-style comments can nest. C-style cannot.
-
-```haskell
-{- Outer comment
- {- Inner comment -}
- Still in outer comment
--} -- All closed
-```
-
----
-
-## 9. Whitespace
-
-### 9.1 Whitespace Characters
-
-GQL-DT treats the following as **whitespace**:
-
-| Character | Unicode | Name |
-|-----------|---------|------|
-| Space | U+0020 | SPACE |
-| Tab | U+0009 | CHARACTER TABULATION |
-| LF | U+000A | LINE FEED |
-| CR | U+000D | CARRIAGE RETURN |
-| VT | U+000B | LINE TABULATION |
-| FF | U+000C | FORM FEED |
-
-### 9.2 Significance
-
-- **Required:** Between adjacent keywords/identifiers
-- **Optional:** Around operators, punctuation
-- **Ignored:** Multiple consecutive whitespace = single whitespace
-
-**Examples:**
-```sql
--- Valid (whitespace required)
-SELECT * FROM evidence
-
--- Invalid (no whitespace)
-SELECT*FROMevidence
-
--- Valid (extra whitespace ignored)
-SELECT * FROM evidence
-```
-
-### 9.3 Line Terminators
-
-Accepted line terminators:
-- **LF** (Unix/Linux/macOS): `\n`
-- **CRLF** (Windows): `\r\n`
-- **CR** (old Mac): `\r`
-
----
-
-## 10. Operator Precedence
-
-**Complete precedence table (highest to lowest):**
-
-| Level | Operators | Associativity | Description |
-|-------|-----------|---------------|-------------|
-| 11 | `.` | Left | Field access |
-| 10 | Function application | Left | `f x` |
-| 9 | `^` | Right | Exponentiation |
-| 8 | `*`, `/`, `div`, `mod` | Left | Multiplicative |
-| 7 | `+`, `-` (binary) | Left | Additive |
-| 6 | `::`, `×`, `⊕` | Right/Left | List cons, type product/sum |
-| 5 | `=`, `<>`, `!=`, `<`, `>`, `<=`, `>=` | Non-assoc | Comparison |
-| 5 | `∈`, `∉`, `⊆`, `⊇` | Non-assoc | Set membership |
-| 4 | `¬`, `NOT` | Right | Logical negation |
-| 3 | `∧`, `AND`, `&&` | Left | Logical conjunction |
-| 2 | `∨`, `OR`, `\|\|` | Left | Logical disjunction |
-| 1 | `→`, `⇒`, `↔`, `⇔`, `->` | Right | Implication, type arrow |
-| 0 | `,` | Left | Comma (separator) |
-
-### 10.1 Associativity Rules
-
-**Left-associative:**
-```
-a + b + c = (a + b) + c
-a * b * c = (a * b) * c
-```
-
-**Right-associative:**
-```
-a ^ b ^ c = a ^ (b ^ c)
-a -> b -> c = a -> (b -> c)
-```
-
-**Non-associative:**
-```
-a < b < c = (SYNTAX ERROR - use a < b AND b < c)
-```
-
-### 10.2 Parentheses
-
-Use parentheses to override precedence:
-
-```sql
-(a + b) * c -- Addition first
-a + (b * c) -- Multiplication first (default)
-```
-
----
-
-## 11. Lexical Analysis Algorithm
-
-### 11.1 Maximal Munch Rule
-
-The lexer uses **maximal munch** (longest match):
-
-```
-<= → Token: <= (not < followed by =)
--> → Token: -> (not - followed by >)
-123.45 → Token: 123.45 (float, not 123 . 45)
-```
-
-### 11.2 Token Recognition Priority
-
-1. **Whitespace and comments** - Skipped
-2. **Keywords** - Matched before identifiers
-3. **Multi-character operators** - Matched before single-char
-4. **Literals** - Numbers, strings, booleans
-5. **Identifiers** - Alphanumeric + underscore
-6. **Single-character operators/punctuation**
-
-### 11.3 Ambiguity Resolution
-
-**Example:** `SELECT*FROM`
-
-- Greedy matching: `SELECT`, `*`, `FROM` (correct)
-- Not: `SELECT*F`, `ROM` (incorrect)
-
-**Rule:** Always prefer keyword matches over identifiers.
-
----
-
-## 12. Lexical Extensions
-
-### 12.1 Unicode Mathematical Symbols
-
-GQL-DT accepts Unicode mathematical symbols with ASCII alternatives:
-
-| Unicode | ASCII | Meaning |
-|---------|-------|---------|
-| `λ` | `\` | Lambda |
-| `∀` | `forall` | Universal quantifier |
-| `∃` | `exists` | Existential quantifier |
-| `∧` | `AND`, `&&` | Logical AND |
-| `∨` | `OR`, `\|\|` | Logical OR |
-| `¬` | `NOT` | Logical NOT |
-| `→` | `->`, `=>` | Implication, function arrow |
-| `⇒` | `==>` | Double implication |
-| `↔` | `<=>` | Biconditional |
-| `⇔` | `<==>` | Double biconditional |
-| `×` | `*` (in type context) | Product type |
-| `⊕` | `+` (in type context) | Sum type |
-| `∈` | `IN` | Set membership |
-| `∉` | `NOT IN` | Not in set |
-| `⊆` | `SUBSET` | Subset |
-| `⊇` | `SUPERSET` | Superset |
-
-### 12.2 Proof Literals
-
-**Lean 4 proof terms:**
-```lean
-⟨95, by omega, by omega⟩
-```
-
-**Idris 2 proof holes:**
-```idris
-?proof_name
-```
-
-**Inline tactics:**
-```lean
-by omega
-by simp [rule1, rule2]; omega
-```
-
----
-
-## 13. Compatibility Notes
-
-### 13.1 Standard GQL Compatibility
-
-GQL-DT is a **superset** of standard Lithoglyph GQL:
-
-- **All standard GQL keywords** are recognized
-- **Type annotations** are optional (inferred if omitted)
-- **Proof clauses** are optional (auto-generated or admitted)
-
-### 13.2 SQL Compatibility
-
-GQL-DT follows SQL conventions:
-
-- **Keywords are case-insensitive** (SELECT = select)
-- **String literals** use single quotes (standard) or double quotes (PostgreSQL-style)
-- **Comments** use `--` (SQL standard) or `/* */` (C-style)
-
-### 13.3 Lean 4 / Idris 2 Compatibility
-
-Type expressions and proof terms can embed:
-
-- **Lean 4 syntax** - Full Lean 4 type expressions in type annotations
-- **Idris 2 syntax** - Full Idris 2 proof terms in WITH_PROOF clauses
-
----
-
-## 14. Error Recovery
-
-### 14.1 Lexical Errors
-
-**Unterminated string:**
-```sql
-INSERT INTO t VALUES ('unterminated
--- ERROR: Unterminated string literal at line 1
-```
-
-**Invalid character:**
-```sql
-SELECT @ FROM t
--- ERROR: Unexpected character '@' at line 1, column 8
-```
-
-**Invalid number:**
-```sql
-SELECT 1.2.3 FROM t
--- ERROR: Invalid float literal '1.2.3' at line 1, column 8
-```
-
-### 14.2 Recovery Strategy
-
-On lexical error:
-1. **Report error** with line and column number
-2. **Skip to next whitespace** or punctuation
-3. **Continue tokenization** (collect all errors)
-
----
-
-## 15. Implementation Notes
-
-### 15.1 Recommended Tools
-
-- **Lexer generator:** Alex (Haskell), ocamllex (OCaml), Flex (C/C++)
-- **Hand-rolled:** Lean 4 Parsec, Rust nom, ReScript combinators
-
-### 15.2 Performance Considerations
-
-- **Unicode normalization:** Normalize identifiers to NFC form
-- **Keyword lookup:** Use hash table for O(1) keyword recognition
-- **Number parsing:** Use fast float parsing (e.g., `from_str_radix`)
-
----
-
-## References
-
-1. **ISO/IEC 14977** - EBNF Syntax Notation
-2. **Unicode Standard Annex #31** - Unicode Identifier and Pattern Syntax
-3. **SQL:2023 Standard** - ISO/IEC 9075
-4. **Lean 4 Reference** - https://lean-lang.org/
-5. **Idris 2 Tutorial** - https://idris2.readthedocs.io/
-
----
-
-**Document Status:** Complete lexical specification for GQL-DT v1.0
-
-**See Also:**
-- `GQL-DT-Grammar.ebnf` - Formal EBNF grammar
-- `GQL_Dependent_Types_Complete_Specification.md` - Type system specification
diff --git a/spec/GQL-DT-Railroad-Diagrams.md b/spec/GQL-DT-Railroad-Diagrams.adoc
similarity index 81%
rename from spec/GQL-DT-Railroad-Diagrams.md
rename to spec/GQL-DT-Railroad-Diagrams.adoc
index 9e741aa..60407ca 100644
--- a/spec/GQL-DT-Railroad-Diagrams.md
+++ b/spec/GQL-DT-Railroad-Diagrams.adoc
@@ -1,33 +1,34 @@
-# GQL-DT Railroad Diagrams
+== GQL-DT Railroad Diagrams
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
-**Version:** 1.0.0
-**Date:** 2026-02-01
+*Version:* 1.0.0 *Date:* 2026-02-01
-This document provides railroad diagram specifications for GQL-DT syntax. These can be used with:
-- **Online:** https://www.bottlecaps.de/rr/ui
-- **CLI:** `rr` (Railroad Diagram Generator)
-- **Graphviz:** Convert to DOT format
+This document provides railroad diagram specifications for GQL-DT
+syntax. These can be used with: - *Online:*
+https://www.bottlecaps.de/rr/ui - *CLI:* `+rr+` (Railroad Diagram
+Generator) - *Graphviz:* Convert to DOT format
-## Table of Contents
+=== Table of Contents
-1. [CREATE COLLECTION](#create-collection)
-2. [INSERT Statement](#insert-statement)
-3. [SELECT Statement](#select-statement)
-4. [Type Expressions](#type-expressions)
-5. [Proof Clauses](#proof-clauses)
-6. [UPDATE Statement](#update-statement)
-7. [Normalization Commands](#normalization-commands)
+[arabic]
+. link:#create-collection[CREATE COLLECTION]
+. link:#insert-statement[INSERT Statement]
+. link:#select-statement[SELECT Statement]
+. link:#type-expressions[Type Expressions]
+. link:#proof-clauses[Proof Clauses]
+. link:#update-statement[UPDATE Statement]
+. link:#normalization-commands[Normalization Commands]
----
+'''''
-## 1. CREATE COLLECTION
+=== 1. CREATE COLLECTION
-### Railroad Diagram Source (EBNF)
+==== Railroad Diagram Source (EBNF)
-```ebnf
+[source,ebnf]
+----
CreateCollection ::= 'CREATE' 'COLLECTION' ('IF' 'NOT' 'EXISTS')?
Identifier
'(' ColumnList ')'
@@ -45,11 +46,11 @@ Option ::= 'DEPENDENT_TYPES'
| 'PROVENANCE_TRACKING'
| 'TARGET_NORMAL_FORM' NormalForm
| 'FUNCTIONAL_DEPENDENCIES' '(' FDList ')'
-```
+----
-### ASCII Railroad Diagram
+==== ASCII Railroad Diagram
-```
+....
CREATE COLLECTION ─┬─────────────────────┬─ Identifier ─┬─ ( ─ ColumnList ─ ) ─┬────────────────────────┬──
└─ IF NOT EXISTS ─────┘ └─────────────────────────┘ └──┘
└─ WITH ─ OptionList ─┘
@@ -62,15 +63,16 @@ Option:
├─ PROVENANCE_TRACKING ───────────────────────────┤
├─ TARGET_NORMAL_FORM ─ NormalForm ───────────────┤
└─ FUNCTIONAL_DEPENDENCIES ─ ( ─ FDList ─ ) ─────┘
-```
+....
----
+'''''
-## 2. INSERT Statement
+=== 2. INSERT Statement
-### Railroad Diagram Source (EBNF)
+==== Railroad Diagram Source (EBNF)
-```ebnf
+[source,ebnf]
+----
InsertStatement ::= 'INSERT' 'INTO' Identifier
('(' ColumnNames ')')?
'VALUES' '(' ValueList ')'
@@ -94,11 +96,11 @@ ProofTerm ::= 'by' TacticExpr
InverseClause ::= 'WITH_INVERSE' '(' Statement ')'
| 'IRREVERSIBLE' 'BECAUSE' StringLiteral
('WITH_JUSTIFICATION' Justification)?
-```
+----
-### ASCII Railroad Diagram
+==== ASCII Railroad Diagram
-```
+....
INSERT INTO ─ Identifier ─┬──────────────────────────────┬─ VALUES ─ ( ─ ValueList ─ ) ─ RationaleClause ─┬────────────────────────────┬─┬─────────────────────┬─┬──────────────────┬──
└─ ( ─ ColumnNames ─ ) ───────┘ └─ ADDED_BY ─ String ───────┘ └─ WITH_PROOF ─ {...}─┘ └─ InverseClause ─┘
@@ -110,15 +112,16 @@ InverseClause:
┌─ WITH_INVERSE ─ ( ─ Statement ─ ) ───────────────────────────────┐
└─ IRREVERSIBLE ─ BECAUSE ─ String ─┬──────────────────────────────┤
└─ WITH_JUSTIFICATION ─ {...} ─┘
-```
+....
----
+'''''
-## 3. SELECT Statement
+=== 3. SELECT Statement
-### Railroad Diagram Source (EBNF)
+==== Railroad Diagram Source (EBNF)
-```ebnf
+[source,ebnf]
+----
SelectStatement ::= 'SELECT' SelectList
'FROM' FromClause
JoinClause?
@@ -141,11 +144,11 @@ Join ::= ('INNER' | 'LEFT' | 'RIGHT' | 'FULL')?
'JOIN' TableRef 'ON' Condition
TypeRefinement ::= '(' Identifier ':' TypeExpr ('|' Condition)? ')'
-```
+----
-### ASCII Railroad Diagram
+==== ASCII Railroad Diagram
-```
+....
SELECT ─┬─ * ─────────────┬─ FROM ─ FromClause ─┬──────────────┬─┬──────────────────┬─┬─────────────────────┬─┬────────────────────┬─┬────────────────┬─┬────────────────────────┬─┬───────────────────┬──
├─ SelectExpr ... ─┤ └─ JoinClause ─┘ └─ WHERE ─ Cond ──┘ └─ GROUP BY ─ Expr ──┘ └─ ORDER BY ─ Order ─┘ └─ LIMIT ─ Nat ─┘ └─ RETURNING ─ TypeRef ─┘ └─ [VERIFY_PROOFS] ─┘
└─ TypeRefinement ─┘
@@ -160,15 +163,16 @@ Join:
TypeRefinement:
( ─ Identifier ─ : ─ TypeExpr ─┬──────────────┬─ ) ──
└─ | ─ Cond ──┘
-```
+....
----
+'''''
-## 4. Type Expressions
+=== 4. Type Expressions
-### Railroad Diagram Source (EBNF)
+==== Railroad Diagram Source (EBNF)
-```ebnf
+[source,ebnf]
+----
TypeExpr ::= PrimitiveType
| RefinedType
| DependentType
@@ -200,11 +204,11 @@ ProductType ::= TypeExpr '×' TypeExpr
QuantifiedType ::= '∀' '(' ParamDef ')' ',' TypeExpr
| '∃' '(' ParamDef ')' ',' TypeExpr
-```
+----
-### ASCII Railroad Diagram
+==== ASCII Railroad Diagram
-```
+....
TypeExpr:
┌─ PrimitiveType ─────────────────┐
├─ RefinedType ───────────────────┤
@@ -231,15 +235,16 @@ DependentType:
FunctionType:
┌─ TypeExpr ─ -> ─ TypeExpr ────────────────┐
└─ ( ─ ParamList ─ ) ─ -> ─ TypeExpr ───────┘
-```
+....
----
+'''''
-## 5. Proof Clauses
+=== 5. Proof Clauses
-### Railroad Diagram Source (EBNF)
+==== Railroad Diagram Source (EBNF)
-```ebnf
+[source,ebnf]
+----
ProofClause ::= 'WITH_PROOF' ProofBlock
ProofBlock ::= '{' ProofList '}'
@@ -255,11 +260,11 @@ TacticExpr ::= Identifier TacticArgs?
| TacticExpr ';' TacticExpr
| TacticExpr '<|>' TacticExpr
| 'first' '|' TacticExpr ('|' TacticExpr)*
-```
+----
-### ASCII Railroad Diagram
+==== ASCII Railroad Diagram
-```
+....
WITH_PROOF ─ { ─ ProofList ─ } ──
ProofList:
@@ -280,15 +285,16 @@ TacticExpr:
├─ TacticExpr ─ <|> ─ TacticExpr ───────────────────────────────────────┤
└─ first ─ | ─ TacticExpr ─┬───────────────────────┬─────────────────────┘
└─ | ─ TacticExpr ──────┘ (loop)
-```
+....
----
+'''''
-## 6. UPDATE Statement
+=== 6. UPDATE Statement
-### Railroad Diagram Source (EBNF)
+==== Railroad Diagram Source (EBNF)
-```ebnf
+[source,ebnf]
+----
UpdateStatement ::= 'UPDATE' Identifier
'SET' AssignmentList
'WHERE' Condition
@@ -302,11 +308,11 @@ UpdateStatement ::= 'UPDATE' Identifier
AssignmentList ::= Assignment (',' Assignment)*
Assignment ::= Identifier '=' Value
-```
+----
-### ASCII Railroad Diagram
+==== ASCII Railroad Diagram
-```
+....
UPDATE ─ Identifier ─ SET ─ AssignmentList ─ WHERE ─ Condition ─ RationaleClause ─┬────────────────────────────┬─┬──────────────────────┬─┬───────────────────────┬─┬─────────────────────┬─┬──────────────────┬──
└─ CORRECTION_TYPE ─ String ─┘ └─ DISCLOSED_AT ─ ... ─┘ └─ DISCLOSED_BY ─ String ─┘ └─ WITH_PROOF ─ {...}─┘ └─ InverseClause ─┘
@@ -316,15 +322,16 @@ Assignment ─┬───────────────────┬─
Assignment:
Identifier ─ = ─ Value ──
-```
+....
----
+'''''
-## 7. Normalization Commands
+=== 7. Normalization Commands
-### Railroad Diagram Source (EBNF)
+==== Railroad Diagram Source (EBNF)
-```ebnf
+[source,ebnf]
+----
DiscoverDependencies ::= 'DISCOVER' 'DEPENDENCIES'
'FROM' Identifier
('SAMPLE' NatLiteral)?
@@ -343,11 +350,11 @@ ProposeNormalization ::= 'PROPOSE' 'NORMALIZATION' Identifier
ApplyNormalization ::= 'APPLY' 'NORMALIZATION' Identifier
ProofClause
RationaleClause
-```
+----
-### ASCII Railroad Diagram
+==== ASCII Railroad Diagram
-```
+....
DISCOVER DEPENDENCIES ─ FROM ─ Identifier ─┬────────────────┬─┬──────────────────────┬─┬────────────────────────┬──
└─ SAMPLE ─ Nat ─┘ └─ CONFIDENCE ─ Float ─┘ └─ RETURNING ─ TypeRef ─┘
@@ -358,15 +365,16 @@ PROPOSE NORMALIZATION ─ Identifier ─ TO ─ NormalForm ─┬─────
└─ STRATEGY ─ Strat ──┘ └─ RETURNING ─ TypeRef ─┘
APPLY NORMALIZATION ─ Identifier ─ ProofClause ─ RationaleClause ──
-```
+....
----
+'''''
-## 8. Lambda Expressions
+=== 8. Lambda Expressions
-### Railroad Diagram Source (EBNF)
+==== Railroad Diagram Source (EBNF)
-```ebnf
+[source,ebnf]
+----
LambdaExpr ::= ('λ' | '\') ParamList '.' Expr
ParamList ::= Identifier (',' Identifier)*
@@ -381,11 +389,11 @@ Expr ::= Literal
ApplicationExpr ::= Expr Expr
InfixExpr ::= Expr InfixOp Expr
-```
+----
-### ASCII Railroad Diagram
+==== ASCII Railroad Diagram
-```
+....
┌─ λ ─┬─ ParamList ─ . ─ Expr ──
└─ \ ─┘
@@ -403,15 +411,16 @@ Expr:
InfixExpr:
Expr ─ InfixOp ─ Expr ──
-```
+....
----
+'''''
-## 9. Struct and Array Literals
+=== 9. Struct and Array Literals
-### Railroad Diagram Source (EBNF)
+==== Railroad Diagram Source (EBNF)
-```ebnf
+[source,ebnf]
+----
StructLiteral ::= '{' FieldList '}'
FieldList ::= FieldAssignment (',' FieldAssignment)*
@@ -421,11 +430,11 @@ FieldAssignment ::= Identifier ':' Value
ArrayLiteral ::= '[' ValueList ']'
ValueList ::= Value (',' Value)*
-```
+----
-### ASCII Railroad Diagram
+==== ASCII Railroad Diagram
-```
+....
StructLiteral:
{ ─ FieldList ─ } ──
@@ -442,15 +451,15 @@ ArrayLiteral:
ValueList:
Value ─┬──────────────┬──
└─ , ─ Value ──┘ (loop)
-```
+....
----
+'''''
-## 10. Complete Example Diagrams
+=== 10. Complete Example Diagrams
-### Example: INSERT with All Optional Clauses
+==== Example: INSERT with All Optional Clauses
-```
+....
INSERT INTO evidence ─ ( ─ title, prompt_scores ─ ) ─
VALUES ─ ( ─ 'ONS Data', {...} ─ ) ─
RATIONALE ─ "Official statistics" ─
@@ -460,42 +469,45 @@ WITH_PROOF ─ {
overall_correct: by lithoglyph_prompt
} ─
WITH_INVERSE ─ ( ─ DELETE FROM evidence WHERE id = $GENERATED_ID ─ ) ──
-```
+....
-### Example: SELECT with Type Refinement
+==== Example: SELECT with Type Refinement
-```
+....
SELECT ─ ( ─ e : Evidence | e.prompt_overall > 90 ─ ) ─
FROM ─ evidence e ─
WHERE ─ investigation_id = 'uk_inflation_2023' ─
RETURNING ─ ( ─ List ─ ( ─ Evidence | prompt_overall > 90 ─ ) ─ ) ──
-```
+....
----
+'''''
-## 11. Usage Instructions
+=== 11. Usage Instructions
-### Online Railroad Diagram Generator
+==== Online Railroad Diagram Generator
-1. Visit https://www.bottlecaps.de/rr/ui
-2. Paste EBNF from sections above
-3. Click "View Diagram"
-4. Export as SVG or PNG
+[arabic]
+. Visit https://www.bottlecaps.de/rr/ui
+. Paste EBNF from sections above
+. Click "`View Diagram`"
+. Export as SVG or PNG
-### CLI Tool
+==== CLI Tool
-```bash
+[source,bash]
+----
# Install rr (Railroad Diagram Generator)
npm install -g railroad-diagrams
# Generate diagrams
rr < GQL-DT-Grammar.ebnf > diagrams.html
-```
+----
-### Integration with Spec
+==== Integration with Spec
Generated SVG files should be placed in:
-```
+
+....
spec/diagrams/
├── create-collection.svg
├── insert-statement.svg
@@ -504,53 +516,52 @@ spec/diagrams/
├── proof-clauses.svg
├── update-statement.svg
└── normalization-commands.svg
-```
+....
----
+'''''
-## 12. Diagram Conventions
+=== 12. Diagram Conventions
-### Notation
+==== Notation
-- **Railroad tracks** - Syntax flow
-- **Boxes** - Terminals (keywords, operators)
-- **Rounded boxes** - Non-terminals (rules)
-- **Arrows** - Sequence direction
-- **Splits** - Alternatives (OR)
-- **Loops** - Repetition (zero or more, one or more)
+* *Railroad tracks* - Syntax flow
+* *Boxes* - Terminals (keywords, operators)
+* *Rounded boxes* - Non-terminals (rules)
+* *Arrows* - Sequence direction
+* *Splits* - Alternatives (OR)
+* *Loops* - Repetition (zero or more, one or more)
-### Reading Direction
+==== Reading Direction
-- **Left to right** - Primary flow
-- **Top to bottom** - Alternatives
+* *Left to right* - Primary flow
+* *Top to bottom* - Alternatives
-### Colors (if generating colored diagrams)
+==== Colors (if generating colored diagrams)
-- **Blue boxes** - Keywords
-- **Green boxes** - Terminals (literals, operators)
-- **Orange boxes** - Non-terminals (references to other rules)
-- **Gray tracks** - Optional paths
+* *Blue boxes* - Keywords
+* *Green boxes* - Terminals (literals, operators)
+* *Orange boxes* - Non-terminals (references to other rules)
+* *Gray tracks* - Optional paths
----
+'''''
-## References
+=== References
-1. **Railroad Diagram Generator:** https://www.bottlecaps.de/rr/ui
-2. **EBNF Standard:** ISO/IEC 14977
-3. **GQL-DT Grammar:** `GQL-DT-Grammar.ebnf`
-4. **W3C EBNF Notation:** https://www.w3.org/TR/REC-xml/#sec-notation
+[arabic]
+. *Railroad Diagram Generator:* https://www.bottlecaps.de/rr/ui
+. *EBNF Standard:* ISO/IEC 14977
+. *GQL-DT Grammar:* `+GQL-DT-Grammar.ebnf+`
+. *W3C EBNF Notation:* https://www.w3.org/TR/REC-xml/#sec-notation
----
+'''''
-**Document Status:** Complete railroad diagram specifications for GQL-DT v1.0
+*Document Status:* Complete railroad diagram specifications for GQL-DT
+v1.0
-**Next Steps:**
-1. Generate SVG diagrams using online tool
-2. Place in `spec/diagrams/` directory
-3. Reference from main specification document
-4. Update as grammar evolves
+*Next Steps:* 1. Generate SVG diagrams using online tool 2. Place in
+`+spec/diagrams/+` directory 3. Reference from main specification
+document 4. Update as grammar evolves
-**See Also:**
-- `GQL-DT-Grammar.ebnf` - Formal EBNF grammar source
-- `GQL-DT-Lexical.md` - Lexical specification
-- `GQL_Dependent_Types_Complete_Specification.md` - Type system spec
+*See Also:* - `+GQL-DT-Grammar.ebnf+` - Formal EBNF grammar source -
+`+GQL-DT-Lexical.md+` - Lexical specification -
+`+GQL_Dependent_Types_Complete_Specification.md+` - Type system spec
diff --git a/spec/GQL_Dependent_Types_Complete_Specification.md b/spec/GQL_Dependent_Types_Complete_Specification.adoc
similarity index 77%
rename from spec/GQL_Dependent_Types_Complete_Specification.md
rename to spec/GQL_Dependent_Types_Complete_Specification.adoc
index d79c6bb..fffbfaf 100644
--- a/spec/GQL_Dependent_Types_Complete_Specification.md
+++ b/spec/GQL_Dependent_Types_Complete_Specification.adoc
@@ -1,40 +1,43 @@
-# GQL with Dependent Types: Complete Specification
+== GQL with Dependent Types: Complete Specification
-**Version**: 0.2.0 (Dependent Types Extension)
-**Status**: Research Prototype
-**Date**: 2025-01-11
-**Authors**: Jonathan D.A. Jewell, Claude (Anthropic)
-**License**: MPL-2.0
+*Version*: 0.2.0 (Dependent Types Extension) +
+*Status*: Research Prototype +
+*Date*: 2025-01-11 +
+*Authors*: Jonathan D.A. Jewell, Claude (Anthropic) +
+*License*: MPL-2.0
-## Table of Contents
+=== Table of Contents
-1. [Introduction](#1-introduction)
-2. [Type System](#2-type-system)
-3. [Refinement Types](#3-refinement-types)
-4. [Dependent Types](#4-dependent-types)
-5. [DDL with Types](#5-ddl-with-types)
-6. [DML with Proofs](#6-dml-with-proofs)
-7. [Queries with Refinements](#7-queries-with-refinements)
-8. [Proof Obligations](#8-proof-obligations)
-9. [Tactics and Automation](#9-tactics-and-automation)
-10. [Complete Examples](#10-complete-examples)
+[arabic]
+. link:#1-introduction[Introduction]
+. link:#2-type-system[Type System]
+. link:#3-refinement-types[Refinement Types]
+. link:#4-dependent-types[Dependent Types]
+. link:#5-ddl-with-types[DDL with Types]
+. link:#6-dml-with-proofs[DML with Proofs]
+. link:#7-queries-with-refinements[Queries with Refinements]
+. link:#8-proof-obligations[Proof Obligations]
+. link:#9-tactics-and-automation[Tactics and Automation]
+. link:#10-complete-examples[Complete Examples]
----
+'''''
-## 1. Introduction
+=== 1. Introduction
-### 1.1 What This Document Covers
+==== 1.1 What This Document Covers
-This specification extends GQL with **dependent types**—types that can depend on values. This enables:
+This specification extends GQL with *dependent types*—types that can
+depend on values. This enables:
-- **Compile-time verification** of constraints (e.g., PROMPT scores in [0, 100])
-- **Provenance in types** (can't create data without provenance)
-- **Reversibility proofs** (prove operations have inverses)
-- **Machine-checkable correctness** (types ARE proofs)
+* *Compile-time verification* of constraints (e.g., PROMPT scores in [0,
+100])
+* *Provenance in types* (can’t create data without provenance)
+* *Reversibility proofs* (prove operations have inverses)
+* *Machine-checkable correctness* (types ARE proofs)
-### 1.2 Relationship to Standard GQL
+==== 1.2 Relationship to Standard GQL
-```
+....
Standard GQL (runtime checks):
CREATE COLLECTION evidence (
prompt_provenance INT CHECK (prompt_provenance BETWEEN 0 AND 100)
@@ -44,31 +47,34 @@ GQL with Dependent Types (compile-time proofs):
CREATE COLLECTION evidence (
prompt_provenance : BoundedNat 0 100 -- Proof at type level
) WITH DEPENDENT_TYPES;
-```
+....
-**Backward Compatibility**: Standard GQL is valid in dependent-type mode (types are inferred).
+*Backward Compatibility*: Standard GQL is valid in dependent-type mode
+(types are inferred).
-### 1.3 Implementation Languages
+==== 1.3 Implementation Languages
-GQL with dependent types can be implemented in:
-- **Idris 2**: Good balance of practicality and power
-- **Lean 4**: Excellent IDE support, strong automation
-- **Agda**: Most expressive, research-oriented
-- **F*** / Dafny**: Refinement types, SMT-based
+GQL with dependent types can be implemented in: - *Idris 2*: Good
+balance of practicality and power - *Lean 4*: Excellent IDE support,
+strong automation - *Agda*: Most expressive, research-oriented - *F** /
+Dafny**: Refinement types, SMT-based
-**Recommendation**: Lean 4 (best LSP support, large proof library).
+*Recommendation*: Lean 4 (best LSP support, large proof library).
-### 1.4 Related Specifications
+==== 1.4 Related Specifications
-- **[Normalization Types](normalization-types.md)**: Extends this specification with type-encoded functional dependencies, normal form predicates (1NF through BCNF), and proof-carrying schema evolution. Integrates with Lithoglyph's self-normalizing database feature.
+* *link:normalization-types.md[Normalization Types]*: Extends this
+specification with type-encoded functional dependencies, normal form
+predicates (1NF through BCNF), and proof-carrying schema evolution.
+Integrates with Lithoglyph’s self-normalizing database feature.
----
+'''''
-## 2. Type System
+=== 2. Type System
-### 2.1 Type Universe
+==== 2.1 Type Universe
-```
+....
Type Hierarchy (Lean 4 notation):
Type 0 (Sort 0): Prop -- Propositions (proofs)
@@ -76,11 +82,12 @@ Type 1 (Sort 1): Type -- Data types
Type 2 (Sort 2): Type 1 -- Types of types
...
Type ω (Sort ω): Type ω-1 -- Infinite hierarchy
-```
+....
-### 2.2 Primitive Types
+==== 2.2 Primitive Types
-```lean
+[source,lean]
+----
-- Lean 4 primitives (available in GQL-DT)
Nat : Type -- Natural numbers (0, 1, 2, ...)
Int : Type -- Integers (..., -1, 0, 1, ...)
@@ -89,11 +96,12 @@ Bool : Type -- true, false
Float : Type -- IEEE 754 floats
Char : Type -- Unicode characters
Unit : Type -- Single value: ()
-```
+----
-### 2.3 Type Constructors
+==== 2.3 Type Constructors
-```lean
+[source,lean]
+----
-- Product types (tuples, structs)
α × β -- Pair type
(a : α) × (b : β) -- Dependent pair (Sigma type)
@@ -101,11 +109,12 @@ Unit : Type -- Single value: ()
-- Sum types (tagged unions)
α ⊕ β -- Either α or β
Option α -- Some a | None
-```
+----
-### 2.4 Dependent Function Types
+==== 2.4 Dependent Function Types
-```lean
+[source,lean]
+----
-- Simple function (non-dependent)
α → β -- Function from α to β
@@ -114,25 +123,27 @@ Option α -- Some a | None
-- Universal quantification
∀ (x : α), P x -- For all x of type α, P x holds
-```
+----
-### 2.5 Dependent Pair Types
+==== 2.5 Dependent Pair Types
-```lean
+[source,lean]
+----
-- Sigma type (exists with witness)
(x : α) × β x -- Pair where second component depends on first
-- Existential quantification
∃ (x : α), P x -- There exists x of type α such that P x holds
-```
+----
----
+'''''
-## 3. Refinement Types
+=== 3. Refinement Types
-### 3.1 Bounded Natural Numbers
+==== 3.1 Bounded Natural Numbers
-```lean
+[source,lean]
+----
-- Definition
structure BoundedNat (min max : Nat) where
val : Nat
@@ -153,11 +164,12 @@ CREATE COLLECTION evidence (
id : UUID,
prompt_provenance : PromptDimension
);
-```
+----
-### 3.2 Bounded Floats
+==== 3.2 Bounded Floats
-```lean
+[source,lean]
+----
-- Definition
structure BoundedFloat (min max : Float) where
val : Float
@@ -172,11 +184,12 @@ CREATE COLLECTION claims (
id : UUID,
confidence_level : Confidence
);
-```
+----
-### 3.3 Non-Empty Strings
+==== 3.3 Non-Empty Strings
-```lean
+[source,lean]
+----
-- Definition
structure NonEmptyString where
val : String
@@ -190,11 +203,12 @@ abbrev ActorId := NonEmptyString
INSERT INTO claims (text)
VALUES ('Some claim')
RATIONALE (r : Rationale); -- Must be non-empty!
-```
+----
-### 3.4 Email Addresses
+==== 3.4 Email Addresses
-```lean
+[source,lean]
+----
-- Definition
structure Email where
val : String
@@ -204,11 +218,12 @@ structure Email where
CREATE COLLECTION users (
email : Email -- Only valid emails!
);
-```
+----
-### 3.5 Validated UUIDs
+==== 3.5 Validated UUIDs
-```lean
+[source,lean]
+----
-- Definition
structure ValidUUID where
val : String
@@ -219,15 +234,16 @@ structure ValidUUID where
CREATE COLLECTION entities (
id : ValidUUID PRIMARY KEY
);
-```
+----
----
+'''''
-## 4. Dependent Types
+=== 4. Dependent Types
-### 4.1 Length-Indexed Vectors
+==== 4.1 Length-Indexed Vectors
-```lean
+[source,lean]
+----
-- Definition
inductive Vector (α : Type) : Nat → Type where
| nil : Vector α 0
@@ -238,20 +254,23 @@ def head {α : Type} {n : Nat} : Vector α (n + 1) → α
| .cons a _ => a
-- Type guarantees non-empty vector
-```
+----
-**GQL Usage**:
-```gql
+*GQL Usage*:
+
+[source,gql]
+----
-- Fixed-size array (compile-time checked)
CREATE COLLECTION survey_responses (
id : UUID,
ratings : Vector PromptDimension 6 -- Exactly 6 PROMPT dimensions
);
-```
+----
-### 4.2 Provenance-Tracked Values
+==== 4.2 Provenance-Tracked Values
-```lean
+[source,lean]
+----
-- Definition
structure Tracked (α : Type) where
value : α
@@ -265,10 +284,12 @@ def mkTracked (a : α) (actor : ActorId) (ts : Timestamp) (rat : Rationale)
⟨a, actor, ts, rat⟩
-- Can't construct without provenance!
-```
+----
+
+*GQL Usage*:
-**GQL Usage**:
-```gql
+[source,gql]
+----
-- All values automatically tracked
CREATE COLLECTION claims (
id : UUID,
@@ -281,11 +302,12 @@ VALUES ('Inflation claim')
ADDED_BY "alice"
RATIONALE "Based on ONS data";
-- Automatically wrapped in Tracked
-```
+----
-### 4.3 PROMPT Scores with Proof
+==== 4.3 PROMPT Scores with Proof
-```lean
+[source,lean]
+----
-- Definition
structure PromptScores where
provenance : PromptDimension
@@ -303,10 +325,12 @@ structure PromptScores where
def mkPromptScores (p r o m pub t : PromptDimension) : PromptScores :=
let avg := (p.val + r.val + o.val + m.val + pub.val + t.val) / 6
⟨p, r, o, m, pub, t, ⟨avg, by omega, by omega⟩, by simp [avg]⟩
-```
+----
+
+*GQL Usage*:
-**GQL Usage**:
-```gql
+[source,gql]
+----
INSERT INTO evidence (prompt_scores)
VALUES ({
provenance: 100,
@@ -318,11 +342,12 @@ VALUES ({
-- 'overall' computed automatically with proof
})
RATIONALE "Official statistics";
-```
+----
-### 4.4 Reversible Operations
+==== 4.4 Reversible Operations
-```lean
+[source,lean]
+----
-- Definition
inductive ReversibleOp (α : Type) : Type where
| insert : (data : Tracked α) →
@@ -346,10 +371,12 @@ inductive ReversibleOp (α : Type) : Type where
axiom roundTrip {α : Type} : α → (α → α) → α
axiom roundTripPreservesIdentity {α : Type} (x : α) (f : α → α)
: roundTrip x f = x
-```
+----
-**GQL Usage**:
-```gql
+*GQL Usage*:
+
+[source,gql]
+----
-- Reversible insertion
INSERT INTO claims (text)
VALUES ('Some claim')
@@ -368,11 +395,12 @@ JUSTIFICATION {
user_request_id: "REQ-001",
physical_deletion: true
};
-```
+----
-### 4.5 Confidence-Indexed Claims
+==== 4.5 Confidence-Indexed Claims
-```lean
+[source,lean]
+----
-- Definition
structure Claim (c : Confidence) where
id : UUID
@@ -388,10 +416,12 @@ def combineClaims {c1 c2 : Confidence}
(claim1 : Claim c1) (claim2 : Claim c2)
(prf : compatible c1 c2)
: Claim (fuseConfidence c1 c2) := sorry
-```
+----
+
+*GQL Usage*:
-**GQL Usage**:
-```gql
+[source,gql]
+----
-- Claim with confidence in type
CREATE COLLECTION claims (
id : UUID,
@@ -404,11 +434,12 @@ SELECT combineClaims(claim1, claim2)
FROM claims claim1, claims claim2
WHERE compatible(claim1.confidence, claim2.confidence);
-- Type error if not compatible!
-```
+----
-### 4.6 Ordered Navigation Paths
+==== 4.6 Ordered Navigation Paths
-```lean
+[source,lean]
+----
-- Definition
structure NavigationPath (ordering : Evidence → Evidence → Bool) where
nodes : List Evidence
@@ -426,10 +457,12 @@ def createPath {ordering : Evidence → Evidence → Bool}
: NavigationPath ordering :=
let sorted := List.insertionSort ordering evs
⟨sorted, insertionSortIsSorted ordering evs⟩
-```
+----
+
+*GQL Usage*:
-**GQL Usage**:
-```gql
+[source,gql]
+----
-- Path with proven ordering
CREATE NAVIGATION_PATH 'skeptic_path'
FOR INVESTIGATION 'uk_inflation_2023'
@@ -440,26 +473,30 @@ BEGIN
WHERE investigation_id = 'uk_inflation_2023'
END;
-- Type checker proves path is sorted
-```
+----
----
+'''''
-## 5. DDL with Types
+=== 5. DDL with Types
-### 5.1 CREATE COLLECTION (With Dependent Types)
+==== 5.1 CREATE COLLECTION (With Dependent Types)
-**Syntax**:
-```gql
+*Syntax*:
+
+[source,gql]
+----
CREATE COLLECTION [IF NOT EXISTS] collection_name (
column_name : type [constraints],
...
) [WITH options];
-```
+----
+
+*Examples*:
-**Examples**:
+*Simple Refinement Types*:
-**Simple Refinement Types**:
-```gql
+[source,gql]
+----
CREATE COLLECTION evidence (
id : UUID,
title : NonEmptyString,
@@ -470,95 +507,111 @@ CREATE COLLECTION evidence (
prompt_publication : BoundedNat 0 100,
prompt_transparency : BoundedNat 0 100
) WITH DEPENDENT_TYPES;
-```
+----
+
+*Provenance Tracking*:
-**Provenance Tracking**:
-```gql
+[source,gql]
+----
CREATE COLLECTION claims (
id : UUID,
text : NonEmptyString,
confidence : Confidence
) WITH PROVENANCE_TRACKING;
-- All values automatically wrapped in Tracked
-```
+----
-**PROMPT Scores with Proof**:
-```gql
+*PROMPT Scores with Proof*:
+
+[source,gql]
+----
CREATE COLLECTION evidence (
id : UUID,
title : NonEmptyString,
prompt_scores : PromptScores -- Proof of correct computation!
) WITH DEPENDENT_TYPES;
-```
+----
+
+*Length-Indexed Arrays*:
-**Length-Indexed Arrays**:
-```gql
+[source,gql]
+----
CREATE COLLECTION survey (
id : UUID,
responses : Vector (BoundedNat 1 5) 10 -- Exactly 10 ratings (1-5 scale)
) WITH DEPENDENT_TYPES;
-```
+----
-### 5.2 CREATE EDGE_COLLECTION (With Types)
+==== 5.2 CREATE EDGE_COLLECTION (With Types)
-```gql
+[source,gql]
+----
CREATE EDGE_COLLECTION relationships (
from_id : UUID,
to_id : UUID,
weight : BoundedFloat 0.0 1.0,
reasoning : Rationale -- Non-empty!
) WITH DEPENDENT_TYPES;
-```
+----
-### 5.3 CREATE CONSTRAINT (With Proofs)
+==== 5.3 CREATE CONSTRAINT (With Proofs)
-```gql
+[source,gql]
+----
CREATE CONSTRAINT chk_adult_content
ON users (age : BoundedNat 0 150)
CHECK (age.val ≥ 18)
WITH_PROOF (λ u. ageProof u.age)
RATIONALE "COPPA compliance"
APPROVERS "legal_team";
-```
+----
----
+'''''
-## 6. DML with Proofs
+=== 6. DML with Proofs
-### 6.1 INSERT (With Proof Obligations)
+==== 6.1 INSERT (With Proof Obligations)
-**Syntax**:
-```gql
+*Syntax*:
+
+[source,gql]
+----
INSERT INTO collection_name (columns : types)
VALUES (values)
RATIONALE (rationale : Rationale)
[WITH_PROOF proofs];
-```
+----
+
+*Examples*:
-**Examples**:
+*Simple Bounded Values*:
-**Simple Bounded Values**:
-```gql
+[source,gql]
+----
INSERT INTO evidence (title, prompt_provenance)
VALUES (
'ONS CPI Data',
100 -- Type checker proves: 0 ≤ 100 ≤ 100 ✓
)
RATIONALE "Official statistics";
-```
+----
+
+*Invalid Value (Type Error)*:
-**Invalid Value (Type Error)**:
-```gql
+[source,gql]
+----
INSERT INTO evidence (prompt_provenance)
VALUES (150) -- TYPE ERROR!
RATIONALE "Test";
-- Error: Cannot prove 150 ≤ 100
-- Suggestion: Use value between 0 and 100
-```
+----
-**PROMPT Scores (Auto-Computed)**:
-```gql
+*PROMPT Scores (Auto-Computed)*:
+
+[source,gql]
+----
INSERT INTO evidence (prompt_scores)
VALUES ({
provenance: 100,
@@ -570,10 +623,12 @@ VALUES ({
-- 'overall' computed with proof automatically!
})
RATIONALE "Official statistics";
-```
+----
+
+*With Explicit Proof*:
-**With Explicit Proof**:
-```gql
+[source,gql]
+----
INSERT INTO claims (text, confidence, evidence_list)
VALUES (
'Inflation claim',
@@ -585,32 +640,38 @@ WITH_PROOF {
confidence_justified: confidenceProof text evidence_list 0.95
-- Proves confidence matches evidence
};
-```
+----
-### 6.2 UPDATE (With Correction Proof)
+==== 6.2 UPDATE (With Correction Proof)
-**Syntax**:
-```gql
+*Syntax*:
+
+[source,gql]
+----
UPDATE collection_name
SET column = value
WHERE condition
REASON (reason : Rationale)
[WITH_PROOF proofs];
-```
+----
+
+*Examples*:
-**Examples**:
+*Simple Update*:
-**Simple Update**:
-```gql
+[source,gql]
+----
UPDATE evidence
SET prompt_replicability = 30 -- Type checker: 0 ≤ 30 ≤ 100 ✓
WHERE id = 'study_x'
REASON "Study failed to replicate"
DISCLOSED_AT NOW();
-```
+----
+
+*Update with Proof of Validity*:
-**Update with Proof of Validity**:
-```gql
+[source,gql]
+----
UPDATE claims
SET text = 'Corrected text',
confidence = 0.98
@@ -620,10 +681,12 @@ WITH_PROOF {
new_confidence_justified: confidenceProof new_text new_evidence 0.98,
correction_documented: reasonValid "ONS revised figures"
};
-```
+----
-**Reversible Update**:
-```gql
+*Reversible Update*:
+
+[source,gql]
+----
UPDATE claims
SET text = 'New text'
WHERE id = 'claim_123'
@@ -637,12 +700,14 @@ WITH_INVERSE (
WITH_PROOF {
inverse_correct: roundTripProof old_text new_text inverse_op
};
-```
+----
+
+==== 6.3 DELETE (With Justification)
-### 6.3 DELETE (With Justification)
+*Reversible Delete*:
-**Reversible Delete**:
-```gql
+[source,gql]
+----
DELETE FROM temp_data
WHERE created_at < NOW() - INTERVAL '30 days'
REASON "Temporary data expired"
@@ -653,10 +718,12 @@ WITH_INVERSE (
WITH_PROOF {
inverse_restores: deleteInsertRoundTrip data inverse
};
-```
+----
-**Irreversible Delete**:
-```gql
+*Irreversible Delete*:
+
+[source,gql]
+----
DELETE FROM sensitive_data
WHERE user = 'xyz'
REASON "GDPR right to erasure"
@@ -667,36 +734,42 @@ WITH_JUSTIFICATION {
no_backup: true,
crypto_deletion: true
};
-```
+----
+
+'''''
----
+=== 7. Queries with Refinements
-## 7. Queries with Refinements
+==== 7.1 SELECT with Type Refinements
-### 7.1 SELECT with Type Refinements
+*Syntax*:
-**Syntax**:
-```gql
+[source,gql]
+----
SELECT (columns : refined_types)
FROM collection
WHERE (condition : Prop)
RETURNING (result : ResultType);
-```
+----
+
+*Examples*:
-**Examples**:
+*Simple Refinement*:
-**Simple Refinement**:
-```gql
+[source,gql]
+----
-- Return only high-quality evidence
SELECT (e : Evidence | e.prompt_overall > 90)
FROM evidence e
WHERE investigation_id = 'uk_inflation_2023';
-- Return type proves all results satisfy predicate!
-```
+----
-**Multiple Refinements**:
-```gql
+*Multiple Refinements*:
+
+[source,gql]
+----
SELECT (
c : Claim | c.confidence > 0.85,
e : Evidence | e.prompt_overall > 90
@@ -707,10 +780,12 @@ FROM claims c
WHERE r.relationship_type = 'SUPPORTS';
-- Type proves all results satisfy both conditions
-```
+----
+
+*Exists with Witness*:
-**Exists with Witness**:
-```gql
+[source,gql]
+----
-- Find claims with at least one supporting evidence
SELECT (c : Claim, ∃ e : Evidence, supports(c, e))
FROM claims c
@@ -720,11 +795,12 @@ WHERE EXISTS (
);
-- Returns pairs (claim, evidence) with proof that e supports c
-```
+----
-### 7.2 Aggregates with Proofs
+==== 7.2 Aggregates with Proofs
-```gql
+[source,gql]
+----
-- Compute average with proof it's in bounds
SELECT (
investigation_id,
@@ -735,47 +811,54 @@ FROM evidence
GROUP BY investigation_id;
-- Type proves average is in [0, 100]
-```
+----
-### 7.3 JOIN with Type Safety
+==== 7.3 JOIN with Type Safety
-```gql
+[source,gql]
+----
-- Type-safe join
SELECT *
FROM claims c
JOIN (e : Evidence | e.prompt_overall > 85) ON ...
-- Can only join with high-quality evidence
-```
+----
----
+'''''
-## 8. Proof Obligations
+=== 8. Proof Obligations
-### 8.1 Automatic Proof Search
+==== 8.1 Automatic Proof Search
-**Simple Arithmetic**:
-```gql
+*Simple Arithmetic*:
+
+[source,gql]
+----
INSERT INTO evidence (prompt_provenance)
VALUES (95); -- Type checker auto-proves: 0 ≤ 95 ≤ 100
-- Behind the scenes (Lean 4 tactics):
-- by omega -- Linear arithmetic solver
-```
+----
+
+*Computed Fields*:
-**Computed Fields**:
-```gql
+[source,gql]
+----
INSERT INTO evidence (prompt_scores)
VALUES ({provenance: 100, ...});
-- Type checker auto-computes overall and proves correctness
-- Behind the scenes:
-- overall_correct: by simp [computeOverall]; omega
-```
+----
+
+==== 8.2 Manual Proofs
-### 8.2 Manual Proofs
+*When Auto-Proof Fails*:
-**When Auto-Proof Fails**:
-```gql
+[source,gql]
+----
INSERT INTO claims (text, confidence, evidence_list)
VALUES ('Complex claim', 0.92, [e1, e2, e3])
RATIONALE "Multi-source synthesis"
@@ -786,12 +869,14 @@ WITH_PROOF {
intro text evidence conf
sorry -- User must complete
};
-```
+----
-### 8.3 Proof Tactics
+==== 8.3 Proof Tactics
-**Available Tactics**:
-```lean
+*Available Tactics*:
+
+[source,lean]
+----
-- Arithmetic
omega -- Linear arithmetic
norm_num -- Numeric normalization
@@ -811,21 +896,25 @@ constructor -- Construct data/proof
trivial -- Solve trivial goals
decide -- Decision procedures
aesop -- Automated search
-```
+----
+
+*Example Usage*:
-**Example Usage**:
-```gql
+[source,gql]
+----
WITH_PROOF {
score_in_bounds: by omega,
overall_correct: by simp [computeOverall]; norm_num,
rationale_nonempty: by decide
}
-```
+----
-### 8.4 Proof Libraries
+==== 8.4 Proof Libraries
-**Pre-Proved Theorems**:
-```lean
+*Pre-Proved Theorems*:
+
+[source,lean]
+----
-- Lithoglyph standard library
namespace Lithoglyph.Proofs
@@ -847,15 +936,16 @@ theorem insertDeleteRoundTrip {α : Type} (x : Tracked α)
: roundTrip x (delete (insert x)) = x := by ...
end Lithoglyph.Proofs
-```
+----
----
+'''''
-## 9. Tactics and Automation
+=== 9. Tactics and Automation
-### 9.1 Lithoglyph-Specific Tactics
+==== 9.1 Lithoglyph-Specific Tactics
-```lean
+[source,lean]
+----
-- Custom tactics for Lithoglyph
namespace Lithoglyph.Tactics
@@ -879,41 +969,42 @@ macro_rules
lithoglyph_bounds)
end Lithoglyph.Tactics
-```
+----
+
+*Usage in GQL*:
-**Usage in GQL**:
-```gql
+[source,gql]
+----
WITH_PROOF {
score_valid: by lithoglyph_prompt,
provenance_exists: by lithoglyph_prov,
confidence_in_range: by lithoglyph_bounds
}
-```
+----
+
+==== 9.2 IDE Integration
-### 9.2 IDE Integration
+*Lean 4 VSCode Extension*:
-**Lean 4 VSCode Extension**:
-```
+....
Features:
• Type on hover (see inferred types)
• Error highlighting (red underlines for proof failures)
• Proof state view (see current goal)
• Tactic suggestions (auto-complete)
• Proof search (find relevant lemmas)
-```
+....
-**Example IDE Workflow**:
-1. Write GQL with `VALUES (...)`
-2. IDE shows: "Missing proof of X"
-3. User writes `WITH_PROOF { x: by }`
-4. IDE suggests tactics: `omega, simp, decide`
-5. User selects tactic, proof completes
-6. IDE shows: ✓ Type checked successfully
+*Example IDE Workflow*: 1. Write GQL with `+VALUES (...)+` 2. IDE shows:
+"`Missing proof of X`" 3. User writes `+WITH_PROOF { x: by }+` 4. IDE
+suggests tactics: `+omega, simp, decide+` 5. User selects tactic, proof
+completes 6. IDE shows: ✓ Type checked successfully
-### 9.3 Proof Caching
+==== 9.3 Proof Caching
-**Incremental Type Checking**:
-```
+*Incremental Type Checking*:
+
+....
# First type-check (slow)
$ lean4 lithoglyph_queries.lean
Type checking... 25s
@@ -923,21 +1014,24 @@ Type checking... 25s
$ lean4 lithoglyph_queries.lean
Type checking... 0.5s (95% cached)
✓ All proofs valid
-```
+....
+
+*Proof Cache Format*:
-**Proof Cache Format**:
-```lean
+[source,lean]
+----
-- .lithoglyph-cache/proofs.lean
theorem cached_proof_12345 : P := by <...compiled proof...>
-```
+----
----
+'''''
-## 10. Complete Examples
+=== 10. Complete Examples
-### 10.1 BoFIG UK Inflation 2023 (Fully Typed)
+==== 10.1 BoFIG UK Inflation 2023 (Fully Typed)
-```gql
+[source,gql]
+----
-- Step 1: Create evidence collection with dependent types
CREATE COLLECTION bofig_evidence (
id : UUID,
@@ -1035,11 +1129,12 @@ WHERE c.investigation_id = 'uk_inflation_2023'
RETURNING (List (Claim × Evidence × Relationship) |
∀ (c, e, r) ∈ result, c.confidence > 0.85 ∧ e.prompt_overall > 90);
-- Return type PROVES all results satisfy conditions!
-```
+----
-### 10.2 Correction Workflow (With Reversiibility Proof)
+==== 10.2 Correction Workflow (With Reversiibility Proof)
-```gql
+[source,gql]
+----
-- Original insertion
INSERT INTO bofig_claims (text, confidence)
VALUES ('Inflation reached 12% in 2023', 0.90)
@@ -1079,11 +1174,12 @@ INTROSPECT bofig_claims.claim_123 CORRECTION_HISTORY
RETURNING (List CorrectionEntry |
∀ e ∈ result, e.inverse_correct ∧ e.reason.length > 0);
-- Type proves all corrections have valid inverses!
-```
+----
-### 10.3 My-Newsroom Belief Fusion (Type-Safe)
+==== 10.3 My-Newsroom Belief Fusion (Type-Safe)
-```gql
+[source,gql]
+----
-- Define belief type
abbrev AgentBelief := Belief Confidence String
@@ -1137,11 +1233,12 @@ WITH_PROOF {
fusion_correct: fusionMatchesDempster b1 b2
};
-- Type checker proves fusion result is in [0.0, 1.0]!
-```
+----
-### 10.4 Navigation Path (With Ordering Proof)
+==== 10.4 Navigation Path (With Ordering Proof)
-```gql
+[source,gql]
+----
-- Create path with proven ordering
CREATE NAVIGATION_PATH 'skeptic_path_typed'
FOR INVESTIGATION 'uk_inflation_2023'
@@ -1163,15 +1260,16 @@ WITH_PROOF {
SELECT * FROM NAVIGATION_PATH 'skeptic_path_typed'
RETURNING (NavigationPath (λ e₁ e₂. e₁.prompt_objective < e₂.prompt_objective));
-- Return type carries ordering proof!
-```
+----
----
+'''''
-## Appendix A: Type Notation Reference
+=== Appendix A: Type Notation Reference
-### A.1 Lean 4 Notation
+==== A.1 Lean 4 Notation
-```lean
+[source,lean]
+----
-- Types
α : Type -- Type variable
α → β -- Function type
@@ -1192,26 +1290,36 @@ P ↔ Q -- If and only if
a ≤ b -- Less than or equal
a < b -- Less than
a = b -- Equality
-```
+----
+
+==== A.2 GQL Notation Mapping
+
+[width="100%",cols="36%,38%,26%",options="header",]
+|===
+|GQL Syntax |Lean 4 Type |Meaning
+|`+BoundedNat 0 100+` |`+{n : Nat // 0 ≤ n ∧ n ≤ 100}+` |Nat in [0, 100]
+
+|`+NonEmptyString+` |`+{s : String // s.length > 0}+` |Non-empty string
+
+|`+Confidence+` |`+BoundedFloat 0.0 1.0+` |Float in [0.0, 1.0]
+
+|`+Tracked α+` |`+(α × ActorId × Timestamp × Rationale)+`
+|Provenance-tracked value
-### A.2 GQL Notation Mapping
+|`+Vector α n+` |Dependent array of exactly n elements |Fixed-length
+array
-| GQL Syntax | Lean 4 Type | Meaning |
-|------------|-------------|---------|
-| `BoundedNat 0 100` | `{n : Nat // 0 ≤ n ∧ n ≤ 100}` | Nat in [0, 100] |
-| `NonEmptyString` | `{s : String // s.length > 0}` | Non-empty string |
-| `Confidence` | `BoundedFloat 0.0 1.0` | Float in [0.0, 1.0] |
-| `Tracked α` | `(α × ActorId × Timestamp × Rationale)` | Provenance-tracked value |
-| `Vector α n` | Dependent array of exactly n elements | Fixed-length array |
-| `Claim c` | Claim indexed by confidence level c | Confidence-indexed claim |
+|`+Claim c+` |Claim indexed by confidence level c |Confidence-indexed
+claim
+|===
----
+'''''
-## Appendix B: Error Messages
+=== Appendix B: Error Messages
-### B.1 Bound Violation
+==== B.1 Bound Violation
-```
+....
TYPE ERROR at line 5, column 23:
INSERT INTO evidence (prompt_provenance) VALUES (150)
@@ -1226,11 +1334,11 @@ Proof failed: 150 ≤ 100
Suggestions:
• Use a value between 0 and 100
• Check if you meant 15 (typo)?
-```
+....
-### B.2 Missing Proof
+==== B.2 Missing Proof
-```
+....
PROOF OBLIGATION FAILED at line 12:
INSERT INTO claims (confidence, evidence_list) VALUES (0.95, [...])
@@ -1244,11 +1352,11 @@ Suggestions:
• Provide WITH_PROOF { confidence_justified: }
• Use a tactic: by confidenceFromEvidence text evidence_list 0.95
• Lower confidence to match evidence quality
-```
+....
-### B.3 Type Mismatch
+==== B.3 Type Mismatch
-```
+....
TYPE ERROR at line 8, column 15:
SELECT combineClaims(claim1, claim2) FROM ...
@@ -1260,26 +1368,28 @@ Type mismatch:
Cannot combine claims with incompatible confidence levels.
Suggestion: Filter claims WHERE confidence BETWEEN 0.8 AND 1.0
-```
+....
----
+'''''
-## Appendix C: Proof Cookbook
+=== Appendix C: Proof Cookbook
-### C.1 Bounded Integers
+==== C.1 Bounded Integers
-```lean
+[source,lean]
+----
-- Prove n is in bounds
example : 95 ≤ 100 := by omega
-- Prove average preserves bounds
example (a b : BoundedNat 0 100) : let avg := (a.val + b.val) / 2; avg ≤ 100 := by
omega
-```
+----
-### C.2 Non-Empty Strings
+==== C.2 Non-Empty Strings
-```lean
+[source,lean]
+----
-- Prove string is non-empty
example : "hello".length > 0 := by decide
@@ -1288,11 +1398,12 @@ example (s1 s2 : NonEmptyString) : (s1.val ++ s2.val).length > 0 := by
have h1 := s1.nonempty
have h2 := s2.nonempty
omega
-```
+----
-### C.3 Provenance Tracking
+==== C.3 Provenance Tracking
-```lean
+[source,lean]
+----
-- Prove tracked value has provenance
example (t : Tracked α) : t.rationale.val.length > 0 :=
t.rationale.nonempty
@@ -1301,11 +1412,12 @@ example (t : Tracked α) : t.rationale.val.length > 0 :=
example (ts : List (Tracked α)) : ∀ t ∈ ts, t.rationale.val.length > 0 := by
intro t ht
exact t.rationale.nonempty
-```
+----
-### C.4 Reversibility
+==== C.4 Reversibility
-```lean
+[source,lean]
+----
-- Prove insert-delete is identity
theorem insertDeleteRoundTrip {α : Type} (x : Tracked α)
: delete (insert x) = x := by
@@ -1317,20 +1429,17 @@ theorem updateReverses {α : Type} (old new : Tracked α)
: update new old (update old new data) = data := by
simp [update]
-- Implementation-specific proof
-```
+----
----
+'''''
-**Document Status**: Research prototype specification.
+*Document Status*: Research prototype specification.
-**Implementation**: Lean 4 recommended (best IDE support).
+*Implementation*: Lean 4 recommended (best IDE support).
-**Timeline**:
-- Phase 1 (Month 1-6): Refinement types
-- Phase 2 (Month 7-12): Simple dependent types
-- Phase 3 (Month 13-18): Full verification
+*Timeline*: - Phase 1 (Month 1-6): Refinement types - Phase 2 (Month
+7-12): Simple dependent types - Phase 3 (Month 13-18): Full verification
-**See Also**:
-- WP06: Dependently-Typed Lithoglyph (research proposal)
-- Lithoglyph arXiv paper (Section 14: Future Work)
-- My-Newsroom Me dialect (epistemic types)
+*See Also*: - WP06: Dependently-Typed Lithoglyph (research proposal) -
+Lithoglyph arXiv paper (Section 14: Future Work) - My-Newsroom Me
+dialect (epistemic types)
diff --git a/spec/README.adoc b/spec/README.adoc
new file mode 100644
index 0000000..a187a99
--- /dev/null
+++ b/spec/README.adoc
@@ -0,0 +1,351 @@
+== GQL-DT Specification Suite
+
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
+
+*Version:* 1.0.0 *Status:* Complete formal specification *Date:*
+2026-02-01
+
+=== Overview
+
+This directory contains the complete formal specification for *GQL-DT*
+(Lithoglyph Query Language with Dependent Types), including grammar,
+semantics, examples, and visual diagrams.
+
+=== Specification Documents
+
+==== 1. Core Specifications
+
+[width="100%",cols="31%,26%,23%,20%",options="header",]
+|===
+|Document |Purpose |Status |Lines
+|*GQL_Dependent_Types_Complete_Specification.md* |Type system,
+semantics, examples |✅ Complete |1,337
+
+|*normalization-types.md* |Functional dependencies, normal forms |✅
+Complete |753
+
+|*GQL-DT-Grammar.ebnf* |Formal EBNF grammar |✅ Complete |800+
+
+|*GQL-DT-Lexical.md* |Lexical specification |✅ Complete |700+
+
+|*GQL-DT-Railroad-Diagrams.md* |Visual syntax diagrams |✅ Complete
+|600+
+|===
+
+==== 2. Supporting Documentation
+
+[width="100%",cols="35%,31%,34%",options="header",]
+|===
+|Document |Purpose |Location
+|*WP06_Dependently_Typed_Lithoglyph.md* |Research whitepaper
+|`+../docs/+`
+
+|*STATE.scm* |Project state tracking |`+../+`
+
+|*ECOSYSTEM.scm* |Ecosystem positioning |`+../+`
+|===
+
+=== Quick Start
+
+==== For Implementers
+
+[arabic]
+. *Start with:* `+GQL-DT-Grammar.ebnf+` - Complete syntax
+. *Then read:* `+GQL-DT-Lexical.md+` - Tokenization rules
+. *Reference:* `+GQL_Dependent_Types_Complete_Specification.md+` - Type
+system
+. *Visual aid:* `+GQL-DT-Railroad-Diagrams.md+` - Syntax diagrams
+
+==== For Users
+
+[arabic]
+. *Start with:* `+GQL_Dependent_Types_Complete_Specification.md+` -
+Examples and usage
+. *Deep dive:* `+normalization-types.md+` - Database normalization
+. *Visual aid:* `+GQL-DT-Railroad-Diagrams.md+` - See syntax visually
+. *Research:* `+../docs/WP06_Dependently_Typed_Lithoglyph.md+` -
+Motivation and theory
+
+==== For Researchers
+
+[arabic]
+. *Theory:* `+../docs/WP06_Dependently_Typed_Lithoglyph.md+` - Dependent
+types for databases
+. *Type system:* `+GQL_Dependent_Types_Complete_Specification.md+`
+(Section 2-4)
+. *Proofs:* `+GQL_Dependent_Types_Complete_Specification.md+` (Section
+8-9)
+. *Normalization:* `+normalization-types.md+` - Proof-carrying evolution
+
+=== Specification Status
+
+==== ✅ Complete
+
+* [x] Type system documentation (Lean 4 notation)
+* [x] Refinement types (BoundedNat, NonEmptyString, etc.)
+* [x] Dependent types (Vector, Tracked, PromptScores, etc.)
+* [x] Proof obligations and tactics
+* [x] Complete examples (BoFIG case study)
+* [x] Normalization types (functional dependencies, normal forms)
+* [x] *Formal EBNF grammar* (NEW: 2026-02-01)
+* [x] *Lexical specification* (NEW: 2026-02-01)
+* [x] *Railroad diagrams* (NEW: 2026-02-01)
+
+==== 🔄 In Progress
+
+* [ ] Reference implementation (Lean 4 parser + type checker)
+* [ ] Proof automation tactics library
+* [ ] IDE integration (VSCode extension)
+
+==== 📋 Planned
+
+* [ ] Formal semantics in Lean 4 (operational + type soundness)
+* [ ] Performance benchmarks
+* [ ] User study (developer experience)
+
+=== Key Features
+
+==== Type System
+
+* *Refinement types:* Values with compile-time constraints
+** `+BoundedNat 0 100+` - Natural numbers in [0, 100]
+** `+NonEmptyString+` - Strings that cannot be empty
+** `+Confidence+` - Floats in [0.0, 1.0]
+* *Dependent types:* Types that depend on values
+** `+Vector α n+` - Arrays of exactly n elements
+** `+Tracked α+` - Values with mandatory provenance
+** `+PromptScores+` - PROMPT framework scores with computed overall
+* *Proof obligations:* Compile-time verification
+** `+WITH_PROOF { score_valid: by lithoglyph_prompt }+`
+** Automatic proof search (omega, simp, decide)
+** Manual proofs for complex cases
+
+==== DDL Extensions
+
+[source,gql]
+----
+-- Type-safe collection with normal form guarantee
+CREATE COLLECTION evidence (
+ id : UUID PRIMARY KEY,
+ title : NonEmptyString,
+ prompt_scores : PromptScores
+) WITH DEPENDENT_TYPES, TARGET_NORMAL_FORM BCNF;
+----
+
+==== DML with Proofs
+
+[source,gql]
+----
+-- Insert with automatic proof generation
+INSERT INTO evidence (title, prompt_scores)
+VALUES ('ONS CPI Data', {
+ provenance: 100,
+ replicability: 100,
+ objective: 95,
+ methodology: 95,
+ publication: 100,
+ transparency: 95
+ -- overall: computed automatically with proof
+})
+RATIONALE "Official UK government statistics"
+WITH_PROOF {
+ scores_in_bounds: by lithoglyph_prompt,
+ provenance_tracked: by lithoglyph_prov
+};
+----
+
+==== Queries with Refinements
+
+[source,gql]
+----
+-- Query with type-level guarantee
+SELECT (e : Evidence | e.prompt_overall > 90)
+FROM evidence e
+WHERE investigation_id = 'uk_inflation_2023'
+RETURNING (List (Evidence | prompt_overall > 90));
+-- Return type PROVES all results have prompt_overall > 90
+----
+
+==== Normalization
+
+[source,gql]
+----
+-- Discover functional dependencies
+DISCOVER DEPENDENCIES FROM employees
+SAMPLE 10000 CONFIDENCE 0.95;
+
+-- Propose normalization to BCNF
+PROPOSE NORMALIZATION employees TO BCNF
+STRATEGY PreferPreserving;
+
+-- Apply with lossless proof
+APPLY NORMALIZATION proposal_id
+WITH_PROOF {
+ lossless: by decomposition_lossless,
+ achieves_bcnf: by bcnf_decomposition_correct
+}
+RATIONALE "Eliminating transitive dependency";
+----
+
+=== Grammar Overview
+
+==== Statements
+
+....
+Statement ::= DDL | DML | Query | Normalization | Introspection
+
+DDL ::= CREATE COLLECTION | CREATE EDGE_COLLECTION | CREATE CONSTRAINT
+ | CREATE NAVIGATION_PATH
+
+DML ::= INSERT | UPDATE | DELETE | INSERT EDGE
+
+Query ::= SELECT ... FROM ... WHERE ... RETURNING ...
+
+Normalization ::= DISCOVER | CHECK | PROPOSE | APPLY | DENORMALIZE
+
+Introspection ::= INTROSPECT ... | ROLLBACK NORMALIZATION
+....
+
+==== Type Expressions
+
+....
+TypeExpr ::= Primitive | Refined | Dependent | Function | Product | Quantified
+
+Primitive ::= Nat | Int | String | Bool | Float | UUID | Timestamp
+
+Refined ::= BoundedNat min max | BoundedFloat min max
+ | NonEmptyString | Email | Confidence
+
+Dependent ::= Vector α n | Tracked α | PromptScores
+ | NavigationPath ordering | Claim confidence
+
+Function ::= α -> β | (params) -> β
+
+Product ::= α × β | (α, β, ...)
+
+Quantified ::= ∀ (x : α), P x | ∃ (x : α), P x
+....
+
+=== Implementation Status
+
+==== Phase 1: Refinement Types (✅ Milestone 1-4 Complete)
+
+* [x] Lean 4 project setup (v4.15.0 + Mathlib4)
+* [x] BoundedNat, BoundedInt with proofs
+* [x] NonEmptyString, Confidence
+* [x] PromptScores with auto-computed overall
+* [x] Provenance tracking (ActorId, Rationale, Tracked)
+
+==== Phase 2: Zig FFI Bridge (⏳ Milestone 5 - Next)
+
+* [ ] `+bridge/lith_types.zig+` - FFI type definitions
+* [ ] `+bridge/lith_insert.zig+` - Insert with proof blob
+* [ ] Lean 4 @[extern] declarations
+* [ ] Integration tests
+
+==== Phase 3: GQL Parser (📋 Milestone 6 - Blocked on M5)
+
+* [ ] Parser from EBNF grammar (NOW UNBLOCKED - grammar complete!)
+* [ ] Type inference
+* [ ] Proof obligation generation
+* [ ] Error messages with suggestions
+
+=== Testing
+
+==== Example Datasets
+
+[arabic]
+. *BoFIG UK Inflation 2023* - Complete case study in spec
+* 7 claims, 10 evidence items, 10 relationships
+* PROMPT scores, provenance tracking
+* Navigation paths for different audiences
+. *Zotero-Lithoglyph* - Production pilot
+* Reference manager with PROMPT scores
+* Real-world refinement type usage
+
+==== Proof Tactics
+
+[source,lean]
+----
+-- Lithoglyph-specific tactics
+lithoglyph_bounds -- Auto-solve bounded value proofs
+lithoglyph_prov -- Auto-solve provenance proofs
+lithoglyph_prompt -- Auto-solve PROMPT score proofs
+fd_tactic -- Functional dependency reasoning
+nf_tactic -- Normal form proofs
+lossless_tactic -- Lossless transformation proofs
+----
+
+=== Contributing
+
+==== Adding New Types
+
+[arabic]
+. Define type in Lean 4 (`+src/GqlDt/Types/YourType.lean+`)
+. Add constructor proofs
+. Add to type system spec (Section 3 or 4)
+. Add to EBNF grammar (`++` or `++`)
+. Add examples to spec (Section 10)
+
+==== Adding New Syntax
+
+[arabic]
+. Update EBNF grammar (`+GQL-DT-Grammar.ebnf+`)
+. Update railroad diagrams (`+GQL-DT-Railroad-Diagrams.md+`)
+. Update lexical spec if new keywords/operators
+. Add to main spec with examples
+. Implement in parser (once M6 starts)
+
+==== Adding New Proofs
+
+[arabic]
+. Add theorem to appropriate module
+. Add to proof library (Section 8.4 of main spec)
+. Add tactic if pattern is common
+. Document usage in examples
+
+=== References
+
+==== Primary References
+
+[arabic]
+. *Lean 4 Reference:* https://lean-lang.org/
+. *Mathlib4 Documentation:*
+https://leanprover-community.github.io/mathlib4_docs/
+. *Idris 2 Tutorial:* https://idris2.readthedocs.io/
+
+==== Related Work
+
+[arabic]
+. *Liquid Haskell:* Refinement types for Haskell
+. **F*:** Dependent types + SMT solving
+. *Dafny:* Verification-aware programming language
+. *Coq:* Proof assistant with dependent types
+
+==== Database Theory
+
+[arabic]
+. *Functional Dependencies:* Armstrong’s Axioms (1974)
+. *Normal Forms:* Codd (1NF-3NF), Boyce-Codd (BCNF)
+. *Multi-Valued Dependencies:* Fagin (4NF)
+. *Proof-Carrying Code:* Necula (1997)
+
+=== License
+
+All specification documents are licensed under *CC-BY-SA-4.0*.
+
+*SPDX-License-Identifier:* CC-BY-SA-4.0 *SPDX-FileCopyrightText:* 2026
+Jonathan D.A. Jewell (@hyperpolymath)
+
+=== Contact
+
+* *Project:* Lithoglyph Query Language with Dependent Types (GQL-DT)
+* *Repository:* https://github.com/hyperpolymath/gnpl
+* *Organization:* hyperpolymath
+* *Author:* Jonathan D.A. Jewell j.d.a.jewell@open.ac.uk
+
+'''''
+
+*Last Updated:* 2026-02-01 *Specification Version:* 1.0.0
+*Implementation Version:* 0.2.0 (65% complete, Milestones 1-4 done)
diff --git a/spec/README.md b/spec/README.md
deleted file mode 100644
index 67c5e69..0000000
--- a/spec/README.md
+++ /dev/null
@@ -1,318 +0,0 @@
-# GQL-DT Specification Suite
-
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
-
-**Version:** 1.0.0
-**Status:** Complete formal specification
-**Date:** 2026-02-01
-
-## Overview
-
-This directory contains the complete formal specification for **GQL-DT** (Lithoglyph Query Language with Dependent Types), including grammar, semantics, examples, and visual diagrams.
-
-## Specification Documents
-
-### 1. Core Specifications
-
-| Document | Purpose | Status | Lines |
-|----------|---------|--------|-------|
-| **GQL_Dependent_Types_Complete_Specification.md** | Type system, semantics, examples | ✅ Complete | 1,337 |
-| **normalization-types.md** | Functional dependencies, normal forms | ✅ Complete | 753 |
-| **GQL-DT-Grammar.ebnf** | Formal EBNF grammar | ✅ Complete | 800+ |
-| **GQL-DT-Lexical.md** | Lexical specification | ✅ Complete | 700+ |
-| **GQL-DT-Railroad-Diagrams.md** | Visual syntax diagrams | ✅ Complete | 600+ |
-
-### 2. Supporting Documentation
-
-| Document | Purpose | Location |
-|----------|---------|----------|
-| **WP06_Dependently_Typed_Lithoglyph.md** | Research whitepaper | `../docs/` |
-| **STATE.scm** | Project state tracking | `../` |
-| **ECOSYSTEM.scm** | Ecosystem positioning | `../` |
-
-## Quick Start
-
-### For Implementers
-
-1. **Start with:** `GQL-DT-Grammar.ebnf` - Complete syntax
-2. **Then read:** `GQL-DT-Lexical.md` - Tokenization rules
-3. **Reference:** `GQL_Dependent_Types_Complete_Specification.md` - Type system
-4. **Visual aid:** `GQL-DT-Railroad-Diagrams.md` - Syntax diagrams
-
-### For Users
-
-1. **Start with:** `GQL_Dependent_Types_Complete_Specification.md` - Examples and usage
-2. **Deep dive:** `normalization-types.md` - Database normalization
-3. **Visual aid:** `GQL-DT-Railroad-Diagrams.md` - See syntax visually
-4. **Research:** `../docs/WP06_Dependently_Typed_Lithoglyph.md` - Motivation and theory
-
-### For Researchers
-
-1. **Theory:** `../docs/WP06_Dependently_Typed_Lithoglyph.md` - Dependent types for databases
-2. **Type system:** `GQL_Dependent_Types_Complete_Specification.md` (Section 2-4)
-3. **Proofs:** `GQL_Dependent_Types_Complete_Specification.md` (Section 8-9)
-4. **Normalization:** `normalization-types.md` - Proof-carrying evolution
-
-## Specification Status
-
-### ✅ Complete
-
-- [x] Type system documentation (Lean 4 notation)
-- [x] Refinement types (BoundedNat, NonEmptyString, etc.)
-- [x] Dependent types (Vector, Tracked, PromptScores, etc.)
-- [x] Proof obligations and tactics
-- [x] Complete examples (BoFIG case study)
-- [x] Normalization types (functional dependencies, normal forms)
-- [x] **Formal EBNF grammar** (NEW: 2026-02-01)
-- [x] **Lexical specification** (NEW: 2026-02-01)
-- [x] **Railroad diagrams** (NEW: 2026-02-01)
-
-### 🔄 In Progress
-
-- [ ] Reference implementation (Lean 4 parser + type checker)
-- [ ] Proof automation tactics library
-- [ ] IDE integration (VSCode extension)
-
-### 📋 Planned
-
-- [ ] Formal semantics in Lean 4 (operational + type soundness)
-- [ ] Performance benchmarks
-- [ ] User study (developer experience)
-
-## Key Features
-
-### Type System
-
-- **Refinement types:** Values with compile-time constraints
- - `BoundedNat 0 100` - Natural numbers in [0, 100]
- - `NonEmptyString` - Strings that cannot be empty
- - `Confidence` - Floats in [0.0, 1.0]
-
-- **Dependent types:** Types that depend on values
- - `Vector α n` - Arrays of exactly n elements
- - `Tracked α` - Values with mandatory provenance
- - `PromptScores` - PROMPT framework scores with computed overall
-
-- **Proof obligations:** Compile-time verification
- - `WITH_PROOF { score_valid: by lithoglyph_prompt }`
- - Automatic proof search (omega, simp, decide)
- - Manual proofs for complex cases
-
-### DDL Extensions
-
-```gql
--- Type-safe collection with normal form guarantee
-CREATE COLLECTION evidence (
- id : UUID PRIMARY KEY,
- title : NonEmptyString,
- prompt_scores : PromptScores
-) WITH DEPENDENT_TYPES, TARGET_NORMAL_FORM BCNF;
-```
-
-### DML with Proofs
-
-```gql
--- Insert with automatic proof generation
-INSERT INTO evidence (title, prompt_scores)
-VALUES ('ONS CPI Data', {
- provenance: 100,
- replicability: 100,
- objective: 95,
- methodology: 95,
- publication: 100,
- transparency: 95
- -- overall: computed automatically with proof
-})
-RATIONALE "Official UK government statistics"
-WITH_PROOF {
- scores_in_bounds: by lithoglyph_prompt,
- provenance_tracked: by lithoglyph_prov
-};
-```
-
-### Queries with Refinements
-
-```gql
--- Query with type-level guarantee
-SELECT (e : Evidence | e.prompt_overall > 90)
-FROM evidence e
-WHERE investigation_id = 'uk_inflation_2023'
-RETURNING (List (Evidence | prompt_overall > 90));
--- Return type PROVES all results have prompt_overall > 90
-```
-
-### Normalization
-
-```gql
--- Discover functional dependencies
-DISCOVER DEPENDENCIES FROM employees
-SAMPLE 10000 CONFIDENCE 0.95;
-
--- Propose normalization to BCNF
-PROPOSE NORMALIZATION employees TO BCNF
-STRATEGY PreferPreserving;
-
--- Apply with lossless proof
-APPLY NORMALIZATION proposal_id
-WITH_PROOF {
- lossless: by decomposition_lossless,
- achieves_bcnf: by bcnf_decomposition_correct
-}
-RATIONALE "Eliminating transitive dependency";
-```
-
-## Grammar Overview
-
-### Statements
-
-```
-Statement ::= DDL | DML | Query | Normalization | Introspection
-
-DDL ::= CREATE COLLECTION | CREATE EDGE_COLLECTION | CREATE CONSTRAINT
- | CREATE NAVIGATION_PATH
-
-DML ::= INSERT | UPDATE | DELETE | INSERT EDGE
-
-Query ::= SELECT ... FROM ... WHERE ... RETURNING ...
-
-Normalization ::= DISCOVER | CHECK | PROPOSE | APPLY | DENORMALIZE
-
-Introspection ::= INTROSPECT ... | ROLLBACK NORMALIZATION
-```
-
-### Type Expressions
-
-```
-TypeExpr ::= Primitive | Refined | Dependent | Function | Product | Quantified
-
-Primitive ::= Nat | Int | String | Bool | Float | UUID | Timestamp
-
-Refined ::= BoundedNat min max | BoundedFloat min max
- | NonEmptyString | Email | Confidence
-
-Dependent ::= Vector α n | Tracked α | PromptScores
- | NavigationPath ordering | Claim confidence
-
-Function ::= α -> β | (params) -> β
-
-Product ::= α × β | (α, β, ...)
-
-Quantified ::= ∀ (x : α), P x | ∃ (x : α), P x
-```
-
-## Implementation Status
-
-### Phase 1: Refinement Types (✅ Milestone 1-4 Complete)
-
-- [x] Lean 4 project setup (v4.15.0 + Mathlib4)
-- [x] BoundedNat, BoundedInt with proofs
-- [x] NonEmptyString, Confidence
-- [x] PromptScores with auto-computed overall
-- [x] Provenance tracking (ActorId, Rationale, Tracked)
-
-### Phase 2: Zig FFI Bridge (⏳ Milestone 5 - Next)
-
-- [ ] `bridge/lith_types.zig` - FFI type definitions
-- [ ] `bridge/lith_insert.zig` - Insert with proof blob
-- [ ] Lean 4 @[extern] declarations
-- [ ] Integration tests
-
-### Phase 3: GQL Parser (📋 Milestone 6 - Blocked on M5)
-
-- [ ] Parser from EBNF grammar (NOW UNBLOCKED - grammar complete!)
-- [ ] Type inference
-- [ ] Proof obligation generation
-- [ ] Error messages with suggestions
-
-## Testing
-
-### Example Datasets
-
-1. **BoFIG UK Inflation 2023** - Complete case study in spec
- - 7 claims, 10 evidence items, 10 relationships
- - PROMPT scores, provenance tracking
- - Navigation paths for different audiences
-
-2. **Zotero-Lithoglyph** - Production pilot
- - Reference manager with PROMPT scores
- - Real-world refinement type usage
-
-### Proof Tactics
-
-```lean
--- Lithoglyph-specific tactics
-lithoglyph_bounds -- Auto-solve bounded value proofs
-lithoglyph_prov -- Auto-solve provenance proofs
-lithoglyph_prompt -- Auto-solve PROMPT score proofs
-fd_tactic -- Functional dependency reasoning
-nf_tactic -- Normal form proofs
-lossless_tactic -- Lossless transformation proofs
-```
-
-## Contributing
-
-### Adding New Types
-
-1. Define type in Lean 4 (`src/GqlDt/Types/YourType.lean`)
-2. Add constructor proofs
-3. Add to type system spec (Section 3 or 4)
-4. Add to EBNF grammar (`` or ``)
-5. Add examples to spec (Section 10)
-
-### Adding New Syntax
-
-1. Update EBNF grammar (`GQL-DT-Grammar.ebnf`)
-2. Update railroad diagrams (`GQL-DT-Railroad-Diagrams.md`)
-3. Update lexical spec if new keywords/operators
-4. Add to main spec with examples
-5. Implement in parser (once M6 starts)
-
-### Adding New Proofs
-
-1. Add theorem to appropriate module
-2. Add to proof library (Section 8.4 of main spec)
-3. Add tactic if pattern is common
-4. Document usage in examples
-
-## References
-
-### Primary References
-
-1. **Lean 4 Reference:** https://lean-lang.org/
-2. **Mathlib4 Documentation:** https://leanprover-community.github.io/mathlib4_docs/
-3. **Idris 2 Tutorial:** https://idris2.readthedocs.io/
-
-### Related Work
-
-1. **Liquid Haskell:** Refinement types for Haskell
-2. **F*:** Dependent types + SMT solving
-3. **Dafny:** Verification-aware programming language
-4. **Coq:** Proof assistant with dependent types
-
-### Database Theory
-
-1. **Functional Dependencies:** Armstrong's Axioms (1974)
-2. **Normal Forms:** Codd (1NF-3NF), Boyce-Codd (BCNF)
-3. **Multi-Valued Dependencies:** Fagin (4NF)
-4. **Proof-Carrying Code:** Necula (1997)
-
-## License
-
-All specification documents are licensed under **CC-BY-SA-4.0**.
-
-**SPDX-License-Identifier:** CC-BY-SA-4.0
-**SPDX-FileCopyrightText:** 2026 Jonathan D.A. Jewell (@hyperpolymath)
-
-## Contact
-
-- **Project:** Lithoglyph Query Language with Dependent Types (GQL-DT)
-- **Repository:** https://github.com/hyperpolymath/gnpl
-- **Organization:** hyperpolymath
-- **Author:** Jonathan D.A. Jewell
-
----
-
-**Last Updated:** 2026-02-01
-**Specification Version:** 1.0.0
-**Implementation Version:** 0.2.0 (65% complete, Milestones 1-4 done)
diff --git a/spec/normalization-types.md b/spec/normalization-types.adoc
similarity index 86%
rename from spec/normalization-types.md
rename to spec/normalization-types.adoc
index bb2c224..5d61cdb 100644
--- a/spec/normalization-types.md
+++ b/spec/normalization-types.adoc
@@ -1,36 +1,39 @@
-# GQL-dt Normalization Types
+== GQL-dt Normalization Types
-**Version**: 0.1.0
-**Status**: Specification
-**Date**: 2026-01-11
-**License**: MPL-2.0
+*Version*: 0.1.0 *Status*: Specification *Date*: 2026-01-11 *License*:
+MPL-2.0
-## Overview
+=== Overview
-This specification defines dependent types for encoding functional dependencies, normal forms, and proof-carrying schema normalization in GQL-dt. These types enable:
+This specification defines dependent types for encoding functional
+dependencies, normal forms, and proof-carrying schema normalization in
+GQL-dt. These types enable:
-- **Compile-time verification** that schemas satisfy target normal forms
-- **Proof-carrying normalization** with equivalence guarantees
-- **Type-safe schema evolution** with reversibility
-- **Integration with Form.Normalizer** for automatic FD discovery
+* *Compile-time verification* that schemas satisfy target normal forms
+* *Proof-carrying normalization* with equivalence guarantees
+* *Type-safe schema evolution* with reversibility
+* *Integration with Form.Normalizer* for automatic FD discovery
-## Table of Contents
+=== Table of Contents
-1. [Functional Dependencies](#1-functional-dependencies)
-2. [Normal Form Predicates](#2-normal-form-predicates)
-3. [Normalization Steps](#3-normalization-steps)
-4. [Multi-Valued Dependencies](#4-multi-valued-dependencies)
-5. [Integration with Form.Normalizer](#5-integration-with-formnormalizer)
-6. [GQL Syntax Extensions](#6-gql-syntax-extensions)
-7. [Complete Examples](#7-complete-examples)
+[arabic]
+. link:#1-functional-dependencies[Functional Dependencies]
+. link:#2-normal-form-predicates[Normal Form Predicates]
+. link:#3-normalization-steps[Normalization Steps]
+. link:#4-multi-valued-dependencies[Multi-Valued Dependencies]
+. link:#5-integration-with-formnormalizer[Integration with
+Form.Normalizer]
+. link:#6-gql-syntax-extensions[GQL Syntax Extensions]
+. link:#7-complete-examples[Complete Examples]
----
+'''''
-## 1. Functional Dependencies
+=== 1. Functional Dependencies
-### 1.1 Core Types
+==== 1.1 Core Types
-```lean
+[source,lean]
+----
/-- An attribute in a schema -/
structure Attribute where
name : String
@@ -52,11 +55,12 @@ structure FDHolds (fd : FunDep S) (r : Relation S) : Prop where
proof : ∀ t1 t2 : Tuple S,
(∀ a ∈ fd.determinant, t1.get a = t2.get a) →
(∀ a ∈ fd.dependent, t1.get a = t2.get a)
-```
+----
-### 1.2 FD Properties
+==== 1.2 FD Properties
-```lean
+[source,lean]
+----
/-- A trivial FD (Y ⊆ X) -/
def FunDep.isTrivial (fd : FunDep S) : Prop :=
fd.dependent ⊆ fd.determinant
@@ -77,11 +81,12 @@ def FunDep.isPartial (fd : FunDep S) (keys : List AttrSet) : Prop :=
def FunDep.isTransitive (fd1 fd2 : FunDep S) (keys : List AttrSet) : Prop :=
fd1.dependent = fd2.determinant ∧
¬fd2.determinantIsSuperkey keys
-```
+----
-### 1.3 Armstrong's Axioms
+==== 1.3 Armstrong’s Axioms
-```lean
+[source,lean]
+----
/-- Reflexivity: If Y ⊆ X, then X → Y -/
theorem fd_reflexivity (X Y : AttrSet) (h : Y ⊆ X) :
FDHolds ⟨X, Y, hX, hY⟩ r := by
@@ -109,11 +114,12 @@ theorem fd_transitivity (fd1 : FunDep S) (fd2 : FunDep S)
rw [← heq] at hb
exact h1.proof t1 t2 hdet b hb
exact h2.proof t1 t2 hmid a ha
-```
+----
-### 1.4 Discovered FDs with Confidence
+==== 1.4 Discovered FDs with Confidence
-```lean
+[source,lean]
+----
/-- An FD discovered from data with a confidence score -/
structure DiscoveredFD (S : Schema) where
fd : FunDep S
@@ -128,15 +134,16 @@ def DiscoveredFD.isApproximate (dfd : DiscoveredFD S) : Prop :=
/-- Threshold for treating approximate FD as exact -/
def approximateFDThreshold : Float := 0.99
-```
+----
----
+'''''
-## 2. Normal Form Predicates
+=== 2. Normal Form Predicates
-### 2.1 First Normal Form (1NF)
+==== 2.1 First Normal Form (1NF)
-```lean
+[source,lean]
+----
/-- All attributes have atomic (non-composite, non-repeating) types -/
def FirstNormalForm (S : Schema) : Prop :=
∀ attr ∈ S.attributes, attr.type.isAtomic
@@ -153,11 +160,12 @@ def GQLType.isAtomic : GQLType → Bool
| .Object _ => false -- Not atomic
| .Option t => t.isAtomic
| _ => true
-```
+----
-### 2.2 Second Normal Form (2NF)
+==== 2.2 Second Normal Form (2NF)
-```lean
+[source,lean]
+----
/-- 1NF + no partial dependencies on candidate keys -/
def SecondNormalForm (S : Schema) (fds : List (FunDep S)) (keys : List AttrSet) : Prop :=
FirstNormalForm S ∧
@@ -173,11 +181,12 @@ def SecondNormalForm' (S : Schema) (fds : List (FunDep S)) (keys : List AttrSet)
theorem second_nf_equiv (S : Schema) (fds : List (FunDep S)) (keys : List AttrSet) :
SecondNormalForm S fds keys ↔ SecondNormalForm' S fds keys := by
sorry -- Proof of equivalence
-```
+----
-### 2.3 Third Normal Form (3NF)
+==== 2.3 Third Normal Form (3NF)
-```lean
+[source,lean]
+----
/-- 2NF + no transitive dependencies on candidate keys -/
def ThirdNormalForm (S : Schema) (fds : List (FunDep S)) (keys : List AttrSet) : Prop :=
SecondNormalForm S fds keys ∧
@@ -191,11 +200,12 @@ def ThirdNormalForm' (S : Schema) (fds : List (FunDep S)) (keys : List AttrSet)
FirstNormalForm S ∧
∀ fd ∈ fds, ¬fd.isTrivial →
fd.determinantIsSuperkey keys ∨ fd.dependentIsPrime keys
-```
+----
-### 2.4 Boyce-Codd Normal Form (BCNF)
+==== 2.4 Boyce-Codd Normal Form (BCNF)
-```lean
+[source,lean]
+----
/-- Every non-trivial FD has a superkey as determinant -/
def BCNF (S : Schema) (fds : List (FunDep S)) (keys : List AttrSet) : Prop :=
FirstNormalForm S ∧
@@ -220,11 +230,12 @@ theorem bcnf_implies_3nf (S : Schema) (fds : List (FunDep S)) (keys : List AttrS
/-- 3NF does not imply BCNF (counterexample exists) -/
-- The classic counterexample: R(A, B, C) with FDs {AB → C, C → B}
-- This is in 3NF but not BCNF because C → B and C is not a superkey
-```
+----
-### 2.5 Normal Form Hierarchy
+==== 2.5 Normal Form Hierarchy
-```lean
+[source,lean]
+----
/-- The normal form of a schema -/
inductive NormalForm where
| unnormalized : NormalForm
@@ -256,15 +267,16 @@ instance : LE NormalForm where
| .bcnf => 4
| .fourth => 5
| .fifth => 6
-```
+----
----
+'''''
-## 3. Normalization Steps
+=== 3. Normalization Steps
-### 3.1 Schema Transformation
+==== 3.1 Schema Transformation
-```lean
+[source,lean]
+----
/-- A transformation from one schema to another -/
structure SchemaTransform where
source : Schema
@@ -282,11 +294,12 @@ structure LosslessTransform (t : SchemaTransform) : Prop where
structure PreservesFDs (t : SchemaTransform) (fds : List (FunDep t.source)) : Prop where
preserved : ∀ fd ∈ fds, ∃ fd' : FunDep t.target,
FDHolds fd r → FDHolds fd' (t.forward r)
-```
+----
-### 3.2 Normalization Step
+==== 3.2 Normalization Step
-```lean
+[source,lean]
+----
/-- A single normalization step with proofs -/
structure NormalizationStep where
transform : SchemaTransform
@@ -310,11 +323,12 @@ inductive FDPreservationStatus where
(lost : List (FunDep source)) →
(lostRationale : NonEmptyString) →
FDPreservationStatus
-```
+----
-### 3.3 Decomposition Operations
+==== 3.3 Decomposition Operations
-```lean
+[source,lean]
+----
/-- Decompose a schema by splitting on a violating FD -/
def decomposeOn (S : Schema) (fd : FunDep S) : SchemaTransform :=
let s1Attrs := fd.determinant ++ fd.dependent
@@ -340,11 +354,12 @@ theorem decomposition_lossless (S : Schema) (fd : FunDep S) (r : Relation S)
-- The key insight: natural join on determinant reconstructs original
-- because the FD guarantees no spurious tuples
sorry
-```
+----
-### 3.4 Normalization Algorithms
+==== 3.4 Normalization Algorithms
-```lean
+[source,lean]
+----
/-- Normalize to 3NF using synthesis algorithm (preserves all FDs) -/
def normalizeTo3NF (S : Schema) (fds : List (FunDep S)) (keys : List AttrSet) :
List NormalizationStep :=
@@ -370,15 +385,16 @@ def normalize (S : Schema) (fds : List (FunDep S)) (keys : List AttrSet)
let bcnfSteps := normalizeToBCNF S fds keys
if bcnfSteps.all (·.fdPreservation.isAllPreserved) then bcnfSteps
else normalizeTo3NF S fds keys
-```
+----
----
+'''''
-## 4. Multi-Valued Dependencies
+=== 4. Multi-Valued Dependencies
-### 4.1 MVD Definition
+==== 4.1 MVD Definition
-```lean
+[source,lean]
+----
/-- A multi-valued dependency X →→ Y -/
structure MVD (S : Schema) where
determinant : AttrSet
@@ -406,11 +422,12 @@ theorem fd_implies_mvd (fd : FunDep S) (h : FDHolds fd r) :
def MVD.isTrivial (mvd : MVD S) : Prop :=
mvd.dependent ⊆ mvd.determinant ∨
mvd.determinant ++ mvd.dependent = S.attributes
-```
+----
-### 4.2 Fourth Normal Form (4NF)
+==== 4.2 Fourth Normal Form (4NF)
-```lean
+[source,lean]
+----
/-- BCNF + no non-trivial MVDs where determinant is not a superkey -/
def FourthNormalForm (S : Schema) (fds : List (FunDep S)) (mvds : List (MVD S))
(keys : List AttrSet) : Prop :=
@@ -425,15 +442,16 @@ theorem fourth_nf_implies_bcnf (S : Schema) (fds : List (FunDep S)) (mvds : List
FourthNormalForm S fds mvds keys → BCNF S fds keys := by
intro ⟨hbcnf, _⟩
exact hbcnf
-```
+----
----
+'''''
-## 5. Integration with Form.Normalizer
+=== 5. Integration with Form.Normalizer
-### 5.1 Bidirectional FFI
+==== 5.1 Bidirectional FFI
-```zig
+[source,zig]
+----
/// Zig FFI for normalization proofs
/// Forward: Form.Normalizer → GQL-dt (for proof verification)
pub export fn lith_verify_normalization_proof(
@@ -462,11 +480,12 @@ pub export fn lith_get_discovered_fds(
out_fds: *[*]u8,
out_len: *usize,
) callconv(.C) LithStatus;
-```
+----
-### 5.2 Proof Obligations
+==== 5.2 Proof Obligations
-```lean
+[source,lean]
+----
/-- Required proofs for applying a normalization step -/
structure NormalizationProofObligation (step : NormalizationStep) where
/-- Proof that source schema exists -/
@@ -487,15 +506,16 @@ def verifyNormalization (step : NormalizationStep)
if ¬proof.achievesTarget.verify then
return .error "Target normal form proof failed"
return .ok ()
-```
+----
----
+'''''
-## 6. GQL Syntax Extensions
+=== 6. GQL Syntax Extensions
-### 6.1 Schema Definition with Normal Form
+==== 6.1 Schema Definition with Normal Form
-```gql
+[source,gql]
+----
-- Declare target normal form
CREATE COLLECTION employees (
employee_id : UUID PRIMARY KEY,
@@ -505,11 +525,12 @@ CREATE COLLECTION employees (
salary : BoundedNat 0 10000000
) WITH DEPENDENT_TYPES
TARGET_NORMAL_FORM BCNF; -- Compile error if schema violates BCNF
-```
+----
-### 6.2 Functional Dependency Declaration
+==== 6.2 Functional Dependency Declaration
-```gql
+[source,gql]
+----
-- Explicit FD declaration
CREATE COLLECTION employees (
employee_id : UUID PRIMARY KEY,
@@ -523,11 +544,12 @@ CREATE COLLECTION employees (
);
-- Type checker: Warning - transitive dependency violates 3NF
-```
+----
-### 6.3 Normalization Commands
+==== 6.3 Normalization Commands
-```gql
+[source,gql]
+----
-- Discover FDs
DISCOVER DEPENDENCIES
FROM employees
@@ -556,15 +578,16 @@ WITH_PROOF {
authorized: AdminAuth.normalize
}
RATIONALE "Eliminating transitive dependency department -> dept_location";
-```
+----
----
+'''''
-## 7. Complete Examples
+=== 7. Complete Examples
-### 7.1 Employee Schema Normalization
+==== 7.1 Employee Schema Normalization
-```gql
+[source,gql]
+----
-- Initial schema (2NF, violates 3NF)
CREATE COLLECTION employees_raw (
employee_id : UUID PRIMARY KEY,
@@ -616,11 +639,12 @@ RATIONALE "Normalizing to 3NF to eliminate update anomalies";
-- Result: Two new collections
-- employees(employee_id, name, department, salary) -- 3NF
-- departments(department, dept_location) -- 3NF
-```
+----
-### 7.2 Type-Safe Query After Normalization
+==== 7.2 Type-Safe Query After Normalization
-```gql
+[source,gql]
+----
-- Query across normalized tables (type-safe join)
SELECT (
e : Employee | e.salary > 50000,
@@ -633,11 +657,12 @@ RETURNING (List (Employee × Department) |
∀ (e, d) ∈ result, e.salary > 50000 ∧ d.dept_location = 'London');
-- Type proves all results satisfy conditions!
-```
+----
-### 7.3 Reversible Normalization
+==== 7.3 Reversible Normalization
-```gql
+[source,gql]
+----
-- Apply normalization
APPLY NORMALIZATION proposal
WITH_INVERSE (
@@ -658,13 +683,14 @@ WITH_PROOF {
inverse_exists: proposal.lossless,
authorized: AdminAuth.denormalize
};
-```
+----
----
+'''''
-## Appendix A: Proof Tactics
+=== Appendix A: Proof Tactics
-```lean
+[source,lean]
+----
namespace Lithoglyph.Normalization.Tactics
/-- Solve FD-related goals -/
@@ -696,15 +722,15 @@ macro_rules
| simp [decomposeOn, SchemaTransform.forward, SchemaTransform.inverse])
end Lithoglyph.Normalization.Tactics
-```
+----
----
+'''''
-## Appendix B: Error Messages
+=== Appendix B: Error Messages
-### B.1 Normal Form Violation
+==== B.1 Normal Form Violation
-```
+....
NORMAL FORM VIOLATION at line 5:
CREATE COLLECTION employees (...) TARGET_NORMAL_FORM BCNF
@@ -720,11 +746,11 @@ Suggestions:
• Remove TARGET_NORMAL_FORM BCNF
• Split collection: PROPOSE NORMALIZATION employees TO BCNF
• Make department a key: PRIMARY KEY (employee_id, department)
-```
+....
-### B.2 Missing Proof
+==== B.2 Missing Proof
-```
+....
PROOF OBLIGATION FAILED at line 12:
APPLY NORMALIZATION proposal WITH_PROOF { ... }
@@ -740,13 +766,16 @@ Missing: roundTrip proof
Suggestions:
• Add: lossless: by decomposition_lossless employees fd h
• Provide manual proof: lossless: by { intro r; simp [decomposeOn]; ... }
-```
+....
----
+'''''
-**Document Status**: Specification
+*Document Status*: Specification
-**See Also**:
-- [Lithoglyph Self-Normalizing Specification](https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph/spec/self-normalizing.adoc)
-- [GQL Dependent Types Complete Specification](./GQL_Dependent_Types_Complete_Specification.md)
-- [Form.Normalizer Architecture](https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph/ARCHITECTURE.adoc)
+*See Also*: -
+https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph/spec/self-normalizing.adoc[Lithoglyph
+Self-Normalizing Specification] -
+link:./GQL_Dependent_Types_Complete_Specification.md[GQL Dependent Types
+Complete Specification] -
+https://github.com/hyperpolymath/nextgen-databases/tree/main/lithoglyph/ARCHITECTURE.adoc[Form.Normalizer
+Architecture]