Skip to content

Commit f4c3c2b

Browse files
committed
ops: auto-start slack bridge on agent boot
start.sh now launches the bridge in a background function that polls for the control-agent socket (up to 60s). Once the socket appears, it starts the bridge tmux session pointing at the correct UUID. Previously the bridge only started when the control-agent chose to run startup-cleanup.sh, which meant a reboot could leave the agent running with no Slack connection.
1 parent c1aeeac commit f4c3c2b

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

start.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,46 @@ else
5050
exit 1
5151
fi
5252

53+
# Start the slack-bridge in the background.
54+
# It waits for the control-agent socket to appear, then connects.
55+
_start_bridge() {
56+
local socket_dir="$HOME/.pi/session-control"
57+
local timeout=60
58+
local elapsed=0
59+
60+
echo "bridge: waiting for control-agent socket..."
61+
while [ $elapsed -lt $timeout ]; do
62+
local alias_file="$socket_dir/control-agent.alias"
63+
if [ -L "$alias_file" ]; then
64+
local target
65+
target=$(readlink "$alias_file")
66+
local uuid="${target%.sock}"
67+
echo "bridge: found control-agent ($uuid)"
68+
69+
# Kill existing bridge if any
70+
tmux kill-session -t slack-bridge 2>/dev/null || true
71+
sleep 1
72+
73+
tmux new-session -d -s slack-bridge \
74+
"export PATH=\$HOME/.varlock/bin:\$HOME/opt/node-v22.14.0-linux-x64/bin:\$PATH && export PI_SESSION_ID=$uuid && cd ~/runtime/slack-bridge && exec varlock run --path ~/.config/ -- node bridge.mjs"
75+
76+
sleep 3
77+
local http_code
78+
http_code=$(curl -s -o /dev/null -w '%{http_code}' -X POST http://127.0.0.1:7890/send -H 'Content-Type: application/json' -d '{}' 2>/dev/null || echo "000")
79+
if [ "$http_code" = "400" ]; then
80+
echo "bridge: up ✓"
81+
else
82+
echo "bridge: started but health check returned HTTP $http_code"
83+
fi
84+
return
85+
fi
86+
sleep 2
87+
elapsed=$((elapsed + 2))
88+
done
89+
echo "bridge: timed out waiting for control-agent socket (${timeout}s)"
90+
}
91+
_start_bridge &
92+
5393
# Start control-agent
5494
# --session-control: enables inter-session communication (handled by control.ts extension)
5595
pi --session-control --model "$MODEL" --skill ~/.pi/agent/skills/control-agent "/skill:control-agent"

0 commit comments

Comments
 (0)