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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ DESKTOP_PORT=8080
KERNEL_URL=
# the kernel's secrets, generated once (deploy/secrets.txt)
KK_AUTHENTICATOR_PASSWORD=
# the MCP router's and its connectors' logins to the kernel's database (S-205)
# the MCP router's, its connectors', the desktop's and the channel's logins to the kernel's database (S-205, S-206, S-220)
MCP_ROUTER_DB_PASSWORD=
MCP_CONNECTOR_DB_PASSWORD=
MCP_DESKTOP_DB_PASSWORD=
MCP_CHANNEL_DB_PASSWORD=
KK_JWT_SECRET=
# OpenRouter models a caller may use (comma-separated names or regex:...); empty: free ones only
GATEWAY_OPENROUTER_MODELS=
Expand Down
15 changes: 8 additions & 7 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ The projects (S-209, S-212; `docs/framework.md`, `docs/repos.md`): **Morphogen**
(the default distribution), **MetaSoar** (the research). A part of Substrate is a kernel module only when it needs the
kernel; otherwise it is an Agent Skill, an MCP server, a compose service or an outside service (S-213). Every
dependency is a contract, never another project's code. 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, before the parts move**
(`docs/parts.md`). The old assistant was removed on 2026-11-23 (S-194); git keeps it.
`slow`, `cloud`), never by model. **The table below is what is in the tree today; the environment, the channel and the router are in their types
(S-219 to S-221), the rest moves as `docs/parts.md` says.** The old assistant was removed on 2026-11-23 (S-194); git keeps it.

