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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +445 -160
  3. package/README.md.backup +269 -0
  4. package/README.md.bak +481 -0
  5. package/README.md.bak.1774780058 +338 -0
  6. package/README.md.bak2 +455 -0
  7. package/bin/dave.js +165 -0
  8. package/docs.bak.1774780058/agent-manager.md +167 -0
  9. package/docs.bak.1774780058/agent-manager.md.bak +137 -0
  10. package/docs.bak.1774780058/agent-manager.md.bak2 +157 -0
  11. package/docs.bak.1774780058/codeserver-pattern.md +191 -0
  12. package/docs.bak.1774780058/path-resolution-best-practices.md +104 -0
  13. package/docs.bak.1774780058/project-overview.md +67 -0
  14. package/docs.bak.1774780058/project-overview.md.bak +67 -0
  15. package/docs.bak.1774780058/prompt-class.md +141 -0
  16. package/docs.bak.1774780058/prompt-class.md.bak +142 -0
  17. package/docs.bak.1774780058/tools-syntax-validation.md +121 -0
  18. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +125 -0
  19. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +125 -0
  20. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +106 -0
  21. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +106 -0
  22. package/docs.bak.1774780058/toolset.md +164 -0
  23. package/docs.bak.1774780058/toolset.md.bak +94 -0
  24. package/docs.bak.1774780058/toolset.md.bak3 +161 -0
  25. package/docs.bak.1774780058/toolset.md.bak4 +161 -0
  26. package/docs.bak.1774780058/toolset.md.bak5 +161 -0
  27. package/docs.bak.1774780058/toolset.md.bak6 +163 -0
  28. package/docs.bak.1774780058/toolset.md.bak_path +163 -0
  29. package/docs.bak.1774780058/toolset.md.bak_syntax +161 -0
  30. package/docs.bak.1774780058/xai-responses.md +111 -0
  31. package/docs.bak.1774780058/xai-responses.md.bak +107 -0
  32. package/docs.bak.1774780058/xai-responses.md.bak2 +107 -0
  33. package/docs.bak.1774780058/xai_collections.md +106 -0
  34. package/examples/ask_agent.js +137 -0
  35. package/examples/code_agent.js +149 -0
  36. package/examples/coderev_agent.js +136 -0
  37. package/examples/codeserver.sh +47 -0
  38. package/examples/daisy_agent.js +170 -0
  39. package/examples/docs_agent.js +148 -0
  40. package/examples/gpt_agent.js +125 -0
  41. package/examples/grok_agent.js +132 -0
  42. package/examples/grok_agent.js.bak +98 -0
  43. package/examples/grok_agent.js.bak.2 +99 -0
  44. package/examples/grok_agent.js.bak.3 +1 -0
  45. package/examples/grok_agent.js.bak.4 +124 -0
  46. package/examples/grok_agent.js.bak.5 +1 -0
  47. package/examples/grok_agent.js.bak.6 +1 -0
  48. package/examples/memory_agent.js +152 -0
  49. package/examples/npm_agent.js +202 -0
  50. package/examples/npm_agent.js.bak.3 +2 -0
  51. package/examples/npm_agent.js.bak.4 +205 -0
  52. package/examples/npm_agent.js.bak.5 +1 -0
  53. package/examples/npm_agent.js.bak.6 +1 -0
  54. package/examples/prompt_agent.js +133 -0
  55. package/examples/readme_agent.js +148 -0
  56. package/examples/spawn_agent.js +293 -0
  57. package/examples/test_agent.js +187 -0
  58. package/examples/todo_agent.js +175 -0
  59. package/examples.bak.1774780058/ask_agent.js +114 -0
  60. package/examples.bak.1774780058/code_agent.js +149 -0
  61. package/examples.bak.1774780058/coderev_agent.js +72 -0
  62. package/examples.bak.1774780058/codeserver.sh +47 -0
  63. package/examples.bak.1774780058/daisy_agent.js +177 -0
  64. package/examples.bak.1774780058/docs_agent.js +119 -0
  65. package/{bin/hdAsk.js → examples.bak.1774780058/gpt_agent.js} +46 -40
  66. package/examples.bak.1774780058/grok_agent.js +98 -0
  67. package/examples.bak.1774780058/memory_agent.js +112 -0
  68. package/examples.bak.1774780058/npm_agent.js +175 -0
  69. package/examples.bak.1774780058/prompt_agent.js +112 -0
  70. package/examples.bak.1774780058/readme_agent.js +144 -0
  71. package/examples.bak.1774780058/spawn_agent.js +263 -0
  72. package/examples.bak.1774780058/test_agent.js +162 -0
  73. package/examples.bak.1774780058/todo_agent.js +138 -0
  74. package/lib/API/openai.com/reponses/text.js +12 -18
  75. package/lib/API/x.ai/collections.js +354 -0
  76. package/lib/API/x.ai/files.js +218 -0
  77. package/lib/API/x.ai/responses.js +492 -0
  78. package/lib/API/x.ai/text.js +1 -1
  79. package/lib/AgentClient.js +13 -6
  80. package/lib/AgentManager.js +80 -10
  81. package/lib/AgentServer.js +50 -22
  82. package/lib/Cli.js +7 -1
  83. package/lib/Prompt.js +4 -2
  84. package/lib/ToolSet.js +2 -1
  85. package/lib/genericToolset.js +258 -88
  86. package/lib/genericToolset.js.bak_syntax +402 -0
  87. package/lib/index.js +4 -2
  88. package/lib/wsCli.js +256 -0
  89. package/lib/wsIO.js +96 -0
  90. package/package.json +26 -21
  91. package/scenarios.bak.1774780058/data/eval_node_message.json +9 -0
  92. package/scenarios.bak.1774780058/data/hist_oa.json +66 -0
  93. package/scenarios.bak.1774780058/data/o3_response1.json +96 -0
  94. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +112 -0
  95. package/scenarios.bak.1774780058/data/tool_oa.json +96 -0
  96. package/scenarios.bak.1774780058/data/tool_xai.json +59 -0
  97. package/scenarios.bak.1774780058/data/tool_xai2.json +40 -0
  98. package/scenarios.bak.1774780058/data/xai-response-1.json +59 -0
  99. package/scenarios.bak.1774780058/data/xai-response-2.json +10 -0
  100. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +59 -0
  101. package/scenarios.bak.1774780058/data/xai_search_response.json +58 -0
  102. package/scenarios.bak.1774780058/environment.js +10 -0
  103. package/scenarios.bak.1774780058/example.js +17 -0
  104. package/scenarios.bak.1774780058/genericToolset.test.js +182 -0
  105. package/scenarios.bak.1774780058/grok.js +113 -0
  106. package/scenarios.bak.1774780058/memory-tools.js +51 -0
  107. package/scenarios.bak.1774780058/openai-o3.js +137 -0
  108. package/scenarios.bak.1774780058/openai-prompt.js +155 -0
  109. package/scenarios.bak.1774780058/openai-session.js +148 -0
  110. package/scenarios.bak.1774780058/openai.js +102 -0
  111. package/scenarios.bak.1774780058/prompt.js +118 -0
  112. package/scenarios.bak.1774780058/promptFishbowl.js +76 -0
  113. package/scenarios.bak.1774780058/search.brave.com.js +25 -0
  114. package/scenarios.bak.1774780058/sh.js +15 -0
  115. package/scenarios.bak.1774780058/test-wsio.js +26 -0
  116. package/scenarios.bak.1774780058/testToolset.js +42 -0
  117. package/scenarios.bak.1774780058/toolset.js +16 -0
  118. package/scenarios.bak.1774780058/toolset.test.js +141 -0
  119. package/scenarios.bak.1774780058/write_file_syntax.test.js +145 -0
  120. package/scenarios.bak.1774780058/write_file_validation/README.md +30 -0
  121. package/scenarios.bak.1774780058/write_file_validation/bad.js +3 -0
  122. package/scenarios.bak.1774780058/write_file_validation/good.js +4 -0
  123. package/scenarios.bak.1774780058/write_file_validation/test.sh +43 -0
  124. package/scenarios.bak.1774780058/wsClient.js +69 -0
  125. package/scenarios.bak.1774780058/xai_responses.integration.test.js +57 -0
  126. package/scenarios.bak.1774780058/xai_responses.test.js +154 -0
  127. package/scenarios.bak.1774780058/xaicoll.js +50 -0
  128. package/scenarios.bak.1774780058/xaifiles.js +48 -0
  129. package/types/API/openai.com/reponses/text.d.ts +17 -3
  130. package/types/API/x.ai/collections.d.ts +167 -0
  131. package/types/API/x.ai/files.d.ts +84 -0
  132. package/types/API/x.ai/responses.d.ts +379 -0
  133. package/types/AgentClient.d.ts +5 -0
  134. package/types/AgentManager.d.ts +25 -31
  135. package/types/AgentServer.d.ts +5 -1
  136. package/types/Prompt.d.ts +4 -2
  137. package/types/ToolSet.d.ts +1 -0
  138. package/types/index.d.ts +4 -3
  139. package/types/wsCli.d.ts +3 -0
  140. package/types/wsIO.d.ts +26 -0
  141. package/utils/bars.js +40 -0
  142. package/utils/clear_sessions.sh +54 -0
  143. package/{bin/hdInspect.js → utils/format_log.js} +5 -0
  144. package/utils/list_sessions.sh +46 -0
  145. package/utils/search_sessions.sh +73 -0
  146. package/utils/syntax_check.sh +61 -0
  147. package/utils/test.sh +46 -0
  148. package/bin/hdClear.js +0 -13
  149. package/bin/hdCode.js +0 -115
  150. package/bin/hdConnect.js +0 -230
  151. package/bin/hdNpm.js +0 -114
  152. package/bin/hdPrompt.js +0 -108
  153. package/examples/claude-test.js +0 -89
  154. package/examples/claude.js +0 -143
  155. package/examples/gpt.js +0 -127
  156. package/examples/gpt_code.js +0 -125
  157. package/examples/gpt_note_keeping.js +0 -117
  158. package/examples/grok.js +0 -119
  159. package/examples/grok_code.js +0 -114
  160. package/examples/grok_note_keeping.js +0 -111
  161. package/module.md +0 -189
