@j-o-r/hello-dave 0.1.1 → 0.1.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 (173) hide show
  1. package/CHANGELOG.md +42 -25
  2. package/README.md +81 -221
  3. package/TODO.md +173 -35
  4. package/agents/agent_creator.js +105 -0
  5. package/agents/agent_creator.prompt.md +371 -0
  6. package/agents/ask_agent.js +64 -127
  7. package/agents/claude_agent.js +68 -0
  8. package/agents/code_agent.js +55 -135
  9. package/agents/code_agent.prompt.md +50 -0
  10. package/agents/echo_agent.js +76 -0
  11. package/agents/financial_expert.js +75 -0
  12. package/agents/gpt_agent.js +52 -103
  13. package/agents/gpt_code.js +81 -0
  14. package/agents/grok_agent.js +58 -114
  15. package/agents/minimax_agent.js +92 -0
  16. package/agents/mureka_agent.js +77 -0
  17. package/agents/planner_agent.js +172 -0
  18. package/agents/stability_agent.js +87 -0
  19. package/agents/test_agent.js +75 -157
  20. package/agents/weather_agent.js +73 -0
  21. package/agents/workflow_agent.js +189 -0
  22. package/bin/dave.js +436 -184
  23. package/docs/bin-dave.md +85 -35
  24. package/docs/cdn-ssh.md +100 -0
  25. package/docs/creating-agents.md +301 -0
  26. package/docs/creating-toolsets.md +336 -0
  27. package/docs/docs-organization.md +48 -0
  28. package/docs/project-overview.md +86 -51
  29. package/lib/API/elevenlabs.io/music.compose.md +441 -0
  30. package/lib/API/elevenlabs.io/music.create-composition-plan.md +370 -0
  31. package/lib/API/elevenlabs.io/music.stream.md +425 -0
  32. package/lib/API/lalal.ai/lalal.js +445 -0
  33. package/lib/API/lalal.ai/openapi.json +2614 -0
  34. package/lib/API/minimax/ImageToolset.js +82 -37
  35. package/lib/API/minimax/MusicToolset.js +125 -79
  36. package/lib/API/minimax/VideoToolset.js +170 -167
  37. package/lib/API/minimax/image.js +5 -1
  38. package/lib/API/minimax/music.js +210 -23
  39. package/lib/API/minimax/video.js +242 -53
  40. package/lib/API/mureka/MusicToolset.js +646 -0
  41. package/lib/API/mureka/README.md +41 -0
  42. package/lib/API/mureka/index.js +7 -0
  43. package/lib/API/mureka/music.js +658 -0
  44. package/lib/API/openai.com/index.js +7 -0
  45. package/lib/API/openai.com/{reponses/text.js → responses.js} +64 -18
  46. package/lib/API/openai.com/video.create.character.md +40 -0
  47. package/lib/API/openai.com/video.create.md +219 -0
  48. package/lib/API/openai.com/video.delete.md +44 -0
  49. package/lib/API/openai.com/video.download.md +31 -0
  50. package/lib/API/openai.com/video.edit.md +155 -0
  51. package/lib/API/openai.com/video.extend.md +166 -0
  52. package/lib/API/openai.com/video.fetch.character.md +43 -0
  53. package/lib/API/openai.com/video.js +784 -0
  54. package/lib/API/openai.com/video.list.md +201 -0
  55. package/lib/API/openai.com/video.remix.md +175 -0
  56. package/lib/API/openai.com/video.retrieve.md +139 -0
  57. package/lib/API/openai.com/videoToolset.js +616 -0
  58. package/lib/API/stability.ai/ImageToolset.js +131 -40
  59. package/lib/API/stability.ai/MusicToolset.js +79 -47
  60. package/lib/API/stability.ai/audio.js +63 -131
  61. package/lib/API/x.ai/chat.responses.md +1040 -0
  62. package/lib/API/x.ai/image.js +229 -59
  63. package/lib/API/x.ai/imageToolset.js +376 -0
  64. package/lib/API/x.ai/index.js +1 -1
  65. package/lib/API/x.ai/responses.js +9 -18
  66. package/lib/Agent.js +271 -0
  67. package/lib/Agent.js.old +284 -0
  68. package/lib/AgentLauncher.js +562 -0
  69. package/lib/Cli.js +87 -13
  70. package/lib/Prompt.js +23 -1
  71. package/lib/Session.js +5 -4
  72. package/lib/ToolSet.js +102 -6
  73. package/lib/agentLoader.js +369 -0
  74. package/lib/cdn.js +67 -231
  75. package/lib/{CdnToolset.js → cdnToolset.js} +47 -64
  76. package/lib/defaultToolsets.js +43 -0
  77. package/lib/fafs.js +1 -1
  78. package/lib/genericToolset.js +442 -119
  79. package/lib/handOffToolset.js +179 -0
  80. package/lib/index.js +34 -27
  81. package/lib/toolsetLoader.js +248 -0
  82. package/package.json +11 -5
  83. package/types/API/lalal.ai/lalal.d.ts +116 -0
  84. package/types/API/minimax/image.d.ts +2 -1
  85. package/types/API/minimax/music.d.ts +189 -26
  86. package/types/API/minimax/video.d.ts +100 -31
  87. package/types/API/mureka/index.d.ts +7 -0
  88. package/types/API/mureka/music.d.ts +472 -0
  89. package/types/API/openai.com/index.d.ts +7 -0
  90. package/types/API/openai.com/{reponses/text.d.ts → responses.d.ts} +11 -11
  91. package/types/API/openai.com/video.d.ts +409 -0
  92. package/types/API/openai.com/videoToolset.d.ts +24 -0
  93. package/types/API/stability.ai/audio.d.ts +14 -103
  94. package/types/API/stability.ai/image.d.ts +2 -2
  95. package/types/API/x.ai/image.d.ts +138 -26
  96. package/types/API/x.ai/imageToolset.d.ts +3 -0
  97. package/types/API/x.ai/index.d.ts +1 -1
  98. package/types/API/x.ai/responses.d.ts +4 -4
  99. package/types/Agent.d.ts +123 -0
  100. package/types/AgentLauncher.d.ts +222 -0
  101. package/types/Cli.d.ts +28 -8
  102. package/types/Prompt.d.ts +23 -5
  103. package/types/Session.d.ts +1 -1
  104. package/types/ToolSet.d.ts +10 -0
  105. package/types/agentLoader.d.ts +78 -0
  106. package/types/cdn.d.ts +15 -90
  107. package/types/defaultToolsets.d.ts +9 -0
  108. package/types/fafs.d.ts +1 -1
  109. package/types/genericToolset.d.ts +1 -1
  110. package/types/handOffToolset.d.ts +28 -0
  111. package/types/index.d.ts +19 -17
  112. package/types/toolsetLoader.d.ts +114 -0
  113. package/utils/format_log.js +101 -23
  114. package/utils/launch_agent.js +18 -0
  115. package/utils/list_sessions.sh +13 -5
  116. package/utils/search_sessions.sh +65 -29
  117. package/utils/toolsets.js +33 -0
  118. package/README.md.bak.1779452127 +0 -240
  119. package/agents/codeserver.sh +0 -47
  120. package/agents/daisy_agent.js +0 -173
  121. package/agents/docs_agent.js +0 -148
  122. package/agents/memory_agent.js +0 -263
  123. package/agents/minimax.js +0 -173
  124. package/agents/npm_agent.js +0 -202
  125. package/agents/prompt_agent.js +0 -133
  126. package/agents/readme_agent.js +0 -148
  127. package/agents/spawn_agent.js +0 -160
  128. package/agents/stability.js +0 -173
  129. package/agents/todo_agent.js +0 -175
  130. package/bin/codeDave +0 -58
  131. package/docs/agent-dave-websocket-protocol.md +0 -180
  132. package/docs/agent-manager.md +0 -244
  133. package/docs/codeserver-pattern.md +0 -191
  134. package/docs/generic-toolset.md +0 -326
  135. package/docs/howtos/agent-networking.md +0 -253
  136. package/docs/howtos/spawn-agents.md.bak +0 -200
  137. package/docs/howtos/spawn-agents.md.bak_new +0 -200
  138. package/docs/multi-agent-clusters.md +0 -265
  139. package/docs/music-toolsets.md +0 -137
  140. package/docs/path-resolution-best-practices.md +0 -104
  141. package/docs/plans/minimax-music-generation.md +0 -80
  142. package/docs/plans/unified-agent-architecture.md +0 -146
  143. package/docs/plans/websocket-streaming-plan.md.bak +0 -317
  144. package/docs/prompt/spawn_agent.md +0 -175
  145. package/docs/prompt/spawn_agent.md.bak +0 -201
  146. package/docs/prompt/task_clarification_and_documentation.md +0 -35
  147. package/docs/prompt-class.md +0 -141
  148. package/docs/todo-archive-infra-2026-04-21.md +0 -15
  149. package/docs/todo-archive-v0.0.8.md +0 -1
  150. package/docs/todo-archive-v0.1.0.md +0 -32
  151. package/docs/todo-archive.md +0 -44
  152. package/docs/tools-syntax-validation.md +0 -121
  153. package/docs/toolset.md +0 -164
  154. package/docs/xai-responses.md +0 -111
  155. package/docs/xai_collections.md +0 -106
  156. package/lib/API/x.ai/ImageToolset.js +0 -165
  157. package/lib/API/x.ai/text.js +0 -415
  158. package/lib/AgentClient.js +0 -248
  159. package/lib/AgentManager.js +0 -245
  160. package/lib/AgentServer.js +0 -404
  161. package/lib/wsCli.js +0 -287
  162. package/lib/wsIO.js +0 -90
  163. package/types/API/x.ai/text.d.ts +0 -286
  164. package/types/AgentClient.d.ts +0 -109
  165. package/types/AgentManager.d.ts +0 -100
  166. package/types/AgentServer.d.ts +0 -89
  167. package/types/wsCli.d.ts +0 -17
  168. package/types/wsIO.d.ts +0 -30
  169. package/utils/test.sh +0 -46
  170. /package/docs/{suggestions.md → _notes/token-counts.md} +0 -0
  171. /package/lib/API/openai.com/{reponses/MESSAGES.md → MESSAGES.md} +0 -0
  172. /package/types/API/{x.ai/ImageToolset.d.ts → mureka/MusicToolset.d.ts} +0 -0
  173. /package/types/{CdnToolset.d.ts → cdnToolset.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,25 +1,42 @@
1
- ## Changelog
2
-
3
- ### v0.0.8 (Released - April 15, 2026)
4
- - **lib/genericToolset.js Timeout Refinements**: Switched `execute_bash_script` to @j-o-r/sh `.options({timeout: ms}).run()` with heredoc delimiter for verbatim multi-line bash_script safety. Default 360s (resets on stdout/stderr output for true idle detection only), SIGTERM on expiry. `execute_remote_script` stdin pipe preserved. Tests: success, sleep timeout (3s<7s), exit1 error, interactive `read -p` no hang.
5
- - **TODO.md Cleanup**: Archived all completed tasks (timeout refinements, prior v0.0.7 carryovers) to `docs/todo-archive-v0.0.8.md`. Pending changelog task completed here. Clean post-release state.
6
- - **.npmignore & package-lock.json**: Minor updates for cleaner packaging.
7
- - **Release Prep**: `package.json` bumped to v0.0.8. `npm run release` ready (types + pack to `./release/`).
8
-
9
- ### v0.0.7 (Released - April 13, 2026)
10
- - **spawn_agent Enhancements**: Strict blueprint enforcement in `docs/prompt/spawn_agent.md` (mandatory tool sequence: INSPECT → VALIDATE → GATHER → GENERATE → AUTO-DEPLOY/TEST). Fixed one-shot hallucination/no-deploy via verbatim AGENT BLUEPRINT TEMPLATE, temp_agent.js validation (syntax/blueprint checks), PROJECT auto-deploy (write/mv/chmod/test/rm), FRESH manual code/bash. Robust fetchLivePrompt() (live MD full-load + fallbacks). CodeServer/PM2 awareness (LAUNCH_MODE detect, client connect hints). Tested 2026-04-13: /tmp FRESH, PROJECT diag_agent.js deploy+--help success.
11
- - **JSDoc Updates (lib/ modules)**: Comprehensive JSDoc added/fixed for AgentClient.js, AgentManager.js, AgentServer.js, Cli.js, Prompt.js, Session.js, ToolSet.js, fafs.js, genericToolset.js, wsCli.js, wsIO.js. Typedefs, @returns, @private tags. Note: Some parser warnings (HTML entities &lt; → &lt;, import() expr); HTML generated in docs/jsdoc/.
12
- - **bin/codeDave Fix**: Resolved SCRIPT_DIR symlink resolution for global npm bin runs from any dir (standard readlink loop idiom). Tested from /tmp/otherdir.
13
- - **Types Regeneration**: `npm run types` full types/*.d.ts updated via tsc.
14
- - **Docs Added/Updated**: docs/generic-toolset.md (toolsPool/examples), docs/jsdoc-best-practices.md, docs/multi-agent-clusters.md (spawn_agent PM2), docs/prompt/spawn_agent.md (PROCESS/blueprint), docs/todo-archive.md (TODO history).
15
- - **NPM Deps & Scripts**: Pruned extraneous, installed missing (@j-o-r/apiserver/cli, gpt-3-encoder). Clean `npm ls`. TODO.md shortened (recent 7 Done items; older archived).
16
- - **utils/search_sessions.sh**: Added/modified for history search.
17
- - **Tests & Fixes**: genericToolset.test.js notes (write_file validation stable). write_file temp-first + cleanup for deploys. All spawn_agent changes verified in CodeServer cluster (PM2 hello-dave_*_9000).
18
- - **Release Prep**: package.json v0.0.7, git commits/tags. Ready for `npm publish --access public`.
19
-
20
- ### v0.0.6 (Released - April 2026)
21
- [Previous content unchanged]
22
-
23
- [... rest of previous sections unchanged ...]
24
-
25
- Full history in git tags.
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - Comprehensive plan for **Agent File-Socket Communication Layer** (`docs/plans/agent-file-socket-communication.md`).
12
+ - Enables persistent agent sessions via Unix domain sockets in `.cache/sockets/`.
13
+ - One-shot calls participate in live sessions (same as interactive CLI).
14
+ - Bi-directional control plane (queries, commands, handoff, reset, info, list_agents, etc.).
15
+ - Any UI/frontend can attach to a running agent.
16
+ - "Keep it simple" mandate: `AgentLauncher` always ensures the socket server; CLI evolves to be a socket client.
17
+ - Updated project documentation to reflect the new direction:
18
+ - `docs/project-overview.md`
19
+ - `docs/bin-dave.md`
20
+ - `TODO.md` (detailed tracking section with phases, open decisions, next actions)
21
+
22
+ ### Architecture Notes
23
+ - Builds directly on the existing clean `Agent` + `AgentLauncher` + in-process handoff model (fresh context only).
24
+ - Leverages `Prompt` as EventEmitter for natural event streaming over sockets.
25
+ - No changes to existing agents or core behavior yet (planning + docs phase complete).
26
+ - Legacy WS/swarm model remains in `_legacy/` and is not revived.
27
+
28
+ See the plan document for full details, phased rollout, risks, and recommended next steps (Phase 1: minimal socket server/client + one-shot path).
29
+
30
+ ---
31
+
32
+ ## [0.1.3] - 2026-06 (prior)
33
+
34
+ ### Added / Changed
35
+ - Unified `Agent` class + `AgentLauncher` with clean in-process handoff (`hand_over` / `load_agent` tools).
36
+ - Fresh handoff semantics (no history copied; only system prompt + short task-focused context).
37
+ - Self-reset support for deliberate fresh starts.
38
+ - Dual-layer documentation model (framework vs project-local `docs/`).
39
+ - `dave` CLI delegates almost everything to `AgentLauncher`.
40
+ - Many agent improvements and toolset work.
41
+
42
+ (Older history summarized; see git log for full details.)
package/README.md CHANGED
@@ -1,242 +1,102 @@
1
- # hello-dave
1
+ # @j-o-r/hello-dave
2
+
3
+ ![Selfie with HAL 9000](assets/selfie-hal9000.png)
2
4
 
3
5
  [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
6
  [![Node.js >=20](https://img.shields.io/badge/Node.js-%3E=20-green.svg)](https://nodejs.org/)
5
- [![Version: v0.0.8](https://img.shields.io/badge/Version-v0.0.8-green.svg)](https://codeberg.org/duin/hello-dave)
6
- [![PM2 Compatible](https://img.shields.io/badge/PM2-Compatible-orange.svg)](https://pm2.keymetrics.io/)
7
-
8
- ## Table of Contents
9
-
10
- - [Description](#description)
11
- - [Features](#features)
12
- - [Folder Structure](#folder-structure)
13
- - [Installation](#installation)
14
- - [Usage](#usage)
15
- - [Usage Examples](#usage-examples)
16
- - [Development](#development)
17
- - [Contributing](#contributing)
18
- - [License](#license)
19
-
20
- ## Description
21
-
22
- **hello-dave** is an ESM (ECMAScript Modules) toolkit for building AI agents with unified access to endpoints from Grok (xAI), OpenAI, and Anthropic. It provides CLI tools for interacting with agents locally or via WebSocket servers, along with pre-built agent scripts for various tasks like code generation, documentation, testing, and more.
23
-
24
- The project emphasizes modular agent management, tool integration (e.g., web search, file operations), and session handling with memory and caching. With v0.0.8, enhanced portability allows spawning agents in isolated environments like `/tmp` while maintaining tool functionality relative to the current working directory (CWD).
25
-
26
- ## Features
27
-
28
- - **Unified API Access**: Seamless integration with xAI (Grok), OpenAI, and Anthropic models.
29
- - **CLI Tools**: `dave` for querying agents, `agentDave` for spawning servers, `codeDave` for code servers.
30
- - **Agent Scripts**: Specialized agents for code, docs, npm, todo, readme, memory, and more.
31
- - **WebSocket Support**: Connect to remote agent servers for interactive or one-shot interactions.
32
- - **Toolsets**: Built-in tools for search, file I/O, email, and custom toolcalls.
33
- - **Music Toolsets**: Dedicated Stability AI (Stable Audio 3) and Minimax (Music 2.6/Cover) toolsets for text-to-music, audio transformation, inpainting, covers, lyrics, and more. See [docs/music-toolsets.md](docs/music-toolsets.md) for full details, tools, and agent examples.
34
- - **Session Management**: Cache history, search sessions, reset, and inspect logs.
35
- - **ESM-First**: Modern Node.js modules with TypeScript definitions.
36
- - **Portable Agent Spawning**: `spawn_agent.js` enables creating and deploying agents anywhere (project dirs or fresh `/tmp`). Supports auto-deploy in existing projects (detects `./agents/*.js`), manual code+bash in isolated setups. Tools adapt to CWD for portability. Hybrid modes combine server/client for chaining. See [docs/prompt/spawn_agent.md](docs/prompt/spawn_agent.md) for blueprint and validation.
37
- - **Multi-Agent Clusters**: PM2-powered CodeServer for scalable, clustered agent deployments (e.g., code_agent + todo_agent). Defaults to port 9000/secret '123'. See [docs/multi-agent-clusters.md](docs/multi-agent-clusters.md) for configuration.
38
-
39
- ## Folder Structure
40
-
41
- - **bin/**: Executables for CLI tools.
42
- - `dave.js`: Main CLI for asking agents or connecting to WebSocket servers.
43
- - `spawn_agent.js`: Spawns agent instances (binary: `agentDave`).
44
- - `codeDave`: Launches code servers (via PM2 clusters). References [docs/multi-agent-clusters.md](docs/multi-agent-clusters.md) for setup and scaling.
45
-
46
- - **agents/**: Agent scripts (`*_agent.js`) for specific tasks. These can be run directly with `node agents/<script>.js`.
47
- - `ask_agent.js`: General query agent.
48
- - `code_agent.js`: Code generation and execution agent (serves as main server in code clusters).
49
- - `daisy_agent.js`: Specialized agent (details in script).
50
- - `docs_agent.js`: Documentation-focused agent.
51
- - `gpt_agent.js`: OpenAI GPT integration agent.
52
- - `grok_agent.js`: xAI Grok-specific agent.
53
- - `memory_agent.js`: Agent with enhanced memory and context handling.
54
- - `npm_agent.js`: NPM package management agent.
55
- - `prompt_agent.js`: Prompt engineering and testing agent.
56
- - `readme_agent.js`: README.md management agent.
57
- - `spawn_agent.js`: Agent spawner (also in bin/). Creates portable CLI/WS agents + PM2 launchers. Validates/tests/deploys to `./agents/<name>.js`. Supports hybrid server/client modes. Portable to `/tmp` (tools follow CWD). Blueprint: [docs/prompt/spawn_agent.md](docs/prompt/spawn_agent.md).
58
- - `test_agent.js`: Testing and validation agent.
59
- - `todo_agent.js`: TODO list and task management agent.
60
- - `codeserver.sh`: Shell script for launching PM2-based code server clusters (uses agents above). See [docs/multi-agent-clusters.md](docs/multi-agent-clusters.md).
61
-
62
- - **lib/**: Core library modules (e.g., `index.js`, `wsCli.js`, `wsIO.js`, API integrations).
63
- - **scenarios/**: Test and example scenarios (e.g., toolset tests, integration scripts).
64
- - **types/**: TypeScript definitions.
65
- - **utils/**: Utility scripts (e.g., session management, testing).
66
- - **docs/**: Additional documentation, including agent blueprints (e.g., [prompt/spawn_agent.md](docs/prompt/spawn_agent.md)) and multi-agent guides (e.g., [multi-agent-clusters.md](docs/multi-agent-clusters.md)).
67
- - New: [music-toolsets.md](docs/music-toolsets.md) — Documentation for Stability and Minimax MusicToolsets with usage examples from agents/stability.js and agents/minimax.js.
68
- - **release/**: Build artifacts.
69
-
70
- Other files: `package.json`, `CHANGELOG.md`, `TODO.md`, `LICENSE`.
71
-
72
- ## Installation
73
-
74
- 1. **Prerequisites**: Node.js >= 20. PM2 for multi-agent clusters: `npm install -g pm2`.
75
-
76
- 2. **Local Development**:
77
- ```bash
78
- git clone https://codeberg.org/duin/hello-dave.git
79
- cd hello-dave
80
- npm install
81
- ```
82
-
83
- 3. **Global CLI Installation** (for `dave`, `agentDave`, `codeDave`):
84
- ```bash
85
- npm install -g .
86
- # Or link for dev: npm run link-self
87
- ```
88
-
89
- 4. **API Keys**: Set environment variables (e.g., `XAIKEY` for xAI, `OPENAI_API_KEY` for OpenAI).
90
-
91
- ## Usage
92
-
93
- ### CLI Tools
94
-
95
- - **dave**: Interact with agents locally or remotely.
96
- - Local query: `dave --ask "Predict the weather"`
97
- - One-shot remote: `echo "Hello" | dave --connect 'ws://127.0.0.1:8080' --secret '123'`
98
- - Interactive remote: `dave --connect 'ws://127.0.0.1:8080' --secret '123'`
99
- - Other: `dave --list` (sessions), `dave --clear` (cache), `dave --help`.
100
-
101
- - **agentDave**: Spawn an agent server (powered by `spawn_agent.js`).
102
- ```bash
103
- agentDave --serve 8080 --secret '123' # Starts WebSocket server
104
- ```
105
-
106
- - **codeDave**: Launch a PM2 code server cluster.
107
- ```bash
108
- codeDave 8080 --secret '123' # Or: dave --code 8080 --secret '123'
109
- ```
110
-
111
- ### Running Agents
112
-
113
- Run agent scripts directly:
7
+
8
+ **'Hello, Dave.'** — A calm, reliable ESM toolkit for building and running AI agents with unified access to Grok (xAI), OpenAI, and Anthropic.
9
+
10
+ ## Quick Start
11
+
12
+ ```bash
13
+ npm install -g @j-o-r/hello-dave
14
+
15
+ dave --help
16
+ dave --list-agents
17
+ dave ask_agent
18
+ dave code_agent "Refactor lib/Session.js"
19
+ echo "Explain this error" | dave ask_agent
20
+ ```
21
+
22
+ ## Core Usage
23
+
114
24
  ```bash
115
- node agents/spawn_agent.js --serve 8080 --secret '123' # Spawn server
116
- node agents/code_agent.js --connect 'ws://127.0.0.1:8080' --secret '123' # Client mode
25
+ dave <agent_name> # interactive
26
+ dave <agent_name> "your message" # one-shot
27
+ echo "message" | dave <agent_name>
28
+ dave <agent_name> --info
29
+ dave --list-agents
117
30
  ```
118
31
 
119
- For full options, see script headers or run with `--help`.
32
+ Agents are `*_agent.js` files discovered via `AgentLauncher`.
33
+
34
+ ## Agent Handoffs (Current Multi-Agent Model)
35
+
36
+ Use the built-in `hand_over` / `load_agent` tools for clean in-process delegation to specialists (or self-reset with fresh context).
37
+
38
+ - Always fresh: target gets only its own system prompt + short task-focused context.
39
+ - No history is copied.
40
+ - Use `list_agents` first when unsure.
41
+
42
+ This replaced the older WebSocket server/client/swarm/CodeServer model (which has been abandoned).
43
+
44
+ See `docs/creating-agents.md` for details.
120
45
 
121
- ### Programmatic Usage
46
+ ## Creating Agents
122
47
 
123
- Import and use in your Node.js app:
124
- ```javascript
125
- import { AgentManager } from '@j-o-r/hello-dave';
126
- // Setup and run agent...
48
+ ```bash
49
+ dave agent_creator "Create a weather_agent..."
50
+ dave agent_creator "Improve code_agent..."
127
51
  ```
128
52
 
129
- ### spawn_agent.js Specifics (v0.0.8 Portability Ready)
130
-
131
- `spawn_agent.js` (executable as `agentDave`) creates and deploys portable agents in CLI, WebSocket server, client, or **hybrid** modes (server + client for tool chaining). It fetches live prompts from [docs/prompt/spawn_agent.md](docs/prompt/spawn_agent.md) and validates new agents via blueprint (temp files, syntax checks, grep for modes/tools).
132
-
133
- - **Modes**:
134
- - **Direct (One-Shot)**: Positional input, e.g., `node agents/spawn_agent.js "Create a tester"`.
135
- - **Interactive CLI**: No input; runs REPL-like session.
136
- - **Server**: `--serve <port>` – Exposes as remote tool (e.g., for other agents to call `spawn_agent`).
137
- - **Client**: `--connect <ws_url>` – Connects to remote server for tool access.
138
- - **Hybrid**: `--serve <port> --connect <ws_url>` – Serves locally while using remote tools.
139
-
140
- - **Portability**:
141
- - **In Project**: Auto-deploys to `./agents/<name>.js` if `./agents/*.js` exist (uses existing structure).
142
- - **Fresh /tmp**: Manual code generation + bash setup (e.g., `mkdir /tmp/myproj/agents; cd /tmp/myproj; node spawn_agent.js ...`). Tools (e.g., `read_file`) follow CWD, ensuring isolation without fixed paths.
143
- - Works in any dir; no repo deps beyond Node.js + npm installs.
144
-
145
- - **Custom Tools**: Specify in prompt, e.g., "name=coderev, tools=read_file,web_search,execute_bash_script".
146
-
147
- For validation/testing: See blueprint in [docs/prompt/spawn_agent.md](docs/prompt/spawn_agent.md) (includes bash examples like `node agents/NEW_AGENT.js --help` or server connect tests).
148
-
149
- ### CodeServer & PM2 Multi-Agent (v0.0.8)
150
-
151
- CodeServer (via `bin/codeDave` or `agents/codeserver.sh`) launches scalable, PM2-clustered multi-agent environments for collaborative tasks (e.g., code generation + task management). It deploys agents like `code_agent`, `todo_agent`, and `readme_agent` on a WebSocket server, enabling chaining and load balancing.
152
-
153
- - **Defaults**: Port 9000, secret '123' (customizable via args).
154
- - **Prerequisites**: Install PM2 globally (`npm install -g pm2`).
155
- - **Quickstart**:
156
- ```bash
157
- codeDave 9000 --secret 123 # Launches PM2 cluster on ws://127.0.0.1:9000/ws
158
- pm2 list # Verify processes (e.g., code_agent, todo_agent instances)
159
- echo "task" | bin/dave.js --connect ws://127.0.0.1:9000/ws --secret 123 # One-shot query to cluster
160
- ```
161
- This starts the cluster, lists running agents, and sends a test task (response routed to available agents).
162
-
163
- - **Scaling & Management**: Use PM2 commands (e.g., `pm2 scale <app> 4`, `pm2 stop all`). For ecosystem config, PM2 JSON files, or agent orchestration, see the [full guide in docs/multi-agent-clusters.md](docs/multi-agent-clusters.md).
164
-
165
- - **Integration**: Combine with `spawn_agent.js` for dynamic agent addition to clusters (e.g., spawn new agents and connect via `--connect ws://127.0.0.1:9000/ws`).
166
-
167
- ## Usage Examples
168
-
169
- - **Direct Spawn (Project)**:
170
- ```bash
171
- cd hello-dave # Or any project with ./agents/
172
- node agents/spawn_agent.js "Create code-review agent: name=coderev, desc=Git diff analyzer, tools=read_file,execute_bash_script,web_search"
173
- # Deploys to ./agents/coderev_agent.js; test: node agents/coderev_agent.js "Review this diff"
174
- ```
175
-
176
- - **/tmp Workflow (Portable, Fresh Setup)**:
177
- ```bash
178
- mkdir -p /tmp/myportable/agents
179
- cd /tmp/myportable
180
- # Copy or fetch spawn_agent.js (e.g., curl from repo or npm install @j-o-r/hello-dave)
181
- npm init -y && npm i @j-o-r/hello-dave @j-o-r/sh
182
- node spawn_agent.js "Create todo agent: name=todo, desc=Task manager, tools=read_file,write_file"
183
- # Deploys to ./agents/todo_agent.js; tools use /tmp/myportable as CWD
184
- node agents/todo_agent.js --serve 8081 --secret abc # Test server mode
185
- ```
186
-
187
- - **Hybrid Mode with Custom Tools**:
188
- ```bash
189
- node agents/spawn_agent.js --serve 8081 --connect ws://127.0.0.1:8080/ws --secret abc "Spawn a docs agent with custom email tool"
190
- # Serves on 8081 (exposes new agent), connects to 8080 (gains remote tools like email)
191
- # Test: In another term, node agents/spawn_agent.js --connect ws://127.0.0.1:8081/ws --secret abc "Use the new docs agent"
192
- ```
193
-
194
- - **Spawn a Server**:
195
- ```bash
196
- node agents/spawn_agent.js --serve 8080 --secret '123'
197
- # Then connect: echo "Task" | dave --connect 'ws://127.0.0.1:8080' --secret '123'
198
- ```
199
-
200
- - **Launch Code Cluster** (includes multiple agents):
201
- ```bash
202
- node agents/codeserver.sh 9000 '123' # Or use codeDave 9000 --secret 123
203
- # Connects code_agent, todo_agent, readme_agent, etc., to the server on ws://127.0.0.1:9000/ws.
204
- # Test: pm2 list; echo "Optimize this code" | dave --connect ws://127.0.0.1:9000/ws --secret 123
205
- # For advanced config: See [docs/multi-agent-clusters.md](docs/multi-agent-clusters.md).
206
- ```
207
-
208
- - **Local Agent Query** (no server):
209
- ```bash
210
- dave --ask --model 'grok-4-1-fast-reasoning' "Write a function"
211
- ```
212
-
213
- - **Custom Agent**:
214
- ```bash
215
- node agents/docs_agent.js --connect 'ws://127.0.0.1:8080' --secret '123'
216
- ```
217
-
218
- See `scenarios/` for more test scenarios.
53
+ **Follow the current standard**: [docs/creating-agents.md](docs/creating-agents.md)
219
54
 
220
- ## Development
55
+ Key pattern:
56
+ - `export default agent;`
57
+ - `new Agent({ prompt, api, call_name, call_description, ... })`
58
+ - Register tools + `toolset.borrow(API.toolset.generic.handoff)`
59
+
60
+ ## Documentation
61
+
62
+ - **[docs/creating-agents.md](docs/creating-agents.md)** — Canonical guide (read this first for agent work).
63
+ - `docs/bin-dave.md`
64
+ - `docs/project-overview.md`
65
+ - `docs/docs-organization.md`
66
+ - `docs/toolset.md` etc.
221
67
 
222
- - **Build Types**: `npm run types`
223
- - **Test**: `npm run tests` (runs `utils/test.sh`)
224
- - **Release**: `npm run release` then `npm run publish`
225
- - **Local Linking**: `npm run link-self` / `npm run unlink-self`
68
+ **Legacy docs** (old WS/swarm/CodeServer patterns) live in `docs/_legacy/`. They are retained for historical reference only.
226
69
 
227
- Use `git status` and `ls` to inspect changes. Ensure ESM compatibility.
70
+ ## Programmatic Usage
228
71
 
229
- ## Contributing
72
+ ```js
73
+ import { Agent, API, AgentLauncher } from '@j-o-r/hello-dave';
230
74
 
231
- Contributions welcome! Fork the repo, create a branch, and submit a pull request to https://codeberg.org/duin/hello-dave.
75
+ const agent = new Agent({
76
+ prompt: "...",
77
+ api: API.chat.xai,
78
+ call_name: 'my_agent',
79
+ call_description: '...'
80
+ });
232
81
 
233
- - Report bugs: https://codeberg.org/duin/hello-dave/issues
234
- - Follow Apache-2.0 license.
82
+ const launcher = new AgentLauncher();
83
+ await launcher.load('code_agent');
84
+ await launcher.run();
85
+ ```
86
+
87
+ ## Development
88
+
89
+ ```bash
90
+ npm install
91
+ npm run link-self
92
+ ```
235
93
 
236
94
  ## License
237
95
 
238
- This project is licensed under the Apache-2.0 License - see the [LICENSE](LICENSE) file for details.
96
+ Apache-2.0
97
+
98
+ Repository: https://codeberg.org/duin/hello-dave
239
99
 
240
100
  ---
241
- *Repository: https://codeberg.org/duin/hello-dave*
242
- ---
101
+
102
+ *Putting itself to the fullest possible use.*
package/TODO.md CHANGED
@@ -1,35 +1,173 @@
1
- ## High Priority Pending
2
- - [ ] 2026-05-04: Create simple event-based unified WebSocket architecture. Remove complicated streaming plan. Focus on live reasoning in CLI/WS, unify user/agent client handling in AgentServer.js, make Prompt events broadcast consistently to user WS connections. Make code more readable and logical. Reference: docs/plans/simple-event-driven-websocket.md.
3
- - [ ] Review current WebSocket protocol and Prompt event emitters.
4
- - [ ] In AgentServer.js: Centralize event listeners for Prompt, add unified broadcast method for user WS, unify user/agent client handling.
5
- - [ ] Update lib/wsIO.js for CLI to handle events similarly to WS.
6
- - [ ] Refactor code for readability and logical flow.
7
- - [ ] Test end-to-end: Event flow from Prompt to user display in CLI and WS.
8
- - [ ] Update docs/websocket-protocol.md with new architecture.
9
-
10
- - [ ] 2026-05-04: Implement unified lib/Agent.js that treats users and agents symmetrically. Key rules: No 'final response' concept. Use Prompt 'ready' event as completion signal. Agents can send 'function_call' requests to user connections (user acts as expert/tool). Update message protocol to be fully event-driven with 'ready' as end marker. Reference: docs/plans/unified-agent-architecture.md.
11
- - [ ] Review current Agent.js, AgentServer.js, and Prompt event system.
12
- - [ ] Refactor lib/Agent.js to unify user and agent handling: shared methods for event emission, listening, and protocol adherence.
13
- - [ ] Integrate Prompt 'ready' event as the primary completion hook across agents and user interactions.
14
- - [ ] Add support for agents to emit 'function_call' events to user WS connections.
15
- - [ ] Update message protocol: Define event types, ensure 'ready' is broadcast consistently.
16
- - [ ] Test symmetry: Verify bidirectional flows (agent-to-user function calls, user-to-agent events) in CLI/WS.
17
- - [ ] Document in docs/websocket-protocol.md and update any related docs.
18
-
19
- ## Prompt & Agent Quality (High Priority)
20
- - [ ] 2026-04-25: Review all prompts (in agents, spawn_agent, memory protocol, etc.) to prevent over-complicating implementations by adding unrequested requirements (e.g. backward compatibility when user explicitly says the project is BETA v0.0.x and does not need it).
21
-
22
- ## Multi-modal
23
- - [ ] 2026-04-25: Implement multi-modal (audio, images, video) capabilities to the CLI.
24
-
25
- ## Agent Improvements
26
- - [ ] 2026-04-25: Teach/instruct the spawn_agent to test and improve agents in a 'server' setting.
27
-
28
- ## Input Handling
29
- - [ ] 2026-04-25: Create a 'smart' pre-evaluation agent that assesses user input for clarity before the main agent starts work. It should check: Is the task clear? Are the necessary tools present? Guess context from previous messages if input seems incomplete (e.g. accidental early enter).
30
-
31
- ## API Capabilities
32
- - [ ] 2026-04-25: Ensure 'hello-dave' is fully capable of implementing/improving other APIs following the exact structure and patterns of this project (tools, agents, memory protocol, etc.).
33
-
34
- ## Done
35
- (none - all archived to docs/todo-archive-v0.1.0.md on 2026-04-24)
1
+ # TODO
2
+
3
+ [ ] [investigate openshell](https://docs.nvidia.com/openshell/about/overview)
4
+
5
+ ## Agent Loader Review Follow-up (`lib/agentLoader.js`) TODO
6
+
7
+ Context: Review of `lib/agentLoader.js` identified several correctness and maintainability issues around agent instance freshness, discovery side effects, path containment, and API/schema consistency.
8
+
9
+ ### Priority 1 — Fresh agent instances for handoff/reset correctness
10
+
11
+ **Problem**:
12
+ - `loadAgent()` imports ESM modules directly and returns singleton default exports as-is.
13
+ - Because ESM modules are cached, repeated loads of singleton-exported agents return the same object.
14
+ - This conflicts with the intended fresh handoff / self-reset behavior in `AgentLauncher`.
15
+ - Verified behavior during review:
16
+ - `loadAgent('echo_agent')` twice returned the same object.
17
+ - Both calls shared the same prompt and session objects.
18
+
19
+ **Tasks**:
20
+ - [ ] Decide and document the official agent module contract:
21
+ - Recommended: loadable agents should export a factory that creates a fresh `Agent` instance.
22
+ - Example: `export default function createAgent() { return new Agent(...) }`.
23
+ - Optional named form: `export function createAgent() { ... }`.
24
+ - [ ] Update `lib/agentLoader.js` to prefer fresh factories:
25
+ - [ ] Prefer `mod.createAgent` when present.
26
+ - [ ] Then support function default exports as factories.
27
+ - [ ] Treat singleton object exports as legacy compatibility only.
28
+ - [ ] Decide whether singleton object exports should:
29
+ - [ ] Produce a warning in development / verbose mode, or
30
+ - [ ] Continue silently for backward compatibility, or
31
+ - [ ] Be rejected in a future breaking release.
32
+ - [ ] Update bundled agents that currently export singleton `Agent` instances to export factories instead.
33
+ - [ ] Audit all files in `agents/*.js` and any example/custom agents in docs.
34
+ - [ ] Update documentation in `docs/creating-agents.md` to clearly show the factory export pattern.
35
+ - [ ] Update any README/examples that currently show singleton agent exports.
36
+
37
+ **Suggested tests**:
38
+ - [ ] Add a `node:test` case proving two calls to `loadAgent('some_agent')` return different `Agent` instances.
39
+ - [ ] Add assertions that their prompt/session instances are also distinct where applicable.
40
+ - [ ] Add a regression test for same-agent reset / handoff to confirm no old session object is reused.
41
+
42
+ **Acceptance criteria**:
43
+ - [ ] Repeated `loadAgent(name)` calls produce fresh instances for factory-based agents.
44
+ - [ ] Same-agent handoff/reset does not reuse the previous `Agent`, `Prompt`, or `Session` object.
45
+ - [ ] Legacy singleton behavior, if retained, is explicitly documented as non-fresh.
46
+
47
+ ### Priority 2 — Make `listAgents()` side-effect-light
48
+
49
+ **Problem**:
50
+ - `listAgents()` currently imports candidate agent modules and may call exported functions to get descriptions.
51
+ - This can execute top-level module code, construct full agents, run top-level await, perform I/O, hang, or seed the ESM module cache before actual loading.
52
+ - Discovery should ideally be cheap and not instantiate agents.
53
+
54
+ **Tasks**:
55
+ - [ ] Define a lightweight metadata contract for agent descriptions.
56
+ - Recommended exports:
57
+ - `export const call_description = '...'`
58
+ - `export const description = call_description`
59
+ - [ ] Update `listAgents()` so it reads exported metadata without calling agent factories.
60
+ - [ ] Avoid invoking default exports during discovery.
61
+ - [ ] Decide fallback behavior when metadata is missing:
62
+ - [ ] Return `[NO DESCRIPTION]`, or
63
+ - [ ] Return `[ERROR]`, or
64
+ - [ ] Use filename-derived fallback text.
65
+ - [ ] Update bundled agents to export metadata constants directly.
66
+ - [ ] Update docs to tell agent authors that descriptions used by `dave --agents` / `list_agents` must be exported as metadata.
67
+
68
+ **Suggested tests**:
69
+ - [ ] Add a fixture agent whose factory throws if called.
70
+ - [ ] Confirm `listAgents()` still lists it from metadata without calling the factory.
71
+ - [ ] Add a fixture with top-level metadata and ensure the listed description matches exactly.
72
+ - [ ] Add a fixture with missing metadata and verify the selected fallback behavior.
73
+
74
+ **Acceptance criteria**:
75
+ - [ ] `listAgents()` does not call agent factories.
76
+ - [ ] Discovery remains fast and predictable.
77
+ - [ ] Listing agents does not accidentally create or cache live agent instances.
78
+
79
+ ### Priority 3 — Harden name-based path resolution against symlink escapes
80
+
81
+ **Problem**:
82
+ - Direct path loading performs realpath/root containment checks.
83
+ - Name-based resolution currently checks readability of candidate files but does not apply equivalent realpath containment validation.
84
+ - A symlink inside an allowed agent directory could point outside the intended search roots and still be imported.
85
+
86
+ **Tasks**:
87
+ - [ ] Add shared helper logic for path containment checks so direct-path and name-based loading use the same security rule.
88
+ - [ ] Realpath each configured agent directory once where practical.
89
+ - [ ] When resolving by agent name, verify the resolved candidate file is inside one of the allowed real agent directories.
90
+ - [ ] Decide whether symlinked files inside the allowed tree are permitted when their real target also remains inside an allowed root.
91
+ - [ ] Improve error messages for symlink escape attempts.
92
+
93
+ **Suggested tests**:
94
+ - [ ] Add a temporary test fixture with an agent symlink that points outside the allowed agent directory.
95
+ - [ ] Confirm `loadAgent(name)` rejects the symlink escape.
96
+ - [ ] Add a positive test for a normal in-tree agent.
97
+ - [ ] If in-tree symlinks are allowed, add a positive test for a symlink whose real target remains inside the allowed root.
98
+
99
+ **Acceptance criteria**:
100
+ - [ ] Name-based loading cannot import files outside configured agent roots via symlinks.
101
+ - [ ] Direct-path and name-based resolution enforce consistent containment semantics.
102
+
103
+ ### Priority 4 — Align agent-name validation rules across loader and handoff tool schema
104
+
105
+ **Problem**:
106
+ - `lib/agentLoader.js` allows names matching `^[a-z0-9_]{2,}$`.
107
+ - `lib/handOffToolset.js` advertises `^[a-z0-9_]{2,64}$`.
108
+ - This means some names are loadable/discoverable but cannot be called through `hand_over` / `load_agent`.
109
+
110
+ **Tasks**:
111
+ - [ ] Centralize the public agent-name regex in a shared module or exported constant.
112
+ - [ ] Decide the canonical limit; recommended: `^[a-z0-9_]{2,64}$`.
113
+ - [ ] Update `lib/agentLoader.js` to use the shared rule.
114
+ - [ ] Update `lib/handOffToolset.js` to use the same source of truth or generate the schema pattern from it.
115
+ - [ ] Update docs for allowed agent names.
116
+
117
+ **Suggested tests**:
118
+ - [ ] Add tests for too-short, valid, invalid-character, and too-long agent names.
119
+ - [ ] Confirm loader and handoff schema accept/reject the same examples.
120
+
121
+ **Acceptance criteria**:
122
+ - [ ] There is one canonical public agent-name rule.
123
+ - [ ] Loader behavior and tool schema behavior are consistent.
124
+
125
+ ### Priority 5 — Clarify or improve direct relative path resolution
126
+
127
+ **Problem**:
128
+ - Direct relative paths are currently resolved against `process.cwd()`.
129
+ - That is reasonable for CLI use, but may surprise callers using `createAgentLoader({ from: import.meta.url })`, who may expect relative paths to resolve from the caller package root.
130
+
131
+ **Tasks**:
132
+ - [ ] Decide whether direct relative paths should remain CWD-relative or become caller-package-root-relative when `from` is provided.
133
+ - [ ] If keeping current behavior:
134
+ - [ ] Document clearly that direct relative paths are always CWD-relative.
135
+ - [ ] Add tests proving that behavior.
136
+ - [ ] If changing behavior:
137
+ - [ ] Resolve relative direct paths from the `from` package root when provided.
138
+ - [ ] Preserve current CLI behavior where no `from` is provided.
139
+ - [ ] Add migration notes for any compatibility impact.
140
+
141
+ **Suggested tests**:
142
+ - [ ] Add tests for direct relative path loading from the project CWD.
143
+ - [ ] Add tests for `createAgentLoader({ from: import.meta.url })` from a nested fixture package.
144
+ - [ ] Add tests for invalid relative direct paths and outside-root attempts.
145
+
146
+ **Acceptance criteria**:
147
+ - [ ] Path resolution behavior is intentional, documented, and covered by tests.
148
+
149
+ ### Priority 6 — Documentation and examples cleanup
150
+
151
+ **Tasks**:
152
+ - [ ] Update agent creation docs to show fresh factory exports and metadata exports together.
153
+ - [ ] Include a minimal recommended agent template:
154
+ - [ ] `export const call_description = '...'`
155
+ - [ ] `export const description = call_description`
156
+ - [ ] `export default function createAgent() { return new Agent(...) }`
157
+ - [ ] Add a short compatibility note for legacy singleton exports if they remain supported.
158
+ - [ ] Update CLI/help docs that mention `list_agents`, `hand_over`, or agent naming constraints.
159
+ - [ ] Add a short security note about agent path resolution and symlink containment.
160
+
161
+ ### Priority 7 — Validation checklist after implementation
162
+
163
+ Run and record results for the following after changes are made:
164
+
165
+ - [ ] `node --check lib/agentLoader.js`
166
+ - [ ] `node --check lib/handOffToolset.js`
167
+ - [ ] Project test script from `package.json`, if available.
168
+ - [ ] Focused `node:test` suite for agent loader behavior.
169
+ - [ ] Manual smoke test:
170
+ - [ ] `dave --agents` or equivalent listing command.
171
+ - [ ] Load the same factory-based agent twice and confirm fresh objects.
172
+ - [ ] Trigger same-agent handoff/reset and confirm the old session object is not reused.
173
+