gunk-dev/the-valley

agy_readonly.go

sourcecfedff357a41main's published tip history
1.0 KiB
1package backend
2
3import (
4 "fmt"
5 "os"
6 "path/filepath"
7 "strings"
8)
9
10// PrepareAgyReadOnly limits the primary agent to file-reading tools.
11func 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(`---
27name: %s
28description: Read-only model consultation
29tools:
30 - view_file
31 - grep_search
32mainAgent: true
33subagent: false
34---
35You 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}