Skip to content

HTTP server (ka serve)

Terminal window
ka serve # binds 127.0.0.1:8417
ka serve --addr 127.0.0.1:9000 --token "$KA_TOKEN"

A hand-rolled HTTP/SSE server: same process, no framework. The bearer token is required on every request when set. It binds to loopback by default; if you expose it, set a token.

Terminal window
ka queue "run the tests" # prompt the live serve session
ka queue "run the tests" --addr 127.0.0.1:9000 --token "$KA_TOKEN"

ka queue <prompt> sends a prompt to a live serve session from any terminal, with the same --addr / --token flags as ka serve.

ka serve loads the full config chain: built-in defaults, the user layer, the project layer when the directory is already trusted (a server never prompts), extra --config files (repeatable, last wins), then environment overrides. There are no CLI model/mode/feature flags on serve; set them in a ka.toml layer or the environment. For an unattended server, [permissions] prompt_policy = "deny" is the stance to set (the run surfaces also take --mode dont_ask); serve reads the same chain, so layers and environment carry it.

Terminal window
ka serve --config /etc/ka/server.toml

Create a session and the conversation streams over SSE. Sessions can start from, or resume, strands on disk:

Terminal window
curl -s http://127.0.0.1:8417/sessions \
-H 'content-type: application/json' \
-d '{"resume": "latest"}'

"resume" accepts "latest" or a strand id / prefix; the prior transcript is replayed over SSE before the new turn, so a restarted client sees the full conversation.

The stream honors Last-Event-ID: a dropped connection resumes from the last event received, rather than restarting the turn. Combined with strand persistence, a ka serve session survives client restarts and network blips.

Any number of observers can stream a session without owning it: GET /sessions/{id}/events replays the ring-buffered history, then streams live events, and honors Last-Event-ID for mid-session reconnects. Presence changes broadcast as {"type":"presence","busy":…,"attached":…} events. GET /sessions lists every session with presence and title; GET /sessions/{id} returns one.

ka attach [id] is the built-in observer: a read-only TUI over that SSE stream, with busy · N attached in the footer. The write path stays single-owner: observers have no prompt route; POST /sessions/{id}/prompt remains the only writer API.

  • a local web UI or tool that wants a conversation without embedding the engine
  • scripting ka from languages where spawning a process is clumsy
  • bridging one ka conversation to several viewers (each with its own Last-Event-ID)