@j-o-r/hello-dave 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +288 -163
- package/README.md.backup +269 -0
- package/bin/dave.js +165 -0
- package/examples/CodeServer +43 -0
- package/{bin/hdAsk.js → examples/askDave.js} +50 -39
- package/examples/codeDave.js +115 -0
- package/examples/coderev.js +72 -0
- package/examples/daisy.js +177 -0
- package/examples/docsDave.js +119 -0
- package/examples/gpt.js +54 -72
- package/examples/grok.js +47 -68
- package/examples/npmDave.js +175 -0
- package/examples/promptDave.js +112 -0
- package/examples/readmeDave.js +144 -0
- package/examples/spawndave.js +240 -0
- package/examples/todoDave.js +132 -0
- package/lib/API/openai.com/reponses/text.js +12 -18
- package/lib/API/x.ai/collections.js +354 -0
- package/lib/API/x.ai/files.js +218 -0
- package/lib/API/x.ai/responses.js +494 -0
- package/lib/API/x.ai/text.js +2 -2
- package/lib/AgentClient.js +13 -6
- package/lib/AgentManager.js +79 -10
- package/lib/AgentServer.js +45 -21
- package/lib/Cli.js +7 -1
- package/lib/Prompt.js +4 -2
- package/lib/ToolSet.js +2 -1
- package/lib/fafs.js +1 -0
- package/lib/genericToolset.js +152 -51
- package/lib/index.js +4 -2
- package/lib/wsCli.js +257 -0
- package/lib/wsIO.js +96 -0
- package/package.json +26 -20
- package/types/API/openai.com/reponses/text.d.ts +17 -3
- package/types/API/x.ai/collections.d.ts +167 -0
- package/types/API/x.ai/files.d.ts +84 -0
- package/types/API/x.ai/responses.d.ts +379 -0
- package/types/API/x.ai/text.d.ts +2 -2
- package/types/AgentClient.d.ts +5 -0
- package/types/AgentManager.d.ts +24 -31
- package/types/AgentServer.d.ts +5 -1
- package/types/Prompt.d.ts +4 -2
- package/types/ToolSet.d.ts +1 -0
- package/types/index.d.ts +4 -3
- package/types/wsCli.d.ts +3 -0
- package/types/wsIO.d.ts +26 -0
- package/utils/bars.js +40 -0
- package/utils/clear_sessions.sh +54 -0
- package/{bin/hdInspect.js → utils/format_log.js} +5 -0
- package/utils/list_sessions.sh +46 -0
- package/utils/search_sessions.sh +73 -0
- package/bin/hdClear.js +0 -13
- package/bin/hdCode.js +0 -110
- package/bin/hdConnect.js +0 -230
- package/bin/hdNpm.js +0 -114
- package/bin/hdPrompt.js +0 -108
- package/examples/claude-test.js +0 -89
- package/examples/claude.js +0 -143
- package/examples/gpt_code.js +0 -125
- package/examples/gpt_note_keeping.js +0 -117
- package/examples/grok_code.js +0 -114
- package/examples/grok_note_keeping.js +0 -111
- package/module.md +0 -189
package/README.md
CHANGED
|
@@ -1,207 +1,332 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
- then use either the programmatic API (AgentManager) or the provided CLIs.
|
|
47
|
-
|
|
48
|
-
### Bonus (when installed)
|
|
49
|
-
|
|
50
|
-
Use the AI right away. Make sure you have an x.ai api key available.
|
|
51
|
-
(Grok gives very good result)
|
|
1
|
+
# Updated README.md content
|
|
2
|
+
|
|
3
|
+
# @j-o-r/hello-dave
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/%40j-o-r%2Fhello-dave)
|
|
6
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
|
+
[](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
|
+
- [Examples](#examples)
|
|
17
|
+
- [Development](#development)
|
|
18
|
+
- [Changelog](#changelog)
|
|
19
|
+
- [Contributing](#contributing)
|
|
20
|
+
- [License](#license)
|
|
21
|
+
- [TODO Alignment](#todo-alignment)
|
|
22
|
+
|
|
23
|
+
## Description
|
|
24
|
+
|
|
25
|
+
**@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).
|
|
26
|
+
|
|
27
|
+
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.
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Unified LLM Access**: Seamless integration with xAI Grok API, Anthropic Claude, and OpenAI GPT via a single API.
|
|
34
|
+
- **AgentManager Class**: Core orchestrator for prompts, tools, sessions, and interactions (CLI, direct calls, WebSocket).
|
|
35
|
+
- **Tool Integration**: Built-in tools for bash scripting, web search, JavaScript execution, and more; easily extensible.
|
|
36
|
+
- **WebSocket Networking with Secrets**: Agents can act as servers or clients with optional secret authentication, enabling secure distributed agent networks across machines.
|
|
37
|
+
- **Direct CLI/Cron Messaging**: Simplified interactions without needing heartbeat mechanisms—ideal for scheduled tasks.
|
|
38
|
+
- **Customizable Prompts**: Tailor agent behavior with system prompts for specialized tasks (e.g., music production, code analysis).
|
|
39
|
+
- **Session Management**: Persistent conversations with large context windows; automatic truncation and history search.
|
|
40
|
+
- **CLI Utilities**: Core tool at `bin/dave.js` for cache management, WS connections, and interactive queries; plus agent generator.
|
|
41
|
+
- **Lightweight & TypeScript-Friendly**: ESM-only, no heavy deps; full types included.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
Install as a dependency in your Node.js project (requires Node.js >= 20 with `"type": "module"` in `package.json`):
|
|
52
46
|
|
|
53
47
|
```bash
|
|
54
|
-
|
|
48
|
+
npm install @j-o-r/hello-dave
|
|
55
49
|
```
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
|
|
51
|
+
For global access to CLI tools (including `dave` from `bin/dave.js`):
|
|
52
|
+
|
|
58
53
|
```bash
|
|
59
|
-
|
|
54
|
+
npm install -g @j-o-r/hello-dave
|
|
60
55
|
```
|
|
61
|
-
(I am used to run Agents within tmux sessions)
|
|
62
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:
|
|
63
64
|
```bash
|
|
64
|
-
|
|
65
|
-
|
|
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` for interactive queries or management:
|
|
76
|
+
```bash
|
|
77
|
+
npx @j-o-r/hello-dave dave --ask
|
|
78
|
+
```
|
|
79
|
+
- Launches an interactive agent session. 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 (e.g., for networked agents):
|
|
89
|
+
```bash
|
|
90
|
+
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 `spawndave` tool (CLI/WS agents + CodeServer launchers):
|
|
94
|
+
```bash
|
|
95
|
+
npx @j-o-r/hello-dave spawndave
|
|
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 spawndave --cwd ~/my-project
|
|
101
|
+
```
|
|
102
|
+
- Supports one-shot: `echo "Create code-review agent" | npx @j-o-r/hello-dave spawndave --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 via `bin/dave.js`
|
|
110
|
+
|
|
111
|
+
`bin/dave.js` provides essential utilities and examples for agent spawning, WS interactions, and basic querying. Key commands:
|
|
112
|
+
|
|
113
|
+
- **Ask Mode** (Interactive or Piped One-Shot):
|
|
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 `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 spawndave --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 spawndave --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 spawndave --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.js`, tests it, provides server/client usage guide.
|
|
143
|
+
|
|
144
|
+
- **WebSocket Client Mode** (with secrets for secure networking):
|
|
145
|
+
```bash
|
|
146
|
+
# Interactive connection
|
|
147
|
+
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**:
|
|
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
|
+
```
|
|
160
|
+
|
|
161
|
+
For custom agents, use `AgentManager` programmatically (see Examples).
|
|
162
|
+
|
|
163
|
+
### Programmatic Usage with AgentManager
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
import AgentManager from '@j-o-r/hello-dave';
|
|
167
|
+
|
|
168
|
+
const agent = new AgentManager({ name: 'MyAgent', secret: 'optional_secret' });
|
|
169
|
+
agent.setup({
|
|
170
|
+
prompt: 'You are a helpful assistant...',
|
|
171
|
+
api: 'xai', // Uses unified xAI Grok API access
|
|
172
|
+
options: { model: 'grok-4', temperature: 0.7, tools: [{ type: 'web_search' }] },
|
|
173
|
+
toolsetMode: 'auto',
|
|
174
|
+
contextWindow: 500000
|
|
175
|
+
});
|
|
66
176
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
echo "Current date time" | npx hdAsk
|
|
177
|
+
agent.addGenericToolcall('execute_bash_script'); // Post-setup generics
|
|
178
|
+
agent.addGenericToolcall('read_file');
|
|
179
|
+
agent.addGenericToolcall('write_file');
|
|
71
180
|
|
|
72
|
-
|
|
73
|
-
|
|
181
|
+
await agent.start(); // Interactive CLI
|
|
182
|
+
// Or: await agent.start(undefined, 8000, undefined, 'Intro', 'toolName', 'desc'); // WS server
|
|
183
|
+
// Or: const response = await agent.directCall('Query'); // One-shot
|
|
74
184
|
```
|
|
75
185
|
|
|
76
|
-
-
|
|
77
|
-
- Use keys inside the TUI:
|
|
78
|
-
- ALT+d: exit
|
|
79
|
-
- ALT+r: reset conversation
|
|
80
|
-
- ALT+s: load a previous session
|
|
81
|
-
- ALT+k: show shortcuts/help
|
|
186
|
+
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.
|
|
82
187
|
|
|
83
|
-
|
|
84
|
-
- echo "explain sse vs websocket in 2 lines" | npx hdAsk
|
|
188
|
+
## Examples
|
|
85
189
|
|
|
86
|
-
-
|
|
87
|
-
- node examples/grok.js --model grok-3-mini --tokens 4000 --context 10000 --temperature 0.3 --top_p 0.9
|
|
88
|
-
- node examples/grok.js --reasoning high
|
|
190
|
+
Example scripts (e.g., `readmeDave.js` for README management, `todoDave.js` for task handling, `spawndave.js` for agent creation) are now organized in the `examples/` folder. These demonstrate specialized 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).
|
|
89
191
|
|
|
90
|
-
-
|
|
91
|
-
- node examples/grok.js --tools javascript,bash
|
|
92
|
-
- javascript adds javascript_interpreter
|
|
93
|
-
- bash adds execute_bash_script
|
|
192
|
+
- **Link to Examples Folder**: Explore [examples/](examples/) for full scripts like `daisy.js` (music agent), `codeDave.js` (code review), `npmDave.js` (NPM inspector).
|
|
94
193
|
|
|
95
|
-
|
|
96
|
-
- Terminal A: node examples/grok.js --serve 8000 --tools javascript,bash
|
|
97
|
-
- Terminal B: node examples/grok.js --connect ws://127.0.0.1:8000/ws
|
|
194
|
+
### Persistent Multi-Agent CodeServer Pattern
|
|
98
195
|
|
|
99
|
-
|
|
100
|
-
- With --serve, the agent starts a WS server on 127.0.0.1:PORT and exposes any connected clients as callable tools.
|
|
101
|
-
- With --connect, an agent registers itself on that WS and will handle queries routed to its tool name.
|
|
196
|
+
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.
|
|
102
197
|
|
|
103
|
-
|
|
198
|
+
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).
|
|
104
199
|
|
|
105
|
-
|
|
106
|
-
- sessions/ incremental ndjson of messages
|
|
107
|
-
- records/ per-day ndjson of timing/token/billing metadata
|
|
108
|
-
- logs/ per-day ndjson of internal events
|
|
200
|
+
**Usage:**
|
|
109
201
|
|
|
110
|
-
|
|
202
|
+
```bash
|
|
203
|
+
# Start the CodeServer (requires PM2: npm i -g pm2)
|
|
204
|
+
./examples/CodeServer 8080 mysecret
|
|
111
205
|
|
|
112
|
-
|
|
206
|
+
# Connect via CLI (interactive or piped)
|
|
207
|
+
npx @j-o-r/hello-dave dave --connect ws://127.0.0.1:8080/ws --secret mysecret
|
|
208
|
+
# 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
|
|
209
|
+
```
|
|
113
210
|
|
|
114
|
-
|
|
211
|
+
Monitor with `pm2 list` and stop via `pm2 delete <name>`.
|
|
115
212
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
213
|
+
### Snippet: Spawning Agents (Portable via `bin/dave.js` --spawndave)
|
|
214
|
+
|
|
215
|
+
`spawndave` 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.
|
|
216
|
+
|
|
217
|
+
Now CodeServer-aware: Can generate PM2 multi-agent launchers (e.g., 'Generate CodeServer for coderev + todo'). See updated [examples/spawndave.js](examples/spawndave.js) and [docs/codeserver-pattern.md](docs/codeserver-pattern.md).
|
|
119
218
|
|
|
120
|
-
|
|
121
|
-
|
|
219
|
+
**Portable**: `spawndave` 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`).
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
// Core setup in spawndave
|
|
223
|
+
const agent = new AgentManager({ name: 'spawn_dave', secret });
|
|
122
224
|
agent.setup({
|
|
123
|
-
prompt: '
|
|
124
|
-
api: '
|
|
125
|
-
options: {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
},
|
|
129
|
-
toolsetMode: 'auto', // 'auto' | 'required' | undefined
|
|
130
|
-
contextWindow: 250_000
|
|
225
|
+
prompt: 'You are AgentCreator... [detailed prompt for portability, validation]',
|
|
226
|
+
api: 'xai',
|
|
227
|
+
options: { model: 'grok-4-fast-reasoning', tools: [{ type: 'web_search' }], reasoning: { effort: 'high' } },
|
|
228
|
+
toolsetMode: 'auto',
|
|
229
|
+
contextWindow: 500000
|
|
131
230
|
});
|
|
231
|
+
agent.addGenericToolcall('execute_bash_script'); // For project inspection
|
|
232
|
+
agent.addGenericToolcall('read_file');
|
|
233
|
+
agent.addGenericToolcall('write_file'); // For generating bin/ scripts
|
|
132
234
|
|
|
133
|
-
|
|
134
|
-
console.log(answer);
|
|
235
|
+
await agent.start(); // Guides user to create e.g., bin/myagent.js
|
|
135
236
|
```
|
|
136
237
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
```js
|
|
140
|
-
const toolset = agent.getToolset();
|
|
141
|
-
if (toolset) {
|
|
142
|
-
toolset.add(
|
|
143
|
-
'say_hello',
|
|
144
|
-
'Return a friendly greeting',
|
|
145
|
-
{
|
|
146
|
-
type: 'object',
|
|
147
|
-
properties: { name: { type: 'string', description: 'Who to greet' } },
|
|
148
|
-
required: ['name']
|
|
149
|
-
},
|
|
150
|
-
async ({ name }) => `Hello, ${name}!`
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Now the model can call say_hello when appropriate.
|
|
155
|
-
```
|
|
238
|
+
- Validates generated ESM code with `node --check` and tool rules (xAI natives pre-setup, generics post-setup).
|
|
239
|
+
- Ensures absolute imports for portability.
|
|
156
240
|
|
|
157
|
-
|
|
241
|
+
**Example Usage:**
|
|
158
242
|
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
```
|
|
243
|
+
```bash
|
|
244
|
+
# Interactive spawning (runs from npm without cloning; current dir)
|
|
245
|
+
npx @j-o-r/hello-dave spawndave
|
|
163
246
|
|
|
164
|
-
|
|
247
|
+
# Portable to specific project (auto-switches cwd, installs deps if needed)
|
|
248
|
+
npx @j-o-r/hello-dave spawndave --cwd ~/my-proj
|
|
165
249
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
'code',
|
|
169
|
-
'Run JavaScript snippets safely and return output',
|
|
170
|
-
'ws://127.0.0.1:8000/ws'
|
|
171
|
-
);
|
|
250
|
+
# Piped one-shot for CodeServer launcher (portable, no cloning)
|
|
251
|
+
echo "Generate CodeServer launcher for coderev + tododave" | npx @j-o-r/hello-dave spawndave --cwd ~/proj
|
|
172
252
|
```
|
|
173
253
|
|
|
174
|
-
|
|
254
|
+
### Snippet: Using xAI Grok API Integration
|
|
175
255
|
|
|
176
|
-
|
|
177
|
-
- lib/Cli.js: a small TUI with history, session loading, and handy shortcuts; it listens to Prompt events.
|
|
178
|
-
- lib/AgentServer.js: local WS server that turns each attached client into a ToolSet function. Calls are routed over WS and responses returned as tool outputs.
|
|
179
|
-
- lib/AgentClient.js: WS client that introduces itself (name + description) and processes queued requests exactly one at a time.
|
|
256
|
+
The unified xAI Grok API access supports options like reasoning and tools:
|
|
180
257
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
-
|
|
185
|
-
|
|
258
|
+
```javascript
|
|
259
|
+
// In AgentManager setup
|
|
260
|
+
const options = {
|
|
261
|
+
model: 'grok-4-1-fast-reasoning',
|
|
262
|
+
temperature: 0.8,
|
|
263
|
+
tools: [{ type: 'web_search' }, { type: 'x_search', from_date: '2024-01-01' }], // Native xAI tools
|
|
264
|
+
reasoning: { effort: 'medium', summary: 'auto' } // Chain-of-thought support
|
|
265
|
+
};
|
|
266
|
+
```
|
|
186
267
|
|
|
187
|
-
|
|
188
|
-
- Types are bundled. Main types for AgentManager are available via types/AgentManager.d.ts.
|
|
268
|
+
Detailed examples for xAI integration (e.g., advanced tool calls, reasoning) are planned (see TODO).
|
|
189
269
|
|
|
190
|
-
|
|
270
|
+
### Running Examples
|
|
191
271
|
|
|
192
272
|
```bash
|
|
193
|
-
#
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
#
|
|
198
|
-
|
|
199
|
-
# Ask a generic quesion to openai gpt-5-nano (openai key needed)
|
|
200
|
-
npx hdAsk
|
|
201
|
-
# Cli Connect to a websocket agent server
|
|
202
|
-
npx hdConnect [ws://127.0.0.1:8000/ws]
|
|
273
|
+
# Music agent (examples/daisy.js)
|
|
274
|
+
chmod +x examples/daisy.js
|
|
275
|
+
./examples/daisy.js "Generate lyrics for a pop song"
|
|
276
|
+
|
|
277
|
+
# TODO manager (examples/todoDave.js)
|
|
278
|
+
./examples/todoDave.js --connect ws://localhost:8080 --secret "secret"
|
|
203
279
|
|
|
280
|
+
# Server setup for networked examples
|
|
281
|
+
npx @j-o-r/hello-dave dave --ask --serve 8080 # Expose as WS server
|
|
204
282
|
```
|
|
205
283
|
|
|
284
|
+
## Development
|
|
285
|
+
|
|
286
|
+
- **Scripts**: `npm test` (runs scenarios/grok.js), `npm run types` (generate TypeScript defs), `npm run release` (pack for release).
|
|
287
|
+
- **Structure**: Core in `lib/` (AgentManager.js, wsCli.js, etc.), API integrations in `lib/API/`, examples in `examples/`, utils in `utils/`.
|
|
288
|
+
- **Testing**: Basic validation via `npm test`. Unit tests for xAI integration planned (see TODO).
|
|
289
|
+
- **Prep for v0.0.4**: Focus on spawnDave enhancements and release testing.
|
|
290
|
+
|
|
291
|
+
## Changelog
|
|
292
|
+
|
|
293
|
+
### v0.0.4 (Prep - March 2026)
|
|
294
|
+
- Reorganized examples to `examples/` folder (readmeDave, todoDave, etc.).
|
|
295
|
+
- Enhanced `bin/dave.js` for core utilities: spawning, WS with secrets, direct messaging.
|
|
296
|
+
- Improved xAI Grok API integration; added native tools/reasoning support.
|
|
297
|
+
- Removed heartbeat needs; direct CLI/cron support.
|
|
298
|
+
- Added piped one-shot support to dave --ask.
|
|
299
|
+
- TODO alignment: High-priority items noted (release prep, spawnDave enhancements).
|
|
300
|
+
|
|
301
|
+
### v0.0.3 (Previous)
|
|
302
|
+
- Initial WS secrets, generic tools, AgentManager refinements.
|
|
303
|
+
|
|
304
|
+
Full history in git tags.
|
|
305
|
+
|
|
306
|
+
## Contributing
|
|
307
|
+
|
|
308
|
+
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.
|
|
309
|
+
|
|
310
|
+
1. Install deps: `npm install`
|
|
311
|
+
2. Self dep `npm run link-self`
|
|
312
|
+
3. Run tests: `npm test`
|
|
313
|
+
4. Generate types: `npm run types`
|
|
314
|
+
5. Report issues: [https://codeberg.org/duin/hello-dave/issues](https://codeberg.org/duin/hello-dave/issues)
|
|
315
|
+
|
|
316
|
+
Follow the [Code of Conduct](CODE_OF_CONDUCT.md) and Apache-2.0 license.
|
|
317
|
+
|
|
206
318
|
## License
|
|
207
|
-
|
|
319
|
+
|
|
320
|
+
Apache License 2.0. See [LICENSE](LICENSE) for details.
|
|
321
|
+
|
|
322
|
+
## TODO Alignment
|
|
323
|
+
|
|
324
|
+
This README aligns with high-priority items from [TODO.md](TODO.md):
|
|
325
|
+
- **v0.0.4 Prep**: Changelog snippet added; release testing emphasized in Development.
|
|
326
|
+
- **spawnDave Enhancements**: Highlighted in Examples with portability notes.
|
|
327
|
+
- xAI integration tests/examples: Deferred to later (general enhancements).
|
|
328
|
+
- Documentation tasks (e.g., AgentManager internals) integrated into Usage/Examples.
|
|
329
|
+
- Deferred: Other xAI features to later; focus on core release and spawnDave.
|
|
330
|
+
|
|
331
|
+
For full TODO, see [TODO.md](TODO.md).
|
|
332
|
+
|