remote: restore sessions with remote= reconnect to remote host
This commit is contained in:
parent
208db7ba68
commit
c4e1950f8c
|
|
@ -802,21 +802,45 @@ func (s *Manager) restoreSession(ps *agent.PersistedSession) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
uname := s.nextUname()
|
uname := s.nextUname()
|
||||||
var execOpts []execute.Option
|
var newDisp func() tools.Dispatcher
|
||||||
if !s.cfg.NoMount {
|
var promptEnv []string
|
||||||
execOpts = append(execOpts, WithMount9P())
|
remoteTarget := ps.Remote
|
||||||
|
|
||||||
|
if remoteTarget != "" {
|
||||||
|
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 },
|
||||||
|
})
|
||||||
|
promptEnv = []string{
|
||||||
|
"PRIME_CWD=" + cwd,
|
||||||
|
"PRIME_PLATFORM=" + rsrv.Info.Platform,
|
||||||
|
"PRIME_IS_GIT_REPO=" + fmt.Sprintf("%v", rsrv.Info.IsGitRepo),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var execOpts []execute.Option
|
||||||
|
if !s.cfg.NoMount {
|
||||||
|
execOpts = append(execOpts, WithMount9P())
|
||||||
|
}
|
||||||
|
if s.cfg.Strict {
|
||||||
|
execOpts = append(execOpts, execute.WithStrict())
|
||||||
|
}
|
||||||
|
if s.cfg.Yolo {
|
||||||
|
execOpts = append(execOpts, execute.WithYolo())
|
||||||
|
}
|
||||||
|
newDisp = tools.NewDispatcherFunc(map[string]func() tools.Server{
|
||||||
|
"execute": execute.Decl(cwd, execOpts...),
|
||||||
|
})
|
||||||
|
promptEnv = agent.PromptEnv(cwd)
|
||||||
}
|
}
|
||||||
if s.cfg.Strict {
|
|
||||||
execOpts = append(execOpts, execute.WithStrict())
|
|
||||||
}
|
|
||||||
if s.cfg.Yolo {
|
|
||||||
execOpts = append(execOpts, execute.WithYolo())
|
|
||||||
}
|
|
||||||
newDisp := tools.NewDispatcherFunc(map[string]func() tools.Server{
|
|
||||||
"execute": execute.Decl(cwd, execOpts...),
|
|
||||||
})
|
|
||||||
env := []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, agent.PromptEnv(cwd)...)
|
env = append(env, promptEnv...)
|
||||||
rt := agent.BuildRuntime(cfg, newDisp(), cwd, env)
|
rt := agent.BuildRuntime(cfg, newDisp(), cwd, env)
|
||||||
|
|
||||||
restoredSession := agent.RestoreSession(ps.Messages)
|
restoredSession := agent.RestoreSession(ps.Messages)
|
||||||
|
|
@ -825,7 +849,6 @@ func (s *Manager) restoreSession(ps *agent.PersistedSession) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var sessPtr *Session
|
var sessPtr *Session
|
||||||
promptEnv := agent.PromptEnv(cwd)
|
|
||||||
core := agent.NewAgentCore(agent.AgentCoreConfig{
|
core := agent.NewAgentCore(agent.AgentCoreConfig{
|
||||||
Backend: be,
|
Backend: be,
|
||||||
AgentName: agentName,
|
AgentName: agentName,
|
||||||
|
|
@ -834,6 +857,7 @@ func (s *Manager) restoreSession(ps *agent.PersistedSession) error {
|
||||||
SessionID: sessID,
|
SessionID: sessID,
|
||||||
Uname: uname,
|
Uname: uname,
|
||||||
CWD: cwd,
|
CWD: cwd,
|
||||||
|
Remote: remoteTarget,
|
||||||
Session: restoredSession,
|
Session: restoredSession,
|
||||||
Runtime: rt,
|
Runtime: rt,
|
||||||
NewDispatcher: newDisp,
|
NewDispatcher: newDisp,
|
||||||
|
|
@ -855,6 +879,14 @@ func (s *Manager) restoreSession(ps *agent.PersistedSession) error {
|
||||||
sess := NewSession(sessID, core, ctx, cancel)
|
sess := NewSession(sessID, core, ctx, cancel)
|
||||||
sessPtr = sess
|
sessPtr = sess
|
||||||
sess.uname = uname
|
sess.uname = uname
|
||||||
|
sess.remote = remoteTarget
|
||||||
|
|
||||||
|
// Start mount for remote sessions (not managed by local execute.Server).
|
||||||
|
if remoteTarget != "" && !s.cfg.NoMount {
|
||||||
|
ms := &mountState{envExtra: make(map[string]string)}
|
||||||
|
startMount(ms, uname)
|
||||||
|
sess.mount = ms
|
||||||
|
}
|
||||||
|
|
||||||
// Replay tail of persisted messages into the chat log so the GUI
|
// Replay tail of persisted messages into the chat log so the GUI
|
||||||
// and `chat` file show recent history on restore.
|
// and `chat` file show recent history on restore.
|
||||||
|
|
@ -1093,6 +1125,7 @@ func (s *Manager) CreateSession(args []string) (string, error) {
|
||||||
SessionID: sessID,
|
SessionID: sessID,
|
||||||
Uname: uname,
|
Uname: uname,
|
||||||
CWD: cwd,
|
CWD: cwd,
|
||||||
|
Remote: remoteTarget,
|
||||||
Runtime: rt,
|
Runtime: rt,
|
||||||
NewDispatcher: newDisp,
|
NewDispatcher: newDisp,
|
||||||
PromptEnvExtra: promptEnv,
|
PromptEnvExtra: promptEnv,
|
||||||
|
|
|
||||||
Reference in New Issue