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

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 (112) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +337 -68
  3. package/README.md.bak +523 -0
  4. package/README.md.bak.1774780058 +338 -0
  5. package/README.md.bak2 +531 -0
  6. package/bin/dave.js +33 -22
  7. package/bin/spawn_agent.js +293 -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/codeserver.sh +47 -0
  37. package/examples/daisy_agent.js +170 -0
  38. package/examples/docs_agent.js +148 -0
  39. package/examples/gpt_agent.js +122 -0
  40. package/examples/grok_agent.js +132 -0
  41. package/examples/memory_agent.js +152 -0
  42. package/examples/npm_agent.js +202 -0
  43. package/examples/prompt_agent.js +133 -0
  44. package/examples/readme_agent.js +148 -0
  45. package/examples/test_agent.js +187 -0
  46. package/examples/todo_agent.js +175 -0
  47. package/{examples/codeDave.js → examples.bak.1774780058/code_agent.js} +40 -6
  48. package/{examples/CodeServer → examples.bak.1774780058/codeserver.sh} +9 -5
  49. package/examples.bak.1774780058/memory_agent.js +112 -0
  50. package/{examples/spawndave.js → examples.bak.1774780058/spawn_agent.js} +29 -6
  51. package/examples.bak.1774780058/test_agent.js +162 -0
  52. package/{examples/todoDave.js → examples.bak.1774780058/todo_agent.js} +8 -2
  53. package/lib/API/x.ai/responses.js +7 -9
  54. package/lib/AgentManager.js +3 -2
  55. package/lib/AgentServer.js +23 -19
  56. package/lib/ToolSet.js +4 -1
  57. package/lib/genericToolset.js +159 -26
  58. package/lib/genericToolset.js.bak_syntax +402 -0
  59. package/lib/index.js +5 -1
  60. package/lib/wsCli.js +0 -1
  61. package/package.json +5 -6
  62. package/scenarios.bak.1774780058/data/eval_node_message.json +9 -0
  63. package/scenarios.bak.1774780058/data/hist_oa.json +66 -0
  64. package/scenarios.bak.1774780058/data/o3_response1.json +96 -0
  65. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +112 -0
  66. package/scenarios.bak.1774780058/data/tool_oa.json +96 -0
  67. package/scenarios.bak.1774780058/data/tool_xai.json +59 -0
  68. package/scenarios.bak.1774780058/data/tool_xai2.json +40 -0
  69. package/scenarios.bak.1774780058/data/xai-response-1.json +59 -0
  70. package/scenarios.bak.1774780058/data/xai-response-2.json +10 -0
  71. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +59 -0
  72. package/scenarios.bak.1774780058/data/xai_search_response.json +58 -0
  73. package/scenarios.bak.1774780058/environment.js +10 -0
  74. package/scenarios.bak.1774780058/example.js +17 -0
  75. package/scenarios.bak.1774780058/genericToolset.test.js +182 -0
  76. package/scenarios.bak.1774780058/grok.js +113 -0
  77. package/scenarios.bak.1774780058/memory-tools.js +51 -0
  78. package/scenarios.bak.1774780058/openai-o3.js +137 -0
  79. package/scenarios.bak.1774780058/openai-prompt.js +155 -0
  80. package/scenarios.bak.1774780058/openai-session.js +148 -0
  81. package/scenarios.bak.1774780058/openai.js +102 -0
  82. package/scenarios.bak.1774780058/prompt.js +118 -0
  83. package/scenarios.bak.1774780058/promptFishbowl.js +76 -0
  84. package/scenarios.bak.1774780058/search.brave.com.js +25 -0
  85. package/scenarios.bak.1774780058/sh.js +15 -0
  86. package/scenarios.bak.1774780058/test-wsio.js +26 -0
  87. package/scenarios.bak.1774780058/testToolset.js +42 -0
  88. package/scenarios.bak.1774780058/toolset.js +16 -0
  89. package/scenarios.bak.1774780058/toolset.test.js +141 -0
  90. package/scenarios.bak.1774780058/write_file_syntax.test.js +145 -0
  91. package/scenarios.bak.1774780058/write_file_validation/README.md +30 -0
  92. package/scenarios.bak.1774780058/write_file_validation/bad.js +3 -0
  93. package/scenarios.bak.1774780058/write_file_validation/good.js +4 -0
  94. package/scenarios.bak.1774780058/write_file_validation/test.sh +43 -0
  95. package/scenarios.bak.1774780058/wsClient.js +69 -0
  96. package/scenarios.bak.1774780058/xai_responses.integration.test.js +57 -0
  97. package/scenarios.bak.1774780058/xai_responses.test.js +154 -0
  98. package/scenarios.bak.1774780058/xaicoll.js +50 -0
  99. package/scenarios.bak.1774780058/xaifiles.js +48 -0
  100. package/types/AgentManager.d.ts +4 -3
  101. package/types/index.d.ts +3 -1
  102. package/utils/syntax_check.sh +61 -0
  103. package/utils/test.sh +46 -0
  104. /package/{examples/askDave.js → examples.bak.1774780058/ask_agent.js} +0 -0
  105. /package/{examples/coderev.js → examples.bak.1774780058/coderev_agent.js} +0 -0
  106. /package/{examples/daisy.js → examples.bak.1774780058/daisy_agent.js} +0 -0
  107. /package/{examples/docsDave.js → examples.bak.1774780058/docs_agent.js} +0 -0
  108. /package/{examples/gpt.js → examples.bak.1774780058/gpt_agent.js} +0 -0
  109. /package/{examples/grok.js → examples.bak.1774780058/grok_agent.js} +0 -0
  110. /package/{examples/npmDave.js → examples.bak.1774780058/npm_agent.js} +0 -0
  111. /package/{examples/promptDave.js → examples.bak.1774780058/prompt_agent.js} +0 -0
  112. /package/{examples/readmeDave.js → examples.bak.1774780058/readme_agent.js} +0 -0
