Skip to content

feat(desktop): clawcodex serve — the desktop gateway backend + boot rewire (stage 2) - #803

Merged
agentforce314 merged 1 commit into
mainfrom
feat/desktop-serve-core
Aug 8, 2026
Merged

feat(desktop): clawcodex serve — the desktop gateway backend + boot rewire (stage 2)#803
agentforce314 merged 1 commit into
mainfrom
feat/desktop-serve-core

Conversation

@agentforce314

Copy link
Copy Markdown
Owner

Summary

Stage 2 of the Desktop port: the Python side gains clawcodex serve — the backend the desktop shell spawns — and the shell's boot ladder now resolves real clawcodex runtimes.

Server (new)

  • clawcodex serve (src/entrypoints/serve_cli.py): loopback HTTP+WS on one OS-assigned port, CLAWCODEX_BACKEND_READY port=N stdout announce + ready-file contract, token via flag/env/generated, agent-server-grade permission plumbing (bypass sanitization + safety; flags-only availability on this multi-session transport).
  • Starlette app (src/server/desktop_serve.py): /api/health (open), /api/status + /api/config (token-gated; config passes through redact_secrets so the env block and key-bearing fields never cross REST), token-carrying / page for backend adoption, /api/ws.
  • JSON-RPC gateway (src/server/desktop_gateway*.py): sessions run the in-process agent core (make_spawn_agent); a pump translates agent frames into the renderer's event vocabulary (message.delta/interim/complete with usage mapping, reasoning.delta, tool.start/complete from SDK envelopes, session.info); approval round-trip parks can_use_tool asks and maps approval.respond {once|session|always|deny} onto permission replies with suggestion-scoped grants; resume = fresh spawn + resume control; interrupt; model.options/get_settings bridging; unknown methods error without dropping the socket.
  • serve added to the CLI sieve; starlette/uvicorn promoted to declared deps (were transitive via mcp).

Desktop shell

  • Legacy fallback subcommand removed (never existed in this backend); serve support sniffed from src/cli.py's sieve, and a too-old runtime is now an actionable update-required boot error.
  • python -m src.cli across the resolver ladder; source-root check = src/cli.py; managed venv .venv (~/.clawcodex/clawcodex/.venv, install.sh layout); About-panel version from pyproject.toml.

Verification

Gate Result
New pytest (tests/server/test_desktop_{serve,gateway}.py) ✅ 18/18 — incl. a real-agent permission round-trip where the tool executes
Full Python suite ✅ 9,830 passed / 0 failed
Live smoke (real serve process) ✅ ready marker, auth matrix, uvicorn WS handshake, session create/close, wrong-token rejected
ui-desktop typecheck / lint / electron vitest ✅ green / 0 errors 88 warnings (= reference) / 78 files green

Next stage: sessions/fs/git REST subset for the sidebar + transcript hydration, and the clawcodex desktop launcher.

🤖 Generated with Claude Code

…ewire (stage 2)

Python gains the serve surface the desktop shell expects, and the shell's
boot ladder now resolves real clawcodex runtimes end-to-end.

Server (new):
- src/entrypoints/serve_cli.py: `clawcodex serve` — loopback HTTP+WS on one
  OS-assigned port, CLAWCODEX_BACKEND_READY stdout announce + ready-file,
  token via flag/env/generated, agent-server-grade permission plumbing
  (bypass sanitization + safety, flags-only availability on this
  multi-session transport).
- src/server/desktop_serve.py: Starlette app — /api/health (open),
  /api/status + /api/config (token; config served through redact_secrets so
  the env block and key-bearing fields never cross REST), token-carrying /,
  /api/ws.
- src/server/desktop_gateway*.py: JSON-RPC gateway — number/string ids echoed,
  {method:'event'} pushes; sessions run the in-process agent core
  (make_spawn_agent) with a pump translating frames to renderer events
  (message.delta/interim/complete with usage mapping, reasoning.delta,
  tool.start/complete from SDK envelopes, session.info from init);
  approval round-trip parks can_use_tool asks and maps
  approval.respond{once|session|always|deny} onto permission replies with
  suggestion-scoped grants; resume = fresh spawn + resume control (spawn's
  third arg is a permission mode, not a resume id); interrupt control;
  model.options/get_settings bridging; unknown methods error without
  dropping the socket; unsupported ask subtypes deny instead of hanging.
- serve added to the CLI sieve; starlette/uvicorn promoted from transitive
  (via mcp) to declared deps.

Desktop shell:
- backend-command: no more legacy dashboard fallback (never existed here);
  serve support sniffed from src/cli.py's sieve.
- main: probe reads src/cli.py; a runtime without serve is an actionable
  update-required boot error; python -m src.cli everywhere;
  source-root check = src/cli.py; managed venv is .venv
  (~/.clawcodex/clawcodex/.venv, install.sh layout); About version from
  pyproject.toml.

Verification: 18 new pytest tests (fake-agent tier + real-spawn tier incl. a
real permission round-trip where the tool executes), full suite 9,830 passed;
live smoke against a real serve process (uvicorn WS handshake, session
create/close, auth matrix, wrong-token rejection); ui-desktop typecheck
green, lint 0 errors/88 warnings (= reference), electron vitest 78 files
green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@agentforce314
agentforce314 merged commit a085a99 into main Aug 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant