Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 14 additions & 1 deletion .claude/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
{}
{
"extraKnownMarketplaces": {
"morphogen": {
"source": {
"source": "github",
"repo": "OpenReplicant/Morphogen",
"ref": "9769a0b5781d3f576ede95a90e1f7599caf05c24"
}
}
},
"enabledPlugins": {
"morphogen@morphogen": true
}
}
7 changes: 3 additions & 4 deletions .claude/skills/setup/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ has decided to skip it. Tell the owner, in a line, what each step did. Use the c

The stack on the fresh tree (S-137) is Postgres (`deploy/postgres`), the model gateway (Bifrost) and Ollama,
plus the `substrate-tools` container, and the Knowledge Kernel (S-153, S-154): the store, in its own database
`kernel` in the same Postgres, from an image built out of `repos/kernel` (`scripts/build.sh kernel`; cloned there
when missing). `scripts/up.sh` makes the database, installs the kernel's schema (`scripts/kernel.sh init`) and
exports the old `store` schema into it (`scripts/kernel.sh export`; safe to run again; it needs no Python of ours,
it is the kernel's own `encoder_substrate`). `scripts/db.py init` also applies the environment's schema
`kernel` in the same Postgres, from an image published or built out of `repos/kernel` (`scripts/build.sh kernel`;
cloned there when missing). `scripts/up.sh` makes the database and installs the kernel's schema (`scripts/kernel.sh
init`); the old `store` schema's content was exported once (S-154) and the schema dropped (S-191). `scripts/db.py init` also applies the environment's schema
(`environment/sql/`, schema `env`); a database that had it applied before S-156 keeps its record (`public.env_migration`
is seeded from `public.store_migration`), so nothing is applied twice.

Expand Down
68 changes: 6 additions & 62 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ CONTAINER_ENGINE=podman
# Where the secrets in deploy/secrets.txt live. env (this file) is the one backend; scripts read them only
# through env_value and sec_*, so a store can sit behind the same calls later.
SECRETS=env
# the optional services compose starts beside the core: llm (the local model and the worker), voice (the voice head);
# comma-separated, e.g. llm,voice; empty: the core only
# the optional services compose starts beside the core: llm (the local models); comma-separated, e.g. llm; empty:
# the core only
COMPOSE_PROFILES=

# ---- Postgres (deploy/postgres: Postgres 17 with pgvector, pg_cron, pgmq, pgGraph)
Expand Down Expand Up @@ -60,20 +60,9 @@ GATEWAY_METER_PASSWORD=
GATEWAY_ADMIN_PASSWORD=
GATEWAY_KEY_SECRET=

# ---- the companion (plan step 4, S-136): Claude Code on the owner's own Claude login, through the gateway
# Anthropic models its keys may reach (comma-separated names or regex:...); empty: Haiku only
COMPANION_MODELS=
# the session's model, until an approved proposal changes it
COMPANION_MODEL=claude-haiku-5-5
# minutes between clock ticks (each also carries the meter); every tick is a turn for the session
COMPANION_CLOCK_MINUTES=60
# the daily token budget the companion starts with (its own proposals change it, once the owner approves)
COMPANION_DAILY_TOKENS=2000000
# the person who decides its proposals, as the record names them
OWNER_NAME=owner
COMPANION_SESSION_KEY=
COMPANION_TASK_KEY=
COMPANION_DB_PASSWORD=
# ---- Anthropic through the gateway: the models a caller on a Claude login may reach (comma-separated names or
# regex:...); empty: Haiku only. No caller has one since the old assistant retired (S-194).
ANTHROPIC_MODELS=

# ---- 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
Expand All @@ -95,54 +84,9 @@ 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
# Kokoro's voice; the CPU threads for speech; seconds of silence that end an utterance
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
TTS_URL=
COMPANION_AUTHOR_KEY=
JUDGE_KEY=
JUDGE_DB_PASSWORD=

# ---- the worker (plan step 1, S-163): an offline agent on the local model, compose service `worker` (profile llm)
# its key at the gateway (local models only) and its login to the store's database; its kernel login is made once with
# scripts/kernel.sh login worker (.state/kernel/worker.env)
WORKER_KEY=
# the worker's compiled skills (S-164): a folder of blocks and plans, e.g. blocks/examples; empty: none
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 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=
WORKER_MAX_STEPS=8
WORKER_CONTEXT_TOKENS=11000
WORKER_REASONING=

# ---- published images (S-167): scripts/up.sh pulls ghcr.io/openreplicant/substrate-* and the kernel's image, and builds only what did not pull
# the tag of Substrate's images, and of the kernel's (main, a v-tag, or a short commit)
SUBSTRATE_IMAGE_TAG=main
KERNEL_IMAGE_TAG=main
# 1: build every image here instead of pulling (the voice head is always built here)
# 1: build every image here instead of pulling
SUBSTRATE_BUILD=
8 changes: 3 additions & 5 deletions .github/workflows/images.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Publishes Substrate's own images to GHCR (S-167): what scripts/up.sh pulls instead of building. Pushes only from this
# repository's main branch and v* tags; a pull request builds the images without pushing, and not at all when it comes
# from a fork. The voice head is not published (S-167: it carries GPL parts, so it stays a local build). The kernel's image
# is the Knowledge Kernel repository's own (ghcr.io/openreplicant/kernel); the worker is built on it.
# from a fork. The kernel's image is the Knowledge Kernel repository's own (ghcr.io/openreplicant/kernel). The old
# assistant's images (companion, worker) are no longer built (S-194).
name: images

on:
Expand All @@ -28,8 +28,6 @@ jobs:
include:
- {name: db, context: deploy/postgres, file: deploy/postgres/Dockerfile}
- {name: tools, context: deploy/tools, file: deploy/tools/Containerfile}
- {name: companion, context: deploy/companion, file: deploy/companion/Containerfile}
- {name: worker, context: deploy/worker, file: deploy/worker/Containerfile}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
Expand All @@ -44,7 +42,7 @@ jobs:
type=sha,format=short,prefix=
type=ref,event=tag
type=semver,pattern={{version}}
# signed in on a pull request too: the worker's base image is the kernel's, which may be private until made public
# signed in on a pull request too, as for a base image that is not public yet
- name: Sign in to GHCR
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ __pycache__/
# this machine's Claude Code settings
.mcp.json
.claude/settings.local.json

# Morphogen: the operator's settings (held-out answers, gateway, meter), never committed (S-193)
morphogen.local.yaml
27 changes: 10 additions & 17 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@ The layers (S-185, `docs/framework.md`, `docs/repos.md`): **the Kernel** (Postgr
(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).
models by their alias (`fast`, `slow`, `cloud`), never by model. **The table below is what is in the tree today.**
The old assistant (the companion, the voice head, the worker, blocks, the components judge, the ladder's code) was
removed on 2026-11-23 (S-194): the assistant starts again from scratch, not ported; git keeps the old parts.

| 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 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`; 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 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) |
| Images | `.github/workflows/images.yml`, `image_ref` in `scripts/lib.sh` | `ghcr.io/openreplicant/substrate-{db,tools,companion,worker}` and the kernel's image are pulled (tags `SUBSTRATE_IMAGE_TAG`, `KERNEL_IMAGE_TAG`); compose keeps `build:` as the fallback; voice is built locally, never published (S-167) |
| Images | `.github/workflows/images.yml`, `image_ref` in `scripts/lib.sh` | `ghcr.io/openreplicant/substrate-{db,tools}` and the kernel's image are pulled (tags `SUBSTRATE_IMAGE_TAG`, `KERNEL_IMAGE_TAG`); compose keeps `build:` as the fallback (S-167) |
| Glue | `scripts/`, `deploy/` | brings the parts up and connects them |

