White Paper 2 of 3 — Technical Architecture | MasteryMade / Forge Infrastructure | April 2026

Intelligence Hub: Technical Architecture

How the compilation pipeline works, what it connects to, and how it's built.

Paper Series: Intelligence Hub Architecture

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

System Overview

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.

What Already Exists (80% of the system)

ComponentStatusRole in Intelligence Hub
Knowledge Service (KFS, port 5012)ProductionEntity graph storage — where compiled articles are dual-written
kfs-graphiti (port 5022)ProductionTemporal graph + bridge/gap detection — powers lint checks
Semantic Memory (Supabase)ActiveVector search for Tier 2 retrieval (when we outgrow index)
Claude Code HooksConfiguredSession capture triggers — SessionEnd, PreCompact, SessionStart
LiteLLM (21 models)RunningCheap extraction via Groq Llama 8B
Claude Agent SDKAvailableCompilation 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.

Architecture Diagram

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)

The Four Operations — Technical Detail

1. INGEST: Zero-Effort Capture

Every source has an automatic trigger — no manual step required:

SourceTriggerAdapterOutput
Claude Code sessionsSessionEnd / PreCompact hookssession-flush.pydaily/YYYY-MM-DD.md
Ralph task completionsralph.sh post-task callbackralph-flush.shdaily/YYYY-MM-DD.md
Intel signals (HN, Reddit)Systemd timerintel-adapter.shraw/intel/YYYY-MM-DD.md
Decision logsDaily timer (7 AM CT)decision-adapter.shraw/decisions/YYYY-MM-DD.md
Meeting transcriptsFile drop in inbox/transcript-adapter.shraw/transcripts/name.md
Telegram conversationsCommander post-conversationbot-flush.shdaily/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.

Key Engineering: The Recursion Guard

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.

2. COMPILE: The Core Pipeline

The compiler (compile.py) is the heart of the system. It reads raw sources and transforms them into structured, interlinked knowledge articles.

  1. Reads AGENTS.md (compiler specification — defines article types, quality thresholds, linking rules)
  2. Reads knowledge/index.md (current article catalog)
  3. Reads all existing articles into context (fits at Tier 1 scale, <200 articles)
  4. Reads the new daily log or raw source to compile
  5. Calls Claude Agent SDK with tools (Read, Write, Edit, Glob, Grep)
  6. The LLM directly creates/edits files — concept articles, connection articles, updates to existing articles
  7. After file writes: dual-write to KFS via POST /v1/ingest/event

Four Article Types

TypePurposeExample
ConceptAtomic knowledge unit — what the system knows about a topic"Karpathy LLM Wiki Pattern" — core explanation, key points, related concepts
ConnectionCross-cutting synthesis — non-obvious relationship between concepts"KFS + Compilation = Organizational Brain" — the insight that emerges from linking two concepts
Q&AFiled answers — every question makes the system smarter"How does lint improve agent autonomy?" — answer with citations to concept articles
Project SynthesisCompiled project state from PRDs + decisions + sessions"Intelligence Hub — State Synthesis" — what's built, key decisions, patterns, open questions
Incremental compilation: only sources whose SHA-256 hash changed since last compile get processed. State tracked in scripts/compiler/state.json. The --all flag forces full recompile.

3. QUERY: The Compounding Loop

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.

4. LINT: Self-Correction

#CheckTypeCostSchedule
1Broken wikilinksStructuralFreeDaily
2Orphan articles (no inbound links)StructuralFreeDaily
3Uncompiled sourcesStructuralFreeDaily
4Stale articles (source changed)StructuralFreeDaily
5Missing backlinksStructuralFreeDaily (auto-fix)
6Sparse articles (<200 words)StructuralFreeDaily
7Knowledge gaps (via Graphiti)GraphFreeDaily
8Contradictions across articlesSemantic (LLM)~$0.15Weekly

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.

The Three-Layer System: How It Fits Together

LayerProjectRoleStatus
Storage + QueryKFS StandaloneEntity graph, Graphiti, semantic search, MCP, multi-tenant API80% built
CompilerIntelligence HubRaw → compiled knowledge. Ingest → compile → query → lint0% → building now
ProtocolCollective IntelligenceMulti-agent wiring — every agent feeds into and queries the shared brainDesigned, blocked on compiler

The compiler is the missing middle. It feeds KFS (storage) and enables collective intelligence (protocol). Build one thing, unlock two.

Dual-Write: Filesystem + KFS

Every compiled article exists in TWO places, each optimized for different access patterns:

LocationFormatAccess PatternWho Uses It
knowledge/ (filesystem)Markdown + YAML frontmatter + wikilinksHuman browsing, Obsidian graph view, git versioningJason, Obsidian, git
KFS (Supabase + Graphiti)Entities + episodes + chunks + graph edgesService queries, MCP tools, graph traversal, temporal reasoningRalph, Claude Code, dashboard, MCP clients

Cost Model

ComponentProviderMonthly Cost
Flush (extraction)Groq Llama 8B via LiteLLM~$0.00
CompilationClaude Agent SDK (Max subscription)$0.00 (covered)
QueryClaude Agent SDK (Max subscription)$0.00 (covered)
Lint structuralPython (no LLM)$0.00
Lint semantic (weekly)Groq / Claude~$0.50
KFS dual-writeSupabase (existing)$0.00
Total incremental~$0.50/mo

Scale Path

Scale TierArticlesRetrievalWhen
Tier 1: Index-first0–200LLM reads index.md, picks articlesV1 (now)
Tier 2: Hybrid200–2,000BM25 + pgvector + reciprocal rank fusionWhen index exceeds context window
Tier 3: Full search2,000+Graph traversal + vector retrieval over compiled articlesWhen 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.

Build Phases

PhaseWhatEffort
Phase 1Foundation: directory structure, AGENTS.md, hooks, flush pipeline~2 Ralph-hours
Phase 2Compiler: compile.py + dual-write to KFS~3 Ralph-hours
Phase 3Source adapters + query engine with file-back~2 Ralph-hours
Phase 4Lint engine + systemd timers + Telegram notifications~2 Ralph-hours
Phase 5Agent 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.

Continue Reading

← 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

]]>