From dac2a166775f53d1a2da401dc909c4576cefa6c2 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Wed, 3 Jun 2026 14:40:42 -0600 Subject: [PATCH] feat: removed conditional fallback of LLM_*_RAW_JSON from built-ins --- assets/functions/scripts/run-agent.py | 5 +++-- assets/functions/scripts/run-agent.sh | 1 + assets/functions/scripts/run-agent.ts | 5 +++-- assets/functions/scripts/run-tool.py | 5 +++-- assets/functions/scripts/run-tool.sh | 1 + assets/functions/scripts/run-tool.ts | 5 +++-- assets/functions/tools/execute_command.sh | 3 +++ assets/functions/tools/execute_sql_code.sh | 2 ++ assets/functions/tools/fs_patch.sh | 3 +++ assets/functions/tools/fs_write.sh | 3 +++ assets/functions/tools/send_mail.sh | 4 ++++ 11 files changed, 29 insertions(+), 8 deletions(-) diff --git a/assets/functions/scripts/run-agent.py b/assets/functions/scripts/run-agent.py index e22368b..206e0c5 100755 --- a/assets/functions/scripts/run-agent.py +++ b/assets/functions/scripts/run-agent.py @@ -32,7 +32,7 @@ def main(): agent_data = parse_raw_data(raw_data) root_dir = "{config_dir}" - setup_env(root_dir, agent_func) + setup_env(root_dir, agent_func, raw_data) agent_tools_path = os.path.join(root_dir, "agents/{agent_name}/tools.py") run(agent_tools_path, agent_func, agent_data) @@ -65,13 +65,14 @@ def parse_argv(): return agent_func, agent_data -def setup_env(root_dir, agent_func): +def setup_env(root_dir, agent_func, raw_data): load_env(os.path.join(root_dir, ".env")) os.environ["LLM_ROOT_DIR"] = root_dir os.environ["LLM_AGENT_NAME"] = "{agent_name}" os.environ["LLM_AGENT_FUNC"] = agent_func os.environ["LLM_AGENT_ROOT_DIR"] = os.path.join(root_dir, "agents", "{agent_name}") os.environ["LLM_AGENT_CACHE_DIR"] = os.path.join(root_dir, "cache", "{agent_name}") + os.environ["LLM_AGENT_RAW_JSON"] = raw_data def load_env(file_path): diff --git a/assets/functions/scripts/run-agent.sh b/assets/functions/scripts/run-agent.sh index ee1af7e..d72b955 100644 --- a/assets/functions/scripts/run-agent.sh +++ b/assets/functions/scripts/run-agent.sh @@ -32,6 +32,7 @@ setup_env() { export LLM_AGENT_ROOT_DIR="$LLM_ROOT_DIR/agents/{agent_name}" export LLM_AGENT_CACHE_DIR="$LLM_ROOT_DIR/cache/{agent_name}" export LLM_PROMPT_UTILS_FILE="{prompt_utils_file}" + export LLM_AGENT_RAW_JSON="$agent_data" } load_env() { diff --git a/assets/functions/scripts/run-agent.ts b/assets/functions/scripts/run-agent.ts index a8e02a3..0195383 100644 --- a/assets/functions/scripts/run-agent.ts +++ b/assets/functions/scripts/run-agent.ts @@ -11,7 +11,7 @@ async function main(): Promise { const agentData = parseRawData(rawData); const configDir = "{config_dir}"; - setupEnv(configDir, agentFunc); + setupEnv(configDir, agentFunc, rawData); const agentToolsPath = join(configDir, "agents", "{agent_name}", "tools.ts"); await run(agentToolsPath, agentFunc, agentData); @@ -48,13 +48,14 @@ function parseArgv(): { agentFunc: string; rawData: string } { return { agentFunc, rawData: agentData }; } -function setupEnv(configDir: string, agentFunc: string): void { +function setupEnv(configDir: string, agentFunc: string, rawData: string): void { loadEnv(join(configDir, ".env")); process.env["LLM_ROOT_DIR"] = configDir; process.env["LLM_AGENT_NAME"] = "{agent_name}"; process.env["LLM_AGENT_FUNC"] = agentFunc; process.env["LLM_AGENT_ROOT_DIR"] = join(configDir, "agents", "{agent_name}"); process.env["LLM_AGENT_CACHE_DIR"] = join(configDir, "cache", "{agent_name}"); + process.env["LLM_AGENT_RAW_JSON"] = rawData; } function loadEnv(filePath: string): void { diff --git a/assets/functions/scripts/run-tool.py b/assets/functions/scripts/run-tool.py index 9ac3c07..b2d2b7a 100644 --- a/assets/functions/scripts/run-tool.py +++ b/assets/functions/scripts/run-tool.py @@ -32,7 +32,7 @@ def main(): tool_data = parse_raw_data(raw_data) root_dir = "{root_dir}" - setup_env(root_dir) + setup_env(root_dir, raw_data) tool_path = "{tool_path}.py" run(tool_path, "run", tool_data) @@ -65,11 +65,12 @@ def parse_argv(): return tool_data -def setup_env(root_dir): +def setup_env(root_dir, raw_data): load_env(os.path.join(root_dir, ".env")) os.environ["LLM_ROOT_DIR"] = root_dir os.environ["LLM_TOOL_NAME"] = "{function_name}" os.environ["LLM_TOOL_CACHE_DIR"] = os.path.join(root_dir, "cache", "{function_name}") + os.environ["LLM_TOOL_RAW_JSON"] = raw_data def load_env(file_path): diff --git a/assets/functions/scripts/run-tool.sh b/assets/functions/scripts/run-tool.sh index c612273..df07249 100644 --- a/assets/functions/scripts/run-tool.sh +++ b/assets/functions/scripts/run-tool.sh @@ -29,6 +29,7 @@ setup_env() { export LLM_TOOL_NAME="{function_name}" export LLM_TOOL_CACHE_DIR="$LLM_ROOT_DIR/cache/{function_name}" export LLM_PROMPT_UTILS_FILE="{prompt_utils_file}" + export LLM_TOOL_RAW_JSON="$tool_data" } load_env() { diff --git a/assets/functions/scripts/run-tool.ts b/assets/functions/scripts/run-tool.ts index 228166a..7580560 100644 --- a/assets/functions/scripts/run-tool.ts +++ b/assets/functions/scripts/run-tool.ts @@ -11,7 +11,7 @@ async function main(): Promise { const toolData = parseRawData(rawData); const rootDir = "{root_dir}"; - setupEnv(rootDir); + setupEnv(rootDir, rawData); const toolPath = "{tool_path}.ts"; await run(toolPath, "run", toolData); @@ -45,11 +45,12 @@ function parseArgv(): string { return toolData; } -function setupEnv(rootDir: string): void { +function setupEnv(rootDir: string, rawData: string): void { loadEnv(join(rootDir, ".env")); process.env["LLM_ROOT_DIR"] = rootDir; process.env["LLM_TOOL_NAME"] = "{function_name}"; process.env["LLM_TOOL_CACHE_DIR"] = join(rootDir, "cache", "{function_name}"); + process.env["LLM_TOOL_RAW_JSON"] = rawData; } function loadEnv(filePath: string): void { diff --git a/assets/functions/tools/execute_command.sh b/assets/functions/tools/execute_command.sh index f8a4efb..0c6383b 100755 --- a/assets/functions/tools/execute_command.sh +++ b/assets/functions/tools/execute_command.sh @@ -10,6 +10,9 @@ set -e source "$LLM_PROMPT_UTILS_FILE" main() { + # shellcheck disable=SC2154 + argc_command="$(jq -r '.command' <<< "$LLM_TOOL_RAW_JSON")" + guard_operation local script script="$(mktemp)" diff --git a/assets/functions/tools/execute_sql_code.sh b/assets/functions/tools/execute_sql_code.sh index 68753a1..3cf581e 100755 --- a/assets/functions/tools/execute_sql_code.sh +++ b/assets/functions/tools/execute_sql_code.sh @@ -14,6 +14,8 @@ source "$LLM_PROMPT_UTILS_FILE" # shellcheck disable=SC2154 main() { + argc_code="$(jq -r '.code' <<< "$LLM_TOOL_RAW_JSON")" + if ! grep -qi '^select' <<<"$argc_code"; then guard_operation "" fi diff --git a/assets/functions/tools/fs_patch.sh b/assets/functions/tools/fs_patch.sh index caa7165..a47e29a 100755 --- a/assets/functions/tools/fs_patch.sh +++ b/assets/functions/tools/fs_patch.sh @@ -16,6 +16,9 @@ source "$LLM_PROMPT_UTILS_FILE" # shellcheck disable=SC2154 main() { + argc_contents="$(jq -r '.contents' <<< "$LLM_TOOL_RAW_JSON")" + argc_path="$(jq -r '.path' <<< "$LLM_TOOL_RAW_JSON")" + if [[ ! -f "$argc_path" ]]; then error "Unable to find the specified file: $argc_path" exit 1 diff --git a/assets/functions/tools/fs_write.sh b/assets/functions/tools/fs_write.sh index 7c18eb5..c977a7b 100755 --- a/assets/functions/tools/fs_write.sh +++ b/assets/functions/tools/fs_write.sh @@ -15,6 +15,9 @@ source "$LLM_PROMPT_UTILS_FILE" # shellcheck disable=SC2154 main() { + argc_contents="$(jq -r '.contents' <<< "$LLM_TOOL_RAW_JSON")" + argc_path="$(jq -r '.path' <<< "$LLM_TOOL_RAW_JSON")" + if [[ -f "$argc_path" ]]; then printf "%s" "$argc_contents" | git diff --no-index "$argc_path" - || true guard_operation "Apply changes?" diff --git a/assets/functions/tools/send_mail.sh b/assets/functions/tools/send_mail.sh index f90870f..c1af68f 100755 --- a/assets/functions/tools/send_mail.sh +++ b/assets/functions/tools/send_mail.sh @@ -14,6 +14,10 @@ set -e # shellcheck disable=SC2154 main() { + argc_recipient="$(jq -r '.recipient' <<< "$LLM_TOOL_RAW_JSON")" + argc_subject="$(jq -r '.subject' <<< "$LLM_TOOL_RAW_JSON")" + argc_body="$(jq -r '.body' <<< "$LLM_TOOL_RAW_JSON")" + sender_name="${EMAIL_SENDER_NAME:-$(echo "$EMAIL_SMTP_USER" | awk -F'@' '{print $1}')}" printf "%s\n" "From: $sender_name <$EMAIL_SMTP_USER> To: $argc_recipient