diff --git a/session/session.go b/session/session.go index d4171fe..e1b0bd3 100644 --- a/session/session.go +++ b/session/session.go @@ -1008,20 +1008,35 @@ func (s *Manager) CreateSession(args []string) (string, error) { execOpts = append(execOpts, execute.WithAllowTools(cfg.AllowTools)) } var newDisp func() tools.Dispatcher + var remoteEnv []string // extra env vars from remote host info if remoteTarget != "" { - newDisp = tools.NewDispatcherFunc(map[string]func() tools.Server{ - "execute": remote.Decl(remote.Config{ - SSHTarget: remoteTarget, - CWD: cwd, - }), + // Dial eagerly so we get HostInfo for prompt resolution. + // FIXME: Eager dial means session creation blocks on SSH connect. + // Eventually make this async or move host info into the prompt + // scripts themselves (running remotely via the RPC). + rsrv, dialErr := remote.Dial(context.Background(), remote.Config{ + SSHTarget: remoteTarget, + CWD: cwd, }) + if dialErr != nil { + return "", fmt.Errorf("remote dial: %w", dialErr) + } + newDisp = tools.NewDispatcherFunc(map[string]func() tools.Server{ + "execute": func() tools.Server { return rsrv }, + }) + remoteEnv = []string{ + "PRIME_PLATFORM=" + rsrv.Info.Platform, + "PRIME_IS_GIT_REPO=" + fmt.Sprintf("%v", rsrv.Info.IsGitRepo), + } } else { newDisp = tools.NewDispatcherFunc(map[string]func() tools.Server{ "execute": execute.Decl(cwd, execOpts...), }) } - rt := agent.BuildRuntime(cfg, newDisp(), cwd, []string{"OLLIE_SESSION_ID=" + sessID, "OLLIE_UNAME=" + uname, "OLLIE=" + MountPathFor(uname)}) + env := []string{"OLLIE_SESSION_ID=" + sessID, "OLLIE_UNAME=" + uname, "OLLIE=" + MountPathFor(uname)} + env = append(env, remoteEnv...) + rt := agent.BuildRuntime(cfg, newDisp(), cwd, env) // sessPtr is set after NewSession; the ReadPlanStep closure captures it. core = agent.NewAgentCore(agent.AgentCoreConfig{