@@ -0,0 +1,137 @@
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 = 'ask_agent';
6
+ const api = 'xai';
7
+ let secret = '';
8
+
9
+ const args = parseArgs();
10
+
11
+ let input;
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
+ const options = { tools: [] };
21
+ options.tools.push({
22
+ type: 'web_search'
23
+ });
24
+ options.tools.push({
25
+ type: 'x_search'
26
+ });
27
+
28
+ if (args['secret']) {
29
+ secret = args['secret'];
30
+ }
31
+ if (args['model'] || true) {
32
+ options.model = args['model'] || 'grok-4-fast-reasoning';
33
+ }
34
+ if (args['temperature']) {
35
+ options.temperature = parseFloat(args['temperature']);
36
+ }
37
+ if (args['tokens']) {
38
+ options.max_output_tokens = parseInt(args['tokens']);
39
+ }
40
+ if (args['top_p']) {
41
+ options.top_p = parseFloat(args['top_p']);
42
+ }
43
+ const reasoning = true;
44
+ if (reasoning) {
45
+ options.reasoning = {
46
+ effort: 'medium',
47
+ summary: 'auto'
48
+ }
49
+ }
50
+ const toolsetMode = 'auto';
51
+ const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
52
+
53
+ function printHelp() {
54
+ console.log(`'${name} --help' You are looking at it.
55
+
56
+ ## USAGE MODES:
57
+
58
+ ### 1. Direct Call (One-Shot, Positional ONLY):
59
+ ./examples/${name}.js "Your query here" [--options]
60
+
61
+ ### 2. Interactive CLI (no positional arg):
62
+ ./examples/${name}.js [--options]
63
+
64
+ ### 3. WS Server (no positional arg):
65
+ ./examples/${name}.js --serve 8080 [--secret mysecret] [--options]
66
+
67
+ ### 4. WS Client (no positional arg):
68
+ ./examples/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
69
+
70
+ ### 5. Hybrid (Server + Client, no positional arg):
71
+ ./examples/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
72
+
73
+ ## SERVER OPTIONS EXPLAINED:
74
+ --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., 'search_agent'). Runs indefinitely until Ctrl+C.
75
+
76
+ --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.
77
+
78
+ --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.
79
+
80
+ Note: Server/Client/Hybrid IGNORES positional input arg (use CLI modes instead). Hybrid: This agent serves AND uses remote tools.
81
+
82
+ ## OPTIONS:
83
+ --model [grok-4-fast-reasoning|...] (default: grok-4-fast-reasoning)
84
+ --temperature [float] (-2 to +2)
85
+ --tokens [number] (max output tokens)
86
+ --top_p [float]
87
+ --context [number] (default: 250000)
88
+
89
+ ## SERVER TOOLS (when no input):
90
+ Exposes as 'search_agent' tool for chaining.
91
+ `);
92
+ process.exit();
93
+ }
94
+
95
+ if (help) {
96
+ printHelp();
97
+ }
98
+
99
+ const tool_call_name = 'search_agent';
100
+ const tool_call_description = `Guide for this smart online AI Agent:
101
+ - query: Formulate ONE efficient, comprehensive search query in natural language, combining multiple sources/subjects/domains; mention optional sources if needed. Avoid multiple queries—consolidate into a single one.`.trim();
102
+
103
+ const prompt = `**CRITICAL: STRICT NO-CODING RULE** - You are a smart search agent. Stick to web_search, x_search, open_link, history_search ONLY. NEVER use or request:
104
+ - Coding tools (javascript_interpreter, execute_bash_script, write_file, read_file, execute_remote_script).
105
+ - Generate or edit code.
106
+ If coding request, decline politely and suggest code_agent.js.
107
+
108
+ Respond briefly and directly, using minimal words. Reason step-by-step first. Focus solely on core point; avoid elaboration or follow-ups. If unclear, ask clarifying questions before proceeding.
109
+
110
+ Current date: April 01, 2026.`.trim();
111
+
112
+ const agent = new AgentManager({ name, secret });
113
+ agent.setup({
114
+ prompt,
115
+ api,
116
+ options,
117
+ toolsetMode,
118
+ contextWindow
119
+ });
120
+ const toolset = agent.getToolset();
121
+ if (toolset) {
122
+ agent.addGenericToolcall('open_link');
123
+ agent.addGenericToolcall('send_email');
124
+ agent.addGenericToolcall('history_search');
125
+ // Removed conditional coding tools (javascript, bash, ssh) for NO-CODING compliance
126
+ }
127
+
128
+ const cliIntro = `${name} ${options.model}.
129
+ - context: ${contextWindow}
130
+ ${tool_call_name}`.trim();
131
+
132
+ if (input) {
133
+ const RES = await agent.directCall(input);
134
+ console.log(RES);
135
+ } else {
136
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
137
+ }
@@ -0,0 +1,149 @@
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 = 'code_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 = {
16
+ tools: []
17
+ }
18
+ options.tools.push({
19
+ type: 'web_search'
20
+ });
21
+ if (args['secret']) {
22
+ secret= args['secret'];
23
+ }
24
+ // Set properties only if provided via command line (except model which has default)
25
+ if (args['model'] || true) { // model gets default value
26
+ // @ts-ignore
27
+ options.model = args['model'] || 'grok-4-1-fast-reasoning';
28
+ }
29
+ // if (args['temperature']) {
30
+ options.temperature = 0.2;
31
+ // }
32
+ if (args['tokens']) {
33
+ options.max_output_tokens = parseInt(args['tokens']);
34
+ }
35
+ if (args['top_p']) {
36
+ options.top_p = parseFloat(args['top_p']);
37
+ }
38
+ const reasoning = args['reasoning'] ? args['reasoning'] : 'medium';
39
+ if (reasoning) {
40
+ options.reasoning = {
41
+ // @ts-ignore
42
+ effort:reasoning,
43
+ summary: 'auto'
44
+ }
45
+ }
46
+ const toolsetMode = 'auto';
47
+ const contextWindow = args['context'] ? parseInt(args['context']) : 2565000;
48
+
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 [string] : model name
58
+ --top_p [float]: number > 0, 0.1 means no top_p
59
+ --reasoning [low|medium|high]
60
+ --tools [javascript,bash,nushell,ssh] 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
+ `);
68
+ process.exit()
69
+ }
70
+
71
+ if (help) {
72
+ printHelp();
73
+ }
74
+
75
+ const agent = new AgentManager({ name, secret});
76
+ const sys = (await agent.environment()).system;
77
+ const prompt = `
78
+ You are a coding assistant specializing in Bash and JavaScript (ESM/ESNext), with support for other languages. Assist by executing, reading, creating, querying, explaining, or helping with code. Use tools like 'execute_bash_script' for code execution and for writing and reading files, stay in the current working folder. Provide clear, step-by-step responses, examples, and ensure safety compliance.
79
+ ---env
80
+ \${sys}
81
+ ---
82
+
83
+ **MANDATORY MEMORY PROTOCOL (For EVERY query/task - NO EXCEPTIONS):**
84
+
85
+ Connected clients (todo_agent, readme_agent, npm_agent, docs_agent, **memory_agent**) are available as tools. **ALWAYS** use **memory_agent** FIRST and LAST:
86
+
87
+ 1. **RECALL PHASE (Step 1 of EVERY response)**:
88
+ - Call \`memory_agent "Recall relevant memories: tasks, errors, prefs for [keywords from user query]. List recent if empty."\`
89
+ - Incorporate recalled info (e.g., avoid known errors, resume tasks, apply prefs like temp=0.2).
90
+
91
+ 2. **CORE ACTION**:
92
+ - Perform coding assistance (tools: execute_bash_script, javascript_interpreter, read_file/write_file, web_search, etc.).
93
+ - Delegate to specialists if relevant:
94
+ - todo_agent: Tasks/TODO.md
95
+ - readme_agent: README.md
96
+ - npm_agent: NPM modules/package.json
97
+ - docs_agent: Documentation
98
+ - memory_agent: Persistent storage
99
+
100
+ 3. **WRITE PHASE (Step 3 of EVERY response)**:
101
+ - Call \`memory_agent "Store updates: [new tasks/errors/prefs/decisions from this interaction]. E.g., 'Task: [next step]', 'Error: [issue]', 'Pref: [setting]'"\`
102
+ - This ensures persistence across sessions/agents, prevents loops/token burn.
103
+
104
+ **EXAMPLE FLOW**:
105
+ User: "Fix bug in main.js"
106
+ - 1. memory_agent "Recall: tasks errors code bugs main.js"
107
+ - 2. read_file main.js → analyze/fix → write_file
108
+ - 3. memory_agent "Write: Task completed: fixed main.js bug. New task: add tests."
109
+
110
+ **PRIORITIES**:
111
+ - Safety: CWD-only, no escapes, validate before write.
112
+ - Efficiency: Use memories to skip repeats (e.g., "Known error: git conflict → skip").
113
+ - Step-by-step: Clear responses with code blocks.
114
+ - Current date: March 27, 2026.
115
+
116
+ FOLLOW MEMORY PROTOCOL RIGIDLY - it's how multi-agent coordination works!
117
+ `.trim();
118
+ agent.setup({
119
+ prompt,
120
+ api,
121
+ options,
122
+ toolsetMode,
123
+ contextWindow
124
+ });
125
+
126
+ const toolset = agent.getToolset();
127
+ if (toolset) {
128
+ agent.addGenericToolcall('history_search');
129
+ agent.addGenericToolcall('javascript_interpreter');
130
+ agent.addGenericToolcall('execute_bash_script');
131
+ agent.addGenericToolcall('read_file');
132
+ agent.addGenericToolcall('write_file');
133
+
134
+ const addTools = (args['tools']) ? args['tools'].split(',') : [''];
135
+ if (addTools.includes('ssh')) {
136
+ agent.addGenericToolcall('execute_remote_script');
137
+ }
138
+ }
139
+ const cliIntro = `
140
+ ${name} ${options.model}
141
+ - context: ${contextWindow}
142
+ - **Memory Protocol ACTIVE**: Auto-recalls/writes via memory_agent for every query!
143
+ `.trim();
144
+ const description = `
145
+ Main CodeServer hub: Coding expert + delegates to todo/readme/npm/docs/memory agents.
146
+ ALWAYS uses memory_agent for persistent tasks/errors/prefs.
147
+ `.trim();
148
+
149
+ await agent.start(serve, connect, cliIntro, "code_agent", description);
@@ -0,0 +1,47 @@
1
+ #!/bin/bash
2
+ if [ $# -lt 1 ] || [ $# -gt 2 ]; then
3
+ echo "Usage: $0 <PORT> [SECRET] # PORT: 1024-65535, SECRET: optional (defaults to '123')"
4
+ exit 1
5
+ fi
6
+
7
+ PORT="$1"
8
+ SECRET="${2:-123}"
9
+
10
+ if [ -z "$SECRET" ] || [ ${#SECRET} -lt 3 ]; then
11
+ echo "Error: SECRET must be at least 3 characters: '$SECRET'"
12
+ exit 1
13
+ fi
14
+
15
+ if ! [[ "$PORT" =~ ^[0-9]+$ ]] || [ "$PORT" -lt 1024 ] || [ "$PORT" -gt 65535 ]; then
16
+ echo "Error: Invalid port number: $PORT. Must be between 1024 and 65535."
17
+ exit 1
18
+ fi
19
+
20
+ # Compute paths relative to THIS script's location (portable from anywhere)
21
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
22
+ PROJECT_DIR="$( cd "$( dirname "${SCRIPT_DIR}" )" && pwd )"
23
+ FOLDER=$(basename "$PROJECT_DIR")
24
+
25
+ echo "Starting CodeServer on port ${PORT} in folder '${FOLDER}' (SCRIPT_DIR: ${SCRIPT_DIR}) with SECRET '${SECRET}'..."
26
+
27
+ # Delete existing processes with folder_port suffix
28
+ pm2 delete "${FOLDER}_code_agent_${PORT}" 2>/dev/null || true
29
+ pm2 delete "${FOLDER}_todo_agent_${PORT}" 2>/dev/null || true
30
+ pm2 delete "${FOLDER}_readme_agent_${PORT}" 2>/dev/null || true
31
+ pm2 delete "${FOLDER}_npm_agent_${PORT}" 2>/dev/null || true
32
+ pm2 delete "${FOLDER}_docs_agent_${PORT}" 2>/dev/null || true
33
+ pm2 delete "${FOLDER}_test_agent_${PORT}" 2>/dev/null || true
34
+ pm2 delete "${FOLDER}_memory_agent_${PORT}" 2>/dev/null || true
35
+
36
+ # Spawn main Agent / server (absolute paths to scripts)
37
+ pm2 start "${SCRIPT_DIR}/code_agent.js" --name "${FOLDER}_code_agent_${PORT}" -- --serve "${PORT}" --tools javascript --secret "${SECRET}"
38
+ # Attach clients
39
+ pm2 start "${SCRIPT_DIR}/todo_agent.js" --name "${FOLDER}_todo_agent_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
40
+ pm2 start "${SCRIPT_DIR}/readme_agent.js" --name "${FOLDER}_readme_agent_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
41
+ pm2 start "${SCRIPT_DIR}/npm_agent.js" --name "${FOLDER}_npm_agent_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
42
+ pm2 start "${SCRIPT_DIR}/docs_agent.js" --name "${FOLDER}_docs_agent_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
43
+ pm2 start "${SCRIPT_DIR}/test_agent.js" --name "${FOLDER}_test_agent_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
44
+ pm2 start "${SCRIPT_DIR}/memory_agent.js" --name "${FOLDER}_memory_agent_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
45
+
46
+ echo "CodeServer processes spawned with prefix '${FOLDER}_' and suffix _${PORT}. Check with: pm2 list | grep '${FOLDER}_${PORT}'"
47
+ echo "dave --connect ws://127.0.0.1:${PORT}/ws --secret '$SECRET'"
@@ -0,0 +1,170 @@
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 = 'daisy_agent';
6
+ const api = 'xai';
7
+ let secret = '';
8
+
9
+ const args = parseArgs();
10
+
11
+ let input;
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
+ } else {
35
+ options.temperature = 0.8;
36
+ }
37
+ if (args['tokens']) {
38
+ options.max_output_tokens = parseInt(args['tokens']);
39
+ }
40
+ if (args['top_p']) {
41
+ options.top_p = parseFloat(args['top_p']);
42
+ }
43
+ const reasoning = true;
44
+ if (reasoning) {
45
+ options.reasoning = {
46
+ effort: 'medium',
47
+ summary: 'auto'
48
+ }
49
+ }
50
+ const toolsetMode = 'auto';
51
+ const contextWindow = args['context'] ? parseInt(args['context']) : 1900000;
52
+
53
+ function printHelp() {
54
+ console.log(`
55
+ '${name} --help' You are looking at it.
56
+
57
+ ## USAGE MODES:
58
+
59
+ ### 1. Direct Call (One-Shot, Positional ONLY):
60
+ ./examples/${name}.js "Generate lyrics for pop song" [--options]
61
+
62
+ ### 2. Interactive CLI (no positional arg):
63
+ ./examples/${name}.js [--options]
64
+
65
+ ### 3. WS Server (no positional arg):
66
+ ./examples/${name}.js --serve 8080 [--secret mysecret] [--options]
67
+
68
+ ### 4. WS Client (no positional arg):
69
+ ./examples/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
70
+
71
+ ### 5. Hybrid (Server + Client, no positional arg):
72
+ ./examples/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
73
+
74
+ ## SERVER OPTIONS EXPLAINED:
75
+ --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., 'daisy_agent'). Runs indefinitely until Ctrl+C.
76
+
77
+ --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.
78
+
79
+ --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.
80
+
81
+ Note: Server/Client/Hybrid IGNORES positional input arg (use CLI modes instead). Hybrid: This agent serves AND uses remote tools.
82
+
83
+ ## OPTIONS:
84
+ --model [grok-4-fast-reasoning|...] (default: grok-4-fast-reasoning)
85
+ --temperature [float] (-2 to +2, default 0.8 for creativity)
86
+ --tokens [number] (max output tokens)
87
+ --top_p [float]
88
+ --context [number] (default: 1900000)
89
+
90
+ ## SERVER TOOLS (when no input):
91
+ Exposes as 'daisy_agent' tool for chaining.
92
+ `);
93
+ process.exit();
94
+ }
95
+
96
+ if (help) {
97
+ printHelp();
98
+ }
99
+
100
+ const tool_call_name = 'daisy_agent';
101
+ const tool_call_description = `
102
+ Daisy Music Assistant:
103
+ - "Lyrics for [theme]" → Generate lyrics.
104
+ - "Suno prompt: [style]" → Optimized Suno prompt.
105
+ - "ffmpeg [task] on file.wav" → Bash script to run.
106
+ - web_search: Research chords/lyrics.
107
+ - execute_bash_script: Processes your local files safely.
108
+ `.trim();
109
+
110
+ const prompt = `
111
+ You are ${name}, a helpful music creation and editing assistant for the user's computer.
112
+
113
+ Core expertise:
114
+ - Generate lyrics: Creative, structured (verses, chorus), themed, rhyming.
115
+ - Suno AI prompts: Detailed, vivid descriptions (genre, mood, instruments, structure, vocals).
116
+ - Local audio editing: Use execute_bash_script with ffmpeg/sox commands. Provide exact bash snippets first, confirm before running. Examples:
117
+ * Trim: ffmpeg -i input.mp3 -ss 00:00:30 -t 00:01:00 output.mp3
118
+ * Concat: echo "file 'a.mp3'" > list.txt; ffmpeg -f concat -i list.txt out.mp3
119
+ * Sox effects: sox input.wav output.wav fade 0 3 2 norm
120
+ * Convert: ffmpeg -i video.mp4 audio.aac
121
+ - Music theory: Chords, scales, BPM, EQ tips.
122
+ - Workflows: Step-by-step for mixing, mastering, layering tracks.
123
+
124
+ Behavior:
125
+ - Be creative & enthusiastic!
126
+ - Step-by-step: Explain, provide code, suggest files in current dir.
127
+ - Safety: Quote bash commands; ask confirmation for destructive ops (e.g., overwrite).
128
+ - Use web_search for inspiration/lyrics if needed.
129
+ - Output ready-to-copy bash for ffmpeg/sox.
130
+ - List files if unclear: Use ls *.wav *.mp3 etc. via bash.
131
+
132
+ Current env: Ubuntu, ffmpeg & sox installed, cwd: /home/jd/devpri/js/hello-dave
133
+
134
+ Respond concisely but completely. Use markdown for code/lyrics/prompts.
135
+ `.trim();
136
+
137
+ const agent = new AgentManager({ name, secret });
138
+ agent.setup({
139
+ prompt,
140
+ api,
141
+ options,
142
+ toolsetMode,
143
+ contextWindow
144
+ });
145
+ const toolset = agent.getToolset();
146
+ if (toolset) {
147
+ agent.addGenericToolcall('open_link');
148
+ agent.addGenericToolcall('send_email');
149
+ agent.addGenericToolcall('execute_bash_script');
150
+ agent.addGenericToolcall('read_file');
151
+ agent.addGenericToolcall('write_file');
152
+ }
153
+
154
+ const cliIntro = `
155
+ ${name} ${options.model} ready! (temp: ${options.temperature}, context: ${contextWindow})
156
+
157
+ Ask me to:
158
+ - Write lyrics
159
+ - Craft Suno prompts
160
+ - Edit audio: "fade out my track.mp3" → I'll give ffmpeg cmd
161
+ Type /help for more.
162
+ ${tool_call_name}
163
+ `.trim();
164
+
165
+ if (input) {
166
+ const RES = await agent.directCall(input);
167
+ console.log(RES);
168
+ } else {
169
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
170
+ }
@@ -0,0 +1,148 @@
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 = 'docs_agent';
6
+ const api = 'xai';
7
+ let secret = '';
8
+
9
+ const args = parseArgs();
10
+
11
+ let input;
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
+ const options = { tools: [] };
21
+ options.tools.push({
22
+ type: 'web_search'
23
+ });
24
+
25
+ if (args['secret']) {
26
+ secret = args['secret'];
27
+ }
28
+ if (args['model'] || true) {
29
+ options.model = args['model'] || 'grok-4-fast-reasoning';
30
+ }
31
+ if (args['temperature']) {
32
+ options.temperature = parseFloat(args['temperature']);
33
+ }
34
+ if (args['tokens']) {
35
+ options.max_output_tokens = parseInt(args['tokens']);
36
+ }
37
+ if (args['top_p']) {
38
+ options.top_p = parseFloat(args['top_p']);
39
+ }
40
+ const reasoning = true;
41
+ if (reasoning) {
42
+ options.reasoning = {
43
+ effort: 'medium',
44
+ summary: 'auto'
45
+ }
46
+ }
47
+ const toolsetMode = 'auto';
48
+ const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
49
+
50
+ function printHelp() {
51
+ console.log(`
52
+ '${name} --help' You are looking at it.
53
+
54
+ ## USAGE MODES:
55
+
56
+ ### 1. Direct Call (One-Shot, Positional ONLY):
57
+ ./examples/${name}.js "Create a doc on Node.js basics" [--options]
58
+
59
+ ### 2. Interactive CLI (no positional arg):
60
+ ./examples/${name}.js [--options]
61
+
62
+ ### 3. WS Server (no positional arg):
63
+ ./examples/${name}.js --serve 8080 [--secret mysecret] [--options]
64
+
65
+ ### 4. WS Client (no positional arg):
66
+ ./examples/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
67
+
68
+ ### 5. Hybrid (Server + Client, no positional arg):
69
+ ./examples/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
70
+
71
+ ## SERVER OPTIONS EXPLAINED:
72
+ --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., 'agent_docs'). Runs indefinitely until Ctrl+C.
73
+
74
+ --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.
75
+
76
+ --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.
77
+
78
+ Note: Server/Client/Hybrid IGNORES positional input arg (use CLI modes instead). Hybrid: This agent serves AND uses remote tools.
79
+
80
+ ## OPTIONS:
81
+ --model [grok-4-fast-reasoning|...] (default: grok-4-fast-reasoning)
82
+ --temperature [float] (-2 to +2)
83
+ --tokens [number] (max output tokens)
84
+ --top_p [float]
85
+ --context [number] (default: 250000)
86
+
87
+ ## SERVER TOOLS (when no input):
88
+ Exposes as 'agent_docs' tool for chaining.
89
+ `);
90
+ process.exit();
91
+ }
92
+
93
+ if (help) {
94
+ printHelp();
95
+ }
96
+
97
+ const tool_call_name = 'agent_docs';
98
+ const tool_call_description = `
99
+ documentation maintainer that creates, updates, retrieves, and organizes Markdown files in ./docs/ for any subject.
100
+ `.trim();
101
+
102
+ const prompt = `
103
+ You are docs_agent, a documentation maintainer that creates, updates, retrieves, and organizes Markdown files in ./docs/ (relative to cwd). You own this folder—create it if missing. All content is in clean Markdown (.md files only). Filenames must descriptively indicate content (e.g., "introduction-to-nodejs.md", "react-hooks-guide.md"—kebab-case, no spaces).
104
+
105
+ **CRITICAL: STRICT NO-CODING RULE** - Stick to docs management ONLY. NEVER:
106
+ - Use coding tools (e.g., javascript_interpreter, read_file, write_file, syntax_check, npm_module_inspector).
107
+ - Generate, execute, or edit code (JS/Python/Bash beyond safe docs ops).
108
+ - Misuse bash for anything beyond safe ./docs/*.md ops (e.g., ls docs/, cat docs/file.md, echo > docs/file.md, cp docs/file.md docs/file.md.bak).
109
+ - Touch files outside ./docs/.
110
+ If asked to code or edit non-docs files, decline: "For coding or other tasks, use specialized agents like code_agent. I'll handle ./docs/ only."
111
+
112
+ Behaviors:
113
+ - AUTONOMOUS: Use tools to manage files without user intervention. For reading: \`ls docs/*.md\` then \`cat docs/[filename].md\`. For writing/updating: Backup first (\`cp docs/old.md docs/old.md.bak\`), then \`echo "[full Markdown content]" > docs/[filename].md\`.
114
+ - RESEARCH: Use web_search or browse_page to gather accurate info before creating/updating.
115
+ - STRUCTURE: Markdown best practices—use # Headings, ## Subheadings, - Lists, \`code\` inline, \`\`\`blocks\`\`\`, links [text](url). Keep concise yet comprehensive.
116
+ - RETRIEVAL: Display full file content in Markdown format when asked.
117
+ - SAFETY: Never delete files. Confirm overwrites via backup. If unsure, ask for clarification.
118
+ - FILENAME SUGGESTION: Propose and use logical names based on topic (e.g., for "AI agents", use "ai-agents-overview.md").
119
+ - OUTPUT: Respond in Markdown. For file ops, show before/after diffs if changed.
120
+
121
+ Use execute_bash_script ONLY for safe ./docs/ ops and inspections (ls, cat, cp, echo >). Use web_search/browse_page for research. Reason step-by-step.
122
+ `.trim();
123
+
124
+ const agent = new AgentManager({ name, secret });
125
+ agent.setup({
126
+ prompt,
127
+ api,
128
+ options,
129
+ toolsetMode,
130
+ contextWindow
131
+ });
132
+ const toolset = agent.getToolset();
133
+ if (toolset) {
134
+ agent.addGenericToolcall('execute_bash_script');
135
+ }
136
+
137
+ const cliIntro = `
138
+ ${name} ${options.model}.
139
+ - context: ${contextWindow}
140
+ ${tool_call_name}
141
+ `.trim();
142
+
143
+ if (input) {
144
+ const RES = await agent.directCall(input);
145
+ console.log(RES);
146
+ } else {
147
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
148
+ }