diff --git a/internal/sessions/access.go b/internal/sessions/access.go index 1f008b476..539fcb827 100644 --- a/internal/sessions/access.go +++ b/internal/sessions/access.go @@ -244,6 +244,7 @@ func Found() []string { add("cursor", filepath.Join(CursorDir(), "chats"), filepath.Join(cursorDataDir(), "projects"), cursorEditorDB()) add("hermes", HermesDirs()...) add("alma", almaDB()) + add("openmausbot", ombDB()) add("minimax-code", minimaxSessions()) kimi := []string{kimiSessions()} for _, sh := range kimiWorkShares() { diff --git a/internal/sessions/manage.go b/internal/sessions/manage.go index 94d2b7ba3..e12d24248 100644 --- a/internal/sessions/manage.go +++ b/internal/sessions/manage.go @@ -33,7 +33,7 @@ import ( // Discord). agy's conversation_summaries.db and jetbox_summaries_proto.pb, // which it keeps open, keep the row, and agy lists no conversation whose // files are gone, as a restore brings it back to its /resume list. -// Hermes's and Alma's are rows in a database the agent keeps open and +// Hermes's, Alma's and OpenMausBot's are rows in a database the agent keeps open and // writes, so they are only listed, and so are OpenCode's and ZCode's, and // Cline's, whose sessions.db lists a session whose files are gone. Grok // Build's are folders, but it copies each session's text into diff --git a/internal/sessions/openmausbot.go b/internal/sessions/openmausbot.go new file mode 100644 index 000000000..b2f81df58 --- /dev/null +++ b/internal/sessions/openmausbot.go @@ -0,0 +1,365 @@ +package sessions + +import ( + "bytes" + "context" + "database/sql" + "encoding/json" + "net/url" + "os" + "path/filepath" + "slices" + "strconv" + "strings" + "sync" + "time" + + "github.com/yetone/magpie/internal/appdir" +) + +// OpenMausBot (milind-soni/OpenMausBot, a chat app whose bots run on agent +// CLIs or on a model API) keeps its data in $OMB_DATA_DIR, else +// ~/.openmausbot on every system (server/config.ts's DATA_DIR): +// +// bots.json the bots, each with its tasks — one a conversation +// (thread): threadId, title ("New thread" until it has +// one), createdAt/updatedAt (ms), and cwd once a turn has +// pinned the folder it works in (server/store.ts) +// messages.db SQLite, in WAL mode, written while it runs: messages +// (thread_id, id, at in ms, role user|bot, kind text| +// activity|digest|options|…, text, json), an activity's +// json holding the tool it ran as tool.name +// (server/message-db.ts) +// usage/.jsonl one row a turn: threadId, driverKind, model, +// input (cache reads and writes included), cachedInput, +// cacheWrite, output, at (server/usage-ledger.ts) +// +// A conversation is a session: its prompts, replies and tools from +// messages.db, its title and folder from bots.json, its tokens from the +// usage rows. Only the rows of a bot that runs on a model API (the +// drivers in ombAPIDrivers) count tokens here: a bot on Claude Code, Codex, +// Pi or another agent CLI runs that CLI, which keeps the turn in its own +// session as well, so its tokens are counted there (Claude Code's and +// Codex's in ~/.claude and ~/.codex) and would be counted twice. +// +// magpie only reads it, and never deletes a conversation: it is rows in a +// database OpenMausBot keeps open, which only OpenMausBot changes safely, +// and it has no command to pick one up again, so its sessions are listed +// read only. + +// OpenMausBotDir is OpenMausBot's data folder. +func OpenMausBotDir() string { + if d := strings.TrimSpace(appdir.Getenv("OMB_DATA_DIR")); d != "" { + return expandHome(d) + } + home, err := os.UserHomeDir() + if err != nil { + return "" + } + return filepath.Join(home, ".openmausbot") +} + +func ombDB() string { + d := OpenMausBotDir() + if d == "" { + return "" + } + return filepath.Join(d, "messages.db") +} + +// ombAPIDrivers are OpenMausBot's drivers that call a model's API +// themselves (server/agents-bridge-switch.ts's CHAT_RUNTIME_DRIVERS): no +// other app keeps their turns, so their tokens are counted here. +var ombAPIDrivers = []string{"cerebras", "greenference", "modelgo", "grok", "groq", "meta", "minimax", "mistral", "openai-compat"} + +// ombTask is what magpie reads of a conversation in bots.json. +type ombTask struct { + Title string + Cwd string +} + +// ombUse is one of usage/*.jsonl's rows. +type ombUse struct { + At string `json:"at"` + ThreadID string `json:"threadId"` + DriverKind string `json:"driverKind"` + Model string `json:"model"` + Input int `json:"input"` + Output int `json:"output"` + Cached int `json:"cachedInput"` + Written int `json:"cacheWrite"` +} + +// ombStore is OpenMausBot's data while a listing reads it. +type ombStore struct { + db *sql.DB + tasks map[string]ombTask + usage map[string][]ombUse +} + +// ombRead is a file read once and kept until it changes: bots.json and +// the usage files are read on every Sessions poll otherwise. +type ombRead[T any] struct { + size int64 + mod time.Time + v T +} + +var ( + ombMu sync.Mutex + ombTasksRead = map[string]ombRead[map[string]ombTask]{} + ombUsageRead = map[string]ombRead[map[string][]ombUse]{} +) + +// ombCached is read(path), or what it gave last while the file's size and +// time are the same. +func ombCached[T any](cache map[string]ombRead[T], path string, read func([]byte) T) (T, bool) { + var zero T + info, err := os.Stat(path) + if err != nil || !info.Mode().IsRegular() { + delete(cache, path) + return zero, false + } + if c, ok := cache[path]; ok && c.size == info.Size() && c.mod.Equal(info.ModTime()) { + return c.v, true + } + b, err := os.ReadFile(path) + if err != nil { + return zero, false + } + v := read(b) + cache[path] = ombRead[T]{size: info.Size(), mod: info.ModTime(), v: v} + return v, true +} + +// ombTasks are bots.json's conversations by thread id. A file that can't +// be parsed (OpenMausBot writes it whole) gives none, and the sessions +// keep their first prompts as titles. +func ombTasks(b []byte) map[string]ombTask { + var bots []struct { + Cwd *string `json:"cwd"` + Tasks []struct { + ThreadID string `json:"threadId"` + Title string `json:"title"` + Cwd *string `json:"cwd"` + } `json:"tasks"` + } + if json.Unmarshal(b, &bots) != nil { + return nil + } + out := map[string]ombTask{} + for _, bot := range bots { + for _, t := range bot.Tasks { + if t.ThreadID == "" { + continue + } + task := ombTask{Title: t.Title} + if t.Cwd != nil { + task.Cwd = *t.Cwd + } + out[t.ThreadID] = task + } + } + return out +} + +// ombUsage are a usage file's rows by thread id; a line that doesn't +// parse (one being written) is skipped. +func ombUsage(b []byte) map[string][]ombUse { + out := map[string][]ombUse{} + for line := range bytes.Lines(b) { + var u ombUse + if json.Unmarshal(line, &u) != nil || u.ThreadID == "" { + continue + } + out[u.ThreadID] = append(out[u.ThreadID], u) + } + return out +} + +func ombTime(ms int64) time.Time { + if ms <= 0 { + return time.Time{} + } + return time.UnixMilli(ms).UTC() +} + +// openmausbotFiles are OpenMausBot's conversations, one a session: its +// path the database's and #, its size the bytes of its +// messages, its time the latest message or usage row, and rev all that +// tells it changed — the database's files change with every write to any +// conversation. A conversation with no prompt and no usage (a bot's +// greeting alone) is left out. +func openmausbotFiles() []file { + if !Reads("openmausbot") { + return nil + } + path := ombDB() + if path == "" || !fileExists(path) { + return nil + } + db := openDB(path) + if db == nil { + return nil + } + cols := hermesColumns(db, "messages") + if !cols["thread_id"] || !cols["at"] || !cols["role"] || !cols["kind"] || !cols["json"] { + return nil + } + dir := filepath.Dir(path) + st := &ombStore{db: db, usage: map[string][]ombUse{}} + ombMu.Lock() + st.tasks, _ = ombCached(ombTasksRead, filepath.Join(dir, "bots.json"), ombTasks) + months, _ := filepath.Glob(filepath.Join(dir, "usage", "*.jsonl")) + slices.Sort(months) + for m := range ombUsageRead { + if !slices.Contains(months, m) { + delete(ombUsageRead, m) + } + } + for _, m := range months { + rows, _ := ombCached(ombUsageRead, m, ombUsage) + for id, r := range rows { + st.usage[id] = append(st.usage[id], r...) + } + } + ombMu.Unlock() + + rows, err := db.Query("SELECT thread_id, COUNT(*), MAX(at), SUM(octet_length(json)), " + + "SUM(CASE WHEN role = 'user' AND kind = 'text' THEN 1 ELSE 0 END) FROM messages GROUP BY thread_id") + if err != nil { + return nil + } + defer rows.Close() + var out []file + for rows.Next() { + var id string + var n, last, size, prompts int64 + if rows.Scan(&id, &n, &last, &size, &prompts) != nil || id == "" { + continue + } + use := st.usage[id] + if prompts == 0 && len(use) == 0 { + continue + } + mod := ombTime(last) + usageLast := "" + for _, u := range use { + if u.At > usageLast { + usageLast = u.At + } + } + if t := almaTime(usageLast); t.After(mod) { + mod = t + } + task := st.tasks[id] + out = append(out, file{ + agent: "openmausbot", + key: "openmausbot:" + id, + path: path + "#" + url.QueryEscape(id), + main: true, + size: size, + mod: modOf(mod), + readOnly: true, + more: &fileMore{ + sid: id, + omb: st, + rev: strings.Join([]string{strconv.FormatInt(n, 10), strconv.FormatInt(last, 10), strconv.FormatInt(size, 10), + strconv.Itoa(len(use)), usageLast, task.Title, task.Cwd}, "|"), + }, + }) + } + return out +} + +// parseOpenMausBot reads one conversation in a read transaction, a +// snapshot while OpenMausBot writes on. +func parseOpenMausBot(f file) *state { + s := &state{Size: f.size, Mod: f.mod.UnixNano(), StateMore: moreOf(StateMore{DBRevision: f.m().rev})} + st := f.m().omb + if st == nil { + return s + } + sid := f.m().sid + tx, err := st.db.BeginTx(context.Background(), nil) + if err != nil { + return &state{} + } + defer tx.Rollback() + rows, err := tx.Query("SELECT at, role, kind, COALESCE(text, ''), json FROM messages WHERE thread_id = ? ORDER BY at, rowid", sid) + if err != nil { + return &state{} + } + first := "" + turns := map[string]bool{} + for rows.Next() { + var at int64 + var role, kind, text, raw string + if rows.Scan(&at, &role, &kind, &text, &raw) != nil { + continue + } + t := ombTime(at) + s.saw(t, true) + switch { + case role == "user" && kind == "text": + s.day(dateOf(t)).Prompts++ + if first == "" && strings.TrimSpace(text) != "" { + first = title(text) + } + case role == "bot" && kind == "text": + // a turn may say something before a tool and again after it: + // one reply a turn. A bot's greeting, before anything was + // asked, is no reply. + var m struct { + TurnID string `json:"turnId"` + } + _ = json.Unmarshal([]byte(raw), &m) + if m.TurnID != "" { + if turns[m.TurnID] { + continue + } + turns[m.TurnID] = true + } else if first == "" { + continue + } + s.day(dateOf(t)).Replies++ + case role == "bot" && kind == "activity": + var m struct { + Tool struct { + Name string `json:"name"` + } `json:"tool"` + } + if json.Unmarshal([]byte(raw), &m) == nil && m.Tool.Name != "" { + s.tool(t, m.Tool.Name, "") + } + } + } + rows.Close() + if rows.Err() != nil { + return &state{} + } + task := st.tasks[sid] + if named := title(task.Title); named != "" && named != "New thread" { + s.Title = named + } else { + s.Title = first + } + s.Cwd = task.Cwd + s.own().First = first + + for _, u := range st.usage[sid] { + t := almaTime(u.At) + if t.IsZero() { + t = s.Last + } + if t.After(s.Last) { + s.Last = t + } + if !slices.Contains(ombAPIDrivers, u.DriverKind) { + continue // counted in the agent CLI's own session + } + cached, written := max(0, u.Cached), max(0, u.Written) + s.use(dateOf(t), strings.TrimSpace(u.Model), Tokens{Input: max(0, u.Input-cached-written), Output: max(0, u.Output), CacheRead: cached, CacheWrite: written}) + } + return s +} diff --git a/internal/sessions/openmausbot_test.go b/internal/sessions/openmausbot_test.go new file mode 100644 index 000000000..8bbc4459b --- /dev/null +++ b/internal/sessions/openmausbot_test.go @@ -0,0 +1,240 @@ +package sessions + +import ( + "bytes" + "database/sql" + "os" + "path/filepath" + "strings" + "testing" + "time" + + _ "modernc.org/sqlite" +) + +// testdata/openmausbot is OpenMausBot 0.1.155's data folder as it wrote it +// (bots.json, messages.db and usage/2026-11.jsonl, the database +// checkpointed): a bot "Scout" on an OpenAI-compatible engine asked "Say +// hi, then list three fruits" and then "你好,再说一次", and in a second +// conversation "TOOL: who is on the team?", where it said a line, ran +// agents_list_bots and replied; and two conversations holding only a +// bot's greeting (Scout's, and MausBot's, the chief of staff's). +const ( + ombFruits = "301edbda-e68f-4c9c-b9da-d2a9b6ab179c" + ombTeam = "ed2913c7-5021-426b-8434-2af0df746c0d" + ombGreet = "3ec55eac-63f4-44d9-bbfd-a86ee201ec5f" + ombChief = "8e80165a-834e-402b-b640-7928e8a481ef" +) + +// ombFixture copies the sample into dir, OpenMausBot's data folder. +func ombFixture(t *testing.T, dir string) { + t.Helper() + copyTree(t, "testdata/openmausbot", dir) +} + +func ombSession(t *testing.T, list []Session, id string) Session { + t.Helper() + for _, s := range list { + if s.Agent == "openmausbot" && s.ID == id { + return s + } + } + t.Fatalf("OpenMausBot conversation %q not listed: %+v", id, list) + return Session{} +} + +func ombManaged(t *testing.T, id string) Managed { + t.Helper() + for _, m := range ListAgent("openmausbot") { + if m.ID == id { + return m + } + } + t.Fatalf("OpenMausBot conversation %q not on the page", id) + return Managed{} +} + +func TestOpenMausBotSessions(t *testing.T) { + setup(t) + home, _ := os.UserHomeDir() + dir := filepath.Join(home, ".openmausbot") + if OpenMausBotDir() != dir { + t.Fatalf("OpenMausBotDir() = %q, want %q", OpenMausBotDir(), dir) + } + ombFixture(t, dir) + db := filepath.Join(dir, "messages.db") + before, err := os.ReadFile(db) + if err != nil { + t.Fatal(err) + } + + list := List(0) + a := ombSession(t, list, ombFruits) + if !a.ReadOnly || a.Resume != "" || a.Title != "Say hi, then list three fruits" || a.Cwd != "" { + t.Errorf("fruits: %+v", a) + } + // input is OpenMausBot's whole prompt; no cache was read or written + if got := model(a, "fake-model-1").Tokens; got != (Tokens{Input: 1202 + 1203, Output: 42 + 43}) { + t.Errorf("fruits tokens = %+v", got) + } + if !a.Start.Equal(time.UnixMilli(1794638499985)) || !a.Last.Equal(time.UnixMilli(1794638502422)) { + t.Errorf("fruits times %v – %v", a.Start, a.Last) + } + b := ombSession(t, list, ombTeam) + if b.Title != "TOOL: who is on the team?" { + t.Errorf("team: %+v", b) + } + if got := model(b, "fake-model-1").Tokens; got != (Tokens{Input: 2403, Output: 83}) { + t.Errorf("team tokens = %+v", got) + } + for _, s := range list { + if s.Agent == "openmausbot" && (s.ID == ombGreet || s.ID == ombChief) { + t.Errorf("a conversation with only a bot's greeting was listed: %+v", s) + } + } + + // the Sessions page: listed, never deletable; a reply a turn, though + // the bot spoke before its tool and after it + managed := ListAgent("openmausbot") + if len(managed) != 2 { + t.Fatalf("ListAgent(openmausbot) = %+v", managed) + } + for _, m := range managed { + if m.Deletable { + t.Errorf("an OpenMausBot conversation is deletable: %+v", m) + } + want := map[string]int{ombFruits: 4, ombTeam: 2}[m.ID] + if m.Messages != want || m.Size == 0 { + t.Errorf("%s on the page: %d messages (want %d), %d bytes", m.ID, m.Messages, want, m.Size) + } + } + if _, err := Delete("openmausbot", ombFruits); err == nil { + t.Error("Delete took a conversation out of OpenMausBot's database") + } + + st := StatsAt(0, time.UnixMilli(1794638536426).Add(24*time.Hour)) + var sum Summary + for _, s := range st.Sessions { + if s.Key == "openmausbot:"+ombTeam { + sum = s + } + } + if sum.Prompts != 1 || sum.Replies != 1 || sum.ToolCalls != 1 || sum.tools.of("agents_list_bots") != 1 { + t.Errorf("team stats: prompts %d replies %d tools %d %v", sum.Prompts, sum.Replies, sum.ToolCalls, sum.tools) + } + + found := false + for _, d := range Dirs() { + found = found || d == dir + } + if !found { + t.Errorf("Dirs() %v leaves out OpenMausBot's", Dirs()) + } + after, err := os.ReadFile(db) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(before, after) { + t.Error("reading OpenMausBot's conversations changed its database") + } +} + +// A bot on Claude Code (or Codex, Pi, another agent CLI) runs that CLI, +// which keeps the turn in its own session: its tokens are counted there, +// not again here. A bot on a model API's are counted here, cache reads +// and writes apart from the fresh input OpenMausBot's input includes. +// The rows are the sample's own, with their engine and cache changed. +func TestOpenMausBotCountsCLITurnsOnce(t *testing.T) { + setup(t) + dir := filepath.Join(t.TempDir(), "omb") + t.Setenv("OMB_DATA_DIR", dir) + ombFixture(t, dir) + path := filepath.Join(dir, "usage", "2026-11.jsonl") + raw, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + lines := strings.SplitAfter(string(raw), "\n") + cli := strings.Replace(lines[0], `"driverKind":"openai-compat","model":"fake-model-1"`, `"driverKind":"claudeAgent","model":"claude-opus-5-5"`, 1) + cached := strings.Replace(lines[1], `"input":1203,"output":43,`, `"input":1203,"output":43,"cachedInput":1000,"cacheWrite":100,`, 1) + if cli == lines[0] || cached == lines[1] { + t.Fatal("the sample's rows changed shape") + } + if err := os.WriteFile(path, []byte(cli+cached+strings.Join(lines[2:], "")), 0o644); err != nil { + t.Fatal(err) + } + bots := filepath.Join(dir, "bots.json") + b, err := os.ReadFile(bots) + if err != nil { + t.Fatal(err) + } + pinned := strings.Replace(string(b), `"title":"Say hi, then list three fruits",`, `"title":"Say hi, then list three fruits","cwd":"/work/fruits",`, 1) + if pinned == string(b) { + t.Fatal("the sample's bots.json changed shape") + } + if err := os.WriteFile(bots, []byte(pinned), 0o644); err != nil { + t.Fatal(err) + } + + a := ombSession(t, List(0), ombFruits) + if got := model(a, "claude-opus-5-5").Tokens; !got.zero() { + t.Errorf("a Claude Code turn's tokens counted again: %+v", got) + } + if got := model(a, "fake-model-1").Tokens; got != (Tokens{Input: 103, Output: 43, CacheRead: 1000, CacheWrite: 100}) { + t.Errorf("an API turn's tokens = %+v", got) + } + if a.Cwd != "/work/fruits" { + t.Errorf("the conversation's folder = %q", a.Cwd) + } +} + +// OpenMausBot writes its WAL all the while it runs: a conversation is +// read again when its own rows, or its title in bots.json, change, though +// the database file's size and time don't. +func TestOpenMausBotReadAgainWhenItChanges(t *testing.T) { + setup(t) + dir := filepath.Join(t.TempDir(), "omb") + t.Setenv("OMB_DATA_DIR", dir) + ombFixture(t, dir) + if s := ombManaged(t, ombTeam); s.Messages != 2 { + t.Fatalf("team: %+v", s) + } + // a new title alone changes neither the database nor its rows + bots := filepath.Join(dir, "bots.json") + b, err := os.ReadFile(bots) + if err != nil { + t.Fatal(err) + } + renamed := bytes.Replace(b, []byte(`"title":"TOOL: who is on the team?"`), []byte(`"title":"The team"`), 1) + if bytes.Equal(renamed, b) { + t.Fatal("the sample's bots.json changed shape") + } + if err := os.WriteFile(bots, renamed, 0o644); err != nil { + t.Fatal(err) + } + if s := ombManaged(t, ombTeam); s.Messages != 2 || s.Title != "The team" { + t.Fatalf("a new title not read: %+v", s) + } + + path := filepath.Join(dir, "messages.db") + info, err := os.Stat(path) + if err != nil { + t.Fatal(err) + } + db, err := sql.Open("sqlite", path) + if err != nil { + t.Fatal(err) + } + defer db.Close() + if _, err := db.Exec(`INSERT INTO messages (thread_id, id, at, role, kind, text, json) + SELECT thread_id, 'again', at + 1000, role, kind, text, json FROM messages WHERE thread_id = ? AND role = 'user'`, ombTeam); err != nil { + t.Fatal(err) + } + if err := os.Chtimes(path, info.ModTime(), info.ModTime()); err != nil { + t.Fatal(err) + } + s := ombManaged(t, ombTeam) + if s.Messages != 3 || s.Title != "The team" { + t.Errorf("team not read again: %+v", s) + } +} diff --git a/internal/sessions/sessions.go b/internal/sessions/sessions.go index c3f764481..51a6d53dd 100644 --- a/internal/sessions/sessions.go +++ b/internal/sessions/sessions.go @@ -2,7 +2,7 @@ // files — Claude Code's projects/*/.jsonl (and Qoder's, the same kind), // Codex's rollout files, OpenCode's database (or its older JSON files) and // ZCode's, Pi's session files and omp's, DeepSeek Harness's, Cline's, Grok -// Build's, WorkBuddy's and CodeBuddy Code's, Droid's, Cursor CLI's and Alma's chat stores — with the tokens each spent, what that cost at the +// Build's, WorkBuddy's and CodeBuddy Code's, Droid's, Cursor CLI's, Alma's and OpenMausBot's chat stores — with the tokens each spent, what that cost at the // effective price, and the command that resumes it. It only ever reads the // agents' folders. // @@ -122,7 +122,7 @@ type Session struct { // Gateway: seen only through magpie's gateway, with no file of the // agent's on this computer (external.go) Gateway bool `json:"gateway,omitempty"` - Agent string `json:"agent"` // magpie agent id: claude, codex, opencode, pi, omp, zcode, dsh, cline, qoder, qoder-cn, grok, workbuddy, workbuddy-ai, codebuddy, droid, cursor, hermes, alma, kimi, agy + Agent string `json:"agent"` // magpie agent id: claude, codex, opencode, pi, omp, zcode, dsh, cline, qoder, qoder-cn, grok, workbuddy, workbuddy-ai, codebuddy, droid, cursor, hermes, alma, openmausbot, kimi, agy ID string `json:"id"` Cwd string `json:"cwd"` Title string `json:"title"` // the name it was given, else the agent's own title, else the first prompt @@ -579,7 +579,9 @@ type fileMore struct { hermes *hermesDB // Alma: its database, and what tells the chat's rows changed alma *almaStore - rev string + // OpenMausBot: its database, bots and usage rows + omb *ombStore + rev string // agy: what conversation_summaries.db says of the conversation agy *agySummary editor *cursorEditorMeta @@ -1003,7 +1005,7 @@ func allFilesWith(kept *filesKept, zcode func() []file) []file { lists := callFileLists(codexFiles()) lists = append(lists, openCodeFiles(), piFiles(), raftFiles(), cindyFiles(), wslFiles("pi", "raft", "omp", "kimi", "antigravity", "agy"), zcode()) lists = append(lists, dshFiles(), clineFiles(), ccFiles("qoder", QoderDir("qoder")), ccFiles("qoder-cn", QoderDir("qoder-cn")), - grokFiles(), workbuddyFiles(), workbuddyAIFiles(), codebuddyFiles(), droidFiles(), ompFiles(), cursorFiles(), hermesFiles(), almaFiles(), kimiFiles(), agyFiles(), + grokFiles(), workbuddyFiles(), workbuddyAIFiles(), codebuddyFiles(), droidFiles(), ompFiles(), cursorFiles(), hermesFiles(), almaFiles(), openmausbotFiles(), kimiFiles(), agyFiles(), antigravityFiles()) // #2190 // each lister asked Reads already; a file listed under another // agent's name is held to that agent too @@ -1117,6 +1119,7 @@ func Dirs() []string { {cursorDataDir(), filepath.Join(cursorDataDir(), "projects")}, {filepath.Dir(cursorEditorDB()), cursorEditorDB()}, {AlmaDir(), almaDB()}, + {OpenMausBotDir(), ombDB()}, {MiniMaxDir(), minimaxSessions()}, {KimiCodeDir(), kimiSessions()}, {AntigravityAppDir(), antigravityConversations()}, @@ -1696,7 +1699,7 @@ func refresh(want, all []file) { if f.cold { continue // in a stopped WSL distro: what was read of it stands } - if s := parsed(f.path); s == nil || s.Size != f.size || s.Mod != f.mod.UnixNano() || ccStale(f, s) || (f.agent == "hermes" && (f.m().hermes == nil || f.m().rev == "" || s.more().DBRevision != f.m().rev)) || ((f.agent == "alma" || f.agent == "cursor" || f.agent == "agy" || f.agent == "antigravity") && s.more().DBRevision != f.m().rev) { + if s := parsed(f.path); s == nil || s.Size != f.size || s.Mod != f.mod.UnixNano() || ccStale(f, s) || (f.agent == "hermes" && (f.m().hermes == nil || f.m().rev == "" || s.more().DBRevision != f.m().rev)) || ((f.agent == "alma" || f.agent == "openmausbot" || f.agent == "cursor" || f.agent == "agy" || f.agent == "antigravity") && s.more().DBRevision != f.m().rev) { if parsing[f.path] != nil { // a refresh is reading it, another or this one (a path // listed twice): its last parse stands until that one is @@ -2299,6 +2302,8 @@ func parserFor(agent string) sessionParser { return sessionParser{whole: parseHermes} case "alma": return sessionParser{whole: parseAlma} + case "openmausbot": + return sessionParser{whole: parseOpenMausBot} case "opencode", "zcode": return sessionParser{whole: parseOpenCode} case "dsh": diff --git a/internal/sessions/skills_every_agent_test.go b/internal/sessions/skills_every_agent_test.go index d8eb7b3b2..50beaa69b 100644 --- a/internal/sessions/skills_every_agent_test.go +++ b/internal/sessions/skills_every_agent_test.go @@ -46,6 +46,7 @@ var skillsCounted = map[string]struct { "codebuddy": {none: "reads with WorkBuddy's parser, which counts no skills"}, "workbuddy-ai": {none: "reads with WorkBuddy's parser, which counts no skills"}, "hermes": {none: "its skill_view tool is not read; hermes is not run in a sandbox (it rewrites the live launcher)"}, + "openmausbot": {none: "a bot finds a skill with skills_list and reads its SKILL.md with its file tools, no tool of its own; the real sample has no such turn"}, "cursor": {none: "selected skills live in selectedContext; needs a signed-in Cursor for a real session"}, "agy": {none: "skill_lookup's keys are not known from a real session"}, "antigravity": {none: "its steps' payloads are encrypted at rest; only the usage in steps.metadata is read"}, diff --git a/internal/sessions/testdata/openmausbot/bots.json b/internal/sessions/testdata/openmausbot/bots.json new file mode 100644 index 000000000..8e2e8a50a --- /dev/null +++ b/internal/sessions/testdata/openmausbot/bots.json @@ -0,0 +1 @@ +[{"id":"341eb366-2641-4378-8c71-52bd4c7292c7","threadId":"ed2913c7-5021-426b-8434-2af0df746c0d","name":"Scout","title":"","description":"","soul":"","soulHash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","notifications":true,"color":"green","mascotBody":"cursor","unread":true,"modelSelection":{"instanceId":"openaiCompat","model":"fake-model-1"},"resumeCursors":{},"createdAt":1794638499736,"tasks":[{"threadId":"ed2913c7-5021-426b-8434-2af0df746c0d","title":"TOOL: who is on the team?","createdAt":1794638536111,"updatedAt":1794638536426,"resumeCursors":{},"approvalMode":"full","autoApprove":false,"alwaysAllow":[],"unread":true,"lastThreadOrderAt":1794638536425,"askedAt":1794638536138,"lastInstanceId":"openaiCompat","usage":{"input":2403,"output":83,"costUsd":null,"turns":1,"lastTurn":{"input":2403,"output":83,"costUsd":null},"context":{"tokens":1244}},"lastContextModel":"openaiCompat:fake-model-1"},{"threadId":"301edbda-e68f-4c9c-b9da-d2a9b6ab179c","title":"Say hi, then list three fruits","createdAt":1794638499966,"updatedAt":1794638502422,"resumeCursors":{},"approvalMode":"full","autoApprove":false,"alwaysAllow":[],"unread":true,"lastThreadOrderAt":1794638502421,"askedAt":1794638502258,"lastInstanceId":"openaiCompat","usage":{"input":2405,"output":85,"costUsd":null,"turns":2,"lastTurn":{"input":1203,"output":43,"costUsd":null},"context":{"tokens":1246}},"lastContextModel":"openaiCompat:fake-model-1"},{"threadId":"3ec55eac-63f4-44d9-bbfd-a86ee201ec5f","title":"New thread","createdAt":1794638499736,"updatedAt":1794638499761,"resumeCursors":{},"unread":false,"lastThreadOrderAt":1794638499761}],"autoApprove":false},{"id":"8362c4ea-5c35-448f-9c68-9ef9dea61659","threadId":"8e80165a-834e-402b-b640-7928e8a481ef","name":"MausBot","title":"","description":"","soul":"","soulHash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","notifications":true,"color":"chrome","unread":false,"modelSelection":{"instanceId":"openaiCompat","model":"fake-model-1"},"resumeCursors":{},"createdAt":1794638479519,"tasks":[{"threadId":"8e80165a-834e-402b-b640-7928e8a481ef","title":"New thread","createdAt":1794638479519,"updatedAt":1794638479538,"resumeCursors":{},"unread":false,"approvalMode":"full","alwaysAllow":[]}],"chiefOfStaff":true,"hidden":false,"defaultBot":{}}] \ No newline at end of file diff --git a/internal/sessions/testdata/openmausbot/messages.db b/internal/sessions/testdata/openmausbot/messages.db new file mode 100644 index 000000000..d5ff40071 Binary files /dev/null and b/internal/sessions/testdata/openmausbot/messages.db differ diff --git a/internal/sessions/testdata/openmausbot/usage/2026-11.jsonl b/internal/sessions/testdata/openmausbot/usage/2026-11.jsonl new file mode 100644 index 000000000..800b3e018 --- /dev/null +++ b/internal/sessions/testdata/openmausbot/usage/2026-11.jsonl @@ -0,0 +1,3 @@ +{"botId":"341eb366-2641-4378-8c71-52bd4c7292c7","botName":"Scout","threadId":"301edbda-e68f-4c9c-b9da-d2a9b6ab179c","instanceId":"openaiCompat","driverKind":"openai-compat","model":"fake-model-1","input":1202,"output":42,"costUsd":null,"trigger":{"kind":"owner"},"turnId":"48cdaaf7-5d2c-4833-8a1e-844a54cc404b","startedAt":"2026-11-14T06:41:41.610Z","endedAt":"2026-11-14T06:41:41.809Z","outcome":{"status":"ok"},"steps":1,"tools":0,"toolErrors":0,"contextTokens":1244,"usageStatus":"partial","at":"2026-11-14T06:41:41.826Z","promptBytes":{"stable":18282,"volatile":4602}} +{"botId":"341eb366-2641-4378-8c71-52bd4c7292c7","botName":"Scout","threadId":"301edbda-e68f-4c9c-b9da-d2a9b6ab179c","instanceId":"openaiCompat","driverKind":"openai-compat","model":"fake-model-1","input":1203,"output":43,"costUsd":null,"trigger":{"kind":"owner"},"turnId":"92433de6-24f1-4a7b-bb60-fa2f29a41a2b","startedAt":"2026-11-14T06:41:42.273Z","endedAt":"2026-11-14T06:41:42.410Z","outcome":{"status":"ok"},"steps":1,"tools":0,"toolErrors":0,"contextTokens":1246,"usageStatus":"partial","at":"2026-11-14T06:41:42.422Z","promptBytes":{"stable":18282,"volatile":4602}} +{"botId":"341eb366-2641-4378-8c71-52bd4c7292c7","botName":"Scout","threadId":"ed2913c7-5021-426b-8434-2af0df746c0d","instanceId":"openaiCompat","driverKind":"openai-compat","model":"fake-model-1","input":2403,"output":83,"costUsd":null,"trigger":{"kind":"owner"},"turnId":"68914cf1-5ffb-49d6-ae64-88cf1b5cd435","startedAt":"2026-11-14T06:42:16.154Z","endedAt":"2026-11-14T06:42:16.416Z","outcome":{"status":"ok"},"steps":2,"tools":2,"toolErrors":0,"contextTokens":1244,"usageStatus":"partial","at":"2026-11-14T06:42:16.426Z","promptBytes":{"stable":18282,"volatile":4720}}