57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package fs
|
|
|
|
import (
|
|
"context"
|
|
|
|
"ollie/cmd/olliesrv/internal/session"
|
|
olog "ollie/log"
|
|
"ollie/virtfs"
|
|
)
|
|
|
|
// Config carries all runtime dependencies for the filesystem tree.
|
|
// It is the single input to NewRoot.
|
|
type Config struct {
|
|
Ctx context.Context
|
|
Log *olog.Logger
|
|
Sink *olog.Sink
|
|
AgentsDir string
|
|
SessionsDir string
|
|
Yolo bool
|
|
ModelCache *ModelCache
|
|
Shutdown func()
|
|
Invalidate func()
|
|
}
|
|
|
|
// NewRoot creates the complete 9P filesystem tree from the spec.
|
|
func NewRoot(cfg Config) *Tree {
|
|
// Initialize session package
|
|
session.Init(session.InitConfig{
|
|
Ctx: cfg.Ctx,
|
|
Log: cfg.Log,
|
|
Sink: cfg.Sink,
|
|
AgentsDir: cfg.AgentsDir,
|
|
SessionsDir: cfg.SessionsDir,
|
|
Yolo: cfg.Yolo,
|
|
})
|
|
|
|
// Build the tree from the spec.
|
|
spec := buildTreeSpec(&cfg)
|
|
helpSpec = &spec
|
|
tree := virtfs.BuildTree(spec)
|
|
|
|
return tree
|
|
}
|
|
|
|
// RestoreSessions restores persisted sessions from disk.
|
|
// Must be called after the 9P listener is ready.
|
|
func RestoreSessions() {
|
|
for _, r := range session.RestoreAllSessions() {
|
|
for _, ra := range r.Agents {
|
|
if ag := r.Session.FindAgent(ra.ID); ag != nil {
|
|
ag.ReplayMessages(ra.Messages)
|
|
wireAgentEvents(r.Session.ID, ag)
|
|
}
|
|
}
|
|
}
|
|
}
|