agent-ws 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 +21 -0
- package/README.md +176 -0
- package/SECURITY.md +25 -0
- package/dist/agent.js +760 -0
- package/dist/agent.js.map +7 -0
- package/dist/cli.js +855 -0
- package/dist/cli.js.map +7 -0
- package/dist/index.js +776 -0
- package/dist/index.js.map +7 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Patrick Little
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# agent-ws
|
|
2
|
+
|
|
3
|
+
WebSocket bridge for CLI AI agents. Stream responses from Claude Code and Codex CLI over WebSocket. A dumb pipe: no prompt engineering, no credential handling, just transport.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js 20+
|
|
8
|
+
- At least one supported CLI agent installed:
|
|
9
|
+
- [Claude Code](https://docs.anthropic.com/en/docs/claude-code) (`npm install -g @anthropic-ai/claude-code`)
|
|
10
|
+
- [Codex](https://github.com/openai/codex) (`npm install -g @openai/codex`)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# From npm
|
|
16
|
+
npm install -g agent-ws
|
|
17
|
+
|
|
18
|
+
# Or run directly
|
|
19
|
+
npx agent-ws
|
|
20
|
+
|
|
21
|
+
# Or clone and run locally
|
|
22
|
+
git clone https://github.com/Lisovate/agent-ws.git
|
|
23
|
+
cd agent-ws
|
|
24
|
+
npm install
|
|
25
|
+
npm run build
|
|
26
|
+
npm start
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Start the WebSocket bridge
|
|
33
|
+
agent-ws
|
|
34
|
+
|
|
35
|
+
# Connect via WebSocket on ws://localhost:9999
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Library Usage
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { AgentWS } from "agent-ws";
|
|
42
|
+
|
|
43
|
+
const agent = new AgentWS({
|
|
44
|
+
port: 9999,
|
|
45
|
+
host: "localhost",
|
|
46
|
+
agentName: "my-app", // Customise the agent identity in connected messages
|
|
47
|
+
sessionDir: "my-sessions", // Customise the temp directory name for sessions
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await agent.start();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## CLI Options
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
-p, --port <port> WebSocket server port (default: 9999)
|
|
57
|
+
-H, --host <host> WebSocket server host (default: localhost)
|
|
58
|
+
-c, --claude-path <path> Path to Claude CLI (default: claude)
|
|
59
|
+
-t, --timeout <seconds> Process timeout in seconds (default: 300)
|
|
60
|
+
--log-level <level> Log level: debug, info, warn, error (default: info)
|
|
61
|
+
--origins <origins> Comma-separated allowed origins
|
|
62
|
+
-V, --version Output version number
|
|
63
|
+
-h, --help Display help
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Architecture
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
┌───────────────┐ WebSocket ┌─────────────┐ stdio ┌─────────────┐
|
|
70
|
+
│ Your App │ <=================> │ agent-ws │ <===============> │ Claude Code │
|
|
71
|
+
│ (any client) │ localhost:9999 │ (Node.js) │ --print --json │ / Codex │
|
|
72
|
+
└───────────────┘ └─────────────┘ └─────────────┘
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Any WebSocket client can connect — browser frontends, backend services, scripts, other CLI tools. Each connection gets its own CLI process. The agent:
|
|
76
|
+
1. Accepts WebSocket connections on localhost
|
|
77
|
+
2. Receives prompt messages from your client
|
|
78
|
+
3. Spawns the appropriate CLI agent (Claude Code or Codex)
|
|
79
|
+
4. Streams output back in real-time
|
|
80
|
+
5. Manages process lifecycle (timeout, cancellation, cleanup)
|
|
81
|
+
|
|
82
|
+
## Supported Agents
|
|
83
|
+
|
|
84
|
+
| Agent | Provider field | CLI |
|
|
85
|
+
|-------|---------------|-----|
|
|
86
|
+
| Claude Code | `"claude"` (default) | `claude --print` (+ `--continue` when `projectId` is set) |
|
|
87
|
+
| Codex | `"codex"` | `codex --json` |
|
|
88
|
+
|
|
89
|
+
## Protocol
|
|
90
|
+
|
|
91
|
+
### Client → Agent
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{ "type": "prompt", "prompt": "Build a login form", "requestId": "uuid", "model": "opus", "provider": "claude" }
|
|
95
|
+
{ "type": "prompt", "prompt": "...", "requestId": "uuid", "projectId": "my-app", "systemPrompt": "...", "thinkingTokens": 2048 }
|
|
96
|
+
{ "type": "cancel", "requestId": "uuid" }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
| Field | Required | Description |
|
|
100
|
+
|-------|----------|-------------|
|
|
101
|
+
| `prompt` | yes | The prompt text (max 512KB) |
|
|
102
|
+
| `requestId` | yes | Unique request identifier |
|
|
103
|
+
| `model` | no | Model name (e.g. `"sonnet"`, `"opus"`) |
|
|
104
|
+
| `provider` | no | `"claude"` (default) or `"codex"` |
|
|
105
|
+
| `projectId` | no | Scopes CLI session by directory. Enables `--continue` for multi-turn. Alphanumeric, hyphens, underscores, dots only. |
|
|
106
|
+
| `systemPrompt` | no | Appended as system prompt (max 64KB) |
|
|
107
|
+
| `thinkingTokens` | no | Max thinking tokens. `0` disables thinking. Omit to let Claude decide. |
|
|
108
|
+
|
|
109
|
+
### Agent → Client
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{ "type": "connected", "version": "1.0", "agent": "agent-ws" }
|
|
113
|
+
{ "type": "chunk", "content": "Here's a login form...", "requestId": "uuid" }
|
|
114
|
+
{ "type": "chunk", "content": "Let me think...", "requestId": "uuid", "thinking": true }
|
|
115
|
+
{ "type": "complete", "requestId": "uuid" }
|
|
116
|
+
{ "type": "error", "message": "Process timed out", "requestId": "uuid" }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Chunks with `thinking: true` contain Claude's reasoning. Clients can display these as a thinking indicator or ignore them.
|
|
120
|
+
|
|
121
|
+
## Security
|
|
122
|
+
|
|
123
|
+
- **Local only**: Binds to `localhost` by default
|
|
124
|
+
- **Origin validation**: Optional `--origins` flag restricts allowed origins
|
|
125
|
+
- **No credentials**: Never stores or transmits API keys
|
|
126
|
+
- **Process isolation**: One CLI process per connection
|
|
127
|
+
- **Message limits**: 1MB max WebSocket payload, 512KB max prompt size
|
|
128
|
+
- **Heartbeat**: Dead connections are cleaned up every 30 seconds
|
|
129
|
+
|
|
130
|
+
## Development
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm install # Install dependencies
|
|
134
|
+
npm run build # Build TypeScript
|
|
135
|
+
npm test # Run tests
|
|
136
|
+
npm run typecheck # Type check
|
|
137
|
+
npm start # Start from built output
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Project Structure
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
src/
|
|
144
|
+
├── index.ts # Barrel export (library entry point)
|
|
145
|
+
├── cli.ts # CLI entry point (Commander)
|
|
146
|
+
├── agent.ts # Orchestrator: wires server + logger
|
|
147
|
+
├── server/
|
|
148
|
+
│ ├── websocket.ts # WebSocket server, heartbeat, per-connection state
|
|
149
|
+
│ └── protocol.ts # Message types, validation
|
|
150
|
+
├── process/
|
|
151
|
+
│ ├── claude-runner.ts # Claude Code process spawn/kill/timeout
|
|
152
|
+
│ ├── codex-runner.ts # Codex process spawn/kill/timeout
|
|
153
|
+
│ └── output-cleaner.ts # ANSI stripping via node:util
|
|
154
|
+
└── utils/
|
|
155
|
+
├── logger.ts # Pino logger factory
|
|
156
|
+
└── claude-check.ts # Claude CLI availability check
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Troubleshooting
|
|
160
|
+
|
|
161
|
+
### "Claude CLI not found"
|
|
162
|
+
Make sure Claude Code is installed:
|
|
163
|
+
```bash
|
|
164
|
+
npm install -g @anthropic-ai/claude-code
|
|
165
|
+
claude --version
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### "Port 9999 already in use"
|
|
169
|
+
Another instance might be running. Kill it or use a different port:
|
|
170
|
+
```bash
|
|
171
|
+
agent-ws --port 9998
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
MIT
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
If you discover a security vulnerability in agent-ws, please report it through [GitHub Security Advisories](https://github.com/Lisovate/agent-ws/security/advisories/new).
|
|
6
|
+
|
|
7
|
+
**Do not open a public issue for security vulnerabilities.**
|
|
8
|
+
|
|
9
|
+
We will acknowledge your report within 48 hours and aim to release a fix within 7 days for critical issues.
|
|
10
|
+
|
|
11
|
+
## Scope
|
|
12
|
+
|
|
13
|
+
agent-ws runs locally on your machine and bridges WebSocket connections to CLI AI agents. Security considerations include:
|
|
14
|
+
|
|
15
|
+
- **Local-only by default**: The WebSocket server binds to `localhost` to prevent external access.
|
|
16
|
+
- **Origin validation**: Optional `--origins` flag restricts which browser origins can connect.
|
|
17
|
+
- **No credential handling**: The agent never stores, processes, or transmits API keys or passwords.
|
|
18
|
+
- **Process isolation**: Each WebSocket connection gets its own CLI process.
|
|
19
|
+
- **Message size limits**: WebSocket payload capped at 1MB by default.
|
|
20
|
+
|
|
21
|
+
## Supported Versions
|
|
22
|
+
|
|
23
|
+
| Version | Supported |
|
|
24
|
+
|---------|-----------|
|
|
25
|
+
| 0.x | Latest release only |
|