AI panel chat: codex integration
The AI panel: Chat tab sees your project’s codex the same way it sees the active chapter.
Ambient context
If you have built a project codex (Inspector → Codex → Rebuild), the chat folds a compact summary of it into every reply: the world, factions, cosmology, timeline, glossary, named events, and one-line blurbs per character / location / object. The summary is pinned into the system prefix so it rides along on the prompt cache — no per-message cost on top of what you’d pay anyway.
When the writer asks about a character, location, object, or world fact, the model is told to prefer answering from the codex over reaching for read_file. The codex is the canonical reference for the project.
If no codex has been built yet, the section is omitted entirely — the model sees nothing about the codex, rather than a confusing “empty” world block.
Tools
The chat has four codex tools on top of the existing read / write / edit / mutate surface:
get_codex(scope, kind?, slug?)— read the full structured payload of a codex.scope: "project"returns the project codex;scope: "entity"pluskind+slugreturns a per-character / location / object codex (bible + voice samples + relations + audit log). The model uses this when the ambient summary isn’t enough detail.list_codices()— enumerate every codex on disk. Tells the model whether the project codex has been built and lists every entity codex by slug + name. Useful when the writer asks something open-ended and the model needs to discover what’s reachable before reading.generate_codex(scope, kind?, slug?)— (re)build a codex from project content. Wraps the samebuildProjectCodex/buildEntityCodexpath the Codex inspector’s Rebuild button takes. Expensive: the project codex runs a Sonnet pass over the manuscript + reference material (typically 6-10k output tokens). Always prompts the writer for confirmation before any model call runs — same modal pattern asdelete_files.update_codex(scope, kind?, slug?, note, patch)— record a new fact in a codex via RFC6902 JSON Patch. Same path the narrator’supdate_codextool takes, including the protected-field guard (slug, version, mentions, voice samples, audit log are all off-limits). The change shows in the Codex inspector and the writer can revert it from the Audit tab. No confirmation modal — this is a low-cost append-style edit.
Confirmation modal
generate_codex opens a monastic modal listing the scope (project, or kind + slug). Cancel declines, Rebuild proceeds. Esc declines; Cmd/Ctrl-Enter accepts. Cancelling the chat call also closes the modal — there’s never a button on screen with no recipient.
Cost notes
get_codex,list_codices,update_codex: zero model cost on the dispatch (update_codexdoes land anauditLogentry on disk).generate_codex: full builder cost. The project codex routinely lands 6-10k output tokens on Sonnet; entity rebuilds are cheaper (Haiku world-slice + scan).