@j-o-r/hello-dave 0.0.4 → 0.0.6

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.
Files changed (107) hide show
  1. package/CHANGELOG.md +35 -17
  2. package/bin/dave.js +105 -74
  3. package/examples/gpt_agent.js +3 -6
  4. package/examples/memory_agent.js +134 -23
  5. package/examples/test_agent.js +0 -2
  6. package/lib/ToolSet.js +4 -1
  7. package/lib/genericToolset.js +4 -88
  8. package/lib/index.js +5 -1
  9. package/lib/wsIO.js +1 -11
  10. package/package.json +4 -4
  11. package/types/index.d.ts +3 -1
  12. package/README.md +0 -492
  13. package/README.md.backup +0 -269
  14. package/README.md.bak +0 -481
  15. package/README.md.bak.1774780058 +0 -338
  16. package/README.md.bak2 +0 -455
  17. package/docs.bak.1774780058/agent-manager.md +0 -167
  18. package/docs.bak.1774780058/agent-manager.md.bak +0 -137
  19. package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
  20. package/docs.bak.1774780058/codeserver-pattern.md +0 -191
  21. package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
  22. package/docs.bak.1774780058/project-overview.md +0 -67
  23. package/docs.bak.1774780058/project-overview.md.bak +0 -67
  24. package/docs.bak.1774780058/prompt-class.md +0 -141
  25. package/docs.bak.1774780058/prompt-class.md.bak +0 -142
  26. package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
  27. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
  28. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
  29. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
  30. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
  31. package/docs.bak.1774780058/toolset.md +0 -164
  32. package/docs.bak.1774780058/toolset.md.bak +0 -94
  33. package/docs.bak.1774780058/toolset.md.bak3 +0 -161
  34. package/docs.bak.1774780058/toolset.md.bak4 +0 -161
  35. package/docs.bak.1774780058/toolset.md.bak5 +0 -161
  36. package/docs.bak.1774780058/toolset.md.bak6 +0 -163
  37. package/docs.bak.1774780058/toolset.md.bak_path +0 -163
  38. package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
  39. package/docs.bak.1774780058/xai-responses.md +0 -111
  40. package/docs.bak.1774780058/xai-responses.md.bak +0 -107
  41. package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
  42. package/docs.bak.1774780058/xai_collections.md +0 -106
  43. package/examples/coderev_agent.js +0 -136
  44. package/examples/grok_agent.js.bak +0 -98
  45. package/examples/grok_agent.js.bak.2 +0 -99
  46. package/examples/grok_agent.js.bak.3 +0 -1
  47. package/examples/grok_agent.js.bak.4 +0 -124
  48. package/examples/grok_agent.js.bak.5 +0 -1
  49. package/examples/grok_agent.js.bak.6 +0 -1
  50. package/examples/npm_agent.js.bak.3 +0 -2
  51. package/examples/npm_agent.js.bak.4 +0 -205
  52. package/examples/npm_agent.js.bak.5 +0 -1
  53. package/examples/npm_agent.js.bak.6 +0 -1
  54. package/examples.bak.1774780058/ask_agent.js +0 -114
  55. package/examples.bak.1774780058/code_agent.js +0 -149
  56. package/examples.bak.1774780058/coderev_agent.js +0 -72
  57. package/examples.bak.1774780058/codeserver.sh +0 -47
  58. package/examples.bak.1774780058/daisy_agent.js +0 -177
  59. package/examples.bak.1774780058/docs_agent.js +0 -119
  60. package/examples.bak.1774780058/gpt_agent.js +0 -109
  61. package/examples.bak.1774780058/grok_agent.js +0 -98
  62. package/examples.bak.1774780058/memory_agent.js +0 -112
  63. package/examples.bak.1774780058/npm_agent.js +0 -175
  64. package/examples.bak.1774780058/prompt_agent.js +0 -112
  65. package/examples.bak.1774780058/readme_agent.js +0 -144
  66. package/examples.bak.1774780058/spawn_agent.js +0 -263
  67. package/examples.bak.1774780058/test_agent.js +0 -162
  68. package/examples.bak.1774780058/todo_agent.js +0 -138
  69. package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
  70. package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
  71. package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
  72. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
  73. package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
  74. package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
  75. package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
  76. package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
  77. package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
  78. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
  79. package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
  80. package/scenarios.bak.1774780058/environment.js +0 -10
  81. package/scenarios.bak.1774780058/example.js +0 -17
  82. package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
  83. package/scenarios.bak.1774780058/grok.js +0 -113
  84. package/scenarios.bak.1774780058/memory-tools.js +0 -51
  85. package/scenarios.bak.1774780058/openai-o3.js +0 -137
  86. package/scenarios.bak.1774780058/openai-prompt.js +0 -155
  87. package/scenarios.bak.1774780058/openai-session.js +0 -148
  88. package/scenarios.bak.1774780058/openai.js +0 -102
  89. package/scenarios.bak.1774780058/prompt.js +0 -118
  90. package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
  91. package/scenarios.bak.1774780058/search.brave.com.js +0 -25
  92. package/scenarios.bak.1774780058/sh.js +0 -15
  93. package/scenarios.bak.1774780058/test-wsio.js +0 -26
  94. package/scenarios.bak.1774780058/testToolset.js +0 -42
  95. package/scenarios.bak.1774780058/toolset.js +0 -16
  96. package/scenarios.bak.1774780058/toolset.test.js +0 -141
  97. package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
  98. package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
  99. package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
  100. package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
  101. package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
  102. package/scenarios.bak.1774780058/wsClient.js +0 -69
  103. package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
  104. package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
  105. package/scenarios.bak.1774780058/xaicoll.js +0 -50
  106. package/scenarios.bak.1774780058/xaifiles.js +0 -48
  107. /package/{examples → bin}/spawn_agent.js +0 -0
