@j-o-r/hello-dave 0.0.3 → 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.
- package/CHANGELOG.md +21 -0
- package/README.md +216 -56
- package/README.md.bak +481 -0
- package/README.md.bak.1774780058 +338 -0
- package/README.md.bak2 +455 -0
- package/docs.bak.1774780058/agent-manager.md +167 -0
- package/docs.bak.1774780058/agent-manager.md.bak +137 -0
- package/docs.bak.1774780058/agent-manager.md.bak2 +157 -0
- package/docs.bak.1774780058/codeserver-pattern.md +191 -0
- package/docs.bak.1774780058/path-resolution-best-practices.md +104 -0
- package/docs.bak.1774780058/project-overview.md +67 -0
- package/docs.bak.1774780058/project-overview.md.bak +67 -0
- package/docs.bak.1774780058/prompt-class.md +141 -0
- package/docs.bak.1774780058/prompt-class.md.bak +142 -0
- package/docs.bak.1774780058/tools-syntax-validation.md +121 -0
- package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +125 -0
- package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +125 -0
- package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +106 -0
- package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +106 -0
- package/docs.bak.1774780058/toolset.md +164 -0
- package/docs.bak.1774780058/toolset.md.bak +94 -0
- package/docs.bak.1774780058/toolset.md.bak3 +161 -0
- package/docs.bak.1774780058/toolset.md.bak4 +161 -0
- package/docs.bak.1774780058/toolset.md.bak5 +161 -0
- package/docs.bak.1774780058/toolset.md.bak6 +163 -0
- package/docs.bak.1774780058/toolset.md.bak_path +163 -0
- package/docs.bak.1774780058/toolset.md.bak_syntax +161 -0
- package/docs.bak.1774780058/xai-responses.md +111 -0
- package/docs.bak.1774780058/xai-responses.md.bak +107 -0
- package/docs.bak.1774780058/xai-responses.md.bak2 +107 -0
- package/docs.bak.1774780058/xai_collections.md +106 -0
- package/examples/ask_agent.js +137 -0
- package/examples/code_agent.js +149 -0
- package/examples/coderev_agent.js +136 -0
- package/examples/codeserver.sh +47 -0
- package/examples/daisy_agent.js +170 -0
- package/examples/docs_agent.js +148 -0
- package/examples/gpt_agent.js +125 -0
- package/examples/grok_agent.js +132 -0
- package/examples/grok_agent.js.bak +98 -0
- package/examples/grok_agent.js.bak.2 +99 -0
- package/examples/grok_agent.js.bak.3 +1 -0
- package/examples/grok_agent.js.bak.4 +124 -0
- package/examples/grok_agent.js.bak.5 +1 -0
- package/examples/grok_agent.js.bak.6 +1 -0
- package/examples/memory_agent.js +152 -0
- package/examples/npm_agent.js +202 -0
- package/examples/npm_agent.js.bak.3 +2 -0
- package/examples/npm_agent.js.bak.4 +205 -0
- package/examples/npm_agent.js.bak.5 +1 -0
- package/examples/npm_agent.js.bak.6 +1 -0
- package/examples/prompt_agent.js +133 -0
- package/examples/readme_agent.js +148 -0
- package/examples/spawn_agent.js +293 -0
- package/examples/test_agent.js +187 -0
- package/examples/todo_agent.js +175 -0
- package/{examples/codeDave.js → examples.bak.1774780058/code_agent.js} +40 -6
- package/{examples/CodeServer → examples.bak.1774780058/codeserver.sh} +9 -5
- package/examples.bak.1774780058/memory_agent.js +112 -0
- package/{examples/spawndave.js → examples.bak.1774780058/spawn_agent.js} +29 -6
- package/examples.bak.1774780058/test_agent.js +162 -0
- package/{examples/todoDave.js → examples.bak.1774780058/todo_agent.js} +8 -2
- package/lib/API/x.ai/responses.js +7 -9
- package/lib/AgentManager.js +3 -2
- package/lib/AgentServer.js +23 -19
- package/lib/genericToolset.js +159 -26
- package/lib/genericToolset.js.bak_syntax +402 -0
- package/lib/wsCli.js +0 -1
- package/package.json +4 -5
- package/scenarios.bak.1774780058/data/eval_node_message.json +9 -0
- package/scenarios.bak.1774780058/data/hist_oa.json +66 -0
- package/scenarios.bak.1774780058/data/o3_response1.json +96 -0
- package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +112 -0
- package/scenarios.bak.1774780058/data/tool_oa.json +96 -0
- package/scenarios.bak.1774780058/data/tool_xai.json +59 -0
- package/scenarios.bak.1774780058/data/tool_xai2.json +40 -0
- package/scenarios.bak.1774780058/data/xai-response-1.json +59 -0
- package/scenarios.bak.1774780058/data/xai-response-2.json +10 -0
- package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +59 -0
- package/scenarios.bak.1774780058/data/xai_search_response.json +58 -0
- package/scenarios.bak.1774780058/environment.js +10 -0
- package/scenarios.bak.1774780058/example.js +17 -0
- package/scenarios.bak.1774780058/genericToolset.test.js +182 -0
- package/scenarios.bak.1774780058/grok.js +113 -0
- package/scenarios.bak.1774780058/memory-tools.js +51 -0
- package/scenarios.bak.1774780058/openai-o3.js +137 -0
- package/scenarios.bak.1774780058/openai-prompt.js +155 -0
- package/scenarios.bak.1774780058/openai-session.js +148 -0
- package/scenarios.bak.1774780058/openai.js +102 -0
- package/scenarios.bak.1774780058/prompt.js +118 -0
- package/scenarios.bak.1774780058/promptFishbowl.js +76 -0
- package/scenarios.bak.1774780058/search.brave.com.js +25 -0
- package/scenarios.bak.1774780058/sh.js +15 -0
- package/scenarios.bak.1774780058/test-wsio.js +26 -0
- package/scenarios.bak.1774780058/testToolset.js +42 -0
- package/scenarios.bak.1774780058/toolset.js +16 -0
- package/scenarios.bak.1774780058/toolset.test.js +141 -0
- package/scenarios.bak.1774780058/write_file_syntax.test.js +145 -0
- package/scenarios.bak.1774780058/write_file_validation/README.md +30 -0
- package/scenarios.bak.1774780058/write_file_validation/bad.js +3 -0
- package/scenarios.bak.1774780058/write_file_validation/good.js +4 -0
- package/scenarios.bak.1774780058/write_file_validation/test.sh +43 -0
- package/scenarios.bak.1774780058/wsClient.js +69 -0
- package/scenarios.bak.1774780058/xai_responses.integration.test.js +57 -0
- package/scenarios.bak.1774780058/xai_responses.test.js +154 -0
- package/scenarios.bak.1774780058/xaicoll.js +50 -0
- package/scenarios.bak.1774780058/xaifiles.js +48 -0
- package/types/AgentManager.d.ts +4 -3
- package/utils/syntax_check.sh +61 -0
- package/utils/test.sh +46 -0
- /package/{examples/askDave.js → examples.bak.1774780058/ask_agent.js} +0 -0
- /package/{examples/coderev.js → examples.bak.1774780058/coderev_agent.js} +0 -0
- /package/{examples/daisy.js → examples.bak.1774780058/daisy_agent.js} +0 -0
- /package/{examples/docsDave.js → examples.bak.1774780058/docs_agent.js} +0 -0
- /package/{examples/gpt.js → examples.bak.1774780058/gpt_agent.js} +0 -0
- /package/{examples/grok.js → examples.bak.1774780058/grok_agent.js} +0 -0
- /package/{examples/npmDave.js → examples.bak.1774780058/npm_agent.js} +0 -0
- /package/{examples/promptDave.js → examples.bak.1774780058/prompt_agent.js} +0 -0
- /package/{examples/readmeDave.js → examples.bak.1774780058/readme_agent.js} +0 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
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_agent';
|
|
6
|
+
const api = 'xai';
|
|
7
|
+
let secret = '';
|
|
8
|
+
|
|
9
|
+
const args = parseArgs();
|
|
10
|
+
|
|
11
|
+
let input; // Directcall input (positional ONLY - NO pipe)
|
|
12
|
+
if (args._.length === 1 && typeof args._[0] === 'string' && args._[0].trim() !== '') {
|
|
13
|
+
input = args._[0].trim();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const help = args['help'] || false;
|
|
17
|
+
const connect = args['connect'] ? args['connect'] : undefined;
|
|
18
|
+
const serve = args['serve'] ? parseInt(args['serve']) : undefined;
|
|
19
|
+
|
|
20
|
+
/** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
|
|
21
|
+
const options = { tools: [] };
|
|
22
|
+
options.tools.push({
|
|
23
|
+
type: 'web_search'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (args['secret']) {
|
|
27
|
+
secret = args['secret'];
|
|
28
|
+
}
|
|
29
|
+
if (args['model'] || true) {
|
|
30
|
+
options.model = args['model'] || 'grok-4-fast-reasoning';
|
|
31
|
+
}
|
|
32
|
+
if (args['temperature']) {
|
|
33
|
+
options.temperature = parseFloat(args['temperature']);
|
|
34
|
+
}
|
|
35
|
+
if (args['tokens']) {
|
|
36
|
+
options.max_output_tokens = parseInt(args['tokens']);
|
|
37
|
+
}
|
|
38
|
+
if (args['top_p']) {
|
|
39
|
+
options.top_p = parseFloat(args['top_p']);
|
|
40
|
+
}
|
|
41
|
+
const reasoning = true;
|
|
42
|
+
if (reasoning) {
|
|
43
|
+
options.reasoning = {
|
|
44
|
+
effort: 'medium',
|
|
45
|
+
summary: 'auto'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const toolsetMode = 'auto';
|
|
49
|
+
const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
|
|
50
|
+
|
|
51
|
+
function printHelp() {
|
|
52
|
+
console.log(`
|
|
53
|
+
'${name} --help' You are looking at it.
|
|
54
|
+
|
|
55
|
+
## USAGE MODES:
|
|
56
|
+
|
|
57
|
+
### 1. Direct Call (One-Shot, Positional ONLY):
|
|
58
|
+
./examples/${name}.js "What modules are installed?" [--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., 'npm_module_inspector'). Runs indefinitely until Ctrl+C.
|
|
74
|
+
|
|
75
|
+
--connect [ws_url]: Connects as CLIENT to remote WS server at [ws_url] (e.g., ws://127.0.0.1:8080/ws). Gains access to remote agent's tools. Interactive CLI available.
|
|
76
|
+
|
|
77
|
+
--secret [string]: SHARED AUTH TOKEN (min 3 chars). SERVER rejects clients without matching --secret. CLIENTS must provide server's secret to connect. Use same secret for chains.
|
|
78
|
+
|
|
79
|
+
Note: Server/Client/Hybrid IGNORES positional input arg (use CLI modes instead). Hybrid: This agent serves AND uses remote tools.
|
|
80
|
+
|
|
81
|
+
## OPTIONS:
|
|
82
|
+
--model [grok-4-fast-reasoning|...] (default: grok-4-fast-reasoning)
|
|
83
|
+
--temperature [float] (-2 to +2)
|
|
84
|
+
--tokens [number] (max output tokens)
|
|
85
|
+
--top_p [float]
|
|
86
|
+
--context [number] (default: 250000)
|
|
87
|
+
|
|
88
|
+
## SERVER TOOLS (when no input):
|
|
89
|
+
Exposes as 'npm_module_inspector' tool for chaining.
|
|
90
|
+
`);
|
|
91
|
+
process.exit()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (help) {
|
|
95
|
+
printHelp();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const tool_call_name = 'npm_module_inspector';
|
|
99
|
+
const tool_call_description = `
|
|
100
|
+
NPM modules expert (scoped & unscoped). Uses \`npm ls -a\` + bash **exclusively inside ./node_modules/**.
|
|
101
|
+
**Smart Cache**: .cache/npm-agent-storage.md (auto-read/update, token-efficient, auto-refreshes on changes). Agent-owned.
|
|
102
|
+
`.trim();
|
|
103
|
+
|
|
104
|
+
const CACHE_FILE = '.cache/npm-agent-storage.md';
|
|
105
|
+
|
|
106
|
+
const prompt = `
|
|
107
|
+
You are a coding assistant specializing in Bash and JavaScript (ESM/ESNext), with support for other languages.
|
|
108
|
+
Your role: Help users code with external NPM modules installed in the project's ./node_modules/ (dynamic CWD).
|
|
109
|
+
Scoped (@j-o-r/cli) == unscoped (gpt-3-encoder) priority.
|
|
110
|
+
|
|
111
|
+
CWD dynamic (pwd; project root w/ package.json/node_modules).
|
|
112
|
+
|
|
113
|
+
CRITICAL: **NEVER** inspect/read **OUTSIDE** ./node_modules/. NO project files. **ONLY** \`npm ls -a\` (local) + node_modules/ paths. **NEVER** run \`npm install\` or suggest installs unless NO existing/native alternative (justify HEAVILY, prefer polyfills).
|
|
114
|
+
|
|
115
|
+
**Dependency Strategy**: For all coding requests, follow this order to keep dependencies minimal (prevent bloat):
|
|
116
|
+
1. **Always try existing installed modules first**: Scan \`npm ls -a\` FULL TREE (all subdeps). Prioritize functions from ANY module.
|
|
117
|
+
2. **Native code**: Node.js/Bash builtins ONLY if no module match.
|
|
118
|
+
3. **Suggest new dep LAST/RARE**: ABSOLUTELY NO unless gap proven (no existing/native). Heavy justification + \`npm i --save-dev PKG\` (dev pref). Goal: ZERO new installs.
|
|
119
|
+
|
|
120
|
+
**Auto-Cache Init (MANDATORY FIRST on EVERY query - FULL SCAN)**:
|
|
121
|
+
touch ${CACHE_FILE}
|
|
122
|
+
echo "## Full Tree (npm ls -a unique modules)" >> ${CACHE_FILE}
|
|
123
|
+
npm ls -a --parseable 2>/dev/null | sed 's|.*/||' | sort -u | head -50 >> ${CACHE_FILE} # All unique PKGs (top + sub)
|
|
124
|
+
echo "## Top-Level (--depth=0)" >> ${CACHE_FILE}
|
|
125
|
+
npm ls --depth=0 | grep -E '^[├└]──' | sed 's/^[├└ ]*── //' | sed 's/ .*//' >> ${CACHE_FILE}
|
|
126
|
+
**Condensed Scan**: find node_modules/ -name package.json | sed 's|.*/||;s|/package.json||' | sort -u > ${CACHE_FILE}.allmods
|
|
127
|
+
|
|
128
|
+
**Vague Query Mode** (e.g., "tests"):
|
|
129
|
+
- Full scan: \`npm ls -a | grep -i "\$QUERY" || find node_modules/ -name "*.d.ts" -o -name "*.js" | head -50 | xargs grep -lE "\$QUERY|test|assert" | sed 's|.*/||;s|\..*||' | sort -u\`
|
|
130
|
+
- Output table: Module | Exports | For | Usage (from all tree).
|
|
131
|
+
- Append "## QUERY: \$QUERY\nHits: list" >> ${CACHE_FILE}
|
|
132
|
+
|
|
133
|
+
**Smart Cache (.cache/npm-agent-storage.md)**: Agent-owned, **auto-managed FULL TREE** (read-first, update-on-change).
|
|
134
|
+
- Token Saver: Grep FIRST across all sections.
|
|
135
|
+
- Init: touch .cache/npm-agent-storage.md
|
|
136
|
+
|
|
137
|
+
PRIORITIZE \`npm ls -a\` (full tree) + bash inside ALL MODULE_DIRs.
|
|
138
|
+
|
|
139
|
+
Tools:
|
|
140
|
+
- execute_bash_script: \`npm ls -a ...\` + \`cat node_modules/\$PKG_NAME/package.json\`. Prefix ALWAYS.
|
|
141
|
+
- web_search: Docs ONLY.
|
|
142
|
+
- history_search: Chats.
|
|
143
|
+
|
|
144
|
+
**Smart Workflow** (per query; full tree always):
|
|
145
|
+
1. **Full Tree Installed/Version**:
|
|
146
|
+
PKGS=\$(npm ls -a --parseable 2>/dev/null | sed 's|.*/||' | sort -u | head -50)
|
|
147
|
+
for PKG in \$PKGS; do npm ls "\$PKG" 2>/dev/null | tail -1 | grep -o 'v[0-9].*' || echo "\$PKG ??"; done
|
|
148
|
+
|
|
149
|
+
2. **Smart Cache Check**:
|
|
150
|
+
grep -A 30 "^## Full Tree" .cache/npm-agent-storage.md || echo "Cache miss"
|
|
151
|
+
|
|
152
|
+
3. **Inspect if Miss** (loop top 10 hits):
|
|
153
|
+
- For each MODULE_DIR=node_modules/\$PKG: [existing inspect + enhanced types/docs grep]
|
|
154
|
+
- Vague: grep -riE "\$QUERY" node_modules/\$PKG/*.{json,md,d.ts,js} | head -20
|
|
155
|
+
|
|
156
|
+
4. **Auto-Update Cache** (CONDENSED, FULL):
|
|
157
|
+
sed -i.bak "/^## Full Tree/,/^## QUERY/d" ${CACHE_FILE} && rm ${CACHE_FILE}.bak
|
|
158
|
+
cat >> ${CACHE_FILE} << EOC
|
|
159
|
+
## Full Tree (npm ls -a)
|
|
160
|
+
\$ALL_PKGS (50 unique)
|
|
161
|
+
|
|
162
|
+
## \$PKG v\$VER
|
|
163
|
+
Exports: \$EXPORTS
|
|
164
|
+
For: \$KEYWORDS (test/query hits)
|
|
165
|
+
Usage: import {fn} from '\$PKG';
|
|
166
|
+
EOC
|
|
167
|
+
|
|
168
|
+
5. **List All**: \`npm ls -a | head -50 | grep -E '^[├└]' | sed 's/^[├└ ]*── //' | cut -d@ -f1 | sort -u\`
|
|
169
|
+
|
|
170
|
+
6. **Coding Help**: ESM/Bash snippets from FULL TREE. **MANDATORY**: Strategy + table + "NO new deps - use existing \$PKG".
|
|
171
|
+
|
|
172
|
+
**MANDATORY**: FULL \`npm ls -a\` every time. Vague scans ALL modules. **STRICT NO INSTALLS** unless proven gap. Condensed output. Portable.
|
|
173
|
+
`.trim();
|
|
174
|
+
|
|
175
|
+
const agent = new AgentManager({ name, secret });
|
|
176
|
+
agent.setup({
|
|
177
|
+
prompt,
|
|
178
|
+
api,
|
|
179
|
+
options,
|
|
180
|
+
toolsetMode,
|
|
181
|
+
contextWindow
|
|
182
|
+
});
|
|
183
|
+
const toolset = agent.getToolset();
|
|
184
|
+
if (toolset) {
|
|
185
|
+
agent.addGenericToolcall('history_search');
|
|
186
|
+
agent.addGenericToolcall('javascript_interpreter');
|
|
187
|
+
agent.addGenericToolcall('execute_bash_script');
|
|
188
|
+
agent.addGenericToolcall('read_file');
|
|
189
|
+
agent.addGenericToolcall('write_file');
|
|
190
|
+
}
|
|
191
|
+
const cliIntro = `
|
|
192
|
+
${name} ${options.model}.
|
|
193
|
+
- context: ${contextWindow}. Smart cache: ${CACHE_FILE} (FULL npm ls -a auto).
|
|
194
|
+
${tool_call_name}
|
|
195
|
+
`.trim();
|
|
196
|
+
|
|
197
|
+
if (input) {
|
|
198
|
+
const RES = await agent.directCall(input);
|
|
199
|
+
console.log(RES);
|
|
200
|
+
} else {
|
|
201
|
+
await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
|
|
202
|
+
}
|