@j-o-r/hello-dave 0.0.4 → 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.
package/bin/dave.js CHANGED
@@ -26,6 +26,8 @@ FLAGS:
26
26
  echo "predict the weather" | bin/dave.js --connect 'ws://...' --secret '123' # user_request
27
27
  echo "user_info" | bin/dave.js --connect 'ws://...' --secret '123' # user_info
28
28
  echo "user_reset" | bin/dave.js --connect 'ws://...' --secret '123' # user_reset
29
+ --code [port] [secret] : Launch CodeServer PM2 cluster via examples/codeserver.sh
30
+ Usage: bin/dave.js --code 8080 --secret 123
29
31
  --ask : Launches a CLI and ask questions about whatever is on your mind
30
32
  XAIKEY required: export XAIKEY=xai-...
31
33
  `);
@@ -36,23 +38,25 @@ FLAGS:
36
38
  const keys = Object.keys(args);
37
39
  if (
38
40
  !(
39
- keys.indexOf('help') > 0 ||
40
- keys.indexOf('clear') > 0 ||
41
- keys.indexOf('search') > 0 ||
42
- keys.indexOf('list') > 0 ||
43
- keys.indexOf('inspect') > 0 ||
44
- keys.indexOf('connect') > 0 ||
45
- keys.indexOf('ask') > 0
41
+ keys.indexOf('--help') > -1 ||
42
+ keys.indexOf('--clear') > -1 ||
43
+ keys.indexOf('--search') > -1 ||
44
+ keys.indexOf('--list') > -1 ||
45
+ keys.indexOf('--inspect') > -1 ||
46
+ keys.indexOf('--connect') > -1 ||
47
+ keys.indexOf('--spawn') > -1 ||
48
+ keys.indexOf('--code') > -1 ||
49
+ keys.indexOf('--ask') > -1
46
50
  )
47
51
  ) {
48
52
  printHelp(1);
49
53
  }
50
54
 
51
- if (args.help) {
55
+ if (args['--help']) {
52
56
  printHelp();
53
57
  }
54
58
 
55
- if (args.clear) {
59
+ if (args['--clear']) {
56
60
  const clear_sessions = path.resolve(__dirname, '..', 'utils', 'clear_sessions.sh')
57
61
  const y = await cli.yesNo('Delete entire cache? (y/n) ');
58
62
  if (y) {
@@ -61,33 +65,33 @@ if (args.clear) {
61
65
  console.log(res);
62
66
  }
63
67
  process.exit();
64
- } else if (args.search) {
68
+ } else if (args['--search']) {
65
69
  const history_search = path.resolve(__dirname, '..', 'utils', 'search_sessions.sh')
66
- if (typeof args.search !== 'string') {
70
+ if (typeof args['--search'] !== 'string') {
67
71
  printHelp(1)
68
72
  }
69
- const res = await SH`${history_search} "${bashEscape(args.search)}"`.run();
73
+ const res = await SH`${history_search} "${bashEscape(args['--search'])}"`.run();
70
74
  console.log(res);
71
75
  process.exit();
72
- } else if (args.list) {
76
+ } else if (args['--list']) {
73
77
  const list = path.resolve(__dirname, '..', 'utils', 'list_sessions.sh');
74
78
  const res = await SH`${list}`.run();
75
79
  console.log(res);
76
80
  process.exit();
77
- } else if (args.inspect) {
81
+ } else if (args['--inspect']) {
78
82
  const format = path.resolve(__dirname, '..', 'utils', 'format_log.js')
79
- if (typeof args.inspect !== 'string') {
83
+ if (typeof args['--inspect'] !== 'string') {
80
84
  printHelp(1)
81
85
  }
82
86
  try {
83
- const res = await SH`${format} "${bashEscape(args.inspect)}"`.run();
87
+ const res = await SH`${format} "${bashEscape(args['--inspect'])}"`.run();
84
88
  console.log(res);
85
89
  } catch (e) {
86
90
  console.error(e);
87
91
  process.exit(1);
88
92
  }
89
- } else if (args.connect) {
90
- let secret = args.secret ? args.secret : '';
93
+ } else if (args['--connect']) {
94
+ let secret = args['--secret'] ? args['--secret'] : '';
91
95
 
92
96
  if (typeof pipedInput === 'string' && pipedInput.trim() !== '') {
93
97
  // Piped input mode: use wsIO for one-shot actions
@@ -102,7 +106,7 @@ if (args.clear) {
102
106
  }
103
107
 
104
108
  try {
105
- const response = await wsIO(args.connect, secret, action, input);
109
+ const response = await wsIO(args['--connect'], secret, action, input);
106
110
  console.log(response.content);
107
111
  } catch (e) {
108
112
  console.error(`Error: ${e.message}`);
@@ -110,9 +114,16 @@ if (args.clear) {
110
114
  }
111
115
  } else {
112
116
  // No piped input: interactive wsCli mode
113
- wsCli(args.connect, secret);
117
+ wsCli(args['--connect'], secret);
114
118
  }
115
- } else if (args.ask) {
119
+ } else if (args['--code']) {
120
+ const port = parseInt(args['--code'] || '8080');
121
+ const secret = args['--secret'] ? args['--secret'].trim() : '123';
122
+ const server = path.resolve(__dirname, '..', 'examples', 'codeserver.sh');
123
+ const RES = await SH`${server} ${port} ${bashEscape(secret)}`.run();
124
+ console.log(RES);
125
+ process.exit(0);
126
+ } else if (args['--ask']) {
116
127
  const name = 'ask_dave';
117
128
  const api = 'xai';
118
129
  let secret = '';
@@ -124,7 +135,7 @@ if (args.clear) {
124
135
  };
125
136
  options.tools.push({ type: 'web_search' });
126
137
  options.tools.push({ type: 'x_search' });
127
- options.model = args.model || args['model'] || 'grok-4-1-fast-reasoning';
138
+ options.model = args['--model'] || args.model || 'grok-4-1-fast-reasoning';
128
139
  options.temperature = 0.2;
129
140
  options.reasoning = { effort: 'medium', summary: 'auto' };
130
141
 
@@ -27,10 +27,7 @@ if (args['secret']) {
27
27
  secret = args['secret'];
28
28
  }
29
29
  if (args['model'] || true) {
30
- options.model = args['model'] || 'gpt-5.4';
31
- }
32
- if (args['temperature']) {
33
- options.temperature = parseFloat(args['temperature']);
30
+ options.model = args['model'] || 'gpt-5.4-mini';
34
31
  }
35
32
  if (args['tokens']) {
36
33
  options.max_output_tokens = parseInt(args['tokens']);
@@ -45,7 +42,7 @@ if (reasoning) {
45
42
  summary: 'auto'
46
43
  }
47
44
  }
48
- const contextWindow = args['context'] ? parseInt(args['context']) : 100000;
45
+ const contextWindow = args['context'] ? parseInt(args['context']) : 200000;
49
46
  const toolsetMode = 'auto';
50
47
 
51
48
  function printHelp() {
@@ -122,4 +119,4 @@ if (input) {
122
119
  console.log(RES);
123
120
  } else {
124
121
  await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
125
- }
122
+ }
package/lib/ToolSet.js CHANGED
@@ -71,8 +71,11 @@ class ToolSet {
71
71
  * @param {function(object): Promise<*>} method - Async function to call
72
72
  */
73
73
  add(name, description, parameters, method) {
74
+ if (typeof name !== 'string') {
75
+ throw new Error('Tool name must be a string');
76
+ }
74
77
  if (!isValidName(name)) {
75
- throw new Error('Invalid name /[a-z_0-9]{2,}/');
78
+ throw new Error(`Invalid tool name '${name}': must match /^[#!a-z_0-9]{2,}$/`);
76
79
  }
