Why: Headless runs need the pi tool names, walked context files, prompt includes, and a trust gate before project settings are loaded. Evidence: go test -count=1 ./runtime/tools/ ./runtime/resources/ ./runtime/skills/ Impact: Existing tool names stay registered. Aliases are added only when the underlying tool exists. Refs: feature/pi-headless N4 Co-authored-by: Cursor <cursoragent@cursor.com>
38 lines
878 B
Go
38 lines
878 B
Go
package resources
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// ContextFiles walks from dir toward the filesystem root and concatenates
|
|
// AGENTS.md and CLAUDE.md (nearest first). SYSTEM.md and APPEND_SYSTEM.md
|
|
// are read from dir only.
|
|
func ContextFiles(dir string) (string, error) {
|
|
var parts []string
|
|
cur := dir
|
|
for {
|
|
for _, name := range []string{"AGENTS.md", "CLAUDE.md"} {
|
|
raw, err := os.ReadFile(filepath.Join(cur, name))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
parts = append(parts, "# "+name+" ("+cur+")\n"+string(raw))
|
|
}
|
|
parent := filepath.Dir(cur)
|
|
if parent == cur {
|
|
break
|
|
}
|
|
cur = parent
|
|
}
|
|
for _, name := range []string{"SYSTEM.md", "APPEND_SYSTEM.md"} {
|
|
raw, err := os.ReadFile(filepath.Join(dir, name))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
parts = append(parts, "# "+name+"\n"+string(raw))
|
|
}
|
|
return strings.Join(parts, "\n\n"), nil
|
|
}
|