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.
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.
| Layer | Content | Produced by |
|---|---|---|
| L0 Code structure | symbols, calls, imports, fields, SQL tables | deterministic (tree-sitter / regex DDL) |
| L0.5 Code analysis | per-file summaries, architectural layer, tags | structure + agents (FileAnalyzer · ArchitectureAnalyzer) |
| L1 Conversations + docs + diagrams | sessions, turns, tool calls; in-repo docs (README / BRD / ADRs) and diagrams (mermaid / drawio / excalidraw / plantuml) | deterministic (file parsers + adapters) |
| L1.5 Triage | relevance / domain / quality / linkage / activity per window; doc-kind for sources | agents (Triage · SourceClassifier) |
| L2 Facts | decisions, business rules, intents, problems/solutions; BRD actors/processes/metrics; incidents → root cause → resolution | agents (Decision · BusinessLogic · Requirements · Intent · ProblemSolution · Incident) + syntax pass |
| L2.5 Domain enrichment | dependencies, skills, entities, relationships, industry, components, gaps; cross-source dedup + corroboration | manifests + SQL · Reconciler · standard: fused enrich (domainFuser + industryFuser) · deep: 8-agent stack |
| L2.6 Knowledge zones | business + tech domains, grouping facts by bounded context / capability | agents (BusinessDomainModeler · TechDomainModeler) |
| L3 Concepts | clustered facts with names + structured summaries, scope-tagged | agents (Clusterer · Summarizer) |
| L4 Cross-project | shared concepts, workspace umbrellas, emergent project links | mechanical (exact + SimHash) + agent (Linker) |
| L5 Skill graph + hierarchy | technical + industry skills; the workspace → industry → business → tech → project tree | mechanical aggregation over L2.5/L2.6 evidence |
| L6 Wisdom | leveled competency areas (Dreyfus novice → expert), cross-project insights / principles, named gaps + recommendations | agent (WisdomSynthesizer) + deterministic fallback; grounded model |
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.
| grounding | meaning | source |
|---|---|---|
structural | objective, parsed from artifacts | code symbols, SQL schema, manifests |
stated | asserted in a conversation | extracted facts |
corroborated | stated and matched to a code entity | the Reconciler |
external | cited from outside the project | research backend (opt-in) |
model | the agent's own inference | enrichment 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.
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.
Enrichment stages (L2.5)
dependency / tool facts (structural). Monorepos with nested manifests are fully covered.entity facts and foreign keys to relates_to edges (structural).same_as and upgrades grounding to corroborated.domainFuser + industryFuser — two flash-first calls replacing eight frontier enrich agents.TechnicalProfiler, DomainModeler, ArchitectureModeler, IndustryClassifier, IndustryEnricher, domain modelers, etc.knowledge_gap nodes; names the gap, never the answer.Deterministic stages
code.db and write a k_to_code edge.Agent stages
clustererBatch for the ambiguous band.
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.
| Agent | Input | Output | Default routing |
|---|---|---|---|
triage | turn window text | 4-axis labels + kept/dropped | every new window |
dedupe | text | embedding vector | every kept window + every new fact |
decision | window | decisions / constraints / patterns | kept windows with signal-grade quality |
businessLogic | window | business rules / entities / constraints | domain ∈ {business_logic, architecture} |
intent | window | user intents | most engineering domains |
problemSolution | window | (problem, solution) pairs | domain ∈ {debugging, implementation} |
requirements | window / docs | requirements, features, actors, processes, metrics | product / BRD signal |
incident | window | incident → root cause → resolution | domain ∈ {debugging, ops} |
clusterer / clustererBatch | new fact(s) + top-K candidates | attach / create / merge | ambiguous facts (batched by default) |
domainFuser | core pack + concepts + entities | relationships, domains, highlights | standard enrich |
industryFuser | core pack + deps + README | industry, skills, architecture, glossary | standard enrich |
summarizer | concept + member facts | name + structured summary | each touched concept |
fileAnalyzer | file defs + imports + calls + source slice | summary + layer + tags + concepts | analysis (L0.5), per file |
architectureAnalyzer | per-directory layer histogram | canonical layer per directory | analysis (L0.5) |
technicalProfiler | languages + dependencies | technical skills | enrichment (L2.5) |
domainModeler | entities + evidence | relationships / gaps (evidence-enforced) | enrichment (L2.5) |
industryClassifier | stack + symbols + README + entities + rules | industry label + confidence + evidence | enrichment (L2.5) |
industryEnricher | industry + present concepts | industry-standard concepts (model/external) | enrichment (L2.5) |
domainAnalyzer | industry + skills + layers + facts | composite portfolio highlights (evidence-cited) | enrichment (L2.5) |
profileWriter | global industries + skills + highlights | portfolio/background markdown | global profile --prose |
knowledgeOrganizer | projects + activity + skills + domains + concepts | PARA projects, leveled competency areas, subject → topic taxonomy (L6) | global wisdom / dashboard build |
wisdomSynthesizer | organized areas + skills + domains + gaps | headline, insights/principles, gaps (L6) | global wisdom / dashboard build |
linker | two cross-project concepts | same_as / variant_of / supersedes / contradicts / none | cross-project candidate pairs |
verifier | pair of same-cluster facts | consistent / contradicts / supersedes | periodic sweep |
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
promptVersion → all prior runs ignored, agent re-runs<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.
| Extensions | Language | Engine |
|---|---|---|
.ts .tsx .mts .cts .js .jsx .mjs .cjs | TypeScript / JavaScript | tree-sitter |
.py | Python | tree-sitter |
.dart | Dart | tree-sitter |
.go | Go | tree-sitter |
.rs | Rust | tree-sitter |
.java | Java | tree-sitter |
.cs | C# | tree-sitter |
.ex .exs | Elixir | tree-sitter |
.sql .ddl | SQL DDL | regex 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.
| Source | Location | Coverage |
|---|---|---|
| Cursor | ~/.cursor/projects/<slug>/agent-transcripts/<uuid>/<uuid>.jsonl | full + tool calls |
| Claude Code | ~/.claude/projects/<slug>/*.jsonl | full + tool calls |
| Codex CLI | ~/.codex/sessions/**/*.jsonl | filtered by cwd metadata |
| GitHub Copilot Chat | VS Code workspace storage | best-effort (private API) |
(agent, model, input_hash, prompt_version). Bumping the prompt version invalidates the cache by design.subnet global link --rebuild triggers a full recompute when the drift becomes visible.subnet update (or subnet watch / automation) to pick up new sessions. MCP subnet_ingest still works.project_metadata JSON rather than schema changes.triage audit --dropped lets you tune.