Architecture

A layered climb up the DIKW pyramid — raw code and conversations at the base, synthesized wisdom at the top — across three databases and one runtime contract. Syntax is deterministic. Meaning is agent-driven. Every claim carries its grounding.

on this page

Layered model

The layers climb the DIKW pyramid: Data (L0–L1) → Information (L1.5–L2) → Knowledge (L2.5–L5) → Wisdom (L6). Each layer has its own SQLite table family; edges cross layers explicitly via foreign keys.

LayerContentProduced by
L0 Code structuresymbols, calls, imports, fields, SQL tablesdeterministic (tree-sitter / regex DDL)
L0.5 Code analysisper-file summaries, architectural layer, tagsstructure + agents (FileAnalyzer · ArchitectureAnalyzer)
L1 Conversations + docs + diagramssessions, turns, tool calls; in-repo docs (README / BRD / ADRs) and diagrams (mermaid / drawio / excalidraw / plantuml)deterministic (file parsers + adapters)
L1.5 Triagerelevance / domain / quality / linkage / activity per window; doc-kind for sourcesagents (Triage · SourceClassifier)
L2 Factsdecisions, business rules, intents, problems/solutions; BRD actors/processes/metrics; incidents → root cause → resolutionagents (Decision · BusinessLogic · Requirements · Intent · ProblemSolution · Incident) + syntax pass
L2.5 Domain enrichmentdependencies, skills, entities, relationships, industry, components, gaps; cross-source dedup + corroborationmanifests + SQL · Reconciler · standard: fused enrich (domainFuser + industryFuser) · deep: 8-agent stack
L2.6 Knowledge zonesbusiness + tech domains, grouping facts by bounded context / capabilityagents (BusinessDomainModeler · TechDomainModeler)
L3 Conceptsclustered facts with names + structured summaries, scope-taggedagents (Clusterer · Summarizer)
L4 Cross-projectshared concepts, workspace umbrellas, emergent project linksmechanical (exact + SimHash) + agent (Linker)
L5 Skill graph + hierarchytechnical + industry skills; the workspace → industry → business → tech → project treemechanical aggregation over L2.5/L2.6 evidence
L6 Wisdomleveled competency areas (Dreyfus novice → expert), cross-project insights / principles, named gaps + recommendationsagent (WisdomSynthesizer) + deterministic fallback; grounded model

Scope × grounding

Two tags on every knowledge node keep objective fact separate from inference. They are the mechanism behind "based on facts, never assume."

scope — technical (architecture) · industry (business domain) · meta.

groundingmeaningsource
structuralobjective, parsed from artifactscode symbols, SQL schema, manifests
statedasserted in a conversationextracted facts
corroboratedstated and matched to a code entitythe Reconciler
externalcited from outside the projectresearch backend (opt-in)
modelthe agent's own inferenceenrichment agents

Project-truth queries default to structural / stated / corroborated. external and model are opt-in and always filterable, so "fill the gap" knowledge never gets mistaken for what your project actually does. subnet status breaks every layer down by both scope and grounding.

Pipeline

Each ingest run pulls new turns, segments them into windows, and routes each window through mechanical cleaning before any classification LLM: session filter → turn normalize → window briefs → pre-triage embed dedupe → triage on briefs → extract with anchor gate → early fact dedupe → batch clusterer → tiered file analyze → fused or deep enrich. See workflow-refactor.md.

Cross-project work runs on top of that, over global.db: the Linker and mechanical matching build L4/L5, then two L6 agents run in order — the KnowledgeOrganizer classifies projects by actionability (PARA), groups skills into proficiency-leveled competency areas, and clusters everything into a subject → topic taxonomy; the WisdomSynthesizer then distills a headline, cross-project insights, and named gaps on top. Both have a data-driven offline fallback so the layer always renders.

