9p: route all agent operations through .Agent()

Interrupt, Queue, Detach, ListDetached, SignalDetached,
GetDetachedOutput, DismissDetached, InjectSystemEvent
now go through sess.Core.Agent() directly.

Session only provides: Agent(), Bus(), Close(), SetEnv(),
CWD(), SetCWD(), SetSessionID(), WaitChange(), SaveSession().
This commit is contained in:
Levi Neely 2026-07-29 22:05:56 +02:00
parent 5ecbd481ed
commit aeef7ff718
6 changed files with 18 additions and 18 deletions

14
dbus.go
View File

@ -199,7 +199,7 @@ func (a *DBusAdapter) startWatcher(id string, sess *mgr.Session) {
return return
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
} }
infos := sess.Core.ListDetached() infos := sess.Core.Agent().ListDetached()
// Clean up stale entries from exitedPIDs // Clean up stale entries from exitedPIDs
activePIDs := make(map[int]bool, len(infos)) activePIDs := make(map[int]bool, len(infos))
for _, info := range infos { for _, info := range infos {
@ -325,7 +325,7 @@ func (a *DBusAdapter) Interrupt(sessionID string) (bool, *dbus.Error) {
if sess == nil { if sess == nil {
return false, nil return false, nil
} }
sess.Core.Interrupt(agent.ErrInterrupted) sess.Core.Agent().Interrupt(agent.ErrInterrupted)
return true, nil return true, nil
} }
@ -514,7 +514,7 @@ func (a *DBusAdapter) DetachProcess(sessionID string) (bool, *dbus.Error) {
if sess == nil { if sess == nil {
return false, dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID)) return false, dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID))
} }
if !sess.Core.Detach() { if !sess.Core.Agent().Detach() {
return false, dbus.MakeFailedError(fmt.Errorf("no running process to detach")) return false, dbus.MakeFailedError(fmt.Errorf("no running process to detach"))
} }
a.conn.Emit(busPath, busIface+".ProcessDetached", sessionID) a.conn.Emit(busPath, busIface+".ProcessDetached", sessionID)
@ -526,7 +526,7 @@ func (a *DBusAdapter) ListDetached(sessionID string) ([]string, *dbus.Error) {
if sess == nil { if sess == nil {
return nil, dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID)) return nil, dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID))
} }
infos := sess.Core.ListDetached() infos := sess.Core.Agent().ListDetached()
out := make([]string, len(infos)) out := make([]string, len(infos))
for i, info := range infos { for i, info := range infos {
status := "running" status := "running"
@ -552,7 +552,7 @@ func (a *DBusAdapter) SignalDetached(sessionID string, pid int32, signal string)
default: default:
return false, dbus.MakeFailedError(fmt.Errorf("unsupported signal: %s", signal)) return false, dbus.MakeFailedError(fmt.Errorf("unsupported signal: %s", signal))
} }
if err := sess.Core.SignalDetached(int(pid), sig); err != nil { if err := sess.Core.Agent().SignalDetached(int(pid), sig); err != nil {
return false, dbus.MakeFailedError(err) return false, dbus.MakeFailedError(err)
} }
return true, nil return true, nil
@ -563,7 +563,7 @@ func (a *DBusAdapter) GetDetachedOutput(sessionID string, pid int32) (string, *d
if sess == nil { if sess == nil {
return "", dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID)) return "", dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID))
} }
output, err := sess.Core.GetDetachedOutput(int(pid)) output, err := sess.Core.Agent().GetDetachedOutput(int(pid))
if err != nil { if err != nil {
return "", dbus.MakeFailedError(err) return "", dbus.MakeFailedError(err)
} }
@ -575,7 +575,7 @@ func (a *DBusAdapter) DismissDetached(sessionID string, pid int32) (bool, *dbus.
if sess == nil { if sess == nil {
return false, dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID)) return false, dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID))
} }
return sess.Core.DismissDetached(int(pid)), nil return sess.Core.Agent().DismissDetached(int(pid)), nil
} }
// --- Generate / Route --- // --- Generate / Route ---

View File

