feat(F-12): wiki-compile — grounded concept pages over RAG substrate #2

Merged
user2595 merged 7 commits from feat/F-12-wiki-compile into main 2026-06-14 05:58:25 +00:00
Owner

Summary

  • codex/wiki.py (~680 Zeilen): Concept, Claim, ConceptPage, CompileReport Dataclasses; OllamaClient; load_concepts(); compile_concept() (Retrieval → LLM-Synthese → Grounding-Guard → Cross-Refs); compile_all() (inkrementell via SHA-256 Hash); write_index(); append_log()
  • wiki/concepts.yaml: 5 kuratierte Konzept-Seeds (discrete-conformal-map, circle-packing, lobachevsky-function, discrete-yamabe-flow, hyperideal-tetrahedron)
  • codex/cli.py: wiki_app Sub-Typer (codex wiki compile/list/check)
  • codex/config.py: wiki_dir, wiki_llm_model, wiki_llm_url, wiki_top_k
  • tests/wiki/: 39 Tests (test_concepts.py, test_compile.py, test_check.py) — DB + LLM gemockt

Requirements

R-21 R-22 R-23 R-24 R-25 R-26 → done; R-27 → pending (Gate-Fix-Session)

Test plan

  • uv run pytest tests/ -q — 127 passed, 0 failed
  • uv run ruff check . — clean
  • uv run mypy codex/ — clean (18 files, strict)
  • Review-Gate (Opus, kalt) — FAIL: Grounding-Guard bypassbar, keine Quarantäne, R-27-ADR fehlt → Gate-Fixes in Folge-PR (session-prompts/F-12-gate-fixes.md)

Nicht mergen bis Gate-Fix-Session abgeschlossen + erneutes Review-Gate PASS.

🤖 Generated with Claude Code

## Summary - `codex/wiki.py` (~680 Zeilen): `Concept`, `Claim`, `ConceptPage`, `CompileReport` Dataclasses; `OllamaClient`; `load_concepts()`; `compile_concept()` (Retrieval → LLM-Synthese → Grounding-Guard → Cross-Refs); `compile_all()` (inkrementell via SHA-256 Hash); `write_index()`; `append_log()` - `wiki/concepts.yaml`: 5 kuratierte Konzept-Seeds (discrete-conformal-map, circle-packing, lobachevsky-function, discrete-yamabe-flow, hyperideal-tetrahedron) - `codex/cli.py`: `wiki_app` Sub-Typer (`codex wiki compile/list/check`) - `codex/config.py`: `wiki_dir`, `wiki_llm_model`, `wiki_llm_url`, `wiki_top_k` - `tests/wiki/`: 39 Tests (test_concepts.py, test_compile.py, test_check.py) — DB + LLM gemockt ## Requirements R-21 R-22 R-23 R-24 R-25 R-26 → done; R-27 → pending (Gate-Fix-Session) ## Test plan - [x] `uv run pytest tests/ -q` — 127 passed, 0 failed - [x] `uv run ruff check .` — clean - [x] `uv run mypy codex/` — clean (18 files, strict) - [ ] Review-Gate (Opus, kalt) — **FAIL**: Grounding-Guard bypassbar, keine Quarantäne, R-27-ADR fehlt → Gate-Fixes in Folge-PR (`session-prompts/F-12-gate-fixes.md`) ⚠ **Nicht mergen** bis Gate-Fix-Session abgeschlossen + erneutes Review-Gate PASS. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
user2595 added 4 commits 2026-06-14 01:45:20 +00:00
Documents the Nougat HTTP server endpoint. Resolves D-02 drift finding.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds wiki/concepts.yaml (5 curated seeds: discrete-conformal-map,
circle-packing, lobachevsky-function, discrete-yamabe-flow,
hyperideal-tetrahedron) and codex/wiki.py with full load_concepts()
implementation (Concept dataclass, YAML parser, graceful empty list).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds codex wiki compile/list/check Typer subgroup to cli.py.
Adds wiki_dir, wiki_llm_model, wiki_llm_url, wiki_top_k settings
to config.py (F-12 section only).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cli.py and config.py were accidentally contaminated with uncommitted F-09
changes (search_app restructure, rich ingest, mathpix/figures settings).
This restores both files to main-baseline + F-12-only additions:
- cli.py: wiki_app group (compile/list/check), restore @app.command search
- config.py: wiki_dir, wiki_llm_model, wiki_llm_url, wiki_top_k only

All 127 tests green, ruff+mypy clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
user2595 added 7 commits 2026-06-14 03:11:41 +00:00
Wrap llm.generate() in compile_concept with a broad try/except;
log a warning and return an empty ConceptPage (no crash) when the
LLM endpoint is unreachable. Add logging module import.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
_parse_claims now skips matches where bibkey contains spaces or starts
with "http", preventing Markdown hyperlinks like [text](https://...) from
being misidentified as citations. Add two tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
compile_concept now accepts chunks as a positional parameter; compile_all
retrieves chunks once and passes them directly, avoiding double-retrieve.
Also separates all_concepts (full list) from compile_concepts (filtered),
so cross-ref injection always uses the complete concept list regardless of
--concept filter (Fix 6 + Fix 8).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
_inject_cross_refs temporarily replaces backtick spans with null-byte
placeholders before injecting [[slug]] cross-refs, then restores them.
This prevents concept titles inside `code` from being rewritten.
Add tests for inline-code protection and full-list cross-ref injection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add _detect_conflicts() using adversative keyword heuristic (but,
however, in contrast, …) between chunks of different bibkeys; results
populate CompileReport.conflicts and appear in wiki/log.md.
Also add CompileReport.quarantined field (used by Fix 2).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace 3-gram substring match with:
- _last_sentence(): only the last sentence before a citation is checked
  (prevents a hallucinated paragraph grounding via a phrase at its end)
- _content_words(): stopwords removed from both claim and chunk before
  n-gram comparison (prevents bypass via "the discrete conformal map")
- Content-5-gram: require 5 consecutive non-stopword tokens from last
  sentence to appear in the chunk's content-word stream
- Claims with <5 content words in last sentence → ungrounded by default

Add adversarial tests: stopword-3-gram bypass → grounded=False;
legitimate content-5-gram → grounded=True.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Document Spike result (grounding ~0.95, hallucination ≤5% on 3 concepts),
content-5-gram guard design, quarantine mechanism, LLM graceful degradation,
cross-ref injection rules, and conflict detection MVP.
R-27 satisfied.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
user2595 merged commit 967e6baa59 into main 2026-06-14 05:58:25 +00:00
user2595 deleted branch feat/F-12-wiki-compile 2026-06-14 05:58:25 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: user2595/codex-py#2
No description provided.