@j-o-r/hello-dave 0.0.2 → 0.0.3
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/README.md +288 -163
- package/README.md.backup +269 -0
- package/bin/dave.js +165 -0
- package/examples/CodeServer +43 -0
- package/{bin/hdAsk.js → examples/askDave.js} +50 -39
- package/{bin/hdCode.js → examples/codeDave.js} +47 -47
- package/examples/coderev.js +72 -0
- package/examples/daisy.js +177 -0
- package/examples/docsDave.js +119 -0
- package/examples/gpt.js +54 -72
- package/examples/grok.js +47 -68
- package/examples/npmDave.js +175 -0
- package/examples/promptDave.js +112 -0
- package/examples/readmeDave.js +144 -0
- package/examples/spawndave.js +240 -0
- package/examples/todoDave.js +132 -0
- package/lib/API/openai.com/reponses/text.js +12 -18
- package/lib/API/x.ai/collections.js +354 -0
- package/lib/API/x.ai/files.js +218 -0
- package/lib/API/x.ai/responses.js +494 -0
- package/lib/API/x.ai/text.js +1 -1
- package/lib/AgentClient.js +13 -6
- package/lib/AgentManager.js +79 -10
- package/lib/AgentServer.js +45 -21
- package/lib/Cli.js +7 -1
- package/lib/Prompt.js +4 -2
- package/lib/ToolSet.js +2 -1
- package/lib/genericToolset.js +124 -87
- package/lib/index.js +4 -2
- package/lib/wsCli.js +257 -0
- package/lib/wsIO.js +96 -0
- package/package.json +26 -20
- package/types/API/openai.com/reponses/text.d.ts +17 -3
- package/types/API/x.ai/collections.d.ts +167 -0
- package/types/API/x.ai/files.d.ts +84 -0
- package/types/API/x.ai/responses.d.ts +379 -0
- package/types/AgentClient.d.ts +5 -0
- package/types/AgentManager.d.ts +24 -31
- package/types/AgentServer.d.ts +5 -1
- package/types/Prompt.d.ts +4 -2
- package/types/ToolSet.d.ts +1 -0
- package/types/index.d.ts +4 -3
- package/types/wsCli.d.ts +3 -0
- package/types/wsIO.d.ts +26 -0
- package/utils/bars.js +40 -0
- package/utils/clear_sessions.sh +54 -0
- package/{bin/hdInspect.js → utils/format_log.js} +5 -0
- package/utils/list_sessions.sh +46 -0
- package/utils/search_sessions.sh +73 -0
- package/bin/hdClear.js +0 -13
- package/bin/hdConnect.js +0 -230
- package/bin/hdNpm.js +0 -114
- package/bin/hdPrompt.js +0 -108
- package/examples/claude-test.js +0 -89
- package/examples/claude.js +0 -143
- package/examples/gpt_code.js +0 -125
- package/examples/gpt_note_keeping.js +0 -117
- package/examples/grok_code.js +0 -114
- package/examples/grok_note_keeping.js +0 -111
- package/module.md +0 -189
package/examples/gpt.js
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import AgentManager from '../lib/AgentManager.js';
|
|
2
|
+
import { AgentManager } from '@j-o-r/hello-dave';
|
|
5
3
|
import { parseArgs, readIn } from '@j-o-r/sh';
|
|
6
|
-
import genTools from '../lib/genericToolset.js';
|
|
7
4
|
|
|
8
|
-
const name =
|
|
5
|
+
const name = 'chat_gpt';
|
|
9
6
|
const api = 'gpt';
|
|
7
|
+
let secret = '';
|
|
10
8
|
|
|
11
|
-
const input = await readIn();
|
|
9
|
+
// const input = await readIn();
|
|
12
10
|
const args = parseArgs();
|
|
13
11
|
const help = args['help'] || false;
|
|
14
12
|
const connect = args['connect'] ? args['connect'] : undefined;
|
|
15
13
|
const serve = args['serve'] ? parseInt(args['serve']) : undefined;
|
|
16
14
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
/** @type {import('@j-o-r/hello-dave/types/API/openai.com/reponses/text').OAOptions} */
|
|
16
|
+
const options = {
|
|
17
|
+
tools: []
|
|
18
|
+
}
|
|
19
|
+
options.tools.push({
|
|
20
|
+
type: 'web_search'
|
|
21
|
+
});
|
|
22
|
+
if (args['secret']) { // model gets default value
|
|
23
|
+
secret = args['secret'];
|
|
24
|
+
}
|
|
21
25
|
// Set properties only if provided via command line (except model which has default)
|
|
22
26
|
if (args['model'] || true) { // model gets default value
|
|
23
|
-
|
|
24
|
-
options.model = args['model'] || 'gpt-5';
|
|
27
|
+
options.model = args['model'] || 'gpt-5.4';
|
|
25
28
|
}
|
|
26
|
-
// temperature is NOT available for o3 / 03-mini
|
|
27
29
|
if (args['temperature']) {
|
|
28
30
|
options.temperature = parseFloat(args['temperature']);
|
|
29
31
|
}
|
|
@@ -33,41 +35,38 @@ if (args['tokens']) {
|
|
|
33
35
|
if (args['top_p']) {
|
|
34
36
|
options.top_p = parseFloat(args['top_p']);
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
// always enable search
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
// options.search = args['search'] || 'medium';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const reasoning = args['reasoning'] ? args['reasoning'] : null;
|
|
43
|
-
|
|
38
|
+
const reasoning = true // args['reasoning'] ? args['reasoning'] : null;
|
|
44
39
|
if (reasoning) {
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
options.reasoning = {
|
|
41
|
+
effort: 'medium',
|
|
42
|
+
summary: 'auto'
|
|
43
|
+
}
|
|
47
44
|
}
|
|
45
|
+
// Large context on grok-4-fast
|
|
46
|
+
const contextWindow = args['context'] ? parseInt(args['context']) : 100000;
|
|
47
|
+
const toolsetMode = 'auto';
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
const contextWindow = args['context'] ? parseInt(args['context']) : 399000;
|
|
51
|
-
|
|
52
|
-
function printHelp () {
|
|
49
|
+
function printHelp() {
|
|
53
50
|
console.log(`
|
|
54
51
|
'${name} --help' You are looking at it.
|
|
55
52
|
'
|
|
56
53
|
OPTIONS:
|
|
57
|
-
--tokens [number]: max generated tokens
|
|
58
|
-
--context [number] : truncate message history to context-windows size default
|
|
59
|
-
--temperature [float] :
|
|
60
|
-
--model [
|
|
61
|
-
--
|
|
62
|
-
--reasoning [low|
|
|
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-1-fast-reasoning'|'grok-4-1-fast-non-reasoning'|'grok-code-fast-1'|'grok-4-fast-reasoning'|'grok-4-fast-non-reasoning']
|
|
58
|
+
--top_p [float]: number > 0, 0.1 means no top_p
|
|
59
|
+
--reasoning [low|high]
|
|
63
60
|
--tools [javascript,bash] comma seperated list
|
|
64
|
-
|
|
65
|
-
|
|
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
66
|
|
|
67
67
|
`);
|
|
68
|
-
process.exit()
|
|
68
|
+
process.exit()
|
|
69
69
|
}
|
|
70
|
-
|
|
71
70
|
if (help) {
|
|
72
71
|
printHelp();
|
|
73
72
|
}
|
|
@@ -76,7 +75,7 @@ const prompt = `
|
|
|
76
75
|
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.
|
|
77
76
|
`.trim();
|
|
78
77
|
|
|
79
|
-
const agent = new AgentManager({ name });
|
|
78
|
+
const agent = new AgentManager({ name, secret });
|
|
80
79
|
agent.setup({
|
|
81
80
|
prompt,
|
|
82
81
|
api,
|
|
@@ -84,44 +83,27 @@ agent.setup({
|
|
|
84
83
|
toolsetMode,
|
|
85
84
|
contextWindow
|
|
86
85
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
tools.push('execute_bash_script');
|
|
102
|
-
toolset.add('execute_bash_script', tool.description, tool.parameters, tool.method);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
86
|
+
// agent.addGenericToolcall('open_link');
|
|
87
|
+
// agent.addGenericToolcall('send_email');
|
|
88
|
+
// agent.addGenericToolcall('history_search');
|
|
89
|
+
//
|
|
90
|
+
// const addTools = (args['tools']) ? args['tools'].split(',') : ['bash'];
|
|
91
|
+
// if (addTools.includes('javascript')) {
|
|
92
|
+
// agent.addGenericToolcall('javascript_interpreter');
|
|
93
|
+
// }
|
|
94
|
+
// if (addTools.includes('bash')) {
|
|
95
|
+
// agent.addGenericToolcall('execute_bash_script');
|
|
96
|
+
// }
|
|
97
|
+
// if (addTools.includes('ssh')) {
|
|
98
|
+
// agent.addGenericToolcall('execute_remote_script');
|
|
99
|
+
// }
|
|
107
100
|
const cliIntro = `
|
|
108
101
|
${name} ${options.model}.
|
|
109
102
|
- context: ${contextWindow}
|
|
110
103
|
`.trim();
|
|
111
|
-
|
|
112
104
|
const description = `
|
|
113
|
-
|
|
105
|
+
Guide for this smart online AI Agent:
|
|
106
|
+
- query: Formulate ONE efficient, comprehensive search query in natural language, combining multiple sources/subjects/domains; mention optional sources if needed. Avoid multiple queries—consolidate into a single one.
|
|
114
107
|
`.trim();
|
|
115
108
|
|
|
116
|
-
|
|
117
|
-
agent.enableServer(name, description, serve);
|
|
118
|
-
}
|
|
119
|
-
if (input !== '') {
|
|
120
|
-
// Direct input output
|
|
121
|
-
const res = await agent.directCall(input);
|
|
122
|
-
console.log(res);
|
|
123
|
-
} else if(connect) {
|
|
124
|
-
agent.attach(name, description, connect)
|
|
125
|
-
} else {
|
|
126
|
-
agent.startCli(cliIntro);
|
|
127
|
-
}
|
|
109
|
+
await agent.start(serve, connect, cliIntro, "search_agent", description);
|
package/examples/grok.js
CHANGED
|
@@ -1,45 +1,56 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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';
|
|
5
9
|
import { parseArgs, readIn } from '@j-o-r/sh';
|
|
6
|
-
import genTools from '../lib/genericToolset.js';
|
|
7
10
|
|
|
8
|
-
const name =
|
|
9
|
-
const api = '
|
|
11
|
+
const name = 'ask_grok';
|
|
12
|
+
const api = 'xai';
|
|
13
|
+
let secret = '';
|
|
10
14
|
|
|
11
15
|
const input = await readIn();
|
|
12
16
|
const args = parseArgs();
|
|
13
17
|
const help = args['help'] || false;
|
|
14
|
-
const connect = args['connect'] ? args['connect'] : undefined;
|
|
15
|
-
const serve = args['serve'] ? parseInt(args['serve']) : undefined;
|
|
16
18
|
|
|
17
|
-
/** @type {import('lib/API/x.ai/
|
|
18
|
-
const options = {
|
|
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
|
+
|
|
19
30
|
// Set properties only if provided via command line (except model which has default)
|
|
20
31
|
if (args['model'] || true) { // model gets default value
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
options.model = args['model'] || 'grok-4';
|
|
32
|
+
// @ts-ignore || grok-4-1-fast-non-reasoning
|
|
33
|
+
options.model = args['model'] || 'grok-4.20-multi-agent-0309';
|
|
23
34
|
}
|
|
24
35
|
if (args['temperature']) {
|
|
25
36
|
options.temperature = parseFloat(args['temperature']);
|
|
26
37
|
}
|
|
27
38
|
if (args['tokens']) {
|
|
28
|
-
options.
|
|
39
|
+
options.max_output_tokens = parseInt(args['tokens']);
|
|
29
40
|
}
|
|
30
41
|
if (args['top_p']) {
|
|
31
42
|
options.top_p = parseFloat(args['top_p']);
|
|
32
43
|
}
|
|
33
|
-
|
|
34
|
-
options.search_parameters = { mode: 'auto' }
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
const reasoning = args['reasoning'] ? args['reasoning'] : null;
|
|
44
|
+
const reasoning = true // args['reasoning'] ? args['reasoning'] : null;
|
|
37
45
|
if (reasoning) {
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
options.reasoning = {
|
|
47
|
+
effort: 'medium',
|
|
48
|
+
summary: 'auto'
|
|
49
|
+
}
|
|
40
50
|
}
|
|
41
|
-
|
|
42
|
-
const contextWindow = args['context'] ? parseInt(args['context']) :
|
|
51
|
+
// Large context on grok-4-fast
|
|
52
|
+
const contextWindow = args['context'] ? parseInt(args['context']) : 1900000;
|
|
53
|
+
const toolsetMode = 'auto';
|
|
43
54
|
|
|
44
55
|
function printHelp() {
|
|
45
56
|
console.log(`
|
|
@@ -49,25 +60,32 @@ OPTIONS:
|
|
|
49
60
|
--tokens [number]: max generated tokens
|
|
50
61
|
--context [number] : truncate message history to context-windows size default 130000
|
|
51
62
|
--temperature [float] : -2 / +2
|
|
52
|
-
--model [grok-4|grok-
|
|
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']
|
|
53
64
|
--top_p [float]: number > 0, 0.1 means no top_p
|
|
54
65
|
--reasoning [low|high]
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
|
|
67
|
+
USAGE:
|
|
68
|
+
|
|
69
|
+
\`\`\`bash
|
|
70
|
+
echo "What is ..." | grok.js
|
|
71
|
+
\`\`\`
|
|
58
72
|
|
|
59
73
|
`);
|
|
60
74
|
process.exit()
|
|
61
75
|
}
|
|
62
|
-
|
|
63
76
|
if (help) {
|
|
64
77
|
printHelp();
|
|
65
78
|
}
|
|
79
|
+
|
|
80
|
+
if (input.trim() === '') {
|
|
81
|
+
printHelp();
|
|
82
|
+
}
|
|
83
|
+
|
|
66
84
|
const prompt = `
|
|
67
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.
|
|
68
86
|
`.trim();
|
|
69
87
|
|
|
70
|
-
const agent = new AgentManager({ name });
|
|
88
|
+
const agent = new AgentManager({ name, secret });
|
|
71
89
|
agent.setup({
|
|
72
90
|
prompt,
|
|
73
91
|
api,
|
|
@@ -75,45 +93,6 @@ agent.setup({
|
|
|
75
93
|
toolsetMode,
|
|
76
94
|
contextWindow
|
|
77
95
|
});
|
|
78
|
-
const tools = [];
|
|
79
|
-
const toolset = agent.getToolset();
|
|
80
|
-
if (toolset && args['tools']) {
|
|
81
|
-
const addTools = args['tools'].split(',') || [];
|
|
82
|
-
if (addTools.includes('javascript')) {
|
|
83
|
-
let tool = genTools.get('javascript_interpreter');
|
|
84
|
-
if (tool) {
|
|
85
|
-
tools.push('javascript_interpreter');
|
|
86
|
-
toolset.add('javascript_interpreter', tool.description, tool.parameters, tool.method);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (addTools.includes('bash')) {
|
|
90
|
-
let tool = genTools.get('execute_bash_script');
|
|
91
|
-
if (tool) {
|
|
92
|
-
tools.push('execute_bash_script');
|
|
93
|
-
toolset.add('execute_bash_script', tool.description, tool.parameters, tool.method);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const cliIntro = `
|
|
99
|
-
${name} ${options.model}.
|
|
100
|
-
- search ${options.search_parameters.mode}
|
|
101
|
-
`.trim();
|
|
102
|
-
|
|
103
|
-
const description = `
|
|
104
|
-
Generic helper and smart AI for difficult tasks. Natural language, math and reasoning - the perfect jack of all trades
|
|
105
|
-
`.trim();
|
|
106
96
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
if (input !== '') {
|
|
111
|
-
// Direct input output
|
|
112
|
-
const res = await agent.directCall(input);
|
|
113
|
-
console.log(res);
|
|
114
|
-
} else if(connect) {
|
|
115
|
-
agent.attach(name, description, connect)
|
|
116
|
-
} else if(!serve) {
|
|
117
|
-
// Mix a cli with a server is a thing we need to test
|
|
118
|
-
agent.startCli(cliIntro);
|
|
119
|
-
}
|
|
97
|
+
const res = await agent.directCall(input);
|
|
98
|
+
console.log(res);
|
|
@@ -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);
|