| 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) |
| 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 kernel's database `kernel` (S-202, the kernel's D-126: one database) | 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 real-time environment | `environment/`, a kernel module (S-219: `module.yaml`, `migration.sql`, installed by `scripts/kernel.sh init`; schema `env` in `environment/sql/`, migrated by `environment/db.py`; its service `environment/review.py`, compose `environment`) on pgmq, in the kernel's database `kernel` (S-202, the kernel's D-126: one database) | signals logged whole and fanned out as topics, a queue per actuator behind its gate (`free`, `propose`, `deny`); a proposed action waits in the kernel's review lane and is decided in the desktop's Review (S-219) |
| The channel | `environment/channel.py`, an MCP server (stdio) a harness starts, as its own login `mcp_channel` (S-220) | an environment queue pushed into a Claude Code session, archived only on `ack` (S-143); acting through the gates |
| 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 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) |
| The desktop | compose service `caddy` (`deploy/caddy/Caddyfile`, `deploy/caddy/apps.json`) on 127.0.0.1:8080 (`DESKTOP_PORT`), in front of the kernel's `kk serve`; its framed apps on 8081 (the gateway's dashboard) and 8082 (the map pages) | the kernel's UI shell as a desktop (the kernel's D-127): a launcher and windows for search, review, change sets, the graph, the view modules and framed apps, each app on an origin of its own with its headers rewritten in the proxy; MCP over HTTP at `/mcp`; a person signs in with `scripts/kernel.sh person NAME` (S-199, S-200) |
| The MCP router | `mcp-router/` (Go), compose services `mcp-router` (its endpoint and page, 127.0.0.1:8083 through Caddy) and one connector per server (`mcp-kernel`); its rules in `environment/sql/010_mcp.sql` | one MCP endpoint for agents and the desktop in front of every connected MCP server; each server and tool registered in the environment, each tool an actuator behind its gate, each call an action recorded and, when it changes the world, waiting for a person on the router's page (S-203, S-205) |
| The MCP router | `mcp-router/` (Go), compose services `mcp-router` (its endpoint and page, 127.0.0.1:8083 through Caddy) and one connector per server (`mcp-kernel`); its registry and rules in the environment module's schema (`environment/sql/010_mcp.sql` to `013`) | one MCP endpoint for agents and the desktop in front of every connected MCP server; each server and tool registered in the environment, each tool an actuator behind its gate, each call an action recorded and, when it changes the world, waiting for a person in the desktop's Review (S-203, S-205, S-219) |
| The desktop and the assistant | `desktop/` (`server.py`; the Assistant view module, mounted into the kernel's container), compose services `desktop` and its connector `mcp-desktop`; `environment/sql/011_desktop.sql`; `scripts/assistant.sh` | the conversation between a person and the agents as signals: the person talks in the desktop's Assistant window, an agent (a Claude Code session started by `scripts/assistant.sh`) hears it on the channel and answers, shows and asks through the router (S-206) |
| 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 |
Expand Down Expand Up @@ -76,12 +77,12 @@ scripts/up.sh # the stack (db, gateway, ollama, ui), the tools cont
scripts/check.sh # is everything up and wired
scripts/test.sh [FILE...] # the test suites, in the tools container (the kernel's in its image, the router's Go tests in Go's)
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, caddy, mcp-router, mcp-kernel, llm, llm-fast
scripts/logs.sh SERVICE # db, gateway, ollama, kernel, environment, ui, caddy, mcp-router, mcp-kernel, llm, llm-fast
scripts/tools.sh start|stop|status
scripts/kernel.sh init|catalog|login NAME|mcp NAME|person NAME # the Knowledge Kernel: its schema, the catalog into it, an agent's login, its MCP server, a person's sign-in
scripts/kernel.sh init|catalog|login NAME|mcp NAME|person NAME # the Knowledge Kernel: its schema and Substrate's modules, the catalog into it, an agent's login, its MCP server, a person's sign-in
scripts/assistant.sh # the assistant: a Claude Code session you talk to in the desktop's Assistant window (S-206)
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 kernel's database and the environment's schema in it (environment/sql/)
bin/in-tools python3 scripts/env.py waiting|decide|publish|actuators|gate|queues # the environment, as a person
bin/in-tools python3 scripts/env.py waiting|publish|actuators|gate|queues # the environment, as a person (proposals are decided in the desktop's Review, S-219)
```
3 changes: 3 additions & 0 deletions DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,6 @@ Status: **decided** (owner agreed), **adopted** (recommended and taken; confirm
| S-216 | **Substrate on the kit: its rules in the catalog, Morphogen's plugin repinned, its own `map`, `catalog` and `research` skills removed** (2026-11-25; after Morphogen #102 and #103 merged; the owner: "what's next?"; plan "The re-cut" steps 1 and 2). (a) `morphogen.yaml` is gone (Morphogen #103 reads every rule from the catalog): a root `catalog-info.yaml` is a Location naming `catalog/catalog-info.yaml`, and the settings it held (`sandbox: podman`, the sandbox image) are on the System entity under `spec.morphogen`. Morphogen at `63648ca` reads all of Substrate's catalog with no errors (`structure check`: 17 interfaces untested, 6 unused, warnings only), and its `status` says the next step is this catalog on `main`. (b) **The plugin is pinned to `63648ca`** (`.claude/settings.json`, and `repos.yaml`'s `checked`), Morphogen's `main` after #103. (c) **Substrate uses Morphogen's skills like any user:** `.claude/skills/{map,catalog,research}` are removed; rule 3 names `morphogen:research`. Picks are still recorded in `DECISIONS.md` (rule 1). `setup` and `upstream` stay. (d) The operator's `morphogen.local.yaml` still names the retired cell `voice-route`; it is uncommitted and the operator's to tidy. | done |
| S-217 | **The demo engagement is done with the kit alone; the plugin is pinned to Morphogen `d945a9c` (0.9.0)** (2026-11-24; the owner: "merged 104 ...continue"; plan "The re-cut" steps 1 and 3). (a) Morphogen #104 adds `demos/fernhill`: a made-up 11-person kitchen firm's material (documents, a job log of 121 jobs, an interview), the first run's map (Backstage entities, 40 evidence quotes, all found on their lines), its quote calculator as a judged cell (held-out cost error 12.4% to 3.4% after `tune`; pass, 7 runs, p = 0.008, Podman), four options for job scheduling quoted from the vendors' pages, and a report of four implementation projects. No kernel and no stack ran. (b) **Step 3's done-when is met:** `run.sh` ran Claude Code on sonnet with only the plugin and the material, and `check.py`'s eight checks passed with no help (its report in `demos/fernhill/runs/`). (c) **The pin moves to `d945a9c`** (`.claude/settings.json`, `repos.yaml`). Morphogen #102 and #103 changed the plugin under version 0.8.0, so `claude plugin update` kept the code from before them, and S-216's pin never reached the install; #104 bumps it to 0.9.0. A plugin repin is checked by the install's `gitCommitSha` in `~/.claude/plugins/installed_plugins.json`, not by the settings file. (d) Four kit findings are listed in the demo's README for issues in Morphogen. (e) The business session (S-188 c) can start from the report. | done |
| S-218 | **The stack on kernel `e4ed8e2`; an MCP tool's gate follows its annotations until a person sets it; the desktop's host port is a setting** (2026-11-24; the owner, on port 8080 taken: "use any other available port, i'm working with 8080 right now"; on the gates: "Free, and change the rule"). (a) **The kernel pin moves to `e4ed8e2`** (main after #140, with #138 / its D-128: every MCP tool says whether it writes; `repos.yaml`); the published image's revision is the same commit; `scripts/check.sh` passes and every suite passes on it (catalog 9, environment 41, gateway 15, kernel 27, UI 36, the router's Go tests). (b) **The gate rule** (`environment/sql/012_mcp_gates.sql`, superseding the "a connector registering again never changes a gate" of `010_mcp.sql` and S-205): the kernel's tools were registered before #138, so its 14 read-only tools kept `propose` and every read waited for a person. Now each registration sets again a gate whose `set_by` is the registering connector (no person has set it since): from `env.mcp_policy` first, else readOnlyHint true is `free` and anything else `propose`, in both directions. A gate a person set is kept (`recall`, set by `person_owner`). On this machine the 14 are `free` by the rule (set_by `connector:kernel`, no decision made in the owner's name); the 5 writers stay `propose`. Seven new checks in `scripts/tests/test_environment.py`; three of them fail without 012. (c) **`DESKTOP_PORT`** (default 8080) is the desktop's port on the host: compose maps it to Caddy's 8080, and the Caddyfile's and the router's `frame-ancestors`, `check.sh`, `kernel.sh person` and `assistant.sh` name it; the framed apps stay on 8081 to 8083 (S-200). This machine uses 8180. The `setup` skill names a taken port as a known cause. | done |
| S-219 | **The environment is a kernel module: a proposed action waits in the kernel's review lane, and the decision made there is the action's** (2026-11-27; `docs/parts.md` "Order" step 2, first part; S-212, S-213 (a), S-214: a part is a kernel module when it needs the kernel's database, a role and the review lane). (a) **Through the kernel's module contract** (its `kernel/schemas/module.schema.json`, `modules/_template`, `kk module install`, read at kernel `e4ed8e2`): `environment/module.yaml` (`urn:kk:module:environment`, kind `control`, slots `trigger` and `actuator`, requires `review-lane`, role `kkm_environment`, runtime a python-service) and `environment/migration.sql` (the role, its agent row, the role granted to the kernel's login, as `actuator-compose` does). `scripts/kernel.sh init` runs `kk module install` on it after `kk init`, so the kernel checks the manifest and its licence and applies the migration once. The environment's own schema `env` stays migrated by `environment/db.py` (numbered files, each once): the kernel's contract applies a module's migration once and has no upgrade step, and `env` has seven files already; `013_review_lane.sql` gives the module's role `env.review_waiting()` and `env.decide` and nothing else in `env`. (b) **Its service** (`environment/review.py`; compose `environment`, in the kernel's image with `../environment` mounted, so it uses the kernel's `kk.lib` as every kernel module does: the kernel's login `kk_authenticator`, switched to `kkm_environment`): each waiting action becomes one change set in the review lane, keyed `environment:action:<id>`, in scope `urn:kk:scope:default`: `urn:kk:environment:action:<id>` a `sosa:Actuation`, `sosa:madeByActuator` its actuator, `as:actor` the caller's kernel agent when it is one, an `rdfs:label` (an MCP tool by the name its caller used, the caller, the action's id) and `dcterms:description` its input in full; standard terms from the kernel's packs, no new vocabulary. The kernel validates it and holds it for a reviewer, so the person decides it in the desktop's Review with everything else. Approved, the kernel applies it (the approved request is kept as claims, five per action) and the service calls `env.decide(approve, the reviewer, the note)`: queued for its actuator; rejected, refused with the reviewer's note. The kernel refuses a change set's approval by its submitter (the module) and the environment a proposal's by its caller, so a person who approves a request they made has it refused, with the reason. It wakes on `env_action` and `kernel_change_set` and looks every 5 s (`KK_SWEEP_SECONDS`), because a rejection sends no notification. (c) **One place to decide:** the router decides nothing any more (its `/api/decide` and the page's Approve and Reject buttons are gone; its Waiting list says to decide in Review; `env.decide` is revoked from `env_router`), and `scripts/env.py decide` is gone. (d) **Checked:** `scripts/tests/test_review.py`, 19/19 in a throwaway kernel (the install and its repeat; one change set per waiting action, held for review, saying what, by whom, with the input; approval, rejection with a note, self-approval refused; the router may not decide; the module may decide and may not act or set a gate); every suite passes (environment 44, review 19, kernel 27, UI 36, gateway 15, catalog 9, the router's Go tests). End to end on a throwaway stack (compose project `recut`, its own ports and volumes): an agent's `kernel_remember` through the router waited, appeared in the kernel's `review_queue` for `person_owner`, was approved with the kernel's own `review` tool and carried out by the kernel's connector; a second was rejected and the router's `router_outcome` said refused, by `person_owner`, "not now". (e) **Found, for the kernel:** `kk module install` gives a python-service module's role a login with a new random password on every run, even when the module is installed (unused here: the service switches from the kernel's login); there is no upgrade path for a module's migration; a rejection sends no `kernel_change_set` notification. Each is a small kernel pull request when wanted, none needed now. (f) **Privacy:** an approved request's input is now a claim in the default scope, which every agent with default clearance can read; before, it was only in `env.action`. Whether proposals go to a scope of their own is the owner's call (`docs/privacy.md`). | adopted |
| S-220 | **The channel and the MCP router are MCP servers on the environment module; the channel connects as its own login** (2026-11-27; `docs/parts.md` "Order" step 2, second part). (a) **The channel** (`environment/channel.py`, stdio, started by the harness) was already an MCP server reading the environment's queues, but it connected as Postgres's superuser. It now connects with `DATABASE_URL`, its own login `mcp_channel` (role `env_agent`: publish, act through the gates, read and acknowledge the queues it subscribed; it cannot decide, set a gate or read another's queue), password `MCP_CHANNEL_DB_PASSWORD` (`deploy/secrets.txt`, made by `scripts/settings.sh`, the login by `scripts/db.py init`). `scripts/assistant.sh` writes it into the channel's MCP entry (`.state/assistant/mcp.json`, mode 600, beside the token it already held); `013_review_lane.sql` gives the login the assistant's queues made before. Without `DATABASE_URL` it still falls back to `ENV_URL`, `STORE_URL`, then the superuser, for a person at the command line. It stays in the `environment` package: it is a few lines over the module's functions, not a part with code of its own. (b) **The router** (`mcp-router/`, Go) is already a compose-service MCP server whose registry (`env.mcp_server`, `env.mcp_tool`, `env.mcp_policy`) and gates are the environment module's schema; it now decides nothing (S-219 c). S-205 (g)'s question, whether it moves into the kernel's core, stays open. (c) **The catalog:** `component:environment` is now a service with its compose service, `component:channel` is new. (d) **Checked:** four new checks in `scripts/tests/test_environment.py` (the channel's session runs on an `env_agent` login; that login may not decide, set a gate or read a queue it did not subscribe), and the channel started from `assistant.sh`'s dry-run settings on the throwaway stack initialised as `mcp_channel` and acted through the gates. | adopted |
| S-221 | **The assistant's conversation is already a view in the kernel's desktop; nothing more is built for it until a use case asks, and `ui/` stays** (2026-11-27; `docs/parts.md` "Order" step 2, third part: "built as far as a use case needs"). The Assistant view (`desktop/view-assistant/`, a view module in the kernel's contract, mounted into the kernel's container, S-206) and its messages as signals in `env` (`011_desktop.sql`) are the target shape already; its server `desktop/server.py` is an MCP server through the router, as S-213 (a) wants. What it lacks (a chat library picked with the `research` skill, S-208) waits for the next use of the assistant. `ui/` is not retired: the kernel's Map view draws one map, and Substrate's many maps (S-207: a map as an item, one marked self) are not in the kernel yet. | adopted |
Loading