Add crew rename, pristine commands and status integration
- gt crew rename: Rename crew workspace (kills session, renames dir) - gt crew pristine: Sync crew workspaces with git pull + bd sync - gt status: Show crew workers per rig with 👤 indicator 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
@@ -274,3 +275,96 @@ func (m *Manager) loadState(name string) (*CrewWorker, error) {
|
||||
|
||||
return &crew, nil
|
||||
}
|
||||
|
||||
// Rename renames a crew worker from oldName to newName.
|
||||
func (m *Manager) Rename(oldName, newName string) error {
|
||||
if !m.exists(oldName) {
|
||||
return ErrCrewNotFound
|
||||
}
|
||||
if m.exists(newName) {
|
||||
return ErrCrewExists
|
||||
}
|
||||
|
||||
oldPath := m.crewDir(oldName)
|
||||
newPath := m.crewDir(newName)
|
||||
|
||||
// Rename directory
|
||||
if err := os.Rename(oldPath, newPath); err != nil {
|
||||
return fmt.Errorf("renaming crew dir: %w", err)
|
||||
}
|
||||
|
||||
// Update state file with new name and path
|
||||
crew, err := m.loadState(newName)
|
||||
if err != nil {
|
||||
// Rollback on error
|
||||
os.Rename(newPath, oldPath)
|
||||
return fmt.Errorf("loading state: %w", err)
|
||||
}
|
||||
|
||||
crew.Name = newName
|
||||
crew.ClonePath = newPath
|
||||
crew.UpdatedAt = time.Now()
|
||||
|
||||
if err := m.saveState(crew); err != nil {
|
||||
// Rollback on error
|
||||
os.Rename(newPath, oldPath)
|
||||
return fmt.Errorf("saving state: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Pristine ensures a crew worker is up-to-date with remote.
|
||||
// It runs git pull --rebase and bd sync.
|
||||
func (m *Manager) Pristine(name string) (*PristineResult, error) {
|
||||
if !m.exists(name) {
|
||||
return nil, ErrCrewNotFound
|
||||
}
|
||||
|
||||
crewPath := m.crewDir(name)
|
||||
crewGit := git.NewGit(crewPath)
|
||||
|
||||
result := &PristineResult{
|
||||
Name: name,
|
||||
}
|
||||
|
||||
// Check for uncommitted changes
|
||||
hasChanges, err := crewGit.HasUncommittedChanges()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("checking changes: %w", err)
|
||||
}
|
||||
result.HadChanges = hasChanges
|
||||
|
||||
// Pull latest (use origin and current branch)
|
||||
if err := crewGit.Pull("origin", ""); err != nil {
|
||||
result.PullError = err.Error()
|
||||
} else {
|
||||
result.Pulled = true
|
||||
}
|
||||
|
||||
// Run bd sync
|
||||
if err := m.runBdSync(crewPath); err != nil {
|
||||
result.SyncError = err.Error()
|
||||
} else {
|
||||
result.Synced = true
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// runBdSync runs bd sync in the given directory.
|
||||
func (m *Manager) runBdSync(dir string) error {
|
||||
cmd := exec.Command("bd", "sync")
|
||||
cmd.Dir = dir
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// PristineResult captures the results of a pristine operation.
|
||||
type PristineResult struct {
|
||||
Name string `json:"name"`
|
||||
HadChanges bool `json:"had_changes"`
|
||||
Pulled bool `json:"pulled"`
|
||||
PullError string `json:"pull_error,omitempty"`
|
||||
Synced bool `json:"synced"`
|
||||
SyncError string `json:"sync_error,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user