Skip to content

[Bug]: CopilotRule.fromFile() determines root by filename alone, ignoring directory context #6

Open

Description

@flanny7

Hello, I always appreciate rulesync.

Problem

CopilotRule.fromFile() determines whether a file is a "root" rule by comparing only relativeFilePath, without considering relativeDirPath. This may cause incorrect root detection in edge cases, especially in global mode.

Evidence

In src/features/rules/copilot-rule.ts around line 208:

const isRoot = relativeFilePath === paths.root.relativeFilePath;

The comparison is performed against only the file name portion (e.g., "copilot-instructions.md"), without verifying that the directory also matches. In project mode, the root file is .github/copilot-instructions.md, and in global mode it is .copilot/copilot-instructions.md. If a non-root file happens to be named copilot-instructions.md in a different directory, it could be incorrectly classified as a root rule.

Expected Behavior

Root detection should use the full relative path (directory + filename) to unambiguously distinguish root from non-root files.

Proposed Solution

Compare the full path including directory:

const isRoot =
  path.join(relativeDirPath, relativeFilePath) ===
  path.join(paths.root.relativeDirPath, paths.root.relativeFilePath);

Your consideration would be appreciated.

Activity

  1. flanny7 commented on Apr 22, 2026

    @flanny7
    OwnerAuthor

    Just a quick follow-up regarding cross-platform compatibility:

    When using path.join(), it applies the OS-specific separator (\ on Windows, / on POSIX). This could cause the strict equality (===) check to fail if the paths.root properties were generated or stored using a different separator convention.

    Given the previous forward slash to backslash conversion bug we saw in the gitignore command, and to ensure this logic works seamlessly across hybrid environments like Windows and WSL2, it might be safer to explicitly normalize the paths before comparing them.

    Here is an updated snippet ensuring the separators are consistent:

    const normalize = (p: string) => p.replace(/\\/g, '/');
    
    const isRoot =
      normalize(path.join(relativeDirPath, relativeFilePath)) ===
      normalize(path.join(paths.root.relativeDirPath, paths.root.relativeFilePath));

    Alternatively, if there is already an existing utility function for cross-platform path normalization in the repository, we can just use that. Let me know what you think!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions