From 95d9e9fd85e72f7c47585e95ad80dc043160ee00 Mon Sep 17 00:00:00 2001 From: ollie Date: Sun, 19 Jul 2026 20:26:52 +0200 Subject: [PATCH] prompt: unified PromptEnv for local and remote sessions Added PromptEnv(cwd) helper that returns PRIME_CWD, PRIME_PLATFORM, PRIME_IS_GIT_REPO. All callers of BuildRuntime now pass these. prime script is now a pure template renderer with no detection logic. Removed ad-hoc PRIME_CWD injection from prompt_resolver. --- pkg/agent/commands.go | 4 +++- pkg/agent/prompt_resolver.go | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pkg/agent/commands.go b/pkg/agent/commands.go index 8571f95..cf56865 100644 --- a/pkg/agent/commands.go +++ b/pkg/agent/commands.go @@ -175,7 +175,9 @@ func (s *agent) handleCommand(ctx context.Context, input string) bool { return } d := s.newDispatcher() - rt := BuildRuntime(cfg, d, s.cwd, []string{"OLLIE_SESSION_ID=" + s.sessionID, "OLLIE_UNAME=" + s.uname, "PWD=" + s.cwd}) + env := []string{"OLLIE_SESSION_ID=" + s.sessionID, "OLLIE_UNAME=" + s.uname} + env = append(env, PromptEnv(s.cwd)...) + rt := BuildRuntime(cfg, d, s.cwd, env) if rt.CfgBackend != "" { newBe, err := s.newBackend(rt.CfgBackend) if err != nil { diff --git a/pkg/agent/prompt_resolver.go b/pkg/agent/prompt_resolver.go index 4495a6a..baba838 100644 --- a/pkg/agent/prompt_resolver.go +++ b/pkg/agent/prompt_resolver.go @@ -7,12 +7,32 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "time" "ollie/pkg/config" ) +// PromptEnv returns the standard PRIME_* environment variables for prompt +// template resolution. For local sessions, values are detected from the +// filesystem. For remote sessions, callers should override these with +// values from remote.HostInfo. +func PromptEnv(cwd string) []string { + platform := runtime.GOOS + isGitRepo := "false" + if cwd != "" { + if _, err := os.Stat(filepath.Join(cwd, ".git")); err == nil { + isGitRepo = "true" + } + } + return []string{ + "PRIME_CWD=" + cwd, + "PRIME_PLATFORM=" + platform, + "PRIME_IS_GIT_REPO=" + isGitRepo, + } +} + // resolvePrompt interprets a Prompt from an agent config. // // If the prompt was parsed from a JSON array, each element is executed as a @@ -46,10 +66,6 @@ func resolveExecPrompt(cmds []string, cwd string, env []string) (string, error) if cwd != "" { if info, err := os.Stat(cwd); err == nil && info.IsDir() { cmd.Dir = cwd - } else { - // CWD doesn't exist locally (remote session). Inject PWD so - // scripts that use ${PWD} via envsubst see the correct value. - env = append(env, "PWD="+cwd) } } cmd.Env = append(os.Environ(), env...)