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
8 changes: 8 additions & 0 deletions cmd/agent-desk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,11 @@ func handleAdd(profile string, args []string) {
}
}

if err := newInstance.PrepareCopilotSession(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}

// Add to instances
instances = append(instances, newInstance)

Expand Down Expand Up @@ -1816,6 +1821,9 @@ func detectTool(cmd string) string {
}

cmd = strings.ToLower(cmd)
if fields := strings.Fields(cmd); len(fields) > 0 && filepath.Base(fields[0]) == "copilot" {
return "copilot"
}
switch {
case strings.Contains(cmd, "claude"):
return "claude"
Expand Down
39 changes: 31 additions & 8 deletions cmd/agent-desk/session_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func printSessionHelp() {
fmt.Println(" wrapper Wrapper command (use {command} to include tool command)")
fmt.Println(" claude-session-id Claude conversation ID (for resume)")
fmt.Println(" gemini-session-id Gemini conversation ID (for resume)")
fmt.Println(" copilot-session-id Copilot conversation UUID (for recovery)")
fmt.Println()
fmt.Println("Set examples:")
fmt.Println(" agent-desk session set my-project title \"New Title\"")
Expand Down Expand Up @@ -199,6 +200,9 @@ func handleSessionStart(profile string, args []string) {
if inst.ClaudeSessionID != "" {
jsonData["claude_session_id"] = inst.ClaudeSessionID
}
if inst.CopilotSessionID != "" {
jsonData["copilot_session_id"] = inst.CopilotSessionID
}
if initialMessage != "" {
jsonData["message"] = initialMessage
jsonData["message_pending"] = true
Expand Down Expand Up @@ -486,6 +490,10 @@ func handleSessionShow(profile string, args []string) {
if inst.Command != "" {
jsonData["command"] = inst.Command
}
if inst.Tool == "copilot" {
jsonData["copilot_session_id"] = inst.CopilotSessionID
jsonData["needs_recovery"] = inst.CopilotSessionID == ""
}

if inst.Tool == "claude" {
jsonData["claude_session_id"] = inst.ClaudeSessionID
Expand Down Expand Up @@ -521,6 +529,13 @@ func handleSessionShow(profile string, args []string) {
}

sb.WriteString(fmt.Sprintf("Tool: %s\n", inst.Tool))
if inst.Tool == "copilot" {
if inst.CopilotSessionID == "" {
sb.WriteString("Copilot: not linked (press R to recover)\n")
} else {
fmt.Fprintf(&sb, "Copilot: %s\n", inst.CopilotSessionID)
}
}

if inst.Command != "" {
sb.WriteString(fmt.Sprintf("Command: %s\n", inst.Command))
Expand Down Expand Up @@ -588,6 +603,7 @@ func handleSessionSet(profile string, args []string) {
fmt.Println(" wrapper Wrapper command (use {command} to include tool command)")
fmt.Println(" claude-session-id Claude conversation ID")
fmt.Println(" gemini-session-id Gemini conversation ID")
fmt.Println(" copilot-session-id Copilot conversation UUID (for recovery)")
fmt.Println()
fmt.Println("Options:")
fs.PrintDefaults()
Expand Down Expand Up @@ -616,19 +632,20 @@ func handleSessionSet(profile string, args []string) {

// Validate field name
validFields := map[string]bool{
"title": true,
"path": true,
"command": true,
"tool": true,
"wrapper": true,
"claude-session-id": true,
"gemini-session-id": true,
"title": true,
"path": true,
"command": true,
"tool": true,
"wrapper": true,
"claude-session-id": true,
"gemini-session-id": true,
"copilot-session-id": true,
}

if !validFields[field] {
out.Error(
fmt.Sprintf(
"invalid field: %s\nValid fields: title, path, command, tool, wrapper, claude-session-id, gemini-session-id",
"invalid field: %s\nValid fields: title, path, command, tool, wrapper, claude-session-id, gemini-session-id, copilot-session-id",
field,
),
ErrCodeInvalidOperation,
Expand Down Expand Up @@ -675,6 +692,12 @@ func handleSessionSet(profile string, args []string) {
case "wrapper":
oldValue = inst.Wrapper
inst.Wrapper = value
case "copilot-session-id":
oldValue = inst.CopilotSessionID
if err := inst.BindCopilotConversation(value); err != nil {
out.Error(err.Error(), ErrCodeInvalidOperation)
os.Exit(1)
}
case "claude-session-id":
oldValue = inst.ClaudeSessionID
inst.ClaudeSessionID = value
Expand Down
57 changes: 57 additions & 0 deletions docs/copilot-recovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copilot conversations after a reboot

Agent Desk's sidebar entries and Copilot's conversation history are persisted
locally. The tmux processes hosting them do not survive a reboot. Restarting an
entry must recreate tmux and resume the correct conversation, not whichever
conversation was used most recently.

## Recover an existing entry

Select a Copilot entry and press **Shift+R**. Enter also starts recovery when its
tmux session is gone.

If the entry has no stored Copilot conversation UUID, a recovery picker opens.
It shows saved conversation names, UUIDs and update times. Type to filter, use
Up/Down to navigate, and Tab to switch between the entry's folder and all folders.
The all-folders option also covers conversations whose working directory changed.
Press Enter to explicitly link and resume the highlighted conversation. Esc
cancels without changing anything.

The link is saved before restarting. Subsequent restarts use
`copilot --resume=<uuid>`, including after a reboot. Missing history or a lock
error is reported by Copilot; Agent Desk does not silently start another
conversation or delete lock files.

For terminal-based recovery:

```sh
agent-desk session set <entry> copilot-session-id <conversation-uuid>
agent-desk session restart <entry>
agent-desk session show <entry> --json
```

The UUID must identify readable local metadata in
`~/.copilot/session-state/<uuid>/workspace.yaml`. Names and folder matches are
discovery aids, never proof that an entry owns a particular conversation.

## New sessions

For the standard `copilot` command, Agent Desk allocates a UUID and persists it
before launching `copilot --session-id=<uuid>`. This requires a Copilot CLI that
supports `--session-id` (checked before launch). Two entries in the same folder
therefore retain distinct identities.

Custom launch commands are left unchanged. They are not assigned a guessed ID.
Automatic restart refuses to discard or rewrite custom flags; use the standard
`copilot` command for managed recovery, or resume explicitly through the custom
command. Wrappers containing `{command}` continue to wrap managed launch and
resume commands.

The stored link follows a conversation, not an arbitrary interactive tab. If you
switch to a different conversation inside Copilot with `/new`, `/resume`, or
`/fork`, explicitly rebind the entry using `session set ... copilot-session-id`
to change which conversation Agent Desk will restore.

Installing a new Agent Desk binary does not update an already-running TUI.
Exit and reopen Agent Desk to use the updated recovery behavior; no Mac reboot
or deletion of Copilot state is needed.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/charmbracelet/lipgloss v1.1.0
github.com/creack/pty v1.1.24
github.com/fsnotify/fsnotify v1.9.0
github.com/google/uuid v1.6.0
github.com/mattn/go-runewidth v0.0.16
github.com/muesli/cancelreader v0.2.2
github.com/muesli/termenv v0.16.0
Expand All @@ -20,6 +21,7 @@ require (
golang.org/x/term v0.37.0
golang.org/x/time v0.14.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.44.3
)

Expand All @@ -34,7 +36,6 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
Expand All @@ -46,7 +47,6 @@ require (
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.3.8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
Expand Down
Loading
Loading