diff --git a/lib/session-watcher.test.mjs b/lib/session-watcher.test.mjs new file mode 100644 index 000000000..d01d41ca7 --- /dev/null +++ b/lib/session-watcher.test.mjs @@ -0,0 +1,14 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import test from "node:test"; + +test("session watcher watches the lister's sessions directory, not ~/.omp/agent/sessions", () => { + const source = readFileSync(new URL("./session-watcher.ts", import.meta.url), "utf8"); + // Every other session consumer uses getSessionsDir(), which honors the + // XDG layout ($XDG_DATA_HOME/omp/sessions when that opt-in exists). The + // watcher previously derived the path from getAgentDir(), so under XDG it + // watched a directory the lister never reads and external session changes + // never reached the sidebar. + assert.match(source, /const sessionsDir = getSessionsDir\(\);/); + assert.doesNotMatch(source, /join\(getAgentDir\(\), "sessions"\)/); +}); diff --git a/lib/session-watcher.ts b/lib/session-watcher.ts index b36a66db7..3ebeab5ae 100644 --- a/lib/session-watcher.ts +++ b/lib/session-watcher.ts @@ -1,13 +1,13 @@ import { watch, type FSWatcher } from "fs"; import { join } from "path"; import { - getAgentDir, invalidateSessionEntriesCache, invalidateSessionListCache, invalidateSessionListMeta, listAllSessions, resolveSessionIdByPath, } from "./session-reader"; +import { getSessionsDir } from "./omp/paths"; // omp owns the writes to a session's JSONL. ompweb streams RPC events only for // the sessions it spawned itself, so a session started outside the web UI — by @@ -94,7 +94,12 @@ function scheduleRetry(): void { function ensureWatcher(): void { if (watcher || retryTimer) return; - const sessionsDir = join(getAgentDir(), "sessions"); + // Watch the directory the session lister actually reads. Deriving this + // from getAgentDir() broke the XDG layout ($XDG_DATA_HOME/omp/sessions): + // the watcher then watched ~/.omp/agent/sessions, so external session + // changes never reached the sidebar for XDG users (or it retried a + // nonexistent directory forever). + const sessionsDir = getSessionsDir(); try { watcher = watch(sessionsDir, { recursive: true, persistent: false }, (_event, filename) => { if (!filename) {