Files
clawmates/crates/cm-api/Cargo.toml
T
Omar Sobh 21ac35c8d4
ci / gates (push) Successful in 6s
ci / frontend (push) Successful in 29s
ci / rust (push) Successful in 2m40s
ci / e2e (push) Has been skipped
ci / publish (push) Successful in 2m27s
research: spawn per-topic ZeroClaw team container on start (commit 1/3)
Commit 1 of the path-B (real per-topic isolation) plan. The
container spawns and its coordinates persist — nothing talks to
it yet; commit 2 wires ZeroClawDriveExecutor to prefer the topic's
URL when populated. This split keeps each landing verifiable.

Backend

- Migration 0038: research_topics gets zeroclaw_container_name +
  zeroclaw_gateway_url columns. Both nullable so a topic can exist
  before a spawn and teardown just NULLs them out.

- cm-db: ResearchTopic struct extended; get/list SELECTs updated;
  new set_zeroclaw_container(id, workspace_id, name, url) helper
  used both for spawn (Some/Some) and teardown (None/None).

- cm-api: bollard added as a workspace dep (matches cm-sandbox's
  version). New research_container module:
    · connect() → uses DOCKER_HOST when set (prod's socket-proxy
      at tcp://socket-proxy:2375) else the local socket. Same
      pattern cm-sandbox already uses.
    · container_name_for(topic_id) → "research-<uuid>-team"
      (deterministic so a re-start reattaches to the same
      container instead of orphaning it).
    · inherited_env() → propagates ZEROCLAW_*, OPENAI_*,
      ANTHROPIC_*, GEMINI_*, GROQ_* from the parent server env
      (provider config + tokens), stripping the server's own
      ZEROCLAW_GATEWAY_URL/WORKSPACE so the team runtime doesn't
      loop back on itself. Appends ZEROCLAW_GATEWAY_PORT=42617
      and ZEROCLAW_WORKSPACE=/zeroclaw-data/workspace for the
      team's own listener.
    · spawn(docker, topic_id, repo_host_path, state_host_path):
        - inspect: if the container already exists, start it if
          stopped and return its coordinates (idempotent restart).
        - else create with:
            image  = CLAWMATES_RESEARCH_TEAM_IMAGE or
                     clawmates-runtime:latest
            cmd    = [daemon, --host, 0.0.0.0]
            env    = inherited_env()
            mounts = repo_host_path → /workspace/repo (rw)
                     state_host_path → /zeroclaw-data (rw)
            network = CLAWMATES_RESEARCH_TEAM_NETWORK or
                      clawmates_core
            labels = clawmates.role=research-team,
                     clawmates.research.topic_id=<uuid>
        - creates state_host_path first so bind doesn't ENOENT.
    · stop(docker, name) → stop + remove. Idempotent on 404/304.

- start_topic wires spawn after the clone completes:
    · state root = CLAWMATES_RESEARCH_WORKSPACE_ROOT / <topic> /
      state
    · on success, persists (name, url) on the topic row so commit
      2 can look them up when constructing the executor
    · every failure (docker connect, docker create/start, DB
      persist) is best-effort: logs and continues. A missing team
      container leaves the topic pointing at the workspace-wide
      gateway URL (env), preserving prior behavior.

Deploy prerequisites (not in this commit)

- The compose stack's clawmates_server service needs bind-mounts
  of CLAWMATES_RESEARCH_WORKSPACE_ROOT (e.g.
  /var/lib/clawmates-research:/var/lib/clawmates-research) so
  paths the server writes to are visible on the host and the
  spawned team container mounts the same underlying data.
- socket-proxy's ACL must allow POST + DELETE on /containers
  (already the case in prod per the audited compose file).
2026-07-09 04:14:26 -07:00

69 lines
2.0 KiB
TOML

[package]
name = "cm-api"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
[dependencies]
getrandom = "0.2"
hex = "0.4"
hmac = "0.12"
sha2 = "0.10"
base64 = "0.22"
async-stream = "0.3"
axum = { version = "0.8", features = ["ws"] }
# Docker API — matches cm-sandbox's version so the workspace resolves cleanly.
# Used by research_container to spawn/stop per-topic team runtimes via the
# same socket-proxy the server already talks to.
bollard = "0.19"
futures = "0.3"
serde = { workspace = true }
serde_json = { workspace = true }
sqlx = { workspace = true }
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
cm-auth = { path = "../cm-auth" }
cm-billing = { path = "../cm-billing" }
cm-brain = { path = "../cm-brain" }
cm-config = { path = "../cm-config" }
cm-db = { path = "../cm-db" }
cm-domain = { path = "../cm-domain" }
cm-llm = { path = "../cm-llm" }
cm-orchestrator = { path = "../cm-orchestrator", features = ["provider"] }
cm-runtime = { path = "../cm-runtime" }
cm-sandbox = { path = "../cm-sandbox" }
cm-safety = { path = "../cm-safety" }
async-trait = "0.1"
cm-scheduler = { path = "../cm-scheduler" }
cm-secrets = { path = "../cm-secrets" }
cm-topology = { path = "../cm-topology" }
thiserror = { workspace = true }
tokio-tungstenite = { version = "0.26", features = ["rustls-tls-webpki-roots"] }
tower-http = { version = "0.6", features = ["trace"] }
time = { workspace = true }
tokio = { workspace = true }
urlencoding = "2"
uuid = { workspace = true }
[dev-dependencies]
axum = { version = "0.8", features = ["ws"] }
jsonwebtoken = "9"
eventsource-stream = "0.2"
reqwest = { version = "0.12", default-features = false, features = [
"json",
"rustls-tls",
"stream",
] }
cm-llm = { path = "../cm-llm" }
cm-testkit = { path = "../cm-testkit" }
hex = "0.4"
hmac = "0.12"
base64 = "0.22"
rand_core = { version = "0.6", features = ["getrandom"] }
rsa = { version = "0.9", features = ["pem"] }
sha2 = "0.10"
[lints]
workspace = true