@@ -0,0 +1,263 @@
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
+ const help = args['help'] || false;
11
+ const connect = args['connect'] ? args['connect'] : undefined;
12
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
13
+
14
+ const options = { tools: [] };
15
+
16
+ options.tools.push({ type: 'web_search' });
17
+
18
+ if (args['secret']) {
19
+ secret = args['secret'];
20
+ }
21
+
22
+ if (args['model'] || true) {
23
+ options.model = args['model'] || 'grok-4-fast-reasoning'; // Up-to-date as of 2026
24
+ }
25
+ if (args['temperature']) {
26
+ options.temperature = parseFloat(args['temperature']);
27
+ }
28
+ if (args['tokens']) {
29
+ options.max_output_tokens = parseInt(args['tokens']);
30
+ }
31
+ if (args['top_p']) {
32
+ options.top_p = parseFloat(args['top_p']);
33
+ }
34
+ options.reasoning = { effort: 'high', summary: 'auto' };
35
+
36
+ const contextWindow = args['context'] ? parseInt(args['context']) : 500000;
37
+ const toolsetMode = 'auto';
38
+
39
+ function printHelp() {
40
+ console.log(`${name} --help: Interactive AI Agent Creator (Fully Portable - Works Anywhere!)
41
+
42
+ Guides you to create custom @j-o-r/hello-dave CLI agents (bin/<name>.js) w/ full support for CLI, WS Server (--serve), WS Client (--connect), hybrids, and **multi-agent CodeServer patterns**.
43
+
44
+ PORTABLE: Runs in ANY project (auto-installs deps, no local docs needed). Docs: https://codeberg.org/duin/hello-dave (agent-manager.md, codeserver-pattern.md).
45
+
46
+ USAGE:
47
+ npx @j-o-r/hello-dave spawn_agent # Interactive creation
48
+ npx @j-o-r/hello-dave spawn_agent --name myagent "Desc" # Semi-auto
49
+ echo "Create CodeServer launcher" | npx @j-o-r/hello-dave spawn_agent # Multi-agent
50
+
51
+ OPTIONS: --model [...] --temp [...] --secret [...]
52
+
53
+ PROCESS:
54
+ 1. Inspect project, auto-install deps (@j-o-r/hello-dave @j-o-r/sh).
55
+ 2. Gather: name, desc, tools, prompt.
56
+ 3. Generate/validate ESM script (node --check + tool rules).
57
+ 4. Write ./bin/<name>.js, chmod +x, **CLI auto-test**.
58
+ 5. **Server/Client Guide**: Test --serve → --connect; hybrids.
59
+ 6. **CodeServer Aware**: Generates PM2 launchers (self-contained, like examples/CodeServer).
60
+
61
+ EXAMPLES (Generated Agents):
62
+ ./bin/myagent.js # CLI
63
+ echo 'query' | ./bin/myagent.js # One-shot
64
+ ./bin/myagent.js --serve 8081 # WS Server
65
+ ./bin/myagent.js --connect ws://...:8081/ws --secret KEY # WS Client
66
+ ./bin/myagent.js --serve 8081 --connect ws://other:8080/ws # Hybrid
67
+ ./examples/MyServer 8081 mysecret # Multi-agent PM2 (generated)
68
+
69
+ **Multi-Agent**: "Generate launcher script like CodeServer pattern for myagent + todoagent".
70
+ `);
71
+ process.exit();
72
+ }
73
+
74
+ if (help) printHelp();
75
+
76
+ const REPO_URL = 'https://codeberg.org/duin/hello-dave';
77
+ const DOCS_BASE = `${REPO_URL}/src/branch/main/docs/`;
78
+ const EXAMPLES_URL = `${REPO_URL}/src/branch/main/examples/`;
79
+
80
+ const promptParts = [
81
+ 'You are AgentCreator, expert in @j-o-r/hello-dave. Create production-ready CLI agents (bin/<name>.js) **portably** anywhere (no local docs needed).',
82
+ '',
83
+ '**AGENT NAME RULE ⚠️**: name MUST be lowercase a-z0-9_ min 2 chars (/^[a-z_0-9_]{2,}$/). EX: myagent, codeagent, ws_tool.',
84
+ '',
85
+ '**IMPORTS CRITICAL ⚠️**: **NAMED imports ONLY** - NO default! `import { AgentManager } from \'@j-o-r/hello-dave\';` `import { parseArgs } from \'@j-o-r/sh\';`',
86
+ '',
87
+ '**PORTABILITY**: Auto-install deps: `@j-o-r/hello-dave @j-o-r/sh`. Absolute imports. NO local file refs (docs/examples).',
88
+ '',
89
+ '**MANDATORY MEMORY PROTOCOL (For EVERY query/task - NO EXCEPTIONS):**',
90
+ 'Connected clients (todo_agent, readme_agent, npm_agent, docs_agent, **memory_agent**) are available as tools. **ALWAYS** use **memory_agent** FIRST and LAST:',
91
+ '1. **RECALL PHASE (Step 1 of EVERY response)**:',
92
+ ' - Call `memory_agent "Recall relevant memories: tasks, errors, prefs for [keywords from user query]. List recent if empty."`',
93
+ ' - Incorporate recalled info (e.g., avoid known errors, resume tasks, apply prefs like temp=0.2).',
94
+ '2. **CORE ACTION**:',
95
+ ' - Perform coding assistance (tools: execute_bash_script, javascript_interpreter, read_file/write_file, web_search, etc.).',
96
+ ' - Delegate to specialists if relevant:',
97
+ ' - todo_agent: Tasks/TODO.md',
98
+ ' - readme_agent: README.md',
99
+ ' - npm_agent: NPM modules/package.json',
100
+ ' - docs_agent: Documentation',
101
+ ' - memory_agent: Persistent storage',
102
+ '3. **WRITE PHASE (Step 3 of EVERY response)**:',
103
+ ' - Call `memory_agent "Store updates: [new tasks/errors/prefs/decisions from this interaction]. E.g., \'Task: [next step]\', \'Error: [issue]\', \'Pref: [setting]\'"`',
104
+ ' - This ensures persistence across sessions/agents, prevents loops/token burn.',
105
+ '',
106
+ '**PRIORITIES**:',
107
+ '- Safety: CWD-only, no escapes, validate before write.',
108
+ '- Efficiency: Use memories to skip repeats (e.g., "Known error: git conflict → skip").',
109
+ '- Step-by-step: Clear responses with code blocks.',
110
+ 'FOLLOW MEMORY PROTOCOL RIGIDLY - it\'s how multi-agent coordination works!',
111
+ '',
112
+ '**INITIAL INSPECT** (execute_bash_script):',
113
+ '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`.',
114
+ '2. `mkdir -p bin examples`.',
115
+ '3. `cat package.json` (project name). `ls -la bin/`.',
116
+ '',
117
+ '**TOOL RULES (CRITICAL - NO MIX)**:',
118
+ '- **XAI Natives** (pre-setup): `options.tools.push({ type: \'web_search\' });` etc.',
119
+ '- **Generics** (post-setup): `agent.addGenericToolcall(\'read_file\');` w/ `toolsetMode: \'auto\'`.',
120
+ 'Default: web_search + execute_bash_script/read_file/write_file.',
121
+ '',
122
+ '**PROCESS (EXACT)**:',
123
+ '1. INSPECT & SETUP.',
124
+ '2. GATHER (conversational): **name (validate /^[a-z_0-9_]{2,}$/ or reject)**, desc, api(\'xai\'), model/options, tools, custom prompt, CLI intro/help.',
125
+ '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.',
126
+ '4. REVIEW: Show ```js``` + "✅ node --check | Tools OK". Edit if needed.',
127
+ '5. DEPLOY: `write_file ./bin/${name}.js FULL_CODE`, `chmod +x ./bin/${name}.js`.',
128
+ '6. **TEST**: `execute_bash_script \'./bin/${name}.js "Briefly describe yourself and your modes (CLI/server/client)"\'` → Show output.',
129
+ '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".',
130
+ '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`).',
131
+ '',
132
+ '**AGENT BLUEPRINT** (COPY/REPLACE - Plain backticks ` NO ESCAPES):',
133
+ `\`#!/usr/bin/env node
134
+ import { AgentManager } from '@j-o-r/hello-dave';
135
+ import { parseArgs } from '@j-o-r/sh';
136
+
137
+ const name = 'AGENTNAME'; // ← REPLACE w/ lowercase /^[a-z_0-9_]{2,}$/
138
+ const api = 'xai';
139
+ let secret = '';
140
+
141
+ const args = parseArgs();
142
+ const help = args['help'] || false;
143
+ const connect = args['connect'] ? args['connect'] : undefined;
144
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
145
+
146
+ const options = { tools: [] };
147
+
148
+ // NATIVES HERE e.g. options.tools.push({ type: 'web_search' });
149
+
150
+ if (args['secret']) { secret = args['secret']; }
151
+ if (args['model'] || true) { options.model = args['model'] || 'grok-4-fast-reasoning'; }
152
+ if (args['temperature']) { options.temperature = parseFloat(args['temperature']); } else { options.temperature = 0.8; }
153
+ options.reasoning = { effort: 'medium', summary: 'auto' };
154
+
155
+ const contextWindow = args['context'] ? parseInt(args['context']) : 500000;
156
+ const toolsetMode = 'auto';
157
+
158
+ function printHelp() {
159
+ console.log(\`AGENTNAME --help: AGENTDESC
160
+
161
+ Full modes: CLI, WS Server (--serve), WS Client (--connect), Hybrid.
162
+
163
+ Repo docs: https://codeberg.org/duin/hello-dave (agent-manager.md, codeserver-pattern.md).
164
+
165
+ USAGE:
166
+ ./bin/AGENTNAME # Interactive CLI
167
+ echo "query" | ./bin/AGENTNAME # One-shot
168
+ ./bin/AGENTNAME --serve 8081 # WS Server
169
+ ./bin/AGENTNAME --connect ws://host:8081/ws --secret KEY # WS Client
170
+ ./bin/AGENTNAME --serve 8081 --connect ws://other:8080/ws # Hybrid
171
+
172
+ OPTIONS: --model ... --secret ...
173
+
174
+ EXAMPLES:
175
+ Chain: Server A --connect B → delegates to B.
176
+ Multi-Agent: Generate/use PM2 launcher (CodeServer pattern).\`);
177
+ process.exit();
178
+ }
179
+
180
+ if (help) printHelp();
181
+
182
+ const prompt = \`You are AGENTNAME, AGENTDESC.
183
+
184
+ CUSTOMPROMPT\`.trim();
185
+
186
+ const agent = new AgentManager({ name, secret });
187
+ agent.setup({ prompt, api, options, toolsetMode, contextWindow });
188
+
189
+ // GENERICS HERE e.g. agent.addGenericToolcall('execute_bash_script');
190
+
191
+ const cliIntro = \`🤖 AGENTNAME ready! Modes: CLI/Server/Client/Hybrid.
192
+
193
+ CLIINTRO\`.trim();
194
+
195
+ const toolName = 'agent_' + name;
196
+ const toolDescription = \`AGENTDESC. Supports WS chaining/multi-agent.\`.trim();
197
+
198
+ await agent.start(serve, connect, cliIntro, toolName, toolDescription);\``,
199
+ '',
200
+ '**CODE_SERVER BLUEPRINT** (Bash for multi-agent - Self-contained, like CodeServer pattern):',
201
+ `\`#!/bin/bash
202
+ # Portable Multi-Agent Launcher (PM2-managed: main server + subs)
203
+ # Run: npm i -g pm2 (once)
204
+ if [ $# -lt 1 ] || [ $# -gt 2 ]; then
205
+ echo "Usage: $0 <PORT> [SECRET] # PORT:1024-65535, SECRET:>=3 chars (def:123)"
206
+ exit 1
207
+ fi
208
+ PORT="$1"
209
+ SECRET="\${2:-123}"
210
+ if [ \${#SECRET} -lt 3 ]; then echo "SECRET too short"; exit 1; fi
211
+ if ! [[ "$PORT" =~ ^[0-9]+$ ]] || [ "$PORT" -lt 1024 ] || [ "$PORT" -gt 65535 ]; then echo "Bad PORT"; exit 1; fi
212
+
213
+ SCRIPT_DIR="\$( cd "\$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
214
+ PROJECT_DIR="\$( cd "\$( dirname "\${SCRIPT_DIR}" )" && pwd )"
215
+ FOLDER=\$(basename "$PROJECT_DIR")
216
+
217
+ echo "Starting <MainAgent>Server on port \${PORT} in '\$FOLDER' w/ SECRET '\$SECRET'..."
218
+
219
+ # Cleanup old PM2
220
+ pm2 delete "\${FOLDER}_mainagent_\${PORT}" 2>/dev/null || true
221
+ pm2 delete "\${FOLDER}_sub1agent_\${PORT}" 2>/dev/null || true # Add per sub
222
+ # ... more subs
223
+
224
+ # Main server
225
+ pm2 start "\${SCRIPT_DIR}/bin/mainagent.js" --name "\${FOLDER}_mainagent_\${PORT}" -- --serve "\${PORT}" --tools javascript --secret "\${SECRET}"
226
+ # Subs as clients
227
+ pm2 start "\${SCRIPT_DIR}/bin/sub1agent.js" --name "\${FOLDER}_sub1agent_\${PORT}" -- --connect "ws://127.0.0.1:\${PORT}/ws" --secret "\${SECRET}"
228
+ # ... more: pm2 start ... sub2agent.js ...
229
+
230
+ echo "Processes: pm2 list | grep '\${FOLDER}_\${PORT}'"
231
+ echo "Connect: npx @j-o-r/hello-dave dave --connect ws://127.0.0.1:\${PORT}/ws --secret '\${SECRET}'"\``,
232
+ '',
233
+ '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'
234
+ ];
235
+
236
+ const prompt = promptParts.join('\\n');
237
+
238
+ const agent = new AgentManager({ name, secret });
239
+ agent.setup({
240
+ prompt,
241
+ api,
242
+ options,
243
+ toolsetMode,
244
+ contextWindow
245
+ });
246
+
247
+ agent.addGenericToolcall('execute_bash_script');
248
+ agent.addGenericToolcall('read_file');
249
+ agent.addGenericToolcall('write_file');
250
+ agent.addGenericToolcall('javascript_interpreter');
251
+
252
+ const cliIntro = `🤖 ${name} (${options.model}) ready! (context: ${contextWindow})
253
+
254
+ Portable Agent Creator: Builds CLI/WS agents + CodeServer launchers **anywhere** (auto-deps, online docs).
255
+
256
+ Examples:
257
+ - "Create code-review agent: name=coderev, desc=Git diff analyzer, tools=read_file execute_bash_script web_search"
258
+ - "Generate CodeServer launcher for coderev + tododave + npmdave"`.trim();
259
+
260
+ const toolName = 'spawn_agent';
261
+ const toolDescription = `Portable creator for CLI/WS agents (bin/<name>.js) + PM2 multi-agent launchers. Validates/tests/deploys. No local docs needed (uses repo: https://codeberg.org/duin/hello-dave).`.trim();
262
+
263
+ await agent.start(serve, connect, cliIntro, toolName, toolDescription);
@@ -0,0 +1,162 @@
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 = 'test_dave';
6
+ const api = 'xai';
7
+ let secret = '';
8
+
9
+ const args = parseArgs();
10
+ const help = args['help'] || false;
11
+ const connect = args['connect'] ? args['connect'] : undefined;
12
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
13
+
14
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
15
+ const options = {
16
+ tools: []
17
+ };
18
+ options.tools.push({
19
+ type: 'web_search'
20
+ });
21
+ if (args['secret']) {
22
+ secret = args['secret'];
23
+ }
24
+ if (args['model'] || true) {
25
+ options.model = args['model'] || 'grok-4-1-fast-reasoning';
26
+ }
27
+ options.temperature = 0.2;
28
+ if (args['tokens']) {
29
+ options.max_output_tokens = parseInt(args['tokens']);
30
+ }
31
+ if (args['top_p']) {
32
+ options.top_p = parseFloat(args['top_p']);
33
+ }
34
+ const reasoning = args['reasoning'] ? args['reasoning'] : 'medium';
35
+ if (reasoning) {
36
+ options.reasoning = {
37
+ effort: reasoning,
38
+ summary: 'auto'
39
+ };
40
+ }
41
+ const toolsetMode = 'auto';
42
+ const contextWindow = args['context'] ? parseInt(args['context']) : 2565000;
43
+
44
+ function printHelp() {
45
+ console.log(`
46
+ '${name} --help' You are looking at it.
47
+
48
+ OPTIONS:
49
+ --tokens [number]: max generated tokens
50
+ --context [number]: truncate message history to context-window size (default ${contextWindow})
51
+ --temperature [float]: -2 / +2
52
+ --model [string]: model name
53
+ --top_p [float]: number > 0, 0.1 means no top_p
54
+ --reasoning [low|medium|high]
55
+ --tools [javascript,bash,nushell,ssh] comma separated list
56
+
57
+ SERVER TOOLS:
58
+ --serve [number]: create an Agent server on port ws://127.0.0.1:[serve]/ws
59
+ --connect [url]: connect to a Server Agent e.g. ws://127.0.0.1:8080/ws (https://my.domain/ws)
60
+ --secret [string]: limit access to websocket server with a secret
61
+ `);
62
+ process.exit();
63
+ }
64
+
65
+ if (help) {
66
+ printHelp();
67
+ }
68
+
69
+ const agent = new AgentManager({ name, secret });
70
+ const sys = (await agent.environment()).system;
71
+
72
+ const prompt = `You are TestDave, the specialized testing agent for CodeServer projects. Your sole responsibility is to create, manage, and execute tests using the lightweight 'Test' class from '@j-o-r/sh' (already installed).
73
+
74
+ **CORE MISSION**:
75
+ - Write executable test scripts in ./scenarios/ folder with the extension *.test.js (e.g., scenarios/toolset.test.js).
76
+ - Tests must use: \`import { Test, assert, jsType } from '@j-o-r/sh';\`
77
+ - Structure: shebang \`#!/usr/bin/env node\`, fluent Test API (\`const t = new Test(); t.add('desc', () => { assert... }); await t.run();\`), exit(1) on errors.
78
+ - After write_file to scenarios/MODULE.test.js, ensure executable: \`chmod +x scenarios/MODULE.test.js\`
79
+ - Leverage project utilities: test existing files (examples/*.js, toolset.js, agents, SH commands, etc.) using read_file, execute_bash_script (ls/cat), npm_module_inspector.
80
+
81
+ **WHAT TO TEST** (discover dynamically):
82
+ 1. Project scripts: e.g., parseArgs, AgentManager flows, toolsets.
83
+ 2. Utilities: SH commands, async hooks, promise tracking.
84
+ 3. Agents: codeDave, npmDave, memoryDave integrations.
85
+ 4. Existing: genericToolset.test.js patterns, sh.js, etc.
86
+ - Query: "Write test for toolset.js" → read_file toolset.js → generate scenarios/toolset.test.js.
87
+
88
+ **Test Example** (from @j-o-r/sh docs):
89
+ \`\`\`
90
+ #!/usr/bin/env node
91
+ import { Test, assert, jsType } from '@j-o-r/sh';
92
+
93
+ const t = new Test();
94
+ t.add('Basic assert', () => assert.strictEqual(1 + 1, 2));
95
+ t.add('Type check', () => assert.strictEqual(jsType([]), 'Array'));
96
+ t.add('Async test', async () => {
97
+ const p = Promise.resolve('ok');
98
+ assert.strictEqual(await p, 'ok');
99
+ });
100
+ const report = await t.run();
101
+ process.exit(report.errors > 0 ? 1 : 0);
102
+ \`\`\`
103
+
104
+ **WORKFLOW** (per user request, e.g., "test parseArgs"):
105
+ 1. Recall memories (tasks/errors for testing).
106
+ 2. Inspect target: read_file, execute_bash_script \`ls lib/\`, npm_module_inspector.
107
+ 3. Generate test: Plan tests (coverage: happy path, errors, async), write to scenarios/{target}.test.js (e.g., scenarios/parseArgs.test.js).
108
+ 4. Validate: execute_bash_script \`node scenarios/{target}.test.js\` or \`./scenarios/{target}.test.js\`.
109
+ 5. Report results, store outcomes.
110
+
111
+ **MANDATORY MEMORY PROTOCOL** (ALWAYS FIRST/LAST):
112
+ 1. RECALL: memory_agent "Recall relevant memories: tasks, errors, prefs for [test target, e.g., toolset.js]."
113
+ 2. CORE: Write/Run tests in scenarios/*.test.js.
114
+ 3. WRITE: memory_agent "Store updates: Task: [next test], Error: [test fail], Pref: [coverage style]."
115
+
116
+ **PRIORITIES**:
117
+ - Safety: CWD-only, validate syntax before write (write_file auto-checks).
118
+ - Coverage: assertions (strictEqual, ok, throws), types (jsType), async (promises).
119
+ - Executable: shebang + chmod +x scenarios/*.test.js.
120
+ - Reuse: Import project utils (e.g., import {parseArgs} from './toolset.js').
121
+ - Current date: March 27, 2026.
122
+
123
+ FOLLOW RIGIDLY: Memory first/last, scenarios/*.test.js only, Test class exclusively.
124
+ `.trim();
125
+
126
+ agent.setup({
127
+ prompt,
128
+ api,
129
+ options,
130
+ toolsetMode,
131
+ contextWindow
132
+ });
133
+
134
+ const toolset = agent.getToolset();
135
+ if (toolset) {
136
+ agent.addGenericToolcall('history_search');
137
+ agent.addGenericToolcall('memory_recall');
138
+ agent.addGenericToolcall('memory_write');
139
+ agent.addGenericToolcall('javascript_interpreter');
140
+ agent.addGenericToolcall('execute_bash_script');
141
+ agent.addGenericToolcall('read_file');
142
+ agent.addGenericToolcall('write_file');
143
+ const addTools = args['tools'] ? args['tools'].split(',') : [''];
144
+ if (addTools.includes('ssh')) {
145
+ agent.addGenericToolcall('execute_remote_script');
146
+ }
147
+ }
148
+
149
+ const cliIntro = `
150
+ ${name} ${options.model}
151
+ - context: ${contextWindow}
152
+ - **Test Agent ACTIVE**: Writes/runs @j-o-r/sh Test scripts in ./scenarios/*.test.js (auto-executable).
153
+ - Example: "Write test for lib/MyClass.js"
154
+ - **Memory Protocol ACTIVE**
155
+ `.trim();
156
+
157
+ const description = `
158
+ TestDave: Generates executable tests (Test class) for project files/utils/agents in ./scenarios/*.test.js.
159
+ Uses memories, delegates to code/npm/etc. agents.
160
+ `.trim();
161
+
162
+ await agent.start(serve, connect, cliIntro, 'test_agent', description);
@@ -0,0 +1,138 @@
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 = 'todo_dave';
6
+ const api = 'xai';
7
+ let secret = '';
8
+
9
+ const args = parseArgs();
10
+ const help = args['help'] || false;
11
+ const connect = args['connect'] ? args['connect'] : undefined;
12
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
13
+
14
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
15
+ const options = { tools : []};
16
+
17
+ if (args['secret']) { // model gets default value
18
+ secret= args['secret'];
19
+ }
20
+ // Set properties only if provided via command line (except model which has default)
21
+ if (args['model'] || true) { // model gets default value
22
+ // @ts-ignore
23
+ options.model = args['model'] || 'grok-4-fast-reasoning';
24
+ }
25
+ if (args['temperature']) {
26
+ options.temperature = parseFloat(args['temperature']);
27
+ }
28
+ if (args['tokens']) {
29
+ options.max_output_tokens = parseInt(args['tokens']);
30
+ }
31
+ if (args['top_p']) {
32
+ options.top_p = parseFloat(args['top_p']);
33
+ }
34
+ const reasoning = true; // args['reasoning'] ? args['reasoning'] : null;
35
+ if (reasoning) {
36
+ options.reasoning = {
37
+ effort:'medium',
38
+ summary: 'auto'
39
+ }
40
+ }
41
+
42
+ options.tools.push({
43
+ type: 'web_search'
44
+ });
45
+ const toolsetMode = 'auto';
46
+ const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
47
+
48
+ // Copy from the generic toolset
49
+ function printHelp() {
50
+ console.log(`
51
+ '${name} --help' You are looking at it.
52
+ '
53
+ OPTIONS:
54
+ --tokens [number]: max generated tokens
55
+ --context [number] : truncate message history to context-windows size default 130000
56
+ --temperature [float] : -2 / +2
57
+ --model [grok-4|grok-3|grok-3-mini|grok-3-mini-fast|grok-code-fast-1]
58
+ --top_p [float]: number > 0, 0.1 means no top_p
59
+ --reasoning [low|high]
60
+ --tools [javascript,bash] comma seperated list
61
+ `);
62
+ process.exit()
63
+ }
64
+
65
+ if (help) {
66
+ printHelp();
67
+ }
68
+
69
+ const tool_call_description = `
70
+ Project TODO list manager. Maintains TODO.md with tasks in Markdown checklists.
71
+ Inspects current TODO.md, adds/checks/completes tasks based on input, updates the file.
72
+ Suggests next actions, stores future important tasks.
73
+ `.trim();
74
+ const tool_call_name = 'todo_agent';
75
+ const prompt = `
76
+ You are an expert TODO manager for this project. TODO.md stores tasks in Markdown format with checklists:
77
+
78
+ ## TODO (high priority pending)
79
+ - [ ] Task 1
80
+
81
+ ## In Progress
82
+ - [ ] Task 2
83
+
84
+ ## Later (future tasks)
85
+ - [ ] Important task to do later
86
+
87
+ ## Done
88
+ - [x] Completed task
89
+
90
+ **CRITICAL: STRICT NO-CODING RULE** - Stick to TODO management ONLY. NEVER:
91
+ - Use coding tools (e.g., javascript_interpreter, write_file, read_file, syntax_check).
92
+ - Generate, execute, or edit code.
93
+ - Misuse bash for anything beyond safe TODO.md ops (e.g., cat TODO.md, echo > TODO.md).
94
+ If asked to code, decline: "For coding, use other agents. I'll handle TODOs only."
95
+ Delegate complex tasks via suggestions; use memory_agent if available for persistence.
96
+
97
+ ALWAYS:
98
+
99
+ 1. Inspect the current TODO.md file if it exists (use \`cat TODO.md\` or similar).
100
+
101
+ 2. Understand the user input:
102
+ - Add new tasks: "add task: Fix bug in foo.js"
103
+ - Complete: "done: task X" or mark specific
104
+ - Check status: "status" or "what's next?"
105
+ - Prioritize/reorganize
106
+ - Archive old done tasks if too many
107
+
108
+ 3. Update TODO.md with changes. Keep it organized, add dates if useful (e.g., - [ ] 2026-02-24: Task).
109
+
110
+ 4. Write the FULL updated content to ./TODO.md.
111
+
112
+ 5. In your response, summarize:
113
+ - Current status (pending count, next suggested)
114
+ - Changes made
115
+ - Updated TODO.md preview (first 10 lines or key sections)
116
+
117
+ If no TODO.md, create one inspecting the project (package.json, README.md, git status) for initial tasks like "Review code", "Add tests", etc.
118
+
119
+ Use tools to inspect files as needed (ls, cat, git log, etc.).
120
+ `.trim();
121
+ const agent = new AgentManager({ name, secret });
122
+ agent.setup({
123
+ prompt,
124
+ api,
125
+ options,
126
+ toolsetMode,
127
+ contextWindow
128
+ });
129
+ const toolset = agent.getToolset();
130
+ if (toolset) {
131
+ agent.addGenericToolcall('execute_bash_script');
132
+ }
133
+ const cliIntro = `
134
+ ${name} ${options.model}.
135
+ - context: ${contextWindow}
136
+ `.trim();
137
+
138
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
@@ -22,12 +22,12 @@ import { sleep } from '@j-o-r/sh';
22
22
  * @property {number} [max_output_tokens=4000] - Maximum number of output tokens.
