From e630714403481ce4ad970b25bffe9000592b42d3 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Wed, 29 Jul 2026 21:46:00 +0200 Subject: [PATCH] 9p: update imports for agent/ package extraction Types moved from ollie/session to ollie/agent: AgentConfig, AgentConfigPath, AgentsDirs, BuildRuntime, Load, Event, PersistedAgent, LoadPersistedAgent, RestoreHistory, PromptEnv, History, Runtime, ErrInterrupted, WatchState. ollie/session is no longer imported directly in top-level 9p/ files or mgr/format.go and mgr/sessionfile.go (they only need agent types). WatchAgent const inlined as string literal. --- dbus.go | 10 +++++----- main.go | 6 +++--- main_test.go | 13 +++++++------ mgr/create.go | 5 +++-- mgr/format.go | 10 +++++----- mgr/manager.go | 3 ++- mgr/persist.go | 13 +++++++------ mgr/session.go | 5 +++-- mgr/sessionfile.go | 6 +++--- 9 files changed, 38 insertions(+), 33 deletions(-) diff --git a/dbus.go b/dbus.go index 8faffea..37c4677 100644 --- a/dbus.go +++ b/dbus.go @@ -13,7 +13,7 @@ import ( "github.com/godbus/dbus/v5" "github.com/godbus/dbus/v5/introspect" - "ollie/session" + "ollie/agent" "ollie/backend" "olliesrv/mgr" ) @@ -139,7 +139,7 @@ func (a *DBusAdapter) startWatcher(id string, sess *mgr.Session) { go func() { current := sess.Core.State() for { - next, ok := sess.Core.WaitChange(ctx, session.WatchState, current) + next, ok := sess.Core.WaitChange(ctx, agent.WatchState, current) if !ok { return } @@ -155,7 +155,7 @@ func (a *DBusAdapter) startWatcher(id string, sess *mgr.Session) { go func() { current := sess.Core.AgentName() for { - next, ok := sess.Core.WaitChange(ctx, session.WatchAgent, current) + next, ok := sess.Core.WaitChange(ctx, "agent", current) if !ok { return } @@ -325,7 +325,7 @@ func (a *DBusAdapter) Interrupt(sessionID string) (bool, *dbus.Error) { if sess == nil { return false, nil } - sess.Core.Interrupt(session.ErrInterrupted) + sess.Core.Interrupt(agent.ErrInterrupted) return true, nil } @@ -461,7 +461,7 @@ func (a *DBusAdapter) ListModels(sessionID string) ([]string, *dbus.Error) { func (a *DBusAdapter) ListAgents() ([]string, *dbus.Error) { var result []string - for _, dir := range session.AgentsDirs() { + for _, dir := range agent.AgentsDirs() { entries, err := os.ReadDir(dir) if err != nil { continue diff --git a/main.go b/main.go index b34609e..7b685f5 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ import ( "syscall" "9fans.net/go/plan9/client" - "ollie/session" + "ollie/agent" "ollie/backend" "ollie/elevate" "ollie/env" @@ -157,7 +157,7 @@ func runServer(sockPath string) { sink := olog.NewSink(os.Stdout, os.Stderr, olog.ParseLevel(os.Getenv("OLLIE_LOG"), olog.LevelWarn)) - agentsDirs := session.AgentsDirs() + agentsDirs := agent.AgentsDirs() sessionsDir := paths.DataDir() + "/sessions" // Create the tool registry @@ -366,7 +366,7 @@ func NewRootStore(reg *tools.Registry) *fs.Tree { }, "agents": func() ([]byte, error) { var sb strings.Builder - for _, dir := range session.AgentsDirs() { + for _, dir := range agent.AgentsDirs() { entries, err := os.ReadDir(dir) if err != nil { continue diff --git a/main_test.go b/main_test.go index dab1557..68f442c 100644 --- a/main_test.go +++ b/main_test.go @@ -12,6 +12,7 @@ import ( "time" "ollie/session" + "ollie/agent" "ollie/backend" olog "ollie/log" "olliesrv/fs" @@ -942,14 +943,14 @@ func TestLoadAgentConfig(t *testing.T) { func TestFormatEvent(t *testing.T) { tests := []struct { - ev session.Event + ev agent.Event want string }{ - {session.Event{Role: "user", Content: "hello"}, "[user]\nhello\n"}, - {session.Event{Role: "assistant", Content: "hi"}, "hi"}, - {session.Event{Role: "call", Name: "fn", Content: "args"}, "[call:fn]\nargs\n"}, - {session.Event{Role: "tool", Name: "fn", Content: "result"}, "[tool:fn]\nresult\n"}, - {session.Event{Role: "info", Content: "msg\n"}, "[info]\nmsg\n"}, + {agent.Event{Role: "user", Content: "hello"}, "[user]\nhello\n"}, + {agent.Event{Role: "assistant", Content: "hi"}, "hi"}, + {agent.Event{Role: "call", Name: "fn", Content: "args"}, "[call:fn]\nargs\n"}, + {agent.Event{Role: "tool", Name: "fn", Content: "result"}, "[tool:fn]\nresult\n"}, + {agent.Event{Role: "info", Content: "msg\n"}, "[info]\nmsg\n"}, } for _, tc := range tests { got := string(mgr.FormatEvent(tc.ev)) diff --git a/mgr/create.go b/mgr/create.go index 76f9c96..0e927ac 100644 --- a/mgr/create.go +++ b/mgr/create.go @@ -2,6 +2,7 @@ package mgr import ( "ollie/session" + "ollie/agent" "context" "fmt" "ollie/backend" @@ -161,7 +162,7 @@ func (s *Manager) CreateSession(args []string) (string, error) { if len(remoteEnv) > 0 { promptEnv = remoteEnv } else { - promptEnv = session.PromptEnv(cwd) + promptEnv = agent.PromptEnv(cwd) } env := []string{"OLLIE_SESSION_ID=" + sessID, "OLLIE_UNAME=" + uname} env = append(env, promptEnv...) @@ -197,7 +198,7 @@ func (s *Manager) CreateSession(args []string) (string, error) { envBlock := prompts.Environment(cwd, platform, isGitRepo, "") disp := newDisp() - rt := session.BuildRuntime(cfg, disp, cwd, env, sysPrompt, opModel, envBlock) + rt := agent.BuildRuntime(cfg, disp, cwd, env, sysPrompt, opModel, envBlock) // sessPtr is set after NewSession; the ReadPlanStep closure captures it. core = session.New(session.Config{ diff --git a/mgr/format.go b/mgr/format.go index bd1cc4e..596f441 100644 --- a/mgr/format.go +++ b/mgr/format.go @@ -1,30 +1,30 @@ package mgr import ( - "ollie/session" + "ollie/agent" "ollie/backend" "os" "strings" ) -func LoadAgentConfig(agentsDir, name string, open func(string) (*os.File, error)) *session.AgentConfig { +func LoadAgentConfig(agentsDir, name string, open func(string) (*os.File, error)) *agent.AgentConfig { if open == nil { open = os.Open } - path := session.AgentConfigPath(agentsDir, name) + path := agent.AgentConfigPath(agentsDir, name) f, err := open(path) if err != nil { return nil } defer f.Close() - cfg, _ := session.Load(f) + cfg, _ := agent.Load(f) return cfg } // FormatEvent converts an agent Event to bytes for appending to a chat log. // Streaming roles (assistant, reasoning) return only the content chunk; // the caller (startEventLog) is responsible for writing the [role] header. -func FormatEvent(ev session.Event) []byte { +func FormatEvent(ev agent.Event) []byte { switch ev.Role { case "user": return []byte("[user]\n" + ev.Content + "\n") diff --git a/mgr/manager.go b/mgr/manager.go index 3a397ee..bf2db80 100644 --- a/mgr/manager.go +++ b/mgr/manager.go @@ -6,6 +6,7 @@ import ( "fmt" "ollie/paths" "ollie/session" + "ollie/agent" "ollie/skills" "ollie/tools" "olliesrv/fs" @@ -588,7 +589,7 @@ func (s *Manager) InterruptAll() { s.mu.RLock() defer s.mu.RUnlock() for _, sess := range s.sessions { - sess.Core.Interrupt(session.ErrInterrupted) + sess.Core.Interrupt(agent.ErrInterrupted) } } diff --git a/mgr/persist.go b/mgr/persist.go index fe91090..c57e1ea 100644 --- a/mgr/persist.go +++ b/mgr/persist.go @@ -2,6 +2,7 @@ package mgr import ( "ollie/session" + "ollie/agent" "context" "fmt" "ollie/backend" @@ -63,7 +64,7 @@ func (s *Manager) restoreAllSessions() { // Load all persisted session JSONs (fast, sequential disk reads) type loadedSession struct { - ps *session.PersistedAgent + ps *agent.PersistedAgent name string } var loaded []loadedSession @@ -72,7 +73,7 @@ func (s *Manager) restoreAllSessions() { continue } path := filepath.Join(dir, e.Name()) - ps, err := session.LoadPersistedAgent(path) + ps, err := agent.LoadPersistedAgent(path) if err != nil { s.cfg.Log.Error("restore session %s: %v", e.Name(), err) continue @@ -98,7 +99,7 @@ func (s *Manager) restoreAllSessions() { wg.Wait() } -func (s *Manager) restoreSession(ps *session.PersistedAgent) error { +func (s *Manager) restoreSession(ps *agent.PersistedAgent) error { cwd := ps.CWD if cwd == "" { cwd, _ = os.Getwd() @@ -170,7 +171,7 @@ func (s *Manager) restoreSession(ps *session.PersistedAgent) error { newDisp = tools.NewDispatcherFunc(map[string]func() tools.Server{ "execute": execute.Decl(cwd, execOpts...), }) - promptEnv = session.PromptEnv(cwd) + promptEnv = agent.PromptEnv(cwd) } env := []string{"OLLIE_SESSION_ID=" + sessID, "OLLIE_UNAME=" + uname} @@ -204,9 +205,9 @@ func (s *Manager) restoreSession(ps *session.PersistedAgent) error { envBlock := prompts.Environment(cwd, platform, isGitRepo, "") disp := newDisp() - rt := session.BuildRuntime(cfg, disp, cwd, env, sysPrompt, opModel, envBlock) + rt := agent.BuildRuntime(cfg, disp, cwd, env, sysPrompt, opModel, envBlock) - restoredSession := session.RestoreHistory(ps) + restoredSession := agent.RestoreHistory(ps) var sessPtr *Session core := session.New(session.Config{ diff --git a/mgr/session.go b/mgr/session.go index c212a44..0b71f63 100644 --- a/mgr/session.go +++ b/mgr/session.go @@ -6,6 +6,7 @@ import ( "time" "ollie/session" + "ollie/agent" ) // Session holds all state for one agent session. @@ -83,7 +84,7 @@ func (sess *Session) Cancel() { } func (sess *Session) Interrupt() { - sess.Core.Interrupt(session.ErrInterrupted) + sess.Core.Interrupt(agent.ErrInterrupted) } // AppendLog appends data to the session's log and bumps the version. @@ -113,7 +114,7 @@ func (sess *Session) startEventLog() { streamingRole := "" // tracks current streaming role ("assistant", "reasoning", or "tool") streamingResponseID := "" - sess.Core.Bus().Subscribe("event", func(ev session.Event) { + sess.Core.Bus().Subscribe("event", func(ev agent.Event) { switch ev.Role { case "assistant", "reasoning": if streamingRole != ev.Role || (ev.Role == "assistant" && ev.ResponseID != streamingResponseID) { diff --git a/mgr/sessionfile.go b/mgr/sessionfile.go index 43455dc..179f64f 100644 --- a/mgr/sessionfile.go +++ b/mgr/sessionfile.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "ollie/session" + "ollie/agent" "ollie/backend" "ollie/tools" olog "ollie/log" @@ -277,7 +277,7 @@ func (h *sessionHelper) fileSpec(name string, mode os.FileMode) fs.FileSpec { if base == "" { base = h.sess.Core.State() } - v, ok := h.sess.Core.WaitChange(ctx, session.WatchState, base) + v, ok := h.sess.Core.WaitChange(ctx, agent.WatchState, base) if !ok { s := h.sess.Core.State() return []byte(s + "\n"), s, nil @@ -637,7 +637,7 @@ func (h *sessionHelper) handleCtl(input string) error { } switch cmd[0] { case "stop": - h.sess.Core.Interrupt(session.ErrInterrupted) + h.sess.Core.Interrupt(agent.ErrInterrupted) case "kill": h.kill() case "rn":