Files
gastown/internal/doctor/daemon_check.go
Ryan Snodgrass e1f2bb8b4b feat(ui): import comprehensive UX system from beads
Import beads' UX design system into gastown:

- Add internal/ui/ package with Ayu theme colors and semantic styling
  - styles.go: AdaptiveColor definitions for light/dark mode
  - terminal.go: TTY detection, NO_COLOR/CLICOLOR support
  - markdown.go: Glamour rendering with agent mode bypass
  - pager.go: Smart paging with GT_PAGER support

- Add colorized help output (internal/cmd/help.go)
  - Group headers in accent color
  - Command names styled for scannability
  - Flag types and defaults muted

- Add gt thanks command (internal/cmd/thanks.go)
  - Contributor display with same logic as bd thanks
  - Styled with Ayu theme colors

- Update gt doctor to match bd doctor UX
  - Category grouping (Core, Infrastructure, Rig, Patrol, etc.)
  - Semantic icons (✓ ⚠ ✖) with Ayu colors
  - Tree connectors for detail lines
  - Summary line with pass/warn/fail counts
  - Warnings section at end with numbered issues

- Migrate existing styles to use ui package
  - internal/style/style.go uses ui.ColorPass etc.
  - internal/tui/feed/styles.go uses ui package colors

Co-Authored-By: SageOx <ox@sageox.ai>
2026-01-09 22:46:06 -08:00

113 lines
2.3 KiB
Go

package doctor
import (
"os"
"os/exec"
"time"
"github.com/steveyegge/gastown/internal/daemon"
)
// DaemonCheck verifies the daemon is running.
type DaemonCheck struct {
FixableCheck
}
// NewDaemonCheck creates a new daemon check.
func NewDaemonCheck() *DaemonCheck {
return &DaemonCheck{
FixableCheck: FixableCheck{
BaseCheck: BaseCheck{
CheckName: "daemon",
CheckDescription: "Check if Gas Town daemon is running",
CheckCategory: CategoryInfrastructure,
},
},
}
}
// Run checks if the daemon is running.
func (c *DaemonCheck) Run(ctx *CheckContext) *CheckResult {
running, pid, err := daemon.IsRunning(ctx.TownRoot)
if err != nil {
return &CheckResult{
Name: c.Name(),
Status: StatusError,
Message: "Failed to check daemon status",
Details: []string{err.Error()},
}
}
if running {
// Get more info about daemon state
state, err := daemon.LoadState(ctx.TownRoot)
details := []string{}
if err == nil && !state.StartedAt.IsZero() {
uptime := time.Since(state.StartedAt).Round(time.Second)
details = append(details, "Uptime: "+uptime.String())
if state.HeartbeatCount > 0 {
details = append(details, "Heartbeats: "+string(rune(state.HeartbeatCount)))
}
}
return &CheckResult{
Name: c.Name(),
Status: StatusOK,
Message: "Daemon is running (PID " + itoa(pid) + ")",
Details: details,
}
}
return &CheckResult{
Name: c.Name(),
Status: StatusWarning,
Message: "Daemon is not running",
FixHint: "Run 'gt daemon start' or 'gt doctor --fix'",
}
}
// Fix starts the daemon.
func (c *DaemonCheck) Fix(ctx *CheckContext) error {
// Find gt executable
gtPath, err := os.Executable()
if err != nil {
return err
}
// Start daemon in background (detach from parent I/O - daemon uses its own logging)
cmd := exec.Command(gtPath, "daemon", "run")
cmd.Dir = ctx.TownRoot
cmd.Stdin = nil
cmd.Stdout = nil
cmd.Stderr = nil
if err := cmd.Start(); err != nil {
return err
}
// Wait a moment for daemon to initialize
time.Sleep(300 * time.Millisecond)
return nil
}
// itoa is a simple int to string helper
func itoa(i int) string {
if i == 0 {
return "0"
}
s := ""
neg := i < 0
if neg {
i = -i
}
for i > 0 {
s = string(rune('0'+i%10)) + s
i /= 10
}
if neg {
s = "-" + s
}
return s
}