diff --git a/cmd/skillshare/backup.go b/cmd/skillshare/backup.go index 387525ffe..c432a023c 100644 --- a/cmd/skillshare/backup.go +++ b/cmd/skillshare/backup.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "sort" "strings" "time" @@ -492,12 +493,27 @@ func restoreTUIDispatch(noTUI bool) error { if projectConfigExists(cwd) { mode = modeProject } - trashBase := resolveTrashBase(mode, cwd, kindSkills) - items := trash.List(trashBase) + skillTrashBase := resolveTrashBase(mode, cwd, kindSkills) + agentTrashBase := resolveTrashBase(mode, cwd, kindAgents) + + // Merge skill + agent trash + var items []trash.TrashEntry + for _, e := range trash.List(skillTrashBase) { + e.Kind = "skill" + items = append(items, e) + } + for _, e := range trash.List(agentTrashBase) { + e.Kind = "agent" + items = append(items, e) + } if len(items) == 0 { ui.Info("Trash is empty") return nil } + sort.Slice(items, func(i, j int) bool { + return items[i].Date.After(items[j].Date) + }) + modeLabel := "global" if mode == modeProject { modeLabel = "project" @@ -507,7 +523,11 @@ func restoreTUIDispatch(noTUI bool) error { if err != nil { return err } - return runTrashTUI(items, trashBase, destDir, cfgPath, modeLabel) + agentDestDir, err := resolveSourceDir(mode, cwd, kindAgents) + if err != nil { + return err + } + return runTrashTUI(items, skillTrashBase, agentTrashBase, destDir, agentDestDir, cfgPath, modeLabel) } return nil diff --git a/cmd/skillshare/trash.go b/cmd/skillshare/trash.go index 04dc2bc12..9d0d7ce26 100644 --- a/cmd/skillshare/trash.go +++ b/cmd/skillshare/trash.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "sort" "strings" "time" @@ -74,6 +75,54 @@ func cmdTrash(args []string) error { } func trashList(mode runMode, cwd string, noTUI bool, kind resourceKindFilter) error { + // TUI path: merge skill + agent trash when kind includes both + if shouldLaunchTUI(noTUI, nil) { + var items []trash.TrashEntry + + if kind.IncludesSkills() { + skillBase := resolveTrashBase(mode, cwd, kindSkills) + for _, e := range trash.List(skillBase) { + e.Kind = "skill" + items = append(items, e) + } + } + if kind.IncludesAgents() { + agentBase := resolveTrashBase(mode, cwd, kindAgents) + for _, e := range trash.List(agentBase) { + e.Kind = "agent" + items = append(items, e) + } + } + + if len(items) == 0 { + ui.Info("Trash is empty") + return nil + } + + // Sort merged list by date (newest first) + sort.Slice(items, func(i, j int) bool { + return items[i].Date.After(items[j].Date) + }) + + modeLabel := "global" + if mode == modeProject { + modeLabel = "project" + } + skillTrashBase := resolveTrashBase(mode, cwd, kindSkills) + agentTrashBase := resolveTrashBase(mode, cwd, kindAgents) + cfgPath := resolveTrashCfgPath(mode, cwd) + destDir, err := resolveSourceDir(mode, cwd, kindSkills) + if err != nil { + return err + } + agentDestDir, err := resolveSourceDir(mode, cwd, kindAgents) + if err != nil { + return err + } + return runTrashTUI(items, skillTrashBase, agentTrashBase, destDir, agentDestDir, cfgPath, modeLabel) + } + + // Plain text path (unchanged) — list single kind trashBase := resolveTrashBase(mode, cwd, kind) items := trash.List(trashBase) @@ -82,21 +131,6 @@ func trashList(mode runMode, cwd string, noTUI bool, kind resourceKindFilter) er return nil } - // TUI dispatch: TTY + items + TUI enabled - if shouldLaunchTUI(noTUI, nil) { - modeLabel := "global" - if mode == modeProject { - modeLabel = "project" - } - cfgPath := resolveTrashCfgPath(mode, cwd) - destDir, err := resolveSourceDir(mode, cwd, kind) - if err != nil { - return err - } - return runTrashTUI(items, trashBase, destDir, cfgPath, modeLabel) - } - - // Plain text output (--no-tui or non-TTY) ui.Header("Trash") for _, item := range items { age := time.Since(item.Date) diff --git a/cmd/skillshare/trash_tui.go b/cmd/skillshare/trash_tui.go index aadd48457..6e1dc6e47 100644 --- a/cmd/skillshare/trash_tui.go +++ b/cmd/skillshare/trash_tui.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "sort" "strings" "time" @@ -33,9 +34,13 @@ func (i trashItem) Title() string { if i.selected { check = "[x]" } + var kindBadge string + if i.entry.Kind == "agent" { + kindBadge = tc.Cyan.Render("[A]") + " " + } age := formatAge(time.Since(i.entry.Date)) size := formatBytes(i.entry.Size) - return fmt.Sprintf("%s %s (%s, %s ago)", check, i.entry.Name, size, age) + return fmt.Sprintf("%s %s%s (%s, %s ago)", check, kindBadge, i.entry.Name, size, age) } func (i trashItem) Description() string { return "" } @@ -51,14 +56,16 @@ type trashOpDoneMsg struct { // trashTUIModel is the bubbletea model for the interactive trash viewer. type trashTUIModel struct { - list list.Model - modeLabel string // "global" or "project" - trashBase string - destDir string - cfgPath string - quitting bool - termWidth int - termHeight int + list list.Model + modeLabel string // "global" or "project" + skillTrashBase string // for reload after operations + agentTrashBase string // for reload after operations + destDir string // skill restore destination + agentDestDir string // agent restore destination + cfgPath string + quitting bool + termWidth int + termHeight int // All items (source of truth for filter + selection) allItems []trashItem @@ -90,7 +97,7 @@ type trashTUIModel struct { detailScroll int } -func newTrashTUIModel(items []trash.TrashEntry, trashBase, destDir, cfgPath, modeLabel string) trashTUIModel { +func newTrashTUIModel(items []trash.TrashEntry, skillTrashBase, agentTrashBase, destDir, agentDestDir, cfgPath, modeLabel string) trashTUIModel { allItems := make([]trashItem, len(items)) listItems := make([]list.Item, len(items)) for i, entry := range items { @@ -119,16 +126,18 @@ func newTrashTUIModel(items []trash.TrashEntry, trashBase, destDir, cfgPath, mod fi.Cursor.Style = tc.Filter return trashTUIModel{ - list: l, - modeLabel: modeLabel, - trashBase: trashBase, - destDir: destDir, - cfgPath: cfgPath, - allItems: allItems, - matchCount: len(allItems), - filterInput: fi, - selected: make(map[int]bool), - opSpinner: sp, + list: l, + modeLabel: modeLabel, + skillTrashBase: skillTrashBase, + agentTrashBase: agentTrashBase, + destDir: destDir, + agentDestDir: agentDestDir, + cfgPath: cfgPath, + allItems: allItems, + matchCount: len(allItems), + filterInput: fi, + selected: make(map[int]bool), + opSpinner: sp, } } @@ -492,9 +501,11 @@ func (m trashTUIModel) startOperation() (tea.Model, tea.Cmd) { } else { entries = m.selectedEntries() } - trashBase := m.trashBase destDir := m.destDir + agentDestDir := m.agentDestDir cfgPath := m.cfgPath + skillTrashBase := m.skillTrashBase + agentTrashBase := m.agentTrashBase cmd := func() tea.Msg { start := time.Now() @@ -505,8 +516,14 @@ func (m trashTUIModel) startOperation() (tea.Model, tea.Cmd) { case "restore": for _, entry := range entries { e := entry // copy for closure - if err := trash.Restore(&e, destDir); err != nil { - errMsgs = append(errMsgs, fmt.Sprintf("%s: %s", entry.Name, err)) + var restoreErr error + if e.Kind == "agent" { + restoreErr = trash.RestoreAgent(&e, agentDestDir) + } else { + restoreErr = trash.Restore(&e, destDir) + } + if restoreErr != nil { + errMsgs = append(errMsgs, fmt.Sprintf("%s: %s", entry.Name, restoreErr)) continue // don't stop — process remaining items } count++ @@ -530,8 +547,19 @@ func (m trashTUIModel) startOperation() (tea.Model, tea.Cmd) { // Log the operation logTrashOp(cfgPath, action, count, "", start, opErr) - // Reload items from disk - reloaded := trash.List(trashBase) + // Reload items from disk — merge skill + agent trash + var reloaded []trash.TrashEntry + for _, e := range trash.List(skillTrashBase) { + e.Kind = "skill" + reloaded = append(reloaded, e) + } + for _, e := range trash.List(agentTrashBase) { + e.Kind = "agent" + reloaded = append(reloaded, e) + } + sort.Slice(reloaded, func(i, j int) bool { + return reloaded[i].Date.After(reloaded[j].Date) + }) return trashOpDoneMsg{ action: action, count: count, @@ -799,8 +827,8 @@ func (m trashTUIModel) renderTrashDetailPanel(entry trash.TrashEntry, width int) // --------------------------------------------------------------------------- // runTrashTUI starts the bubbletea TUI for the trash viewer. -func runTrashTUI(items []trash.TrashEntry, trashBase, destDir, cfgPath, modeLabel string) error { - model := newTrashTUIModel(items, trashBase, destDir, cfgPath, modeLabel) +func runTrashTUI(items []trash.TrashEntry, skillTrashBase, agentTrashBase, destDir, agentDestDir, cfgPath, modeLabel string) error { + model := newTrashTUIModel(items, skillTrashBase, agentTrashBase, destDir, agentDestDir, cfgPath, modeLabel) p := tea.NewProgram(model, tea.WithAltScreen(), tea.WithMouseCellMotion()) _, err := p.Run() return err diff --git a/internal/trash/trash.go b/internal/trash/trash.go index bb9792091..b9956dd79 100644 --- a/internal/trash/trash.go +++ b/internal/trash/trash.go @@ -79,6 +79,7 @@ type TrashEntry struct { Path string // Full path to trashed directory Date time.Time // Parsed or stat-based date Size int64 // Total size in bytes + Kind string // "skill" or "agent" — set by caller } // MoveToTrash moves a skill directory to the trash.