Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43ece0cfd6 | ||
|
|
38cba33bbf |
No files matched your search
+3
-2
@@ -12,8 +12,9 @@ data/drafts/
|
||||
.pytest_cache/
|
||||
config.json
|
||||
*.log
|
||||
# Machine-specific experiments/recipes (GPU offload probe, benchmark harness).
|
||||
# Deliberately not part of the shipped agent.
|
||||
# Machine-specific material: deployment notes (hostnames, addresses, SSH,
|
||||
# model choices), GPU offload probe, benchmark harness. Deliberately not part
|
||||
# of the shipped agent.
|
||||
local/
|
||||
*.egg-info/
|
||||
*.bak.*
|
||||
@@ -204,90 +204,41 @@ simplex_ws.py neutral SimpleX daemon protocol shared by the command gateway
|
||||
|
||||
## Run / verify
|
||||
|
||||
Dev machine is a thin client (no GPU, ~1.4G disk): only pure stdlib unit tests
|
||||
run here (`python3 -m pytest tests/ -q --ignore=tests/integration`).
|
||||
Integration tests run on the staging machine `jarvis` (see "### jarvis (staging)").
|
||||
Pure stdlib unit tests run anywhere:
|
||||
`python3 -m pytest tests/ -q --ignore=tests/integration`. Integration tests need
|
||||
a real SemIf engine + a real LLM endpoint; run them on a provisioned host (see
|
||||
"### Provisioning (`scripts/bootstrap.sh`)").
|
||||
|
||||
## Local deployment notes
|
||||
|
||||
This repo is generic: it names no particular host, address, path, or model.
|
||||
**Every deployment-specific value lives in the gitignored `local/` folder** —
|
||||
see `local/ENVIRONMENT.md` for this deployment's hostnames, addresses, SSH keys,
|
||||
paths, and model choices. If that file is absent, this is a fresh clone and the
|
||||
values are yours to choose.
|
||||
|
||||
## Git / sync
|
||||
|
||||
- Canonical repo lives on Gitea: `git.manyworlds.fit`, **SSH on port 222**
|
||||
(`ssh://git@git.manyworlds.fit:222/gabby/semif-agent.git`). Key
|
||||
`~/.ssh/id_ed25519` is registered there. The staging machine `jarvis` runs
|
||||
from a manual clone at `~/repos/semif-agent` (`scripts/bootstrap.sh` provisions
|
||||
everything else and never re-clones the agent repo); the old box working copy
|
||||
is also at `~/repos/semif-agent` (its editable install still points at the moved
|
||||
`~/semif-agent`, so `import semif_agent` is broken there — moot, guppy runs
|
||||
ollama only now); the dev machine at `~/Repos/semif-agent`. Push/pull from
|
||||
Gitea — never rsync/tar the code.
|
||||
- **`config.json` is gitignored and per-machine** (dev and the box use different
|
||||
engine/LLM paths). Copy `config.example.json` to `config.json` and edit.
|
||||
`data/decisions.jsonl`, `data/runs.jsonl`, and `data/drafts/` are runtime
|
||||
artifacts and gitignored too.
|
||||
- The Gitea instance was rebuilt fresh (Sep 2026) after its git pack transfer
|
||||
broke (`sh: bad option '--oneshot'` — a stray system `uploadpack.packObjectsHook`
|
||||
killed pack generation; the old AGENTS.md note blaming `authorized_keys` was
|
||||
a misdiagnosis). Both the dev key (`shitass@nunya`) and the box key
|
||||
(`guppy@semif-agent`) are re-registered; clone/fetch/push all work now. If a
|
||||
fresh machine can't pull, the durable fix is on the Gitea host:
|
||||
`git config --system --unset-all uploadpack.packObjectsHook`.
|
||||
- Push/pull from your git remote — never rsync/tar the code.
|
||||
- **`config.json` is gitignored, per-machine, and required** (hosts use
|
||||
different LLM/codegen endpoints and models). `scripts/bootstrap.sh` seeds it
|
||||
from `config.example.json` once (only when absent) and **nothing writes it
|
||||
afterwards — only a human edits `config.json`**. `data/decisions.jsonl`,
|
||||
`data/runs.jsonl`, and `data/drafts/` are runtime artifacts and gitignored too.
|
||||
- **`pins.json` is committed and code-owned** — the single home for every
|
||||
external ref (SemIf commit, GGUF url+sha256, HF tokenizer revision,
|
||||
simplex-chat version/url+sha256). These are bumped by a git change and picked
|
||||
up on the next bootstrap run; they are deliberately NOT in `config.json` (a
|
||||
ref replaced on every update is not per-machine user config).
|
||||
- Decision rows logged before the `run_id` threading landed show up under
|
||||
run_id `"?"` in the dashboard — that's expected, not a bug.
|
||||
|
||||
Machine split (Sep 2026): **guppy** hosts the remote **codegen** model (the
|
||||
12G `qwen38-iq3s`) only; **jarvis** is the staging/test target (semif-agent +
|
||||
SemIf engine + deps) and runs its **own local ollama** serving the small
|
||||
title/description model (`qwen3.5:4b`). Only codegen traffic travels to guppy.
|
||||
Provision jarvis with `scripts/bootstrap.sh` (see "### jarvis (staging)").
|
||||
|
||||
**Connecting to jarvis (`ssh jarvis@192.168.8.130`)**: this is a plain `ssh`
|
||||
call. The key `~/.ssh/id_ed25519` is passphrase-protected and Linux Mint pops an
|
||||
askpass dialog for it; the flatpak overlay
|
||||
(`SSH_AUTH_SOCK=/run/flatpak/ssh-auth`) blocks the user's password locker, so
|
||||
they cannot paste from it and must type the passphrase by hand. **Warn the user
|
||||
right before running the command** ("about to ssh to jarvis — be ready to type
|
||||
your passphrase") so they can enter it, then just run `ssh`. Do **not** burn
|
||||
tokens on ssh-agent/askpass/fixed-socket workarounds — once the user types the
|
||||
passphrase at the prompt, plain `ssh` works for the session. The `agent refused
|
||||
operation` error from the flatpak socket is exactly this prompt, not a broken
|
||||
key.
|
||||
|
||||
Guppy key facts:
|
||||
|
||||
- ssh key `~/.ssh/id_ed25519` is passphrase-protected. Load it into an agent at
|
||||
a fixed socket before connecting (the default flatpak `SSH_AUTH_SOCK` refuses):
|
||||
```sh
|
||||
SOCK=/tmp/opencode/ssh-agent.sock; rm -f "$SOCK"; eval $(ssh-agent -a "$SOCK")
|
||||
printf '#!/bin/sh\necho "<PASSPHRASE>"\n' > /tmp/opencode/askpass.sh; chmod 700 /tmp/opencode/askpass.sh
|
||||
SSH_ASKPASS=/tmp/opencode/askpass.sh SSH_ASKPASS_REQUIRE=force setsid -w ssh-add ~/.ssh/id_ed25519
|
||||
```
|
||||
The agent dies if this machine restarts; redo it each session.
|
||||
- The agent on guppy is **deprecated** (guppy is ollama-only now). The box
|
||||
venv's editable install (`__editable__.semif_agent_0_1_0_finder.py`) still
|
||||
maps to `/home/abby/semif-agent`, which was moved to `~/repos/semif-agent`,
|
||||
so `import semif_agent` fails there — expected, not a bug. Run the agent on
|
||||
**jarvis** instead (below).
|
||||
- Dashboard: runs as a systemd **user** service on the box
|
||||
(`semif-dashboard.service`, linger enabled, binds `0.0.0.0:8765`), so it's up
|
||||
after reboots with no manual launch — browser UI at http://192.168.8.181:8765/.
|
||||
Manage it with `systemctl --user status/restart semif-dashboard.service`.
|
||||
Note the submit/relabel POST endpoints are therefore open to the whole LAN.
|
||||
It works in live mode on the box (submit runs the real engine + LLM) and in
|
||||
replay mode anywhere (`--replay`; reads decisions.jsonl + runs.jsonl; submit
|
||||
degrades to a JSON error without the engine). Relabeling in the UI writes a
|
||||
human override (3x weight in dream) via `POST /api/relabel`. On the dev
|
||||
machine, replay mode: `cd ~/Repos/semif-agent && python3 -m semif_agent.cli
|
||||
dashboard --replay` (binds 127.0.0.1:8765).
|
||||
- Integration tests (real engine + real LLM) only run on the box:
|
||||
`~/semif-venv/bin/python -m pytest tests/integration -q -s`
|
||||
They take ~100s (model load ~34s). Run them in the background and poll —
|
||||
long-lived ssh sessions get SIGHUP'd and kill the run.
|
||||
|
||||
## Roadmap
|
||||
|
||||
### v1 (done)
|
||||
Core loop, urgency queue, skill tree, skill loop with real SemIf assessment
|
||||
(decision, not generation), decision logging, `dream` cost pass, REPL + JSONL
|
||||
CLI, unit tests (24) + box integration tests (2).
|
||||
CLI, unit tests (24) + integration tests (2).
|
||||
|
||||
### v2
|
||||
- Real fine-tuning from `decisions.jsonl` at a regular interval ("dreaming"):
|
||||
@@ -302,7 +253,7 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
persisted to `data/categories.json` (under that category's `skills` list) and
|
||||
merged into the running tree as a leaf. Since Sep 2026 the leaf also gets a
|
||||
real runnable body via the async authoring pipeline: a larger
|
||||
OpenAI-compatible model (`codegen`, default `qwen38-iq3s`) writes an `act`-only
|
||||
OpenAI-compatible model (`codegen`, your configured code-capable model) writes an `act`-only
|
||||
body plus its own flat `CONTRACT` against `SKILL.md`, then a test
|
||||
(against `TESTGEN.md`) is generated and auto-run before the leaf
|
||||
is declared ready — all persisted to a folder in `data/skills/` and
|
||||
@@ -446,35 +397,33 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
## Constraints & gotchas (learned the hard way)
|
||||
|
||||
### Environment
|
||||
- **Dev box**: Python 3.13, GTX 780M (Kepler, useless), ~1.4G disk free. Never
|
||||
pip-install heavy deps here.
|
||||
- **guppy box**: Python 3.14, AMD RX 6950 XT (gfx1030), 32 cores, 30G RAM,
|
||||
passwordless sudo. Now serves **codegen only** (`qwen38-iq3s`). SemIf runs via
|
||||
llama.cpp **CPU** backend (its llamacpp backend forces `n_gpu_layers=0`), so
|
||||
the GPU is NOT used by the decision engine — it IS used by ollama.
|
||||
- **jarvis box**: runs the agent and its **own local ollama** serving the small
|
||||
title/description model (`qwen3.5:4b`). `config.json` `llm.base_url` points at
|
||||
`http://127.0.0.1:11434/v1`; only `codegen.base_url` points at guppy.
|
||||
- The core is pure stdlib and runs anywhere Python does. Never pip-install heavy
|
||||
deps on a thin client; a full install belongs on a provisioned host.
|
||||
- The SemIf engine runs via llama.cpp **CPU** backend (its llamacpp backend
|
||||
forces `n_gpu_layers=0`), so the decision engine does not use a GPU; ollama
|
||||
does.
|
||||
- The SemIf tokenizer is fetched from HF (`Qwen/Qwen3.5-4B` at the pinned
|
||||
revision), cached under each checkout's `.runtime/hf` (`HF_HOME`).
|
||||
- Per-host specs and model choices for this deployment: `local/ENVIRONMENT.md`.
|
||||
|
||||
### SemIf install (box)
|
||||
- **Legacy layout** (predates the `.runtime/` containment rule; kept for the
|
||||
deprecated guppy agent venv). New machines use `scripts/bootstrap.sh`, which
|
||||
installs the venv/engine/GGUF/cache under the checkout's `.runtime/` — see
|
||||
"### jarvis (staging)" and "Code principles".
|
||||
### SemIf install
|
||||
- New machines use `scripts/bootstrap.sh`, which installs the venv/engine/GGUF/
|
||||
cache under the checkout's `.runtime/` — see "### Provisioning
|
||||
(`scripts/bootstrap.sh`)" and "Code principles". (A legacy layout that
|
||||
installed the engine outside the checkout predates the `.runtime/`
|
||||
containment rule; prefer bootstrap.)
|
||||
- SemIf hard-pins `torch==2.10.0`, `numpy==2.2.6`, etc. The llamacpp path does
|
||||
**not** need torch (torch is imported lazily inside `direct.score`). Install
|
||||
with `--no-deps` and bring only what's needed — the committed manifest
|
||||
`requirements/staging.txt` is the single source of truth:
|
||||
`pip install -e ~/semif --no-deps`, then
|
||||
`pip install -e <semif-clone> --no-deps`, then
|
||||
`CMAKE_BUILD_PARALLEL_LEVEL=6 MAKEFLAGS=-j6 pip install -r requirements/staging.txt`
|
||||
(numpy 2.3.5, transformers 5.17.0, tokenizers 0.23.2, huggingface-hub 1.31.0,
|
||||
llama-cpp-python 0.3.35, pytest).
|
||||
- **Expected pip warnings:** pip reports "dependency conflicts" against
|
||||
semif-phase1's declared requirements (torch/accelerate/protobuf/sentencepiece
|
||||
not installed, numpy 2.2.6 vs 2.3.5). These are informational — the box runs
|
||||
exactly this set — not a bug; do not "fix" them by installing torch.
|
||||
not installed, numpy 2.2.6 vs 2.3.5). These are informational — the staging
|
||||
host runs exactly this set — not a bug; do not "fix" them by installing torch.
|
||||
- `numpy==2.2.6` has **no cp314 wheel** → pip tries a source build that fails
|
||||
without `pkg-config` + `python3-dev`. Use numpy 2.3.5 (has cp314 wheels).
|
||||
- `llama-cpp-python==0.3.35` builds from source. With all 32 cores it OOM-kills
|
||||
@@ -482,57 +431,47 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
`CMAKE_BUILD_PARALLEL_LEVEL=6 MAKEFLAGS=-j6 pip install llama-cpp-python==0.3.35`.
|
||||
Do NOT bump the llama-cpp-python version — SemIf calls specific llama.cpp C
|
||||
APIs that change between versions.
|
||||
- The pinned GGUF: `Qwen3.5-4B-Q4_K_M.gguf` from bartowski (2.8G) at
|
||||
`~/models/`. Load ~34s; score ~0.9s/decision on CPU at 8 threads.
|
||||
- The pinned GGUF: `Qwen3.5-4B-Q4_K_M.gguf` from bartowski (2.8G), downloaded
|
||||
into `.runtime/models/` by bootstrap. Load ~34s; score ~0.9s/decision on CPU
|
||||
at 8 threads.
|
||||
|
||||
### ollama
|
||||
- **guppy = codegen host.** Installed at `/home/abby/ollama/bin/ollama` (not on
|
||||
PATH), systemd service `ollama.service`, ROCm backend with
|
||||
`HSA_OVERRIDE_GFX_VERSION=10.3.0` and KV cache q4_0 + flash attention. Serves
|
||||
`qwen38-iq3s` (12G 27B, the codegen model). Binds `OLLAMA_HOST=0.0.0.0`, so
|
||||
jarvis reaches it as a plain remote API at `http://192.168.8.181:11434` (no
|
||||
auth — LAN-visible, same exposure as the old dashboard POST endpoints).
|
||||
- `semif-hermes` / `semif-hermes-v3` are for ANOTHER project (hermes agent) —
|
||||
ignore them; they spew "token repeat limit" errors.
|
||||
- If generation hangs with no log output, restart the service
|
||||
(`sudo systemctl restart ollama`) — the ROCm runner can wedge.
|
||||
- **jarvis = local small model.** Runs its own ollama (`/usr/local/bin/ollama`,
|
||||
systemd `ollama.service`, `127.0.0.1:11434`) serving `qwen3.5:4b` for
|
||||
new-skill title/description authoring (~3s). `bootstrap.sh` ensures
|
||||
that model is pulled; `config.json` `llm.base_url` points here.
|
||||
- `bootstrap.sh` installs **no ollama**: it expects the target box to already
|
||||
run one for `llm` (and pulls `llm.model` into it), while codegen is remote.
|
||||
- **The local `llm` model is a reasoning model — thinking must be off.** The
|
||||
default `qwen3.5:4b` has ollama's `thinking` capability: it emits hidden
|
||||
chain-of-thought and puts the answer in `content`. Through the `/v1` compat
|
||||
endpoint the CoT consumes the entire reply budget, so
|
||||
- `bootstrap.sh` installs **no ollama**: it expects the target host to already
|
||||
run one for `llm` (and pulls `llm.model` into it), while `codegen` may be
|
||||
remote. Point `--llm-url`/`--codegen-url` at the right daemons.
|
||||
- If generation hangs with no log output, restart the ollama service — the GPU
|
||||
runner can wedge.
|
||||
- **A local reasoning model needs thinking off for `llm`.** A reasoning model
|
||||
emits hidden chain-of-thought and puts the answer in `content`. Through the
|
||||
`/v1` compat endpoint the CoT consumes the entire reply budget, so
|
||||
`generate_category`/`generate_skill`'s `max_tokens=128` returns
|
||||
`finish_reason: length` with `content: ""` → `JSONDecodeError` and a traced
|
||||
`draft_failed` (no category/skill is ever authored — the whole create branch
|
||||
is silently dead). `LLMClient` now sends `reasoning_effort: "none"`
|
||||
is silently dead). `LLMClient` sends `reasoning_effort: "none"`
|
||||
(`llm.disable_thinking`, **default on**) so the model answers the ~30-token
|
||||
JSON directly (~2.5s). Ollama's native `think:false` is **not** plumbed
|
||||
JSON directly. Ollama's native `think:false` is **not** plumbed
|
||||
through `/v1` (silently ignored), and `/no_think` in the prompt is ignored
|
||||
too; only `reasoning_effort` works there. Codegen *wants* the reasoning, so
|
||||
the knob is `llm`-only — `CodegenClient` never sets it. Unbounded (no
|
||||
`max_tokens`) does not help: the model loops on this prompt (2048 tokens of
|
||||
reasoning, still empty `content`, 3+ min).
|
||||
`max_tokens`) does not help: a reasoning model can loop on this prompt
|
||||
(thousands of reasoning tokens, still empty `content`).
|
||||
|
||||
### jarvis (staging)
|
||||
### Provisioning (`scripts/bootstrap.sh`)
|
||||
|
||||
- Provision a fresh Ubuntu machine into a running staging box: clone
|
||||
`semif-agent` to a checkout (jarvis keeps it at `~/repos/semif-agent`; the
|
||||
script derives all paths from wherever it is run, so any path works — just
|
||||
register its SSH key on Gitea first), then
|
||||
`scripts/bootstrap.sh --llm-url http://127.0.0.1:11434 --codegen-url http://192.168.8.181:11434`.
|
||||
The script must be run from a checkout — it reads pins from that checkout's
|
||||
`config.example.json` and never re-clones the agent repo (only the SemIf
|
||||
engine and the simplex-chat binary). Idempotent and rerunnable; every stage
|
||||
no-ops on existing state, so it also boots an unknown-state machine. It
|
||||
installs **no ollama**: `llm` is this box's local ollama (bootstrap pulls
|
||||
`llm.model`), only `codegen` points at the peer guppy. It pulls the pinned
|
||||
small model into the local ollama and WARNs (never auto-pulls) if the remote
|
||||
codegen host is missing.
|
||||
- Provision a fresh Ubuntu machine into a running host: clone `semif-agent` to
|
||||
a checkout (register its SSH key on your git host first), then run
|
||||
`scripts/bootstrap.sh`. With no `config.json` yet it seeds one from
|
||||
`config.example.json`; edit that to set `llm.model`/`codegen.model` and the
|
||||
endpoints. Flags (`--llm-url`, `--codegen-url`, `--llm-model`,
|
||||
`--codegen-model`) override the values read from `config.json` **for that run
|
||||
only** and are never written back. The script must be run from a checkout —
|
||||
it reads pins from that checkout's `pins.json` and never re-clones the agent
|
||||
repo (only the SemIf engine and the simplex-chat binary). Idempotent and
|
||||
rerunnable; every stage no-ops on existing state, so it also boots an
|
||||
unknown-state machine. It installs **no ollama**: `llm` is the local ollama
|
||||
(bootstrap pulls `llm.model` if configured), `codegen` may point at a peer
|
||||
host. It WARNs (never auto-pulls) if the remote codegen host is missing its
|
||||
model, and WARNs if `llm.model`/`codegen.model` are unset.
|
||||
- **All installation artifacts live inside the checkout under a gitignored
|
||||
`.runtime/`** (`venv/`, `engine/`, `models/`, `hf/`, `bin/simplex-chat`,
|
||||
`simplex/`, `systemd/`), so an end user can find and debug the whole stack in
|
||||
@@ -540,57 +479,51 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
(`~/.ssh`) and the real systemd user dir + linger (the rendered units are
|
||||
stored in `.runtime/systemd/` and symlinked into `~/.config/systemd/user/`).
|
||||
See the "Code principles" containment rule.
|
||||
- All pins are read from `config.example.json`: the `engine` block
|
||||
- All pins are read from the committed `pins.json`: the `engine` block
|
||||
(`semif_repo` public GitHub `TheoLeeCJ/SemIf`, `semif_ref` pinned commit,
|
||||
`gguf_url`/`gguf_sha256`, HF tokenizer `source`/`revision`) and the
|
||||
`simplex_chat` block (`version`, `bin_url`, `sha256`, `port`,
|
||||
`display_name`). The python dep pins live in `requirements/staging.txt`
|
||||
(committed, one versioned artifact — jarvis, guppy, and any future box all
|
||||
provision from it). **Maintenance**: bump the pins in `config.example.json` /
|
||||
`requirements/staging.txt`, rerun the script, re-run the integration tests.
|
||||
The script never guesses.
|
||||
`simplex_chat` block (`version`, `bin_url`, `sha256`). Per-machine
|
||||
`simplex_chat` ports/display names stay in `config.json`. The python dep pins
|
||||
live in `requirements/staging.txt` (committed, one versioned artifact — every
|
||||
host provisions from it). The agent reads `engine.source`/`revision` from
|
||||
`pins.json` and derives the GGUF path from `engine.gguf_url` under
|
||||
`.runtime/models/` (an explicit `engine.gguf` in `config.json` overrides it).
|
||||
**Maintenance**: bump the pins in `pins.json` / `requirements/staging.txt`,
|
||||
rerun the script, re-run the integration tests. The script never guesses.
|
||||
- pip prints **expected** "dependency conflict" warnings at install time
|
||||
(semif-phase1 declares torch/accelerate/protobuf/sentencepiece/numpy 2.2.6
|
||||
that we intentionally do not install — the llama.cpp CPU path doesn't need
|
||||
them; numpy 2.3.5 is deliberate, 2.2.6 has no cp314 wheel). Same as the box;
|
||||
do not "fix" them by installing torch.
|
||||
- Generates `config.json` with `llm.base_url` = `--llm-url` (this box, local) and
|
||||
`codegen.base_url` = `--codegen-url` (the remote codegen host; `codegen.timeout:
|
||||
3600` since it travels the LAN), a repo-relative `.runtime/models` GGUF path,
|
||||
and a backup of any prior file. `--threads N` overrides engine threads;
|
||||
`--copy-data SRC` rsyncs guppy's `data/` for continuity; `--public-dashboard`
|
||||
binds the dashboard to `0.0.0.0`.
|
||||
It also enables the SimpleX gateway (`gateway.simplex.enabled = true`,
|
||||
`ws_url` from `simplex_chat.port`) and the standalone forwarding bridge
|
||||
(`bridges.simplex.enabled = true`, `ws_url` from `simplex_chat.forward_port`,
|
||||
top-level `simplex_bridge_url`), rendering/enabling four user services:
|
||||
them; numpy 2.3.5 is deliberate, 2.2.6 has no cp314 wheel). Do not "fix" them
|
||||
by installing torch.
|
||||
- Seeds `config.json` from `config.example.json` (only when absent) and **never
|
||||
writes it again** — only a human edits `config.json`. `config.example.json`
|
||||
ships the provisioned defaults, so a seeded `config.json` already has
|
||||
`codegen.timeout: 3600`, the SimpleX gateway enabled
|
||||
(`gateway.simplex.enabled = true`, `ws_url` from `simplex_chat.port`) and the
|
||||
standalone forwarding bridge enabled (`bridges.simplex.enabled = true`,
|
||||
`ws_url` from `simplex_chat.forward_port`, top-level `simplex_bridge_url`);
|
||||
the operator sets `llm.model`/`llm.base_url` and `codegen.model`/
|
||||
`codegen.base_url`. Bootstrap renders/enables four user services:
|
||||
`semif-simplex.service` (the command `simplex-chat` bot daemon,
|
||||
`--create-bot-display-name` on `simplex_chat.port`), `semif-gateway.service`
|
||||
(`.runtime/venv/bin/python -m semif_agent.cli gateway`),
|
||||
`semif-simplex-forward.service` (the bridge's **own** daemon/profile on
|
||||
`simplex_chat.forward_port`) and `semif-bridge.service`
|
||||
(`.runtime/venv/bin/python -m semif_agent.cli bridge`). `--simplex-allowed-users
|
||||
CSV` / `--simplex-home-channel ID` / `--simplex-display-name NAME` populate
|
||||
the gateway allowlist/fallback/identity; with an empty allowlist the gateway
|
||||
(`.runtime/venv/bin/python -m semif_agent.cli bridge`). The gateway allowlist
|
||||
(`gateway.simplex.allowed_users`) and fallback (`home_channel`) are
|
||||
`config.json` fields the operator edits; with an empty allowlist the gateway
|
||||
denies everyone (the safe default until the human adds their contact id).
|
||||
`--copy-data SRC` rsyncs a prior host's `data/` for continuity.
|
||||
Bootstrap then runs `scripts/simplex-address.py` to create/print the command
|
||||
bot's contact address (and the forwarding bot's, via `--ws-url`).
|
||||
- Run / verify on jarvis:
|
||||
```sh
|
||||
REPO=~/repos/semif-agent && cd "$REPO" && export HF_HOME="$REPO/.runtime/hf"
|
||||
"$REPO/.runtime/venv/bin/python" -m semif_agent.cli run # REPL
|
||||
"$REPO/.runtime/venv/bin/python" -m semif_agent.cli dream # cost report
|
||||
"$REPO/.runtime/venv/bin/python" -m pytest tests/integration -q -s # ~100s, background+poll
|
||||
"$REPO/.runtime/venv/bin/python" -m semif_agent.cli dashboard --port 8765
|
||||
systemctl --user status semif-simplex semif-gateway semif-simplex-forward semif-bridge # gateway + bridge stack
|
||||
```
|
||||
- First run downloads the 2.8G GGUF and builds `llama-cpp-python` from source
|
||||
(~10 min on 6 cores); reruns are fast no-ops.
|
||||
- Per-host run/verify commands and addresses: `local/ENVIRONMENT.md`.
|
||||
|
||||
### codegen (skill bodies, box)
|
||||
### codegen (skill bodies)
|
||||
- Skill **bodies** are written by a separate OpenAI-compatible model, configured
|
||||
under `codegen` in config.json (default model `qwen38-iq3s`, the 12G 27B
|
||||
IQ3_S GGUF — huge/slow). Title + description for new skills come from the
|
||||
under `codegen` in config.json (your configured code-capable model —
|
||||
larger/slower than `llm`). Title + description for new skills come from the
|
||||
separate small `llm` provider (its own endpoint/model, shared transport in
|
||||
`provider.py`); only the runnable code body uses codegen.
|
||||
- **Alternate hosted provider: OpenCode Console** (`console.py`). Either
|
||||
@@ -618,15 +551,14 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
their own adapters. The Console's **Jev** (`/zen/v1/systemone`) is a
|
||||
probability/decision evaluator — do NOT wire it into routing/assessment; SemIf
|
||||
alone decides.
|
||||
- **Do NOT cap `max_tokens`** on the codegen call. qwen38-iq3s reasons first
|
||||
and a cap truncates the hidden reasoning, leaving `content` empty
|
||||
(`finish_reason: length`) and the body write fails with "skill body is
|
||||
empty". Unbounded, it runs to completion in ~25–45 min with the card
|
||||
sampler (~28–70k tokens of reasoning then the code, ~25–40 tok/s); the
|
||||
client reads only `content`, so reasoning is filtered automatically. The
|
||||
client default timeout is 1200s and qwen38-iq3s routinely exceeds it —
|
||||
the box `config.json` sets `codegen.timeout: 3600`. Raise `codegen.timeout`
|
||||
in config if a harder prompt needs more.
|
||||
- **Do NOT cap `max_tokens`** on the codegen call. A reasoning codegen model
|
||||
reasons first and a cap truncates the hidden reasoning, leaving `content`
|
||||
empty (`finish_reason: length`) and the body write fails with "skill body is
|
||||
empty". Unbounded, it runs to completion (tens of thousands of reasoning
|
||||
tokens then the code); the client reads only `content`, so reasoning is
|
||||
filtered automatically. The client default timeout is 1200s and a slow codegen
|
||||
model can exceed it — the per-machine `config.json` sets `codegen.timeout:
|
||||
3600`. Raise `codegen.timeout` in config if a harder prompt needs more.
|
||||
- Bodies are persisted as one **folder per skill**: `data/skills/<category>/<name>/`
|
||||
holding `skill.py`, `skill.test.py`, `contract.json`, and `config.json` (all
|
||||
gitignored), loaded back at startup via `importlib`, so
|
||||
@@ -663,8 +595,8 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
catalog revision on the trace is future work.
|
||||
- **Trust boundary**: generated skill code is executed locally (it is imported
|
||||
as a module and its `act` runs in-process; `skill.test.py` runs as a
|
||||
subprocess in the skill folder). The box is the intended target; treat the
|
||||
endpoint as trusted.
|
||||
subprocess in the skill folder). The provisioned host is the intended target;
|
||||
treat the endpoint as trusted.
|
||||
- Flow in `scheduler._dispatch_skill`: the request is queued to the **single-slot
|
||||
`llm` draft worker** (small model authors title+description) → stub registered
|
||||
+ hot-merged into the tree → the body write is queued to a **separate
|
||||
@@ -716,8 +648,8 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
the skill row / `skill_write_failed` flow node. Codegen failure — including a
|
||||
request timeout — is raised as `CodegenError` by the client, never a raw
|
||||
`TimeoutError`. The default codegen timeout is 1200s
|
||||
(`cli.build_scheduler`); the box `config.json` sets `codegen.timeout: 3600`
|
||||
because qwen38-iq3s's card sampler writes routinely run 25–45 min. Raise
|
||||
(`cli.build_scheduler`); a slow codegen model's writes can run 25–45 min, so
|
||||
the per-machine `config.json` sets `codegen.timeout: 3600`. Raise
|
||||
`codegen.timeout` in config for harder prompts.
|
||||
- **Config tiering + first-fire collection.** After the contract lands, a SemIf
|
||||
`choice` per variable auto-populates the skill `config.json` from the whole
|
||||
@@ -777,7 +709,7 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
`reasoning` (ollama) or `reasoning_content` (other OpenAI-compatible
|
||||
backends) — do not drop one for the other. Echoing is console-only; the
|
||||
returned content is identical either way. Integration tests already force
|
||||
streaming; see it with `-s` on the box.
|
||||
streaming; see it with `-s`.
|
||||
- `codegen.idle_warn` (default 60s) / `codegen.idle_timeout` (default 180s)
|
||||
surface a silent stream: a wedged generation prints a warning at `idle_warn`
|
||||
seconds with no tokens, then raises `CodegenError` (→ graceful stub) at
|
||||
@@ -799,7 +731,7 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
handles both shapes and falls back to `model_info.<arch>.context_length`. The
|
||||
total wall-clock `timeout` is enforced while the stream is live (a
|
||||
continuously-streaming runaway is cut off), not only during idle gaps. The
|
||||
budget is a safety net, not the loop cure: qwen38-iq3s's reasoning routinely
|
||||
budget is a safety net, not the loop cure: a reasoning codegen model routinely
|
||||
exceeds even the relaxed cap before it settles on a body.
|
||||
- **Sampler params (opt-in).** `temperature`/`top_p`/`presence_penalty`/
|
||||
`frequency_penalty` are **not sent by default**: a `None`/absent value is
|
||||
@@ -807,8 +739,8 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
provider never guesses a value for the user — set one in the `llm`/`codegen`
|
||||
config block (or per `chat` call) only when you know the right value for the
|
||||
model. `config.example.json` ships explicit values as a starting point, so a
|
||||
provisioned box still sends them. When configured, a high `presence_penalty`
|
||||
(not greedy temperature) is the anti-repetition loop cure for qwen38-iq3s, and
|
||||
provisioned host still sends them. When configured, a high `presence_penalty`
|
||||
(not greedy temperature) is the anti-repetition loop cure for a looping codegen model, and
|
||||
those four are the only sampler knobs reachable via ollama's OpenAI-compat
|
||||
API (`repeat_penalty`/`min_p`/`top_k` are Modelfile-only). There is **no
|
||||
escalated preset**: a rejected body retries with a fresh short prompt that
|
||||
@@ -825,7 +757,7 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
Recorded as **trace-only** events (kind `codegen`, with probs and
|
||||
`stop_prob`) — never in the decision log. Disabled when no engine is
|
||||
available (`enabled` defaults true; the runtime engine check is what gates
|
||||
it off the box).
|
||||
it off when no engine is loaded).
|
||||
|
||||
### gateway (messenger intake)
|
||||
|
||||
@@ -834,7 +766,7 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
configured `gateway.simplex` adapter in the foreground. `--dashboard`
|
||||
co-serves the browser UI from a daemon thread. Config lives under
|
||||
`gateway.simplex` in `config.json`; `enabled` defaults false. On a
|
||||
bootstrap-provisioned box `scripts/bootstrap.sh` renders and enables the
|
||||
bootstrap-provisioned host `scripts/bootstrap.sh` renders and enables the
|
||||
`semif-simplex.service` bot daemon (pinned `simplex-chat` in **bot mode**,
|
||||
profile under `.runtime/simplex/`, port from `simplex_chat.port`) and the
|
||||
`semif-gateway.service` agent process, so the gateway runs across
|
||||
@@ -909,7 +841,7 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
`/_show_address` / `/_address` (`SimplexDaemon.request_address`, thread-safe
|
||||
via `run_coroutine_threadsafe`). It carries no policy: no allowlist, no
|
||||
scheduler, no HTTP.
|
||||
- **Tests.** `tests/test_gateway.py` (stdlib, dev box): adapter allowlist/auth,
|
||||
- **Tests.** `tests/test_gateway.py` (stdlib): adapter allowlist/auth,
|
||||
structured send command, batching (real `asyncio`), and `GatewayService`
|
||||
routing against a real `Scheduler` (lazy engine, unreachable LLM).
|
||||
`tests/test_simplex_ws.py` covers the neutral protocol layer (parse shapes,
|
||||
@@ -920,9 +852,9 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
`tests/test_seed_skills.py` hermetically tests every
|
||||
`seeds/<category>/<name>/` package, including `simplex.next_message` and
|
||||
`simplex.connect_link`. The live `websockets` transport against a real daemon
|
||||
is a jarvis integration concern.
|
||||
is a live-daemon integration concern.
|
||||
- **Deps.** `websockets` is pinned in `requirements/staging.txt` (staging
|
||||
only); the dev box core stays stdlib-only.
|
||||
only); the core stays stdlib-only.
|
||||
|
||||
### bridges (third-party API services)
|
||||
|
||||
@@ -944,7 +876,7 @@ CLI, unit tests (24) + box integration tests (2).
|
||||
bridges until interrupted. Each bridge owns its service daemon: `SimplexBridge`
|
||||
connects to a **second** simplex-chat daemon/profile (`bridges.simplex.ws_url`,
|
||||
default port 5228, pinning `simplex_chat.forward_port`), separate from the
|
||||
command gateway's. On a bootstrap-provisioned box, `scripts/bootstrap.sh`
|
||||
command gateway's. On a bootstrap-provisioned host, `scripts/bootstrap.sh`
|
||||
renders and enables `semif-simplex-forward.service` (the second daemon) and
|
||||
`semif-bridge.service` (`cli bridge`) alongside the gateway units.
|
||||
- **HTTP surface** (`bridges/base.py` + `bridges/simplex.py`): JSON in/out,
|
||||
@@ -1022,7 +954,7 @@ The bridge read path (`simplex.next_message`) and contact-link lookup
|
||||
touch data-structure math only (queue ordering, dream cost, contract
|
||||
serialization) or drive scheduling mechanics through the `ScriptedEngine`
|
||||
double in `tests/conftest.py`; decisions themselves are verified by
|
||||
integration tests on the box.
|
||||
integration tests on a provisioned host.
|
||||
- Engine import is **lazy** (`engine.py`) so the rest of the package stays pure
|
||||
stdlib and testable without SemIf installed. Keep it that way.
|
||||
- `DecisionLog.append` labels a row with the *selected* option by default
|
||||
@@ -1050,8 +982,12 @@ The bridge read path (`simplex.next_message`) and contact-link lookup
|
||||
the `_parse_json` helper and the LLMClient provider. `tests/conftest.py``s `ScriptedEngine`
|
||||
drives scheduling mechanics (assessment is now a SemIf decision) without a
|
||||
GGUF.
|
||||
- `tests/integration/` — jarvis only (staging); requires real SemIf + real
|
||||
ollama (guppy serves the models over the LAN).
|
||||
- `tests/test_no_env_leaks.py` guards the generic-repo rule: it fails if a
|
||||
deployment hostname, address, username, absolute home path, or local model
|
||||
name reappears in a tracked file. Deployment specifics belong in the
|
||||
gitignored `local/` folder (see "Local deployment notes").
|
||||
- `tests/integration/` — run only where real SemIf + a real LLM endpoint are
|
||||
available (the endpoint may be remote).
|
||||
- After touching scheduler/skills/codegen/engine, re-run both; the integration
|
||||
tests are the only end-to-end verification.
|
||||
- **Fixtures are not the runtime.** Generated skill tests (and unit tests of the
|
||||
|
||||
@@ -28,8 +28,8 @@ A successful release of this could be defined by a single question: "Can I use t
|
||||
- [Features](#features)
|
||||
- [Repository layout](#repository-layout)
|
||||
- [Installation](#installation)
|
||||
- [Option A: one-command staging box (`bootstrap.sh`)](#option-a-one-command-staging-box-bootstrapsh)
|
||||
- [Option B: dev machine (stdlib only)](#option-b-dev-machine-stdlib-only)
|
||||
- [Option A: one-command provisioning (`bootstrap.sh`)](#option-a-one-command-provisioning-bootstrapsh)
|
||||
- [Option B: core only (stdlib)](#option-b-core-only-stdlib)
|
||||
- [Prerequisites: ollama models](#prerequisites-ollama-models)
|
||||
- [Configuration](#configuration)
|
||||
- [Running the agent](#running-the-agent)
|
||||
@@ -176,7 +176,7 @@ worker. It is **asynchronous**, so the gate stays free while either model thinks
|
||||
gateway) defers to a question queue and the worker waits
|
||||
(`codegen.elicitation.wait_timeout`).
|
||||
3. **Codegen body** (`generate_skill_body`): a larger OpenAI-compatible model
|
||||
(`codegen`, default `qwen38-iq3s`) writes a single `act` against `SKILL.md`,
|
||||
(`codegen`, your configured code-capable model) writes a single `act` against `SKILL.md`,
|
||||
reading every operational value from `ctx.config` and declaring `INTEGRATION`
|
||||
(service / transport / config_vars) plus its own flat `CONTRACT`
|
||||
(variable → description; every key must be read from `ctx.config`).
|
||||
@@ -380,11 +380,13 @@ semif_agent/
|
||||
seeds/ committed starter skills (calendar, simplex)
|
||||
scripts/ bootstrap.sh, simplex-address.py, systemd/*.in
|
||||
requirements/ staging.txt — the pinned engine deps
|
||||
tests/ stdlib unit tests + tests/integration (staging only)
|
||||
tests/ stdlib unit tests + tests/integration (real engine + LLM)
|
||||
SKILL.md the contract fed to the skill-body codegen model
|
||||
TESTGEN.md the contract fed to the test/contract codegen model
|
||||
AGENTS.md the operational guide (read this before touching code)
|
||||
config.example.json per-machine config template
|
||||
config.example.json per-machine config template (seeded to config.json once)
|
||||
pins.json committed pins: engine/GGUF/tokenizer/simplex-chat refs
|
||||
local/ gitignored: this deployment's notes (hosts, addresses, models)
|
||||
```
|
||||
|
||||
---
|
||||
@@ -401,27 +403,30 @@ in the checkout.
|
||||
Two OpenAI-compatible endpoints (usually ollama), which may be on different
|
||||
machines:
|
||||
|
||||
- **`codegen`** — the large model that writes skill bodies (e.g.
|
||||
`qwen38-iq3s`, a 27B IQ3_S GGUF). This is slow and ideally on a beefier host.
|
||||
- **`llm`** — a small, fast model (e.g. `qwen3.5:4b`) that authors the title +
|
||||
description of a newly created category/skill. Deliberately its own
|
||||
endpoint/model, so it can stay local even when `codegen` is remote; it uses
|
||||
the same provider transport (`provider.py`) and an unreachable endpoint is
|
||||
graceful (the request is not re-dispatched), never fatal.
|
||||
- **`codegen`** — a large, code-capable model that writes skill bodies. This is
|
||||
slow and ideally on a beefier host.
|
||||
- **`llm`** — a small, fast model that authors the title + description of a
|
||||
newly created category/skill. Deliberately its own endpoint/model, so it can
|
||||
stay local even when `codegen` is remote; it uses the same provider transport
|
||||
(`provider.py`) and an unreachable endpoint is graceful (the request is not
|
||||
re-dispatched), never fatal.
|
||||
|
||||
The **decision engine is separate** and runs via llama.cpp CPU (or Vulkan if your
|
||||
build enables it), not ollama.
|
||||
|
||||
### Option A: one-command staging box (`bootstrap.sh`)
|
||||
### Option A: one-command provisioning (`bootstrap.sh`)
|
||||
|
||||
On a fresh Ubuntu machine, from a checkout of this repo:
|
||||
|
||||
```sh
|
||||
scripts/bootstrap.sh \
|
||||
--llm-url http://127.0.0.1:11434 \
|
||||
--codegen-url http://192.168.8.181:11434
|
||||
scripts/bootstrap.sh
|
||||
```
|
||||
|
||||
With no `config.json` yet, the script seeds one from `config.example.json`; edit
|
||||
it to set `llm.model`/`codegen.model` (and the endpoints). Flags override those
|
||||
values for the run only — `--llm-url`, `--codegen-url`, `--llm-model`,
|
||||
`--codegen-model` — and are never written back to `config.json`.
|
||||
|
||||
The script is idempotent (every stage no-ops on existing state) and:
|
||||
|
||||
1. installs system prereqs + enables linger;
|
||||
@@ -432,20 +437,24 @@ The script is idempotent (every stage no-ops on existing state) and:
|
||||
4. downloads and sha256-verifies the pinned GGUF into `.runtime/models/`;
|
||||
5. pre-fetches the HF tokenizer into `.runtime/hf/`;
|
||||
6. downloads and sha256-verifies the pinned `simplex-chat` binary;
|
||||
7. writes `config.json` (paths, LLM/codegen URLs, dashboard, SimpleX);
|
||||
7. seeds `config.json` from `config.example.json` **only if it does not already
|
||||
exist** — it never rewrites `config.json` (only a human edits that file);
|
||||
8. renders and enables systemd **user** units:
|
||||
`semif-simplex` (bot daemon), `semif-gateway` (agent gateway),
|
||||
`semif-simplex-forward` (the bridge's own daemon), `semif-bridge`;
|
||||
9. prints the bot's SimpleX contact address.
|
||||
|
||||
Useful flags: `--threads N`, `--public-dashboard`, `--copy-data SRC`,
|
||||
`--simplex-allowed-users CSV`, `--simplex-home-channel ID`,
|
||||
`--simplex-display-name NAME`. Run `scripts/bootstrap.sh -h` for the full list.
|
||||
Flags (`--llm-url`, `--codegen-url`, `--llm-model`, `--codegen-model`,
|
||||
`--copy-data SRC`) override the values read from `config.json` for that run only.
|
||||
Run `scripts/bootstrap.sh -h` for the full list.
|
||||
|
||||
It installs **no ollama**; it expects one for `llm` and pulls `llm.model`,
|
||||
warning (never auto-pulling) if the remote codegen host is missing its model.
|
||||
Pinned external refs (engine commit, GGUF url+sha256, HF tokenizer revision,
|
||||
simplex-chat version/url+sha256) live in the committed `pins.json`, not in
|
||||
`config.json`.
|
||||
|
||||
### Option B: dev machine (stdlib only)
|
||||
### Option B: core only (stdlib)
|
||||
|
||||
The core is dependency-free, so unit tests run anywhere:
|
||||
|
||||
@@ -455,22 +464,29 @@ python3 -m pytest tests/ -q --ignore=tests/integration
|
||||
|
||||
For a full install on a machine you manage, follow the same steps bootstrap
|
||||
performs (venv, `semif-phase1 --no-deps`, `requirements/staging.txt`, GGUF,
|
||||
tokenizer cache), then copy `config.example.json` to `config.json` and adjust
|
||||
paths.
|
||||
|
||||
### Configuration
|
||||
|
||||
`config.json` is **gitignored and per-machine**. Copy the template and edit:
|
||||
tokenizer cache), then create `config.json` from the template and adjust paths:
|
||||
|
||||
```sh
|
||||
cp config.example.json config.json
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
`config.json` is **gitignored, per-machine, and required** — the agent refuses
|
||||
to start without it. `scripts/bootstrap.sh` seeds it from `config.example.json`
|
||||
once; afterwards only a human edits it (nothing writes `config.json`). Pinned
|
||||
external refs live in the committed `pins.json`, so `config.json` holds only
|
||||
per-machine settings:
|
||||
|
||||
```sh
|
||||
cp config.example.json config.json # if not already created by bootstrap
|
||||
```
|
||||
|
||||
Key blocks:
|
||||
|
||||
| Block | What it controls |
|
||||
| --- | --- |
|
||||
| `engine` | SemIf source/revision, GGUF path, context, threads |
|
||||
| `engine` | per-machine engine settings: backend, context, threads, optional GGUF path override (refs come from `pins.json`) |
|
||||
| `llm` | small model endpoint that authors new category/skill title + description |
|
||||
| `codegen` | skill-body model endpoint, timeouts, sampler, elicitation, fidelity, repair, test, degeneration watchdog, token budget |
|
||||
| `navigation` | two-stage guards: leaf `intent_tau`, category `category_tau` |
|
||||
@@ -480,15 +496,19 @@ Key blocks:
|
||||
| `gateway.simplex` | command gateway: ws_url, allowlist, batching |
|
||||
| `bridges.simplex` | forwarding bridge: host/port/token/ws_url |
|
||||
| `simplex_bridge_url` / `simplex_bridge_token` | what skill bodies call |
|
||||
| `simplex_chat` | pinned simplex-chat binary + gateway/forward ports |
|
||||
| `simplex_chat` | gateway/forward ports and bot display names (binary refs come from `pins.json`) |
|
||||
| `dashboard` | bind host/port |
|
||||
|
||||
`llm.model` and `codegen.model` are **required** (no default): set each to a
|
||||
model its endpoint serves. A missing model fails fast at startup with a clear
|
||||
config error rather than sending a request to a model that isn't there.
|
||||
|
||||
Runtime artifacts (`data/decisions.jsonl`, `data/runs.jsonl`,
|
||||
`data/categories.json`, `data/skills/`, `data/drafts/`) are gitignored too.
|
||||
|
||||
> **Codegen timeout:** do not cap codegen `max_tokens`. The reasoning model
|
||||
> writes for 25–45 min; `codegen.timeout` defaults to 1200 s and the staging
|
||||
> config raises it to 3600 s.
|
||||
> **Codegen timeout:** do not cap codegen `max_tokens`. A reasoning codegen
|
||||
> model can write for 25–45 min; `codegen.timeout` defaults to 1200 s and a
|
||||
> per-machine config may raise it to 3600 s.
|
||||
|
||||
---
|
||||
|
||||
@@ -508,10 +528,10 @@ python -m semif_agent.cli gateway [--platform simplex] [--dashboard]
|
||||
python -m semif_agent.cli bridge [--name simplex]
|
||||
```
|
||||
|
||||
On a bootstrap box, use the venv and set `HF_HOME` to the checkout's cache:
|
||||
On a provisioned host, use the venv and set `HF_HOME` to the checkout's cache:
|
||||
|
||||
```sh
|
||||
REPO=~/repos/semif-agent
|
||||
REPO=<your-checkout>
|
||||
HF_HOME="$REPO/.runtime/hf" "$REPO/.runtime/venv/bin/python" -m semif_agent.cli run
|
||||
```
|
||||
|
||||
@@ -652,14 +672,14 @@ committed seed never holds secrets.
|
||||
# anywhere, fast, stdlib only
|
||||
python3 -m pytest tests/ -q --ignore=tests/integration
|
||||
|
||||
# staging box only: real SemIf + real ollama
|
||||
~/repos/semif-agent/.runtime/venv/bin/python -m pytest tests/integration -q -s
|
||||
# where real SemIf + a real ollama are available (run from the checkout root)
|
||||
./.runtime/venv/bin/python -m pytest tests/integration -q -s
|
||||
```
|
||||
|
||||
Unit tests use the `ScriptedEngine` double (`tests/conftest.py`) to drive
|
||||
scheduling mechanics without a GGUF; data-structure tests cover queue ordering,
|
||||
dream cost and contract serialization. Integration tests exercise the real
|
||||
engine + LLM end to end and take ~100 s on the staging box.
|
||||
engine + LLM end to end.
|
||||
|
||||
**Fixtures are not the runtime.** Skill tests use real local endpoints (a
|
||||
loopback server, never a mock); a real run is the only proof an integration
|
||||
|
||||
+11
-20
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"_comment": "Per-machine config. config.json is gitignored; copy this file to config.json and adjust paths. The box (guppy) keeps its own config.json with local paths.",
|
||||
"_comment": "Per-machine config. config.json is gitignored. bootstrap.sh seeds config.json from this file only when config.json does not exist, and NOTHING writes config.json afterwards — only a human edits it. Pinned engine/tokenizer/GGUF/simplex-chat refs live in the committed pins.json, not here. Every machine keeps its own config.json.",
|
||||
"tau": 0.6,
|
||||
"max_reentries": 3,
|
||||
"creation_approval": false,
|
||||
@@ -10,22 +10,16 @@
|
||||
},
|
||||
"queue": {"max_size": 100, "age_rate": 0.01},
|
||||
"engine": {
|
||||
"_comment": "Per-machine engine settings only. The pinned engine/tokenizer/GGUF refs (semif_repo, semif_ref, gguf_url, gguf_sha256, source, revision) live in the committed pins.json — bumped on update, never per-machine config. The GGUF path is derived from pins.json's engine.gguf_url under .runtime/models/; set `gguf` here only to override it with a custom path.",
|
||||
"backend": "llamacpp",
|
||||
"source": "Qwen/Qwen3.5-4B",
|
||||
"revision": "851bf6e806efd8d0a36b00ddf55e13ccb7b8cd0a",
|
||||
"gguf": "/home/abby/models/Qwen3.5-4B-Q4_K_M.gguf",
|
||||
"gguf_url": "https://huggingface.co/bartowski/Qwen_Qwen3.5-4B-GGUF/resolve/main/Qwen_Qwen3.5-4B-Q4_K_M.gguf",
|
||||
"gguf_sha256": "13c16f426047e2de38cd075bdade4a7bcbc8c774384876f677740cda65f8a983",
|
||||
"semif_repo": "https://github.com/TheoLeeCJ/SemIf.git",
|
||||
"semif_ref": "1f2dea3e25379f9dfc98cb83c324f00ab5deda37",
|
||||
"context_tokens": 4096,
|
||||
"threads": 8
|
||||
},
|
||||
"llm": {
|
||||
"_comment": "Small OpenAI-compatible model that authors a new category/skill title + description (never the runnable body — that is `codegen` below). Deliberately its own endpoint/model, so it can be local and fast even when codegen is remote. Runs on THIS machine's local ollama; bootstrap sets base_url from --llm-url (default http://127.0.0.1:11434) and pulls `model` if it is missing. Uses the same provider machinery as codegen (real SSE stream, token budget, idle watchdog); short JSON replies. Sampler params (temperature/top_p/presence_penalty/frequency_penalty) are opt-in: an unset value is omitted from the request so the server's model default applies — set them here only when you know the right values for the model. The draft is authored asynchronously by a single-slot worker and the request re-runs when it lands; an unreachable endpoint is graceful (traced, user notified), not fatal. disable_thinking sends reasoning_effort:none so a reasoning model answers the short JSON directly instead of spending the reply budget on hidden chain-of-thought (set false only for an endpoint that rejects the parameter). provider selects the transport: \"ollama\" (default; a local OpenAI-compatible server, context auto-detected via /api/show) or \"opencode\" (the hosted OpenCode Console inference API at https://opencode.ai/inference/openai/v1 — set model to a Chat Completions family id such as kimi-k2.7-code or glm-5.3, and provide api_key or api_key_env; the ollama probe is skipped).",
|
||||
"_comment": "Small OpenAI-compatible model that authors a new category/skill title + description (never the runnable body — that is `codegen` below). Deliberately its own endpoint/model, so it can be local and fast even when codegen is remote. Runs on THIS machine's local ollama; bootstrap reads base_url/model from here (a --llm-url/--llm-model flag overrides for that run only) and pulls `model` if it is missing. `model` is required (no default): set it to a model the endpoint serves. Uses the same provider machinery as codegen (real SSE stream, token budget, idle watchdog); short JSON replies. Sampler params (temperature/top_p/presence_penalty/frequency_penalty) are opt-in: an unset value is omitted from the request so the server's model default applies — set them here only when you know the right values for the model. The draft is authored asynchronously by a single-slot worker and the request re-runs when it lands; an unreachable endpoint is graceful (traced, user notified), not fatal. disable_thinking sends reasoning_effort:none so a reasoning model answers the short JSON directly instead of spending the reply budget on hidden chain-of-thought (set false only for an endpoint that rejects the parameter). provider selects the transport: \"ollama\" (default; a local OpenAI-compatible server, context auto-detected via /api/show) or \"opencode\" (the hosted OpenCode Console inference API at https://opencode.ai/inference/openai/v1 — set model to a Chat Completions family id such as kimi-k2.7-code or glm-5.3, and provide api_key or api_key_env; the ollama probe is skipped).",
|
||||
"provider": "ollama",
|
||||
"base_url": "http://localhost:11434/v1",
|
||||
"model": "qwen3.5:4b",
|
||||
"model": "",
|
||||
"api_key": "",
|
||||
"api_key_env": "",
|
||||
"user_agent": "",
|
||||
@@ -41,14 +35,14 @@
|
||||
"disable_thinking": true
|
||||
},
|
||||
"codegen": {
|
||||
"_comment": "OpenAI-compatible model that writes runnable skill bodies. Runs on a REMOTE ollama host (bootstrap sets base_url from --codegen-url, default guppy http://192.168.8.181:11434); the local small model is `llm` above. Bodies perform real actions against the user's configured services via stdlib transports, read every operational value from ctx.config, and declare their integration (INTEGRATION: service/transport/config_vars). Larger/slower than the decision or title/description model. The transport always streams so the client-side token budget (output cap / peak total fill) can abort a runaway in real time; stream only toggles console echo of tokens. timeout is total seconds; idle_warn/idle_timeout surface a silent (wedged) stream. The context window is auto-detected via ollama /api/show; context_window is the manual fallback (0 = auto/default 100000). smart_limit/warn_limit and max_fill_ratio/warn_fill_ratio bound total fill; max_output caps streamed output (>=1 absolute tokens, 0<x<1 fraction of window); chars_per_token converts chars to the token estimate. temperature/top_p/presence_penalty/frequency_penalty are opt-in: an unset value is omitted from the request so the server's model/Modelfile default applies; set them here only when you know the right values for the model. A rejected body retries with a fresh short prompt (max_attempts attempts), reusing the same sampler params. elicitation asks the product owner implementation questions before the body is written (posted to the question queue; every front end defers). After the body lands it is reviewed for real-action fidelity, then the data contract (contract.json) is derived in a separate call, then skill.test.py (hermetic mechanics test: loopback http.server for HTTP bodies, fixtures inline, no external network) in a shared-context call, and the test is auto-run as a subprocess (test_timeout seconds); on failure a 3-option SemIf decision (code/contract/test) regenerates the failing piece, bounded by test_max_attempts. contract_search.enabled auto-populates the skill config.json via SemIf against the global + category config. provider selects the transport: \"ollama\" (default; local OpenAI-compatible server, context auto-detected via /api/show) or \"opencode\" (the hosted OpenCode Console inference API at https://opencode.ai/inference/openai/v1 — set model to a Chat Completions family id such as kimi-k2.7-code, glm-5.3, or deepseek-v4.1-flash, and provide api_key or api_key_env; the ollama probe is skipped).",
|
||||
"_comment": "OpenAI-compatible model that writes runnable skill bodies. Runs on a REMOTE ollama host (bootstrap reads base_url/model from here; a --codegen-url/--codegen-model flag overrides for that run only); the local small model is `llm` above. `model` is required (no default): set it to a code-capable model the endpoint serves. Bodies perform real actions against the user's configured services via stdlib transports, read every operational value from ctx.config, and declare their integration (INTEGRATION: service/transport/config_vars). Larger/slower than the decision or title/description model. The transport always streams so the client-side token budget (output cap / peak total fill) can abort a runaway in real time; stream only toggles console echo of tokens. timeout is total seconds; idle_warn/idle_timeout surface a silent (wedged) stream. The context window is auto-detected via ollama /api/show; context_window is the manual fallback (0 = auto/default 100000). smart_limit/warn_limit and max_fill_ratio/warn_fill_ratio bound total fill; max_output caps streamed output (>=1 absolute tokens, 0<x<1 fraction of window); chars_per_token converts chars to the token estimate. temperature/top_p/presence_penalty/frequency_penalty are opt-in: an unset value is omitted from the request so the server's model/Modelfile default applies; set them here only when you know the right values for the model. A rejected body retries with a fresh short prompt (max_attempts attempts), reusing the same sampler params. elicitation asks the product owner implementation questions before the body is written (posted to the question queue; every front end defers). After the body lands it is reviewed for real-action fidelity, then the data contract (contract.json) is derived in a separate call, then skill.test.py (hermetic mechanics test: loopback http.server for HTTP bodies, fixtures inline, no external network) in a shared-context call, and the test is auto-run as a subprocess (test_timeout seconds); on failure a 3-option SemIf decision (code/contract/test) regenerates the failing piece, bounded by test_max_attempts. contract_search.enabled auto-populates the skill config.json via SemIf against the global + category config. provider selects the transport: \"ollama\" (default; local OpenAI-compatible server, context auto-detected via /api/show) or \"opencode\" (the hosted OpenCode Console inference API at https://opencode.ai/inference/openai/v1 — set model to a Chat Completions family id such as kimi-k2.7-code, glm-5.3, or deepseek-v4.1-flash, and provide api_key or api_key_env; the ollama probe is skipped).",
|
||||
"provider": "ollama",
|
||||
"base_url": "http://localhost:11434/v1",
|
||||
"model": "qwen38-iq3s",
|
||||
"model": "",
|
||||
"api_key": "",
|
||||
"api_key_env": "",
|
||||
"user_agent": "",
|
||||
"timeout": 1200,
|
||||
"timeout": 3600,
|
||||
"stream": true,
|
||||
"idle_warn": 60,
|
||||
"idle_timeout": 180,
|
||||
@@ -104,10 +98,7 @@
|
||||
"trace": "data/runs.jsonl",
|
||||
"category_registry": "data/categories.json",
|
||||
"simplex_chat": {
|
||||
"_comment": "Pinned simplex-chat daemon(s). The command gateway talks to the daemon on `port` (profile .runtime/simplex/, unit semif-simplex.service). The SimpleX forwarding bridge owns its OWN daemon/profile on `forward_port` (profile .runtime/simplex-forward/, unit semif-simplex-forward.service) so messaging UX never shares the command bot's identity. bootstrap.sh downloads this exact binary (sha256 verified) into .runtime/bin/ and renders both units. Bump version/bin_url/sha256 together. gateway.simplex.ws_url must match `port`; bridges.simplex.ws_url must match `forward_port`.",
|
||||
"version": "v7.0.3",
|
||||
"bin_url": "https://github.com/simplex-chat/simplex-chat/releases/download/v7.0.3/simplex-chat-ubuntu-24_04-x86_64",
|
||||
"sha256": "895fb14cfaa662d1c0947f2f871141fc89680fe3e70bff64c366cbe9e59aa4f0",
|
||||
"_comment": "Per-machine simplex-chat daemon settings. The pinned binary (version/bin_url/sha256) lives in the committed pins.json, not here. The command gateway talks to the daemon on `port` (profile .runtime/simplex/, unit semif-simplex.service). The SimpleX forwarding bridge owns its OWN daemon/profile on `forward_port` (profile .runtime/simplex-forward/, unit semif-simplex-forward.service) so messaging UX never shares the command bot's identity. bootstrap.sh renders both units from these values. gateway.simplex.ws_url must match `port`; bridges.simplex.ws_url must match `forward_port`.",
|
||||
"port": 5226,
|
||||
"display_name": "semif",
|
||||
"forward_port": 5228,
|
||||
@@ -117,7 +108,7 @@
|
||||
"_comment": "Standalone third-party API bridges: a simple, secure local HTTP layer between codegen-authored skill bodies and real system services. Each bridge runs as its own process (`python -m semif_agent.cli bridge [--name NAME]`), one process per service daemon, and never runs inside the command gateway — gateway isolation is non-negotiable (see AGENTS.md). The bridge catalog (names, endpoints, config vars) is injected into the code-generation prompts via `semif_agent.bridges.describe_bridges()`.",
|
||||
"simplex": {
|
||||
"_comment": "SimpleX forwarding bridge: buffers every inbound DM (no allowlist — the point is to see who reached the bot through its invite link), and serves invite-link / read / send over HTTP. It owns its own simplex-chat daemon/profile (`ws_url`, `forward_port` above), separate from the command gateway's. Skills use the top-level `simplex_bridge_url`; keep it in sync with host/port. Binds localhost only; an optional `token` is required in the X-Semif-Token header when set.",
|
||||
"enabled": false,
|
||||
"enabled": true,
|
||||
"host": "127.0.0.1",
|
||||
"port": 5227,
|
||||
"token": "",
|
||||
@@ -131,7 +122,7 @@
|
||||
"gateway": {
|
||||
"_comment": "Messenger COMMAND intake — and nothing else. `python -m semif_agent.cli gateway` connects to the command simplex-chat daemon (`simplex_chat.port`) over its JSON WebSocket API and feeds authorized DM text through the normal gate/score/queue/dispatch pipeline; results, authoring questions, and repair offers are sent back to the originating chat. It must never read a contact's history, show/create invite links, or compose on the user's behalf — that is the independent bridge services' job (`bridges`). Requires the optional `websockets` package (lazy-imported; the gateway refuses to start without it). allowed_users entries match either a numeric contactId or a display name; default is deny-all unless allow_all_users is set. home_channel receives messages whose origin chat is unknown (e.g. a background repair offer). text_batch_delay concatenates rapid-fire messages from one contact. Groups/attachments are not supported in this first cut.",
|
||||
"simplex": {
|
||||
"enabled": false,
|
||||
"enabled": true,
|
||||
"ws_url": "ws://127.0.0.1:5226",
|
||||
"allowed_users": [],
|
||||
"allow_all_users": false,
|
||||
@@ -142,5 +133,5 @@
|
||||
"reconnect": {"initial": 1.0, "max": 60.0, "jitter": 0.2}
|
||||
}
|
||||
},
|
||||
"dashboard": {"port": 8765, "host": "0.0.0.0"}
|
||||
"dashboard": {"port": 8765, "host": "127.0.0.1"}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"_comment": "Committed pin manifest for the external artifacts this repo downloads: the SemIf engine ref, the pinned GGUF, the HF tokenizer revision, and the simplex-chat binary. These are code-owned, deployment-independent values bumped by a git change and picked up on the next `scripts/bootstrap.sh` run. They are deliberately NOT in config.json (per-machine user config): a ref that changes with every update is not user configuration. The agent reads engine.source/revision from here; the GGUF path is derived from engine.gguf_url unless config.json overrides engine.gguf.",
|
||||
"engine": {
|
||||
"semif_repo": "https://github.com/TheoLeeCJ/SemIf.git",
|
||||
"semif_ref": "1f2dea3e25379f9dfc98cb83c324f00ab5deda37",
|
||||
"gguf_url": "https://huggingface.co/bartowski/Qwen_Qwen3.5-4B-GGUF/resolve/main/Qwen_Qwen3.5-4B-Q4_K_M.gguf",
|
||||
"gguf_sha256": "13c16f426047e2de38cd075bdade4a7bcbc8c774384876f677740cda65f8a983",
|
||||
"source": "Qwen/Qwen3.5-4B",
|
||||
"revision": "851bf6e806efd8d0a36b00ddf55e13ccb7b8cd0a"
|
||||
},
|
||||
"simplex_chat": {
|
||||
"version": "v7.0.3",
|
||||
"bin_url": "https://github.com/simplex-chat/simplex-chat/releases/download/v7.0.3/simplex-chat-ubuntu-24_04-x86_64",
|
||||
"sha256": "895fb14cfaa662d1c0947f2f871141fc89680fe3e70bff64c366cbe9e59aa4f0"
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
# never imports torch (it's lazy inside direct.score), and numpy 2.2.6 has no
|
||||
# cp314 wheel (source build fails). So semif-phase1 is installed with
|
||||
# `--no-deps` and exactly this set is brought in instead. The pins match the
|
||||
# proven guppy venv; huggingface-hub is pinned to 1.31.0 (semif-phase1's
|
||||
# proven staging venv; huggingface-hub is pinned to 1.31.0 (semif-phase1's
|
||||
# declared version) so the pip resolver stays quiet about it.
|
||||
numpy==2.3.5
|
||||
transformers==5.17.0
|
||||
|
||||
+143
-147
@@ -1,15 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
# Provision a new Ubuntu machine into a running semif-agent staging box.
|
||||
# Provision a new Ubuntu machine into a running semif-agent host.
|
||||
#
|
||||
# Idempotent: safe to rerun; every stage no-ops on already-provisioned state,
|
||||
# so it can also bootstrap a machine of unknown state. The small self-assessment
|
||||
# model runs on this machine's local ollama (bootstrap pulls it); only codegen
|
||||
# points at a remote ollama host (default: guppy). This script installs NO ollama.
|
||||
# so it can also bootstrap a machine of unknown state. The small
|
||||
# title/description model runs on this machine's local ollama (bootstrap pulls
|
||||
# it); codegen may point at a remote ollama host. This script installs NO ollama.
|
||||
#
|
||||
# Must be run from a semif-agent checkout (it reads pins from this checkout's
|
||||
# config.example.json); the checkout is used as-is and never re-cloned — only
|
||||
# the SemIf engine and the simplex-chat binary are fetched. Clone the agent
|
||||
# repo first (its SSH key must be registered on Gitea).
|
||||
# Must be run from a semif-agent checkout. The checkout is used as-is and never
|
||||
# re-cloned — only the SemIf engine and the simplex-chat binary are fetched.
|
||||
# Clone the agent repo first (its SSH key must be registered on your git host).
|
||||
#
|
||||
# config.json is the per-machine USER config and this script NEVER writes it. It
|
||||
# seeds config.json from config.example.json only when config.json is absent,
|
||||
# then reads every per-machine value from config.json; only a human edits
|
||||
# config.json afterwards. Pinned external refs (SemIf commit, GGUF url+sha256,
|
||||
# HF tokenizer revision, simplex-chat version/url+sha256) live in the committed
|
||||
# pins.json and the python dep pins in requirements/staging.txt — bump those
|
||||
# (via git) and rerun to upgrade.
|
||||
#
|
||||
# Every installation artifact lives INSIDE this checkout under .runtime/
|
||||
# (gitignored), so an end user can find and debug the whole stack in one tree:
|
||||
@@ -20,41 +27,31 @@
|
||||
# Only artifacts that operationally must live elsewhere are outside: the SSH
|
||||
# key (~/.ssh) and the real systemd user dir/linger.
|
||||
#
|
||||
# Pins (SemIf commit, GGUF url+sha256, simplex-chat url+sha256) are read from
|
||||
# config.example.json's engine/simplex_chat blocks, and the python dep pins
|
||||
# from requirements/staging.txt — all committed here and the single source of
|
||||
# truth; bump those and rerun to upgrade.
|
||||
# Flags override the values read from config.json FOR THIS RUN ONLY; nothing is
|
||||
# written back to config.json.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/bootstrap.sh [--llm-url URL] [--codegen-url URL] [--threads N]
|
||||
# [--copy-data SRC] [--public-dashboard]
|
||||
# [--simplex-allowed-users CSV] [--simplex-home-channel X]
|
||||
# [--simplex-display-name NAME] [-h]
|
||||
# scripts/bootstrap.sh [--llm-url URL] [--codegen-url URL] [--llm-model MODEL]
|
||||
# [--codegen-model MODEL] [--copy-data SRC] [-h]
|
||||
#
|
||||
# Run as the human user; sudo is used internally for system bits.
|
||||
set -euo pipefail
|
||||
|
||||
LLM_URL="http://127.0.0.1:11434"
|
||||
CODEGEN_URL="http://192.168.8.181:11434"
|
||||
THREADS=""
|
||||
LLM_URL=""
|
||||
CODEGEN_URL=""
|
||||
LLM_MODEL=""
|
||||
CODEGEN_MODEL=""
|
||||
COPY_DATA=""
|
||||
PUBLIC_DASHBOARD=0
|
||||
SIMPLEX_ALLOWED_USERS=""
|
||||
SIMPLEX_HOME_CHANNEL=""
|
||||
SIMPLEX_DISPLAY_NAME=""
|
||||
|
||||
usage() {
|
||||
sed -n '2,32p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
|
||||
sed -n '2,35p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
|
||||
echo
|
||||
echo " --llm-url URL ollama API for the small title/description model (default: $LLM_URL; this machine)"
|
||||
echo " --codegen-url URL ollama API for codegen skill bodies (default: $CODEGEN_URL)"
|
||||
echo " --threads N engine threads for config.json (default: config.example value)"
|
||||
echo " --copy-data SRC rsync SRC (e.g. abby@box:~/repos/semif-agent/data) to data/ — opt-in"
|
||||
echo " --public-dashboard bind dashboard to 0.0.0.0 instead of 127.0.0.1"
|
||||
echo " --simplex-allowed-users CSV comma-separated contactIds/display names the gateway accepts"
|
||||
echo " --simplex-home-channel ID gateway fallback channel for unsolicited messages"
|
||||
echo " --simplex-display-name NAME simplex-chat bot display name (default: config.example value)"
|
||||
echo " -h this help"
|
||||
echo " --llm-url URL override llm.base_url from config.json for this run (else config.json, else http://127.0.0.1:11434)"
|
||||
echo " --codegen-url URL override codegen.base_url from config.json for this run"
|
||||
echo " --llm-model MODEL override llm.model from config.json for this run (pulled if the local ollama lacks it)"
|
||||
echo " --codegen-model MODEL override codegen.model from config.json for this run"
|
||||
echo " --copy-data SRC rsync SRC (e.g. user@host:/path/to/semif-agent/data) to data/ — opt-in"
|
||||
echo " -h this help"
|
||||
exit "${1:-0}"
|
||||
}
|
||||
|
||||
@@ -62,12 +59,9 @@ while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--llm-url) LLM_URL="$2"; shift 2 ;;
|
||||
--codegen-url) CODEGEN_URL="$2"; shift 2 ;;
|
||||
--threads) THREADS="$2"; shift 2 ;;
|
||||
--llm-model) LLM_MODEL="$2"; shift 2 ;;
|
||||
--codegen-model) CODEGEN_MODEL="$2"; shift 2 ;;
|
||||
--copy-data) COPY_DATA="$2"; shift 2 ;;
|
||||
--public-dashboard) PUBLIC_DASHBOARD=1; shift ;;
|
||||
--simplex-allowed-users) SIMPLEX_ALLOWED_USERS="$2"; shift 2 ;;
|
||||
--simplex-home-channel) SIMPLEX_HOME_CHANNEL="$2"; shift 2 ;;
|
||||
--simplex-display-name) SIMPLEX_DISPLAY_NAME="$2"; shift 2 ;;
|
||||
-h|--help) usage 0 ;;
|
||||
*) echo "unknown option: $1" >&2; usage 1 ;;
|
||||
esac
|
||||
@@ -75,6 +69,8 @@ done
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
EXAMPLE="$REPO_ROOT/config.example.json"
|
||||
CONFIG="$REPO_ROOT/config.json"
|
||||
PINS="$REPO_ROOT/pins.json"
|
||||
|
||||
RUNTIME="$REPO_ROOT/.runtime"
|
||||
VENV="$RUNTIME/venv"
|
||||
@@ -92,51 +88,85 @@ if [[ ! -f "$EXAMPLE" ]]; then
|
||||
echo "config.example.json not found at $EXAMPLE — run from a semif-agent checkout" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "$PINS" ]]; then
|
||||
echo "pins.json not found at $PINS — run from a semif-agent checkout" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- read pins from config.example.json ------------------------------------
|
||||
read -r SEMIF_REPO SEMIF_REF GGUF_URL GGUF_SHA256 HF_SOURCE HF_REV \
|
||||
SIMPLEX_BIN_URL SIMPLEX_SHA256 SIMPLEX_PORT SIMPLEX_DISPLAY \
|
||||
SIMPLEX_FORWARD_PORT SIMPLEX_FORWARD_DISPLAY LLM_MODEL < <(
|
||||
python3 - "$EXAMPLE" <<'PY'
|
||||
# config.json is per-machine USER config. Seed it once from the template, then
|
||||
# never write it again — only a human edits config.json.
|
||||
if [[ ! -f "$CONFIG" ]]; then
|
||||
echo "== seeding config.json from config.example.json (edit it to configure this machine)"
|
||||
cp "$EXAMPLE" "$CONFIG"
|
||||
fi
|
||||
|
||||
# --- read pins from the committed pins.json ---------------------------------
|
||||
# The ASCII unit separator (\x1f) delimits fields so an empty value never
|
||||
# shifts the fields after it (space-splitting collapses runs of whitespace).
|
||||
IFS=$'\x1f' read -r SEMIF_REPO SEMIF_REF GGUF_URL GGUF_SHA256 HF_SOURCE HF_REV \
|
||||
SIMPLEX_BIN_URL SIMPLEX_SHA256 < <(
|
||||
python3 - "$PINS" <<'PY'
|
||||
import json, sys
|
||||
cfg = json.load(open(sys.argv[1]))
|
||||
e = cfg["engine"]
|
||||
s = cfg.get("simplex_chat", {})
|
||||
print(
|
||||
" ".join(
|
||||
[
|
||||
str(e.get("semif_repo", "")),
|
||||
str(e.get("semif_ref", "")),
|
||||
str(e.get("gguf_url", "")),
|
||||
str(e.get("gguf_sha256", "")),
|
||||
str(e.get("source", "")),
|
||||
str(e.get("revision", "")),
|
||||
str(s.get("bin_url", "")),
|
||||
str(s.get("sha256", "")),
|
||||
str(s.get("port", "")),
|
||||
str(s.get("display_name", "")),
|
||||
str(s.get("forward_port", "")),
|
||||
str(s.get("forward_display_name", "")),
|
||||
str(cfg.get("llm", {}).get("model", "")),
|
||||
]
|
||||
)
|
||||
)
|
||||
pins = json.load(open(sys.argv[1]))
|
||||
e = pins["engine"]
|
||||
s = pins.get("simplex_chat", {})
|
||||
print("\x1f".join([
|
||||
str(e.get("semif_repo", "")),
|
||||
str(e.get("semif_ref", "")),
|
||||
str(e.get("gguf_url", "")),
|
||||
str(e.get("gguf_sha256", "")),
|
||||
str(e.get("source", "")),
|
||||
str(e.get("revision", "")),
|
||||
str(s.get("bin_url", "")),
|
||||
str(s.get("sha256", "")),
|
||||
]))
|
||||
PY
|
||||
)
|
||||
|
||||
if [[ -z "$SEMIF_REPO" || -z "$SEMIF_REF" || -z "$GGUF_URL" || -z "$GGUF_SHA256" ]]; then
|
||||
echo "engine pins missing in $EXAMPLE (semif_repo/semif_ref/gguf_url/gguf_sha256)" >&2
|
||||
echo "engine pins missing in $PINS (semif_repo/semif_ref/gguf_url/gguf_sha256)" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z "$SIMPLEX_BIN_URL" || -z "$SIMPLEX_SHA256" || -z "$SIMPLEX_PORT" ]]; then
|
||||
echo "simplex_chat pins missing in $EXAMPLE (bin_url/sha256/port)" >&2
|
||||
if [[ -z "$SIMPLEX_BIN_URL" || -z "$SIMPLEX_SHA256" ]]; then
|
||||
echo "simplex_chat pins missing in $PINS (bin_url/sha256)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$SIMPLEX_DISPLAY_NAME" ]]; then
|
||||
SIMPLEX_DISPLAY="$SIMPLEX_DISPLAY_NAME"
|
||||
# --- read per-machine values from config.json (flags override for this run) --
|
||||
IFS=$'\x1f' read -r CFG_LLM_URL CFG_LLM_MODEL CFG_CODEGEN_URL CFG_CODEGEN_MODEL \
|
||||
SIMPLEX_PORT SIMPLEX_DISPLAY SIMPLEX_FORWARD_PORT SIMPLEX_FORWARD_DISPLAY < <(
|
||||
python3 - "$CONFIG" <<'PY'
|
||||
import json, sys
|
||||
cfg = json.load(open(sys.argv[1]))
|
||||
s = cfg.get("simplex_chat", {})
|
||||
def strip_v1(u):
|
||||
u = str(u or "").rstrip("/")
|
||||
return u[:-3] if u.endswith("/v1") else u
|
||||
print("\x1f".join([
|
||||
strip_v1(cfg.get("llm", {}).get("base_url")),
|
||||
str(cfg.get("llm", {}).get("model", "") or ""),
|
||||
strip_v1(cfg.get("codegen", {}).get("base_url")),
|
||||
str(cfg.get("codegen", {}).get("model", "") or ""),
|
||||
str(s.get("port", "")),
|
||||
str(s.get("display_name", "") or ""),
|
||||
str(s.get("forward_port", "")),
|
||||
str(s.get("forward_display_name", "") or ""),
|
||||
]))
|
||||
PY
|
||||
)
|
||||
|
||||
# A flag overrides config.json for this run only; config.json is never touched.
|
||||
LLM_URL="${LLM_URL:-${CFG_LLM_URL:-http://127.0.0.1:11434}}"
|
||||
CODEGEN_URL="${CODEGEN_URL:-$CFG_CODEGEN_URL}"
|
||||
LLM_MODEL="${LLM_MODEL:-$CFG_LLM_MODEL}"
|
||||
CODEGEN_MODEL="${CODEGEN_MODEL:-$CFG_CODEGEN_MODEL}"
|
||||
|
||||
if [[ -z "$SIMPLEX_PORT" || -z "$SIMPLEX_FORWARD_PORT" ]]; then
|
||||
echo "config.json: simplex_chat.port and simplex_chat.forward_port are required" >&2
|
||||
exit 1
|
||||
fi
|
||||
SIMPLEX_DISPLAY="${SIMPLEX_DISPLAY:-semif}"
|
||||
SIMPLEX_FORWARD_DISPLAY="${SIMPLEX_FORWARD_DISPLAY:-semif-forward}"
|
||||
|
||||
# Native ollama API bases (no /v1) for tags/pull; the clients use /v1.
|
||||
LLM_API="${LLM_URL%/v1}"; LLM_API="${LLM_API%/}"
|
||||
@@ -249,54 +279,9 @@ fi
|
||||
simplex_ok || { echo "simplex-chat sha256 mismatch: expected $SIMPLEX_SHA256" >&2; exit 1; }
|
||||
echo "== simplex-chat verified ($SIMPLEX_BIN)"
|
||||
|
||||
# --- stage 7: config.json -----------------------------------------------------------
|
||||
if [[ -f "$REPO_ROOT/config.json" ]]; then
|
||||
cp "$REPO_ROOT/config.json" "$REPO_ROOT/config.json.bak.$(date +%s)"
|
||||
fi
|
||||
echo "== writing config.json (llm -> $LLM_URL, codegen -> $CODEGEN_URL, runtime -> $RUNTIME)"
|
||||
python3 - "$REPO_ROOT/config.example.json" "$REPO_ROOT/config.json" "$THREADS" "$LLM_URL" "$CODEGEN_URL" \
|
||||
"$([ "$PUBLIC_DASHBOARD" = 1 ] && echo 0.0.0.0 || echo 127.0.0.1)" \
|
||||
"$REPO_ROOT" "$SIMPLEX_ALLOWED_USERS" "$SIMPLEX_HOME_CHANNEL" "$SIMPLEX_DISPLAY" <<'PY'
|
||||
import json, os, sys
|
||||
(example, out, threads, llm_url, codegen_url, dash_host, repo,
|
||||
allowed_csv, home_channel, display) = sys.argv[1:]
|
||||
cfg = json.load(open(example))
|
||||
eng = cfg["engine"]
|
||||
runtime = os.path.join(repo, ".runtime")
|
||||
eng["gguf"] = os.path.join(runtime, "models", os.path.basename(eng["gguf_url"]))
|
||||
if threads and threads != "__example__":
|
||||
eng["threads"] = int(threads)
|
||||
# The clients hit {base_url}/chat/completions on ollama's OpenAI-compat path,
|
||||
# which lives under /v1. The native API (/api/tags, /api/show) has no /v1.
|
||||
def v1(url):
|
||||
url = url.rstrip("/")
|
||||
return url if url.endswith("/v1") else url + "/v1"
|
||||
cfg["llm"]["base_url"] = v1(llm_url)
|
||||
cfg["codegen"]["base_url"] = v1(codegen_url)
|
||||
cfg["codegen"]["timeout"] = 3600
|
||||
cfg.setdefault("simplex_chat", {})["display_name"] = display
|
||||
cfg.setdefault("dashboard", {})["port"] = 8765
|
||||
cfg["dashboard"]["host"] = dash_host
|
||||
allowed = [u.strip() for u in allowed_csv.split(",") if u.strip()]
|
||||
simplex = cfg.setdefault("gateway", {}).setdefault("simplex", {})
|
||||
simplex["enabled"] = True
|
||||
simplex["ws_url"] = f"ws://127.0.0.1:{cfg['simplex_chat'].get('port', 5226)}"
|
||||
simplex["allowed_users"] = allowed
|
||||
simplex["home_channel"] = home_channel
|
||||
# The standalone SimpleX forwarding bridge owns its own daemon/profile
|
||||
# (simplex_chat.forward_port), separate from the command gateway, and serves the
|
||||
# invite-link / read / send HTTP API skills use. Expose its URL as the top-level
|
||||
# `simplex_bridge_url` so the data-contract config search auto-populates it, and
|
||||
# mirror its optional shared secret as `simplex_bridge_token` for the auth header.
|
||||
bridge = cfg.setdefault("bridges", {}).setdefault("simplex", {})
|
||||
bridge_port = int(bridge.get("port", 5227))
|
||||
bridge["enabled"] = True
|
||||
bridge["ws_url"] = f"ws://127.0.0.1:{cfg['simplex_chat'].get('forward_port', 5228)}"
|
||||
cfg["simplex_bridge_url"] = f"http://127.0.0.1:{bridge_port}"
|
||||
cfg["simplex_bridge_token"] = bridge.get("token", "") or ""
|
||||
simplex.pop("bridge", None) # legacy key; forwarding is a separate service now
|
||||
json.dump(cfg, open(out, "w"), indent=2)
|
||||
PY
|
||||
# config.json is USER config: seeded above if absent, read for per-machine values,
|
||||
# and never written by this script. Edit config.json to change endpoints, models,
|
||||
# ports, the dashboard bind, or the gateway allowlist.
|
||||
|
||||
# --- stage 8: systemd user units -----------------------------------------------------
|
||||
render_unit() {
|
||||
@@ -405,43 +390,51 @@ echo "== verifying imports"
|
||||
|
||||
# The small self-assessment model runs on this machine's local ollama; ensure it
|
||||
# is pulled so assess/elicitation/fidelity work without a remote dependency.
|
||||
echo "== llm ollama ($LLM_API), model $LLM_MODEL"
|
||||
if ! curl -sf --max-time 5 "$LLM_API/api/tags" >/dev/null 2>&1; then
|
||||
echo "WARN: no local ollama at $LLM_API — install/run ollama and pull $LLM_MODEL" >&2
|
||||
echo " (bootstrap installs no ollama; only codegen is remote)" >&2
|
||||
if [[ -z "$LLM_MODEL" ]]; then
|
||||
echo "WARN: llm.model is not set in config.json — set it (and codegen.model) before starting the agent" >&2
|
||||
else
|
||||
LLM_TAGS="$(curl -sf --max-time 5 "$LLM_API/api/tags" || true)"
|
||||
if grep -qF "\"$LLM_MODEL\"" <<<"$LLM_TAGS"; then
|
||||
echo "llm model $LLM_MODEL: present"
|
||||
echo "== llm ollama ($LLM_API), model $LLM_MODEL"
|
||||
if ! curl -sf --max-time 5 "$LLM_API/api/tags" >/dev/null 2>&1; then
|
||||
echo "WARN: no local ollama at $LLM_API — install/run ollama and pull $LLM_MODEL" >&2
|
||||
echo " (bootstrap installs no ollama; only codegen is remote)" >&2
|
||||
else
|
||||
echo "== pulling llm model $LLM_MODEL from $LLM_API"
|
||||
if ! curl -sf --max-time 3600 "$LLM_API/api/pull" -H 'Content-Type: application/json' \
|
||||
-d "{\"model\":\"$LLM_MODEL\",\"stream\":false}" >/dev/null; then
|
||||
echo "WARN: /api/pull failed; trying the ollama CLI" >&2
|
||||
if command -v ollama >/dev/null 2>&1; then
|
||||
ollama pull "$LLM_MODEL" || echo "WARN: could not pull $LLM_MODEL" >&2
|
||||
else
|
||||
echo "WARN: could not pull $LLM_MODEL (no ollama CLI)" >&2
|
||||
LLM_TAGS="$(curl -sf --max-time 5 "$LLM_API/api/tags" || true)"
|
||||
if grep -qF "\"$LLM_MODEL\"" <<<"$LLM_TAGS"; then
|
||||
echo "llm model $LLM_MODEL: present"
|
||||
else
|
||||
echo "== pulling llm model $LLM_MODEL from $LLM_API"
|
||||
if ! curl -sf --max-time 3600 "$LLM_API/api/pull" -H 'Content-Type: application/json' \
|
||||
-d "{\"model\":\"$LLM_MODEL\",\"stream\":false}" >/dev/null; then
|
||||
echo "WARN: /api/pull failed; trying the ollama CLI" >&2
|
||||
if command -v ollama >/dev/null 2>&1; then
|
||||
ollama pull "$LLM_MODEL" || echo "WARN: could not pull $LLM_MODEL" >&2
|
||||
else
|
||||
echo "WARN: could not pull $LLM_MODEL (no ollama CLI)" >&2
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# The OpenAI-compat chat path is what llm actually hits; probe it explicitly.
|
||||
LLM_V1_OK="$(curl -sf --max-time 60 "$LLM_V1/chat/completions" -H 'Content-Type: application/json' \
|
||||
-d "{\"model\":\"$LLM_MODEL\",\"messages\":[{\"role\":\"user\",\"content\":\"hi\"}],\"stream\":false,\"options\":{\"num_predict\":1}}" || true)"
|
||||
if grep -qE 'chatcmpl|"choices"' <<<"$LLM_V1_OK"; then
|
||||
echo "llm /v1/chat/completions ($LLM_MODEL): OK"
|
||||
else
|
||||
echo "WARN: local llm /v1/chat/completions returned no completion" >&2
|
||||
# The OpenAI-compat chat path is what llm actually hits; probe it explicitly.
|
||||
LLM_V1_OK="$(curl -sf --max-time 60 "$LLM_V1/chat/completions" -H 'Content-Type: application/json' \
|
||||
-d "{\"model\":\"$LLM_MODEL\",\"messages\":[{\"role\":\"user\",\"content\":\"hi\"}],\"stream\":false,\"options\":{\"num_predict\":1}}" || true)"
|
||||
if grep -qE 'chatcmpl|"choices"' <<<"$LLM_V1_OK"; then
|
||||
echo "llm /v1/chat/completions ($LLM_MODEL): OK"
|
||||
else
|
||||
echo "WARN: local llm /v1/chat/completions returned no completion" >&2
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Codegen is the remote larger model (e.g. guppy). Warn only — never auto-pull.
|
||||
echo "== codegen ollama ($CODEGEN_API)"
|
||||
CODEGEN_TAGS="$(curl -sf --max-time 5 "$CODEGEN_API/api/tags" || true)"
|
||||
if grep -qE "qwen38-iq3s" <<<"$CODEGEN_TAGS"; then
|
||||
echo "codegen serves qwen38-iq3s: OK"
|
||||
# Codegen is the larger model, possibly on a remote host. Warn only — never auto-pull.
|
||||
if [[ -n "$CODEGEN_URL" && -n "$CODEGEN_MODEL" ]]; then
|
||||
echo "== codegen ollama ($CODEGEN_API)"
|
||||
CODEGEN_TAGS="$(curl -sf --max-time 5 "$CODEGEN_API/api/tags" || true)"
|
||||
if grep -qF "$CODEGEN_MODEL" <<<"$CODEGEN_TAGS"; then
|
||||
echo "codegen serves $CODEGEN_MODEL: OK"
|
||||
else
|
||||
echo "WARN: codegen host $CODEGEN_API serves no $CODEGEN_MODEL (offline? new-skill authoring will fail)" >&2
|
||||
fi
|
||||
else
|
||||
echo "WARN: codegen host $CODEGEN_API serves no qwen38-iq3s (offline? new-skill authoring will fail)" >&2
|
||||
echo "WARN: codegen.base_url/model is not set in config.json — set it before starting the agent" >&2
|
||||
fi
|
||||
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
@@ -455,6 +448,9 @@ fi
|
||||
cat <<EOF
|
||||
|
||||
Done. Next steps:
|
||||
1. Edit config.json — set llm.model/llm.base_url and codegen.model/codegen.base_url.
|
||||
bootstrap.sh seeded config.json from config.example.json (if it was absent)
|
||||
and NEVER rewrites it; only you edit config.json.
|
||||
cd "$REPO_ROOT"
|
||||
HF_HOME="$HF_CACHE" "$PYTHON" -m semif_agent.cli run
|
||||
HF_HOME="$HF_CACHE" "$PYTHON" -m pytest tests/integration -q -s (needs real engine+LLM)
|
||||
|
||||
@@ -13,12 +13,12 @@ Navigation is two-stage at both levels, and the guards are the create doors:
|
||||
This replays a hand-labeled eval set through the **real** decision engine and
|
||||
the **real** skill tree, measuring each guard's probability per request so the
|
||||
floors can be placed between the true matches and the true mismatches. Run it on
|
||||
a box with the pinned engine (jarvis):
|
||||
a host with the pinned engine:
|
||||
|
||||
.runtime/venv/bin/python scripts/tune_navigation.py
|
||||
.runtime/venv/bin/python scripts/tune_navigation.py --level leaf --tau 0.6
|
||||
|
||||
The tree is whatever the box currently has loaded (committed seeds + the runtime
|
||||
The tree is whatever the host currently has loaded (committed seeds + the runtime
|
||||
`data/skills/`), so an expectation naming a skill that is not present is
|
||||
reported as N/A rather than counted wrong. Labels are hand-written ground truth;
|
||||
self-labeled decision rows are not evidence. Nothing is written to the runtime
|
||||
|
||||
+72
-14
@@ -1,6 +1,6 @@
|
||||
"""CLI entrypoint: interactive REPL, scripted JSONL mode, and subcommands.
|
||||
|
||||
Run on the box with SemIf + a GGUF + a local OpenAI-compatible server:
|
||||
Run on a host with SemIf + a GGUF + a local OpenAI-compatible server:
|
||||
|
||||
python -m semif_agent.cli run # REPL
|
||||
python -m semif_agent.cli run --script inputs.jsonl
|
||||
@@ -76,6 +76,23 @@ def _opt_float(value) -> float | None:
|
||||
return None if value is None else float(value)
|
||||
|
||||
|
||||
def _required_model(cfg: dict, provider: str) -> str:
|
||||
"""The configured model name, or a clear fatal error.
|
||||
|
||||
There is no default: which model an endpoint serves is deployment-specific,
|
||||
so the per-machine config must name it rather than the code guessing a model
|
||||
the endpoint may not have. Failing fast turns a missing model into an
|
||||
actionable config error instead of a request to a model that isn't there.
|
||||
"""
|
||||
model = str(cfg.get("model") or "").strip()
|
||||
if not model:
|
||||
raise SystemExit(
|
||||
f"config.json: {provider}.model is required "
|
||||
f"(set it to a model your {provider} endpoint serves)"
|
||||
)
|
||||
return model
|
||||
|
||||
|
||||
def _provider_endpoint(cfg: dict, default_base: str) -> dict:
|
||||
"""Endpoint kwargs shared by the llm/codegen clients.
|
||||
|
||||
@@ -99,35 +116,76 @@ def _provider_endpoint(cfg: dict, default_base: str) -> dict:
|
||||
def load_config(path: str = "config.json") -> dict:
|
||||
"""Load config.json and anchor its runtime paths to the checkout root.
|
||||
|
||||
config.json is the per-machine user config and is required: bootstrap.sh
|
||||
seeds it from config.example.json once, and only a human edits it. There is
|
||||
no in-code fallback — a missing config.json is a hard error.
|
||||
|
||||
Path-valued keys (`skill_seeds`, `skill_bodies`, `category_registry`, `log`,
|
||||
`trace`) resolve against REPO_ROOT, not the process cwd, so a fresh clone
|
||||
loads its committed seeds and writes runtime artifacts into the checkout no
|
||||
matter where the CLI is invoked from. Absolute values pass through untouched.
|
||||
"""
|
||||
config = json.loads(Path(path).read_text())
|
||||
config_path = Path(path)
|
||||
if not config_path.is_file():
|
||||
raise SystemExit(
|
||||
f"config.json not found at {config_path} — run scripts/bootstrap.sh "
|
||||
f"to seed it from config.example.json, then configure it"
|
||||
)
|
||||
config = json.loads(config_path.read_text())
|
||||
for key in _PATH_KEYS:
|
||||
config[key] = _anchor_path(config.get(key) or _PATH_DEFAULTS[key])
|
||||
return config
|
||||
|
||||
|
||||
def build_scheduler(config: dict) -> tuple[Scheduler, dict]:
|
||||
engine = SemIfEngine(
|
||||
EngineConfig(
|
||||
backend=config.get("engine", {}).get("backend", "llamacpp"),
|
||||
source=config.get("engine", {}).get("source", ""),
|
||||
revision=config.get("engine", {}).get("revision", ""),
|
||||
gguf=config.get("engine", {}).get("gguf", ""),
|
||||
context_tokens=int(config.get("engine", {}).get("context_tokens", 4096)),
|
||||
threads=config.get("engine", {}).get("threads"),
|
||||
)
|
||||
def load_pins(path: str | None = None) -> dict:
|
||||
"""Load the committed pin manifest (pins.json) that owns every external ref.
|
||||
|
||||
Pins are code, not per-machine config: the SemIf engine commit, GGUF
|
||||
url+sha256, HF tokenizer revision, and simplex-chat version/url+sha256 live
|
||||
in pins.json so a `git pull` bump propagates on the next bootstrap run
|
||||
instead of being frozen in each machine's config.json.
|
||||
"""
|
||||
pins_path = Path(path) if path else REPO_ROOT / "pins.json"
|
||||
if not pins_path.is_file():
|
||||
raise SystemExit(f"pins.json not found at {pins_path}")
|
||||
return json.loads(pins_path.read_text())
|
||||
|
||||
|
||||
def build_engine_config(config: dict, pins: dict | None = None) -> EngineConfig:
|
||||
"""Engine settings for a run: per-machine tuning from config.json, pinned
|
||||
refs from pins.json.
|
||||
|
||||
`engine.backend`/`context_tokens`/`threads` are per-machine config. The
|
||||
tokenizer source/revision and the GGUF are pins; the GGUF path is derived
|
||||
from the pin's filename under `.runtime/models/`, unless config.json sets an
|
||||
explicit `engine.gguf` override.
|
||||
"""
|
||||
pins = load_pins() if pins is None else pins
|
||||
eng = config.get("engine", {}) or {}
|
||||
pin_eng = pins.get("engine", {}) or {}
|
||||
override = eng.get("gguf")
|
||||
gguf = _anchor_path(override) if override else str(
|
||||
REPO_ROOT / ".runtime" / "models" / os.path.basename(pin_eng.get("gguf_url", ""))
|
||||
)
|
||||
return EngineConfig(
|
||||
backend=eng.get("backend", "llamacpp"),
|
||||
source=pin_eng.get("source", ""),
|
||||
revision=pin_eng.get("revision", ""),
|
||||
gguf=gguf,
|
||||
context_tokens=int(eng.get("context_tokens", 4096)),
|
||||
threads=eng.get("threads"),
|
||||
)
|
||||
|
||||
|
||||
def build_scheduler(config: dict) -> tuple[Scheduler, dict]:
|
||||
engine = SemIfEngine(build_engine_config(config))
|
||||
llm_cfg = config.get("llm", {}) or {}
|
||||
llm_provider = str(llm_cfg.get("provider", "ollama") or "ollama").lower()
|
||||
llm_cls = ConsoleLLMClient if llm_provider == "opencode" else LLMClient
|
||||
llm_endpoint = _provider_endpoint(llm_cfg, "http://localhost:11434/v1")
|
||||
llm = llm_cls(
|
||||
base_url=llm_endpoint["base_url"],
|
||||
model=llm_cfg.get("model", "qwen2.5:3b"),
|
||||
model=_required_model(llm_cfg, "llm"),
|
||||
timeout=float(llm_cfg.get("timeout", 600.0)),
|
||||
stream=bool(llm_cfg.get("stream", False)),
|
||||
idle_warn=float(llm_cfg.get("idle_warn", 30.0)),
|
||||
@@ -156,7 +214,7 @@ def build_scheduler(config: dict) -> tuple[Scheduler, dict]:
|
||||
)
|
||||
codegen = codegen_cls(
|
||||
base_url=codegen_endpoint["base_url"],
|
||||
model=codegen_cfg.get("model", "qwen38-iq3s"),
|
||||
model=_required_model(codegen_cfg, "codegen"),
|
||||
timeout=float(codegen_cfg.get("timeout", 1200.0)),
|
||||
stream=bool(codegen_cfg.get("stream", False)),
|
||||
idle_warn=float(codegen_cfg.get("idle_warn", 60.0)),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""Skill code-body generation through an OpenAI-compatible API.
|
||||
|
||||
The small `llm` provider authors a skill's title + description; writing the
|
||||
runnable body is a separate step: a larger OpenAI-compatible model (e.g.
|
||||
qwen38-iq3s on ollama) is prompted with the SKILL.md contract plus the request
|
||||
runnable body is a separate step: a larger OpenAI-compatible model (a
|
||||
code-capable model on your configured codegen endpoint) is prompted with the SKILL.md contract plus the request
|
||||
and the existing tree, and must reply with valid Python implementing `act` plus
|
||||
the `INTEGRATION` and `CONTRACT` module constants. The shared provider transport
|
||||
lives in `provider.py`.
|
||||
|
||||
@@ -8,9 +8,9 @@ request, answer a run paused for input, answer a deferred authoring question,
|
||||
resolve a repair offer, restart a skill write, and relabel a decision (human
|
||||
override).
|
||||
|
||||
The scheduler's engine and LLM are built lazily, so the dashboard runs on the
|
||||
thin dev box in replay mode (reads logs; submit degrades to a JSON error) and
|
||||
in live mode on the box with SemIf + a local LLM.
|
||||
The scheduler's engine and LLM are built lazily, so the dashboard runs in
|
||||
replay mode on a machine without the engine (reads logs; submit degrades to a
|
||||
JSON error) and in live mode on a host with SemIf + a local LLM.
|
||||
|
||||
python -m semif_agent.cli dashboard [--port 8765]
|
||||
"""
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ class LLMClient(OpenAICompatClient):
|
||||
from config.
|
||||
|
||||
`disable_thinking` defaults **on**: the small local model is often a
|
||||
reasoning model (e.g. `qwen3.5:4b`) whose hidden chain-of-thought consumes
|
||||
reasoning model whose hidden chain-of-thought consumes
|
||||
the short reply budget and leaves `content` empty — the same cap problem
|
||||
codegen documents, but here the reply is a ~30-token JSON object, so the
|
||||
thinking is pure overhead. Set `llm.disable_thinking: false` for a
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
engine used ONLY by pure-stdlib unit tests of scheduling mechanics (pausing,
|
||||
resuming, routing, authoring). The real engine is the decision-maker in
|
||||
production and in the integration tests; this double exists so a mechanics test
|
||||
can drive the loop without loading a GGUF on the dev machine, exactly as a
|
||||
can drive the loop without loading a GGUF locally, exactly as a
|
||||
loopback HTTP server stands in for a live service elsewhere.
|
||||
|
||||
It is not a mock of SemIf scoring: it answers each `DecisionRequest` with a
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""End-to-end pipeline test. Run ONLY on the box with real SemIf + real LLM.
|
||||
"""End-to-end pipeline test. Run ONLY where real SemIf + a real LLM are available.
|
||||
|
||||
python -m pytest tests/integration -q
|
||||
|
||||
@@ -12,7 +12,13 @@ import time
|
||||
|
||||
import pytest
|
||||
|
||||
from semif_agent.cli import _opt_float, build_scheduler, load_config
|
||||
from semif_agent.cli import (
|
||||
_opt_float,
|
||||
_required_model,
|
||||
build_engine_config,
|
||||
build_scheduler,
|
||||
load_config,
|
||||
)
|
||||
from semif_agent.codegen import (
|
||||
CodegenClient,
|
||||
generate_skill_body,
|
||||
@@ -40,18 +46,9 @@ from semif_agent.skills import (
|
||||
|
||||
|
||||
def require_real(config: dict):
|
||||
from semif_agent.engine import SemIfEngine, EngineConfig
|
||||
from semif_agent.engine import SemIfEngine
|
||||
|
||||
engine = SemIfEngine(
|
||||
EngineConfig(
|
||||
backend=config.get("engine", {}).get("backend", "llamacpp"),
|
||||
source=config.get("engine", {}).get("source", ""),
|
||||
revision=config.get("engine", {}).get("revision", ""),
|
||||
gguf=config.get("engine", {}).get("gguf", ""),
|
||||
context_tokens=int(config.get("engine", {}).get("context_tokens", 4096)),
|
||||
threads=config.get("engine", {}).get("threads"),
|
||||
)
|
||||
)
|
||||
engine = SemIfEngine(build_engine_config(config))
|
||||
try:
|
||||
engine._ensure_loaded()
|
||||
except EngineUnavailable as exc:
|
||||
@@ -61,7 +58,7 @@ def require_real(config: dict):
|
||||
def _isolate_runtime(config: dict, tmp_path) -> None:
|
||||
"""Point every runtime artifact at tmp_path.
|
||||
|
||||
Without this, persisted authoring output in the box's `data/categories.json`
|
||||
Without this, persisted authoring output in the runtime `data/categories.json`
|
||||
and `data/skills/` leaks into the tree and navigation routes to a stale stub
|
||||
instead of the injected fixture — an environment-dependent failure.
|
||||
"""
|
||||
@@ -294,8 +291,8 @@ def test_generate_skill_body_codegen(tmp_path):
|
||||
|
||||
The body must perform the action via a stdlib transport and declare
|
||||
INTEGRATION; the test is a hermetic mechanics check (loopback for HTTP), not
|
||||
proof of the live integration. Slow: uses the big codegen model
|
||||
(qwen38-iq3s by default). Run this one in the background and poll —
|
||||
proof of the live integration. Slow: uses the configured codegen model.
|
||||
Run this one in the background and poll —
|
||||
long-lived ssh sessions get SIGHUP'd.
|
||||
"""
|
||||
config = load_config()
|
||||
@@ -303,7 +300,7 @@ def test_generate_skill_body_codegen(tmp_path):
|
||||
codegen_cfg = config.get("codegen", {})
|
||||
client = CodegenClient(
|
||||
base_url=codegen_cfg.get("base_url", "http://localhost:11434/v1"),
|
||||
model=codegen_cfg.get("model", "qwen38-iq3s"),
|
||||
model=_required_model(codegen_cfg, "codegen"),
|
||||
timeout=float(codegen_cfg.get("timeout", 1200.0)),
|
||||
stream=True,
|
||||
temperature=_opt_float(codegen_cfg.get("temperature")),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
The scheduler is constructed with the lazy SemIfEngine (never loaded), so this
|
||||
runs anywhere without SemIf. Submit degrades to a JSON error, which is the
|
||||
expected behaviour on the thin dev box; relabel works against a seeded log.
|
||||
expected behaviour without an engine; relabel works against a seeded log.
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -223,7 +223,7 @@ def test_skill_writing_and_created_events_in_payload(tmp_path):
|
||||
category="tracking",
|
||||
skill="track_live",
|
||||
description="Follow a package in real time.",
|
||||
model="qwen38-iq3s",
|
||||
model="test-codegen",
|
||||
contract_ref="a1b2c3d",
|
||||
contract_dirty=True,
|
||||
)
|
||||
@@ -246,7 +246,7 @@ def test_skill_writing_and_created_events_in_payload(tmp_path):
|
||||
writing = next(e for e in run["events"] if e["kind"] == "skill_writing")
|
||||
assert writing["skill"] == "track_live"
|
||||
assert "real time" in writing["description"]
|
||||
assert writing["model"] == "qwen38-iq3s"
|
||||
assert writing["model"] == "test-codegen"
|
||||
assert writing["contract_ref"] == "a1b2c3d"
|
||||
assert writing["contract_dirty"] is True
|
||||
created = next(e for e in run["events"] if e["kind"] == "skill_created")
|
||||
|
||||
@@ -4,8 +4,8 @@ The gateway is the agent's command surface only. These tests exercise its own
|
||||
routing, authorization, and batching; parsing/accept/address live in
|
||||
`tests/test_simplex_ws.py`. The decision engine is never loaded and the LLM
|
||||
endpoint is unreachable, so scheduler calls degrade to errors — which is fine.
|
||||
The real `websockets` transport against a live `simplex-chat` daemon is a jarvis
|
||||
integration concern, not a dev-box unit test.
|
||||
The real `websockets` transport against a live `simplex-chat` daemon is a
|
||||
live-daemon integration concern, not a unit test.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
"""Guard: no deployment-specific artifacts in tracked files.
|
||||
|
||||
The repo is generic. Hostnames, addresses, usernames, absolute home paths, and
|
||||
the local model choices of any one deployment must not leak into tracked files —
|
||||
they belong in the gitignored ``local/`` folder (see ``local/ENVIRONMENT.md``).
|
||||
This test fails if a denylisted term reappears anywhere in the tree.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
# Generated/ignored trees and binary assets. ``local/`` is the intended home
|
||||
# for deployment specifics and is gitignored, so it is exempt.
|
||||
SKIP_DIRS = {".git", ".runtime", "local", "data", ".pytest_cache", "__pycache__"}
|
||||
SKIP_SUFFIXES = {
|
||||
".pyc", ".svg", ".png", ".jpg", ".jpeg", ".gif", ".ico",
|
||||
".woff", ".woff2", ".ttf", ".pdf", ".zip", ".gz",
|
||||
}
|
||||
SKIP_NAMES = {Path(__file__).name}
|
||||
# Fallback (non-git) walk: skip gitignored per-machine artifacts by name/pattern.
|
||||
SKIP_GLOBS = ("config.json", "*.bak.*", "*.log")
|
||||
|
||||
# label -> regex. Kept specific so a legitimate generic term is not flagged.
|
||||
DENYLIST = {
|
||||
"deployment hostname": r"jarvis|guppy",
|
||||
"operator username": r"\babby\b",
|
||||
"ssh key comment": r"shitass",
|
||||
"git owner": r"gabby",
|
||||
"git host": r"manyworlds",
|
||||
"lan address": r"192\.168\.8\.",
|
||||
"local codegen model": r"qwen38",
|
||||
"local llm model": r"qwen3\.5:4b",
|
||||
"stale llm default": r"qwen2\.5:3b",
|
||||
"absolute home path": r"/home/abby",
|
||||
"old venv path": r"semif-venv",
|
||||
"machine descriptor": r"\b(?:the box|dev box|dev machine|staging box)\b",
|
||||
}
|
||||
|
||||
|
||||
def _git_tracked_files() -> list[Path] | None:
|
||||
"""Tracked files from git (so gitignored per-machine files are exempt).
|
||||
|
||||
Returns ``None`` when git is unavailable or this is not a checkout, so the
|
||||
guard still works on an extracted tarball via the walk fallback.
|
||||
"""
|
||||
try:
|
||||
out = subprocess.run(
|
||||
["git", "-C", str(REPO_ROOT), "ls-files", "-z"],
|
||||
capture_output=True,
|
||||
check=True,
|
||||
).stdout
|
||||
except (OSError, subprocess.CalledProcessError):
|
||||
return None
|
||||
names = [n for n in out.decode("utf-8", "surrogateescape").split("\0") if n]
|
||||
return [REPO_ROOT / n for n in names]
|
||||
|
||||
|
||||
def _iter_tracked_text_files():
|
||||
"""Yield candidate files, pruning ignored trees and binary assets."""
|
||||
tracked = _git_tracked_files()
|
||||
if tracked is not None:
|
||||
candidates = tracked
|
||||
else:
|
||||
candidates = []
|
||||
for dirpath, dirnames, filenames in os.walk(REPO_ROOT):
|
||||
dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS]
|
||||
for name in filenames:
|
||||
path = Path(dirpath) / name
|
||||
if any(path.match(g) for g in SKIP_GLOBS):
|
||||
continue
|
||||
candidates.append(path)
|
||||
for path in candidates:
|
||||
if path.name in SKIP_NAMES or path.suffix in SKIP_SUFFIXES:
|
||||
continue
|
||||
yield path
|
||||
|
||||
|
||||
def test_no_deployment_specific_artifacts():
|
||||
hits: list[str] = []
|
||||
for path in _iter_tracked_text_files():
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
except (UnicodeDecodeError, OSError):
|
||||
continue
|
||||
for label, pattern in DENYLIST.items():
|
||||
for match in re.finditer(pattern, text, re.IGNORECASE):
|
||||
line = text.count("\n", 0, match.start()) + 1
|
||||
hits.append(
|
||||
f"{path.relative_to(REPO_ROOT)}:{line}: {label} "
|
||||
f"-> {match.group(0)!r}"
|
||||
)
|
||||
assert not hits, "deployment-specific artifacts in tracked files:\n" + "\n".join(
|
||||
hits
|
||||
)
|
||||
@@ -3,7 +3,7 @@
|
||||
`semif_agent.simplex_ws` is shared by the command gateway and the forwarding
|
||||
bridge, so its parsing/accept/address behavior is tested here, independent of
|
||||
either front end. The real `websockets` transport against a live daemon is a
|
||||
jarvis integration concern.
|
||||
live-daemon integration concern.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
@@ -4,7 +4,7 @@ path when the engine is unavailable.
|
||||
|
||||
No mocking: the async write test uses a real CodegenClient against a throwaway
|
||||
stdlib HTTP server (real endpoint, per the repo rule); engine-dependent success
|
||||
paths are exercised only by the box integration tests against the real decision
|
||||
paths are exercised only by the integration tests against the real decision
|
||||
model.
|
||||
"""
|
||||
|
||||
|
||||
Reference in new issue
Block a user