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

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 (161) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +445 -160
  3. package/README.md.backup +269 -0
  4. package/README.md.bak +481 -0
  5. package/README.md.bak.1774780058 +338 -0
  6. package/README.md.bak2 +455 -0
  7. package/bin/dave.js +165 -0
  8. package/docs.bak.1774780058/agent-manager.md +167 -0
  9. package/docs.bak.1774780058/agent-manager.md.bak +137 -0
  10. package/docs.bak.1774780058/agent-manager.md.bak2 +157 -0
  11. package/docs.bak.1774780058/codeserver-pattern.md +191 -0
  12. package/docs.bak.1774780058/path-resolution-best-practices.md +104 -0
  13. package/docs.bak.1774780058/project-overview.md +67 -0
  14. package/docs.bak.1774780058/project-overview.md.bak +67 -0
  15. package/docs.bak.1774780058/prompt-class.md +141 -0
  16. package/docs.bak.1774780058/prompt-class.md.bak +142 -0
  17. package/docs.bak.1774780058/tools-syntax-validation.md +121 -0
  18. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +125 -0
  19. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +125 -0
  20. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +106 -0
  21. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +106 -0
  22. package/docs.bak.1774780058/toolset.md +164 -0
  23. package/docs.bak.1774780058/toolset.md.bak +94 -0
  24. package/docs.bak.1774780058/toolset.md.bak3 +161 -0
  25. package/docs.bak.1774780058/toolset.md.bak4 +161 -0
  26. package/docs.bak.1774780058/toolset.md.bak5 +161 -0
  27. package/docs.bak.1774780058/toolset.md.bak6 +163 -0
  28. package/docs.bak.1774780058/toolset.md.bak_path +163 -0
  29. package/docs.bak.1774780058/toolset.md.bak_syntax +161 -0
  30. package/docs.bak.1774780058/xai-responses.md +111 -0
  31. package/docs.bak.1774780058/xai-responses.md.bak +107 -0
  32. package/docs.bak.1774780058/xai-responses.md.bak2 +107 -0
  33. package/docs.bak.1774780058/xai_collections.md +106 -0
  34. package/examples/ask_agent.js +137 -0
  35. package/examples/code_agent.js +149 -0
  36. package/examples/coderev_agent.js +136 -0
  37. package/examples/codeserver.sh +47 -0
  38. package/examples/daisy_agent.js +170 -0
  39. package/examples/docs_agent.js +148 -0
  40. package/examples/gpt_agent.js +125 -0
  41. package/examples/grok_agent.js +132 -0
  42. package/examples/grok_agent.js.bak +98 -0
  43. package/examples/grok_agent.js.bak.2 +99 -0
  44. package/examples/grok_agent.js.bak.3 +1 -0
  45. package/examples/grok_agent.js.bak.4 +124 -0
  46. package/examples/grok_agent.js.bak.5 +1 -0
  47. package/examples/grok_agent.js.bak.6 +1 -0
  48. package/examples/memory_agent.js +152 -0
  49. package/examples/npm_agent.js +202 -0
  50. package/examples/npm_agent.js.bak.3 +2 -0
  51. package/examples/npm_agent.js.bak.4 +205 -0
  52. package/examples/npm_agent.js.bak.5 +1 -0
  53. package/examples/npm_agent.js.bak.6 +1 -0
  54. package/examples/prompt_agent.js +133 -0
  55. package/examples/readme_agent.js +148 -0
  56. package/examples/spawn_agent.js +293 -0
  57. package/examples/test_agent.js +187 -0
  58. package/examples/todo_agent.js +175 -0
  59. package/examples.bak.1774780058/ask_agent.js +114 -0
  60. package/examples.bak.1774780058/code_agent.js +149 -0
  61. package/examples.bak.1774780058/coderev_agent.js +72 -0
  62. package/examples.bak.1774780058/codeserver.sh +47 -0
  63. package/examples.bak.1774780058/daisy_agent.js +177 -0
  64. package/examples.bak.1774780058/docs_agent.js +119 -0
  65. package/{bin/hdAsk.js → examples.bak.1774780058/gpt_agent.js} +46 -40
  66. package/examples.bak.1774780058/grok_agent.js +98 -0
  67. package/examples.bak.1774780058/memory_agent.js +112 -0
  68. package/examples.bak.1774780058/npm_agent.js +175 -0
  69. package/examples.bak.1774780058/prompt_agent.js +112 -0
  70. package/examples.bak.1774780058/readme_agent.js +144 -0
  71. package/examples.bak.1774780058/spawn_agent.js +263 -0
  72. package/examples.bak.1774780058/test_agent.js +162 -0
  73. package/examples.bak.1774780058/todo_agent.js +138 -0
  74. package/lib/API/openai.com/reponses/text.js +12 -18
  75. package/lib/API/x.ai/collections.js +354 -0
  76. package/lib/API/x.ai/files.js +218 -0
  77. package/lib/API/x.ai/responses.js +492 -0
  78. package/lib/API/x.ai/text.js +1 -1
  79. package/lib/AgentClient.js +13 -6
  80. package/lib/AgentManager.js +80 -10
  81. package/lib/AgentServer.js +50 -22
  82. package/lib/Cli.js +7 -1
  83. package/lib/Prompt.js +4 -2
  84. package/lib/ToolSet.js +2 -1
  85. package/lib/genericToolset.js +258 -88
  86. package/lib/genericToolset.js.bak_syntax +402 -0
  87. package/lib/index.js +4 -2
  88. package/lib/wsCli.js +256 -0
  89. package/lib/wsIO.js +96 -0
  90. package/package.json +26 -21
  91. package/scenarios.bak.1774780058/data/eval_node_message.json +9 -0
  92. package/scenarios.bak.1774780058/data/hist_oa.json +66 -0
  93. package/scenarios.bak.1774780058/data/o3_response1.json +96 -0
  94. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +112 -0
  95. package/scenarios.bak.1774780058/data/tool_oa.json +96 -0
  96. package/scenarios.bak.1774780058/data/tool_xai.json +59 -0
  97. package/scenarios.bak.1774780058/data/tool_xai2.json +40 -0
  98. package/scenarios.bak.1774780058/data/xai-response-1.json +59 -0
  99. package/scenarios.bak.1774780058/data/xai-response-2.json +10 -0
  100. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +59 -0
  101. package/scenarios.bak.1774780058/data/xai_search_response.json +58 -0
  102. package/scenarios.bak.1774780058/environment.js +10 -0
  103. package/scenarios.bak.1774780058/example.js +17 -0
  104. package/scenarios.bak.1774780058/genericToolset.test.js +182 -0
  105. package/scenarios.bak.1774780058/grok.js +113 -0
  106. package/scenarios.bak.1774780058/memory-tools.js +51 -0
  107. package/scenarios.bak.1774780058/openai-o3.js +137 -0
  108. package/scenarios.bak.1774780058/openai-prompt.js +155 -0
  109. package/scenarios.bak.1774780058/openai-session.js +148 -0
  110. package/scenarios.bak.1774780058/openai.js +102 -0
  111. package/scenarios.bak.1774780058/prompt.js +118 -0
  112. package/scenarios.bak.1774780058/promptFishbowl.js +76 -0
  113. package/scenarios.bak.1774780058/search.brave.com.js +25 -0
  114. package/scenarios.bak.1774780058/sh.js +15 -0
  115. package/scenarios.bak.1774780058/test-wsio.js +26 -0
  116. package/scenarios.bak.1774780058/testToolset.js +42 -0
  117. package/scenarios.bak.1774780058/toolset.js +16 -0
  118. package/scenarios.bak.1774780058/toolset.test.js +141 -0
  119. package/scenarios.bak.1774780058/write_file_syntax.test.js +145 -0
  120. package/scenarios.bak.1774780058/write_file_validation/README.md +30 -0
  121. package/scenarios.bak.1774780058/write_file_validation/bad.js +3 -0
  122. package/scenarios.bak.1774780058/write_file_validation/good.js +4 -0
  123. package/scenarios.bak.1774780058/write_file_validation/test.sh +43 -0
  124. package/scenarios.bak.1774780058/wsClient.js +69 -0
  125. package/scenarios.bak.1774780058/xai_responses.integration.test.js +57 -0
  126. package/scenarios.bak.1774780058/xai_responses.test.js +154 -0
  127. package/scenarios.bak.1774780058/xaicoll.js +50 -0
  128. package/scenarios.bak.1774780058/xaifiles.js +48 -0
  129. package/types/API/openai.com/reponses/text.d.ts +17 -3
  130. package/types/API/x.ai/collections.d.ts +167 -0
  131. package/types/API/x.ai/files.d.ts +84 -0
  132. package/types/API/x.ai/responses.d.ts +379 -0
  133. package/types/AgentClient.d.ts +5 -0
  134. package/types/AgentManager.d.ts +25 -31
  135. package/types/AgentServer.d.ts +5 -1
  136. package/types/Prompt.d.ts +4 -2
  137. package/types/ToolSet.d.ts +1 -0
  138. package/types/index.d.ts +4 -3
  139. package/types/wsCli.d.ts +3 -0
  140. package/types/wsIO.d.ts +26 -0
  141. package/utils/bars.js +40 -0
  142. package/utils/clear_sessions.sh +54 -0
  143. package/{bin/hdInspect.js → utils/format_log.js} +5 -0
  144. package/utils/list_sessions.sh +46 -0
  145. package/utils/search_sessions.sh +73 -0
  146. package/utils/syntax_check.sh +61 -0
  147. package/utils/test.sh +46 -0
  148. package/bin/hdClear.js +0 -13
  149. package/bin/hdCode.js +0 -115
  150. package/bin/hdConnect.js +0 -230
  151. package/bin/hdNpm.js +0 -114
  152. package/bin/hdPrompt.js +0 -108
  153. package/examples/claude-test.js +0 -89
  154. package/examples/claude.js +0 -143
  155. package/examples/gpt.js +0 -127
  156. package/examples/gpt_code.js +0 -125
  157. package/examples/gpt_note_keeping.js +0 -117
  158. package/examples/grok.js +0 -119
  159. package/examples/grok_code.js +0 -114
  160. package/examples/grok_note_keeping.js +0 -111
  161. package/module.md +0 -189
