fix: share skills watcher ignores

This commit is contained in:
Peter Steinberger
2026-01-17 08:04:24 +00:00
parent e6477363e9
commit 8f1132e8ec
2 changed files with 11 additions and 8 deletions

View File

@@ -12,19 +12,20 @@ vi.mock("chokidar", () => {
}); });
describe("ensureSkillsWatcher", () => { describe("ensureSkillsWatcher", () => {
it("ignores node_modules and dist by default", async () => { it("ignores node_modules, dist, and .git by default", async () => {
const mod = await import("./refresh.js"); const mod = await import("./refresh.js");
mod.ensureSkillsWatcher({ workspaceDir: "/tmp/workspace" }); mod.ensureSkillsWatcher({ workspaceDir: "/tmp/workspace" });
expect(watchMock).toHaveBeenCalledTimes(1); expect(watchMock).toHaveBeenCalledTimes(1);
const opts = watchMock.mock.calls[0]?.[1] as { ignored?: unknown }; const opts = watchMock.mock.calls[0]?.[1] as { ignored?: unknown };
expect(Array.isArray(opts.ignored)).toBe(true); expect(opts.ignored).toBe(mod.DEFAULT_SKILLS_WATCH_IGNORED);
const ignored = opts.ignored as RegExp[]; const ignored = mod.DEFAULT_SKILLS_WATCH_IGNORED;
expect(ignored.some((re) => re.test("/tmp/workspace/skills/node_modules/pkg/index.js"))).toBe( expect(ignored.some((re) => re.test("/tmp/workspace/skills/node_modules/pkg/index.js"))).toBe(
true, true,
); );
expect(ignored.some((re) => re.test("/tmp/workspace/skills/dist/index.js"))).toBe(true); expect(ignored.some((re) => re.test("/tmp/workspace/skills/dist/index.js"))).toBe(true);
expect(ignored.some((re) => re.test("/tmp/workspace/skills/.git/config"))).toBe(true); expect(ignored.some((re) => re.test("/tmp/workspace/skills/.git/config"))).toBe(true);
expect(ignored.some((re) => re.test("/tmp/.hidden/skills/index.md"))).toBe(false);
}); });
}); });

View File

@@ -26,6 +26,12 @@ const workspaceVersions = new Map<string, number>();
const watchers = new Map<string, SkillsWatchState>(); const watchers = new Map<string, SkillsWatchState>();
let globalVersion = 0; let globalVersion = 0;
export const DEFAULT_SKILLS_WATCH_IGNORED = [
/(^|[\\/])\.git([\\/]|$)/,
/(^|[\\/])node_modules([\\/]|$)/,
/(^|[\\/])dist([\\/]|$)/,
] as const;
function bumpVersion(current: number): number { function bumpVersion(current: number): number {
const now = Date.now(); const now = Date.now();
return now <= current ? current + 1 : now; return now <= current ? current + 1 : now;
@@ -127,11 +133,7 @@ export function ensureSkillsWatcher(params: { workspaceDir: string; config?: Cla
}, },
// Avoid FD exhaustion on macOS when a workspace contains huge trees. // Avoid FD exhaustion on macOS when a workspace contains huge trees.
// This watcher only needs to react to skill changes. // This watcher only needs to react to skill changes.
ignored: [ ignored: DEFAULT_SKILLS_WATCH_IGNORED,
/(^|[\\/])\../, // dotfiles (includes .git)
/(^|[\\/])node_modules([\\/]|$)/,
/(^|[\\/])dist([\\/]|$)/,
],
}); });
const state: SkillsWatchState = { watcher, pathsKey, debounceMs }; const state: SkillsWatchState = { watcher, pathsKey, debounceMs };