๐Ÿค– AGENTS.md

The contract for agents (and anyone else) using this pipeline to draft content. A draft here is co-authored: the human curates the corpus, sets the scope and steers; the agent retrieves, writes grounded prose, and records the judgement behind it. This file is the agent's half of that bargain.

Changing chitragupta's own code, rather than drafting with it? Read DEVELOPER-AGENTS.md first; it governs. (It exists in a git checkout only, because chitragupta init deliberately does not scaffold it; see CLAUDE.md's routing table.) Test policy, the local check suite, environment constraints, code standards, and commit/PR/release conventions all live there.

CLAUDE.md is the one-screen router between the two, for an agent that has not yet worked out which task it is on.

SOUL.md explains on one page the reasons behind everything below. When this file and that one seem to disagree, that one is the tie-breaker.

Every artefact shape this file names (a dossier, a review report, a gate-passed draft, a signed spec) exists as a real, committed example under docs/examples/sample-project/, produced by running the real pipeline over five sample papers. docs/examples/README.md is the map. When in doubt about what a file should look like, look there before inventing a shape.

๐Ÿ”‘ The hard invariant: never fabricate a citekey

Fabricated placeholder references have made it into real papers before. This pipeline is built to prevent that failure, which is why this is the one rule that cannot bend. SOUL.md states the invariant itself. In a conventional retrieval pipeline the model is asked not to invent a reference; here, nothing you generate can reach a rendered document without passing a check you cannot talk your way past.

Rule: a citekey may only be used if it appears in papers/bibliography.bib (the source of truth; see below), was picked up into content/ledger.sqlite by python -m chitragupta.corpus sync, and its PDF parsed (ledger status parsed). An entry with no PDF, such as a web page, is in the .bib, but nothing in the corpus can ground a claim on it: the gate fails it and retrieval never offers it.

A citation is always a marker: [@key], or \citep{key} in a .tex fragment. Citations render in IEEE style, so a paper used as a noun is still the marker: "In [@key], the authors ..." renders as "In [3], the authors ...". Never write the key itself in prose or in a code span: it prints raw, and no reader can resolve it (draft style reports it as BareCitekey). A remark about the corpus itself, a duplicate entry for instance, belongs in the dossier's revisions.md, never in the draft.

All six genre skills (survey-writer, thesis-chapter-writer, textbook-chapter-writer, tutorial-writer, deep-research, review-digest) must run python -m chitragupta.draft gate <file> on its own output and only present the draft once it exits 0. So must book-assembler, which writes no prose but does write a document: the LaTeX book it composes is a new file, and this layer has one exit whatever produced the file. This is a gate, not a lint suggestion: treat a FAIL the same way you'd treat a failing test. It binds the two teaching genres too, where citations are optional: a draft that cites nothing passes trivially, but a draft that cites anything must pass on merit.

Each harness has its own copy of every skill's SKILL.md, naming its own tools: .claude/skills/ for Claude Code, .agents/skills/ for Codex, and .opencode/skills/ for OpenCode, where the names carry an -opencode suffix (survey-writer-opencode, draft-reviser-opencode, ...). Use the copy your harness offers. A skill's reference files exist once, under .claude/skills/<name>/references/ and .claude/skills-common/references/, and every copy names them by their path from the project root: when a step says to read one, read it before you carry on. docs/HARNESS.md explains the layout.

