@j-o-r/hello-dave 0.0.7 → 0.0.8

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.
@@ -0,0 +1,326 @@
1
+ # Generic Toolset Module (lib/genericToolset.js)
2
+
3
+ ## Overview
4
+
5
+ The `genericToolset.js` module provides a pre-built collection of 11 utility tools designed for integration with the `ToolSet` class from the hello-dave library. These tools handle common operations like code execution, file I/O, system interactions, and memory management. They are exported as `toolsPool`, an object mapping tool names to `TSTool` objects (containing description, parameters schema, and execution method).
6
+
7
+ This module is ideal for toolsets or utility libraries, enabling agents to perform real-world tasks without custom implementations. Tools follow OpenAI-style JSON Schema for parameters and support asynchronous execution.
8
+
9
+ **Key Benefits**:
10
+ - **Ready-to-Use**: Load into any `ToolSet` instance for immediate functionality.
11
+ - **Secure & Sandboxed**: Tools operate in controlled environments (e.g., specific CWD, no escaping in Bash).
12
+ - **Persistent State**: Memory tools allow offloading state from LLM context for efficiency.
13
+ - **Documentation**: Each tool includes JSDoc annotations for IDE support and generated docs.
14
+
15
+ To generate full JSDoc for this module (and the library):
16
+ 1. Install JSDoc: `npm install -g jsdoc`
17
+ 2. Run: `jsdoc lib/genericToolset.js -d docs/jsdoc/generic-toolset`
18
+ 3. View HTML docs in `docs/jsdoc/generic-toolset/index.html`.
19
+
20
+ See [ToolSet Documentation](../toolset.md) for integration details.
21
+
22
+ ## Exports
23
+
24
+ - **`toolsPool`**: `{ [name: string]: TSTool }` – Object with 11 pre-defined tools.
25
+ - `TSTool`: `{ description: string, parameters: TSSchema, method: async (params: object) => any }`
26
+ - `TSSchema`: JSON Schema object (e.g., `{ type: "object", properties: {...}, required: [...] }`).
27
+
28
+ No default export; use named import: `import { toolsPool } from "@j-o-r/hello-dave/lib/genericToolset.js";`
29
+
30
+ ## Usage Examples
31
+
32
+ ### Basic Import and Population of ToolSet
33
+ ```javascript
34
+ import { ToolSet } from "@j-o-r/hello-dave";
35
+ import { toolsPool } from "@j-o-r/hello-dave/lib/genericToolset.js";
36
+
37
+ const toolset = new ToolSet("auto"); // Or "required" for empty start
38
+
39
+ // Add all generic tools
40
+ Object.entries(toolsPool).forEach(([name, tool]) => {
41
+ toolset.add(name, tool.description, tool.parameters, tool.method);
42
+ });
43
+
44
+ // Or selectively
45
+ toolset.add("memory_recall", toolsPool.memory_recall.description, toolsPool.memory_recall.parameters, toolsPool.memory_recall.method);
46
+
47
+ // List available tools
48
+ console.log(toolset.list());
49
+ ```
50
+
51
+ ### Integration with AgentManager
52
+ ```javascript
53
+ import { AgentManager } from "@j-o-r/hello-dave";
54
+
55
+ const agent = new AgentManager("my-agent");
56
+ agent.setup({
57
+ toolsetMode: "auto" // Automatically loads all tools from toolsPool
58
+ });
59
+
60
+ // Add specific tools post-setup
61
+ agent.addGenericToolcall("execute_bash_script");
62
+ agent.addGenericToolcall("memory_write");
63
+ ```
64
+
65
+ ### Example: Using Memory Tools in a Prompt Workflow
66
+ ```javascript
67
+ import { Prompt } from "@j-o-r/hello-dave";
68
+ import { toolsPool } from "@j-o-r/hello-dave/lib/genericToolset.js";
69
+
70
+ const prompt = new Prompt("You are a task manager. Use memory tools to track progress.");
71
+ const toolset = new ToolSet("required");
72
+ toolset.add("memory_write", ...toolsPool.memory_write); // Spread for destructuring
73
+
74
+ // In agent loop: prompt.addMessage("Start new task: Implement login.");
75
+ await toolset.execute(prompt); // LLM may call tools based on prompt
76
+ ```
77
+
78
+ ## Key Tools
79
+
80
+ Below is a list of the 11 tools in `toolsPool`, with descriptions, parameter schemas, and usage examples. For full JSDoc details, generate docs as noted above.
81
+
82
+ ### 1. `javascript_interpreter`
83
+ **Description**: Execute ESM ES6 JavaScript in a Node.js environment. Captures `console.log` output. CWD: `~/devpri/js/hello-dave`.
84
+
85
+ **Parameters Schema**:
86
+ ```json
87
+ {
88
+ "type": "object",
89
+ "properties": {
90
+ "code": { "type": "string", "description": "JavaScript code to execute" }
91
+ },
92
+ "required": ["code"]
93
+ }
94
+ ```
95
+
96
+ **Usage Example**:
97
+ ```javascript
98
+ await toolset.call("javascript_interpreter", { code: "console.log(2 + 2);" });
99
+ // Returns: { output: "4\n", error: null }
100
+ ```
101
+
102
+ ### 2. `get_user_env`
103
+ **Description**: Retrieve user environment details (name, system info, location, IP).
104
+
105
+ **Parameters Schema**:
106
+ ```json
107
+ {
108
+ "type": "object",
109
+ "properties": {},
110
+ "required": []
111
+ }
112
+ ```
113
+
114
+ **Usage Example**:
115
+ ```javascript
116
+ await toolset.call("get_user_env", {});
117
+ // Returns: { name: "User", system: "Ubuntu 25.10", city: "Example City", ... }
118
+ ```
119
+
120
+ ### 3. `execute_bash_script`
121
+ **Description**: Run raw Bash scripts/commands verbatim (no escaping). Supports Ubuntu 25.10 environment.
122
+
123
+ **Parameters Schema**:
124
+ ```json
125
+ {
126
+ "type": "object",
127
+ "properties": {
128
+ "bash_script": { "type": "string", "description": "Raw Bash script (literal text)" }
129
+ },
130
+ "required": ["bash_script"]
131
+ }
132
+ ```
133
+
134
+ **Usage Example**:
135
+ ```javascript
136
+ await toolset.call("execute_bash_script", { bash_script: "ls -la" });
137
+ // Returns: { stdout: "...", stderr: "", exitCode: 0 }
138
+ ```
139
+
140
+ ### 4. `send_email`
141
+ **Description**: Send email using `msmtp` (to, subject, body).
142
+
143
+ **Parameters Schema**:
144
+ ```json
145
+ {
146
+ "type": "object",
147
+ "properties": {
148
+ "to": { "type": "string" },
149
+ "subject": { "type": "string" },
150
+ "body": { "type": "string" }
151
+ },
152
+ "required": ["to", "subject", "body"]
153
+ }
154
+ ```
155
+
156
+ **Usage Example**:
157
+ ```javascript
158
+ await toolset.call("send_email", { to: "user@example.com", subject: "Hello", body: "Test" });
159
+ // Returns: { success: true }
160
+ ```
161
+
162
+ ### 5. `open_link`
163
+ **Description**: Open URL or file using `xdg-open`.
164
+
165
+ **Parameters Schema**:
166
+ ```json
167
+ {
168
+ "type": "object",
169
+ "properties": {
170
+ "url": { "type": "string", "description": "URL or file path" }
171
+ },
172
+ "required": ["url"]
173
+ }
174
+ ```
175
+
176
+ **Usage Example**:
177
+ ```javascript
178
+ await toolset.call("open_link", { url: "https://example.com" });
179
+ // Returns: { opened: true }
180
+ ```
181
+
182
+ ### 6. `execute_remote_script`
183
+ **Description**: Execute Bash script on remote server via SSH (`ssh://user@host[:port]`).
184
+
185
+ **Parameters Schema**:
186
+ ```json
187
+ {
188
+ "type": "object",
189
+ "properties": {
190
+ "remote": { "type": "string", "description": "SSH URL" },
191
+ "script": { "type": "string", "description": "Bash script" }
192
+ },
193
+ "required": ["remote", "script"]
194
+ }
195
+ ```
196
+
197
+ **Usage Example**:
198
+ ```javascript
199
+ await toolset.call("execute_remote_script", { remote: "ssh://user@host", script: "whoami" });
200
+ // Returns: { stdout: "user\n", ... }
201
+ ```
202
+
203
+ ### 7. `history_search`
204
+ **Description**: Search chat history sessions using regex (e.g., in `.cache/[app]/[prompt]/sessions/*.ndjson`).
205
+
206
+ **Parameters Schema**:
207
+ ```json
208
+ {
209
+ "type": "object",
210
+ "properties": {
211
+ "query": { "type": "string", "description": "Regex query" }
212
+ },
213
+ "required": ["query"]
214
+ }
215
+ ```
216
+
217
+ **Usage Example**:
218
+ ```javascript
219
+ await toolset.call("history_search", { query: package.json });
220
+ // Returns: [{ session: "path", matches: [...] }, ...]
221
+ ```
222
+
223
+ ### 8. `read_file`
224
+ **Description**: Read file content from CWD (relative path, no absolute/parent traversal).
225
+
226
+ **Parameters Schema**:
227
+ ```json
228
+ {
229
+ "type": "object",
230
+ "properties": {
231
+ "path": { "type": "string", "description": "Relative file path" }
232
+ },
233
+ "required": ["path"]
234
+ }
235
+ ```
236
+
237
+ **Usage Example**:
238
+ ```javascript
239
+ await toolset.call("read_file", { path: "example.txt" });
240
+ // Returns: { content: "File text\n", encoding: "utf8" }
241
+ ```
242
+
243
+ ### 9. `write_file`
244
+ **Description**: Write raw content to file in CWD (relative path). Returns bytes written.
245
+
246
+ **Parameters Schema**:
247
+ ```json
248
+ {
249
+ "type": "object",
250
+ "properties": {
251
+ "path": { "type": "string" },
252
+ "content": { "type": "string" }
253
+ },
254
+ "required": ["path", "content"]
255
+ }
256
+ ```
257
+
258
+ **Usage Example**:
259
+ ```javascript
260
+ await toolset.call("write_file", { path: "output.txt", content: "Hello World" });
261
+ // Returns: { bytesWritten: 11 }
262
+ ```
263
+
264
+ ### 10. `memory_recall`
265
+ **Description**: Recall latest values for keys from agent-specific memory (`.cache/[agent]/memory.ndjson`).
266
+
267
+ **Parameters Schema**:
268
+ ```json
269
+ {
270
+ "type": "object",
271
+ "properties": {
272
+ "keys": {
273
+ "type": "array",
274
+ "items": { "type": "string" },
275
+ "description": "List of keys to recall"
276
+ }
277
+ },
278
+ "required": ["keys"]
279
+ }
280
+ ```
281
+
282
+ **Usage Example**:
283
+ ```javascript
284
+ await toolset.call("memory_recall", { keys: ["current_task"] });
285
+ // Returns: { current_task: "Implement login" } or {}
286
+ ```
287
+
288
+ ### 11. `memory_write`
289
+ **Description**: Append/update key-value pairs in agent memory (overwrites same keys).
290
+
291
+ **Parameters Schema**:
292
+ ```json
293
+ {
294
+ "type": "object",
295
+ "properties": {
296
+ "entries": {
297
+ "type": "array",
298
+ "items": {
299
+ "type": "object",
300
+ "properties": {
301
+ "key": { "type": "string" },
302
+ "value": { "type": "string" }
303
+ },
304
+ "required": ["key", "value"]
305
+ }
306
+ }
307
+ },
308
+ "required": ["entries"]
309
+ }
310
+ ```
311
+
312
+ **Usage Example**:
313
+ ```javascript
314
+ await toolset.call("memory_write", { entries: [{ key: "step", value: "1/5" }] });
315
+ // Returns: { stored: [{ key: "step", value: "1/5" }] }
316
+ ```
317
+
318
+ ## Best Practices
319
+ - **Security**: Tools like `execute_bash_script` and `write_file` are powerful; use in trusted environments.
320
+ - **Error Handling**: Methods return `{ success: boolean, error?: string, data: any }` for robustness.
321
+ - **Customization**: Extend `toolsPool` by adding your own tools before populating `ToolSet`.
322
+ - **JSDoc Integration**: Annotations include `@param`, `@returns`, `@example` for full type safety in editors like VS Code.
323
+
324
+ For syntax validation in tools (e.g., JS in `write_file`), see [Tools Syntax Validation](../tools-syntax-validation.md). For path handling, see [Path Resolution Best Practices](../path-resolution-best-practices.md).
325
+
326
+ **Updated**: April 10, 2026
@@ -0,0 +1,253 @@
1
+ # Agent Networking How-Tos
2
+
3
+ ## Table of Contents
4
+ - [Introduction](#introduction)
5
+ - [Current Howtos Files](#current-howtos-files)
6
+ - [Overview of Agent Networking](#overview-of-agent-networking)
7
+ - [Setup Steps](#setup-steps)
8
+ - [Using --serve Flag](#using--serve-flag)
9
+ - [Using --connect Flag](#using--connect-flag)
10
+ - [Multi-Agent Chains via CodeServer](#multi-agent-chains-via-codeserver)
11
+ - [Examples](#examples)
12
+ - [Bash Examples from codeserver.sh](#bash-examples-from-codeserver-sh)
13
+ - [JavaScript Fetch Examples](#javascript-fetch-examples)
14
+ - [Troubleshooting](#troubleshooting)
15
+ - [Related Documentation](#related-documentation)
16
+
17
+ ## Introduction
18
+ This guide provides accurate how-tos for networking agents in the hello-dave project. Agent communication uses WebSocket servers for real-time interaction, primarily through the CodeServer setup. The CLI entrypoint is `bin/dave.js` (or `node bin/dave.js`), with flags like `--serve` (for starting a WebSocket server on individual agents like `code_agent.js`), `--connect` (to chain to a server), and `--ask` (for querying agents locally or remotely). Multi-agent chains are orchestrated via `agents/codeserver.sh`, which launches a PM2 cluster of interconnected agents.
19
+
20
+ Networking enables specialized agents (e.g., memory_agent, todo_agent, code_agent) to collaborate by connecting to a central server, supporting complex workflows like code generation with memory and testing.
21
+
22
+ ## Current Howtos Files
23
+ After the urgent fix and deletion of the inaccurate previous file:
24
+ - The `./docs/howtos/` directory was recreated and now contains only this file: `agent-networking.md` (newly created based on real project structure).
25
+ - No other `.md` files are present.
26
+
27
+ ## Overview of Agent Networking
28
+ In hello-dave, networking is WebSocket-based:
29
+ - **Server Mode (--serve)**: Starts a WebSocket server (e.g., on `code_agent.js`) for other agents to connect to.
30
+ - **Client Mode (--connect)**: Agents connect to a WebSocket server (e.g., `ws://localhost:8080/ws`) to forward requests and share state.
31
+ - **Primary Example**: `agents/codeserver.sh` spawns a central `code_agent` server and connects helper agents (todo, memory, etc.) to it, forming a multi-agent chain.
32
+ - No standalone `--serve` on `bin/dave.js`; it's used on individual agent scripts (e.g., `node code_agent.js --serve 8080`).
33
+ - Interactions: Use `bin/dave.js --connect ws://... --secret ...` for remote queries, or pipe inputs for one-shot actions.
34
+ - Chaining: Outputs from connected agents (e.g., memory_agent recall) feed into the main agent via WebSocket messages.
35
+
36
+ This setup is useful for scalable agent collaboration but is centered around the CodeServer pattern. For broader networking, consider extending with custom WebSocket handlers.
37
+
38
+ ## Setup Steps
39
+ 1. **Prerequisites**:
40
+ - Node.js (v18+), PM2 (`npm install -g pm2`), and project dependencies: `npm install`.
41
+ - Set environment: `export XAIKEY=your_xai_api_key` for Grok API access (required for local asks).
42
+ - Ensure ports (e.g., 8080) are free and firewall allows localhost connections.
43
+
44
+ 2. **Project Structure**:
45
+ - CLI: `bin/dave.js` for high-level commands.
46
+ - Agents: Individual scripts in root (e.g., `code_agent.js`, `memory_agent.js`).
47
+ - Orchestrator: `agents/codeserver.sh` for multi-agent setup.
48
+
49
+ 3. **Start a Basic Server**:
50
+ - Run an individual agent in server mode: `node code_agent.js --serve 8080 --secret 123 --tools javascript`.
51
+
52
+ 4. **Connect and Interact**:
53
+ - Use `bin/dave.js --connect ws://localhost:8080/ws --secret 123` for interactive mode.
54
+ - Or pipe: `echo "Write a function" | bin/dave.js --connect ws://localhost:8080/ws --secret 123`.
55
+
56
+ ## Using --serve Flag
57
+ The `--serve` flag is supported on individual agent scripts (e.g., `code_agent.js`) to start a WebSocket server. It enables the agent to act as a hub for connected clients.
58
+
59
+ ### Syntax
60
+ ```
61
+ node [agent-script].js --serve [PORT] --secret [SECRET] [--tools [TOOLSET]]
62
+ ```
63
+ - `PORT`: WebSocket port (default 8080).
64
+ - `SECRET`: Authentication token (min 3 chars, default '123').
65
+ - `--tools`: Optional toolset (e.g., 'javascript' for code_agent).
66
+
67
+ ### Example: Serving Code Agent
68
+ ```
69
+ node code_agent.js --serve 8080 --secret mysecret --tools javascript
70
+ ```
71
+ Output:
72
+ ```
73
+ Code Agent WebSocket server started at ws://localhost:8080/ws
74
+ Waiting for connections...
75
+ ```
76
+ The server exposes `/ws` endpoint for WebSocket connections. Connected agents can send actions like `user_request`, `user_info`, `user_reset`.
77
+
78
+ ## Using --connect Flag
79
+ The `--connect` flag (on `bin/dave.js` or agent scripts) connects to a WebSocket server, enabling remote interaction or chaining.
80
+
81
+ ### Syntax
82
+ ```
83
+ bin/dave.js --connect [ws://URL] --secret [SECRET]
84
+ ```
85
+ Or on agents:
86
+ ```
87
+ node [agent-script].js --connect [ws://URL] --secret [SECRET]
88
+ ```
89
+ - Supports interactive mode or piped input (e.g., `echo "query" | bin/dave.js --connect ...`).
90
+ - Actions: `user_request` (default for queries), `user_info`, `user_reset`.
91
+
92
+ ### Example: Connecting to CodeServer
93
+ Interactive:
94
+ ```
95
+ bin/dave.js --connect ws://localhost:8080/ws --secret 123
96
+ ```
97
+ Piped:
98
+ ```
99
+ echo "Generate code for a todo app" | bin/dave.js --connect ws://localhost:8080/ws --secret 123
100
+ ```
101
+ This forwards the request to the connected server, leveraging any chained agents.
102
+
103
+ ## Multi-Agent Chains via CodeServer
104
+ The primary multi-agent setup is via `agents/codeserver.sh`, which launches a PM2 cluster:
105
+ - Central: `code_agent` in `--serve` mode.
106
+ - Helpers: `todo_agent`, `memory_agent`, `readme_agent`, `npm_agent`, `docs_agent`, `test_agent` all `--connect` to the central WS.
107
+ - Chain Flow: Input → code_agent → delegates to connected agents (e.g., memory for recall, todo for planning, test for validation) → response.
108
+
109
+ This forms implicit chains, e.g., code_agent queries memory_agent for context before generating code.
110
+
111
+ ### Chain Example: Memory → Todo → Code
112
+ - memory_agent stores/recalls state.
113
+ - todo_agent manages tasks based on memory.
114
+ - code_agent generates code from todo lists, with all connected to the same WS hub.
115
+
116
+ Orchestration happens internally via WebSocket message passing.
117
+
118
+ ## Examples
119
+ ### Basic Server + Connect
120
+ 1. Start server:
121
+ ```
122
+ node code_agent.js --serve 8080 --secret 123
123
+ ```
124
+ 2. Connect interactively:
125
+ ```
126
+ bin/dave.js --connect ws://localhost:8080/ws --secret 123
127
+ ```
128
+ Type queries; responses use the code_agent's capabilities.
129
+
130
+ ### Remote Ask via Connect
131
+ ```
132
+ bin/dave.js --ask --connect ws://localhost:8080/ws --secret 123
133
+ ```
134
+ Combines local asking with remote execution.
135
+
136
+ ## Bash Examples from codeserver.sh
137
+ The `agents/codeserver.sh` script is the canonical multi-agent launcher. It:
138
+ - Validates port (1024-65535) and secret (≥3 chars).
139
+ - Deletes old PM2 processes.
140
+ - Spawns central `code_agent --serve`.
141
+ - Connects helpers: todo, readme, npm, docs, test, memory.
142
+
143
+ ### Full Script Usage
144
+ ```
145
+ cd hello-dave
146
+ ./agents/codeserver.sh 8080 mysecret
147
+ ```
148
+ Output:
149
+ ```
150
+ Starting CodeServer on port 8080 in folder 'hello-dave' ... with SECRET 'mysecret'...
151
+ CodeServer processes spawned with prefix 'hello-dave_' and suffix _8080. Check with: pm2 list | grep 'hello-dave_8080'
152
+ dave --connect ws://127.0.0.1:8080/ws --secret 'mysecret'
153
+ ```
154
+
155
+ ### Custom Bash Chain Script
156
+ Create `start-chain.sh` (inspired by codeserver.sh):
157
+ ```bash
158
+ #!/bin/bash
159
+ PORT=${1:-8080}
160
+ SECRET=${2:-123}
161
+
162
+ # Start central server
163
+ node code_agent.js --serve $PORT --secret $SECRET --tools javascript &
164
+ SERVER_PID=$!
165
+
166
+ # Connect helpers
167
+ node memory_agent.js --connect "ws://127.0.0.1:$PORT/ws" --secret $SECRET &
168
+ node todo_agent.js --connect "ws://127.0.0.1:$PORT/ws" --secret $SECRET &
169
+
170
+ # Interact
171
+ echo "Build a simple app" | bin/dave.js --connect "ws://127.0.0.1:$PORT/ws" --secret $SECRET
172
+
173
+ # Cleanup (optional)
174
+ # kill $SERVER_PID
175
+ ```
176
+ Run: `chmod +x start-chain.sh && ./start-chain.sh 8080 mysecret`
177
+
178
+ Use PM2 for production: `pm2 start ecosystem.config.js` (define processes similarly).
179
+
180
+ ## JavaScript Fetch Examples
181
+ For programmatic chaining, use native `fetch` (Node.js 18+) to interact with WS (via WebSocket library) or HTTP endpoints if exposed. However, hello-dave uses pure WS; for fetch, assume agent servers expose REST if customized. Here's a basic WS client example using `ws` library (`npm install ws`).
182
+
183
+ ### JS WS Client Chain
184
+ Create `chain-client.js`:
185
+ ```javascript
186
+ const WebSocket = require('ws');
187
+
188
+ async function connectAndChain(url, secret, input) {
189
+ return new Promise((resolve, reject) => {
190
+ const ws = new WebSocket(url);
191
+
192
+ ws.on('open', () => {
193
+ // Send user_request (simulates piped input)
194
+ ws.send(JSON.stringify({ action: 'user_request', input, secret }));
195
+
196
+ let response = '';
197
+ ws.on('message', (data) => {
198
+ const msg = JSON.parse(data);
199
+ if (msg.type === 'content') {
200
+ response += msg.content;
201
+ if (msg.done) {
202
+ ws.close();
203
+ resolve(response);
204
+ }
205
+ }
206
+ });
207
+
208
+ ws.on('error', reject);
209
+ });
210
+ });
211
+ }
212
+
213
+ // Chain: Query memory via todo, then code
214
+ async function exampleChain() {
215
+ const url = 'ws://localhost:8080/ws';
216
+ const secret = '123';
217
+
218
+ // Step 1: Recall memory (via connected memory_agent)
219
+ const memory = await connectAndChain(url, secret, 'Recall last task');
220
+ console.log('Memory:', memory);
221
+
222
+ // Step 2: Add to todo
223
+ const todo = await connectAndChain(url, secret, `Add task from memory: ${memory}`);
224
+ console.log('Todo:', todo);
225
+
226
+ // Step 3: Generate code
227
+ const code = await connectAndChain(url, secret, `Generate code for: ${todo}`);
228
+ console.log('Code:', code);
229
+ }
230
+
231
+ exampleChain().catch(console.error);
232
+ ```
233
+ Run: `node chain-client.js` (after starting CodeServer).
234
+
235
+ Note: Actual message format matches project's `wsIO` (action: 'user_request', input).
236
+
237
+ ## Troubleshooting
238
+ - **Connection Refused**: Verify server is running (`node code_agent.js --serve 8080`) and port open (`netstat -tuln | grep 8080`). Check WS URL format: `ws://localhost:8080/ws`.
239
+ - **Secret Mismatch**: Ensure `--secret` matches on connect/serve (case-sensitive, ≥3 chars). Error: "Invalid secret".
240
+ - **PM2 Issues**: List processes: `pm2 list | grep code_agent`. Delete: `pm2 delete hello-dave_code_agent_8080`. Restart: `pm2 restart all`.
241
+ - **No Response in Chain**: Add logging to agents (e.g., `console.log` in handlers). Verify connections: `pm2 logs hello-dave_*_8080`.
242
+ - **Port Conflicts**: Change port in `codeserver.sh` call. Avoid <1024 ports.
243
+ - **WebSocket Errors**: Use `wscat` for testing: `npm install -g wscat; wscat -c ws://localhost:8080/ws` (manual auth may vary).
244
+ - **XAIKEY Missing**: For local `--ask`, set `export XAIKEY=sk-...`.
245
+ - **Version/Deps**: Ensure Node ≥18, `npm update`. Check agent scripts for flag support.
246
+
247
+ If networking needs extend beyond CodeServer (e.g., peer-to-peer), note in TODO.md for future enhancements. For now, this covers the project's real capabilities.
248
+
249
+ ## Related Documentation
250
+ - [Project README](../README.md) (CLI flags, setup).
251
+ - [Agent Scripts](../ (list individual agents like code_agent.js)).
252
+ - [PM2 Guide](https://pm2.keymetrics.io/docs/usage/quick-start/) (for cluster management).
253
+ - [WebSocket in Node.js](https://nodejs.org/api/websocket.html) (low-level details).