remote sessions: eager dial, pass host info to prompt resolution
Dial the remote eagerly during session creation so HostInfo is available for BuildRuntime. Pass PRIME_PLATFORM and PRIME_IS_GIT_REPO as env vars so the system prompt reflects the remote host, not the local machine.
This commit is contained in:
parent
b95bab0ef8
commit
28232fd833
|
|
@ -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{
|
||||
|
|
|
|||
Reference in New Issue