agentleFS
rasatpetabitrasatpetabit/ai-skills/skills/docs-rebuild/SKILL.md

docs-rebuild

Skill0 starsChanged 2 months agoMITView on GitHub

Use when LLM-facing markdown documentation for a repo, project, or subsystem has drifted from the system it describes, is monolithic and hard for an agent to navigate, or needs routine maintenance after a large change — "rebuild the docs for X", "how stale are our docs", "restructure the docs so agents can find things", docs that contradict the code, giant README files, missing indexes, dead cross-references.

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 11 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈11

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always runs audit → gate → rebuild → self-verify.

    line 27
  2. Distinctive:

    What "never writes" means, precisely: before the gate is answered, nothing is created, edited, moved, or deleted inside the documentation …

    line 29
  3. Distinctive:

    Put the default first and mark it Recommended.

    line 75
  4. Distinctive:

    Never audit or restructure: generated or ingested corpora, parsed/extracted dumps, vendored dependencies, build output, worktree or …

    line 125
  5. Distinctive:

    If the corpus taxonomy is ambiguous — several plausible roots, or the scope phrase spans repos —

    line 130
  6. Distinctive:

    Recon is fail-closed, not optional theatre: If a dispatched lens dies, times out, returns empty, or the spawn itself fails (stale run, …

    line 164
  7. Distinctive:

    If no reviewer from a different model vendor is reachable, say so and continue parent-side.

    line 171
  8. Distinctive:

    Leave them untouched — rewrite current-state trees only *(recommended)*

    line 216
  9. Distinctive:

    Leaves first: Write each leaf doc from the ground-truth artifacts, not from its predecessor.

    line 241
  10. Distinctive:

    Do not report completion on the strength of having written the files.

    line 264
  11. Distinctive:

    Deterministic checks, by script, not by reading: every relative link resolves.

    line 266

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

docs-rebuild

Overview

Routine, scope-bounded rebuild of a documentation corpus so that it is accurate (every statement traceable to the system as it is right now) and navigable (a future agent finds the one correct answer without reading the whole tree).

The spine — rebuild FROM the system, never FROM the old docs.

Old doc prose is evidence of intent, never evidence of fact. Every sentence that survives into the rebuilt tree must be re-derived this run from an artifact you opened this run. Editing the old text in place launders its errors forward and is the single largest source of the drift this skill exists to remove.

Two failure families, audited and fixed separately:

  • Accuracy — the docs say things the system does not do.
  • Shape — the docs are true but unnavigable: monolithic, unindexed, unreachable, duplicated.

Always runs audit → gate → rebuild → self-verify.

What "never writes" means, precisely: before the gate is answered, nothing is created, edited, moved, or deleted inside the documentation corpus or its repository. The single exception is the audit report itself when out= names a path, and that path must resolve outside the corpus — if it does not, stop and ask rather than writing where the guarantee said you would not.

Invocation

/docs-rebuild <scope phrase> [effort] [key=value ...]

<scope phrase> is free text — "this repo", "the payments service", "everything under docs/architecture". Phase 0 resolves it to concrete roots and confirms.

Argument forms

Both key=value and --key=value are accepted everywhere, as are bare and ---prefixed effort words. These are all equivalent:

high      --high      effort=high      --effort=high
tier=high --tier=high level=high       --level=high
KeyValuesDefaultEffect
effort (tier, level)low | medium | highhigh (still asks)Scales both axes together
verifylow | medium | highfollows effortPins verification depth only
restructurelow | medium | highfollows effortPins restructuring aggressiveness only
scopepath/glob listall markdown under cwdExplicit roots, skips inference
audit-onlyflagoffStop at the gate; never write
include-generatedflagoffOpt generated/vendored trees back in
outpathreport inlineWrite the audit report here. Must resolve outside the corpus
shard-ceilingintegersee structure contractOverride the split threshold

Any unrecognized key=value stops the run and asks. Never silently ignore an argument — a typo'd restructre=low that gets dropped produces exactly the churn the user tried to prevent. Bare words that are not keys or effort words are part of the scope phrase.

Scope and effort resolution

Default scope is every markdown file under cwd that is not generated/vendored: root README.md / AGENTS.md / CLAUDE.md, docs/**/*.md, and .okf/**/*.md when present. A narrower scope phrase still wins when the user typed one.

Default effort is high. Interactive sessions still ask first — they do not silently start. Put the default first and mark it Recommended; the question tool's own free-text row covers any other answer, so do not invent extra options. With no question tool, number the options in one chat message.

  1. Explicit effort= / scope= / a concrete scope phrase, if given — still confirm with a structured question unless the user already answered both this turn.
  2. Interactive, unspecified: one structured question call with two questions (scope + effort). Recommended options: All markdown under cwd and high.
  3. Non-interactive/scheduled: high + all-docs-under-cwd.

State the resolved effort and how it was resolved in the report header. Never infer effort from how bad the corpus looks — a large mess is a reason to report loudly, not to silently escalate blast radius.

Effort matrix

lowmediumhigh
Corpus readentry points + indexesevery doc in scopeevery doc in scope
Claimsheadline claims sampledevery claim classifiedevery claim classified, then adversarially falsified
Structurefix indexes and dead links onlysplit over-ceiling docs, build/repair one index layerfull re-shard, multi-level hierarchy, merge/dissolve, repoint
Gapsnot huntednamed in the report, not writtennamed and written
Recon lensesground-truth, corpus, consumer+ gap+ inbound
Inbound sweepnonoyes — whole known corpus
Post-verifyself-verifyself-verify+ cross-vendor adversarial falsification

verify= governs the Claims / Recon / Post-verify rows. restructure= governs the Structure / Gaps rows. Unset, both follow effort.

Phase 0 — Resolve scope (read-only)

Produce, and confirm before proceeding:

  • Doc roots — where the in-scope markdown lives. Default: all markdown under cwd (see resolution above).
  • Ground-truth surfaces — name each one that exists; a missing surface is a finding, not a reason to treat another surface as the same thing:
    • checkout — authored source + generated-in-repo artifacts
    • install — versioned production copy (e.g. /srv/<svc>) when the project has one
    • runtime — what processes actually load (e.g. /etc/<svc>) Plus code, schemas, CLI/Makefile targets, and tests the docs are about.
  • Entry points — the files an agent actually arrives at first (root README, agent-instruction files, skill pointers, whatever this project uses).
  • Live vs archive — which trees are current-state operator docs vs historical records (masterplan bundles, evidence receipts, handoffs, superpowers plans). Archives are audited; they are not rewritten unless the Phase 3 gate says so.
  • Exclusions.

Exclusions — default OFF, and non-negotiable without include-generated

Never audit or restructure: generated or ingested corpora, parsed/extracted dumps, vendored dependencies, build output, worktree or checkout duplicates of the same tree, and third-party docs committed verbatim. Re-sharding a generated corpus destroys it and cannot be reviewed meaningfully.

If the corpus taxonomy is ambiguous — several plausible roots, or the scope phrase spans repos — ask, do not guess. Wrong-scope work is wasted whether or not it is correct.

Phase 1 — Parallel recon (read-only, all tiers)

Dispatch one read-only agent per lens, concurrently, in a single batch. Split by lens, never by directory — directory splits produce four agents with the same blind spot.

LensQuestion it answersTiers
Ground truthWhat does this system actually do now? Entry points, real control flow, config surface, invariants, live state.all
CorpusWhat docs exist in scope? Path, size, headings, the claims each makes, its outbound links, and how it is reached.all
ConsumerWho reads these docs and with what question? Which pointers lead here; what an agent arriving cold needs first.all
GapWhat exists in the system that appears in no doc?medium, high
InboundAcross the whole known corpus — every other repo, instruction file, skill, runbook, and doc tree available — what references this scope, by link, by path, or by name?high

The inbound lens is what makes a high-tier run safe to restructure aggressively: a moved file whose referrers were never found is a new broken link, not an improvement.

The sweep must exclude non-referrers, or it inverts. A referrer is something that would break if the path changed. A record that merely quotes a path breaks nothing, and these records are enormous: agent session transcripts, chat and command history, logs, caches, search indexes, backups, archives, and .git internals quote virtually every path that has ever existed. Sweep them and every document comes back referenced — a clean 100% that reads as "safe to move anything" and means the opposite. Enumerate the excluded roots in the report alongside the swept ones; a sweep whose scope is unstated cannot be judged.

The failure mode is silent and inverted: an unexcluded sweep produces a reassuring result, so nothing prompts a second look. Treat a sweep that finds nearly everything referenced as a broken sweep until proven otherwise — on a real corpus most documents have few referrers.

A recon agent's citations are unverified. Open every artifact yourself before any claim derived from it is written into a doc. A recon report is a map of where to look, not a source.

Recon is fail-closed, not optional theatre. If a dispatched lens dies, times out, returns empty, or the spawn itself fails (stale run, missing or unavailable model), do not wait on a second identical fan-out. Continue the missing lenses yourself from primary files in this session. Record recon: parent-continued and which lenses died in the audit header. An audit that pretends five lenses reported when they did not is a false completeness claim.

If no reviewer from a different model vendor is reachable, say so and continue parent-side; do not substitute a same-vendor self-review for a required high-tier post-verify (Phase 5 still FAIL).

Phase 2 — Audit (read-only)

Classify every claim in scope (sampled, at low) into exactly one class. At high, classify every claim in live operator docs; archive/history trees may be sampled for path/default/install contradictions and reported under Not covered if not fully read.

Path claims are the highest-value class. A layout box, generated-output path, consumer path, or default-model sentence on an entry point that disagrees with checkout or install or runtime is CONTRADICTED even when a later paragraph in the same file is correct. Name which surface the claim is about; "the catalog default is X" with no surface is underspecified.

Taxonomy:

ClassMeaningRequired action
VERIFIEDTraced to a named artifact opened this runKeep; may be rewritten for shape
CONTRADICTEDAn artifact says otherwiseCorrect from the artifact
UNVERIFIABLENo artifact establishes it either wayDelete, or demote to an explicitly-marked intent/history doc — never leave it stated as current fact
OBSOLETEDescribes something that no longer existsDelete; record in the report

Structural findings are judged against references/structure-contract.md. Report format, severity ladder, and the required headline metrics are in references/audit-report.md.

The report must open with the "how off is it" headline — verified/contradicted/unverifiable counts, structural conformance, and coverage — because that number, not a narrative, is what decides whether to spend the rebuild.

Phase 3 — The gate

Present the audit and stop. Ask two single-select questions in one structured-question call (AskUserQuestion on Claude Code, ask_user_question on Pi; with no question tool, the same options numbered in one chat message), showing the blast radius (files created / rewritten / moved / merged, and every inbound reference that must be repointed):

  1. What the rebuild changes:
    • Apply everything at the resolved effort (recommended when accuracy findings exist)
    • Accuracy only — correct claims, leave the file layout untouched
    • Structure only — re-shard and index, deferring claim corrections (see the constraint below)
    • Abort — report only
  2. Archive bodies (evidence, handoffs, plans):
    • Leave them untouched — rewrite current-state trees only (recommended)
    • Rewrite them too

The second answer governs archive bodies whatever the first says, so Apply everything with Leave them untouched is a full apply to current-state trees only. On Abort, discard the second answer.

Deferral is a choice the human makes, not a silent outcome. The per-class actions in Phase 2 are what a full apply performs; a narrower gate answer defers the rest rather than dissolving it. Every deferred finding is carried into the run report as outstanding work, with its class and severity intact.

One constraint on Structure only: it may not be applied silently while Critical accuracy findings stand — a doc that would make an agent do the wrong thing must not be re-sharded and re-indexed into greater prominence while still saying the wrong thing. Surface those findings again and get an explicit acknowledgement that they are knowingly being left in place; without it, nothing is written.

audit-only runs stop here permanently. A gate that times out or is declined is not consent to write.

Phase 4 — Rebuild (writes)

Order matters:

  1. Leaves first. Write each leaf doc from the ground-truth artifacts, not from its predecessor. Keep the old file open for intent — what question was this trying to answer — and for nothing else.
  2. Then indexes, bottom-up. An index is a routing table: per child, the question that child answers. A bare list of links is not an index.
  3. Then repoint inbound references found by the inbound lens.
  4. Then the entry point, last, so it reflects the finished tree.

Rules that hold at every tier:

  • Preserve the project's existing taxonomy where it is coherent. Adopt its vocabulary and directory semantics; do not impose a house layout on a tree that already has a working one.
  • No content is deleted without an accounting. Content is relocated, folded, or explicitly dropped-and-recorded in the run report. "It looked redundant" is not an accounting.
  • Prefer deletion to duplication. A doc that restates what one source file already says better should become a pointer to that file. Every duplicated fact is a future drift site; the cheapest way to keep docs accurate is to have fewer claims that can go stale.
  • Never interleave state, intent, and history. How it works, why we chose it, and what we plan next are three different documents. Mixing them is the most reliable way to manufacture drift.

Phase 5 — Self-verify (required)

Do not report completion on the strength of having written the files.

  1. Deterministic checks, by script, not by reading: every relative link resolves; every leaf is reachable from an entry point within the hop limit; no doc exceeds the shard ceiling; no directory lacks an index. Paste the actual output.
  2. Re-audit a sample of the rewritten claims against ground truth — at high, all of them. Findings from Phase 2 must now come back clean; any that do not are reported as remaining work, not quietly dropped.
  3. At high only: a fresh-context cross-vendor adversary re-reads the rebuilt tree and tries to falsify its claims: a model from a different vendor than the one that did the rebuild. Never a same-vendor reviewer, and the author's own re-read is not a review. If no cross-vendor reviewer is available, that is a FAIL to report and the run is reported incomplete — not a step to substitute or skip.

Triage review findings before rewriting. A finding is legitimate only if it is grounded in the artifact, material, in scope, and not a chunk/context hallucination (e.g. "file truncated" when the file continues). Apply legitimate majors; reject invalid/churn with a one-line reason in the run report. Do not treat a degraded/timed-out review as a pass.

Phase 6 — Retain corrections

Record the major corrections: what the docs asserted, what is actually true, and the artifact that settles it. If your agent setup has a durable memory store, retain them there; otherwise list them in the run report under Corrections to remember. Keep the corrections and the durable structural decisions — not "ran a docs rebuild", not per-file edit logs.

Nothing is written into the repo as tracking metadata. No provenance front-matter, no manifest, no verified-stamps: the corpus stays plain markdown, and drift memory lives outside it.

Red flags — stop and restart the phase

  • Editing an existing doc's sentences instead of re-deriving them → drift laundering.
  • A claim marked verified whose artifact you did not open this run.
  • Restructuring before the inbound lens has reported (at high) → guaranteed broken referrers.
  • Writing anything before the gate is answered.
  • Escalating effort mid-run because the corpus turned out worse than expected.
  • Reporting completion with the deterministic link/reachability check unrun or unpasted.
  • Touching an excluded generated/vendored tree because it "clearly needed it too".
  • Treating a dead recon fan-out as completed recon.
  • Collapsing checkout, install, and runtime into one "the system" when they disagree.
  • Rewriting archived masterplan/evidence/handoff bodies without an explicit gate option.
  • Counting regex hits inside code fences (\.[0-9]+) as dead markdown links.
  • Applying SHARD_CEILING to archived plans as if they were live operator docs.

Rationalizations

ExcuseReality
"The old doc was probably right, I'll just tidy it"Probably-right is exactly how drift survives a rebuild. Re-derive it.
"The code is self-evident, no need to open it"Then the claim costs one file read. Open it.
"This claim is obviously true"Obvious claims are the ones nobody rechecks; they age worst. Classify it.
"I'll fix the inbound links later"Later is a broken tree in the interim and forgotten by the report.
"It's a small corpus, skip the gate"The gate costs one question; an unwanted restructure costs a revert.
"No cross-vendor reviewer available, I'll self-review"Self-review does not satisfy a review gate. Report the FAIL.
"Deleting an unverifiable claim loses information"A claim nothing supports is not information. Demote it to a marked intent doc or drop it.

References

  • references/structure-contract.md — what a well-formed, agent-navigable tree is, and the tunable thresholds.
  • references/audit-report.md — finding taxonomy, severity ladder, and the report template.
  • REQUIRED BACKGROUND for the prose itself: writing-for-agents — this skill decides what is true and where it lives; that skill governs how the sentences are written.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.