Skip to content

Commit 891abd8

Browse files
NikitasT2003claude
andcommitted
feat(wiki): align with full Karpathy LLM Wiki pattern
The previous implementation was a truncated version of the pattern: one-source-one-wiki-page with no entity pages, concept pages, index catalog, or log. That's glorified RAG, not a compounding knowledge base. User pointed at Karpathy's idea file and asked for the real thing. Changes AGENTS.md — rewritten end-to-end * Three layers now named explicitly: raw / wiki / schema * Four page categories: research/wiki/sources/ one per raw file research/wiki/entities/ one per person/method/dataset/concept (accretes across sources) research/wiki/concepts/ higher-level themes research/wiki/queries/ filed-back substantive Q&A * research/wiki/index.md — content-oriented catalog, not chronological * research/wiki/log.md — append-only chronological record with a grep-friendly `## [YYYY-MM-DD] <op> | ...` prefix convention * Citation format unchanged: `[src:<raw_filename>]` * Page template extended with frontmatter + See also + Conflicts * 10 hard rules now include: one ingest touches many pages, use edit_file for in-place updates, reciprocal cross-refs, log every substantive op Skills * wiki-curator/SKILL.md — rewritten. Canonical multi-page ingest flow: source summary → entity pages → concept pages → index.md → log.md → manifest flip. Explicit warning: if you only touched 1-2 pages, you missed the point — redo it. * wiki-linter/SKILL.md — NEW. Wiki health check: unresolved contradictions, stale claims, orphan pages, missing cross-refs, missing entity/concept pages, data gaps, 2-5 suggested follow-up questions. Appends to log.md. * thesis-writer/SKILL.md — updated. Navigation order now index.md → concept → entity → source → raw (drill only when needed). Adds a file-back step: substantive synthesis from a drafting session gets filed to research/wiki/queries/ so the reasoning compounds instead of disappearing into chat. Agent main system prompt * Names the wiki subdirectories explicitly. * Instructs file-back on substantial chat syntheses. * Reinforces edit_file vs write_file (the latter refuses to overwrite by design). CLI * _ensure_workspace: pre-creates sources/ entities/ concepts/ queries/ and seeds research/wiki/index.md + log.md with the expected section headers. First ingest no longer has to mkdir anything or guess at structure. * `thesis curate`: prompt updated — spells out the multi-page invariant and the log prefix format. * `thesis lint`: - no args → wiki-linter (new default) - a file → citation-linter on that chapter - --citations → citation-linter on all chapters (old default) Tests (15 new, 312 total passing) * Schema tests for: - All 6 skills present (was 5) - AGENTS.md declares the 4 page categories - AGENTS.md declares index.md + log.md + grep-friendly prefix - AGENTS.md states the "one ingest, many pages" rule * CLI tests split into three lint paths: - test_lint_defaults_to_wiki_linter - test_lint_specific_file_uses_citation_linter - test_lint_citations_flag_forces_citation_linter * End-to-end scripted-LLM tests: - test_multi_page_ingest_produces_all_categories: the canonical ingest produces pages in all 4 categories + updates index.md + appends log.md + flips manifest. Verifies the file structure at disk level, not just that the agent responded. - test_init_creates_full_wiki_layout: workspace scaffold seeds every wiki subdirectory and the two special files with the right section headers. Ruff clean. Symlink sandbox test still skipped on Windows. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6df7e11 commit 891abd8

9 files changed

Lines changed: 899 additions & 147 deletions

File tree

AGENTS.md

Lines changed: 259 additions & 68 deletions
Large diffs are not rendered by default.

