fix: agent rename uses SetName() not Submit(/agent ...); add SetName method to agent.Agent

This commit is contained in:
Ollie Agent 2026-08-01 18:12:18 +02:00
parent d90fd1448f
commit ff17a90bbf
3 changed files with 9 additions and 2 deletions

View File

@ -66,6 +66,13 @@ func (ag *Agent) Backend() backend.Backend {
// Name returns the agent's name.
func (ag *Agent) Name() string { return ag.agentName }
// SetName changes the agent's display name without reloading config.
func (ag *Agent) SetName(name string) {
ag.stateMu.Lock()
ag.agentName = name
ag.stateMu.Unlock()
}
// ID returns the agent's unique identity.
func (ag *Agent) ID() string { return ag.id }

View File

@ -198,7 +198,7 @@ func (h *agentHelper) fileSpec(name string, mode os.FileMode) FileSpec {
if newName == "" {
return nil
}
h.sess.Core.Agent().Submit(h.sess.SessionCtx, "/agent "+newName)
h.sess.Core.Agent().SetName(newName)
return nil
}
case "cwd":

View File

@ -147,7 +147,7 @@ func NewRoot(cfg Config) *Tree {
if sess == nil {
return fmt.Errorf("session not found: %s", sessName)
}
sess.Core.Agent().Submit(sess.SessionCtx, "/agent "+new)
sess.Core.Agent().SetName(new)
rs.cfg.Log.Info("renamed agent in session %s -> %s", sessName, new)
broadcastEvents()
return nil