diff --git a/fs/root.go b/server/root.go similarity index 66% rename from fs/root.go rename to server/root.go index ae3fa51..c374231 100644 --- a/fs/root.go +++ b/server/root.go @@ -1,7 +1,8 @@ -package fs +package server import ( "context" + "olliesrv/fs" "fmt" "os" "strings" @@ -11,7 +12,7 @@ import ( ) // NewRootStore returns a read-only FileTree for synthetic root-level files. -func NewRootStore() *Tree { +func NewRootStore() *fs.Tree { helpPath := paths.CfgDir() + "/help.md" entries := map[string]func() ([]byte, error){ "backends": func() ([]byte, error) { @@ -26,27 +27,27 @@ func NewRootStore() *Tree { } readOnly := func([]byte) error { return fmt.Errorf("read-only") } - return NewTree(nil, 0444, - WithReadOnly(), - WithResolver(func(_ []string, name string) (string, error) { + return fs.NewTree(nil, 0444, + fs.WithReadOnly(), + fs.WithResolver(func(_ []string, name string) (string, error) { if _, ok := entries[name]; ok { return name, nil } return "", fmt.Errorf("%s: not found", name) }), - WithLister(func(_ []string) ([]os.DirEntry, error) { + fs.WithLister(func(_ []string) ([]os.DirEntry, error) { return []os.DirEntry{ - FileEntry("backends", 0444), - FileEntry("help", 0444), + fs.FileEntry("backends", 0444), + fs.FileEntry("help", 0444), }, nil }), - WithOpener(func(_ []string, name string) (File, error) { + fs.WithOpener(func(_ []string, name string) (fs.File, error) { readFn, ok := entries[name] if !ok { return nil, fmt.Errorf("%s: not found", name) } - return &FileConfig{ - StatFn: func() (os.FileInfo, error) { return &SyntheticFileInfo{Name_: name, Mode_: 0444}, nil }, + return &fs.FileConfig{ + StatFn: func() (os.FileInfo, error) { return &fs.SyntheticFileInfo{Name_: name, Mode_: 0444}, nil }, ReadFn: readFn, WriteFn: readOnly, BlockingReadFn: notBlocking, diff --git a/server/server.go b/server/server.go index f8ec12c..ce8534c 100644 --- a/server/server.go +++ b/server/server.go @@ -104,13 +104,13 @@ func New(sink *olog.Sink, opts ...Option) *Server { agentStore: fs.NewTree(agentsDirs, 0644), promptStore: fs.NewTree(agent.PromptsDirs(), 0444, fs.WithReadOnly()), memStore: fs.NewTree([]string{memDir}, 0644), - toolStore: fs.NewTree([]string{execute.ToolsPath()}, 0755, fs.WithIndex(fs.ToolIndex)), + toolStore: fs.NewTree([]string{execute.ToolsPath()}, 0755, fs.WithIndex(ToolIndex)), utilStore: fs.NewTree([]string{paths.CfgDir() + "/scripts/u"}, 0555, fs.WithReadOnly()), pluginStore: fs.NewTree([]string{execute.PluginsPath()}, 0555, fs.WithReadOnly()), skillStore: fs.NewSkillStore(), transcriptStore: fs.NewTree([]string{transcriptDir}, 0444, fs.WithReadOnly()), tmpStore: fs.NewTree([]string{tmpDir}, 0600), - rootStore: fs.NewRootStore(), + rootStore: NewRootStore(), groups: make(map[string]map[string]bool), } for _, o := range opts { diff --git a/fs/tool.go b/server/tool.go similarity index 93% rename from fs/tool.go rename to server/tool.go index 05a9d7a..df692c4 100644 --- a/fs/tool.go +++ b/server/tool.go @@ -1,12 +1,14 @@ -package fs +package server import ( "fmt" + + "olliesrv/fs" "strings" ) // ToolIndex generates a tool index from a store's file listing. -func ToolIndex(s FileTree) ([]byte, error) { +func ToolIndex(s fs.FileTree) ([]byte, error) { entries, err := s.List() if err != nil { return nil, err