Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ the arrows keep working inside `claude`.
| `↵` | open / attach |
| `n` | new session |
| `a` | add project |
| `e` | rename the focused project or session |
| `e` | edit the focused project, or a session's title and agent |
| `x` | end session — close and keep the worktree, or delete both. In the session view, `x` on a running agent only stops it, and a second `x` ends the session |
| `c` | connect this session to one on another project |
| `K` / `J`, or `⇧↑` / `⇧↓` | move the selected session up / down its project's list |
Expand All @@ -140,8 +140,8 @@ ssh -t <host> 'tmux new -A -s deck deck'

`x` and `c` act on the selected session, so they need the sessions column to
have focus — `tab` or a click moves it there, and the focused column carries
the accent border. `e` reads the same focus and renames whichever of the two
the cursor is on. `↵` opens from either column.
the accent border. `e` reads the same focus and edits whichever of the two the
cursor is on. `↵` opens from either column.

The mouse works on the dashboard. A click on a project or a session puts the
cursor and the focus on it, and a second click on the same row opens it, as
Expand Down Expand Up @@ -169,7 +169,7 @@ its worktree belongs to that project's repository.
| `^g K` / `^g J` | move this session up / down its project's list |
| `^g` and a number | jump straight to that session |
| `^g n` | new session |
| `^g e` | rename this session |
| `^g e` | edit this session: its title and agent |
| `^g x` | stop the agent, or end a stopped session as `x` does |
| `^g esc` | detach from the pane |
| `^g ↵` | attach to the pane |
Expand Down Expand Up @@ -264,10 +264,21 @@ the Agent field with its four choices](assets/deck-new-session.png)

The new-session form has an **Agent** field — `claude`, `cathode`, `codex`,
`gemini` — and the last choice becomes the default for the next session. Each
session remembers what it started, so changing the default never relabels a
session that is already running. `-agent` overrides the default for one run and
session remembers its own agent, so changing the default never changes a
session that already exists. `-agent` overrides the default for one run and
takes any program that talks to a terminal, listed or not.

A session can switch agent later. Its `e` form has the same **Agent** field, and
the new agent runs from the session's next start; one already running keeps
going, and keeps its name in the session's bar, until it is stopped. When an
agent exits — you quit it, or it crashed — `↵` on the session opens the agent
list on that agent: `↵` again restarts it, and choosing another starts that one
instead and keeps it for the session, once it has started. The worktree, branch
and title stay the same. Starting `claude` in an isolated session continues the
latest `claude` conversation in that worktree, and cathode's backend writes its
conversations there too, so after a switch from `cathode` that may be the one
cathode was having.

Only `claude` reports exact turn status, and only `claude` and `cathode` are
handed a coordination config. Anything else runs perfectly well in a pane, with
status inferred from output and no sibling awareness.
Expand Down
30 changes: 22 additions & 8 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ That split is why the agent is a **choice, not a build-time decision**:
`claude`, `cathode`, `codex`, `gemini`, or anything else that talks to a
terminal works unchanged.

Each session records the program it started (`store.Session.Agent`), and the
new-session form picks it. That is what keeps a running session honestly
labelled after the default changes, and it is why nothing reads the agent from
the model at attach time. `settings.Agent` remembers the last choice as the
Each session records the program it starts (`store.Session.Agent`). The
new-session form picks it, and the session's edit form and the list `↵` opens on
an exited agent change it. It is read when the agent starts, never from the
model's default, which is what keeps one session's program independent of the
next form's choice. What is in the pane is labelled from the runner
(`Runner.Command`), not from the record: a switch made while an agent runs waits
for the next start, and until then the record names the next program and the
runner names the current one. `settings.Agent` remembers the last choice as the
default for the next form; `-agent` overrides it for one run and is the way to
name a program the form does not list. A session recorded before the field
existed is filled in once by `store.Load`, so no reader has to guess.
Expand Down Expand Up @@ -388,8 +392,11 @@ relative path finds the same file.

