#!/usr/bin/env bash # opencode-qwen38fn-strata-gb10 entrypoint. Runs inside the container; takes no arguments. # 127.0.0.1:8080 Strata 0.2.13 (`strata launch`), Qwen3.8-Flash-Next IQ3_S, 262144-token context, pictures on # 0.0.0.0:4096 opencode serve ([runtime.app]: m64 exposes it, web UI and full API, on a second front port) # 0.0.0.0:$M64_PORT agent_gateway.py: the agent.session API # The engine is started exactly as the qwen38-flash-next-strata-gb10 capsule starts it (only the context differs): # the GGUF shards are mounted read-only under /weights; nothing is fetched at runtime. set -eu QUANT=${QUANT:-IQ3_S} CONTEXT=${CONTEXT:-262144} VISION=${VISION:-on} status() { printf '{"phase":"%s","detail":"%s"}\n' "$1" "$2" >> "$M64_STATUS"; } status loading "preparing the model folder" # Strata's state, settings, install folder and data all live in this run's /scratch. export HOME=/scratch/home XDG_STATE_HOME=/scratch/state XDG_CONFIG_HOME=/scratch/config export STRATA_INSTALL_DIR=/scratch/install D=/scratch/Strata-data M=/scratch/model mkdir -p "$HOME" "$XDG_STATE_HOME" "$XDG_CONFIG_HOME" "$STRATA_INSTALL_DIR/third_party" "$D" "$M" ln -sfn /opt/strata/seed/third_party/llama.cpp "$STRATA_INSTALL_DIR/third_party/llama.cpp" # The draft layer made in the image; setup rewrites its vocabulary subset, so it gets a writable copy (0.8 GB). cp -r /opt/strata/mtp "$D/mtp" # The shards and the picture reader, under the names setup knows. m64 checked them against their Hugging Face # SHA-256 (the ones setup.py pins), so they get finish marks and are not hashed again at every start. for f in /weights/qwen38fn/"$QUANT"/*.gguf /weights/qwen38fn/mmproj-Qwen3.8-Flash-Next-BF16.gguf; do ln -sf "$f" "$M/"; printf 'm64 verified\n' > "$M/$(basename "$f").done" done status loading "preparing the $QUANT pack and starting Strata at $CONTEXT tokens (a few minutes)" # --access local: Strata listens on 127.0.0.1 only and needs no key. /opt/strata/terminal/bin/strata launch --no-tui --yes \ --family qwen --model "$QUANT" --model-path "$M" --data-dir "$D" \ --context "$CONTEXT" --vision "$VISION" --parallel "${PARALLEL:-1}" --tune skip \ --access local --port 8080 --save-preset m64 # Strata names the model itself; opencode.json asks for that name. SERVED=$(curl -sf http://127.0.0.1:8080/v1/models | python3 -c 'import json,sys; print(json.load(sys.stdin)["data"][0]["id"])') [ "$SERVED" = qwen3.8-flash-next-iq3_s ] || { status error "Strata serves $SERVED, not the model opencode.json names"; exit 1; } export AGENT_PROVIDER=local-strata AGENT_MODEL=$SERVED # HOME is the run's /scratch: opencode's DB, caches and every session dir go with the run. export WORK_DIR=/scratch/work mkdir -p "$WORK_DIR/sessions" # Packages opencode installs on first start, warmed at build time (at run time there is no # network unless the run is granted some). cp -rn /opt/opencode-capsule/. "$HOME/" export OPENCODE_CONFIG=/capsule/opencode.json # Its provider is Strata on 127.0.0.1, so nothing goes through the m64 gate unless the agent's own tools reach # out (and the run allows it). Run from $WORK_DIR; the gateway gives each of its sessions a directory under sessions/. cd "$WORK_DIR" opencode serve --hostname 0.0.0.0 --port 4096 --pure & OPENCODE_PID=$! # If opencode or the engine dies, take the container down so m64 reports the error ($$ is the gateway after exec). alive() { [ -r "/proc/$1/stat" ] && [ "$(cut -d')' -f2 "/proc/$1/stat" | cut -d' ' -f2)" != Z ]; } ( while alive "$OPENCODE_PID" && curl -sf -o /dev/null http://127.0.0.1:8080/v1/models; do sleep 10; done echo '{"phase":"error","detail":"opencode or Strata exited"}' >> "$M64_STATUS" kill -TERM $$ ) & exec /opt/gateway/bin/python3 /capsule/agent_gateway.py