Skip to content

API Reference parrot.sdd.scripts.id_ledger

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.sdd.scripts.id_ledger

View source

IdLedger model + bootstrap for the git-native TASK/FEAT ID allocator.

This module defines the tiny, git-tracked "next ID" ledger (sdd/tasks/.id_ledger.json) used by scripts/sdd/reserve_ids.py as a compare-and-swap counter for globally-unique TASK-<NNN> (and best-effort FEAT-<NNN>) numbers (FEAT-387).

IdLedger is deliberately kept a pure data container — no reserve/increment logic lives here. That belongs to reserve_ids.py (Module 2), keeping this module and its allocator independently testable per the spec's Module Breakdown.

Class IdLedger

The full contents of sdd/tasks/.id_ledger.json.

A single, tiny, git-tracked file acting as a compare-and-swap counter for globally-unique TASK-<NNN> numbers (and, best-effort, FEAT-<NNN> numbers). Every allocator reads this file, computes a reservation, and races to push an update — the push itself is the compare-and-swap: a non-fast-forward rejection means someone else already advanced the counter, so the allocator must re-read and retry.

Fields:

Field Type Default Description
next_task_id int Next unassigned TASK number.
next_feature_id int Next unassigned FEAT number.
updated_at str ISO-8601 UTC timestamp of the last reservation.
updated_by str Free-text origin of the last reservation (feature slug or session id) — diagnostic only, not used for correctness.

Attribute LEDGER_PATH

Function bootstrap_ledger

Seed a fresh IdLedger strictly ahead of every ID currently in use.

Scans sdd/tasks/index/*.json (all id/feature_id fields) AND sdd/specs/*.md (the **Feature ID**: FEAT-<NNN> header line) for the current maximum TASK-<NNN> and FEAT-<NNN> respectively, and returns an IdLedger with next_task_id/next_feature_id set to max + 1.

bootstrap_ledger(index_dir: Path = Path('sdd/tasks/index'), specs_dir: Path = Path('sdd/specs')) -> IdLedger

Parameter Type Default Description
index_dir Path Path('sdd/tasks/index') Directory containing per-spec index JSON files.
specs_dir Path Path('sdd/specs') Directory containing spec markdown files.

Returns: IdLedger — A freshly bootstrapped IdLedger.

Function load_ledger

Load and validate an IdLedger from path.

load_ledger(path: Path) -> IdLedger

Parameter Type Default Description
path Path Path to the ledger JSON file.

Returns: IdLedger — The parsed and validated IdLedger.

Function main

CLI entry point: python -m scripts.sdd.id_ledger bootstrap.

main(argv: list[str] | None = None) -> int

Parameter Type Default Description
argv list[str] | None None

Returns: int

Function save_ledger

Write ledger to path as byte-stable JSON.

Matches migrate_index.py's own output convention (json.dumps(..., indent=2, sort_keys=False) plus a trailing newline) so diffs stay small and reviewable.

save_ledger(path: Path, ledger: IdLedger) -> None

Parameter Type Default Description
path Path Destination path for the ledger JSON file.
ledger IdLedger The IdLedger to serialize.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally