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.
This commit is contained in:
ollie 2026-07-19 20:26:52 +02:00
parent a53d5b9618
commit 95d9e9fd85
2 changed files with 23 additions and 5 deletions

View File

@ -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 {

View File

@ -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...)