23
23
  * @property {number} [max_tool_calls=10] - Maximum number of tool calls allowed.
24
24
  * @property {?Object} [metadata=null] - Optional metadata object.
25
- * @property {'gpt-4.1'|'GPT-4o'|'o3'|'o3-mini'|'o4-mini'|'o1'|'o3-pro'} [model='gpt-4.1'] - Model version to use.
25
+ * @property {'gpt-5.4'|'gpt-5-mini'|'gpt-5-nano'|'gpt-5-pro'} [model='gpt-5-mini'] - Model version to use.
26
26
  * @property {?string} [prompt=null] - Reusable prompt string.
27
27
  * @property {Object} [reasoning={effort: 'medium', summary: 'auto'}] - Reasoning configuration.
28
28
  * @property {'low'|'medium'|'high'|null} reasoning.effort - Effort level for reasoning.
29
29
  * @property {'auto'|'concise'|'detailed'} reasoning.summary - Summary type for reasoning.
30
- * @property {'low'|'medium'|'high'} [search]
30
+ * @property {'low'|'medium'|'high'} [search] - Convenience: Adds `{type: "web_search_preview", search_context_size: search}` tool.
31
31
  * @property {'auto'} [service_tier='auto'] - Service tier option, default is auto-selected.
32
32
  * @property {boolean} [store=false] - Whether to store the response or not.
