How ashish16052/opencode-runtime works
opencode-runtime embeds OpenCode as a managed Python service: an application requests an isolated runtime session, sends prompts, and receives a complete response or streamed events. Runtime orchestration keys servers by workspace, user, and project, starts or reuses OpenCode processes, and tracks them in a shared registry. Sessions use an HTTP/SSE client for conversation operations; a separate CLI manages and inspects the server fleet. The graph reflects README capabilities and sampled call paths; unsampled implementation details are represented only where the tree or documentation supports them.
Main entry points: session.py Conversation session · server.py Server manager · client.py HTTP / SSE client · runtime.py Runtime factory
Components 12
Python API
- Runtime factory
src/opencode_runtime/runtime.py - Conversation session
src/opencode_runtime/session.py - Collected response
src/opencode_runtime/response.py - Stream event
src/opencode_runtime/event.py
Runtime Lifecycle
- Server manager
src/opencode_runtime/server.py - Process primitives
src/opencode_runtime/process.py - Instance registry
src/opencode_runtime/registry.py
Conversation
- HTTP / SSE client
src/opencode_runtime/client.py
Fleet Management
- Management CLI
src/opencode_runtime/cli.py
Other components
- Embedding application
- OpenCode server
- Fleet operator
Connections 17
- Embedding application → Runtime factory: creates runtime
- Runtime factory → Server manager: gets or starts server
- Server manager → Instance registry: claims and tracks
- Server manager → Process primitives: spawns and stops
- Process primitives → OpenCode server: launches process
- Server manager → HTTP / SSE client: checks health
- HTTP / SSE client → OpenCode server: sends HTTP requests
- OpenCode server → HTTP / SSE client: streams SSE events
- Runtime factory → Conversation session: creates session
- Conversation session → HTTP / SSE client: creates and prompts
- Conversation session → HTTP / SSE client: consumes event stream
- Conversation session → Collected response: collects answer
- Conversation session → Stream event: yields events
- Embedding application → Conversation session: asks or streams
- Fleet operator → Management CLI: runs commands
- Management CLI → Server manager: starts, checks, stops
- Management CLI → Instance registry: lists instances