update paths for new agent tree architecture

Session files (chat, prompt, cfg, ctl, usage) now live under
s/{sid}/agent/{aid}/ instead of s/{sid}/. Add agentBase() helper
to discover the active agent directory.
This commit is contained in:
Levi Neely 2026-07-30 00:27:29 +02:00
parent 6d0386b654
commit 6e94053c5b
1 changed files with 29 additions and 9 deletions

38
main.go
View File

@ -30,6 +30,22 @@ func main() {
select {}
}
// agentBase returns the filesystem path to the active agent within a session.
// Layout: s/{sid}/agent/{aid}/
func agentBase(sid string) string {
agentDir := filepath.Join(ollie, "s", sid, "agent")
entries, err := os.ReadDir(agentDir)
if err != nil {
return filepath.Join(agentDir, "0") // fallback
}
for _, e := range entries {
if e.IsDir() {
return filepath.Join(agentDir, e.Name())
}
}
return filepath.Join(agentDir, "0")
}
// --- session list window ---
type sessionList struct {
@ -113,7 +129,8 @@ func (sl *sessionList) eventLoop() {
arg := strings.TrimSpace(string(e.Arg))
sid := sl.resolveFullSID(arg)
if sid != "" {
os.WriteFile(filepath.Join(ollie, "s", sid, "ctl"), []byte("kill"), 0644) //nolint:errcheck
ab := agentBase(sid)
os.WriteFile(filepath.Join(ab, "ctl"), []byte("kill"), 0644) //nolint:errcheck
sl.refresh()
}
continue
@ -180,7 +197,8 @@ func openChat(sid string) {
chatWindows.Store(sid, cw)
// Load existing chat.
chatPath := filepath.Join(ollie, "s", sid, "chat")
ab := agentBase(sid)
chatPath := filepath.Join(ab, "chat")
if data, err := os.ReadFile(chatPath); err == nil && len(data) > 0 {
w.Write("body", data)
cw.offset = len(data)
@ -193,23 +211,24 @@ func openChat(sid string) {
func (cw *chatWin) eventLoop() {
defer chatWindows.Delete(cw.sid)
ab := agentBase(cw.sid)
for e := range cw.win.EventChan() {
switch e.C2 {
case 'x', 'X':
cmd := strings.TrimSpace(string(e.Text))
switch cmd {
case "Prompt":
openFile(filepath.Join(ollie, "s", cw.sid, "prompt"))
openFile(filepath.Join(ab, "prompt"))
case "Stop":
os.WriteFile(filepath.Join(ollie, "s", cw.sid, "ctl"), []byte("stop"), 0644) //nolint:errcheck
os.WriteFile(filepath.Join(ab, "ctl"), []byte("stop"), 0644) //nolint:errcheck
case "Ctl":
openFile(filepath.Join(ollie, "s", cw.sid, "ctl"))
openFile(filepath.Join(ab, "ctl"))
case "Cfg":
openFile(filepath.Join(ollie, "s", cw.sid, "cfg"))
openFile(filepath.Join(ab, "cfg"))
case "Nudge":
os.WriteFile(filepath.Join(ollie, "s", cw.sid, "prompt"), []byte("."), 0644) //nolint:errcheck
os.WriteFile(filepath.Join(ab, "prompt"), []byte("."), 0644) //nolint:errcheck
case "Usage":
openFile(filepath.Join(ollie, "s", cw.sid, "usage"))
openFile(filepath.Join(ab, "usage"))
default:
cw.win.WriteEvent(e)
}
@ -221,7 +240,8 @@ func (cw *chatWin) eventLoop() {
// tail polls the chat file for new content and streams it to the window.
func (cw *chatWin) tail() {
chatPath := filepath.Join(ollie, "s", cw.sid, "chat")
ab := agentBase(cw.sid)
chatPath := filepath.Join(ab, "chat")
for {
fi, err := os.Stat(chatPath)