@ -533,7 +533,7 @@ func TestSessionFileStoreContentAllFields(t *testing.T) {
func TestSessionFileStoreReadFifoOut(t *testing.T) { func TestSessionFileStoreReadFifoOut(t *testing.T) {
sess := testSession("s1") sess := testSession("s1")
defer sess.Cancel() defer sess.Cancel()
sess.Core.Queue("queued-item") sess.Core.Agent().Queue("queued-item")
sf := newTestSessionFileStore(t, sess) sf := newTestSessionFileStore(t, sess)
data := testStoreRead(t, sf, "fifo.out") data := testStoreRead(t, sf, "fifo.out")

View File

@ -175,7 +175,7 @@ func (s *Manager) Readdir(name string) ([]os.DirEntry, error) {
} }
// {id}/agent/{aid}/proc — list detached process PIDs // {id}/agent/{aid}/proc — list detached process PIDs
if len(parts) == 4 && parts[3] == "proc" { if len(parts) == 4 && parts[3] == "proc" {
procs := sess.Core.ListDetached() procs := sess.Core.Agent().ListDetached()
entries := make([]os.DirEntry, len(procs)) entries := make([]os.DirEntry, len(procs))
for i, p := range procs { for i, p := range procs {
entries[i] = fs.FileEntry(fmt.Sprintf("%d", p.PID), 0666) entries[i] = fs.FileEntry(fmt.Sprintf("%d", p.PID), 0666)
@ -374,7 +374,7 @@ func (s *Manager) openEntry(name string) (fs.File, error) {
return &fs.SyntheticFileInfo{Name_: pidStr, Mode_: 0444}, nil return &fs.SyntheticFileInfo{Name_: pidStr, Mode_: 0444}, nil
}, },
ReadFn: func() ([]byte, error) { ReadFn: func() ([]byte, error) {
output, err := sess.Core.GetDetachedOutput(pid) output, err := sess.Core.Agent().GetDetachedOutput(pid)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -514,7 +514,7 @@ func (s *Manager) del(name string) error {
if err != nil { if err != nil {
return fmt.Errorf("invalid pid: %s", parts[2]) return fmt.Errorf("invalid pid: %s", parts[2])
} }
if !sess.Core.DismissDetached(pid) { if !sess.Core.Agent().DismissDetached(pid) {
return fmt.Errorf("process %d not found or still running", pid) return fmt.Errorf("process %d not found or still running", pid)
} }
return nil return nil
@ -589,7 +589,7 @@ func (s *Manager) InterruptAll() {
s.mu.RLock() s.mu.RLock()
defer s.mu.RUnlock() defer s.mu.RUnlock()
for _, sess := range s.sessions { for _, sess := range s.sessions {
sess.Core.Interrupt(agent.ErrInterrupted) sess.Core.Agent().Interrupt(agent.ErrInterrupted)
} }
} }

View File

@ -86,7 +86,7 @@ func (sess *Session) Cancel() {
} }
func (sess *Session) Interrupt() { func (sess *Session) Interrupt() {
sess.Core.Interrupt(agent.ErrInterrupted) sess.Core.Agent().Interrupt(agent.ErrInterrupted)
} }
// AppendLog appends data to the session's log and bumps the version. // AppendLog appends data to the session's log and bumps the version.

View File

@ -214,7 +214,7 @@ func (h *sessionHelper) fileSpec(name string, mode os.FileMode) fs.FileSpec {
if input == "" { if input == "" {
return nil return nil
} }
h.sess.Core.Queue(input) h.sess.Core.Agent().Queue(input)
return nil return nil
} }
case "ctl": case "ctl":
@ -637,7 +637,7 @@ func (h *sessionHelper) handleCtl(input string) error {
} }
switch cmd[0] { switch cmd[0] {
case "stop": case "stop":
h.sess.Core.Interrupt(agent.ErrInterrupted) h.sess.Core.Agent().Interrupt(agent.ErrInterrupted)
case "kill": case "kill":
h.kill() h.kill()
case "rn": case "rn":
@ -653,7 +653,7 @@ func (h *sessionHelper) handleCtl(input string) error {
h.sess.mu.RUnlock() h.sess.mu.RUnlock()
return h.saveTranscript(data) return h.saveTranscript(data)
case "detach": case "detach":
if !h.sess.Core.Detach() { if !h.sess.Core.Agent().Detach() {
return fmt.Errorf("no running process to detach") return fmt.Errorf("no running process to detach")
} }
case "signal": case "signal":
@ -668,7 +668,7 @@ func (h *sessionHelper) handleCtl(input string) error {
if len(cmd) >= 3 && strings.ToUpper(cmd[2]) == "KILL" { if len(cmd) >= 3 && strings.ToUpper(cmd[2]) == "KILL" {
sig = 9 sig = 9
} }
if err := h.sess.Core.SignalDetached(pid, sig); err != nil { if err := h.sess.Core.Agent().SignalDetached(pid, sig); err != nil {
return err return err
} }
case "invalidate": case "invalidate":

View File

@ -553,7 +553,7 @@ func (s *Server) pathType(path string) string {
if sess == nil { if sess == nil {
return "" return ""
} }
for _, p := range sess.Core.ListDetached() { for _, p := range sess.Core.Agent().ListDetached() {
if fmt.Sprintf("%d", p.PID) == parts[2] { if fmt.Sprintf("%d", p.PID) == parts[2] {
return "file" return "file"
} }