flowchart TB raw[L1 raw turns] --> seg[Window Segmenter] seg --> syn[Syntax Pass] seg --> tri[Triage Agent] tri -->|kept| ded[Dedupe Agent] ded -->|novel| route{Route by domain} route --> dec[Decision] route --> biz[BusinessLogic] route --> int[Intent] route --> ps[ProblemSolution] syn --> facts[L2 facts] dec --> facts biz --> facts int --> facts ps --> facts facts --> res[Code Resolver] facts --> clu[Clusterer] clu --> sum[Summarizer] sum --> concepts[L3 concepts] facts --> enr[L2.5 Enrichment] code[L0 code + manifests] --> enr enr --> entities[entities / relationships / skills / industry / gaps] concepts --> link[Linker + mechanical] entities --> link link --> global[L4 links + L5 skills] facts --> ver[Verifier]

Enrichment stages (L2.5)

Deterministic stages

Agent stages

The agent layer

A couple dozen chat agents plus one embedding-only agent. Each has a versioned prompt, a JSON schema, and a model reference resolved from config. All share a single runtime that handles caching, validation, and persistence. Agent-bound calls run with bounded concurrency (config.concurrency). The table below is representative, not exhaustive.

AgentInputOutputDefault routing
triageturn window text4-axis labels + kept/droppedevery new window
dedupetextembedding vectorevery kept window + every new fact
decisionwindowdecisions / constraints / patternskept windows with signal-grade quality
businessLogicwindowbusiness rules / entities / constraintsdomain ∈ {business_logic, architecture}
intentwindowuser intentsmost engineering domains
problemSolutionwindow(problem, solution) pairsdomain ∈ {debugging, implementation}
requirementswindow / docsrequirements, features, actors, processes, metricsproduct / BRD signal
incidentwindowincident → root cause → resolutiondomain ∈ {debugging, ops}
clusterer / clustererBatchnew fact(s) + top-K candidatesattach / create / mergeambiguous facts (batched by default)
domainFusercore pack + concepts + entitiesrelationships, domains, highlightsstandard enrich
industryFusercore pack + deps + READMEindustry, skills, architecture, glossarystandard enrich
summarizerconcept + member factsname + structured summaryeach touched concept
fileAnalyzerfile defs + imports + calls + source slicesummary + layer + tags + conceptsanalysis (L0.5), per file
architectureAnalyzerper-directory layer histogramcanonical layer per directoryanalysis (L0.5)
technicalProfilerlanguages + dependenciestechnical skillsenrichment (L2.5)
domainModelerentities + evidencerelationships / gaps (evidence-enforced)enrichment (L2.5)
industryClassifierstack + symbols + README + entities + rulesindustry label + confidence + evidenceenrichment (L2.5)
industryEnricherindustry + present conceptsindustry-standard concepts (model/external)enrichment (L2.5)
domainAnalyzerindustry + skills + layers + factscomposite portfolio highlights (evidence-cited)enrichment (L2.5)
profileWriterglobal industries + skills + highlightsportfolio/background markdownglobal profile --prose
knowledgeOrganizerprojects + activity + skills + domains + conceptsPARA projects, leveled competency areas, subject → topic taxonomy (L6)global wisdom / dashboard build
wisdomSynthesizerorganized areas + skills + domains + gapsheadline, insights/principles, gaps (L6)global wisdom / dashboard build
linkertwo cross-project conceptssame_as / variant_of / supersedes / contradicts / nonecross-project candidate pairs
verifierpair of same-cluster factsconsistent / contradicts / supersedesperiodic sweep

Agent runtime

Every agent call goes through one function. Inputs are a typed payload plus the agent's prompt and schema; outputs are validated JSON, cached by content hash, and persisted to agent_runs for audit.

interface Agent<I, O> {
  name: string;
  promptVersion: number;        // bump invalidates cache
  modelKey?: string;            // overrides config lookup
  schema: JsonSchema;           // strict validation
  prompt(input): ChatMessage[];
  postprocess?(o, input): { output, confidence };
}

