Skip to content
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ Running it needs `claude` on PATH with `claude login` already done. Verify with
`claude` then `/status`: anything but the subscription route means you are
billing the API.

Deck finds `claude` on the PATH it was started with, which is not always the one
your shell has. A tmux server started without nvm loaded, for example, finds a
system-wide install your shell never reaches. So starting a session names the
file it ran, and for `claude` and `cathode` the `claude` version that answers,
in the footer: `started /usr/local/bin/claude (2.0.9) in …`. A version you do
not recognise is a second install.

## Use

```bash
Expand Down
14 changes: 12 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,20 @@ Three rules the design rests on:
taken from the box before the reply was written, and nothing confirms
claude read it.

Wiring the agent is the one place Deck knows anything about the program it
hosts (`ui.coordArgs`): `claude` takes `--mcp-config`, `cathode` forwards a
Wiring the agent is where Deck knows most about the program it hosts
(`ui.coordArgs`): `claude` takes `--mcp-config`, `cathode` forwards a
second config with `-mcp`. Any other agent gets no config file at all.

Starting one also names what ran (`ui/agentinfo.go`). The footer gives the file
the agent's name resolved to on PATH, and for `claude` and `cathode` — which
starts `claude` by name from the PATH it inherits — the `claude` that answers
and its `--version`. That check runs as a command off the UI's goroutine, and
its answer replaces the notice only if nothing newer has. It exists because a
second install is easy to have and invisible otherwise: a tmux server started
without nvm loaded found a stale system-wide `claude` that the user's own shell
never reached, and every session failed with a model the API no longer serves
while the same command typed by hand worked.

`TestLiveClaudeSeesSiblings` drives a real `claude` against the server and is
the only test that proves config shape, transport, and tool naming actually
work together. It is opt-in because it spends a subscription turn:
Expand Down
120 changes: 120 additions & 0 deletions internal/ui/agentinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package ui

// What the footer says about the program a session started: the file its
// name resolved to on PATH, and for an agent that runs claude, which claude
// answers and its version.
//
// Deck starts an agent by name, and two installs of one program on PATH are
// easy to end up with. The shell you type in may find a different one from
// the environment Deck inherited — a tmux server started without nvm loaded
// finds a stale system-wide install, and a session fails in a way the same
// command typed by hand does not. Naming the file and the version is what
// makes that visible.

import (
"context"
"os/exec"
"path/filepath"
"strings"
"time"

tea "github.com/charmbracelet/bubbletea"

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

// versionTimeout bounds `claude --version`. It runs off the UI's goroutine,
// so a slow one costs nothing but a late notice; this only stops a wedged one
// from leaving a process behind.
const versionTimeout = 5 * time.Second

// agentVersionMsg carries what a version check found back to the footer.
// started is the notice it was asked for, so a notice that has since been
// replaced is left alone.
type agentVersionMsg struct {
started, agentPath, dir, info string
}

// startedNotice is the footer line for an agent that just started. info is
// what the version check found, or "" before it has answered.
func startedNotice(agentPath, dir, info string) string {
if info != "" {
agentPath += " (" + info + ")"
}
return "started " + agentPath + " in " + dir
}

// runsClaude reports whether an agent answers through the claude CLI: claude
// itself, or cathode, which starts claude by name from the PATH it inherits
// from Deck. coordArgs and willResume switch on the same base name.
func runsClaude(command string) bool {
switch filepath.Base(command) {
case "claude", "cathode":
return true
}
return false
}

// announceStart sets the notice for an agent that just started and returns
// the check that completes it, or nil when there is nothing to ask.
//
// Start has already resolved the command, so LookPath answers here; a failure
// would mean PATH changed between the two, and the name is shown instead.
func (m *Model) announceStart(command, dir string) tea.Cmd {
agentPath, err := exec.LookPath(command)
if err != nil {
agentPath = command
}
m.notice = startedNotice(agentPath, dir, "")
if !runsClaude(command) {
return nil
}
started := m.notice
return func() tea.Msg {
return agentVersionMsg{started: started, agentPath: agentPath, dir: dir,
info: claudeInfo(filepath.Base(command) == "claude", agentPath)}
}
}

// claudeInfo is the claude part of the notice. For claude itself the path is
// already shown, so only the version is; for cathode it is the claude cathode
// will start, which is the one that answers.
//
// A failure is reported in place of the version rather than dropped: "could
// not read" is the notice that should send someone to look.
func claudeInfo(isClaude bool, agentPath string) string {
path := agentPath
if !isClaude {
p, err := exec.LookPath("claude")
if err != nil {
return "claude not found on PATH"
}
path = p
}
ctx, cancel := context.WithTimeout(context.Background(), versionTimeout)
defer cancel()
cmd := exec.CommandContext(ctx, path, "--version")
cmd.Env = agent.ScrubbedEnv()
out, err := cmd.Output()
if err != nil {
return "could not read the version of " + path + ": " + err.Error()
}
// "2.1.322 (Claude Code)": the first word is the version, and the rest
// only repeats the program's name, which the notice already gives.
version := "(no version printed)"
if fields := strings.Fields(string(out)); len(fields) > 0 {
version = fields[0]
}
if isClaude {
return version
}
return "claude " + version + " at " + path
}

// applyVersion completes the start notice, unless something has replaced it
// since — a later notice is newer news than this one.
func (m *Model) applyVersion(msg agentVersionMsg) {
if m.notice == msg.started {
m.notice = startedNotice(msg.agentPath, msg.dir, msg.info)
}
}
123 changes: 123 additions & 0 deletions internal/ui/agentinfo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package ui

// The footer naming the binary a session started and the claude behind it,
// against fake programs on a PATH the test controls. A real claude on the
// machine running the tests would otherwise decide what they see.

import (
"os"
"path/filepath"
"strings"
"testing"

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

// fakeClaude is a claude that prints a version and otherwise stays up, as
// the real one does in a pane. Absolute paths, because PATH holds only bin.
const fakeClaude = "#!/bin/sh\nif [ \"$1\" = --version ]; then echo '2.0.9 (Claude Code)'; exit 0; fi\nexec /bin/sleep 30\n"

// fakeBin writes executables into a fresh directory and makes it the whole
// PATH, so nothing installed on the machine can answer instead.
func fakeBin(t *testing.T, files map[string]string) string {
t.Helper()
bin := t.TempDir()
for name, body := range files {
if err := os.WriteFile(filepath.Join(bin, name), []byte(body), 0o755); err != nil {
t.Fatal(err)
}
}
t.Setenv("PATH", bin)
return bin
}

// startedWith starts a session running command and returns the model, and the
// notice once the version check has answered.
func startedWith(t *testing.T, command string) (Model, string) {
t.Helper()
st := &store.State{}
p := st.AddProject(store.Project{Name: "demo", Path: t.TempDir()})
st.AddSession(store.Session{ProjectID: p.ID, Name: "s", Agent: command, Dir: t.TempDir()})
m := sized(New(st, command, nil), 120, 30)
m.screen = screenSession
t.Cleanup(func() { m.Close() })

next, cmd := m.attach()
m = next.(Model)
if m.fault != nil {
t.Fatalf("start: %v", m.fault)
}
if cmd == nil {
return m, m.notice
}
after, _ := m.Update(cmd())
return m, after.(Model).notice
}

// TestCathodeNamesTheClaudeThatAnswers is the case this exists for: the
// session runs cathode, and the claude cathode starts is the one that matters.
func TestCathodeNamesTheClaudeThatAnswers(t *testing.T) {
bin := fakeBin(t, map[string]string{"cathode": "#!/bin/sh\nexec /bin/sleep 30\n", "claude": fakeClaude})

_, notice := startedWith(t, "cathode")
want := "claude 2.0.9 at " + filepath.Join(bin, "claude")
if !strings.Contains(notice, filepath.Join(bin, "cathode")) || !strings.Contains(notice, want) {
t.Errorf("notice = %q, want the cathode file and %q", notice, want)
}
}

// TestClaudeNamesItsOwnVersion: the path is already the claude, so only the
// version is added.
func TestClaudeNamesItsOwnVersion(t *testing.T) {
bin := fakeBin(t, map[string]string{"claude": fakeClaude})

_, notice := startedWith(t, "claude")
if want := filepath.Join(bin, "claude") + " (2.0.9)"; !strings.Contains(notice, want) {
t.Errorf("notice = %q, want %q", notice, want)
}
}

// TestAMissingOrBrokenClaudeIsSaid: either is the notice that should send
// someone to look, so neither is dropped.
func TestAMissingOrBrokenClaudeIsSaid(t *testing.T) {
fakeBin(t, map[string]string{"cathode": "#!/bin/sh\nexec /bin/sleep 30\n"})
if _, notice := startedWith(t, "cathode"); !strings.Contains(notice, "claude not found on PATH") {
t.Errorf("with no claude: notice = %q", notice)
}

fakeBin(t, map[string]string{"cathode": "#!/bin/sh\nexec /bin/sleep 30\n", "claude": "#!/bin/sh\nexit 3\n"})
if _, notice := startedWith(t, "cathode"); !strings.Contains(notice, "could not read the version") {
t.Errorf("with a claude that fails: notice = %q", notice)
}
}

// TestOtherAgentsAreNamedWithoutAVersion: Deck knows what --version means only
// for claude, so other agents get their path and no check at all.
func TestOtherAgentsAreNamedWithoutAVersion(t *testing.T) {
bin := fakeBin(t, map[string]string{"codex": "#!/bin/sh\nexec /bin/sleep 30\n", "claude": fakeClaude})

m, notice := startedWith(t, "codex")
if notice != "started "+filepath.Join(bin, "codex")+" in "+m.state.Sessions[0].Dir {
t.Errorf("notice = %q", notice)
}
}

// TestALaterNoticeIsNotOverwritten: the check answers late by design, and by
// then the footer may say something newer.
func TestALaterNoticeIsNotOverwritten(t *testing.T) {
fakeBin(t, map[string]string{"claude": fakeClaude})
st := &store.State{}
p := st.AddProject(store.Project{Name: "demo", Path: t.TempDir()})
st.AddSession(store.Session{ProjectID: p.ID, Name: "s", Agent: "claude", Dir: t.TempDir()})
m := sized(New(st, "claude", nil), 120, 30)
m.screen = screenSession
t.Cleanup(func() { m.Close() })

next, cmd := m.attach()
m = next.(Model)
m.notice = "something newer"
after, _ := m.Update(cmd())
if got := after.(Model).notice; got != "something newer" {
t.Errorf("the late version replaced a newer notice: %q", got)
}
}
4 changes: 4 additions & 0 deletions internal/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (m Model) route(msg tea.Msg) (tea.Model, tea.Cmd) {

case tea.KeyMsg:
return m.handleKey(msg)

case agentVersionMsg:
m.applyVersion(msg)
return m, nil
}

return m, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (m Model) attach() (tea.Model, tea.Cmd) {
m.runners[sess.ID] = r
m.attached = true
m.screen = screenSession
m.notice = "started " + sess.Agent + " in " + sess.Dir
announce := m.announceStart(sess.Agent, sess.Dir)

// Announce the session so its siblings can see it. Registering after the
// process starts keeps the registry to sessions that actually exist.
Expand All @@ -49,7 +49,7 @@ func (m Model) attach() (tea.Model, tea.Cmd) {
Isolated: sess.Isolated, BaseRef: sess.BaseRef,
})
}
return m, nil
return m, announce
}

// stopRunner stops a session's agent and frees what it held in the
Expand Down
Loading