@j-o-r/hello-dave 0.0.2 → 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 +445 -160
- package/README.md.backup +269 -0
- package/README.md.bak +481 -0
- package/README.md.bak.1774780058 +338 -0
- package/README.md.bak2 +455 -0
- package/bin/dave.js +165 -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.bak.1774780058/ask_agent.js +114 -0
- package/examples.bak.1774780058/code_agent.js +149 -0
- package/examples.bak.1774780058/coderev_agent.js +72 -0
- package/examples.bak.1774780058/codeserver.sh +47 -0
- package/examples.bak.1774780058/daisy_agent.js +177 -0
- package/examples.bak.1774780058/docs_agent.js +119 -0
- package/{bin/hdAsk.js → examples.bak.1774780058/gpt_agent.js} +46 -40
- package/examples.bak.1774780058/grok_agent.js +98 -0
- package/examples.bak.1774780058/memory_agent.js +112 -0
- package/examples.bak.1774780058/npm_agent.js +175 -0
- package/examples.bak.1774780058/prompt_agent.js +112 -0
- package/examples.bak.1774780058/readme_agent.js +144 -0
- package/examples.bak.1774780058/spawn_agent.js +263 -0
- package/examples.bak.1774780058/test_agent.js +162 -0
- package/examples.bak.1774780058/todo_agent.js +138 -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 +492 -0
- package/lib/API/x.ai/text.js +1 -1
- package/lib/AgentClient.js +13 -6
- package/lib/AgentManager.js +80 -10
- package/lib/AgentServer.js +50 -22
- package/lib/Cli.js +7 -1
- package/lib/Prompt.js +4 -2
- package/lib/ToolSet.js +2 -1
- package/lib/genericToolset.js +258 -88
- package/lib/genericToolset.js.bak_syntax +402 -0
- package/lib/index.js +4 -2
- package/lib/wsCli.js +256 -0
- package/lib/wsIO.js +96 -0
- package/package.json +26 -21
- 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/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 +25 -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/utils/syntax_check.sh +61 -0
- package/utils/test.sh +46 -0
- package/bin/hdClear.js +0 -13
- package/bin/hdCode.js +0 -115
- 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.js +0 -127
- package/examples/gpt_code.js +0 -125
- package/examples/gpt_note_keeping.js +0 -117
- package/examples/grok.js +0 -119
- package/examples/grok_code.js +0 -114
- package/examples/grok_note_keeping.js +0 -111
- package/module.md +0 -189
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Delete entire agent directories (including logs/, records/, and sessions/) that contain all three.
|
|
3
|
+
# Usage: ./utils/clear_sessions.sh
|
|
4
|
+
# Lists targets (unique/sorted), then deletes them without confirmation.
|
|
5
|
+
|
|
6
|
+
set -uo pipefail
|
|
7
|
+
|
|
8
|
+
CACHE_BASE=".cache"
|
|
9
|
+
|
|
10
|
+
echo "🔍 Scanning for agent directories containing logs/, records/, and sessions/..."
|
|
11
|
+
echo "=================================================================="
|
|
12
|
+
|
|
13
|
+
declare -a agent_dirs=()
|
|
14
|
+
declare -a targets=()
|
|
15
|
+
|
|
16
|
+
# Load all candidate agent dirs into array (null-separated, sorted)
|
|
17
|
+
mapfile -t -d '' agent_dirs < <(find "$CACHE_BASE" -mindepth 2 -maxdepth 2 -type d -print0 2>/dev/null | sort -z)
|
|
18
|
+
|
|
19
|
+
echo "📊 Found ${#agent_dirs[@]} candidate agent directories. Filtering..."
|
|
20
|
+
|
|
21
|
+
for agent_dir in "${agent_dirs[@]}"; do
|
|
22
|
+
if [[ -n "$agent_dir" && -d "$agent_dir/logs" && -d "$agent_dir/records" && -d "$agent_dir/sessions" ]]; then
|
|
23
|
+
app_name="$(basename "$(dirname "$agent_dir")")"
|
|
24
|
+
prompt_name="$(basename "$agent_dir")"
|
|
25
|
+
targets+=("$agent_dir")
|
|
26
|
+
echo "📁 Target: $app_name/$prompt_name/ (will be DELETED entirely)"
|
|
27
|
+
fi
|
|
28
|
+
done
|
|
29
|
+
|
|
30
|
+
target_count=${#targets[@]}
|
|
31
|
+
|
|
32
|
+
echo ""
|
|
33
|
+
if [ "$target_count" -eq 0 ]; then
|
|
34
|
+
echo "✅ No matching directories found."
|
|
35
|
+
exit 0
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
echo "⚠️ Will DELETE ENTIRELY $target_count directories."
|
|
39
|
+
echo " (logs/, records/, sessions/ and all other contents gone.)"
|
|
40
|
+
echo ""
|
|
41
|
+
|
|
42
|
+
# No confirmation, proceed directly
|
|
43
|
+
|
|
44
|
+
cleared=0
|
|
45
|
+
for agent_dir in "${targets[@]}"; do
|
|
46
|
+
echo "🧹 Deleting $agent_dir ..."
|
|
47
|
+
rm -rf "$agent_dir" 2>/dev/null || true
|
|
48
|
+
# Verify dir is gone
|
|
49
|
+
if [[ ! -d "$agent_dir" ]]; then
|
|
50
|
+
cleared=$((cleared + 1))
|
|
51
|
+
fi
|
|
52
|
+
done
|
|
53
|
+
|
|
54
|
+
echo "✅ Deleted $cleared/$target_count directories."
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env -S node
|
|
2
|
+
// Formatted output of hello-dave cache files [*.ndjson]
|
|
2
3
|
import { CacheSync } from "@j-o-r/cache";
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { parseArgs, readIn } from '@j-o-r/sh';
|
|
@@ -25,4 +26,8 @@ console.log({ folder, name, ext });
|
|
|
25
26
|
|
|
26
27
|
const c = new CacheSync(folder, false, ext);
|
|
27
28
|
const content = c.read(name);
|
|
29
|
+
if (!content) {
|
|
30
|
+
console.error(`Not Found: ${filePath}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
28
33
|
console.log(JSON.stringify(content, null, ' '));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# List unique sessions (once) per agent across all apps hierarchically, with latest mod timestamp.
|
|
3
|
+
# Strips trailing _[0-9]+, converts _+ to spaces, trims. Picks newest mtime per base name.
|
|
4
|
+
# FIXED: Reset assoc array per agent; skip empty agents.
|
|
5
|
+
|
|
6
|
+
CACHE_BASE=".cache"
|
|
7
|
+
shopt -s nullglob
|
|
8
|
+
|
|
9
|
+
for app_dir in "$CACHE_BASE"/*/; do
|
|
10
|
+
if [[ ! -d "$app_dir" ]]; then
|
|
11
|
+
continue
|
|
12
|
+
fi
|
|
13
|
+
app_name=$(basename "$app_dir")
|
|
14
|
+
echo "$app_name:"
|
|
15
|
+
has_sessions=false
|
|
16
|
+
for sessions_dir in "$app_dir"/*/sessions/; do
|
|
17
|
+
if [[ ! -d "$sessions_dir" ]]; then
|
|
18
|
+
continue
|
|
19
|
+
fi
|
|
20
|
+
agent=$(basename "$(dirname "$sessions_dir")")
|
|
21
|
+
|
|
22
|
+
unset timestamps || true
|
|
23
|
+
declare -A timestamps
|
|
24
|
+
for f in "$sessions_dir"/*.ndjson; do
|
|
25
|
+
if [[ -f "$f" ]]; then
|
|
26
|
+
name=$(basename "$f" .ndjson)
|
|
27
|
+
base=$(echo "$name" | sed 's/_[0-9]\+$//' | sed 's/_\+/ /g' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
|
28
|
+
mtime=$(date -r "$f" '+%Y-%m-%d %H:%M')
|
|
29
|
+
if [[ -z "${timestamps[$base]}" || "$mtime" > "${timestamps[$base]}" ]]; then
|
|
30
|
+
timestamps[$base]="$mtime"
|
|
31
|
+
fi
|
|
32
|
+
fi
|
|
33
|
+
done
|
|
34
|
+
|
|
35
|
+
if [[ ${#timestamps[@]} -gt 0 ]]; then
|
|
36
|
+
echo " $agent:"
|
|
37
|
+
for base in "${!timestamps[@]}"; do
|
|
38
|
+
echo " - $base ... (${timestamps[$base]})"
|
|
39
|
+
done | sort
|
|
40
|
+
has_sessions=true
|
|
41
|
+
fi
|
|
42
|
+
done
|
|
43
|
+
if [[ "$has_sessions" == true ]]; then
|
|
44
|
+
echo
|
|
45
|
+
fi
|
|
46
|
+
done
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# No set -e to avoid unexpected exits; use explicit checks
|
|
4
|
+
set -uo pipefail
|
|
5
|
+
|
|
6
|
+
if [ $# -eq 0 ]; then
|
|
7
|
+
echo "Usage: $0 <search_query_or_regex>"
|
|
8
|
+
echo " Searches filenames & content in all .cache/[app]/[prompt]/sessions/*.ndjson"
|
|
9
|
+
echo " Shows matching sessions/files with context (grep -i -C5, line nums)."
|
|
10
|
+
echo " Quote multi-word/regex: $0 \"package.json\" or $0 \"(hdTodo|todo)\""
|
|
11
|
+
exit 1
|
|
12
|
+
fi
|
|
13
|
+
|
|
14
|
+
QUERY="$1"
|
|
15
|
+
echo "🔍 Searching sessions for (case-insensitive regex): '$QUERY'"
|
|
16
|
+
echo "=================================================================="
|
|
17
|
+
echo ""
|
|
18
|
+
|
|
19
|
+
total_matches=0
|
|
20
|
+
session_count=0
|
|
21
|
+
|
|
22
|
+
# Process substitution avoids subshell
|
|
23
|
+
while IFS= read -r -d '' sess_dir; do
|
|
24
|
+
[ -d "$sess_dir" ] || continue
|
|
25
|
+
|
|
26
|
+
session_count=$((session_count + 1))
|
|
27
|
+
app_name=$(basename "$(dirname "$(dirname "$sess_dir")")")
|
|
28
|
+
prompt_name=$(basename "$(dirname "$sess_dir")")
|
|
29
|
+
mod_time=$(stat -c %Y "$sess_dir" 2>/dev/null || echo 0)
|
|
30
|
+
date_str=$(date -d "@$mod_time" '+%Y-%m-%d %H:%M' 2>/dev/null || echo "unknown")
|
|
31
|
+
|
|
32
|
+
echo "📁 $app_name/$prompt_name ($date_str)"
|
|
33
|
+
echo " $sess_dir"
|
|
34
|
+
echo " -------------------------------------------------"
|
|
35
|
+
|
|
36
|
+
dir_matches=0
|
|
37
|
+
shopt -s nullglob
|
|
38
|
+
for ndjson_file in "$sess_dir"/*.ndjson; do
|
|
39
|
+
[ -f "$ndjson_file" ] || continue
|
|
40
|
+
|
|
41
|
+
fname_base=$(basename "$ndjson_file" .ndjson)
|
|
42
|
+
fname=$(echo "$fname_base" | sed 's/__/ /g' | sed 's/_[0-9]*$//' | fold -w70 | head -1)
|
|
43
|
+
fname_short="${fname:0:70}..."
|
|
44
|
+
|
|
45
|
+
# Filename match
|
|
46
|
+
if echo "$ndjson_file" | grep -qiE "$QUERY" || echo "$fname_base" | grep -qiE "$QUERY"; then
|
|
47
|
+
echo " 💾 FILENAME: $fname_short"
|
|
48
|
+
dir_matches=$((dir_matches + 1))
|
|
49
|
+
total_matches=$((total_matches + 1))
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# Content matches
|
|
53
|
+
content_matches=$(grep -iHn -C 5 -E -m 20 "$QUERY" "$ndjson_file" 2>/dev/null || true)
|
|
54
|
+
if [ -n "$content_matches" ]; then
|
|
55
|
+
echo " 📄 CONTENT in $fname_short:"
|
|
56
|
+
echo "$content_matches"
|
|
57
|
+
echo ""
|
|
58
|
+
dir_matches=$((dir_matches + 1))
|
|
59
|
+
total_matches=$((total_matches + 1))
|
|
60
|
+
fi
|
|
61
|
+
done
|
|
62
|
+
shopt -u nullglob
|
|
63
|
+
|
|
64
|
+
if [ $dir_matches -eq 0 ]; then
|
|
65
|
+
echo " (no matches)"
|
|
66
|
+
fi
|
|
67
|
+
echo ""
|
|
68
|
+
done < <(find .cache -mindepth 3 -maxdepth 5 -type d -name "sessions" -print0 2>/dev/null | sort -rz | head -30)
|
|
69
|
+
|
|
70
|
+
echo "✅ $total_matches matches across $session_count sessions."
|
|
71
|
+
if [ $total_matches -eq 0 ]; then
|
|
72
|
+
echo "💡 Tip: Broader query? e.g. 'todo', regex '(package|bin)' or check spelling."
|
|
73
|
+
fi
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# utils/syntax_check.sh - Multi-language syntax validation
|
|
3
|
+
# Usage: ./utils/syntax_check.sh <file> [--fix|--verbose]
|
|
4
|
+
# Detects lang from ext/shebang, runs checker. Returns 0=OK, 1=error.
|
|
5
|
+
# Integrates with write_file tool retries.
|
|
6
|
+
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
|
|
9
|
+
FILE="${1?Error: Provide file path}"
|
|
10
|
+
VERBOSE="${2:-}"
|
|
11
|
+
FIX="${VERBOSE:0:4}==--fix"
|
|
12
|
+
|
|
13
|
+
[ ! -f "$FILE" ] && { echo "❌ File not found: $FILE"; exit 1; }
|
|
14
|
+
|
|
15
|
+
# Detect language
|
|
16
|
+
EXT="${FILE##*.}"
|
|
17
|
+
SHEBANG=$(head -n1 "$FILE" 2>/dev/null | cut -d' ' -f1)
|
|
18
|
+
|
|
19
|
+
detect_lang() {
|
|
20
|
+
case "$SHEBANG" in
|
|
21
|
+
*node|*/node|*js) echo "js" ;;
|
|
22
|
+
*python*|*/python|*py) echo "py" ;;
|
|
23
|
+
*bash|*sh) echo "bash" ;;
|
|
24
|
+
*/bin/sh|*/bin/bash) echo "bash" ;;
|
|
25
|
+
*) case "$EXT" in
|
|
26
|
+
js|jsx|mjs) echo "js" ;;
|
|
27
|
+
py) echo "py" ;;
|
|
28
|
+
sh|bash) echo "bash" ;;
|
|
29
|
+
json) echo "json" ;;
|
|
30
|
+
*) echo "unknown" ;;
|
|
31
|
+
esac
|
|
32
|
+
esac
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
LANG=$(detect_lang)
|
|
36
|
+
echo "🔍 Validating $FILE (lang: $LANG)"
|
|
37
|
+
|
|
38
|
+
case "$LANG" in
|
|
39
|
+
js)
|
|
40
|
+
node --check "$FILE" && echo "✅ JS OK" || { echo "❌ JS syntax error"; exit 1; }
|
|
41
|
+
;;
|
|
42
|
+
py)
|
|
43
|
+
python3 -m py_compile "$FILE" && echo "✅ Python OK" || { echo "❌ Python syntax error"; exit 1; }
|
|
44
|
+
;;
|
|
45
|
+
bash|sh)
|
|
46
|
+
bash -n "$FILE" && echo "✅ Bash OK" || { echo "❌ Bash syntax error"; exit 1; }
|
|
47
|
+
# Optional: shellcheck if installed
|
|
48
|
+
if command -v shellcheck >/dev/null; then
|
|
49
|
+
shellcheck "$FILE" || echo "⚠️ Shellcheck warnings"
|
|
50
|
+
fi
|
|
51
|
+
;;
|
|
52
|
+
json)
|
|
53
|
+
node -e "JSON.parse(require('fs').readFileSync(process.argv[1], 'utf8'))" "$FILE" && echo "✅ JSON OK" || { echo "❌ JSON invalid"; exit 1; }
|
|
54
|
+
;;
|
|
55
|
+
unknown)
|
|
56
|
+
echo "⚠️ Unknown lang for $EXT / shebang: $SHEBANG"
|
|
57
|
+
exit 0 # Non-fatal
|
|
58
|
+
;;
|
|
59
|
+
esac
|
|
60
|
+
|
|
61
|
+
echo "✅ Syntax validation passed for $FILE"
|
package/utils/test.sh
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
TEST_DIR="${1:-scenarios}"
|
|
5
|
+
echo "=== TestDave: Running all tests in $TEST_DIR/ ==="
|
|
6
|
+
|
|
7
|
+
shopt -s nullglob
|
|
8
|
+
TEST_FILES=("$TEST_DIR"/*.test.js)
|
|
9
|
+
|
|
10
|
+
if [ ${#TEST_FILES[@]} -eq 0 ]; then
|
|
11
|
+
echo "No *.test.js files found in $TEST_DIR/"
|
|
12
|
+
exit 0
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
echo "Found ${#TEST_FILES[@]} test files."
|
|
16
|
+
|
|
17
|
+
TOTAL=${#TEST_FILES[@]}
|
|
18
|
+
PASSED=0
|
|
19
|
+
FAILED=()
|
|
20
|
+
|
|
21
|
+
for test_file in "${TEST_FILES[@]}"; do
|
|
22
|
+
echo ""
|
|
23
|
+
echo "=== $test_file ==="
|
|
24
|
+
RC=$(timeout 60s "$test_file");
|
|
25
|
+
XT=$?
|
|
26
|
+
echo "$RC";
|
|
27
|
+
if [ "$XT" -eq 0 ]; then
|
|
28
|
+
echo "✅ PASS"
|
|
29
|
+
((PASSED = PASSED + 1))
|
|
30
|
+
else
|
|
31
|
+
echo "❌ FAIL (exit code $XT)"
|
|
32
|
+
FAILED+=("$test_file")
|
|
33
|
+
fi
|
|
34
|
+
done
|
|
35
|
+
|
|
36
|
+
echo ""
|
|
37
|
+
echo "=== SUMMARY ==="
|
|
38
|
+
echo "Total: $TOTAL"
|
|
39
|
+
echo "Passed: $PASSED"
|
|
40
|
+
echo "Failed: ${#FAILED[@]}"
|
|
41
|
+
if [ ${#FAILED[@]} -gt 0 ]; then
|
|
42
|
+
echo "Failed tests:"
|
|
43
|
+
for f in "${FAILED[@]}"; do echo " $f"; done
|
|
44
|
+
exit 1
|
|
45
|
+
fi
|
|
46
|
+
echo "🎉 All tests passed!"
|
package/bin/hdClear.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node
|
|
2
|
-
|
|
3
|
-
// clear .cache/hello-dave if it exsists
|
|
4
|
-
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { SH } from '@j-o-r/sh';
|
|
7
|
-
|
|
8
|
-
const folder = path.resolve('.cache', 'hello-dave');
|
|
9
|
-
const res = await SH`[ -d "${folder}" ] && echo "yes" || echo "no"`.run();
|
|
10
|
-
if (res === 'yes') {
|
|
11
|
-
console.log(`rm -fr ${folder}/*`);
|
|
12
|
-
await SH`rm -fr ${folder}/*`.run()
|
|
13
|
-
}
|
package/bin/hdCode.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import AgentManager from '../lib/AgentManager.js';
|
|
3
|
-
import { parseArgs, readIn } from '@j-o-r/sh';
|
|
4
|
-
|
|
5
|
-
const name = 'hdCode';
|
|
6
|
-
const api = 'grok';
|
|
7
|
-
|
|
8
|
-
const input = await readIn();
|
|
9
|
-
const args = parseArgs();
|
|
10
|
-
const help = args['help'] || false;
|
|
11
|
-
const connect = args['connect'] ? args['connect'] : undefined;
|
|
12
|
-
const serve = args['serve'] ? parseInt(args['serve']) : undefined;
|
|
13
|
-
|
|
14
|
-
/** @type {import('lib/API/x.ai/text.js').XOptions} */
|
|
15
|
-
const options = {}
|
|
16
|
-
// Set properties only if provided via command line (except model which has default)
|
|
17
|
-
if (args['model'] || true) { // model gets default value
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
options.model = args['model'] || 'grok-code-fast-1';
|
|
20
|
-
}
|
|
21
|
-
if (args['temperature']) {
|
|
22
|
-
options.temperature = parseFloat(args['temperature']);
|
|
23
|
-
}
|
|
24
|
-
if (args['tokens']) {
|
|
25
|
-
options.max_completion_tokens = parseInt(args['tokens']);
|
|
26
|
-
}
|
|
27
|
-
if (args['top_p']) {
|
|
28
|
-
options.top_p = parseFloat(args['top_p']);
|
|
29
|
-
}
|
|
30
|
-
options.search_parameters = { mode: 'auto' }
|
|
31
|
-
const reasoning = args['reasoning'] ? args['reasoning'] : null;
|
|
32
|
-
if (reasoning) {
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
options.reasoning_effort = reasoning
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const toolsetMode = 'auto';
|
|
38
|
-
const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
|
|
39
|
-
|
|
40
|
-
function printHelp() {
|
|
41
|
-
console.log(`
|
|
42
|
-
'${name} --help' You are looking at it.
|
|
43
|
-
'
|
|
44
|
-
OPTIONS:
|
|
45
|
-
--tokens [number]: max generated tokens
|
|
46
|
-
--context [number] : truncate message history to context-windows size default 130000
|
|
47
|
-
--temperature [float] : -2 / +2
|
|
48
|
-
--model [grok-4|grok-3|grok-3-mini|grok-3-mini-fast|grok-code-fast-1]
|
|
49
|
-
--top_p [float]: number > 0, 0.1 means no top_p
|
|
50
|
-
--reasoning [low|high]
|
|
51
|
-
--tools [javascript,bash,nushell,ssh] comma seperated list
|
|
52
|
-
e.g.
|
|
53
|
-
grok.js --model grok-3-mini --tokens 4000 --context 10000
|
|
54
|
-
|
|
55
|
-
`);
|
|
56
|
-
process.exit()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (help) {
|
|
60
|
-
printHelp();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const agent = new AgentManager({ name });
|
|
64
|
-
const sys = (await agent.environment()).system;
|
|
65
|
-
const prompt = `
|
|
66
|
-
You are a coding assistant specializing in Bash and JavaScript (ESM/ESNext), with support for other languages. Assist by executing, reading, creating, querying, explaining, or helping with code. Use tools like 'execute_bash_script' for code execution and for writing and reading files, stay in the current working folder. Provide clear, step-by-step responses, examples, and ensure safety compliance.
|
|
67
|
-
---env
|
|
68
|
-
${sys}
|
|
69
|
-
---
|
|
70
|
-
`.trim();
|
|
71
|
-
agent.setup({
|
|
72
|
-
prompt,
|
|
73
|
-
api,
|
|
74
|
-
options,
|
|
75
|
-
toolsetMode,
|
|
76
|
-
contextWindow
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const toolset = agent.getToolset();
|
|
80
|
-
if (toolset) {
|
|
81
|
-
const addTools = (args['tools']) ? args['tools'].split(',') : ['bash'];
|
|
82
|
-
if (addTools.includes('javascript')) {
|
|
83
|
-
agent.addGenericToolcall('javascript_interpreter');
|
|
84
|
-
}
|
|
85
|
-
if (addTools.includes('bash')) {
|
|
86
|
-
agent.addGenericToolcall('execute_bash_script');
|
|
87
|
-
}
|
|
88
|
-
if (addTools.includes('nushell')) {
|
|
89
|
-
agent.addGenericToolcall('execute_nushell_script');
|
|
90
|
-
}
|
|
91
|
-
if (addTools.includes('ssh')) {
|
|
92
|
-
agent.addGenericToolcall('execute_remote_script');
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const cliIntro = `
|
|
96
|
-
${name} ${options.model}.
|
|
97
|
-
- search ${options.search_parameters.mode}
|
|
98
|
-
- context: ${contextWindow}
|
|
99
|
-
`.trim();
|
|
100
|
-
const description = `
|
|
101
|
-
Handles execution, reading, creation, querying, explaining and code help, with safety and folder restrictions.
|
|
102
|
-
`.trim();
|
|
103
|
-
|
|
104
|
-
if (input === '' && serve) {
|
|
105
|
-
agent.enableServer('code', description, serve);
|
|
106
|
-
}
|
|
107
|
-
if (input !== '') {
|
|
108
|
-
// Direct input output
|
|
109
|
-
const res = await agent.directCall(input);
|
|
110
|
-
console.log(res);
|
|
111
|
-
} else if (connect) {
|
|
112
|
-
agent.attach('code', description, connect)
|
|
113
|
-
} else {
|
|
114
|
-
agent.startCli(cliIntro);
|
|
115
|
-
}
|
package/bin/hdConnect.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node
|
|
2
|
-
/*
|
|
3
|
-
* Websocket client for a hello-dave server
|
|
4
|
-
*/
|
|
5
|
-
import cli from '@j-o-r/cli';
|
|
6
|
-
import { WebSocketClient } from "@j-o-r/apiserver";
|
|
7
|
-
import { parseArgs, SH } from '@j-o-r/sh';
|
|
8
|
-
const args = parseArgs();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Copy text to the clipboard
|
|
13
|
-
* @param {string} text
|
|
14
|
-
* @retruns {Promise<string>}
|
|
15
|
-
*/
|
|
16
|
-
const copyToClipboard = async (text) => {
|
|
17
|
-
if (typeof text !== 'string') return;
|
|
18
|
-
if (text === '') text = ' ';
|
|
19
|
-
const prams = [
|
|
20
|
-
'-selection',
|
|
21
|
-
'clipboard'
|
|
22
|
-
]
|
|
23
|
-
return SH`xclip ${prams}`.options({ stdio: 'inherit' }).run(text);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const HELP = () => {
|
|
27
|
-
console.log(
|
|
28
|
-
`
|
|
29
|
-
hdConnect [url]
|
|
30
|
-
|
|
31
|
-
usage:
|
|
32
|
-
npx hdConnect ws:/127.0.0.1:8000/ws
|
|
33
|
-
`.trim()
|
|
34
|
-
)
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (args._.length !== 1) {
|
|
39
|
-
HELP();
|
|
40
|
-
}
|
|
41
|
-
const connect = args._[0];
|
|
42
|
-
let busy = false;
|
|
43
|
-
let lastMessage = '';
|
|
44
|
-
const pendingRequests = new Map(); // key: msg_id (or `${conn_id}:${msg_id}` if conn_id is available), value: {resolve, reject, timeout} 11:06:22 [32/1290]
|
|
45
|
-
|
|
46
|
-
const ws = new WebSocketClient(connect);
|
|
47
|
-
ws.onopen = () => {
|
|
48
|
-
ws.send(JSON.stringify({
|
|
49
|
-
action: 'user_introduction',
|
|
50
|
-
content: '',
|
|
51
|
-
id: new Date().getTime()
|
|
52
|
-
}));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @param {MessageEvent} m
|
|
56
|
-
*/
|
|
57
|
-
ws.onmessage = (m) => {
|
|
58
|
-
try {
|
|
59
|
-
const data = JSON.parse(m.data);
|
|
60
|
-
const msgId = data.id; // Assume response has the same 'id' as the request
|
|
61
|
-
if (msgId && pendingRequests.has(msgId)) {
|
|
62
|
-
const { resolve, timeout } = pendingRequests.get(msgId);
|
|
63
|
-
clearTimeout(timeout); // Cancel the timeout
|
|
64
|
-
pendingRequests.delete(msgId);
|
|
65
|
-
resolve(data); // Resolve the promise with the response data
|
|
66
|
-
}
|
|
67
|
-
} catch (e) {
|
|
68
|
-
console.error('Error parsing WebSocket message:', e);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
ws.onclose = () => {
|
|
72
|
-
console.log('Lost connection');
|
|
73
|
-
// Optionally, reject all pending requests here
|
|
74
|
-
for (const [id, { reject }] of pendingRequests) {
|
|
75
|
-
reject(new Error('Connection closed'));
|
|
76
|
-
pendingRequests.delete(id);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
ws.onerror = (e) => {
|
|
80
|
-
console.error('WebSocket error:', e);
|
|
81
|
-
// Optionally, reject all pending requests on error
|
|
82
|
-
for (const [id, { reject }] of pendingRequests) {
|
|
83
|
-
reject(e);
|
|
84
|
-
pendingRequests.delete(id);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
cli.registerKeyMappings([
|
|
90
|
-
{ // Clear the screen
|
|
91
|
-
// ALT - c
|
|
92
|
-
name: 'c', ctrl: false, meta: true, shift: false, handler: async () => {
|
|
93
|
-
if (!busy) {
|
|
94
|
-
cli.clear();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
{ // reset the session, empty the context from the prompt
|
|
99
|
-
// ALT - r
|
|
100
|
-
name: 'r', ctrl: false, meta: true, shift: false, handler: async () => {
|
|
101
|
-
if (!busy) {
|
|
102
|
-
await sendMessage({
|
|
103
|
-
action: 'user_reset',
|
|
104
|
-
content: ''
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
{ // load a previous ssession
|
|
110
|
-
// ALT - s
|
|
111
|
-
name: 's', ctrl: false, meta: true, shift: false, handler: async () => {
|
|
112
|
-
if (!busy) {
|
|
113
|
-
await sendMessage({
|
|
114
|
-
action: 'user_sessionlist',
|
|
115
|
-
content: '',
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
{ // Request server info
|
|
122
|
-
// ALT - i
|
|
123
|
-
name: 'i', ctrl: false, meta: true, shift: false, handler: async () => {
|
|
124
|
-
if (!busy) {
|
|
125
|
-
await sendMessage({
|
|
126
|
-
action: 'user_info',
|
|
127
|
-
content: '',
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
{ // Copy last message to clipboard
|
|
133
|
-
name: 'm', ctrl: false, meta: true, shift: false, handler: async () => {
|
|
134
|
-
if (!busy) {
|
|
135
|
-
const r = await copyToClipboard(lastMessage);
|
|
136
|
-
cli.focus('util');
|
|
137
|
-
cli.write('copied');
|
|
138
|
-
cli.focus('user', true);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
{ // Show help /keys
|
|
143
|
-
name: 'k', ctrl: true, meta: false, shift: false, handler: async () => {
|
|
144
|
-
// cli.focus('util')
|
|
145
|
-
// cli.write(HELP)
|
|
146
|
-
// cli.focus('user', true);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
]);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const sendMessage = async (m) => {
|
|
153
|
-
const id = new Date().getTime(); // Unique ID for the request
|
|
154
|
-
m.id = id;
|
|
155
|
-
busy = true;
|
|
156
|
-
ws.send(JSON.stringify(m));
|
|
157
|
-
|
|
158
|
-
// Create a promise and store it in pendingRequests
|
|
159
|
-
const promise = new Promise((resolve, reject) => {
|
|
160
|
-
const timeout = setTimeout(() => {
|
|
161
|
-
pendingRequests.delete(id);
|
|
162
|
-
reject(new Error('Request timeout')); // Timeout after 10 seconds (adjust as needed)
|
|
163
|
-
}, 1000 * 60 * 60 * 12); // 12 hours
|
|
164
|
-
pendingRequests.set(id, { resolve, reject, timeout });
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
cli.startSpinner(); // Start spinner while waiting
|
|
168
|
-
try {
|
|
169
|
-
const response = await promise; // Wait for the response
|
|
170
|
-
// Process the response here (e.g., log it or display it)
|
|
171
|
-
// console.log('Response received:', response);
|
|
172
|
-
if (response.action === 'server_response') {
|
|
173
|
-
cli.focus('assistant');
|
|
174
|
-
cli.write(response.content);
|
|
175
|
-
lastMessage = response.content;
|
|
176
|
-
}
|
|
177
|
-
if (response.action === 'server_info') {
|
|
178
|
-
cli.focus('util');
|
|
179
|
-
cli.write(response.content);
|
|
180
|
-
}
|
|
181
|
-
if (response.action === 'server_reset') {
|
|
182
|
-
cli.clear();
|
|
183
|
-
}
|
|
184
|
-
if (response.action === 'server_sessionlist') {
|
|
185
|
-
// Select a session to load
|
|
186
|
-
const list = response.content;
|
|
187
|
-
const selected = await cli.select('Select your session: ', list);
|
|
188
|
-
if (selected && selected !== 'NONE') {
|
|
189
|
-
return sendMessage({ action: 'user_loadsession', content: selected });
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (response.action === 'server_sessionloaded') {
|
|
193
|
-
// Putput the selected session messages
|
|
194
|
-
cli.clear();
|
|
195
|
-
const messages = response.content;
|
|
196
|
-
messages.forEach((msg) => {
|
|
197
|
-
cli.focus(msg.role);
|
|
198
|
-
cli.write(msg.content);
|
|
199
|
-
lastMessage = msg.content;
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
} catch (e) {
|
|
203
|
-
console.error('Error waiting for response:', e);
|
|
204
|
-
// Handle error (e.g., show error message to user)
|
|
205
|
-
} finally {
|
|
206
|
-
busy = false;
|
|
207
|
-
cli.stopSpinner(); // Stop spinner
|
|
208
|
-
cli.focus('user', true); // Give focus back to user input
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// @ts-ignore
|
|
214
|
-
cli.inputHandler = async (s) => {
|
|
215
|
-
if (!s || s.trim() === '') {
|
|
216
|
-
// busy = false;
|
|
217
|
-
// cli.focus('user', true); // Give focus back to user input
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const m = {
|
|
221
|
-
action: 'user_request',
|
|
222
|
-
content: s
|
|
223
|
-
}
|
|
224
|
-
await sendMessage(m);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
cli.focus('log');
|
|
228
|
-
cli.write('CTRL - d exit');
|
|
229
|
-
cli.write('CTRL - r clear screen / reset');
|
|
230
|
-
cli.focus('user', true);
|