33
33
  * @property {boolean} [stream=false] - Whether to stream the response or not.
@@ -36,7 +36,7 @@ import { sleep } from '@j-o-r/sh';
36
36
  * @property {'text'|'json_schema'} text.format - Summary type for reasoning.
37
37
  * @property {boolean} [parallel_tool_calls=true] - Allow parallel tool calls if true.
38
38
  * @property {'auto'} [tool_choice='auto'] - Tool choice setting, default is auto-selected.
39
- * @property {OAToolCall[]} tools=[] Array of tool call objects.
39
+ * @property {OpenAITool[]} [tools=[]] - Array of tool objects: custom function tools (`OAToolCall`) or built-in OpenAI tools (e.g., `{type: "web_search_preview"}`).
40
40
  * @property {?number } top_logprobs=null An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability.
41
41
  * @property {?number } top_p=1 Top-p sampling value between 0 and 1.
42
42
  * @property {?string} [previous_response_id] - Needed reponse_id to validate tool calls on the next request
@@ -51,6 +51,14 @@ import { sleep } from '@j-o-r/sh';
51
51
  * @property {Object.<string, OAParameterProperty>} parameters.properties - An object describing each parameter property.
52
52
  * @property {string[]} [parameters.required] - An array of required parameter names.
53
53
  */
