@j-o-r/hello-dave 0.0.5 → 0.0.7
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 +13 -26
- package/README.md +161 -522
- package/README.md.bak +144 -449
- package/{examples → agents}/ask_agent.js +5 -5
- package/{examples → agents}/codeserver.sh +14 -14
- package/{examples → agents}/daisy_agent.js +5 -5
- package/{examples → agents}/docs_agent.js +5 -5
- package/{examples → agents}/gpt_agent.js +5 -5
- package/{examples → agents}/grok_agent.js +5 -5
- package/agents/memory_agent.js +263 -0
- package/{examples → agents}/npm_agent.js +5 -5
- package/{examples → agents}/prompt_agent.js +5 -5
- package/agents/spawn_agent.js +137 -0
- package/{examples → agents}/test_agent.js +6 -8
- package/{examples → agents}/todo_agent.js +5 -5
- package/bin/codeDave +58 -0
- package/bin/dave.js +114 -96
- package/lib/AgentClient.js +111 -67
- package/lib/AgentManager.js +111 -80
- package/lib/AgentServer.js +144 -104
- package/lib/Cli.js +126 -93
- package/lib/Prompt.js +38 -5
- package/lib/Session.js +102 -79
- package/lib/ToolSet.js +79 -60
- package/lib/fafs.js +54 -19
- package/lib/genericToolset.js +109 -213
- package/lib/wsCli.js +50 -19
- package/lib/wsIO.js +11 -17
- package/package.json +2 -2
- package/types/AgentClient.d.ts +69 -35
- package/types/AgentManager.d.ts +50 -56
- package/types/AgentServer.d.ts +63 -16
- package/types/Cli.d.ts +56 -10
- package/types/Prompt.d.ts +36 -4
- package/types/Session.d.ts +23 -9
- package/types/ToolSet.d.ts +49 -32
- package/types/fafs.d.ts +68 -25
- package/types/wsCli.d.ts +14 -0
- package/types/wsIO.d.ts +9 -5
- package/utils/search_sessions.sh +100 -53
- package/README.md.backup +0 -269
- package/README.md.bak.1774780058 +0 -338
- package/README.md.bak2 +0 -531
- package/bin/spawn_agent.js +0 -293
- package/docs.bak.1774780058/agent-manager.md +0 -167
- package/docs.bak.1774780058/agent-manager.md.bak +0 -137
- package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
- package/docs.bak.1774780058/codeserver-pattern.md +0 -191
- package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
- package/docs.bak.1774780058/project-overview.md +0 -67
- package/docs.bak.1774780058/project-overview.md.bak +0 -67
- package/docs.bak.1774780058/prompt-class.md +0 -141
- package/docs.bak.1774780058/prompt-class.md.bak +0 -142
- package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
- package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
- package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
- package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
- package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
- package/docs.bak.1774780058/toolset.md +0 -164
- package/docs.bak.1774780058/toolset.md.bak +0 -94
- package/docs.bak.1774780058/toolset.md.bak3 +0 -161
- package/docs.bak.1774780058/toolset.md.bak4 +0 -161
- package/docs.bak.1774780058/toolset.md.bak5 +0 -161
- package/docs.bak.1774780058/toolset.md.bak6 +0 -163
- package/docs.bak.1774780058/toolset.md.bak_path +0 -163
- package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
- package/docs.bak.1774780058/xai-responses.md +0 -111
- package/docs.bak.1774780058/xai-responses.md.bak +0 -107
- package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
- package/docs.bak.1774780058/xai_collections.md +0 -106
- package/examples/memory_agent.js +0 -152
- package/examples.bak.1774780058/ask_agent.js +0 -114
- package/examples.bak.1774780058/code_agent.js +0 -149
- package/examples.bak.1774780058/coderev_agent.js +0 -72
- package/examples.bak.1774780058/codeserver.sh +0 -47
- package/examples.bak.1774780058/daisy_agent.js +0 -177
- package/examples.bak.1774780058/docs_agent.js +0 -119
- package/examples.bak.1774780058/gpt_agent.js +0 -109
- package/examples.bak.1774780058/grok_agent.js +0 -98
- package/examples.bak.1774780058/memory_agent.js +0 -112
- package/examples.bak.1774780058/npm_agent.js +0 -175
- package/examples.bak.1774780058/prompt_agent.js +0 -112
- package/examples.bak.1774780058/readme_agent.js +0 -144
- package/examples.bak.1774780058/spawn_agent.js +0 -263
- package/examples.bak.1774780058/test_agent.js +0 -162
- package/examples.bak.1774780058/todo_agent.js +0 -138
- package/lib/genericToolset.js.bak_syntax +0 -402
- package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
- package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
- package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
- package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
- package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
- package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
- package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
- package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
- package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
- package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
- package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
- package/scenarios.bak.1774780058/environment.js +0 -10
- package/scenarios.bak.1774780058/example.js +0 -17
- package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
- package/scenarios.bak.1774780058/grok.js +0 -113
- package/scenarios.bak.1774780058/memory-tools.js +0 -51
- package/scenarios.bak.1774780058/openai-o3.js +0 -137
- package/scenarios.bak.1774780058/openai-prompt.js +0 -155
- package/scenarios.bak.1774780058/openai-session.js +0 -148
- package/scenarios.bak.1774780058/openai.js +0 -102
- package/scenarios.bak.1774780058/prompt.js +0 -118
- package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
- package/scenarios.bak.1774780058/search.brave.com.js +0 -25
- package/scenarios.bak.1774780058/sh.js +0 -15
- package/scenarios.bak.1774780058/test-wsio.js +0 -26
- package/scenarios.bak.1774780058/testToolset.js +0 -42
- package/scenarios.bak.1774780058/toolset.js +0 -16
- package/scenarios.bak.1774780058/toolset.test.js +0 -141
- package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
- package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
- package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
- package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
- package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
- package/scenarios.bak.1774780058/wsClient.js +0 -69
- package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
- package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
- package/scenarios.bak.1774780058/xaicoll.js +0 -50
- package/scenarios.bak.1774780058/xaifiles.js +0 -48
- /package/{examples → agents}/code_agent.js +0 -0
- /package/{examples → agents}/readme_agent.js +0 -0
|
@@ -55,19 +55,19 @@ function printHelp() {
|
|
|
55
55
|
## USAGE MODES:
|
|
56
56
|
|
|
57
57
|
### 1. Direct Call (One-Shot, Positional ONLY):
|
|
58
|
-
./
|
|
58
|
+
./agents/${name}.js "Generate test for toolset.js" [--options]
|
|
59
59
|
|
|
60
60
|
### 2. Interactive CLI (no positional arg):
|
|
61
|
-
./
|
|
61
|
+
./agents/${name}.js [--options]
|
|
62
62
|
|
|
63
63
|
### 3. WS Server (no positional arg):
|
|
64
|
-
./
|
|
64
|
+
./agents/${name}.js --serve 8080 [--secret mysecret] [--options]
|
|
65
65
|
|
|
66
66
|
### 4. WS Client (no positional arg):
|
|
67
|
-
./
|
|
67
|
+
./agents/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
|
|
68
68
|
|
|
69
69
|
### 5. Hybrid (Server + Client, no positional arg):
|
|
70
|
-
./
|
|
70
|
+
./agents/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
|
|
71
71
|
|
|
72
72
|
## SERVER OPTIONS EXPLAINED:
|
|
73
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., 'test_agent'). Runs indefinitely until Ctrl+C.
|
|
@@ -108,7 +108,7 @@ const prompt = `You are TestAgent, the specialized testing agent for CodeServer
|
|
|
108
108
|
- Tests must use: \`import { Test, assert, jsType } from '@j-o-r/sh';\`
|
|
109
109
|
- Structure: shebang \`#!/usr/bin/env node\`, fluent Test API (\`const t = new Test(); t.add('desc', () => { assert... }); await t.run();\`), exit(1) on errors.
|
|
110
110
|
- After write_file to scenarios/MODULE.test.js, ensure executable: \`chmod +x scenarios/MODULE.test.js\`
|
|
111
|
-
- Leverage project utilities: test existing files (
|
|
111
|
+
- Leverage project utilities: test existing files (agents/*.js, toolset.js, agents, SH commands, etc.) using read_file, execute_bash_script (ls/cat), npm_module_inspector.
|
|
112
112
|
|
|
113
113
|
**WHAT TO TEST** (discover dynamically):
|
|
114
114
|
1. Project scripts: e.g., parseArgs, AgentManager flows, toolsets.
|
|
@@ -166,8 +166,6 @@ agent.setup({
|
|
|
166
166
|
const toolset = agent.getToolset();
|
|
167
167
|
if (toolset) {
|
|
168
168
|
agent.addGenericToolcall('history_search');
|
|
169
|
-
agent.addGenericToolcall('memory_recall');
|
|
170
|
-
agent.addGenericToolcall('memory_write');
|
|
171
169
|
agent.addGenericToolcall('javascript_interpreter');
|
|
172
170
|
agent.addGenericToolcall('execute_bash_script');
|
|
173
171
|
agent.addGenericToolcall('read_file');
|
|
@@ -55,19 +55,19 @@ function printHelp() {
|
|
|
55
55
|
## USAGE MODES:
|
|
56
56
|
|
|
57
57
|
### 1. Direct Call (One-Shot, Positional ONLY):
|
|
58
|
-
./
|
|
58
|
+
./agents/${name}.js "List tasks" [--options]
|
|
59
59
|
|
|
60
60
|
### 2. Interactive CLI (no positional arg):
|
|
61
|
-
./
|
|
61
|
+
./agents/${name}.js [--options]
|
|
62
62
|
|
|
63
63
|
### 3. WS Server (no positional arg):
|
|
64
|
-
./
|
|
64
|
+
./agents/${name}.js --serve 8080 [--secret mysecret] [--options]
|
|
65
65
|
|
|
66
66
|
### 4. WS Client (no positional arg):
|
|
67
|
-
./
|
|
67
|
+
./agents/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
|
|
68
68
|
|
|
69
69
|
### 5. Hybrid (Server + Client, no positional arg):
|
|
70
|
-
./
|
|
70
|
+
./agents/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
|
|
71
71
|
|
|
72
72
|
## SERVER OPTIONS EXPLAINED:
|
|
73
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., 'todo_agent'). Runs indefinitely until Ctrl+C.
|
package/bin/codeDave
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
|
|
3
|
+
echo "Usage: $0 <PORT> [SECRET] # PORT: 1024-65535, SECRET: optional (defaults to '123')"
|
|
4
|
+
exit 1
|
|
5
|
+
fi
|
|
6
|
+
|
|
7
|
+
PORT="$1"
|
|
8
|
+
SECRET="${2:-123}"
|
|
9
|
+
|
|
10
|
+
if [ -z "$SECRET" ] || [ ${#SECRET} -lt 3 ]; then
|
|
11
|
+
echo "Error: SECRET must be at least 3 characters: '$SECRET'"
|
|
12
|
+
exit 1
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
if ! [[ "$PORT" =~ ^[0-9]+$ ]] || [ "$PORT" -lt 1024 ] || [ "$PORT" -gt 65535 ]; then
|
|
16
|
+
echo "Error: Invalid port number: $PORT. Must be between 1024 and 65535."
|
|
17
|
+
exit 1
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
# Compute canonical paths relative to THIS script's real location (resolves symlinks for global npm installs)
|
|
21
|
+
SOURCE="${BASH_SOURCE[0]}"
|
|
22
|
+
while [ -h "$SOURCE" ]; do
|
|
23
|
+
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
|
|
24
|
+
SOURCE="$(readlink "$SOURCE")"
|
|
25
|
+
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
|
26
|
+
done
|
|
27
|
+
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
|
|
28
|
+
PROJECT_DIR="$( cd -P "$( dirname "$SCRIPT_DIR" )" >/dev/null 2>&1 && pwd )"
|
|
29
|
+
|
|
30
|
+
# FOLDER: basename of CURRENT WORKING DIRECTORY (pwd) for per-project PM2 prefixes (e.g., myproject_code_8080)
|
|
31
|
+
# This allows multi-project usage without name conflicts; PROJECT_DIR remains package location for agents/
|
|
32
|
+
FOLDER=$(basename "$(pwd)")
|
|
33
|
+
|
|
34
|
+
echo "Starting codeDave on port ${PORT} in folder '${FOLDER}' (SCRIPT_DIR: ${SCRIPT_DIR}) with SECRET '${SECRET}'..."
|
|
35
|
+
|
|
36
|
+
# Delete existing processes with folder_port suffix
|
|
37
|
+
pm2 delete "${FOLDER}_code_${PORT}" 2>/dev/null || true
|
|
38
|
+
pm2 delete "${FOLDER}_todo_${PORT}" 2>/dev/null || true
|
|
39
|
+
pm2 delete "${FOLDER}_readme_${PORT}" 2>/dev/null || true
|
|
40
|
+
pm2 delete "${FOLDER}_npm_${PORT}" 2>/dev/null || true
|
|
41
|
+
pm2 delete "${FOLDER}_docs_${PORT}" 2>/dev/null || true
|
|
42
|
+
pm2 delete "${FOLDER}_test_${PORT}" 2>/dev/null || true
|
|
43
|
+
pm2 delete "${FOLDER}_memory_${PORT}" 2>/dev/null || true
|
|
44
|
+
pm2 delete "${FOLDER}_spawn_${PORT}" 2>/dev/null || true
|
|
45
|
+
|
|
46
|
+
# Spawn main Agent / server (absolute paths to scripts)
|
|
47
|
+
pm2 start "${PROJECT_DIR}/agents/code_agent.js" --name "${FOLDER}_code_${PORT}" -- --serve "${PORT}" --tools javascript --secret "${SECRET}"
|
|
48
|
+
# Attach clients
|
|
49
|
+
pm2 start "${PROJECT_DIR}/agents/todo_agent.js" --name "${FOLDER}_todo_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
|
|
50
|
+
pm2 start "${PROJECT_DIR}/agents/readme_agent.js" --name "${FOLDER}_readme_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
|
|
51
|
+
pm2 start "${PROJECT_DIR}/agents/npm_agent.js" --name "${FOLDER}_npm_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
|
|
52
|
+
pm2 start "${PROJECT_DIR}/agents/docs_agent.js" --name "${FOLDER}_docs_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
|
|
53
|
+
pm2 start "${PROJECT_DIR}/agents/test_agent.js" --name "${FOLDER}_test_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
|
|
54
|
+
pm2 start "${PROJECT_DIR}/agents/memory_agent.js" --name "${FOLDER}_memory_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
|
|
55
|
+
pm2 start "${PROJECT_DIR}/agents/spawn_agent.js" --name "${FOLDER}_spawn_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
|
|
56
|
+
|
|
57
|
+
echo "codeDave processes spawned with prefix '${FOLDER}_' and suffix _${PORT}. Check with: pm2 list | grep '${FOLDER}_${PORT}'"
|
|
58
|
+
echo "dave --connect ws://127.0.0.1:${PORT}/ws --secret '$SECRET'"
|
package/bin/dave.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env -S node
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import cli from '@j-o-r/cli';
|
|
4
|
-
import wsCli from '
|
|
5
|
-
import wsIO from '../lib/wsIO.js';
|
|
6
|
-
import { AgentManager } from '@j-o-r/hello-dave';
|
|
4
|
+
import { AgentManager, wsCli, wsIO } from '@j-o-r/hello-dave';
|
|
7
5
|
import { SH, parseArgs, readIn, bashEscape } from '@j-o-r/sh';
|
|
8
6
|
import { fileURLToPath } from 'node:url';
|
|
9
7
|
|
|
@@ -20,78 +18,148 @@ FLAGS:
|
|
|
20
18
|
--search "[search_query_or_regex]" : Search in cache history
|
|
21
19
|
--list : List all agent sessions in this folder
|
|
22
20
|
--inspect "[path_to_ndjson_log]" : Inspect, Format and output a ndjson log file
|
|
23
|
-
--connect [ws://url][--secret "..."] : Connect to Agent websocket server
|
|
21
|
+
--connect [ws://url] [--secret "..."] : Connect to Agent websocket server
|
|
24
22
|
Interactive: bin/dave.js --connect 'ws://localhost:8080' --secret '123'
|
|
25
23
|
Piped actions:
|
|
26
24
|
echo "predict the weather" | bin/dave.js --connect 'ws://...' --secret '123' # user_request
|
|
27
25
|
echo "user_info" | bin/dave.js --connect 'ws://...' --secret '123' # user_info
|
|
28
26
|
echo "user_reset" | bin/dave.js --connect 'ws://...' --secret '123' # user_reset
|
|
29
|
-
--
|
|
27
|
+
--ask [--connect [ws://url]] [--secret "..."] [--model modelname] : Ask agent locally (XAIKEY req.) or remote
|
|
28
|
+
Local: bin/dave.js --ask [--model grok-4-1-fast-reasoning]
|
|
29
|
+
Remote: bin/dave.js --ask --connect 'ws://localhost:8080' --secret '123'
|
|
30
|
+
Piped local: echo "predict the weather" | bin/dave.js --ask
|
|
31
|
+
Piped remote: echo "predict the weather" | bin/dave.js --ask --connect 'ws://...' --secret '123'
|
|
32
|
+
--code [port] [--secret "..."] : Launch CodeServer PM2 cluster via agents/codeserver.sh
|
|
30
33
|
Usage: bin/dave.js --code 8080 --secret 123
|
|
31
|
-
--ask : Launches a CLI and ask questions about whatever is on your mind
|
|
32
|
-
XAIKEY required: export XAIKEY=xai-...
|
|
33
34
|
`);
|
|
34
35
|
process.exit(exitCode)
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// Make sure an action is defined
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
!(
|
|
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
|
|
50
|
-
)
|
|
51
|
-
) {
|
|
39
|
+
const actions = ['help', 'clear', 'search', 'list', 'inspect', 'connect', 'code', 'ask'];
|
|
40
|
+
if (!actions.some(key => args[key])) {
|
|
52
41
|
printHelp(1);
|
|
53
42
|
}
|
|
54
43
|
|
|
55
|
-
if (args
|
|
44
|
+
if (args.help) {
|
|
56
45
|
printHelp();
|
|
57
46
|
}
|
|
58
47
|
|
|
59
|
-
if (args
|
|
60
|
-
const clear_sessions = path.resolve(__dirname, '..', 'utils', 'clear_sessions.sh')
|
|
48
|
+
if (args.clear) {
|
|
49
|
+
const clear_sessions = path.resolve(__dirname, '..', 'utils', 'clear_sessions.sh');
|
|
61
50
|
const y = await cli.yesNo('Delete entire cache? (y/n) ');
|
|
62
51
|
if (y) {
|
|
63
52
|
console.log(clear_sessions);
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
const res = await SH`${clear_sessions}`.run();
|
|
54
|
+
console.log(res);
|
|
66
55
|
}
|
|
67
56
|
process.exit();
|
|
68
|
-
} else if (args
|
|
69
|
-
const history_search = path.resolve(__dirname, '..', 'utils', 'search_sessions.sh')
|
|
70
|
-
if (typeof args
|
|
71
|
-
printHelp(1)
|
|
57
|
+
} else if (args.search) {
|
|
58
|
+
const history_search = path.resolve(__dirname, '..', 'utils', 'search_sessions.sh');
|
|
59
|
+
if (typeof args.search !== 'string') {
|
|
60
|
+
printHelp(1);
|
|
72
61
|
}
|
|
73
|
-
const res = await SH`${history_search} "${bashEscape(args
|
|
62
|
+
const res = await SH`${history_search} "${bashEscape(args.search)}"`.run();
|
|
74
63
|
console.log(res);
|
|
75
64
|
process.exit();
|
|
76
|
-
} else if (args
|
|
65
|
+
} else if (args.list) {
|
|
77
66
|
const list = path.resolve(__dirname, '..', 'utils', 'list_sessions.sh');
|
|
78
67
|
const res = await SH`${list}`.run();
|
|
79
68
|
console.log(res);
|
|
80
69
|
process.exit();
|
|
81
|
-
} else if (args
|
|
82
|
-
const format = path.resolve(__dirname, '..', 'utils', 'format_log.js')
|
|
83
|
-
if (typeof args
|
|
84
|
-
printHelp(1)
|
|
70
|
+
} else if (args.inspect) {
|
|
71
|
+
const format = path.resolve(__dirname, '..', 'utils', 'format_log.js');
|
|
72
|
+
if (typeof args.inspect !== 'string') {
|
|
73
|
+
printHelp(1);
|
|
85
74
|
}
|
|
86
75
|
try {
|
|
87
|
-
const res = await SH`${format} "${bashEscape(args
|
|
76
|
+
const res = await SH`${format} "${bashEscape(args.inspect)}"`.run();
|
|
88
77
|
console.log(res);
|
|
89
78
|
} catch (e) {
|
|
90
79
|
console.error(e);
|
|
91
80
|
process.exit(1);
|
|
92
81
|
}
|
|
93
|
-
} else if (args
|
|
94
|
-
let secret = args
|
|
82
|
+
} else if (args.ask) {
|
|
83
|
+
let secret = args.secret || '';
|
|
84
|
+
if (args.connect) {
|
|
85
|
+
// Remote mode: same as --connect
|
|
86
|
+
if (typeof pipedInput === 'string' && pipedInput.trim() !== '') {
|
|
87
|
+
// Piped input mode: use wsIO for one-shot actions
|
|
88
|
+
let action, input;
|
|
89
|
+
const trimmed = pipedInput.trim();
|
|
90
|
+
if (trimmed === 'user_info' || trimmed === 'user_reset') {
|
|
91
|
+
action = trimmed;
|
|
92
|
+
input = '';
|
|
93
|
+
} else {
|
|
94
|
+
action = 'user_request';
|
|
95
|
+
input = trimmed;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const response = await wsIO(args.connect, secret, action, input);
|
|
100
|
+
console.log(response.content);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error(`Error: ${e.message}`);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
// No piped input: interactive wsCli mode
|
|
107
|
+
wsCli(args.connect, secret);
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
// Local mode
|
|
111
|
+
const name = 'ask_dave';
|
|
112
|
+
const api = 'xai';
|
|
113
|
+
const contextWindow = 1900000;
|
|
114
|
+
const toolsetMode = 'auto';
|
|
115
|
+
/** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
|
|
116
|
+
const options = {
|
|
117
|
+
tools: []
|
|
118
|
+
};
|
|
119
|
+
options.tools.push({ type: 'web_search' });
|
|
120
|
+
options.tools.push({ type: 'x_search' });
|
|
121
|
+
options.model = args.model || 'grok-4-1-fast-reasoning';
|
|
122
|
+
options.temperature = 0.2;
|
|
123
|
+
options.reasoning = { effort: 'medium', summary: 'auto' };
|
|
124
|
+
|
|
125
|
+
const prompt = `
|
|
126
|
+
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.
|
|
127
|
+
`.trim();
|
|
128
|
+
|
|
129
|
+
const agent = new AgentManager({ name });
|
|
130
|
+
agent.setup({
|
|
131
|
+
prompt,
|
|
132
|
+
api,
|
|
133
|
+
options,
|
|
134
|
+
toolsetMode,
|
|
135
|
+
contextWindow
|
|
136
|
+
});
|
|
137
|
+
agent.addGenericToolcall('open_link');
|
|
138
|
+
agent.addGenericToolcall('send_email');
|
|
139
|
+
agent.addGenericToolcall('history_search');
|
|
140
|
+
|
|
141
|
+
const cliIntro = `
|
|
142
|
+
${name} (${options.model}).
|
|
143
|
+
- context: ${contextWindow}
|
|
144
|
+
`.trim();
|
|
145
|
+
const description = `Ask dave, he knows.`.trim();
|
|
146
|
+
|
|
147
|
+
// Support piped one-shot (like --connect), else interactive CLI
|
|
148
|
+
if (typeof pipedInput === 'string' && pipedInput.trim() !== '') {
|
|
149
|
+
try {
|
|
150
|
+
const response = await agent.directCall(pipedInput.trim());
|
|
151
|
+
console.log(response);
|
|
152
|
+
} catch (e) {
|
|
153
|
+
console.error(`Error: ${e.message}`);
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
await agent.start(undefined, undefined, cliIntro, name, description);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} else if (args.connect) {
|
|
161
|
+
// Pure --connect (no --ask): same logic
|
|
162
|
+
let secret = args.secret || '';
|
|
95
163
|
|
|
96
164
|
if (typeof pipedInput === 'string' && pipedInput.trim() !== '') {
|
|
97
165
|
// Piped input mode: use wsIO for one-shot actions
|
|
@@ -106,7 +174,7 @@ if (args['--clear']) {
|
|
|
106
174
|
}
|
|
107
175
|
|
|
108
176
|
try {
|
|
109
|
-
const response = await wsIO(args
|
|
177
|
+
const response = await wsIO(args.connect, secret, action, input);
|
|
110
178
|
console.log(response.content);
|
|
111
179
|
} catch (e) {
|
|
112
180
|
console.error(`Error: ${e.message}`);
|
|
@@ -114,63 +182,13 @@ if (args['--clear']) {
|
|
|
114
182
|
}
|
|
115
183
|
} else {
|
|
116
184
|
// No piped input: interactive wsCli mode
|
|
117
|
-
wsCli(args
|
|
185
|
+
wsCli(args.connect, secret);
|
|
118
186
|
}
|
|
119
|
-
} else if (args
|
|
120
|
-
const port = parseInt(args
|
|
121
|
-
const secret = args
|
|
187
|
+
} else if (args.code) {
|
|
188
|
+
const port = parseInt(args.code || '8080');
|
|
189
|
+
const secret = (args.secret || '').trim() || '123';
|
|
122
190
|
const server = path.resolve(__dirname, '..', 'examples', 'codeserver.sh');
|
|
123
|
-
|
|
124
|
-
|
|
191
|
+
const RES = await SH`${server} ${port} ${bashEscape(secret)}`.run();
|
|
192
|
+
console.log(RES);
|
|
125
193
|
process.exit(0);
|
|
126
|
-
} else if (args['--ask']) {
|
|
127
|
-
const name = 'ask_dave';
|
|
128
|
-
const api = 'xai';
|
|
129
|
-
let secret = '';
|
|
130
|
-
const contextWindow = 1900000;
|
|
131
|
-
const toolsetMode = 'auto';
|
|
132
|
-
/** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
|
|
133
|
-
const options = {
|
|
134
|
-
tools: []
|
|
135
|
-
};
|
|
136
|
-
options.tools.push({ type: 'web_search' });
|
|
137
|
-
options.tools.push({ type: 'x_search' });
|
|
138
|
-
options.model = args['--model'] || args.model || 'grok-4-1-fast-reasoning';
|
|
139
|
-
options.temperature = 0.2;
|
|
140
|
-
options.reasoning = { effort: 'medium', summary: 'auto' };
|
|
141
|
-
|
|
142
|
-
const prompt = `
|
|
143
|
-
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.
|
|
144
|
-
`.trim();
|
|
145
|
-
|
|
146
|
-
const agent = new AgentManager({ name, secret });
|
|
147
|
-
agent.setup({
|
|
148
|
-
prompt,
|
|
149
|
-
api,
|
|
150
|
-
options,
|
|
151
|
-
toolsetMode,
|
|
152
|
-
contextWindow
|
|
153
|
-
});
|
|
154
|
-
agent.addGenericToolcall('open_link');
|
|
155
|
-
agent.addGenericToolcall('send_email');
|
|
156
|
-
agent.addGenericToolcall('history_search');
|
|
157
|
-
|
|
158
|
-
const cliIntro = `
|
|
159
|
-
${name} ${options.model}.
|
|
160
|
-
- context: ${contextWindow}
|
|
161
|
-
`.trim();
|
|
162
|
-
const description = `Ask dave, he knows.`.trim();
|
|
163
|
-
|
|
164
|
-
// Support piped one-shot (like --connect), else interactive CLI
|
|
165
|
-
if (typeof pipedInput === 'string' && pipedInput.trim() !== '') {
|
|
166
|
-
try {
|
|
167
|
-
const response = await agent.directCall(pipedInput.trim());
|
|
168
|
-
console.log(response);
|
|
169
|
-
} catch (e) {
|
|
170
|
-
console.error(`Error: ${e.message}`);
|
|
171
|
-
process.exit(1);
|
|
172
|
-
}
|
|
173
|
-
} else {
|
|
174
|
-
await agent.start(undefined, undefined, cliIntro, name, description);
|
|
175
|
-
}
|
|
176
194
|
}
|