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 +91 -109
- package/dist/src/index.js +824 -1117
- package/dist/src/{lib-WNJM7YOZ.js → lib-YXLVEBQC.js} +10 -10
- package/dist/tsup.config.js +28 -0
- package/package.json +1 -1
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
|
-
|
|
5
|
+
**Authorization Header**: `X-Replicas-Engine-Secret: <REPLICAS_ENGINE_SECRET>`
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
##
|
|
12
|
+
## Engine API surface (v1)
|
|
12
13
|
|
|
13
|
-
|
|
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
|
-
|
|
20
|
+
Stream:
|
|
26
21
|
|
|
27
22
|
- `GET /events` (SSE)
|
|
28
23
|
|
|
29
|
-
|
|
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
|
-
|
|
34
|
+
Plans:
|
|
40
35
|
|
|
41
|
-
- `GET /
|
|
42
|
-
- `
|
|
43
|
-
- `GET /hooks/status`
|
|
36
|
+
- `GET /plans`
|
|
37
|
+
- `GET /plans/:filename`
|
|
44
38
|
|
|
45
|
-
|
|
39
|
+
Repos and hooks:
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
- `GET /repos`
|
|
42
|
+
- `GET /repos?includeDiffs=true` (includes `gitDiff.fullDiff`)
|
|
43
|
+
- `GET /hooks/status`
|
|
50
44
|
|
|
51
|
-
SSE
|
|
45
|
+
SSE envelope:
|
|
52
46
|
|
|
53
47
|
- `id`: stable event id
|
|
54
|
-
- `event`: event type
|
|
55
|
-
- `data`: JSON-serialized
|
|
56
|
-
|
|
57
|
-
##
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
- `
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
- `
|
|
89
|
-
-
|
|
90
|
-
-
|
|
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
|
-
|
|
115
|
-
- `/events` emits canonical runtime deltas only
|
|
102
|
+
## Environment contract
|
|
116
103
|
|
|
117
|
-
|
|
104
|
+
`src/engine-env.ts` is the source of truth for engine runtime environment variables.
|
|
118
105
|
|
|
119
|
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
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
|
-
|
|
111
|
+
Engine env vars are injected by monolith when the engine is started inside sandboxes.
|
|
124
112
|
|
|
125
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
122
|
+
The engine calls monolith with:
|
|
138
123
|
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
127
|
+
Outgoing endpoints:
|
|
145
128
|
|
|
146
|
-
-
|
|
147
|
-
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
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`
|