fix: resolve ${PWD} in system prompt from session cwd, not process env

expandSystemPrompt fell through to os.Getenv("PWD") which always
returned the process startup directory. Map "PWD" explicitly to the
cwd parameter so the system prompt reflects the session's working
directory.
This commit is contained in:
Levi Neely 2026-04-22 12:21:57 +02:00
parent e0bd5cefe8
commit 197c3664c6
2 changed files with 10 additions and 0 deletions

View File

@ -137,6 +137,8 @@ func expandSystemPrompt(content, cwd string) string {
}
mapper := func(key string) string {
switch key {
case "PWD":
return cwd
case "PRIME_DATE":
return time.Now().Format("2006-01-02")
case "PRIME_PLATFORM":

View File

@ -544,6 +544,14 @@ func TestExpandSystemPrompt_IsGitFalse(t *testing.T) {
}
}
func TestExpandSystemPrompt_PWDUsesCWD(t *testing.T) {
dir := t.TempDir()
got := expandSystemPrompt("${PWD}", dir)
if got != dir {
t.Errorf("got %q; want %q", got, dir)
}
}
// --- BuildAgentEnv: missing system prompt ---
func TestBuildAgentEnv_MissingSystemPrompt(t *testing.T) {