diff options
| -rwxr-xr-x | scripts/run-agent.js | 36 | ||||
| -rwxr-xr-x | scripts/run-agent.py | 34 | ||||
| -rwxr-xr-x | scripts/run-tool.js | 36 | ||||
| -rwxr-xr-x | scripts/run-tool.py | 34 |
4 files changed, 100 insertions, 40 deletions
diff --git a/scripts/run-agent.js b/scripts/run-agent.js index 6a02792..b8dddd0 100755 --- a/scripts/run-agent.js +++ b/scripts/run-agent.js @@ -67,20 +67,38 @@ async function setupEnv(rootDir, agentName, agentFunc) { } async function loadEnv(filePath) { + let lines = []; try { const data = await readFile(filePath, "utf-8"); - const lines = data.split("\n"); + lines = data.split("\n"); + } catch { + return; + } + + const envVars = new Map(); + + for (const line of lines) { + if (line.trim().startsWith("#") || line.trim() === "") { + continue; + } - lines.forEach((line) => { - if (line.trim().startsWith("#") || line.trim() === "") return; + const [key, ...valueParts] = line.split("="); + const envName = key.trim(); - const [key, ...value] = line.split("="); - const envName = key.trim(); - if (!process.env[envName]) { - process.env[envName] = value.join("=").trim(); + if (!process.env[envName]) { + let envValue = valueParts.join("=").trim(); + if (envValue.startsWith('"') && envValue.endsWith('"')) { + envValue = envValue.slice(1, -1); + } else if (envValue.startsWith("'") && envValue.endsWith("'")) { + envValue = envValue.slice(1, -1); } - }); - } catch { } + envVars.set(envName, envValue); + } + } + + for (const [envName, envValue] of envVars.entries()) { + process.env[envName] = envValue; + } } async function run(agentPath, agentFunc, agentData) { diff --git a/scripts/run-agent.py b/scripts/run-agent.py index 5c925ba..58595e4 100755 --- a/scripts/run-agent.py +++ b/scripts/run-agent.py @@ -61,17 +61,29 @@ def setup_env(root_dir, agent_name, agent_func): def load_env(file_path): try: with open(file_path, "r") as f: - for line in f: - line = line.strip() - if line.startswith("#") or line == "": - continue - - key, *value = line.split("=") - env_name = key.strip() - if env_name not in os.environ: - os.environ[env_name] = "=".join(value).strip() - except FileNotFoundError: - pass + lines = f.readlines() + except: + return + + env_vars = {} + + for line in lines: + line = line.strip() + if line.startswith("#") or not line: + continue + + key, *value_parts = line.split("=") + env_name = key.strip() + + if env_name not in os.environ: + env_value = "=".join(value_parts).strip() + if env_value.startswith('"') and env_value.endswith('"'): + env_value = env_value[1:-1] + elif env_value.startswith("'") and env_value.endswith("'"): + env_value = env_value[1:-1] + env_vars[env_name] = env_value + + os.environ.update(env_vars) def run(agent_path, agent_func, agent_data): diff --git a/scripts/run-tool.js b/scripts/run-tool.js index d610772..e4ac434 100755 --- a/scripts/run-tool.js +++ b/scripts/run-tool.js @@ -54,20 +54,38 @@ async function setupEnv(rootDir, toolName) { } async function loadEnv(filePath) { + let lines = []; try { const data = await readFile(filePath, "utf-8"); - const lines = data.split("\n"); + lines = data.split("\n"); + } catch { + return; + } + + const envVars = new Map(); + + for (const line of lines) { + if (line.trim().startsWith("#") || line.trim() === "") { + continue; + } - lines.forEach((line) => { - if (line.trim().startsWith("#") || line.trim() === "") return; + const [key, ...valueParts] = line.split("="); + const envName = key.trim(); - const [key, ...value] = line.split("="); - const envName = key.trim(); - if (!process.env[envName]) { - process.env[envName] = value.join("=").trim(); + if (!process.env[envName]) { + let envValue = valueParts.join("=").trim(); + if (envValue.startsWith('"') && envValue.endsWith('"')) { + envValue = envValue.slice(1, -1); + } else if (envValue.startsWith("'") && envValue.endsWith("'")) { + envValue = envValue.slice(1, -1); } - }); - } catch { } + envVars.set(envName, envValue); + } + } + + for (const [envName, envValue] of envVars.entries()) { + process.env[envName] = envValue; + } } async function run(toolPath, toolFunc, toolData) { diff --git a/scripts/run-tool.py b/scripts/run-tool.py index 99af580..6ea3361 100755 --- a/scripts/run-tool.py +++ b/scripts/run-tool.py @@ -56,17 +56,29 @@ def setup_env(root_dir, tool_name): def load_env(file_path): try: with open(file_path, "r") as f: - for line in f: - line = line.strip() - if line.startswith("#") or line == "": - continue - - key, *value = line.split("=") - env_name = key.strip() - if env_name not in os.environ: - os.environ[env_name] = "=".join(value).strip() - except FileNotFoundError: - pass + lines = f.readlines() + except: + return + + env_vars = {} + + for line in lines: + line = line.strip() + if line.startswith("#") or not line: + continue + + key, *value_parts = line.split("=") + env_name = key.strip() + + if env_name not in os.environ: + env_value = "=".join(value_parts).strip() + if env_value.startswith('"') and env_value.endswith('"'): + env_value = env_value[1:-1] + elif env_value.startswith("'") and env_value.endswith("'"): + env_value = env_value[1:-1] + env_vars[env_name] = env_value + + os.environ.update(env_vars) def run(tool_path, tool_func, tool_data): |
