Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
79e142e
Two local models: Inkling on the CPU (local/slow), a small fast one o…
claude Nov 22, 2026
b5ae6f4
Voice routing: the fast model picks talk, delegate or save_note; work…
claude Nov 22, 2026
5c6f175
Fast layer: quick tools in the voice head, streamed speech, SearXNG s…
claude Nov 22, 2026
cd9047e
Plan: our own light runtime, MCP for every component, harnesses as ag…
claude Nov 22, 2026
9a1a4b1
Plan: OpenTelemetry through the runtime; the kernel's boundary (optio…
claude Nov 22, 2026
0b43257
Plan: describe, check, decode; pluggable runtimes; a compatibility li…
claude Nov 22, 2026
fcc5d91
Vocabularies: standards first, a thin profile, plans in PROV-O not P-…
claude Nov 22, 2026
d5a5e15
Plan: the P-Plan question decided (S-175); the v0 migration left to s…
claude Nov 22, 2026
2c11545
repos.yaml: the kernel checked at 0411460 (main after #132; the pulle…
claude Nov 22, 2026
6ceeb23
The catalog entry: Substrate's parts as Backstage entities in the ker…
claude Nov 22, 2026
7d1315c
Compose into the kernel and back (S-177); the catalog's database is d…
claude Nov 22, 2026
9f037cf
M-17's gate: a proxy asking decision questions (S-178); the decider t…
claude Nov 23, 2026
f36ec2f
Docs: the gate after Soar (S-180); one assistant, two products, role …
claude Nov 23, 2026
4a8eb7c
Experience, not a decision log; its privacy terms; the assistant's fi…
claude Nov 23, 2026
8d444a7
Experience: env.experience and env.outcome, encrypted, deletable, wit…
claude Nov 23, 2026
9596fcf
Substrate's shape: an orchestrator on a Postgres kernel; OpenEnv adop…
claude Nov 23, 2026
a4e262c
Plan: everything on top of the shape, the bootstrap instance, a secon…
claude Nov 23, 2026
36f69e1
Registries and trust for the MCP installer; LFM3 recommended; busines…
claude Nov 23, 2026
1b229dc
The motto corrected; one Postgres server, databases per concern; agen…
claude Nov 23, 2026
44654f9
One database after all, the kernel's (S-190)
claude Nov 23, 2026
16ac6df
The retired store schema dropped (backed up); the kernel's D-126 repl…
claude Nov 23, 2026
27ae101
Handoff: S-189 to S-191 and the open pushes
claude Nov 23, 2026
4d001f6
The OpenEnv spike: all seven points pass; gates stay a propose tool; …
claude Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,25 @@ COMPANION_SESSION_KEY=
COMPANION_TASK_KEY=
COMPANION_DB_PASSWORD=

# ---- the local model (plan step 5): llama.cpp's server on the GPU, behind the gateway as provider `local`
# the folder holding GGUF files (mounted read-only) and the file to serve; empty LLM_MODEL: no local model
# ---- the local models (plan step 5, S-169): llama.cpp's server, behind the gateway. Two of them: a slow capable one on
# the CPU and in RAM (provider `local`), and a small fast one wholly on the GPU (provider `fast`) for what must answer at
# once; the GPU is left to the fast models (a slow model's GPU work slowed the fast one by a quarter, S-169)
# the folder holding GGUF files (mounted read-only) and the file to serve; empty LLM_MODEL: no slow model
LLM_MODELS_DIR=
LLM_MODEL=
# its name at the gateway (local/<LLM_ALIAS>)
LLM_ALIAS=gemma
# llama-server's options: all layers on the GPU, MoE experts in system RAM, 16k context, 4-bit KV cache
LLM_ARGS=-ngl 999 --cpu-moe -c 16384 -ctk q4_0 -ctv q4_0 -fa auto
LLM_IMAGE=ghcr.io/ggml-org/llama.cpp:server-cuda12-b12098
LLM_ALIAS=slow
# llama-server's options: no layers on the GPU, 6 threads (memory bandwidth is the limit: 8 were no faster), 16k context,
# 4-bit KV cache; a machine with a free GPU may put layers there (-ngl 999 --cpu-moe, then -ot for experts)
LLM_ARGS=-ngl 0 --no-op-offload -t 6 -c 16384 -b 512 -ub 128 -ctk q4_0 -ctv q4_0 -fa on
# llama.cpp's server image, for both models (b12627: Inkling 2's architecture, inkling2_loop, arrived in b12591)
LLM_IMAGE=ghcr.io/ggml-org/llama.cpp:server-cuda12-b12627
# the fast model: its folder and file (empty: none), its name at the gateway (fast/<LLM_FAST_ALIAS>), its options;
# recommended: LFM3 1.7B (Q6_K GGUF), downloaded by you, under Liquid AI's LFM Open License v1.0 (read it; S-169, S-188)
LLM_FAST_MODELS_DIR=
LLM_FAST_MODEL=
LLM_FAST_ALIAS=fast
LLM_FAST_ARGS=-ngl 999 -t 2 -c 32768 -fa on -ctk q8_0 -ctv q8_0

# ---- the voice head (plan step 5): the companion's voice and face, at 127.0.0.1:VOICE_PORT
VOICE_PORT=8110
Expand All @@ -92,6 +102,16 @@ VOICE_STYLE=af_heart
VOICE_THREADS=4
VOICE_SILENCE_S=0.6
VOICE_KEY=
# the model the voice head answers with; empty: the slow model (local/<LLM_ALIAS>); e.g. fast/fast
VOICE_MODEL=
# what decides between answering by talking and handing work to the worker (S-170): tools (the voice model calls talk,
# delegate or save_note), embed (a vote over example embeddings, by the store's embedding model) or off (the voice
# model's own HANDOFF line, to the companion)
VOICE_ROUTER=tools
# the time zone the voice head tells its model and sets reminders in (e.g. America/Los_Angeles); empty: UTC
TZ=
# signs the local SearXNG's sessions (the voice head's search tool; compose service search), generated once
SEARXNG_SECRET=
# the avatar (S-158, S-159): a .vrm, .glb or .gltf under .state/avatar/ (never committed), e.g. .state/avatar/pixar-girl/scene.gltf; empty: the canvas face
AVATAR_FILE=
# Kokoro on the GPU (compose service tts, S-150): http://tts:8880; empty: Kokoro on the CPU in the voice head
Expand All @@ -109,9 +129,13 @@ WORKER_BLOCKS=
WORKER_DB_PASSWORD=
# its kernel login (the memory profile), copied here by scripts/up.sh from .state/kernel/worker.env
WORKER_KERNEL_URL=
# the model it asks for at the gateway; steps a task may take; tokens of context it keeps (the model has 16k); empty: the model's own

# ---- the assistant's experience (S-182): one episode per model call the gate sees, its text encrypted under this key
# (made by scripts/settings.sh; keep a copy: without it the stored text cannot be read)
EXPERIENCE_KEY=
# the model it asks for at the gateway (empty: local/<LLM_ALIAS>); steps a task may take; tokens of context it keeps (the model has 16k); empty: the model's own
# reasoning setting, or none | low | medium | high
WORKER_MODEL=local/gemma
WORKER_MODEL=
WORKER_MAX_STEPS=8
WORKER_CONTEXT_TOKENS=11000
WORKER_REASONING=
Expand Down
36 changes: 23 additions & 13 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
# Substrate

An agent framework: you put an environment on a system you need, run it, and watch and change it. Its shape is
`docs/framework.md`; what is built next is `docs/plan.md`, the one plan; every default and its reason is in
`DECISIONS.md` (append-only). Read the plan first.
An operating system for AI agents (S-185): a top-level orchestrator (an ordinary LLM harness given skills, MCP
servers and hooks) that maps, orchestrates and optimises a working system, on a kernel made of Postgres where
everything is an object. Its shape is `docs/framework.md`; what is built next is `docs/plan.md` ("Next, in order"),
the one plan; every default and its reason is in `DECISIONS.md` (append-only). Read the plan first.

This is the **fresh tree** (S-137). v1 is tagged `v1-final` and its plans are in `docs/archive/`: history, not
plans to work from. v1's databases are kept in the same Postgres volume (`workbench`, `gateway`) and dumped in
`.state/backups/`; what people stated there comes back as data imported into the new store.

See `docs/repos.md` for what each repository (Kernel, Substrate, MetaSoar, Morphogen) owns.
The layers (S-185, `docs/framework.md`, `docs/repos.md`): **the Kernel** (Postgres made into a kernel), **Substrate**
(the orchestrator kit, the adapters, the reference stack), **Morphogen** (the optimiser, a Claude Code plugin),
**distributions** (folders in `distributions/` here for now), **MetaSoar** (the research). Every dependency is a
contract, never another project's code. Environments are OpenEnv environments (S-184). Name parts by their role and
models by their alias (`fast`, `slow`, `cloud`), never by model. **The table below is what is in the tree today:**
the companion, voice head, worker, blocks and the ladder's experience store are the assistant distribution's parts
and move into `distributions/assistant/` (plan step 3).

| Part | Where | Role |
| --- | --- | --- |
| The store | the Knowledge Kernel (S-153, S-154, S-156: the UI and the skills read it from the kernel's database `kernel`, the agent's tools are the kernel's MCP `substrate` profile; `scripts/kernel.sh`); the old `store` package is retired and its schema stays in database `substrate` until the owner drops it (S-156) | Wikibase's data model with OpenWiki's pinned evidence (S-135, S-138): entities, statements with ranks, references, spans, revisions, a page per entity; the agent's tools over MCP, and maps, roles, interfaces and catalogs (S-139; the `map` and `catalog` skills) |
| The store | the Knowledge Kernel (S-153, S-154, S-156: the UI and the skills read it from the kernel's database `kernel`, the agent's tools are the kernel's MCP `substrate` profile; `scripts/kernel.sh`); the old `store` package is retired and its schema was dropped on 2026-11-23 (S-191; a dump is in `.state/backups/`) | Wikibase's data model with OpenWiki's pinned evidence (S-135, S-138): entities, statements with ranks, references, spans, revisions, a page per entity; the agent's tools over MCP, and maps, roles, interfaces and catalogs (S-139; the `map` and `catalog` skills) |
| envkit | `envkit/` (declarations in `envkit/declarations/`; tests: `python3 -m pytest envkit`) | The fast in-process scheduler (lockstep or realtime) for live play, one module contract with `environment/` (S-161); moved from MetaSoar |
| The real-time environment | `environment/` (schema `env` in `environment/sql/`, migrated by `environment/db.py`, the channel in `environment/channel.py`) on pgmq in the same Postgres | signals logged whole and fanned out as topics, a queue per actuator behind its gate (`free`, `propose`, `deny`), the channel into Claude Code, archived only on `ack` (S-143) |
| The model gateway | container `gateway` (Bifrost), `scripts/gateway.py` | every model call goes through it with its caller's key and is recorded there, not by the caller (S-77) |
| Local models | container `ollama`; container `llm` (llama.cpp, profile `llm`) | Ollama for the store's embeddings; the local chat model (Gemma 4 26B-A4B from `LLM_MODELS_DIR`) on llama.cpp, at the gateway as `local/gemma` (S-149) |
| Local models | container `ollama`; containers `llm` and `llm-fast` (llama.cpp, profile `llm`) | Ollama for the store's embeddings; two chat models (S-169): the slow capable one, Inkling 2 Mini on the CPU, at the gateway as `local/slow`; the fast one, LFM3 1.7B on the GPU, as `fast/fast` (the alias names the role, not the model; Gemma is retired) |
| Tools | `bin/`, container `substrate-tools` | the scripts' Python and gitleaks, run in a container as you (S-19) |
| The companion | `deploy/companion` (compose service `companion`), `environment/companion.py` (service `environment`), the UI's `#/companion` | the first environment: Claude Code on Haiku through the gateway's pass-through route on the owner's login, fed by the channel; it replies, starts background tasks and proposes budget and model changes (S-136, S-144) |
| The voice head | `voice/` (compose service `voice`, profile `voice`) on 127.0.0.1:8110 | the companion's voice and face: microphone in over a WebSocket, Silero and Parakeet to text, the local model to answer, Kokoro to speak, a face that moves with it; hands real work to the companion (S-147, S-149) |
| The worker | `environment/worker.py` (environment `worker`), `deploy/worker/` (compose service `worker`, profile `llm`, the kernel's image plus `openai`), the UI's `#/worker` | an offline agent on the local model (`local/gemma` through the gateway as caller `worker:loop`): our own loop on `mcp` + `openai` (S-162); the kernel's `memory` profile over stdio and a few workspace tools; `gate(state)` before every model call is M-17's seam (S-163) |
| The gate (being built) | experience: `env.experience` (`environment/sql/008_experience.sql`, `environment/experience.py`, key `EXPERIENCE_KEY`; S-183); the decider's trial `scripts/trials/decider/`; the proxy next (`docs/plan.md` step 3) | System 1, in a proxy in front of the gateway: at every model call it recalls a response distilled from the assistant's experience (episodes of scenario, response, outcome): a skill, or a rung (`fast`, `slow`, `cloud`); TabICL over embeddings with outcome-labelled episodes from Postgres, the fast model's probabilities as cold start; impasses typed, outcomes attached later by episode id (S-178 to S-182) |
| The companion (to retire) | `deploy/companion` (compose service `companion`), `environment/companion.py` (service `environment`), the UI's `#/companion` | Claude Code on Haiku through the gateway's pass-through route on the owner's login, fed by the channel (S-136, S-144); becomes the assistant's `cloud` rung behind `propose`, then retires as a separate agent (S-181) |
| The voice head | `voice/` (compose service `voice`, profile `voice`) on 127.0.0.1:8110 | the companion's voice and face: microphone in over a WebSocket, Silero and Parakeet to text, the fast model deciding each turn by the tool it calls (talk, quick tools such as notes, reminders, lookup and SearXNG search, or delegate), Kokoro to speak, a face that moves with it; delegated work goes to the worker on the slow model, not the companion (S-147, S-170, S-171) |
| The worker (becoming the assistant) | `environment/worker.py` (environment `worker`), `deploy/worker/` (compose service `worker`, profile `llm`, the kernel's image plus `openai`), the UI's `#/worker` | the assistant's one loop (S-181); today an agent on the self-hosted slow model (`local/slow` through the gateway as caller `worker:loop`; S-165, S-169): our own loop on `mcp` + `openai` (S-162); the kernel's `memory` profile over stdio and a few workspace tools; `gate(state)` before every model call is M-17's seam (S-163) |
| Blocks | `blocks/` (`block.yaml` blocks, JSON plans, `blocks/run.py` the default executor, `blocks/executor.yaml`; tests: `scripts/tests/test_blocks.py`) | what the agent compiles from what it solved: catalog entries with an interface and effects, assembled as P-Plan plans, run without the model; `skill_gate` plugs into the worker's `gate` (S-157, S-164) |
| Components and the judge | `env.component` and `env.verdict` (`environment/sql/007_components.sql`), `environment/author.py`, `environment/judge.py` (compose service `judge`), `judge/cases` (the judge's only) | every version of a component with its card; an author proposes from the record, the judge tests it against the active one on cases the author cannot read, the owner activates (S-151) |
| The UI | `ui/` (`ui/server.py`, `ui/static`), compose service `ui` on 127.0.0.1:8100 | the store's pages and maps as diagrams (S-140), read-only; v1's Workbench rebuilt, with no name of its own (S-141) |
Expand All @@ -45,11 +53,13 @@ See `docs/repos.md` for what each repository (Kernel, Substrate, MetaSoar, Morph
Claude Code. A tool goes into a container (`deploy/tools/Containerfile`, or the companion's).
7. **Licences:** permissive or LGPL for what the repository contains or links into Substrate's code. A GPL part may
be a default when it is fetched at setup (never in the repository), runs unmodified in its own container and is
reached over a process boundary (S-146). Check before adding.
reached over a process boundary (S-146). Models and tools the user downloads themselves (never bundled or
committed) may be recommended whatever their licence, with the licence named (S-188). Check before adding.
8. **Every change ends with `scripts/check.sh` passing**, and `scripts/test.sh` where tests exist, or with the
failure named and explained.
9. **Morphogen is out of the build** while the owner refactors it elsewhere: do not touch `repos/morphogen` or
depend on it. Fixes to an upstream project go by pull request (the `upstream` skill).
9. **Morphogen is the optimiser** (S-185; it was out of the build only so it could be iterated on quickly): use it
through its contract (the cell file, its Claude Code plugin and MCP server), never by importing its code; change
it only by pull request in its own repository, like any upstream project (the `upstream` skill).

## Working with the owner

Expand All @@ -69,7 +79,7 @@ scripts/test.sh [FILE...] # the test suites, in the tools container
scripts/build.sh [db|tools|companion|voice|kernel|worker] # none: pull published images, build what did not pull; SUBSTRATE_BUILD=1 builds all
scripts/logs.sh SERVICE # db, gateway, ollama, ui, environment, companion, llm, voice
scripts/tools.sh start|stop|status
scripts/kernel.sh init|export|login NAME|mcp NAME # the Knowledge Kernel: schema, one-off export of the old `store` schema, an agent's login and its MCP server
scripts/kernel.sh init|export|login NAME|mcp NAME # the Knowledge Kernel: schema, one-off export of the old `store` schema (now dropped), an agent's login and its MCP server
scripts/down.sh [--volumes] # stop (deleting data asks first)
python3 scripts/gateway.py render|keys # the gateway's config from .env and its callers
bin/in-tools python3 scripts/db.py init # the databases and the environment's schema (environment/sql/)
Expand Down
Loading