gunk-dev/the-valley

backend.go

source6a6791929c36main's published tip history
1.7 KiB
1package cmd
2
3import (
4 "path/filepath"
5
6 "the-valley/flow/internal/backend"
7 "the-valley/flow/internal/config"
8 "the-valley/flow/internal/flowenv"
9 "the-valley/flow/internal/run"
10 "github.com/spf13/cobra"
11)
12
13func 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(sessionIDFromEnv()); err == nil && s != nil {
20 name = s.AgentBackend
21 }
22 }
23 }
24 if name == "" {
25 name = flowenv.AgentBackend.Get()
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.
36func 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.
42func writeClaudeSettings(path, repo string) error {
43 return run.WritePromptFile(path, backend.ClaudeSettingsWithStatusLine(repo))
44}
45
46func trustBackendWorktree(k backend.Kind, dir string) error {
47 if k == backend.Claude {
48 return config.PreTrustWorktree(dir)
49 }
50 return nil
51}
52func linkBackendMemory(k backend.Kind, dir string) error {
53 if k == backend.Claude {
54 return config.LinkSharedMemory(dir)
55 }
56 return nil
57}
58
59func isClaudeRun(s *run.State) bool { return s.Backend == "" || s.Backend == string(backend.Claude) }