session: eliminate Core interface, use concrete *agent.Session
- Delete session/core.go (the consumer-defined interface) - Change Session.Core field from interface to *agent.Session - Change NewSession and ManagerConfig.NewCore to use concrete type - Rewrite all tests to use real sessions with backend.Noop The 9p layer now depends directly on the concrete type from ollie/session. No more interface indirection. Tests exercise real session behavior instead of stub methods.
This commit is contained in:
parent
cf894920fa
commit
3d2172d93a
969
main_test.go
969
main_test.go
File diff suppressed because it is too large
Load Diff
|
|
@ -1,55 +0,0 @@
|
||||||
package session
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/simonfxr/pubsub"
|
|
||||||
agent "ollie/session"
|
|
||||||
"ollie/backend"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Core is the interface that a session implementation must satisfy.
|
|
||||||
// Defined here (at the consumer) rather than in ollie/session so that
|
|
||||||
// the core package exports only a concrete struct with no interface overhead.
|
|
||||||
// Tests can substitute a lightweight stub.
|
|
||||||
type Core interface {
|
|
||||||
Submit(ctx context.Context, input string)
|
|
||||||
Interrupt(cause error) bool
|
|
||||||
Inject(prompt string)
|
|
||||||
Queue(prompt string)
|
|
||||||
PopQueue() (string, bool)
|
|
||||||
Bus() *pubsub.Bus
|
|
||||||
IsRunning() bool
|
|
||||||
State() string
|
|
||||||
Reply() string
|
|
||||||
AgentName() string
|
|
||||||
BackendName() string
|
|
||||||
ModelName() string
|
|
||||||
CWD() string
|
|
||||||
SetCWD(dir string) error
|
|
||||||
SetSessionID(newID string) error
|
|
||||||
Context() []backend.Message
|
|
||||||
SystemPrompt() string
|
|
||||||
GenerationParams() backend.GenerationParams
|
|
||||||
SetGenerationParams(params backend.GenerationParams) error
|
|
||||||
CompactionModel() string
|
|
||||||
SetCompactionModel(model string)
|
|
||||||
Usage() string
|
|
||||||
Cost() string
|
|
||||||
CtxSz() string
|
|
||||||
ListModels() string
|
|
||||||
WaitChange(ctx context.Context, field, current string) (string, bool)
|
|
||||||
SaveSession(path string) error
|
|
||||||
Close()
|
|
||||||
Detach() bool
|
|
||||||
ListDetached() []agent.DetachedInfo
|
|
||||||
SignalDetached(pid, signal int) error
|
|
||||||
GetDetachedOutput(pid int) (string, error)
|
|
||||||
DismissDetached(pid int) bool
|
|
||||||
InjectSystemEvent(content string)
|
|
||||||
React(emoji string)
|
|
||||||
ReactTo(responseID, emoji string) error
|
|
||||||
Reactions() map[string]string
|
|
||||||
ToolCallCount() int64
|
|
||||||
SetEnv(key, value string)
|
|
||||||
}
|
|
||||||
|
|
@ -29,7 +29,7 @@ type Session struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
id string
|
id string
|
||||||
uname string // immutable user principal (numeric UID), set at creation
|
uname string // immutable user principal (numeric UID), set at creation
|
||||||
Core Core
|
Core *agent.Session
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
log []byte
|
log []byte
|
||||||
|
|
@ -46,7 +46,7 @@ type Session struct {
|
||||||
modelsCacheAt time.Time
|
modelsCacheAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSession(id string, core Core, ctx context.Context, cancel context.CancelFunc) *Session {
|
func NewSession(id string, core *agent.Session, ctx context.Context, cancel context.CancelFunc) *Session {
|
||||||
sess := &Session{id: id, Core: core, Ctx: ctx, cancel: cancel}
|
sess := &Session{id: id, Core: core, Ctx: ctx, cancel: cancel}
|
||||||
sess.startEventLog()
|
sess.startEventLog()
|
||||||
return sess
|
return sess
|
||||||
|
|
@ -235,8 +235,8 @@ type ManagerConfig struct {
|
||||||
ReadFile func(string) ([]byte, error)
|
ReadFile func(string) ([]byte, error)
|
||||||
MkdirAll func(string, os.FileMode) error
|
MkdirAll func(string, os.FileMode) error
|
||||||
// NewCore, if non-nil, replaces the default backend.New + agent.New
|
// NewCore, if non-nil, replaces the default backend.New + agent.New
|
||||||
// path. It receives the session ID, agent name, and cwd, and returns a Core.
|
// path. It receives the session ID, agent name, and cwd, and returns a Session.
|
||||||
NewCore func(sessionID, agentName, cwd string) (Core, error)
|
NewCore func(sessionID, agentName, cwd string) (*agent.Session, error)
|
||||||
// Strict rejects inline code steps; only tool steps are allowed.
|
// Strict rejects inline code steps; only tool steps are allowed.
|
||||||
Strict bool
|
Strict bool
|
||||||
// Yolo skips the landrun sandbox.
|
// Yolo skips the landrun sandbox.
|
||||||
|
|
@ -1122,7 +1122,7 @@ func (s *Manager) CreateSession(args []string) (string, error) {
|
||||||
return "", fmt.Errorf("session already exists: %s", sessID)
|
return "", fmt.Errorf("session already exists: %s", sessID)
|
||||||
}
|
}
|
||||||
|
|
||||||
var core Core
|
var core *agent.Session
|
||||||
var sessPtr *Session
|
var sessPtr *Session
|
||||||
uname := s.nextUname()
|
uname := s.nextUname()
|
||||||
if s.cfg.NewCore != nil {
|
if s.cfg.NewCore != nil {
|
||||||
|
|
|
||||||
Reference in New Issue