knowledge-compose
Knowledge Compose
Phase 5 of the inverted pipeline. Reads the per-project plan.json + ingest-manifest.json + the populated wiki at <binding.wiki_path>/wiki/, dispatches wiki-composer once, and verifies the output files land on disk.
The default --source web path composes from this run's web-ingested sources (the ingest-manifest.json Phase 4 produced). --source wiki is the wiki-only rung — a full structured, verified report grounded only in the already-populated wiki (wiki/sources/*.md + wiki/syntheses/*.md + distilled pages) and the .cogni-knowledge/fetch-cache/, with no web crawl: it preserves the retired research-report --source wiki capability so that capability does not vanish when cogni-research is archived.
The wiki-only mode does not change the composer or the verify/finalize tail at all. Instead, Step 0 synthesizes an ingest-manifest.json from the bound wiki's wiki/sources/*.md pages — mapping each source to the current plan's sub-questions via the shared wiki-grounding discovery primitive (scripts/wiki-source-manifest.py) — so the dispatched wiki-composer reads a normal manifest and runs byte-for-byte identically whether that manifest came from a web crawl or from the wiki. The composer does not branch on source mode and needs no new input. (See --source in Parameters and the Step 0 pre-flight.)
The composer reads wiki/index.md + selected wiki/sources/*.md (lazily) + prior wiki/syntheses/*.md. Since the distillation interphase (knowledge-distill), it also reads the distilled wiki/{concepts,entities}/*.md pages (topic-matched, lazily) — these serve both as narrative framing and as citable cross-source evidence: when ≥2 sources converge on a fact the distilled page already captures, the composer cites the distilled page itself via its dcl-NNN claim id, so the convergence carries epistemic weight rather than a row of source markers. Distilled pages carry distilled_claims: (not pre_extracted_claims:), and a distilled-page citation is scored by the verifier against that claim's text. Distillation stays optional and fail-soft: when it hasn't run, the composer simply has no distilled pages to draw on and composes from sources + syntheses alone.
The composer also reads the type: question nodes at wiki/questions/*.md (topic-matched, lazily) — first-class wiki pages each recording one research question the base has already explored, with ## Findings [[links]] to the sources that answered it. These serve both as narrative framing and as a citable cross-source answer surface: a question node may carry an answer_claims: block (acl-NNN ids, synthesized by knowledge-distill), and when its backlinks[] list ≥2 distinct sources the composer cites the node directly via its acl-NNN claim — one citation carrying "N sources agree on the answer" — exactly mirroring the distilled-page rule just above. A single-source answer, or a question node with no answer_claims: block yet, stays framing-only: the composer reads it for orientation but cites the backing source page, never the node (an inline citation to a claim-less node would score unsupported). A question-node citation is scored by the verifier against that answer claim's text.
The composer then writes:
<project>/output/draft-v{N}.md— the draft, with clickable numbered[N]inline citations (wikilinks confined to the reference list).<project>/.metadata/citation-records-v{N}.txt— one raw-text record per citation (the composer writes this; it never hand-builds JSON). This skill then runscitation-store.py buildto serialize and validate<project>/.metadata/citation-manifest.json(schema0.1.1, one{id, draft_position, draft_sentence, wiki_slug, claim_id, url}entry per citation). Escaping is owned byjson.dumps, never the LLM — a straight"in adraft_sentencewould otherwise break a hand-built manifest'sjson.loadsand kill the verify phase.
A writer-outline-v{N}.json is persisted by the composer's Phase 1 before any draft Write attempt — this is the outline-recovery contract. If the composer crashes between outlining and drafting, re-running this skill detects the leftover outline and re-dispatches the composer with RESUME_FROM_OUTLINE=true so only Phase 2 runs.