Skip to content

Commit c99514c

Browse files
Gregg CochranCopilot
andcommitted
Prevent noisy Pulse orphan terminals
Launch Agent Pulse with exec in spawned terminals, close stale Terminal zsh windows from prior Pulse runs, preserve explicit scan roots, and suppress startup notification bells from historical alerts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1209e5f commit c99514c

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

agent_pulse.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,13 +3286,15 @@ class AgentPulseApp(App):
32863286
_prev_error_rate_high: bool = False
32873287
_alerted_milestones: set = None
32883288
_alerted_commanders: set = None
3289+
_alerts_ready: bool = False
32893290

32903291
def __init__(self) -> None:
32913292
super().__init__()
32923293
self.store = PulseStore()
32933294
self.engine = MetricsEngine(self.store)
32943295
self._alerted_milestones = set()
32953296
self._alerted_commanders = set()
3297+
self._alerts_ready = False
32963298

32973299
def compose(self) -> ComposeResult:
32983300
yield Vertical(
@@ -3438,17 +3440,18 @@ def _poll(self) -> None:
34383440
if self._paused:
34393441
return
34403442
m = self.engine.poll()
3443+
suppress_alerts = not self._alerts_ready
34413444

34423445
# Feature 5: Alert on new agent launches
3443-
if self._prev_spawned > 0 and m.spawned_all_time > self._prev_spawned:
3446+
if not suppress_alerts and self._prev_spawned > 0 and m.spawned_all_time > self._prev_spawned:
34443447
diff = m.spawned_all_time - self._prev_spawned
34453448
if m.recent_events:
34463449
latest_type = m.recent_events[0][1]
34473450
self.notify(f"⚡ New {latest_type} agent launched", timeout=4)
34483451

34493452
# Feature 5: Error rate alert
34503453
error_high = m.error_count_24h > 3
3451-
if error_high and not self._prev_error_rate_high:
3454+
if not suppress_alerts and error_high and not self._prev_error_rate_high:
34523455
self.notify("🔴 Error rate elevated", severity="error", timeout=6)
34533456
self._prev_error_rate_high = error_high
34543457

@@ -3460,16 +3463,18 @@ def _poll(self) -> None:
34603463
if key in self._alerted_commanders:
34613464
continue
34623465
self._alerted_commanders.add(key)
3463-
self.notify(f"🛑 {alert.get('message', 'Commander died before completing')}", severity="error", timeout=10)
3466+
if not suppress_alerts:
3467+
self.notify(f"🛑 {alert.get('message', 'Commander died before completing')}", severity="error", timeout=10)
34643468

34653469
# Feature 5: Milestones
34663470
for milestone in (10, 50, 100, 500, 1000):
34673471
if m.spawned_all_time >= milestone and milestone not in self._alerted_milestones:
34683472
self._alerted_milestones.add(milestone)
3469-
if self._prev_spawned > 0: # don't alert on first load
3473+
if not suppress_alerts and self._prev_spawned > 0:
34703474
self.notify(f"🎉 Milestone: {milestone} agents!", timeout=8)
34713475

34723476
self._prev_spawned = m.spawned_all_time
3477+
self._alerts_ready = True
34733478

34743479
# Update all widgets
34753480
self.logo.metrics = m

start.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,20 @@ if [ "$MODE" = "here" ]; then
9898
fi
9999

100100
# --- Otherwise, spawn in a new window/pane of the user's terminal emulator ---
101-
CMD="export AGENT_PULSE_SPAWNED=1; cd '$SCRIPT_DIR' && '$VENV/bin/python' '$SCRIPT_DIR/agent_pulse.py' ${PASSTHROUGH_ARGS[*]}"
101+
shell_quote() {
102+
printf "%q" "$1"
103+
}
104+
105+
QUOTED_ARGS=""
106+
for arg in "${PASSTHROUGH_ARGS[@]}"; do
107+
QUOTED_ARGS+=" $(shell_quote "$arg")"
108+
done
109+
110+
CMD="export AGENT_PULSE_SPAWNED=1"
111+
if [ -n "${AGENT_PULSE_SCAN_ROOTS:-}" ]; then
112+
CMD+="; export AGENT_PULSE_SCAN_ROOTS=$(shell_quote "$AGENT_PULSE_SCAN_ROOTS")"
113+
fi
114+
CMD+="; cd $(shell_quote "$SCRIPT_DIR") && exec $(shell_quote "$VENV/bin/python") $(shell_quote "$SCRIPT_DIR/agent_pulse.py")${QUOTED_ARGS}"
102115

103116
# tmux — open a new window in the current session
104117
if [ -n "$TMUX" ]; then
@@ -172,6 +185,11 @@ case "$TERM_APP" in
172185
osascript -e "
173186
tell application \"Terminal\"
174187
activate
188+
repeat with w in windows
189+
if (name of w) contains \"copilot-cli-agent-pulse\" and (name of w) contains \"-zsh\" then
190+
close w saving no
191+
end if
192+
end repeat
175193
do script \"$CMD\"
176194
end tell" &>/dev/null
177195
echo "⚡ Agent Pulse launched in a new Terminal window."
@@ -201,6 +219,11 @@ case "$TERM_APP" in
201219
osascript -e "
202220
tell application \"Terminal\"
203221
activate
222+
repeat with w in windows
223+
if (name of w) contains \"copilot-cli-agent-pulse\" and (name of w) contains \"-zsh\" then
224+
close w saving no
225+
end if
226+
end repeat
204227
do script \"$CMD\"
205228
end tell" &>/dev/null
206229
echo "⚡ Agent Pulse launched in a new Terminal window."

0 commit comments

Comments
 (0)