From 53a6b53f5b395f4645112589c1b056210e3b6ca7 Mon Sep 17 00:00:00 2001 From: Andreas Spannagel Date: Mon, 16 Nov 2026 21:49:03 +0100 Subject: [PATCH] feat(ui): delete a session on an SSH connection d, and Delete in the row menu, on an agent under an SSH connection now asks, then runs `agent-manager delete` on its host, the call delete_session already makes. The host's delete, from #1045, removes the pane, the row, the terminals under the agent and a clean worktree with its am/ branch, so the confirm counts those terminals the way a local delete does. When the host keeps a worktree, the status line says the agent was deleted there and why the worktree stayed. A host older than v0.49.0 does not know delete and fails with the existing "too old" error. d on a remote terminal closes it, as x does, since the host's delete takes agents only. Deleting a group on a connection stays refused, and the refusal now names the group: the host's delete-group moves its sessions to the root instead of deleting them. Part of #876. --- docs/ssh-connections.md | 2 +- docs/usage.md | 4 +-- internal/remote/operations.go | 4 +-- internal/remote/operations_test.go | 3 ++ internal/ui/connections/call.go | 8 ++++-- internal/ui/connections/call_test.go | 4 +++ internal/ui/connections/link/call.go | 14 ++++++++- internal/ui/connections/link/call_test.go | 13 +++++++++ internal/ui/connections/rows.go | 11 ++++++- internal/ui/connections/rows_test.go | 4 +-- internal/ui/connections_adapter.go | 15 +++++++--- internal/ui/connections_adapter_test.go | 35 ++++++++++++++++++++++- internal/ui/help/catalog.go | 2 +- internal/ui/rail/hosts_test.go | 13 +++++++-- internal/ui/rail/legend.go | 3 ++ internal/ui/rail/legend_test.go | 14 +++++++++ internal/ui/rail/menu.go | 13 ++++----- tools/e2e/README.md | 4 +-- tools/e2e/ssh_scenarios.py | 9 +++++- 19 files changed, 145 insertions(+), 30 deletions(-) diff --git a/docs/ssh-connections.md b/docs/ssh-connections.md index ba7ed0a75..66a632e0e 100644 --- a/docs/ssh-connections.md +++ b/docs/ssh-connections.md @@ -75,7 +75,7 @@ The local machine can be Linux, macOS or Windows. The remote host must be Linux ## Not in scope These are refused on a remote row with a message naming the gap: -- Rename, move, delete, restart and fork. +- Rename, move, deleting a group, restart and fork. - Diff review. - The editor. - Copying a reply, marking idle, cancelling an after-turn end, reordering. diff --git a/docs/usage.md b/docs/usage.md index c80f435ac..493480161 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -438,10 +438,10 @@ The connection sits in the list after your own groups, in its own color with an On a connection's rows: - `enter` and `A` attach over SSH in this terminal; detaching returns to the manager. A remote pane is never embedded. - Quick prompt mode types into a remote agent's pane as you, the way it does on this machine, or starts a new agent on the CLI, model, effort and profile the bar shows when a connection or remote group is selected. `n` starts one there too; the directory and the worktree default are the other machine's unless you set them. -- `T` opens a terminal there and `g` creates a group there, under the selected one; `x` kills an agent or closes a terminal, `v` revives, `a` and `u` archive and restore. +- `T` opens a terminal there and `g` creates a group there, under the selected one; `x` kills an agent or closes a terminal, `v` revives, `a` and `u` archive and restore. `d` deletes an agent there the way it does here, its worktree included when clean, and asks first; on a terminal it closes it, like `x`. - On the connection row itself, `r` edits it and `d` removes it. Removing asks first; its sessions keep running on that host. -Rename, move, delete, restart, fork, review, the editor, copying a reply, reordering, marking idle, cancelling an after-turn end and kill all or revive all are refused on a remote row with a message naming the gap. A failed call shows the other machine's error. Nothing from a connection is written to this machine's store. See [SSH connections](ssh-connections.md) for the protocol. +Rename, move, deleting a group, restart, fork, review, the editor, copying a reply, reordering, marking idle, cancelling an after-turn end and kill all or revive all are refused on a remote row with a message naming the gap. A failed call shows the other machine's error. Nothing from a connection is written to this machine's store. See [SSH connections](ssh-connections.md) for the protocol. ## Status diff --git a/internal/remote/operations.go b/internal/remote/operations.go index 7089421f9..0c202f69d 100644 --- a/internal/remote/operations.go +++ b/internal/remote/operations.go @@ -225,8 +225,8 @@ func (c *Client) Kill(ctx context.Context, ref Ref) (sessioncmd.Session, error) return c.lifecycle(ctx, ref, []string{"kill", "--json"}) } -// Delete removes the session on its host, which refuses while its worktree -// holds unsaved work. +// Delete removes the session and the terminals under it on its host. A +// worktree with unsaved work stays there, and the notice says so. func (c *Client) Delete(ctx context.Context, ref Ref) (sessioncmd.Deletion, error) { var deleted sessioncmd.Deletion if err := validRef(ref); err != nil { diff --git a/internal/remote/operations_test.go b/internal/remote/operations_test.go index 836de7b7a..05813995d 100644 --- a/internal/remote/operations_test.go +++ b/internal/remote/operations_test.go @@ -323,6 +323,9 @@ func TestUnknownCommandIsTooOldNotUnreadable(t *testing.T) { if _, err := c.Type(context.Background(), Ref{Host: "gpu", ID: "a1"}, "yes"); err == nil || err.Error() != "gpu: agent-manager there is too old for SSH connections; update agent-manager on that host" { t.Fatalf("type on a host that predates it = %v", err) } + if _, err := c.Delete(context.Background(), Ref{Host: "gpu", ID: "a1"}); err == nil || err.Error() != "gpu: agent-manager there is too old for SSH connections; update agent-manager on that host" { + t.Fatalf("delete on a host that predates it = %v", err) + } c = newTestClient(t, func(context.Context, []string) ([]byte, []byte, error) { return []byte("closed terminal a1\n"), nil, nil }) diff --git a/internal/ui/connections/call.go b/internal/ui/connections/call.go index 826a24b0d..c716e6227 100644 --- a/internal/ui/connections/call.go +++ b/internal/ui/connections/call.go @@ -18,6 +18,7 @@ const ( OpRevive OpArchive OpRestore + OpDelete ) // Call is the lifecycle call a rail action makes on a remote session or @@ -42,7 +43,7 @@ type Call struct { var Refusals = map[uirail.ActionKind]string{ uirail.RenameAction: "rename", uirail.MoveToGroup: "move", - uirail.Delete: "delete", + uirail.Delete: "deleting a group", uirail.Restart: "restart", uirail.Fork: "fork", uirail.OpenReview: "review", @@ -67,6 +68,7 @@ var confirm = map[Op]struct { OpRevive: {uidialogs.ConfirmRevive, "revive", ""}, OpArchive: {uidialogs.ConfirmArchive, "archive", ""}, OpRestore: {uidialogs.ConfirmRestore, "restore", ""}, + OpDelete: {uidialogs.ConfirmDelete, "delete", ""}, } // KeyHint fills format with the list key bound to action, and is empty while @@ -88,8 +90,10 @@ func SessionCall(row Row, kind uirail.ActionKind, hint KeyHint) Call { return Call{Op: OpAttach, Answered: true} case row.Terminal && (kind == uirail.Revive || kind == uirail.Archive || kind == uirail.Restore): return Call{Refusal: "a terminal on " + row.Host + " is not archived or revived" + hint(keybind.Kill, " - %s closes it"), Answered: true} - case kind == uirail.Kill && row.Terminal: + case (kind == uirail.Kill || kind == uirail.Delete) && row.Terminal: return asking(OpCloseTerminal, false, hint) + case kind == uirail.Delete: + return asking(OpDelete, false, hint) case kind == uirail.Kill: return asking(OpKill, row.Status == "dead", hint) case kind == uirail.Revive: diff --git a/internal/ui/connections/call_test.go b/internal/ui/connections/call_test.go index f951cf339..82990771b 100644 --- a/internal/ui/connections/call_test.go +++ b/internal/ui/connections/call_test.go @@ -26,6 +26,10 @@ func TestSessionCallAnswersEveryRemoteAction(t *testing.T) { Call{Op: OpKill, Dead: true, Answered: true, Action: uidialogs.ConfirmKill, Verb: "kill"}}, {"a terminal kill closes it", Row{Kind: SessionRow, Host: "box", Name: "sh", Terminal: true}, uirail.Kill, Call{Op: OpCloseTerminal, Answered: true, Action: uidialogs.ConfirmKill, Verb: "close terminal"}}, + {"delete asks without a revive", row, uirail.Delete, + Call{Op: OpDelete, Answered: true, Action: uidialogs.ConfirmDelete, Verb: "delete"}}, + {"a terminal delete closes it", Row{Kind: SessionRow, Host: "box", Name: "sh", Terminal: true}, uirail.Delete, + Call{Op: OpCloseTerminal, Answered: true, Action: uidialogs.ConfirmKill, Verb: "close terminal"}}, {"revive", row, uirail.Revive, Call{Op: OpRevive, Answered: true, Action: uidialogs.ConfirmRevive, Verb: "revive"}}, {"archive an unarchived row", row, uirail.Archive, diff --git a/internal/ui/connections/link/call.go b/internal/ui/connections/link/call.go index a9000f6ac..d8c99c6f6 100644 --- a/internal/ui/connections/link/call.go +++ b/internal/ui/connections/link/call.go @@ -20,6 +20,7 @@ const ( Archive Restore CreateGroup + Delete ) type Call struct { @@ -43,9 +44,10 @@ type Call struct { } // Result is what a call returned: the session or terminal it made or -// changed. +// changed, and why a deleted session's worktree stayed on the host. type Result struct { Session sessioncmd.Session + Notice string } func Run(ctx context.Context, client *remote.Client, openers remote.Openers, call Call) (Result, error) { @@ -64,6 +66,10 @@ func Run(ctx context.Context, client *remote.Client, openers remote.Openers, cal result.Session, err = client.Kill(ctx, call.Ref) case CloseTerminal: err = client.Terminals(openers).CloseForUser(ctx, call.Ref) + case Delete: + var deleted sessioncmd.Deletion + deleted, err = client.Delete(ctx, call.Ref) + result.Session, result.Notice = deleted.Session, deleted.Notice case Revive: result.Session, err = client.Revive(ctx, call.Ref) case Archive, Restore: @@ -100,6 +106,12 @@ func (s *State) ApplyCall(root Root, call Call, result Result, err error) tea.Cm root.ReportDone("opened terminal " + result.Session.Name + on) case Kill, CloseTerminal: root.ReportDone("killed " + call.Name + on) + case Delete: + if result.Notice != "" { + root.ReportErr("deleted " + call.Name + on + "; " + result.Notice) + } else { + root.ReportDone("deleted " + call.Name + on) + } case Revive: root.ReportDone("revived " + call.Name + on) case Archive: diff --git a/internal/ui/connections/link/call_test.go b/internal/ui/connections/link/call_test.go index a822aa279..fb6ada6e6 100644 --- a/internal/ui/connections/link/call_test.go +++ b/internal/ui/connections/link/call_test.go @@ -15,6 +15,7 @@ func TestRunTurnsEachCallIntoItsHostCommand(t *testing.T) { }{ {Type, []string{"type", "--json", "--", "s1", "hello"}}, {Kill, []string{"kill", "--json", "--", "s1"}}, + {Delete, []string{"delete", "--json", "--", "s1"}}, {Revive, []string{"revive", "--json", "--", "s1"}}, {Archive, []string{"archive", "--json", "--", "s1"}}, {Restore, []string{"archive", "--restore", "--json", "--", "s1"}}, @@ -86,6 +87,18 @@ func TestASpawnFromTheFormClosesItAndAQuickSpawnClearsTheBar(t *testing.T) { } } +// A delete whose worktree stayed on the host says so with the delete, on +// the host it happened, since the row stays until the next refresh. +func TestADeleteReportsTheHostsNotice(t *testing.T) { + state := listedState(t, &ssh{}) + call := Call{Op: Delete, Host: "box", Ref: remote.Ref{Host: "box", ID: "s1"}, Name: "api"} + root := &recorder{} + state.ApplyCall(root, call, Result{Notice: "worktree kept (has work): /srv/wt/api"}, nil) + if want := []string{"deleted api on box; worktree kept (has work): /srv/wt/api"}; !equal(root.errs, want) || len(root.done) != 0 { + t.Fatalf("done %q errors %q, want errors %q", root.done, root.errs, want) + } +} + func equal(left, right []string) bool { if len(left) != len(right) { return false diff --git a/internal/ui/connections/rows.go b/internal/ui/connections/rows.go index 61f87a029..49ceffeb1 100644 --- a/internal/ui/connections/rows.go +++ b/internal/ui/connections/rows.go @@ -29,6 +29,9 @@ type Row struct { Status string Terminal bool Archived bool + // Terminals counts the host's terminals nested under an agent, which + // its delete takes with it. + Terminals int } // Row finds the target's row; an agent or terminal the last snapshot does @@ -41,7 +44,13 @@ func (c *Connections) Row(target Target) (Row, bool) { host := c.hosts[target.Host] for _, sess := range host.Sessions { if sess.ID == target.ID { - return row.of(sess, false), true + row = row.of(sess, false) + for _, term := range host.Terminals { + if term.ParentID == sess.ID { + row.Terminals++ + } + } + return row, true } } for _, term := range host.Terminals { diff --git a/internal/ui/connections/rows_test.go b/internal/ui/connections/rows_test.go index 236fe54b5..4f5939553 100644 --- a/internal/ui/connections/rows_test.go +++ b/internal/ui/connections/rows_test.go @@ -12,10 +12,10 @@ func TestRowFindsAgentsAndTerminals(t *testing.T) { c.Refreshed("box", c.Gen(), Host{ OK: true, Sessions: []Session{{ID: "s1", Name: "api", Group: "web", Status: "idle"}}, - Terminals: []Session{{ID: "t1", Name: "sh", Group: "web", Archived: true}}, + Terminals: []Session{{ID: "t1", Name: "sh", Group: "web", Archived: true}, {ID: "t2", Name: "api-sh", Group: "web", ParentID: "s1"}, {ID: "t3", Name: "api-log", Group: "web", ParentID: "s1", Archived: true}}, }) agent, ok := c.Row(Target{Kind: SessionRow, Host: "box", ID: "s1"}) - if !ok || agent.Terminal || agent.Ref != (remote.Ref{Host: "box", ID: "s1"}) || agent.Name != "api" || agent.Group != "web" { + if !ok || agent.Terminal || agent.Ref != (remote.Ref{Host: "box", ID: "s1"}) || agent.Name != "api" || agent.Group != "web" || agent.Terminals != 2 { t.Fatalf("agent row = %+v, %v", agent, ok) } term, ok := c.Row(Target{Kind: SessionRow, Host: "box", ID: "t1"}) diff --git a/internal/ui/connections_adapter.go b/internal/ui/connections_adapter.go index 0c4635c35..1320f9b72 100644 --- a/internal/ui/connections_adapter.go +++ b/internal/ui/connections_adapter.go @@ -93,7 +93,7 @@ func (m *Model) remoteSessionIntent(row uiconnections.Row, call uiconnections.Ca request := remoteCall(row.Host, row.Ref, row.Name) request.Op = remoteOp[call.Op] request.Dead = call.Dead - return m.confirmRemote(request, call), true + return m.confirmRemote(request, call, row.Terminals), true } // remoteOp is the call a remote row's lifecycle op makes. @@ -103,17 +103,24 @@ var remoteOp = map[uiconnections.Op]uilink.Op{ uiconnections.OpRevive: uilink.Revive, uiconnections.OpArchive: uilink.Archive, uiconnections.OpRestore: uilink.Restore, + uiconnections.OpDelete: uilink.Delete, } // confirmRemote asks before a lifecycle call goes to the host; an offline -// host refuses before the question. -func (m *Model) confirmRemote(request uilink.Call, call uiconnections.Call) tea.Cmd { +// host refuses before the question. A delete there takes the terminals under +// the agent, and names them as a local delete does. +func (m *Model) confirmRemote(request uilink.Call, call uiconnections.Call, terminals int) tea.Cmd { if refusal, offline := m.ssh.Offline(request.Host); offline { m.reportErr(refusal) return nil } + subject := presentation.EscapeControlsInline(request.Name + " on " + request.Host) + label := call.Verb + " " + subject + "?" + call.Consequence + if call.Op == uiconnections.OpDelete { + label = uisession.FollowConfirmLabel(call.Verb, subject, terminals, "kills its tmux session there.", "kills their tmux sessions there.") + } m.openConfirm(confirmTarget{ - prompt: uidialogs.Confirm{Action: call.Action, Label: call.Verb + " " + presentation.EscapeControlsInline(request.Name+" on "+request.Host+"?") + call.Consequence}, + prompt: uidialogs.Confirm{Action: call.Action, Label: label}, remote: &request, }) return nil diff --git a/internal/ui/connections_adapter_test.go b/internal/ui/connections_adapter_test.go index bdb3420b5..64c287bef 100644 --- a/internal/ui/connections_adapter_test.go +++ b/internal/ui/connections_adapter_test.go @@ -65,6 +65,9 @@ func TestRemoteActionsBuildTheirRemoteCall(t *testing.T) { }{ {"kill an agent", boxSession("s1"), uirail.Kill, []string{"kill", "--json", "--", "s1"}, "killed api on box"}, {"kill a terminal closes it", boxSession("t1"), uirail.Kill, []string{"terminal", "close", "--", "t1"}, "killed sh on box"}, + {"delete an agent", boxSession("s1"), uirail.Delete, []string{"delete", "--json", "--", "s1"}, "deleted api on box"}, + {"delete an archived agent", boxSession("s3"), uirail.Delete, []string{"delete", "--json", "--", "s3"}, "deleted shelved on box"}, + {"delete a terminal closes it", boxSession("t1"), uirail.Delete, []string{"terminal", "close", "--", "t1"}, "killed sh on box"}, {"revive", boxSession("s2"), uirail.Revive, []string{"revive", "--json", "--", "s2"}, "revived old on box"}, {"archive", boxSession("s1"), uirail.Archive, []string{"archive", "--json", "--", "s1"}, "archived api on box"}, {"restore", boxSession("s3"), uirail.Restore, []string{"archive", "--restore", "--json", "--", "s3"}, "restored shelved on box"}, @@ -116,7 +119,7 @@ func TestRemoteActionsAlreadyInPlaceDoNothing(t *testing.T) { func TestUnsupportedRemoteActionsAreRefusedWithoutIO(t *testing.T) { refused := map[uirail.ActionKind]string{ - uirail.RenameAction: "rename", uirail.MoveToGroup: "move", uirail.Delete: "delete", + uirail.RenameAction: "rename", uirail.MoveToGroup: "move", uirail.Restart: "restart", uirail.Fork: "fork", uirail.OpenReview: "review", uirail.OpenEditor: "the editor", uirail.CopyReply: "copy reply", uirail.MarkIdle: "mark idle", uirail.CancelEnd: "cancel end", uirail.KillAll: "kill all", @@ -140,6 +143,10 @@ func TestUnsupportedRemoteActionsAreRefusedWithoutIO(t *testing.T) { t.Fatalf("kill on %+v: status %q", target, m.errBar.text) } } + m.clearErr() + if _, cmd := m.runRailIntent(uirail.Intent{Kind: uirail.Delete, Target: boxGroup}); cmd != nil || confirmOpen(m) || m.errBar.text != "deleting a group isn't available on SSH connections yet" { + t.Fatalf("delete on a remote group: status %q", m.errBar.text) + } if calls := fake.taken(); len(calls) != 0 { t.Fatalf("calls = %q, want none", calls) } @@ -346,6 +353,32 @@ func TestRemoteLifecycleAsksFirstAndNoSendsNothing(t *testing.T) { } } +// The host's delete takes the terminals nested under the agent, archived +// ones too, so its confirm counts them the way a local delete does. +func TestRemoteDeleteConfirmCountsTheTerminalsItTakes(t *testing.T) { + fake := &fakeSSH{} + m := listedModel(t, fake) + fake.snapshot.Terminals = append(fake.snapshot.Terminals, + sessioncmd.Terminal{ID: "t2", Name: "api-sh", Group: "web", Status: "idle", Running: true, ParentID: "s1"}, + sessioncmd.Terminal{ID: "t3", Name: "api-log", Group: "web", Status: "dead", ParentID: "s1", Archived: true}, + sessioncmd.Terminal{ID: "t4", Name: "shelved-sh", Group: "web", Status: "dead", ParentID: "s3", Archived: true}) + setHost(m, "box", uilink.Facts(remote.HostState{OK: true, Snapshot: fake.snapshot})) + for id, want := range map[string]string{ + "s1": "delete api on box and 2 terminals? kills their tmux sessions there.", + "s2": "delete old on box? kills its tmux session there.", + "s3": "delete shelved on box and 1 terminal? kills their tmux sessions there.", + } { + m.runRailIntent(uirail.Intent{Kind: uirail.Delete, Target: boxSession(id)}) + if !confirmOpen(m) || pendingConfirm(m).prompt.Label != want { + t.Fatalf("delete %s: label %q, want %q", id, pendingConfirm(m).prompt.Label, want) + } + m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("n")}) + } + if calls := fake.taken(); len(calls) != 0 { + t.Fatalf("calls before an answer = %q", calls) + } +} + func TestQuickBarRefusesWhenARefreshDropsItsRemoteTarget(t *testing.T) { fake := &fakeSSH{} m := connectedModel(t, fake) diff --git a/internal/ui/help/catalog.go b/internal/ui/help/catalog.go index fbe37118d..fa1c90da7 100644 --- a/internal/ui/help/catalog.go +++ b/internal/ui/help/catalog.go @@ -135,7 +135,7 @@ func connectionRowHelpRows(list keybind.Table, mode presentation.GlyphMode) [][2 h.action("edit its name and SSH destination", keybind.Rename) h.action("remove it; its sessions keep running on that host", keybind.Delete) h.action("new session or terminal on that host", keybind.NewSession, keybind.Terminal) - h.fixed("", "its sessions: attach, quick prompt, kill, revive, archive, restore") + h.fixed("", "its agents: attach, prompt, kill, revive, archive, restore, delete") h.fixed("", "attach opens an SSH attach in this terminal") return h.rows } diff --git a/internal/ui/rail/hosts_test.go b/internal/ui/rail/hosts_test.go index c5f3b88ca..798158fd6 100644 --- a/internal/ui/rail/hosts_test.go +++ b/internal/ui/rail/hosts_test.go @@ -233,12 +233,12 @@ func TestConnectionMenusOfferOnlyRemoteActions(t *testing.T) { t.Errorf("connection menu = %v", got) } session := labels(Selection{Kind: SessionRow, SessionID: "far", Host: "box"}) - for _, refused := range []string{"Rename", "Move to group", "Fork", "Review changes", "Open in editor", "Restart", "Delete"} { + for _, refused := range []string{"Rename", "Move to group", "Fork", "Review changes", "Open in editor", "Restart"} { if slices.Contains(session, refused) { t.Errorf("remote session menu offers %s: %v", refused, session) } } - if !slices.Contains(session, "Kill") || !slices.Contains(session, "Attach") { + if !slices.Contains(session, "Kill") || !slices.Contains(session, "Attach") || !slices.Contains(session, "Delete") { t.Errorf("remote session menu = %v", session) } // The host archives and revives agents only. @@ -248,6 +248,15 @@ func TestConnectionMenusOfferOnlyRemoteActions(t *testing.T) { if got := labels(Selection{Kind: GroupRow}); !slices.Contains(got, "New connection") { t.Errorf("root menu = %v, want New connection", got) } + model.Reconcile(Snapshot{Hosts: []Host{{Name: "box", State: HostOnline, Sessions: []Session{{ID: "far", Name: "far", Tool: "claude", Status: "dead"}}}}}) + if got := labels(Selection{Kind: SessionRow, SessionID: "far", Host: "box"}); !slices.Equal(got, []string{"Revive", "Archive", "Delete"}) { + t.Errorf("dead remote session menu = %v, want Revive, Archive and Delete", got) + } + model.SetArchived(true) + model.Reconcile(Snapshot{Hosts: []Host{{Name: "box", State: HostOnline, Sessions: []Session{{ID: "far", Name: "far", Tool: "claude", Status: "dead", Archived: true}}}}}) + if got := labels(Selection{Kind: SessionRow, SessionID: "far", Host: "box"}); !slices.Equal(got, []string{"Restore", "Delete"}) { + t.Errorf("archived remote session menu = %v, want Restore and Delete", got) + } } func TestHostFoldsFollowTheirConnection(t *testing.T) { diff --git a/internal/ui/rail/legend.go b/internal/ui/rail/legend.go index 5b644c207..9c98fcda7 100644 --- a/internal/ui/rail/legend.go +++ b/internal/ui/rail/legend.go @@ -290,6 +290,9 @@ func (m Model) RemoteLegend(ctx LegendContext, row RemoteRow, collapsed bool) Le title, kill, leads = "Shell", "close", nil } pairs := [][2]string{{k(keybind.Open, keybind.Attach), "attach over SSH"}, {k(keybind.Kill), kill}} + if !row.Terminal { + pairs = append(pairs, [2]string{k(keybind.Delete), "delete"}) + } if row.Dead { pairs = append(pairs, [2]string{k(keybind.Revive), "revive"}) } diff --git a/internal/ui/rail/legend_test.go b/internal/ui/rail/legend_test.go index 8e6817825..305a97c4c 100644 --- a/internal/ui/rail/legend_test.go +++ b/internal/ui/rail/legend_test.go @@ -70,3 +70,17 @@ func TestRootLegendOnlyOffersApplicableActions(t *testing.T) { } } } + +func TestRemoteLegendOffersDeleteOnAnAgentOnly(t *testing.T) { + model := rail.New(nil) + ctx := rail.LegendContext{ListKeys: keybind.DefaultList()} + agent := model.RemoteLegend(ctx, rail.RemoteRow{Kind: rail.SessionRow, Host: "box"}, false) + if !slices.Contains(agent.Pairs, [2]string{"d", "delete"}) { + t.Fatalf("a remote agent should offer delete, got %+v", agent.Pairs) + } + // d on a shell closes it, which x already offers. + shell := model.RemoteLegend(ctx, rail.RemoteRow{Kind: rail.SessionRow, Host: "box", Terminal: true}, false) + if slices.Contains(shell.Pairs, [2]string{"d", "delete"}) { + t.Fatalf("a remote shell should leave delete to close, got %+v", shell.Pairs) + } +} diff --git a/internal/ui/rail/menu.go b/internal/ui/rail/menu.go index 4bc3b0d19..f607d04b6 100644 --- a/internal/ui/rail/menu.go +++ b/internal/ui/rail/menu.go @@ -114,8 +114,9 @@ func remoteMenuItems(row treeRow, create []menuItem, connection menuItem) []menu case GroupRow: return append(create, group) } + remove := menuItem{label: "Delete", action: Delete, danger: true} if row.sess.Archived { - return []menuItem{{label: "Restore", action: Restore}} + return []menuItem{{label: "Restore", action: Restore}, remove} } kill := menuItem{label: "Kill", action: Kill, danger: true} if row.sess.IsShell { @@ -127,16 +128,12 @@ func remoteMenuItems(row treeRow, create []menuItem, connection menuItem) []menu } archive := menuItem{label: "Archive", action: Archive} if row.sess.Status == "dead" { - return menuSections([]menuItem{{label: "Revive", action: Revive}}, []menuItem{archive}) - } - var agent []menuItem - if !row.sess.IsShell { - agent = []menuItem{{label: "Quick prompt mode", action: Prompt}, {label: "New terminal", action: NewTerminal}} + return menuSections([]menuItem{{label: "Revive", action: Revive}}, []menuItem{archive, remove}) } return menuSections( []menuItem{{label: "Attach", action: Attach}}, - agent, - []menuItem{archive, kill}, + []menuItem{{label: "Quick prompt mode", action: Prompt}, {label: "New terminal", action: NewTerminal}}, + []menuItem{archive, kill, remove}, ) } diff --git a/tools/e2e/README.md b/tools/e2e/README.md index 363c80f88..3b124cb79 100644 --- a/tools/e2e/README.md +++ b/tools/e2e/README.md @@ -164,6 +164,6 @@ or the Linux/SSH platform matrix. python3 tools/e2e/ssh_scenarios.py --binary /tmp/agent-manager-e2e ``` -A fixture `ssh` first on PATH drops every argument but the remote command and runs it with `/bin/sh -c` under a second disposable HOME and its own short tmux socket directory, so the "host" is a real agent-manager with its own profile and no network, keys or `~/.ssh`. A copy of the binary, first on PATH at a path unique to the run, serves both sides. The scenario seeds an agent on the host through its CLI, adds the connection through the `C` dialog, waits for the remote row, answers it from the quick bar and checks the prompt reached the host's pane with nothing queued in its inbox, kills it and checks its tmux session is gone on the host, and requires that the local store holds the connection and no sessions. A second connection whose ssh fails shows as unreachable. The first refresh starts the host's headless manager. +A fixture `ssh` first on PATH drops every argument but the remote command and runs it with `/bin/sh -c` under a second disposable HOME and its own short tmux socket directory, so the "host" is a real agent-manager with its own profile and no network, keys or `~/.ssh`. A copy of the binary, first on PATH at a path unique to the run, serves both sides. The scenario seeds an agent on the host through its CLI, adds the connection through the `C` dialog, waits for the remote row, answers it from the quick bar and checks the prompt reached the host's pane with nothing queued in its inbox, kills it and checks its tmux session is gone on the host. It then revives, archives and restores it, deletes a second agent and checks the host's store no longer has it, attaches to the first and detaches, and starts an agent, a terminal and a group there. It requires that the local store holds the connection and no sessions. A second connection whose ssh fails shows as unreachable. The first refresh starts the host's headless manager. -Cleanup ends every process by PID: the binary copy's processes (the host's `serve` among them) and the tmux servers on the run's own sockets, listed in `ended-processes.json`. No `kill-server` is sent. Attach needs a terminal on both sides and is left to the unit tests, which check the SSH command it builds. +Cleanup ends every process by PID: the binary copy's processes (the host's `serve` among them) and the tmux servers on the run's own sockets, listed in `ended-processes.json`. No `kill-server` is sent. diff --git a/tools/e2e/ssh_scenarios.py b/tools/e2e/ssh_scenarios.py index 5a8fdfd8e..879ec3980 100644 --- a/tools/e2e/ssh_scenarios.py +++ b/tools/e2e/ssh_scenarios.py @@ -6,7 +6,7 @@ to a real agent-manager "host" without a network or the user's ~/.ssh. The scenario adds a connection through the dialog and drives every action a remote row offers: preview, quick send, kill, revive, archive, restore, -attach, quick spawn and a new terminal. A second connection whose host +delete, attach, quick spawn and a new terminal. A second connection whose host refuses shows as unreachable and is removed. Every process it started is ended by PID. """ import argparse @@ -255,6 +255,13 @@ def lifecycle(sandbox, remote, agent_id): key(sandbox, 't') frame(sandbox, 'active-view', f'{CONNECTION} ssh', 'ARCHIVED') + select(sandbox, 'grouped-agent', f'{GROUPED_AGENT} on {CONNECTION}') + key(sandbox, 'd') + confirm(sandbox, 'remote-delete', f'delete {GROUPED_AGENT} on {CONNECTION}?', + f'deleted {GROUPED_AGENT} on {CONNECTION}') + sandbox.wait('remote-deleted', lambda: str(remote.query(f"SELECT id FROM sessions WHERE name = '{GROUPED_AGENT}'")), + lambda value: value == '[]') + def attach(sandbox, remote, agent_id): """Attach runs ssh -t in this terminal; the remote pane fills it until detach."""