fix: ensure env variables are exported to subagents
The issue: variables sourced in cmd_delegate were not being passed to child processes (subagents) because 'source' doesn't automatically export variables to child processes. Fix: 1. Use 'set -a' before sourcing to auto-export all variables 2. Use 'set +a' after sourcing to disable auto-export 3. Updated template comments to recommend 'export' prefix Also added unit test to verify env pass-through works. Verified with tests that child processes now see the exported variables.
This commit is contained in:
@@ -564,12 +564,13 @@ cmd_delegate() {
|
||||
local log_file="$LOGS_DIR/delegate-$(date +%s).log"
|
||||
|
||||
mkdir -p "$ENV_DIR"
|
||||
local env_sh=""
|
||||
local env_sh="set -a; "
|
||||
if [ -f "$ENV_DIR/pm-agent.env" ]; then
|
||||
env_sh="source '$ENV_DIR/pm-agent.env'; "
|
||||
env_sh="${env_sh}source '$ENV_DIR/pm-agent.env'; "
|
||||
elif [ -f "$ENV_DIR/default.env" ]; then
|
||||
env_sh="source '$ENV_DIR/default.env'; "
|
||||
env_sh="${env_sh}source '$ENV_DIR/default.env'; "
|
||||
fi
|
||||
env_sh="${env_sh}set +a; "
|
||||
|
||||
nohup sh -c "${env_sh}opencode run '$message' --continue --session '$pm_session' >> '$log_file' 2>&1" > /dev/null 2>&1 &
|
||||
disown
|
||||
@@ -951,9 +952,10 @@ EOF
|
||||
if [ ! -f "$ENV_DIR/default.env" ]; then
|
||||
cat > "$ENV_DIR/default.env" << 'EOF'
|
||||
# Default environment variables for all agents
|
||||
# Add variables that all agents should have access to
|
||||
# Variables here are exported to subagents
|
||||
# Use 'export' prefix for variables that subagents need
|
||||
# Example:
|
||||
# GITEA_TOKEN=your_token_here
|
||||
# export GITEA_TOKEN=your_token_here
|
||||
EOF
|
||||
echo "Created default env file: $ENV_DIR/default.env"
|
||||
fi
|
||||
@@ -961,7 +963,9 @@ EOF
|
||||
cat > "$ENV_DIR/pm-agent.env" << 'EOF'
|
||||
# PM Agent environment variables
|
||||
# These override default.env for the PM agent
|
||||
# GITEA_TOKEN=your_gitea_token_here
|
||||
# Use 'export' prefix for variables that subagents need
|
||||
# Example:
|
||||
# export GITEA_TOKEN=your_gitea_token_here
|
||||
EOF
|
||||
echo "Created pm-agent env file: $ENV_DIR/pm-agent.env"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user