Learning Distill
Goal
Convert raw task evidence into concise, durable repo knowledge, routed by kind:
- Descriptive (facts, rationale, architecture, troubleshooting patterns, repo decisions) -> OKF pages under the curated wiki trees
openwiki/{decisions,troubleshooting}/ and openwiki/.
- Prescriptive (agent behavior rules, procedures) ->
.agents/AGENTS.md or .agents/playbooks/.
Distillation never invokes openwiki --update; it authors pages directly and refreshes indexes deterministically.
Prerequisites (fail closed)
Before writing any wiki output, verify all of the following; on failure stop without writing and print the remediation:
openspec / openwiki binaries on PATH:
node .agents/skills/aksk-bootstrap/scripts/check_peer_tools.mjs openspec openwiki
openwiki/INSTRUCTIONS.md exists AND carries the AKSK contract markers
(AKSK:WIKI-CONTRACT). If missing or stub-only, run the attachment:
node .agents/skills/aksk-bootstrap/scripts/attach_wiki_contract.mjs
Inputs
- session bundle directory under
.agents/sessions/
.agents/AGENTS.md, .agents/playbooks/
openwiki/INSTRUCTIONS.md (curation contract: curated trees and rules)
- existing curated pages under
openwiki/
Read the canonical task/session identifier from the task_id field in the bundle's summary.json. Do not infer identity from the session folder name.
Skill initialization (before first distillation)
Run once per target repo after this skill folder is present under .agents/skills/learning-distill/. Idempotent.
- Resolve the repo root (the directory containing
.git/).
- Ensure
.agents/ exists.
- Ensure
.agents/playbooks/ exists. If .agents/playbooks/README.md is missing, copy bootstrap/playbooks/README.md into place.
- Ensure
.agents/sessions/ exists. If .agents/sessions/README.md is missing, copy bootstrap/sessions/README.md into place.
- If
.agents/AGENTS.md is missing, copy bootstrap/AGENTS.md into place. Never overwrite an existing one.
- Ensure
.agents/.gitignore contains exactly these two lines (merge if absent, do not remove unrelated rules):sessions/*
!sessions/README.md
- Run the aksk-bootstrap peer-tool check and wiki-contract attachment (see Prerequisites) so the wiki side of distillation is ready.
The kit's durable knowledge base lives in the wiki; this skill no longer seeds any .agents/docs/ scaffold.
Classification categories
Classify each candidate lesson as one of:
- ephemeral
- AGENTS guidance
- playbook
- decision record (curated wiki page)
- troubleshooting record (curated wiki page)
- descriptive lesson (any other curated wiki page)
Distillation rules
- Preserve only stable, reusable knowledge. Reject low-confidence or one-off lessons.
- Do not copy task history into
.agents/AGENTS.md.
- Decision records ->
openwiki/decisions/<slug>.md; troubleshooting records -> openwiki/troubleshooting/<slug>.md; other descriptive lessons -> a topical page under openwiki/. The filename stem is the entry identity; keep it unique within its tree.
- Wiki page frontmatter follows OpenWiki OKF (
type, title, description, tags, timestamp) plus AKSK extensions: aksk_status (accepted, superseded, or provisional) on decision pages; optional aksk_superseded_by; optional aksk_depends_on listing qualified slugs (decisions/<slug>, troubleshooting/<slug>).
- Cross-references between knowledge pages use relative Markdown links; superseded pages point at their successor via
aksk_superseded_by plus a link.
- No duplication with OpenSpec: if a candidate decision restates or overlaps a requirement that already exists in
openspec/specs/, do not create or extend a wiki page for it; cite the spec capability instead. Wiki pages record facts and rationale; requirements live only in OpenSpec.
- Curated-page preservation: treat trees marked curated in
INSTRUCTIONS.md as preserve-and-link targets - update AKSK-authored content in place; link generated material to it rather than overwriting it; never drop aksk_* frontmatter fields.
- Use
.agents/playbooks/ for durable multi-step procedures; add to .agents/AGENTS.md only if the lesson is broad, stable, concise, and actionable.
Finding session bundles (gitignore)
Per-task folders under .agents/sessions/ are gitignored (only README.md is tracked). Many search tools skip ignored paths by default.
Do not conclude there are no bundles based on an ignore-aware search alone. Locate bundles with at least one ignore-blind method: filesystem listing (ls, find) or ripgrep with --no-ignore-vcs.
Then read each candidate's summary.json: treat task_id as canonical and filter using distillation state fields (distilled, status, distillation_status). Do not select a bundle from its folder name.
Procedure
Locate and read the session bundle (see above); read summary.json for task_id.
Search related existing knowledge with grep over openwiki/ (page bodies are plain Markdown) before comparing manually. For decision- or requirement-shaped candidates, also search openspec/specs/ - a rule already codified as a SHALL requirement there must not be duplicated as a wiki page.
Compare candidates against existing knowledge; remove duplication.
Classify each lesson.
For wiki-bound lessons: load authoring guidance at runtime from the installed package, then author the page directly. With NPM_ROOT="$(npm root -g)":
Load upstream authoring guidance (use init for new pages, update for edits):
NPM_ROOT="$(npm root -g)" node --input-type=module -e '
import { pathToFileURL } from "node:url"; import path from "node:path";
const m = await import(pathToFileURL(path.join(process.env.NPM_ROOT, "openwiki/dist/agent/prompt.js")).href);
console.log(m.createSystemPrompt(process.argv[1] ?? "init"));
' init
Write the page under the correct curated tree following that guidance and the OKF frontmatter rules above, then validate it:
NPM_ROOT="$(npm root -g)" node --input-type=module -e '
import { readFileSync } from "node:fs";
import { pathToFileURL } from "node:url"; import path from "node:path";
const fm = await import(pathToFileURL(path.join(process.env.NPM_ROOT, "openwiki/dist/okf/frontmatter.js")).href);
const file = process.argv[1];
console.log(JSON.stringify(fm.validateOkfFrontmatter(readFileSync(file, "utf8"), file)));
' openwiki/<path>.md
Fix every reported issue before continuing.
Draft minimal updates to .agents/AGENTS.md or playbooks for prescriptive lessons.
Refresh wiki indexes deterministically (never via the CLI):
node .agents/skills/aksk-bootstrap/scripts/sync_wiki_indexes.mjs
Mark the session bundle as distilled (its summary.json flags).
There is no activity log to append; accountability lives in the bundle flags and git history.
Constraints
- Do not modify source code outside the knowledge layer.
- Do not invent new repo rules unsupported by task evidence.
- Do not expand
.agents/AGENTS.md with rationale or narrative.
- Do not copy secrets, private identifiers, personal data, or long raw output into durable docs or wiki pages.
- Never edit OpenWiki-owned files:
index.md files, run metadata (.last-update.json), or anything outside the curated trees except through deterministic index sync.
- Prefer small edits over large rewrites.
AGENTS criteria
A lesson belongs in .agents/AGENTS.md only if it is high confidence, broadly useful in this repo, likely to recur, concise, and actionable.
1---2name: learning-distill3description: Read a completed temporary session bundle from `.agents/sessions/` and distill durable repo knowledge - descriptive lessons become curated OpenWiki pages, prescriptive agent-behavior lessons stay in `.agents/`. Use only after task-closeout has produced a bundle and when the goal is to separate stable guidance from temporary task notes.4---56# Learning Distill78## Goal910Convert raw task evidence into concise, durable repo knowledge, routed by kind:1112- **Descriptive** (facts, rationale, architecture, troubleshooting patterns, repo decisions) -> OKF pages under the curated wiki trees `openwiki/{decisions,troubleshooting}/` and `openwiki/`.13- **Prescriptive** (agent behavior rules, procedures) -> `.agents/AGENTS.md` or `.agents/playbooks/`.1415Distillation never invokes `openwiki --update`; it authors pages directly and refreshes indexes deterministically.1617## Prerequisites (fail closed)1819Before writing any wiki output, verify all of the following; on failure stop without writing and print the remediation:20211. `openspec` / `openwiki` binaries on PATH:22 `node .agents/skills/aksk-bootstrap/scripts/check_peer_tools.mjs openspec openwiki`232. `openwiki/INSTRUCTIONS.md` exists AND carries the AKSK contract markers24 (`AKSK:WIKI-CONTRACT`). If missing or stub-only, run the attachment:25 `node .agents/skills/aksk-bootstrap/scripts/attach_wiki_contract.mjs`2627## Inputs2829- session bundle directory under `.agents/sessions/`30- `.agents/AGENTS.md`, `.agents/playbooks/`31- `openwiki/INSTRUCTIONS.md` (curation contract: curated trees and rules)32- existing curated pages under `openwiki/`3334Read the canonical task/session identifier from the `task_id` field in the bundle's `summary.json`. Do not infer identity from the session folder name.3536## Skill initialization (before first distillation)3738Run once per target repo after this skill folder is present under `.agents/skills/learning-distill/`. Idempotent.39401. Resolve the repo root (the directory containing `.git/`).412. Ensure `.agents/` exists.423. Ensure `.agents/playbooks/` exists. If `.agents/playbooks/README.md` is missing, copy `bootstrap/playbooks/README.md` into place.434. Ensure `.agents/sessions/` exists. If `.agents/sessions/README.md` is missing, copy `bootstrap/sessions/README.md` into place.445. If `.agents/AGENTS.md` is missing, copy `bootstrap/AGENTS.md` into place. Never overwrite an existing one.456. Ensure `.agents/.gitignore` contains exactly these two lines (merge if absent, do not remove unrelated rules):46 ```gitignore47 sessions/*48 !sessions/README.md49 ```507. Run the aksk-bootstrap peer-tool check and wiki-contract attachment (see Prerequisites) so the wiki side of distillation is ready.5152The kit's durable knowledge base lives in the wiki; this skill no longer seeds any `.agents/docs/` scaffold.5354## Classification categories5556Classify each candidate lesson as one of:5758- ephemeral59- AGENTS guidance60- playbook61- decision record (curated wiki page)62- troubleshooting record (curated wiki page)63- descriptive lesson (any other curated wiki page)6465## Distillation rules6667- Preserve only stable, reusable knowledge. Reject low-confidence or one-off lessons.68- Do not copy task history into `.agents/AGENTS.md`.69- Decision records -> `openwiki/decisions/<slug>.md`; troubleshooting records -> `openwiki/troubleshooting/<slug>.md`; other descriptive lessons -> a topical page under `openwiki/`. The filename stem is the entry identity; keep it unique within its tree.70- Wiki page frontmatter follows OpenWiki OKF (`type`, `title`, `description`, `tags`, `timestamp`) plus AKSK extensions: `aksk_status` (`accepted`, `superseded`, or `provisional`) on decision pages; optional `aksk_superseded_by`; optional `aksk_depends_on` listing qualified slugs (`decisions/<slug>`, `troubleshooting/<slug>`).71- Cross-references between knowledge pages use relative Markdown links; superseded pages point at their successor via `aksk_superseded_by` plus a link.72- **No duplication with OpenSpec:** if a candidate decision restates or overlaps a requirement that already exists in `openspec/specs/`, do not create or extend a wiki page for it; cite the spec capability instead. Wiki pages record facts and rationale; requirements live only in OpenSpec.73- Curated-page preservation: treat trees marked curated in `INSTRUCTIONS.md` as preserve-and-link targets - update AKSK-authored content in place; link generated material to it rather than overwriting it; never drop `aksk_*` frontmatter fields.74- Use `.agents/playbooks/` for durable multi-step procedures; add to `.agents/AGENTS.md` only if the lesson is broad, stable, concise, and actionable.7576## Finding session bundles (gitignore)7778Per-task folders under `.agents/sessions/` are gitignored (only `README.md` is tracked). Many search tools skip ignored paths by default.7980**Do not** conclude there are no bundles based on an ignore-aware search alone. Locate bundles with at least one ignore-blind method: filesystem listing (`ls`, `find`) or ripgrep with `--no-ignore-vcs`.8182Then read each candidate's `summary.json`: treat `task_id` as canonical and filter using distillation state fields (`distilled`, `status`, `distillation_status`). Do not select a bundle from its folder name.8384## Procedure85861. Locate and read the session bundle (see above); read `summary.json` for `task_id`.872. Search related existing knowledge with grep over `openwiki/` (page bodies are plain Markdown) before comparing manually. For decision- or requirement-shaped candidates, also search `openspec/specs/` - a rule already codified as a SHALL requirement there must not be duplicated as a wiki page.883. Compare candidates against existing knowledge; remove duplication.894. Classify each lesson.905. For wiki-bound lessons: load authoring guidance at runtime from the installed package, then author the page directly. With `NPM_ROOT="$(npm root -g)"`:9192 Load upstream authoring guidance (use `init` for new pages, `update` for edits):9394 ```bash95 NPM_ROOT="$(npm root -g)" node --input-type=module -e '96 import { pathToFileURL } from "node:url"; import path from "node:path";97 const m = await import(pathToFileURL(path.join(process.env.NPM_ROOT, "openwiki/dist/agent/prompt.js")).href);98 console.log(m.createSystemPrompt(process.argv[1] ?? "init"));99 ' init100 ```101102 Write the page under the correct curated tree following that guidance and the OKF frontmatter rules above, then validate it:103104 ```bash105 NPM_ROOT="$(npm root -g)" node --input-type=module -e '106 import { readFileSync } from "node:fs";107 import { pathToFileURL } from "node:url"; import path from "node:path";108 const fm = await import(pathToFileURL(path.join(process.env.NPM_ROOT, "openwiki/dist/okf/frontmatter.js")).href);109 const file = process.argv[1];110 console.log(JSON.stringify(fm.validateOkfFrontmatter(readFileSync(file, "utf8"), file)));111 ' openwiki/<path>.md112 ```113114 Fix every reported issue before continuing.1156. Draft minimal updates to `.agents/AGENTS.md` or playbooks for prescriptive lessons.1167. Refresh wiki indexes deterministically (never via the CLI):117 ```bash118 node .agents/skills/aksk-bootstrap/scripts/sync_wiki_indexes.mjs119 ```1208. Mark the session bundle as distilled (its `summary.json` flags).121122There is no activity log to append; accountability lives in the bundle flags and git history.123124## Constraints125126- Do not modify source code outside the knowledge layer.127- Do not invent new repo rules unsupported by task evidence.128- Do not expand `.agents/AGENTS.md` with rationale or narrative.129- Do not copy secrets, private identifiers, personal data, or long raw output into durable docs or wiki pages.130- Never edit OpenWiki-owned files: `index.md` files, run metadata (`.last-update.json`), or anything outside the curated trees except through deterministic index sync.131- Prefer small edits over large rewrites.132133## AGENTS criteria134135A lesson belongs in `.agents/AGENTS.md` only if it is high confidence, broadly useful in this repo, likely to recur, concise, and actionable.