From 5bf743f93de46688cf23344c7f7af813f5a70cb8 Mon Sep 17 00:00:00 2001 From: Gagan Date: Mon, 13 Jul 2026 17:45:51 +0530 Subject: [PATCH] fix(workspace): pre-create watched roots so late-appearing dirs emit events chokidar v4 silently skips a watched directory that doesn't exist at watch time, so e.g. calendar_sync/ created by the first sync after app start would never emit events until restart. Create the dir roots up front; for the file root only its parent dir is needed. --- apps/x/packages/core/src/workspace/watcher.ts | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/x/packages/core/src/workspace/watcher.ts b/apps/x/packages/core/src/workspace/watcher.ts index be7344c4..c50163d7 100644 --- a/apps/x/packages/core/src/workspace/watcher.ts +++ b/apps/x/packages/core/src/workspace/watcher.ts @@ -16,20 +16,20 @@ export type WorkspaceChangeCallback = (event: z.infer { await ensureWorkspaceRoot(); - const roots = WATCHED_ROOTS.map((rel) => path.join(WorkDir, rel)); + // chokidar v4 never picks up a watched directory that doesn't exist yet + // (a missing file is fine as long as its parent dir exists), so create the + // roots up front — otherwise e.g. calendar_sync/ appearing after app start + // would stay invisible until restart. + for (const rel of WATCHED_DIR_ROOTS) { + await fs.mkdir(path.join(WorkDir, rel), { recursive: true }); + } + for (const rel of WATCHED_FILE_ROOTS) { + await fs.mkdir(path.dirname(path.join(WorkDir, rel)), { recursive: true }); + } + + const roots = [...WATCHED_DIR_ROOTS, ...WATCHED_FILE_ROOTS].map((rel) => path.join(WorkDir, rel)); const watcher = chokidar.watch(roots, { ignoreInitial: true, // knowledge/ is a git repo (version history) — its .git object store is