@essentialai/cogent-bridge 1.0.0
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/LICENSE +15 -0
- package/README.md +311 -0
- package/dist/backend/backend-provider.d.ts +28 -0
- package/dist/backend/backend-provider.d.ts.map +1 -0
- package/dist/backend/backend-provider.js +60 -0
- package/dist/backend/backend-provider.js.map +1 -0
- package/dist/backend/file-backend.d.ts +22 -0
- package/dist/backend/file-backend.d.ts.map +1 -0
- package/dist/backend/file-backend.js +46 -0
- package/dist/backend/file-backend.js.map +1 -0
- package/dist/backend/http-backend.d.ts +94 -0
- package/dist/backend/http-backend.d.ts.map +1 -0
- package/dist/backend/http-backend.js +185 -0
- package/dist/backend/http-backend.js.map +1 -0
- package/dist/backend/index.d.ts +5 -0
- package/dist/backend/index.d.ts.map +1 -0
- package/dist/backend/index.js +4 -0
- package/dist/backend/index.js.map +1 -0
- package/dist/backend/storage-backend.d.ts +22 -0
- package/dist/backend/storage-backend.d.ts.map +1 -0
- package/dist/backend/storage-backend.js +2 -0
- package/dist/backend/storage-backend.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +18 -0
- package/dist/cli.js.map +1 -0
- package/dist/cloud/backoff.d.ts +19 -0
- package/dist/cloud/backoff.d.ts.map +1 -0
- package/dist/cloud/backoff.js +32 -0
- package/dist/cloud/backoff.js.map +1 -0
- package/dist/cloud/credential-store.d.ts +29 -0
- package/dist/cloud/credential-store.d.ts.map +1 -0
- package/dist/cloud/credential-store.js +38 -0
- package/dist/cloud/credential-store.js.map +1 -0
- package/dist/cloud/http-client.d.ts +36 -0
- package/dist/cloud/http-client.d.ts.map +1 -0
- package/dist/cloud/http-client.js +94 -0
- package/dist/cloud/http-client.js.map +1 -0
- package/dist/cloud/index.d.ts +10 -0
- package/dist/cloud/index.d.ts.map +1 -0
- package/dist/cloud/index.js +7 -0
- package/dist/cloud/index.js.map +1 -0
- package/dist/cloud/message-inbox.d.ts +49 -0
- package/dist/cloud/message-inbox.d.ts.map +1 -0
- package/dist/cloud/message-inbox.js +109 -0
- package/dist/cloud/message-inbox.js.map +1 -0
- package/dist/cloud/ws-client.d.ts +112 -0
- package/dist/cloud/ws-client.d.ts.map +1 -0
- package/dist/cloud/ws-client.js +241 -0
- package/dist/cloud/ws-client.js.map +1 -0
- package/dist/cloud/ws-frames.d.ts +66 -0
- package/dist/cloud/ws-frames.d.ts.map +1 -0
- package/dist/cloud/ws-frames.js +19 -0
- package/dist/cloud/ws-frames.js.map +1 -0
- package/dist/config.d.ts +40 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +39 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/e2e/helpers.d.ts +101 -0
- package/dist/e2e/helpers.d.ts.map +1 -0
- package/dist/e2e/helpers.js +228 -0
- package/dist/e2e/helpers.js.map +1 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +53 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +22 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +79 -0
- package/dist/logger.js.map +1 -0
- package/dist/services/cc-cli.d.ts +8 -0
- package/dist/services/cc-cli.d.ts.map +1 -0
- package/dist/services/cc-cli.js +104 -0
- package/dist/services/cc-cli.js.map +1 -0
- package/dist/services/health-check.d.ts +33 -0
- package/dist/services/health-check.d.ts.map +1 -0
- package/dist/services/health-check.js +96 -0
- package/dist/services/health-check.js.map +1 -0
- package/dist/services/peer-registry.d.ts +9 -0
- package/dist/services/peer-registry.d.ts.map +1 -0
- package/dist/services/peer-registry.js +207 -0
- package/dist/services/peer-registry.js.map +1 -0
- package/dist/startup.d.ts +18 -0
- package/dist/startup.d.ts.map +1 -0
- package/dist/startup.js +270 -0
- package/dist/startup.js.map +1 -0
- package/dist/tools/create-session.d.ts +12 -0
- package/dist/tools/create-session.d.ts.map +1 -0
- package/dist/tools/create-session.js +113 -0
- package/dist/tools/create-session.js.map +1 -0
- package/dist/tools/deregister-peer.d.ts +3 -0
- package/dist/tools/deregister-peer.d.ts.map +1 -0
- package/dist/tools/deregister-peer.js +38 -0
- package/dist/tools/deregister-peer.js.map +1 -0
- package/dist/tools/get-history.d.ts +3 -0
- package/dist/tools/get-history.d.ts.map +1 -0
- package/dist/tools/get-history.js +40 -0
- package/dist/tools/get-history.js.map +1 -0
- package/dist/tools/health-check.d.ts +3 -0
- package/dist/tools/health-check.d.ts.map +1 -0
- package/dist/tools/health-check.js +28 -0
- package/dist/tools/health-check.js.map +1 -0
- package/dist/tools/join-session.d.ts +12 -0
- package/dist/tools/join-session.d.ts.map +1 -0
- package/dist/tools/join-session.js +90 -0
- package/dist/tools/join-session.js.map +1 -0
- package/dist/tools/list-peers.d.ts +3 -0
- package/dist/tools/list-peers.d.ts.map +1 -0
- package/dist/tools/list-peers.js +36 -0
- package/dist/tools/list-peers.js.map +1 -0
- package/dist/tools/register-peer.d.ts +3 -0
- package/dist/tools/register-peer.d.ts.map +1 -0
- package/dist/tools/register-peer.js +155 -0
- package/dist/tools/register-peer.js.map +1 -0
- package/dist/tools/send-message.d.ts +3 -0
- package/dist/tools/send-message.d.ts.map +1 -0
- package/dist/tools/send-message.js +121 -0
- package/dist/tools/send-message.js.map +1 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/wizard/detect.d.ts +4 -0
- package/dist/wizard/detect.d.ts.map +1 -0
- package/dist/wizard/detect.js +21 -0
- package/dist/wizard/detect.js.map +1 -0
- package/dist/wizard/index.d.ts +5 -0
- package/dist/wizard/index.d.ts.map +1 -0
- package/dist/wizard/index.js +140 -0
- package/dist/wizard/index.js.map +1 -0
- package/dist/wizard/prompts.d.ts +18 -0
- package/dist/wizard/prompts.d.ts.map +1 -0
- package/dist/wizard/prompts.js +66 -0
- package/dist/wizard/prompts.js.map +1 -0
- package/dist/wizard/scaffold-demo.d.ts +6 -0
- package/dist/wizard/scaffold-demo.d.ts.map +1 -0
- package/dist/wizard/scaffold-demo.js +37 -0
- package/dist/wizard/scaffold-demo.js.map +1 -0
- package/dist/wizard/scaffold-real.d.ts +16 -0
- package/dist/wizard/scaffold-real.d.ts.map +1 -0
- package/dist/wizard/scaffold-real.js +64 -0
- package/dist/wizard/scaffold-real.js.map +1 -0
- package/dist/wizard/templates.d.ts +9 -0
- package/dist/wizard/templates.d.ts.map +1 -0
- package/dist/wizard/templates.js +182 -0
- package/dist/wizard/templates.js.map +1 -0
- package/package.json +71 -0
- package/server.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 cc-bridge-mcp-server contributors
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# @essentialai/cogent-bridge
|
|
2
|
+
|
|
3
|
+
Cogent Bridge from Essential AI Solutions (essentialai.uk) — MCP server for inter-Claude-Code session communication.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### Install via Plugin Marketplace (Recommended)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
claude plugin marketplace add eaisdevelopment/cogent-marketplace
|
|
11
|
+
claude plugin install cogent-bridge@cogent-marketplace
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Restart Claude Code. Use `/cogent-bridge:register` to join the bridge — session discovery, registration, and message protocol are all handled automatically.
|
|
15
|
+
|
|
16
|
+
### Alternative: Manual Setup
|
|
17
|
+
|
|
18
|
+
Add `.mcp.json` to **both** project repositories:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"mcpServers": {
|
|
23
|
+
"cogent-bridge": {
|
|
24
|
+
"command": "npx",
|
|
25
|
+
"args": ["-y", "@essentialai/cogent-bridge"],
|
|
26
|
+
"env": {}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or use the CLI:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
claude mcp add --transport stdio cogent-bridge -- npx -y @essentialai/cogent-bridge
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Restart Claude Code in both repos. The bridge tools are now available.
|
|
39
|
+
|
|
40
|
+
> See [docs/installation.md](docs/installation.md) for all installation options, configuration, and troubleshooting.
|
|
41
|
+
|
|
42
|
+
## What It Does
|
|
43
|
+
|
|
44
|
+
Two Claude Code instances -- one working on a backend repo, another on a frontend repo -- need to negotiate testing scenarios and debug collaboratively in real-time without mixing their accumulated project context.
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
Cogent_Backend Cogent_Frontend
|
|
48
|
+
| |
|
|
49
|
+
+-- .mcp.json --> @essentialai/cogent-bridge |
|
|
50
|
+
| | |
|
|
51
|
+
| +-- ~/.cogent/cogent-state.json
|
|
52
|
+
| | |
|
|
53
|
+
| | <-- .mcp.json ---+
|
|
54
|
+
| |
|
|
55
|
+
+-- claude --resume <sessionId> -p "msg" -+
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Each CC instance spawns its own MCP server process via stdio transport. Shared state is persisted to `~/.cogent/cogent-state.json` with file locking so both processes see the same peer registry and message history.
|
|
59
|
+
|
|
60
|
+
Messages are relayed by calling `claude --resume <sessionId> -p "message"` as a subprocess. Before sending, the bridge validates that the target session file exists on disk — if the session has ended, it fails immediately instead of waiting for timeout. On timeout, it retries once with a shorter 30-second timeout. File locking uses `fs.writeFile` with `flag: "wx"` (O_CREAT | O_EXCL), stale lock detection via `process.kill(pid, 0)`, and atomic writes via temp-file-then-rename.
|
|
61
|
+
|
|
62
|
+
## Tools Reference
|
|
63
|
+
|
|
64
|
+
The server exposes six tools, all prefixed with `cogent_`:
|
|
65
|
+
|
|
66
|
+
### cogent_register_peer
|
|
67
|
+
|
|
68
|
+
Register a Claude Code session as a named peer on the bridge.
|
|
69
|
+
|
|
70
|
+
| Parameter | Type | Required | Description |
|
|
71
|
+
|-------------|--------|----------|--------------------------------------------------------------|
|
|
72
|
+
| `peerId` | string | yes | Unique identifier, e.g. `"backend"` or `"frontend"` |
|
|
73
|
+
| `sessionId` | string | yes | Claude Code session ID (used with `--resume`) |
|
|
74
|
+
| `cwd` | string | yes | Absolute path to the project working directory |
|
|
75
|
+
| `label` | string | yes | Human-readable label, e.g. `"Cogent_Backend"` or `"Cogent_Frontend"` |
|
|
76
|
+
|
|
77
|
+
### cogent_deregister_peer
|
|
78
|
+
|
|
79
|
+
Remove a previously registered peer from the bridge.
|
|
80
|
+
|
|
81
|
+
| Parameter | Type | Required | Description |
|
|
82
|
+
|-----------|--------|----------|---------------------------------------|
|
|
83
|
+
| `peerId` | string | yes | Peer ID to deregister, e.g. `"backend"` |
|
|
84
|
+
|
|
85
|
+
### cogent_send_message
|
|
86
|
+
|
|
87
|
+
Send a message from one registered peer to another. The message is relayed by resuming the target's Claude Code session via CLI subprocess. Returns the target's response.
|
|
88
|
+
|
|
89
|
+
| Parameter | Type | Required | Description |
|
|
90
|
+
|--------------|--------|----------|--------------------------------------------|
|
|
91
|
+
| `fromPeerId` | string | yes | Peer ID of the sender, e.g. `"backend"` |
|
|
92
|
+
| `toPeerId` | string | yes | Peer ID of the recipient, e.g. `"frontend"` |
|
|
93
|
+
| `message` | string | yes | The message content to send |
|
|
94
|
+
|
|
95
|
+
### cogent_list_peers
|
|
96
|
+
|
|
97
|
+
List all currently registered peers. Returns peer IDs, session IDs, working directories, labels, and a `potentiallyStale` flag for peers idle beyond the configured timeout. No parameters.
|
|
98
|
+
|
|
99
|
+
### cogent_get_history
|
|
100
|
+
|
|
101
|
+
Retrieve the message history for the bridge. Returns messages in chronological order, most recent last.
|
|
102
|
+
|
|
103
|
+
| Parameter | Type | Required | Description |
|
|
104
|
+
|-----------|--------|----------|------------------------------------------------|
|
|
105
|
+
| `peerId` | string | no | Filter history to messages involving this peer |
|
|
106
|
+
| `limit` | number | no | Maximum number of messages to return (default 50) |
|
|
107
|
+
|
|
108
|
+
### cogent_health_check
|
|
109
|
+
|
|
110
|
+
Diagnose the bridge's operational status. No parameters required.
|
|
111
|
+
|
|
112
|
+
**Checks performed:**
|
|
113
|
+
|
|
114
|
+
- **State file** -- Can the state directory be read and written?
|
|
115
|
+
- **Lock mechanism** -- Can file locks be acquired and released?
|
|
116
|
+
- **Claude CLI** -- Is the `claude` binary available and responsive?
|
|
117
|
+
|
|
118
|
+
**Response fields:**
|
|
119
|
+
|
|
120
|
+
| Field | Type | Description |
|
|
121
|
+
|-----------------|---------|-----------------------------------------|
|
|
122
|
+
| `healthy` | boolean | All checks passed |
|
|
123
|
+
| `serverVersion` | string | Current server version |
|
|
124
|
+
| `statePath` | string | Path to state file |
|
|
125
|
+
| `claudePath` | string | Path to Claude CLI |
|
|
126
|
+
| `checks` | object | Per-check pass/fail with detail messages |
|
|
127
|
+
| `timestamp` | string | ISO timestamp of the check |
|
|
128
|
+
|
|
129
|
+
## Configuration
|
|
130
|
+
|
|
131
|
+
All settings are configured via environment variables with sensible defaults:
|
|
132
|
+
|
|
133
|
+
| Variable | Default | Description |
|
|
134
|
+
|----------|---------|-------------|
|
|
135
|
+
| `COGENT_STATE_PATH` | `~/.cogent` | Directory for state file and logs |
|
|
136
|
+
| `COGENT_TIMEOUT_MS` | `120000` (2 min) | CLI subprocess timeout in milliseconds |
|
|
137
|
+
| `COGENT_CHAR_LIMIT` | `0` (unlimited) | Max characters in relayed message (0 = no limit) |
|
|
138
|
+
| `COGENT_LOG_LEVEL` | `info` | Log verbosity: `debug`, `info`, `warn`, `error` |
|
|
139
|
+
| `COGENT_CLAUDE_PATH` | `claude` | Path to the Claude Code CLI executable |
|
|
140
|
+
| `COGENT_STALE_TIMEOUT_MS` | `1800000` (30 min) | Idle time before peer is flagged stale (0 = disabled) |
|
|
141
|
+
|
|
142
|
+
To override defaults, set environment variables in your `.mcp.json`:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"mcpServers": {
|
|
147
|
+
"cogent-bridge": {
|
|
148
|
+
"command": "npx",
|
|
149
|
+
"args": ["-y", "@essentialai/cogent-bridge"],
|
|
150
|
+
"env": {
|
|
151
|
+
"COGENT_STATE_PATH": "/custom/path",
|
|
152
|
+
"COGENT_LOG_LEVEL": "debug"
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Usage Workflow
|
|
160
|
+
|
|
161
|
+
1. Start two Claude Code sessions, one per repo.
|
|
162
|
+
|
|
163
|
+
2. In each session, find your session ID:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
ls -t ~/.claude/projects/$(pwd | sed 's/[^a-zA-Z0-9-]/-/g')/*.jsonl 2>/dev/null | head -1 | xargs -I{} basename {} .jsonl
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
3. Each session registers itself on the bridge:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
# In Cogent_Backend:
|
|
173
|
+
Use cogent_register_peer:
|
|
174
|
+
peerId: "backend", sessionId: "<backend-session-id>",
|
|
175
|
+
cwd: "/path/to/backend", label: "Cogent_Backend"
|
|
176
|
+
|
|
177
|
+
# In Cogent_Frontend:
|
|
178
|
+
Use cogent_register_peer:
|
|
179
|
+
peerId: "frontend", sessionId: "<frontend-session-id>",
|
|
180
|
+
cwd: "/path/to/frontend", label: "Cogent_Frontend"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
4. Send a message from either session:
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
Use cogent_send_message:
|
|
187
|
+
fromPeerId: "backend", toPeerId: "frontend",
|
|
188
|
+
message: "What endpoint does the login form POST to?"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
5. The bridge validates the target session exists, resumes it with the message, and returns the response. On timeout, it automatically retries once.
|
|
192
|
+
|
|
193
|
+
6. Check message history at any time:
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
Use cogent_get_history to see all exchanges, or filter by peerId.
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
7. When done, deregister peers:
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
Use cogent_deregister_peer:
|
|
203
|
+
peerId: "backend"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Troubleshooting
|
|
207
|
+
|
|
208
|
+
### NVM/PATH: "npx not found" or server fails to start
|
|
209
|
+
|
|
210
|
+
MCP servers are spawned as subprocesses and may not inherit your NVM configuration.
|
|
211
|
+
|
|
212
|
+
**Option 1: Use absolute path to npx**
|
|
213
|
+
|
|
214
|
+
Find your npx path with `which npx` (e.g., `/Users/you/.nvm/versions/node/v22.11.0/bin/npx`), then update `.mcp.json`:
|
|
215
|
+
|
|
216
|
+
```json
|
|
217
|
+
{
|
|
218
|
+
"mcpServers": {
|
|
219
|
+
"cogent-bridge": {
|
|
220
|
+
"command": "/Users/you/.nvm/versions/node/v22.11.0/bin/npx",
|
|
221
|
+
"args": ["-y", "@essentialai/cogent-bridge"]
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
**Option 2: Use `claude mcp add` (handles PATH automatically)**
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
claude mcp add --transport stdio cogent-bridge -- npx -y @essentialai/cogent-bridge
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**Option 3: Ensure NVM loads in non-interactive shells**
|
|
234
|
+
|
|
235
|
+
Add to `~/.zshrc` or `~/.bashrc`:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
export NVM_DIR="$HOME/.nvm"
|
|
239
|
+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### State file location
|
|
243
|
+
|
|
244
|
+
The bridge stores state at `~/.cogent/cogent-state.json` by default.
|
|
245
|
+
|
|
246
|
+
- Override with: `COGENT_STATE_PATH=/your/path`
|
|
247
|
+
- Logs are stored at: `<state-path>/logs/`
|
|
248
|
+
- First-run config is persisted to `~/.cogent-config.json`
|
|
249
|
+
|
|
250
|
+
### Common errors
|
|
251
|
+
|
|
252
|
+
| Error | Cause | Fix |
|
|
253
|
+
|-------|-------|-----|
|
|
254
|
+
| `CLI_NOT_FOUND` | `claude` not on PATH | Install Claude Code or set `COGENT_CLAUDE_PATH` |
|
|
255
|
+
| `CLI_TIMEOUT` | Response took > 2 min (retried once at 30s) | Increase `COGENT_TIMEOUT_MS`, or check target session is active |
|
|
256
|
+
| `LOCK_TIMEOUT` | Lock held by dead process | Delete `<state-path>/cogent-state.json.lock` |
|
|
257
|
+
| `STATE_CORRUPT` | Invalid JSON in state | Auto-recovers; backup saved as `.corrupt.<timestamp>` |
|
|
258
|
+
| `PEER_NOT_FOUND` | Target peer not registered | Register both peers before sending messages |
|
|
259
|
+
| `CLI_EXEC_FAILED` (session not found) | Target session file missing | Ask peer to re-register with current session ID |
|
|
260
|
+
|
|
261
|
+
## Development
|
|
262
|
+
|
|
263
|
+
Build from source:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
git clone https://github.com/eaisdevelopment/cogent.git
|
|
267
|
+
cd cogent-bridge
|
|
268
|
+
npm install
|
|
269
|
+
npm run build
|
|
270
|
+
npm test
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Project Structure
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
src/
|
|
277
|
+
├── index.ts # Server entry point, registers tools, starts stdio transport
|
|
278
|
+
├── config.ts # Environment variable loading and validation (zod)
|
|
279
|
+
├── constants.ts # Server name and version from package.json
|
|
280
|
+
├── errors.ts # BridgeError class and error code enum
|
|
281
|
+
├── logger.ts # Timestamped file + stderr logger
|
|
282
|
+
├── startup.ts # First-run prompt, config loading, CLI validation
|
|
283
|
+
├── types.ts # Core interfaces (PeerInfo, MessageRecord, etc.)
|
|
284
|
+
├── services/
|
|
285
|
+
│ ├── cc-cli.ts # CLI subprocess wrapper (spawn with claude --resume)
|
|
286
|
+
│ ├── health-check.ts # State file, lock, and CLI diagnostic checks
|
|
287
|
+
│ └── peer-registry.ts # File-based shared state with locking
|
|
288
|
+
└── tools/
|
|
289
|
+
├── register-peer.ts # cogent_register_peer
|
|
290
|
+
├── deregister-peer.ts # cogent_deregister_peer
|
|
291
|
+
├── send-message.ts # cogent_send_message
|
|
292
|
+
├── list-peers.ts # cogent_list_peers
|
|
293
|
+
├── get-history.ts # cogent_get_history
|
|
294
|
+
└── health-check.ts # cogent_health_check
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### npm Scripts
|
|
298
|
+
|
|
299
|
+
| Script | Command | Description |
|
|
300
|
+
|--------|---------|-------------|
|
|
301
|
+
| `npm run build` | `tsc` | Compile TypeScript to `dist/` |
|
|
302
|
+
| `npm run dev` | `tsx watch src/index.ts` | Development mode with auto-reload |
|
|
303
|
+
| `npm start` | `node dist/index.js` | Run compiled server |
|
|
304
|
+
| `npm run clean` | `rm -rf dist` | Remove build artifacts |
|
|
305
|
+
| `npm test` | `vitest run` | Run test suite |
|
|
306
|
+
| `npm run test:watch` | `vitest` | Run tests in watch mode |
|
|
307
|
+
| `npm run test:coverage` | `vitest run --coverage` | Run tests with coverage report |
|
|
308
|
+
|
|
309
|
+
## License
|
|
310
|
+
|
|
311
|
+
ISC
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { StorageBackend } from "./storage-backend.js";
|
|
2
|
+
/** Set the singleton backend (called during server startup). */
|
|
3
|
+
export declare function initBackend(backend: StorageBackend): void;
|
|
4
|
+
/**
|
|
5
|
+
* Get the active storage backend.
|
|
6
|
+
*
|
|
7
|
+
* If no backend has been set via initBackend(), lazy-initializes a FileBackend.
|
|
8
|
+
* This makes existing tests pass without modification -- they never call
|
|
9
|
+
* initBackend(), so getBackend() auto-creates a FileBackend that delegates
|
|
10
|
+
* to the same service functions the tests already mock via vi.mock().
|
|
11
|
+
*/
|
|
12
|
+
export declare function getBackend(): StorageBackend;
|
|
13
|
+
/** Reset the singleton to null (for test isolation). */
|
|
14
|
+
export declare function resetBackend(): void;
|
|
15
|
+
/** Check whether a value looks like a cloud endpoint (http:// or https://). */
|
|
16
|
+
export declare function isCloudEndpoint(value: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Factory: create a backend from an optional endpoint string.
|
|
19
|
+
*
|
|
20
|
+
* - If endpoint is an HTTP/HTTPS URL, creates an HttpBackend for cloud mode.
|
|
21
|
+
* Requires sessionId and token (from env vars or tool-based session setup).
|
|
22
|
+
* - Otherwise returns a FileBackend for local file-based state.
|
|
23
|
+
*
|
|
24
|
+
* Note: Does NOT import config.ts to avoid circular dependency risk
|
|
25
|
+
* (decision from 02B-01). Caller passes params explicitly.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createBackend(endpoint?: string, sessionId?: string, token?: string): StorageBackend;
|
|
28
|
+
//# sourceMappingURL=backend-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend-provider.d.ts","sourceRoot":"","sources":["../../src/backend/backend-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAetD,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAEzD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,IAAI,cAAc,CAK3C;AAED,wDAAwD;AACxD,wBAAgB,YAAY,IAAI,IAAI,CAEnC;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,cAAc,CAahB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { FileBackend } from "./file-backend.js";
|
|
2
|
+
import { HttpBackend } from "./http-backend.js";
|
|
3
|
+
import { HttpClient } from "../cloud/http-client.js";
|
|
4
|
+
/**
|
|
5
|
+
* Singleton accessor for the active storage backend.
|
|
6
|
+
*
|
|
7
|
+
* Follows the same pattern as config.ts: explicit init for production,
|
|
8
|
+
* lazy fallback for tests. getBackend() auto-creates a FileBackend when
|
|
9
|
+
* no backend has been set, ensuring existing tests work without modification.
|
|
10
|
+
*/
|
|
11
|
+
let _backend = null;
|
|
12
|
+
/** Set the singleton backend (called during server startup). */
|
|
13
|
+
export function initBackend(backend) {
|
|
14
|
+
_backend = backend;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the active storage backend.
|
|
18
|
+
*
|
|
19
|
+
* If no backend has been set via initBackend(), lazy-initializes a FileBackend.
|
|
20
|
+
* This makes existing tests pass without modification -- they never call
|
|
21
|
+
* initBackend(), so getBackend() auto-creates a FileBackend that delegates
|
|
22
|
+
* to the same service functions the tests already mock via vi.mock().
|
|
23
|
+
*/
|
|
24
|
+
export function getBackend() {
|
|
25
|
+
if (!_backend) {
|
|
26
|
+
_backend = new FileBackend();
|
|
27
|
+
}
|
|
28
|
+
return _backend;
|
|
29
|
+
}
|
|
30
|
+
/** Reset the singleton to null (for test isolation). */
|
|
31
|
+
export function resetBackend() {
|
|
32
|
+
_backend = null;
|
|
33
|
+
}
|
|
34
|
+
/** Check whether a value looks like a cloud endpoint (http:// or https://). */
|
|
35
|
+
export function isCloudEndpoint(value) {
|
|
36
|
+
return /^https?:\/\//i.test(value);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Factory: create a backend from an optional endpoint string.
|
|
40
|
+
*
|
|
41
|
+
* - If endpoint is an HTTP/HTTPS URL, creates an HttpBackend for cloud mode.
|
|
42
|
+
* Requires sessionId and token (from env vars or tool-based session setup).
|
|
43
|
+
* - Otherwise returns a FileBackend for local file-based state.
|
|
44
|
+
*
|
|
45
|
+
* Note: Does NOT import config.ts to avoid circular dependency risk
|
|
46
|
+
* (decision from 02B-01). Caller passes params explicitly.
|
|
47
|
+
*/
|
|
48
|
+
export function createBackend(endpoint, sessionId, token) {
|
|
49
|
+
if (endpoint && isCloudEndpoint(endpoint)) {
|
|
50
|
+
if (!sessionId || !token) {
|
|
51
|
+
throw new Error("Cloud mode requires COGENT_SESSION_ID and COGENT_SECRET " +
|
|
52
|
+
"(or use create-session/join-session tools). " +
|
|
53
|
+
`Got endpoint: ${endpoint}`);
|
|
54
|
+
}
|
|
55
|
+
const httpClient = new HttpClient(endpoint, token);
|
|
56
|
+
return new HttpBackend(httpClient, sessionId);
|
|
57
|
+
}
|
|
58
|
+
return new FileBackend();
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=backend-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend-provider.js","sourceRoot":"","sources":["../../src/backend/backend-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;;;;;GAMG;AAEH,IAAI,QAAQ,GAA0B,IAAI,CAAC;AAE3C,gEAAgE;AAChE,MAAM,UAAU,WAAW,CAAC,OAAuB;IACjD,QAAQ,GAAG,OAAO,CAAC;AACrB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,YAAY;IAC1B,QAAQ,GAAG,IAAI,CAAC;AAClB,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAiB,EACjB,SAAkB,EAClB,KAAc;IAEd,IAAI,QAAQ,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CACb,0DAA0D;gBAC1D,8CAA8C;gBAC9C,iBAAiB,QAAQ,EAAE,CAC5B,CAAC;QACJ,CAAC;QACD,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACnD,OAAO,IAAI,WAAW,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,WAAW,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PeerInfo, MessageRecord, CliExecResult } from "../types.js";
|
|
2
|
+
import { HealthCheckResult } from "../services/health-check.js";
|
|
3
|
+
import { StorageBackend } from "./storage-backend.js";
|
|
4
|
+
/**
|
|
5
|
+
* File-based storage backend.
|
|
6
|
+
*
|
|
7
|
+
* Pure pass-through delegation to existing free functions in peer-registry.ts,
|
|
8
|
+
* cc-cli.ts, and health-check.ts. No added logic, logging, or transformation.
|
|
9
|
+
*/
|
|
10
|
+
export declare class FileBackend implements StorageBackend {
|
|
11
|
+
registerPeer(peerId: string, sessionId: string, cwd: string, label: string): Promise<PeerInfo>;
|
|
12
|
+
deregisterPeer(peerId: string): Promise<boolean>;
|
|
13
|
+
getPeer(peerId: string): Promise<PeerInfo | undefined>;
|
|
14
|
+
listPeers(): Promise<PeerInfo[]>;
|
|
15
|
+
updateLastSeen(peerId: string): Promise<void>;
|
|
16
|
+
recordMessage(record: Omit<MessageRecord, "id" | "timestamp">): Promise<MessageRecord>;
|
|
17
|
+
getHistory(peerId?: string, limit?: number): Promise<MessageRecord[]>;
|
|
18
|
+
validateSession(sessionId: string, cwd: string): Promise<boolean>;
|
|
19
|
+
execClaude(sessionId: string, message: string, cwd: string, timeoutMs?: number): Promise<CliExecResult>;
|
|
20
|
+
checkHealth(): Promise<HealthCheckResult>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=file-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-backend.d.ts","sourceRoot":"","sources":["../../src/backend/file-backend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAKtD;;;;;GAKG;AACH,qBAAa,WAAY,YAAW,cAAc;IAGhD,YAAY,CACV,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,QAAQ,CAAC;IAIpB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIhD,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAItD,SAAS,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIhC,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7C,aAAa,CACX,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,WAAW,CAAC,GAC9C,OAAO,CAAC,aAAa,CAAC;IAIzB,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAMrE,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjE,UAAU,CACR,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC;IAMzB,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAG1C"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as registry from "../services/peer-registry.js";
|
|
2
|
+
import * as cli from "../services/cc-cli.js";
|
|
3
|
+
import * as health from "../services/health-check.js";
|
|
4
|
+
/**
|
|
5
|
+
* File-based storage backend.
|
|
6
|
+
*
|
|
7
|
+
* Pure pass-through delegation to existing free functions in peer-registry.ts,
|
|
8
|
+
* cc-cli.ts, and health-check.ts. No added logic, logging, or transformation.
|
|
9
|
+
*/
|
|
10
|
+
export class FileBackend {
|
|
11
|
+
// --- Peer management ---
|
|
12
|
+
registerPeer(peerId, sessionId, cwd, label) {
|
|
13
|
+
return registry.registerPeer(peerId, sessionId, cwd, label);
|
|
14
|
+
}
|
|
15
|
+
deregisterPeer(peerId) {
|
|
16
|
+
return registry.deregisterPeer(peerId);
|
|
17
|
+
}
|
|
18
|
+
getPeer(peerId) {
|
|
19
|
+
return registry.getPeer(peerId);
|
|
20
|
+
}
|
|
21
|
+
listPeers() {
|
|
22
|
+
return registry.listPeers();
|
|
23
|
+
}
|
|
24
|
+
updateLastSeen(peerId) {
|
|
25
|
+
return registry.updateLastSeen(peerId);
|
|
26
|
+
}
|
|
27
|
+
// --- Message state ---
|
|
28
|
+
recordMessage(record) {
|
|
29
|
+
return registry.recordMessage(record);
|
|
30
|
+
}
|
|
31
|
+
getHistory(peerId, limit) {
|
|
32
|
+
return registry.getHistory(peerId, limit);
|
|
33
|
+
}
|
|
34
|
+
// --- Message relay ---
|
|
35
|
+
validateSession(sessionId, cwd) {
|
|
36
|
+
return cli.validateSession(sessionId, cwd);
|
|
37
|
+
}
|
|
38
|
+
execClaude(sessionId, message, cwd, timeoutMs) {
|
|
39
|
+
return cli.execClaude(sessionId, message, cwd, timeoutMs);
|
|
40
|
+
}
|
|
41
|
+
// --- Health ---
|
|
42
|
+
checkHealth() {
|
|
43
|
+
return health.checkHealth();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=file-backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-backend.js","sourceRoot":"","sources":["../../src/backend/file-backend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAC;AACzD,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAC;AAC7C,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACtB,0BAA0B;IAE1B,YAAY,CACV,MAAc,EACd,SAAiB,EACjB,GAAW,EACX,KAAa;QAEb,OAAO,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IAED,cAAc,CAAC,MAAc;QAC3B,OAAO,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,MAAc;QACpB,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAED,SAAS;QACP,OAAO,QAAQ,CAAC,SAAS,EAAE,CAAC;IAC9B,CAAC;IAED,cAAc,CAAC,MAAc;QAC3B,OAAO,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,wBAAwB;IAExB,aAAa,CACX,MAA+C;QAE/C,OAAO,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,UAAU,CAAC,MAAe,EAAE,KAAc;QACxC,OAAO,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,wBAAwB;IAExB,eAAe,CAAC,SAAiB,EAAE,GAAW;QAC5C,OAAO,GAAG,CAAC,eAAe,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAED,UAAU,CACR,SAAiB,EACjB,OAAe,EACf,GAAW,EACX,SAAkB;QAElB,OAAO,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,iBAAiB;IAEjB,WAAW;QACT,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { StorageBackend } from "./storage-backend.js";
|
|
2
|
+
import type { PeerInfo, MessageRecord, CliExecResult } from "../types.js";
|
|
3
|
+
import type { HealthCheckResult } from "../services/health-check.js";
|
|
4
|
+
import type { HttpClient } from "../cloud/http-client.js";
|
|
5
|
+
/**
|
|
6
|
+
* Cloud-mode storage backend.
|
|
7
|
+
*
|
|
8
|
+
* Implements StorageBackend by translating all state operations into REST
|
|
9
|
+
* API calls to the cloud relay server. Used when COGENT_ENDPOINT is
|
|
10
|
+
* set to an HTTP/HTTPS URL.
|
|
11
|
+
*
|
|
12
|
+
* Cloud-specific behavior differences from FileBackend:
|
|
13
|
+
* - updateLastSeen is a no-op (server tracks activity automatically)
|
|
14
|
+
* - validateSession always returns true (server validates on every request)
|
|
15
|
+
* - execClaude returns a synthetic result (no CLI subprocess in cloud mode)
|
|
16
|
+
* - checkHealth queries the server health endpoint instead of local checks
|
|
17
|
+
*/
|
|
18
|
+
export declare class HttpBackend implements StorageBackend {
|
|
19
|
+
private readonly http;
|
|
20
|
+
private readonly sessionId;
|
|
21
|
+
constructor(http: HttpClient, sessionId: string);
|
|
22
|
+
/**
|
|
23
|
+
* Register a peer in the cloud session.
|
|
24
|
+
* POST /api/sessions/:sessionId/peers
|
|
25
|
+
*
|
|
26
|
+
* The sessionId parameter from StorageBackend is the local CC sessionId;
|
|
27
|
+
* in cloud mode we ignore it and use this.sessionId (the cloud session).
|
|
28
|
+
*/
|
|
29
|
+
registerPeer(peerId: string, _sessionId: string, cwd: string, label: string): Promise<PeerInfo>;
|
|
30
|
+
/**
|
|
31
|
+
* Deregister a peer from the cloud session.
|
|
32
|
+
* DELETE /api/sessions/:sessionId/peers/:peerId
|
|
33
|
+
*
|
|
34
|
+
* Returns true on success, false if the peer was not found.
|
|
35
|
+
*/
|
|
36
|
+
deregisterPeer(peerId: string): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Get a single peer by ID.
|
|
39
|
+
* No dedicated single-peer REST endpoint exists, so we list all peers
|
|
40
|
+
* and filter client-side.
|
|
41
|
+
*/
|
|
42
|
+
getPeer(peerId: string): Promise<PeerInfo | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* List all peers in the cloud session.
|
|
45
|
+
* GET /api/sessions/:sessionId/peers
|
|
46
|
+
*/
|
|
47
|
+
listPeers(): Promise<PeerInfo[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Update last-seen timestamp for a peer.
|
|
50
|
+
* In cloud mode, the server updates lastSeenAt automatically on
|
|
51
|
+
* authenticated requests, so this is a no-op.
|
|
52
|
+
*/
|
|
53
|
+
updateLastSeen(_peerId: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Record a message in the cloud session.
|
|
56
|
+
* POST /api/sessions/:sessionId/messages
|
|
57
|
+
*
|
|
58
|
+
* Sends the message to the server which stores it and returns
|
|
59
|
+
* { id, success, timestamp }. We merge the server response with
|
|
60
|
+
* the input record to construct a full MessageRecord.
|
|
61
|
+
*/
|
|
62
|
+
recordMessage(record: Omit<MessageRecord, "id" | "timestamp">): Promise<MessageRecord>;
|
|
63
|
+
/**
|
|
64
|
+
* Get message history from the cloud session.
|
|
65
|
+
* GET /api/sessions/:sessionId/messages
|
|
66
|
+
*
|
|
67
|
+
* Supports optional peerId filter and limit (default 100).
|
|
68
|
+
*/
|
|
69
|
+
getHistory(peerId?: string, limit?: number): Promise<MessageRecord[]>;
|
|
70
|
+
/**
|
|
71
|
+
* Validate a session.
|
|
72
|
+
* In cloud mode, the server validates session authenticity on every
|
|
73
|
+
* authenticated request, so this always returns true.
|
|
74
|
+
*/
|
|
75
|
+
validateSession(_sessionId: string, _cwd: string): Promise<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* Execute a Claude CLI command.
|
|
78
|
+
* In cloud mode, there is no CLI subprocess. Message delivery is
|
|
79
|
+
* handled by recordMessage() via REST. The send-message tool handler
|
|
80
|
+
* calls execClaude() after validating peers, then calls recordMessage()
|
|
81
|
+
* separately. In cloud mode, execClaude simply returns a synthetic
|
|
82
|
+
* result indicating the message was delivered via the cloud relay.
|
|
83
|
+
*/
|
|
84
|
+
execClaude(_sessionId: string, _message: string, _cwd: string, _timeoutMs?: number): Promise<CliExecResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Check health of the cloud relay server.
|
|
87
|
+
* GET /api/health
|
|
88
|
+
*
|
|
89
|
+
* Maps the server's HealthResponse into the local HealthCheckResult
|
|
90
|
+
* format with cloud-mode-specific diagnostics.
|
|
91
|
+
*/
|
|
92
|
+
checkHealth(): Promise<HealthCheckResult>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=http-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-backend.d.ts","sourceRoot":"","sources":["../../src/backend/http-backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAc1D;;;;;;;;;;;;GAYG;AACH,qBAAa,WAAY,YAAW,cAAc;IAE9C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,SAAS;gBADT,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM;IAGpC;;;;;;OAMG;IACG,YAAY,CAChB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,QAAQ,CAAC;IAKpB;;;;;OAKG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAatD;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAK5D;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAMtC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD;;;;;;;OAOG;IACG,aAAa,CACjB,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,WAAW,CAAC,GAC9C,OAAO,CAAC,aAAa,CAAC;IAmBzB;;;;;OAKG;IACG,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAe3E;;;;OAIG;IACG,eAAe,CACnB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,OAAO,CAAC;IAInB;;;;;;;OAOG;IACG,UAAU,CACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,aAAa,CAAC;IAQzB;;;;;;OAMG;IACG,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAoChD"}
|