@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,132 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * Full modes: Direct call (one-shot positional ONLY), CLI interactive (no args), WS Server (--serve), Client (--connect).
4
+ * Direct: grok_agent.js "What is your task?"
5
+ * CLI: grok_agent.js
6
+ * Server: grok_agent.js --serve 8080
7
+ */
8
+ import { AgentManager } from '@j-o-r/hello-dave';
9
+ import { parseArgs } from '@j-o-r/sh';
10
+
11
+ const name = 'grok_agent';
12
+ const api = 'xai';
13
+ let secret = '';
14
+
15
+ const args = parseArgs();
16
+
17
+ let input; // Directcall input (positional ONLY - NO pipe)
18
+ if (args._.length === 1 && typeof args._[0] === 'string' && args._[0].trim() !== '') {
19
+ input = args._[0].trim();
20
+ }
21
+
22
+ const help = args['help'] || false;
23
+ const connect = args['connect'] ? args['connect'] : undefined;
24
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
25
+
26
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
27
+ const options = { tools: [] };
28
+ options.tools.push({
29
+ type: 'web_search'
30
+ });
31
+ options.tools.push({
32
+ type: 'x_search'
33
+ });
34
+
35
+ if (args['secret']) {
36
+ secret = args['secret'];
37
+ }
38
+ if (args['model'] || true) {
39
+ options.model = args['model'] || 'grok-4-fast-reasoning';
40
+ }
41
+ if (args['temperature']) {
42
+ options.temperature = parseFloat(args['temperature']);
43
+ }
44
+ if (args['tokens']) {
45
+ options.max_output_tokens = parseInt(args['tokens']);
46
+ }
47
+ if (args['top_p']) {
48
+ options.top_p = parseFloat(args['top_p']);
49
+ }
50
+ const reasoning = true;
51
+ if (reasoning) {
52
+ options.reasoning = {
53
+ effort: 'medium',
54
+ summary: 'auto'
55
+ }
56
+ }
57
+ const toolsetMode = 'auto';
58
+ const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
59
+
60
+ function printHelp() {
61
+ console.log(`
62
+ '${name} --help' You are looking at it.
63
+
64
+ ## USAGE MODES:
65
+
66
+ ### 1. Direct Call (One-Shot, Positional ONLY):
67
+ ./examples/${name}.js "What is your task?" [--options]
68
+
69
+ ### 2. Interactive CLI (no positional arg):
70
+ ./examples/${name}.js [--options]
71
+
72
+ ### 3. WS Server (no positional arg):
73
+ ./examples/${name}.js --serve 8080 [--secret mysecret] [--options]
74
+
75
+ ### 4. WS Client (no positional arg):
76
+ ./examples/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
77
+
78
+ ### 5. Hybrid (Server + Client, no positional arg):
79
+ ./examples/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
80
+
81
+ ## SERVER OPTIONS EXPLAINED:
82
+ --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. Runs indefinitely until Ctrl+C.
83
+
84
+ --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.
85
+
86
+ --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.
87
+
88
+ Note: Server/Client/Hybrid IGNORES positional input arg (use CLI modes instead). Hybrid: This agent serves AND uses remote tools.
89
+
90
+ ## OPTIONS:
91
+ --model [grok-4-fast-reasoning|...] (default: grok-4-fast-reasoning)
92
+ --temperature [float] (-2 to +2)
93
+ --tokens [number] (max output tokens)
94
+ --top_p [float]
95
+ --context [number] (default: 250000)
96
+
97
+ ## SERVER TOOLS (when no input):
98
+ Exposes as brief responder tool for chaining.
99
+ `);
100
+ process.exit()
101
+ }
102
+
103
+ if (help) {
104
+ printHelp();
105
+ }
106
+
107
+ const prompt = `
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
+ `.trim();
110
+
111
+ const agent = new AgentManager({ name, secret });
112
+ agent.setup({
113
+ prompt,
114
+ api,
115
+ options,
116
+ toolsetMode,
117
+ contextWindow
118
+ });
119
+
120
+ const cliIntro = `
121
+ ${name} ${options.model}.
122
+ - context: ${contextWindow}. Tools: web_search, x_search.
123
+ Brief responder ready for CLI/Server/Client modes.
124
+ `.trim();
125
+
126
+ if (input) {
127
+ // one-shot
128
+ const RES = await agent.directCall(input);
129
+ console.log(RES);
130
+ } else {
131
+ await agent.start(serve, connect, cliIntro);
132
+ }
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * ONE SHOT , direct call example
4
+ * ```bash
5
+ * echo "What is your task?" | examples/grok.js
6
+ * ```
7
+ */
8
+ import { AgentManager } from '@j-o-r/hello-dave';
9
+ import { parseArgs, readIn } from '@j-o-r/sh';
10
+
11
+ const name = 'ask_grok';
12
+ const api = 'xai';
13
+ let secret = '';
14
+
15
+ const input = await readIn();
16
+ const args = parseArgs();
17
+ const help = args['help'] || false;
18
+
19
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
20
+ const options = {
21
+ tools: []
22
+ }
23
+ options.tools.push({
24
+ type: 'web_search'
25
+ });
26
+ options.tools.push({
27
+ type: 'x_search'
28
+ });
29
+
30
+ // Set properties only if provided via command line (except model which has default)
31
+ if (args['model'] || true) { // model gets default value
32
+ // @ts-ignore || grok-4-1-fast-non-reasoning
33
+ options.model = args['model'] || 'grok-4.20-multi-agent-0309';
34
+ }
35
+ if (args['temperature']) {
36
+ options.temperature = parseFloat(args['temperature']);
37
+ }
38
+ if (args['tokens']) {
39
+ options.max_output_tokens = parseInt(args['tokens']);
40
+ }
41
+ if (args['top_p']) {
42
+ options.top_p = parseFloat(args['top_p']);
43
+ }
44
+ const reasoning = true // args['reasoning'] ? args['reasoning'] : null;
45
+ if (reasoning) {
46
+ options.reasoning = {
47
+ effort: 'medium',
48
+ summary: 'auto'
49
+ }
50
+ }
51
+ // Large context on grok-4-fast
52
+ const contextWindow = args['context'] ? parseInt(args['context']) : 1900000;
53
+ const toolsetMode = 'auto';
54
+
55
+ function printHelp() {
56
+ console.log(`
57
+ '${name} --help' You are looking at it.
58
+ '
59
+ OPTIONS:
60
+ --tokens [number]: max generated tokens
61
+ --context [number] : truncate message history to context-windows size default 130000
62
+ --temperature [float] : -2 / +2
63
+ --model ['grok-4-1-fast-reasoning'|'grok-4-1-fast-non-reasoning'|'grok-code-fast-1'|'grok-4-fast-reasoning'|'grok-4-fast-non-reasoning']
64
+ --top_p [float]: number > 0, 0.1 means no top_p
65
+ --reasoning [low|high]
66
+
67
+ USAGE:
68
+
69
+ \`\`\`bash
70
+ echo "What is ..." | grok.js
71
+ \`\`\`
72
+
73
+ `);
74
+ process.exit()
75
+ }
76
+ if (help) {
77
+ printHelp();
78
+ }
79
+
80
+ if (!input || input.trim() === '') {
81
+ printHelp();
82
+ }
83
+
84
+ const prompt = `
85
+ 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.
86
+ `.trim();
87
+
88
+ const agent = new AgentManager({ name, secret });
89
+ agent.setup({
90
+ prompt,
91
+ api,
92
+ options,
93
+ toolsetMode,
94
+ contextWindow
95
+ });
96
+
97
+ const res = await agent.directCall(input);
98
+ console.log(res);
@@ -0,0 +1,99 @@
1
+ # Backup of current grok_agent.js before fix
2
+ #!/usr/bin/env node
3
+ /*
4
+ * ONE SHOT , direct call example
5
+ * ```bash
6
+ * echo \"What is your task?\" | examples/grok_agent.js
7
+ * ```
8
+ */
9
+ import { AgentManager } from '@j-o-r/hello-dave';
10
+ import { parseArgs, readIn } from '@j-o-r/sh';
11
+
12
+ const name = 'grok_agent';
13
+ const api = 'xai';
14
+ let secret = '';
15
+
16
+ const input = await readIn();
17
+ const args = parseArgs();
18
+ const help = args['help'] || false;
19
+
20
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
21
+ const options = {
22
+ tools: []
23
+ }
24
+ options.tools.push({
25
+ type: 'web_search'
26
+ });
27
+ options.tools.push({
28
+ type: 'x_search'
29
+ });
30
+
31
+ // Set properties only if provided via command line (except model which has default)
32
+ if (args['model'] || true) { // model gets default value
33
+ // @ts-ignore || grok-4-1-fast-non-reasoning
34
+ options.model = args['model'] || 'grok-4.20-multi-agent-0309';
35
+ }
36
+ if (args['temperature']) {
37
+ options.temperature = parseFloat(args['temperature']);
38
+ }
39
+ if (args['tokens']) {
40
+ options.max_output_tokens = parseInt(args['tokens']);
41
+ }
42
+ if (args['top_p']) {
43
+ options.top_p = parseFloat(args['top_p']);
44
+ }
45
+ const reasoning = true // args['reasoning'] ? args['reasoning'] : null;
46
+ if (reasoning) {
47
+ options.reasoning = {
48
+ effort: 'medium',
49
+ summary: 'auto'
50
+ }
51
+ }
52
+ // Large context on grok-4-fast
53
+ const contextWindow = args['context'] ? parseInt(args['context']) : 1900000;
54
+ const toolsetMode = 'auto';
55
+
56
+ function printHelp() {
57
+ console.log(`
58
+ '${name} --help' You are looking at it.
59
+ '
60
+ OPTIONS:
61
+ --tokens [number]: max generated tokens
62
+ --context [number] : truncate message history to context-windows size default 130000
63
+ --temperature [float] : -2 / +2
64
+ --model ['grok-4-1-fast-reasoning'|'grok-4-1-fast-non-reasoning'|'grok-code-fast-1'|'grok-4-fast-reasoning'|'grok-4-fast-non-reasoning']
65
+ --top_p [float]: number > 0, 0.1 means no top_p
66
+ --reasoning [low|high]
67
+
68
+ USAGE:
69
+
70
+ \`\`\`bash
71
+ echo \"What is ...\" | grok_agent.js
72
+ \`\`\`
73
+
74
+ `);
75
+ process.exit()
76
+ }
77
+ if (help) {
78
+ printHelp();
79
+ }
80
+
81
+ if (!input || input.trim() === '') {
82
+ printHelp();
83
+ }
84
+
85
+ const prompt = `
86
+ 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.
87
+ `.trim();
88
+
89
+ const agent = new AgentManager({ name, secret });
90
+ agent.setup({
91
+ prompt,
92
+ api,
93
+ options,
94
+ toolsetMode,
95
+ contextWindow
96
+ });
97
+
98
+ const res = await agent.directCall(input);
99
+ console.log(res);
@@ -0,0 +1 @@
1
+ # Full backup of grok_agent.js before printHelp clarity update
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * Full modes: Direct call (one-shot), CLI interactive, WS Server (--serve), Client (--connect).
4
+ * Direct: grok_agent.js "What is your task?"
5
+ * Pipe/Stdin: echo "What is your task?" | grok_agent.js
6
+ * CLI: grok_agent.js
7
+ * Server: grok_agent.js --serve 8080
8
+ */
9
+ import { AgentManager } from '@j-o-r/hello-dave';
10
+ import { parseArgs } from '@j-o-r/sh';
11
+
12
+ const name = 'grok_agent';
13
+ const api = 'xai';
14
+ let secret = '';
15
+
16
+ let input; // Directcall input (positional or fallback to readIn for pipe)
17
+ const args = parseArgs();
18
+
19
+ if (args._.length === 1 && typeof args._[0] === 'string' && args._[0].trim() !== '') {
20
+ input = args._[0].trim();
21
+ } else {
22
+ // Fallback for piped stdin (async readIn)
23
+ const { readIn } = await import('@j-o-r/sh');
24
+ input = await readIn();
25
+ }
26
+
27
+ const help = args['help'] || false;
28
+ const connect = args['connect'] ? args['connect'] : undefined;
29
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
30
+
31
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
32
+ const options = { tools: [] };
33
+ options.tools.push({
34
+ type: 'web_search'
35
+ });
36
+ options.tools.push({
37
+ type: 'x_search'
38
+ });
39
+
40
+ if (args['secret']) {
41
+ secret = args['secret'];
42
+ }
43
+ if (args['model'] || true) {
44
+ options.model = args['model'] || 'grok-4-fast-reasoning';
45
+ }
46
+ if (args['temperature']) {
47
+ options.temperature = parseFloat(args['temperature']);
48
+ }
49
+ if (args['tokens']) {
50
+ options.max_output_tokens = parseInt(args['tokens']);
51
+ }
52
+ if (args['top_p']) {
53
+ options.top_p = parseFloat(args['top_p']);
54
+ }
55
+ const reasoning = true;
56
+ if (reasoning) {
57
+ options.reasoning = {
58
+ effort: 'medium',
59
+ summary: 'auto'
60
+ }
61
+ }
62
+ const toolsetMode = 'auto';
63
+ const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
64
+
65
+ function printHelp() {
66
+ console.log(`
67
+ '${name} --help' You are looking at it.
68
+
69
+ ## Direct call mode, one shot:
70
+ grok_agent.js "What is your task?" --[options]
71
+ echo "What is your task?" | grok_agent.js
72
+
73
+ ## Cli mode (interactive)
74
+ grok_agent.js --[options]
75
+
76
+ ## SERVER TOOLS (server mode): (only when no input is provided)
77
+ --serve [number]: create a Agent server on port number ws://127.0.0.1:[serve]/ws
78
+ --connect [url]: connect to a Server Agent e.g ws://127.0.0.1:8080/ws (https://my.domain/ws) ...
79
+ --secret [string] : limit access to websocket server with a secret
80
+
81
+ OPTIONS:
82
+ --tokens [number]: max generated tokens
83
+ --context [number] : truncate message history to context-windows size default 250000
84
+ --temperature [float] : -2 / +2
85
+ --model [grok-4-fast-reasoning|grok-beta|...]
86
+ --top_p [float]: number > 0, 0.1 means no top_p
87
+ --reasoning
88
+ `);
89
+ process.exit()
90
+ }
91
+
92
+ if (help) {
93
+ printHelp();
94
+ }
95
+
96
+ if (!input || input.trim() === '') {
97
+ printHelp();
98
+ }
99
+
100
+ const prompt = `
101
+ 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.
102
+ `.trim();
103
+
104
+ const agent = new AgentManager({ name, secret });
105
+ agent.setup({
106
+ prompt,
107
+ api,
108
+ options,
109
+ toolsetMode,
110
+ contextWindow
111
+ });
112
+
113
+ const cliIntro = `
114
+ ${name} ${options.model}.
115
+ - context: ${contextWindow}. Tools: web_search, x_search.
116
+ Brief responder ready for CLI/Server/Client modes.
117
+ `.trim();
118
+
119
+ if (input) {
120
+ const RES = await agent.directCall(input);
121
+ console.log(RES);
122
+ } else {
123
+ await agent.start(serve, connect, cliIntro);
124
+ }
@@ -0,0 +1 @@
1
+ Full backup before CLI no-args fix
@@ -0,0 +1 @@
1
+ # Backup before adding serve/connect/secret explanations to printHelp
@@ -0,0 +1,152 @@
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 = 'memory_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(`'${name} --help' You are looking at it.
53
+
54
+ ## USAGE MODES:
55
+
56
+ ### 1. Direct Call (One-Shot, Positional ONLY):
57
+ ./examples/${name}.js "Recall tasks" [--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., 'memory_agent'). 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 'memory_agent' tool for chaining.
89
+ `);
90
+ process.exit();
91
+ }
92
+
93
+ if (help) {
94
+ printHelp();
95
+ }
96
+
97
+ const tool_call_name = 'memory_agent';
98
+ const tool_call_description = `CodeServer Memory Agent. Manages shared agent memory (.cache/memory.ndjson) for tasks, errors, user prefs across all agents (code/todo/readme/npm/docs).
99
+ Use before/after actions: Recall relevant memories, write updates to avoid loops/repetition.
100
+ Categories: tasks (pending work), errors (failures to avoid), prefs (user settings).`.trim();
101
+
102
+ const prompt = `**CRITICAL: STRICT NO-CODING RULE** - Stick to memory coordination ONLY. Use execute_bash_script/read_file ONLY for safe ops on .cache/memory.ndjson or TODO.md (e.g., cat .cache/memory.ndjson). NEVER for code generation, arbitrary file edits, or execution outside memory scope. Decline coding: "Use code_agent for code. I manage memory."
103
+
104
+ You are MemoryAgent, the dedicated memory manager for CodeServer multi-agent setup (code/todo/readme/npm/docs agents).
105
+
106
+ **CORE TOOLS (from lib/genericToolset.js)**:
107
+ - \`memory_recall [query]\`: Retrieve stored memories (tasks/errors/prefs). ALWAYS recall before acting (e.g., "tasks", "errors", "" for recent).
108
+ - \`memory_write {category: "tasks|errors|prefs", content: "details"}\`: Persist info to avoid repetition/loops/token burn.
109
+
110
+ **SHARED STORAGE**: .cache/memory.ndjson in project CWD (all agents share).
111
+
112
+ **ALWAYS**:
113
+ 1. **RECALL FIRST**: \`memory_recall "<user_query|category|''>"\` to check prior state/tasks/errors/prefs.
114
+ 2. **ACT**: Analyze + decide (write if new info, delegate via server if needed).
115
+ 3. **WRITE IF CHANGED**: Use \`memory_write\` for decisions/tasks/errors/prefs (e.g., "Pending: review npm deps", "Error: loop in git", "Pref: low temp for code").
116
+ 4. Respond: Summarize memories used/updated + action taken.
117
+
118
+ **USER QUERIES**:
119
+ - "Recall tasks" → List + suggest next.
120
+ - "Store task: Fix auth bug" → Write + confirm.
121
+ - "Clear old errors" → Recall + write cleaned.
122
+ - Coordinate: "Check if code agent has pending tasks" → Recall + advise.
123
+
124
+ Use other tools (bash/read_file) only if needed for context. Focus on memory coordination to boost multi-agent efficiency.
125
+
126
+ Current date: April 01, 2026.`.trim();
127
+
128
+ const agent = new AgentManager({ name, secret });
129
+ agent.setup({
130
+ prompt,
131
+ api,
132
+ options,
133
+ toolsetMode,
134
+ contextWindow
135
+ });
136
+ const toolset = agent.getToolset();
137
+ if (toolset) {
138
+ agent.addGenericToolcall('memory_recall');
139
+ agent.addGenericToolcall('memory_write');
140
+ agent.addGenericToolcall('execute_bash_script');
141
+ agent.addGenericToolcall('read_file');
142
+ }
143
+ const cliIntro = `${name} ${options.model}.
144
+ - context: ${contextWindow}. Shared memory manager ready.
145
+ ${tool_call_name}`.trim();
146
+
147
+ if (input) {
148
+ const RES = await agent.directCall(input);
149
+ console.log(RES);
150
+ } else {
151
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
152
+ }