Communitygithub.com

ledger

A traceability workflow for AI agents. Three on-disk ledgers — a file ledger (MANIFEST.md), a chapter book (BOOK.md, index-first retrieval), and an artifact ledger — plus five gate commands that exit non-zero when work is untraceable. Use when a task will produce more than a few files or run across more than a few steps, when outputs are landing in scattered or duplicate files, when the context is bloating from re-reading history, or when you need to decide whether a task deserves a ledger at all.

What is ledger?

ledger is a Claude Code agent skill that a traceability workflow for AI agents. Three on-disk ledgers — a file ledger (MANIFEST.md), a chapter book (BOOK.md, index-first retrieval), and an artifact ledger — plus five gate commands that exit non-zero when work is untraceable. Use when a task will produce more than a few files or run across more than a few steps, when outputs are landing in scattered or duplicate files, when the context is bloating from re-reading history, or when you need to decide whether a task deserves a ledger at all.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/yinxia2000y-hash/Ledger/tree/HEAD/skills/ledger

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

What does ledger do?

Everything is ledgered; everything is paged on demand.

A conclusion that cannot be found again did not happen. A "done" that nothing checks is an opinion.


0. The one-line loop

init -> book -> chapter -> record -> gate -> close

Do not skip to chapter. The plan is itself a verifiable artifact.

Ledger is not "always better". It is better in the right band. Applied to a one-line change it produces empty shells; that failure has been measured and the threshold in §6 exists because of it.


1. Three iron rules

#RuleMachine check
1Pass a threshold before you ledger. >3 outputs, >3 steps, or must be retrievable later. Otherwise work directly and state the path.init --expect N [--trace] refuses and suggests skipping
2One chapter, one file; the index is the only entry point. Prose lives in chapter files. BOOK.md holds title, one-line summary, keywords, status — nothing else.book check (duplicate numbers, status/file mismatch)
3Every output is attached. A file belongs to a chapter, or the plan had a gap.book check / book orphans (exit 1)

Rule 1 is a correction, not a preference. Its earlier form — every task, even a one-line change, must init — produced 26 of 83 ledgers that were more than 20% of the task's total output, 5 of them 100%. A rule that manufactures empty shells is a bad rule, however tidy it sounds.


2. Structure

Ledger
├─ 3 iron rules
├─ 3 ledgers
│   ├─ file ledger      MANIFEST.md   who made it / what for / who reads it / how to verify
│   ├─ chapter book     BOOK.md       which chapter answers my question
│   └─ artifact ledger  artifact *    keep / register path only / delete, each with a reason
└─ 1 CLI               tools/ledger.mjs   zero dependencies, Node >= 18

A ledger is not a transcript. A transcript is read top to bottom; a ledger is paged.


3. Layout

<root>/<slug>/
├── MANIFEST.md          file ledger
├── BOOK.md              chapter book (<=200 lines, the only retrieval entry)
├── 00-brief/ch00.md
├── 10-plan/ch10.md
├── 20-exec/ch20.md
├── 30-evidence/ch30.md
├── 40-deliver/ch40.md   the single authoritative conclusion
├── out/                 real deliverables
├── backup/              originals, for rollback
└── tmp/                 probes; must be empty at close

<root> resolves as --root <dir> → $LEDGER_ROOT → ./_work.

Chapter directories are derived from the number: ch0x→00-brief, ch1x→10-plan, ch2x→20-exec, ch3x→30-evidence, ch4x→40-deliver.

Never number documents by round. round-17-notes.md is not structure. Stages are structure. Permanent assets (skills, promoted tools) do not live in a task directory — move them out and register the move.


4. The loop

#ActionCommandVerify
1Create the task dirledger init <slug> --goal "..." --expect N [--trace]MANIFEST.md exists
2Write the whole chapter table at once (empty bodies are fine)ledger book init <slug> --title T --goal G --ch "ch10|Title|Summary|kw1,kw2" xNbook check chapter count
3Create the file before writing the bodyledger book touch <slug> chNN --answer "what must this answer"first section non-empty after edit
4Register every output twiceledger add + the chapter's "Outputs from this chapter" tablebook check reports 0 orphans
5One conclusion, one placeonly 40-deliver/ch40.md; other chapters point at itno second conclusion
6Gatesbook check → book orphans → book root → artifact guard → closeall pass
ledger init cache --goal "pick an invalidation strategy" --expect 8 --trace
ledger book init cache --title "Invalidation" --goal "pick one" \
  --ch "ch10|Options|the candidates|candidates" \
  --ch "ch30|Evidence|bench results|bench" \
  --ch "ch40|Conclusion|the decision|decision"
ledger book touch cache ch30 --answer "what the benchmark showed"
ledger add cache out/bench.json --does "p99 numbers" --for "ch30" --verify "cat out/bench.json"
ledger book check cache
ledger close cache

State machine: pending --touch--> writing --conclusion written--> done; abandoned chapters are marked dropped and the number is never reused.

check rules: status != pending but the file is missing → fail. File exists but status is still pending → warn.

Append a chapter you forgot with ledger book add <slug> --ch "ch11|...". Renumbering is not supported.


5. Gates

