diff --git a/internal/p9/configstore.go b/internal/p9/configstore.go deleted file mode 100644 index b2b966a..0000000 --- a/internal/p9/configstore.go +++ /dev/null @@ -1,20 +0,0 @@ -package p9 - -import ( - "os" - - "ollie/pkg/config" -) - -// loadAgentConfig resolves and loads the config for a named agent. -// Returns nil (not an error) if the config file does not exist; -// BuildAgentEnv handles nil configs. -func loadAgentConfig(agentsDir, name string) *config.Config { - f, err := os.Open(agentsDir + "/" + name + ".json") - if err != nil { - return nil - } - defer f.Close() - cfg, _ := config.Load(f) - return cfg -} diff --git a/internal/p9/pluginstore.go b/internal/p9/pluginstore.go deleted file mode 100644 index 44a6ca4..0000000 --- a/internal/p9/pluginstore.go +++ /dev/null @@ -1,30 +0,0 @@ -package p9 - -import ( - "os" - - "ollie/pkg/tools/execute" -) - -// ExecStore is a read-only FlatDirStore backed by the scripts/x/ directory. -// Plugins are executables invoked by the server (e.g. elevation backends), not -// by the agent or user directly. -type ExecStore struct { - *FlatDirStore -} - -func NewExecStore() *ExecStore { - return &ExecStore{FlatDirStore: NewFlatDirStore(execute.PluginsPath(), 0555)} -} - -func (s *ExecStore) Stat(name string) (os.FileInfo, error) { - return s.FlatDirStore.Stat(name) -} - -func (s *ExecStore) List() ([]os.DirEntry, error) { - return s.FlatDirStore.List() -} - -func (s *ExecStore) Get(name string) ([]byte, error) { - return s.FlatDirStore.Get(name) -} diff --git a/internal/p9/store.go b/internal/p9/store.go index cca0936..e6376a1 100644 --- a/internal/p9/store.go +++ b/internal/p9/store.go @@ -1,9 +1,14 @@ package p9 import ( + "fmt" "os" + "strings" + "ollie/pkg/config" + "ollie/pkg/paths" "ollie/pkg/store" + "ollie/pkg/tools/execute" ) // Re-export core store types so existing 9p code compiles unchanged. @@ -29,3 +34,139 @@ func syntheticEntry(name string, mode os.FileMode) os.DirEntry { func syntheticDirEntry(name string, mode os.FileMode) os.DirEntry { return store.DirEntry(name, mode) } + +// --- config --- + +// loadAgentConfig resolves and loads the config for a named agent. +// Returns nil (not an error) if the config file does not exist; +// BuildAgentEnv handles nil configs. +func loadAgentConfig(agentsDir, name string) *config.Config { + f, err := os.Open(agentsDir + "/" + name + ".json") + if err != nil { + return nil + } + defer f.Close() + cfg, _ := config.Load(f) + return cfg +} + +// --- util --- + +// UtilStore is a FlatDirStore backed by the scripts/u/ directory. +type UtilStore struct { + *FlatDirStore +} + +func NewUtilStore() *UtilStore { + return &UtilStore{FlatDirStore: NewFlatDirStore(paths.CfgDir()+"/scripts/u", 0555)} +} + +func (s *UtilStore) Stat(name string) (os.FileInfo, error) { + return s.FlatDirStore.Stat(name) +} + +func (s *UtilStore) List() ([]os.DirEntry, error) { + return s.FlatDirStore.List() +} + +func (s *UtilStore) Get(name string) ([]byte, error) { + return s.FlatDirStore.Get(name) +} + +// --- exec --- + +// ExecStore is a read-only FlatDirStore backed by the scripts/x/ directory. +type ExecStore struct { + *FlatDirStore +} + +func NewExecStore() *ExecStore { + return &ExecStore{FlatDirStore: NewFlatDirStore(execute.PluginsPath(), 0555)} +} + +func (s *ExecStore) Stat(name string) (os.FileInfo, error) { + return s.FlatDirStore.Stat(name) +} + +func (s *ExecStore) List() ([]os.DirEntry, error) { + return s.FlatDirStore.List() +} + +func (s *ExecStore) Get(name string) ([]byte, error) { + return s.FlatDirStore.Get(name) +} + +// --- tools --- + +// ToolStore is a BlobStore backed by the tools directory. +// It extends FlatDirStore with a synthetic "idx" entry that lists all tools +// with their descriptions and argument signatures. +type ToolStore struct { + *FlatDirStore +} + +func NewToolStore() *ToolStore { + return &ToolStore{FlatDirStore: NewFlatDirStore(execute.ToolsPath(), 0755)} +} + +func (s *ToolStore) Stat(name string) (os.FileInfo, error) { + if name == "idx" { + return &syntheticFileInfo{Name_: "idx", Mode_: 0444}, nil + } + return s.FlatDirStore.Stat(name) +} + +func (s *ToolStore) List() ([]os.DirEntry, error) { + entries, err := s.FlatDirStore.List() + result := make([]os.DirEntry, 0, len(entries)+1) + result = append(result, syntheticEntry("idx", 0444)) + result = append(result, entries...) + return result, err +} + +func (s *ToolStore) Get(name string) ([]byte, error) { + if name == "idx" { + return s.index() + } + return s.FlatDirStore.Get(name) +} + +func (s *ToolStore) index() ([]byte, error) { + entries, err := s.FlatDirStore.List() + if err != nil { + return nil, err + } + var sb strings.Builder + for _, e := range entries { + if e.IsDir() { + continue + } + data, err := s.FlatDirStore.Get(e.Name()) + if err != nil { + continue + } + var desc, args string + for line := range strings.SplitSeq(string(data), "\n") { + if d, ok := strings.CutPrefix(line, "# description:"); ok { + desc = strings.TrimSpace(d) + } else if a, ok := strings.CutPrefix(line, "# Args:"); ok { + args = strings.TrimSpace(a) + } else if a, ok := strings.CutPrefix(line, "# args:"); ok { + args = strings.TrimSpace(a) + } + if !strings.HasPrefix(line, "#") && line != "" { + break + } + } + if desc == "" { + continue + } + fmt.Fprintf(&sb, "## %s\n", e.Name()) + fmt.Fprintf(&sb, "description: %s\n", desc) + if args != "" { + fmt.Fprintf(&sb, "args: %s\n", args) + } + sb.WriteString("\n") + } + return []byte(sb.String()), nil +} diff --git a/internal/p9/toolstore.go b/internal/p9/toolstore.go deleted file mode 100644 index b02f0bb..0000000 --- a/internal/p9/toolstore.go +++ /dev/null @@ -1,82 +0,0 @@ -package p9 - -import ( - "fmt" - "os" - "strings" - - "ollie/pkg/tools/execute" -) - -// ToolStore is a BlobStore backed by the tools directory. -// It extends FlatDirStore with a synthetic "idx" entry that lists all tools -// with their descriptions and argument signatures. -type ToolStore struct { - *FlatDirStore -} - -func NewToolStore() *ToolStore { - return &ToolStore{FlatDirStore: NewFlatDirStore(execute.ToolsPath(), 0755)} -} - -func (s *ToolStore) Stat(name string) (os.FileInfo, error) { - if name == "idx" { - return &syntheticFileInfo{Name_: "idx", Mode_: 0444}, nil - } - return s.FlatDirStore.Stat(name) -} - -func (s *ToolStore) List() ([]os.DirEntry, error) { - entries, err := s.FlatDirStore.List() - result := make([]os.DirEntry, 0, len(entries)+1) - result = append(result, syntheticEntry("idx", 0444)) - result = append(result, entries...) - return result, err -} - -func (s *ToolStore) Get(name string) ([]byte, error) { - if name == "idx" { - return s.index() - } - return s.FlatDirStore.Get(name) -} - -func (s *ToolStore) index() ([]byte, error) { - entries, err := s.FlatDirStore.List() - if err != nil { - return nil, err - } - var sb strings.Builder - for _, e := range entries { - if e.IsDir() { - continue - } - data, err := s.FlatDirStore.Get(e.Name()) - if err != nil { - continue - } - var desc, args string - for line := range strings.SplitSeq(string(data), "\n") { - if d, ok := strings.CutPrefix(line, "# description:"); ok { - desc = strings.TrimSpace(d) - } else if a, ok := strings.CutPrefix(line, "# Args:"); ok { - args = strings.TrimSpace(a) - } else if a, ok := strings.CutPrefix(line, "# args:"); ok { - args = strings.TrimSpace(a) - } - if !strings.HasPrefix(line, "#") && line != "" { - break - } - } - if desc == "" { - continue - } - fmt.Fprintf(&sb, "## %s\n", e.Name()) - fmt.Fprintf(&sb, "description: %s\n", desc) - if args != "" { - fmt.Fprintf(&sb, "args: %s\n", args) - } - sb.WriteString("\n") - } - return []byte(sb.String()), nil -} diff --git a/internal/p9/utilstore.go b/internal/p9/utilstore.go deleted file mode 100644 index 59d40a5..0000000 --- a/internal/p9/utilstore.go +++ /dev/null @@ -1,28 +0,0 @@ -package p9 - -import ( - "os" - - "ollie/pkg/paths" -) - -// UtilStore is a FlatDirStore backed by the scripts/u/ directory. -type UtilStore struct { - *FlatDirStore -} - -func NewUtilStore() *UtilStore { - return &UtilStore{FlatDirStore: NewFlatDirStore(paths.CfgDir()+"/scripts/u", 0555)} -} - -func (s *UtilStore) Stat(name string) (os.FileInfo, error) { - return s.FlatDirStore.Stat(name) -} - -func (s *UtilStore) List() ([]os.DirEntry, error) { - return s.FlatDirStore.List() -} - -func (s *UtilStore) Get(name string) ([]byte, error) { - return s.FlatDirStore.Get(name) -}