skills/thesis-writer/SKILL.md

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
---
22
name: thesis-writer
33
description: >
4-
Use this skill when the user asks you to draft, write, or expand a thesis
5-
section, chapter, paragraph, or the whole thesis. Enforces the grounding
6-
rule (every factual claim cites an indexed source), loads the user's writing
7-
style from `style/STYLE.md`, navigates the wiki for supporting material, and
8-
writes to `thesis/chapters/<NN>.md` matching `thesis/outline.md` numbering.
4+
Use this skill to draft, write, or expand a thesis section, chapter,
5+
paragraph, or the whole thesis. Enforces the grounding rule (every
6+
factual claim cites an indexed source), loads the user's writing style
7+
from `style/STYLE.md`, navigates the LLM-Wiki-pattern knowledge base
8+
(index.md → concept pages → entity pages → source pages → raw), and
9+
writes to `thesis/chapters/<NN>.md` matching `thesis/outline.md`
10+
numbering. When the drafting surfaced substantive synthesis worth
11+
keeping, also files a query/synthesis page back into the wiki.
912
Triggers "draft", "write section", "expand outline", "write chapter",
1013
"flesh out 2.1", "continue writing".
1114
---
@@ -14,29 +17,66 @@ description: >
1417

1518
## Procedure (non-negotiable order)
1619

17-
1. **Style check.** Read `style/STYLE.md`. If it does not exist, STOP and tell the user: "Run `thesis style` first to compile your writing-style guide from `style/samples/`." Do not draft without a style guide.
20+
1. **Style check.** Read `style/STYLE.md`. If missing, STOP and tell the
21+
user: "Run `thesis style` first to compile your writing-style guide from
22+
`style/samples/`." Do not draft without a style guide.
1823

19-
2. **Outline check.** Read `thesis/outline.md`. Find the section the user asked for. If missing, ask the user to add it to the outline first.
24+
2. **Outline check.** Read `thesis/outline.md`. Locate the requested section.
25+
If absent, ask the user to add it to the outline before drafting.
2026

21-
3. **Wiki navigation.** Read `research/wiki/index.md`. Identify pages relevant to the section (match on tags, entity names, section keywords). Read each relevant wiki page.
27+
3. **Wiki navigation** (do this in order; do NOT jump straight to raw files):
28+
a. Read `research/wiki/index.md` and identify the concept pages relevant
29+
to the section.
30+
b. Read those concept pages. Follow their `See also` links to
31+
entity pages.
32+
c. Read the entity pages. Follow their `See also` links to source-summary
33+
pages where you need the source's exact wording.
34+
d. Drill into `research/raw/<file>.md` ONLY when a source page lacks a
35+
specific detail. Prefer wiki-first.
2236

23-
4. **Drill-down (only if needed).** If a wiki page's summary/key-claims do not cover a point you need, read the corresponding `research/raw/<file>.md` for verbatim context. Prefer wiki-first.
24-
25-
5. **Delegate to drafter.** Hand off to the `drafter` subagent with:
37+
4. **Delegate to the `drafter` subagent** with:
2638
- Section identifier + outline excerpt.
27-
- The list of wiki pages that will ground the draft.
28-
- A reminder to follow `style/STYLE.md`.
39+
- The list of wiki pages (concept → entity → source) you consulted.
40+
- A reminder to follow `style/STYLE.md` exactly.
41+
42+
5. **Drafter writes** to `thesis/chapters/<NN>.md` (where `NN` matches the
43+
outline numbering). If the chapter file already exists, extend it —
44+
use `edit_file`, not `write_file` (which refuses to overwrite).
2945

30-
6. **Drafter writes** `thesis/chapters/<NN>.md` where `NN` matches the outline's numbering (e.g. section 2.1 → chapter 02). If the chapter file already exists, extend it — do not overwrite silently.
46+
6. **Self-lint before returning.** Every paragraph making a factual
47+
statement has at least one `[src:<raw_filename>]`. Transitions and
48+
author commentary without facts are fine.
3149