package/lib/index.js CHANGED
@@ -11,6 +11,8 @@ import AgentClient from './AgentClient.js';
11
11
  import Session from './Session.js';
12
12
  import Prompt from './Prompt.js';
13
13
  import Cli from './Cli.js';
14
+ import wsCli from '../lib/wsCli.js';
15
+ import wsIO from '../lib/wsIO.js';
14
16
 
15
17
  const API = {
16
18
  text:{
@@ -32,5 +34,7 @@ export {
32
34
  API,
33
35
  Cli,
34
36
  env,
35
- GLOBAL
37
+ GLOBAL,
38
+ wsCli,
39
+ wsIO
36
40
  };
package/lib/wsIO.js CHANGED
@@ -38,13 +38,6 @@ export default async function wsio(connectUrl, secret = '', action, input = '')
38
38
  const ws = new WebSocket(url);
39
39
 
40
40
  let resolved = false;
41
- const TIMEOUT_MS = 30000; // 30s timeout
42
- const timeoutId = setTimeout(() => {
43
- if (!resolved) {
44
- ws.close();
45
- reject(new Error('Request timeout (30s)'));
46
- }
47
- }, TIMEOUT_MS);
48
41
 
49
42
  const actionId = Date.now();
50
43
 
@@ -69,7 +62,6 @@ export default async function wsio(connectUrl, secret = '', action, input = '')
69
62
  try {
70
63
  const parsed = JSON.parse(data.toString());
71
64
  if (parsed.id === actionId) {
72
- clearTimeout(timeoutId);
73
65
  resolved = true;
74
66
  ws.close(1000, 'Request complete');
75
67
  resolve(parsed);
@@ -80,17 +72,15 @@ export default async function wsio(connectUrl, secret = '', action, input = '')
80
72
  });
81
73
 
82
74
  ws.on('close', (code, reason) => {
83
- clearTimeout(timeoutId);
84
75
  if (!resolved) {
85
76
  reject(new Error(`Connection closed (${code}): ${reason || 'Unknown reason'}`));
86
77
  }
87
78
  });
88
79
 
89
80
  ws.on('error', (error) => {
90
- clearTimeout(timeoutId);
91
81
  if (!resolved) {
92
82
  reject(new Error(`WebSocket error: ${error.message}`));
93
83
  }
94
84
  });
95
85
  });
96
- }
86
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@j-o-r/hello-dave",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "description": "ESM toolkit for building AI agents with unified access to Grok (XAI), OpenAI, and Anthropic endpoints",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./types/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "bin": {
16
16
  "dave": "bin/dave.js",
17
- "createAgent": "examples/spawn_agent.js"
17
+ "createAgent": "bin/spawn_agent.js"
18
18
  },
19
19
  "scripts": {
20
20
  "release": "npm run types && npm pack --pack-destination=release",
@@ -39,7 +39,7 @@
39
39
  "types": "./types/index.d.ts",
40
40
  "default": "./lib/index.js"
41
41
  },
42
- "./*": "lib/*.js"
42
+ "./lib/*": "./lib/*"
43
43
  },
44
44
  "author": "Jorrit Duin <j-o-r@duin.work>",