package/README.md.bak ADDED
@@ -0,0 +1,481 @@
1
+ # @j-o-r/hello-dave
2
+
3
+ [![npm version](https://badge.fury.io/js/%40j-o-r%2Fhello-dave.svg)](https://www.npmjs.com/package/%40j-o-r%2Fhello-dave)
4
+ [![Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
+ [![Node.js >=20](https://img.shields.io/badge/Node.js-%3E=20-green.svg)](https://nodejs.org/)
6
+
7
+ ## Table of Contents
8
+
9
+ - [Description](#description)
10
+ - [Features](#features)
11
+ - [Installation](#installation)
12
+ - [Quick Start](#quick-start)
13
+ - [Usage](#usage)
14
+ - [Startup Modes](#startup-modes)
15
+ - [Examples](#examples)
16
+ - [Development](#development)
17
+ - [Changelog](#changelog)
18
+ - [Contributing](#contributing)
19
+ - [License](#license)
20
+ - [TODO Alignment](#todo-alignment)
21
+
22
+ ## Description
23
+
24
+ **@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).
25
+
26
+ 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.
27
+
28
+ 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.
29
+
30
+ ## Features
31
+
32
+ - **Unified LLM Access**: Seamless integration with xAI Grok API, Anthropic Claude, and OpenAI GPT via a single API.
33
+ - **AgentManager Class**: Core orchestrator for prompts, tools, sessions, and interactions (CLI, direct calls, WebSocket).
34
+ - **Tool Integration**: Built-in tools for bash scripting, web search, JavaScript execution, and more; easily extensible.
35
+ - **WebSocket Networking with Secrets**: Agents can act as servers or clients with optional secret authentication, enabling secure distributed agent networks across machines.
36
+ - **Direct CLI/Cron Messaging**: Simplified interactions without needing heartbeat mechanisms—ideal for scheduled tasks.
37
+ - **Customizable Prompts**: Tailor agent behavior with system prompts for specialized tasks (e.g., music production, code analysis).
38
+ - **Session Management**: Persistent conversations with large context windows; automatic truncation and history search.
39
+ - **CLI Utilities**: Core tool at `bin/dave.js` for cache management, WS connections, and interactive queries; plus agent generator.
40
+ - **Lightweight & TypeScript-Friendly**: ESM-only, no heavy deps; full types included.
41
+ - **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'`).
42
+
43
+ ## Installation
44
+
45
+ Install as a dependency in your Node.js project (requires Node.js >= 20 with `"type": "module"` in `package.json`):
46
+
47
+ ```bash
48
+ npm install @j-o-r/hello-dave
49
+ ```
50
+
51
+ For global access to CLI tools (including `dave` from `bin/dave.js`):
52
+
53
+ ```bash
54
+ npm install -g @j-o-r/hello-dave
55
+ ```
56
+
57
+ Set your API keys via environment variables (only set what you need):
58
+ - `XAIKEY` for xAI Grok
59
+ - `ANTHKEY` for Anthropic Claude
60
+ - `OPENAIKEY` for OpenAI GPT
61
+ - `BRAVESEARCHKEY` for web search (optional)
62
+
63
+ Create a cache directory for sessions:
64
+ ```bash
65
+ mkdir .cache
66
+ ```
67
+
68
+ ## Quick Start
69
+
70
+ 1. Set an API key (e.g., for Grok):
71
+ ```bash
72
+ export XAIKEY=your_xai_api_key
73
+ ```
74
+
75
+ 2. Use the core CLI utility `bin/dave.js` (not a full agent) for interactive queries or management:
76
+ ```bash
77
+ npx @j-o-r/hello-dave dave --ask
78
+ ```
79
+ - Launches an interactive agent session using default Grok tools. Use `Alt+d` to exit, `Alt+r` to reset.
80
+ - Example: Ask questions about anything; it uses xAI Grok by default with web search and X search tools.
81
+
82
+ 3. For one-shot queries via piped input:
83
+ ```bash
84
+ echo "Explain quantum computing" | npx @j-o-r/hello-dave dave --ask --model grok-4
85
+ ```
86
+ - Provides a direct response using the specified model (e.g., `--model grok-4`).
87
+
88
+ 4. Connect to a WebSocket server using the CLI utility (for UI access to servers):
89
+ ```bash
90
+ Utility: npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret your_secret
91
+ ```
92
+
93
+ 5. Generate a custom agent using the portable `spawn_agent` tool (CLI/WS agents + CodeServer launchers):
94
+ ```bash
95
+ npx @j-o-r/hello-dave spawn_agent
96
+ ```
97
+ - Interactive: Follow prompts to create a new agent script in `bin/` (e.g., `bin/myagent.js`).
98
+ - Portable to any project (auto-installs deps like `@j-o-r/hello-dave`):
99
+ ```bash
100
+ npx @j-o-r/hello-dave spawn_agent --cwd ~/my-project
101
+ ```
102
+ - Supports one-shot: `echo "Create code-review agent" | npx @j-o-r/hello-dave spawn_agent --cwd ~/proj`.
103
+ - Aligns with CodeServer pattern for multi-agent setups (see Usage/Examples).
104
+
105
+ `bin/dave.js` also supports cache operations like `--list` (list sessions), `--search "query"`, `--clear`, and `--inspect path/to/log.ndjson`.
106
+
107
+ ## Usage
108
+
109
+ ### Core CLI Utility via `bin/dave.js` (Not a Full Agent)
110
+
111
+ `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:
112
+
113
+ - **Ask Mode** (Interactive or Piped One-Shot, using default Grok agent):
114
+ ```bash
115
+ # Interactive
116
+ npx @j-o-r/hello-dave dave --ask --model grok-4 --temperature 0.2
117
+
118
+ # Piped one-shot
119
+ echo "What is quantum computing?" | npx @j-o-r/hello-dave dave --ask --model grok-4
120
+ ```
121
+ - Note: Piped input triggers a direct response via `directCall`; without pipe, it launches an interactive CLI session.
122
+ - `--model` option works for both modes (e.g., `grok-4`, `grok-4-1-fast-reasoning`).
123
+ - Uses default `AgentManager` with xAI Grok API integration, adds tools like `web_search`, `x_search`, `open_link`, `send_email`, `history_search`.
124
+ - System prompt emphasizes brief, direct responses with step-by-step reasoning.
125
+
126
+ - **SpawnDave Mode** (Portable Agent Creator with --cwd Support):
127
+ ```bash
128
+ # Interactive in current project
129
+ npx @j-o-r/hello-dave spawn_agent --model grok-4-fast-reasoning --temperature 0.7
130
+
131
+ # Portable to another project (switches cwd, auto-deps)
132
+ npx @j-o-r/hello-dave spawn_agent --cwd ../other-proj
133
+
134
+ # One-shot for quick generation
135
+ 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
136
+ ```
137
+ - Creates production-ready CLI/WS agents (`bin/<name>.js`) supporting CLI, server (`--serve`), client (`--connect`), and hybrid modes.
138
+ - Generates multi-agent CodeServer launchers (`examples/<Name>Server`) using PM2 for persistent networked setups (main server + sub-agents).
139
+ - **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.
140
+ - Aligns with CodeServer pattern: Self-contained Bash launchers for PM2-managed multi-agents (e.g., code review + TODO + NPM agents).
141
+ - Requires `XAIKEY`; uses online repo docs (https://codeberg.org/duin/hello-dave) for portability.
142
+ - Example output: Deploys `bin/coderev_agent.js`, tests it, provides server/client usage guide.
143
+
144
+ - **WebSocket Client Mode** (Utility UI for connecting to servers, with secrets for secure networking):
145
+ ```bash
146
+ # Interactive connection
147
+ Utility: npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
148
+
149
+ # Piped one-shot (direct CLI/cron messaging, no heartbeat needed)
150
+ echo "Predict the weather" | npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
151
+ echo "user_reset" | npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
152
+ ```
153
+
154
+ - **Cache Management** (Session maintenance in .cache):
155
+ ```bash
156
+ npx @j-o-r/hello-dave dave --list # List sessions
157
+ npx @j-o-r/hello-dave dave --search "AI agents" # Search history
158
+ npx @j-o-r/hello-dave dave --clear # Clear cache
159
+ npx @j-o-r/hello-dave dave --inspect path/to/log.ndjson # Inspect log
160
+ ```
161
+
162
+ For custom full agents (with prompts/tools/server support), use `AgentManager` programmatically (see Examples) or scripts like `examples/npm_agent.js`.
163
+
164
+ ### Programmatic Usage with AgentManager (For Full Agents)
165
+
166
+ ```javascript
167
+ import AgentManager from '@j-o-r/hello-dave';
168
+
169
+ const agent = new AgentManager({ name: 'MyAgent', secret: 'optional_secret' });
170
+ agent.setup({
171
+ prompt: 'You are a helpful assistant...',
172
+ api: 'xai', // Uses unified xAI Grok API access
173
+ options: { model: 'grok-4', temperature: 0.7, tools: [{ type: 'web_search' }] },
174
+ toolsetMode: 'auto',
175
+ contextWindow: 500000
176
+ });
177
+
178
+ agent.addGenericToolcall('execute_bash_script'); // Post-setup generics
179
+ agent.addGenericToolcall('read_file');
180
+ agent.addGenericToolcall('write_file');
181
+ agent.addGenericToolcall('memory_recall'); // Persist/recall tasks, errors, prefs in .cache/memory.ndjson
182
+ agent.addGenericToolcall('memory_write'); // Optimizes loops and long-running sessions
183
+
184
+ await agent.start(); // Interactive CLI
185
+ // Or: await agent.start(undefined, 8000, undefined, 'Intro', 'toolName', 'desc'); // WS server
186
+ // Or: const response = await agent.directCall('Query'); // One-shot
187
+ ```
188
+
189
+ 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.
190
+
191
+ 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.
192
+
193
+ ## Startup Modes
194
+
195
+ 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).
196
+
197
+ 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).
198
+
199
+ ### AgentManager.start() Options Explained
200
+ The `start()` method is the smart launcher for all modes. It accepts up to 5 arguments in order:
201
+ - `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.
202
+ - `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.
203
+ - `cliIntro` (string | undefined): Custom welcome message for interactive CLI mode (e.g., "NPM Agent ready. Ask about modules.").
204
+ - `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.
205
+ - `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.").
206
+
207
+ **Mode Determination**:
208
+ - If `serve` provided: Starts WS server (exposes tools).
209
+ - If `connect` provided: Starts WS client (attaches to remote, gains tools).
210
+ - If both: Hybrid mode (serves locally while using remote tools).
211
+ - If neither: Interactive CLI mode.
212
+ - For one-shot (non-start): Use `directCall(input)` directly (positional arg in scripts).
213
+
214
+ **Shared Notes**:
215
+ - `--secret [string]` (min 3 chars): Shared auth token. Servers reject mismatched clients; use the same for chains/networks.
216
+ - Other options: `--model [grok-4-fast-reasoning|...]`, `--temperature [-2 to +2]`, `--tokens`, `--top_p`, `--context [250000]`.
217
+ - Positional args ignored in WS modes (use CLI/pipes instead).
218
+ - No heartbeat: Event-driven responses.
219
+ - For multi-agent chaining, see [CodeServer pattern](docs/codeserver-pattern.md).
220
+
221
+ ### 1. Direct Call (One-Shot, Positional Arg Only)
222
+ 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.)
223
+
224
+ **CLI Example (Full Agent, e.g., npm_agent.js)**:
225
+ ```bash
226
+ ./examples/npm_agent.js "What modules are installed?" [--model grok-4]
227
+ ```
228
+ - Input: Positional string (trimmed). If empty/missing, falls to interactive CLI or help.
229
+
230
+ **Programmatic (AgentManager)**:
231
+ ```javascript
232
+ import { AgentManager } from '@j-o-r/hello-dave' ;
233
+ const agent = new AgentManager({ name: 'npm_agent' });
234
+ await agent.setup({ /* prompt, api, options, toolsetMode, contextWindow */ });
235
+ const response = await agent.directCall('What modules are installed?' );
236
+ console.log(response);
237
+ ```
238
+ - Pair with `readIn()` from `@j-o-r/sh` for piped stdin detection in scripts (e.g., `echo "query" | script.js`).
239
+
240
+ **Utility (dave.js for Default Queries)**:
241
+ ```bash
242
+ echo "Explain quantum computing" | npx @j-o-r/hello-dave dave --ask [--model grok-4]
243
+ ```
244
+ - Triggers `directCall` on piped input.
245
+
246
+ ### 2. Interactive CLI (No Positional Arg)
247
+ Launches ongoing conversation session with REPL-like input (multi-turn, until Ctrl+C or `Alt+d`).
248
+
249
+ **CLI Example (Full Agent)**:
250
+ ```bash
251
+ ./examples/npm_agent.js [--model grok-4]
252
+ ```
253
+ - No positional: Starts `agent.start()` with CLI intro.
254
+
255
+ **Programmatic**:
256
+ ```javascript
257
+ await agent.start(undefined, undefined, 'NPM Agent ready. Ask about modules or tools.' ); // Interactive CLI with custom intro
258
+ ```
259
+ - Uses `cliIntro` for welcome message. Supports history, reset (`Alt+r`).
260
+
261
+ **Utility (dave.js)**:
262
+ ```bash
263
+ npx @j-o-r/hello-dave dave --ask
264
+ ```
265
+ - Default agent; no custom tools/prompts.
266
+
267
+ ### 3. WS Server (--serve [port])
268
+ 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.)
269
+
270
+ **CLI Example (Full Agent)**:
271
+ ```bash
272
+ ./examples/npm_agent.js --serve 8080 [--secret mysecret] [--model grok-4]
273
+ ```
274
+ - Exposes `tool_call_name` (e.g., `npm_module_inspector`) for remote calls.
275
+
276
+ **Programmatic**:
277
+ ```javascript
278
+ await agent.start(8080, undefined, undefined, 'npm_module_inspector' , 'NPM modules expert using bash and cache in node_modules/.', 'mysecret' ); // Server on 8080; secret optional but recommended
279
+ ```
280
+ - `tool_call_name` and `tool_call_description` required for exposure. See [AgentManager docs](docs/agent-manager.md) for full server config, including reset propagation.
281
+
282
+ **Client Usage** (Connect to this server):
283
+ ```bash
284
+ # Interactive
285
+ npx @j-o-r/hello-dave dave --connect ws://127.0.0.1:8080 --secret mysecret
286
+ # Or full agent: ./examples/other_agent.js --connect ws://127.0.0.1:8080 --secret mysecret
287
+ ```
288
+ - Clients gain the server's tools (e.g., call `npm_module_inspector` in their prompts).
289
+
290
+ ### 4. WS Client (--connect [ws_url])
291
+ Connects to a remote WS server as a client, gaining access to its tools, then launches interactive CLI.
292
+
293
+ **CLI Example (Full Agent)**:
294
+ ```bash
295
+ ./examples/npm_agent.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--model grok-4]
296
+ ```
297
+ - Attaches to server; uses remote tools in local sessions.
298
+
299
+ **Programmatic**:
300
+ ```javascript
301
+ await agent.start(undefined, 'ws://127.0.0.1:8080/ws' , undefined, undefined, undefined, 'mysecret' ); // Client mode; secret required if server uses one
302
+ ```
303
+ - After connection, interactive CLI starts. For one-shot: Pipe to script (uses `directCall` with remote tools).
304
+
305
+ **Utility (dave.js)**:
306
+ ```bash
307
+ # Interactive
308
+ npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
309
+ # Piped one-shot (cron-friendly)
310
+ echo "Use remote NPM tool to list modules" | npx @j-o-r/hello-dave dave --connect ws://localhost:8080 --secret "mysecret"
311
+ ```
312
+
313
+ ### 5. Hybrid (--serve [port] + --connect [ws_url])
314
+ 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.)
315
+
316
+ **CLI Example (Full Agent)**:
317
+ ```bash
318
+ ./examples/npm_agent.js --serve 8081 --connect ws://otherhost:8080/ws [--secret mysecret]
319
+ ```
320
+ - Local server on 8081 (exposes local tools); client to remote (uses remote tools).
321
+
322
+ **Programmatic**:
323
+ ```javascript
324
+ 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
325
+ ```
326
+ - Custom handling for secrets (use same or per-mode). See [AgentManager docs](docs/agent-manager.md) for hybrid details and error handling.
327
+
328
+ **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.
329
+
330
+ 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/).
331
+
332
+ ## Examples
333
+
334
+ 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).
335
+
336
+ - **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).
337
+
338
+ 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.
339
+
340
+ ### Persistent Multi-Agent CodeServer Pattern
341
+
342
+ 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.
343
+
344
+ 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).
345
+
346
+ **Usage:**
347
+
348
+ ```bash
349
+ # Start the CodeServer (requires PM2: npm i -g pm2)
350
+ ./examples/CodeServer 8080 mysecret
351
+
352
+ # Connect via CLI utility (interactive or piped)
353
+ Utility: npx @j-o-r/hello-dave dave --connect ws://127.0.0.1:8080/ws --secret mysecret
354
+ # 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
355
+ ```
356
+
357
+ Monitor with `pm2 list` and stop via `pm2 delete <name>`.
358
+
359
+ ### Snippet: Spawning Agents (Portable via `bin/dave.js` --spawn_agent)
360
+
361
+ `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.
362
+
363
+ 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).
364
+
365
+ **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`).
366
+
367
+ ```javascript
368
+ // Core setup in spawn_agent
369
+ const agent = new AgentManager({ name: 'spawn_agent', secret });
370
+ agent.setup({
371
+ prompt: 'You are AgentCreator... [detailed prompt for portability, validation]',
372
+ api: 'xai',
373
+ options: { model: 'grok-4-fast-reasoning', tools: [{ type: 'web_search' }], reasoning: { effort: 'high' } },
374
+ toolsetMode: 'auto',
375
+ contextWindow: 500000
376
+ });
377
+ agent.addGenericToolcall('execute_bash_script'); // For project inspection
378
+ agent.addGenericToolcall('read_file');
379
+ agent.addGenericToolcall('write_file'); // For generating bin/ scripts
380
+ agent.addGenericToolcall('memory_recall'); // For recalling previous generations or prefs
381
+ agent.addGenericToolcall('memory_write'); // For persisting agent configs or errors
382
+
383
+ await agent.start(); // Guides user to create e.g., bin/myagent.js
384
+ ```
385
+
386
+ - Validates generated ESM code with `node --check` and tool rules (xAI natives pre-setup, generics post-setup).
387
+ - Ensures absolute imports for portability.
388
+
389
+ **Example Usage:**
390
+
391
+ ```bash
392
+ # Interactive spawning (runs from npm without cloning; current dir)
393
+ npx @j-o-r/hello-dave spawn_agent
394
+
395
+ # Portable to specific project (auto-switches cwd, installs deps if needed)
396
+ npx @j-o-r/hello-dave spawn_agent --cwd ~/my-proj
397
+
398
+ # Piped one-shot for CodeServer launcher (portable, no cloning)
399
+ echo "Generate CodeServer launcher for coderev + tododave" | npx @j-o-r/hello-dave spawn_agent --cwd ~/proj
400
+ ```
401
+
402
+ ### Snippet: Using xAI Grok API Integration
403
+
404
+ The unified xAI Grok API access supports options like reasoning and tools:
405
+
406
+ ```javascript
407
+ // In AgentManager setup
408
+ const options = {
409
+ model: 'grok-4-1-fast-reasoning',
410
+ temperature: 0.8,
411
+ tools: [{ type: 'web_search' }, { type: 'x_search', from_date: '2024-01-01' }], // Native xAI tools
412
+ reasoning: { effort: 'medium', summary: 'auto' } // Chain-of-thought support
413
+ };
414
+ ```
415
+
416
+ Detailed examples for xAI integration (e.g., advanced tool calls, reasoning) are planned (see TODO).
417
+
418
+ ### Running Examples
419
+
420
+ ```bash
421
+ # Music agent (examples/daisy_agent.js - full agent)
422
+ chmod +x examples/daisy_agent.js
423
+ ./examples/daisy_agent.js "Generate lyrics for a pop song"
424
+
425
+ # TODO manager (examples/todo_agent.js - full agent)
426
+ ./examples/todo_agent.js --connect ws://localhost:8080 --secret "secret"
427
+
428
+ # Server setup for networked examples (use full agents, not dave utility)
429
+ ./examples/npm_agent.js --serve 8080 # Expose as WS server
430
+ ```
431
+
432
+ ## Development
433
+
434
+ - **Scripts**: `npm test` (runs scenarios/grok_agent.js), `npm run types` (generate TypeScript defs), `npm run release` (pack for release).
435
+ - **Structure**: Core in `lib/` (AgentManager.js, wsCli.js, etc.), API integrations in `lib/API/`, examples in `examples/`, utils in `utils/`.
436
+ - **Testing**: Basic validation via `npm test`. Unit tests for xAI integration planned (see TODO).
437
+ - **Prep for v0.0.4**: Focus on spawn_agent enhancements and release testing.
438
+
439
+ ## Changelog
440
+
441
+ ### v0.0.4 (Prep - March 2026)
442
+ - Reorganized examples to `examples/` folder (readmeDave, todoDave, etc.).
443
+ - Enhanced `bin/dave.js` for core utilities: spawning, WS with secrets, direct messaging.
444
+ - Improved xAI Grok API integration; added native tools/reasoning support.
445
+ - Removed heartbeat needs; direct CLI/cron support.
446
+ - Added piped one-shot support to dave --ask.
447
+ - **Completed: Unified Startup Modes documentation** - Finalized section with 5 modes, AgentManager.start() explanations, examples, and links to docs/.
448
+ - TODO alignment: High-priority items noted (release prep, spawn_agent enhancements).
449
+
450
+ ### v0.0.3 (Previous)
451
+ - Initial WS secrets, generic tools, AgentManager refinements.
452
+
453
+ Full history in git tags.
454
+
455
+ ## Contributing
456
+
457
+ 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.
458
+
459
+ 1. Install deps: `npm install`
460
+ 2. Self dep `npm run link-self`
461
+ 3. Run tests: `npm test`
462
+ 4. Generate types: `npm run types`
463
+ 5. Report issues: [https://codeberg.org/duin/hello-dave/issues](https://codeberg.org/duin/hello-dave/issues)
464
+
465
+ Follow the [Code of Conduct](CODE_OF_CONDUCT.md) and Apache-2.0 license.
466
+
467
+ ## License
468
+
469
+ Apache License 2.0. See [LICENSE](LICENSE) for details.
470
+
471
+ ## TODO Alignment
472
+
473
+ This README aligns with high-priority items from [TODO.md](TODO.md):
474
+ - **v0.0.4 Prep**: Changelog snippet added; release testing emphasized in Development.
475
+ - **spawn_agent Enhancements**: Highlighted in Examples with portability notes.
476
+ - xAI integration tests/examples: Deferred to later (general enhancements).
477
+ - Documentation tasks (e.g., AgentManager internals) integrated into Usage/Examples.
478
+ - **Completed: Explain startup modes** - Finalized dedicated section with unified 5 modes, examples, AgentManager.start() options, and links to [docs/agent-manager.md](docs/agent-manager.md).
479
+ - Deferred: Other xAI features to later; focus on core release and spawn_agent.
480
+
481
+ For full TODO, see [TODO.md](TODO.md).