That check runs as a command off the UI's goroutine, bounded by
`versionTimeout`, plus `WaitDelay` for a wrapper's child that still holds the
output pipe. The timeout kills the process it started, not that process's own
children. A failure is shown with the first line `claude` wrote to stderr, and a
output pipe. A process that printed and exited 0 has answered (`answered`),
even when the read ends in an error: that child's open pipe, or a timeout that
fires as the process exits, before it is collected. The timeout kills the
process it started, not that process's own children. A failure is shown with
the first line `claude` wrote to stderr, and a
timeout says so rather than reading as a crash. The answer replaces the notice
only if that notice is still the one from the same start, counted by
`Model.starts`, because two starts in one directory set identical notices. It
Expand Down Expand Up @@ -1019,8 +1026,15 @@ every later key went to the agent, which never clears the fault line, so it
stayed on screen.

The pane says what to do next, because the banner only said what had happened.
`↵` runs `attach`, which already restarts an exited runner rather than
refusing. The hint promises a resumed conversation only when one is coming:
`↵` runs `attach`, which on an exited runner opens the agent list
(`openAgentPicker`) on the agent that exited rather than refusing: `↵` again
restarts it, and another choice starts that one and becomes the session's
agent. Quitting an agent is often the step before trying a different one, and
restarting the same one unasked made that a trip through the edit form. A
session that has not run this time starts straight away, as it always did;
its `e` form switches the agent ahead of a start. The list's rows are the
Agent field's own choices (`agentField`), so the form and the list cannot
offer different programs. The hint promises a resumed conversation only when one is coming:
`willResume` is the one predicate `agentArgsFor` reads to decide
`--continue`, so the sentence and the argv cannot disagree.

Expand Down
5 changes: 5 additions & 0 deletions internal/agent/executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
// Path is the file the agent runs. See Runner.path.
func (r *Runner) Path() string { return r.path }

// Command is the command the agent was started with, as given. A session's
// own record says what its next start runs, which a switch can change while
// this process is still the one in the pane.
func (r *Runner) Command() string { return r.cfg.Command }