45
45
  "bugs": {
@@ -51,4 +51,4 @@
51
51
  "engines": {
52
52
  "node": ">=20"
53
53
  }
54
- }
54
+ }
package/types/index.d.ts CHANGED
@@ -17,8 +17,10 @@ export namespace API {
17
17
  import Cli from './Cli.js';
18
18
  import { env } from './fafs.js';
19
19
  import { GLOBAL } from './fafs.js';
20
+ import wsCli from '../lib/wsCli.js';
21
+ import wsIO from '../lib/wsIO.js';
20
22
  import { request as gpt } from './API/openai.com/reponses/text.js';
21
23
  import { request as xai } from './API/x.ai/responses.js';
22
24
  import { request as claude } from './API/anthropic.com/text.js';
23
25
  import { request as brave } from './API/brave.com/search.js';
24
- export { AgentManager, AgentServer, AgentClient, Prompt, ToolSet, Session, Cli, env, GLOBAL };
26
+ export { AgentManager, AgentServer, AgentClient, Prompt, ToolSet, Session, Cli, env, GLOBAL, wsCli, wsIO };
package/README.md DELETED
@@ -1,492 +0,0 @@
1
- # Updated README.md with enhanced Changelog for v0.0.4 prep
2
-
3
- # @j-o-r/hello-dave
4
-
5
- [![npm version](https://badge.fury.io/js/%40j-o-r%2Fhello-dave.svg)](https://www.npmjs.com/package/%40j-o-r%2Fhello-dave)
6
- [![Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7
- [![Node.js >=20](https://img.shields.io/badge/Node.js-%3E=20-green.svg)](https://nodejs.org/)
8
-
9
- ## Table of Contents
10
-
11
- - [Description](#description)
12
- - [Features](#features)
13
- - [Installation](#installation)
14
- - [Quick Start](#quick-start)
15
- - [Usage](#usage)
16
- - [Startup Modes](#startup-modes)
17
- - [Examples](#examples)
18
- - [Development](#development)
19
- - [Changelog](#changelog)
20
- - [Contributing](#contributing)
21
- - [License](#license)
22
- - [TODO Alignment](#todo-alignment)
23
-
24
- ## Description
25
-
26
- **@j-o-r/hello-dave** is a lightweight, ESM-only Node.js framework for building intelligent AI agents powered by large language models (LLMs) such as xAI Grok, Anthropic Claude, or OpenAI GPT. It simplifies the creation of custom agents with features like the central `AgentManager` class, WebSocket-based client/server support for networked agents, seamless tool integration (e.g., bash execution, web search), customizable system prompts, and robust session management supporting large context windows (up to millions of tokens).
27
-
28
- The framework emphasizes ease of use, allowing developers and non-experts alike to rapidly prototype and deploy specialized agents. Core integrations include unified xAI Grok API access, WebSocket (WS) networking with secret-based authentication, and direct CLI/cron messaging (no heartbeat/ping mechanism required). Example scripts like `readmeDave`, `todoDave`, and others have been reorganized into the `examples/` folder for clarity.
29
-
30
- Whether you're building a code reviewer, a research assistant, or a creative collaborator, `@j-o-r/hello-dave` abstracts away API complexities, providing a unified interface across providers. It's alpha-stage but production-ready for personal projects, with persistence for sessions and logs in NDJSON format.
31
-
32
- ## Features
33
-
34
- - **Unified LLM Access**: Seamless integration with xAI Grok API, Anthropic Claude, and OpenAI GPT via a single API.
35
- - **AgentManager Class**: Core orchestrator for prompts, tools, sessions, and interactions (CLI, direct calls, WebSocket).
36
- - **Tool Integration**: Built-in tools for bash scripting, web search, JavaScript execution, and more; easily extensible.
37
- - **WebSocket Networking with Secrets**: Agents can act as servers or clients with optional secret authentication, enabling secure distributed agent networks across machines.
38
- - **Direct CLI/Cron Messaging**: Simplified interactions without needing heartbeat mechanisms—ideal for scheduled tasks.
39
- - **Customizable Prompts**: Tailor agent behavior with system prompts for specialized tasks (e.g., music production, code analysis).
40
- - **Session Management**: Persistent conversations with large context windows; automatic truncation and history search.
41
- - **CLI Utilities**: Core tool at `bin/dave.js` for cache management, WS connections, and interactive queries; plus agent generator.
42
- - **Lightweight & TypeScript-Friendly**: ESM-only, no heavy deps; full types included.
43
- - **Memory Tools**: Generic tools `memory_recall` and `memory_write` for persisting and recalling tasks, errors, and preferences in `.cache/memory.ndjson`, optimizing loops and long-running agent sessions (available in `toolsetMode: 'auto').
44
-
45
- ## Installation
46
-
47
- Install as a dependency in your Node.js project (requires Node.js >= 20 with `"type": "module"` in `package.json`):
48
-
49
- ```bash
50
- npm install @j-o-r/hello-dave
51
- ```
52
-
53
- For global access to CLI tools (including `dave` from `bin/dave.js`):
54
-
55
- ```bash
56
- npm install -g @j-o-r/hello-dave
57
- ```
58
-
59
- Set your API keys via environment variables (only set what you need):
60
- - `XAIKEY` for xAI Grok
61
- - `ANTHKEY` for Anthropic Claude
62
- - `OPENAIKEY` for OpenAI GPT
63
- - `BRAVESEARCHKEY` for web search (optional)
64
-
65
- Create a cache directory for sessions:
66
- ```bash
67
- mkdir .cache
68
- ```
69
-
70
- ## Quick Start
71
-
72
- 1. Set an API key (e.g., for Grok):
73
- ```bash
74
- export XAIKEY=your_xai_api_key
75
- ```
76
-
77
- 2. Use the core CLI utility `bin/dave.js` (not a full agent) for interactive queries or management:
78
- ```bash
79
- npx @j-o-r/hello-dave dave --ask
80
- ```
81
- - Launches an interactive agent session using default Grok tools. Use `Alt+d` to exit, `Alt+r` to reset.
82
- - Example: Ask questions about anything; it uses xAI Grok by default with web search and X search tools.
83
-
84
- 3. For one-shot queries via piped input:
85
- ```bash
86
- echo "Explain quantum computing" | npx @j-o-r/hello-dave dave --ask --model grok-4
87
- ```
88
- - Provides a direct response using the specified model (e.g., `--model grok-4`).
89
-
90
- 4. Connect to a WebSocket server using the CLI utility (for UI access to servers):
91
- ```bash
92
- Utility: npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret your_secret
93
- ```
94
-
95
- 5. Generate a custom agent using the portable `spawn_agent` tool (CLI/WS agents + CodeServer launchers):
96
- ```bash
97
- npx @j-o-r/hello-dave spawn_agent
98
- ```
99
- - Interactive: Follow prompts to create a new agent script in `bin/` (e.g., `bin/myagent.js`).
100
- - Portable to any project (auto-installs deps like `@j-o-r/hello-dave`):
101
- ```bash
102
- npx @j-o-r/hello-dave spawn_agent --cwd ~/my-project
103
- ```
104
- - Supports one-shot: `echo "Create code-review agent" | npx @j-o-r/hello-dave spawn_agent --cwd ~/proj`.
105
- - Aligns with CodeServer pattern for multi-agent setups (see Usage/Examples).
106
-
107
- `bin/dave.js` also supports cache operations like `--list` (list sessions), `--search "query"`, `--clear`, and `--inspect path/to/log.ndjson`.
108
-
109
- ## Usage
110
-
111
- ### Core CLI Utility via `bin/dave.js` (Not a Full Agent)
112
-
113
- `bin/dave.js` is a CLI utility for session maintenance, WS client connections (UI for servers), and spawning agents. It does NOT support custom prompts/tools or server mode (--serve). For full agents with customization, use examples like `npm_agent.js` or programmatic `AgentManager`. Key functions:
114
-
115
- - **Ask Mode** (Interactive or Piped One-Shot, using default Grok agent):
116
- ```bash
117
- # Interactive
118
- npx @j-o-r/hello-dave dave --ask --model grok-4 --temperature 0.2
119
-
120
- # Piped one-shot
121
- echo "What is quantum computing?" | npx @j-o-r/hello-dave dave --ask --model grok-4
122
- ```
123
- - Note: Piped input triggers a direct response via `directCall`; without pipe, it launches an interactive CLI session.
124
- - `--model` option works for both modes (e.g., `grok-4`, `grok-4-1-fast-reasoning`).
125
- - Uses default `AgentManager` with xAI Grok API integration, adds tools like `web_search`, `x_search`, `open_link`, `send_email`, `history_search`.
126
- - System prompt emphasizes brief, direct responses with step-by-step reasoning.
127
-
128
- - **SpawnDave Mode** (Portable Agent Creator with --cwd Support):
129
- ```bash
130
- # Interactive in current project
131
- npx @j-o-r/hello-dave spawn_agent --model grok-4-fast-reasoning --temperature 0.7
132
-
133
- # Portable to another project (switches cwd, auto-deps)
134
- npx @j-o-r/hello-dave spawn_agent --cwd ../other-proj
135
-
136
- # One-shot for quick generation
137
- echo "name=coderev desc=Git diff analyzer tools=read_file execute_bash_script web_search" | npx @j-o-r/hello-dave spawn_agent --cwd ~/my-proj
138
- ```
139
- - Creates production-ready CLI/WS agents (`bin/<name>.js`) supporting CLI, server (`--serve`), client (`--connect`), and hybrid modes.
140
- - Generates multi-agent CodeServer launchers (`examples/<Name>Server`) using PM2 for persistent networked setups (main server + sub-agents).
141
- - **Portable**: Runs via `npx` anywhere—no local install needed. Auto-inspects project, installs `@j-o-r/hello-dave @j-o-r/sh` if missing, validates ESM code (`node --check`), tests deployment.
142
- - Aligns with CodeServer pattern: Self-contained Bash launchers for PM2-managed multi-agents (e.g., code review + TODO + NPM agents).
143
- - Requires `XAIKEY`; uses online repo docs (https://codeberg.org/duin/hello-dave) for portability.
144
- - Example output: Deploys `bin/coderev_agent.js`, tests it, provides server/client usage guide.
145
-
146
- - **WebSocket Client Mode** (Utility UI for connecting to servers, with secrets for secure networking):
147
- ```bash
148
- # Interactive connection
149
- Utility: npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
150
-
151
- # Piped one-shot (direct CLI/cron messaging, no heartbeat needed)
152
- echo "Predict the weather" | npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
153
- echo "user_reset" | npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
154
- ```
155
-
156
- - **Cache Management** (Session maintenance in .cache):
157
- ```bash
158
- npx @j-o-r/hello-dave dave --list # List sessions
159
- npx @j-o-r/hello-dave dave --search "AI agents" # Search history
160
- npx @j-o-r/hello-dave dave --clear # Clear cache
161
- npx @j-o-r/hello-dave dave --inspect path/to/log.ndjson # Inspect log
162
- ```
163
-
164
- For custom full agents (with prompts/tools/server support), use `AgentManager` programmatically (see Examples) or scripts like `examples/npm_agent.js`.
165
-
166
- ### Programmatic Usage with AgentManager (For Full Agents)
167
-
168
- ```javascript
169
- import AgentManager from '@j-o-r/hello-dave';
170
-
171
- const agent = new AgentManager({ name: 'MyAgent', secret: 'optional_secret' });
172
- agent.setup({
173
- prompt: 'You are a helpful assistant...',
174
- api: 'xai', // Uses unified xAI Grok API access
175
- options: { model: 'grok-4', temperature: 0.7, tools: [{ type: 'web_search' }] },
176
- toolsetMode: 'auto',
177
- contextWindow: 500000
178
- });
179
-
180
- agent.addGenericToolcall('execute_bash_script'); // Post-setup generics
181
- agent.addGenericToolcall('read_file');
182
- agent.addGenericToolcall('write_file');
183
- agent.addGenericToolcall('memory_recall'); // Persist/recall tasks, errors, prefs in .cache/memory.ndjson
184
- agent.addGenericToolcall('memory_write'); // Optimizes loops and long-running sessions
185
-
186
- await agent.start(); // Interactive CLI
187
- // Or: await agent.start(undefined, 8000, undefined, 'Intro', 'toolName', 'desc'); // WS server
188
- // Or: const response = await agent.directCall('Query'); // One-shot
189
- ```
190
-
191
- Direct CLI/cron: Pipe inputs to custom scripts for non-interactive use. WS supports secrets for authentication; no heartbeat required due to event-driven messaging.
192
-
193
- The `memory_recall` and `memory_write` tools, available when `toolsetMode: 'auto'`, enable agents to persist and recall tasks, errors, and preferences in `.cache/memory.ndjson`. This optimizes iterative loops and long-running sessions by maintaining state across interactions without relying solely on session history.
194
-
195
- ## Startup Modes
196
-
197
- This section unifies the startup modes for full agents (e.g., `examples/npm_agent.js`) and the programmatic `AgentManager.start(serve, connect, cliIntro, tool_call_name, tool_call_description)`. These modes are standardized across agents generated by `spawn_agent` and align with the [AgentManager docs](docs/agent-manager.md). The CLI utility `bin/dave.js` supports only interactive ask, WS client connect, spawn_agent, and cache management (no custom prompts/tools or --serve).
198
-
199
- All modes are cron-friendly with no heartbeat/ping required—agents respond directly to event-driven inputs. In WS modes (--serve, --connect, hybrid), positional arguments are ignored; use interactive CLI or piped inputs for messaging. Agent names and tool names must follow the strict lowercase naming rules: `/^[a-z_0-9_]{2,}$/` (no uppercase, hyphens, or specials) for filesystem/tool safety—see [AgentManager docs](docs/agent-manager.md).
200
-
201
- ### AgentManager.start() Options Explained
202
- The `start()` method is the smart launcher for all modes. It accepts up to 5 arguments in order:
203
- - `serve` (number | undefined): Port for WS **server** mode (e.g., 8080). Exposes the agent as a remote tool via `ws://127.0.0.1:[port]/ws`. Requires `--secret` for client authentication. Runs indefinitely until Ctrl+C. See [AgentManager docs](docs/agent-manager.md) for server config.
204
- - `connect` (string | undefined): WS URL for **client** mode (e.g., `ws://127.0.0.1:8080/ws`). Connects to a remote server to gain access to its tools. Launches interactive CLI after connection.
205
- - `cliIntro` (string | undefined): Custom welcome message for interactive CLI mode (e.g., "NPM Agent ready. Ask about modules.").
206
- - `tool_call_name` (string | undefined): **Required for server mode**. The tool name this agent exposes (must match naming regex `/^[a-z_0-9_]{2,}$/`). E.g., `npm_module_inspector`. Used when clients attach.
207
- - `tool_call_description` (string | undefined): **Required for server mode**. Detailed description of the exposed tool (e.g., "Inspects NPM modules in node_modules/ using bash and cache.").
208
-
209
- **Mode Determination**:
210
- - If `serve` provided: Starts WS server (exposes tools).
211
- - If `connect` provided: Starts WS client (attaches to remote, gains tools).
212
- - If both: Hybrid mode (serves locally while using remote tools).
213
- - If neither: Interactive CLI mode.
214
- - For one-shot (non-start): Use `directCall(input)` directly (positional arg in scripts).
215
-
216
- **Shared Notes**:
217
- - `--secret [string]` (min 3 chars): Shared auth token. Servers reject mismatched clients; use the same for chains/networks.
218
- - Other options: `--model [grok-4-fast-reasoning|...]`, `--temperature [-2 to +2]`, `--tokens`, `--top_p`, `--context [250000]`.
219
- - Positional args ignored in WS modes (use CLI/pipes instead).
220
- - No heartbeat: Event-driven responses.
221
- - For multi-agent chaining, see [CodeServer pattern](docs/codeserver-pattern.md).
222
-
223
- ### 1. Direct Call (One-Shot, Positional Arg Only)
224
- For single responses via positional query. Ideal for scripts/cron jobs. Bypasses CLI/WS; uses `agent.directCall(input)`. (Not available in `dave` utility for custom agents; use full agents or `--ask` for defaults.)
225
-
226
- **CLI Example (Full Agent, e.g., npm_agent.js)**:
227
- ```bash
228
- ./examples/npm_agent.js "What modules are installed?" [--model grok-4]
229
- ```
230
- - Input: Positional string (trimmed). If empty/missing, falls to interactive CLI or help.
231
-
232
- **Programmatic (AgentManager)**:
233
- ```javascript
234
- import { AgentManager } from '@j-o-r/hello-dave' ;
235
- const agent = new AgentManager({ name: 'npm_agent' });
236
- await agent.setup({ /* prompt, api, options, toolsetMode, contextWindow */ });
237
- const response = await agent.directCall('What modules are installed?' );
238
- console.log(response);
239
- ```
240
- - Pair with `readIn()` from `@j-o-r/sh` for piped stdin detection in scripts (e.g., `echo "query" | script.js`).
241
-
242
- **Utility (dave.js for Default Queries)**:
243
- ```bash
244
- echo "Explain quantum computing" | npx @j-o-r/hello-dave dave --ask [--model grok-4]
245
- ```
246
- - Triggers `directCall` on piped input.
247
-
248
- ### 2. Interactive CLI (No Positional Arg)
249
- Launches ongoing conversation session with REPL-like input (multi-turn, until Ctrl+C or `Alt+d`).
250
-
251
- **CLI Example (Full Agent)**:
252
- ```bash
253
- ./examples/npm_agent.js [--model grok-4]
254
- ```
255
- - No positional: Starts `agent.start()` with CLI intro.
256
-
257
- **Programmatic**:
258
- ```javascript
259
- await agent.start(undefined, undefined, 'NPM Agent ready. Ask about modules or tools.' ); // Interactive CLI with custom intro
260
- ```
261
- - Uses `cliIntro` for welcome message. Supports history, reset (`Alt+r`).
262
-
263
- **Utility (dave.js)**:
264
- ```bash
265
- npx @j-o-r/hello-dave dave --ask
266
- ```
267
- - Default agent; no custom tools/prompts.
268
-
269
- ### 3. WS Server (--serve [port])
270
- Starts a WebSocket server at `ws://127.0.0.1:[port]/ws` to expose the agent as a remote tool for clients. Runs indefinitely. (Not supported in `dave` utility.)
271
-
272
- **CLI Example (Full Agent)**:
273
- ```bash
274
- ./examples/npm_agent.js --serve 8080 [--secret mysecret] [--model grok-4]
275
- ```
276
- - Exposes `tool_call_name` (e.g., `npm_module_inspector`) for remote calls.
277
-
278
- **Programmatic**:
279
- ```javascript
280
- await agent.start(8080, undefined, undefined, 'npm_module_inspector' , 'NPM modules expert using bash and cache in node_modules/.' ); // Server on 8080; secret optional but recommended
281
- ```
282
- - `tool_call_name` and `tool_call_description` required for exposure. See [AgentManager docs](docs/agent-manager.md) for full server config, including reset propagation.
283
-
284
- **Client Usage** (Connect to this server):
285
- ```bash
286
- # Interactive
287
- npx @j-o-r/hello-dave dave --connect ws://127.0.0.1:8080 --secret mysecret
288
- # Or full agent: ./examples/other_agent.js --connect ws://127.0.0.1:8080 --secret mysecret
289
- ```
290
- - Clients gain the server's tools (e.g., call `npm_module_inspector` in their prompts).
291
-
292
- ### 4. WS Client (--connect [ws_url])
293
- Connects to a remote WS server as a client, gaining access to its tools, then launches interactive CLI.
294
-
295
- **CLI Example (Full Agent)**:
296
- ```bash
297
- ./examples/npm_agent.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--model grok-4]
298
- ```
299
- - Attaches to server; uses remote tools in local sessions.
300
-
301
- **Programmatic**:
302
- ```javascript
303
- await agent.start(undefined, 'ws://127.0.0.1:8080/ws' , undefined, undefined, undefined ); // Client mode; secret required if server uses one
304
- ```
305
- - After connection, interactive CLI starts. For one-shot: Pipe to script (uses `directCall` with remote tools).
306
-
307
- **Utility (dave.js)**:
308
- ```bash
309
- # Interactive
310
- npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
311
- # Piped one-shot (cron-friendly)
312
- echo "Use remote NPM tool to list modules" | npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
313
- ```
314
-
315
- ### 5. Hybrid (--serve [port] + --connect [ws_url])
316
- Serves tools locally (on local port) while connecting as a client to a remote server (gains remote tools). No positional arg; launches interactive CLI. Ideal for agent chains/networks. (Not supported in `dave` utility.)
317
-
318
- **CLI Example (Full Agent)**:
319
- ```bash
320
- ./examples/npm_agent.js --serve 8081 --connect ws://otherhost:8080/ws [--secret mysecret]
321
- ```
322
- - Local server on 8081 (exposes local tools); client to remote (uses remote tools).
323
-
324
- **Programmatic**:
325
- ```javascript
326
- await agent.start(8081, 'ws://otherhost:8080/ws' , 'Hybrid NPM Agent ready.' , 'npm_module_inspector' , 'Hybrid NPM inspector with remote access.' ); // Hybrid; secret for both if needed
327
- ```
328
- - Custom handling for secrets (use same or per-mode). See [AgentManager docs](docs/agent-manager.md) for hybrid details and error handling.
329
-
330
- **Notes**: Positional args ignored. Use for distributed setups (e.g., NPM agent serves locally but uses a code agent's tools remotely). Monitor with tools like `netstat` or PM2 in CodeServer.
331
-
332
- This section completes the unified documentation for startup modes, aligned with `npm_agent.js` help output and `AgentManager` API. For more, see [docs/agent-manager.md](docs/agent-manager.md) and [examples/](examples/).
333
-
334
- ## Examples
335
-
336
- Example scripts (e.g., `readme_agent.js` for README management, `todo_agent.js` for task handling, `spawn_agent.js` for agent creation) are now organized in the `examples/` folder. These demonstrate specialized full agents using `AgentManager`, xAI Grok API integration, and tools. **Note**: Agent names and filenames follow lowercase naming rules per [docs/agent-manager.md](docs/agent-manager.md) (regex `/^[a-z_0-9_]{2,}$/` for safety in folders, tools, and filesystems—no uppercase, hyphens, or specials).
337
-
338
- - **Link to Examples Folder**: Explore [examples/](examples/) for full scripts like `daisy_agent.js` (music agent), `code_agent.js` (code review), `npm_agent.js` (NPM inspector).
339
-
340
- In custom agents, consider adding `memory_recall` and `memory_write` tools to enable state persistence for complex workflows, such as tracking progress in multi-step tasks or storing user preferences across sessions.
341
-
342
- ### Persistent Multi-Agent CodeServer Pattern
343
-
344
- The `examples/CodeServer` script provides a persistent multi-agent setup using PM2 to manage long-running processes. It starts a main code agent as a WebSocket server on a specified port, with sub-agents (for TODO, README, NPM, and docs tasks) attached as clients. This pattern enables a networked ecosystem of specialized agents that maintain state across sessions, ideal for extended development workflows where context persistence and task delegation are key.
345
-
346
- Benefits include seamless integration for dev sessions—agents stay online, handling queries via WS without restarts, supporting large context windows and tool calls. For full details, see [docs/codeserver-pattern.md](docs/codeserver-pattern.md).
347
-
348
- **Usage:**
349
-
350
- ```bash
351
- # Start the CodeServer (requires PM2: npm i -g pm2)
352
- ./examples/CodeServer 8080 mysecret
353
-
354
- # Connect via CLI utility (interactive or piped)
355
- Utility: npx @j-o-r/hello-dave dave --connect ws://127.0.0.1:8080/ws --secret mysecret
356
- # Or for one-shot: echo "Review this code" | npx @j-o-r/hello-dave dave --connect ws://127.0.0.1:8080/ws --secret mysecret
357
- ```
358
-
359
- Monitor with `pm2 list` and stop via `pm2 delete <name>`.
360
-
361
- ### Snippet: Spawning Agents (Portable via `bin/dave.js` --spawn_agent)
362
-
363
- `spawn_agent` uses `AgentManager` to interactively generate new agent scripts, now fully aware of WebSocket server/client modes and the CodeServer multi-agent pattern for networked setups.
364
-
365
- Now CodeServer-aware: Can generate PM2 multi-agent launchers (e.g., 'Generate CodeServer for coderev + todo'). See updated [examples/spawn_agent.js](examples/spawn_agent.js) and [docs/codeserver-pattern.md](docs/codeserver-pattern.md).
366
-
367
- **Portable**: `spawn_agent` is fully portable—no local docs/examples needed. Uses online repo links (https://codeberg.org/duin/hello-dave). Works in any project via `npx` (auto-deps with `--cwd`).
368
-
369
- ```javascript
370
- // Core setup in spawn_agent
371
- const agent = new AgentManager({ name: 'spawn_agent', secret });
372
- agent.setup({
373
- prompt: 'You are AgentCreator... [detailed prompt for portability, validation]',
374
- api: 'xai',
375
- options: { model: 'grok-4-fast-reasoning', tools: [{ type: 'web_search' }], reasoning: { effort: 'high' } },
376
- toolsetMode: 'auto',
377
- contextWindow: 500000
378
- });
379
- agent.addGenericToolcall('execute_bash_script'); // For project inspection
380
- agent.addGenericToolcall('read_file');
381
- agent.addGenericToolcall('write_file'); // For generating bin/ scripts
382
- agent.addGenericToolcall('memory_recall'); // For recalling previous generations or prefs
383
- agent.addGenericToolcall('memory_write'); // For persisting agent configs or errors
384
-
385
- await agent.start(); // Guides user to create e.g., bin/myagent.js
386
- ```
387
-
388
- - Validates generated ESM code with `node --check` and tool rules (xAI natives pre-setup, generics post-setup).
389
- - Ensures absolute imports for portability.
390
-
391
- **Example Usage:**
392
-
393
- ```bash
394
- # Interactive spawning (runs from npm without cloning; current dir)
395
- npx @j-o-r/hello-dave spawn_agent
396
-
397
- # Portable to specific project (auto-switches cwd, installs deps if needed)
398
- npx @j-o-r/hello-dave spawn_agent --cwd ~/my-proj
399
-
400
- # Piped one-shot for CodeServer launcher (portable, no cloning)
401
- echo "Generate CodeServer launcher for coderev + tododave" | npx @j-o-r/hello-dave spawn_agent --cwd ~/proj
402
- ```
403
-
404
- ### Snippet: Using xAI Grok API Integration
405
-
406
- The unified xAI Grok API access supports options like reasoning and tools:
407
-
408
- ```javascript
409
- // In AgentManager setup
410
- const options = {
411
- model: 'grok-4-1-fast-reasoning',
412
- temperature: 0.8,
413
- tools: [{ type: 'web_search' }, { type: 'x_search', from_date: '2024-01-01' }], // Native xAI tools
414
- reasoning: { effort: 'medium', summary: 'auto' } // Chain-of-thought support
415
- };
416
- ```
417
-
418
- Detailed examples for xAI integration (e.g., advanced tool calls, reasoning) are planned (see TODO).
419
-
420
- ### Running Examples
421
-
422
- ```bash
423
- # Music agent (examples/daisy_agent.js - full agent)
424
- chmod +x examples/daisy_agent.js
425
- ./examples/daisy_agent.js "Generate lyrics for a pop song"
426
-
427
- # TODO manager (examples/todo_agent.js - full agent)
428
- ./examples/todo_agent.js --connect ws://localhost:8080 --secret "secret"
429
-
430
- # Server setup for networked examples (use full agents, not dave utility)
431
- ./examples/npm_agent.js --serve 8080 # Expose as WS server
432
- ```
433
-
434
- ## Development
435
-
436
- - **Scripts**: `npm test` (runs scenarios/grok_agent.js), `npm run types` (generate TypeScript defs), `npm run release` (pack for release).
437
- - **Structure**: Core in `lib/` (AgentManager.js, wsCli.js, etc.), API integrations in `lib/API/`, examples in `examples/`, utils in `utils/`.
438
- - **Testing**: Basic validation via `npm test`. Unit tests for xAI integration planned (see TODO).
439
- - **Prep for v0.0.4**: Focus on spawn_agent enhancements and release testing.
440
-
441
- ## Changelog
442
-
443
- ### v0.0.4 (Upcoming - April 2026)
444
- - **Release Preparation Complete**: Updated package.json to version "0.0.4" (pending final commit/tag). Full test suite passed 100% (no regressions in genericToolset.test.js or other scenarios). Types generated and verified.
445
- - **Agent Standardization**: All 12 example agents (e.g., code_agent.js, readme_agent.js, test_agent.js) now follow unified npm_agent.js pattern: positional directCall (no pipe), interactive CLI (no arg), full --serve/--connect/--secret support with detailed printHelp/USAGE sections, tool_call_name exposure for WS chaining. Syntax validated across all.
446
- - **Prompt Safeguards**: Added STRICT NO-CODING RULE to non-coding agents (e.g., todo_agent.js, readme_agent.js, docs_agent.js, prompt_agent.js) to prevent misuse of tools like execute_code, write_file, syntax_check. Matches todo_agent.js style; verified no regressions.
447
- - **Memory Protocol Enhancements**: Updated prompts (e.g., spawn_agent.js, test_agent.js) to mandate memory_recall/write FIRST/LAST for tasks/errors/prefs/decisions, reducing token burn and enabling human handoff. Integrated into workflows for iterative testing and agent generation.
448
- - **File Renames and Cleanup**: Renamed all examples/ files to *_agent.js (e.g., codedave.js → code_agent.js); updated references in README.md, docs/, TODO.md, package.json. Removed all old "Dave/dave" references (grep -r confirmed zero remnants).
449
- - **NPM Agent Improvements**: Enhanced prompt with Dependency Strategy (prefer installed modules/native JS/Bash, suggest new deps only as last resort). Added full npm ls -a scanning for subdeps; strict no-installs policy. Vague query handling improved (e.g., auto-cache for tests).
450
- - **Startup Modes Documentation**: Finalized "## Startup Modes" section in README.md with 5 unified modes (Direct Call, CLI, Server, Client, Hybrid), AgentManager.start() explanations, CLI/programmatic examples, and links to docs/agent-manager.md. Aligned with all agent help outputs.
451
- - **Test Agent Enhancements**: test_agent.js standardized; prompt updated for Test class usage in scenarios/*.test.js (e.g., toolset.test.js generation/validation). Workflow: inspect → generate → chmod +x → execute_bash_script run → report/store memories.
452
- - **WS Client Refinements**: lib/wsCli.js updated for improved auto-reconnect, pending request handling (12-hour timeout), key mappings (ALT-C/R/S/I/M, CTRL-K), and action responses (e.g., server_reset, sessionlist). Clipboard copy via xclip; better error logging.
453
- - **TODO Alignment**: High-priority items cleared (e.g., explain startup modes, agent standardization, prompt updates). No high-priority pending; project reviewed stable as of April 02, 2026.
454
- - **Other**: Reorganized examples/ folder; enhanced spawn_agent portability (npx --cwd, auto-deps, online repo awareness). Git ahead by 1 commit (cleanup toolset test); ready for v0.0.4 tag/publish.
455
-
456
- ### v0.0.3 (Previous - March 2026)
457
- - Initial WS secrets, generic tools, AgentManager refinements.
458
- - Reorganized examples to `examples/` folder (readmeDave, todoDave, etc.).
459
- - Enhanced `bin/dave.js` for core utilities: spawning, WS with secrets, direct messaging.
460
- - Improved xAI Grok API integration; added native tools/reasoning support.
461
- - Removed heartbeat needs; direct CLI/cron support.
462
- - Added piped one-shot support to dave --ask.
463
-
464
- Full history in git tags (recent: cleanup toolset test, TODO status update, fixed test/README, syntax fixes, startup modes explanation).
465
-
466
- ## Contributing
467
-
468
- Contributions are welcome! Fork the repo at [https://codeberg.org/duin/hello-dave](https://codeberg.org/duin/hello-dave), create a feature branch, and submit a pull request.
469
-
470
- 1. Install deps: `npm install`
471
- 2. Self dep `npm run link-self`
472
- 3. Run tests: `npm test`
473
- 4. Generate types: `npm run types`
474
- 5. Report issues: [https://codeberg.org/duin/hello-dave/issues](https://codeberg.org/duin/hello-dave/issues)
475
-
476
- Follow the [Code of Conduct](CODE_OF_CONDUCT.md) and Apache-2.0 license.
477
-
478
- ## License
479
-
480
- Apache License 2.0. See [LICENSE](LICENSE) for details.
481
-
482
- ## TODO Alignment
483
-
484
- This README aligns with high-priority items from [TODO.md](TODO.md):
485
- - **v0.0.4 Prep**: Changelog updated with recent completions; release steps emphasized (version bump, tests, types, commit/tag, publish).
486
- - **spawn_agent Enhancements**: Highlighted in Examples with portability and CodeServer awareness.
487
- - **Agent Standardization and Safeguards**: Integrated into Changelog and Usage notes.
488
- - xAI integration tests/examples: Deferred to post-v0.0.4 (future enhancements).
489
- - Documentation tasks (e.g., AgentManager internals, WS refinements) completed in Usage/Examples/Changelog.
490
- - **Status**: No high-priority pending; all tests stable. Focus shifted to release and future features like xAI files.js integration.
491
-
492
- For full TODO, see [TODO.md](TODO.md).