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

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 (127) hide show
  1. package/CHANGELOG.md +13 -26
  2. package/README.md +161 -522
  3. package/README.md.bak +144 -449
  4. package/{examples → agents}/ask_agent.js +5 -5
  5. package/{examples → agents}/codeserver.sh +14 -14
  6. package/{examples → agents}/daisy_agent.js +5 -5
  7. package/{examples → agents}/docs_agent.js +5 -5
  8. package/{examples → agents}/gpt_agent.js +5 -5
  9. package/{examples → agents}/grok_agent.js +5 -5
  10. package/agents/memory_agent.js +263 -0
  11. package/{examples → agents}/npm_agent.js +5 -5
  12. package/{examples → agents}/prompt_agent.js +5 -5
  13. package/agents/spawn_agent.js +137 -0
  14. package/{examples → agents}/test_agent.js +6 -8
  15. package/{examples → agents}/todo_agent.js +5 -5
  16. package/bin/codeDave +58 -0
  17. package/bin/dave.js +114 -96
  18. package/lib/AgentClient.js +111 -67
  19. package/lib/AgentManager.js +111 -80
  20. package/lib/AgentServer.js +144 -104
  21. package/lib/Cli.js +126 -93
  22. package/lib/Prompt.js +38 -5
  23. package/lib/Session.js +102 -79
  24. package/lib/ToolSet.js +79 -60
  25. package/lib/fafs.js +54 -19
  26. package/lib/genericToolset.js +109 -213
  27. package/lib/wsCli.js +50 -19
  28. package/lib/wsIO.js +11 -17
  29. package/package.json +2 -2
  30. package/types/AgentClient.d.ts +69 -35
  31. package/types/AgentManager.d.ts +50 -56
  32. package/types/AgentServer.d.ts +63 -16
  33. package/types/Cli.d.ts +56 -10
  34. package/types/Prompt.d.ts +36 -4
  35. package/types/Session.d.ts +23 -9
  36. package/types/ToolSet.d.ts +49 -32
  37. package/types/fafs.d.ts +68 -25
  38. package/types/wsCli.d.ts +14 -0
  39. package/types/wsIO.d.ts +9 -5
  40. package/utils/search_sessions.sh +100 -53
  41. package/README.md.backup +0 -269
  42. package/README.md.bak.1774780058 +0 -338
  43. package/README.md.bak2 +0 -531
  44. package/bin/spawn_agent.js +0 -293
  45. package/docs.bak.1774780058/agent-manager.md +0 -167
  46. package/docs.bak.1774780058/agent-manager.md.bak +0 -137
  47. package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
  48. package/docs.bak.1774780058/codeserver-pattern.md +0 -191
  49. package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
  50. package/docs.bak.1774780058/project-overview.md +0 -67
  51. package/docs.bak.1774780058/project-overview.md.bak +0 -67
  52. package/docs.bak.1774780058/prompt-class.md +0 -141
  53. package/docs.bak.1774780058/prompt-class.md.bak +0 -142
  54. package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
  55. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
  56. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
  57. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
  58. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
  59. package/docs.bak.1774780058/toolset.md +0 -164
  60. package/docs.bak.1774780058/toolset.md.bak +0 -94
  61. package/docs.bak.1774780058/toolset.md.bak3 +0 -161
  62. package/docs.bak.1774780058/toolset.md.bak4 +0 -161
  63. package/docs.bak.1774780058/toolset.md.bak5 +0 -161
  64. package/docs.bak.1774780058/toolset.md.bak6 +0 -163
  65. package/docs.bak.1774780058/toolset.md.bak_path +0 -163
  66. package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
  67. package/docs.bak.1774780058/xai-responses.md +0 -111
  68. package/docs.bak.1774780058/xai-responses.md.bak +0 -107
  69. package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
  70. package/docs.bak.1774780058/xai_collections.md +0 -106
  71. package/examples/memory_agent.js +0 -152
  72. package/examples.bak.1774780058/ask_agent.js +0 -114
  73. package/examples.bak.1774780058/code_agent.js +0 -149
  74. package/examples.bak.1774780058/coderev_agent.js +0 -72
  75. package/examples.bak.1774780058/codeserver.sh +0 -47
  76. package/examples.bak.1774780058/daisy_agent.js +0 -177
  77. package/examples.bak.1774780058/docs_agent.js +0 -119
  78. package/examples.bak.1774780058/gpt_agent.js +0 -109
  79. package/examples.bak.1774780058/grok_agent.js +0 -98
  80. package/examples.bak.1774780058/memory_agent.js +0 -112
  81. package/examples.bak.1774780058/npm_agent.js +0 -175
  82. package/examples.bak.1774780058/prompt_agent.js +0 -112
  83. package/examples.bak.1774780058/readme_agent.js +0 -144
  84. package/examples.bak.1774780058/spawn_agent.js +0 -263
  85. package/examples.bak.1774780058/test_agent.js +0 -162
  86. package/examples.bak.1774780058/todo_agent.js +0 -138
  87. package/lib/genericToolset.js.bak_syntax +0 -402
  88. package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
  89. package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
  90. package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
  91. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
  92. package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
  93. package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
  94. package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
  95. package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
  96. package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
  97. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
  98. package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
  99. package/scenarios.bak.1774780058/environment.js +0 -10
  100. package/scenarios.bak.1774780058/example.js +0 -17
  101. package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
  102. package/scenarios.bak.1774780058/grok.js +0 -113
  103. package/scenarios.bak.1774780058/memory-tools.js +0 -51
  104. package/scenarios.bak.1774780058/openai-o3.js +0 -137
  105. package/scenarios.bak.1774780058/openai-prompt.js +0 -155
  106. package/scenarios.bak.1774780058/openai-session.js +0 -148
  107. package/scenarios.bak.1774780058/openai.js +0 -102
  108. package/scenarios.bak.1774780058/prompt.js +0 -118
  109. package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
  110. package/scenarios.bak.1774780058/search.brave.com.js +0 -25
  111. package/scenarios.bak.1774780058/sh.js +0 -15
  112. package/scenarios.bak.1774780058/test-wsio.js +0 -26
  113. package/scenarios.bak.1774780058/testToolset.js +0 -42
  114. package/scenarios.bak.1774780058/toolset.js +0 -16
  115. package/scenarios.bak.1774780058/toolset.test.js +0 -141
  116. package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
  117. package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
  118. package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
  119. package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
  120. package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
  121. package/scenarios.bak.1774780058/wsClient.js +0 -69
  122. package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
  123. package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
  124. package/scenarios.bak.1774780058/xaicoll.js +0 -50
  125. package/scenarios.bak.1774780058/xaifiles.js +0 -48
  126. /package/{examples → agents}/code_agent.js +0 -0
  127. /package/{examples → agents}/readme_agent.js +0 -0