interface AgentRuntime {
  run<I, O>(agent, input): Promise<{ output, confidence, model, cached }>;
  // 1. hash(agent.name + model + prompt_version + input) -> cache lookup
  // 2. call backend (Ollama / OpenAI-compatible / Anthropic)
  // 3. parse JSON; validate against schema; one repair retry on failure
  // 4. write to agent_runs (success or failure)
}

Cache invariants

Storage

<project>/.substrate-net/
├── code.db          # L0 — codegraph-compatible schema
│   ├── nodes              (id, kind, name, qualified_name, file_path, ...)
│   ├── edges              (source, target, kind, line, col, provenance)
│   ├── files              (path, content_hash, indexed_at, ...)
│   ├── file_analysis      (L0.5 — summary, layer, tags per file)
│   ├── nodes_fts          (FTS5 over names / signatures / docstrings)
│   └── unresolved_refs
│
├── knowledge.db     # L1, L1.5, L2, L2.5, L3 + agent cache
│   ├── sessions / turns / tool_calls
│   ├── turns_fts          (FTS5 over turn text)
│   ├── turn_windows / triage_labels
│   ├── k_nodes            (+ scope, grounding, source_url columns)
│   ├── k_edges / k_provenance / k_to_code
│   ├── k_nodes_fts        (FTS5 over fact titles + summaries)
│   ├── k_node_embeddings  (sidecar — keeps k_nodes lean)
│   ├── concepts           (+ scope, grounding columns)
│   ├── research_cache     (external lookups, opt-in)
│   └── agent_runs         (cache + audit)
│
└── canvas/          # generated .canvas.tsx artifacts

~/.substrate-net/
├── global.db
│   ├── projects
│   ├── concepts_global    (mirrors per-project concepts with embeddings)
│   ├── concept_links      (a, b, kind, score, source)
│   ├── skills             (L5 — name, scope, evidence_weight, project_count)
│   ├── skill_evidence     (per-project evidence behind each skill)
│   ├── industries         (classified business domains across projects)
│   ├── business_domains / tech_domains / taxonomy_edges   (L2.6 zones + hierarchy)
│   ├── workspaces / project_workspace / project_links     (L4 umbrellas + links)
│   ├── highlights         (composite portfolio statements per project)
│   ├── wisdom_meta / competency_groups / competency_skills (L6 — synthesized)
│   ├── wisdom_insights / wisdom_gaps                       (L6 — synthesized)
│   └── agent_runs         (cache + audit for global agents — ProfileWriter, WisdomSynthesizer)
└── config.json

Three databases, three responsibilities. The split keeps the code DB drop-in for codegraph users and lets the knowledge schema evolve independently. Knowledge-schema columns (scope, grounding, …) are added via additive migrations, so existing databases upgrade in place.

Languages

ExtensionsLanguageEngine
.ts .tsx .mts .cts .js .jsx .mjs .cjsTypeScript / JavaScripttree-sitter
.pyPythontree-sitter
.dartDarttree-sitter
.goGotree-sitter
.rsRusttree-sitter
.javaJavatree-sitter
.csC#tree-sitter
.ex .exsElixirtree-sitter
.sql .ddlSQL DDLregex parser

Adding a language: a new entry in src/code/languages.ts plus ~50 lines of node-type handlers in src/code/extractor.ts. Tree-sitter WASMs for Swift, Kotlin, PHP, Ruby, C, and C++ are already shipped in tree-sitter-wasms and only need wiring.

Conversation sources

SourceLocationCoverage
Cursor~/.cursor/projects/<slug>/agent-transcripts/<uuid>/<uuid>.jsonlfull + tool calls
Claude Code~/.claude/projects/<slug>/*.jsonlfull + tool calls
Codex CLI~/.codex/sessions/**/*.jsonlfiltered by cwd metadata
GitHub Copilot ChatVS Code workspace storagebest-effort (private API)

Design trade-offs