| 1 | package backend |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "strings" |
| 8 | |
| 9 | "the-valley/flow/internal/location" |
| 10 | ) |
| 11 | |
| 12 | // PrepareAgyReadOnly limits the primary agent to file-reading tools. |
| 13 | func PrepareAgyReadOnly() (string, func(), error) { |
| 14 | home, err := os.UserHomeDir() |
| 15 | if err != nil { |
| 16 | return "", nil, err |
| 17 | } |
| 18 | dir := filepath.Join(home, ".gemini", "config", "agents") |
| 19 | if err := os.MkdirAll(dir, 0700); err != nil { |
| 20 | return "", nil, err |
| 21 | } |
| 22 | f, err := os.CreateTemp(dir, location.TempPattern("consult-*.md")) |
| 23 | if err != nil { |
| 24 | return "", nil, err |
| 25 | } |
| 26 | cleanup := func() { _ = os.Remove(f.Name()) } |
| 27 | name := strings.TrimSuffix(filepath.Base(f.Name()), ".md") |
| 28 | body := fmt.Sprintf(`--- |
| 29 | name: %s |
| 30 | description: Read-only model consultation |
| 31 | tools: |
| 32 | - view_file |
| 33 | - grep_search |
| 34 | mainAgent: true |
| 35 | subagent: false |
| 36 | --- |
| 37 | You are a read-only thinking partner. You may only read files and answer questions. |
| 38 | `, name) |
| 39 | if _, err := f.WriteString(body); err != nil { |
| 40 | f.Close() |
| 41 | cleanup() |
| 42 | return "", nil, err |
| 43 | } |
| 44 | if err := f.Close(); err != nil { |
| 45 | cleanup() |
| 46 | return "", nil, err |
| 47 | } |
| 48 | return name, cleanup, nil |
| 49 | } |