From 197c3664c68482be3ffb39249168587e48b412a2 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Wed, 22 Apr 2026 12:21:57 +0200 Subject: [PATCH] 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. --- pkg/agent/core.go | 2 ++ pkg/agent/core_test.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/pkg/agent/core.go b/pkg/agent/core.go index 65901ba..1eaf6df 100644 --- a/pkg/agent/core.go +++ b/pkg/agent/core.go @@ -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": diff --git a/pkg/agent/core_test.go b/pkg/agent/core_test.go index bac5847..bd9555c 100644 --- a/pkg/agent/core_test.go +++ b/pkg/agent/core_test.go @@ -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) {