@@ -1,293 +0,0 @@
1
- #!/usr/bin/env node
2
- import { AgentManager } from '@j-o-r/hello-dave';
3
- import { parseArgs } from '@j-o-r/sh';
4
-
5
- const name = 'spawn_agent';
6
- const api = 'xai';
7
- let secret = '';
8
-
9
- const args = parseArgs();
10
-
11
- let input; // Directcall input (positional ONLY - NO pipe)
12
- if (args._.length === 1 && typeof args._[0] === 'string' && args._[0].trim() !== '') {
13
- input = args._[0].trim();
14
- }
15
-
16
- const help = args['help'] || false;
17
- const connect = args['connect'] ? args['connect'] : undefined;
18
- const serve = args['serve'] ? parseInt(args['serve']) : undefined;
19
-
20
- /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
21
- const options = { tools: [] };
22
- options.tools.push({
23
- type: 'web_search'
24
- });
25
-
26
- if (args['secret']) {
27
- secret = args['secret'];
28
- }
29
- if (args['model'] || true) {
30
- options.model = args['model'] || 'grok-4-fast-reasoning';
31
- }
32
- if (args['temperature']) {
33
- options.temperature = parseFloat(args['temperature']);
34
- }
35
- if (args['tokens']) {
36
- options.max_output_tokens = parseInt(args['tokens']);
37
- }
38
- if (args['top_p']) {
39
- options.top_p = parseFloat(args['top_p']);
40
- }
41
- const reasoning = true;
42
- if (reasoning) {
43
- options.reasoning = {
44
- effort: 'medium',
45
- summary: 'auto'
46
- }
47
- }
48
- const toolsetMode = 'auto';
49
- const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
50
-
51
- function printHelp() {
52
- console.log(`
53
- '${name} --help' You are looking at it.
54
-
55
- ## USAGE MODES:
56
-
57
- ### 1. Direct Call (One-Shot, Positional ONLY):
58
- ./examples/${name}.js "Create a code agent" [--options]
59
-
60
- ### 2. Interactive CLI (no positional arg):
61
- ./examples/${name}.js [--options]
62
-
63
- ### 3. WS Server (no positional arg):
64
- ./examples/${name}.js --serve 8080 [--secret mysecret] [--options]
65
-
66
- ### 4. WS Client (no positional arg):
67
- ./examples/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
68
-
69
- ### 5. Hybrid (Server + Client, no positional arg):
70
- ./examples/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
71
-
72
- ## SERVER OPTIONS EXPLAINED:
73
- --serve [port]: Starts WebSocket SERVER at ws://127.0.0.1:[port]/ws. Allows other agents (--connect) to connect and use this agent as a remote TOOL (e.g., 'spawn_agent'). Runs indefinitely until Ctrl+C.
74
-
75
- --connect [ws_url]: Connects as CLIENT to remote WS server at [ws_url] (e.g., ws://127.0.0.1:8080/ws). Gains access to remote agent's tools. Interactive CLI available.
76
-
77
- --secret [string]: SHARED AUTH TOKEN (min 3 chars). SERVER rejects clients without matching --secret. CLIENTS must provide server's secret to connect. Use same secret for chains.
78
-
79
- Note: Server/Client/Hybrid IGNORES positional input arg (use CLI modes instead). Hybrid: This agent serves AND uses remote tools.
80
-
81
- ## OPTIONS:
82
- --model [grok-4-fast-reasoning|...] (default: grok-4-fast-reasoning)
83
- --temperature [float] (-2 to +2)
84
- --tokens [number] (max output tokens)
85
- --top_p [float]
86
- --context [number] (default: 250000)
87
-
88
- ## SERVER TOOLS (when no input):
89
- Exposes as 'spawn_agent' tool for chaining.
90
- `);
91
- process.exit()
92
- }
93
-
94
- if (help) {
95
- printHelp();
96
- }
97
-
98
- const tool_call_name = 'spawn_agent';
99
- const tool_call_description = `
100
- Portable creator for CLI/WS agents (bin/<name>.js) + PM2 multi-agent launchers. Validates/tests/deploys. No local docs needed.
101
- `.trim();
102
-
103
- const REPO_URL = 'https://codeberg.org/duin/hello-dave';
104
- const DOCS_BASE = `${REPO_URL}/src/branch/main/docs/`;
105
- const EXAMPLES_URL = `${REPO_URL}/src/branch/main/examples/`;
106
-
107
- const promptParts = [
108
- 'You are AgentCreator, expert in @j-o-r/hello-dave. Create production-ready CLI agents (bin/<name>.js) **portably** anywhere (no local docs needed).',
109
- '',
110
- '**AGENT NAME RULE ⚠️**: name MUST be lowercase a-z0-9_ min 2 chars (/^[a-z_0-9_]{2,}$/). EX: myagent, codeagent, ws_tool.',
111
- '',
112
- '**IMPORTS CRITICAL ⚠️**: **NAMED imports ONLY** - NO default! `import { AgentManager } from \'@j-o-r/hello-dave\';` `import { parseArgs } from \'@j-o-r/sh\';`',
113
- '',
114
- '**PORTABILITY**: Auto-install deps: `@j-o-r/hello-dave @j-o-r/sh`. Absolute imports. NO local file refs (docs/examples).',
115
- '',
116
- '**MANDATORY MEMORY PROTOCOL (For EVERY query/task - NO EXCEPTIONS):**',
117
- 'Connected clients (todo_agent, readme_agent, npm_agent, docs_agent, **memory_agent**) are available as tools. **ALWAYS** use **memory_agent** FIRST and LAST:',
118
- '1. **RECALL PHASE (Step 1 of EVERY response)**:',
119
- ' - Call `memory_agent "Recall relevant memories: tasks, errors, prefs for [keywords from user query]. List recent if empty."`',
120
- ' - Incorporate recalled info (e.g., avoid known errors, resume tasks, apply prefs like temp=0.2).',
121
- '2. **CORE ACTION**:',
122
- ' - Perform coding assistance (tools: execute_bash_script, javascript_interpreter, read_file/write_file, web_search, etc.).',
123
- ' - Delegate to specialists if relevant:',
124
- ' - todo_agent: Tasks/TODO.md',
125
- ' - readme_agent: README.md',
126
- ' - npm_agent: NPM modules/package.json',
127
- ' - docs_agent: Documentation',
128
- ' - memory_agent: Persistent storage',
129
- '3. **WRITE PHASE (Step 3 of EVERY response)**:',
130
- ' - Call `memory_agent "Store updates: [new tasks/errors/prefs/decisions from this interaction]. E.g., \'Task: [next step]\', \'Error: [issue]\', \'Pref: [setting]\'"`',
131
- ' - This ensures persistence across sessions/agents, prevents loops/token burn.',
132
- '',
133
- '**PRIORITIES**:',
134
- '- Safety: CWD-only, no escapes, validate before write.',
135
- '- Efficiency: Use memories to skip repeats (e.g., "Known error: git conflict → skip").',
136
- '- Step-by-step: Clear responses with code blocks.',
137
- 'FOLLOW MEMORY PROTOCOL RIGIDLY - it\'s how multi-agent coordination works!',
138
- '',
139
- '**INITIAL INSPECT** (execute_bash_script):',
140
- '1. `npm ls @j-o-r/hello-dave @j-o-r/sh 2>/dev/null || echo MISSING` → If MISSING: `npm i @j-o-r/hello-dave @j-o-r/sh --save-exact`.',
141
- '2. `mkdir -p bin examples`.',
142
- '3. `cat package.json` (project name). `ls -la bin/`.',
143
- '',
144
- '**TOOL RULES (CRITICAL - NO MIX)**:',
145
- '- **XAI Natives** (pre-setup): `options.tools.push({ type: \'web_search\' });` etc.',
146
- '- **Generics** (post-setup): `agent.addGenericToolcall(\'read_file\');` w/ `toolsetMode: \'auto\'`.',
147
- 'Default: web_search + execute_bash_script/read_file/write_file.',
148
- '',
149
- '**PROCESS (EXACT)**:',
150
- '1. INSPECT & SETUP.',
151
- '2. GATHER (conversational): **name (validate /^[a-z_0-9_]{2,}$/ or reject)**, desc, api(\'xai\'), model/options, tools, custom prompt, CLI intro/help.',
152
- '3. GENERATE & VALIDATE: Use blueprint. Write temp_validate.js, `node --check temp_validate.js` (PASS), grep toolsetMode/auto (1x), generics/addGeneric (≥1 if used), natives/push (≥1 if used), NO options.tools.function.read_file. rm temp.',
153
- '4. REVIEW: Show ```js``` + "✅ node --check | Tools OK". Edit if needed.',
154
- '5. DEPLOY: `write_file ./bin/${name}.js FULL_CODE`, `chmod +x ./bin/${name}.js`.',
155
- '6. **TEST**: `execute_bash_script \'./bin/${name}.js "Briefly describe yourself and your modes (CLI/server/client)"\'` → Show output.',
156
- '7. **SERVER/CLIENT GUIDE**: "Test server: ./bin/${name}.js --serve 8081 (find free port). Client: echo \'query\' | ./bin/${name}.js --connect ws://localhost:8081/ws --secret SECRET".',
157
- '8. **CodeServer MULTI-AGENT**: If requested (e.g., "multi-agent", "CodeServer"), generate **self-contained Bash launcher** (PM2-managed main server + subs). Write to examples/<Name>Server (e.g., examples/CodeServer). Use blueprint below. PM2: Assume installed (`npm i -g pm2`).',
158
- '',
159
- '**AGENT BLUEPRINT** (COPY/REPLACE - Plain backticks ` NO ESCAPES):',
160
- `\`#!/usr/bin/env node
161
- import { AgentManager } from '@j-o-r/hello-dave';
162
- import { parseArgs } from '@j-o-r/sh';
163
-
164
- const name = 'AGENTNAME'; // ← REPLACE w/ lowercase /^[a-z_0-9_]{2,}$/
165
- const api = 'xai';
166
- let secret = '';
167
-
168
- const args = parseArgs();
169
- const help = args['help'] || false;
170
- const connect = args['connect'] ? args['connect'] : undefined;
171
- const serve = args['serve'] ? parseInt(args['serve']) : undefined;
172
-
173
- const options = { tools: [] };
174
-
175
- // NATIVES HERE e.g. options.tools.push({ type: 'web_search' });
176
-
177
- if (args['secret']) { secret = args['secret']; }
178
- if (args['model'] || true) { options.model = args['model'] || 'grok-4-fast-reasoning'; }
179
- if (args['temperature']) { options.temperature = parseFloat(args['temperature']); } else { options.temperature = 0.8; }
180
- options.reasoning = { effort: 'medium', summary: 'auto' };
181
-
182
- const contextWindow = args['context'] ? parseInt(args['context']) : 500000;
183
- const toolsetMode = 'auto';
184
-
185
- function printHelp() {
186
- console.log(\`AGENTNAME --help: AGENTDESC
187
-
188
- Full modes: CLI, WS Server (--serve), WS Client (--connect), Hybrid.
189
-
190
- Repo docs: https://codeberg.org/duin/hello-dave (agent-manager.md, codeserver-pattern.md).
191
-
192
- USAGE:
193
- ./bin/AGENTNAME # Interactive CLI
194
- echo "query" | ./bin/AGENTNAME # One-shot
195
- ./bin/AGENTNAME --serve 8081 # WS Server
196
- ./bin/AGENTNAME --connect ws://host:8081/ws --secret KEY # WS Client
197
- ./bin/AGENTNAME --serve 8081 --connect ws://other:8080/ws # Hybrid
198
-
199
- OPTIONS: --model ... --secret ...
200
-
201
- EXAMPLES:
202
- Chain: Server A --connect B → delegates to B.
203
- Multi-Agent: Generate/use PM2 launcher (CodeServer pattern).\`);
204
- process.exit();
205
- }
206
-
207
- if (help) printHelp();
208
-
209
- const prompt = \`You are AGENTNAME, AGENTDESC.
210
-
211
- CUSTOMPROMPT\`.trim();
212
-
213
- const agent = new AgentManager({ name, secret });
214
- agent.setup({ prompt, api, options, toolsetMode, contextWindow });
215
-
216
- // GENERICS HERE e.g. agent.addGenericToolcall('execute_bash_script');
217
-
218
- const cliIntro = \`🤖 AGENTNAME ready! Modes: CLI/Server/Client/Hybrid.
219
-
220
- CLIINTRO\`.trim();
221
-
222
- const toolName = 'agent_' + name;
223
- const toolDescription = \`AGENTDESC. Supports WS chaining/multi-agent.\`.trim();
224
-
225
- await agent.start(serve, connect, cliIntro, toolName, toolDescription);\``,
226
- '',
227
- '**CODE_SERVER BLUEPRINT** (Bash for multi-agent - Self-contained, like CodeServer pattern):',
228
- `\`#!/bin/bash
229
- # Portable Multi-Agent Launcher (PM2-managed: main server + subs)
230
- # Run: npm i -g pm2 (once)
231
- if [ $# -lt 1 ] || [ $# -gt 2 ]; then
232
- echo "Usage: $0 <PORT> [SECRET] # PORT:1024-65535, SECRET:>=3 chars (def:123)"
233
- exit 1
234
- fi
235
- PORT="$1"
236
- SECRET="\${2:-123}"
237
- if [ \${#SECRET} -lt 3 ]; then echo "SECRET too short"; exit 1; fi
238
- if ! [[ "$PORT" =~ ^[0-9]+$ ]] || [ "$PORT" -lt 1024 ] || [ "$PORT" -gt 65535 ]; then echo "Bad PORT"; exit 1; fi
239
-
240
- SCRIPT_DIR="\$( cd "\$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
241
- PROJECT_DIR="\$( cd "\$( dirname "\${SCRIPT_DIR}" )" && pwd )"
242
- FOLDER=\$(basename "$PROJECT_DIR")
243
-
244
- echo "Starting <MainAgent>Server on port \${PORT} in '\$FOLDER' w/ SECRET '\$SECRET'..."
245
-
246
- # Cleanup old PM2
247
- pm2 delete "\${FOLDER}_mainagent_\${PORT}" 2>/dev/null || true
248
- pm2 delete "\${FOLDER}_sub1agent_\${PORT}" 2>/dev/null || true # Add per sub
249
- # ... more subs
250
-
251
- # Main server
252
- pm2 start "\${SCRIPT_DIR}/bin/mainagent.js" --name "\${FOLDER}_mainagent_\${PORT}" -- --serve "\${PORT}" --tools javascript --secret "\${SECRET}"
253
- # Subs as clients
254
- pm2 start "\${SCRIPT_DIR}/bin/sub1agent.js" --name "\${FOLDER}_sub1agent_\${PORT}" -- --connect "ws://127.0.0.1:\${PORT}/ws" --secret "\${SECRET}"
255
- # ... more: pm2 start ... sub2agent.js ...
256
-
257
- echo "Processes: pm2 list | grep '\${FOLDER}_\${PORT}'"
258
- echo "Connect: npx @j-o-r/hello-dave dave --connect ws://127.0.0.1:\${PORT}/ws --secret '\${SECRET}'"\``,
259
- '',
260
- 'Enthusiastic, step-by-step. Match portable style. **ALWAYS validate name regex before generate/deploy.** Current date: 2026. Models: grok-4-fast-reasoning/grok-beta. CodeServer pattern: https://codeberg.org/duin/hello-dave/src/branch/main/examples/CodeServer'
261
- ];
262
-
263
- const prompt = promptParts.join('\\n');
264
-
265
- const agent = new AgentManager({ name, secret });
266
- agent.setup({
267
- prompt,
268
- api,
269
- options,
270
- toolsetMode,
271
- contextWindow
272
- });
273
- const toolset = agent.getToolset();
274
- if (toolset) {
275
- agent.addGenericToolcall('execute_bash_script');
276
- agent.addGenericToolcall('read_file');
277
- agent.addGenericToolcall('write_file');
278
- agent.addGenericToolcall('javascript_interpreter');
279
- }
280
- const cliIntro = `🤖 ${name} (${options.model}) ready! (context: ${contextWindow})
281
-
282
- Portable Agent Creator: Builds CLI/WS agents + CodeServer launchers **anywhere** (auto-deps, online docs).
283
-
284
- Examples:
285
- - "Create code-review agent: name=coderev, desc=Git diff analyzer, tools=read_file execute_bash_script web_search"
286
- - "Generate CodeServer launcher for coderev + tododave + npmdave"`.trim();
287
-
288
- if (input) {
289
- const RES = await agent.directCall(input);
290
- console.log(RES);
291
- } else {
292
- await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
293
- }
@@ -1,167 +0,0 @@
1
- # AgentManager (`lib/AgentManager.js`)
2
-
3
- ## Overview
4
- **AgentManager** is the central orchestrator class in the hello-dave framework. It manages agent lifecycle: setup (prompts, API, tools, sessions), execution modes (CLI, direct calls, WebSocket server/client), and tool integration. Designed for simplicity and extensibility, it abstracts LLM providers (`xai`, `gpt`, `claude`), `Prompt.js`, `ToolSet.js`, and `Session.js`.
5
-
6
- **Uses named exports from `lib/index.js` - NO default export.**
7
-
8
- Key Features:
9
- - **Modes**: Interactive CLI, one-shot `directCall`, WS **server** (expose agent as tool), **client** (attach to remote server), hybrid (server + client).
10
- - **Tool Handling**: Pre-configured (`toolsetMode: 'auto'`/`'required'`), generics (`addGenericToolcall`), custom `ToolSet`.
11
- - **Persistence**: Sessions in `.cache/[name]/` (NDJSON logs).
12
- - **Networking**: WS with optional `secret` auth (base64-encoded).
13
- - **Validation**: Strict name regex `/^[a-z_0-9_]{2,}$/`.
14
- - **Events**: Leverages `Prompt` events (e.g., `reset` → server resetAll).
15
-
16
- Exports: `{ AgentManager }` (named).
17
-
18
- ## Agent Naming Rules ⚠️
19
- **CRITICAL**: The `name` (constructor) and `toolName` (in `start()`) **MUST** match regex `/^[a-z_0-9_]{2,}$/`:
20
- - Lowercase `a-z`, digits `0-9`, `_` **only**.
21
- - **Minimum 2 characters**.
22
-
23
- **Valid ✅**:
24
- - `myagent`
25
- - `chatbot`
26
- - `weather_agent`
27
- - `tool123`
28
- - `ws_client`
29
-
30
- **Invalid ❌ (throws `Error`)**:
31
- - `MyAgent` (uppercase)
32
- - `agent-v1` (hyphen)
33
- - `a` (too short)
34
- - `agent#tool` (`#` invalid)
35
- - `Agent_` (uppercase)
36
-
37
- **Why?** Safe for folders, tool names, filesystems (no specials/caps/spaces).
38
-
39
- ## Quick Usage
40
- ```javascript
41
- import { AgentManager } from '@j-o-r/hello-dave';
42
-
43
- const agent = new AgentManager({ name: 'myagent', secret: 'mysecret' });
44
- agent.setup({
45
- prompt: 'You are a helpful coding assistant.',
46
- api: 'xai',
47
- options: { model: 'grok-4-fast-reasoning' },
48
- toolsetMode: 'auto',
49
- contextWindow: 128000
50
- });
51
- agent.addGenericToolcall('execute_bash_script');
52
-
53
- await agent.start(); // CLI mode
54
- // Or: await agent.directCall('Write a Bash script'); // One-shot
55
- // Or: await agent.start(8000); // WS server on port 8000
56
- ```
57
-
58
- ## Constructor Options
59
- | Property | Type | Default | Description |
60
- |----------|------|---------|-------------|
61
- | `name` | string | `'agent'` | **Agent ID (session folder, tool name). MUST match `/^[a-z_0-9_]{2,}$/` (lowercase a-z0-9_; ≥2 chars).** |
62
- | `secret` | string | `''` | WS auth (base64-encoded; optional, match server/client). |
63
- | `cachePath` | string | `'.cache/hello-dave'` | Session storage root. |
64
-
65
- ## setup(setup) → `this` (chainable)
66
- Configures the agent. Must call before `start()`/`directCall()`.
67
-
68
- | Property | Type | Default | Description |
69
- |----------|------|---------|-------------|
70
- | `prompt` | string | - | **Required**: System prompt. |
71
- | `api` | `'xai'|'gpt'|'claude'` | `'gpt'` | LLM provider (uses `lib/API/[provider]/text.js`). |
72
- | `options` | `XAIOptions`/`OAOptions`/etc. | `{}` | Provider-specific (model, temperature, tools, reasoning). |
73
- | `contextWindow` | number | `300000` | Token limit for `Prompt`. |
74
- | `toolsetMode` | `'auto'|'required'` | `null` | `'auto'`: Generic tools; `'required'`: Empty `ToolSet` (add manually). |
75
- | `debug` | boolean | `false` | Verbose logging. |
76
-
77
- Internals: Creates `Prompt`, `Session`, sets `Prompt.setAdaptor(API.text[api], toolset, options)`.
78
-
79
- ## Key Methods
80
- | Method | Args | Returns | Description |
81
- |--------|------|---------|-------------|
82
- | `directCall(input)` | `string` | `Promise<string>` | One-shot query (via `prompt.call()`). |
83
- | `getPrompt()` | - | `Prompt` | Access internal `Prompt`. |
84
- | `getToolset()` | - | `ToolSet\|void` | Access tools. |
85
- | `environment()` | - | `Promise<EnvironmentInfo>` | System info (via `fafs.js/env()`). |
86
- | `addGenericToolcall(name)` | string (e.g., `'read_file'`) | - | Copy from `genericToolset.js` pool. Post-setup only. |
87
- | `start(servePort?, connectUrl?, cliIntro?, toolName?, toolDesc?)` | Mixed | `Promise<void>` | **Smart launcher**:<br>- `servePort` (num): WS **server** (**toolName** MUST match name regex or auto-gen).<br>- `connectUrl` (str, e.g. `'ws://127.0.0.1:8000/ws'`): WS **client** (toolName/desc for attachment).<br>- Neither: **CLI** mode.<br>- Both: Hybrid. |
88
-
89
- ## Workflow Diagram
90
- ```mermaid
91
- graph TD
92
- A[New AgentManager name, secret] --> B[setup prompt, api, options, toolsetMode]
93
- B --> C{start args?}
94
- C -->|servePort| D[enableServer port, name, desc<br/>+ optional attach client]
95
- C -->|connectUrl| E[attach client url, name, desc]
96
- C -->|none| F[startCli intro]
97
- D --> G[Session Loop: Prompt → API/Tools → Response]
98
- E --> G
99
- F --> G
100
- G --> H[directCall or persist]
101
- ```
102
-
103
- **Per-Endpoint Options**:
104
- - **CLI**: `start()` → `Cli` (interactive/piped). Options via `setup`.
105
- - **WS Server**: `start(port)` → `AgentServer` (localhost only). Exposes agent as tool (name/desc). `secret` required for clients. `prompt.on('reset')` → `server.resetAll()`.
106
- - **WS Client**: `start(undefined, url)` → `AgentClient`. Connects to remote server; agent callable as tool.
107
- - **Direct**: `directCall()` bypasses networking/CLI.
108
-
109
- ## Examples
110
-
111
- ### 1. Interactive CLI Agent
112
- ```javascript
113
- import { AgentManager } from '@j-o-r/hello-dave';
114
-
115
- const agent = new AgentManager({ name: 'chatbot' });
116
- agent.setup({
117
- prompt: 'You are a friendly chatbot.',
118
- api: 'xai',
119
- toolsetMode: 'auto'
120
- });
121
- await agent.start('Chatbot ready!'); // Auto-generates intro
122
- ```
123
-
124
- ### 2. WS Server (Expose as Tool)
125
- ```javascript
126
- import { AgentManager } from '@j-o-r/hello-dave';
127
-
128
- agent.setup({ ... });
129
- await agent.start(8000, undefined, undefined, 'weathertool', 'Get real-time weather');
130
- ```
131
- - Clients: `npx @j-o-r/hello-dave dave --connect ws://localhost:8000/ws --secret mysecret`
132
-
133
- ### 3. Hybrid + Direct Call
134
- ```javascript
135
- import { AgentManager } from '@j-o-r/hello-dave';
136
-
137
- await agent.start(8001, 'ws://other:8000/ws'); // Server on 8001 + client to other
138
- const resp = await agent.directCall('Hybrid query'); // Uses attached tools too
139
- ```
140
-
141
- ### 4. Custom Tools + Generics
142
- ```javascript
143
- import { AgentManager } from '@j-o-r/hello-dave';
144
-
145
- agent.setup({ toolsetMode: 'required' });
146
- const ts = agent.getToolset();
147
- ts.add('custommath', 'Add numbers', {
148
- type: 'object', properties: {a: {type: 'number'}, b: {type: 'number'}},
149
- required: ['a', 'b']
150
- }, async ({a, b}) => a + b);
151
- agent.addGenericToolcall('javascript_interpreter');
152
- ```
153
-
154
- ## Advanced: Networking & Secrets
155
- - **Server-Client Chain**: Server A attaches to Server B → A callable from B (and vice versa if mutual).
156
- - **Cron/CLI Messaging**: Pipe to client: `echo 'query' | npx ... dave --connect ...`
157
- - **Reset**: `Prompt` emits `'reset'` → propagates to attached servers/clients.
158
-
159
- ## Errors
160
- - No `setup()`: Throws.
161
- - **Invalid `name`/`toolName`: Regex `/^[a-z_0-9_]{2,}$/` fail → `Error`.**
162
- - No `toolset` on server: Throws.
163
-
164
- See source `lib/AgentManager.js` for full JSDoc/types. Cross-links:
165
- - [Prompt](./prompt-class.md)
166
- - [ToolSet](./toolset.md)
167
- - [Generic Tools](../lib/genericToolset.js)
@@ -1,137 +0,0 @@
1
- # AgentManager (`lib/AgentManager.js`)
2
-
3
- ## Overview
4
- **AgentManager** is the central orchestrator class in the hello-dave framework. It manages agent lifecycle: setup (prompts, API, tools, sessions), execution modes (CLI, direct calls, WebSocket server/client), and tool integration. Designed for simplicity and extensibility, it abstracts LLM providers (`xai`, `gpt`, `claude`), `Prompt.js`, `ToolSet.js`, and `Session.js`.
5
-
6
- Key Features:
7
- - **Modes**: Interactive CLI, one-shot `directCall`, WS **server** (expose agent as tool), **client** (attach to remote server), hybrid (server + client).
8
- - **Tool Handling**: Pre-configured (`toolsetMode: 'auto'`/`'required'`), generics (`addGenericToolcall`), custom `ToolSet`.
9
- - **Persistence**: Sessions in `.cache/[name]/` (NDJSON logs).
10
- - **Networking**: WS with optional `secret` auth (base64-encoded).
11
- - **Validation**: Strict name regex `/^[a-z_0-9]{2,}$/`.
12
- - **Events**: Leverages `Prompt` events (e.g., `reset` → server resetAll).
13
-
14
- Exports: `default AgentManager`.
15
-
16
- ## Quick Usage
17
- ```javascript
18
- import AgentManager from '../lib/AgentManager.js'; // or '@j-o-r/hello-dave'
19
-
20
- const agent = new AgentManager({ name: 'myagent', secret: 'mysecret' });
21
- agent.setup({
22
- prompt: 'You are a helpful coding assistant.',
23
- api: 'xai',
24
- options: { model: 'grok-4-fast-reasoning' },
25
- toolsetMode: 'auto',
26
- contextWindow: 128000
27
- });
28
- agent.addGenericToolcall('execute_bash_script');
29
-
30
- await agent.start(); // CLI mode
31
- // Or: await agent.directCall('Write a Bash script'); // One-shot
32
- // Or: await agent.start(8000); // WS server on port 8000
33
- ```
34
-
35
- ## Constructor Options
36
- | Property | Type | Default | Description |
37
- |----------|------|---------|-------------|
38
- | `name` | string | `'agent'` | Agent ID (session folder, tool name). Regex: `/^[a-z_0-9]{2,}$/`. |
39
- | `secret` | string | `''` | WS auth (base64-encoded; optional, match server/client). |
40
- | `cachePath` | string | `'.cache/hello-dave'` | Session storage root. |
41
-
42
- ## setup(setup) → `this` (chainable)
43
- Configures the agent. Must call before `start()`/`directCall()`.
44
-
45
- | Property | Type | Default | Description |
46
- |----------|------|---------|-------------|
47
- | `prompt` | string | - | **Required**: System prompt. |
48
- | `api` | `'xai'|'gpt'|'claude'` | `'gpt'` | LLM provider (uses `lib/API/[provider]/text.js`). |
49
- | `options` | `XAIOptions`/`OAOptions`/etc. | `{}` | Provider-specific (model, temperature, tools, reasoning). |
50
- | `contextWindow` | number | `300000` | Token limit for `Prompt`. |
51
- | `toolsetMode` | `'auto'|'required'` | `null` | `'auto'`: Generic tools; `'required'`: Empty `ToolSet` (add manually). |
52
- | `debug` | boolean | `false` | Verbose logging. |
53
-
54
- Internals: Creates `Prompt`, `Session`, sets `Prompt.setAdaptor(API.text[api], toolset, options)`.
55
-
56
- ## Key Methods
57
- | Method | Args | Returns | Description |
58
- |--------|------|---------|-------------|
59
- | `directCall(input)` | `string` | `Promise<string>` | One-shot query (via `prompt.call()`). |
60
- | `getPrompt()` | - | `Prompt` | Access internal `Prompt`. |
61
- | `getToolset()` | - | `ToolSet\|void` | Access tools. |
62
- | `environment()` | - | `Promise<EnvironmentInfo>` | System info (via `fafs.js/env()`). |
63
- | `addGenericToolcall(name)` | string (e.g., `'read_file'`) | - | Copy from `genericToolset.js` pool. Post-setup only. |
64
- | `start(servePort?, connectUrl?, cliIntro?, toolName?, toolDesc?)` | Mixed | `Promise<void>` | **Smart launcher**:<br>- `servePort` (num): WS **server** (toolName/desc auto-gen).<br>- `connectUrl` (str, e.g. `'ws://127.0.0.1:8000/ws'`): WS **client** (attach as tool).<br>- Neither: **CLI** mode.<br>- Both: Hybrid server+client. |
65
-
66
- ## Workflow Diagram
67
- ```mermaid
68
- graph TD
69
- A[New AgentManager name, secret] --> B[setup prompt, api, options, toolsetMode]
70
- B --> C{start args?}
71
- C -->|servePort| D[enableServer port, name, desc<br/>+ optional attach client]
72
- C -->|connectUrl| E[attach client url, name, desc]
73
- C -->|none| F[startCli intro]
74
- D --> G[Session Loop: Prompt → API/Tools → Response]
75
- E --> G
76
- F --> G
77
- G --> H[directCall or persist]
78
- ```
79
-
80
- **Per-Endpoint Options**:
81
- - **CLI**: `start()` → `Cli` (interactive/piped). Options via `setup`.
82
- - **WS Server**: `start(port)` → `AgentServer` (localhost only). Exposes agent as tool (name/desc). `secret` required for clients. `prompt.on('reset')` → `server.resetAll()`.
83
- - **WS Client**: `start(undefined, url)` → `AgentClient`. Connects to remote server; agent callable as tool.
84
- - **Direct**: `directCall()` bypasses networking/CLI.
85
-
86
- ## Examples
87
-
88
- ### 1. Interactive CLI Agent
89
- ```javascript
90
- const agent = new AgentManager({ name: 'chatbot' });
91
- agent.setup({
92
- prompt: 'You are a friendly chatbot.',
93
- api: 'xai',
94
- toolsetMode: 'auto'
95
- });
96
- await agent.start('Chatbot ready!'); // Auto-generates intro
97
- ```
98
-
99
- ### 2. WS Server (Expose as Tool)
100
- ```javascript
101
- agent.setup({ ... });
102
- await agent.start(8000, undefined, undefined, 'weatherTool', 'Get real-time weather');
103
- ```
104
- - Clients: `npx @j-o-r/hello-dave dave --connect ws://localhost:8000/ws --secret mysecret`
105
-
106
- ### 3. Hybrid + Direct Call
107
- ```javascript
108
- await agent.start(8001, 'ws://other:8000/ws'); // Server on 8001 + client to other
109
- const resp = await agent.directCall('Hybrid query'); // Uses attached tools too
110
- ```
111
-
112
- ### 4. Custom Tools + Generics
113
- ```javascript
114
- agent.setup({ toolsetMode: 'required' });
115
- const ts = agent.getToolset();
116
- ts.add('customMath', 'Add numbers', {
117
- type: 'object', properties: {a: {type: 'number'}, b: {type: 'number'}},
118
- required: ['a', 'b']
119
- }, async ({a, b}) => a + b);
120
- agent.addGenericToolcall('javascript_interpreter');
121
- ```
122
-
123
- ## Advanced: Networking & Secrets
124
- - **Server-Client Chain**: Server A attaches to Server B → A callable from B (and vice versa if mutual).
125
- - **Cron/CLI Messaging**: Pipe to client: `echo 'query' | npx ... dave --connect ...`
126
- - **Reset**: `Prompt` emits `'reset'` → propagates to attached servers/clients.
127
-
128
- ## Errors
129
- - No `setup()`: Throws.
130
- - Invalid `name`/`toolName`: Regex fail.
131
- - No `toolset` on server: Throws.
132
-
133
- See source `lib/AgentManager.js` for full JSDoc/types. Cross-links:
134
- - [Prompt](./prompt-class.md)
135
- - [ToolSet](./toolset.md)
136
- - [Generic Tools](../lib/genericToolset.js)
137
- "