@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/CHANGELOG.md +28 -17
- package/README.md +160 -51
- package/README.md.bak +106 -64
- package/README.md.bak2 +194 -118
- package/bin/dave.js +33 -22
- package/examples/gpt_agent.js +3 -6
- package/lib/ToolSet.js +4 -1
- package/lib/index.js +5 -1
- package/package.json +3 -3
- package/types/index.d.ts +3 -1
- package/examples/coderev_agent.js +0 -136
- package/examples/grok_agent.js.bak +0 -98
- package/examples/grok_agent.js.bak.2 +0 -99
- package/examples/grok_agent.js.bak.3 +0 -1
- package/examples/grok_agent.js.bak.4 +0 -124
- package/examples/grok_agent.js.bak.5 +0 -1
- package/examples/grok_agent.js.bak.6 +0 -1
- package/examples/npm_agent.js.bak.3 +0 -2
- package/examples/npm_agent.js.bak.4 +0 -205
- package/examples/npm_agent.js.bak.5 +0 -1
- package/examples/npm_agent.js.bak.6 +0 -1
- /package/{examples → bin}/spawn_agent.js +0 -0
|
@@ -1,205 +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 = 'npm_agent';
|
|
6
|
-
const api = 'xai';
|
|
7
|
-
let secret = '';
|
|
8
|
-
|
|
9
|
-
let input; // Directcall input
|
|
10
|
-
const args = parseArgs();
|
|
11
|
-
|
|
12
|
-
if (args._.length === 1 && typeof args._[0] === 'string' && args._[0].trim() !== '') {
|
|
13
|
-
input = args._[0].trim();
|
|
14
|
-
} else {
|
|
15
|
-
// Fallback for piped stdin (async readIn)
|
|
16
|
-
const { readIn } = await import('@j-o-r/sh');
|
|
17
|
-
input = await readIn();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const help = args['help'] || false;
|
|
21
|
-
const connect = args['connect'] ? args['connect'] : undefined;
|
|
22
|
-
const serve = args['serve'] ? parseInt(args['serve']) : undefined;
|
|
23
|
-
|
|
24
|
-
/** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
|
|
25
|
-
const options = { tools: [] };
|
|
26
|
-
options.tools.push({
|
|
27
|
-
type: 'web_search'
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (args['secret']) {
|
|
31
|
-
secret = args['secret'];
|
|
32
|
-
}
|
|
33
|
-
if (args['model'] || true) {
|
|
34
|
-
options.model = args['model'] || 'grok-4-fast-reasoning';
|
|
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;
|
|
46
|
-
if (reasoning) {
|
|
47
|
-
options.reasoning = {
|
|
48
|
-
effort: 'medium',
|
|
49
|
-
summary: 'auto'
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
const toolsetMode = 'auto';
|
|
53
|
-
const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
|
|
54
|
-
|
|
55
|
-
function printHelp() {
|
|
56
|
-
console.log(`
|
|
57
|
-
'${name} --help' You are looking at it.
|
|
58
|
-
|
|
59
|
-
## USAGE MODES:
|
|
60
|
-
|
|
61
|
-
### 1. Direct Call (One-Shot, Positional):
|
|
62
|
-
./examples/${name}.js "What modules are installed?" [--options]
|
|
63
|
-
|
|
64
|
-
### 2. Pipe/Stdin (One-Shot):
|
|
65
|
-
echo "What modules are installed?" | ./examples/${name}.js [--options]
|
|
66
|
-
|
|
67
|
-
### 3. Interactive CLI:
|
|
68
|
-
./examples/${name}.js [--options]
|
|
69
|
-
|
|
70
|
-
### 4. WS Server (no input):
|
|
71
|
-
./examples/${name}.js --serve 8080 [--secret mysecret] [--options]
|
|
72
|
-
|
|
73
|
-
### 5. WS Client (no input):
|
|
74
|
-
./examples/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
|
|
75
|
-
|
|
76
|
-
### 6. Hybrid (Server + Client):
|
|
77
|
-
./examples/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
|
|
78
|
-
|
|
79
|
-
## OPTIONS:
|
|
80
|
-
--model [grok-4-fast-reasoning|...] (default: grok-4-fast-reasoning)
|
|
81
|
-
--temperature [float] (-2 to +2)
|
|
82
|
-
--tokens [number] (max output tokens)
|
|
83
|
-
--top_p [float]
|
|
84
|
-
--context [number] (default: 250000)
|
|
85
|
-
--secret [string] (WS auth)
|
|
86
|
-
|
|
87
|
-
## SERVER TOOLS (when no input):
|
|
88
|
-
Exposes as 'npm_module_inspector' tool for chaining.
|
|
89
|
-
`);
|
|
90
|
-
process.exit()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (help) {
|
|
94
|
-
printHelp();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const tool_call_name = 'npm_module_inspector';
|
|
98
|
-
const tool_call_description = `
|
|
99
|
-
NPM modules expert (scoped & unscoped). Uses \`npm ls -a\` + bash **exclusively inside ./node_modules/**.
|
|
100
|
-
**Smart Cache**: .cache/npm-agent-storage.md (auto-read/update, token-efficient, auto-refreshes on changes). Agent-owned.
|
|
101
|
-
`.trim();
|
|
102
|
-
|
|
103
|
-
const CACHE_FILE = '.cache/npm-agent-storage.md';
|
|
104
|
-
|
|
105
|
-
const prompt = `
|
|
106
|
-
You are a coding assistant specializing in Bash and JavaScript (ESM/ESNext), with support for other languages.
|
|
107
|
-
Your role: Help users code with external NPM modules installed in the project's ./node_modules/ (dynamic CWD).
|
|
108
|
-
Scoped (@j-o-r/cli) == unscoped (gpt-3-encoder) priority.
|
|
109
|
-
|
|
110
|
-
CWD dynamic (pwd; project root w/ package.json/node_modules).
|
|
111
|
-
|
|
112
|
-
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).
|
|
113
|
-
|
|
114
|
-
**Dependency Strategy**: For all coding requests, follow this order to keep dependencies minimal (prevent bloat):
|
|
115
|
-
1. **Always try existing installed modules first**: Scan \`npm ls -a\` FULL TREE (all subdeps). Prioritize functions from ANY module.
|
|
116
|
-
2. **Native code**: Node.js/Bash builtins ONLY if no module match.
|
|
117
|
-
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.
|
|
118
|
-
|
|
119
|
-
**Auto-Cache Init (MANDATORY FIRST on EVERY query - FULL SCAN)**:
|
|
120
|
-
touch ${CACHE_FILE}
|
|
121
|
-
echo "## Full Tree (npm ls -a unique modules)" >> ${CACHE_FILE}
|
|
122
|
-
npm ls -a --parseable 2>/dev/null | sed 's|.*/||' | sort -u | head -50 >> ${CACHE_FILE} # All unique PKGs (top + sub)
|
|
123
|
-
echo "## Top-Level (--depth=0)" >> ${CACHE_FILE}
|
|
124
|
-
npm ls --depth=0 | grep -E '^[├└]──' | sed 's/^[├└ ]*── //' | sed 's/ .*//' >> ${CACHE_FILE}
|
|
125
|
-
**Condensed Scan**: find node_modules/ -name package.json | sed 's|.*/||;s|/package.json||' | sort -u > ${CACHE_FILE}.allmods
|
|
126
|
-
|
|
127
|
-
**Vague Query Mode** (e.g., "tests"):
|
|
128
|
-
- 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\`
|
|
129
|
-
- Output table: Module | Exports | For | Usage (from all tree).
|
|
130
|
-
- Append "## QUERY: \$QUERY\nHits: list" >> ${CACHE_FILE}
|
|
131
|
-
|
|
132
|
-
**Smart Cache (.cache/npm-agent-storage.md)**: Agent-owned, **auto-managed FULL TREE** (read-first, update-on-change).
|
|
133
|
-
- Token Saver: Grep FIRST across all sections.
|
|
134
|
-
- Init: touch .cache/npm-agent-storage.md
|
|
135
|
-
|
|
136
|
-
PRIORITIZE \`npm ls -a\` (full tree) + bash inside ALL MODULE_DIRs.
|
|
137
|
-
|
|
138
|
-
Tools:
|
|
139
|
-
- execute_bash_script: \`npm ls -a ...\` + \`cat node_modules/\$PKG_NAME/package.json\`. Prefix ALWAYS.
|
|
140
|
-
- web_search: Docs ONLY.
|
|
141
|
-
- history_search: Chats.
|
|
142
|
-
|
|
143
|
-
**Smart Workflow** (per query; full tree always):
|
|
144
|
-
1. **Full Tree Installed/Version**:
|
|
145
|
-
PKGS=\$(npm ls -a --parseable 2>/dev/null | sed 's|.*/||' | sort -u | head -50)
|
|
146
|
-
for PKG in \$PKGS; do npm ls "\$PKG" 2>/dev/null | tail -1 | grep -o 'v[0-9].*' || echo "\$PKG ??"; done
|
|
147
|
-
|
|
148
|
-
2. **Smart Cache Check**:
|
|
149
|
-
grep -A 30 "^## Full Tree" .cache/npm-agent-storage.md || echo "Cache miss"
|
|
150
|
-
|
|
151
|
-
3. **Inspect if Miss** (loop top 10 hits):
|
|
152
|
-
- For each MODULE_DIR=node_modules/\$PKG: [existing inspect + enhanced types/docs grep]
|
|
153
|
-
- Vague: grep -riE "\$QUERY" node_modules/\$PKG/*.{json,md,d.ts,js} | head -20
|
|
154
|
-
|
|
155
|
-
4. **Auto-Update Cache** (CONDENSED, FULL):
|
|
156
|
-
sed -i.bak "/^## Full Tree/,/^## QUERY/d" ${CACHE_FILE} && rm ${CACHE_FILE}.bak
|
|
157
|
-
cat >> ${CACHE_FILE} << EOC
|
|
158
|
-
## Full Tree (npm ls -a)
|
|
159
|
-
\$ALL_PKGS (50 unique)
|
|
160
|
-
|
|
161
|
-
## \$PKG v\$VER
|
|
162
|
-
Exports: \$EXPORTS
|
|
163
|
-
For: \$KEYWORDS (test/query hits)
|
|
164
|
-
Usage: import {fn} from '\$PKG';
|
|
165
|
-
EOC
|
|
166
|
-
|
|
167
|
-
5. **List All**: \`npm ls -a | head -50 | grep -E '^[├└]' | sed 's/^[├└ ]*── //' | cut -d@ -f1 | sort -u\`
|
|
168
|
-
|
|
169
|
-
6. **Coding Help**: ESM/Bash snippets from FULL TREE. **MANDATORY**: Strategy + table + "NO new deps - use existing \$PKG".
|
|
170
|
-
|
|
171
|
-
**MANDATORY**: FULL \`npm ls -a\` every time. Vague scans ALL modules. **STRICT NO INSTALLS** unless proven gap. Condensed output. Portable.
|
|
172
|
-
`.trim();
|
|
173
|
-
|
|
174
|
-
const agent = new AgentManager({ name, secret });
|
|
175
|
-
agent.setup({
|
|
176
|
-
prompt,
|
|
177
|
-
api,
|
|
178
|
-
options,
|
|
179
|
-
toolsetMode,
|
|
180
|
-
contextWindow
|
|
181
|
-
});
|
|
182
|
-
const toolset = agent.getToolset();
|
|
183
|
-
if (toolset) {
|
|
184
|
-
agent.addGenericToolcall('history_search');
|
|
185
|
-
agent.addGenericToolcall('javascript_interpreter');
|
|
186
|
-
agent.addGenericToolcall('execute_bash_script');
|
|
187
|
-
agent.addGenericToolcall('read_file');
|
|
188
|
-
agent.addGenericToolcall('write_file');
|
|
189
|
-
}
|
|
190
|
-
const cliIntro = `
|
|
191
|
-
${name} ${options.model}.
|
|
192
|
-
- context: ${contextWindow}. Smart cache: ${CACHE_FILE} (FULL npm ls -a auto).
|
|
193
|
-
${tool_call_name}
|
|
194
|
-
`.trim();
|
|
195
|
-
|
|
196
|
-
if (!input || input.trim() === '') {
|
|
197
|
-
printHelp();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (input) {
|
|
201
|
-
const RES = await agent.directCall(input);
|
|
202
|
-
console.log(RES);
|
|
203
|
-
} else {
|
|
204
|
-
await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
|
|
205
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Full backup before CLI no-args fix
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Backup before adding serve/connect/secret explanations to printHelp
|
|
File without changes
|