knowledge-distill
Skill1 starsChanged 39 days agoMITView on GitHub
Distills a library's docs and source at a pinned version into knowledge/libraries/<lib>/ concept files, clean-context verified. Triggers: 'distill knowledge for nuxt@4.0.3', 'create a knowledge bundle for phaser', /knowledge-distill.
In this repository23 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- harness-auditSkill
- skill-benchSkill
- ask-biginSkill
- bigin-harness-setupSkill
- contract-syncSkill
- debug-workflowSkill
- discovery-workflowSkill
- epic-workflowSkill
- flutter-figma-handoffSkill
- go-scaffoldSkill
- model-routerSkill
- napkinSkill
- next-scaffoldSkill
- nodejs-scaffoldSkill
- nuxt-marketing-scaffoldSkill
- nuxt-scaffoldSkill
- nuxt-ui-figma-handoffSkill
- project-scaffoldSkill
- session-handoffSkill
- sprint-distillSkill
- task-workflowSkill
- write-testsSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 0 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 65
Stop at step 3. Steps 4–6 are enforcement wiring — pre-commit, AI_REVIEW_CHECKLIST.md, CI — and they belong to the harness, not here.
- Very specific: line 74
No version given, or the user said "latest" / "current" / "newest" → ask.
- Very specific: line 98
Read references/distill-prompts.md → ## Distillation for what belongs in each file and what doesn't.
- Very specific: line 113
Cite in frontmatter: Every file gets a sources: key naming the repo, tag, and the doc paths it was derived from — one entry per path, …
- Very specific: line 117
Blend conventions visibly: If the user passed team convention docs (.claude/rules/*, a house style guide), fold the relevant rule in *at …
- Very specific: line 121
Budget mechanically, before Phase 2: Run node ${CLAUDE_SKILL_DIR}/scripts/count_budget.mjs knowledge/libraries/<lib> and trim until it …
- Very specific: line 131
Dispatch a fresh auditor: Call the Agent tool with subagent_type: "bigin-skills:knowledge-auditor", passing the bundle directory path, the …
- Very specific: line 181
Update pin.md frontmatter: version, source_commit, generated.at, and remove any drift_ack (it acknowledged staleness that no longer exists) …
- Very specific: line 184
Update the root-index line's version, and the deltas section in the bundle's index.md.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
Knowledge Distill
Turns a library's docs + source at a pinned version into concept files under
knowledge/libraries/<lib>/ in the current repo. Agents then read them through the
index-first protocol the repo already has, instead of guessing at an API that moved.
This is a static-artifact pipeline, not a retrieval tool. It runs when asked, writes files,
and exits. Nothing loads at task time except through .claude/rules/knowledge.md.
Read references/bundle-format.md before writing any file. The output has to pass
tools/knowledge_validate.mjs, which runs in the target repo's pre-commit and CI, and every
rule in that reference is there because the validator enforces it.
Preconditions
gitis available and the library's repo is public. Private repos and non-git doc sources are out of scope.- The repo has a
knowledge/bundle. Ifknowledge/index.mdis missing, do Phase 0a first. - The bundle is on the OKF v0.2 layout. If any
knowledge/libraries/*/index.mdcarries alibrary:key and has nopin.mdbeside it, that bundle predates v1.62.0 — stop and runnode tools/knowledge_migrate_okf.mjs(dry run first, then--write). Distilling over a legacy bundle leaves two pins in one directory, and only one of them is the one the drift guard reads. The script is in${CLAUDE_PLUGIN_ROOT}/skills/bigin-harness-setup/references/knowledge-migration.mdif the repo doesn't have it yet.
Phase 0a — Bootstrap the bundle (only when it's absent)
A distilled bundle is self-validating without a repo-level bundle — its own index.md seeds
the validator's reachability walk. So what's missing isn't correctness. It's that nothing would ever read the bundle (discovery runs through
.claude/rules/knowledge.md's index-first protocol), and Phase 3's validator step would have
no validator to run. Distilling into a repo with neither is paying a clone plus up to three
audit rounds for files no session opens.
Offer two paths and wait — writing rule files and a commit-time validator into someone's repo is a bigger change than "distill a bundle," and it isn't yours to assume:
- Full harness (
bigin-harness-setup) — pick this if the repo has noCLAUDE.mdor.claude/rules/either. The knowledge bundle is one phase of a harness such a repo wants anyway, and that skill also wires the commit gates and CI. - Bundle only — bootstrap here, then continue into Phase 0.
On "bundle only": do exactly what bigin-harness-setup Phase 5.5 steps 1–3 do
(${CLAUDE_PLUGIN_ROOT}/skills/bigin-harness-setup/SKILL.md), reading its templates from
${CLAUDE_PLUGIN_ROOT}/skills/bigin-harness-setup/references/knowledge-bundle.md. Apply that
phase's whole substitution paragraph, not just {DATE}. That means {CONVENTIONS_RULE} set
to whichever conventions rule exists under .claude/rules/, plus the conditional drops each
template states. With no conventions rule, agent-rules.md loses its conventions source entry
and its migration section. With no openapi.yaml/openapi.json, there is no contract concept,
no ## Contracts index section, no "Before touching handlers/routes" section and no contract
link in log.md. Drop any other sources entry whose file this repo lacks. Skipping a drop
leaves a literal placeholder or a link to a file that was never written, and the validator
fails on both. That phase holds the canonical file list —
do not restate it here, or the two drift the first time one is edited. Skip any file that
already exists.
Stop at step 3. Steps 4–6 are enforcement wiring — pre-commit, AI_REVIEW_CHECKLIST.md, CI —
and they belong to the harness, not here. Say so when you report, so nobody reads a bootstrapped
repo as a fully gated one: the bundle is validated when you run the validator in Phase 3, but
nothing yet runs it on commit. Phase 3 still installs the drift guard and wires it if the repo
turns out to have a pre-commit script.
Phase 0 — Preflight
- Resolve the pin. Required: the library's git URL and an exact tag or commit.
- No version given, or the user said "latest" / "current" / "newest" → ask. Never
resolve it yourself. A bundle whose version came from whatever
HEADhappened to be is worse than no bundle: it looks pinned and isn't.git ls-remote --tags <repo>is fine for showing the user the available tags to pick from. - Accept
lib@versionshorthand (nuxt@4.0.3) and bothv-prefixed and bare tags.
- No version given, or the user said "latest" / "current" / "newest" → ask. Never
resolve it yourself. A bundle whose version came from whatever
- Clone shallow, outside the project tree. Clone into the session scratchpad, never into
the repo being worked on:
git clone --depth 1 --branch <tag> <repo> <scratchpad>/distill-<lib>-<tag>Record the resolved SHA (git -C <clone> rev-parse HEAD) — that SHA, not the tag, is the provenance that survives a retagged release. Delete the clone when the run ends. - Find the docs. Probe in order:
docs/,documentation/,content/,website/docs/,apps/docs/,docs/content/. One match → use it. Several plausible matches, or none → ask, listing what you found. If there are genuinely no prose docs (godoc-only libraries likepgx), say so and confirm the user wants a source-derived bundle before continuing. Propose topics, then stop. Derive a topic list from the docs tree structure — one topic per coherent area a developer would ask about, not one per doc file. Present the list plus the per-file budgets from
references/bundle-format.md.Gate: do not read docs for distillation or write anything until the user confirms the topic list and budgets. Topics decide the whole shape of the bundle and are cheap to change now, expensive after Phase 1.
Phase 1 — Distill
Read references/distill-prompts.md → ## Distillation for what belongs in each file and
what doesn't. Write, per the confirmed topic list:
| File | type | Holds |
knowledge/libraries/<lib>/index.md | (reserved — no frontmatter) | The mental model, decision tables, top anti-patterns, deltas from the previous major, and links to pin.md and every topic file. Never a table of contents — if a line adds nothing a filename doesn't already say, cut it. |
knowledge/libraries/<lib>/pin.md | Contract | The pin and its provenance, all in frontmatter: library, version, source_repo, source_commit, docs_path, conventions_blended, plus generated/verified. The body is two lines — what's pinned and how to re-distill it. |
knowledge/libraries/<lib>/<topic>.md | Domain | Operational knowledge for one topic: API surface, idioms, anti-patterns, code shapes. |
knowledge/libraries/<lib>/sources.md | Playbook | Topic → path-in-source-repo map, so a deep dive knows where to look instead of re-cloning blind. |
Rules that are not negotiable:
- Rewrite, never copy. These files are our distillation of someone else's documentation. Paraphrase into our own decision-oriented framing; do not paste doc prose or reproduce doc pages wholesale. Short illustrative code shapes are fine — a copied chapter is not.
- Cite in frontmatter. Every file gets a
sources:key naming the repo, tag, and the doc paths it was derived from — one entry per path,resourcerequired on each. This is what the bundle spec requires for any externally-sourced claim; the v0.1# Citationssection is deprecated and the validator warns on it. - Blend conventions visibly. If the user passed team convention docs (
.claude/rules/*, a house style guide), fold the relevant rule in at the point of relevance prefixedTeam convention:— never silently merged into a library fact, and never in a separate section at the bottom where nobody reads it. List the paths inconventions_blended. - Budget mechanically, before Phase 2. Run
node ${CLAUDE_SKILL_DIR}/scripts/count_budget.mjs knowledge/libraries/<lib>and trim until it exits 0. Trim by cutting low-value lines, not by moving text into a new file that nothing links to — the validator warns on unreachable files and the reader never finds them.
Phase 2 — Verify (mandatory, clean context)
The failure this phase exists to catch: a hallucinated API in a bundle is worse than no bundle, because every future session in the repo now reads it as fact.
- Dispatch a fresh auditor. Call the Agent tool with
subagent_type: "bigin-skills:knowledge-auditor", passing the bundle directory path, the clone path, the pinned tag and SHA, and the audit prompt fromreferences/distill-prompts.md→## Audit. Pass the files themselves and the clone — never your own account of what you distilled or why. That self-report is exactly what the independence is for. Parse the response againstreferences/audit-contract.md. - On
FAIL— fix only what the issues list names, then dispatch a new auditor (fresh Agent call, new agent ID, no memory of this round) against the corrected bundle. Cap at 3 rounds. - Round cap hit — stop. Show the user the latest issues list and ask whether to cut the affected topics, adjust the budgets, or take over manually. Do not commit.
- On
PASS— append the audit topin.md'sverified:list as{ by: knowledge-auditor/<model>, at: <today, ISO 8601> }. That actor form is what marks the bundle machine-confirmed rather than human-reviewed; never write it ashuman:<id>. Continue.
A bundle that has not passed a clean audit must not be committed. No exceptions for "small" bundles or re-distills.
Phase 3 — Commit & wire up
- Link it from the root index. Append one line to
knowledge/index.mdunder a## Librariesheading (create the heading if absent), in the index's existing format:* [Nuxt 4.0.3](/libraries/nuxt/index.md) - distilled API surface and idioms, pinned to 4.0.3 - Validate.
node tools/knowledge_validate.mjsmust exit 0 with noERRORlines. Fix anything it reports before committing — this is the gate that runs in CI anyway. - Install the drift guard, once per repo. Two independent checks, so a half-install
completes on the next run instead of staying half-installed:
tools/knowledge_drift.mjsmissing → write it fromreferences/drift-guard.md.- The repo's pre-commit script (or
simple-git-hooks/huskyconfig) doesn't already run it → addnode tools/knowledge_drift.mjsnext to theknowledge_validate.mjsstep. Skip either one that's already done. Never create a second copy or a second hook.
- Commit. Conventional Commits:
feat(knowledge): add <lib> <version> bundle, orchore(knowledge): update <lib> to <version>for a re-distill. - Report. State the files written, the pin, the audit rounds it took, and the validator
output. Do not touch the project's
CLAUDE.md—.claude/rules/knowledge.mdalready routes agents toknowledge/index.md, and the new line from step 1 is on that path. A per-library pointer in an always-loaded file is exactly the cost this bundle format exists to avoid.
Update flow (version bump)
Triggered by "update the nuxt bundle to 4.1.0". Cheaper than a full re-distill because the docs diff bounds the work:
- Clone both tags shallow.
git -C <new-clone> diff <old-tag>..<new-tag> -- <docs_path>— for a shallow clone, fetch the old tag first (git -C <new-clone> fetch --depth 1 origin tag <old-tag>) or clone the old tag separately and diff the two trees. - Rewrite only the topic files the diff touches. Leave the rest byte-identical — a rewritten file with no semantic change is pure review noise.
- Update
pin.mdfrontmatter:version,source_commit,generated.at, and remove anydrift_ack(it acknowledged staleness that no longer exists) and any staleverifiedentries — the new content hasn't been audited yet. - Update the root-index line's version, and the deltas section in the bundle's
index.md. - Phase 2 in full, regardless of diff size. A three-line docs diff can still invalidate a claim three files away.
When not to use
- General coding, or "how do I use library X" — answer the question; don't distill a bundle.
- Documentation lookup for one API. Read the docs.
- Knowledge about our own code — decisions, invariants, playbooks. That's
sprint-distilland the rest of theknowledge/bundle. - Structural facts about our repo — call flow, dependency graph, schema shape. Those live in
graphify-out/graph.jsonand are extracted, not distilled. - Generating an
llms.txt, or anything consumed outside this repo's bundle format.
References
references/bundle-format.md— output layout, flat frontmatter schema, budgets, and the validator constraints behind each rule. Read before writing files.references/distill-prompts.md— the distillation guidance and the auditor's audit prompt.references/audit-contract.md— the auditor's JSON output schema.references/drift-guard.md—tools/knowledge_drift.mjstemplate and its hook wiring.
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
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.

