agent: inline loadSystemPrompt into BuildAgentEnv

This commit is contained in:
Levi Neely 2026-04-21 15:58:17 +02:00
parent 0b705a1ee7
commit a4d4744eae
2 changed files with 10 additions and 16 deletions

View File

@ -79,7 +79,12 @@ func BuildAgentEnv(cfg *config.Config, d tools.Dispatcher, cwd string) AgentEnv
}
}
base := loadSystemPrompt(cwd)
path := DefaultPromptsDir() + "/SYSTEM_PROMPT.md"
data, err := os.ReadFile(path)
if err != nil {
panic(fmt.Sprintf("loadSystemPrompt: %s: %v", path, err))
}
base := expandSystemPrompt(string(data), cwd)
sp := base
if agentPrompt != "" {
if sp != "" {
@ -123,17 +128,6 @@ func DefaultPromptsDir() string {
return paths.CfgDir() + "/prompts"
}
// loadSystemPrompt reads SYSTEM_PROMPT.md from DefaultPromptsDir and expands
// environment variables, including computed PRIME_* values.
func loadSystemPrompt(cwd string) string {
path := DefaultPromptsDir() + "/SYSTEM_PROMPT.md"
data, err := os.ReadFile(path)
if err != nil {
panic(fmt.Sprintf("loadSystemPrompt: %s: %v", path, err))
}
return expandSystemPrompt(string(data), cwd)
}
func expandSystemPrompt(content, cwd string) string {
if cwd == "" {
cwd, _ = os.Getwd()

View File

@ -526,17 +526,17 @@ func TestAgentSpawnFiresOnce(t *testing.T) {
}
}
// --- loadSystemPrompt ---
// --- BuildAgentEnv: missing system prompt ---
func TestLoadSystemPrompt_MissingFile(t *testing.T) {
func TestBuildAgentEnv_MissingSystemPrompt(t *testing.T) {
t.Setenv("OLLIE_CFG_PATH", t.TempDir()) // no SYSTEM_PROMPT.md written
defer func() {
if recover() == nil {
t.Error("expected panic from loadSystemPrompt; got none")
t.Error("expected panic from BuildAgentEnv; got none")
}
}()
loadSystemPrompt("")
BuildAgentEnv(nil, tools.NewDispatcher(), "")
}
// --- panic recovery ---