diff --git a/DECISIONS.md b/DECISIONS.md index d659512..1710983 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -183,3 +183,5 @@ Status: **decided** (owner agreed), **adopted** (recommended and taken; confirm | S-173 | **Our own light runtime on Postgres, MCP as every component's interface, one agent loop of ours, other harnesses as agent instances** (2026-11-22; the owner's direction; supersedes S-162's narrower own-loop pick by widening it, and parks S-172's trial; `docs/plan.md` "The runtime, components and agents"). Postgres is the backbone (pgmq queues, the `env` gates and record, the kernel as catalog). A block is an MCP tool and a registered MCP server's tools are components, both ways, behind the environment's gates. Blocks run on demand by default (measured 2026-11-22 in the tools container: a Python block per call with JSON in and out 18.8 ms median, a bare `python3 -I` 10.2 ms, a process spawn 0.6 ms, about 8 MB idle), with a `hot` toggle for a supervised persistent process. A process supervisor runs processes in one small container; **Nomad is out by default: its LICENSE is the Business Source License** (read 2026-11-22), so process-compose (Apache-2.0, Go, v1.124.0 of 2026-10-26) is the lead candidate, to be picked with the research skill against s6, supervisord and systemd units. One agent loop (the worker's, generalised) with M-17's gate at the model endpoint; Claude Code and other harnesses join as agent instances (tasks from a queue, tools from the MCP endpoint, models through the gateway, `task.done` back). | decided | | S-174 | **Describe, check, decode: Substrate builds no runtime and does not mediate links; runtimes are pluggable, Compose first; the kernel as a symbolic latent space** (2026-11-22; the owner's direction; supersedes S-173's runtime engine, its bindings and its blocks MCP server as a requirement; `docs/plan.md` "Describe, check, decode"). Components talk to each other directly in the protocols they already speak; their interfaces are described in a WoT Thing Description's shape (affordance, schema, forms with protocol and address); two parts fit when one provides what the other requires, and otherwise a translator from the catalog goes between them. Substrate decodes the map into existing runtimes' native formats and encodes their state back (the kernel's D-41: automations stay in their runners' formats; D-36: chain runners parked). **The kernel's boundary is already decided there:** queues belong to a distribution in its own database (the kernel's D-94 c), signals and telemetry are observations, not claims (D-101), and the catalog entry becomes D-101's first content type, the proof that proposed framing waits on. **The kernel as a symbolic latent space** (the owner's words): one universal symbolic representation that systems are interpreted into and out of. **Compatibility list** (`docs/compatibility/README.md` and `runtimes.json`, read 2026-11-22 from each project's docs and GitHub by three Haiku subagents): 10 service and process runtimes, 15 workflow orchestrators, 7 cloud services, 13 interchange standards, each with its native format, API and licence; a licence decides only whether a part can be a default (open: Compose, Podman, process-compose, systemd, Kubernetes, Flowable, Kestra, Argo, Conductor, Node-RED, Airflow, Prefect, Dagster, Temporal, Hatchet), the rest are targets (Nomad and Restate BUSL-1.1, Inngest SSPL, n8n Sustainable Use, Camunda License, Windmill AGPL plus proprietary EE, cloud services). **Found:** P-Plan, whose terms blocks' plans use (S-164) and the kernel's chain model maps to, is CC BY-NC-SA 2.0, a non-commercial licence: the owner to decide how they refer to it. Next: the catalog entry content type with a compatibility check, then the Compose decoder and encoder tested on Substrate's own `deploy/compose.yaml`. | decided | | S-175 | **Vocabularies: standards first and a thin profile of our own, no custom ontology; plans in PROV-O, not P-Plan** (2026-11-22; the owner: "alternative ontologies are fine ... it's your call"; the kernel's D-124, which closes its O-13). P-Plan's licence is CC BY-NC-SA 2.0 (non-commercial, found by S-174). A full custom ontology was weighed and set aside: owning every modelling decision would fight the kernel as a symbolic latent space (S-174, the kernel's D-122), which carries formats in and out best when its middle speaks the vocabularies they map to. So the kernel's D-40 stands (standard vocabularies first), with a thin profile of our own terms only where none fits, each mapped (SKOS). Blocks' plans keep their JSON shape; in the kernel a plan is `prov:Plan` and a run a `prov:Activity` with `prov:hadPlan`, with the profile's terms for steps, order and variables (mapped to BBO/BPMN where they overlap). `blocks/__init__.py` and `blocks/executor.yaml` no longer call the format P-Plan. P-Plan's IRIs already in kernel v0 stay until the owner schedules that migration. Also done this day, with the owner's go-ahead: the kernel's branches cleaned (27 deleted: 24 merged or squash-merged, and three early `*_iteration` branches first kept as `archive/*` tags). | decided | +| S-176 | **The catalog entry: Substrate's parts as Backstage entity files, read into the kernel by encoder-backstage; a fit check over files, compose and the kernel** (2026-11-22; plan step 1 of S-174; the kernel's D-101 first content type, D-123). **Format chosen, not invented:** Backstage's entity format (`backstage.io/v1alpha1`), which the kernel already reads (`encoder-backstage`, the kernel's D-100) and `map-drift` already compares with observed calls; one file per entity in `catalog/` (47: 22 components including jobs, agents, blocks, a plan and two external services, 22 APIs, the database, the system, the owner), so each file is one item's version. Interfaces are `API` entities, `spec.type` the protocol (`openapi`, `asyncapi` for pgmq queues, `mcp`, `websocket`, `http`, `wot-td`), `spec.definition` the contract (a block's is a WoT Thing Description action from its `block.yaml`); licence, image, compose service and decision as `substrate.dev/*` annotations. A queue is provided by the component that receives on it (AsyncAPI's sense). **`scripts/catalog.py`:** `check` (every consumed API has a provider, every reference resolves, compose matched both ways), `apis`, and `check --kernel` (the same fit from the kernel's usable claims under the read model's role, `kkm_view_substrate`, and drift between files and kernel). **Into the kernel:** compose job `kernel-catalog` (profile kernel-admin; `scripts/kernel.sh catalog`), the volume `kernel-artifacts` as the artifact store. **Seen:** 47 change sets applied; every claim cites its file and line (each file an artifact, `application/yaml`); 45 provides and consumes links, no gap, no drift; a second run submitted only the one new file. **Found on the way:** the first entries modelled the worker's queue backwards and missed two compose jobs, both caught by the check; my own `kernel-catalog` job was flagged until it had an entry. `scripts/check.sh` now runs the check; `scripts/tests/test_catalog.py` (9 checks). **For the kernel, follow-ups:** `encoder-backstage` reports every cross-file reference as `dangling-ref` (it resolves within one file, though the claims point at the right IRIs), and writes no current-version link from an item to its artifact (D-101's `kkt:hasArtifact`, or a standard term, `docs/content.md`'s open question); D-101's per-type items view is not built yet. | adopted | +| S-177 | **Compose into the kernel and back: the kernel's `encoder-compose` and `decoder-compose`** (2026-11-22; plan step 2 of S-174; the kernel's D-125, PR OpenReplicant/kernel#134, stacked on #133). Built as kernel modules, not in Substrate, because the kernel's architecture puts encoders and decoders in modules and Compose is any distribution's concern; they generalise the self-encoder's `encode_compose` (which reads only the kernel's own files). A compose file becomes a service template whose version is the file (D-101) and node templates `urn:kk:node:` with node type, image, profiles, ports, volumes, environment variable names (never values) and dependencies, each claim citing its lines; the decoder renders the file from that version and the current claims, so a changed claim changes the file. **Seen in this stack's kernel:** `deploy/compose.yaml`'s 17 services became 242 claims and decoded back equal as compose reads it; the catalog's components and compose's services meet on the same nodes (the voice head: 20 claims from the catalog, 28 from compose). **Found and fixed:** the catalog called the database `postgres` and compose `db`, so their nodes did not meet: the entry is now `resource:db`; the old file's claims stayed current until the kernel encoders gained `--prune` (retract what removed or renamed files said); a run from another working directory re-keyed every file (456 claims retracted and re-added, nothing lost), so the `kernel-catalog` job now passes `--root /`. **Not yet:** a `scripts/kernel.sh compose` job (it waits for a published kernel image with the modules), running state encoded back (`compose ps` as observations), and the decoder writing the stack's compose file in use. | adopted | diff --git a/catalog/README.md b/catalog/README.md new file mode 100644 index 0000000..dad68e9 --- /dev/null +++ b/catalog/README.md @@ -0,0 +1,23 @@ +# Substrate's catalog + +Substrate's own parts, one file per entity, in **Backstage's entity format** (`backstage.io/v1alpha1`): components +(services, jobs, agents, blocks, plans, external services), the APIs they provide and consume, the database, the +system and its owner (S-176). It is the first content type of the kernel's D-101: each entity is an item, each file a +version kept as an artifact, and the kernel's claims about it (each citing its file and line) are its fields. + +- **Interfaces** are `API` entities: `spec.type` names the protocol (`openapi`, `asyncapi` for a pgmq queue, `mcp`, + `websocket`, `http`, `wot-td` for blocks and plans) and `spec.definition` holds the contract; a block's is a + WoT Thing Description action read from its `block.yaml`. +- **Annotations** (`substrate.dev/*`): `licence`, `image`, `compose-service`, `decision`, `source`, `gate`, + `otel-service`, `trigger`. +- **A queue's provider** is the component that receives on it (the worker provides `worker-tasks`; the voice head + and the UI consume it by publishing to it), as in AsyncAPI. + +```sh +bin/in-tools python3 scripts/catalog.py check --compose deploy/compose.yaml # every consumed API provided, compose matched +bin/in-tools python3 scripts/catalog.py apis # each API, its providers and consumers +scripts/kernel.sh catalog # into the kernel (encoder-backstage) +bin/in-tools python3 scripts/catalog.py check --kernel # the same fit from the kernel's claims, and drift +``` + +`scripts/check.sh` runs the first; a compose service added without an entry fails it. diff --git a/catalog/api-anthropic-api.yaml b/catalog/api-anthropic-api.yaml new file mode 100644 index 0000000..bce85b4 --- /dev/null +++ b/catalog/api-anthropic-api.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: anthropic-api + title: Anthropic's API +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "api.anthropic.com", + "version": "0" + }, + "paths": { + "/v1/messages": { + "post": { + "summary": "api.anthropic.com" + } + } + } + } diff --git a/catalog/api-anthropic-messages.yaml b/catalog/api-anthropic-messages.yaml new file mode 100644 index 0000000..e903fc0 --- /dev/null +++ b/catalog/api-anthropic-messages.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: anthropic-messages + title: Anthropic Messages at the gateway +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "Messages API, and the pass-through route for a Claude login", + "version": "0" + }, + "paths": { + "/anthropic/v1/messages": { + "post": { + "summary": "Messages API, and the pass-through route for a Claude login" + } + } + } + } diff --git a/catalog/api-block-note-with-count.yaml b/catalog/api-block-note-with-count.yaml new file mode 100644 index 0000000..ca0e06f --- /dev/null +++ b/catalog/api-block-note-with-count.yaml @@ -0,0 +1,45 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: block-note-with-count + title: The note_with_count plan + description: Count the words of a text and save it as a note. + annotations: + substrate.dev/trigger: '(?is)^save a note called (?P[\w-]+): (?P.+)$' +spec: + type: wot-td + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "@context": "https://www.w3.org/2022/wot/td/v1.1", + "title": "note_with_count", + "actions": { + "note_with_count": { + "input": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "text": { + "type": "string" + } + }, + "required": [ + "name", + "text" + ] + }, + "safe": false, + "forms": [ + { + "href": "substrate:blocks/run.py", + "subprotocol": "substrate-plan" + } + ] + } + } + } diff --git a/catalog/api-block-word-count.yaml b/catalog/api-block-word-count.yaml new file mode 100644 index 0000000..8fe59dd --- /dev/null +++ b/catalog/api-block-word-count.yaml @@ -0,0 +1,53 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: block-word-count + title: The word_count block + description: Counts the words in a text. + annotations: {} +spec: + type: wot-td + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "@context": "https://www.w3.org/2022/wot/td/v1.1", + "title": "word_count", + "actions": { + "word_count": { + "input": { + "type": "object", + "properties": { + "text": { + "type": "string" + } + }, + "required": [ + "text" + ] + }, + "output": { + "type": "object", + "properties": { + "words": { + "type": "integer" + } + }, + "required": [ + "words" + ] + }, + "safe": true, + "idempotent": true, + "forms": [ + { + "href": "stdio:python -I word_count:run", + "contentType": "application/json", + "subprotocol": "substrate-block-stdio" + } + ] + } + } + } diff --git a/catalog/api-block-write-note.yaml b/catalog/api-block-write-note.yaml new file mode 100644 index 0000000..995907e --- /dev/null +++ b/catalog/api-block-write-note.yaml @@ -0,0 +1,58 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: block-write-note + title: The write_note block + description: Writes a note into the worker's workspace (WORKER_WORKSPACE, default /workspace) as notes/.txt. + annotations: + substrate.dev/gate: blocks.write_note +spec: + type: wot-td + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "@context": "https://www.w3.org/2022/wot/td/v1.1", + "title": "write_note", + "actions": { + "write_note": { + "input": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "text": { + "type": "string" + } + }, + "required": [ + "name", + "text" + ] + }, + "output": { + "type": "object", + "properties": { + "path": { + "type": "string" + } + }, + "required": [ + "path" + ] + }, + "safe": false, + "idempotent": true, + "forms": [ + { + "href": "stdio:python -I write_note:run", + "contentType": "application/json", + "subprotocol": "substrate-block-stdio" + } + ] + } + } + } diff --git a/catalog/api-companion-channel.yaml b/catalog/api-companion-channel.yaml new file mode 100644 index 0000000..7c5cc5a --- /dev/null +++ b/catalog/api-companion-channel.yaml @@ -0,0 +1,18 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: companion-channel + title: The channel into Claude Code +spec: + type: mcp + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "protocol": "model-context-protocol", + "transport": "stdio", + "tools": [], + "note": "the claude/channel contract: signals in, archived only on ack (S-143)" + } diff --git a/catalog/api-companion-session.yaml b/catalog/api-companion-session.yaml new file mode 100644 index 0000000..db0c140 --- /dev/null +++ b/catalog/api-companion-session.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: companion-session + title: The companion's session queue +spec: + type: asyncapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "asyncapi": "3.0.0", + "info": { + "title": "signals for the companion's Claude Code session", + "version": "0" + }, + "channels": { + "companion_session": { + "address": "companion_session", + "description": "signals for the companion's Claude Code session" + } + }, + "x-transport": "pgmq (Postgres), the env schema's topics and queues (S-143)" + } diff --git a/catalog/api-embeddings.yaml b/catalog/api-embeddings.yaml new file mode 100644 index 0000000..529bbb8 --- /dev/null +++ b/catalog/api-embeddings.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: embeddings + title: Embeddings at the gateway +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "ollama/qwen3-embedding:0.6b", + "version": "0" + }, + "paths": { + "/v1/embeddings": { + "post": { + "summary": "ollama/qwen3-embedding:0.6b" + } + } + } + } diff --git a/catalog/api-kernel-mcp-memory.yaml b/catalog/api-kernel-mcp-memory.yaml new file mode 100644 index 0000000..64a8051 --- /dev/null +++ b/catalog/api-kernel-mcp-memory.yaml @@ -0,0 +1,23 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: kernel-mcp-memory + title: The kernel's memory profile +spec: + type: mcp + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "protocol": "model-context-protocol", + "transport": "stdio", + "tools": [ + "remember", + "recall", + "explain", + "changes_since" + ], + "note": "KK_PROFILE=memory" + } diff --git a/catalog/api-kernel-mcp-substrate.yaml b/catalog/api-kernel-mcp-substrate.yaml new file mode 100644 index 0000000..11525b6 --- /dev/null +++ b/catalog/api-kernel-mcp-substrate.yaml @@ -0,0 +1,29 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: kernel-mcp-substrate + title: The kernel's substrate profile +spec: + type: mcp + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "protocol": "model-context-protocol", + "transport": "stdio", + "tools": [ + "search", + "read", + "expand", + "locate", + "path", + "alternatives", + "violations", + "create_item", + "say", + "deprecate" + ], + "note": "KK_PROFILE=substrate" + } diff --git a/catalog/api-llama-chat-fast.yaml b/catalog/api-llama-chat-fast.yaml new file mode 100644 index 0000000..980aaf8 --- /dev/null +++ b/catalog/api-llama-chat-fast.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: llama-chat-fast + title: llama-server, the fast model +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "llama.cpp's OpenAI-compatible server at llm-fast:8080", + "version": "0" + }, + "paths": { + "/v1/chat/completions": { + "post": { + "summary": "llama.cpp's OpenAI-compatible server at llm-fast:8080" + } + } + } + } diff --git a/catalog/api-llama-chat-slow.yaml b/catalog/api-llama-chat-slow.yaml new file mode 100644 index 0000000..6f0d649 --- /dev/null +++ b/catalog/api-llama-chat-slow.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: llama-chat-slow + title: llama-server, the slow model +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "llama.cpp's OpenAI-compatible server at llm:8080", + "version": "0" + }, + "paths": { + "/v1/chat/completions": { + "post": { + "summary": "llama.cpp's OpenAI-compatible server at llm:8080" + } + } + } + } diff --git a/catalog/api-model-chat.yaml b/catalog/api-model-chat.yaml new file mode 100644 index 0000000..827451e --- /dev/null +++ b/catalog/api-model-chat.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: model-chat + title: OpenAI Chat Completions at the gateway +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "chat completions, tool calls, streaming; key in Authorization: Bearer or x-bf-vk", + "version": "0" + }, + "paths": { + "/v1/chat/completions": { + "post": { + "summary": "chat completions, tool calls, streaming; key in Authorization: Bearer or x-bf-vk" + } + } + } + } diff --git a/catalog/api-model-responses.yaml b/catalog/api-model-responses.yaml new file mode 100644 index 0000000..729ee31 --- /dev/null +++ b/catalog/api-model-responses.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: model-responses + title: OpenAI Responses at the gateway +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "the Responses API, translated by Bifrost (checked 2026-11-22)", + "version": "0" + }, + "paths": { + "/v1/responses": { + "post": { + "summary": "the Responses API, translated by Bifrost (checked 2026-11-22)" + } + } + } + } diff --git a/catalog/api-ollama-api.yaml b/catalog/api-ollama-api.yaml new file mode 100644 index 0000000..c1a8999 --- /dev/null +++ b/catalog/api-ollama-api.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: ollama-api + title: Ollama API +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "Ollama's native API", + "version": "0" + }, + "paths": { + "/api/embed": { + "post": { + "summary": "Ollama's native API" + } + } + } + } diff --git a/catalog/api-search-api.yaml b/catalog/api-search-api.yaml new file mode 100644 index 0000000..1c5ebc3 --- /dev/null +++ b/catalog/api-search-api.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: search-api + title: SearXNG search +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "q, format=json", + "version": "0" + }, + "paths": { + "/search": { + "get": { + "summary": "q, format=json" + } + } + } + } diff --git a/catalog/api-speech-api.yaml b/catalog/api-speech-api.yaml new file mode 100644 index 0000000..cc2d2a7 --- /dev/null +++ b/catalog/api-speech-api.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: speech-api + title: OpenAI-compatible speech +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "Kokoro-FastAPI; pcm or wav", + "version": "0" + }, + "paths": { + "/v1/audio/speech": { + "post": { + "summary": "Kokoro-FastAPI; pcm or wav" + } + } + } + } diff --git a/catalog/api-ui-http.yaml b/catalog/api-ui-http.yaml new file mode 100644 index 0000000..fb1c87d --- /dev/null +++ b/catalog/api-ui-http.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: ui-http + title: The UI +spec: + type: http + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "the pages; the API under /api", + "version": "0" + }, + "paths": { + "/": { + "get": { + "summary": "the pages; the API under /api" + } + } + } + } diff --git a/catalog/api-voice-ws.yaml b/catalog/api-voice-ws.yaml new file mode 100644 index 0000000..5bca126 --- /dev/null +++ b/catalog/api-voice-ws.yaml @@ -0,0 +1,18 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: voice-ws + title: The voice head's page and socket +spec: + type: websocket + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "page": "http://127.0.0.1:8110/", + "socket": "ws://127.0.0.1:8110/", + "in": "16 kHz int16 PCM frames; {type: stop}", + "out": "state, heard, say, audio (24 kHz PCM), error" + } diff --git a/catalog/api-wikipedia-rest.yaml b/catalog/api-wikipedia-rest.yaml new file mode 100644 index 0000000..c04254f --- /dev/null +++ b/catalog/api-wikipedia-rest.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: wikipedia-rest + title: Wikipedia REST +spec: + type: openapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "openapi": "3.1.0", + "info": { + "title": "then /api/rest_v1/page/summary/{title}", + "version": "0" + }, + "paths": { + "/w/rest.php/v1/search/page": { + "get": { + "summary": "then /api/rest_v1/page/summary/{title}" + } + } + } + } diff --git a/catalog/api-worker-results.yaml b/catalog/api-worker-results.yaml new file mode 100644 index 0000000..de3a3a2 --- /dev/null +++ b/catalog/api-worker-results.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: worker-results + title: The worker's results +spec: + type: asyncapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "asyncapi": "3.0.0", + "info": { + "title": "each task's outcome: text, ok, model_calls, skipped_calls, cited, reply_to", + "version": "0" + }, + "channels": { + "worker.task.done": { + "address": "worker.task.done", + "description": "each task's outcome: text, ok, model_calls, skipped_calls, cited, reply_to" + } + }, + "x-transport": "pgmq (Postgres), the env schema's topics and queues (S-143)" + } diff --git a/catalog/api-worker-tasks.yaml b/catalog/api-worker-tasks.yaml new file mode 100644 index 0000000..8c31a53 --- /dev/null +++ b/catalog/api-worker-tasks.yaml @@ -0,0 +1,26 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: worker-tasks + title: The worker's task queue +spec: + type: asyncapi + lifecycle: experimental + owner: owner + system: substrate + definition: |- + { + "asyncapi": "3.0.0", + "info": { + "title": "worker.owner.message and worker.task: tasks for the worker, which receives on this channel (so it provides it); the voice head and the UI publish to it; reply_to says who wants the answer", + "version": "0" + }, + "channels": { + "worker_loop": { + "address": "worker_loop", + "description": "worker.owner.message and worker.task: tasks for the worker, which receives on this channel (so it provides it); the voice head and the UI publish to it; reply_to says who wants the answer" + } + }, + "x-transport": "pgmq (Postgres), the env schema's topics and queues (S-143)" + } diff --git a/catalog/component-anthropic.yaml b/catalog/component-anthropic.yaml new file mode 100644 index 0000000..64f8bdf --- /dev/null +++ b/catalog/component-anthropic.yaml @@ -0,0 +1,16 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: anthropic + title: Anthropic API + description: Claude, reached only with a caller's own Claude login (the companion's). + annotations: + substrate.dev/licence: proprietary service +spec: + type: external-service + lifecycle: production + owner: owner + system: substrate + providesApis: + - anthropic-api diff --git a/catalog/component-block-word-count.yaml b/catalog/component-block-word-count.yaml new file mode 100644 index 0000000..16d9369 --- /dev/null +++ b/catalog/component-block-word-count.yaml @@ -0,0 +1,18 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: block-word-count + title: word_count + description: Counts the words of a text (blocks/examples/word_count). + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/source: blocks/examples/word_count + substrate.dev/decision: S-164 +spec: + type: block + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - block-word-count diff --git a/catalog/component-block-write-note.yaml b/catalog/component-block-write-note.yaml new file mode 100644 index 0000000..f34ade6 --- /dev/null +++ b/catalog/component-block-write-note.yaml @@ -0,0 +1,18 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: block-write-note + title: write_note + description: Writes a note into the worker's workspace; changes the world, behind blocks.write_note (S-164). + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/source: blocks/examples/write_note + substrate.dev/decision: S-164 +spec: + type: block + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - block-write-note diff --git a/catalog/component-companion.yaml b/catalog/component-companion.yaml new file mode 100644 index 0000000..8a31ba1 --- /dev/null +++ b/catalog/component-companion.yaml @@ -0,0 +1,23 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: companion + title: Claude Code (the companion) + description: An agent instance on the owner's Claude login through the gateway, fed by the channel (S-136). + annotations: + substrate.dev/licence: proprietary (Claude Code) + substrate.dev/image: ghcr.io/openreplicant/substrate-companion + substrate.dev/compose-service: companion + substrate.dev/decision: S-136, S-144 +spec: + type: agent + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - companion-channel + consumesApis: + - anthropic-messages + - companion-session + - kernel-mcp-substrate diff --git a/catalog/component-environment.yaml b/catalog/component-environment.yaml new file mode 100644 index 0000000..6ffc1c6 --- /dev/null +++ b/catalog/component-environment.yaml @@ -0,0 +1,21 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: environment + title: The companion's environment + description: Its streams, actuators and gates on pgmq; the clock and the meter (environment/companion.py). + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/openreplicant/substrate-tools + substrate.dev/compose-service: environment + substrate.dev/decision: S-143, S-144 +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - companion-session + dependsOn: + - resource:db diff --git a/catalog/component-gateway.yaml b/catalog/component-gateway.yaml new file mode 100644 index 0000000..0fb8d66 --- /dev/null +++ b/catalog/component-gateway.yaml @@ -0,0 +1,30 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: gateway + title: Bifrost + description: Every model call passes here, under its caller's key, and is logged (S-77). + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: docker.io/maximhq/bifrost:v2.3.2 + substrate.dev/compose-service: gateway + substrate.dev/decision: S-04, S-77 + substrate.dev/otel-service: bifrost +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - model-chat + - model-responses + - anthropic-messages + - embeddings + consumesApis: + - ollama-api + - llama-chat-slow + - llama-chat-fast + - anthropic-api + dependsOn: + - resource:db diff --git a/catalog/component-judge.yaml b/catalog/component-judge.yaml new file mode 100644 index 0000000..2c62f2d --- /dev/null +++ b/catalog/component-judge.yaml @@ -0,0 +1,21 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: judge + title: The judge + description: Tests a component's candidate against the active one on cases its author never read (S-151). + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/openreplicant/substrate-tools + substrate.dev/compose-service: judge + substrate.dev/decision: S-151 +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + consumesApis: + - model-chat + dependsOn: + - resource:db diff --git a/catalog/component-kernel-catalog.yaml b/catalog/component-kernel-catalog.yaml new file mode 100644 index 0000000..1e13f26 --- /dev/null +++ b/catalog/component-kernel-catalog.yaml @@ -0,0 +1,21 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: kernel-catalog + title: encoder-backstage + description: Reads catalog/*.yaml, these entries, into the kernel as claims citing their lines (scripts/kernel.sh catalog); + a one-shot job. + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/openreplicant/kernel + substrate.dev/compose-service: kernel-catalog + substrate.dev/decision: S-176, the kernel's D-100 +spec: + type: job + lifecycle: experimental + owner: owner + system: substrate + dependsOn: + - resource:db + - component:kernel diff --git a/catalog/component-kernel-export.yaml b/catalog/component-kernel-export.yaml new file mode 100644 index 0000000..52c94d9 --- /dev/null +++ b/catalog/component-kernel-export.yaml @@ -0,0 +1,20 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: kernel-export + title: encoder-substrate + description: Exports the retired store's items into the kernel as change sets (scripts/kernel.sh export); a one-shot job. + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/openreplicant/kernel + substrate.dev/compose-service: kernel-export + substrate.dev/decision: S-154, the kernel's D-103 +spec: + type: job + lifecycle: experimental + owner: owner + system: substrate + dependsOn: + - resource:db + - component:kernel diff --git a/catalog/component-kernel-init.yaml b/catalog/component-kernel-init.yaml new file mode 100644 index 0000000..1f87ad1 --- /dev/null +++ b/catalog/component-kernel-init.yaml @@ -0,0 +1,20 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: kernel-init + title: kk init + description: Installs the kernel's schema, modules and packs in the database kernel (scripts/kernel.sh init); a one-shot + job. + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/openreplicant/kernel + substrate.dev/compose-service: kernel-init + substrate.dev/decision: S-154 +spec: + type: job + lifecycle: experimental + owner: owner + system: substrate + dependsOn: + - resource:db diff --git a/catalog/component-kernel-mcp.yaml b/catalog/component-kernel-mcp.yaml new file mode 100644 index 0000000..8d733a7 --- /dev/null +++ b/catalog/component-kernel-mcp.yaml @@ -0,0 +1,21 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: kernel-mcp + title: kernel-mcp + description: The kernel's MCP server, run per agent over stdio with the agent's own login. + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/openreplicant/kernel + substrate.dev/decision: S-154, the kernel's D-88, D-105 +spec: + type: tool + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - kernel-mcp-memory + - kernel-mcp-substrate + dependsOn: + - component:kernel diff --git a/catalog/component-kernel.yaml b/catalog/component-kernel.yaml new file mode 100644 index 0000000..27a197c --- /dev/null +++ b/catalog/component-kernel.yaml @@ -0,0 +1,19 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: kernel + title: The Knowledge Kernel + description: Claims with provenance, belief and clearance; validator and belief model (kk serve). + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/openreplicant/kernel + substrate.dev/compose-service: kernel + substrate.dev/decision: S-153, S-154 +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + dependsOn: + - resource:db diff --git a/catalog/component-llm-fast.yaml b/catalog/component-llm-fast.yaml new file mode 100644 index 0000000..71a0407 --- /dev/null +++ b/catalog/component-llm-fast.yaml @@ -0,0 +1,19 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: llm-fast + title: 'llama.cpp: the fast model' + description: A small model wholly on the GPU, fast/fast (S-169). + annotations: + substrate.dev/licence: MIT (llama.cpp); the model's own (LFM Open License v1.0 for LFM3) + substrate.dev/image: ghcr.io/ggml-org/llama.cpp:server-cuda12-b12627 + substrate.dev/compose-service: llm-fast + substrate.dev/decision: S-169 +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - llama-chat-fast diff --git a/catalog/component-llm.yaml b/catalog/component-llm.yaml new file mode 100644 index 0000000..472c608 --- /dev/null +++ b/catalog/component-llm.yaml @@ -0,0 +1,19 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: llm + title: 'llama.cpp: the slow model' + description: Inkling 2 Mini on the CPU and in RAM, local/slow (S-169). + annotations: + substrate.dev/licence: MIT (llama.cpp); Apache-2.0 (Inkling 2 Mini) + substrate.dev/image: ghcr.io/ggml-org/llama.cpp:server-cuda12-b12627 + substrate.dev/compose-service: llm + substrate.dev/decision: S-169 +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - llama-chat-slow diff --git a/catalog/component-ollama.yaml b/catalog/component-ollama.yaml new file mode 100644 index 0000000..8f3ff4f --- /dev/null +++ b/catalog/component-ollama.yaml @@ -0,0 +1,19 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: ollama + title: Ollama + description: Local embeddings for the store and the voice router (qwen3-embedding:0.6b). + annotations: + substrate.dev/licence: MIT + substrate.dev/image: docker.io/ollama/ollama:0.40.12 + substrate.dev/compose-service: ollama + substrate.dev/decision: S-83 +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - ollama-api diff --git a/catalog/component-plan-note-with-count.yaml b/catalog/component-plan-note-with-count.yaml new file mode 100644 index 0000000..9fe19e9 --- /dev/null +++ b/catalog/component-plan-note-with-count.yaml @@ -0,0 +1,21 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: plan-note-with-count + title: note_with_count + description: 'The example plan: count the words, then save the note (blocks/examples/plans).' + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/source: blocks/examples/plans/note.plan.json + substrate.dev/decision: S-164 +spec: + type: plan + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - block-note-with-count + consumesApis: + - block-word-count + - block-write-note diff --git a/catalog/component-search.yaml b/catalog/component-search.yaml new file mode 100644 index 0000000..1b88934 --- /dev/null +++ b/catalog/component-search.yaml @@ -0,0 +1,19 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: search + title: SearXNG + description: Web search for the voice head's search tool; no host port (S-171). + annotations: + substrate.dev/licence: AGPL-3.0 + substrate.dev/image: docker.io/searxng/searxng:2026.11.8-74418092d + substrate.dev/compose-service: search + substrate.dev/decision: S-171 +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - search-api diff --git a/catalog/component-tts.yaml b/catalog/component-tts.yaml new file mode 100644 index 0000000..b7b08b1 --- /dev/null +++ b/catalog/component-tts.yaml @@ -0,0 +1,19 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: tts + title: Kokoro-FastAPI + description: Speech on the GPU (S-150). + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/remsky/kokoro-fastapi-gpu:latest + substrate.dev/compose-service: tts + substrate.dev/decision: S-150 +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - speech-api diff --git a/catalog/component-ui.yaml b/catalog/component-ui.yaml new file mode 100644 index 0000000..d85f31d --- /dev/null +++ b/catalog/component-ui.yaml @@ -0,0 +1,25 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: ui + title: The UI + description: The store's pages and maps, the companion's and worker's pages (127.0.0.1:8100). + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/openreplicant/substrate-tools + substrate.dev/compose-service: ui + substrate.dev/decision: S-140, S-141 +spec: + type: website + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - ui-http + consumesApis: + - worker-tasks + - companion-session + dependsOn: + - resource:db + - component:kernel diff --git a/catalog/component-voice.yaml b/catalog/component-voice.yaml new file mode 100644 index 0000000..2f22e94 --- /dev/null +++ b/catalog/component-voice.yaml @@ -0,0 +1,29 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: voice + title: The voice head + description: Microphone in, speech out, the avatar; the fast layer's tools (S-147, S-170, S-171). + annotations: + substrate.dev/licence: Apache-2.0 (ours); GPL-3.0 espeak-ng in its own container (S-146) + substrate.dev/image: localhost/substrate-voice:local + substrate.dev/compose-service: voice + substrate.dev/decision: S-147, S-170, S-171 +spec: + type: service + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - voice-ws + consumesApis: + - model-chat + - embeddings + - speech-api + - search-api + - wikipedia-rest + - worker-tasks + - worker-results + dependsOn: + - resource:db diff --git a/catalog/component-wikipedia.yaml b/catalog/component-wikipedia.yaml new file mode 100644 index 0000000..d9e2d4c --- /dev/null +++ b/catalog/component-wikipedia.yaml @@ -0,0 +1,16 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: wikipedia + title: Wikipedia + description: Its REST search and page summaries, for the voice head's lookup tool (S-171). + annotations: + substrate.dev/licence: CC BY-SA (content) +spec: + type: external-service + lifecycle: production + owner: owner + system: substrate + providesApis: + - wikipedia-rest diff --git a/catalog/component-worker.yaml b/catalog/component-worker.yaml new file mode 100644 index 0000000..805ae60 --- /dev/null +++ b/catalog/component-worker.yaml @@ -0,0 +1,25 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: worker + title: The worker + description: An agent on the slow local model with the kernel's memory and workspace tools (S-163). + annotations: + substrate.dev/licence: Apache-2.0 + substrate.dev/image: ghcr.io/openreplicant/substrate-worker + substrate.dev/compose-service: worker + substrate.dev/decision: S-162, S-163 +spec: + type: agent + lifecycle: experimental + owner: owner + system: substrate + providesApis: + - worker-tasks + - worker-results + consumesApis: + - model-chat + - kernel-mcp-memory + - companion-session + - block-note-with-count diff --git a/catalog/group-owner.yaml b/catalog/group-owner.yaml new file mode 100644 index 0000000..89e609d --- /dev/null +++ b/catalog/group-owner.yaml @@ -0,0 +1,9 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Group +metadata: + name: owner + description: 'The owner: the person who decides.' +spec: + type: person + children: [] diff --git a/catalog/resource-db.yaml b/catalog/resource-db.yaml new file mode 100644 index 0000000..cdf5d18 --- /dev/null +++ b/catalog/resource-db.yaml @@ -0,0 +1,16 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: Resource +metadata: + name: db + title: Postgres 17 (pgvector, pg_cron, pgmq, pgGraph) + description: 'The one database: the env schema, the kernel''s database, the gateway''s log.' + annotations: + substrate.dev/licence: PostgreSQL + substrate.dev/image: ghcr.io/openreplicant/substrate-db + substrate.dev/compose-service: db + substrate.dev/decision: S-19, the kernel's D-94 +spec: + type: database + owner: owner + system: substrate diff --git a/catalog/system-substrate.yaml b/catalog/system-substrate.yaml new file mode 100644 index 0000000..ff808f5 --- /dev/null +++ b/catalog/system-substrate.yaml @@ -0,0 +1,8 @@ +# A catalog entry (S-176): Backstage's entity format, read into the kernel by encoder-backstage. +apiVersion: backstage.io/v1alpha1 +kind: System +metadata: + name: substrate + description: 'Substrate: an environment put on a system, run, watched and changed; its own parts as catalog entries (S-174).' +spec: + owner: owner diff --git a/deploy/compose.yaml b/deploy/compose.yaml index b1c3628..ef22998 100644 --- a/deploy/compose.yaml +++ b/deploy/compose.yaml @@ -139,6 +139,29 @@ services: depends_on: db: {condition: service_healthy} + # Substrate's catalog into the kernel (S-176): encoder-backstage (the kernel's D-100) reads catalog/*.yaml, one Backstage + # entity per file, as claims in Backstage's terms, each citing its file and line; each file is kept as an artifact in + # the volume kernel-artifacts. An unchanged file submits nothing; a changed one supersedes what it said + # (scripts/kernel.sh catalog). Profile kernel-admin: run, not kept running. + kernel-catalog: + profiles: [kernel-admin] + image: ghcr.io/openreplicant/kernel:${KERNEL_IMAGE_TAG:-main} + # --root /: files are recorded as substrate/catalog/ whatever the image's working directory (a different root + # re-keys every file: the kernel's D-125 lesson) + entrypoint: ["sh", "-c", "exec python3 -m encoder_backstage --project substrate --root / /substrate/catalog/*.yaml"] + read_only: true + cap_drop: [ALL] + security_opt: [no-new-privileges:true] + tmpfs: [/tmp] + environment: + DATABASE_URL: postgresql://kk_authenticator:${KK_AUTHENTICATOR_PASSWORD:?set in .env}@db:5432/kernel + KK_ARTIFACTS: /artifacts + volumes: + - ../catalog:/substrate/catalog:ro + - kernel-artifacts:/artifacts + depends_on: + db: {condition: service_healthy} + # The UI (S-140, S-141: Substrate's UI, no name of its own): the store's pages and maps, read-only, on the standard # library (ui/server.py) in the tools image. It sees only ui/ and reaches Postgres as db: the entities, pages and # maps from the kernel's read model (S-154), the companion's page from the substrate database. @@ -432,6 +455,8 @@ services: gateway: {condition: service_started} volumes: + kernel-artifacts: + name: ${KERNEL_ARTIFACTS_VOLUME:-substrate_kernel-artifacts} # the kernel's artifact store: catalog files as they were read search-cache: worker-workspace: name: ${WORKER_VOLUME:-substrate_worker-workspace} # the only place its file tools reach diff --git a/docs/plan.md b/docs/plan.md index 6caa40b..59169f9 100644 --- a/docs/plan.md +++ b/docs/plan.md @@ -95,9 +95,13 @@ are views of the same items and claims; what can be said in one format can be ca 1. **The catalog entry content type** (D-101's first): a component's item with its interfaces described WoT-style, and a compatibility check between two entries. Done when Substrate's own parts are entries and the check says - which talk to which. + which talk to which. — done 2026-11-22 (S-176): `catalog/` in Backstage's entity format, read by the kernel's + `encoder-backstage`; `scripts/catalog.py check` over files, compose and the kernel. Left for the kernel: the + current-version link and the per-type items view (D-101). 2. **The first decoder and encoder: the map to and from Compose,** with Substrate's own `deploy/compose.yaml` as the - test (decoded from the map, it should match what runs; the running state encoded back). + test (decoded from the map, it should match what runs; the running state encoded back). — built 2026-11-22 (S-177, the + kernel's D-125): `encoder-compose` and `decoder-compose`; Substrate's compose file round-trips through the kernel. + Left: the running state encoded back, and a `scripts/kernel.sh compose` job once the kernel image has the modules. 3. **M-17's gate at the model endpoint**, then M-17's first experiment (the handoff, 2026-11-22). 4. **The telemetry collector and a process runtime** (process-compose first), picked with the `research` skill, as the second decoder target. diff --git a/scripts/catalog.py b/scripts/catalog.py new file mode 100644 index 0000000..13fda82 --- /dev/null +++ b/scripts/catalog.py @@ -0,0 +1,180 @@ +"""Substrate's catalog (S-176): its parts as Backstage entity files in catalog/, one per entity, which the kernel reads +with encoder-backstage (the kernel's D-100). This script checks them, without the kernel: + +- **fit**: every API a component consumes has a provider; every API is provided by someone; every reference + (providesApis, consumesApis, dependsOn, owner, system) names an entity that exists; +- **what uses what**: each component that uses some APIs to provide others (the gateway uses llama-server's API to + provide its own chat API, a translator; the voice head uses several to provide its page); where two parts share no + API, a translator from the catalog has to go between them; +- **compose**: the catalog against deploy/compose.yaml, both ways: a service with no entry, an entry naming a service + compose does not have; +- **kernel** (`--kernel`): the same fit read from the kernel's claims (what `scripts/kernel.sh catalog` put there, through + the read model, under its own role), and the drift between the files and the kernel: a provides or consumes in one + and not the other (a file changed and not yet encoded). + + bin/in-tools python3 scripts/catalog.py check [--compose deploy/compose.yaml] [--kernel] + bin/in-tools python3 scripts/catalog.py apis # each API with its providers and consumers + +Exit 1 when a check fails. Needs PyYAML (the tools container has it). +""" +from __future__ import annotations + +import argparse +import sys +from pathlib import Path + +import yaml + +ROOT = Path(__file__).resolve().parents[1] +ANN = "substrate.dev/" + + +def load(directory: Path) -> dict[tuple[str, str], dict]: + """(kind, name) -> entity, lower-cased kind; every document of every *.yaml file.""" + out: dict[tuple[str, str], dict] = {} + for f in sorted(directory.glob("*.yaml")): + for doc in yaml.safe_load_all(f.read_text(encoding="utf-8")): + if not isinstance(doc, dict) or "kind" not in doc: + continue + key = (doc["kind"].lower(), doc["metadata"]["name"]) + if key in out: + raise SystemExit(f"{f.name}: {key[0]}:{key[1]} is defined twice") + doc["_file"] = f.name + out[key] = doc + return out + + +def ref(r: str, default_kind: str) -> tuple[str, str]: + """A Backstage entity reference: [kind:][namespace/]name.""" + kind, _, name = r.rpartition(":") + return (kind or default_kind).lower(), name.split("/")[-1] + + +def apis(ents: dict) -> dict[str, dict[str, list[str]]]: + table = {n: {"providers": [], "consumers": []} for (k, n) in ents if k == "api"} + for (k, n), e in ents.items(): + if k != "component": + continue + for a in e["spec"].get("providesApis") or []: + table.setdefault(ref(a, "api")[1], {"providers": [], "consumers": []})["providers"].append(n) + for a in e["spec"].get("consumesApis") or []: + table.setdefault(ref(a, "api")[1], {"providers": [], "consumers": []})["consumers"].append(n) + return table + + +def check(ents: dict, compose: Path | None) -> list[str]: + problems: list[str] = [] + table = apis(ents) + for name, t in sorted(table.items()): + if ("api", name) not in ents: + problems.append(f"API {name} is referenced ({', '.join(t['providers'] + t['consumers'])}) but has no entry") + if not t["providers"]: + who = f", consumed by {', '.join(t['consumers'])}" if t["consumers"] else "" + problems.append(f"gap: no component provides API {name}{who}") + for (k, n), e in ents.items(): + spec = e.get("spec") or {} + for field, default in (("dependsOn", "component"), ("owner", "group"), ("system", "system")): + vals = spec.get(field) + for r in ([vals] if isinstance(vals, str) else vals or []): + if ref(r, default) not in ents: + problems.append(f"{k}:{n} ({e['_file']}): {field} {r} names no entity") + if compose: + services = set((yaml.safe_load(compose.read_text(encoding="utf-8")).get("services") or {})) + named = {e["metadata"].get("annotations", {}).get(ANN + "compose-service"): f"{k}:{n}" + for (k, n), e in ents.items() if e["metadata"].get("annotations", {}).get(ANN + "compose-service")} + for s in sorted(services - set(named)): + problems.append(f"compose service {s} has no catalog entry") + for s, who in sorted(named.items()): + if s not in services: + problems.append(f"{who} names compose service {s}, which {compose.name} does not have") + return problems + + +BS = "https://w3id.org/knowledge-kernel/backstage#" +SYSTEM = "urn:kk:system:substrate" + + +def kernel_links() -> set[tuple[str, str, str]]: + """(component, providesApi|consumesApi, api) for every component part of Substrate's system, from the kernel's + usable claims, read as the read model's role (as the UI reads them).""" + import os + import psycopg + sys.path[:0] = [str(ROOT / "scripts"), str(ROOT)] + from db import kernel_url + from gateway import settings + url = os.environ.get("KERNEL_URL") or kernel_url(settings()) + with psycopg.connect(url, connect_timeout=10) as c: + c.execute("set role kkm_view_substrate") + rows = c.execute( + "select u.subject, u.predicate, u.object_entity from substrate.usable u where u.predicate = any(%s) and " + "exists (select 1 from substrate.usable p where p.subject = u.subject and p.predicate = %s and p.object_entity = %s)", + ([BS + "providesApi", BS + "consumesApi"], BS + "partOf", SYSTEM)).fetchall() + name = lambda iri: iri.rsplit(":", 1)[-1] # noqa: E731 + return {(name(s), p.rsplit("#", 1)[-1], name(o)) for s, p, o in rows} + + +def file_links(ents: dict) -> set[tuple[str, str, str]]: + out = set() + for (k, n), e in ents.items(): + if k == "component": + for field, rel in (("providesApis", "providesApi"), ("consumesApis", "consumesApi")): + out |= {(n, rel, ref(a, "api")[1]) for a in e["spec"].get(field) or []} + return out + + +def check_kernel(ents: dict) -> tuple[list[str], int]: + links = kernel_links() + problems = [] + provided = {a for _, r, a in links if r == "providesApi"} + for c, r, a in sorted(links): + if r == "consumesApi" and a not in provided: + problems.append(f"kernel: gap: {c} consumes {a}, which no component of the system provides") + f = file_links(ents) + for c, r, a in sorted(f - links): + problems.append(f"drift: the files say {c} {r} {a}; the kernel does not (scripts/kernel.sh catalog)") + for c, r, a in sorted(links - f): + problems.append(f"drift: the kernel says {c} {r} {a}; the files do not") + return problems, len(links) + + +def translators(ents: dict) -> list[tuple[str, list[str], list[str]]]: + """Components that provide some APIs by consuming others: the bridges in the map.""" + out = [] + for (k, n), e in sorted(ents.items()): + if k == "component" and e["spec"].get("providesApis") and e["spec"].get("consumesApis"): + out.append((n, e["spec"]["consumesApis"], e["spec"]["providesApis"])) + return out + + +def main() -> None: + ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) + ap.add_argument("command", choices=["check", "apis"]) + ap.add_argument("--catalog", default=str(ROOT / "catalog")) + ap.add_argument("--compose", default=None, help="a compose file to compare with (check)") + ap.add_argument("--kernel", action="store_true", help="also check the kernel's claims, and their drift from the files") + a = ap.parse_args() + ents = load(Path(a.catalog)) + if a.command == "apis": + for name, t in sorted(apis(ents).items()): + typ = ents.get(("api", name), {}).get("spec", {}).get("type", "?") + print(f"{name} [{typ}]: provided by {', '.join(t['providers']) or 'nobody'}; consumed by {', '.join(t['consumers']) or 'nobody'}") + return + problems = check(ents, Path(a.compose) if a.compose else None) + if a.kernel: + kp, n = check_kernel(ents) + print(f"kernel: {n} provides and consumes links of {SYSTEM}") + problems += kp + kinds = {} + for (k, _) in ents: + kinds[k] = kinds.get(k, 0) + 1 + print("catalog: " + ", ".join(f"{v} {k}" for k, v in sorted(kinds.items()))) + for n, ins, outs in translators(ents): + print(f" {n} uses {', '.join(ins)} to provide {', '.join(outs)}") + for p in problems: + print(" FAIL " + p) + print("ok: every consumed API has a provider and every reference resolves" if not problems else f"{len(problems)} problem(s)") + sys.exit(1 if problems else 0) + + +if __name__ == "__main__": + main() diff --git a/scripts/check.sh b/scripts/check.sh index b650a1f..272ea73 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -105,6 +105,10 @@ say "Wiring" if st=$(sec_status 2>&1); then ok "secrets ($SECRETS): $st"; else bad "secrets ($SECRETS): $st"; fi "$ROOT/scripts/tools.sh" status >/dev/null 2>&1 && ok "tools container running (bin/ wrappers work)" || bad "tools container not running: scripts/tools.sh start" "$ROOT/bin/gitleaks" version >/dev/null 2>&1 && ok "gitleaks in the tools container: $("$ROOT/bin/gitleaks" version 2>/dev/null)" || bad "bin/gitleaks does not run" +# The catalog (S-176): every part an entry, every consumed API provided, every compose service described +if out=$("$ROOT/bin/in-tools" python3 "$ROOT/scripts/catalog.py" check --compose "$ROOT/deploy/compose.yaml" 2>&1); then + ok "catalog $(printf '%s\n' "$out" | head -1 | sed 's/^catalog: //'); fits, matches compose" +else bad "catalog: $(printf '%s\n' "$out" | grep FAIL | head -2 | sed 's/^ *FAIL *//' | tr '\n' ';') (bin/in-tools python3 scripts/catalog.py check --compose deploy/compose.yaml)"; fi # where the local model server computes: its last device report (S-84) dev=$(rt_logs ollama 2>/dev/null | grep 'msg="inference compute"' | tail -1 | sed -n 's/.*library=\([^ ]*\).*description="\([^"]*\)".*total="\([^"]*\)".*/\1 on \2, \3/p') gpu=$(env_value OLLAMA_GPU) diff --git a/scripts/kernel.sh b/scripts/kernel.sh index 7c7fb4c..c5290a8 100755 --- a/scripts/kernel.sh +++ b/scripts/kernel.sh @@ -6,6 +6,8 @@ # scripts/kernel.sh init # install the kernel's schema and default modules (safe to run again) # scripts/kernel.sh export # the store's items and statements as kernel change sets (safe to run again: # # an unchanged item submits nothing); the kernel service applies them +# scripts/kernel.sh catalog # catalog/*.yaml (Substrate's parts, Backstage entities) into the kernel by +# # encoder-backstage (S-176); an unchanged file submits nothing # scripts/kernel.sh login NAME # an agent's own login (printed nowhere: .state/kernel/NAME.env, mode 600) and # # its MCP entry `kernel` in .mcp.json (the profile substrate: ten tools) # scripts/kernel.sh login NAME --no-mcp-json # the same, without touching .mcp.json (the worker's: up.sh runs it) @@ -24,6 +26,9 @@ case "${1:-}" in export) compose run --rm --no-deps kernel-export ;; + catalog) + compose run --rm --no-deps kernel-catalog + ;; login) name=${2:?usage: scripts/kernel.sh login NAME [--no-mcp-json]} nomcp=${3:-} diff --git a/scripts/tests/test_catalog.py b/scripts/tests/test_catalog.py new file mode 100644 index 0000000..d37b525 --- /dev/null +++ b/scripts/tests/test_catalog.py @@ -0,0 +1,77 @@ +"""Substrate's catalog and its check (S-176). No database: catalog files in a temporary folder. +It should: +- pass on the repository's own catalog/ against deploy/compose.yaml +- report an API nobody provides, an API referenced with no entry, a reference to no entity +- report a compose service with no entry, and an entry naming a service compose does not have +- list what each component uses to provide what +- refuse an entity defined twice + + python3 scripts/tests/test_catalog.py +""" +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +sys.path.insert(0, str(ROOT / "scripts")) + +import catalog as C # noqa: E402 + +checks = [] + + +def check(name, ok, detail=""): + checks.append(bool(ok)) + print(("ok " if ok else "FAIL"), name, "" if ok else detail) + + +def ent(kind, name, spec=None, annotations=None): + md = {"name": name, **({"annotations": annotations} if annotations else {})} + import yaml + return yaml.safe_dump({"apiVersion": "backstage.io/v1alpha1", "kind": kind, "metadata": md, "spec": spec or {}}) + + +def folder(files: dict) -> Path: + d = Path(tempfile.mkdtemp()) + for n, text in files.items(): + (d / n).write_text(text) + return d + + +def main(): + ents = C.load(ROOT / "catalog") + problems = C.check(ents, ROOT / "deploy/compose.yaml") + check("the repository's catalog fits and matches compose", problems == [], problems) + check("it describes its components and their APIs", sum(k == "component" for k, _ in ents) >= 20 and sum(k == "api" for k, _ in ents) >= 20) + check("the gateway is listed as using the model servers to provide the chat API", + any(n == "gateway" and "llama-chat-slow" in ins and "model-chat" in outs for n, ins, outs in C.translators(ents))) + + base = {"system.yaml": ent("System", "s", {"owner": "group:o"}), "group.yaml": ent("Group", "o", {"type": "team"})} + d = folder({**base, + "a.yaml": ent("Component", "a", {"owner": "o", "system": "s", "consumesApis": ["x"], "dependsOn": ["resource:db"]}, + {"substrate.dev/compose-service": "a"}), + "b.yaml": ent("Component", "b", {"owner": "o", "system": "s", "providesApis": ["y"]}, + {"substrate.dev/compose-service": "gone"}), + "x.yaml": ent("API", "x", {"type": "openapi", "owner": "o", "system": "s"})}) + compose = d / "compose.yaml" + compose.write_text("services:\n a: {image: a}\n extra: {image: e}\n") + p = C.check(C.load(d), compose) + check("an API nobody provides is a gap, with who consumes it", any("gap: no component provides API x, consumed by a" in m for m in p), p) + check("an API referenced with no entry is reported", any("API y is referenced" in m for m in p), p) + check("a reference to no entity is reported", any("dependsOn resource:db names no entity" in m for m in p), p) + check("a compose service with no entry is reported", any("compose service extra has no catalog entry" in m for m in p), p) + check("an entry naming a service compose does not have is reported", any("names compose service gone" in m for m in p), p) + + twice = folder({"one.yaml": ent("API", "x"), "two.yaml": ent("API", "x")}) + try: + C.load(twice) + check("an entity defined twice is refused", False) + except SystemExit as e: + check("an entity defined twice is refused", "defined twice" in str(e), e) + + print(f"{sum(checks)}/{len(checks)} checks passed") + sys.exit(0 if all(checks) else 1) + + +if __name__ == "__main__": + main()