diff --git a/dbus.go b/dbus.go index 22d3dd4..23dd764 100644 --- a/dbus.go +++ b/dbus.go @@ -301,7 +301,7 @@ func (a *DBusAdapter) Submit(sessionID, prompt string) (bool, *dbus.Error) { if sess == nil { return false, nil } - go sess.Core.Agent().Submit(sess.Ctx, prompt) + go sess.Core.Agent().Submit(sess.SessionCtx, prompt) return true, nil } @@ -393,7 +393,7 @@ func (a *DBusAdapter) SetConfig(sessionID, key, value string) (bool, *dbus.Error } switch key { case "model": - sess.Core.Agent().Submit(sess.Ctx, "/model "+value) + sess.Core.Agent().Submit(sess.SessionCtx, "/model "+value) case "cwd": if err := sess.Core.SetCWD(value); err != nil { return false, nil @@ -652,7 +652,7 @@ func (a *DBusAdapter) Compact(sessionID string) (bool, *dbus.Error) { if sess == nil { return false, nil } - sess.Core.Agent().Submit(sess.Ctx, "/compact") + sess.Core.Agent().Submit(sess.SessionCtx, "/compact") return true, nil } @@ -661,7 +661,7 @@ func (a *DBusAdapter) ClearContext(sessionID string) (bool, *dbus.Error) { if sess == nil { return false, nil } - sess.Core.Agent().Submit(sess.Ctx, "/clear") + sess.Core.Agent().Submit(sess.SessionCtx, "/clear") return true, nil } diff --git a/main_test.go b/main_test.go index c2cbcd5..191ff2a 100644 --- a/main_test.go +++ b/main_test.go @@ -301,7 +301,7 @@ func TestSessionManagerDeleteAndKill(t *testing.T) { t.Error("session should be gone after Delete") } // Verify core was closed by checking ctx is cancelled - if sess.Ctx.Err() == nil { + if sess.SessionCtx.Err() == nil { t.Error("session ctx should be cancelled after Delete") } if err := s.Tree().Delete("nope"); err == nil { @@ -328,7 +328,7 @@ func TestSessionManagerInterruptAll(t *testing.T) { defer sess.Cancel() // Submit in background to make it "running" - go sess.Core.Agent().Submit(sess.Ctx, "hello") + go sess.Core.Agent().Submit(sess.SessionCtx, "hello") time.Sleep(50 * time.Millisecond) // let it enter thinking state s.AddSession(sess) @@ -384,7 +384,7 @@ func TestSessionManagerRenameErrors(t *testing.T) { } // running sess := testBlockingSession("r") - go sess.Core.Agent().Submit(sess.Ctx, "hello") + go sess.Core.Agent().Submit(sess.SessionCtx, "hello") time.Sleep(50 * time.Millisecond) s.AddSession(sess) if err := s.Tree().Rename("r", "r2"); err == nil { @@ -625,7 +625,7 @@ func TestSessionFileStoreWriteBackendWhileRunning(t *testing.T) { defer sess.Cancel() // Make session running - go sess.Core.Agent().Submit(sess.Ctx, "hello") + go sess.Core.Agent().Submit(sess.SessionCtx, "hello") time.Sleep(50 * time.Millisecond) sf := newTestSessionFileStore(t, sess) @@ -660,7 +660,7 @@ func TestSessionFileStoreWriteParamsWhileRunning(t *testing.T) { sess := testBlockingSession("s1") defer sess.Cancel() - go sess.Core.Agent().Submit(sess.Ctx, "hello") + go sess.Core.Agent().Submit(sess.SessionCtx, "hello") time.Sleep(50 * time.Millisecond) sf := newTestSessionFileStore(t, sess) @@ -676,7 +676,7 @@ func TestSessionFileStoreHandleCtl(t *testing.T) { defer sess.Cancel() // Make session running for interrupt test - go sess.Core.Agent().Submit(sess.Ctx, "hello") + go sess.Core.Agent().Submit(sess.SessionCtx, "hello") time.Sleep(50 * time.Millisecond) sf := newTestSessionFileStore(t, sess) @@ -725,7 +725,7 @@ func TestSessionFileStoreBlockingRead(t *testing.T) { return } // Use BlockingRead which invokes the Wait function - data, _, _ := e.BlockingRead(sess.Ctx, "") + data, _, _ := e.BlockingRead(sess.SessionCtx, "") done <- string(data) }() @@ -733,7 +733,7 @@ func TestSessionFileStoreBlockingRead(t *testing.T) { time.Sleep(100 * time.Millisecond) // Submit triggers state change: idle → thinking - go sess.Core.Agent().Submit(sess.Ctx, "trigger") + go sess.Core.Agent().Submit(sess.SessionCtx, "trigger") select { case v := <-done: @@ -1070,7 +1070,7 @@ func TestSessionInterrupt(t *testing.T) { sess := testBlockingSession("s1") defer sess.Cancel() - go sess.Core.Agent().Submit(sess.Ctx, "hello") + go sess.Core.Agent().Submit(sess.SessionCtx, "hello") time.Sleep(50 * time.Millisecond) sess.Interrupt() diff --git a/mgr/create.go b/mgr/create.go index 16543fd..c528e72 100644 --- a/mgr/create.go +++ b/mgr/create.go @@ -228,8 +228,8 @@ func (s *Manager) CreateSession(args []string) (string, error) { }) } - ctx, cancel := context.WithCancel(s.cfg.Ctx) - sess := NewSession(sessID, core, ctx, cancel) + sessionCtx, sessionCancel := context.WithCancel(s.cfg.Ctx) + sess := NewSession(sessID, core, sessionCtx, sessionCancel) sessPtr = sess sess.remote = remoteTarget @@ -241,7 +241,7 @@ func (s *Manager) CreateSession(args []string) (string, error) { s.mu.Unlock() // HACK: Load the agent now that the session mount is active. - core.Agent().Submit(ctx, "/agent "+agentName) + core.Agent().Submit(sessionCtx, "/agent "+agentName) s.cfg.Log.Info("new session %s (backend=%s model=%s agent=%s)", sessID, core.Agent().BackendName(), core.Agent().ModelName(), core.Agent().Name()) diff --git a/mgr/persist.go b/mgr/persist.go index 022f2b5..e4573fc 100644 --- a/mgr/persist.go +++ b/mgr/persist.go @@ -237,8 +237,8 @@ func (s *Manager) restoreSession(ps *agent.PersistedAgent) error { }, }) - ctx, cancel := context.WithCancel(s.cfg.Ctx) - sess := NewSession(sessID, core, ctx, cancel) + sessionCtx, sessionCancel := context.WithCancel(s.cfg.Ctx) + sess := NewSession(sessID, core, sessionCtx, sessionCancel) sessPtr = sess sess.uname = uname sess.remote = remoteTarget diff --git a/mgr/session.go b/mgr/session.go index 86ab6b6..4ca9345 100644 --- a/mgr/session.go +++ b/mgr/session.go @@ -16,7 +16,7 @@ type Session struct { id string uname string // immutable user principal (numeric UID), set at creation Core *session.Session - Ctx context.Context + SessionCtx context.Context cancel context.CancelFunc log []byte logVers uint32 @@ -32,7 +32,7 @@ type Session struct { } func NewSession(id string, core *session.Session, ctx context.Context, cancel context.CancelFunc) *Session { - sess := &Session{id: id, Core: core, Ctx: ctx, cancel: cancel} + sess := &Session{id: id, Core: core, SessionCtx: ctx, cancel: cancel} sess.startEventLog() return sess } diff --git a/mgr/sessionfile.go b/mgr/sessionfile.go index f853b34..bfeb9a4 100644 --- a/mgr/sessionfile.go +++ b/mgr/sessionfile.go @@ -203,7 +203,7 @@ func (h *sessionHelper) fileSpec(name string, mode os.FileMode) fs.FileSpec { h.sess.prevPrompt = []byte(input) h.sess.mu.Unlock() go func() { - h.sess.Core.Agent().Submit(h.sess.Ctx, input) + h.sess.Core.Agent().Submit(h.sess.SessionCtx, input) h.sess.EnsureTrailingNewline() }() return nil @@ -273,7 +273,7 @@ func (h *sessionHelper) fileSpec(name string, mode os.FileMode) fs.FileSpec { fs.Wait = func(connCtx context.Context, base string) ([]byte, string, error) { ctx, cancel := context.WithCancel(connCtx) defer cancel() - context.AfterFunc(h.sess.Ctx, cancel) + context.AfterFunc(h.sess.SessionCtx, cancel) if base == "" { base = h.sess.Core.Agent().State() } @@ -486,7 +486,7 @@ func (h *sessionHelper) handleCfg(input string) error { if h.sess.Core.Agent().IsRunning() { return fmt.Errorf("cannot switch %s while agent is running", k) } - h.sess.Core.Agent().Submit(h.sess.Ctx, "/agent "+v) + h.sess.Core.Agent().Submit(h.sess.SessionCtx, "/agent "+v) case "backend", "model": if v == "" { continue @@ -616,10 +616,10 @@ func (h *sessionHelper) handleCfg(input string) error { } // Apply backend/model after agent= so manual overrides win. if deferredBackend != "" { - h.sess.Core.Agent().Submit(h.sess.Ctx, "/backend "+deferredBackend) + h.sess.Core.Agent().Submit(h.sess.SessionCtx, "/backend "+deferredBackend) } if deferredModel != "" { - h.sess.Core.Agent().Submit(h.sess.Ctx, "/model "+deferredModel) + h.sess.Core.Agent().Submit(h.sess.SessionCtx, "/model "+deferredModel) } if hasParams { if h.sess.Core.Agent().IsRunning() { @@ -680,7 +680,7 @@ func (h *sessionHelper) handleCtl(input string) error { "agents", "agent", "sessions", "cwd", "skills", "tools", "context", "usage", "cost", "history", "irw", "help": - h.sess.Core.Agent().Submit(h.sess.Ctx, "/"+input) + h.sess.Core.Agent().Submit(h.sess.SessionCtx, "/"+input) default: return fmt.Errorf("unknown ctl command: %s", cmd[0]) }