diff --git a/cmd/olliesrv/internal/fs/ctl.go b/cmd/olliesrv/internal/fs/ctl.go index ed45c2b..5a0d701 100644 --- a/cmd/olliesrv/internal/fs/ctl.go +++ b/cmd/olliesrv/internal/fs/ctl.go @@ -6,12 +6,12 @@ import ( ) // rdwrHandler is a request-response ctl command handler. -type rdwrHandler func(ctx HandlerCtx, args []string) ([]byte, error) +type rdwrHandler func(ctx Hctx, args []string) ([]byte, error) // rdwrDispatch returns a Request handler that dispatches based on the first // whitespace-delimited word in the input. -func rdwrDispatch(handlers map[string]rdwrHandler) func(HandlerCtx, []byte) ([]byte, error) { - return func(ctx HandlerCtx, data []byte) ([]byte, error) { +func rdwrDispatch(handlers map[string]rdwrHandler) func(Hctx, []byte) ([]byte, error) { + return func(ctx Hctx, data []byte) ([]byte, error) { input := strings.TrimSpace(string(data)) if input == "" { return nil, nil diff --git a/cmd/olliesrv/internal/fs/handlers_agent.go b/cmd/olliesrv/internal/fs/handlers_agent.go index 4b4863f..9e64640 100644 --- a/cmd/olliesrv/internal/fs/handlers_agent.go +++ b/cmd/olliesrv/internal/fs/handlers_agent.go @@ -14,7 +14,7 @@ import ( "ollie/cmd/olliesrv/internal/session" ) -func requestAgentNew(ctx HandlerCtx, data []byte) ([]byte, error) { +func requestAgentNew(ctx Hctx, data []byte) ([]byte, error) { args := strings.Fields(string(data)) ag, err := session.CreateAgent(ctx.Session.Name(), args) if err != nil { @@ -29,14 +29,14 @@ func requestAgentNew(ctx HandlerCtx, data []byte) ([]byte, error) { // agentBindings returns bindings for all agents in a session. // The Blueprint pattern clones the structure and binds ctx.Agent + ctx.AgentLog. -func agentBindings(ctx HandlerCtx) ([]Binding, error) { +func agentBindings(ctx Hctx) ([]Binding, error) { sess := ctx.Session - if sess == nil || sess.Core == nil { + if sess == nil || sess.Session == nil { return nil, nil } var out []Binding - for _, ag := range sess.Core.Agents() { + for _, ag := range sess.Session.Agents() { a := ag // capture al := sess.AgentLogFor(a.ID()) if al == nil { @@ -47,7 +47,7 @@ func agentBindings(ctx HandlerCtx) ([]Binding, error) { Aliases: []string{a.ID()}, UID: a.ID(), GID: "agent", - Applier: func(c HandlerCtx) HandlerCtx { + Applier: func(c Hctx) Hctx { c.Agent = a c.AgentLog = al return c @@ -62,7 +62,7 @@ func agentBindings(ctx HandlerCtx) ([]Binding, error) { return out, nil } -func writeAgentPrompt(ctx HandlerCtx, data []byte) error { +func writeAgentPrompt(ctx Hctx, data []byte) error { input := strings.TrimSpace(string(data)) if input == "" { return nil @@ -78,7 +78,7 @@ func writeAgentPrompt(ctx HandlerCtx, data []byte) error { return nil } -func writeAgentFifoIn(ctx HandlerCtx, data []byte) error { +func writeAgentFifoIn(ctx Hctx, data []byte) error { input := strings.TrimSpace(string(data)) if input == "" { return nil @@ -87,7 +87,7 @@ func writeAgentFifoIn(ctx HandlerCtx, data []byte) error { return nil } -func readAgentFifoOut(ctx HandlerCtx) ([]byte, error) { +func readAgentFifoOut(ctx Hctx) ([]byte, error) { item, ok := ctx.Agent.PopQueue() if !ok { return nil, nil @@ -102,7 +102,7 @@ func statAgentChat() os.FileInfo { return &SyntheticFileInfo{Name_: "chat", Mode_: 0444, Size_: 64 * 1024} } -func readAgentChat(ctx HandlerCtx) ([]byte, error) { +func readAgentChat(ctx Hctx) ([]byte, error) { ctx.AgentLog.mu.RLock() defer ctx.AgentLog.mu.RUnlock() data := make([]byte, len(ctx.AgentLog.log)) @@ -110,19 +110,19 @@ func readAgentChat(ctx HandlerCtx) ([]byte, error) { return data, nil } -func readAgentChatText(ctx HandlerCtx) ([]byte, error) { +func readAgentChatText(ctx Hctx) ([]byte, error) { ctx.AgentLog.mu.RLock() defer ctx.AgentLog.mu.RUnlock() return stripMarkers(ctx.AgentLog.log), nil } -func streamAgentChat(ctx HandlerCtx, cctx context.Context, base string) ([]byte, string, error) { +func streamAgentChat(ctx Hctx, cctx context.Context, base string) ([]byte, string, error) { merged, cancel := mergeCtx(ctx, cctx) defer cancel() return streamChat(ctx.AgentLog, merged, base) } -func streamAgentChatText(ctx HandlerCtx, cctx context.Context, base string) ([]byte, string, error) { +func streamAgentChatText(ctx Hctx, cctx context.Context, base string) ([]byte, string, error) { merged, cancel := mergeCtx(ctx, cctx) defer cancel() for { @@ -175,7 +175,7 @@ func stripMarkers(data []byte) []byte { return out } -func blockAgentStateWait(ctx HandlerCtx, cctx context.Context, base string) ([]byte, string, error) { +func blockAgentStateWait(ctx Hctx, cctx context.Context, base string) ([]byte, string, error) { merged, cancel := mergeCtx(ctx, cctx) defer cancel() if base == "" { @@ -189,7 +189,7 @@ func blockAgentStateWait(ctx HandlerCtx, cctx context.Context, base string) ([]b return []byte(v + "\n"), v, nil } -func readAgentLog(ctx HandlerCtx) ([]byte, error) { +func readAgentLog(ctx Hctx) ([]byte, error) { const maxWindow = 64 * 1024 ctx.AgentLog.mu.RLock() log := ctx.AgentLog.log @@ -203,7 +203,7 @@ func readAgentLog(ctx HandlerCtx) ([]byte, error) { return data, nil } -func readAgentPlan(ctx HandlerCtx) ([]byte, error) { +func readAgentPlan(ctx Hctx) ([]byte, error) { ctx.AgentLog.mu.RLock() data := make([]byte, len(ctx.AgentLog.plan)) copy(data, ctx.AgentLog.plan) @@ -211,7 +211,7 @@ func readAgentPlan(ctx HandlerCtx) ([]byte, error) { return data, nil } -func writeAgentPlan(ctx HandlerCtx, data []byte) error { +func writeAgentPlan(ctx Hctx, data []byte) error { ctx.AgentLog.mu.Lock() ctx.AgentLog.plan = make([]byte, len(data)) copy(ctx.AgentLog.plan, data) @@ -219,7 +219,7 @@ func writeAgentPlan(ctx HandlerCtx, data []byte) error { return nil } -func readAgentCfg(ctx HandlerCtx) ([]byte, error) { +func readAgentCfg(ctx Hctx) ([]byte, error) { ctx.AgentLog.mu.RLock() defer ctx.AgentLog.mu.RUnlock() p := ctx.Agent.GenParams() @@ -248,7 +248,7 @@ func readAgentCfg(ctx HandlerCtx) ([]byte, error) { return []byte(sb.String()), nil } -func writeAgentCfg(ctx HandlerCtx, data []byte) error { +func writeAgentCfg(ctx Hctx, data []byte) error { input := strings.TrimSpace(string(data)) if input == "" { return nil @@ -268,35 +268,35 @@ func writeAgentCfg(ctx HandlerCtx, data []byte) error { return nil } -func requestAgentCtl(ctx HandlerCtx, data []byte) ([]byte, error) { +func requestAgentCtl(ctx Hctx, data []byte) ([]byte, error) { return rdwrDispatch(agentCtlHandlers)(ctx, data) } var agentCtlHandlers = map[string]rdwrHandler{ - "kill": func(ctx HandlerCtx, _ []string) ([]byte, error) { - if ctx.Session.Core != nil { - ctx.Session.Core.RemoveAgent(ctx.Agent.ID()) + "kill": func(ctx Hctx, _ []string) ([]byte, error) { + if ctx.Session.Session != nil { + ctx.Session.Session.RemoveAgent(ctx.Agent.ID()) session.PublishEvent("session."+ctx.Session.ID()+".agent."+ctx.Agent.ID()+".kill", "") } return []byte("ok\n"), nil }, - "stop": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "stop": func(ctx Hctx, _ []string) ([]byte, error) { ctx.Agent.Interrupt(agent.ErrInterrupted) return []byte("ok\n"), nil }, - "compact": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "compact": func(ctx Hctx, _ []string) ([]byte, error) { if err := ctx.Agent.Compact(ctx.Session.Ctx()); err != nil { return nil, err } return []byte("ok\n"), nil }, - "clear": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "clear": func(ctx Hctx, _ []string) ([]byte, error) { if err := ctx.Agent.Clear(); err != nil { return nil, err } return []byte("ok\n"), nil }, - "inject": func(ctx HandlerCtx, args []string) ([]byte, error) { + "inject": func(ctx Hctx, args []string) ([]byte, error) { text := strings.Join(args, " ") if text == "" { return nil, fmt.Errorf("inject requires text") @@ -304,7 +304,7 @@ var agentCtlHandlers = map[string]rdwrHandler{ ctx.Agent.InjectRewrite(text) return []byte("ok\n"), nil }, - "i": func(ctx HandlerCtx, args []string) ([]byte, error) { + "i": func(ctx Hctx, args []string) ([]byte, error) { text := strings.Join(args, " ") if text == "" { return nil, fmt.Errorf("inject requires text") @@ -312,7 +312,7 @@ var agentCtlHandlers = map[string]rdwrHandler{ ctx.Agent.InjectRewrite(text) return []byte("ok\n"), nil }, - "agent": func(ctx HandlerCtx, args []string) ([]byte, error) { + "agent": func(ctx Hctx, args []string) ([]byte, error) { if len(args) == 0 { return []byte(ctx.Agent.Profile() + "\n"), nil } @@ -321,7 +321,7 @@ var agentCtlHandlers = map[string]rdwrHandler{ } return []byte(args[0] + "\n"), nil }, - "model": func(ctx HandlerCtx, args []string) ([]byte, error) { + "model": func(ctx Hctx, args []string) ([]byte, error) { if len(args) == 0 { if be := ctx.Agent.Backend(); be != nil { return []byte(be.Model() + "\n"), nil @@ -333,13 +333,13 @@ var agentCtlHandlers = map[string]rdwrHandler{ } return []byte(strings.Join(args, " ") + "\n"), nil }, - "models": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "models": func(ctx Hctx, _ []string) ([]byte, error) { return []byte(ctx.Session.CachedListModels() + "\n"), nil }, - "tools": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "tools": func(ctx Hctx, _ []string) ([]byte, error) { return readAgentTools(ctx) }, - "tool_load": func(ctx HandlerCtx, args []string) ([]byte, error) { + "tool_load": func(ctx Hctx, args []string) ([]byte, error) { if len(args) == 0 { return nil, fmt.Errorf("tool_load requires a tool name") } @@ -353,7 +353,7 @@ var agentCtlHandlers = map[string]rdwrHandler{ ctx.Agent.RefreshTools() return []byte(args[0] + "\n"), nil }, - "backend": func(ctx HandlerCtx, args []string) ([]byte, error) { + "backend": func(ctx Hctx, args []string) ([]byte, error) { if len(args) == 0 { if be := ctx.Agent.Backend(); be != nil { return []byte(be.Name() + "\n"), nil @@ -362,14 +362,14 @@ var agentCtlHandlers = map[string]rdwrHandler{ } return nil, fmt.Errorf("backend switching not supported via ctl; use cfg") }, - "name": func(ctx HandlerCtx, args []string) ([]byte, error) { + "name": func(ctx Hctx, args []string) ([]byte, error) { if len(args) == 0 { return []byte(ctx.Agent.Name() + "\n"), nil } ctx.Agent.SetName(strings.Join(args, " ")) return []byte(strings.Join(args, " ") + "\n"), nil }, - "cwd": func(ctx HandlerCtx, args []string) ([]byte, error) { + "cwd": func(ctx Hctx, args []string) ([]byte, error) { if len(args) == 0 { return []byte(ctx.Agent.Cwd() + "\n"), nil } @@ -380,10 +380,10 @@ var agentCtlHandlers = map[string]rdwrHandler{ ctx.Agent.SetCWD(dir) return []byte(dir + "\n"), nil }, - "systemprompt": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "systemprompt": func(ctx Hctx, _ []string) ([]byte, error) { return []byte(ctx.Agent.SystemPrompt() + "\n"), nil }, - "help": func(_ HandlerCtx, _ []string) ([]byte, error) { + "help": func(_ Hctx, _ []string) ([]byte, error) { return []byte(`stop — interrupt running agent compact — compact context clear — clear history @@ -402,14 +402,14 @@ help — this message }, } -func readAgentStats(ctx HandlerCtx) ([]byte, error) { +func readAgentStats(ctx Hctx) ([]byte, error) { s := "usage=" + ctx.Agent.UsageStr() + "\n" + "cost=" + ctx.Agent.CostStr() + "\n" + "ctxsz=" + ctx.Agent.CtxSz() + "\n" return []byte(s), nil } -func readAgentTools(ctx HandlerCtx) ([]byte, error) { +func readAgentTools(ctx Hctx) ([]byte, error) { ts := ctx.Agent.ToolServer() if ts == nil { return []byte("(no tool server)\n"), nil @@ -429,7 +429,7 @@ func readAgentTools(ctx HandlerCtx) ([]byte, error) { return []byte(sb.String()), nil } -func writeAgentTools(ctx HandlerCtx, data []byte) error { +func writeAgentTools(ctx Hctx, data []byte) error { name := strings.TrimSpace(string(data)) if name == "" { return nil @@ -445,11 +445,11 @@ func writeAgentTools(ctx HandlerCtx, data []byte) error { return nil } -func readAgentName(ctx HandlerCtx) ([]byte, error) { +func readAgentName(ctx Hctx) ([]byte, error) { return []byte(ctx.Agent.Name() + "\n"), nil } -func writeAgentName(ctx HandlerCtx, data []byte) error { +func writeAgentName(ctx Hctx, data []byte) error { newName := strings.TrimSpace(string(data)) if newName == "" { return nil @@ -459,7 +459,7 @@ func writeAgentName(ctx HandlerCtx, data []byte) error { return nil } -func readAgentID(ctx HandlerCtx) ([]byte, error) { +func readAgentID(ctx Hctx) ([]byte, error) { return []byte(ctx.Agent.ID() + "\n"), nil } @@ -495,7 +495,7 @@ func streamChat(al *AgentLog, cctx context.Context, base string) ([]byte, string } // processBindings returns bindings for detached processes. -func processBindings(ctx HandlerCtx) ([]Binding, error) { +func processBindings(ctx Hctx) ([]Binding, error) { if ctx.Session == nil { return nil, nil } @@ -512,7 +512,7 @@ func processBindings(ctx HandlerCtx) ([]Binding, error) { id := pid // capture out = append(out, Binding{ Name: strconv.Itoa(id), - Applier: func(c HandlerCtx) HandlerCtx { + Applier: func(c Hctx) Hctx { c.Data = id return c }, @@ -523,7 +523,7 @@ func processBindings(ctx HandlerCtx) ([]Binding, error) { return out, nil } -func readProcess(ctx HandlerCtx) ([]byte, error) { +func readProcess(ctx Hctx) ([]byte, error) { pid := ctx.Data.(int) conn := ctx.Session.DialToolServer() if conn == nil { @@ -537,7 +537,7 @@ func readProcess(ctx HandlerCtx) ([]byte, error) { return []byte(output), nil } -func readProcessStatus(ctx HandlerCtx) ([]byte, error) { +func readProcessStatus(ctx Hctx) ([]byte, error) { pid := ctx.Data.(int) conn := ctx.Session.DialToolServer() if conn == nil { @@ -562,7 +562,7 @@ func readProcessStatus(ctx HandlerCtx) ([]byte, error) { return nil, fmt.Errorf("process %d not found", pid) } -func writeProcessCtl(ctx HandlerCtx, data []byte) error { +func writeProcessCtl(ctx Hctx, data []byte) error { pid := ctx.Data.(int) conn := ctx.Session.DialToolServer() if conn == nil { diff --git a/cmd/olliesrv/internal/fs/handlers_root.go b/cmd/olliesrv/internal/fs/handlers_root.go index 15ee4fa..07e8c32 100644 --- a/cmd/olliesrv/internal/fs/handlers_root.go +++ b/cmd/olliesrv/internal/fs/handlers_root.go @@ -37,13 +37,13 @@ func wireAgentEvents(sessID string, ag *agent.Agent, al *AgentLog) { }) } -func readBackends(_ HandlerCtx) ([]byte, error) { +func readBackends(_ Hctx) ([]byte, error) { return []byte(strings.Join(backend.Backends(), "\n") + "\n"), nil } var helpFn func() string -func readHelp(_ HandlerCtx) ([]byte, error) { +func readHelp(_ Hctx) ([]byte, error) { if helpFn == nil { return []byte("help not initialized\n"), nil } @@ -64,14 +64,14 @@ var ( helpText string ) -func readModels(ctx HandlerCtx) ([]byte, error) { +func readModels(ctx Hctx) ([]byte, error) { if ctx.Models != nil { return ctx.Models.Get(), nil } return []byte("(no model cache)\n"), nil } -func readAgents(_ HandlerCtx) ([]byte, error) { +func readAgents(_ Hctx) ([]byte, error) { var sb strings.Builder for _, dir := range agent.AgentsDirs() { entries, err := os.ReadDir(dir) @@ -88,7 +88,7 @@ func readAgents(_ HandlerCtx) ([]byte, error) { return []byte(sb.String()), nil } -func readTools(_ HandlerCtx) ([]byte, error) { +func readTools(_ Hctx) ([]byte, error) { tools := toolsrv.DiscoverTools() if len(tools) == 0 { return []byte("(no tools found)\n"), nil @@ -100,12 +100,12 @@ func readTools(_ HandlerCtx) ([]byte, error) { return []byte(sb.String()), nil } -func requestRootCtl(ctx HandlerCtx, data []byte) ([]byte, error) { +func requestRootCtl(ctx Hctx, data []byte) ([]byte, error) { return rdwrDispatch(rootCtlHandlers)(ctx, data) } var rootCtlHandlers = map[string]rdwrHandler{ - "invalidate": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "invalidate": func(ctx Hctx, _ []string) ([]byte, error) { if ctx.Models != nil { ctx.Models.Invalidate() } @@ -114,7 +114,7 @@ var rootCtlHandlers = map[string]rdwrHandler{ } return []byte("ok\n"), nil }, - "kill": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "kill": func(ctx Hctx, _ []string) ([]byte, error) { if ctx.Shutdown != nil { ctx.Shutdown() } @@ -122,15 +122,15 @@ var rootCtlHandlers = map[string]rdwrHandler{ }, } -func readEventwait(_ HandlerCtx) ([]byte, error) { +func readEventwait(_ Hctx) ([]byte, error) { return nil, fmt.Errorf("eventwait: use blocking read") } -func blockEventwait(_ HandlerCtx, cctx context.Context, _ string) ([]byte, string, error) { +func blockEventwait(_ Hctx, cctx context.Context, _ string) ([]byte, string, error) { return session.WaitEvent(cctx) } -func requestGenerate(ctx HandlerCtx, data []byte) ([]byte, error) { +func requestGenerate(ctx Hctx, data []byte) ([]byte, error) { var req backend.GenerateRequest if err := json.Unmarshal(data, &req); err != nil { req.Prompt = strings.TrimSpace(string(data)) @@ -142,7 +142,7 @@ func requestGenerate(ctx HandlerCtx, data []byte) ([]byte, error) { return []byte(result + "\n"), nil } -func readAliases(_ HandlerCtx) ([]byte, error) { +func readAliases(_ Hctx) ([]byte, error) { var sb strings.Builder for name, sess := range session.Sessions() { sid := sess.ID @@ -156,7 +156,7 @@ func readAliases(_ HandlerCtx) ([]byte, error) { var errNoBypass = fmt.Errorf("bypass broker not available") -func readBypassPolicy(ctx HandlerCtx) ([]byte, error) { +func readBypassPolicy(ctx Hctx) ([]byte, error) { if ctx.Bypass == nil { return nil, errNoBypass } @@ -164,7 +164,7 @@ func readBypassPolicy(ctx HandlerCtx) ([]byte, error) { return p.Marshal() } -func writeBypassPolicy(ctx HandlerCtx, data []byte) error { +func writeBypassPolicy(ctx Hctx, data []byte) error { if ctx.Bypass == nil { return errNoBypass } @@ -176,7 +176,7 @@ func writeBypassPolicy(ctx HandlerCtx, data []byte) error { } // bypassBindings returns bindings for pending bypass requests. -func bypassBindings(ctx HandlerCtx) ([]Binding, error) { +func bypassBindings(ctx Hctx) ([]Binding, error) { if ctx.Bypass == nil { return nil, errNoBypass } @@ -186,7 +186,7 @@ func bypassBindings(ctx HandlerCtx) ([]Binding, error) { req := r // capture out[i] = Binding{ Name: r.ID, - Applier: func(c HandlerCtx) HandlerCtx { + Applier: func(c Hctx) Hctx { c.Data = req return c }, @@ -195,12 +195,12 @@ func bypassBindings(ctx HandlerCtx) ([]Binding, error) { return out, nil } -func readBypassRequest(ctx HandlerCtx) ([]byte, error) { +func readBypassRequest(ctx Hctx) ([]byte, error) { req := ctx.Data.(*bypass.Request) return []byte(req.Summary() + "\n"), nil } -func writeBypassRequest(ctx HandlerCtx, data []byte) error { +func writeBypassRequest(ctx Hctx, data []byte) error { req := ctx.Data.(*bypass.Request) cmd := strings.TrimSpace(string(data)) var res bypass.Resolution diff --git a/cmd/olliesrv/internal/fs/handlers_session.go b/cmd/olliesrv/internal/fs/handlers_session.go index 34b7511..a05a977 100644 --- a/cmd/olliesrv/internal/fs/handlers_session.go +++ b/cmd/olliesrv/internal/fs/handlers_session.go @@ -9,15 +9,15 @@ import ( "ollie/cmd/olliesrv/internal/session" ) -func readSessionIdx(_ HandlerCtx) ([]byte, error) { +func readSessionIdx(_ Hctx) ([]byte, error) { return session.BuildIndex(), nil } -func readAgentIdx(ctx HandlerCtx) ([]byte, error) { - return session.BuildAgentIndex(ctx.Session.Core), nil +func readAgentIdx(ctx Hctx) ([]byte, error) { + return session.BuildAgentIndex(ctx.Session.Session), nil } -func requestSessionNew(_ HandlerCtx, data []byte) ([]byte, error) { +func requestSessionNew(_ Hctx, data []byte) ([]byte, error) { args := strings.Fields(string(data)) name := "" remote := "" @@ -40,7 +40,7 @@ func requestSessionNew(_ HandlerCtx, data []byte) ([]byte, error) { // sessionBindings returns bindings for all sessions. // The Blueprint pattern clones the structure and binds ctx.Session. -func sessionBindings(ctx HandlerCtx) ([]Binding, error) { +func sessionBindings(ctx Hctx) ([]Binding, error) { rs := ctx.RootState sessions := session.Sessions() @@ -54,7 +54,7 @@ func sessionBindings(ctx HandlerCtx) ([]Binding, error) { Aliases: []string{sess.ID}, UID: sess.Uname, GID: "agent", - Applier: func(c HandlerCtx) HandlerCtx { + Applier: func(c Hctx) Hctx { c.Context = node.Ctx() c.Session = node c.Remove = func() { @@ -86,7 +86,7 @@ func sessionBindings(ctx HandlerCtx) ([]Binding, error) { return out, nil } -func readSessionEnv(ctx HandlerCtx) ([]byte, error) { +func readSessionEnv(ctx Hctx) ([]byte, error) { s := ctx.Session var sb strings.Builder fmt.Fprintf(&sb, "OLLIE_SESSION_ID=%s\n", s.ID()) @@ -99,50 +99,50 @@ func readSessionEnv(ctx HandlerCtx) ([]byte, error) { return []byte(sb.String()), nil } -func readSessionPaused(ctx HandlerCtx) ([]byte, error) { +func readSessionPaused(ctx Hctx) ([]byte, error) { if ctx.Session.IsPaused() { return []byte("true\n"), nil } return []byte("false\n"), nil } -func readSessionConnected(ctx HandlerCtx) ([]byte, error) { +func readSessionConnected(ctx Hctx) ([]byte, error) { if ctx.Session.IsConnected() { return []byte("true\n"), nil } return []byte("false\n"), nil } -func requestSessionCtl(ctx HandlerCtx, data []byte) ([]byte, error) { +func requestSessionCtl(ctx Hctx, data []byte) ([]byte, error) { return rdwrDispatch(sessionCtlHandlers)(ctx, data) } var sessionCtlHandlers = map[string]rdwrHandler{ - "kill": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "kill": func(ctx Hctx, _ []string) ([]byte, error) { ctx.Remove() return []byte("ok\n"), nil }, - ".": func(ctx HandlerCtx, _ []string) ([]byte, error) { + ".": func(ctx Hctx, _ []string) ([]byte, error) { ctx.Remove() return []byte("ok\n"), nil }, - "save": func(ctx HandlerCtx, _ []string) ([]byte, error) { - if ctx.Session.Core != nil { - ctx.Session.Core.Save() + "save": func(ctx Hctx, _ []string) ([]byte, error) { + if ctx.Session.Session != nil { + ctx.Session.Session.Save() } return []byte("ok\n"), nil }, - "invalidate": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "invalidate": func(ctx Hctx, _ []string) ([]byte, error) { ctx.Session.InvalidateModelsCache() return []byte("ok\n"), nil }, - "pause": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "pause": func(ctx Hctx, _ []string) ([]byte, error) { if err := ctx.Session.Pause(); err != nil { return nil, err } return []byte("ok\n"), nil }, - "resume": func(ctx HandlerCtx, _ []string) ([]byte, error) { + "resume": func(ctx Hctx, _ []string) ([]byte, error) { if err := ctx.Session.Resume(); err != nil { return nil, err } @@ -150,11 +150,11 @@ var sessionCtlHandlers = map[string]rdwrHandler{ }, } -func readSessionName(ctx HandlerCtx) ([]byte, error) { +func readSessionName(ctx Hctx) ([]byte, error) { return []byte(ctx.Session.Name() + "\n"), nil } -func writeSessionName(ctx HandlerCtx, data []byte) error { +func writeSessionName(ctx Hctx, data []byte) error { newName := strings.TrimSpace(string(data)) if newName == "" { return nil @@ -166,11 +166,11 @@ func writeSessionName(ctx HandlerCtx, data []byte) error { return nil } -func readSessionID(ctx HandlerCtx) ([]byte, error) { +func readSessionID(ctx Hctx) ([]byte, error) { return []byte(ctx.Session.ID() + "\n"), nil } -func readSessionBypass(ctx HandlerCtx) ([]byte, error) { +func readSessionBypass(ctx Hctx) ([]byte, error) { if ctx.Bypass == nil { return nil, fmt.Errorf("bypass broker not available") } @@ -178,7 +178,7 @@ func readSessionBypass(ctx HandlerCtx) ([]byte, error) { return p.Marshal() } -func writeSessionBypass(ctx HandlerCtx, data []byte) error { +func writeSessionBypass(ctx Hctx, data []byte) error { if ctx.Bypass == nil { return fmt.Errorf("bypass broker not available") } diff --git a/cmd/olliesrv/internal/fs/newroot.go b/cmd/olliesrv/internal/fs/newroot.go index b71172a..5b06258 100644 --- a/cmd/olliesrv/internal/fs/newroot.go +++ b/cmd/olliesrv/internal/fs/newroot.go @@ -56,7 +56,7 @@ func NewRoot(cfg Config) *Tree { } // Build the root context with all available deps. - ctx := HandlerCtx{ + ctx := Hctx{ Context: cfg.Ctx, // per-operation cancellation deadline Root: nil, // set after tree is built RootState: rs, diff --git a/cmd/olliesrv/internal/fs/session_node.go b/cmd/olliesrv/internal/fs/session_node.go index 4f7a2a5..12bf9ab 100644 --- a/cmd/olliesrv/internal/fs/session_node.go +++ b/cmd/olliesrv/internal/fs/session_node.go @@ -14,7 +14,7 @@ import ( // SessionNode wraps session.Session for 9P handlers. // It adds AgentLogs (9P chat streaming state) and models cache. type SessionNode struct { - Core *session.Session + Session *session.Session // AgentLogs for chat streaming, keyed by agent ID. mu sync.RWMutex @@ -28,49 +28,49 @@ type SessionNode struct { // NewSessionNode creates a SessionNode wrapping a session. func NewSessionNode(core *session.Session) *SessionNode { - return &SessionNode{Core: core, AgentLogs: make(map[string]*AgentLog)} + return &SessionNode{Session: core, AgentLogs: make(map[string]*AgentLog)} } // --- Delegation to Core --- -func (s *SessionNode) ID() string { return s.Core.ID } -func (s *SessionNode) Name() string { return s.Core.Name() } -func (s *SessionNode) SetName(n string) { s.Core.SetName(n) } -func (s *SessionNode) Uname() string { return s.Core.Uname } -func (s *SessionNode) Cancel() { if s.Core.Cancel != nil { s.Core.Cancel() } } -func (s *SessionNode) IsPaused() bool { return s.Core.IsPaused() } -func (s *SessionNode) IsConnected() bool { return s.Core.IsConnected() } +func (s *SessionNode) ID() string { return s.Session.ID } +func (s *SessionNode) Name() string { return s.Session.Name() } +func (s *SessionNode) SetName(n string) { s.Session.SetName(n) } +func (s *SessionNode) Uname() string { return s.Session.Uname } +func (s *SessionNode) Cancel() { if s.Session.Cancel != nil { s.Session.Cancel() } } +func (s *SessionNode) IsPaused() bool { return s.Session.IsPaused() } +func (s *SessionNode) IsConnected() bool { return s.Session.IsConnected() } func (s *SessionNode) Pause() error { - err := s.Core.Pause() + err := s.Session.Pause() if err == nil { - session.PublishEvent("session."+s.Core.ID+".pause", "") + session.PublishEvent("session."+s.Session.ID+".pause", "") } return err } func (s *SessionNode) Resume() error { - err := s.Core.Resume() + err := s.Session.Resume() if err == nil { - session.PublishEvent("session."+s.Core.ID+".resume", "") + session.PublishEvent("session."+s.Session.ID+".resume", "") } return err } func (s *SessionNode) LoadTool(name string, ag *agent.Agent) error { - return s.Core.LoadTool(name, ag) + return s.Session.LoadTool(name, ag) } func (s *SessionNode) Ctx() context.Context { - return s.Core.Ctx + return s.Session.Ctx } func (s *SessionNode) ToolsConn() *toolsrv.Conn { - return s.Core.ToolsConn() + return s.Session.ToolsConn() } func (s *SessionNode) DialToolServer() *toolsrv.Conn { - return s.Core.DialToolServer() + return s.Session.DialToolServer() } // --- AgentLog management --- @@ -112,7 +112,7 @@ func (s *SessionNode) CachedListModels() string { } s.modelsMu.Unlock() - agents := s.Core.Agents() + agents := s.Session.Agents() if len(agents) == 0 { return "" } diff --git a/cmd/olliesrv/internal/fs/spec.go b/cmd/olliesrv/internal/fs/spec.go index 0e40774..d62ad20 100644 --- a/cmd/olliesrv/internal/fs/spec.go +++ b/cmd/olliesrv/internal/fs/spec.go @@ -13,10 +13,10 @@ import ( olog "ollie/log" ) -// HandlerCtx carries runtime dependencies for handler functions. +// Hctx carries runtime dependencies for handler functions. // The wire step populates the correct subset per node scope. // Handlers assert their scope by checking which pointer is non-nil. -type HandlerCtx struct { +type Hctx struct { context.Context // per-operation cancellation deadline // Root-level (always available). @@ -43,8 +43,8 @@ type HandlerCtx struct { // Type aliases from fsedsl, specialized to HandlerCtx. type ( - FsNodeDecl = fsedsl.FsNodeDecl[HandlerCtx] - Binding = fsedsl.Binding[HandlerCtx] + FsNodeDecl = fsedsl.FsNodeDecl[Hctx] + Binding = fsedsl.Binding[Hctx] Tree = fsedsl.Tree File = fsedsl.File SyntheticFileInfo = fsedsl.SyntheticFileInfo @@ -60,20 +60,20 @@ const ( ) var ( - DirNode = fsedsl.DirNode[HandlerCtx] - FileNode = fsedsl.FileNode[HandlerCtx] - Each = fsedsl.Each[HandlerCtx] - Doc = fsedsl.Doc[HandlerCtx] - Read = fsedsl.Read[HandlerCtx] - Write = fsedsl.Write[HandlerCtx] - Stream = fsedsl.Stream[HandlerCtx] - BlockOnce = fsedsl.BlockOnce[HandlerCtx] - Request = fsedsl.Request[HandlerCtx] - Remove = fsedsl.RemoveNode[HandlerCtx] - Stat = fsedsl.StatOverride[HandlerCtx] - UID = fsedsl.UID[HandlerCtx] - GID = fsedsl.GID[HandlerCtx] - Bind = fsedsl.Bind[HandlerCtx] + DirNode = fsedsl.DirNode[Hctx] + FileNode = fsedsl.FileNode[Hctx] + Each = fsedsl.Each[Hctx] + Doc = fsedsl.Doc[Hctx] + Read = fsedsl.Read[Hctx] + Write = fsedsl.Write[Hctx] + Stream = fsedsl.Stream[Hctx] + BlockOnce = fsedsl.BlockOnce[Hctx] + Request = fsedsl.Request[Hctx] + Remove = fsedsl.RemoveNode[Hctx] + Stat = fsedsl.StatOverride[Hctx] + UID = fsedsl.UID[Hctx] + GID = fsedsl.GID[Hctx] + Bind = fsedsl.Bind[Hctx] ) var treeSpecUID, treeSpecGID string @@ -240,7 +240,7 @@ FileNode("generate", 0666, FileNode("statewait", 0444, Doc("Blocking read that returns when state changes. Returns new state value."), - Read(func(ctx HandlerCtx) ([]byte, error) { + Read(func(ctx Hctx) ([]byte, error) { return []byte(ctx.Agent.State() + "\n"), nil }), BlockOnce(blockAgentStateWait),