replicas-engine 0.1.41 → 0.1.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,149 +2,131 @@
2
2
 
3
3
  Replicas Engine is the workspace runtime that powers coding agents.
4
4
 
5
- This version is built around:
5
+ **Authorization Header**: `X-Replicas-Engine-Secret: <REPLICAS_ENGINE_SECRET>`
6
6
 
7
- - one canonical event stream (`GET /events`, SSE)
8
- - multi-chat and multi-thread support for Claude and Codex
9
- - multi-repo workspaces (agents operate from workspace root)
7
+ **Core Flow**:
8
+ 1. Fetch snapshots (`/status`, `/chats`, `/repos`, `/hooks/status`).
9
+ 2. Open `GET /events` for deltas.
10
+ 3. Send messages via `POST /chats/:chatId/messages`.
10
11
 
11
- ## Core model
12
+ ## Engine API surface (v1)
12
13
 
13
- - **Event-first runtime**: all meaningful state transitions emit typed `EngineEvent` payloads.
14
- - **Snapshot + stream**: clients fetch current state endpoints, then subscribe to `/events` for deltas.
15
- - **Chat-centric API**: chats are first-class resources; provider sessions are internal details.
16
-
17
- ## Endpoints
18
-
19
- ### System
14
+ System:
20
15
 
21
16
  - `GET /health`
22
17
  - `GET /status`
23
18
  - `GET /token-refresh/health`
24
19
 
25
- ### Stream
20
+ Stream:
26
21
 
27
22
  - `GET /events` (SSE)
28
23
 
29
- ### Chats
24
+ Chats:
30
25
 
31
26
  - `POST /chats`
32
27
  - `GET /chats`
33
28
  - `GET /chats/:chatId`
29
+ - `DELETE /chats/:chatId`
34
30
  - `GET /chats/:chatId/history`
35
31
  - `POST /chats/:chatId/messages`
36
32
  - `POST /chats/:chatId/interrupt`
37
- - `POST /chats/:chatId/reset`
38
33
 
39
- ### Repos and hooks
34
+ Plans:
40
35
 
41
- - `GET /repos`
42
- - `POST /repos/refresh`
43
- - `GET /hooks/status`
36
+ - `GET /plans`
37
+ - `GET /plans/:filename`
44
38
 
45
- ## SSE usage
39
+ Repos and hooks:
46
40
 
47
- 1. Fetch current state from resource endpoints (`/status`, `/chats`, `/repos`, `/hooks/status`, chat history endpoints).
48
- 2. Connect to `GET /events` and apply incoming events as state deltas.
49
- 3. On disconnect/reconnect, fetch state again and resubscribe.
41
+ - `GET /repos`
42
+ - `GET /repos?includeDiffs=true` (includes `gitDiff.fullDiff`)
43
+ - `GET /hooks/status`
50
44
 
51
- SSE payload format:
45
+ SSE envelope:
52
46
 
53
47
  - `id`: stable event id
