gunk-dev/the-valley

agy_readonly.go

source4cbb5ec9c5dbmain's published tip history
1.1 KiB
1package backend
2
3import (
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.
13func 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(`---
29name: %s
30description: Read-only model consultation
31tools:
32 - view_file
33 - grep_search
34mainAgent: true
35subagent: false
36---
37You 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}