diff --git a/docs/extending/SOCKET_API.md b/docs/extending/SOCKET_API.md index 5d663a7..0461021 100644 --- a/docs/extending/SOCKET_API.md +++ b/docs/extending/SOCKET_API.md @@ -13,6 +13,7 @@ list_agents complete_agent restart_agent trigger_cleanup +trigger_refresh repair_state get_repo_config update_repo_config @@ -49,6 +50,7 @@ Each command below matches a `case` in `handleRequest`. | `complete_agent` | Mark agent ready for cleanup | `repo`, `name`, `summary`, `failure_reason` | | `restart_agent` | Restart a persistent agent | `repo`, `name` | | `trigger_cleanup` | Force cleanup cycle | none | +| `trigger_refresh` | Force worktree refresh cycle | none | | `repair_state` | Run state repair routine | none | | `get_repo_config` | Get merge-queue / pr-shepherd config | `repo` | | `update_repo_config` | Update repo config | `repo`, `config` (JSON object) | @@ -644,6 +646,27 @@ class MulticlaudeClient { } ``` +#### trigger_refresh + +**Description:** Trigger immediate worktree refresh for all agents (syncs with main branch) + +**Request:** +```json +{ + "command": "trigger_refresh" +} +``` + +**Response:** +```json +{ + "success": true, + "data": "Worktree refresh triggered" +} +``` + +**Note:** Refresh runs asynchronously in the background. + #### repair_state **Description:** Repair inconsistent state (equivalent to `multiclaude repair`) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 3e06628..11acc6b 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -13,6 +13,8 @@ import ( "strings" "time" + "github.com/google/uuid" + "github.com/dlorenc/multiclaude/internal/agents" "github.com/dlorenc/multiclaude/internal/bugreport" "github.com/dlorenc/multiclaude/internal/daemon" @@ -5538,14 +5540,25 @@ func (c *CLI) restartClaude(args []string) error { // Build the command var cmdArgs []string + sessionID := agent.SessionID if hasHistory { // Session has history - use --resume to continue - cmdArgs = []string{"--resume", agent.SessionID} - fmt.Printf("Resuming Claude session %s...\n", agent.SessionID) + cmdArgs = []string{"--resume", sessionID} + fmt.Printf("Resuming Claude session %s...\n", sessionID) } else { - // New session - use --session-id - cmdArgs = []string{"--session-id", agent.SessionID} - fmt.Printf("Starting new Claude session %s...\n", agent.SessionID) + // No history - generate a new session ID to avoid "already in use" errors + // This can happen when Claude exits abnormally or the previous session + // was started but never used + sessionID = uuid.New().String() + cmdArgs = []string{"--session-id", sessionID} + fmt.Printf("Starting new Claude session %s...\n", sessionID) + + // Update agent with new session ID + agent.SessionID = sessionID + if err := st.UpdateAgent(repoName, agentName, agent); err != nil { + fmt.Printf("Warning: failed to save new session ID: %v\n", err) + // Continue anyway - the session will work, just won't persist + } } // Add common flags