@@ -324,20 +324,6 @@ resolve_pi_session_id() {
324324 return 1
325325}
326326
327- pause_before_attach () {
328- if [ " ${BAUDBOT_ATTACH_NO_PAUSE:- 0} " = " 1" ]; then
329- return 0
330- fi
331-
332- if [ -t 0 ] && [ -t 1 ]; then
333- echo -e " ${DIM} Press Enter to attach (Ctrl+C to cancel)...${RESET} "
334- # shellcheck disable=SC2162
335- read _
336- else
337- sleep 2
338- fi
339- }
340-
341327cmd_status () {
342328 if has_systemd && systemctl is-enabled baudbot & > /dev/null; then
343329 local status_rc=0
@@ -433,128 +419,109 @@ cmd_sessions() {
433419 fi
434420}
435421
436- cmd_attach () {
437- require_root " attach "
422+ cmd_debug () {
423+ require_root " debug "
438424
439425 local AGENT_USER=" baudbot_agent"
440426 local AGENT_HOME=" /home/$AGENT_USER "
441- local ATTACH_MODE=" auto"
442- local TARGET=" "
443- local tmux_target pi_target
427+ local MODEL=" "
444428
445429 while [ " $# " -gt 0 ]; do
446430 case " $1 " in
447- --pi)
448- ATTACH_MODE=" pi"
449- shift
450- ;;
451- --tmux)
452- ATTACH_MODE=" tmux"
453- shift
431+ --model)
432+ MODEL=" $2 "
433+ shift 2
454434 ;;
455435 -h|--help)
456- echo " Usage: sudo baudbot attach [--pi|--tmux] [session-name|session-id]"
436+ echo " Usage: sudo baudbot debug [--model <model>]"
437+ echo " "
438+ echo " Launch a debug agent with a live dashboard showing control-agent"
439+ echo " activity, health metrics, and system state. Use send_to_session"
440+ echo " to communicate with running agents."
457441 echo " "
458- echo " Examples:"
459- echo " sudo baudbot attach # defaults to control-agent"
460- echo " sudo baudbot attach --pi control-agent"
461- echo " sudo baudbot attach --pi <uuid>"
462- echo " sudo baudbot attach --tmux sentry-agent"
442+ echo " Options:"
443+ echo " --model <model> LLM model to use (default: auto-detect from API keys)"
444+ echo " "
445+ echo " Exit: Ctrl+C (does NOT affect the running control-agent)"
463446 exit 0
464447 ;;
465448 * )
466- if [ -n " $TARGET " ]; then
467- echo " ❌ Too many arguments for attach"
468- exit 1
469- fi
470- TARGET=" $1 "
471- shift
449+ echo " ❌ Unknown option: $1 "
450+ echo " Usage: sudo baudbot debug [--model <model>]"
451+ exit 1
472452 ;;
473453 esac
474454 done
475455
476- if [ -z " $TARGET " ]; then
477- TARGET=" control-agent"
478- fi
479-
480- attach_tmux_session () {
481- local tmux_target=" $1 "
482- echo -e " ${BOLD}${CYAN} Attaching to tmux session:${RESET} $tmux_target "
483- echo -e " ${GREEN} Safe detach:${RESET} Ctrl+b, d ${DIM} (keeps agent running)${RESET} "
484- echo " "
485- pause_before_attach
486- exec sudo -u " $AGENT_USER " tmux attach-session -t " $tmux_target "
487- }
488-
489- attach_pi_session () {
490- local pi_target=" $1 "
491- echo -e " ${BOLD}${CYAN} Attaching to pi session:${RESET} $pi_target "
492- echo -e " ${BOLD}${YELLOW} Safe detach (does NOT stop the agent):${RESET} "
493- echo -e " ${YELLOW} 1)${RESET} Press Ctrl+C once to clear input/cancel local prompt"
494- echo -e " ${YELLOW} 2)${RESET} Press Ctrl+C again to exit this client"
495- echo -e " ${GREEN} Agent keeps running under systemd in the background.${RESET} "
496- echo " "
497- pause_before_attach
498- local node_bin_dir=" "
499- node_bin_dir=" $( bb_resolve_runtime_node_bin_dir " $AGENT_HOME " ) "
500- exec sudo -u " $AGENT_USER " bash -lc " export PATH='$AGENT_HOME /.varlock/bin:$node_bin_dir ':\$ PATH; cd ~; varlock run --path ~/.config/ -- pi --session '$pi_target '"
501- }
502-
503- choose_tmux_target () {
504- local requested=" ${1:- } "
505- local first
506-
507- if [ -n " $requested " ]; then
508- if sudo -u " $AGENT_USER " tmux has-session -t " $requested " 2> /dev/null; then
509- echo " $requested "
510- return 0
456+ # Auto-detect model from env if not specified
457+ if [ -z " $MODEL " ]; then
458+ # Load env vars to check API keys
459+ local env_file=" $AGENT_HOME /.config/.env"
460+ if [ -r " $env_file " ]; then
461+ local env_val=" "
462+ env_val=" $( grep -E ' ^BAUDBOT_MODEL=' " $env_file " 2> /dev/null | tail -1 | cut -d= -f2- || true) "
463+ if [ -n " $env_val " ]; then
464+ MODEL=" $env_val "
465+ else
466+ env_val=" $( grep -E ' ^ANTHROPIC_API_KEY=' " $env_file " 2> /dev/null | tail -1 | cut -d= -f2- || true) "
467+ if [ -n " $env_val " ]; then
468+ MODEL=" anthropic/claude-sonnet-4-5"
469+ else
470+ env_val=" $( grep -E ' ^OPENAI_API_KEY=' " $env_file " 2> /dev/null | tail -1 | cut -d= -f2- || true) "
471+ if [ -n " $env_val " ]; then
472+ MODEL=" openai/gpt-4.1"
473+ else
474+ env_val=" $( grep -E ' ^GEMINI_API_KEY=' " $env_file " 2> /dev/null | tail -1 | cut -d= -f2- || true) "
475+ if [ -n " $env_val " ]; then
476+ MODEL=" google/gemini-3-flash-preview"
477+ fi
478+ fi
479+ fi
511480 fi
512- return 1
513- fi
514-
515- first=$( sudo -u " $AGENT_USER " tmux ls -F ' #{session_name}' 2> /dev/null | head -1)
516- [ -n " $first " ] || return 1
517- echo " $first "
518- return 0
519- }
520-
521- choose_pi_target () {
522- local requested=" ${1:- } "
523- local resolved
524-
525- if ! resolved=$( resolve_pi_session_id " $AGENT_USER " " $requested " ) ; then
526- return 1
527481 fi
528482
529- [ -n " $resolved " ] || return 1
530- echo " $resolved "
531- return 0
532- }
533-
534- if [ " $ATTACH_MODE " = " tmux" ]; then
535- if tmux_target=$( choose_tmux_target " $TARGET " ) ; then
536- attach_tmux_session " $tmux_target "
483+ if [ -z " $MODEL " ]; then
484+ echo " ❌ No LLM API key found. Set --model or configure API keys in $AGENT_HOME /.config/.env"
485+ exit 1
537486 fi
538- echo " ❌ tmux session not found. See: sudo baudbot sessions"
539- exit 1
540487 fi
541488
542- if [ " $ATTACH_MODE " = " pi" ]; then
543- if pi_target=$( choose_pi_target " $TARGET " ) ; then
544- attach_pi_session " $pi_target "
545- fi
546- echo " ❌ pi session not found. See: sudo baudbot sessions"
489+ # Validate MODEL — must be a safe provider/model string (alphanumeric, hyphens, dots, slashes)
490+ if [[ ! " $MODEL " =~ ^[a-zA-Z0-9._/-]+$ ]]; then
491+ echo " ❌ Invalid model name: $MODEL "
547492 exit 1
548493 fi
549494
550- if pi_target=$( choose_pi_target " $TARGET " ) ; then
551- attach_pi_session " $pi_target "
495+ local SKILL_DIR=" $AGENT_HOME /.pi/agent/skills/debug-agent"
496+ if [ ! -f " $SKILL_DIR /SKILL.md" ]; then
497+ # Fall back to deployed location
498+ SKILL_DIR=" /opt/baudbot/current/pi/skills/debug-agent"
552499 fi
553500
554- if tmux_target=$( choose_tmux_target " $TARGET " ) ; then
555- attach_tmux_session " $tmux_target "
501+ if [ ! -f " $SKILL_DIR /SKILL.md" ]; then
502+ echo " ❌ Debug agent skill not found. Run: sudo baudbot deploy"
503+ exit 1
556504 fi
557505
558- echo " ❌ No matching tmux/pi session found. See: sudo baudbot sessions"
559- exit 1
506+ echo -e " ${BOLD}${CYAN} Launching debug agent${RESET} "
507+ echo -e " ${DIM} Model: $MODEL ${RESET} "
508+ echo -e " ${DIM} Skill: $SKILL_DIR ${RESET} "
509+ echo -e " ${GREEN} Exit: Ctrl+C (does NOT affect the running control-agent)${RESET} "
510+ echo " "
511+
512+ local node_bin_dir=" "
513+ node_bin_dir=" $( bb_resolve_runtime_node_bin_dir " $AGENT_HOME " ) "
514+
515+ exec sudo -u " $AGENT_USER " bash -lc "
516+ unset PKG_EXECPATH
517+ export PATH='$AGENT_HOME /.varlock/bin:$node_bin_dir ':\$ PATH
518+ export VARLOCK_TELEMETRY_DISABLED=1
519+ cd ~
520+ varlock run --path ~/.config/ -- pi \
521+ --session-control \
522+ --model '$MODEL ' \
523+ --skill '$SKILL_DIR ' \
524+ -e '$SKILL_DIR /debug-dashboard.ts' \
525+ '/skill:debug-agent'
526+ "
560527}
0 commit comments