32-
7. **Self-lint before returning.** Every paragraph with a factual statement has at least one `[src:<filename>]`. Grab-bag transitions without factual content are fine.
50+
7. **File-back check.** If the drafting required non-trivial synthesis —
51+
a cross-source comparison, a new connection, a causal argument the
52+
sources didn't state outright — file that reasoning back into the wiki
53+
as a query/synthesis page:
54+
`research/wiki/queries/<YYYY-MM-DD>-<slug>.md`. Why: the reasoning
55+
compounds if it's in the wiki, but disappears if it's only in a chapter
56+
(where future questions can't reach it easily). Update `index.md` under
57+
Queries and append to `log.md`:
58+
```
59+
## [YYYY-MM-DD] query | wrote section <N.M>
60+
- Filed: [[queries/YYYY-MM-DD-<slug>]]
61+
- Pages read: [[…]], [[…]]
62+
```
63+
For routine drafting that just restates what sources already say, skip
64+
this step.
3365

3466
## Hard rules
35-
- **Never write a factual claim without `[src:<raw_filename>]`.** If wiki + raw don't support it, output "no grounding in indexed sources — add material or remove claim" and stop.
36-
- **Never use pretraining knowledge** for facts, statistics, quotes, author attributions, or dates. The indexed sources are the only truth.
37-
- **Never fabricate** a source filename. Every `[src:X]` must correspond to an actual file under `research/raw/`.
38-
- **Match the style guide**: sentence length, hedging, jargon density, POV, transitions. The drafter should re-read `STYLE.md` before every handoff.
39-
- **Respect write scope**: drafter writes only under `thesis/**`.
67+
- **Never a factual claim without `[src:<raw_filename>]`.** Refuse with
68+
"no grounding in indexed sources — add material or remove claim."
69+
- **No pretraining facts, no web.** The wiki is the truth.
70+
- **Never fabricate** a source filename. Every `[src:X]` corresponds to
71+
an actual file in `research/raw/`.
72+
- **Match `STYLE.md`** — sentence length, hedging, POV, citation placement,
73+
transitions. Re-read it at the start of each drafting turn.
74+
- **Respect scope**: drafter writes only under `thesis/**`; file-back
75+
queries go under `research/wiki/queries/**`.
76+
- **Use `edit_file` to extend** existing chapters. `write_file` refuses
77+
to overwrite.
4078

4179
## Output
42-
After drafting, report to the user: file written, approximate word count, and a 2-line summary of what you drafted. Do not paste the full chapter back into chat unless asked.
80+
Report back: the chapter file written, approximate word count, number of
81+
citations, and (if filed) the query page path. Do not paste the full chapter
82+
into chat unless asked.

skills/wiki-curator/SKILL.md

Lines changed: 97 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,112 @@
11
---
22
name: wiki-curator
33
description: >
4-
Use this skill to build or update the research wiki from newly-ingested raw
5-
sources following the Karpathy LLM Wiki pattern, one page per source file.
6-
Read the template from AGENTS.md and produce `research/wiki/<source_stem>.md`
7-
for every entry in `research/raw/_index.json` with status "pending", update
8-
`research/wiki/index.md`, flag contradictions (flag only, no merging), then
9-
flip status to "curated". Triggers include "curate", "build wiki",
10-
"compile wiki", "update the wiki", "after ingest".
4+
Use this skill to curate newly-ingested raw sources into the LLM Wiki
5+
following AGENTS.md. A single ingest must touch multiple pages —
6+
create/update the source-summary page, every relevant entity page,
7+
every relevant concept page, update `index.md`, append to `log.md`,
8+
flag contradictions, and flip the manifest status. One source typically
9+
touches 5-15 pages. Triggers include "curate", "build wiki",
10+
"compile wiki", "ingest into wiki", "update the wiki", "after ingest".
1111
---
1212

1313
# wiki-curator
1414

1515
## Goal
16-
Turn normalised raw sources into a compound, navigable knowledge base. The wiki is the retrieval layer for thesis writing — quality here determines drafting quality downstream.
16+
Turn normalised raw sources into a persistent, compounding knowledge base
17+
per the Karpathy LLM Wiki pattern. **The knowledge must accumulate across
18+
entity and concept pages — not sit in isolated one-per-source pages.**
1719

18-
## Procedure (follow exactly)
20+
## Procedure (follow for every pending source)
1921

20-
1. Read `research/raw/_index.json`. Collect every entry with `status == "pending"`.
21-
2. For each pending entry, in order:
22-
a. Read the raw normalised markdown at `research/raw/<entry.filename>`.
23-
b. Compose a wiki page at `research/wiki/<entry.filename>.md` (same stem + `.md`), following the template in AGENTS.md verbatim. Required sections: frontmatter (source, title, authors, date, tags), Summary, Key claims, Methods/datasets (if empirical), Key terms, See also, Conflicts.
24-
c. Every claim on the page MUST carry `[src:<entry.orig>]`.
25-
d. Update `research/wiki/index.md`: add a line under the appropriate topic tag cluster pointing to the new page (`- [[<stem>]] — <one-line teaser>`). Create the cluster if it doesn't exist yet.
26-
e. Contradiction check: for each key claim, glob existing `research/wiki/*.md` and check if any previously-curated page asserts a conflicting claim on the same topic. If so, append `- ⚠ conflicts with [[<other_stem>]] on <topic>` to the `Conflicts` section of BOTH pages. Flag only — do not quote sides, do not merge.
27-
f. Update `research/raw/_index.json`: set `entry.status = "curated"` and append `<entry.filename>.md` to `entry.curated_pages`.
28-
3. After all pending entries are processed, write a one-line summary to the user: `curated N sources (M conflicts flagged, K cross-refs added)`.
22+
1. Read `research/raw/_index.json`. Collect entries where `status == "pending"`.
2923

30-
## Tagging guidance
31-
Tags should be short (1-2 words), lowercase, domain-specific. Reuse existing tags from `index.md` when possible; add new ones sparingly. Aim for 3–8 tags per page.
24+
2. For each pending entry, read the raw normalised markdown at
25+
`research/raw/<entry.filename>`.
3226

33-
## Cross-references (`See also`)
34-
Add a cross-reference when two sources discuss the same entity, method, or claim. Cross-references must be reciprocal: edit BOTH pages.
27+
3. **Write the source-summary page** at
28+
`research/wiki/sources/<entry.filename>.md` following the AGENTS.md
29+
page template. Sections: frontmatter, Summary, Key claims, Methods/datasets,
30+
Key terms, See also, Conflicts. Every claim cites `[src:<entry.orig>]`.
31+
32+
4. **Identify entities** in the source: named people, specific methods,
33+
datasets, well-defined concepts, tools, systems. For each:
34+
- Use `read_file` on `research/wiki/entities/<slug>.md` (via `ls` first to
35+
check existence).
36+
- If the page exists, **extend it**: use `edit_file` to append new claims
37+
from this source, each carrying `[src:<entry.orig>]`. Add a reciprocal
38+
`See also: [[sources/<entry.filename>]]` link.
39+
- If it doesn't exist, **create it** with the new claims as seed content.
40+
Include a `See also: [[sources/<entry.filename>]]` link back.
41+
42+
5. **Identify major themes/concepts** the source touches (usually 2-5).
43+
For each, same pattern as entities but under
44+
`research/wiki/concepts/<slug>.md`.
45+
46+
6. **Update `research/wiki/index.md`**:
47+
- Add the new source under its topic cluster.
48+
- List any new entity pages under `## Entities`.
49+
- List any new concept pages under `## Concepts`.
50+
- Preserve existing entries. Use `edit_file`.
51+
52+
7. **Check for contradictions**: for each new claim, glob existing
53+
entity/concept pages and `grep` for conflicting claims on the same topic.
54+
On match, add `⚠ conflicts with [[<other>]] on <topic>` to the `Conflicts`
55+
section of **both** pages. **Flag only** — do not quote both sides, do not
56+
merge.
57+
58+
8. **Append to `research/wiki/log.md`** using the exact grep-friendly prefix:
59+
```
60+
## [YYYY-MM-DD] ingest | <Source Title>
61+
- New pages: [[sources/…]], [[entities/…]], [[concepts/…]]
62+
- Updated pages: [[entities/…]] (+N claims), …
63+
- Conflicts flagged: N
64+
```
65+
Use `edit_file` to append (read current log, add new entry at the end).
66+
67+
9. **Flip manifest status**: `edit_file` on `research/raw/_index.json` to
68+
change `"status": "pending"` to `"status": "curated"` for the entry, and
69+
populate `curated_pages` with the list of wiki pages you touched for that
70+
source.
71+
72+
10. After all pending entries processed, report:
73+
`curated N sources, touched M pages, flagged K conflicts, suggested J questions`.
74+
75+
## What a good ingest looks like
76+
77+
For a single paper on, say, "attention mechanisms in transformers":
78+
- 1 source page: `sources/attention-is-all-you-need.pdf.md`
79+
- 3-5 entity pages (created or updated): `entities/transformer-architecture.md`,
80+
`entities/self-attention.md`, `entities/multi-head-attention.md`,
81+
`entities/vaswani.md` (author), `entities/machine-translation.md`
82+
- 1-2 concept pages: `concepts/attention-mechanisms.md`,
83+
`concepts/sequence-to-sequence-models.md`
84+
- `index.md` (updated)
85+
- `log.md` (appended)
86+
87+
**Total: 7-10 pages touched.** If you only wrote 1-2 pages, you're not
88+
building a wiki — you're making isolated summaries.
89+
90+
## Slug convention (AGENTS.md §Slug)
91+
92+
`<lowercase-kebab-case>`, under 60 chars, strip punctuation. Examples:
93+
- "Self-Supervised Learning" → `self-supervised-learning`
94+
- "GPT-4" → `gpt-4`
3595

3696
## What NOT to do
37-
- Do NOT write to `research/raw/**`. Those files are immutable.
38-
- Do NOT merge conflicting pages. Flag and move on; the user resolves.
97+
98+
- Do NOT write to `research/raw/**` (sources are immutable). The exception is
99+
updating `research/raw/_index.json` via `edit_file`.
100+
- Do NOT use `write_file` to overwrite an existing wiki page. It will refuse.
101+
Use `edit_file` for in-place updates.
102+
- Do NOT merge conflicting claims. Flag on both pages and move on.
39103
- Do NOT invent authors, dates, or tags not supported by the source.
40-
- Do NOT skip the status flip — the manifest is how the user knows curation is done.
104+
- Do NOT stop after the source page. The value of this pattern is that
105+
entity and concept pages compound — that's what the wiki is for.
106+
- Do NOT skip the `log.md` append. Every ingest must leave a chronological
107+
trace.
108+
109+
## Reciprocal cross-refs
110+
111+
When you add `See also: [[X]]` on page A, also add `See also: [[A]]` on page
112+
X. Use `edit_file` on both. This is not optional — the graph breaks otherwise.

skills/wiki-linter/SKILL.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
name: wiki-linter
3+
description: >
4+
Use this skill to health-check the LLM Wiki under `research/wiki/`.
5+
Scans every page and reports: unresolved contradictions, stale claims
6+
newer sources contradict, orphan pages with no inbound links, pages
7+
that reference an entity without linking its page, entities/concepts
8+
mentioned in source summaries but lacking their own page, thinly-covered
9+
topics that would benefit from more sources, and 2-5 suggested follow-up
10+
questions. Appends a `lint` entry to `log.md`. Triggers include
11+
"lint wiki", "check wiki", "wiki health", "audit the wiki",
12+
"review the knowledge base", "find orphans", "find gaps".
13+
---
14+
15+
# wiki-linter
16+
17+
## Goal
18+
Keep the wiki healthy as it grows. Humans give up on wikis because the
19+
maintenance burden outpaces the value. Your job is to keep that burden near
20+
zero by catching the things that silently break a compound knowledge base:
21+
orphan pages, stale claims, broken cross-refs, data gaps.
22+
23+
## Procedure
24+
25+
1. Read `research/wiki/index.md` and `research/wiki/log.md` to orient.
26+
27+
2. Enumerate pages: `glob("research/wiki/**/*.md")`.
28+
29+
3. For each category below, scan + build a list of issues. Numbered, so the
30+
user can act on them one at a time.
31+
32+
### Contradictions (unresolved)
33+
Glob for `⚠ conflicts with` markers. Report file + line + the conflicting
34+
pages. **Do not resolve** — surface them for the user to decide.
35+
36+
### Stale claims
37+
An entity page may assert claim X from source A, and a later source B may
38+
contradict it. If neither page flagged the conflict, the old claim is stale.
39+
Strategy: read each entity page's `Key claims` section; for each claim, grep
40+
other pages that cite the same topic; if wording clearly disagrees, flag
41+
`⚠ possibly stale` on the older claim (and record both pages in the report).
42+
43+
### Orphan pages
44+
A page is an orphan if no other page links to it via `[[...]]`. Expected
45+
orphans: `index.md`, `log.md`. Everything else should have at least one
46+
inbound link. Report orphan slugs + suggest where they should be linked from
47+
(usually `index.md` or the concept page closest to their topic).
48+
49+
### Missing cross-references
50+
If page A mentions entity E (by name) but doesn't link `[[entities/<e-slug>]]`,
51+
flag it. Heuristic: for each entity page, grep wiki for its title (and common
52+
aliases listed in frontmatter); any hit without a `[[...]]` link is a missing
53+
cross-ref.
54+
55+
### Missing entity / concept pages
56+
Scan source-summary pages for capitalized named entities and key terms listed
57+
in their `Key terms` section. For each, check if an entity page exists. If
58+
not, flag `missing entity page: <name>` and suggest the slug.
59+
60+
### Data gaps (thinly covered topics)
61+
Count how many sources each entity / concept page cites. Flag any
62+
entity/concept page with fewer than 2 citing sources as a potential data
63+
gap — the user may want to find more reading on it. Report the slug and the
64+
current citation count.
65+
66+
### Suggested follow-up questions
67+
End the report with 2-5 questions the user could ask next, generated from
68+
the wiki's current shape. Good questions:
69+
- Point at thinly-covered topics: "What does the literature say about X?"
70+
- Point at unresolved contradictions: "Which view of Y seems better
71+
supported — the one in [[entities/a]] or [[entities/b]]?"
72+
- Point at synthesis gaps: "How do [[concepts/p]] and [[concepts/q]]
73+
relate, given the sources cover them separately?"
74+
Bad questions: vague prompts, anything generic that ignores the wiki's
75+
content.
76+
77+
4. Output a grouped report like:
78+
79+
```
80+
Wiki health report — N pages scanned
81+
82+
== Contradictions (unresolved) ==
83+
1. [[entities/transformer]] ⚠ conflicts with [[entities/rnn]] on vanishing
84+
gradients (line 42 + line 37). Consider: add a short comparison section
85+
to [[concepts/sequence-modelling]] and note the trade-off.
86+
87+
== Orphan pages ==
88+
2. [[entities/gpt-2]] — no inbound links. Suggested: add to index.md under
89+
"Entities > Models" and reference from [[concepts/pretraining]].
90+
91+
== Missing cross-references ==
92+
3. [[sources/attention-is-all-you-need]] mentions "Transformer" without a
93+
link to [[entities/transformer]] (line 18).
94+
95+
== Missing entity pages ==
96+
4. "Adam optimizer" appears in 3 source summaries with no entity page.
97+
Suggested slug: entities/adam-optimizer.
98+
99+
== Data gaps ==
100+
5. [[entities/layer-normalization]] cites only 1 source. Consider reading
101+
more on this.
102+
103+
== Follow-up questions you might ask ==
104+
- How does [[entities/adam-optimizer]] compare to SGD across the sources
105+
that cover both?
106+
- Why does [[concepts/attention-mechanisms]] cite 8 sources but
107+
[[concepts/positional-encoding]] only 2 — is that a real gap in the
108+
literature or a gap in your reading?
109+
```
110+
111+
5. **Append a log entry** to `research/wiki/log.md`:
112+
```
113+
## [YYYY-MM-DD] lint | pass <n>
114+
- Contradictions: <count>
115+
- Orphans: <count>
116+
- Missing xrefs: <count>
117+
- Missing pages: <count>
118+
- Data gaps: <count>
119+
- Questions suggested: <count>
120+
```
121+
122+
## What NOT to do
123+
- Do NOT auto-fix. Offer; the user decides.
124+
- Do NOT run web searches — you have no web tool. Suggest where one could
125+
help; the user can do it manually.
126+
- Do NOT write to `research/raw/**` or `data/**`.
127+
- Do NOT mark EVERY claim `⚠ possibly stale` — only those you're confident
128+
a newer source contradicts. False positives train the user to ignore you.

0 commit comments

Comments
 (0)