@@ -182,17 +182,30 @@ case "$TERM_APP" in
182182 echo " ⚡ Agent Pulse launched in a new Warp window."
183183 ;;
184184 terminal)
185- osascript -e "
186- tell application \" Terminal\"
187- 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
193- do script \" $CMD \"
194- end tell" & > /dev/null
195- echo " ⚡ Agent Pulse launched in a new Terminal window."
185+ TERMINAL_RESULT=$( osascript << OSA 2>/dev/null
186+ tell application "Terminal"
187+ 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
193+ repeat with w in windows
194+ if (name of w) contains "agent_pulse.py" or (name of w) contains "AgentPulse" then
195+ set index of w to 1
196+ return "reused"
197+ end if
198+ end repeat
199+ do script "$CMD "
200+ return "launched"
201+ end tell
202+ OSA
203+ )
204+ if [ " $TERMINAL_RESULT " = " reused" ]; then
205+ echo " ⚡ Agent Pulse already running; focused existing Terminal window."
206+ else
207+ echo " ⚡ Agent Pulse launched in a new Terminal window."
208+ fi
196209 ;;
197210 * )
198211 # Linux / unknown — fall back through common emulators by availability
@@ -216,17 +229,30 @@ case "$TERM_APP" in
216229 echo " ⚡ Agent Pulse launched in xterm."
217230 elif command -v osascript & > /dev/null; then
218231 # macOS last-resort: use Terminal.app
219- osascript -e "
220- tell application \" Terminal\"
221- 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
227- do script \" $CMD \"
228- end tell" & > /dev/null
229- echo " ⚡ Agent Pulse launched in a new Terminal window."
232+ TERMINAL_RESULT=$( osascript << OSA 2>/dev/null
233+ tell application "Terminal"
234+ activate
235+ repeat with w in windows
236+ if (name of w) contains "copilot-cli-agent-pulse" and (name of w) contains "-zsh" then
237+ close w saving no
238+ end if
239+ end repeat
240+ repeat with w in windows
241+ if (name of w) contains "agent_pulse.py" or (name of w) contains "AgentPulse" then
242+ set index of w to 1
243+ return "reused"
244+ end if
245+ end repeat
246+ do script "$CMD "
247+ return "launched"
248+ end tell
249+ OSA
250+ )
251+ if [ " $TERMINAL_RESULT " = " reused" ]; then
252+ echo " ⚡ Agent Pulse already running; focused existing Terminal window."
253+ else
254+ echo " ⚡ Agent Pulse launched in a new Terminal window."
255+ fi
230256 else
231257 echo " ⚠️ Could not detect a terminal emulator — running in the current terminal."
232258 echo " (Tip: pass --here to always run in place.)"
0 commit comments