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"
|
local log_file="$LOGS_DIR/delegate-$(date +%s).log"
|
||||||
|
|
||||||
mkdir -p "$ENV_DIR"
|
mkdir -p "$ENV_DIR"
|
||||||
local env_sh=""
|
local env_sh="set -a; "
|
||||||
if [ -f "$ENV_DIR/pm-agent.env" ]; then
|
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
|
elif [ -f "$ENV_DIR/default.env" ]; then
|
||||||
env_sh="source '$ENV_DIR/default.env'; "
|
env_sh="${env_sh}source '$ENV_DIR/default.env'; "
|
||||||
fi
|
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 &
|
nohup sh -c "${env_sh}opencode run '$message' --continue --session '$pm_session' >> '$log_file' 2>&1" > /dev/null 2>&1 &
|
||||||
disown
|
disown
|
||||||
@@ -951,9 +952,10 @@ EOF
|
|||||||
if [ ! -f "$ENV_DIR/default.env" ]; then
|
if [ ! -f "$ENV_DIR/default.env" ]; then
|
||||||
cat > "$ENV_DIR/default.env" << 'EOF'
|
cat > "$ENV_DIR/default.env" << 'EOF'
|
||||||
# Default environment variables for all agents
|
# 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:
|
# Example:
|
||||||
# GITEA_TOKEN=your_token_here
|
# export GITEA_TOKEN=your_token_here
|
||||||
EOF
|
EOF
|
||||||
echo "Created default env file: $ENV_DIR/default.env"
|
echo "Created default env file: $ENV_DIR/default.env"
|
||||||
fi
|
fi
|
||||||
@@ -961,7 +963,9 @@ EOF
|
|||||||
cat > "$ENV_DIR/pm-agent.env" << 'EOF'
|
cat > "$ENV_DIR/pm-agent.env" << 'EOF'
|
||||||
# PM Agent environment variables
|
# PM Agent environment variables
|
||||||
# These override default.env for the PM agent
|
# 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
|
EOF
|
||||||
echo "Created pm-agent env file: $ENV_DIR/pm-agent.env"
|
echo "Created pm-agent env file: $ENV_DIR/pm-agent.env"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user