Skip to content

Commit 4ac72b5

Browse files
authored
feat: support check-related features (#162)
We can run `argc check` to ensure that everything is ready (environment variables, Node/Python dependencies, mcp-bridge server)
1 parent 50ee642 commit 4ac72b5

File tree

5 files changed

+189
-5
lines changed

5 files changed

+189
-5
lines changed

Argcfile.sh

+88-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
# @meta dotenv
5+
46
BIN_DIR=bin
57
TMP_DIR="cache/__tmp__"
68
VENV_DIR=".venv"
@@ -231,8 +233,8 @@ build-bin@agent() {
231233
found=false
232234
for item in "${LANG_CMDS[@]}"; do
233235
lang="${item%:*}"
234-
agent_tools_file="$agent_dir/tools.$lang"
235-
if [[ -f "$agent_tools_file" ]]; then
236+
agent_tools_path="$agent_dir/tools.$lang"
237+
if [[ -f "$agent_tools_path" ]]; then
236238
found=true
237239
if _is_win; then
238240
bin_file="$BIN_DIR/$name.cmd"
@@ -293,8 +295,8 @@ build-declarations@agent() {
293295
tools_json_data=""
294296
for item in "${LANG_CMDS[@]}"; do
295297
lang="${item%:*}"
296-
agent_tools_file="$agent_dir/tools.$lang"
297-
if [[ -f "$agent_tools_file" ]]; then
298+
agent_tools_path="$agent_dir/tools.$lang"
299+
if [[ -f "$agent_tools_path" ]]; then
298300
agent_json_data="$(generate-declarations@agent "$name")" || {
299301
ok=false
300302
build_failed_agents+=("$name")
@@ -359,6 +361,64 @@ generate-declarations@agent() {
359361
fi
360362
}
361363

364+
# @cmd Check environment variables, Node/Python dependencies, MCP-Bridge-Server status
365+
check() {
366+
argc check@tool
367+
argc check@agent
368+
argc mcp check
369+
}
370+
371+
# @cmd Check dependencies and environment variables for a specific tool
372+
# @alias tool:check
373+
# @arg tools*[`_choice_tool`] The tool name
374+
check@tool() {
375+
if [[ "${#argc_tools[@]}" -gt 0 ]]; then
376+
tool_names=("${argc_tools[@]}")
377+
else
378+
tool_names=($(cat tools.txt | grep -v '^#'))
379+
fi
380+
for name in "${tool_names[@]}"; do
381+
tool_path="tools/$name"
382+
echo "Check $tool_path"
383+
if [[ -f "$tool_path" ]]; then
384+
_check_bin "${name%.*}"
385+
_check_envs "$tool_path"
386+
./scripts/check-deps.sh "$tool_path"
387+
else
388+
echo "✗ not found tool file"
389+
fi
390+
done
391+
}
392+
393+
# @cmd Check dependencies and environment variables for a specific agent
394+
# @alias agent:check
395+
# @arg agents*[`_choice_agent`] The agent name
396+
check@agent() {
397+
if [[ "${#argc_agents[@]}" -gt 0 ]]; then
398+
agent_names=("${argc_agents[@]}")
399+
else
400+
agent_names=($(cat agents.txt | grep -v '^#'))
401+
fi
402+
for name in "${agent_names[@]}"; do
403+
agent_dir="agents/$name"
404+
echo "Check $agent_dir"
405+
if [[ -d "$agent_dir" ]]; then
406+
for item in "${LANG_CMDS[@]}"; do
407+
lang="${item%:*}"
408+
agent_tools_path="$agent_dir/tools.$lang"
409+
if [[ -f "$agent_tools_path" ]]; then
410+
_check_bin "$name"
411+
_check_envs "$agent_tools_path"
412+
./scripts/check-deps.sh "$agent_tools_path"
413+
break
414+
fi
415+
done
416+
else
417+
echo "✗ not found agent dir"
418+
fi
419+
done
420+
}
421+
362422
# @cmd List tools which can be put into functions.txt
363423
# @alias tool:list
364424
# Examples:
@@ -602,6 +662,30 @@ python "__ROOT_DIR__/scripts/run-__KIND__.py" "$(basename "$0")" "$@"
602662
EOF
603663
}
604664
665+
_check_bin() {
666+
bin_name="$1"
667+
if _is_win; then
668+
bin_name+=".cmd"
669+
fi
670+
if [[ ! -f "$BIN_DIR/$bin_name" ]]; then
671+
echo "✗ missing bin/$bin_name"
672+
fi
673+
}
674+
675+
_check_envs() {
676+
script_path="$1"
677+
envs=( $(sed -E -n 's/.* @env ([A-Z0-9_]+)!.*/\1/p' $script_path) )
678+
missing_envs=()
679+
for env in $envs; do
680+
if [[ -z "${!env}" ]]; then
681+
missing_envs+=("$env")
682+
fi
683+
done
684+
if [[ -n "$missing_envs" ]]; then
685+
echo "✗ missing envs ${missing_envs[*]}"
686+
fi
687+
}
688+
605689
_link_tool() {
606690
from="$1"
607691
to="$2.${1##*.}"

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ todo
7676
argc build
7777
```
7878

79+
#### IV. Ensure that everything is ready (environment variables, Node/Python dependencies, mcp-bridge server)
80+
81+
```sh
82+
argc check
83+
```
84+
7985
### 3. Install to AIChat
8086

8187
Symlink this repo directory to AIChat's **functions_dir**:

docs/argcfile.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ argc -h # Print help information
1616
argc <command> -h # Print help information for <command>
1717

1818
# -------- Build --------
19-
# Build
19+
# Build all
2020
argc build
2121

2222
# Build all tools
@@ -29,6 +29,20 @@ argc build@agent
2929
# Build specific agents
3030
argc build@agent coder todo
3131

32+
# -------- Check --------
33+
# Check all
34+
argc check
35+
36+
# Check all tools
37+
argc check@tool
38+
# Check specific tools
39+
argc check@tool get_current_weather.sh execute_command.sh
40+
41+
# Check all agents
42+
argc check@agent
43+
# Check specific agents
44+
argc check@agent coder todo
45+
3246
# -------- Run --------
3347
# Run tool
3448
argc run@tool get_current_weather.sh '{"location":"London"}'

scripts/check-deps.sh

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# @describe Check dependencies
5+
#
6+
# Examples:
7+
# ./scripts/check-deps.sh tools/execute_sql_code.sh
8+
# ./scripts/check-deps.sh agents/json-viewer/tools.js
9+
#
10+
# @arg script-path! The script file path
11+
12+
main() {
13+
script_path="$argc_script_path"
14+
if [[ ! -f "$script_path" ]]; then
15+
_exit "✗ not found $script_path"
16+
fi
17+
ext="${script_path##*.}"
18+
if [[ "$script_path" == tools/* ]]; then
19+
if [[ "$ext" == "sh" ]]; then
20+
check_sh_dependencies
21+
fi
22+
elif [[ "$script_path" == agents/* ]]; then
23+
if [[ "$ext" == "sh" ]]; then
24+
check_sh_dependencies
25+
elif [[ "$ext" == "js" ]]; then
26+
check_agent_js_dependencies
27+
elif [[ "$ext" == "py" ]]; then
28+
check_agent_py_dependencies
29+
fi
30+
fi
31+
}
32+
33+
check_sh_dependencies() {
34+
deps=( $(sed -E -n 's/.*@meta require-tools //p' "$script_path") )
35+
missing_deps=()
36+
for dep in "${deps[@]}"; do
37+
if ! command -v "$dep" &> /dev/null; then
38+
missing_deps+=("$dep")
39+
fi
40+
done
41+
if [[ -n "${missing_deps}" ]]; then
42+
_exit "✗ missing tools: ${missing_deps[*]}"
43+
fi
44+
}
45+
46+
check_agent_js_dependencies() {
47+
agent_dir="$(dirname "$script_path")"
48+
if [[ -f "$agent_dir/package.json" ]]; then
49+
npm ls --prefix="$agent_dir" --depth=0 --silent >/dev/null 2>&1 || \
50+
_exit "✗ missing node modules, FIX: cd $agent_dir && npm install"
51+
fi
52+
}
53+
54+
check_agent_py_dependencies() {
55+
agent_dir="$(dirname "$script_path")"
56+
if [[ -f "$agent_dir/requirements.txt" ]]; then
57+
python <(cat "$agent_dir/requirements.txt" | sed -E -n 's/^([A-Za-z_]+).*/import \1/p') >/dev/null 2>&1 || \
58+
_exit "✗ missing python modules, FIX: cd $agent_dir && pip install -r requirements.txt"
59+
fi
60+
}
61+
62+
_exit() {
63+
echo "$*" >&2
64+
exit 0
65+
}
66+
67+
# See more details at https://github.com/sigoden/argc
68+
eval "$(argc --argc-eval "$0" "$@")"

scripts/mcp.sh

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ stop() {
4646
"$0" recovery-functions -S
4747
}
4848

49+
# @cmd Check the mcp bridge server is running
50+
check() {
51+
if [[ -f "$MCP_JSON_PATH" ]]; then
52+
echo "Check mcp/bridge"
53+
pid="$(get-server-pid)"
54+
if [[ -z "$pid" ]]; then
55+
stop
56+
echo "✗ server is not running"
57+
fi
58+
fi
59+
}
60+
4961
# @cmd Run the mcp tool
5062
# @arg tool![`_choice_tool`] The tool name
5163
# @arg json The json data

0 commit comments

Comments
 (0)