From 5e4cea238919aab9a16fb0b235c0f36e0b607d86 Mon Sep 17 00:00:00 2001 From: OpenReplicant <122761100+OpenReplicant@users.noreply.github.com> Date: Fri, 27 Nov 2026 06:52:14 -0800 Subject: [PATCH 1/3] Preview release prep (WIP): pinned image versions, the desktop's app ports and the tools container as settings Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KhsqyyPmp7iKCkTFcXs6sh --- .env.example | 21 +++++++++--- VERSION | 1 + bin/in-tools | 10 +++--- deploy/caddy/Caddyfile | 10 ++++-- deploy/caddy/apps.json | 6 ++-- deploy/compose.yaml | 35 +++++++++++--------- scripts/assistant.sh | 5 +-- scripts/build.sh | 20 +++++++---- scripts/check.sh | 14 +++++--- scripts/lib.sh | 16 +++++---- scripts/tests/test_release.py | 62 +++++++++++++++++++++++++++++++++++ scripts/tools.sh | 9 ++++- 12 files changed, 161 insertions(+), 48 deletions(-) create mode 100644 VERSION create mode 100644 scripts/tests/test_release.py diff --git a/.env.example b/.env.example index ba54481..594a9b6 100644 --- a/.env.example +++ b/.env.example @@ -9,6 +9,11 @@ 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 compose project: its containers are named after it (PROJECT-db-1, ...). A second instance on one machine needs a +# name of its own here, its own TOOLS_CONTAINER, volumes (DB_VOLUME, OLLAMA_VOLUME, KERNEL_ARTIFACTS_VOLUME) and ports +COMPOSE_PROJECT_NAME=substrate +# the tools container (scripts/tools.sh), which bin/ runs commands in +TOOLS_CONTAINER=substrate-tools # the optional services compose starts beside the core: llm (the local models); comma-separated, e.g. llm; empty: # the core only COMPOSE_PROFILES= @@ -19,6 +24,8 @@ POSTGRES_PASSWORD= DB_PORT=5432 # the volume its data lives in; a second instance on one machine needs its own DB_VOLUME=substrate_db-data +# the kernel's artifact store (catalog files as they were read); a second instance needs its own +KERNEL_ARTIFACTS_VOLUME=substrate_kernel-artifacts # ---- models (S-75, S-77) # OpenRouter's API key; empty: no OpenRouter @@ -43,8 +50,13 @@ GATEWAY_IMAGE=docker.io/maximhq/bifrost:v2.3.2 GATEWAY_PORT=8090 # the UI (S-140) on the host; change it if 8100 is taken UI_PORT=8100 -# the desktop (Caddy, S-199) on the host; change it if 8080 is taken (its framed apps stay on 8081 to 8083) +# the desktop (Caddy, S-199) on the host; change it if 8080 is taken DESKTOP_PORT=8080 +# the desktop's framed apps on the host, each on an origin of its own (S-200): the gateway's dashboard, the map pages, +# the MCP router (its page, and its MCP endpoint at /mcp); change one if it is taken +DESKTOP_GATEWAY_PORT=8081 +DESKTOP_MAPS_PORT=8082 +DESKTOP_ROUTER_PORT=8083 # ---- the Knowledge Kernel (S-153, S-154): the store, in its own database `kernel` in this Postgres # the kernel's database as the UI reaches it; empty: the `kernel` database in this Postgres, as the kernel's @@ -91,8 +103,9 @@ LLM_FAST_ALIAS=fast LLM_FAST_ARGS=-ngl 999 -t 2 -c 32768 -fa on -ctk q8_0 -ctv q8_0 # ---- 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 +# the tag of Substrate's images, and of the kernel's: this release's and the kernel release it was tested with (VERSION); +# main follows the main branches (what a working checkout wants), a short commit pins one build +SUBSTRATE_IMAGE_TAG=0.1.0-preview.1 +KERNEL_IMAGE_TAG=0.1.0 # 1: build every image here instead of pulling SUBSTRATE_BUILD= diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..2833354 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0-preview.1 diff --git a/bin/in-tools b/bin/in-tools index faef50d..5ee2fad 100755 --- a/bin/in-tools +++ b/bin/in-tools @@ -1,14 +1,16 @@ #!/bin/sh -# Run a command inside the substrate-tools container (S-19). The other files in bin/ call this; Claude Code +# Run a command inside the tools container (S-19; TOOLS_CONTAINER in .env, default substrate-tools). The other files in bin/ call this; Claude Code # calls them from hooks, so it stays small and fast (no .env parsing beyond one line). # # bin/in-tools COMMAND [ARGS...] root=$(cd "$(dirname "$0")/.." && pwd) engine=${CONTAINER_ENGINE:-$(sed -n 's/^CONTAINER_ENGINE=//p' "$root/.env" 2>/dev/null | tail -1)} engine=${engine:-podman} +name=${TOOLS_CONTAINER:-$(sed -n 's/^TOOLS_CONTAINER=//p' "$root/.env" 2>/dev/null | tail -1)} +name=${name:-substrate-tools} -if [ "$($engine inspect -f '{{.State.Running}}' substrate-tools 2>/dev/null)" != "true" ]; then - echo "substrate-tools is not running: $root/scripts/tools.sh start" >&2 +if [ "$($engine inspect -f '{{.State.Running}}' "$name" 2>/dev/null)" != "true" ]; then + echo "$name is not running: $root/scripts/tools.sh start" >&2 exit 1 fi @@ -23,4 +25,4 @@ for v in DATABASE_URL CLAUDE_PROJECT_DIR CLAUDE_SESSION_ID; do eval "isset=\${$v+x}"; [ -n "$isset" ] && envs="$envs -e $v" done # shellcheck disable=SC2086 -exec "$engine" exec $flags $envs -w "$workdir" substrate-tools "$@" +exec "$engine" exec $flags $envs -w "$workdir" "$name" "$@" diff --git a/deploy/caddy/Caddyfile b/deploy/caddy/Caddyfile index 79cf93d..b96b822 100644 --- a/deploy/caddy/Caddyfile +++ b/deploy/caddy/Caddyfile @@ -1,4 +1,6 @@ -# The front door (S-199, S-200), on 127.0.0.1 only (deploy/compose.yaml publishes each port there): +# The front door (S-199, S-200), on 127.0.0.1 only (deploy/compose.yaml publishes each port there). The ports below are +# the container's; on the host they are DESKTOP_PORT, DESKTOP_GATEWAY_PORT, DESKTOP_MAPS_PORT and DESKTOP_ROUTER_PORT +# (defaults 8080 to 8083), which the frame-src below and apps.json name: # :8080 the desktop: the kernel's UI shell at /ui/ (its D-44, D-127) and MCP at /mcp; /ui/apps.json, the framed apps # the shell lists (deploy/caddy/apps.json), is served from here, and the shell's own Content-Security-Policy # gains a frame-src naming exactly those apps' origins; /desktop/api/* is the desktop server's chat API (S-206) @@ -26,6 +28,10 @@ rewrite * /apps.json header Content-Type application/json header X-Content-Type-Options nosniff + # apps.json names each app's host port by the DESKTOP_*_PORT settings ({{env "NAME"}}) + templates { + mime application/json + } file_server } handle /mcp* { @@ -38,7 +44,7 @@ } handle { reverse_proxy kernel:8000 { - header_down Content-Security-Policy "default-src 'self';" "default-src 'self'; frame-src http://127.0.0.1:8081 http://127.0.0.1:8082 http://127.0.0.1:8083;" + header_down Content-Security-Policy "default-src 'self';" "default-src 'self'; frame-src http://127.0.0.1:{$DESKTOP_GATEWAY_PORT} http://127.0.0.1:{$DESKTOP_MAPS_PORT} http://127.0.0.1:{$DESKTOP_ROUTER_PORT};" } } } diff --git a/deploy/caddy/apps.json b/deploy/caddy/apps.json index a5e471e..f7cfa6d 100644 --- a/deploy/caddy/apps.json +++ b/deploy/caddy/apps.json @@ -1,5 +1,5 @@ [ - {"id": "gateway", "title": "Model gateway", "url": "http://127.0.0.1:8081/"}, - {"id": "maps", "title": "Substrate's maps", "url": "http://127.0.0.1:8082/"}, - {"id": "mcp", "title": "MCP router", "url": "http://127.0.0.1:8083/"} + {"id": "gateway", "title": "Model gateway", "url": "http://127.0.0.1:{{env "DESKTOP_GATEWAY_PORT"}}/"}, + {"id": "maps", "title": "Substrate's maps", "url": "http://127.0.0.1:{{env "DESKTOP_MAPS_PORT"}}/"}, + {"id": "mcp", "title": "MCP router", "url": "http://127.0.0.1:{{env "DESKTOP_ROUTER_PORT"}}/"} ] diff --git a/deploy/compose.yaml b/deploy/compose.yaml index 0ee747b..5d3e031 100644 --- a/deploy/compose.yaml +++ b/deploy/compose.yaml @@ -2,7 +2,8 @@ # The old assistant's services (the companion, the voice head, the worker, the judge) were retired in S-194. # SPARQL (deploy/ontop) comes later (docs/plan.md 3b); Caddy is the front door to the kernel's shell (S-199). # Images (S-167): each service names its published image (ghcr.io/openreplicant/substrate-NAME:SUBSTRATE_IMAGE_TAG, the -# kernel's at KERNEL_IMAGE_TAG, both default main) and keeps its build: as the fallback. scripts/up.sh pulls first and builds +# kernel's at KERNEL_IMAGE_TAG; by default this release's, 0.1.0-preview.1 and the kernel's 0.1.0: VERSION, scripts/tests/test_release.py) +# and keeps its build: as the fallback. scripts/up.sh pulls first and builds # what did not pull (SUBSTRATE_BUILD=1 builds all). # # Started by scripts/up.sh: @@ -26,7 +27,7 @@ services: # Database: substrate (the store, S-135; made by scripts/db.py init). v1's databases (workbench, and the # gateway's) stay in the same volume. db: - image: ghcr.io/openreplicant/substrate-db:${SUBSTRATE_IMAGE_TAG:-main} + image: ghcr.io/openreplicant/substrate-db:${SUBSTRATE_IMAGE_TAG:-0.1.0-preview.1} build: {context: ./postgres, dockerfile: Dockerfile} command: ["postgres", "-c", "shared_preload_libraries=pg_cron,graph", "-c", "cron.database_name=kernel"] # one database (S-202) environment: @@ -95,7 +96,7 @@ services: # 2026-11-21 (S-155). kernel-init: profiles: [kernel-admin] - image: ghcr.io/openreplicant/kernel:${KERNEL_IMAGE_TAG:-main} + image: ghcr.io/openreplicant/kernel:${KERNEL_IMAGE_TAG:-0.1.0} command: ["kk", "init"] read_only: true cap_drop: [ALL] @@ -109,7 +110,7 @@ services: kernel: <<: *locked - image: ghcr.io/openreplicant/kernel:${KERNEL_IMAGE_TAG:-main} + image: ghcr.io/openreplicant/kernel:${KERNEL_IMAGE_TAG:-0.1.0} # MCP over HTTP and the kernel's UI shell at /ui (the kernel's D-44), reached through caddy (S-199) command: ["kk", "serve", "--host", "0.0.0.0", "--port", "8000", "--only", "mcp,validator"] tmpfs: [/tmp] @@ -131,7 +132,7 @@ services: # (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} + image: ghcr.io/openreplicant/kernel:${KERNEL_IMAGE_TAG:-0.1.0} # --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"] @@ -153,7 +154,7 @@ services: # maps from the kernel's read model (S-154). ui: <<: *locked - image: ghcr.io/openreplicant/substrate-tools:${SUBSTRATE_IMAGE_TAG:-main} + image: ghcr.io/openreplicant/substrate-tools:${SUBSTRATE_IMAGE_TAG:-0.1.0-preview.1} build: {context: ./tools, dockerfile: Containerfile} # the fallback command: ["python3", "-m", "ui.server"] working_dir: /app @@ -181,7 +182,7 @@ services: # recorded, applied by the server's connector; its page (waiting calls, the record, the tools) is a desktop app. mcp-router: <<: *locked - image: ghcr.io/openreplicant/substrate-mcp-router:${SUBSTRATE_IMAGE_TAG:-main} + image: ghcr.io/openreplicant/substrate-mcp-router:${SUBSTRATE_IMAGE_TAG:-0.1.0-preview.1} build: {context: ../mcp-router, dockerfile: Containerfile} # the fallback command: ["serve"] environment: @@ -196,7 +197,7 @@ services: # caller's role), so the kernel still decides what that caller may see and do. mcp-kernel: <<: *locked - image: ghcr.io/openreplicant/substrate-mcp-router:${SUBSTRATE_IMAGE_TAG:-main} + image: ghcr.io/openreplicant/substrate-mcp-router:${SUBSTRATE_IMAGE_TAG:-0.1.0-preview.1} build: {context: ../mcp-router, dockerfile: Containerfile} command: ["connect", "--name", "kernel", "--url", "http://kernel:8000/mcp", "--list-role", "person_owner"] environment: @@ -210,7 +211,7 @@ services: # the router (say, show, ask, feed) and the chat view's API at /desktop/api/ on the desktop's origin (Caddy). desktop: <<: *locked - image: ghcr.io/openreplicant/substrate-tools:${SUBSTRATE_IMAGE_TAG:-main} + image: ghcr.io/openreplicant/substrate-tools:${SUBSTRATE_IMAGE_TAG:-0.1.0-preview.1} build: {context: ./tools, dockerfile: Containerfile} # the fallback command: ["python3", "-m", "desktop.server"] working_dir: /app @@ -228,7 +229,7 @@ services: # The desktop's connector to the router (S-205, S-206): its tools, each call signed as its caller. mcp-desktop: <<: *locked - image: ghcr.io/openreplicant/substrate-mcp-router:${SUBSTRATE_IMAGE_TAG:-main} + image: ghcr.io/openreplicant/substrate-mcp-router:${SUBSTRATE_IMAGE_TAG:-0.1.0-preview.1} build: {context: ../mcp-router, dockerfile: Containerfile} command: ["connect", "--name", "desktop", "--url", "http://desktop:8095/mcp", "--list-role", "person_owner"] environment: @@ -250,18 +251,22 @@ services: tmpfs: [/data, /config] environment: DESKTOP_PORT: ${DESKTOP_PORT:-8080} # the desktop's origin, in frame-ancestors + # the framed apps' origins on the host, in the desktop's frame-src and apps.json + DESKTOP_GATEWAY_PORT: ${DESKTOP_GATEWAY_PORT:-8081} + DESKTOP_MAPS_PORT: ${DESKTOP_MAPS_PORT:-8082} + DESKTOP_ROUTER_PORT: ${DESKTOP_ROUTER_PORT:-8083} XDG_DATA_HOME: /data XDG_CONFIG_HOME: /config volumes: - ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro - ./caddy/apps.json:/etc/caddy/apps.json:ro - # the desktop (DESKTOP_PORT on the host), then its framed apps on origins of their own (S-200); the Caddyfile and - # apps.json name these ports + # the desktop (DESKTOP_PORT on the host), then its framed apps on origins of their own (S-200), each port a setting; + # inside the container they stay 8081 to 8083 (the Caddyfile's sites) ports: - "127.0.0.1:${DESKTOP_PORT:-8080}:8080" - - "127.0.0.1:8081:8081" - - "127.0.0.1:8082:8082" - - "127.0.0.1:8083:8083" + - "127.0.0.1:${DESKTOP_GATEWAY_PORT:-8081}:8081" + - "127.0.0.1:${DESKTOP_MAPS_PORT:-8082}:8082" + - "127.0.0.1:${DESKTOP_ROUTER_PORT:-8083}:8083" depends_on: [kernel, gateway, ui, mcp-router] # The local slow model (plan step 5, S-169): llama.cpp's server, serving LLM_MODEL from LLM_MODELS_DIR read-only, by diff --git a/scripts/assistant.sh b/scripts/assistant.sh index e19111f..34469ce 100755 --- a/scripts/assistant.sh +++ b/scripts/assistant.sh @@ -15,10 +15,11 @@ KK_JWT_SECRET=$(env_value KK_JWT_SECRET); export KK_JWT_SECRET compose run --rm --no-deps -T kernel-init kk agent add assistant --no-login >/dev/null token=$(compose run --rm --no-deps -T -e KK_JWT_SECRET kernel-init kk token agent_assistant --days 1 2>/dev/null | tail -1) [ -n "$token" ] || { echo "could not mint the assistant's token (scripts/logs.sh kernel)" >&2; exit 1; } -TOKEN=$token ROOT=$ROOT WHO=$who python3 - "$dir/mcp.json" <<'PY' +rport=$(env_value DESKTOP_ROUTER_PORT) +TOKEN=$token ROOT=$ROOT WHO=$who RPORT=${rport:-8083} python3 - "$dir/mcp.json" <<'PY' import json, os, sys cfg = {"mcpServers": { - "router": {"type": "http", "url": "http://127.0.0.1:8083/mcp", + "router": {"type": "http", "url": "http://127.0.0.1:" + os.environ["RPORT"] + "/mcp", "headers": {"Authorization": "Bearer " + os.environ["TOKEN"]}}, "desktop": {"command": os.path.join(os.environ["ROOT"], "bin/in-tools"), "args": ["python3", "-m", "environment.channel", "assistant_" + os.environ["WHO"], diff --git a/scripts/build.sh b/scripts/build.sh index 2c4e371..7317be7 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,11 +1,11 @@ #!/bin/sh # Substrate's images, all inside the container engine (S-19). With no argument: pull the published images (db, tools, -# kernel; S-167) and build only the ones that did not pull. SUBSTRATE_BUILD=1 (here or in .env) builds everything. +# mcp-router, kernel; S-167) and build only the ones that did not pull. SUBSTRATE_BUILD=1 (here or in .env) builds everything. # A build is tagged with the published name, so compose finds it. Cheap to run again: the engine's layer cache keeps unchanged steps. # # scripts/build.sh # pull, then build what is missing # SUBSTRATE_BUILD=1 scripts/build.sh # build all of them -# scripts/build.sh db|tools|kernel # build that one +# scripts/build.sh db|tools|mcp-router|kernel # build that one set -eu . "$(dirname "$0")/lib.sh" @@ -13,6 +13,10 @@ build_db() { "$ENGINE" build -q -t "$(image_ref db)" -f "$ROOT/deploy/postgres/Dockerfile" "$ROOT/deploy/postgres" >/dev/null \ && echo " $(image_ref db) (Postgres with pgvector, pg_cron, pgmq, pgGraph)" } +build_mcp_router() { + "$ENGINE" build -q -t "$(image_ref mcp-router)" -f "$ROOT/mcp-router/Containerfile" "$ROOT/mcp-router" >/dev/null \ + && echo " $(image_ref mcp-router) (the MCP router and its connectors)" +} build_tools() { "$ENGINE" build -q -t "$(image_ref tools)" -f "$ROOT/deploy/tools/Containerfile" "$ROOT/deploy/tools" >/dev/null \ && echo " $(image_ref tools)" @@ -25,6 +29,9 @@ build_kernel() { if [ ! -d "$ROOT/repos/kernel/.git" ]; then url=$(sed -n '/^kernel:/,/^[a-z]/s/^ url: *//p' "$ROOT/repos.yaml" | head -1) branch=$(sed -n '/^kernel:/,/^[a-z]/s/^ branch: *//p' "$ROOT/repos.yaml" | head -1) + # a kernel release (KERNEL_IMAGE_TAG a version, as by default) builds from its tag, v; else the branch + tag=$(image_ref kernel); tag=${tag##*:} + case "$tag" in [0-9]*.*) branch=v$tag ;; esac mkdir -p "$ROOT/repos" && git clone --quiet --branch "${branch:-main}" "$url" "$ROOT/repos/kernel" fi if [ -n "${CA_BUNDLE:-}" ]; then set -- --secret "id=ca,src=$CA_BUNDLE"; else set --; fi @@ -35,7 +42,7 @@ build_kernel() { # pull what is published, build what is not pull_or_build() { # NAME ref=$(image_ref "$1") - if rt_pull "$ref"; then echo " $ref (pulled)"; else echo " $1: not pulled ($ref), building"; "build_$1"; fi + if rt_pull "$ref"; then echo " $ref (pulled)"; else echo " $1: not pulled ($ref), building"; "build_$(echo "$1" | tr - _)"; fi } say "Images ($ENGINE)" @@ -43,12 +50,13 @@ force=${SUBSTRATE_BUILD:-$(env_value SUBSTRATE_BUILD)} case "${1:-all}" in db) build_db ;; tools) build_tools ;; + mcp-router) build_mcp_router ;; kernel) build_kernel ;; all) if [ "$force" = 1 ]; then - build_db; build_tools; build_kernel + build_db; build_tools; build_mcp_router; build_kernel else - for n in db tools kernel; do pull_or_build "$n"; done + for n in db tools mcp-router kernel; do pull_or_build "$n"; done fi ;; - *) echo "usage: scripts/build.sh [db|tools|kernel]" >&2; exit 1 ;; + *) echo "usage: scripts/build.sh [db|tools|mcp-router|kernel]" >&2; exit 1 ;; esac diff --git a/scripts/check.sh b/scripts/check.sh index 26bfc16..631b319 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -66,13 +66,14 @@ for _ in $(seq 1 30); do done [ "$code" = "401" ] && ok "gateway http://127.0.0.1:$(env_value GATEWAY_PORT)/ (Bifrost; a call without a key is refused)" || bad "the model gateway returned $code to a call without a key (scripts/logs.sh gateway)" # The local models (S-169), when COMPOSE_PROFILES in .env turns them on +project=$(env_value COMPOSE_PROJECT_NAME); project=${project:-substrate} case ",$(env_value COMPOSE_PROFILES)," in *,llm,*) case "$running" in *-llm-*) ;; *) bad "service llm is not running (scripts/logs.sh llm)" ;; esac - if [ "$("$ENGINE" inspect -f '{{.State.Health.Status}}' substrate-llm-1 2>/dev/null)" = healthy ]; then + if [ "$("$ENGINE" inspect -f '{{.State.Health.Status}}' "$project-llm-1" 2>/dev/null)" = healthy ]; then ok "llm $(env_value LLM_MODEL) on llama.cpp, at the gateway as local/$(env_value LLM_ALIAS)" else note "llm not healthy yet (a large model takes minutes to load; scripts/logs.sh llm)"; fi if [ -n "$(env_value LLM_FAST_MODEL)" ]; then - if [ "$("$ENGINE" inspect -f '{{.State.Health.Status}}' substrate-llm-fast-1 2>/dev/null)" = healthy ]; then + if [ "$("$ENGINE" inspect -f '{{.State.Health.Status}}' "$project-llm-fast-1" 2>/dev/null)" = healthy ]; then ok "llm-fast $(env_value LLM_FAST_MODEL) on llama.cpp, at the gateway as fast/$(env_value LLM_FAST_ALIAS)" else note "llm-fast not healthy yet (scripts/logs.sh llm-fast)"; fi fi ;; @@ -87,16 +88,19 @@ case "$hdr" in esac # The front door (S-199): Caddy to the kernel's shell, with the kernel's own security headers on it dport=$(env_value DESKTOP_PORT); dport=${dport:-8080} -desk=http://127.0.0.1:$dport # DESKTOP_PORT; the apps stay on 8081 to 8083, which apps.json names (S-200) +gport=$(env_value DESKTOP_GATEWAY_PORT); gport=${gport:-8081} +mport=$(env_value DESKTOP_MAPS_PORT); mport=${mport:-8082} +rport=$(env_value DESKTOP_ROUTER_PORT); rport=${rport:-8083} +desk=http://127.0.0.1:$dport # DESKTOP_PORT; the apps on DESKTOP_GATEWAY_PORT, _MAPS_PORT, _ROUTER_PORT, which apps.json names (S-200) hdr=$(curl -s -D - -o /dev/null "$desk/ui/" 2>/dev/null | tr -d '\r') case "$hdr" in - *" 200 "*"frame-src http://127.0.0.1:8081 http://127.0.0.1:8082 http://127.0.0.1:8083;"*"frame-ancestors 'none'"*) + *" 200 "*"frame-src http://127.0.0.1:$gport http://127.0.0.1:$mport http://127.0.0.1:$rport;"*"frame-ancestors 'none'"*) ok "desktop $desk/ (the kernel's shell; frames only the apps in deploy/caddy/apps.json; sign in: scripts/kernel.sh person NAME)" ;; *" 200 "*) bad "the kernel's shell answers at $desk/ui/ without its CSP or the apps' frame-src (deploy/caddy/Caddyfile)" ;; *) bad "the kernel's shell does not answer at $desk/ui/ (scripts/logs.sh caddy, scripts/logs.sh kernel)" ;; esac # Its framed apps (S-200): each on an origin of its own, framable by the desktop only, with no X-Frame-Options left -for app in 8081:gateway 8082:maps 8083:mcp; do +for app in $gport:gateway $mport:maps $rport:mcp; do hdr=$(curl -s -D - -o /dev/null "http://127.0.0.1:${app%%:*}/" 2>/dev/null | tr -d '\r') case "$hdr" in *[Xx]-[Ff]rame-[Oo]ptions*) bad "app ${app#*:} at :${app%%:*} still sends X-Frame-Options (deploy/caddy/Caddyfile)" ;; diff --git a/scripts/lib.sh b/scripts/lib.sh index 71480f0..8d03564 100755 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -66,13 +66,17 @@ compose() { fi } -# The published image for a part (S-167): ghcr.io/openreplicant/substrate-NAME at SUBSTRATE_IMAGE_TAG (default main); the -# kernel's own is ghcr.io/openreplicant/kernel at KERNEL_IMAGE_TAG. scripts/build.sh tags a local build with the same name, -# so compose, tools.sh, kernel.sh and test.sh find one image whether it was pulled or built. -image_ref() { # NAME: db, tools, kernel +# The published image for a part (S-167): ghcr.io/openreplicant/substrate-NAME at SUBSTRATE_IMAGE_TAG; the kernel's own is +# ghcr.io/openreplicant/kernel at KERNEL_IMAGE_TAG. Unset, they are this release's (VERSION) and the kernel release it pins, +# as deploy/compose.yaml's defaults (scripts/tests/test_release.py keeps them equal); `main` follows the main branches. +# scripts/build.sh tags a local build with the same name, so compose, tools.sh, kernel.sh and test.sh find one image whether +# it was pulled or built. +SUBSTRATE_VERSION=0.1.0-preview.1 +KERNEL_VERSION=0.1.0 +image_ref() { # NAME: db, tools, mcp-router, kernel case "$1" in - kernel) _t=$(env_value KERNEL_IMAGE_TAG); echo "ghcr.io/openreplicant/kernel:${_t:-main}" ;; - *) _t=$(env_value SUBSTRATE_IMAGE_TAG); echo "ghcr.io/openreplicant/substrate-$1:${_t:-main}" ;; + kernel) _t=$(env_value KERNEL_IMAGE_TAG); echo "ghcr.io/openreplicant/kernel:${_t:-$KERNEL_VERSION}" ;; + *) _t=$(env_value SUBSTRATE_IMAGE_TAG); echo "ghcr.io/openreplicant/substrate-$1:${_t:-$SUBSTRATE_VERSION}" ;; esac } diff --git a/scripts/tests/test_release.py b/scripts/tests/test_release.py new file mode 100644 index 0000000..f5bd85c --- /dev/null +++ b/scripts/tests/test_release.py @@ -0,0 +1,62 @@ +"""A release's versions agree everywhere they are written. No database, no containers: the files only. +It should: +- read the release from VERSION, a semantic version +- find the same Substrate version, and one kernel version, as the image defaults of scripts/lib.sh, .env.example and + every ghcr.io/openreplicant image in deploy/compose.yaml (none left on `main`) +- find the images workflow publishing on v* tags, with the version as pushed and without the v +- find release notes for this version under docs/release-notes/ + + python3 scripts/tests/test_release.py +""" +import re +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +checks = [] +SEMVER = re.compile(r"^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$") + + +def check(name, ok, detail=""): + checks.append(bool(ok)) + print(("ok " if ok else "FAIL"), name, "" if ok else detail) + + +def main(): + version = (ROOT / "VERSION").read_text().strip() + check("VERSION is a semantic version", SEMVER.match(version), version) + + lib = (ROOT / "scripts/lib.sh").read_text() + sv = re.search(r"^SUBSTRATE_VERSION=(\S+)", lib, re.M) + kv = re.search(r"^KERNEL_VERSION=(\S+)", lib, re.M) + check("scripts/lib.sh defaults Substrate's images to VERSION", sv and sv.group(1) == version, sv and sv.group(1)) + kernel = kv.group(1) if kv else "" + check("scripts/lib.sh pins a kernel release", SEMVER.match(kernel), kernel) + + env = (ROOT / ".env.example").read_text() + st = re.search(r"^SUBSTRATE_IMAGE_TAG=(.*)$", env, re.M) + kt = re.search(r"^KERNEL_IMAGE_TAG=(.*)$", env, re.M) + check(".env.example's SUBSTRATE_IMAGE_TAG is VERSION", st and st.group(1) == version, st and st.group(1)) + check(".env.example's KERNEL_IMAGE_TAG is the kernel release", kt and kt.group(1) == kernel, kt and kt.group(1)) + + compose = (ROOT / "deploy/compose.yaml").read_text() + ours = re.findall(r"image: (ghcr\.io/openreplicant/[a-z-]+):(\S+)", compose) + check("compose names our images", len(ours) >= 6, ours) + wrong = [(i, t) for i, t in ours + if t != ("${KERNEL_IMAGE_TAG:-%s}" % kernel if i.endswith("/kernel") else "${SUBSTRATE_IMAGE_TAG:-%s}" % version)] + check("every one of them defaults to this release (the kernel's to its release)", not wrong, wrong) + + wf = (ROOT / ".github/workflows/images.yml").read_text() + check("the images workflow runs on v* tags", re.search(r'tags: \["v\*"\]', wf), "on.push.tags") + check("it tags the image with the git tag and with the version without the v", + "type=ref,event=tag" in wf and "type=semver,pattern={{version}}" in wf, "metadata-action tags") + + notes = ROOT / "docs/release-notes" / f"v{version}.md" + check(f"release notes for v{version}", notes.exists(), notes) + + print(f"{sum(checks)}/{len(checks)} checks passed") + sys.exit(0 if all(checks) else 1) + + +if __name__ == "__main__": + main() diff --git a/scripts/tools.sh b/scripts/tools.sh index b245be3..f6fcf74 100755 --- a/scripts/tools.sh +++ b/scripts/tools.sh @@ -8,7 +8,8 @@ set -eu . "$(dirname "$0")/lib.sh" -NAME=substrate-tools +# its name: TOOLS_CONTAINER in .env (default substrate-tools); a second checkout on one machine needs its own +NAME=$(env_value TOOLS_CONTAINER); NAME=${NAME:-substrate-tools} # Projects already connected (recorded one per line in .state/projects), plus any named now. projects() { @@ -29,6 +30,12 @@ start() { img_want=$("$ENGINE" image inspect -f '{{.Id}}' "$(image)" 2>/dev/null || true) img_have=$("$ENGINE" inspect -f '{{.Image}}' "$NAME" 2>/dev/null || true) if running && [ "$want" = "$have" ] && [ "${img_want#sha256:}" = "${img_have#sha256:}" ]; then echo " $NAME running"; return; fi + # never replace another checkout's container of the same name (it would lose that checkout's mounts) + other=$("$ENGINE" inspect -f '{{.Config.WorkingDir}}' "$NAME" 2>/dev/null || true) + if [ -n "$other" ] && [ "$other" != "$ROOT" ]; then + echo " $NAME belongs to another checkout ($other): set TOOLS_CONTAINER in .env to a name of this one's own" >&2 + exit 1 + fi "$ENGINE" rm -f "$NAME" >/dev/null 2>&1 || true set -- --detach --name "$NAME" --label "substrate.mounts=$want" --network host \ --cap-drop ALL --security-opt no-new-privileges \ From 3c9b88cb90c867900f0ab19e77e5b6dc50640a6d Mon Sep 17 00:00:00 2001 From: OpenReplicant <122761100+OpenReplicant@users.noreply.github.com> Date: Fri, 27 Nov 2026 08:29:05 -0800 Subject: [PATCH 2/3] Preview release v0.1.0-preview.1: README (requirements, what works, what is moving), release notes, first-up gateway fix, curl checked (S-222) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KhsqyyPmp7iKCkTFcXs6sh --- .claude/skills/setup/SKILL.md | 5 +- CLAUDE.md | 6 +- DECISIONS.md | 1 + README.md | 107 +++++++++++++++++++++---- docs/release-notes/v0.1.0-preview.1.md | 74 +++++++++++++++++ scripts/bootstrap.sh | 1 + scripts/gateway.py | 7 +- 7 files changed, 178 insertions(+), 23 deletions(-) create mode 100644 docs/release-notes/v0.1.0-preview.1.md diff --git a/.claude/skills/setup/SKILL.md b/.claude/skills/setup/SKILL.md index 6b70734..1556111 100644 --- a/.claude/skills/setup/SKILL.md +++ b/.claude/skills/setup/SKILL.md @@ -51,8 +51,9 @@ again. Known causes: substrate-db-1 psql -U postgres` with `\set pw '…'` and `alter role postgres password :'pw'` on stdin), then run `scripts/up.sh` again; it resets the gateway's roles itself. - **A port is taken** ("address already in use"): another program has it. Do not stop it; it is the owner's. Set - the service's port in `.env`: `DB_PORT`, `GATEWAY_PORT`, `UI_PORT`, `DESKTOP_PORT` (the desktop; its framed apps - stay on 8081 to 8083). Find the holder by process name and working directory, never its arguments. + the service's port in `.env`: `DB_PORT`, `GATEWAY_PORT`, `UI_PORT`, `OLLAMA_PORT`, `DESKTOP_PORT` (the desktop) and + `DESKTOP_GATEWAY_PORT`, `DESKTOP_MAPS_PORT`, `DESKTOP_ROUTER_PORT` (its framed apps; S-222). A second copy on one + machine also needs its own `COMPOSE_PROJECT_NAME`, `TOOLS_CONTAINER` and volumes (the README). Find the holder by process name and working directory, never its arguments. - **The gateway answers 400 to every call**: it knows no provider. With only local models, `.env` needs `OLLAMA_URL=http://ollama:11434`. diff --git a/CLAUDE.md b/CLAUDE.md index 33d9dac..ce142d7 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -27,10 +27,10 @@ dependency is a contract, never another project's code. Name parts by their role | 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 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), 8082 (the map pages) and 8083 (the router; `DESKTOP_GATEWAY_PORT`, `DESKTOP_MAPS_PORT`, `DESKTOP_ROUTER_PORT`, S-222) | 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 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) | +| Images | `.github/workflows/images.yml`, `image_ref` in `scripts/lib.sh` | `ghcr.io/openreplicant/substrate-{db,tools,mcp-router}` and the kernel's image are pulled (tags `SUBSTRATE_IMAGE_TAG`, `KERNEL_IMAGE_TAG`; by default the release in `VERSION` and the kernel release it pins, S-222; `main` follows the main branches); compose keeps `build:` as the fallback (S-167) | | Glue | `scripts/`, `deploy/` | brings the parts up and connects them | `deploy/ontop` (SPARQL) is kept and not started yet. @@ -47,7 +47,7 @@ dependency is a contract, never another project's code. Name parts by their role 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, Claude Code, +6. **Nothing installed on the host** beyond git, python3 (standard library), curl, 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 diff --git a/DECISIONS.md b/DECISIONS.md index 6461803..6ba8542 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -226,3 +226,4 @@ 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-222 | **A preview release, v0.1.0-preview.1: images pinned to the release, a fresh install tested, a second copy on one machine possible** (2026-11-27; the owner wants projects released, Morphogen first, Substrate as a clearly labelled preview while the re-cut is under way; numbered after the re-cut's S-219 to S-221, PR #32). (a) **Versions:** `VERSION` holds the release (`0.1.0-preview.1`); `deploy/compose.yaml`'s image defaults, `image_ref` in `scripts/lib.sh` (`SUBSTRATE_VERSION`, `KERNEL_VERSION`) and `.env.example` name it and the kernel release it pins (`0.1.0`, the kernel's tag on `e4ed8e2`'s code), no longer `main`; `scripts/tests/test_release.py` keeps them equal, checks the images workflow publishes `v*` tags (it already did: the tag as pushed and the version without the v) and that release notes exist (`docs/release-notes/`). A kernel image that does not pull is built from its tag `v`; `scripts/build.sh` pulls or builds the router's image too. A working checkout that wants `main` sets the tags in `.env` (an existing `.env` keeps what it has). (b) **The fresh install** (a clone in a temporary folder, the README only, beside other stacks on the owner's machine): it failed three ways, each fixed: the desktop's framed-app ports 8081 to 8083 were fixed and taken on this machine (now `DESKTOP_GATEWAY_PORT`, `DESKTOP_MAPS_PORT`, `DESKTOP_ROUTER_PORT`: compose maps them to Caddy's fixed 8081 to 8083, the Caddyfile's frame-src names them, `apps.json` is rendered by Caddy's `templates` with `{{env}}`, `check.sh` and `assistant.sh` read them); a first `up.sh` stopped in `gateway.py prune` while Bifrost was still making its tables (prune now waits for none of them: with any missing there is nothing stale); and a second copy would have shared the first one's data and tools container (`COMPOSE_PROJECT_NAME`, `TOOLS_CONTAINER`, `KERNEL_ARTIFACTS_VOLUME` are settings beside `DB_VOLUME` and `OLLAMA_VOLUME`; `tools.sh` refuses to replace another checkout's container, which it did before: the test removed the owner's stopped `substrate-tools`, which `scripts/tools.sh start` recreates). `bootstrap.sh` checks for curl (rule 6 names it). With those, bootstrap, up, check and every test suite passed on the fresh clone. (c) **The README** says what the preview is, what works, what is moving and what it needs; release notes are `docs/release-notes/v0.1.0-preview.1.md`. (d) **The owner releases** (not done here): the kernel's `v0.1.0` first, then this repository's `v0.1.0-preview.1`, each pushed tag publishing its images. | adopted — confirm | diff --git a/README.md b/README.md index 8561b21..322df3f 100644 --- a/README.md +++ b/README.md @@ -25,24 +25,69 @@ implementation project runs end to end on a demo small business without new core and picks an opportunity, the harness carries it out under the kernel's gates, a person approves what matters, and Morphogen judges the result (S-211). -**Where it stands (2026-11-24):** the stack below runs on one machine, and a person has talked to the assistant in -the kernel's desktop (S-208). The re-cut is decided and the parts are not moved yet. The work goes to Morphogen -(the kit) and the kernel first. +> **Preview release (v0.1.0-preview.1, 2026-11-27).** The stack below installs from a fresh clone and passes its +> checks and tests, but Substrate is in the middle of a re-cut (`docs/plan.md`, "The re-cut"; `docs/parts.md`, +> "Order"): its parts are moving into their final types, and names, services and settings will change before 0.1.0. +> Use it to try the stack and the desktop, not as something to build on yet. + +**Where it stands (2026-11-27):** the re-cut's kit is done: Morphogen maps a made-up firm from its material to a +report of implementation projects with no kernel and no stack (Morphogen #102 to #104; S-216, S-217). Substrate uses +Morphogen's plugin like any user (pinned to `d945a9c`, plugin 0.9.0). The stack runs on the kernel at `e4ed8e2`, +and a person has talked to the assistant in the kernel's desktop (S-208, S-218). Next is the re-cut's step 2: +Substrate's parts in their types (the environment as a kernel module, the channel and the router as MCP servers on +it, the assistant's view installed into the kernel's desktop), then the default distribution. + +## Preview: what works, what is moving + +**Works in this preview** (checked on a fresh clone, 2026-11-27: `scripts/bootstrap.sh`, `scripts/up.sh`, +`scripts/check.sh` all passing, and `scripts/test.sh`: catalog 9, environment 41, gateway 15, kernel 27, UI 36, +release 10 checks, the router's Go tests): + +- the stack from published images, pinned to this release (Substrate `0.1.0-preview.1`, the kernel `0.1.0`), or built + here when they do not pull; +- the desktop (the kernel's shell) at http://127.0.0.1:8080/ with search, review, change sets, the graph, the view + modules, and the framed apps: the gateway's dashboard, Substrate's map pages and the MCP router's page; +- a person's sign-in (`scripts/kernel.sh person NAME`) and an agent's own login with the kernel's MCP tools + (`scripts/kernel.sh login NAME`); +- the MCP router: one endpoint in front of the kernel's and the desktop's tools, read-only tools free, every tool that + writes waiting for a person on the router's page; +- the assistant (`scripts/assistant.sh`): a Claude Code session you talk to in the desktop's Assistant window; +- the model gateway (Bifrost) with a key per caller and every call logged without content, and Ollama behind it; +- Morphogen's plugin (map, research, catalog, optimise) in Claude Code, on Substrate's own catalog. + +**Moving** (expect changes before 0.1.0): + +- `environment/` becomes a kernel module whose gates use the kernel's review lane; the channel and `mcp-router/` + become MCP servers on it; `desktop/` becomes a view installed into the kernel's desktop (`docs/parts.md`); +- `ui/` (the old store pages, on :8100) is retired once the kernel's views and a map viewer do its job; +- the kernel's Substrate-specific modules (`encoder-substrate`, `view-substrate`, kernel-mcp's `substrate` profile) + are retired once Morphogen's file-based skills replace them; `scripts/kernel.sh mcp` uses that profile today; +- the compose file becomes the default distribution: the kernel's core and Substrate's modules installed onto it. + +**Known limits of the preview:** tested on one Linux machine with rootless Podman only (Docker should work through +`CONTAINER_ENGINE=docker` but was not tried for this release); everything binds to 127.0.0.1, with no HTTPS and no +multi-user setup; the local models (`llm`, `llm-fast`) need an NVIDIA GPU's driver libraries and your own GGUF files; +`scripts/kernel.sh mcp` and the assistant need Claude Code; there is no upgrade path promised from this preview to +the next release (keep your data volume, but expect to re-run `scripts/up.sh` and possibly re-initialise). ## What runs -The stack as it is in the tree today, before the parts move (`docs/parts.md`). Everything is in containers under +The stack as it is in the tree today, while the parts move (`docs/parts.md`). Everything is in containers under Podman compose, published on 127.0.0.1 only. | Part | Where | What it does | | --- | --- | --- | -| The store | the Knowledge Kernel (`scripts/kernel.sh`), Postgres (`deploy/postgres`) | Wikibase's data model with pinned evidence: things, statements, and the exact span of the source each statement rests on. A changed source flags what cites it, with no model call. Maps of parts, roles and interfaces, and catalogs of candidates with measurements and trade-off notes | -| The environment | `environment/`, schema `env` | Signals logged whole and fanned out as pgmq topics; one queue per actuator behind a gate (`free`, `propose`, `deny`); proposals wait for a person; every action recorded | +| The kernel | the Knowledge Kernel's image (`ghcr.io/openreplicant/kernel`), its database `kernel` in the stack's Postgres (`deploy/postgres`), `scripts/kernel.sh` | Knowledge with provenance: every claim attributed, cited and reviewed; logins and row-level security; the record. Substrate's catalog (`catalog/`) is read into it as Backstage entities | +| The desktop | service `caddy` (`deploy/caddy/`) in front of the kernel's `kk serve`, http://127.0.0.1:8080/ | The kernel's UI shell as a desktop: a launcher and windows, framed apps each on an origin of its own (:8081 to :8083), MCP over HTTP at `/mcp` | +| The environment | `environment/`, schema `env` in the kernel's database | Signals logged whole and fanned out as pgmq topics; one queue per actuator behind a gate (`free`, `propose`, `deny`); proposals wait for a person; every action recorded | | The channel | `environment/channel.py` | Pushes an environment's signals into a live Claude Code session; a signal not acknowledged comes back | +| The MCP router | `mcp-router/` (Go), services `mcp-router`, `mcp-kernel`, `mcp-desktop`; http://127.0.0.1:8083/ | One MCP endpoint for agents in front of every connected MCP server; each tool an actuator behind its gate, each call recorded, writers waiting for a person on its page | +| The assistant | `desktop/`, services `desktop`, `mcp-desktop`; `scripts/assistant.sh` | The conversation between a person and the agents as signals: you talk in the desktop's Assistant window, a Claude Code session hears it on the channel and answers through the router | | The gateway | `gateway` (Bifrost), `scripts/gateway.py` | Every model call goes through it under its caller's key and is logged there, not by the caller. Keys decide which providers a caller may reach; a meter counts a judged run's calls (S-193) | -| The local models | services `llm` and `llm-fast` (llama.cpp) | Two of your own GGUFs (S-169): a slow capable one on the CPU (`slow`; Inkling 2 Mini here) and a small fast one on the GPU (`fast`; LFM3 1.7B here) | +| The local models | `ollama`; services `llm` and `llm-fast` (llama.cpp, profile `llm`) | Ollama for embeddings; two of your own GGUFs (S-169): a slow capable one on the CPU (`slow`) and a small fast one on the GPU (`fast`) | | The optimiser | Morphogen's Claude Code plugin; its rules in the catalog (`catalog-info.yaml` at the root, S-216) | Cells from Substrate's catalog (`catalog/`); a change is judged on cases it cannot read, its model calls counted at the gateway (S-193) | -| The UI | `ui/`, service `ui`, http://127.0.0.1:8100 | The store's pages and maps as diagrams, read-only | +| The old store UI | `ui/`, service `ui`, http://127.0.0.1:8100 | The kernel's read model as pages and maps, read-only; to be retired (above) | +| The tools container | `deploy/tools/`, `bin/` | The scripts' Python and gitleaks, run in a container as you, so the host needs almost nothing | Who may do what is enforced by Postgres logins, not by convention: a process that runs a model can publish and act, but cannot decide a proposal or change a gate. Every signal and action keeps the login that really wrote it, @@ -74,21 +119,48 @@ route does, with the caller's key still required and its allowed models enforced full-text search beyond chance, so none is used until the record gives real queries. The first assistant's trials (speech, the local models, the voice router, the decider) are in `DECISIONS.md` (S-147 to S-183) and git history. -## Running it +## Requirements + +- **Linux on x86_64.** Tested on Ubuntu 24.04 (kernel 6.8). macOS and Windows are untested. +- **Podman with a compose provider** (tested: rootless Podman 4.9.3 with Docker Compose v5.8.0 as its provider; + `podman compose version` must answer), or Docker with compose v2 (`CONTAINER_ENGINE=docker` in `.env`; untested). +- **git, python3** (3.9 or later, standard library only) **and curl** on the host. Nothing else is installed there. +- **Disk:** about 7 GB for the images (Ollama's is 5 GB of it), plus whatever models you pull or point at. +- **Memory:** the core stack uses about 0.5 GB at rest; local models need what their GGUF files need on top. +- **Network:** the first run pulls images from ghcr.io and docker.io (public; no login needed). +- **Optional:** Claude Code (the assistant, `scripts/kernel.sh mcp`, Morphogen's plugin) and uv (the plugin runs its + MCP server with it); an NVIDIA GPU and your own GGUF files for the local models; an OpenRouter key for its free models. +- **Ports on 127.0.0.1:** 5432 (Postgres), 8080 (the desktop), 8081 to 8083 (its framed apps), 8090 (the gateway), + 8100 (the old UI), 11434 (Ollama). Each is a setting in `.env` (below). -Needs git, python3, Podman with compose, Claude Code and uv (for Morphogen's plugin) on the host; everything else -runs in containers. +## Running it ```sh -scripts/bootstrap.sh # once: images and the tools container +git clone https://github.com/OpenReplicant/Substrate && cd Substrate +scripts/bootstrap.sh # once: checks the host tools, makes .env and its secrets, pulls the images, starts the tools container scripts/up.sh # the stack and its databases, then scripts/check.sh scripts/check.sh # is everything up and wired scripts/test.sh # the test suites, each in a throwaway database +scripts/kernel.sh person NAME # your sign-in for the desktop (the password is kept in .state/kernel/, never printed) ``` -Settings live in `.env` (made from `.env.example`, mode 600; secrets are generated once). For the local models, -set `LLM_MODELS_DIR` and `LLM_MODEL` (and `LLM_FAST_MODELS_DIR`, `LLM_FAST_MODEL`) to your GGUF files and -`COMPOSE_PROFILES=llm`. +Then open http://127.0.0.1:8080/ and sign in as NAME. `scripts/down.sh` stops the stack (`--volumes` deletes its +data, and asks first). + +Settings live in `.env` (made from `.env.example` by `scripts/bootstrap.sh`, mode 600; secrets are generated once and +never printed). The images are this release's by default (`SUBSTRATE_IMAGE_TAG`, `KERNEL_IMAGE_TAG`; `main` follows +the main branches); one that does not pull is built here. The first `scripts/up.sh` takes a few minutes. + +**When a port is taken, or for a second copy on one machine:** run `scripts/settings.sh` first (it makes `.env`), +change the settings below in `.env`, then run `scripts/bootstrap.sh` and `scripts/up.sh` as above. A port: `DB_PORT`, +`DESKTOP_PORT`, `DESKTOP_GATEWAY_PORT`, `DESKTOP_MAPS_PORT`, `DESKTOP_ROUTER_PORT`, `GATEWAY_PORT`, `UI_PORT`, +`OLLAMA_PORT`. A second copy also needs its own `COMPOSE_PROJECT_NAME`, `TOOLS_CONTAINER`, `DB_VOLUME`, +`OLLAMA_VOLUME` and `KERNEL_ARTIFACTS_VOLUME`; with the defaults it would share the first copy's data. +`scripts/tools.sh` refuses to replace another checkout's tools container. + +**Local models (optional):** set `LLM_MODELS_DIR` and `LLM_MODEL` (and `LLM_FAST_MODELS_DIR`, `LLM_FAST_MODEL`) to your +GGUF files and `COMPOSE_PROFILES=llm`; on a GPU, `NVIDIA_LIB_DIR` if the driver's libraries are not in +`/usr/lib/x86_64-linux-gnu`. ## Privacy @@ -98,8 +170,9 @@ local models keep everything on this machine. ## Not built yet -`docs/plan.md`, "The re-cut": Morphogen as the kit (its pull request), Substrate's parts in their types, the -default distribution, and the test of the bet on a demo small business. +`docs/plan.md`, "The re-cut", and `docs/parts.md`, "Order": Substrate's parts in their types (under way), the +default distribution, and the test of the bet: one implementation project on a demo small business, carried out +under the kernel's gates. What this release is and what comes next: `docs/release-notes/v0.1.0-preview.1.md`. ## Where to read more diff --git a/docs/release-notes/v0.1.0-preview.1.md b/docs/release-notes/v0.1.0-preview.1.md new file mode 100644 index 0000000..746da56 --- /dev/null +++ b/docs/release-notes/v0.1.0-preview.1.md @@ -0,0 +1,74 @@ +# Substrate v0.1.0-preview.1 (draft) + +**A preview.** Substrate is in the middle of a re-cut (`docs/plan.md`, "The re-cut"; `docs/parts.md`, "Order"). This +release lets you install the stack, sign in to the desktop and try the assistant, the MCP router and the gateway. Its +parts, names and settings will change before 0.1.0, and no upgrade path from this preview is promised. + +## What it is + +The default distribution of two products: **Morphogen**, the kit (map, research, catalog and optimise, on Backstage +files, no database), and the **Knowledge Kernel** (Postgres made into a kernel: knowledge with provenance, review, +logins and row-level security, a module contract, a desktop in the browser). Substrate adds its optional parts onto +a kernel instance (the live environment and its gates, the channel into a harness, the MCP router, the assistant's +view), a configured harness (Claude Code first), a model gateway and local models, and the stack that runs them. + +## Pinned + +| What | Version | +| --- | --- | +| Substrate's images (`ghcr.io/openreplicant/substrate-{db,tools,mcp-router}`) | `0.1.0-preview.1` | +| The Knowledge Kernel (`ghcr.io/openreplicant/kernel`) | `0.1.0` (tested at `e4ed8e2`, the commit that release tags) | +| Morphogen's Claude Code plugin | `d945a9c` (plugin 0.9.0) | +| Bifrost (the gateway) | `v2.3.2` | +| Ollama | `0.40.12` | +| Caddy | `2.11.7-alpine` | +| llama.cpp's server (profile `llm`) | `server-cuda12-b12627` | + +## What works + +Checked on a fresh clone on 2026-11-27 (Ubuntu 24.04, rootless Podman 4.9.3, Docker Compose v5.8.0 as its provider), +beside another stack on the same machine: `scripts/bootstrap.sh`, `scripts/up.sh` and `scripts/check.sh` pass, and +`scripts/test.sh` passes every suite (catalog 9, environment 41, gateway 15, kernel 27, UI 36, release 10, the +router's Go tests). + +- The stack from published images (or built here when they do not pull), everything on 127.0.0.1. +- The desktop at http://127.0.0.1:8080/: the kernel's shell with search, review, change sets, the graph, the view + modules and three framed apps (the gateway's dashboard, the map pages, the MCP router's page), each on an origin of + its own. +- Sign-ins: `scripts/kernel.sh person NAME` for a person, `scripts/kernel.sh login NAME` for an agent (its own login; + the password is kept under `.state/`, never printed). +- The MCP router: one endpoint for agents in front of the kernel's and the desktop's tools; read-only tools run at + once, tools that write wait for a person on the router's page; every call recorded. +- The assistant (`scripts/assistant.sh`): a Claude Code session you talk to in the desktop's Assistant window. +- The model gateway: a key per caller, the providers each may reach, every call logged without its content. +- Morphogen's plugin in Claude Code, reading Substrate's own catalog. + +## Changed in this release (S-222) + +- Images are pinned: compose, `scripts/lib.sh` and `.env.example` default to this release and its kernel release + instead of `main`; `scripts/tests/test_release.py` keeps them equal to `VERSION`. A kernel image that does not pull + is built from the kernel's release tag. The images workflow already published `v*` tags. +- A second copy on one machine, or one whose ports are taken: the desktop's framed-app ports + (`DESKTOP_GATEWAY_PORT`, `DESKTOP_MAPS_PORT`, `DESKTOP_ROUTER_PORT`), the compose project (`COMPOSE_PROJECT_NAME`), + the tools container (`TOOLS_CONTAINER`) and the kernel's artifact volume (`KERNEL_ARTIFACTS_VOLUME`) are settings. + `scripts/tools.sh` no longer replaces another checkout's tools container. +- A first `scripts/up.sh` no longer fails while the gateway is still making its tables. +- `scripts/bootstrap.sh` checks for curl, which `scripts/check.sh` uses. +- The README: requirements, what works in the preview and what is moving. + +## Known limits + +- Tested on one Linux machine with rootless Podman. Docker (`CONTAINER_ENGINE=docker`), macOS and Windows are untested. +- Local only: no HTTPS, no multi-user setup; everything binds to 127.0.0.1. +- The local models need an NVIDIA GPU's driver libraries and GGUF files you download yourself (their licences are + theirs; LFM3's is Liquid AI's LFM Open License v1.0). +- The assistant, the agents' MCP server and Morphogen's plugin need Claude Code; the plugin also needs uv. +- `ui/` (the old store pages on :8100) and the kernel's `substrate` MCP profile are on their way out. +- A port already in use stops `scripts/up.sh` with the engine's "address already in use"; change that port's setting. + +## What's next + +The re-cut's step 2 (under way): the environment as a kernel module whose gates use the kernel's review lane, the +channel and the router as MCP servers on it, the assistant's view installed into the kernel's desktop. Then the +default distribution (the compose file installs the kernel's core and Substrate's modules), then the test of the bet: +one implementation project on a demo small business, end to end, under the kernel's gates. diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index d44a9da..6fbb664 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -14,6 +14,7 @@ require() { show "$1" "$2"; have "$1" || required_missing="$required_missing $1" require git "https://git-scm.com" require python3 "any Python 3.9+; the scripts use only its standard library" +require curl "scripts/check.sh probes the services with it" require "$ENGINE" "CONTAINER_ENGINE in .env picks podman or docker" if "$ENGINE" compose version >/dev/null 2>&1; then printf ' %-10s %s\n' compose "$("$ENGINE" compose version 2>/dev/null | head -1)" diff --git a/scripts/gateway.py b/scripts/gateway.py index fab8944..68c7319 100644 --- a/scripts/gateway.py +++ b/scripts/gateway.py @@ -157,7 +157,12 @@ def prune(env: dict[str, str]) -> None: keep = [r["id"] for r in cfg["governance"]["rate_limits"]] url = f"postgresql://postgres:{env['POSTGRES_PASSWORD']}@127.0.0.1:{env.get('DB_PORT') or 5432}/gateway" with psycopg.connect(url, connect_timeout=5, autocommit=True) as c: - if not c.execute("select to_regclass('governance_rate_limits')").fetchone()[0]: + # a fresh store: Bifrost makes its tables as it first starts, which may still be under way (first install, + # 2026-11-27): with any of them missing there is nothing stale to drop + tables = ("governance_rate_limits", "governance_model_configs", "governance_virtual_keys", + "governance_virtual_key_provider_configs", "config_providers") + if not all(c.execute("select to_regclass(%s)", (t,)).fetchone()[0] for t in tables): + print(" gateway store: new (its tables are not all made yet), nothing to prune") return n = c.execute("delete from governance_model_configs where rate_limit_id is not null and not rate_limit_id = any(%s)", (keep,)).rowcount for t in ("governance_virtual_keys", "governance_virtual_key_provider_configs", "config_providers"): From 2fe5c18048081f09d26484f00635696c462ea959 Mon Sep 17 00:00:00 2001 From: OpenReplicant <122761100+OpenReplicant@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:16:11 -0800 Subject: [PATCH 3/3] Preview: test counts after #32 (environment 44, review 19) (S-222) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KhsqyyPmp7iKCkTFcXs6sh --- README.md | 2 +- docs/release-notes/v0.1.0-preview.1.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 667fb18..1a64016 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ it, and the assistant's view is already a view in the kernel's desktop. Next is ## Preview: what works, what is moving **Works in this preview** (checked on a fresh clone, 2026-11-27: `scripts/bootstrap.sh`, `scripts/up.sh`, -`scripts/check.sh` all passing, and `scripts/test.sh`: catalog 9, environment 41, gateway 15, kernel 27, UI 36, +`scripts/check.sh` all passing, and `scripts/test.sh`: catalog 9, environment 44, gateway 15, kernel 27, review 19, UI 36, release 10 checks, the router's Go tests): - the stack from published images, pinned to this release (Substrate `0.1.0-preview.1`, the kernel `0.1.0`), or built diff --git a/docs/release-notes/v0.1.0-preview.1.md b/docs/release-notes/v0.1.0-preview.1.md index 3893e14..70855a2 100644 --- a/docs/release-notes/v0.1.0-preview.1.md +++ b/docs/release-notes/v0.1.0-preview.1.md @@ -28,7 +28,7 @@ view), a configured harness (Claude Code first), a model gateway and local model Checked on a fresh clone on 2026-11-27 (Ubuntu 24.04, rootless Podman 4.9.3, Docker Compose v5.8.0 as its provider), beside another stack on the same machine: `scripts/bootstrap.sh`, `scripts/up.sh` and `scripts/check.sh` pass, and -`scripts/test.sh` passes every suite (catalog 9, environment 41, gateway 15, kernel 27, UI 36, release 10, the +`scripts/test.sh` passes every suite (catalog 9, environment 44, gateway 15, kernel 27, review 19, UI 36, release 10, the router's Go tests). - The stack from published images (or built here when they do not pull), everything on 127.0.0.1.