Schemaed outputs are the record, not logs. Every operation produces a versioned, machine-verifiable receipt.
Stable ordering and budgets prevent "comment churn" in PR workflows:
- Same inputs → byte-identical outputs
- Explicit truncation markers, not silent drops
- Normalized paths regardless of OS
Analysis provides information, not judgments:
- "Doc density is 12%" — not "Documentation is poor"
- "File changed 47 times" — not "This is a problem file"
- Users interpret signals in their context
tokmd is a sensor for inventory, distribution, risk signals, and blast radius. It is explicitly not a productivity metric tool.
Run the scan once. Derive all views (lang, module, export, analysis) from that single source of truth.
- Quick scans return fast summaries
- Deep analysis is opt-in via presets
- Feature flags control compilation footprint
The capabilities field explicitly reports which checks were available, unavailable, or skipped. This lets directors distinguish "all checks passed" from "nothing ran" instead of treating unavailable evidence as success.
┌─────────────────────────────────────────────────────────────┐
│ tokmd │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ CLI │ │ Python │ │ Node.js │ │ Library │ │
│ │ (tokmd) │ │ Bindings │ │ Bindings │ │ API │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
│ │ │ │ │ │
│ └─────────────┴─────────────┴─────────────┘ │
│ │ │
│ ┌──────┴──────┐ │
│ │ tokmd-core │ │
│ │ (facade) │ │
│ └──────┬──────┘ │
│ │ │
│ ┌────────────────────────┴────────────────────────┐ │
│ │ │ │
│ │ tokmd-scan → tokmd-model → tokmd-format │ │
│ │ ↓ ↓ │ │
│ │ tokmd-analysis → tokmd-format::analysis │ │
│ │ │ │
│ └──────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
↓
Receipts (JSON/JSONL/CSV)
Every JSON receipt includes:
{
"schema_version": 2,
"tool": "tokmd",
"tool_version": "1.11.0",
"generated_at_ms": 1706886000000,
"mode": "lang",
"scan": { ... },
"totals": { ... },
"rows": [ ... ],
"integrity": "blake3:..."
}tokmd is a code-evidence producer: it produces receipts, review packets,
proof-routing inputs, and context bundles, not the whole evidence backplane.
External directors and evidencebus can aggregate tokmd receipts with evidence
from mergecode, CI sensors, gates, perf tools, and other producers.
Separate versions per receipt family:
- Core receipts:
SCHEMA_VERSION = 2 - Analysis receipts:
ANALYSIS_SCHEMA_VERSION = 9 - Cockpit receipts:
COCKPIT_SCHEMA_VERSION = 3 - Handoff manifests:
HANDOFF_SCHEMA_VERSION = 5 - Context receipts:
CONTEXT_SCHEMA_VERSION = 4 - Context bundles:
CONTEXT_BUNDLE_SCHEMA_VERSION = 2 - Tool schemas:
TOOL_SCHEMA_VERSION = 1 - Sensor reports: semantic schema id
sensor.report.v1
Evolution rules:
- Additive changes within vN (new optional fields)
- Breaking changes require vN+1 with migration notes
- Ordered structures:
BTreeMap/BTreeSetat all boundaries - Stable sorting: Descending by code lines, then ascending by name
- Path normalization: Forward slashes (
/) regardless of OS - Redaction determinism: Same input → same BLAKE3 hash
Wraps tokei library:
ScanOptions → tokei Config
tokei Languages → tokmd receipts (via tokmd-model)
Uses shell git log (not git2):
git log --numstat → CommitHistory
Respects --max-commits, --max-commit-files
File content analysis:
File bytes → entropy (Shannon bits/byte)
File bytes → tag counts (TODO, FIXME)
File bytes → BLAKE3 hash
Filesystem traversal:
Tries git ls-files first
Falls back to ignore crate
Respects .gitignore, .tokeignore
Host-abstracted file access for in-memory and WASM execution:
ReadFs trait → HostFs (native std::fs)
→ MemFs (tests / in-memory substrates)
Presets bundle enrichers for common use cases:
| Preset | Enrichers |
|---|---|
receipt |
derived + dup + git + complexity + API surface |
estimate |
receipt + effort estimation and optional base/head delta |
health |
derived + content (TODOs) + complexity + Halstead |
risk |
health + git (hotspots, coupling, freshness) |
supply |
derived + walk (assets) + content (deps) |
architecture |
derived + content (imports) |
topics |
semantic topic clouds (TF-IDF) |
security |
license radar + entropy profiling |
identity |
archetype detection + corporate fingerprint |
git |
predictive churn + advanced git metrics |
deep |
all enrichers (except fun) |
fun |
eco-label, novelty outputs |
#[cfg(feature = "git")]
fn run_git_enrichers() { ... }
#[cfg(feature = "content")]
fn run_content_enrichers() { ... }
#[cfg(feature = "walk")]
fn run_walk_enrichers() { ... }- ScanError: File access, tokei failures
- AnalysisError: Enricher failures
- GateError: Policy evaluation failures
- ConfigError: Configuration parsing failures
- Graceful degradation: Missing optional inputs → skip verdict
- Partial receipts: Runtime errors → emit what's available
- Explicit failures: Policy violations → exit code 2
All PR-facing outputs are budgeted:
- Max highlights per section
- Max files in review plan
- Stable truncation indicators
Context packing respects token budgets:
--budget 128k → Select files that fit
--strategy greedy|spread → Selection order
--rank-by code|tokens|churn|hotspot → File priority signal
Explicit [truncated] markers
- Determinism: Same inputs → same outputs
- Idempotency: Repeated operations → same results
- Composition: Filters compose predictably
- Monotonicity: More input → proportionally more output
- Unit tests: Domain logic (sorting, aggregation, hash computation)
- Integration tests: CLI contract (flags, outputs, exit codes)
- Golden tests: Output format stability
- Property tests: Invariant verification
- Fuzz tests: Parser robustness
- Mutation tests: Test quality verification