54
- - `event`: event type (same as `EngineEvent.type`)
55
- - `data`: JSON-serialized event envelope
56
-
57
- ## Multi-chat model
58
-
59
- - each chat has its own provider session/thread
60
- - chat metadata and provider session ids are persisted in `~/.replicas/engine/chats.json`
61
- - chats are independent, so multiple active chats can run in parallel
62
-
63
- ## Multi-repo model
64
-
65
- - workspace root defaults to `~/workspaces`
66
- - repos are discovered as directories under root
67
- - agents execute from workspace root and can access all repos by default
68
-
69
- ## Local development
70
-
71
- ```bash
72
- yarn build
73
- yarn dev
74
- ```
75
-
76
- Environment essentials:
77
-
78
- - `REPLICAS_ENGINE_SECRET`
79
- - `WORKSPACE_ID`
80
- - `MONOLITH_URL`
48
+ - `event`: engine event type
49
+ - `data`: JSON-serialized `EngineEvent`
50
+
51
+ ## VM/runtime contract
52
+
53
+ The engine is expected to run in a VM/sandbox with:
54
+
55
+ - OS user with writable home (default `/home/ubuntu`)
56
+ - Workspace root at `~/workspaces`
57
+ - Git available in PATH
58
+ - `gh` CLI available in PATH (for PR URL discovery)
59
+ - Claude and Codex CLIs installed/configurable
60
+
61
+ ### Provisioning contract (what monolith injects before engine start)
62
+
63
+ From `monolith/src/lib/daytona.ts` + `monolith/src/lib/workspaces.ts`, the VM is expected to be prepped with:
64
+
65
+ - Git identity (optional but expected for commits):
66
+ - `git config --global user.name <bot-or-user-name>`
67
+ - `git config --global user.email <bot-or-user-email>`
68
+ - Git credential helper setup when GitHub token is available:
69
+ - `git config --global credential.helper store`
70
+ - `~/.git-credentials` with `https://x-access-token:<token>@github.com`
71
+ - Repository materialization:
72
+ - clone repositories into `/home/ubuntu/workspaces/<repo-name>`
73
+ - if no repository URL is provided, create empty `/home/ubuntu/workspaces/<repo-name>`
74
+ - Claude credentials (optional):
75
+ - file: `~/.claude/.credentials.json`
76
+ - source: OAuth credential object provisioned by monolith
77
+ - Bedrock credentials (optional):
78
+ - file: `~/.claude/.bedrock-credentials.json`
79
+ - env: `CLAUDE_CODE_USE_BEDROCK=1`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`
80
+ - Codex credentials (optional):
81
+ - file: `~/.codex/auth.json`
82
+ - format includes `tokens.id_token`, `tokens.access_token`, `tokens.refresh_token`, `tokens.account_id`
83
+
84
+ Token refresh managers may later overwrite credential files in place:
85
+
86
+ - `~/.git-credentials`
87
+ - `~/.claude/.credentials.json`
88
+ - `~/.codex/auth.json`
89
+
90
+ Engine persistence locations:
81
91
 
82
- Optional:
83
-
84
- - `WORKSPACE_HOME`, `REPLICAS_REPO_NAME`, `REPLICAS_DEFAULT_BRANCH`
85
-
86
- ## Code layout
87
-
88
- - `src/index.ts`: bootstrapping and server wiring
89
- - `src/v1-routes.ts`: request validation and route handlers
90
- - `src/chat-service.ts`: chat orchestration and persistence
91
- - `src/event-service.ts`: event bus and SSE fanout
92
- - `src/providers/`: provider adapter interface + Claude/Codex adapters
93
- - `src/repo-service.ts`: repo discovery and workspace root logic
94
- - `src/services/replicas-config.ts`: start-hook lifecycle state and config loading
95
-
96
- ## Architecture
97
-
98
- Flow:
99
-
100
- 1. HTTP handlers validate requests.
101
- 2. Domain services execute behavior.
102
- 3. Domain services publish typed `EngineEvent` entries.
103
- 4. Events are persisted to JSONL and broadcast to SSE subscribers.
104
-
105
- Module responsibilities:
106
-
107
- - `src/v1-routes.ts`: route definitions, request validation, typed responses
108
- - `src/chat-service.ts`: chat registry, persistence, turn orchestration, provider-event lifecycle
109
- - `src/event-service.ts`: append-only event persistence and subscriber fanout
110
- - `src/repo-service.ts`: workspace root resolution and repo discovery
111
-
112
- Event guarantees:
92
+ - `~/.replicas/engine/chats.json`
93
+ - `~/.replicas/engine/events.jsonl`
94
+ - `~/.replicas/engine-state.json`
95
+ - `~/.replicas/startHooks.log`
96
+ - Plan read locations (for `/plans` endpoints):
97
+ - `~/.claude/plans`
98
+ - `~/.replicas/plans`
99
+ - Health endpoint readiness signal file:
100
+ - `/var/log/cloud-init-output.log` (if missing, `/health` reports `initializing`)
113
101
 
114
- - every persisted event has `id`, `ts`, `type`, and `payload`
115
- - `/events` emits canonical runtime deltas only
102
+ ## Environment contract
116
103
 
117
- Persistence:
104
+ `src/engine-env.ts` is the source of truth for engine runtime environment variables.
118
105
 
119
- - `~/.replicas/engine/chats.json`
120
- - `~/.replicas/engine/events.jsonl`
121
- - provider-specific session files remain provider-specific
106
+ Use that file to understand:
107
+ - required vars (boot-time validated)
108
+ - optional vars used by engine code
109
+ - ambient/runtime vars captured for SDK/CLI/agent compatibility
122
110
 
123
- ## Contributor notes
111
+ Engine env vars are injected by monolith when the engine is started inside sandboxes.
124
112
 
125
- - keep routes thin and move behavior into services
126
- - keep all payloads strongly typed
127
- - add a new `EngineEvent` variant for every new externally-visible runtime transition
128
- - prefer explicit naming over implicit side-effects
113
+ Credential files expected/used by provider CLIs:
129
114
 
130
- ### Add a new event type
115
+ - `~/.git-credentials` (git/gh auth)
116
+ - `~/.claude/.credentials.json` (Claude OAuth auth)
117
+ - `~/.claude/.bedrock-credentials.json` (Claude Bedrock config)
118
+ - `~/.codex/auth.json` (Codex auth)
131
119
 
132
- 1. Add the event variant in `@replicas/shared` (`shared/src/engine/v1.ts`).
133
- 2. Emit the event from the relevant domain service.
134
- 3. Ensure payload is strongly typed and stable.
135
- 4. Document the new event in this README if client-facing.
120
+ ## What the engine sends upstream
136
121
 
137
- ### Add a new provider
122
+ The engine calls monolith with:
138
123
 
139
- 1. Implement provider manager/adapter in `src/managers`/`src/providers`.
140
- 2. Ensure chat service can construct and persist provider session identity.
141
- 3. Emit canonical chat events from provider outputs.
142
- 4. Validate with multiple chats running concurrently.
124
+ - `Authorization: Bearer <REPLICAS_ENGINE_SECRET>`
125
+ - `X-Workspace-Id: <WORKSPACE_ID>`
143
126
 
144
- ### Quality checklist
127
+ Outgoing endpoints:
145
128
 
146
- - no `any` in new code
147
- - all external payloads typed
148
- - routes stay thin
149
- - build passes (`shared`, `engine`, `monolith`)
150
- - behavior documented in this README
129
+ - `POST /v1/engine/webhook`
130
+ - `POST /v1/engine/github/refresh-token`
131
+ - `POST /v1/engine/claude/refresh-credentials`
132
+ - `POST /v1/engine/codex/refresh-credentials`