env: use pkg/env for defaults; expose ollie/env in 9p filesystem
- Replace inline ensureEnv() with env.EnsureDefaults() from ollie/pkg/env - Serve ollie/env as a readable file containing the daemon's full process env - Remove extraEnv/InitialEnv session-spec mechanism (no longer needed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
237e4dec8c
commit
eef8ccecd9
|
|
@ -5,6 +5,7 @@
|
|||
// ollie/
|
||||
// a/ (dir) agent configs (r/w, backed by ~/.config/ollie/agents/)
|
||||
// backends (read) list of ollie-provided backends
|
||||
// env (read) daemon environment (NAME=VALUE lines)
|
||||
// help (read) help file (backed by ~/.config/ollie/help.md)
|
||||
// m/ (dir) memories (r/w, backed by OLLIE_MEMORY_PATH)
|
||||
// p/ (dir) prompt templates
|
||||
|
|
@ -47,6 +48,7 @@ import (
|
|||
"ollie/pkg/agent"
|
||||
"ollie/pkg/backend"
|
||||
"ollie/pkg/config"
|
||||
"ollie/pkg/env"
|
||||
olog "ollie/pkg/log"
|
||||
"ollie/pkg/paths"
|
||||
"ollie/pkg/tools"
|
||||
|
|
@ -360,6 +362,8 @@ func (s *Server) pathType(path string) string {
|
|||
}
|
||||
case len(parts) == 1 && parts[0] == "backends":
|
||||
return "file"
|
||||
case len(parts) == 1 && parts[0] == "env":
|
||||
return "file"
|
||||
case len(parts) == 1 && parts[0] == "help":
|
||||
return "file"
|
||||
case len(parts) == 2 && parts[0] == "a":
|
||||
|
|
@ -611,6 +615,12 @@ func (s *Server) read(cs *connState, fc *plan9.Fcall) *plan9.Fcall {
|
|||
return s.readSlice(fc, content)
|
||||
}
|
||||
|
||||
// env exposes the daemon's managed environment variables to frontends.
|
||||
if path == "/env" {
|
||||
plog.Debug("Tread path=%q offset=%d count=%d", path, fc.Offset, fc.Count)
|
||||
return s.readSlice(fc, env.Format())
|
||||
}
|
||||
|
||||
// backends is a static list of ollie-provided backends.
|
||||
if path == "/backends" {
|
||||
plog.Debug("Tread path=%q offset=%d count=%d", path, fc.Offset, fc.Count)
|
||||
|
|
@ -1180,13 +1190,6 @@ func (s *Server) createSession(args []string) error {
|
|||
|
||||
env := agent.BuildAgentEnv(cfg, newDisp(), cwd)
|
||||
|
||||
// Inject per-session env vars into the execute server.
|
||||
if srv, ok := env.Dispatcher().GetServer("execute"); ok {
|
||||
if es, ok := srv.(tools.EnvSetter); ok {
|
||||
es.SetEnv("OLLIE_SESSION_ID", sessID)
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
core := agent.NewAgentCore(agent.AgentCoreConfig{
|
||||
Backend: be,
|
||||
|
|
@ -1294,6 +1297,7 @@ func (s *Server) readDir(path string, offset uint64, count uint32) []byte {
|
|||
dirs = append(dirs, makeDir("a", "/a", true, plan9.DMDIR|0755))
|
||||
dirs = append(dirs, makeDir("b", "/b", true, plan9.DMDIR|0755))
|
||||
dirs = append(dirs, makeDir("backends", "/backends", false, 0444))
|
||||
dirs = append(dirs, makeDir("env", "/env", false, 0444))
|
||||
dirs = append(dirs, makeDir("help", "/help", false, 0444))
|
||||
dirs = append(dirs, makeDir("m", "/m", true, plan9.DMDIR|0755))
|
||||
dirs = append(dirs, makeDir("p", "/p", true, plan9.DMDIR|0555))
|
||||
|
|
@ -1498,7 +1502,7 @@ func (s *Server) makeStat(path string) plan9.Dir {
|
|||
case "backend", "agent", "model", "cwd":
|
||||
mode = 0666
|
||||
default:
|
||||
if path == "/backends" || path == "/help" {
|
||||
if path == "/backends" || path == "/env" || path == "/help" {
|
||||
mode = 0444
|
||||
} else if isSessionStoreFile(path) {
|
||||
mode = plan9.Perm(sessionStoreFiles[base])
|
||||
|
|
|
|||
21
main.go
21
main.go
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"9fans.net/go/plan9/client"
|
||||
p9 "olliesrv/internal/p9"
|
||||
"ollie/pkg/env"
|
||||
olog "ollie/pkg/log"
|
||||
)
|
||||
|
||||
|
|
@ -140,26 +141,8 @@ func stopServer(sockPath, pidPath string) {
|
|||
fmt.Println("olliesrv stopped")
|
||||
}
|
||||
|
||||
func ensureEnv() {
|
||||
home, _ := os.UserHomeDir()
|
||||
defaults := map[string]string{
|
||||
"OLLIE": filepath.Join(home, "mnt", "ollie"),
|
||||
"OLLIE_TOOLS_PATH": filepath.Join(home, ".config", "ollie", "tools"),
|
||||
"OLLIE_SKILLS_PATH": filepath.Join(home, ".config", "ollie", "skills"),
|
||||
"OLLIE_PLAN_PATH": filepath.Join(home, ".config", "ollie", "planning"),
|
||||
"OLLIE_MEMORY_PATH": filepath.Join(home, ".config", "ollie", "memory"),
|
||||
"OLLIE_TMP_PATH": filepath.Join(home, ".local", "share", "ollie", "tmp"),
|
||||
"OLLIE_TRANSCRIPT_PATH": filepath.Join(home, ".config", "ollie", "transcript"),
|
||||
}
|
||||
for k, v := range defaults {
|
||||
if os.Getenv(k) == "" {
|
||||
os.Setenv(k, v) //nolint:errcheck
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func runServer(sockPath, pidPath string) {
|
||||
ensureEnv()
|
||||
env.EnsureDefaults()
|
||||
|
||||
// Remove stale socket
|
||||
if _, err := os.Stat(sockPath); err == nil {
|
||||
|
|
|
|||
Reference in New Issue