replicas-engine
v0.1.41
Published
Lightweight API server for Replicas workspaces
Readme
Replicas Engine (V1)
Replicas Engine is the workspace runtime that powers coding agents.
This version is built around:
- one canonical event stream (
GET /events, SSE) - multi-chat and multi-thread support for Claude and Codex
- multi-repo workspaces (agents operate from workspace root)
Core model
- Event-first runtime: all meaningful state transitions emit typed
EngineEventpayloads. - Snapshot + stream: clients fetch current state endpoints, then subscribe to
/eventsfor deltas. - Chat-centric API: chats are first-class resources; provider sessions are internal details.
Endpoints
System
GET /healthGET /statusGET /token-refresh/health
Stream
GET /events(SSE)
Chats
POST /chatsGET /chatsGET /chats/:chatIdGET /chats/:chatId/historyPOST /chats/:chatId/messagesPOST /chats/:chatId/interruptPOST /chats/:chatId/reset
Repos and hooks
GET /reposPOST /repos/refreshGET /hooks/status
SSE usage
- Fetch current state from resource endpoints (
/status,/chats,/repos,/hooks/status, chat history endpoints). - Connect to
GET /eventsand apply incoming events as state deltas. - On disconnect/reconnect, fetch state again and resubscribe.
SSE payload format:
id: stable event idevent: event type (same asEngineEvent.type)data: JSON-serialized event envelope
Multi-chat model
- each chat has its own provider session/thread
- chat metadata and provider session ids are persisted in
~/.replicas/engine/chats.json - chats are independent, so multiple active chats can run in parallel
Multi-repo model
- workspace root defaults to
~/workspaces - repos are discovered as directories under root
- agents execute from workspace root and can access all repos by default
Local development
yarn build
yarn devEnvironment essentials:
REPLICAS_ENGINE_SECRETWORKSPACE_IDMONOLITH_URL
Optional:
WORKSPACE_HOME,REPLICAS_REPO_NAME,REPLICAS_DEFAULT_BRANCH
Code layout
src/index.ts: bootstrapping and server wiringsrc/v1-routes.ts: request validation and route handlerssrc/chat-service.ts: chat orchestration and persistencesrc/event-service.ts: event bus and SSE fanoutsrc/providers/: provider adapter interface + Claude/Codex adapterssrc/repo-service.ts: repo discovery and workspace root logicsrc/services/replicas-config.ts: start-hook lifecycle state and config loading
Architecture
Flow:
- HTTP handlers validate requests.
- Domain services execute behavior.
- Domain services publish typed
EngineEvententries. - Events are persisted to JSONL and broadcast to SSE subscribers.
Module responsibilities:
src/v1-routes.ts: route definitions, request validation, typed responsessrc/chat-service.ts: chat registry, persistence, turn orchestration, provider-event lifecyclesrc/event-service.ts: append-only event persistence and subscriber fanoutsrc/repo-service.ts: workspace root resolution and repo discovery
Event guarantees:
- every persisted event has
id,ts,type, andpayload /eventsemits canonical runtime deltas only
Persistence:
~/.replicas/engine/chats.json~/.replicas/engine/events.jsonl- provider-specific session files remain provider-specific
Contributor notes
- keep routes thin and move behavior into services
- keep all payloads strongly typed
- add a new
EngineEventvariant for every new externally-visible runtime transition - prefer explicit naming over implicit side-effects
Add a new event type
- Add the event variant in
@replicas/shared(shared/src/engine/v1.ts). - Emit the event from the relevant domain service.
- Ensure payload is strongly typed and stable.
- Document the new event in this README if client-facing.
Add a new provider
- Implement provider manager/adapter in
src/managers/src/providers. - Ensure chat service can construct and persist provider session identity.
- Emit canonical chat events from provider outputs.
- Validate with multiple chats running concurrently.
Quality checklist
- no
anyin new code - all external payloads typed
- routes stay thin
- build passes (
shared,engine,monolith) - behavior documented in this README
