@ai-ledger/cli
v0.2.0
Published
Reference CLI for AI Ledger. Initializes .ai-ledger structure, generates contracts and entries, and runs basic compliance checks.
Maintainers
Readme
@ai-ledger/cli
Reference CLI for AI Ledger. Run with npx (no install):
npx @ai-ledger/cli init
npx @ai-ledger/cli new --title "..."
npx @ai-ledger/cli checkinit— scaffold.ai-ledger/(templates, config), ensureAGENTS.mdhas AI Ledger setup instructions, set up storage mode, and manage a basic CI workflownew --title "..."— generate a new contract and entrycheck— validate that contracts/entries exist and are non-empty in the configured storage (workspace or git-branch); suitable for CI
Storage strategy (0.2.0)
By default, init chooses storage mode automatically:
git-branch(default when inside a git repository):- contracts and entries are committed to a dedicated ledger branch, by default
ai-ledger/log - files are written in a dedicated git worktree under
.git/.ai-ledger/worktree initautomatically migrates existing workspace ledger files into the detached branch when possible, then deletes the migrated copies (and their now-emptycontracts/entriesfolders) from the working tree- your active branch stays clean (no ledger-file noise), while the ledger branch contains the append-only history
- contracts and entries are committed to a dedicated ledger branch, by default
workspace(fallback outside git):- contracts and entries are written to
.ai-ledger/contractsand.ai-ledger/entriesin your working tree
- contracts and entries are written to
You can control this via .ai-ledger/config.json:
{
"storage": {
"mode": "git-branch",
"branch": "ai-ledger/log"
}
}Why these names:
ai-ledger/logis a plain-language branch name for the ledger stream..git/.ai-ledger/worktreegroups internals under a single.ai-ledgerdirectory instead of a one-off folder name.
What init actually does
When you run:
npx @ai-ledger/[email protected] initthe CLI will:
- Create
.ai-ledger/if needed:.ai-ledger/templates/contract.yaml.ai-ledger/templates/entry.md.ai-ledger/config.json.ai-ledger/README.mdexplaining where contracts/entries live (workspace vs ledger branch)
- Ensure
AGENTS.mdcontains the AI Ledger non‑negotiables. - If
storage.mode = "git-branch":- Create or reuse a worktree for the ledger branch (default
ai-ledger/log) under.git/.ai-ledger/worktree. - Migrate any existing
.ai-ledger/contracts/*and.ai-ledger/entries/*in the workspace into the ledger worktree, committing them on the ledger branch. - Delete migrated workspace files (and remove now-empty
.ai-ledger/contracts/.ai-ledger/entriesdirectories), leaving the ledger branch as the source of truth. - Install a
pre-pushhook that pushes the ledger branch to the same remote whenever you push any ref (skipped if you already have a custom pre-push hook).
- Create or reuse a worktree for the ledger branch (default
- Manage a basic GitHub Actions workflow:
- If
.github/workflows/ai-ledger-basic.ymldoes not exist, create one that runsnpx @ai-ledger/[email protected] checkon pull requests. - If it does exist and matches the old pattern that diffs
.ai-ledger/contracts/.ai-ledger/entriesand printsAI Ledger: missing new contract and/or entry., rewrite it to the CLI‑based check.
- If
This means:
- Existing projects on 0.1.0 that used the documented
ai-ledger-basic.ymlwill be migrated to detached storage and get a compatible CI workflow when they runinit. - New projects get storage + CI set up in one step.
Using check in CI
For consumer projects, the recommended CI pattern is to call the CLI, not to diff .ai-ledger/ directly, for example:
name: AI Ledger (basic)
on:
pull_request:
jobs:
basic:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: AI Ledger check
run: npx @ai-ledger/[email protected] checkThe check command:
- In
workspacemode: verifies.ai-ledger/contracts/and.ai-ledger/entries/exist and are non‑empty. - In
git-branchmode: ensures the ledger worktree exists for the configured branch and that its.ai-ledger/contracts/and.ai-ledger/entries/are non‑empty.
Pushing the ledger branch
The CLI writes and commits to the ledger branch locally. When using git-branch storage, init installs a pre-push hook that pushes the ledger branch (e.g. ai-ledger/log) to the same remote whenever you push any ref.
So when you run git push origin main or git push origin your-feature-branch, the hook also runs a secondary git push --no-verify origin ai-ledger/log (with recursion protection), keeping the remote ledger in sync without looping.
If you have a custom pre-push hook already, the CLI will not overwrite it. If the hook cannot be installed/updated (for example due to permissions), init warns and continues. In either case you can push the ledger branch manually:
git push origin ai-ledger/log