DocGuard reads what your docs claim about your code. It reads the code too. It reports every claim that no longer matches, and says which findings it is sure about and which it is not.
The faster AI writes code, the faster everyone loses the map of what was built. Every agent session starts from zero and works out again how the system works. The docs are the map. Nothing checks whether the map still matches the territory.
4. [MED] Traceability DATA-MODEL.md — exists but no matching source code found (unlinked doc) → Doc lives in canonical/ but isn't in the manifest — guard skips it, drift accumulates silently.
npx docguard-cli demo finds seventeen of these in half a second in a project whose
docs look complete. Each names the file, the claim, and what you lose if you trust it.
Fig. 1 — The same docs, two questions. DocGuard reports both and never lets one replace the other.
The doc says it; the code agrees. Believe it.
The doc says it; the code says otherwise. DocGuard names the fix.
Something changed near this claim. The judgment is yours — DocGuard says so instead of guessing.
A document can be beautifully formatted and completely wrong. A green check is worth exactly as much as the question it answered.
A canonical doc holds two kinds of sentence. Some come from code — endpoints, entities, environment variables. Some are human reasoning — why the queue is idempotent, which trade-off was rejected, the gotcha nobody would guess. A tool that rewrites the whole file destroys the second kind each time it refreshes the first.
DocGuard keeps both in one readable markdown file, separated by HTML-comment markers. It owns the bytes
inside a source=code block and may rewrite them when the code changes. It never touches anything else.
<!-- docguard:section id=api-endpoints source=code --> | GET | /api/orders/:id | orders.controller.ts | | POST | /api/orders | orders.controller.ts | <!-- /docguard:section --> The orders service is idempotent on client-supplied keys because the mobile client retries on any 5xx; see ADR-007 for the rejected alternative. ← never regenerated
Fig. 2 — One file, two owners. The tool refreshes the blue bands and checks the gray one. It never does the reverse.
| Direction | Verb | What it does |
|---|---|---|
| code → docs | generate | Build a canonical memory from any codebase. Forty-six scanners build the code-truth skeleton (routes, schemas, screens, env vars, IaC). An agent writes the prose around it. |
| code ↔ docs | sync | When code changes, refresh only the affected source=code sections. Automatic where certain; a structured agent task where not. |
| docs ↔ code | guard | Check that the memory still matches reality: deleted endpoints still documented, routes never documented, env vars nobody reads, requirement IDs no test traces to. |
Any language works. JavaScript/TypeScript and Python get a syntax tree. Rust, Go, Java/Kotlin, Ruby, PHP and C# get a fallback that reads code shape. Every finding says which produced it; silence on a fallback file is weak evidence, not a pass.
The tool is allowed to be wrong about the table. It is never allowed to be wrong about your paragraph — so it is not allowed to touch it.
Every run follows the same five steps. None of them calls a language model. The pipeline is deterministic, offline and reproducible: the same tree gives the same findings on every machine. That is why a finding can be a CI gate and not an opinion.
Fig. 3 — The pipeline. Step 4 is where DocGuard differs from a linter: a finding is not one number, it is five independent answers.
A finding used to answer one question — how worried should you be? — with one field. That field did three jobs: how certain the detector was, whether a human had to look, and whether anyone had checked the number against reality. DocGuard now splits it into five independent channels. A blocking error can still be an escalation. A high-confidence observation can still be one only you can judge.
| Channel | The question it answers | Values |
|---|---|---|
| severity | Does CI block? | error · warn · info |
| disposition | Who decides — the tool or you? | act DocGuard states a defect and names the fix · escalate the judgment is yours |
| confidence | How sure is the detector of its observation? | high · low |
| evidence | Has the reviewed corpus ever measured this code? | measured with n and a Wilson bound · not-measured (a maintainer's prior, nothing more) |
| parserTier | Which analyzer could see this file? | js-ast · py-ast · regex-fallback · fallback-language · mixed |
“13 code commits since ARCHITECTURE.md was reviewed.” The count comes from git log, so it is exact. It proves only that a review is due, never that the document is wrong. Editing until it stops printing fixes nothing.
“README says 15 validators; the package ships 33.” Both sides are counted from disk, so the tool may rewrite the number. It also records where the count came from. A later reader can see the fix was about the same subject.
Across fourteen real repositories, 671 findings split 234 the tool would fix and 437 it handed to a human. It says which is which on every line.
Each validator compares one family of documented claims with one source of evidence. grouped by what they read, which decides how much a finding is worth.
| Family | Reads | Validators | The claim it tests |
|---|---|---|---|
| Code truth · 9 | AST: routes, schemas, env reads, imports | Docs-Sync · Docs-Diff · API-Surface · Schema-Sync · Environment · Architecture · Surface-Sync · Docs-Coverage · Generated-Staleness | “This endpoint / entity / variable / layer rule exists and looks like this.” The findings the tool fixes itself. |
| Structure · 8 | File tree, headings, manifests | Structure (with Doc Sections) · Changelog · Document-Lifecycle · Spec-Registry · Spec-Kit · Metadata-Sync · Doc-Ownership · Decision-Records | “Required chapters exist, requirements reach tasks, versions agree, decisions name their successor.” Completeness, not correctness. |
| References · 6 | Links, symbols, IDs across two revisions | Cross-Reference · Reference-Existence · Traceability · Test-Spec · Path-Scoped-Rules · AI-DLC | “This link resolves; this symbol exists; this requirement has a test; a path-scoped rule matches files; an AI-DLC record names real files.” |
| Change & time · 5 | git log, the diff since a ref, code fingerprints | Freshness · Diff-Suspicion · Drift-Comments · Doc-Dependency · Requirement-Anchors | “Something changed near this claim.” Exact, but escalated: a review is due. |
| Numbers & self · 3 | Counts on disk, typed JSON, its own package | Metrics-Consistency · Canonical-Sync · Evidence | “The number in this sentence equals the number on disk.” Includes the tool's own README, so its count claims are checked, not remembered. |
| Quality & hygiene · 5 | Prose metrics, secret patterns, TODOs, suppressions | Doc-Quality · API-Doc-Smells · TODO-Tracking · Security · Suppressions | “Readable, not bloated, not documented in name only; no secret committed; no TODO untracked; no suppression past its expiry.” Soft by design. |
A validator with nothing to validate returns N/A with a reason, never a pass. A green line says what it looked at.
Where a published method exists, the detector implements it (page 5). Where none does, the finding's own help text calls the heuristic a heuristic.
First-run conditions on production codebases; every finding hand-classified as true, false, or inert (page 6).
A detector that floods gets precision levers and is re-measured. One that adds nothing is removed — not shipped default-off.
The change-aware detectors are not inventions. Each implements a published result. Each also needed a precision lever the paper never required before it could run unattended in someone else's CI.
| Detector | Published basis | What was taken | What had to be added before default-on |
|---|---|---|---|
| Diff-Suspicion | Outdated-comment detection, arXiv 2010.01625 | A fixed rule reached F1 74.7, beating every post-hoc neural model: prose that shares tokens with a deleted part of the diff is suspect. Applied to docs, not comments. | Two signals must both hold (the doc references the changed file and shares its removed symbols); a generic-token filter; a per-doc cap. See Fig. 4. |
| Reference-Existence | Two-revision symbol check, arXiv 2212.01479 | A backticked symbol that existed when the doc was last updated but is gone at HEAD marks the doc outdated. Field tests reached roughly 50% maintainer acceptance. | CLI flags excluded, two-revision gate required: the two documented false-positive modes of the source method. |
| API-Doc-Smells | API-documentation smell taxonomy, 1,000-unit benchmark | The two smells with strong deterministic detectors: Bloated (F1 0.90) and Lazy (F1 0.95), based on documentation length per signature-headed section. | The three semantic smells that need a BERT model were left out on purpose and routed to staged agent judgment instead. |
| Finding labels | TRACE — calibrated explainability, IEEE TMLCN 2026 | The HIGH / MEDIUM / LOW vocabulary, used as deterministic strata (a validator's check pass-ratio). | A plain statement that the strata were never calibrated against outcomes. DocGuard measures precision instead (page 6). |
| Doc generation | AITPG — multi-agent debate + RAG, IEEE TSE 2026 | The staged prose pattern behind generate and diagnose: the CLI structures, the agent writes, the validators check. | Nothing generated is trusted: every source=code section is re-checked on the next run. |
Evaluating AGENTS.md (arXiv 2602.11988, revised June 2026) found that repository context files did not generally improve agent task success in its evaluated settings. They also increased inference cost. The study also found agents generally followed the instructions they were given.
DocGuard's README cites this study in its own “Why” section and says plainly that the results
do not establish DocGuard's effectiveness. They led to two changes. The tool keeps
context short (retired plans leave the tree; memory packs task-specific context, not everything).
It also measures outcomes instead of assuming them.
Fig. 4 — Why a paper's F1 is the start, not the end. The same rule, three levers later.
The recall-maximizing variants of these detectors were built, tested, and rejected: a false-positive flood destroys trust faster than a miss does.
Most tools publish an accuracy figure. DocGuard publishes a frozen benchmark, the cases behind it, the confidence interval, the caveat, and a loader. The loader refuses to quote the number if anyone edited any of those by hand.
Fig. 5 — The frozen corpus, benchmarks/baseline.json. Every dot is a retained case the loader recomputes from.
Benchmark precision on a deliberately balanced corpus of 12 defect and 12 clean-control cases … This is DocGuard's precision on labelled cases, not the probability that a finding in your repository is real; quote every ratio with its n and Wilson 95% bound.
DocGuard does not publish a calibration document. The real base rate of a stale claim is nowhere near the corpus's 50/50 split, so a probability taken from this corpus would mislead. The README says so in the same paragraph that cites the number.
The baseline is an envelope of retained cases plus derived ratios. The loader recomputes every ratio from the cases and refuses an envelope if someone edited its numbers, caveat or measure by hand. A test covers each rejection path. TestGuard probes that nobody can remove the guard silently.
The corpus could only take in a false positive that was already fixed. So a disagreement the maintainers reviewed and declined left no trace, and “precision 1.0” described the contribution pipeline, not the detectors. An adjudication row now records the disagreement and leaves the measurement intact.
docguard feedback used to sample only findings that the confidence label already doubted. So the
channel meant to test the label sampled nothing it could learn from. It now selects “unmeasured code, or low
confidence”, and the command says what it left out.
“Precision 1.000” is true, and it is a claim about twelve labeled cases. The tool is built to stop that sentence from ever being shortened.
More than a hundred releases in under eight months. What fed them matters more than the pace. Each report from a real working session became a regression test with a control. Agents wrote most reports after they hit friction on a real tree. The control asserts the behavior before the fix, so a later change cannot silently break it again.
Fig. 6 — Blue above the line: capability. Clay below: something real broke, and became a test.
DocGuard guards its own repository on every push. guard, score, diff, badge
and the packed npm tarball run without installed dependencies. A machine checks the count claims in its README. Its
sibling, TestGuard, probes its claims with planted faults. This habit found three things:
The semantic-claim extractor ignored .docguardignore; an excluded audit contributed 28 of 39 “unverified claims”. Fixed; the count fell to 12 — and one of those 12 was real drift, a stale suite-runtime claim in TEST-SPEC.md.
REF002 flagged DocGuard's own source: doc comments used realistic ADR-012 examples and fixtures cited ADRs. The fix skips tests and fixtures and uses placeholders without digits, such as ADR-NNN. It shipped with zero self-findings.
The README said “33 tests” from March 15 through all 92 releases while the suite grew past 2,000. Every self-guard stayed green. Metrics-Consistency had computed the test count since v0.8.2 and never compared it to anything. A human found it, not the tool.
declared test cases (static, AST) 1,721 reported by node:test 2,085 // loops generate cases a static count cannot see — so the static number is a FLOOR. MET003 flags a documented count below the floor (stale for certain) and passes anything above it. It carries no mechanical fix: writing the floor would replace a stale number with a wrong one.
A green self-guard proves the existing checks passed, not that the right checks exist. This page tells the honest version: a half-built check, a human reader, and a lower-bound design that refuses to guess. That is why page 10 covers the limits.
Through 0.42, DocGuard asked one question: do the docs still match the code? Versions 0.43 and 0.44 add more questions. Which section should a change have touched? Did a feature go through its spec first? What must an agent read? Did the tool get slower or noisier? Fifty-one specs (014–064) were written, planned and tasked before their code. Thirty-four carry TestGuard claims probed with planted faults.
| Area | What changed | Why it matters |
|---|---|---|
| Docs know their code | A section declares the code it describes (covers=); a reviewed fingerprint lock names the section to re-read when that code changes. Module and entity diagrams are drawn from code. | Freshness said a review was due somewhere. This says which paragraph, and why. |
| Spec first, enforced | A spec-first gate classifies each change to governed paths as covered, exempt or uncovered. Completions record the reviewed revision and survive squash merges. As-built specs describe older code. | “We follow Spec Kit” becomes a checked property of the history, not a habit. |
| Agents read less, better | MCP doc tools answer which docs describe this file and return one bounded section. Path-scoped rules report which instruction files each harness loads for a path. | The AGENTS.md study on page 5 measured cost; these cut what an agent must read to find the rule that applies. |
| The tool measured | Budgets run base and head side by side on every PR. An install older than 14 days tells the agent so — from its own CHANGELOG, no network call — and names docguard upgrade. | A guard that slows down or grows noisier erodes trust the same way drift does. |
| Reads real projects | Served routes for every framework it detects, NestJS to ASP.NET Core; unreadable paths counted, never guessed. | Gaps found on ten real repositories, closed by specs 040–064. |
| Exceptions explained | Ignore entries carry a reason and an expiry; docguard ignore lists every suppression. | A suppression now says why, and until when. |
The compact guard response was meant to lose nothing. A reconstruction test reads every field back and caught the first draft dropping validator messages.
The symbol map ships opt-in. A frozen 54-trial benchmark found no regression but no benefit on navigation tasks. Steps were unchanged and latency was 6% lower, against a 15% bar. So it stays off by default.
Every feature in these releases started as a written spec.
Through 0.44, a green line meant the check found nothing. Versions 0.45 and 0.46 make it say what it looked at. It records which function a requirement lives in, and whether a check could see what it needed. AWS AI-DLC and DORA ideas were rebuilt, not copied.
| Area | What changed | Why it matters |
|---|---|---|
| Requirements in the code | An @implements tag anchors to the function under it, and turns suspect when that code or the requirement changes. | Traceability that knows which function, not just which file. |
| Every check decides | Each validator ends in one of six verdicts. A git call that fails is a recorded gap, never a finding. | “Could not look” stops reading as “looked and found nothing”. |
| Checks you grow into | New checks start advisory. docguard policy shows which ones CI history says are ready to promote. Suppressions name an owner and an end date. | Stricter over time, on evidence from your own runs. |
| Chains and decisions | Requirements must reach tasks; ADR supersession must run both ways; authoring guidance comes from the registry the validators read. | The tool’s own skill had told agents to write a section its checker rejected. |
| AWS AI-DLC | Reads AI-DLC’s records and memory; a plugin sensor fails a gate on drift the stage introduced, not drift it inherited. | A gate that fails on old warnings gets switched off. |
| DORA evidence | score --dora maps DORA’s documentation items and AI capabilities to repository evidence. | DORA found documentation multiplies what every practice pays back. |
| Releases compared | Each release is compared with the last, finding by finding; nineteen parsers are fuzzed on every run. | A batch of fixes cannot quietly change what users see. |
A 265 KB line of HTML comments took the comment reader 9.7 seconds. Now under a millisecond, with identical output.
The release A/B added 159 findings across twelve projects, all advisory: listed, never counted against an exit code.
A check that could not see is not a check that passed. Since 0.46, DocGuard says which one it was.
.docguard-evidence.json can verify selected statements; every other statement stays unverified, and the badge prints how many.guard says whether it is true. Nor is score --dora a DORA survey.| Alongside | What that does | What DocGuard adds |
|---|---|---|
| GitHub Spec Kit | Generates feature specs, plans, tasks — spec → code, once. | Governance after generation: drift tracking, lifecycle (retire what shipped), spec-quality checks. DocGuard is an official Spec Kit community extension. |
| AGENTS.md | One instruction file: build, test, style. | AGENTS.md is one of the required files. DocGuard validates it, packs task-specific context from the canonical docs, and keeps every agent on the same map. |
| Kiro · Cursor rules | IDE-bound spec or rule files. | Portable across any IDE and any agent; enforced in CI rather than read by one editor. |
| AWS AI-DLC | A gated lifecycle where agents write each stage’s artifacts. | A plugin sensor that fails a gate on new drift; reads AI-DLC’s records and memory. |
| TestGuard | Breaks a promise on purpose and asks whether a test noticed. | The other half of the same question: whether the documentation of that promise is still true. They share an evidence format, and TestGuard fault-probes DocGuard's own claims in CI. |
npm and PyPI packages with provenance attestation, Homebrew, a GitHub Action, a Docker image, an MCP server and Claude Desktop bundle, a Spec Kit extension. No telemetry, no network at validation time.
JSON, SARIF and JUnit carry all five channels on every finding. The badge prints the unverified-claim count next to the check count. The benchmark envelope includes its cases.
When an agent writes both the code and the docs, the typical failure is confident, plausible documentation of a system that no longer exists. A deterministic comparison against the tree can catch it.
A score tells you the map is complete. DocGuard tells you which parts of the map still match the territory — and which parts it cannot tell.