`deploy/caddy` (in front of the UI) and `deploy/ontop` (SPARQL) are kept and not started yet.
Expand All @@ -49,8 +42,9 @@ and move into `distributions/assistant/` (plan step 3).
lists every setting, empty; `deploy/secrets.txt` says how each secret is made.
5. **One tested path.** Compose with Podman. Scripts call only the runtime's four verbs (`rt_up`, `rt_down`,
`rt_status`, `rt_logs`) and keep engine-specific code in `scripts/lib.sh`.
6. **Nothing installed on the host** beyond git, python3 (standard library), the engine and its compose, and
Claude Code. A tool goes into a container (`deploy/tools/Containerfile`, or the companion's).
6. **Nothing installed on the host** beyond git, python3 (standard library), the engine and its compose, Claude Code,
and uv, which Claude Code plugins such as Morphogen's run their MCP servers with (S-196). A tool goes into a
container (`deploy/tools/Containerfile`).
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). Models and tools the user downloads themselves (never bundled or
Expand All @@ -76,13 +70,12 @@ scripts/bootstrap.sh # once per machine: host tools, images (pulled from g
scripts/up.sh # the stack (db, gateway, ollama, ui), the tools container, the databases; then check.sh
scripts/check.sh # is everything up and wired
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/build.sh [db|tools|kernel] # none: pull published images, build what did not pull; SUBSTRATE_BUILD=1 builds all
scripts/logs.sh SERVICE # db, gateway, ollama, kernel, ui, llm, llm-fast
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 (now dropped), an agent's login and its MCP server
scripts/kernel.sh init|catalog|login NAME|mcp NAME # the Knowledge Kernel: its schema, the catalog into it, 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/)
bin/in-tools python3 scripts/env.py waiting|decide|publish|actuators|gate|queues # the environment, as a person
scripts/companion.sh login|attach|restart|status # the companion's session (log in once)
```
Loading