Skip to content

Fix watch depth limit being inert on Windows (path separator)#7

Open
Osamaali313 wants to merge 1 commit into
daymonio:mainfrom
Osamaali313:fix/watch-depth-windows-separator
Open

Fix watch depth limit being inert on Windows (path separator)#7
Osamaali313 wants to merge 1 commit into
daymonio:mainfrom
Osamaali313:fix/watch-depth-windows-separator

Conversation

@Osamaali313

Copy link
Copy Markdown

Summary

The recursive file watcher (src/sidecar/file-watcher.ts) is meant to ignore changes deeper than 2 path levels (comment: "Limit depth to 1 (direct children + 1 level of subdirectories)"). It computes depth by splitting a path.relative() result on the literal '/':

const rel = relative(watch.path, filePath)
const depth = rel.split('/').length
if (depth > 2) return

On Windows, path.relative() returns backslash-separated paths (a\b\c\deep.txt), so split('/') returns a single-element array → depth is always 1depth > 2 never fires. The depth limit is completely inert on Windows, so deeply-nested file changes trigger Claude Code actions the code intends to suppress.

Fix

Extract the depth computation into a small helper that splits on either separator (identical behavior on POSIX, correct on Windows), and reuse it in the watcher:

function watchRelativeDepth(watchPath: string, filePath: string): number {
  return relative(watchPath, filePath).split(/[/\]/).length
}
-      if (isDir) {
-        const rel = relative(watch.path, filePath)
-        const depth = rel.split('/').length
-        if (depth > 2) return
-      }
+      if (isDir && watchRelativeDepth(watch.path, filePath) > 2) return

watchRelativeDepth is exposed via the existing _testing export.

Testing

Added a watchRelativeDepth block to src/sidecar/__tests__/file-watcher.test.ts using path.join (OS-native separators):

  • direct child → depth 1; 1–2 levels → not skipped; 3–4 levels → skipped.

Verified on Windows: with the old split('/'), every path reports depth 1 so the 3- and 4-level cases are wrongly not skipped (test fails); with the fix they report depth 3/4 and are skipped (test passes). POSIX behavior is unchanged (/ paths split identically).

The recursive file watcher limits triggers to a depth of 2 by splitting the
relative path on '/'. path.relative() returns backslash-separated paths on
Windows, so the split yields a single segment, depth is always 1, and the
`depth > 2` guard never fires — deeply-nested changes trigger actions the code
intends to suppress.

Extract the depth computation into a small helper that splits on either
separator (no change to POSIX behavior) and add a regression test.
Copilot AI review requested due to automatic review settings June 21, 2026 16:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants