@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,148 @@
1
+ #!/usr/bin/env node
2
+ import { AgentManager } from '@j-o-r/hello-dave';
3
+ import { parseArgs, readIn } from '@j-o-r/sh';
4
+
5
+ const name = 'readme_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
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
15
+ const options = { tools : []};
16
+ options.tools.push({
17
+ type: 'web_search'
18
+ });
19
+ if (args['secret']) { // model gets default value
20
+ secret = args['secret'];
21
+ }
22
+ // Set properties only if provided via command line (except model which has default)
23
+ if (args['model'] || true) { // model gets default value
24
+ // @ts-ignore
25
+ options.model = args['model'] || 'grok-4-fast-reasoning';
26
+ }
27
+ if (args['temperature']) {
28
+ options.temperature = parseFloat(args['temperature']);
29
+ }
30
+ if (args['tokens']) {
31
+ options.max_output_tokens = parseInt(args['tokens']);
32
+ }
33
+ if (args['top_p']) {
34
+ options.top_p = parseFloat(args['top_p']);
35
+ }
36
+ const reasoning = args['reasoning'] ? args['reasoning'] : null;
37
+ if (reasoning) {
38
+ options.reasoning = {
39
+ // @ts-ignore
40
+ effort: reasoning,
41
+ summary: 'auto'
42
+ }
43
+ }
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
+ SERVER TOOLS:
63
+ --serve [number]: create a Agent server on port number ws://127.0.0.1:[serve]/ws
64
+ --connect [url]: connect to a Server Agent e.g ws://127.0.0.1:8080/ws (https://my.domain/ws) ...
65
+ --secret [string] : limit access to websocket server with a secret
66
+ `);
67
+ process.exit()
68
+ }
69
+
70
+ if (help) {
71
+ printHelp();
72
+ }
73
+
74
+ const tool_call_description = `
75
+ Project README manager. Maintains README.md with comprehensive project documentation.
76
+ Inspects current README.md, updates sections (installation, usage, etc.), generates content based on project files and user input.
77
+ Suggests improvements, adds badges, TOC, etc.
78
+ `.trim();
79
+ const tool_call_name = 'readme_agent';
80
+ const prompt = `
81
+ You are an expert README.md manager for this project. README.md should follow best practices with sections like:
82
+
83
+ # Project Title
84
+ ![Badges]
85
+
86
+ ## Table of Contents
87
+
88
+ ## Description
89
+ ## Features
90
+ ## Installation
91
+ ## Usage
92
+ ## Examples
93
+ ## Development
94
+ ## Contributing
95
+ ## License
96
+
97
+ **CRITICAL: STRICT NO-CODING RULE** - Stick to README management ONLY. NEVER:
98
+ - Use coding tools (e.g., javascript_interpreter, read_file, write_file, syntax_check, npm_module_inspector).
99
+ - Generate, execute, or edit code (JS/Python/Bash beyond safe README ops).
100
+ - Misuse bash for anything beyond safe README.md ops (e.g., cat README.md, echo > README.md, cp README.md README.md.bak, ls, git status).
101
+ If asked to code or edit non-README files, decline: "For coding or other tasks, use specialized agents like code_agent. I'll handle README.md only."
102
+
103
+ ALWAYS:
104
+
105
+ 1. Inspect the current README.md if it exists (use \`cat README.md\` or similar).
106
+
107
+ 2. Inspect key project files safely: \`cat package.json\`, \`ls -la\`, \`ls bin/\`, \`ls lib/\`, \`git status\`, etc.
108
+
109
+ 3. Understand the user input:
110
+ - "add installation instructions"
111
+ - "generate usage examples"
112
+ - "add table of contents"
113
+ - "update description to: ..."
114
+ - "suggest improvements"
115
+ - "include npm badges"
116
+ - "make it more professional"
117
+
118
+ 4. Update README.md with changes. Ensure excellent Markdown formatting, accuracy based on project. Backup first if overwriting: \`cp README.md README.md.bak\`.
119
+
120
+ 5. Write the FULL updated content to ./README.md using safe bash (e.g., echo "content" > README.md).
121
+
122
+ 6. In your response, summarize:
123
+ - Changes made
124
+ - Preview of key sections (e.g., first 20 lines)
125
+ - Any suggestions for further enhancements
126
+
127
+ If no README.md exists, create a comprehensive one by analyzing the entire project: package.json, code structure, scripts, etc. Infer project name, description, usage from files.
128
+
129
+ Use execute_bash_script ONLY for safe README ops and inspections. Use web_search for best practices if needed.
130
+ `.trim();
131
+ const agent = new AgentManager({ name, secret });
132
+ agent.setup({
133
+ prompt,
134
+ api,
135
+ options,
136
+ toolsetMode,
137
+ contextWindow
138
+ });
139
+ const toolset = agent.getToolset();
140
+ if (toolset) {
141
+ agent.addGenericToolcall('execute_bash_script');
142
+ }
143
+ const cliIntro = `
144
+ ${name} ${options.model}.
145
+ - context: ${contextWindow}
146
+ `.trim();
147
+
148
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
@@ -0,0 +1,293 @@
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
+ }
@@ -0,0 +1,187 @@
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_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 "Generate test for toolset.js" [--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., 'test_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 'test_agent' tool for chaining.
90
+ `);
91
+ process.exit()
92
+ }
93
+
94
+ if (help) {
95
+ printHelp();
96
+ }
97
+
98
+ const tool_call_name = 'test_agent';
99
+ const tool_call_description = `
100
+ TestDave: Generates executable tests (Test class) for project files/utils/agents in ./scenarios/*.test.js.
101
+ Uses memories, delegates to code/npm/etc. agents.
102
+ `.trim();
103
+
104
+ const prompt = `You are TestAgent, 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).
105
+
106
+ **CORE MISSION**:
107
+ - Write executable test scripts in ./scenarios/ folder with the extension *.test.js (e.g., scenarios/toolset.test.js).
108
+ - Tests must use: \`import { Test, assert, jsType } from '@j-o-r/sh';\`
109
+ - Structure: shebang \`#!/usr/bin/env node\`, fluent Test API (\`const t = new Test(); t.add('desc', () => { assert... }); await t.run();\`), exit(1) on errors.
110
+ - After write_file to scenarios/MODULE.test.js, ensure executable: \`chmod +x scenarios/MODULE.test.js\`
111
+ - 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.
112
+
113
+ **WHAT TO TEST** (discover dynamically):
114
+ 1. Project scripts: e.g., parseArgs, AgentManager flows, toolsets.
115
+ 2. Utilities: SH commands, async hooks, promise tracking.
116
+ 3. Agents: code_agent, npm_agent, memory_agent integrations.
117
+ 4. Existing: genericToolset.test.js patterns, sh.js, etc.
118
+ - Query: "Write test for toolset.js" → read_file toolset.js → generate scenarios/toolset.test.js.
119
+
120
+ **Test Example** (from @j-o-r/sh docs):
121
+ \`\`\`
122
+ #!/usr/bin/env node
123
+ import { Test, assert, jsType } from '@j-o-r/sh';
124
+
125
+ const t = new Test();
126
+ t.add('Basic assert', () => assert.strictEqual(1 + 1, 2));
127
+ t.add('Type check', () => assert.strictEqual(jsType([]), 'Array'));
128
+ t.add('Async test', async () => {
129
+ const p = Promise.resolve('ok');
130
+ assert.strictEqual(await p, 'ok');
131
+ });
132
+ const report = await t.run();
133
+ process.exit(report.errors > 0 ? 1 : 0);
134
+ \`\`\`
135
+
136
+ **WORKFLOW** (per user request, e.g., "test parseArgs"):
137
+ 1. Recall memories (tasks/errors for testing).
138
+ 2. Inspect target: read_file, execute_bash_script \`ls lib/\`, npm_module_inspector.
139
+ 3. Generate test: Plan tests (coverage: happy path, errors, async), write to scenarios/{target}.test.js (e.g., scenarios/parseArgs.test.js).
140
+ 4. Validate: execute_bash_script \`node scenarios/{target}.test.js\` or \`./scenarios/{target}.test.js\`.
141
+ 5. Report results, store outcomes.
142
+
143
+ **MANDATORY MEMORY PROTOCOL** (ALWAYS FIRST/LAST):
144
+ 1. RECALL: memory_agent "Recall relevant memories: tasks, errors, prefs for [test target, e.g., toolset.js]."
145
+ 2. CORE: Write/Run tests in scenarios/*.test.js.
146
+ 3. WRITE: memory_agent "Store updates: Task: [next test], Error: [test fail], Pref: [coverage style]."
147
+
148
+ **PRIORITIES**:
149
+ - Safety: CWD-only, validate syntax before write (write_file auto-checks).
150
+ - Coverage: assertions (strictEqual, ok, throws), types (jsType), async (promises).
151
+ - Executable: shebang + chmod +x scenarios/*.test.js.
152
+ - Reuse: Import project utils (e.g., import {parseArgs} from './toolset.js').
153
+ - Current date: April 01, 2026.
154
+
155
+ FOLLOW RIGIDLY: Memory first/last, scenarios/*.test.js only, Test class exclusively.
156
+ `.trim();
157
+
158
+ const agent = new AgentManager({ name, secret });
159
+ agent.setup({
160
+ prompt,
161
+ api,
162
+ options,
163
+ toolsetMode,
164
+ contextWindow
165
+ });
166
+ const toolset = agent.getToolset();
167
+ if (toolset) {
168
+ agent.addGenericToolcall('history_search');
169
+ agent.addGenericToolcall('memory_recall');
170
+ agent.addGenericToolcall('memory_write');
171
+ agent.addGenericToolcall('javascript_interpreter');
172
+ agent.addGenericToolcall('execute_bash_script');
173
+ agent.addGenericToolcall('read_file');
174
+ agent.addGenericToolcall('write_file');
175
+ }
176
+ const cliIntro = `
177
+ ${name} ${options.model}.
178
+ - context: ${contextWindow}.
179
+ ${tool_call_name}
180
+ `.trim();
181
+
182
+ if (input) {
183
+ const RES = await agent.directCall(input);
184
+ console.log(RES);
185
+ } else {
186
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
187
+ }