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