A hook (.claude/hooks/citation_gate_hook.py) also enforces this mechanically: any write under content/drafts/*.md or *.tex runs the gate automatically and surfaces a blocking FAIL naming the offending citekey(s) if it doesn't pass. The same script runs on every supported harness: on Claude Code's Write/Edit (.claude/settings.json), on Codex's apply_patch (.codex/hooks.json, once you have trusted the project's hooks), and on OpenCode's file tools (its plugin in .opencode/); docs/HARNESS.md has what each one enforces. It fires after the write lands: the file exists, with the bad citekey in it, until the FAIL is fixed. The block stops the agent continuing as though the draft were sound; it does not stop the bytes reaching disk, and a draft abandoned at that point stays wrong on disk. The hook backs up the instruction above and does not replace it. Still run the gate by hand before calling a draft done, since the hook only fires on the tool call that wrote the file, not on demand. A write through a shell command is seen by no hook; the gate you run by hand warns when a draft changed with no hook checking it, and draft render refuses a draft the gate rejects, in every format.

The gate proves every citekey is real. Whether each cited paper supports its sentence is a different question, answered by the review layer below, advisorily and never as a block.

๐Ÿงผ Start each draft in a clean session

Begin a draft in a fresh session: /clear in Claude Code, or a new conversation in whatever agent you use. A fresh session closes the one failure the gate above cannot see.

The gate is mechanical and complete for what it measures. A citekey is in the ledger or it is not, so a fabricated one is caught every time. What it cannot catch is a real citekey (present in content/ledger.sqlite, correctly spelled, genuinely parsed from a genuine PDF) that an earlier task in the same session left sitting in context, and that then gets cited for a claim it does not support. Every deterministic check in this pipeline passes that draft. python -m chitragupta.draft gate passes it, the PostToolUse hook passes it, and python -m chitragupta.review verbatim scan is looking for something else entirely. Nothing anywhere detects it, which is why the remedy is a procedure and not another check.

Framing travels the same way. A session that spent an hour on one topic carries its vocabulary, its emphases and its sense of what matters, and the next draft inherits all three without anyone having chosen them.

Clearing is cheap here by design: it is what content/dossiers/ is for. The reader, the scope, the glossary, the kept evidence, the rejected candidates and the steering already given live on disk, not in the conversation, so a fresh session picks a draft back up by reading them. docs/DRAFT-ITERATION.md describes that design, and it and this guidance support each other.

One thing to do before clearing mid-work: get this session's steering into steering.md first. draft-reviser reads chat steering from the dossier, so steering that was only ever said dies with the session.

๐Ÿ“š The bib file is the source of truth (not this pipeline)

papers/bibliography.bib (path configurable via config.toml's [bib].path or the BIB_FILE env var; gitignored, per-host data; see docs/CONFIG.md) is a manual export from your reference manager's BibTeX export feature. No auto-sync plugin is installed, so it is not continuously auto-synced. Whatever citekey BibTeX assigns there (e.g. talasila_composable_2025, or noauthor_digital_nodate for an item with no discoverable author) is the citekey everywhere downstream. chitragupta/core/corpus/bib_reader.py parses it and is the only place that reads it; nothing else should ever generate or guess a citekey.

One constraint follows from that, enforced in bib_reader.citekey_problem(): a citekey is also a filename stem (content/parsed/<citekey>.txt, its .passages.json sidecar, the enrichment layer's content/docling/<citekey>.md), so it has to be usable as one. A citekey containing a path separator, a character Windows forbids, or a reserved device name is skipped with a warning naming it instead of being sanitised. This project never rewrites a citekey, so the only fix is to rename it in the reference manager and re-export. Skipping loses one paper and says so; letting it through would write outside content/.

That rule is why a module needing bibliographic detail reads it back out of the ledger rather than re-opening the bib file.

Adding or removing a paper is the user's job, not a skill's: change it in the reference manager, re-export, re-run python -m chitragupta.corpus sync. There is no watch/auto-export step. Removal is deliberately opt-in: sync only reports a citekey that has dropped out of the bib file until it is re-run with --remove-stale, because a short export is more often a botched one than an intentional deletion. README.md and docs/ZOTERO.md have the full semantics.

๐Ÿ— The four layers

The numbers below are the order these are introduced, and the order you meet them: you need a corpus before a draft, and there is nothing to review until a draft exists. They are not a dependency rank: the enrichment layer is optional and nothing above it needs it.

๐Ÿ”Ž Retrieval

chitragupta/core/draft/retrieval.py (BM25 over a cached term-frequency index, stdlib-only, no venv or model download needed) is what the genre skills use by default. chitragupta/core/corpus/enrich/embed_index.py (sentence-transformers + Chroma) is a working upgrade path with a matching search(query, k) shape, to swap in when BM25 stops being enough. That is a judgement call, not a corpus-size threshold. docs/RETRIEVAL.md has the caching mechanics and the choose-between-them guidance.

Retrieval finds a document; chitragupta/core/draft/passages.py decides which part of it may be shown. Anything that needs to point at a span of a source instead of the whole of it (citation_provenance, verbatim_check, the enrichment layer) goes through that one ladder instead of re-deriving passages, so a caller cannot accidentally quote from a rung that isn't quotable. See docs/LADDERS.md.

Log what you retrieve: python -m chitragupta.draft retrieve search "<query>" --log <draft> appends the call to the dossier's retrieval.md. That log lets the dossier's drift report say, months later, which new papers the draft's own queries would surface today.

โš™ Config lives in config.toml

Every setting lives in config.toml at the repo root, and every one is overridable by an env var of the same name (e.g. BIB_FILE=/other/path.bib python -m chitragupta.corpus sync). docs/CONFIG.md is the reference.

python -m chitragupta.draft gate needs no venv: it only reads content/ledger.sqlite through stdlib sqlite3 and runs with bare python. python -m chitragupta.corpus sync does need the venv, and must be run through the installed one rather than the bare system interpreter.