Skip to content

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

@flanny7

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.

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