Skip to content

mission control for agent skills

feat(tui): add action to delete broken symlinks

panudetjt0028d6ac619b
diff --git a/internal/actions/actions.go b/internal/actions/actions.go
index 9ac6a66..5f9e176 100644
--- a/internal/actions/actions.go
+++ b/internal/actions/actions.go
@@ -207,6 +207,9 @@ func ForSkillWithResolver(sk *model.Skill, resolve SkillsResolver) []CommandPrev
if hasOrphanedLock(sk) {
previews = append(previews, pruneLockPreview(sk))
}
+ if hasBrokenSymlink(sk) {
+ previews = append(previews, deleteBrokenSymlinkPreview(sk))
+ }
return previews
}
@@ -242,6 +245,44 @@ func pruneLockPreview(sk *model.Skill) CommandPreview {
}
}
+// brokenSymlinkPaths returns the on-disk paths of this skill's broken
+// (dangling) symlinks.
+func brokenSymlinkPaths(sk *model.Skill) []string {
+ if sk == nil {
+ return nil
+ }
+ var paths []string
+ for _, op := range sk.ObservedPaths {
+ if op.Status == model.StatusBrokenSymlink {
+ paths = append(paths, op.Path)
+ }
+ }
+ return paths
+}
+
+func hasBrokenSymlink(sk *model.Skill) bool {
+ return len(brokenSymlinkPaths(sk)) > 0
+}
+
+// deleteBrokenSymlinkPreview builds the internal action that deletes the
+// broken/dangling symlink files for a skill. The TUI owns the filesystem
+// mutation and triggers a rescan afterwards. ONLY broken symlinks are ever
+// deleted — never working symlinks or canonical skill files.
+func deleteBrokenSymlinkPreview(sk *model.Skill) CommandPreview {
+ return CommandPreview{
+ ID: "delete_broken_symlink",
+ Title: "Delete broken symlink(s)",
+ Description: "Delete the broken/dangling symlink file(s) for this skill.",
+ Command: "delete broken symlinks for " + compat.SanitizeMetadata(sk.Name),
+ Exec: ExecSpec{Internal: "delete_broken_symlink"},
+ Mutates: true,
+ RequiresConfirm: true,
+ Dangerous: true,
+ ConfirmValue: sk.Name,
+ Available: true,
+ }
+}
+
func openEditorAction(sk *model.Skill) (CommandPreview, bool, string) {
editor := os.Getenv("EDITOR")
if editor == "" {
diff --git a/internal/actions/actions_test.go b/internal/actions/actions_test.go
index 452bb6f..46b7e33 100644
--- a/internal/actions/actions_test.go
+++ b/internal/actions/actions_test.go
@@ -43,6 +43,52 @@ func TestForSkillPruneLockAction(t *testing.T) {
}
}
+func TestDeleteBrokenSymlinkAction(t *testing.T) {
+ // Skill with a broken symlink should include delete_broken_symlink.
+ withBroken := &model.Skill{
+ Name: "broken-skill",
+ Scope: model.ScopeProject,
+ ObservedPaths: []model.ObservedPath{
+ {Path: "/tmp/link-to-nowhere", Status: model.StatusBrokenSymlink, TargetPath: "/tmp/gone"},
+ {Path: "/tmp/working-link", Status: model.StatusSymlink, TargetPath: "/tmp/real"},
+ },
+ }
+ previews := ForSkill(withBroken)
+ var deleteAct *CommandPreview
+ for i := range previews {
+ if previews[i].ID == "delete_broken_symlink" {
+ deleteAct = &previews[i]
+ }
+ }
+ if deleteAct == nil {
+ t.Fatal("expected a delete_broken_symlink action for skill with broken symlink")
+ }
+ if !deleteAct.Available || !deleteAct.Dangerous || !deleteAct.RequiresConfirm {
+ t.Fatalf("expected dangerous+confirm action: %+v", *deleteAct)
+ }
+ if deleteAct.ConfirmValue != "broken-skill" || deleteAct.Exec.Internal != "delete_broken_symlink" {
+ t.Fatalf("unexpected delete preview: %+v", *deleteAct)
+ }
+ if !strings.Contains(deleteAct.Title, "broken symlink") {
+ t.Fatalf("expected title to mention broken symlinks, got %q", deleteAct.Title)
+ }
+
+ // Skill WITHOUT any broken symlink should NOT include delete_broken_symlink.
+ healthy := &model.Skill{
+ Name: "ok",
+ Scope: model.ScopeProject,
+ ObservedPaths: []model.ObservedPath{
+ {Path: "/tmp/working-link", Status: model.StatusSymlink, TargetPath: "/tmp/real"},
+ },
+ CanonicalPath: "/tmp/ok",
+ }
+ for _, a := range ForSkill(healthy) {
+ if a.ID == "delete_broken_symlink" {
+ t.Fatal("did not expect delete_broken_symlink action for a healthy skill")
+ }
+ }
+}
+
func TestForSkillBuildsStructuredSanitizedCommandPreviews(t *testing.T) {
t.Setenv("EDITOR", "")
sk := &model.Skill{
diff --git a/internal/tui/update.go b/internal/tui/update.go
index b054fd8..e8f0484 100644
--- a/internal/tui/update.go
+++ b/internal/tui/update.go
@@ -1030,6 +1030,48 @@ func (m appModel) executeAction(action actions.CommandPreview) (tea.Model, tea.C
m.actionResult = nil
return m, loadSnapshot(m.cwd)
}
+ if action.Exec.Internal == "delete_broken_symlink" {
+ m.commands = false
+ m.confirming = false
+ m.confirmInput = ""
+ m.confirmError = ""
+ removed, failed := 0, 0
+ firstErr := ""
+ for _, sk := range m.result.Skills {
+ if sk.Name != action.ConfirmValue {
+ continue
+ }
+ for _, op := range sk.ObservedPaths {
+ if op.Status != model.StatusBrokenSymlink {
+ continue // safety: never touch working symlinks or canonical files
+ }
+ if err := os.Remove(op.Path); err != nil {
+ if os.IsNotExist(err) {
+ continue
+ }
+ failed++
+ if firstErr == "" {
+ firstErr = err.Error()
+ }
+ continue
+ }
+ removed++
+ }
+ break
+ }
+ if failed > 0 {
+ m.actionResult = &runner.Result{
+ Program: "delete-broken-symlink",
+ Args: []string{action.ConfirmValue},
+ ExitCode: -1,
+ Err: fmt.Sprintf("removed %d broken symlink(s), %d failed: %s", removed, failed, compat.SanitizeMetadata(firstErr)),
+ }
+ m.syncViewport()
+ return m, nil
+ }
+ m.actionResult = nil
+ return m, loadSnapshot(m.cwd)
+ }
if action.Exec.Internal == "refresh" {
m.actionResult = nil
return m, loadSnapshot(m.cwd)