aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore10
-rw-r--r--Argcfile.sh74
-rw-r--r--README.md1
3 files changed, 60 insertions, 25 deletions
diff --git a/.gitignore b/.gitignore
index 2255aa6..108e031 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,16 +1,14 @@
/tmp
-functions.txt
-tools.txt
-agents.txt
+/tools.txt
+/agents.txt
functions.json
/bin
/cache
/tools/test.*
/.env
-*.cmd
__pycache__
/venv
node_modules
-package.json
-package-lock.json
+/package.json
+/package-lock.json
*.lock \ No newline at end of file
diff --git a/Argcfile.sh b/Argcfile.sh
index a5bb74c..092176b 100644
--- a/Argcfile.sh
+++ b/Argcfile.sh
@@ -102,7 +102,7 @@ build-bin@tool() {
fi
fi
if [[ -z "$names" ]]; then
- _die "error: not input tools, not found '$argc_names_file', please create it add some tools."
+ _die "error: no tools provided. '$argc_names_file' is missing. please create it and add some tools."
fi
not_found_tools=()
for name in "${names[@]}"; do
@@ -139,7 +139,7 @@ build-declarations@tool() {
names=($(cat "$argc_names_file" | grep -v '^#'))
fi
if [[ -z "$names" ]]; then
- _die "error: not input tools, not found '$argc_names_file', please create it add some tools."
+ _die "error: no tools provided. '$argc_names_file' is missing. please create it and add some tools."
fi
json_list=()
not_found_tools=()
@@ -162,8 +162,13 @@ build-declarations@tool() {
if [[ -n "$build_failed_tools" ]]; then
_die "error: invalid tools: ${build_failed_tools[*]}"
fi
- echo "Build $argc_declarations_file"
- echo "["$(IFS=,; echo "${json_list[*]}")"]" | jq '.' > "$argc_declarations_file"
+ json_data="$(echo "["$(IFS=,; echo "${json_list[*]}")"]" | jq '.')"
+ if [[ "$argc_declarations_file" == "-" ]]; then
+ echo "$json_data"
+ else
+ echo "Build $argc_declarations_file"
+ echo "$json_data" > "$argc_declarations_file"
+ fi
}
@@ -210,7 +215,7 @@ build-bin@agent() {
fi
fi
if [[ -z "$names" ]]; then
- _die "error: not input agents, not found '$argc_names_file', please create it add some tools."
+ _die "error: no agents provided. '$argc_names_file' is missing. please create it and add some agents."
fi
not_found_agents=()
for name in "${names[@]}"; do
@@ -229,6 +234,11 @@ build-bin@agent() {
ln -s -f "$PWD/scripts/run-agent.$lang" "$bin_file"
fi
echo "Build agent $name"
+ tool_names_file="$agent_dir/tools.txt"
+ if [[ -f "$tool_names_file" ]]; then
+ argc build-bin@tool --names-file "${tool_names_file}"
+ fi
+ break
fi
done
if [[ "$found" == "false" ]] && [[ ! -d "$agent_dir" ]]; then
@@ -251,28 +261,54 @@ build-declarations@agent() {
names=($(cat "$argc_names_file" | grep -v '^#'))
fi
if [[ -z "$names" ]]; then
- _die "error: not input agents, not found '$argc_names_file', please create it add some tools."
+ _die "error: no agents provided. '$argc_names_file' is missing. please create it and add some agents."
fi
not_found_agents=()
build_failed_agents=()
for name in "${names[@]}"; do
agent_dir="agents/$name"
- build_ok=false
+ declarations_file="$agent_dir/functions.json"
+ tool_names_file="$agent_dir/tools.txt"
+ rm -rf "$declarations_file"
found=false
- for item in "${LANG_CMDS[@]}"; do
- lang="${item%:*}"
- agent_tools_file="$agent_dir/tools.$lang"
- if [[ -f "$agent_tools_file" ]]; then
- found=true
- json_data="$(generate-declarations@agent "$name")" || {
+ if [[ -d "$agent_dir" ]]; then
+ found=true
+ ok=true
+ json_data=""
+ agent_json_data=""
+ tools_json_data=""
+ for item in "${LANG_CMDS[@]}"; do
+ lang="${item%:*}"
+ agent_tools_file="$agent_dir/tools.$lang"
+ if [[ -f "$agent_tools_file" ]]; then
+ agent_json_data="$(generate-declarations@agent "$name")" || {
+ ok=false
+ build_failed_agents+=("$name")
+ }
+ break
+ fi
+ done
+ if [[ -f "$tool_names_file" ]]; then
+ tools_json_data="$(argc build-declarations@tool --names-file="$tool_names_file" --declarations-file=-)" || {
+ ok=false
build_failed_agents+=("$name")
}
- declarations_file="$agent_dir/functions.json"
- echo "Build $declarations_file"
- echo "$json_data" > "$declarations_file"
fi
- done
- if [[ "$found" == "false" ]] && [[ ! -d "$agent_dir" ]]; then
+ if [[ "$ok" == "true" ]]; then
+ if [[ -n "$agent_json_data" ]] && [[ -n "$tools_json_data" ]]; then
+ json_data="$(jq -s '.[0] + .[1]' <(echo "$agent_json_data") <(echo "$tools_json_data"))"
+ elif [[ -n "$agent_json_data" ]]; then
+ json_data="$agent_json_data"
+ elif [[ -n "$tools_json_data" ]]; then
+ json_data="$tools_json_data"
+ fi
+ if [[ -n "$json_data" ]]; then
+ echo "Build $declarations_file"
+ echo "$json_data" > "$declarations_file"
+ fi
+ fi
+ fi
+ if [[ "$found" == "false" ]]; then
not_found_agents+=("$name")
fi
done
@@ -295,7 +331,7 @@ generate-declarations@agent() {
fi
lang="${tools_path##*.}"
cmd="$(_lang_to_cmd "$lang")"
- json="$("$cmd" "scripts/build-declarations.$lang" "$tools_path")"
+ json="$("$cmd" "scripts/build-declarations.$lang" "$tools_path" | jq --arg agent "$1" 'map(. + {agent: $agent})')"
if [[ -n "$argc_oneline" ]]; then
echo "$json" | jq -r '.[] | .name + ": " + (.description | split("\n"))[0]'
else
diff --git a/README.md b/README.md
index 1336ea0..10a6656 100644
--- a/README.md
+++ b/README.md
@@ -125,6 +125,7 @@ The agent has the following folder structure:
└── myagent
├── functions.json # Function declarations file (Auto-generated)
├── index.yaml # Agent definition file
+ ├── tools.txt # Reuse tools
└── tools.{sh,js,py} # Agent tools script
```