// checkCommandFile refuses a command named by path that is missing or a
// directory, with that reason. exec would refuse it too, but at fork as
// "permission denied" for a directory. The path is handed to the kernel as
Expand Down
3 changes: 2 additions & 1 deletion internal/ui/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func (m Model) commitForm() (tea.Model, tea.Cmd) {
f.fields[editFieldDescription].value(),
)
case formEditSession:
return m.renameSession(f.subject, f.fields[editSessionFieldTitle].value())
return m.editSession(f.subject, f.fields[editSessionFieldTitle].value(),
f.fields[editSessionFieldAgent].value())
case formNewSession:
return m.newSession(
f.fields[sessionFieldProject].value(),
Expand Down
15 changes: 13 additions & 2 deletions internal/ui/agentinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package ui
import (
"context"
"errors"
"os"
"os/exec"
"path/filepath"
"strings"
Expand Down Expand Up @@ -110,8 +111,7 @@ func claudeInfo(isClaude bool, agentPath, dir string) string {
cmd.Env = agent.ScrubbedEnv()
cmd.WaitDelay = versionWaitDelay
out, err := cmd.Output()
// A pipe a child still held is not a failure when the version arrived.
if err != nil && !(errors.Is(err, exec.ErrWaitDelay) && len(out) > 0) {
if err != nil && !answered(out, cmd.ProcessState) {
reason := err.Error()
var exit *exec.ExitError
switch {
Expand Down Expand Up @@ -157,3 +157,14 @@ func printable(s string) string {
return r
}, s)
}

// answered reports whether a version check that ended in an error answered
// anyway: it printed and exited 0. Two errors arrive over a good answer. A
// child of the process holding stdout open ends the read by WaitDelay. And a
// timeout that fires as the process exits, before Wait has collected it,
// reports a kill though the process had already exited 0 — seen once in
// eight runs of TestAWedgedCheckIsBounded on a loaded machine, and not
// reproduced by an independent run of thirty.
func answered(out []byte, state *os.ProcessState) bool {
return len(out) > 0 && state != nil && state.Success()
}
37 changes: 37 additions & 0 deletions internal/ui/agentinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ui

import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -287,3 +288,39 @@ func TestAClaudeFoundOnlyRelativelySaysSo(t *testing.T) {
t.Errorf("notice = %q, want it to name the relative PATH entry", notice)
}
}

// TestOutputFromAFailedRunIsNotAVersion: a claude that printed and then
// failed did not answer, whatever it printed first.
func TestOutputFromAFailedRunIsNotAVersion(t *testing.T) {
fakeBin(t, map[string]string{"cathode": "#!/bin/sh\nexec /bin/sleep 30\n",
"claude": claudeWith("echo 2.0.9; exit 4")})
if _, notice := startedWith(t, "cathode"); !strings.Contains(notice, "could not read the version") {
t.Errorf("notice = %q, want the failed run reported", notice)
}
}

// TestAnsweredIsTheExitAndTheOutput pins the rule claudeInfo applies when the
// read ends in an error: printed and exited 0 is an answer, and nothing else
// is. Real states, from running a shell that exits each way.
func TestAnsweredIsTheExitAndTheOutput(t *testing.T) {
state := func(code string) *os.ProcessState {
cmd := exec.Command("/bin/sh", "-c", "exit "+code)
_ = cmd.Run()
return cmd.ProcessState
}
ok, failed := state("0"), state("3")
for _, tc := range []struct {
out string
state *os.ProcessState
want bool
}{
{"2.0.9", ok, true},
{"2.0.9", failed, false},
{"", ok, false},
{"2.0.9", nil, false},
} {
if got := answered([]byte(tc.out), tc.state); got != tc.want {
t.Errorf("answered(%q, %v) = %v, want %v", tc.out, tc.state, got, tc.want)
}
}
}
54 changes: 54 additions & 0 deletions internal/ui/agentpick.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ui

// Choosing which agent a session runs when it starts again: the agent list
// as a picker, and starting the one chosen. The session's edit form changes
// the same field ahead of time; formsession.go builds that.

import (
tea "github.com/charmbracelet/bubbletea"

"github.com/tripledownab/deck/internal/store"
)

// openAgentPicker asks which agent to start a session with, on its current
// one so ↵ ↵ restarts what was running. The rows are the Agent field's own
// choices, so the list and the form cannot offer different programs.
func (m Model) openAgentPicker(sess *store.Session) (tea.Model, tea.Cmd) {
choices := agentField(sess.Agent, "").choices
rows := make([]pickerRow, 0, len(choices))
for _, c := range choices {
rows = append(rows, pickerRow{id: c.value, label: c.label, desc: c.help})
}
m.pickerSubject = sess.ID
m.picker = newPicker(pickAgent, "Start "+sessionLabel(*sess)+" with", rows, sess.Agent)
return m, nil
}

// agentPicked starts the session with the agent chosen, and keeps the choice
// as the session's agent, so the next start runs it too.
//
// It resolves the session from pickerSubject, as endPicked does, so the
// choice lands on the session the list was opened for. The choice is kept
// only if that agent started: one that is not installed, or a worktree that is
// gone, leaves the session's agent as it was, and start reports why. A save
// that fails after a good start is reported, and the agent keeps running.
func (m Model) agentPicked(choice string) (tea.Model, tea.Cmd) {
sess := m.state.Session(m.pickerSubject)
if sess == nil {
return m, nil
}
before, prev := m.runners[sess.ID], sess.Agent
sess.Agent = choice
next, cmd := m.start(sess)
nm := next.(Model)
if r := nm.runners[sess.ID]; r == nil || r == before {
sess.Agent = prev
return nm, cmd
}
if choice != prev {
if err := nm.state.Save(); err != nil {
nm.fault = err
}
}
return nm, cmd
}
Loading
Loading