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 {} 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 --- // --- session list window ---
type sessionList struct { type sessionList struct {
@ -113,7 +129,8 @@ func (sl *sessionList) eventLoop() {
arg := strings.TrimSpace(string(e.Arg)) arg := strings.TrimSpace(string(e.Arg))
sid := sl.resolveFullSID(arg) sid := sl.resolveFullSID(arg)
if sid != "" { 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() sl.refresh()
} }
continue continue
@ -180,7 +197,8 @@ func openChat(sid string) {
chatWindows.Store(sid, cw) chatWindows.Store(sid, cw)
// Load existing chat. // 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 { if data, err := os.ReadFile(chatPath); err == nil && len(data) > 0 {
w.Write("body", data) w.Write("body", data)
cw.offset = len(data) cw.offset = len(data)
@ -193,23 +211,24 @@ func openChat(sid string) {
func (cw *chatWin) eventLoop() { func (cw *chatWin) eventLoop() {
defer chatWindows.Delete(cw.sid) defer chatWindows.Delete(cw.sid)
ab := agentBase(cw.sid)
for e := range cw.win.EventChan() { for e := range cw.win.EventChan() {
switch e.C2 { switch e.C2 {
case 'x', 'X': case 'x', 'X':
cmd := strings.TrimSpace(string(e.Text)) cmd := strings.TrimSpace(string(e.Text))
switch cmd { switch cmd {
case "Prompt": case "Prompt":
openFile(filepath.Join(ollie, "s", cw.sid, "prompt")) openFile(filepath.Join(ab, "prompt"))
case "Stop": 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": case "Ctl":
openFile(filepath.Join(ollie, "s", cw.sid, "ctl")) openFile(filepath.Join(ab, "ctl"))
case "Cfg": case "Cfg":
openFile(filepath.Join(ollie, "s", cw.sid, "cfg")) openFile(filepath.Join(ab, "cfg"))
case "Nudge": 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": case "Usage":
openFile(filepath.Join(ollie, "s", cw.sid, "usage")) openFile(filepath.Join(ab, "usage"))
default: default:
cw.win.WriteEvent(e) 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. // tail polls the chat file for new content and streams it to the window.
func (cw *chatWin) tail() { func (cw *chatWin) tail() {
chatPath := filepath.Join(ollie, "s", cw.sid, "chat") ab := agentBase(cw.sid)
chatPath := filepath.Join(ab, "chat")
for { for {
fi, err := os.Stat(chatPath) fi, err := os.Stat(chatPath)