| 1 | package cmd |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | |
| 7 | "the-valley/flow/internal/backend" |
| 8 | "the-valley/flow/internal/config" |
| 9 | "the-valley/flow/internal/run" |
| 10 | "github.com/spf13/cobra" |
| 11 | ) |
| 12 | |
| 13 | func resolveAgentBackend(cmd *cobra.Command, cfg config.Config) (backend.Kind, error) { |
| 14 | name, _ := cmd.Flags().GetString("backend") |
| 15 | if name == "" { |
| 16 | // Read saved session state so dashboard dispatch works even when its tmux |
| 17 | // pane did not inherit the coordinator process's environment. |
| 18 | if store, err := sessionStore(); err == nil { |
| 19 | if s, err := store.Load(os.Getenv(sessionIDEnv)); err == nil && s != nil { |
| 20 | name = s.AgentBackend |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | if name == "" { |
| 25 | name = os.Getenv("KLAUS_AGENT_BACKEND") |
| 26 | } |
| 27 | if name == "" { |
| 28 | name = cfg.DefaultAgentBackend |
| 29 | } |
| 30 | return backend.Parse(name) |
| 31 | } |
| 32 | |
| 33 | // claudeSettingsPath is the file a Claude coordinator loads with --settings |
| 34 | // (backend.Options.SettingsFile), in the session's prompts directory. It is |
| 35 | // never in the worktree, where git would see it. |
| 36 | func claudeSettingsPath(store run.StateStore, id string) string { |
| 37 | return filepath.Join(run.PromptDir(store), id+".settings.json") |
| 38 | } |
| 39 | |
| 40 | // writeClaudeSettings writes the settings that give a Claude coordinator a |
| 41 | // status line naming repo to path. |
| 42 | func writeClaudeSettings(path, repo string) error { |
| 43 | return run.WritePromptFile(path, backend.ClaudeSettingsWithStatusLine(repo)) |
| 44 | } |
| 45 | |
| 46 | func trustBackendWorktree(k backend.Kind, dir string) error { |
| 47 | if k == backend.Claude { |
| 48 | return config.PreTrustWorktree(dir) |
| 49 | } |
| 50 | return nil |
| 51 | } |
| 52 | func linkBackendMemory(k backend.Kind, dir string) error { |
| 53 | if k == backend.Claude { |
| 54 | return config.LinkSharedMemory(dir) |
| 55 | } |
| 56 | return nil |
| 57 | } |
| 58 | |
| 59 | func isClaudeRun(s *run.State) bool { return s.Backend == "" || s.Backend == string(backend.Claude) } |