@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,175 @@
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 = 'npm_dave';
6
+ const api = 'xai';
7
+ let secret = '';
8
+
9
+ const input = ''; //await readIn();
10
+ const args = parseArgs();
11
+ const help = args['help'] || false;
12
+ const connect = args['connect'] ? args['connect'] : undefined;
13
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
14
+
15
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
16
+ const options = { tools : []};
17
+ options.tools.push({
18
+ type: 'web_search'
19
+ });
20
+
21
+ if (args['secret']) { // model gets default value
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-fast-reasoning';
28
+ }
29
+ if (args['temperature']) {
30
+ options.temperature = parseFloat(args['temperature']);
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 = true; // args['reasoning'] ? args['reasoning'] : null;
39
+ if (reasoning) {
40
+ options.reasoning = {
41
+ effort: 'medium',
42
+ summary: 'auto'
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
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
+ `);
68
+ process.exit()
69
+ }
70
+
71
+ if (help) {
72
+ printHelp();
73
+ }
74
+ const tool_call_name = 'npm_module_inspector';
75
+ const tool_call_description = `
76
+ NPM modules expert (scoped & unscoped). Uses \`npm ls\` + bash **exclusively inside ./node_modules/**.
77
+ **Smart Cache**: .cache/npm-agent-storage.md (auto-read/update, token-efficient, auto-refreshes on changes). Agent-owned.
78
+ `.trim();
79
+
80
+ const CACHE_FILE='.cache/npm-agent-storage.md';
81
+
82
+ const prompt = `
83
+ You are a coding assistant specializing in Bash and JavaScript (ESM/ESNext), with support for other languages.
84
+ Your role: Help users code with external NPM modules installed in the project's ./node_modules/ (dynamic CWD).
85
+ Scoped (@j-o-r/cli) == unscoped (gpt-3-encoder) priority.
86
+
87
+ CWD dynamic (pwd; project root w/ package.json/node_modules).
88
+
89
+ CRITICAL: **NEVER** inspect/read **OUTSIDE** ./node_modules/. NO project files. **ONLY** \`npm ls\` (local) + node_modules/ paths.
90
+
91
+ **Smart Cache (${CACHE_FILE})**: Agent-owned, hidden, **auto-managed** (read-first, update-on-change, NO user confirm).
92
+ - **Token Saver**: Grep cache **FIRST** (if match version → use, skip inspect).
93
+ - **Auto-Update**: ALWAYS check \`npm ls \$PKG_NAME\`; if version changed/missing → inspect + **silently rewrite** section.
94
+ - Init: \`touch ${CACHE_FILE}\`
95
+
96
+ PRIORITIZE \`npm ls --depth=1\` (versions/tree) + bash **inside** MODULE_DIR.
97
+
98
+ Tools:
99
+ - execute_bash_script: \`npm ls ...\` + \`cat node_modules/\$PKG_NAME/package.json\`. **node_modules/ prefix ALWAYS**.
100
+ - web_search: Docs supplement.
101
+ - history_search: Chats.
102
+
103
+ **Smart Workflow** (per query; e.g., "@j-o-r/cli"):
104
+ 1. **Confirm Installed/Version**:
105
+ \`CURRENT_VERSION=\$(npm ls "\$PKG_NAME" --depth=0 2>/dev/null | grep -o ' @[0-9].*' | sed 's/ @//') || echo "Not installed"\`
106
+
107
+ 2. **Smart Cache Check** (token-efficient):
108
+ - Init: \`touch ${CACHE_FILE}\`
109
+ - Exact match? \`grep -A 30 "^## \$PKG_NAME v\$CURRENT_VERSION " ${CACHE_FILE} || echo "Cache miss/outdated"\`
110
+ - If hit: Use cache summary (paste relevant sections). **Skip** full inspect.
111
+ - List all: \`grep "^## " ${CACHE_FILE} | sed 's/^## //' || echo "Empty cache"\`
112
+
113
+ 3. **Inspect if Cache Miss/Outdated** (set MODULE_DIR=node_modules/\$PKG_NAME):
114
+ - Path: \`[ -d "node_modules/\$PKG_NAME" ] && echo "OK" || echo "Dir missing"\`
115
+ - Desc: \`grep '"description"' "node_modules/\$PKG_NAME/package.json" | sed 's/.*"description": "\\([^"]*\\)".*/\\1/' || echo "No desc"\`
116
+ - Entrypoints: \`grep -E '"(main|module|types|exports)"' "node_modules/\$PKG_NAME/package.json" || echo "None"\`
117
+ - README: \`head -50 "node_modules/\$PKG_NAME/README.md" 2>/dev/null || echo "No README"\`
118
+ - Types/Exports: \`find "node_modules/\$PKG_NAME" -name "*.d.ts" 2>/dev/null | head -8 | xargs grep -hE "export (interface|type|function|class|const)" | head -25 || find "node_modules/\$PKG_NAME" -name "*.{ts,js,mjs,cjs}" 2>/dev/null | head -8 | xargs grep -hE "export " | head -25 || echo "No exports"\`
119
+ - Examples: \`grep -rniE "example|usage|demo" "node_modules/\$PKG_NAME/" 2>/dev/null | head -15 || echo "No examples"\`
120
+ - Subdeps: \`npm ls "\$PKG_NAME" --depth=1\`
121
+
122
+ 4. **Auto-Update Cache** (**ALWAYS after inspect**, silent, replace section):
123
+ \`sed -i.bak "/^## \$PKG_NAME /,/^## \\|^$/d" ${CACHE_FILE} && rm ${CACHE_FILE}.bak 2>/dev/null; cat >> ${CACHE_FILE} << 'EOC'
124
+ ## \$PKG_NAME v\$CURRENT_VERSION
125
+
126
+ ### Overview
127
+ \$DESC
128
+
129
+ ### Installation
130
+ Installed (\$CURRENT_VERSION). import {example} from '\$PKG_NAME'; // ESM
131
+
132
+ ### Usage Examples
133
+ \$EXAMPLES
134
+
135
+ ### API Reference
136
+ \$EXPORTS
137
+
138
+ ### Dependencies
139
+ \$SUBDEPS
140
+
141
+ ### Notes
142
+ Best practices/gotchas from README/types.
143
+ EOC\`
144
+
145
+ 5. **List All Modules** (top-level, cached/versions):
146
+ \`npm ls --depth=0 | grep -E '^[├└]──' | sed 's/^[├└ ]*── //' | sed 's/ .*//' || echo "npm ls --depth=0"\`
147
+
148
+ 6. **Coding Help**: ESM snippets, errors (\`npm ls --why=\$PKG_NAME\`), best practices (cache + local + web).
149
+
150
+ **MANDATORY**: Cache-first. Auto-update **every time** version changes/miss. **No asks**. Scoped=unscoped. Portable.
151
+ `.trim();
152
+
153
+ const agent = new AgentManager({ name, secret });
154
+ agent.setup({
155
+ prompt,
156
+ api,
157
+ options,
158
+ toolsetMode,
159
+ contextWindow
160
+ });
161
+ const toolset = agent.getToolset();
162
+ if (toolset) {
163
+ agent.addGenericToolcall('history_search');
164
+ agent.addGenericToolcall('javascript_interpreter');
165
+ agent.addGenericToolcall('execute_bash_script');
166
+ agent.addGenericToolcall('read_file');
167
+ agent.addGenericToolcall('write_file');
168
+ }
169
+ const cliIntro = `
170
+ ${name} ${options.model}.
171
+ - context: ${contextWindow}. Smart cache: ${CACHE_FILE} (auto).
172
+ ${tool_call_name}
173
+ `.trim();
174
+
175
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
@@ -0,0 +1,112 @@
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 = 'prompt_dave';
6
+ const api = 'xai';
7
+ let secret = '';
8
+
9
+ const input = ''; // await readIn();
10
+ const args = parseArgs();
11
+ const help = args['help'] || false;
12
+ const connect = args['connect'] ? args['connect'] : undefined;
13
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
14
+
15
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
16
+ const options = {
17
+ tools: []
18
+ }
19
+ options.tools.push({
20
+ type: 'web_search'
21
+ });
22
+
23
+ if (args['secret']) { // model gets default value
24
+ secret = args['secret'];
25
+ }
26
+ // Set properties only if provided via command line (except model which has default)
27
+ if (args['model'] || true) { // model gets default value
28
+ // @ts-ignore || grok-4-1-fast-non-reasoning
29
+ options.model = args['model'] || 'grok-4-1-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 // args['reasoning'] ? args['reasoning'] : null;
41
+ if (reasoning) {
42
+ // options.reasoning_effort = reasoning
43
+ options.reasoning = {
44
+ effort: 'medium',
45
+ summary: 'auto'
46
+ }
47
+ }
48
+ // Large context on grok-4-fast
49
+ const contextWindow = args['context'] ? parseInt(args['context']) : 1900000;
50
+ const toolsetMode = 'auto';
51
+
52
+ function printHelp() {
53
+ console.log(`
54
+ '${name} --help' You are looking at it.
55
+ '
56
+ OPTIONS:
57
+ --tokens [number]: max generated tokens
58
+ --context [number] : truncate message history to context-windows size default 130000
59
+ --temperature [float] : -2 / +2
60
+ --model [grok-4|grok-3|grok-3-mini|grok-3-mini-fast|grok-code-fast-1]
61
+ --top_p [float]: number > 0, 0.1 means no top_p
62
+ --reasoning [low|high]
63
+ --tools [javascript,bash] comma seperated list
64
+
65
+ SERVER TOOLS:
66
+ --serve [number]: create a Agent server on port number ws://127.0.0.1:[serve]/ws
67
+ --connect [url]: connect to a Server Agent e.g ws://127.0.0.1:8080/ws (https://my.domain/ws) ...
68
+ --secret [string] : limit access to websocket server with a secret
69
+
70
+
71
+ `);
72
+ process.exit()
73
+ }
74
+ if (help) {
75
+ printHelp();
76
+ }
77
+
78
+ const prompt = `
79
+ You are a prompt optimizer. Check for: 1) Clarity and specificity. 2) Brevity, non-ambiguity, ethics. 3) Token efficiency. If good, say "Approved." If not, rewrite concisely or ask 1-2 questions. Output: - Summary. - Rewritten prompt (if needed). - Questions (if unclear). Be efficient.
80
+ `.trim();
81
+
82
+ const agent = new AgentManager({ name, secret });
83
+ agent.setup({
84
+ prompt,
85
+ api,
86
+ options,
87
+ toolsetMode,
88
+ contextWindow
89
+ });
90
+ agent.addGenericToolcall('open_link');
91
+ agent.addGenericToolcall('send_email');
92
+ agent.addGenericToolcall('history_search');
93
+
94
+ const addTools = (args['tools']) ? args['tools'].split(',') : ['bash'];
95
+ if (addTools.includes('javascript')) {
96
+ agent.addGenericToolcall('javascript_interpreter');
97
+ }
98
+ if (addTools.includes('bash')) {
99
+ agent.addGenericToolcall('execute_bash_script');
100
+ }
101
+ if (addTools.includes('ssh')) {
102
+ agent.addGenericToolcall('execute_remote_script');
103
+ }
104
+ const cliIntro = `
105
+ ${name} ${options.model}.
106
+ - context: ${contextWindow}
107
+ `.trim();
108
+
109
+ const description = `
110
+ Given a specific prompt, inspect and adjust it for better readability and clarity.
111
+ `.trim();
112
+ await agent.start(serve, connect, cliIntro, "prompt_engineer_agent", description);
@@ -0,0 +1,144 @@
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_dave';
6
+ const api = 'xai';
7
+ let secret = '';
8
+
9
+ const args = parseArgs();
10
+ const help = args['help'] || false;
11
+ const connect = args['connect'] ? args['connect'] : undefined;
12
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
13
+
14
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
15
+ const options = { tools : []};
16
+ 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
+ if (reasoning) {
39
+ options.reasoning = {
40
+ // @ts-ignore
41
+ effort: reasoning,
42
+ summary: 'auto'
43
+ }
44
+ }
45
+ }
46
+
47
+ const toolsetMode = 'auto';
48
+ const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
49
+
50
+ // Copy from the generic toolset
51
+ function printHelp() {
52
+ console.log(`
53
+ '${name} --help' You are looking at it.
54
+
55
+ OPTIONS:
56
+ --tokens [number]: max generated tokens
57
+ --context [number] : truncate message history to context-windows size default 130000
58
+ --temperature [float] : -2 / +2
59
+ --model [grok-4|grok-3|grok-3-mini|grok-3-mini-fast|grok-code-fast-1]
60
+ --top_p [float]: number > 0, 0.1 means no top_p
61
+ --reasoning [low|high]
62
+ --tools [javascript,bash] comma seperated list
63
+
64
+ SERVER TOOLS:
65
+ --serve [number]: create a Agent server on port number ws://127.0.0.1:[serve]/ws
66
+ --connect [url]: connect to a Server Agent e.g ws://127.0.0.1:8080/ws (https://my.domain/ws) ...
67
+ --secret [string] : limit access to websocket server with a secret
68
+ `);
69
+ process.exit()
70
+ }
71
+
72
+ if (help) {
73
+ printHelp();
74
+ }
75
+
76
+ const tool_call_description = `
77
+ Project README manager. Maintains README.md with comprehensive project documentation.
78
+ Inspects current README.md, updates sections (installation, usage, etc.), generates content based on project files and user input.
79
+ Suggests improvements, adds badges, TOC, etc.
80
+ `.trim();
81
+ const tool_call_name = 'readme_agent';
82
+ const prompt = `
83
+ You are an expert README.md manager for this project. README.md should follow best practices with sections like:
84
+
85
+ # Project Title
86
+ ![Badges]
87
+
88
+ ## Table of Contents
89
+
90
+ ## Description
91
+ ## Features
92
+ ## Installation
93
+ ## Usage
94
+ ## Examples
95
+ ## Development
96
+ ## Contributing
97
+ ## License
98
+
99
+ ALWAYS:
100
+
101
+ 1. Inspect the current README.md if it exists (\`cat README.md\` or similar).
102
+
103
+ 2. Inspect key project files: \`cat package.json\`, \`ls -la\`, \`ls bin/\`, \`ls lib/\`, \`git status\`, etc.
104
+
105
+ 3. Understand the user input:
106
+ - "add installation instructions"
107
+ - "generate usage examples"
108
+ - "add table of contents"
109
+ - "update description to: ..."
110
+ - "suggest improvements"
111
+ - "include npm badges"
112
+ - "make it more professional"
113
+
114
+ 4. Update README.md with changes. Ensure excellent Markdown formatting, accuracy based on project.
115
+
116
+ 5. Write the FULL updated content to ./README.md.
117
+
118
+ 6. In your response, summarize:
119
+ - Changes made
120
+ - Preview of key sections (e.g., first 20 lines)
121
+ - Any suggestions for further enhancements
122
+
123
+ 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.
124
+
125
+ Use tools to read files, list directories, etc., as needed.
126
+ `.trim();
127
+ const agent = new AgentManager({ name, secret });
128
+ agent.setup({
129
+ prompt,
130
+ api,
131
+ options,
132
+ toolsetMode,
133
+ contextWindow
134
+ });
135
+ const toolset = agent.getToolset();
136
+ if (toolset) {
137
+ agent.addGenericToolcall('execute_bash_script');
138
+ }
139
+ const cliIntro = `
140
+ ${name} ${options.model}.
141
+ - context: ${contextWindow}
142
+ `.trim();
143
+
144
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);