# LLM Wikis

akm supports [Andrej Karpathy's LLM
Wiki](https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f)
pattern: a markdown-based knowledge base that an LLM agent maintains
together with a human, on a filesystem it can read and write directly,
with no special SDK.

An LLM wiki is a bundle format, not an asset type: the LLM Wiki adapter
recognizes it, and there is no `akm wiki` command.

## The design

A wiki is a directory. Full stop.

```
<wiki-root>/
  schema.md                  rulebook the agent reads first
  index.md                   catalog of pages, regenerable
  log.md                     append-only activity log
  raw/                       immutable ingested sources (never edit)
  pages/<page>.md            agent-authored pages
  pages/<topic>/<page>.md    optional nesting
```

Three layers, from Karpathy's gist:

- **Raw sources** (`raw/`) — what you ingest. Articles, papers,
  transcripts, notes. Immutable.
- **Wiki pages** (`pages/<page>.md`, optionally nested) — what the agent
  writes. Summaries, entity pages, concept pages, FAQs. Cross-referenced
  via `xrefs:` frontmatter; provenance recorded via `sources:`
  frontmatter pointing at the cited raw files.
- **Schema** (`schema.md`) — the per-wiki configuration: voice, page
  kinds, contradiction policy, any conventions the agent should follow.
  akm never touches it.

### Principle — akm surfaces, the agent writes

Karpathy's workflow is a conversation between a human, an agent, and a
filesystem. akm is not that agent. Page writes — create, append, xref,
log — all use the agent's native `Read` / `Write` / `Edit` tools. akm's
job is recognition and discovery: it mounts the wiki, indexes the pages,
and makes them searchable alongside every other asset.

## How akm sees a wiki

The LLM Wiki adapter recognizes a wiki when the bundle is added: a bundle
whose root holds a `schema.md` plus a `pages/` directory is mounted
with the `llm-wiki` adapter. From there:

- `pages/**.md` are indexed as searchable documents; each page's ref is
  `bundle//conceptId`, where the conceptId is the root-relative path
  minus `.md` (a page at `pages/attention.md` in bundle `research-wiki`
  is `research-wiki//pages/attention`). A page's type is its `pageKind:`
  frontmatter value, `note` when it has none (`akm search --type note`).
- `raw/**.md` **are** indexed — as first-class, addressable, searchable
  `wiki-source` documents (a ref looks like
  `bundle//raw/<slug>`), so citations resolve and raw content is
  discoverable by search too.
- `schema.md`, `index.md`, and `log.md` are structural and are never
  indexed as a concept.
- `xrefs:` frontmatter becomes cross-reference edges; `sources:`
  frontmatter becomes citation edges back to raw files.

A wiki is always its own bundle: configure it as one (`adapter: llm-wiki`, or let akm detect it from its `schema.md`
plus `pages/`). A wiki folder inside an ordinary akm bundle (for example `wikis/articles/`) gets no wiki handling from
the akm adapter: its files are plain akm files, typed by akm's path rules (Markdown there is `knowledge`).
To have it indexed as a wiki, move the folder out of the akm bundle and add it as a bundle of its own. Do not add the
folder in place as a nested bundle: bundles whose directories overlap share files, `akm bundle add` refuses it, and
`akm doctor` warns (`bundle-shared-path`) about a pair that was configured before.

## Working with a wiki

```sh
akm bundle add github:team/research-wiki        # install a wiki bundle (or point at a local dir)
akm search "attention"                   # pages rank alongside all other indexed content
akm show research-wiki//pages/attention  # read a page by ref
akm show research-wiki//pages/attention#history
```

To build a new wiki, create the directory shape above by hand (or have
your agent do it — `schema.md` plus an empty `pages/` is enough for
recognition), then add it as a bundle. Ingesting raw sources, writing
pages, and maintaining `index.md`/`log.md` are the agent's job, guided
by `schema.md`.