54
+ /**
55
+ * @typedef {Object} OABuiltinTool
56
+ * @property {'code_interpreter'|'file_search'|'computer'|'web_search'} type - Type of built-in OpenAI tool (Responses API).
57
+ * @property {'low'|'medium'|'high'} [search_context_size] - Context size for `web_search_preview` only.
58
+ */
59
+ /**
60
+ * @typedef {OAToolCall | OABuiltinTool} OpenAITool
61
+ */
54
62
 
55
63
  /**
56
64
  * @typedef {Object} OAParameterProperty
@@ -247,23 +255,9 @@ function getBody(prompt, toolset, options) {
247
255
  if (toolset) {
248
256
  // @ts-ignore
249
257
  body.tool_choice = toolset.toolChoice;
250
- body.tools = generateTools(toolset);
258
+ body.tools = [...body.tools, ...generateTools(toolset)];
251
259
  body.parallel_tool_calls = true;
252
- // parallel_tool_calls
253
- }
254
- // Add OPENAI SEARCH
255
- // in the toolset
256
- if (body.search) {
257
- if (!body.tools) {
258
- body.tools = [];
259
- }
260
- body.tools.push({
261
- type: 'web_search_preview',
262
- // @ts-ignore
263
- search_context_size: body.search
264
- })
265
260
  }
266
- delete body.search;
267
261
  return body;
268
262
 
269
263
  }