#GateCoversOn failure
1book check <slug>Inside one task: duplicate chapter numbers, status/file mismatch, orphan outputs, BOOK.md >200 lines; warns on index rot and ledger driftexit 1
2book orphans [slug]Inside one task, no book needed: unregistered files against MANIFEST.mdexit 1
3book rootBetween tasks: the root holds only task directoriesexit 1
4artifact clean <slug> [--apply]Keep / register / delete. Dry-run by defaultexit 1 only on refusal cases
5artifact guard <slug> --max-mb NSize budget for one taskexit 1
6close <slug>Unregistered files + tmp/ leftovers; flips status to doneexit 1

check guards inside a task, root guards between tasks. Together they answer "are the files scattered".

Artifact retention

ArtifactRuling
Failed build output (apk/ipa/dex/img/dump)delete; keep only the .md report
Successful, <=50MBkeep
Successful, >50MBdelete the file, register path + size in the report
dex/so/dll/class (regenerable from a package)delete
dump / decompile / log / one-off scriptdelete (promote a general one to a permanent tool first)
Any .md report or analysis dataalways keep

Images: a filename carrying keyframe / contact-sheet / storyboard / reference is a deliverable asset and is kept; screen / shot / capture / screenshot or anything under tmp/ is an analysis screenshot — keep the data, drop the image; anything unrecognised is kept conservatively. Every ruling prints its reason, which is the only reason a heuristic is acceptable here.


6. The threshold (the important section)

New task
  |- <=3 outputs, one-shot            -> no ledger. Work. State the path in your reply.   [A]
  |- <=3 outputs, needs a paper trail -> init only, no book.                              [B]
  |- >3 outputs or >3 steps           -> init + book.                                     [C]
  '- must be retrievable later        -> init + book, keywords filled in.                 [C]
Use it (positive return)Do not (negative return)
More than 3 output filesChanging one line of config (overhead can hit 100%)
More than 3 steps, interruptibleA single lookup
A conclusion people will re-ask aboutBuild-and-ship with no intermediates
Handing work to a person or a later sessionA mechanical replace
A shared config change needing rollbackExploratory thrash that will be rewritten
Outputs that multiply copies and big files—

Staged exit:

exploration (outcome unknown) -> no book; allow tmp/ to be messy; write the book once the answer settles
convergence (direction set)   -> init + book, fill chapters
delivery                      -> check + orphans + guard + close

A measured counter-example: a task with 528 files and 964 MB kept a MANIFEST.md and no book. That was the correct call — a book would have been rewritten every time the exploration turned.

Signals to stop: three consecutive check failures that are all "forgot to touch" → demote to manifest-only. Same chapter rewritten >2 times → the book was built too early. Overhead above 30% of the task's total output → do not init next time.


7. Retrieval

  1. Read BOOK.md (<=200 lines) → pick 1–2 chapters from the summary and keyword columns.
  2. Read only those chapter files.
  3. Only if the index misses may you grep, and only inside 20-exec/ and 30-evidence/. Never recurse the project.
  4. Cross-task history → ledger book find <keyword> (reads indexes only).
  5. Write the summary and keywords back after you learn something, so step 1 hits next time.
MethodRead volume
grep -r the whole workspace~115,000 files / 46 GB
book findthe BOOK.md indexes, ~14 KB
The chapter you hitone file, ~5 KB

Three orders of magnitude, measured.


8. Known limitations

Stated plainly. A workflow that hides its failure modes cannot be trusted.

#LimitationStatus
1Small-task overhead can exceed the output (26/83 measured, 5 at 100%)Fixed by the §6 threshold
2Fixed boilerplate in MANIFEST.mdSlimmed to ~1.2 KB; sync refreshes old ledgers
3Books were used in only 11% of tasks; 45 tasks with >3 files had nonePartly unsolvable — a judgement call, not a mandate
4MANIFEST.md and BOOK.md can disagreeDetected by check (warn, non-blocking)
5Index rot: body changed, summary not updatedDetected by check (warn, non-blocking)
6Chapter numbers are permanentAccepted — stable references beat refactor convenience. Chapters can be appended, never renumbered
7Three gates used to be dead for tasks without a book (89% of them)Fixed by book orphans
8Artifact classification is heuristic; it can be silently wrongAccepted — every decision prints its reason, and clean is dry-run by default
9Everything is prompt-level; there is no hook-level enforcementUnresolved — an agent can ignore all of it
10artifact clean treating backup/ as process material would delete rollback originalsFixed — backup/ is exempt in every gate and in the classifier

9. Long-term memory does not replace a book

Memory tools have a hard size cap and are billed every turn. They are for cross-session facts: environment quirks, user preferences, lessons that do not belong to one task.

Task bodies belong on disk. Write the fact into BOOK.md's keyword column so step 1 of §7 hits, and leave the prose in the chapter.


10. Self-check

Four lines. If you cannot fill one, the task is not finished.

Book:      <root>/<slug>/BOOK.md   (N chapters, all done)
Retrieval: read BOOK.md -> hit chXX -> no full scan was needed
Recording: MANIFEST.md and BOOK.md output tables agree (N items each)
Cleanup:   tmp cleared N, archived N, deleted N; check / orphans / root / guard all pass

And the closing three lines go in your reply:

Authoritative artifact: <single path>
Verification: <command> -> exit 0
Cleanup: tmp cleared N, archived N, deleted N

Related Skills