53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package template
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func findProjectRoot() string {
|
|
wd, _ := os.Getwd()
|
|
dir := wd
|
|
for i := 0; i < 10; i++ {
|
|
if _, err := os.Stat(filepath.Join(dir, "templates", "docs")); err == nil {
|
|
return dir
|
|
}
|
|
parent := filepath.Dir(dir)
|
|
if parent == dir {
|
|
break
|
|
}
|
|
dir = parent
|
|
}
|
|
return wd
|
|
}
|
|
|
|
func GetDocTemplate(name string) (string, error) {
|
|
name = strings.TrimSuffix(name, ".md")
|
|
root := findProjectRoot()
|
|
path := filepath.Join(root, "templates", "docs", name+".md")
|
|
b, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return "", fmt.Errorf("read doc template %s: %w", name, err)
|
|
}
|
|
return string(b), nil
|
|
}
|
|
|
|
func GetAgentInstruction(role string) (string, error) {
|
|
role = strings.TrimSuffix(role, ".md")
|
|
root := findProjectRoot()
|
|
path := filepath.Join(root, "configs", "agents", role+".md")
|
|
b, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return "", fmt.Errorf("read agent instruction %s: %w", role, err)
|
|
}
|
|
|
|
inst := string(b)
|
|
writingPath := filepath.Join(root, "configs", "shared", "writing.md")
|
|
if wb, err := os.ReadFile(writingPath); err == nil {
|
|
inst += "\n\n" + string(wb)
|
|
}
|
|
return inst, nil
|
|
}
|