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