77
80
  if (this.has(name)) {
78
81
  // throw new Error('Function already defined');
package/lib/index.js CHANGED
@@ -11,6 +11,8 @@ import AgentClient from './AgentClient.js';
11
11
  import Session from './Session.js';
12
12
  import Prompt from './Prompt.js';
13
13
  import Cli from './Cli.js';
14
+ import wsCli from '../lib/wsCli.js';
15
+ import wsIO from '../lib/wsIO.js';
14
16
 
15
17
  const API = {
16
18
  text:{
@@ -32,5 +34,7 @@ export {
32
34
  API,
33
35
  Cli,
34
36
  env,
35
- GLOBAL
37
+ GLOBAL,
38
+ wsCli,
39
+ wsIO
36
40
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@j-o-r/hello-dave",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "description": "ESM toolkit for building AI agents with unified access to Grok (XAI), OpenAI, and Anthropic endpoints",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./types/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "bin": {
16
16
  "dave": "bin/dave.js",
17
- "createAgent": "examples/spawn_agent.js"
17
+ "createAgent": "bin/spawn_agent.js"
18
18
  },
19
19
  "scripts": {
20
20
  "release": "npm run types && npm pack --pack-destination=release",
@@ -39,7 +39,7 @@
39
39
  "types": "./types/index.d.ts",
40
40
  "default": "./lib/index.js"
41
41
  },
42
- "./*": "lib/*.js"
42
+ "./lib/*": "./lib/*"
43
43
  },
44
44
  "author": "Jorrit Duin <j-o-r@duin.work>",
45
45
  "bugs": {
package/types/index.d.ts CHANGED
@@ -17,8 +17,10 @@ export namespace API {
17
17
  import Cli from './Cli.js';
18
18
  import { env } from './fafs.js';
19
19
  import { GLOBAL } from './fafs.js';
20
+ import wsCli from '../lib/wsCli.js';
21
+ import wsIO from '../lib/wsIO.js';
20
22
  import { request as gpt } from './API/openai.com/reponses/text.js';
21
23
  import { request as xai } from './API/x.ai/responses.js';
22
24
  import { request as claude } from './API/anthropic.com/text.js';
23
25
  import { request as brave } from './API/brave.com/search.js';
24
- export { AgentManager, AgentServer, AgentClient, Prompt, ToolSet, Session, Cli, env, GLOBAL };
26
+ export { AgentManager, AgentServer, AgentClient, Prompt, ToolSet, Session, Cli, env, GLOBAL, wsCli, wsIO };
@@ -1,136 +0,0 @@
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 = 'coderev_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
- }
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']) : 500000;
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 "Paste git diff here" [--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., 'coderev_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: 500000)
87
-
88
- ## SERVER TOOLS (when no input):
89
- Exposes as 'coderev_agent' tool for chaining.
90
- `);
91
- process.exit();
92
- }
93
-
94
- if (help) {
95
- printHelp();
96
- }
97
-
98
- const tool_call_name = 'coderev_agent';
99
- const tool_call_description = `
100
- Git diff analyzer. Supports WS chaining.
101
- `.trim();
102
-
103
- const prompt = `
104
- You are coderev, a Git diff analyzer.
105
-
106
- Analyze git diffs provided in queries, review code changes for bugs, improvements, best practices, security issues, and provide actionable suggestions. Use read_file to access specific files, execute_bash_script for git commands or other shell tasks, and web_search for looking up coding standards or references if needed. Be thorough, constructive, and reference specific lines in diffs when possible.
107
-
108
- Respond in a structured format: Summary, Issues Found, Suggestions, Overall Rating (1-10).
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
- const toolset = agent.getToolset();
120
- if (toolset) {
121
- agent.addGenericToolcall('read_file');
122
- agent.addGenericToolcall('execute_bash_script');
123
- }
124
-
125
- const cliIntro = `
126
- ${name} ${options.model}.
127
- - context: ${contextWindow}
128
- ${tool_call_name}
129
- `.trim();
130
-
131
- if (input) {
132
- const RES = await agent.directCall(input);
133
- console.log(RES);
134
- } else {
135
- await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
136
- }
@@ -1,98 +0,0 @@
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);
@@ -1,99 +0,0 @@
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);
@@ -1 +0,0 @@
1
- # Full backup of grok_agent.js before printHelp clarity update
@@ -1,124 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- Full backup before CLI no-args fix
@@ -1 +0,0 @@
1
- # Backup before adding serve/connect/secret explanations to printHelp