You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/SPEC.md
+35-35Lines changed: 35 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# `libgitledger`
2
2
3
-
> A *Git‑Native* Ledger Library (C, `libgit2`): Spec + Project Plan with Step‑By‑Step Tasks & Tests
3
+
> A *Git-Native* Ledger Library (C, `libgit2`): Spec + Project Plan with Step-By-Step Tasks & Tests
4
4
5
-
This is the unification of two proven systems: **Shiplog**’s field‑tested deployment ledger and **git‑mind**’s hexagonal, binary‑safe engine, distilled into a reusable C library with a stable ABI and high‑performance indexing. It uses Git itself as the database, leans on `libgit2`, and bakes in policy + trust. In short: batteries included, foot‑guns removed.
5
+
This is the unification of two proven systems: **Shiplog**’s field-tested deployment ledger and **git-mind**’s hexagonal, binary-safe engine, distilled into a reusable C library with a stable ABI and high-performance indexing. It uses Git itself as the database, leans on `libgit2`, and bakes in policy + trust. In short: batteries included, foot-guns removed.
6
6
7
7
---
8
8
@@ -19,33 +19,33 @@ This is the unification of two proven systems: **Shiplog**’s field‑tested de
19
19
20
20
-**Git backend**: `libgit2` (not shelling out) — keeps things fast, safe, and embeddable.
These choices align with my previous work, the `git‑mind`/`shiplog` lineage.
25
+
These choices align with my previous work, the `git-mind`/`shiplog` lineage.
26
26
27
27
---
28
28
29
29
## I. Overview
30
30
31
-
`libgitledger` is a portable, embeddable C library for append‑only ledgers inside a Git repository. Each ledger is a linear history of Git commits on dedicated refs; entries are optionally signed, policy‑checked, and indexed for instant queries. It enables both human‑readable (`shiplog` style) and binary‑safe (`git‑mind` style) payloads via a pluggable encoder. 
31
+
`libgitledger` is a portable, embeddable C library for append-only ledgers inside a Git repository. Each ledger is a linear history of Git commits on dedicated refs; entries are optionally signed, policy-checked, and indexed for instant queries. It enables both human-readable (`shiplog` style) and binary-safe (`git-mind` style) payloads via a pluggable encoder. 
32
32
33
-
**Why this exists**: I’ve built the pattern twice already. `shiplog` (battle‑tested CLI & policy/trust) and `git‑mind` (rigorous hexagonal architecture + roaring bitmap cache). `libgitledger` fuses them into one stable core library with bindings for Go/JS/Python.
33
+
**Why this exists**: I’ve built the pattern twice already. `shiplog` (battle-tested CLI & policy/trust) and `git-mind` (rigorous hexagonal architecture + roaring bitmap cache). `libgitledger` fuses them into one stable core library with bindings for Go/JS/Python.
34
34
35
35
---
36
36
37
-
## II. Goals & Non‑Goals
37
+
## II. Goals & Non-Goals
38
38
39
39
### Goals
40
40
41
-
- Git‑native persistence (objects + refs are the DB).
42
-
- Append‑only (fast‑forward only), immutability by default.
43
-
- Library‑first: stable C ABI, no global state; embeddable; safe for bindings.
44
-
- Pluggable encoder/indexer so shiplog and git‑mind both fit naturally. 
45
-
- Policy as Code and Multi‑Signature Trust (chain or attestation) built‑in. 
46
-
- High‑performance queries using roaring bitmap cache, fully rebuildable. 
41
+
- Git-native persistence (objects + refs are the DB).
42
+
- Append-only (fast-forward only), immutability by default.
43
+
- Library-first: stable C ABI, no global state; embeddable; safe for bindings.
44
+
- Pluggable encoder/indexer so shiplog and git-mind both fit naturally. 
45
+
- Policy as Code and Multi-Signature Trust (chain or attestation) built-in. 
46
+
- High-performance queries using roaring bitmap cache, fully rebuildable. 
47
47
48
-
### Non‑Goals
48
+
### Non-Goals
49
49
50
50
- Not a full “ledger server”. No background daemons; it’s a library.
51
51
- Not a replacement for Git’s transport/auth or repo mgmt.
@@ -55,8 +55,8 @@ These choices align with my previous work, the `git‑mind`/`shiplog` lineage.
55
55
56
56
## III. Core Principles
57
57
58
-
-**Git‑Native**: object store + refs as the database; ref updates = writes.
59
-
-**Append‑Only**: fast‑forward updates; rejects history rewrites.
58
+
-**Git-Native**: object store + refs as the database; ref updates = writes.
59
+
-**Append-Only**: fast-forward updates; rejects history rewrites.
60
60
-**Hexagonal Architecture**: domain core is pure C; all I/O behind ports; libgit2 only in adapters. 
- Encoders return bytes; we do not force UTF‑8. Git will store the bytes; use textual encodings (e.g., JSON + trailers; base64‑CBOR) when needed. (Matches `shiplog`/`git‑mind` styles.)
658
+
- Encoders return bytes; we do not force UTF-8. Git will store the bytes; use textual encodings (e.g., JSON + trailers; base64-CBOR) when needed. (Matches `shiplog`/`git-mind` styles.)
659
659
- Policy/Trust are JSON; the library enforces them during `append()` and on `verify_ledger_integrity()`. (Shiplog precedent.) 
660
660
- Tag association uses notes on tag objects under `refs/gitledger/tag_notes`. 
661
661
662
662
---
663
663
664
-
## VII. Policy & Trust (built‑in)
664
+
## VII. Policy & Trust (built-in)
665
665
666
-
### Policy as Code (per‑ledger)
666
+
### Policy as Code (per-ledger)
667
667
668
668
`policy.json` under `refs/gitledger/policy/<L>` with keys like:
Enforced at append and verify time. Mirrors `shiplog`’s model, generalized for any ledger. 
677
677
678
-
### Multi‑Signature Trust
678
+
### Multi-Signature Trust
679
679
680
680
`trust.json` under `refs/gitledger/trust/<L>` including:
681
681
682
682
- `maintainers: [{id, email, key_fingerprint}]`
683
-
- `threshold: N` (N‑of‑M approvals for trust changes)
683
+
- `threshold: N` (N-of-M approvals for trust changes)
684
684
- `signature_mode: "chain" | "attestation"`
685
685
- `allowed_signers: [...]`
686
686
@@ -689,7 +689,7 @@ Library verifies signatures of entries against current trust + policy; updates t
689
689
### Signatures
690
690
691
691
- **Chain** = signed commit.
692
-
- **Attestation** = detached SSH/GPG signature note co‑stored and linked.
692
+
- **Attestation** = detached SSH/GPG signature note co-stored and linked.
693
693
694
694
Verification uses `libgit2` extraction + pluggable verification backend (GPGME/SSH sig adapter), defaulting to “present + fingerprint match” until crypto adapter is configured.
695
695
@@ -705,16 +705,16 @@ Indexer callback parses payload format and emits “terms” (`key:value`).
705
705
706
706
Library builds roaring bitmaps: one bitmap per term; entry IDs are ordinal positions in the ledger chain.
707
707
708
-
Queries are boolean set ops over bitmaps (`AND`/`OR`/`NOT`). Cache is rebuildable from journal. This mirrors git‑mind’s fast query path. 
708
+
Queries are boolean set ops over bitmaps (`AND`/`OR`/`NOT`). Cache is rebuildable from journal. This mirrors git-mind’s fast query path. 
709
709
710
710
Query API accepts a term array with leading operator shorthands (`+` for **MUST**, `-` for **MUST_NOT**). Result is an iterator of matching entry OIDs.
711
711
712
712
---
713
713
714
714
## IX. Concurrency, Atomicity, & Integrity
715
715
716
-
- **Append is optimistic**: we read `HEAD_oid`, create a commit object, then try to fast‑forward `refs/gitledger/journal/<L>` from `HEAD_oid` → `new_oid`. If the ref moved, return `GL_ERR_CONFLICT` so the caller retries after reloading latest.
717
-
- **Integrity audit**: linear parent chain check, ref integrity, optional BLAKE3 checksums on ref tips. (You flagged this as “self‑audit hooks.”) 
716
+
- **Append is optimistic**: we read `HEAD_oid`, create a commit object, then try to fast-forward `refs/gitledger/journal/<L>` from `HEAD_oid` → `new_oid`. If the ref moved, return `GL_ERR_CONFLICT` so the caller retries after reloading latest.
717
+
- **Integrity audit**: linear parent chain check, ref integrity, optional BLAKE3 checksums on ref tips. (You flagged this as “self-audit hooks.”) 
718
718
719
719
---
720
720
@@ -733,16 +733,16 @@ libgitledger/
733
733
└─ cli/ # 'git-ledger' demo tool
734
734
```
735
735
736
-
This is aligned to the hexagonal structure used in [git‑mind](https://github.com/neuroglyph/git-mind).
736
+
This is aligned to the hexagonal structure used in [git-mind](https://github.com/neuroglyph/git-mind).
737
737
738
738
---
739
739
740
740
## XI. Security Considerations
741
741
742
742
- No shell `exec` in core; signing/verification uses pluggable crypto adapters.
743
743
- Key material never stored by lib; only fingerprints/IDs in trust docs.
744
-
- Policy default‑deny if document missing (configurable).
745
-
- Replay protection via append‑only + trust verification; server‑side hooks recommended (`pre‑receive`) — pattern borrowed from `shiplog`. 
744
+
- Policy default-deny if document missing (configurable).
745
+
- Replay protection via append-only + trust verification; server-side hooks recommended (`pre-receive`) — pattern borrowed from `shiplog`. 
746
746
747
747
---
748
748
@@ -751,7 +751,7 @@ This is aligned to the hexagonal structure used in [git‑mind](https://github.c
751
751
- Stable C ABI (opaque handles; no inline structs in public headers).
752
752
- No global state; all config on a context or ledger handle.
753
753
- Bindings can map errors to idiomatic exceptions/results (Go, JS, Python).
754
-
- Threading: ledger handles are not thread‑safe; concurrent reads via separate handles; concurrent appends require higher‑level retry.
754
+
- Threading: ledger handles are not thread-safe; concurrent reads via separate handles; concurrent appends require higher-level retry.
0 commit comments