White Paper 2 of 3 — Technical Architecture | MasteryMade / Forge Infrastructure | April 2026
How the compilation pipeline works, what it connects to, and how it's built.
Paper 1: Vision & Thesis — Why we're building this, what it unlocks
Paper 2: Technical Architecture (this document) — How it works
Paper 3: The Cascade — Forward-looking effects and standalone service vision
The Intelligence Hub is NOT a new service. It's a compilation pipeline — a set of Python scripts, Claude Code hooks, and source adapters that wire together existing Forge infrastructure. No new databases. No new ports. No new services to maintain.
| Component | Status | Role in Intelligence Hub |
|---|---|---|
| Knowledge Service (KFS, port 5012) | Production | Entity graph storage — where compiled articles are dual-written |
| kfs-graphiti (port 5022) | Production | Temporal graph + bridge/gap detection — powers lint checks |
| Semantic Memory (Supabase) | Active | Vector search for Tier 2 retrieval (when we outgrow index) |
| Claude Code Hooks | Configured | Session capture triggers — SessionEnd, PreCompact, SessionStart |
| LiteLLM (21 models) | Running | Cheap extraction via Groq Llama 8B |
| Claude Agent SDK | Available | Compilation engine — covered by Max subscription |
What's new (20%): Flush pipeline, compile script, source adapters, AGENTS.md schema, lint engine, query engine with file-back.
CAPTURE LAYER (automatic, zero-effort)
Claude Code Hooks Ralph Post-Task Timers
├─ SessionEnd → flush.py ├─ ralph-flush.sh ├─ intel
├─ PreCompact → flush.py └─ writes to daily/ ├─ decisions
└─ SessionStart → inject └─ transcripts
context from index.md
┌─────────────┐ ┌─────────────────┐
│ daily/ │ │ raw/ │ IMMUTABLE
│ session │ │ intel/ │ APPEND-ONLY
│ logs │ │ decisions/ │ SOURCE OF TRUTH
└──────┬──────┘ └────────┬────────┘
│ │
▼ ▼
COMPILATION LAYER (LLM-driven, incremental)
compile.py
├─ Reads: AGENTS.md + existing articles + new sources
├─ Uses: Claude Agent SDK (Max) or Groq (extraction)
├─ Writes: knowledge/ articles + KFS dual-write
└─ State: SHA-256 hashes, incremental only
┌──────────────────────────────────┐
│ knowledge/ │
│ ├─ index.md (master catalog) │
│ ├─ concepts/ (knowledge) │ ──DUAL-WRITE──▶ KFS (5012)
│ ├─ connections/ (synthesis) │ │
│ ├─ qa/ (filed answers) │ ▼
│ └─ projects/ (state) │ Graphiti (5022)
└──────────────────────────────────┘
QUERY + FILE-BACK LAYER
hub-query.sh "question" [--file-back]
├─ Reads index → selects articles → synthesizes answer
└─ With --file-back: creates Q&A article (system gets smarter)
LINT LAYER (daily auto, weekly deep)
lint.py
├─ 6 structural checks (free)
├─ 1 graph check via Graphiti gaps endpoint (free)
└─ 1 semantic check for contradictions (weekly, LLM)
Every source has an automatic trigger — no manual step required:
| Source | Trigger | Adapter | Output |
|---|---|---|---|
| Claude Code sessions | SessionEnd / PreCompact hooks | session-flush.py | daily/YYYY-MM-DD.md |
| Ralph task completions | ralph.sh post-task callback | ralph-flush.sh | daily/YYYY-MM-DD.md |
| Intel signals (HN, Reddit) | Systemd timer | intel-adapter.sh | raw/intel/YYYY-MM-DD.md |
| Decision logs | Daily timer (7 AM CT) | decision-adapter.sh | raw/decisions/YYYY-MM-DD.md |
| Meeting transcripts | File drop in inbox/ | transcript-adapter.sh | raw/transcripts/name.md |
| Telegram conversations | Commander post-conversation | bot-flush.sh | daily/YYYY-MM-DD.md |
All adapters normalize to a common markdown format with YAML frontmatter (source_type, source_id, agent_id, vault_id, timestamp). Downstream, the compiler doesn't know or care where a source came from.
When hooks spawn the flush pipeline (which uses Claude Agent SDK), that would normally fire the hooks again — infinite loop. The fix: CLAUDE_INVOKED_BY=memory_flush environment variable, set at Python import time (before any other imports). Both hooks check this variable and exit immediately if set. This is a proven pattern from cole/memory-compiler.
The compiler (compile.py) is the heart of the system. It reads raw sources and transforms them into structured, interlinked knowledge articles.
AGENTS.md (compiler specification — defines article types, quality thresholds, linking rules)knowledge/index.md (current article catalog)POST /v1/ingest/event| Type | Purpose | Example |
|---|---|---|
| Concept | Atomic knowledge unit — what the system knows about a topic | "Karpathy LLM Wiki Pattern" — core explanation, key points, related concepts |
| Connection | Cross-cutting synthesis — non-obvious relationship between concepts | "KFS + Compilation = Organizational Brain" — the insight that emerges from linking two concepts |
| Q&A | Filed answers — every question makes the system smarter | "How does lint improve agent autonomy?" — answer with citations to concept articles |
| Project Synthesis | Compiled project state from PRDs + decisions + sessions | "Intelligence Hub — State Synthesis" — what's built, key decisions, patterns, open questions |
scripts/compiler/state.json. The --all flag forces full recompile.
Any script, agent, or human can query the compiled knowledge base:
hub-query.sh "What patterns exist in our dashboard builds?" hub-query.sh "What did we decide about auth?" --file-back --json
With --file-back, the answer is saved as a Q&A article in knowledge/qa/, updates the index, and dual-writes to KFS. Every question makes the system smarter. This is the compounding mechanism.
Ralph's session-zero will call hub-query.sh "What do we know about <project>?" before starting any task — giving it compiled context from all prior sessions, decisions, and patterns.
| # | Check | Type | Cost | Schedule |
|---|---|---|---|---|
| 1 | Broken wikilinks | Structural | Free | Daily |
| 2 | Orphan articles (no inbound links) | Structural | Free | Daily |
| 3 | Uncompiled sources | Structural | Free | Daily |
| 4 | Stale articles (source changed) | Structural | Free | Daily |
| 5 | Missing backlinks | Structural | Free | Daily (auto-fix) |
| 6 | Sparse articles (<200 words) | Structural | Free | Daily |
| 7 | Knowledge gaps (via Graphiti) | Graph | Free | Daily |
| 8 | Contradictions across articles | Semantic (LLM) | ~$0.15 | Weekly |
Lint uses Graphiti's existing /v1/expert/*/gaps endpoint for gap detection — the graph finds structural holes that text analysis can't. This is a capability no flat-wiki system has.
| Layer | Project | Role | Status |
|---|---|---|---|
| Storage + Query | KFS Standalone | Entity graph, Graphiti, semantic search, MCP, multi-tenant API | 80% built |
| Compiler | Intelligence Hub | Raw → compiled knowledge. Ingest → compile → query → lint | 0% → building now |
| Protocol | Collective Intelligence | Multi-agent wiring — every agent feeds into and queries the shared brain | Designed, blocked on compiler |
The compiler is the missing middle. It feeds KFS (storage) and enables collective intelligence (protocol). Build one thing, unlock two.
Every compiled article exists in TWO places, each optimized for different access patterns:
| Location | Format | Access Pattern | Who Uses It |
|---|---|---|---|
knowledge/ (filesystem) | Markdown + YAML frontmatter + wikilinks | Human browsing, Obsidian graph view, git versioning | Jason, Obsidian, git |
| KFS (Supabase + Graphiti) | Entities + episodes + chunks + graph edges | Service queries, MCP tools, graph traversal, temporal reasoning | Ralph, Claude Code, dashboard, MCP clients |
| Component | Provider | Monthly Cost |
|---|---|---|
| Flush (extraction) | Groq Llama 8B via LiteLLM | ~$0.00 |
| Compilation | Claude Agent SDK (Max subscription) | $0.00 (covered) |
| Query | Claude Agent SDK (Max subscription) | $0.00 (covered) |
| Lint structural | Python (no LLM) | $0.00 |
| Lint semantic (weekly) | Groq / Claude | ~$0.50 |
| KFS dual-write | Supabase (existing) | $0.00 |
| Total incremental | ~$0.50/mo |
| Scale Tier | Articles | Retrieval | When |
|---|---|---|---|
| Tier 1: Index-first | 0–200 | LLM reads index.md, picks articles | V1 (now) |
| Tier 2: Hybrid | 200–2,000 | BM25 + pgvector + reciprocal rank fusion | When index exceeds context window |
| Tier 3: Full search | 2,000+ | Graph traversal + vector retrieval over compiled articles | When Tier 2 isn't enough |
Tier 2 infrastructure already exists (Supabase pgvector + KFS semantic search). The dual-write means articles already have embeddings. Transitioning is adding a search step, not a migration.
| Phase | What | Effort |
|---|---|---|
| Phase 1 | Foundation: directory structure, AGENTS.md, hooks, flush pipeline | ~2 Ralph-hours |
| Phase 2 | Compiler: compile.py + dual-write to KFS | ~3 Ralph-hours |
| Phase 3 | Source adapters + query engine with file-back | ~2 Ralph-hours |
| Phase 4 | Lint engine + systemd timers + Telegram notifications | ~2 Ralph-hours |
| Phase 5 | Agent wiring: Ralph session-zero, session-exit learnings | ~1 Ralph-hour |
Total: ~10 Ralph-hours. Most of the work is wiring existing infrastructure, not building from scratch.
← Paper 1: Vision & Thesis
Paper 3: The Cascade → — What this unlocks for Jason, Forge, MasteryMade, and as a standalone service
Published by Forge Intelligence Hub project · April 2026 · MasteryMade infrastructure